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

Cannot see BLE_ADV_EVT_SLOW_WHITELIST

Hello,

I have two devices, one central and one peripheral and I try to implement whitelist. I took a look at ble_app_hrs_c example and the whiltelist is working on central side for scanning. But on the peripheral side during advertising, i cannot use whitelist. Indeed, i can see the event BLE_ADV_EVT_WHITELIST_REQUEST in my advertising handler but i cannot see the BLE_ADV_EVT_SLOW_WHITELIST, there is only the following one : BLE_ADV_EVT_SLOW. It means that advertising is started without whitelist.

Here is a piece of my code : 

/**@brief Retrieve a list of peer manager peer IDs.
 *
 * @param[inout] p_peers   The buffer where to store the list of peer IDs.
 * @param[inout] p_size    In: The size of the @p p_peers buffer.
 *                         Out: The number of peers copied in the buffer.
 */
static void peer_list_get(pm_peer_id_t * p_peers, uint32_t * p_size)
{
    pm_peer_id_t peer_id;
    uint32_t     peers_to_copy;

    peers_to_copy = (*p_size < BLE_GAP_WHITELIST_ADDR_MAX_COUNT) ?
                     *p_size : BLE_GAP_WHITELIST_ADDR_MAX_COUNT;

    peer_id = pm_next_peer_id_get(PM_PEER_ID_INVALID);
    *p_size = 0;

    while ((peer_id != PM_PEER_ID_INVALID) && (peers_to_copy--))
    {
        p_peers[(*p_size)++] = peer_id;
        peer_id = pm_next_peer_id_get(peer_id);
    }
}


static void whitelist_load()
{
    ret_code_t   ret;
    pm_peer_id_t peers[8];
    uint32_t     peer_cnt;

    memset(peers, PM_PEER_ID_INVALID, sizeof(peers));
    peer_cnt = (sizeof(peers) / sizeof(pm_peer_id_t));

    // Load all peers from flash and whitelist them.
    peer_list_get(peers, &peer_cnt);

    ret = pm_whitelist_set(peers, peer_cnt);
    APP_ERROR_CHECK(ret);

    // Setup the device identies list.
    // Some SoftDevices do not support this feature.
    ret = pm_device_identities_list_set(peers, peer_cnt);
    if (ret != NRF_ERROR_NOT_SUPPORTED)
    {
        APP_ERROR_CHECK(ret);
    }

    // Display peer devices
    NRF_LOG_INFO("Peer devices saved :");
    ble_gap_addr_t p_addrs[8];
    uint32_t       p_addr_cnt = 8;
    pm_whitelist_get(p_addrs, &p_addr_cnt, NULL, NULL);
    for (uint8_t i=0; i<p_addr_cnt; i++) {
        NRF_LOG_INFO("    [%02X:%02X:%02X:%02X:%02X:%02X]",
              p_addrs[i].addr[5],
              p_addrs[i].addr[4],
              p_addrs[i].addr[3],
              p_addrs[i].addr[2],
              p_addrs[i].addr[1],
              p_addrs[i].addr[0]);
    }
}


static void on_whitelist_req(void)
{
    ret_code_t err_code;

    // Whitelist buffers.
    ble_gap_addr_t whitelist_addrs[8];
    ble_gap_irk_t  whitelist_irks[8];

    memset(whitelist_addrs, 0x00, sizeof(whitelist_addrs));
    memset(whitelist_irks,  0x00, sizeof(whitelist_irks));

    uint32_t addr_cnt = (sizeof(whitelist_addrs) / sizeof(ble_gap_addr_t));
    uint32_t irk_cnt  = (sizeof(whitelist_irks)  / sizeof(ble_gap_irk_t));

    // Reload the whitelist and whitelist all peers.
    whitelist_load();

    // Get the whitelist previously set using pm_whitelist_set().
    err_code = pm_whitelist_get(whitelist_addrs, &addr_cnt,
                                whitelist_irks,  &irk_cnt);

    if (((addr_cnt == 0) && (irk_cnt == 0)) ||
        (m_whitelist_disabled))
    {
    
        NRF_LOG_INFO("Whitelist NOT used");
        // Don't use whitelist.
        //err_code = nrf_ble_scan_params_set(&m_scan, NULL);
        //APP_ERROR_CHECK(err_code);
    }
    else {
        NRF_LOG_INFO("Whitelist used");
    }
}

/**@brief Function for handling advertising events.
 *
 * @details This function will be called for advertising events which are passed to the application.
 *
 * @param[in] ble_adv_evt  Advertising event.
 */
static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
    uint32_t err_code;

    switch (ble_adv_evt)
    {
        case BLE_ADV_EVT_FAST:
            NRF_LOG_INFO("Fast advertising started");
	    advertising_in_progress = true;
            break;
        case BLE_ADV_EVT_SLOW:
            NRF_LOG_INFO("Slow advertising started");
	    advertising_in_progress = true;
            break;
        case BLE_ADV_EVT_IDLE:
            NRF_LOG_INFO("Advertising stopped");
            advertising_in_progress = false;
            break;
        case BLE_ADV_EVT_FAST_WHITELIST:
            NRF_LOG_INFO("BLE_ADV_EVT_FAST_WHITELIST");
	    advertising_in_progress = true;
            break;
        case BLE_ADV_EVT_SLOW_WHITELIST:
            NRF_LOG_INFO("BLE_ADV_EVT_SLOW_WHITELIST");
	    advertising_in_progress = true;
            break;
        case BLE_ADV_EVT_WHITELIST_REQUEST:
            NRF_LOG_INFO("BLE_ADV_EVT_WHITELIST_REQUEST");
            on_whitelist_req();
            m_whitelist_disabled = false;
            break;
        case BLE_ADV_EVT_PEER_ADDR_REQUEST:
            NRF_LOG_INFO("BLE_ADV_EVT_PEER_ADDR_REQUEST");
            break;
        default:
            break;
    }
}

Whitelisting is activated in the function advertising_init by setting the following bit : init.config.ble_adv_whitelist_enabled = true;

Here is my logs 

<info> app: ********************************

<info> app: ADH DISABLED

<info> app: reset number : 0

<info> app: Start advertising ..

<info> app: BLE_ADV_EVT_WHITELIST_REQUEST

<info> app: Peer devices saved :

<info> app:     [C1:3B:C5:BC:D1:E6]

<info> app: Whitelist used

<info> app: BLE_ADV_EVT_SLOW

<info> app: Event: FDS_EVT_UPDATE received (FDS_SUCCESS)

<info> app: Event: FDS_EVT_UPDATE received (FDS_SUCCESS)

<info> app: Event: FDS_EVT_UPDATE received (FDS_SUCCESS)

<info> app: Event: FDS_EVT_UPDATE received (FDS_SUCCESS)

<info> app: BLE_GAP_EVT_CONNECTED

<info> app: Connected - handle : 0002

<info> peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 2, procedure: Encryption

<info> app: Event: FDS_EVT_UPDATE received (FDS_SUCCESS)

<info> peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 2, procedure: Encryption

<info> app: BLE_NUS_EVT_RX_DATA

Actually, i can see my whitelist is not taken into account when i try to connect with my phone to my peripheral. The connections are not rejected ...

If you have any idea, feel free to share Slight smile

Thank you in advance,

Best regards,

Aurélien

Parents
  • Hello Aurélien

    When you request a whitelist using BLE_ADV_EVT_WHITELIST_REQUEST the whitelist must be set afterward, which it seems like your application doesn't do, and therefore starts advertising without the whitelist. Please make sure you set your whitelist correctly. If you're using the peer manager you can use the ble_app_hids_keyboard example as a reference.

    Best regards,

    Simon

Reply
  • Hello Aurélien

    When you request a whitelist using BLE_ADV_EVT_WHITELIST_REQUEST the whitelist must be set afterward, which it seems like your application doesn't do, and therefore starts advertising without the whitelist. Please make sure you set your whitelist correctly. If you're using the peer manager you can use the ble_app_hids_keyboard example as a reference.

    Best regards,

    Simon

Children
Related