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.

CC2530: Creating Whitelist using MAC address(IEEE address).

Part Number: CC2530
Other Parts Discussed in Thread: Z-STACK

Hello everyone.

Now I am using zstack3,0,1.

Then I have one issue.

My smart system consist of several ZC and several ZED only.

I can register a several end devic's address at the cooperator through UART.
So I want to be able to connect only the already registered end devices in the coordinator.
So I have the following code

#define NV_APP_EASEN_LOOKUP             0x0402

...

uint8 ZMacAssociateRsp( ZMacAssociateRsp_t *pData )
{
uint8 iEndDev;
uint8* passAddr;
/* TBD: set security to zero for now. Require Ztool change */
pData->Sec.SecurityLevel = false;

for(iEndDev = 0; iEndDev < MAX_END_DEV_NUM; iEndDev ++)
{
osal_nv_item_init(NV_APP_EASEN_LOOKUP + iEndDev, Z_EXTADDR_LEN, NULL);
osal_nv_read(NV_APP_EASEN_LOOKUP + iEndDev, 0, Z_EXTADDR_LEN,
passAddr);
if ( AddrMgrExtAddrEqual( passAddr, pData-> DeviceAddress) == TRUE )
{
return ( MAC_MlmeAssociateRsp( (macMlmeAssociateRsp_t *) pData ) );
}
}
return ZNwkUnknownDevice;
}

I have not registered any terminal, but I am registered at any terminal.
So I set a breakpoint on above function, but it does not come in here.

Please explain why this is the case.
Or am I wrong with the code implementation?

Please help me.

Thanks in advance.

Piao

  • When a device joins, it will call ZDO_JoinIndicationCB and you can add your logic in it.
  • YK Chen Sir.

    Thanks for your right reply.

    Then I have some issue too.

    1)
    Even if the address of the End device is deleted from the coordinator while the registered end device is communicating, the communication still proceeds.
    However, when the coordinator is restarted at this time, the terminal is not communicated.
    To solve this problem, should the coordinator be restarted as a software?
    2)
    If you add a new end device, the newly added end device will not be connected.
    In this case, the end device is restarted.
    What is the solution for this?

    Please help me.

    Thanks in advance.

    Piao
  • i don't understand your descriptions well. Can you elaborate what you want to achieve?
  • 1)
    I have register one end device in one coordinator.And two end device is running now,registered end device only is connecting with coordinator.
    This is normal.

    When connecting end device is connecting with coordinator,I have remove ieee address of this end device from coordinator,but this end device is continue connecting.
    So I restart end device,end device was disconnected from coordinator.

    What is the solution for this?

    2)
    I tested another case.
    I run one coordinator and one end device.
    Here, this coordinator don't have ieee address of this end device.
    So this end device don't connect with coordinator.
    This is normal.

    In these status,I registered ieee address of this end device in coordinator through UART.

    I think that end device is connected with coordinator, but end device don't connect with coordinator.

    I want that end device connect with coordinator in these case.

    Piao
  • What do you mean "have remove ieee address of this end device from coordinator"? Can you elaborate what you do register IEEE address of device to coordinator through UART? As I know, there is no standard procedure defined by Zigbee spec for this.
  • I have save IEEE address of end devices in NV memory of coordinator through UART.

    So I want to be able to connect only the already registered end devices in the coordinator.

    ZStatus_t ZDO_JoinIndicationCB(uint16 ShortAddress, uint8 *ExtendedAddress,
    uint8 CapabilityFlags, uint8 type)
    {

    (void)ExtendedAddress;
    //check if the device is leaving before responding to rejoin request
    if( osal_get_timeoutEx( ZDAppTaskID , ZDO_DEVICE_RESET) )
    {
    return ZFailure; // device leaving , hence do not allow rejoin
    }

    #if 1
    uint8 iEndDev;
    uint8 passAddr[Z_EXTADDR_LEN];
    uint8 fSuccess = 0;

    for(iEndDev = 0; iEndDev < MAX_END_DEV_NUM; iEndDev ++)
    {
    osal_nv_item_init(NV_APP_EASEN_LOOKUP + iEndDev, Z_EXTADDR_LEN, NULL);
    osal_nv_read(NV_APP_EASEN_LOOKUP + iEndDev, 0, Z_EXTADDR_LEN,
    passAddr);
    if ( AddrMgrExtAddrEqual( passAddr, ExtendedAddress) == TRUE )
    {
    fSuccess = 1;
    break;
    }
    }
    if (fSuccess == 0) return ZFailure;
    #endif
    //////////////////////////

    #if ZDO_NV_SAVE_RFDs
    (void)CapabilityFlags;

    #else // if !ZDO_NV_SAVE_RFDs
    if (CapabilityFlags & CAPINFO_DEVICETYPE_FFD)
    #endif

    ...

    "REMOVE or REGISTER of IEEE address" I said is for NV memory.

    So I want to be able to connect only the already registered end devices in the coordinator.
  • The device list is managed by Z-Stack library and I don't think you can just add or remove a device like this way.
  • YK Chen Sir.

    I want to use several coordinators and several end devices.
    All coordinators use same channel.
    So I want that specified end device connect with specified coordinator.
    So I have use above method.

    I can't change device list is managed by zstack library?

    I want that specified end device connect with specified coordinator.

    Piao
  • You can create a whitelist on coordinator and send ZDP leave request to the joined node if the node is not on whitelist.
  • OK,You are right.

    So I implemented as following.

    ZStatus_t ZDO_JoinIndicationCB(uint16 ShortAddress, uint8 *ExtendedAddress,
    uint8 CapabilityFlags, uint8 type)
    {

    (void)ExtendedAddress;
    //check if the device is leaving before responding to rejoin request
    if( osal_get_timeoutEx( ZDAppTaskID , ZDO_DEVICE_RESET) )
    {
    return ZFailure; // device leaving , hence do not allow rejoin
    }

    #if 1
    uint8 iEndDev;
    uint8 passAddr[Z_EXTADDR_LEN];
    uint8 fSuccess = 0;

    for(iEndDev = 0; iEndDev < MAX_END_DEV_NUM; iEndDev ++)
    {
    osal_nv_item_init(NV_APP_EASEN_LOOKUP + iEndDev, Z_EXTADDR_LEN, NULL);
    osal_nv_read(NV_APP_EASEN_LOOKUP + iEndDev, 0, Z_EXTADDR_LEN,
    passAddr);
    if ( AddrMgrExtAddrEqual( passAddr, ExtendedAddress) == TRUE )
    {
    fSuccess = 1;
    break;
    }
    }
    if (fSuccess == 0) return ZFailure;
    #endif
    //////////////////////////

    #if ZDO_NV_SAVE_RFDs
    (void)CapabilityFlags;

    #else // if !ZDO_NV_SAVE_RFDs
    if (CapabilityFlags & CAPINFO_DEVICETYPE_FFD)
    #endif

    ....

    This is wrong way?
  • YK Chen Sir.

    Would you please explain to me right method to create whitelist.?

    Thanks in advance.

    Piao
  • You can just create an IEEE address list that contains IEEE address of device that you want to allow join so you can check it in Join Indication callback.
  • YK Chen Sir.
    Thanks for your reply,

    Sorry for disturb to you.
    I have one question.

    Where is part of Join Indication callback you said?

    Thanks in advance.
  • It’s ZDO_JoinIndicationCB
  • YK Chen Sir.

    Right.
    So I have implement as following.
    ZStatus_t ZDO_JoinIndicationCB(uint16 ShortAddress, uint8 *ExtendedAddress,
    uint8 CapabilityFlags, uint8 type)
    {

    (void)ExtendedAddress;
    //check if the device is leaving before responding to rejoin request
    if( osal_get_timeoutEx( ZDAppTaskID , ZDO_DEVICE_RESET) )
    {
    return ZFailure; // device leaving , hence do not allow rejoin
    }

    // updated by 873
    #if 1
    uint8 iEndDev;
    uint8 passAddr123[Z_EXTADDR_LEN];
    uint8 passAddr[Z_EXTADDR_LEN];
    uint8 fSuccess = 0;

    osal_memcpy(passAddr123,ExtendedAddress,Z_EXTADDR_LEN);
    printf("End device ADDR : %x %x %x %x %x %x %x %x\n",passAddr123[0],passAddr123[1],passAddr123[2],passAddr123[3],passAddr123[4],passAddr123[5],passAddr123[6],passAddr123[7]);
    for(iEndDev = 0; iEndDev < MAX_END_DEV_NUM; iEndDev ++)
    {
    osal_nv_item_init(NV_APP_EASEN_LOOKUP + iEndDev, Z_EXTADDR_LEN, NULL);
    osal_nv_read(NV_APP_EASEN_LOOKUP + iEndDev, 0, Z_EXTADDR_LEN,
    passAddr);
    if ( AddrMgrExtAddrEqual( passAddr, ExtendedAddress) == TRUE )
    {
    fSuccess = 1;
    break;
    }
    }
    if (fSuccess == 0) return ZFailure;
    #endif
    //////////////////////////

    #if ZDO_NV_SAVE_RFDs
    (void)CapabilityFlags;

    #else // if !ZDO_NV_SAVE_RFDs
    if (CapabilityFlags & CAPINFO_DEVICETYPE_FFD)
    #endif
    {
    ZDApp_NVUpdate(); // Notify to save info into NV.
    }

    if (ZG_SECURE_ENABLED) // Send notification to TC of new device.
    {
    if ( type == NWK_ASSOC_JOIN ||
    type == NWK_ASSOC_REJOIN_UNSECURE ||
    type == NWK_ASSOC_REJOIN_SECURE )
    {
    uint16 timeToFire;
    ZDAppNewDevice_t *pNewDevice, *pDeviceList;

    pNewDevice = (ZDAppNewDevice_t *) osal_mem_alloc( sizeof(ZDAppNewDevice_t) );

    if ( pNewDevice == NULL )
    {
    // Memory alloc failed
    return ZMemError;
    }

    // Add the new device to the New Device List
    if ( ZDApp_NewDeviceList == NULL )
    {
    // The list is empty, add the first element
    ZDApp_NewDeviceList = pNewDevice;
    }
    else
    {
    pDeviceList = ZDApp_NewDeviceList;

    // Walk the list to last element
    while ( pDeviceList->next )
    {
    pDeviceList = (ZDAppNewDevice_t *) pDeviceList->next;
    }

    // Add new device at the end
    pDeviceList->next = pNewDevice;
    }

    // get the remaining time of the timer
    timeToFire = osal_get_timeoutEx( ZDAppTaskID, ZDO_NEW_DEVICE );

    pNewDevice->next = NULL;
    pNewDevice->shortAddr = ShortAddress;
    pNewDevice->timeDelta = ZDAPP_NEW_DEVICE_TIME - timeToFire;

    // Start the timer only if there is no pending timer
    if ( pNewDevice->timeDelta == ZDAPP_NEW_DEVICE_TIME )
    {
    osal_start_timerEx( ZDAppTaskID, ZDO_NEW_DEVICE, ZDAPP_NEW_DEVICE_TIME );
    }
    }
    }

    return ZSuccess;

    }

    1)
    I have register one end device in one coordinator.And two end device is running now,registered end device only is connecting with coordinator.
    This is normal.

    When connecting end device is connecting with coordinator,I have remove ieee address of this end device from coordinator,but this end device is continue connecting.
    So I restart end device,end device was disconnected from coordinator.

    What is the solution for this?

    2)
    I tested another case.
    I run one coordinator and one end device.
    Here, this coordinator don't have ieee address of this end device.
    So this end device don't connect with coordinator.
    This is normal.

    In these status,I registered ieee address of this end device in coordinator through UART.

    I think that end device is connected with coordinator, but end device don't connect with coordinator.

    I want that end device connect with coordinator in these case.

    Piao
  • You cannot just return failure in this callback when the device IEEE address is not in white list. You have to send ZDP leave request to ask devices to leave.