Configuring Security Mode 1 Level 2 on peripheral_hids_keyboard

Hello,

I am trying to modify peripheral_hids_keyboard 's security configuration as Security Mode 1 Level 2.

According to some Q&A thread, I tried the following:

1. Modify conn_auth_callbacks as NULL:
static struct bt_conn_auth_cb conn_auth_callbacks = {
    .passkey_display = NULL,
    .passkey_confirm = NULL,
    .passkey_entry = NULL,
    .cancel = auth_cancel,
#if CONFIG_NFC_OOB_PAIRING
    .oob_data_request = auth_oob_data_request,
#endif
};Post

err = bt_conn_auth_cb_register(&conn_auth_callbacks);
2. Add the following in prj.conf:
CONFIG_BT_HIDS_DEFAULT_PERM_RW_ENCRYPT=y
I tried a few combination of conn_auth_callbacks but always get
"Security failed: id:id:id:id:id:id (public) level 1 err 4", which implies 
BT_SECURITY_ERR_AUTH_REQUIREMENT

I am using NCS v3.0.1.
Do you have any idea? Thank you!
Parents
  • Hi,

    I have not been able to reproduce on my end. I took the peripheral_hids_keyboard sample from NCS 3.0.1 and did this tiny modification (just removing the .passkey_display and .passkey_confirm function pointers):

    diff --git a/samples/bluetooth/peripheral_hids_keyboard/src/main.c b/samples/bluetooth/peripheral_hids_keyboard/src/main.c
    index aacd17f48f..ff476acdde 100644
    --- a/samples/bluetooth/peripheral_hids_keyboard/src/main.c
    +++ b/samples/bluetooth/peripheral_hids_keyboard/src/main.c
    @@ -619,8 +619,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,//auth_passkey_display,
    +       .passkey_confirm = NULL,//auth_passkey_confirm,
            .cancel = auth_cancel,
     #if CONFIG_NFC_OOB_PAIRING
            .oob_data_request = auth_oob_data_request,

    And with that I am able to pair with just works from my phone. See log:

    *** Booting nRF Connect SDK v3.0.1-9eb5615da66b ***
    *** Using Zephyr OS v4.0.99-77f865b8f8d0 ***
    Starting Bluetooth Peripheral HIDS keyboard sample
    I: 2 Sectors of 4096 bytes
    I: alloc wra: 0, fd0
    I: data wra: 0, 1c
    I: SoftDevice Controller build revision: 
    I: 89 9a 50 8a 95 01 9c 58 |..P....X
    I: fc 39 d2 c1 10 04 ee 02 |.9......
    I: 64 ce 25 be             |d.%.    
    I: HW Platform: Nordic Semiconductor (0x0002)
    I: HW Variant: nRF52x (0x0002)
    I: Firmware: Standard Bluetooth controller (0x00) Version 137.20634 Build 2617349514
    I: No ID address. App must call settings_load()
    Bluetooth initialized
    I: Identity: D6:63:7A:DC:0D:FB (random)
    I: HCI: version 6.0 (0x0e) revision 0x10f3, manufacturer 0x0059
    I: LMP: version 6.0 (0x0e) subver 0x10f3
    NFC configuration start
    NFC configuration done
    Advertising successfully started
    Advertising continued
    Connected 61:79:35:B0:55:BC (random)
    W: Ignoring data for unknown channel ID 0x003a
    Security changed: 61:79:35:B0:55:BC (random) level 2
    Pairing completed: 98:0D:AF:7E:9C:5A (public), bonded: 1
    I: BAS Notifications enabled
    Output report has been received 98:0D:AF:7E:9C:5A (public)

    Unless you have doen other changes, this should work on your end as well. One other potential pitfall is if there are existing bonding information in either the central (phone, PC or similer), or the nRF. Can you make sure you perform a full erase of the nRF and delete any old bonds on the central, and see if that helps? If not, can you share all your modifications (perhpas the whole project) and full log so that I can better understand the details?

  • Hi Einar,

    Thanks for your quick reply. Erasing the nRF board by using the "Erase and Flash to Board" button solves my problem.

    In this case, it seems to me that some bonding information was stored in the flash of nRF. However, by reading main.c of this example I cannot find relevant code. Could you confirm if this is something done in the BLE stack level?

    Thank you!

Reply Children
Related