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

Whitelisting in S132 v3 for advertising filter policy

Hi,

I am using nRF5 SDK 12.1.0.

I have read the s132_nrf52_3.0.0_migration-document.pdf and I am trying to implement the whitelist without the private addresses i.e. just whitelisting public addresses

I would like to set a whitelist for advertising filter policy at the peripheral device. Please find my code as follows:

    case BLE_ADV_EVT_WHITELIST_REQUEST:
	{
    	//Public Address
    	ble_gap_addr_t public_device = {
    			.addr_type = BLE_GAP_ADDR_TYPE_PUBLIC,
				.addr = {0x38, 0x32, 0x52, 0xCB, 0x9F, 0x77}
    	};

    	ble_gap_addr_t const * whitelist = &public_device;

    	err_code = sd_ble_gap_whitelist_set(&whitelist, 1);

    	//Check error codes after setting whitelist
    	if (err_code == NRF_SUCCESS)
        	SEGGER_RTT_WriteString(0, "Successfully set whitelist! Yeah baby\n");
        if (err_code == NRF_ERROR_INVALID_ADDR)
        	SEGGER_RTT_WriteString(0, "NRF_ERROR_INVALID_ADDR\n");
        if (err_code == BLE_ERROR_GAP_WHITELIST_IN_USE)
        	SEGGER_RTT_WriteString(0, "BLE_ERROR_GAP_WHITELIST_IN_USE\n");
        if (err_code == BLE_ERROR_GAP_INVALID_BLE_ADDR)
        	SEGGER_RTT_WriteString(0, "BLE_ERROR_GAP_INVALID_BLE_ADDR\n");
        if (err_code == NRF_ERROR_DATA_SIZE)
        	SEGGER_RTT_WriteString(0, "NRF_ERROR_DATA_SIZE\n");

    	ble_gap_adv_params_t adv_params = {0};
    	adv_params.fp = BLE_GAP_ADV_FP_FILTER_BOTH;	//Filter scan and connection requests

    	err_code = sd_ble_gap_adv_start(&adv_params);

    	//Check error codes after starting advertising
        if (err_code == NRF_SUCCESS)
        	SEGGER_RTT_WriteString(0, "Start advertising this baby!\n");

        if (err_code == NRF_ERROR_INVALID_ADDR)
        	SEGGER_RTT_WriteString(0, "NRF_ERROR_INVALID_ADDR\n");

        if (err_code == NRF_ERROR_INVALID_STATE)
        	SEGGER_RTT_WriteString(0, "NRF_ERROR_INVALID_STATE\n");

        if (err_code == NRF_ERROR_INVALID_PARAM)
        	SEGGER_RTT_WriteString(0, "NRF_ERROR_INVALID_PARAM\n");

        if (err_code == BLE_ERROR_GAP_INVALID_BLE_ADDR)
        	SEGGER_RTT_WriteString(0, "BLE_ERROR_GAP_INVALID_BLE_ADDR\n");

        if (err_code == BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST)
        	SEGGER_RTT_WriteString(0, "BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST\n");

        APP_ERROR_CHECK(err_code);
	}
	break;

I am getting an error message that says NRF_ERROR_INVALID_PARAM (in RTT Viewer) when trying to start the advertisement using the function sd_ble_gap_adv_start(). I have configured adv_params.fp to filter connection requests and scan requests.

May I know how can I overcome this issue? Am I missing some adv_params that should be configured as well?

Thank you.

  • Oh my gosh it worked!! But I had to use the nRF Connect App in order to test the connection. If I used the HRS central example app, somehow it is not able to connect to the peripheral. I added the smartphone's MAC address to the whitelist and I was able to connect to the nrf52. After that, I removed the device's address from the whitelist and was not able to perform the connection afterwards.

  • I've managed to perform the whitelisting on the Heart Rate example. A big shoutout to Petter for his help and guidance! This would not have been possible without him. The link he posted was very important. I would like to share my code so that anyone that tries to perform whitelisting can refer to this. Beware that it is not 100% bug free and it is only for evaluation purposes.

    ble_app_advertiser_whitelist.zip

    Setup: You will need to setup GCC with Eclipse in order to compile the codes. I have not done this in Keil so not sure if it is able to.

    Steps:

    1. To test this, flash S132 v3.0.0 firmware to nRF52832.

    2. Then, change the bluetooth address to add your own device address to your whitelist in the on_adv_evt() function in the peer_addr.addr variable (under case BLE_ADV_EVT_WHITELIST_REQUEST)

    3. Compile the software

    4. Flash the .hex file into the nRF52832 using nRFgo Studio

    5. On your smartphone device, download the nRF Connect app from the Play Store

    6. Open the app and scan for devices, click on "Connect"

    7. You should be connected to the device.

    8. After that click on the Heart Rate Service and enable notifications to receive heart rate measurements

  • Thanks for sharing Joshua! I'm going to accept your answer and give you a vote :)

  • Thank you Petter! I could not have done it without you!

  • Hi, 

    I am working on nrf52832 , SDK15 and softdevice S132.

    I was referring to your code to imitata the same with hrs example in  SDK 15.

    I have hard coded the MAC address , but it is not connecting. 

    If i disable whitelist it is connecting.

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

    Image from my Android phone

    Or is there any restriction to the adddress type of the address in the phone?

    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.

    with regards,

    Geetha

Related