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

Whitelisting in Gatt Server mode (SDK 15.2 /nrf52840)

Im using sdk 15.2 with 2 nrf52840 boards, i would like the server to connect to a particular client. How to add the devices to whitelist in sdk 15.2 ?. I have gone through various blogs and  I have used the following snippet, but the server connects to any client available in the vicinity. Please do correct me if im wrong .

ble_gap_addr_t whitelist_addr = {1, BLE_GAP_ADDR_TYPE_PUBLIC,{0x27,0x23,0xBC,0x70,0xF2,0xDC}};
ble_gap_addr_t const *p_whitelist_addr[] = {&whitelist_addr};

ret_code_t err_code;
err_code = sd_ble_gap_whitelist_set(p_whitelist_addr, 1);
if (err_code==NRF_SUCCESS)
{
NRF_LOG_INFO("wHITELIST SET SUCCESSFULLY ");
}
APP_ERROR_CHECK(err_code);

thanks,

Preethi

Parents
  • I managed to make it work using respectively \nRF5_SDK_15.2.0\examples\ble_peripheral\ble_app_uart and nRF5_SDK_15.2.0\examples\ble_central\ble_app_uart_c. 

    • In ble_app_uart_c/main.c I figured out the address and address type by using sd_ble_gap_addr_get():

    ret_code_t err_code;
        ble_gap_addr_t mac_addr;
        err_code = sd_ble_gap_addr_get(&mac_addr); 
        APP_ERROR_CHECK(err_code);
    
        if(BLE_GAP_ADDR_TYPE_PUBLIC == mac_addr.addr_type){
            NRF_LOG_INFO("Address type is BLE_GAP_ADDR_TYPE_PUBLIC");
        }else if(BLE_GAP_ADDR_TYPE_RANDOM_STATIC == mac_addr.addr_type){
            NRF_LOG_INFO("Address type is BLE_GAP_ADDR_TYPE_RANDOM_STATIC");
        } else if(BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE == mac_addr.addr_type){
            NRF_LOG_INFO("Address type is BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE");
        } else if(BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE == mac_addr.addr_type){
            NRF_LOG_INFO("Address type is BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE");
        } else if(BLE_GAP_ADDR_TYPE_ANONYMOUS == mac_addr.addr_type){
            NRF_LOG_INFO("Address type is BLE_GAP_ADDR_TYPE_ANONYMOUS");
        }
        
        NRF_LOG_INFO("Address: [%X, %X, %X, %X, %X, %X]", mac_addr.addr[0], mac_addr.addr[1], mac_addr.addr[2], mac_addr.addr[3], mac_addr.addr[4], mac_addr.addr[5]);
    

    • I got the following log:

    Address type is BLE_GAP_ADDR_TYPE_RANDOM_STATIC
    <info> app: Address: [D3, EA, 17, FD, E8, FB]

    In ble_app_uart/main.c I made the following changes:

    • In main.c --> advertising_init() I added the following:

    init.config.ble_adv_whitelist_enabled = true;

    • In the top of main.c -->on_adv_evt() I added the following:

    ble_gap_addr_t whitelist_addr = {1, BLE_GAP_ADDR_TYPE_RANDOM_STATIC, {0xD3, 0xEA, 0x17, 0xFD, 0xE8, 0xFB}};
    ble_gap_addr_t const     *p_whitelist_addr[] = {&whitelist_addr};

    • In  main.c -->on_adv_evt() I added a new case:

            case BLE_ADV_EVT_WHITELIST_REQUEST:
                err_code = sd_ble_gap_whitelist_set(p_whitelist_addr, 1);
                APP_ERROR_CHECK(err_code);
                err_code = ble_advertising_whitelist_reply(&m_advertising, &whitelist_addr, 1, NULL, 0);
                APP_ERROR_CHECK(err_code);
                break;


    You can also use scan filtering, which filters on a higher level of abstraction than the SoftDevice, read more about the difference here.

    Best regards,

    Simon

  • Hi Simon ,

    Thanks for the detailed reply. I am trying on ble_peripheral where im whitelisting while using a scanner. It would be very nice of you if you can show how to whitelist in scanning in a peripheral/gatt server . I have done similar steps in the ble scanning evt handler.

    Thanks,

    Preethi.

  • I have not tested this, but I think I figured out how to do this with the scanner (all changes are done to ble_app_uart_c/main.c):

    • In scan_init(), after memset(&init_scan, 0, sizeof(init_scan)), set init_scan.scan_param->filter_policy=BLE_GAP_SCAN_FP_WHITELIST.
    • In ble_app_uart_c/main.c, under scan_evt_handler()-->case 
      NRF_BLE_SCAN_EVT_WHITELIST_REQUEST you should set the whitelist using 
      sd_ble_gap_whitelist_set()

    Could you report back to me if this works or not.

    Best regards,

    Simon

  • Hi Simon ,

    I tired compiling with your changes and it throw me an error reporting the filter_policy is just read only. I have attached the screen post along with this message.

    Thanks,

    Preethi,

  • I am sorry for the long delay, I've been quite busy lately. Have you made any progress on this?

  • Hi Simon,

    Sorry for the long delay. No have not made any progress. It is still the same like i have said before . i get that error when i make those changes.

    Thanks,

    Preethi

  • Try to add it in the following manner instead:

    static ble_gap_scan_params_t m_scan_param =                               /**< Scan parameters requested for scanning and connection. */
    {
        // Other params
        .filter_policy = BLE_GAP_SCAN_FP_WHITELIST,
        // Other params
    };
    
    .
    .
    .
    .
    
    /**@brief Function to start scanning. */
    static void scan_start(void)
    {
        ret_code_t ret;
    
        ret = nrf_ble_scan_params_set(&m_scan, &m_scan_param);
    
    .
    .
    static void scan_init(void)
    {
        .
        .
        .
        init_scan.p_scan_param     = &m_scan_param;

    Best regards,

    Simon

Reply
  • Try to add it in the following manner instead:

    static ble_gap_scan_params_t m_scan_param =                               /**< Scan parameters requested for scanning and connection. */
    {
        // Other params
        .filter_policy = BLE_GAP_SCAN_FP_WHITELIST,
        // Other params
    };
    
    .
    .
    .
    .
    
    /**@brief Function to start scanning. */
    static void scan_start(void)
    {
        ret_code_t ret;
    
        ret = nrf_ble_scan_params_set(&m_scan, &m_scan_param);
    
    .
    .
    static void scan_init(void)
    {
        .
        .
        .
        init_scan.p_scan_param     = &m_scan_param;

    Best regards,

    Simon

Children
No Data
Related