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.

Selective bonding with device using Whitelist [CC2541]

Other Parts Discussed in Thread: CC2541, CC2650

HI,

I'm trying to implement a feature which will allow the CC2541 to advertise normally initially but as soon as it connects to a device, it saves the device in White List and then changes the advertising mode to White List Only so that in future it can only connect to that particular device.

Here's my current method:

In SensorTag.c, when the cc2541 connects to the device I'm syncing the whitelist

case GAPROLE_CONNECTED:

      HalLedSet(HAL_LED_1, HAL_LED_MODE_OFF );

         uint8 WL = HCI_LE_ReadWhiteListSizeCmd();
         printf("%d", WL);                                                           // output = 46339
      
      uint8 syncWL = TRUE;
      GAPBondMgr_SetParameter( GAPBOND_AUTO_SYNC_WL, sizeof ( uint8 ), &syncWL );

         WL = HCI_LE_ReadWhiteListSizeCmd();
         printf("%d", WL);                                                           // output = 46337
      break;

In peripheral.c, I read the white list count and if it's >0 I switch the advertising to whitelist.

if ( events & START_ADVERTISING_EVT ){
    uint8 WL = HCI_LE_ReadWhiteListSizeCmd();
printf("%u", WL); // output = 0
if(WL>0 ){ gapRole_AdvFilterPolicy = GAP_FILTER_POLICY_WHITE; } else{ gapRole_AdvFilterPolicy = GAP_FILTER_POLICY_ALL; } ... }

My question is that what does HCI_LE_ReadWhiteListSizeCmd() actually return? in SensorTag.c, before autosync it returns value 46339 and after it returns 46337 . But in peripheral.c the returned value is always 0.

how can I make this work?

 

Thanks

 

 

  • Hi Sanat,

    You can use the below code in order to initially connect to a device, and then, once you connect to the device, you save it in the whitelist and on subsequent advertising events, only advertise to whitelisted device that you already added:

    case GAPROLE_CONNECTED:

    uint8 adv_filter = GAP_FILTER_POLICY_WHITE;
    uint8 remoteBdAddr[B_ADDR_LEN] = {0};

    GAPRole_GetParameter(GAPROLE_CONN_BD_ADDR, remoteBdAddr);

    // set the white list for advertise and scan
    GAPRole_SetParameter( GAPROLE_ADV_FILTER_POLICY, sizeof( uint8 ), &adv_filter );

    HCI_LE_ClearWhiteListCmd();
    HCI_LE_AddWhiteListCmd( HCI_PUBLIC_DEVICE_ADDRESS, remoteBdAddr );

    We have tested this code and it works.

    I hope this helps you.

    Thanks,
    Sunny

  • I can't thank you enough for this. I've been working on this for more than two weeks now but couldn't get it working.
    Thanks :)
  • You are welcome Sanat.
  • Hi Sunny,

    I wanted to get the Bluetooth address of the connected device using 2 CC2650,and add that device in white list,I went through one of you post for cc2541  for that you have given the code can you suggest how i can implement same in CC2650 i tried the same approach but it didn't work,

    Atul W. 

  • Hi All,

    I wanted to connect 2 CC2650 devices and after connection how can i get the MAC/Bluetooth Address of the device connected and store it in a white-list.? 

    Atul W.

  • Hello Atul,

    The procedure for obtaining the BD ADDR is the same as CC254x. See the "case GAPROLE_CONNECTED:" procedure above.

    Have you tried this?

    Best wishes
  • Hello JXS,

    I have Tried the above method but here when i am trying to read using above method i am getting the same device address bluetooth address,i want the other device address with which it is connected.

  • When i Execute the command GAPRole_GetParameter(GAPROLE_CONN_BD_ADDR, remoteBdAddr);
    i am getting the same device address from which i am trying to read.