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

Whitelist add from serial connection

Hello DevZone,

I want to transmit some connection information such as a Bluetooth address serially to my peripheral and have it add it to its whitelist.

I have read a couple of threads about whitelisting but I haven't found any on how to manually add a device to my whitelist.

Do I first have to call the function pm_whitelist_get, add my device I want to add to this list and use sd_ble_gap_whitelist_set to update it?

Im using a nrf52832 DK with sdk 17.0.2 and softdevice s132 

Kind regards

Parents
  • Do I first have to call the function pm_whitelist_get, add my device I want to add to this list and use sd_ble_gap_whitelist_set to update it?

    That sounds like a reasonable approach. Typically though whitelisting also include that you have established a bond with the peer device that include for instance encryption keys, but I assume you want to use whitelist simply to make sure you connect with a specific peer.

    I suggest to for instance take a look at the ble_app_hids_keyboard example, and search for whitelist in main.c. You should find some examples there on how to use whitelist, it should be fairly straight forward to manipulate the whitelist if you wanted to.

    Kenneth

  • Thank you for the confirmation.

    It works. Here is my solution for people with the same problem.

    void AddUserToWhitelist(ble_gap_addr_t * p_BLEaddr)
    {
        uint32_t u32ErrCode;
        ble_gap_addr_t whitelist_addrs[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
        ble_gap_irk_t  whitelist_irks[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
        uint32_t       addr_cnt = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;
        uint32_t       irk_cnt  = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;
    
        u32ErrCode = pm_whitelist_get(whitelist_addrs, &addr_cnt, whitelist_irks,  &irk_cnt);
        APP_ERROR_CHECK(u32ErrCode);
    
        bool bPresent = false;
        for(uint8_t i = 0; i < addr_cnt; i++)
        {
    	    // Loop through all addresses in the whitelist table.
    	    if(strcmp(whitelist_addrs[i].addr, p_BLEaddr->addr) == 0)
            {
        	    // Address is present in whitelist.
                bPresent = true;
            }
        }
        if(bPresent == false)
        {
    	    whitelist_addrs[addr_cnt] = *p_BLEaddr;
    	    addr_cnt++;
    
    	    ble_gap_addr_t const * p_addr[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
    
    	    for (uint32_t i = 0; i < BLE_GAP_WHITELIST_ADDR_MAX_COUNT; i++)
    	    {
    	        p_addr[i] = &whitelist_addrs[i];
    	    }
        
    	    u32ErrCode = sd_ble_gap_whitelist_set(p_addr, addr_cnt);
    	    APP_ERROR_CHECK(u32ErrCode);
        }
    }

  • Thank you!

    This code helped me solve an issue I was having Slight smile

Reply Children
No Data
Related