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

Issue in implementing whitelist

Hi, 

I am working on nrf52832 , SDK15 and softdevice S132. I am modifying the ble_app_hrs example code in SDK

I was trying to implement a whitelist with the address of my ANdroid phone so that peripheral will connect only to this phone .

I have hard coded the MAC address , but it is not connecting.  And If i disable whitelist it is connecting.

My doubt is , which address(of the phone) should we put?(I am attaching an image)

Image showing the addresses in my phone

Or is there any restriction to the adddress type of the address in the phone?(due to which the disconnect happens)

And in which order should the array to be filled?

I have done as follows(the address is shown in the image)

peer_addr.addr[0] = 0xbc;
peer_addr.addr[1] = 0x41;
peer_addr.addr[2] = 0x01;
peer_addr.addr[3] = 0x31;
peer_addr.addr[4] = 0x8f;
peer_addr.addr[5] = 0x48;

Is this the correct way to fill the array?

Thanking you.

Here  are my code snippets

1) In advertising_init() added the following

init.advdata.flags= BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;

init.config.ble_adv_whitelist_enabled = true;

2) Added the following in on_adv_evt()

ble_gap_addr_t peer_addr; //peer device address
ble_gap_addr_t const * p_peer_addr;
ble_gap_addr_t const * const * pp_peer_addr;

..............................

.............................

case BLE_ADV_EVT_WHITELIST_REQUEST:
memset(&peer_addr, 0x00, sizeof(peer_addr));


peer_addr.addr[0] = 0xbc;
peer_addr.addr[1] = 0x41;
peer_addr.addr[2] = 0x01;
peer_addr.addr[3] = 0x31;
peer_addr.addr[4] = 0x8f;
peer_addr.addr[5] = 0x48

//peer_addr pointers. Double pointers for the win! :S
p_peer_addr = &peer_addr;
pp_peer_addr = &p_peer_addr;

// Set white list
err_code = sd_ble_gap_whitelist_set(pp_peer_addr, 0x01);
if (err_code == NRF_SUCCESS)
NRF_LOG_INFO("Successfully set whitelist!\n");

// White list reply
err_code = ble_advertising_whitelist_reply(&m_advertising,p_peer_addr, 1, NULL, (uint32_t) NULL);
if (err_code == NRF_SUCCESS)
NRF_LOG_INFO( "Whitelist replied\n");

APP_ERROR_CHECK(err_code);

break;

Please let me know are the above changes sufficient to make the whitelist work?

Am I missing something?

Anything to do with filter policies?

with regards,

Geetha

Parents
  • Hi Geetha.

    First problem here is that you have used the Wi-FI MAC address. You need to use your Bluetooth address.
    Note also that most smart phones change Bluetooth address roughly every 15 minute.

    I made the following change to your code and ran it successfully:

    1) In advertising_init():

    static void advertising_init(void)
    {
        ret_code_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_GENERAL_DISC_MODE;  // Comment this line out if you havn't done it already
        init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        init.advdata.uuids_complete.p_uuids  = m_adv_uuids;
    
        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.advdata.flags                     = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; // These two lines are correct
        init.config.ble_adv_whitelist_enabled = true;									//
    
       
        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);
    }

    2) In on_adv_evt():

    	ble_gap_addr_t peer_addr; //peer device address
    	ble_gap_addr_t const * p_peer_addr;
    	// ble_gap_addr_t const * const * pp_peer_addr; --> This was not needed
    
    	----------------------------------------
    	........................................
    	----------------------------------------
    
    	case BLE_ADV_EVT_WHITELIST_REQUEST:
    	memset(&peer_addr, 0x00, sizeof(peer_addr));
    
    
    	//peer_addr.addr[0] = 0xbc;			| Reverse the order you placed these:
    	//peer_addr.addr[1] = 0x41;			|
    	//peer_addr.addr[2] = 0x01;			| Also note that you used wrong address,
    	//peer_addr.addr[3] = 0x31;			| as I said in my reply
    	//peer_addr.addr[4] = 0x8f;			| 
    	//peer_addr.addr[5] = 0x48; 		| Insert the address like this:
    
    	peer_addr.addr[5] = 0xbc;
        peer_addr.addr[4] = 0x41;
        peer_addr.addr[3] = 0x01;
        peer_addr.addr[2] = 0x31;
        peer_addr.addr[1] = 0x8f;
        peer_addr.addr[0] = 0x48;
    
        peer_addr.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC; // Add the address type
    
    	//peer_addr pointers. Double pointers for the win! :S
    	p_peer_addr = &peer_addr;
    	//pp_peer_addr = &p_peer_addr; --> Remove this line
    
    	// Set white list
    	err_code = sd_ble_gap_whitelist_set(&p_peer_addr, 0x01); //swap pp_peer_addr with &p_peer_addr, like this
    	if (err_code == NRF_SUCCESS)
    	{
    		NRF_LOG_INFO("Successfully set whitelist!\n");
    	}
    
    	APP_ERROR_CHECK(err_code); //Added an error check, always useful to have.
    
    	// White list reply
    	err_code = ble_advertising_whitelist_reply(&m_advertising,p_peer_addr, 1, NULL, (uint32_t) NULL);
    	if (err_code == NRF_SUCCESS)
    	{
    		NRF_LOG_INFO( "Whitelist replied\n");
    	}
    	APP_ERROR_CHECK(err_code);
    
    	break;
    

    As you can see in the code you had not set the address type for the peer_addr pointer.

    I ran this successfully with the use of nRF Connect, where you easy can see your Bluetooth Address, example in the picture below:

    The address I added to my whitelist was:

                peer_addr.addr[5] = 0xE3;
                peer_addr.addr[4] = 0x30;
                peer_addr.addr[3] = 0x15;
                peer_addr.addr[2] = 0x8D;
                peer_addr.addr[1] = 0xDA;
                peer_addr.addr[0] = 0x72;

    As you can se, this is the address i read below nRF5x (E3:30:15:8D:DA:72)

    Hope this helps.

    - Andreas

  • Hello Andreas,

    Thank you very much. I also could  check it.

    If I change the address the connection is not happening..

    Thank you very much once again.

    If the address (of the phone) is not of type "BLE_GAP_ADDR_TYPE_RANDOM_STATIC".Then how can I do this?

    Can you provide some code examples for the same.

    It will be a great help if you can help me in this.

    Thank you in advance and once again. I could not have done this without your help.

    with regards,

    Geetha

  • Hi Geetha.

    There are 5 different macros that the peer_addr.addr_type can be set as, you find if you look at the definition of BLE_GAP_ADDR_TYPE_RANDOM_STATIC in SES.

    They are located in ble_gap.h, and are the following:

    /**@defgroup BLE_GAP_ADDR_TYPES GAP Address types
     * @{ */
    #define BLE_GAP_ADDR_TYPE_PUBLIC                        0x00 /**< Public (identity) address.*/
    #define BLE_GAP_ADDR_TYPE_RANDOM_STATIC                 0x01 /**< Random static (identity) address. */
    #define BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE     0x02 /**< Random private resolvable address. */
    #define BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE 0x03 /**< Random private non-resolvable address. */
    #define BLE_GAP_ADDR_TYPE_ANONYMOUS                     0x7F /**< An advertiser may advertise without its address.
                                                                      This type of advertising is called anonymous. */
    /**@} */

    Note that your phone may have changed its address from the one in the picture you sent, as most phones change Bluetooth address roughly every 15 minutes.

    - Andreas

  • Hi

    Thank you.

    But today also my phone shows the same address 

    But still I could not connect to the phone.

    But I could connect successfully with nRFConnect on desktop.

    Is there anything I need to take care while connecting to phone?

    with regards,

    Geetha

  • Hi.

    If you don't have the right address in your code you cant connect. You should be able to connect with the address  bc:41:01:33:15:dc added to your whitelist.

    - Andreas

  • Hi Andreas,

    Thank you for your reply.

    I apologize for bothering( after a long time)  you thus.

    I have tried the following.

    I am having two RIGADO DK. I have installed nRFConnect Desktop App in my PC. So one device I connected to the PC to run the desktop App and another DK I used to flash the 'modified ble_app_hrs' code. I have hardcoded the address of the DK (used to run the Desktop App) in the HRM code . And this code is flashed to other DK.

    Now if I press scan button in nRF Connect desktop App, the 'Nordic HRM ' name will get displayed in the list and when I press 'connect '  button it will establish connection successfully.

    If I give a different address( hardcode with a different address) then the device is not getting displayed  in the liast of nRFConnect Desktop App. So this means the whhitelistin is working fine in this set up. Am I correct?

    But if I use nRFConnect App from mobile phone (instead of using nRFConnect Desktop App) the connection is not happening? Is it because the address type in the phone and in the DK are different?

    Thanking you in advance.

    with regards,

    Geetha

Reply
  • Hi Andreas,

    Thank you for your reply.

    I apologize for bothering( after a long time)  you thus.

    I have tried the following.

    I am having two RIGADO DK. I have installed nRFConnect Desktop App in my PC. So one device I connected to the PC to run the desktop App and another DK I used to flash the 'modified ble_app_hrs' code. I have hardcoded the address of the DK (used to run the Desktop App) in the HRM code . And this code is flashed to other DK.

    Now if I press scan button in nRF Connect desktop App, the 'Nordic HRM ' name will get displayed in the list and when I press 'connect '  button it will establish connection successfully.

    If I give a different address( hardcode with a different address) then the device is not getting displayed  in the liast of nRFConnect Desktop App. So this means the whhitelistin is working fine in this set up. Am I correct?

    But if I use nRFConnect App from mobile phone (instead of using nRFConnect Desktop App) the connection is not happening? Is it because the address type in the phone and in the DK are different?

    Thanking you in advance.

    with regards,

    Geetha

Children
No Data
Related