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.

CC2541: WhiteList usage in the Observer role of CC2541 !

Part Number: CC2541


I have application base on the peripheral + observer simplePeripheral project.

The BLE device first scan other devices and saved these discovered device's address to white list, so later it can only scan these devices in the whitelist.


but I have problem to do that and need to know the right procedure of enable whiltelist during scan.

Below is the steps I did:

1) first initial scan parameter and start scan

 uint8 WhiteState=FALSE;  

 DEFAULT_SCAN_DURATION = 4000 ; // 4s

 GAP_SetParamValue( TGAP_GEN_DISC_SCAN, DEFAULT_SCAN_DURATION );

 uint8 scanRes = DEFAULT_MAX_SCAN_RES; // 8
 GAPRole_SetParameter( GAPOBSERVERROLE_MAX_SCAN_RES, sizeof( uint8 ), &scanRes );

 // start scan
 GAPObserverRole_StartDiscovery( DEFAULT_DISCOVERY_MODE,
                              DEFAULT_DISCOVERY_ACTIVE_SCAN,
                              WhiteState) )

2) add key pressed function for button SW1,
    //toggle whitelist enable/disable 
 WhiteState = !WhiteState; 

3) add key pressed function for SW2

 HCI_LE_ClearWhiteListCmd(); //clear whitelist
 
 HCI_LE_AddWhiteListCmd( HCI_PUBLIC_DEVICE_ADDRESS, simpleBLEDevList[i].addr )) //add discoveried device's address to whitelist
 
 WhiteState=TRUE;

4) in the timeout of scan period call scan again

static void observerEventCB( observerRoleEvent_t *pEvent )
{
  switch ( pEvent->gap.opcode )
  {
 case GAP_DEVICE_INFO_EVENT:
      {
 //  scan again
  GAPObserverRole_StartDiscovery( DEFAULT_DISCOVERY_MODE,
                              DEFAULT_DISCOVERY_ACTIVE_SCAN,
                              WhiteState) ) ;
 
       }
 break; 
 case GAP_DEVICE_INIT_DONE_EVENT:
  //add device's address to simpleBLEDevList[i]
  osal_memcpy( simpleBLEDevList[simpleBLEScanRes].addr, pEvent->deviceInfo.addr, B_ADDR_LEN );
 break;
  }
}

I press SW2 to add scanned device to list and after 4s , I turn on another BLE device and it will not been scan just as expetction.


later I pressed SW1 to toggle WhiteState to FALSE so the next scan will disable use whitelist, and new turned on device can be scanned by it. 

also as expection.

pressed SW1 again to toggle WhiteState to TRUE so only devices in the whitelist can be discorved , but didn't find anyone !

and this is the problem I can't figure out. also I restart(reset) it , and seems exist the whitelist table but also didn't work when press SW2 switch the

WhiteState to TRUE.


Also even no saved addresses in whitelist, but call GAPObserverRole_StartDiscovery with WhiteState=TRUE, will not discover any devices.

Would like to know the right way of using whitelist with observer to avoid the problems I met.

Thanks in advance.

  • Hi,

    You should restart discovery in the GAP_DEVICE_INFO_EVENT, instead should be in GAP_DEVICE_DISCOVERY_EVENT (which signal end of discovery)

    I would try adding the device to the whitelist manually first,

    static uint8 bdAddressPeer[6] = {0x90,0x78,0x56,0x34,0x12,0x00}; //insert device BD address
    HCI_LE_AddWhiteListCmd(ADDRMODE_PUBLIC, bdAddressPeer);

    then start discovery to see if the device in the whitlist is received.

    Best wishes
  • Dear Zahid,

    I don't understand why you said "restart discovery in the GAP_DEVICE_INFO_EVENT, instead should be in GAP_DEVICE_DISCOVERY_EVENT (which signal end of discovery)" ?

    Restart discovery in the end of discovery (GAP_DEVICE_DISCOVERY_EVENT) not in the on going discovery (GAP_DEVICE_INFO_EVENT) should be resonsable, also usage in the sample code (combo).

    By the way, I found the problem (can't find any devices)  happened only when advertisement also is enabled , no matter  advertisement is enabled before or after added devices to whitelist.

    Real want to know the right way (sequence) to enable white list with both discovery and advertisement turn on. (change usage whitelist dymincally for advertisement and scan) 

    Also why no exist any white list in NV but set TRUE to use whitelist in the discovery function will casue scan find nothing ?   

    Thanks  

  • Hi ,

    In the step 4, I wrote the wrong handle event in the Post but in my code is correct, below is the right POST:

    4) in the timeout of scan period call scan again

    static void observerEventCB( observerRoleEvent_t *pEvent )
    {
    switch ( pEvent->gap.opcode )
    {
    case GAP_DEVICE_DISCOVERY_EVENT:
    {
    // end of scan then scan again
    GAPObserverRole_StartDiscovery( DEFAULT_DISCOVERY_MODE,
    DEFAULT_DISCOVERY_ACTIVE_SCAN,
    WhiteState) ) ;

    }
    break;
    case GAP_DEVICE_INFO_EVENT:
    //add device's address to simpleBLEDevList[i]
    osal_memcpy( simpleBLEDevList[simpleBLEScanRes].addr, pEvent->deviceInfo.addr, B_ADDR_LEN );
    break;
    }
    }

    It just my typro , problem still there.

    Thanks