Thread network key changes when migrating from NCS 2.4.1 to 2.6.1

nRF52840

NCS 2.4.1  to NCS 2.6.1

My project is based on the coap_server example.  When I ported it from NCS 2.4.1 to NCS 2.6.1, the network key and PSKC changed.  All other Thread credentials stayed the same (channel, channel mask,  panid, extended panid, mesh local prefix, network name, security policy).

The project supports DFU, so when upgrading from a 2.4.1 based version to a 2.6.1 based version, the network key changed and the device cannot communicate with other devices on the original network.

Both versions use identical pm_static.yml files, so the storage settings partition has not moved.

Is this a bug?  Is there a workaround?

Mary

Parents Reply Children
  • Is it only with DFU that the key is reset, or will it also reset over a power cycle?

    Since their project is based on the coap_server, are you setting the network key manually in your project? And if so, might you have changed it or set it to something other than the actual network key?

  • The network key is created randomly if, at bootup, there is not already a valid dataset.  The network key is empty in the prj.conf.

    prj.conf

    CONFIG_OPENTHREAD_NETWORKKEY=""

    coap_server_task()

    	ret = ot_coap_init(&on_publish_request, &on_subscribe_request, &on_tcpclient_request, &on_status_request);
    	if (ret) {
    		LOG_ERR("Could not initialize OpenThread CoAP");
    		goto end;
    	}
    
        // Network parameters
    	otOperationalDataset dataset;
    	otInstance *instance;
    	instance = openthread_get_default_instance();
    	if (!otDatasetIsCommissioned(instance))
    	{
    		LOG_INF("Thread not commissioned. Creating dataset.");
    		otDatasetCreateNewNetwork(instance, &dataset);
    
    		// Form network name from MAC address last three bytes (16 char limit)
    		// channel, panid, and networkkey will be random
    		uint32_t maclo = NRF_FICR->DEVICEADDR[0];
    		uint32_t machi = NRF_FICR->DEVICEADDR[1];
    		uint8_t mac[3];
    		mac[0] = machi;			// unique part
    		mac[1] = maclo >> 24;
    		mac[2] = maclo >> 16;
    
    		snprintk(dataset.mNetworkName.m8, sizeof(dataset.mNetworkName.m8), "MyNet_%02X%02X%02X", mac[0], mac[1], mac[2]);
    		dataset.mComponents.mIsNetworkNamePresent = true;
    		otDatasetSetActive(instance, &dataset);
    	}

    1. So, starting with project version 1.x, built with NCS 2.4.1, the server consistently uses the same network key, even after multiple DFUs and reboots/power cycles.

    2. Then  build version 2.x using NCS 2.6.1, and program the board using J-Link.  The network key has changed.  

    3. Using DFU, reload version 1.x.  Now the original network key is back.

    The other Thread parameters never change.

    Somehow there are two different network keys,

    Mary

  • Could you try to set the same key with CONFIG_OPENTHREAD_NETWORKKEY in the prj.conf for NCS 2.4.1 and NCS 2.6.1? Let me know if this can help or not. Here is the example: https://github.com/nrfconnect/sdk-nrf/blob/v2.4.1/samples/openthread/coap_client/prj.conf#L31 

  • I set

    CONFIG_OPENTHREAD_NETWORKKEY="00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff"
    in prf.conf for both 2.4.1 and 2.6.1.
     
    and commented out this code:
    	// if (!otDatasetIsCommissioned(instance))
    	// {
    	// 	LOG_INF("Thread not commissioned. Creating dataset.");
    	// 	otDatasetCreateNewNetwork(instance, &dataset);
    
    	// 	// Form network name from MAC address last three bytes (16 char limit)
    	// 	// channel, panid, and networkkey will be random
    	// 	uint32_t maclo = NRF_FICR->DEVICEADDR[0];
    	// 	uint32_t machi = NRF_FICR->DEVICEADDR[1];
    	// 	uint8_t mac[3];
    	// 	mac[0] = machi;			// unique part
    	// 	mac[1] = maclo >> 24;
    	// 	mac[2] = maclo >> 16;
    
    	// 	snprintk(dataset.mNetworkName.m8, sizeof(dataset.mNetworkName.m8), "MyNet_%02X%02X%02X", mac[0], mac[1], mac[2]);
    	// 	dataset.mComponents.mIsNetworkNamePresent = true;
    	// 	otDatasetSetActive(instance, &dataset);
    	// }
    I had to do a factory reset to see this network key appear. 
    1. compiled with 2.4.1, downloaded with J-Link, and ran.  Old network key appeared
    2. Factory reset, ran.  New hard coded network key appeared
    3. Then compiled with 2.6.1, downloaded with J-Link, and ran.  New hard coded network key appeared.
    4. Factory reset, ran. New hard coded network key appeared.
    I'm not sure what this tells us.  I cannot use a hard coded network key for production.
    Mary
  • Mary said:
    1. compiled with 2.4.1, downloaded with J-Link, and ran.  Old network key appeared

    Could you try to erase the board (nrfjprog --eraseall) before programming? Does it help?

Related