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.

  • I'm not sure what is causing this error. What flags are you setting in the advertisments? BLE_GAP_ADV_FLAG_LE_LIMITED_DISC_MODE?

  • Thank you for your reply. I am using BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE as my advertising flag. I have managed to overcome my NRF_ERROR_INVALID_PARAM by setting the adv_params.interval and adv_params.timeout parameters. I am now getting a different error: BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST. Upon further investigation, this macro indicates that "Use of Whitelist not permitted with discoverable advertising". I have already set it to limited discoverable mode.

    I found out an important information in the core specification v4.2, Vol 3, Part C, Section 9.2.3 and 9.2.4 (Limited Discoverable Mode and General Discoverable Mode "The Host shall set the advertising filter policy to 'process scan and connection requests from all devices'. So I believe this is why the error persists. May I know what type of advertising flags should I be using? Thank you =)

  • What if you don't set either BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE or BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE?

  • I did what you had proposed but this time I encounter FATAL error which I believe is reported by APP_ERROR_CHECK(err_code)

    Thank you very much for your suggestion! I came across a function called pm_whitelist_set() and pm_whitelist_get(). What is the difference between using pm_whitelist_set() with sd_ble_gap_whitelist_set()? Thank you =)

  • I didn't notice that you were using the advertising module. If you want to use it, you should do like explained here. You can also look at the ble_app_hids_keyboard example on how it is implemented there.

    It gets a bit messy if you start calling sd_ble_gap_adv_start() directly in addition to using the advertising module. I would recommend either only use the advertising module, or implement all advertising functionality yourself. What do you want to do?

Related