This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Allow LESC "Just Works" Pairing/Bonding with NRF Connect SDK (Zephyr) after pressing Button

Hi

Is there an example for BLE "Just Works" using the NRF Connect SDK for the peripheral device?

I am using a peripheral device without display and would like to allow pairing / bonding for a short period of time after pressing a button.

Having registered callbacks using bt_conn_auth_cb and setting .passkey_display = NULL and .passkey_confirm = NULL does result in being able to pair and bond, yet I would like to only allow bonding in case a button has been pressed before.

Registering pairing_confirm and calling bt_conn_auth_cancel (in case pairing is not allowd) has not yielded the desired outcome so far and I am wondering if this is at all possible (the above pattern used to work with the nRF5 SDK).

Any advise would be appreciated!

Best
Manuel

Parents
  • Try setting .pairing_confirm = NULL as well.

    I got LESC Just Works to work by modifying the peripheral_uart sample in NCS in the following manner:

    diff --git a/samples/bluetooth/peripheral_uart/prj.conf b/samples/bluetooth/peripheral_uart/prj.conf
    index cd6df0664..57b883765 100644
    --- a/samples/bluetooth/peripheral_uart/prj.conf
    +++ b/samples/bluetooth/peripheral_uart/prj.conf
    @@ -48,3 +48,6 @@ CONFIG_LOG_BACKEND_RTT=y
     CONFIG_LOG_BACKEND_UART=n
     
     CONFIG_ASSERT=y
    +CONFIG_BT_SMP_SC_PAIR_ONLY=y
    +CONFIG_BT_MAX_PAIRED=3
    \ No newline at end of file
    diff --git a/samples/bluetooth/peripheral_uart/src/main.c b/samples/bluetooth/peripheral_uart/src/main.c
    index cf51a899f..224fee01c 100644
    --- a/samples/bluetooth/peripheral_uart/src/main.c
    +++ b/samples/bluetooth/peripheral_uart/src/main.c
    @@ -364,10 +364,10 @@ static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
     
     
     static struct bt_conn_auth_cb conn_auth_callbacks = {
    -       .passkey_display = auth_passkey_display,
    -       .passkey_confirm = auth_passkey_confirm,
    +       .passkey_display = NULL,//auth_passkey_display,
    +       .passkey_confirm = NULL, //auth_passkey_confirm,
            .cancel = auth_cancel,
    -       .pairing_confirm = pairing_confirm,
    +       .pairing_confirm = NULL,//pairing_confirm,
            .pairing_complete = pairing_complete,
            .pairing_failed = pairing_failed
     };

    Best regards,

    Simon

Reply
  • Try setting .pairing_confirm = NULL as well.

    I got LESC Just Works to work by modifying the peripheral_uart sample in NCS in the following manner:

    diff --git a/samples/bluetooth/peripheral_uart/prj.conf b/samples/bluetooth/peripheral_uart/prj.conf
    index cd6df0664..57b883765 100644
    --- a/samples/bluetooth/peripheral_uart/prj.conf
    +++ b/samples/bluetooth/peripheral_uart/prj.conf
    @@ -48,3 +48,6 @@ CONFIG_LOG_BACKEND_RTT=y
     CONFIG_LOG_BACKEND_UART=n
     
     CONFIG_ASSERT=y
    +CONFIG_BT_SMP_SC_PAIR_ONLY=y
    +CONFIG_BT_MAX_PAIRED=3
    \ No newline at end of file
    diff --git a/samples/bluetooth/peripheral_uart/src/main.c b/samples/bluetooth/peripheral_uart/src/main.c
    index cf51a899f..224fee01c 100644
    --- a/samples/bluetooth/peripheral_uart/src/main.c
    +++ b/samples/bluetooth/peripheral_uart/src/main.c
    @@ -364,10 +364,10 @@ static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
     
     
     static struct bt_conn_auth_cb conn_auth_callbacks = {
    -       .passkey_display = auth_passkey_display,
    -       .passkey_confirm = auth_passkey_confirm,
    +       .passkey_display = NULL,//auth_passkey_display,
    +       .passkey_confirm = NULL, //auth_passkey_confirm,
            .cancel = auth_cancel,
    -       .pairing_confirm = pairing_confirm,
    +       .pairing_confirm = NULL,//pairing_confirm,
            .pairing_complete = pairing_complete,
            .pairing_failed = pairing_failed
     };

    Best regards,

    Simon

Children
  • Hi Simon

    Thank you for taking a look at this. I can confirm, that I am now able to pair and bond without needing to enter a passcode.

    For the application I would like to only allow pairing/bonding for a period of time after a button has been pressed on the NRF device.

    Is there a method I can call to globally allow or disallow pairing/bonding? Alternatively is there a callback where I can decide whether or not to allow to pair/bond?

    Best
    Manuel

  • I'm not sure what's the proper way to disable pairing/bonding in runtime, but can you try the following:

    • Create the function pairing confirm:

    static void pairing_confirm(struct bt_conn *conn)
    {
    	bt_conn_auth_cancel(conn);
    }

    • Set .pairing_confirm, .passkey_display and .passkey_confirm to NULL, such that LESC just works is used in the start
    • Implement a delayable work item and submit it to the work queue, which will make it possible to run a custom function after x time
    • Inside the handler associated with the delayed work item, do the following
      • Modify conn_auth_callbacks and set .pairing_confirm = pairing_confirm
      • Run bt_conn_auth_cb_register(&conn_auth_callbacks)
    • If someone tries to pair now, bt_conn_auth_cancel(conn) will get called, which will cancel the pairing request received from the central

    Let me know if this works or not

    Best regards,

    Simon

     

Related