How to check if AppSKey is transmitting correctly

Hi all,

I have been exploring the forums for some time and I notice a lot of similar posts, however none have yet to provide a solution.

I have used the LMIC library and altered it to be used in the espressif esp-idf V4.4, this was mostly in the HAL area with some minor changes required in other parts (such as removing PROGMEM) .

The problem is odd and I’m not sure how to approach it, I print all the value out before transmitting and the addresses appear to be fine.

I am getting the error MIC Mismatch, the same as described here.

Partial output from gateway here:

"payload": {
      "m_hdr": {},
      "mic": "fA5MzA==",
      "join_request_payload": {
        "join_eui": "E9B52C70414C5CA1",
        "dev_eui": "7CDFA1414C5C5B5B",
        "dev_nonce": "10AF"
      }
    },
    "settings": {
      "data_rate": {
        "lora": {
          "bandwidth": 125000,
          "spreading_factor": 10
        }
      },
      "coding_rate": "4/5",
      "frequency": "916800000",
      "timestamp": 4055932708
    }

I am also getting a similar problem when using ABP.

I can see that the DevAddress is coming through fine yet it appears the AppSKey and NwkSKey might not be coming through (can’t determine from the gateway packets. Once again, these values get printed before sending and appear fine.

Output from an ABP packet on the gateway:

 "data": {
    "@type": "type.googleapis.com/ttn.lorawan.v3.UplinkMessage",
    "raw_payload": "QKW9DSYAAAABSWVsbG8shcpiVGxkIYrH6WE=",
    "payload": {
      "m_hdr": {
        "m_type": "UNCONFIRMED_UP"
      },
      "mic": "isfpYQ==",
      "mac_payload": {
        "f_hdr": {
          "dev_addr": "260DBDA5",
          "f_ctrl": {}
        },
        "f_port": 1,
        "frm_payload": "SWVsbG8shcpiVGxkIQ=="
      }
    },
    "settings": {
      "data_rate": {
        "lora": {
          "bandwidth": 125000,
          "spreading_factor": 7
        }
      },
      "coding_rate": "4/5",
      "frequency": "917000000",
      "timestamp": 4209304516
    },

Output from ABP device terminal:
Output from device terminal:

I (1846) lmic: Line 3007
I (1846) lmic: Line 3010
Address DVAADR: 260dbda5
Address NWKSKEY: 67-4d-b3-6d-63-9c-99-50-bb-d1-8e-9-ed-22-d7-66
Address APPSKEY: 44-93-b6-80-9a-8a-92-1d-b9-42-a-f3-e1-3c-2-c7
Settings
34308: engineUpdate, opmode=0x808
EV_TXSTARTI (1856) radio: Line 431
I (1856) radio: Line 384

I am using a Pygate 8 channel gateway which is setup on the TTN V3 Stack

Other details:
Using AU915 FSB2
MCU is esp32-s2
Had trouble using the default AES encryption that was in the LMIC library, used the advice given here to get it working.

I hope I’m not doubling up (theres so many similar posts!), but I’ve spent many hours searching these forums.

Any help is appreciated.

Cheers,
Dylan

Have you checked the endianness of the keys?

You may want to explore this to help with debugging:

https://lorawan-packet-decoder-0ta6puiniaut.runkit.sh

Hi,

Sure have (although admittedly, I’m not entirely sure what to do with the information):
OTAA with Secret AppSkey copied from the device in the TTN:

Assuming base64-encoded packet
AKFcTEFwLLXpW1tcTEGh33zCEHxjTMw=

Message Type = Join Request
  PHYPayload = 00A15C4C41702CB5E95B5B5C4C41A1DF7CC2107C634CCC

( PHYPayload = MHDR[1] | MACPayload[..] | MIC[4] )
        MHDR = 00
  MACPayload = A15C4C41702CB5E95B5B5C4C41A1DF7CC210
         MIC = 7C634CCC (from packet) INVALID (tried MSB 0000-FFFF)
             = D2711654 (expected, assuming 32 bits frame counter with MSB 0000)

( MACPayload = AppEUI[8] | DevEUI[8] | DevNonce[2] )
      AppEUI = E9B52C70414C5CA1
      DevEUI = 7CDFA1414C5C5B5B
    DevNonce = 10C2

ABP with NwkSKey and AppSKey:

Assuming base64-encoded packet
QKW9DSYAAAABSWVsbG8shcpiVGxkIYrH6WE=

Message Type = Data
  PHYPayload = 40A5BD0D260000000149656C6C6F2C85CA62546C64218AC7E961

( PHYPayload = MHDR[1] | MACPayload[..] | MIC[4] )
        MHDR = 40
  MACPayload = A5BD0D260000000149656C6C6F2C85CA62546C6421
         MIC = 8AC7E961 (from packet) INVALID (tried MSB 0000-FFFF)
             = 7559632D (expected, assuming 32 bits frame counter with MSB 0000)

( MACPayload = FHDR | FPort | FRMPayload )
        FHDR = A5BD0D26000000
       FPort = 01
  FRMPayload = 49656C6C6F2C85CA62546C6421 (from packet, encrypted)
             = 6428C4CF556492E4136BC3217E (decrypted)

      ( FHDR = DevAddr[4] | FCtrl[1] | FCnt[2] | FOpts[0..15] )
     DevAddr = 260DBDA5 (Big Endian)
       FCtrl = 00
        FCnt = 0000 (Big Endian)
       FOpts = 

Message Type = Unconfirmed Data Up
   Direction = up
        FCnt = 0
   FCtrl.ACK = false
   FCtrl.ADR = false

Because the secrets are not transmitted with ABP receiving the transmitted keys can not be the problem which means you need to look at the code on your node. Given the issues with AES you mention that would be the first suspect.

I bet your right,
Undoing the edits I made, I am getting the error:
…/components/src/aes/other.c: In function ‘os_aes_cmac’:
…/components/src/aes/other.c:56:9: error: implicit declaration of function ‘lmic_aes_encrypt’ [-Werror=implicit-function-declaration]
lmic_aes_encrypt(AESaux, AESkey);
^~~~~~~~~~~~~~~~
cc1.exe: some warnings being treated as errors

I see this line but I’m not sure where it should be defined?

// This should be defined elsewhere
void lmic_aes_encrypt(u1_t *data, u1_t *key);

I have it working using what was done in this library (for the AES stufff):

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.