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

s332 advertising whitelist error

Hello Nordic:

I am trying to add advertising with whitelist function to my code which is base on

nrf52832 dk

softdevice s332 5.0.0

SDK 14.2

I use the example code HID MOUSE Application which implement whitelist as reference.

I make functions related to whitelist almost exactly the same as in HID MOUSE Application and copy the missing function like peer_list_get() to my code.

When the first device is bonded and added into whitelist, the function seems to work correctly.

However when the device  disconnected, the device did go to direct advertising but somehow return an error afterwards as below.

0> <info> ant_hrm: ANT HRM channel 0 init
0> <info> ant_hrm: ANT HRM channel 0 open
0> <info> app: Initialization finish entering main loop
0> <info> app: pm_whitelist_get returns 0 addr in whitelist and 0 irk whitelist
0> <info> app: Fast advertising.
0> <info> app: pm_whitelist_get returns 0 addr in whitelist and 0 irk whitelist
0> <info> app: Slow advertising.
0> <info> app: Connected.
0> <info> app: Link secured. Role: 1. conn_handle: 0, Procedure: 1
0> <info> app: New Bond, add the peer to the whitelist if possible
0> <info> app: m_whitelist_peer_cnt 1, MAX_PEERS_WLIST 8
0> <info> app: add 0 to whitelist
0> <info> app: Disconnected
0> <info> app: BLE_ADV_EVT_PEER_ADDR_REQUEST
0> <info> app: Directed advertising.
0> <info> app: pm_whitelist_get returns 1 addr in whitelist and 1 irk whitelist
0> <error> app: ERROR 7 [NRF_ERROR_INVALID_PARAM] at ..\..\..\..\..\..\components\ble\ble_advertising\ble_advertising.c:287

after reset, the error always come up

0> <info> ant_hrm: ANT HRM channel 0 init
0> <info> app: pm_whitelist_get returns 1 addr in whitelist and 1 irk whitelist
0> <error> app: ERROR 7 [NRF_ERROR_INVALID_PARAM] at ..\..\..\..\..\..\components\ble\ble_advertising\ble_advertising.c:287

This erorr was ERROR 12801 [Unknown error code] from ble_advertising_error_handler before i put APP_ERROR_CHECK to advertising.c.

As far as I know from other posts, 12801 stands for "BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST"

which is Use of Whitelist not permitted with discoverable.

It seems that the problem occur because the device is trying to advertise with whitelist.

I did set BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE in advertising_init() but the example code also do so which seems like it will switch automatically the flag to BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED before switching to advertising with whitelist from the code below, am i correct?

static ret_code_t set_adv_mode_fast(ble_advertising_t * const p_advertising,
                                    ble_gap_adv_params_t    * p_adv_params)
{
    ret_code_t ret;

    p_adv_params->interval = p_advertising->adv_modes_config.ble_adv_fast_interval;
    p_adv_params->timeout  = p_advertising->adv_modes_config.ble_adv_fast_timeout;

    if ((p_advertising->adv_modes_config.ble_adv_whitelist_enabled) &&
        (!p_advertising->whitelist_temporarily_disabled) &&
        (whitelist_has_entries(p_advertising)))
    {
        #if (NRF_SD_BLE_API_VERSION <= 2)
            p_adv_params->p_whitelist = &m_whitelist;
        #endif

        p_adv_params->fp = BLE_GAP_ADV_FP_FILTER_CONNREQ;
        p_advertising->advdata.flags  = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;

        ret = ble_advdata_set(&(p_advertising->advdata), NULL);
        if (ret != NRF_SUCCESS)
        {
						APP_ERROR_CHECK(ret);
            return ret;
        }

        p_advertising->adv_evt = BLE_ADV_EVT_FAST_WHITELIST;
    }
    else
    {
        p_advertising->adv_evt = BLE_ADV_EVT_FAST;
    }

    return NRF_SUCCESS;
}

I also try to switch the flag in advertising_init() directly to BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED however the advertising mode seems to go to IDLE directly which result in sleep mode enter.

Since I am new to Bluetooth and embedded system. This might be a stupid question. but Could you kindly let me know how to fix this problem?

Parents
  • Ok, I have some ideas and I think we should be able to crack this together Slight smile

    First of all I think you found a bug where the the return from ble_advdata_set, if not NRF_SUCCESS, is not checked. It gets returned to where it was called in ble_advertising_start. but then the ret is replaces by ret = sd_ble_gap_adv_start(...) which is then returned to main.

            case BLE_ADV_MODE_SLOW:
                ret = set_adv_mode_slow(p_advertising, &adv_params); // NOT CHEKCED!
                break;
        }
        if (p_advertising->adv_mode_current != BLE_ADV_MODE_IDLE)
        {
            ret = sd_ble_gap_adv_start(&adv_params, p_advertising->conn_cfg_tag); //REPLACED HERE!

     

    You say you get ERROR 7 [NRF_ERROR_INVALID_PARAM] at ..\..\..\..\..\..\components\ble\ble_advertising\ble_advertising.c:287.

    This could definetly lead to an error in the later sofdevice call in sd_ble_gap_adv_start where i think you got ERROR 12801 [Unknown error code] before you put APP_ERROR_CHECK to advertising.c.

    However, this error should have been returned to main as a normal return code as far as I could see. Instead you said you got it from the advertising error handler. So the error probably did not come from sd_ble_gap_adv_start directly Do you think you could use a debugger to look at the call stack for the error handler? (Or just put some breakpoints in the locations it can be called)

    It could be called from

    ble_advertising_restart_without_whitelist()

    on_disconnected()

    ble_advertising_on_sys_evt()

    Back to the NRF_ERROR_INVALID_PARAM, this could be returned from several places in ble_advdata.c

    manuf_specific_data_encode()

    service_data_encode()

    advdata_check()

    srdata_check()

    name_encode()

    conn_int_check()

    Please have a look with the call stack (or some breakpoints) and let me know the origin of the error code inside ble_advdata.c Slight smile

    Last but not least, it looks like you said you call advertising_start in main with parameter false, wich means you never delete the old bonds but always use them. However it looks like you commented out the code that actually restores the whitelist from flash and loads it into the SoftDevice.

    /**@brief Function for starting advertising.
     */
    void advertising_start(bool erase_bonds)
    {
        if (erase_bonds == true)
        {
            delete_bonds();
            // Advertising is started by PM_EVT_PEERS_DELETE_SUCCEEDED event.
        }
        else
        {
            ret_code_t ret;
    
    //        memset(m_whitelist_peers, PM_PEER_ID_INVALID, sizeof(m_whitelist_peers));
    //        m_whitelist_peer_cnt = (sizeof(m_whitelist_peers) / sizeof(pm_peer_id_t));
    
    //        peer_list_get(m_whitelist_peers, &m_whitelist_peer_cnt);
    
    //        ret = pm_whitelist_set(m_whitelist_peers, m_whitelist_peer_cnt);
    //        APP_ERROR_CHECK(ret);
    
    //        // Setup the device identies list.
    //        // Some SoftDevices do not support this feature.
    //        ret = pm_device_identities_list_set(m_whitelist_peers, m_whitelist_peer_cnt);
    //        if (ret != NRF_ERROR_NOT_SUPPORTED)
    //        {
    //            APP_ERROR_CHECK(ret);
    //        }
    
            ret = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
            APP_ERROR_CHECK(ret);
        }
    }

Reply
  • Ok, I have some ideas and I think we should be able to crack this together Slight smile

    First of all I think you found a bug where the the return from ble_advdata_set, if not NRF_SUCCESS, is not checked. It gets returned to where it was called in ble_advertising_start. but then the ret is replaces by ret = sd_ble_gap_adv_start(...) which is then returned to main.

            case BLE_ADV_MODE_SLOW:
                ret = set_adv_mode_slow(p_advertising, &adv_params); // NOT CHEKCED!
                break;
        }
        if (p_advertising->adv_mode_current != BLE_ADV_MODE_IDLE)
        {
            ret = sd_ble_gap_adv_start(&adv_params, p_advertising->conn_cfg_tag); //REPLACED HERE!

     

    You say you get ERROR 7 [NRF_ERROR_INVALID_PARAM] at ..\..\..\..\..\..\components\ble\ble_advertising\ble_advertising.c:287.

    This could definetly lead to an error in the later sofdevice call in sd_ble_gap_adv_start where i think you got ERROR 12801 [Unknown error code] before you put APP_ERROR_CHECK to advertising.c.

    However, this error should have been returned to main as a normal return code as far as I could see. Instead you said you got it from the advertising error handler. So the error probably did not come from sd_ble_gap_adv_start directly Do you think you could use a debugger to look at the call stack for the error handler? (Or just put some breakpoints in the locations it can be called)

    It could be called from

    ble_advertising_restart_without_whitelist()

    on_disconnected()

    ble_advertising_on_sys_evt()

    Back to the NRF_ERROR_INVALID_PARAM, this could be returned from several places in ble_advdata.c

    manuf_specific_data_encode()

    service_data_encode()

    advdata_check()

    srdata_check()

    name_encode()

    conn_int_check()

    Please have a look with the call stack (or some breakpoints) and let me know the origin of the error code inside ble_advdata.c Slight smile

    Last but not least, it looks like you said you call advertising_start in main with parameter false, wich means you never delete the old bonds but always use them. However it looks like you commented out the code that actually restores the whitelist from flash and loads it into the SoftDevice.

    /**@brief Function for starting advertising.
     */
    void advertising_start(bool erase_bonds)
    {
        if (erase_bonds == true)
        {
            delete_bonds();
            // Advertising is started by PM_EVT_PEERS_DELETE_SUCCEEDED event.
        }
        else
        {
            ret_code_t ret;
    
    //        memset(m_whitelist_peers, PM_PEER_ID_INVALID, sizeof(m_whitelist_peers));
    //        m_whitelist_peer_cnt = (sizeof(m_whitelist_peers) / sizeof(pm_peer_id_t));
    
    //        peer_list_get(m_whitelist_peers, &m_whitelist_peer_cnt);
    
    //        ret = pm_whitelist_set(m_whitelist_peers, m_whitelist_peer_cnt);
    //        APP_ERROR_CHECK(ret);
    
    //        // Setup the device identies list.
    //        // Some SoftDevices do not support this feature.
    //        ret = pm_device_identities_list_set(m_whitelist_peers, m_whitelist_peer_cnt);
    //        if (ret != NRF_ERROR_NOT_SUPPORTED)
    //        {
    //            APP_ERROR_CHECK(ret);
    //        }
    
            ret = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
            APP_ERROR_CHECK(ret);
        }
    }

Children
No Data
Related