Issue link: https://read.uberflip.com/i/1428377
LoRaWAN Specification ©2015 LoRa™ Alliance Page 21 of 82 The authors reserve the right to change specifications without notice. 1 Size (bytes) 1 4 1 4 4 1 1 A i 0x01 4 x 0x00 Dir DevAddr FCntUp or FCntDown 0x00 i 2 The direction field (Dir) is 0 for uplink frames and 1 for downlink frames. 3 The blocks A i are encrypted to get a sequence S of blocks S i : 4 5 S i = aes128_encrypt(K, A i ) for i = 1..k 6 S = S 1 | S 2 | .. | S k 7 Encryption and decryption of the payload is done by truncating 8 9 (pld | pad 16 ) xor S 10 to the first len(pld) octets. 11 4.3.3.2 Encryption above the LoRaWAN layer 12 If the layers above LoRaWAN provide pre-encrypted FRMPayload to LoRaWAN on selected 13 ports (but not on FPort 0 which is reserved for MAC commands), LoRaWAN transfers 14 FRMPayload from MACPayload to the application and FRMPayload from the application to 15 MACPayload without any modification of FRMPayload. 16 17 4.4 Message Integrity Code (MIC) 18 The message integrity code (MIC) is calculated over all the fields in the message. 19 20 msg = MHDR | FHDR | FPort | FRMPayload 21 whereby len(msg) denotes the length of the message in octets. 22 The MIC is calculated as follows [RFC4493]: 23 24 cmac = aes128_cmac(NwkSKey, B 0 | msg) 25 MIC = cmac[0..3] 26 27 whereby the block B 0 is defined as follows: 28 Size (bytes) 1 4 1 4 4 1 1 B 0 0x49 4 x 0x00 Dir DevAddr FCntUp or FCntDown 0x00 len(msg) 29 The direction field (Dir) is 0 for uplink frames and 1 for downlink frames. 30
