STM32CubeWL icon indicating copy to clipboard operation
STM32CubeWL copied to clipboard

LmHandlerSetAppKey does not update the APPKey

Open asob opened this issue 4 years ago • 2 comments

Hi,

I've been playing around with STM32CubeWL using Nucleo-64 (STM32WL55). The default LoRaWan applications seem to work correctly against TTI stack, but when I tried to make my own using Projects/NUCLEO-WL55JC/Applications/LoRaWAN/LoRaWAN_End_Node/ as basis things didn't work as expected

The main issue I'm having is that if have the most basic initialization code :

static uint8_t app_eui[] = { ... };
static uint8_t dev_eui[] = { ... };
static uint8_t app_key[] = { ... };

void APP_Init ( void )
{
    /* Register LmHandler task */
    UTIL_SEQ_RegTask(   (1 << CFG_SEQ_Task_LmHandlerProcess),
                        UTIL_SEQ_RFU,
                        LmHandlerProcess,
                        0);

    /* Initialize LoRaMac */
    LoraInfo_Init();
    LmHandlerInit(&lmhandler_callbacks);
    LmHandlerConfigure(&lmhandler_params);

    /* Set credentials */
    LmHandlerSetAppEUI(app_eui);
    LmHandlerSetAppKey(app_key);
    LmHandlerSetDevEUI(dev_eui);

    /* Start Join Process */
    LmHandlerJoin(lmhandler_activation_type);

}

And I provision the device with abovementioned keys in TTI I'm getting a MIC MISMATCH and no join will occur, but as soon as the line containing LmHandlerSetAppKey(app_key); is removed and APP KEY in backend is substituted with the one from LoRaWAN_End_Node/LoRaWAN/App/se-identity.h everything is fine.

So my question is :

Why define and implement LmHandlerSetAppKey() when this function simply is useless ?

asob avatar Oct 28 '21 13:10 asob

ST Internal Reference: 121057

ASELSTM avatar Jan 17 '22 16:01 ASELSTM

@asob

Try this:

/* Init Info table used by LmHandler */
LoraInfo_Init();

/* Init the Lora Stack*/
LmHandlerInit(&LmHandlerCallbacks);

LmHandlerConfigure(&LmHandlerParams);

MibRequestConfirm_t mibReq;

mibReq.Type = MIB_DEV_EUI;
mibReq.Param.DevEui = yourDevEui;

LoRaMacMibSetRequestConfirm(&mibReq);

mibReq.Type = MIB_JOIN_EUI;
mibReq.Param.JoinEui = yourJoinEui;

LoRaMacMibSetRequestConfirm(&mibReq);

mibReq.Type = MIB_NWK_KEY;
mibReq.Param.AppKey = yourAppKey;

LoRaMacMibSetRequestConfirm(&mibReq);

RomanJasmann avatar Jan 25 '22 11:01 RomanJasmann

Hi @asob,

According to our development teams, you have to use the LmHandlerSetNwkKey() function with the value of the APP_KEY you register in TTI.

Please find below more details:

  • The APP_KEY define in TTI is the key you will need to join the network. This implementation differs from the Link Layer specifications.
  • In your case, when setting a custom APP_KEY:
    • You get a mismatch because the APP_KEY in TTI means NWK_KEY.
    • In other words, it's not the same key you have registered in your device's configuration.
  • When you commented the call to the LmHandlerSetAppKey() function and reconfigured the device in TTI to set the APP_KEY to the original value, it worked because:
    • In the code, the same value is used for both the APP_KEY and the NWK_KEY.
    • Hence, the NWK_KEY value will be used (which is the same as the APP_KEY).

The se-identity.h file shall be updated to clarify the key usage. The update will be part of version 1.3.0 of this firmware, already available on st.com and soon on GitHub.

We hope this helps.

With regards,

ALABSTM avatar Dec 08 '22 15:12 ALABSTM