Other Parts Discussed in Thread: SIMPLELINK-CC13X2-26X2-SDK, Z-STACK
Hi,
Zstack Version 3.0.2
Problem : On every reset coordinators network frame counter would be set 1250,
routers would stop responding to the packets from the coordinator with frame counter lower than last processed message.
Based on Toby Pan 's recommendation in the this post i tried debugging and found a bug in the following function:
void ZDApp_RestoreNwkSecMaterial(void) { uint8 Found = FALSE; uint8 i; nwkSecMaterialDesc_t nwkSecMaterialDesc; uint8 UpdateFrameCounter = FALSE; //Search if we do have security material for this network for( i = 0; i < gMAX_NWK_SEC_MATERIAL_TABLE_ENTRIES; i++) { osal_nv_read(ZCD_NV_NWK_SEC_MATERIAL_TABLE_START + i,0,sizeof(nwkSecMaterialDesc_t),&nwkSecMaterialDesc); { if(osal_memcmp(_NIB.extendedPANID,nwkSecMaterialDesc.extendedPanID,Z_EXTADDR_LEN)) { UpdateFrameCounter = TRUE; Found = TRUE; break; } } } //Check if we do have frame counter stored in the generic if(!Found) { //The last entry readed has the Generic item, thefore, no need to read it again if(nwkSecMaterialDesc.FrameCounter) { UpdateFrameCounter = TRUE; } } if(UpdateFrameCounter && (!FrameCounterUpdated)) { FrameCounterUpdated = TRUE; // Increment the frame counter stored in NV nwkSecMaterialDesc.FrameCounter += ( MAX_NWK_FRAMECOUNTER_CHANGES + NWK_FRAMECOUNTER_CHANGES_RESTORE_DELTA ); nwkFrameCounter = nwkSecMaterialDesc.FrameCounter; osal_nv_write(ZCD_NV_NWK_SEC_MATERIAL_TABLE_START + i,0,sizeof(nwkSecMaterialDesc_t),&nwkSecMaterialDesc);// <<<<<-------- nwkFrameCounterChanges = 0; } return; }
In this function in for loop since 'i' is incremented to "gMAX_NWK_SEC_MATERIAL_TABLE_ENTRIES "
So osal_nv_write ( line 41) is done to an uninitialized NV ID, it fails and the frame counter remains the same on each reset
Bug Fix:
Instead NV write should be done on the last element of the table which contains the generic security material i.e. "ZCD_NV_NWK_SEC_MATERIAL_TABLE_START + i - 1"
as below
osal_nv_write(ZCD_NV_NWK_SEC_MATERIAL_TABLE_START + i - 1,0,sizeof(nwkSecMaterialDesc_t),&nwkSecMaterialDesc);
It worked for me.
Just need the confirmation if it correct or am i missing something here?
Thanks