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

Deleting Bonds then Restart Advertising does not enable Advertising w/ LE General Discoverable Mode

Hello,

I have the following issue. I am developing an application very similar to the "ble app hids keyboard" example. SDK 15.0, S132 V6.0.0, nrf52832.

I would like to implement a function where the user can hold a button, and cause the device to do the following: disconnect (if connected), stop advertising, delete bonds, and start advertising again. When I do the following steps: turn on device (now advertising w/o whitelist), connect and bond with phone, turn off Bluetooth on phone to disconnect it (device then starts advertising w/ whitelist), press button to delete bonds  (device stops advertising, calls pm_peers_delete, then starts advertising when pm event received indicating success); the application clears all bonds and goes into fast advertising w/o whitelist mode, but when the packets are checked on nrf Connect, the flag for LE General Discoverable Mode is not set, meaning any other new device cannot see the advertising. checking the whitelist, as well as the advertising parameters when calling ble_advertising_start all verify that advertising should be w/o whitelist, and the advertising event handler reports that the device is fast advertising w/o whitelist, however it is not actually doing so according to the nrf Connect app. Interestingly, if advertising is restarted with ble_advertising_restart_without_whitelist, the advertising becomes general discoverable, but having to do this is unexpected.

I have put together an example that demonstrates the issue using the SDK 15.0 "ble app hids keyboard" example, modifying only main.c (attached). In here, I set a timer at startup that, after 30s, stops advertising, deletes bonds, then starts advertising again. If the user powers the dev kit running the application, pairs with a phone then disconnects it from the phone (ex. by turning off phone bluetooth) before 30s is over from power on, the device will advertise w/ whitelist until 30s is up, then it will delete bonds and advertise w/o whitelist, however on nrf Connect the LE General Discoverable Mode flag will not be set and the device cannot be seen on any other phone.

Any insight into this issue is appreciated, thank you,

J

main.c

Parents
  • Hello,

    When the advertising is first initialized in main it supplies the advertising data to the advertising module with the flag

    adv_flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

    Later, when we start advertising, we check if we are using the whitelist, and if we are, the flags are now replaced with 

    BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED

    But the only case they are set back to BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE is if we call ble_advertising_restart_without_whitelist(). 

    Ideally, we should set the flag back to BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE whenever the check for whitelist returns false.

    (before:)

        if (use_whitelist(p_advertising))
        {
            p_adv_params->filter_policy = BLE_GAP_ADV_FP_FILTER_CONNREQ;
    
            // Set correct flags.
            ret = flags_set(p_advertising, BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED);
            VERIFY_SUCCESS(ret);
    
            p_advertising->adv_evt = BLE_ADV_EVT_FAST_WHITELIST;
        }

    (after:)

        if (use_whitelist(p_advertising))
        {
            p_adv_params->filter_policy = BLE_GAP_ADV_FP_FILTER_CONNREQ;
    
            // Set correct flags.
            ret = flags_set(p_advertising, BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED);
            VERIFY_SUCCESS(ret);
    
            p_advertising->adv_evt = BLE_ADV_EVT_FAST_WHITELIST;
        }
        else
        {
            // Set correct flags.
            ret = flags_set(p_advertising, BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
            VERIFY_SUCCESS(ret);
        }

    But if you want to avoid making changes to the module, the best workaround that I tested on my desk would what you found yourself. Using the restart function to set the flag in the correct state.

    static void test_timeout(void * p_context)
    {
        ble_advertising_restart_without_whitelist(&m_advertising);
        (void) sd_ble_gap_adv_stop(m_advertising.adv_handle);
        NRF_LOG_INFO("timeout!");
        delete_bonds();
    }

    For most of our examples, the bonds are cleared by holding button 2 during reset/power cycle. So the flag would always revert back to BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE whenever the whitelist is deleted because advertising_init() would be called again. Historically, peer devices have tended to ignore the flag(s) of the advertising packet. Which could be another reason this has gone unnoticed for a long time.

    I will report this internally. Let me know if you have more problems with this and we will be happy to help out.

  • I see, thank you for the detailed response Havard.

Reply Children
No Data
Related