Sasmosaw
Sasmosaw

Reputation: 1

Calculating the MIC of a LoRaWAN package on Join-Request in firmware

Context

I'm currently using TTSS (The Things Stack Sandbox), I'm trying to do an OTAA activation, but I receive a MIC mismatch error, using (this debugging webpage)[https://lorawan-packet-decoder-0ta6puiniaut.runkit.sh] I can indeed see that there's is a problem whit the MIC, I'm using some libraries that some coworker gave me.

He was using this library to calculate the MIC on a uplink payload (and it worked), tho, from what I understand, for the version of LoRaWAN that I'm using that shouldn't matter.

these libraries are based on a CMAC and AES libraries provided from Semtech, so those should be working just fine.

The function that calculates the MIC that my coworker gave me has this documentation

/*!
 * \brief Computes the LoRaMAC frame MIC field
 *
 * \param [IN]  buffer          Data buffer
 * \param [IN]  size            Data buffer size
 * \param [IN]  key             AES key to be used
 * \param [IN]  address         Frame address
 * \param [IN]  dir             Frame direction [0: uplink, 1: downlink]
 * \param [IN]  sequenceCounter Frame sequence counter
 * \param [OUT] mic Computed MIC field
 */
void LoRaMacComputeMic( const uint8_t *buffer, uint16_t size, const uint8_t *key, uint32_t address, uint8_t dir, uint32_t sequenceCounter, uint32_t *mic )
{

To use this function on the Join-request I should only input 0 in every parameter except the Data buffer, data buffer size and AES key to be used.

But when I try to do that, the MIC obtain is apparently not the rigth one, for example, for the following join-request (no MIC on this package, the AppEui is 0x0807060504030201, and the DevEUI is 0x8070605050607080): 00 08 07 06 05 04 03 02 01 80 70 60 50 50 60 70 80 00 00 Whit the following key: {0XAB, 0xC6, 0x6A, 0xAD, 0x4C, 0x97, 0x52, 0x3B, 0x0A, 0xED, 0x5A, 0xDA, 0xE4, 0xBC, 0x72, 0xA0} I get the following MIC: 030b08d0 But I should be getting (used the debugguer for this)[https://lorawan-packet-decoder-0ta6puiniaut.runkit.sh/?data=gEAwIBAAAAAK7R8eg9P0%2BgyO2hk6XDmRhAycZO7v%2Beij&nwkskey=BABECAFE12345678BABECAFE12345678&appskey=CAFEBABE12345678CAFEBABE12345678]: C89686D5

I though about the endian of the bits, but if I try whit the inverted key it doesn't work either (you can check that here)[https://lorawan-packet-decoder-0ta6puiniaut.runkit.sh/?data=AAgHBgUEAwIBgHBgUFBgcIAAAFtNvgg%3D&nwkskey=&appskey=A072BCE4DA5AED0A3B52974CAD6AC6AB]

Even weirder (for me), if I try to do this whit an uplink using the libraries, then it does work, the website I'm using for debugging says is the correct MIC, so the function is working properly.

The question

Can someone point out where the problem might be? maybe I'm missing some difference between the B0 block on the Join-request and the uplink?

Additional information I'm using the LoRaWAN specification 1.0.4

Upvotes: 0

Views: 88

Answers (0)

Related Questions