Bluetooth pairing fails when running sample peripheral_cts_client

I am trying to run the sample using NCS v2.5.0. This is what happens on the console when I try to connect from the dongle, when running the Test Procedure:

The discovery procedure succeeded
Security failed: E3:FE:4E:E0:6D:C5 (random) level 1 err 4
Pairing failed conn: E3:FE:4E:E0:6D:C5 (random), reason 4
Disconnected from E3:FE:4E:E0:6D:C5 (random) (reason 0x16)

Please advise. I don't have much BLE experience. Thank you.

Burt Silverman

  • Susheel, I wish to keep this simple, and follow the test procedure, and use the nRF52840 dongle. I assume in that case it gets time information from the computer it is plugged into, and there is no need to use security? Anyway, I have set CONFIG_BT_SMP=n and removed related code from src/main.c to make it compile, but I end up with

    Advertising successfully started
    Connected E3:FE:4E:E0:6D:C5 (random)
    The discovery procedure succeeded
    button_changed() entered...
    Cannot read Current Time: E3:FE:4E:E0:6D:C5 (random), error: -22
    button_changed() entered...
    button_changed() entered...
    Cannot read Current Time: E3:FE:4E:E0:6D:C5 (random), error: -22
    button_changed() entered...
    button_changed() entered...
    Cannot read Current Time: E3:FE:4E:E0:6D:C5 (random), error: -22
    button_changed() entered...

    Hopefully we can ignore for now that I need to do something about both edges of the button press being noticed. Why won't this just work? Thanks, Susheel.

    Burt S.

  • Also note that I was confused about the flash: we have a SPI flash on our board like the nRF9160DK board does, but CONFIG_SETTINGS and CONFIG_BT_SETTINGS uses the internal nRF52832 flash, right? So, it doesn't matter where the board's SPI flash is!

    Burt

  • I think it is return error if the peer (server) does not allow read on the descriptor that is set to be only read with encrypted connections. 

    If you want to know even deeper reason, just set a breakpoint in bt_cts_read_current_time function in cts_client.c file and step into bt_gatt_read function. You will know exactly why you are getting that error.

  • I will give up with CONFIG_BT_SMP=n and stick with the original. But I am about to give up entirely. It would be helpful to me if you could go through the test procedure yourself and then tell me step by step where it is possible for something to go wrong--anything that may be missing from the instructions (assumptions made by an experienced person). The other question I can ask--what if rather than use the dongle and Bluetooth Low Energy application from nRF Connect for Desktop, I wish to use one of your phone apps. I would need a step-by-step procedure. For example, with BLE app we copy the file cts_central.ncs by using capabilities built into the BLE app, but what's the corresponding method if we wish to use the appropriate Nordic iPhone app? Thanks, Susheel.

    Burt

  • I am setting CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE so at least I can get a bonded encrypted unauthenticated link. I added some printk statements to the standard LOG_DBG. Why can't I read the Current Time? Why am I getting Invalid Argument -22 return at the bottom:

    [00:14:05.686,340] <dbg> bt_smp: smp_pairing_req: req: io_capability 0x03, oob_flag 0x00, auth_req 0x09, max_key_size 0x10, init_key_dist 0x01, resp_key_dist 0x01
    smp_pairing_req() called get_pair_method(); method=0 (0==JUST_WORKS)
    [00:14:05.686,431] <dbg> bt_smp: smp_pairing_req: rsp: io_capability 0x03, oob_flag 0x00, auth_req 0x09, max_key_size 0x10, init_key_dist 0x00, resp_key_dist 0x00
    [00:14:05.731,567] <dbg> bt_smp: bt_smp_recv: Received SMP code 0x0c len 64
    [00:14:05.731,597] <dbg> bt_smp: smp_public_key: 
    [00:14:05.746,459] <dbg> bt_smp: bt_smp_recv: Received SMP code 0x04 len 16
    [00:14:05.746,459] <dbg> bt_smp: smp_pairing_random: 
    [00:14:05.758,850] <dbg> bt_smp: bt_smp_dhkey_ready: 0x20004c4c
    [00:14:05.761,444] <dbg> bt_smp: bt_smp_recv: Received SMP code 0x0d len 16
    [00:14:05.761,474] <dbg> bt_smp: smp_dhkey_check: 
    [00:14:05.763,519] <dbg> bt_smp: sc_smp_send_dhkey_check: 
    bt_conn_security_changed() entered hci_err=0(31==BT_HCI_ERR_UNSPECIFIED) err=0
    [00:14:05.831,085] <dbg> bt_smp: bt_smp_encrypt_change: chan 0x20001fdc conn 0x20001d08 handle 11 encrypt 0x01 hci status 0x00 
    [00:14:05.831,115] <dbg> bt_smp: smp_pairing_complete: got status 0x0
    Pairing completed: E3:FE:4E:E0:6D:C5 (random), bonded: 1
    Security changed: E3:FE:4E:E0:6D:C5 (random) level 2
    Cannot read Current Time: E3:FE:4E:E0:6D:C5 (random), error: -22

    a little more detail using printk's...no matter what I try to enter into the BLE Application, I end up with

    Pairing completed: E3:FE:4E:E0:6D:C5 (random), bonded: 1
    Security changed: E3:FE:4E:E0:6D:C5 (random) level 2
    button_changed() about to bt_cts_read_current_time
    bt_cts_read_current_time() about to bt_gatt_read(...)
    bt_cts_read_callback() err=0
    current_time_decode() length=1 expected length=10
    read_current_time_cb() entered...err=-22
    Cannot read Current Time: E3:FE:4E:E0:6D:C5 (random), error: -22
    button_changed() about to bt_cts_read_current_time
    bt_cts_read_current_time() about to bt_gatt_read(...)
    bt_cts_read_callback() err=0
    current_time_decode() length=1 expected length=10
    read_current_time_cb() entered...err=-22
    Cannot read Current Time: E3:FE:4E:E0:6D:C5 (random), error: -22

Related