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

Parents
  • It seemed to connect once after a "west flash --erase" rather than a "west flash". But it only paired once and then failed. And I never saw any time data, and it only paired once so it's impossible to experiment and see what is going on. I know nothing much about Bluetooth other than I have used devices that pair, and as a user I would have no access to reflashing let alone with a --erase, and it's not like I have to discard the device after one usage. So, what the heck is going on here???

  • Pairing failed because the dongle still had old bonding keys after you erased and re-flashed the board. Delete the bond on the dongle as well, then pairs again. The CTS example is a client and it only prints time when it connects to a device that provides CTS service, such as a phone or some other device that is broadcasting CTS service.

    Did you make sure that you have Settings enabled in your prj.conf for persistence key storage?

    CONFIG_BT_SETTINGS=y
    CONFIG_SETTINGS=y

  • Thank you, Susheel. I do have the Settings as you described in prj.conf. How do I delete the bond on the dongle?

    About Step 7 in the test instructions, it says to Perform Bonding. It appears that one should never try that more than once, or he will need to "west flash --erase" the kit (or custom equivalent). Do you think that this is why I have had such difficulty? The instructions do not give any warning. Or is something else going on? Thanks.

    Burt

    ps

    Connected E3:FE:4E:E0:6D:C5 (random)
    The discovery procedure succeeded
    Pairing completed: E3:FE:4E:E0:6D:C5 (random), bonded: 0
    Security changed: E3:FE:4E:E0:6D:C5 (random) level 2

    Is this good or bad--I don't know about bonded: 0 -- that looks bad to me.

  • Oh, oops, I guess settings are set in flash, and we have flash but it's undoubtedly connected to different SPI pins and I did not fix up the dts file for that prior to testing. I didn't realize how complex this "simple" sample was.

    Just for curiosity, is there a way to do a sample CTS like this but without the security aspect?

  • Ah, interesting. Glad that you figured the dts porting need to make this work.

    Burt said:
    Just for curiosity, is there a way to do a sample CTS like this but without the security aspect?

    You can definitely disable the security aspect of the CTS by doing CONFIG_BT_SMP=n but then you wont be able to test it with phones and PC that required an encrypted link from the peer to share its CTS data. You could design another Central with CTS server that does not need encrypted link to connect and share its CTS data. But phones and PCs by default seems to need an encrypted link.

  • 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.

Reply
  • 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.

Children
  • 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

  • I have solved the problem of the time not getting to the client. It was the user interface on BLE App. When you fill in the 10 byte Time, you have to press the check mark--I'm not sure if it is after or before hitting the Write button--regardless, the poor instructions in the documentation do not describe the user interface properly--no mention is made about the check box.

    In order to not get screwed up with double bonding I added

    CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE=y

    to my prj.conf. Please advise of any other possibilities that will protect me from having to re-flash. Also, please have the documentation team correct the instructions in the documentation to make them idempotent. I should be able to run through the test procedure as written multiple times without a severe error that requires re-flashing. Thank you.

    Burt Silverman

Related