This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2652R: Updating network key

Part Number: CC2652R

Hi!

I am trying to update network key while the network is up and running by pressing on btn -2 , is used the following code;

zstack_secNwkKeyGetReq_t zstack_secNwkKeyGetReq;
zstack_secNwkKeyGetRsp_t zstack_secNwkKeyGetRsp;

zstack_secNwkKeySetReq_t zstack_secNwkKeySetReq;
zstack_secNwkKeyUpdateReq_t zstack_secNwkKeyUpdateReq;
zstack_secNwkKeySwitchReq_t zstack_secNwkKeySwitchReq;

seqNum++;

zstack_secNwkKeyGetReq.activeKey = TRUE;
Zstackapi_secNwkKeyGetReq(appServiceTaskId, &zstack_secNwkKeyGetReq, &zstack_secNwkKeyGetRsp);

zstack_secNwkKeySetReq.activeKey = TRUE;
zstack_secNwkKeySetReq.seqNum = seqNum;
zstack_secNwkKeySetReq.has_key = TRUE;
OsalPort_memcpy(zstack_secNwkKeySetReq.key, Nwk_Key, INSTALL_CODE_LEN);

Zstackapi_secNwkKeySetReq(appServiceTaskId, &zstack_secNwkKeySetReq);

zstack_secNwkKeyUpdateReq.dstAddr = 0xFFFF;
zstack_secNwkKeyUpdateReq.seqNum = seqNum;
Zstackapi_secNwkKeyUpdateReq(appServiceTaskId, &zstack_secNwkKeyUpdateReq);

zstack_secNwkKeySwitchReq.dstAddr = 0xFFFF;
zstack_secNwkKeySwitchReq.seqNum = seqNum;
Zstackapi_secNwkKeySwitchReq(appServiceTaskId, &zstack_secNwkKeySwitchReq);

Building and compiling this doesn't give any error, I have controlled that the key is actually copied over to key and I get success status.
But when I use packet sniffing (Ubiqua protocol analyzer) the network key is not changed but APS command Transport key and Switch key is broadcasted when i press the button.
The Network key inside  transport key is not changed and is always the same.
Also, the DEFAULT_KEY is still set to 0 which will generate random key at initializing and it shouldn't effect NWK key updates, right? 
Seems like I am missing or forgetting something... 

Regards,
Hamza

  • Hi Hamza,

    Hamza Kadhum said:
    The Network key inside  transport key is not changed and is always the same.

    What SDK version are you using?

    Did you try the code without setting a specific network key first? Could you please attach a sniffer log so that I may look at what is happening?

    Hamza Kadhum said:
    Also, the DEFAULT_KEY is still set to 0 which will generate random key at initializing and it shouldn't effect NWK key updates, right? 

    Keeping the DEFAULT_KEY as 0 should not affect the NWK Key updates, correct.

    Best Regards,

    Marlyn

  • Hi Marlyn,

    I am using simplelink CC13x2 26x2 SDK version 3.30.03. 

    This is how the packet looks when I try to update the nwk key, starting with packet 41 

    This key is similar to the one when I don't give a specific key to update..

  • Hi, 

    It seemed like I missed the secNwkKeyUpdateReq call, the key is now updated and broadcasted. 
    I solved it by doing this:

    zstack_secNwkKeyUpdateReq.dstAddr = 0xFFFF;
    zstack_secNwkKeyUpdateReq.seqNum = seqNum;
    
    zstack_secNwkKeyUpdateReq.key = OsalPort_malloc(INSTALL_CODE_LEN); //The solution
    OsalPort_memcpy(zstack_secNwkKeyUpdateReq.key, Nwk_Key, INSTALL_CODE_LEN); //The solution
    Zstackapi_secNwkKeyUpdateReq(appServiceTaskId, &zstack_secNwkKeyUpdateReq); 
    OsalPort_free(zstack_secNwkKeyUpdateReq.key); //solution

    The structure sends a network key update structure, which was missing from the first code..
    In the first code we set the key but we don't update it, using zstack_secNwkKeyUpdateReq.key we update the network key given to that structure. 
    If I understand it correctly, zstack_secNwkKeySetReq sets key but It is update only when we request update structure? 
    Related to the question above, can we locate the available keys in the memory? If we can do that, it means we can update the structure with the available keys, right? 

    Regards,
    Hamza


  • Hi Hamza,

    Hamza Kadhum said:
    If I understand it correctly, zstack_secNwkKeySetReq sets key but It is update only when we request update structure? 

    Yes, zstack_secNwkKeyUpdateReq allows the Trust Center to send a new Network key to the dstAddr on the network. This allows the new Network key to be stored as an alternate key in the destination device/devices. Once the Trust Center calls ztack_secNwkKeySwitchReq all specified destination device/devices will use their alternate key.

    Hamza Kadhum said:
    can we locate the available keys in the memory? If we can do that, it means we can update the structure with the available keys, right? 

    Yes, you can use  ztack_secNwkKeyGetReq to locate the active or alternate keys. Set the input boolean value true for the active key or false for the alternate key/keys. The IDs for the active and alternate keys are located in the "NWK Layer NV item IDs" section of the zcomdef.h file and are 0x3A and 0x3B respectfully.

    Best Regards,

    Marlyn