This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Passkey corruption when using pc-ble-driver-py

We are using the latest master of pc-ble-driver-py. Pairing using a passkey fails frequently. The problem seems to be that the frame with the passkey contains a corrupted value.

Since ble_driver.py or ble_adapter.py do not offer methods for passkey entry, we are using the sd_ble_gap_auth_key_reply method of the underlying driver.

Example: After getting a on_gap_evt_auth_key_request, we call sd_ble_gap_auth_key_reply with passkey=913858

Fullscreen
1
2
pk = util.list_to_uint8_array(b'913858').cast()
driver.sd_ble_gap_auth_key_reply(self.adapter.driver.rpc_adapter, self.conn_handle, driver.BLE_GAP_AUTH_KEY_TYPE_PASSKEY, pk)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The pairing fails with BLE_GAP_SEC_STATUS_CONFIRM_VALUE. Looking in the debug output, the following packet was sent:

pc_ble_driver_py.ble_adapter DEBUG       24 ->  [00 80 00 00 01 01 39 31 33 38 c8 69 ] type:     VENDOR_SPECIFIC reliable:yes seq#:6 ack#:1 payload_length:c data_integrity:1 header_checksum:64 err_code:0x0

Note the bytes 39 31 33 38 c8 69. The expected values would be 39 31 33 38 35 38.

Here are some more examples:

passkey: 308558 packet: [00 80 00 00 01 01 33 30 38 35 58 a9 ]

passkey: 045296 packet: [00 80 00 00 01 01 30 34 35 32 c8 69 ]

passkey: 773757 packet: [00 80 00 00 01 01 37 37 33 37 c8 69 ]

When the correct passkey is in the packet, pairing works (BLE_GAP_SEC_STATUS_SUCCESS).

Is there anything we are doing wrong?

Below is some more context from the debug output:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2019-09-30T11:38:58.734 ble INFO connect_device_address(): Connecting to device address: <EA97AFB59913>
2019-09-30T11:38:58.735 pc_ble_driver_py.ble_adapter DEBUG 15 -> [00 8c 01 02 13 99 b5 af 97 ea 01 01 40 01 f0 00 0a 00 01 0c 00 18 00 00 00 90 01 00 ] type: VENDOR_SPECIFIC reliable:yes seq#:3 ack#:3 payload_length:1c data_integrity:1 header_checksum:56 err_code:0x0
2019-09-30T11:38:58.738 pc_ble_driver_py.ble_adapter DEBUG 11/ 0 <- [N/A] type: ACK reliable: no seq#:0 ack#:4 payload_length:0 data_integrity:0 err_code:0x0
2019-09-30T11:38:58.738 pc_ble_driver_py.ble_adapter DEBUG 12/ 0 <- [01 8c 00 00 00 00 ] type: VENDOR_SPECIFIC reliable:yes seq#:3 ack#:4 payload_length:6 data_integrity:1 header_checksum:af err_code:0x0
2019-09-30T11:38:58.738 pc_ble_driver_py.ble_adapter DEBUG 16 -> [N/A] type: ACK reliable: no seq#:0 ack#:4 payload_length:0 data_integrity:0 err_code:0x0
2019-09-30T11:38:59.455 pc_ble_driver_py.ble_adapter DEBUG 13/ 0 <- [02 10 00 00 00 02 13 99 b5 af 97 ea 02 18 00 18 00 00 00 90 01 ] type: VENDOR_SPECIFIC reliable:yes seq#:4 ack#:4 payload_length:15 data_integrity:1 header_checksum:bd err_code:0x0
2019-09-30T11:38:59.455 pc_ble_driver_py.ble_adapter DEBUG 17 -> [N/A] type: ACK reliable: no seq#:0 ack#:5 payload_length:0 data_integrity:0 err_code:0x0
2019-09-30T11:38:59.455 pc_ble_driver_py.ble_driver DEBUG ble_evt_handler_sync
2019-09-30T11:38:59.455 ble INFO [e_connected] Connected
2019-09-30T11:38:59.456 ble INFO connect_device_address(): Connected to device addr: EA97AFB59913
2019-09-30T11:38:59.456 ble INFO Authenticating...
2019-09-30T11:38:59.456 pc_ble_driver_py.ble_adapter DEBUG 18 -> [00 7e 00 00 01 23 07 10 01 01 ] type: VENDOR_SPECIFIC reliable:yes seq#:4 ack#:5 payload_length:a data_integrity:1 header_checksum:66 err_code:0x0
2019-09-30T11:38:59.459 pc_ble_driver_py.ble_adapter DEBUG 14/ 0 <- [N/A] type: ACK reliable: no seq#:0 ack#:5 payload_length:0 data_integrity:0 err_code:0x0
2019-09-30T11:38:59.459 pc_ble_driver_py.ble_adapter DEBUG 15/ 0 <- [01 7e 00 00 00 00 ] type: VENDOR_SPECIFIC reliable:yes seq#:5 ack#:5 payload_length:6 data_integrity:1 header_checksum:a5 err_code:0x0
2019-09-30T11:38:59.459 pc_ble_driver_py.ble_adapter DEBUG 19 -> [N/A] type: ACK reliable: no seq#:0 ack#:6 payload_length:0 data_integrity:0 err_code:0x0
2019-09-30T11:38:59.518 pc_ble_driver_py.ble_adapter DEBUG 16/ 0 <- [02 13 00 00 00 03 00 10 01 00 ] type: VENDOR_SPECIFIC reliable:yes seq#:6 ack#:5 payload_length:a data_integrity:1 header_checksum:64 err_code:0x0
2019-09-30T11:38:59.518 pc_ble_driver_py.ble_adapter DEBUG 20 -> [N/A] type: ACK reliable: no seq#:0 ack#:7 payload_length:0 data_integrity:0 err_code:0x0
2019-09-30T11:38:59.518 pc_ble_driver_py.ble_driver DEBUG ble_evt_handler_sync
2019-09-30T11:38:59.518 ble DEBUG on_gap_evt_sec_params_request Security Parameters bond(1) mitm(1) lesc(0) keypress(0) io_caps(BLEGapIOCaps.display_only) oob(0) max_key_size(16) min_key_size(0) kdist_own(enc(1) id(0) sign(0) link(0)) kdist_peer(enc(0) id(0) sign(0) link(0))
2019-09-30T11:38:59.519 pc_ble_driver_py.ble_adapter DEBUG 21 -> [00 7f 00 00 00 00 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ] type: VENDOR_SPECIFIC reliable:yes seq#:5 ack#:7 payload_length:113 data_integrity:1 header_checksum:b4 err_code:0x0
2019-09-30T11:38:59.524 pc_ble_driver_py.ble_adapter DEBUG 17/ 0 <- [N/A] type: ACK reliable: no seq#:0 ack#:6 payload_length:0 data_integrity:0 err_code:0x0
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Parents
  • Hi.

    Could you provide me with the test you did so I can share it with the development team?

    I can make the ticket private if you don't wish to share that with anyone else beside Nordic.

    Best regards,

    Andreas

  • Hi Andreas,

    I have written a short script with which you can reproduce the problem, both on nRF51 or nRF52 dongles.

    The script connects to a peripheral (address is hard-coded) which should support security.

    To simplify it, I always send a fixed passkey of 123456, which of course causes bonding to fail, but the invalid bytes can be seen in the log, starting with [00 80 00 00 01 01 ...

    The problem occurs roughly 1 out of 10 attempts, so you will have to run it several times and inspect the log.

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi.

    The development team has not been able to reproduce the issue with the script you provided, the only modifications they made was changing the UART port used and the BLE address.

    Do you have some more input?

    Best regards,

    Andreas

  • Hi Andreas,

    I have only been able to reproduce it in the "Release" build.

    In pc-ble-driver v4.1.1, I added some logging in file src/sd_api_v5/ble_gap_impl.cpp:

    Fullscreen
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Here's the output from a failure:

    Fullscreen
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    It seems that the closure data gets corrupted (are closures even a thing in C++? I'm a complete beginner here, as I only do C).

Reply
  • Hi Andreas,

    I have only been able to reproduce it in the "Release" build.

    In pc-ble-driver v4.1.1, I added some logging in file src/sd_api_v5/ble_gap_impl.cpp:

    Fullscreen
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Here's the output from a failure:

    Fullscreen
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    It seems that the closure data gets corrupted (are closures even a thing in C++? I'm a complete beginner here, as I only do C).

Children
  • Hi.

    Thanks for the input, may I ask which compiler and platform you're using?

    Best regards,

    Andreas

  • Visual Studio 2017 on Windows 10.

    Here's the output from cmake:

    Fullscreen
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi again.

    Thanks for the information, I've forwarded it to the development team, they will do some testing.

    I will get back to you when i know more :-)

    Best regards,

    Andreas

  • Hi again.

    Hei, kan du be kunden å endre koden i on_gap_evt_auth_key_request fra:
    Can you try to change the following in the code:
    Fullscreen
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    And change it to this:
    Fullscreen
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    Best regards,
    Andreas
  • Hi Andreas,

    That did indeed solve the problem, though I don't really understand why.

    Please consider extending the pc-ble-driver-py package with methods for passkey entry, because other customers might run into the same issue.

    Best regards,

    Stephan Walter