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

Use LESC in just works for the ble_thread_dyn_mtd_coap_cli_nfc exemple

Hello

I would like to modify the example "ble_thread_dyn_mtd_coap_cli_nfc" to use Just Works pairing instead of OOB with NFC.

To do this, I modified this in sdk_config.h:
#define NFC_BLE_PAIR_LIB_ENABLED 0
#define NFC_PAIRING_MODE 2

I added this in main.c:

/**@brief Function for handling Peer Manager events.
 *
 * @param[in] p_evt  Peer Manager event.
 */
static void pm_evt_handler(pm_evt_t const * p_evt)
{
    pm_handler_on_pm_evt(p_evt);
    pm_handler_flash_clean(p_evt);
}

/**@brief Function for the Peer Manager initialization.
 *
 * @param[in] erase_bonds  This flag informs if existing bonds should be erased.
 */
void peer_manager_init(bool erase_bonds)
{
    ble_gap_sec_params_t sec_param;
    ret_code_t err_code;

    err_code = pm_init();
    APP_ERROR_CHECK(err_code);

    if (erase_bonds)
    {
        err_code = pm_peers_delete();
        APP_ERROR_CHECK(err_code);
    }
    memset(&sec_param, 0, sizeof(ble_gap_sec_params_t));
    // Security parameters to be used for all security procedures.
    sec_param.bond = false;//true;
    sec_param.mitm = false;
    sec_param.lesc = 1;
    sec_param.keypress = 0;
    sec_param.io_caps = BLE_GAP_IO_CAPS_NONE;
    sec_param.oob = false;
    sec_param.min_key_size = 7;
    sec_param.max_key_size = 16;
    sec_param.kdist_own.enc = 0;//1;
    sec_param.kdist_own.id = 0;//1;
    sec_param.kdist_peer.enc = 0;//1;
    sec_param.kdist_peer.id = 0;//1;

    err_code = pm_sec_params_set(&sec_param);
    APP_ERROR_CHECK(err_code);

    err_code = pm_register(pm_evt_handler);
    APP_ERROR_CHECK(err_code);
}

And I added this in the while(true) of the main():

err_code = nrf_ble_lesc_request_handler();
APP_ERROR_CHECK(err_code);

I think I forgot something because I can connect but there is no pairing. Do you know why ?
I notice that sometimes it is indicated in the code that pairing is not supported: is this related to my problem?



Thank you

  • Now it works: I had to comment out "case BLE_GAP_EVT_SEC_PARAMS_REQUEST:" in ble_evt_handler ().

    But I still have a small problem: when I connect with nRF Connect, it asks me twice if I want to pair myself? (I am using a Samsung S10)
    Here are the logs.

    4760.Test.pcapng

  • In fact, I only have this problem on my Samsung S10 (Android) and not on my Iphone (IOS).

    This problem is also in the Nordic examples when connecting with an Android.

    When I want to connect to a device and I accept the piring when I receive a message to ask me, I see that I am then sending these messages:


    Then I am asked a second time if I want to pair myself. If I accept, it then sends these messages:


    Do you also have this problem with your Android phones on your Nordic examples?
    Do you have any idea why or if it would be possible to correct this problem?

    Thank you

  • Hi Quentin,

    QuentinD said:
    This problem is also in the Nordic examples when connecting with an Android.

     Which Nordic example do you refer to?

    -Amanda H. 

  • Hi Amanda,

    For example, if I modify the "ble_app_multirole_lesc" example to have a connection that uses LESC in "just works" without bonding (sec_param.bond = false) as presented above, I receive 2 pairing messages on my Samsung S10 to ask me if I want to pair myself. But I find that I don't have this problem if I run the test on my S7.

    Android Version on my S7: 8.0.0
    Android Version on my S10: 11

  • Also, I find that if I press "cancel" when it asks me to pair myself for the second time, that I get the error "BLE_GAP_SEC_STATUS_NUM_COMP_FAILURE" in the nrf52840. Why am I getting this error even though I have enabled these options? 

    memset(&sec_param, 0, sizeof(ble_gap_sec_params_t));
        // Security parameters to be used for all security procedures.
        sec_param.bond = false;//true;
        sec_param.mitm = false;
        sec_param.lesc = 1;
        sec_param.keypress = 0;
        sec_param.io_caps = BLE_GAP_IO_CAPS_NONE;
        sec_param.oob = false;
        sec_param.min_key_size = 7;
        sec_param.max_key_size = 16;
        sec_param.kdist_own.enc = 0;//1;
        sec_param.kdist_own.id = 0;//1;
        sec_param.kdist_peer.enc = 0;//1;
        sec_param.kdist_peer.id = 0;//1;


    Here is the Wireshark log if I hit "cancel" on the second message:

    6406.Test.pcapng

    Thank you

Related