BLE Just Works on nrf52832 and NRF Connect

Hi, I am working on something that requires me to use Just Works on nrf52832 custom board. Here is the work sccenario. under normal conditions, my module has a bonding PIN and the user is supposed to enter the PIN on his application to get data. My NRF module is a peripheral and i have enabled following in the prj.conf.


CONFIG_BT_NUS_SECURITY_ENABLED

CONFIG_BT_FIXED_PASSKEY

I have registered the necessary callbacks too.

What I now need to implement is a functionality which allows user to bond without a PIN temporarily after a button press. I assume BLE Just Works is what I need for this purpose. But I am open to any other suggestions or new perspectives to get this done.Thanks in advance.

Parents
  • Hi Midhunjac, 

    To be able to change the capability of the device to not have passkey (no display and keyboard) what you need to do is to 

    bt_conn_auth_cb_register() with NULL input to remove the callback. Then you recall the bt_conn_auth_cb_register() without the display or confirm or entry callback. 

    However we need to look at how you define your characteristics as well. Because in the characteristic definitions you also define the minimum level of security to access the characteristics. If you set it to requires MITM, having Just work bonding would not be enough to allow accessing the characteristics. 
    If it's the case you may want to reinitalize the characteristic with new parameter. 
  • I tried your suggestion but it didnt work. When I tried out what you suggested, the bonding failed. These are the logs.

    <inf>: Connected 68:4A:E9:DC:F3:BC (public)
    <wrn>: Security failed: 68:4A:E9:DC:F3:BC (public) level 1 err 4
    <inf> migration1: Pairing failed conn: 68:4A:E9:DC:F3:BC (public), reason 4
    <inf>: Disconnected: 68:4A:E9:DC:F3:BC (public) (reason 19)
    <inf>:Disconnected 68:4A:E9:DC:F3:BC (public) :
    I am sure it must be a mistake on my side. Can you please take a look at this ? Isn't this how you suggested that I do ? Just to make sure that we are not misunderstanding each other, I am using NCSv2.1.0 and for testing purposes, I have switched to the basic peripheral UART example. So the characteristics of that particular service applies now. What I am testing is if I can bond with the peripheral without a passkey. I am not trying to access any particular characteristic. I just want to bond with the peripheral straight away.

    /*some code*/
    err = bt_conn_auth_cb_register(NULL);
    err = bt_conn_auth_cb_register(&conn_auth_callbacks);
    /* some code */
    
    static struct bt_conn_auth_cb conn_auth_callbacks = {
    		.cancel = auth_cancel,
    
    };

    Tried adding the bt_conn_auth_cb_register() with the passkey display and passkey entry and passkey confirm callbacks set to NULL. That didnt work out too.

Reply
  • I tried your suggestion but it didnt work. When I tried out what you suggested, the bonding failed. These are the logs.

    <inf>: Connected 68:4A:E9:DC:F3:BC (public)
    <wrn>: Security failed: 68:4A:E9:DC:F3:BC (public) level 1 err 4
    <inf> migration1: Pairing failed conn: 68:4A:E9:DC:F3:BC (public), reason 4
    <inf>: Disconnected: 68:4A:E9:DC:F3:BC (public) (reason 19)
    <inf>:Disconnected 68:4A:E9:DC:F3:BC (public) :
    I am sure it must be a mistake on my side. Can you please take a look at this ? Isn't this how you suggested that I do ? Just to make sure that we are not misunderstanding each other, I am using NCSv2.1.0 and for testing purposes, I have switched to the basic peripheral UART example. So the characteristics of that particular service applies now. What I am testing is if I can bond with the peripheral without a passkey. I am not trying to access any particular characteristic. I just want to bond with the peripheral straight away.

    /*some code*/
    err = bt_conn_auth_cb_register(NULL);
    err = bt_conn_auth_cb_register(&conn_auth_callbacks);
    /* some code */
    
    static struct bt_conn_auth_cb conn_auth_callbacks = {
    		.cancel = auth_cancel,
    
    };

    Tried adding the bt_conn_auth_cb_register() with the passkey display and passkey entry and passkey confirm callbacks set to NULL. That didnt work out too.

Children
  • Hi Midhunjac, 

    Pairing failed reason 4 means: 

        /** The requested security level could not be reached. */
        BT_SECURITY_ERR_AUTH_REQUIREMENT,

    Could you give some more information on how you tested ? 

    - Which central device did you use ? 

    - How did you do the test, have you tried to remove the previous bond  ? I suspect that it may have something to do with that. You may need to call bt_unpair() or can simply do a chip erase and then reflash for testing. 

    - Please try to capture a sniffer trace of the bonding process.  We would need to see exactly what exchanged between the peers. 

  • Hi,

    my central device is my phone running the nrf connect android application. In the scanner page of the application, instead of clicking on the 'Connect' button, I click on the kebab icon on the connect button and it shows me an option to bond. I use that to check the bonding.
    Additionally, i just tried with the nrf52 dongle and the NRF Connect for desktop to bond. But when i try to bond with the device, this is what I get on the desktop app.

    Before I test, I erase and reflash the chip.
    Is my method of testing wrong? If so, how should I test ?

    16:23:22.682
    Connecting to device
    16:23:22.742
    Connected to device CD:DB:D6:42:56:FE: interval: 7.5ms, timeout: 4000ms, latency: 0
    16:23:22.826
    Phy updated for device CD:DB:D6:42:56:FE, tx: 2 Mb/s, rx: 2 Mb/s
    16:23:23.028
    Attribute value read, handle: 0x0B, value (0x): 4E-6F-72-64-69-63-5F-55-41-52-54-5F-53-65-72-76-69-63-65
    16:23:27.794
    Connection parameters updated for device CD:DB:D6:42:56:FE: interval 30ms, timeout 420ms, latency: 0
    16:23:40.674
    Authentication failed with status BLE_GAP_SEC_STATUS_UNSPECIFIED
  • Hi Midhunjac, 

    Please try capturing a sniffer trace of the process. 

    I attached here a quick example that I modified from the peripheral_uart sample, SDK v2.1.2. 

    If you press button 3 it will erase all bond. If you press button 4 it will switch the pairing response from supporting MITM to not supporting MITM ( no display , no keyboard, just work). If you want to have display capability again you would need to modify the code to have another button to enable that or just reset the board. 

    peripheral_uart_changebond.zip

  • Hi, i am working on the sniffer API. But I just wanted to let you know that the source code you provided did not work as expected. I tried in the v2.1.0 SDK as well as the 2.1.2. It behaved the same in both cases. When I press button 4, in you code, the device connects and then suddenly disconnects on its own.

    Is there any explanation for this behavior ?

    Also, can you please confirm if the code that you provided worked in the SDKv2.1.2. Are there any changes in this general area in the SDK V2.1.1 and above ?

  • Hi Midhunjac, 
    I'm not sure if you need to do anything with the sniffer API. To run the sniffer you just need to copy it to wireshark folder and use Wireshark to capture. You don't need to work with the API directly. 
    Please make sure you erase bonding on the phone's side before testing. 

Related