This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

how can i use whitelist in advertising

hello,

    I am using the SDK15.2 for development.

    I want to set a central address in peripheral like the whitelist function via uart without bonding.

    This code is about whitelist set。    

     err_code = sd_ble_gap_whitelist_set(addr_ptrs, whitelist_count);  .


     if(err_code != NRF_SUCCESS)
     {
              APP_ERROR_CHECK(err_code);
     }

     when debug ,the err_code = NRF_SUCCESS.

     So , I think the whitelist setting is successful,but the program cannot enter  whitelist  advertising。

     How can I set the whitelist address via uart without bonding?

     How can I confirm that the whitelist is set successfully?

     How can the peripheral start advertising with whitelist after reset the peripheral?

     The following is the code all about whitelist function, please read and help me to solve this problem。

     Thanks。

static void advertising_init(void)
{
         uint32_t err_code;
        ble_advertising_init_t init;

memset(&init, 0, sizeof(init));

init.advdata.name_type = BLE_ADVDATA_FULL_NAME;
init.advdata.include_appearance = true;
init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;

init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
init.srdata.uuids_complete.p_uuids = m_adv_uuids;

init.config.ble_adv_whitelist_enabled = true;
init.config.ble_adv_directed_high_duty_enabled = true;
init.config.ble_adv_fast_enabled = true;
init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
init.config.ble_adv_fast_timeout = APP_ADV_DURATION;
// init.config.ble_adv_slow_enabled = true;
// init.config.ble_adv_slow_interval = APP_ADV_SLOW_INTERVAL;
// init.config.ble_adv_slow_timeout = APP_ADV_SLOW_DURATION;


init.evt_handler = on_adv_evt;

err_code = ble_advertising_init(&m_advertising, &init);
APP_ERROR_CHECK(err_code);

ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);

}

void whitelist_set(void)
{
          ret_code_t err_code;
          static uint8_t data_array[6]={0xCB,0xEC,0x36,0x94,0x8b,0xd3};
          static ble_gap_addr_t my_addr[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
          ble_gap_addr_t const * addr_ptrs[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
          uint32_t whitelist_count = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;

         sd_ble_gap_whitelist_set(NULL, 8);

for(uint32_t i = 0; i < BLE_GAP_ADDR_LEN; i++)
{
       my_addr[0].addr[i] = data_array[i];
}
my_addr[0].addr_id_peer = 0x00;
my_addr[0].addr_type = 0x01;

for (uint32_t i = 0; i < BLE_GAP_WHITELIST_ADDR_MAX_COUNT; i++) //
{
       addr_ptrs[i] = &my_addr[i];
}

// NRF_ERROR_DATA_SIZE, if peer_cnt > BLE_GAP_WHITELIST_ADDR_MAX_COUNT.
// BLE_ERROR_GAP_WHITELIST_IN_USE, if a whitelist is in use.
err_code = sd_ble_gap_whitelist_set(addr_ptrs, whitelist_count);
if(err_code != NRF_SUCCESS)
{
      APP_ERROR_CHECK(err_code);
}

}

static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
       ret_code_t err_code;

switch (ble_adv_evt)
{
case BLE_ADV_EVT_DIRECTED_HIGH_DUTY:
         NRF_LOG_INFO("Directed advertising.");
         err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING_DIRECTED);
         APP_ERROR_CHECK(err_code);
break;

case BLE_ADV_EVT_FAST:
         NRF_LOG_INFO("Fast advertising.");
#if SWIFT_PAIR_SUPPORTED == 1
           err_code = ble_advertising_advdata_update(&m_advertising, &m_sp_advdata_buf, false);
          APP_ERROR_CHECK(err_code);
#endif
           err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
          APP_ERROR_CHECK(err_code);
break;

case BLE_ADV_EVT_SLOW:
          NRF_LOG_INFO("Slow advertising.");
          err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING_SLOW);
         APP_ERROR_CHECK(err_code);
break;

case BLE_ADV_EVT_FAST_WHITELIST:
         NRF_LOG_INFO("Fast advertising with whitelist.");
         err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING_WHITELIST);
         APP_ERROR_CHECK(err_code);
break;

case BLE_ADV_EVT_SLOW_WHITELIST:
          NRF_LOG_INFO("Slow advertising with whitelist.");
          err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING_WHITELIST);
          APP_ERROR_CHECK(err_code);
          err_code = ble_advertising_restart_without_whitelist(&m_advertising);
          APP_ERROR_CHECK(err_code);
break;

case BLE_ADV_EVT_IDLE:
         err_code = bsp_indication_set(BSP_INDICATE_IDLE);
        APP_ERROR_CHECK(err_code);
        sleep_mode_enter();
break;

case BLE_ADV_EVT_WHITELIST_REQUEST:
{

}
break;

case BLE_ADV_EVT_PEER_ADDR_REQUEST:
{

break;
}

         default:
         break;
         }
}

static void advertising_start(void)
{
         whitelist_set();
        uint32_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);//
        APP_ERROR_CHECK(err_code);
}

 

  • Hi.

    I have to  look at bit more into this, I will give you a reply tomorrow if this is OK.

    Best regards,

    Andreas

  • Hi.

     How can I set the whitelist address via uart without bonding?

     Do you wish to create a peripheral and use UART to tell the peripheral which addresses should be whitelisted?

    You have to send either the MAC address or the Identity Resolving Key (IRK) over UART, and add the incoming data to your whitelist in the code.

         How can I confirm that the whitelist is set successfully?

     You can try to connect with a device which is not in the whitelist.

         How can the peripheral start advertising with whitelist after reset the peripheral?

     I'm unsure what you mean here. You set up advertising with whitelist in your code.

         The following is the code all about whitelist function, please read and help me to solve this problem。

     Have you tried to debug the code and see what errors you get?

  • Thanks,AndreasF

    I wish to create a peripheral and use UART to tell the peripheral which addresses should be whitelisted?  When receive the uart data ,I set the mac address use function err_code = sd_ble_gap_whitelist_set(addr_ptrs, whitelist_count);  When debug , the err_code = NRF_SUCCESS, but the peripheral can not enter Fast advertising with whitelist, and another phone that its mac is not in whitelist alse can Identify the peripheral's mac and device name. I don't know why.

  • Hi.

    amywei said:
    and another phone that its mac is not in whitelist alse can Identify the peripheral's mac and device name

     This is normal behaviour, just because you add a whitelist, does not mean that the device is invisible for other devices not on the whitelist.

    Have you looked at any examples that implement a whitelist with Fast advertising?

    I recommend that you take a look at the examples\ble_peripheral\ble_app_hids_keyboard example.

    Best regards,

    Andreas

Related