Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Basics of whitelist set function

Hi,

Custom board based on nrf52810

Soft device - S112 v6.0

I am trying to understand the usage of the function pm_whitelist_set (pm_peer_id_t const * p_peers, uint32_t peer_cnt).  I am not able to understand what to pass for peer_cnt ?               for example

I pair a phone(A) to nrf52810 and I want it to be whitelisted; I call pm_whitelist_set (&peer_ID_array, 0x01);   peer_cnt is 0x01 because only one peer to be whitelisted. Now I disconnect the phone(A) and connect a different phone(B) to nrf52810. I want this phone(B) also to be white listed. So I again call pm_whitelist_set(&peer_ID_array, 0x01) , during the second whitelisting process should the peer_cnt be 0x01 or 0x02? Since there are two peers in peer_ID_array now...

Thanks

   

Parents
  • Hello Rakesh,

    peer_cnt is the total number of peers.

    Notice how examples using whitelist will get the stored list of peers first and then set the whitelist.

    Excerpt beneath from when hid keyboard example (peripheral/ble_app_hids) starts advertising

    /**@brief Function for starting advertising.
     */
    static void advertising_start(bool erase_bonds)
    {
        if (erase_bonds == true)
        {
            delete_bonds();
            // Advertising is started by PM_EVT_PEERS_DELETE_SUCCEEDED event.
        }
        else
        {
            ret_code_t ret;
    
            memset(m_whitelist_peers, PM_PEER_ID_INVALID, sizeof(m_whitelist_peers));
            m_whitelist_peer_cnt = (sizeof(m_whitelist_peers) / sizeof(pm_peer_id_t));
    
            peer_list_get(m_whitelist_peers, &m_whitelist_peer_cnt);
    
            ret = pm_whitelist_set(m_whitelist_peers, m_whitelist_peer_cnt);
            APP_ERROR_CHECK(ret);
    
            // Setup the device identies list.
            // Some SoftDevices do not support this feature.
            ret = pm_device_identities_list_set(m_whitelist_peers, m_whitelist_peer_cnt);
            if (ret != NRF_ERROR_NOT_SUPPORTED)
            {
                APP_ERROR_CHECK(ret);
            }
    
            ret = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
            APP_ERROR_CHECK(ret);
        }
    }

    /**@brief Fetch the 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);
        }
    }

Reply
  • Hello Rakesh,

    peer_cnt is the total number of peers.

    Notice how examples using whitelist will get the stored list of peers first and then set the whitelist.

    Excerpt beneath from when hid keyboard example (peripheral/ble_app_hids) starts advertising

    /**@brief Function for starting advertising.
     */
    static void advertising_start(bool erase_bonds)
    {
        if (erase_bonds == true)
        {
            delete_bonds();
            // Advertising is started by PM_EVT_PEERS_DELETE_SUCCEEDED event.
        }
        else
        {
            ret_code_t ret;
    
            memset(m_whitelist_peers, PM_PEER_ID_INVALID, sizeof(m_whitelist_peers));
            m_whitelist_peer_cnt = (sizeof(m_whitelist_peers) / sizeof(pm_peer_id_t));
    
            peer_list_get(m_whitelist_peers, &m_whitelist_peer_cnt);
    
            ret = pm_whitelist_set(m_whitelist_peers, m_whitelist_peer_cnt);
            APP_ERROR_CHECK(ret);
    
            // Setup the device identies list.
            // Some SoftDevices do not support this feature.
            ret = pm_device_identities_list_set(m_whitelist_peers, m_whitelist_peer_cnt);
            if (ret != NRF_ERROR_NOT_SUPPORTED)
            {
                APP_ERROR_CHECK(ret);
            }
    
            ret = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
            APP_ERROR_CHECK(ret);
        }
    }

    /**@brief Fetch the 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);
        }
    }

Children
Related