peripheral_hids_keyboard only works with some hosts

Hi there,

I'm running the peripheral_hids_keyboard sample of the nRF Connect SDK 2.5.1 on my nRF52840-DK. After pushing button 4, advertising starts as expected, but I can only connect with some of my phones/tablets.

I can connect with:
- OnePlus 9 Pro phone running Android 13
- Huawei P20 Pro running Android 10

I can't connect with:
- MacBook Air running macOS Ventura 13.6.3 - After pressing the Connect button, a progress indicator shortly appears and then disappears.
- Huawei MediaPad M5 lite 10 tablet running Android 8.0.0 - Upon trying to pair, I get the "Pairing failed. Incorrect pairing key or the device you want to pair with is configured incorrectly" message.
- NPad-Pro tablet running Android 12 - "Pairing..." momentarily appears, then disappears.

The sample doesn't show up in the Bluetooth devices list:
- ThinkPad T520 running Windows 20 Pro 22H2

Can you reproduce such discrepancies across various hosts, and can you make them connect?

Parents
  • Hi Mlac, 

    Do you have any modification to the sample ? Do you use any filter accept list  ? 

    Do you see any log on the NRF52 when you try to pair from those it can not connect ? 

    I would suggest to try capture a sniffer trace so that we can inspect further. 

  • Hi Hung,

    - As it turns out, the NPad-Pro tablet is a piece of crap that doesn't pair with any keyboard. :)
    - The ThinkPad T520 doesn't list other BLE keyboards either. I think it has a Bluetooth classic module that doesn't support BLE.
    - The Huawei MediaPad M5 lite 10 tablet actually works with the peripheral_hids_keyboard sample. I'm unsure why it didn't work the last time.

    This leaves us with the MacBook Air running macOS Ventura 13.6.3. When trying to connect, I can see the following in the console:

    Connected 10:B5:88:72:9A:E6 (public)
    W: Ignoring data for unknown channel ID 0x003a
    Disconnected from 10:B5:88:72:9A:E6 (public) (reason 19)

    Does the above ring a bell? (I've installed the sniffer, but filtering the device seems a bit tricky. I can try to capture a trace if still needed.)

    Thanks for everything!

  • Hi, 

    Disconnect reason 19 is GATT_CONN_TERMINATE_PEER_USER. Seems like the Macbook proactively disconnect . We will need to take a look a the sniffer trace. Any chance that it was paired with the keyboard before and tried to use old bond information?

    Have you tried with the default keyboard example ?

    mlac said:
    Ignoring data for unknown channel ID 0x003a

    This is just some proprietary thing Apple does and usually get ignored by the peer if it doesnt support this

  • If the sample was previously paired to the MacBook, I should see an icon that allows me to unpair it. But I can't see such an icon.

    Attached are the captured packets. I took the following steps to export them:

    1. I pressed button 4 on the dev board to start advertising
    2. At this point, on the Macbook, the Nordic_HIDS_keyboard shows up
    3. I start the capture
    4. On the Macbook, I tried to connect to the dev board, and it immediately disconnected (assuming it connected at all)
    5. I stopped the capture
    6. I entered the following Wireshark filter: btle.advertising_address == ea:28:02:bf:ad:1b
    7. I selected the filtered packets and used the "File -> Export Specified Packets -> Selected packets only" feature to export the file.

    hids-keyboard-mac.pcapng

  • Hi Mlac, 

    The trace unfortunately doesn't contain much useful information. The reason is that the nRF Sniffer can't capture all connections simultaneously like other professional sniffer. It can only follow one connection at a time. You would need to select the device prior to the connection. 
    There is a device dropdown list that you need to use to select the device. 
    Please follow our guide here: academy.nordicsemi.com/.../

  • Thanks for your further instructions, Hung!

    I've made another capture based on the instructions. Is it useful this time?

    mac.pcapng

  • Hi Mlac, 

    Thanks for the trace. I can see that the nRF52840 rejected the pairing with "Unspecific reason". 


    I'm checking internally to see why this happens. 
    I assume you were testing with unmodified peripheral_hids_keyboard sample ? ( with CONFIG_NFC_OOB_PAIRING=n ?)
    Could you send us the trace when it can connect and pair with other device not the MAC so we can compare ? 

    Could you try testing with the peripheral_hids_mouse and check if you have the same problem (and give us the trace)

Reply
  • Hi Mlac, 

    Thanks for the trace. I can see that the nRF52840 rejected the pairing with "Unspecific reason". 


    I'm checking internally to see why this happens. 
    I assume you were testing with unmodified peripheral_hids_keyboard sample ? ( with CONFIG_NFC_OOB_PAIRING=n ?)
    Could you send us the trace when it can connect and pair with other device not the MAC so we can compare ? 

    Could you try testing with the peripheral_hids_mouse and check if you have the same problem (and give us the trace)

Children
  • Hi again, 
    Please also add CONFIG_BT_SMP_LOG_LEVEL_DBG=y to the code and send us the log if it actually show any extra information on why it reject the pairing request. 

  • Hi Hung,

    I haven't had CONFIG_NFC_OOB_PAIRING enabled, and I've enabled CONFIG_BT_SMP_LOG_LEVEL_DBG for the following tests as requested:

    keyboard-mac.pcapng

    Advertisin successfully started
    Advertising continued
    D: conn 0x20001cb0 handle 0
    D: chan 0x2000205c cid 0x0006
    Connected 10:B5:88:72:9A:E6 (public)
    W: Ignoring data for unknown channel ID 0x003a
    D: Received SMP code 0x01 len 6
    D: req: io_capability 0x04, oob_flag 0x00, auth_req 0x2D, max_key_size 0x10, init_key_dist 0x0B, resp_key_dist 0x0B
    D: Unable to get keys for 10:B5:88:72:9A:E6 (public)
    D: chan 0x2000205c cid 0x0006
    Disconnected from 10:B5:88:72:9A:E6 (public) (reason 19)
    
    

    keyboard-phone.pcapng

    Advertising successfully started
    Advertising continued
    D: conn 0x20001cb0 handle 0
    D: chan 0x2000205c cid 0x0006
    D: 
    D: prnd 14912dac28b97ae452a0005dd6afb4e5
    Connected AC:D6:18:1B:3D:B5 (public)
    W: Unhandled ATT code 0x1d
    D: Received SMP code 0x01 len 6
    D: req: io_capability 0x04, oob_flag 0x00, auth_req 0x2D, max_key_size 0x10, init_key_dist 0x0F, resp_key_dist 0x0F
    D: rsp: io_capability 0x01, oob_flag 0x00, auth_req 0x0D, max_key_size 0x10, init_key_dist 0x02, resp_key_dist 0x00
    D: Received SMP code 0x0c len 64
    D: 
    D: 0x2000904c
    D: Received SMP code 0x04 len 16
    D: 
    Passkey for AC:D6:18:1B:3D:B5 (public): 180785
    Press Button 1 to confirm, Button 2 to reject.
    D: Received SMP code 0x0d len 16
    D: 
    D: 
    Numeric Match, conn 0x20001cb0
    D: chan 0x2000205c conn 0x20001cb0 handle 0 encrypt 0x01 hci status 0x00
    Security changed: AC:D6:18:1B:3D:B5 (public) level 4
    D: Received SMP code 0x08 len 16
    D: 
    D: Received SMP code 0x09 len 7
    D: identity AC:D6:18:1B:3D:B5 (public)
    D: got status 0x0
    Pairing completed: AC:D6:18:1B:3D:B5 (public), bonded: 1
    
    

    mouse-mac.pcapng

    D: conn 0x20001d08 handle 0
    D: chan 0x200020b4 cid 0x0006
    Connected 10:B5:88:72:9A:E6 (public)
    Direct advertising to EC:8C:9A:A8:4E:57 (public) started
    D: chan 0x200020b4 cid 0x0006
    Disconnected from 10:B5:88:72:9A:E6 (public) (reason 8)
    Directed advertising failed to start
    Direct advertising to EC:8C:9A:A8:4E:57 (public) timed out
    Direct advertising to AC:D6:18:1B:3D:B5 (public) started
    Direct advertising to AC:D6:18:1B:3D:B5 (public) timed out
    Regular advertising started
    D: conn 0x20001d08 handle 0
    D: chan 0x200020b4 cid 0x0006
    Connected 10:B5:88:72:9A:E6 (public)
    Direct advertising to EC:8C:9A:A8:4E:57 (public) started
    D: chan 0x200020b4 cid 0x0006
    Disconnected from 10:B5:88:72:9A:E6 (public) (reason 8)
    Directed advertising failed to start
    Direct advertising to EC:8C:9A:A8:4E:57 (public) timed out
    Direct advertising to AC:D6:18:1B:3D:B5 (public) started
    Direct advertising to AC:D6:18:1B:3D:B5 (public) timed out
    Regular advertising started
    D: conn 0x20001d08 handle 0
    D: chan 0x200020b4 cid 0x0006
    Connected 10:B5:88:72:9A:E6 (public)
    Direct advertising to EC:8C:9A:A8:4E:57 (public) started
    D: chan 0x200020b4 cid 0x0006
    Disconnected from 10:B5:88:72:9A:E6 (public) (reason 8)
    Directed advertising failed to start
    Direct advertising to EC:8C:9A:A8:4E:57 (public) timed out
    Direct advertising to AC:D6:18:1B:3D:B5 (public) started
    Direct advertising to AC:D6:18:1B:3D:B5 (public) timed out
    Regular advertising started
    D: conn 0x20001d08 handle 0
    D: chan 0x200020b4 cid 0x0006
    Connected 10:B5:88:72:9A:E6 (public)
    Direct advertising to EC:8C:9A:A8:4E:57 (public) started
    D: chan 0x200020b4 cid 0x0006
    Disconnected from 10:B5:88:72:9A:E6 (public) (reason 8)
    Directed advertising failed to start
    Direct advertising to EC:8C:9A:A8:4E:57 (public) timed out
    Direct advertising to AC:D6:18:1B:3D:B5 (public) started
    Direct advertising to AC:D6:18:1B:3D:B5 (public) timed out
    Regular advertising started
    D: conn 0x20001d08 handle 0
    D: chan 0x200020b4 cid 0x0006
    Connected 10:B5:88:72:9A:E6 (public)
    Direct advertising to EC:8C:9A:A8:4E:57 (public) started
    D: chan 0x200020b4 cid 0x0006
    Disconnected from 10:B5:88:72:9A:E6 (public) (reason 8)
    Directed advertising failed to start
    Direct advertising to EC:8C:9A:A8:4E:57 (public) timed out
    Direct advertising to AC:D6:18:1B:3D:B5 (public) started
    Direct advertising to AC:D6:18:1B:3D:B5 (public) timed out
    Regular advertising started
    
    

    mouse-phone.pcapng

    D: conn 0x20001d08 handle 0
    D: chan 0x200020b4 cid 0x0006
    Connected AC:D6:18:1B:3D:B5 (public)
    Direct advertising to E8C:9A:A8:4lic) started
    Direct advertising to EC:8C:9A:A8:4E:57 (public) timed out
    Regular advertising started
    D: Received SMP code 0x01 len 6
    D: req: io_capability 0x04, oob_flag 0x00, auth_req 0x2D, max_key_size 0x10, init_key_dist 0x0F, resp_key_dist 0x0F
    D: prnd c9ee4a30a30d95e5df0128728d51e951
    D: rsp: io_capability 0x01, oob_flag 0x00, auth_req 0x0D, max_key_size 0x10, init_key_dist 0x02, resp_key_dist 0x02
    D: Received SMP code 0x0c len 64
    D: 
    D: 0x20008b05
    D: Received SMP code 0x04 len 16
    D: 
    Passkey for AC:D6:18:1B:3D:B5 (public): 713638
    Press Button  to confirm, Button 2ct.
    Numeric Match, conn 0x20001d08
    D: Received SMP code 0x0d len 16
    D: 
    D: 
    D: chan 0x200020b4 conn 0x20001d08 handle 0 encrypt 0x01 hci status 0x00
    Security changed: AC:D6:18:1B:3D:B5 (public) level 4
    D: Received SMP code 0x08 len 16
    D: 
    D: Received SMP code 0x09 len 7
    D: identity AC:D6:18:1B:3D:B5 (public)
    D: got status 0x0
    Pairing completed: AC:D6:18:1B:3D:B5 (public), bonded: 1
    button_changed(): left
    button_changed(): left
    
    

    The phone connection attempts were successful, and the Mac connection attempts were unsuccessful.

  • Hi Mlac, 

    Regarding the trace between mouse and MAC, it doesn't seem they do pairing. Could you please test again and make sure the sniffer follows the mouse ? 
    The log say "Unable to get keys for", it either returned by bt_keys_get_addr()  or bt_keys_get_type(). In both case it's related to that an old key can not be retracted or it can not create a new slot for the key. 
    Have you made sure you erased the whole flash before testing ? I am under the impression that it reached the maximum number of device can be paired. 

    Another option is to enable CONFIG_BT_KEYS_OVERWRITE_OLDEST so that it will overwrite the old key. 

    If that doesn't help, could you add a breakpoint in the code where "Unable to get keys" is printed out in smp.c (there are 10 locations). We need to know which exact function causing the issue. 

  • Hi Hung,

    I remembered that in a similarly strange but different situation when I upgraded my application to MCUboot, and it kept crashing shortly after boot, I used the `nrfjprog --recover` command successfully, and I tried it again for this issue, and it solved the problem for the keyboard sample.

    How did `nrfjprog --recover` fix the issue? I'm starting to get dependent on this command without understanding what's happening in the background.

    As for the mouse, now it pairs, but when I press the buttons, the mouse pointer doesn't move on the Mac, so I'm attaching the updated log and capture:

    mouse-mac-2.pcapng

    D: conn 0x20001d08 handle 0
    D: chan 0x200020b4 cid 0x0006
    I: BAS Notifications enabled
    Connected 10:B5:88:72:9A:E6 (public)
    Regular advertising started
    W: Ignoring data for unknown channel ID 0x003a
    button_changed(): right
    button_changed(): left
    button_changed(): up
    button_changed(): down
    button_changed(): right
    button_changed(): right
    button_changed(): right
    button_changed(): left
    button_changed(): left
    button_changed(): left
    button_changed(): left
    button_changed(): up
    button_changed(): up
    button_changed(): up
    button_changed(): up
    button_changed(): up
    button_changed(): down
    button_changed(): down
    button_changed(): down
    button_changed(): down
    
    

  • Hi mlac, 

    When you do "nrfjprog --recover" the whole flash memory of the chip will be erased. If you simply erase and flash the new code without a full erase, the settings partition will retain, meaning all the bond in your test will still be in the flash. It could be the reason why you can't pair the MAC device because it exceed the maximum of pair information in the setting partition. 


    From what I can see in the sniffer trace, the mouse did send the notification to the MAC. So there must be an issue interpreting the data on MAC that doesn't result in the mouse movement. 

    One thing I noticed is that there were no pairing/bonding with the mouse. Could you check why ? It could be reason the MAC doesn't show mouse movement. 
     I assume the mouse works fine on other machine, correct ? 


    Could you try using the nRF Desktop application ? It can also emulate a desktop mouse on a DK. 
    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/applications/nrf_desktop/README.html#

Related