I’m trying to develop a Python code working as ED + GW which means I have keys in it, create PHY payload and send it to the network server via packet forwarder protocol.
So far I could implement the join process and derive keys successfully, but when I send an uplink message, I get “Invalid MIC” on the logs.
here is my code calculating the MIC:
def compute_mic(data): # based on https://lora-alliance.org/sites/default/files/2018-04/lorawantm_specification_-v1.1.pdf#page=27 cmac = AES_CMAC() fcntup = [0x00, 0x00, 0x00, 0x00] b0 = [0x49, 0x00, 0x00, 0x00, 0x00] b0 += [0x00] #dir b0 += config['devaddr'][::-1] b0 += fcntup b0 += [0x00] b0 += [len(data)] b0 += data b1 = [0x49, 0x00, 0x00] b1 += [0x02] #txdr b1 += [0x00] #txch b1 += [0x00] #dir b1 += config['devaddr'][::-1] b1 += fcntup b1 += [0x00] b1 += [len(data)] b1 += data sn_mic = cmac.encode(bytes(config['snwksintkey']), bytes(b1))[:2] fn_mic = cmac.encode(bytes(config['fnwksintkey']), bytes(b0))[:2] mic = list(map(int, sn_mic)) mic += list(map(int, fn_mic)) return mic
Regarding the devAddr, I tried both MSB and LSB but didn’t work. Can someone point out the problem?
Thanks in advance.