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

Set and Activate Whitelist in SDK15 with Android Phone

Dear Sir,

I wanted to make the peripheral connect to a predefined central device. Here I am using an android phone ( with nRFConnect installed in it) as the central device.

I was using ble_app_hrs code as reference and modified as follows to implement the whitelist operation.

I want the peripheral to be visible/connect  to only those device whose address is mentioned in the whitelist.

I have made the following changes in the 'ble_app_hrs' code.

Inside function "advertising_init()" the following line is added

 init.config.ble_adv_whitelist_enabled = true;

And the line

init.advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
 

is changed as follows

 init.advdata.flags                   = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;//BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

Then insdie function "on_adv_evt(ble_adv_evt_t ble_adv_evt)" the following lines are added on top

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

And inside the same function in 'switch (ble_adv_evt)'  added the following case also

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

    peer_addr.addr[5] = 0xdc;//EC;
    peer_addr.addr[4] = 0x15;//9F;
    peer_addr.addr[3] = 0x33;//A1;
    peer_addr.addr[2] = 0x01;//E5;
    peer_addr.addr[1] = 0x41;//5B;
    peer_addr.addr[0] = 0xbc;//B3;

    peer_addr.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC; // Add the address type
	p_peer_addr = &peer_addr;
	// 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;

Now I flashed the program to a peripheral device.

I have tried to connect to the peripheral in two ways

1) Using nRFConnect Desktop App with the help of another BLE DK from Rigado- In this case I could see the peripheral name in the App and I could establish the connection successfully.

2)Using ANdroid phone( with nRFConnect App installed in it) - In this case I had to give the address in reverse order and I could see the peripheral device while scanning .But here when I try to connect to the peripheral it fails with the following message( shown in the App in phone)

The following  image shows the address in my mobile phone

Is there anything to do with the address type.?

Or anything else I  am missing ?

Please shre your comments .

with regards,

Geetha

  • Likely the phone is using private random address, and thereby will cycle the address at given intervals (this is due to security and privacy reasons to ensure no one can follow you around). So yes, likely the address type is why adding the gap address to the white list will not work here, instead you need to use irk for the whitelist, however that is only possible after bonding, in which case you can look at the ble hids examples which support whitelist with gap address and irk.

  • Hi,

    The bonding can happen only after establishing a valid connection, right?

    If I want to use whitelist advertising, it mandatory to use the pm module?

  • GK said:
    The bonding can happen only after establishing a valid connection, right?

     Yes

     

    GK said:
    If I want to use whitelist advertising, it mandatory to use the pm module?

     Not mandatory, however highly recommended I would say to reduce development time in general.

  • Hi Kenneth,

    Thank you very much.

    If the address is random static we can hard code the address in the code and use the whitelist before establishing the connection. And we can establish the connection only to the pre defined address.

    If the address is random resolvable (as in Android phones), then we need to use IRK and which requires bonding and hence a valid connection.

    But I want to use whitelist to establish connection to the selected devices/phones only.  Is there a way to do this without bonding(and hence established connection)?. My requirement is as follows.So I need to do the selection of the device ( using whitelist) at first hand(similar to the case of random static addresses ) without establishing connection.

    Please shed some light on this.

    Thanking you in advance.

    with regards,

    Geetha

  • I do not see any way of doing this with Android phones using whitelist without bonding no.

    I guess you may try to use RSSI to detect that a phone that are very close in proximity, and only add those to the whitelist, can that help?

Related