Exemple #1
0
        public byte[] DecryptFRMPayload(byte[] key, UnconfirmedDataUp data)
        {
            var  returnvalue = new byte[data.FRMPayload.Length];
            int  j           = 0;
            byte i           = 1;

            while (j < data.FRMPayload.Length)
            {
                var partsize = data.FRMPayload.Length - (j * 16) >= 16 ? 16 : data.FRMPayload.Length - (j * 16);
                var part     = new byte[partsize];
                Buffer.BlockCopy(data.FRMPayload, j, part, 0, partsize);

                var buf = new byte[16];
                buf[0] = 0x01;
                buf[5] = 0x00;
                Buffer.BlockCopy(MarshalDevAddr(data.Fhdr.DevAddr), 0, buf, 6, 4);
                Buffer.BlockCopy(BitConverter.GetBytes(Convert.ToUInt32(data.Fhdr.FCnt)), 0, buf, 10, 4);
                buf[15] = i;

                var key2 = Encrypt(buf, key);
                for (int x = 0; x < partsize; x++)
                {
                    returnvalue[(j * 16) + x] = (byte)(part[x] ^ key2[x]);
                }

                j += 16;
            }
            return(returnvalue);
        }
Exemple #2
0
        public UnconfirmedDataUp UnmarshalUnconfirmedDataUp(byte[] message)
        {
            var returnvalue = new UnconfirmedDataUp();

            returnvalue.Mhdr = UnmarshalMhdr(message[0]);

            var fctrl = UnmarshalFCtrlUplink(message[5]);

            var fhdr = new byte[7 + fctrl.FOptsLen];

            Buffer.BlockCopy(message, 1, fhdr, 0, 7 + fctrl.FOptsLen);
            returnvalue.Fhdr = UnmarshalFhdrUplink(fhdr, fctrl);
            if (message.Length - 1 /*mhdr*/ - 7 /*fhdr*/ - fctrl.FOptsLen - 4 /*mic*/ > 0)
            {
                returnvalue.FPort = message[1 + 7 + fctrl.FOptsLen];
                var frmpayloadsize = message.Length - 1 /*mhdr*/ - 7 /*fhdr*/ - fctrl.FOptsLen - 1 /*fport*/ - 4 /*mic*/;
                returnvalue.FRMPayload = new byte[frmpayloadsize];
                Buffer.BlockCopy(message, 1 + 7 + fctrl.FOptsLen + 1, returnvalue.FRMPayload, 0, frmpayloadsize);
            }
            returnvalue.Mic = new byte[4];
            Buffer.BlockCopy(message, message.Length - 4, returnvalue.Mic, 0, 4);
            return(returnvalue);
        }