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
  • Hello,

    Have you found any solution to this? I am trying to achieve something similar by using pairing_confirm callback and the bt_conn_auth_pairing_confirm function to wait for an input before confirming pairing.

    My setup is very similar. Based on the peripheral_uart sample I set bt_conn_auth_cb .passkey_display = NULL and .passkey_confirm = NULL, but keep .pairing_confirm active.

    Whatever I do this results in a timeout during pairing/bonding, even though bt_conn_auth_pairing_confirm is called either inside .pairing_confirm or asynchronously when a button is pressed.

    Best

    Jonas

Reply
  • Hello,

    Have you found any solution to this? I am trying to achieve something similar by using pairing_confirm callback and the bt_conn_auth_pairing_confirm function to wait for an input before confirming pairing.

    My setup is very similar. Based on the peripheral_uart sample I set bt_conn_auth_cb .passkey_display = NULL and .passkey_confirm = NULL, but keep .pairing_confirm active.

    Whatever I do this results in a timeout during pairing/bonding, even though bt_conn_auth_pairing_confirm is called either inside .pairing_confirm or asynchronously when a button is pressed.

    Best

    Jonas

Children
  • Hello Jonas,

    I'll take a look at this.

    Best regards,

    Simon

  • Hi Simon,

    Thank you for your time. I found a solution for this. Here is my diff compared to the peripheral_uart sample:

    diff --git a/applications/peripheral_uart/prj.conf b/applications/peripheral_uart/prj.conf
    index e5262de..881a897 100644
    --- a/applications/peripheral_uart/prj.conf
    +++ b/applications/peripheral_uart/prj.conf
    @@ -22,7 +22,7 @@ CONFIG_BT_PERIPHERAL=y
     CONFIG_BT_DEVICE_NAME="Nordic_UART_Service"
     CONFIG_BT_DEVICE_APPEARANCE=833
     CONFIG_BT_MAX_CONN=1
    -CONFIG_BT_MAX_PAIRED=1
    +CONFIG_BT_MAX_PAIRED=2
     
     # Enable the NUS service
     CONFIG_BT_NUS=y
    @@ -45,6 +45,6 @@ CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
     CONFIG_LOG=y
     CONFIG_USE_SEGGER_RTT=y
     CONFIG_LOG_BACKEND_RTT=y
    -CONFIG_LOG_BACKEND_UART=n
    +CONFIG_LOG_BACKEND_UART=y
     
     CONFIG_ASSERT=y
    diff --git a/applications/peripheral_uart/src/main.c b/applications/peripheral_uart/src/main.c
    index ee72be1..529b3a9 100644
    --- a/applications/peripheral_uart/src/main.c
    +++ b/applications/peripheral_uart/src/main.c
    @@ -421,9 +421,9 @@ static void pairing_confirm(struct bt_conn *conn)
     
     	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
     
    -	bt_conn_auth_pairing_confirm(conn);
    +	auth_conn = bt_conn_ref(conn);
     
    -	LOG_INF("Pairing confirmed: %s", log_strdup(addr));
    +	LOG_INF("Please confirm pairing: %s", log_strdup(addr));
     }
     
     
    @@ -450,8 +450,8 @@ 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,
    +	.passkey_confirm = NULL,
     	.cancel = auth_cancel,
     	.pairing_confirm = pairing_confirm,
     	.pairing_complete = pairing_complete,
    @@ -525,11 +525,11 @@ void error(void)
     static void num_comp_reply(bool accept)
     {
     	if (accept) {
    -		bt_conn_auth_passkey_confirm(auth_conn);
    -		LOG_INF("Numeric Match, conn %p", (void *)auth_conn);
    +		int ret = bt_conn_auth_pairing_confirm(auth_conn);
    +		LOG_INF("Pairing confirmed");
     	} else {
     		bt_conn_auth_cancel(auth_conn);
    -		LOG_INF("Numeric Reject, conn %p", (void *)auth_conn);
    +		LOG_INF("Pairing rejected");
     	}
     
     	bt_conn_unref(auth_conn);

  • There you go, thanks for sharing the solution!

Related