コード例 #1
0
        public PHYPayload(byte[] packet, byte[] nwkSKey, byte[] appSKey, byte[] appKey, int fCntMsbSeed)
        {
            Packet = packet;
            Mhdr   = new MHDR(this);
            switch (Mhdr.MessageType)
            {
            case MessageType.JoinRequest:
                MacPayload = new JoinRequestMessage(this, appKey);
                break;

            case MessageType.JoinAccept:
                MacPayload = new JoinAcceptMessage(this, appKey);
                break;

            case MessageType.Data:
                MacPayload = new DataMessage(this, nwkSKey, appSKey, fCntMsbSeed);
                break;

            case MessageType.Proprietary:
                throw new NotSupportedException();

            default:
                throw new NotSupportedException();
            }
            Mic = new MIC(this);
        }
コード例 #2
0
ファイル: CalculatedMIC.cs プロジェクト: sntcz/LoRa.Message
 /// <summary>
 ///
 /// </summary>
 /// <param name="joinAcceptMessage"></param>
 /// <param name="appKey"></param>
 public CalculatedMIC(JoinAcceptMessage joinAcceptMessage, byte[] appKey)
 {
     if (appKey != null && appKey.Length == 16)
     {
         CryptoService crypto = new CryptoService();
         // cmac = aes128_cmac(AppKey, MHDR | AppNonce | NetID | DevAddr | DLSettings | RxDelay | CFList)
         // MIC = cmac[0..3]
         byte[] data = new byte[joinAcceptMessage.RawData.Length + 1];
         joinAcceptMessage.Parent.Mhdr.RawData.CopyTo(data.AsSpan()); // [1]
         joinAcceptMessage.RawData.CopyTo(data.AsSpan(1));
         byte[] fullCAMC = crypto.AESCMAC(appKey, data);
         RawData = fullCAMC.AsSpan(0, 4).ToArray();
         IsValid = true;
     }
     else
     {
         RawData = Array.Empty <byte>();
         IsValid = false;
     }
 }