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

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)

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:

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
2019-09-30T11:38:59.524 pc_ble_driver_py.ble_adapter DEBUG    18/ 0 <-  [01 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#:7 ack#:6 payload_length:113 data_integrity:1 header_checksum:ba err_code:0x0
2019-09-30T11:38:59.524 pc_ble_driver_py.ble_adapter DEBUG       22 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:0 payload_length:0 data_integrity:0 err_code:0x0
2019-09-30T11:38:59.527 pc_ble_driver_py.ble_adapter DEBUG    19/ 0 <-  [02 17 00 00 00 01 ] type:     VENDOR_SPECIFIC reliable:yes seq#:0 ack#:6 payload_length:6 data_integrity:1 header_checksum:a2 err_code:0x0
2019-09-30T11:38:59.527 pc_ble_driver_py.ble_adapter DEBUG       23 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:1 payload_length:0 data_integrity:0 err_code:0x0
2019-09-30T11:38:59.527 pc_ble_driver_py.ble_driver DEBUG ble_evt_handler_sync
2019-09-30T11:38:59.527 ble INFO [e_passkey_request] Call the callback_passkey_request() method
2019-09-30T11:38:59.538 ble INFO [e_passkey_request] Returned passkey: 913858
2019-09-30T11:38:59.692 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
2019-09-30T11:38:59.692 pc_ble_driver_py.ble_adapter DEBUG    20/ 0 <-  [N/A] type:                 ACK reliable: no seq#:0 ack#:7 payload_length:0 data_integrity:0 err_code:0x0
2019-09-30T11:38:59.692 pc_ble_driver_py.ble_adapter DEBUG    21/ 0 <-  [01 80 00 00 00 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:1 ack#:7 payload_length:6 data_integrity:1 header_checksum:99 err_code:0x0
2019-09-30T11:38:59.692 pc_ble_driver_py.ble_adapter DEBUG       25 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:2 payload_length:0 data_integrity:0 err_code:0x0
2019-09-30T11:38:59.790 pc_ble_driver_py.ble_adapter DEBUG    22/ 0 <-  [02 19 00 00 00 84 01 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 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#:2 ack#:7 payload_length:117 data_integrity:1 header_checksum:77 err_code:0x0
2019-09-30T11:38:59.790 pc_ble_driver_py.ble_adapter DEBUG       26 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:3 payload_length:0 data_integrity:0 err_code:0x0
2019-09-30T11:38:59.790 pc_ble_driver_py.ble_driver DEBUG ble_evt_handler_sync
2019-09-30T11:38:59.791 ble WARNING Authentication failed: confirm_value kwargs={'error_src': 1, 'bonded': 0, 'sm1_levels': <pc_ble_driver_py.lib.nrf_ble_driver_sd_api_v5.ble_gap_sec_levels_t; proxy of <Swig Object of type 'ble_gap_sec_levels_t *' at 0x0F3267D0> >, 'sm2_levels': <pc_ble_driver_py.lib.nrf_ble_driver_sd_api_v5.ble_gap_sec_levels_t; proxy of <Swig Object of type 'ble_gap_sec_levels_t *' at 0x0F326E90> >, 'kdist_own': <pc_ble_driver_py.ble_driver.BLEGapSecKDist object at 0x12546850>, 'kdist_peer': <pc_ble_driver_py.ble_driver.BLEGapSecKDist object at 0x125469F0>}

  • Visual Studio 2017 on Windows 10.

    Here's the output from cmake:

    C:\work\tas\pc-ble-driver\build>cmake -DNRF_BLE_DRIVER_VERSION=4.1.1 -DCONNECTIVITY_VERSION=4.1.1 -DCMAKE_BUILD_TYPE=Release -G Ninja ..
    -- The C compiler identification is MSVC 19.16.27027.1
    -- The CXX compiler identification is MSVC 19.16.27027.1
    -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
    -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
    -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Architecture not set, using native 32-bit toolchain.
    -- Found Git: C:/Program Files/Git/cmd/git.exe (found version "2.20.1.windows.1")
    -- Check if the system is big endian
    -- Searching 16 bit integer
    -- Looking for sys/types.h
    -- Looking for sys/types.h - found
    -- Looking for stdint.h
    -- Looking for stdint.h - found
    -- Looking for stddef.h
    -- Looking for stddef.h - found
    -- Check size of unsigned short
    -- Check size of unsigned short - done
    -- Using unsigned short
    -- Check if the system is big endian - little endian
    -- Compiled examples are installed in directory "bin"
    -- Found Python: C:/Program Files (x86)/Python37-32/python.exe (found version "3.7.4") found components:  Interpreter
    -- Did not find clang-tidy, target tidy is disabled.
    -- If clang-tidy is installed, make sure run-clang-tidy.py and clang-tidy is in PATH
    -- Configuring done
    -- Generating done
    -- Build files have been written to: C:/work/tas/pc-ble-driver/build

  • 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:
     pk = util.list_to_uint8_array(b'123456').cast()
            driver.sd_ble_gap_auth_key_reply(adapter.driver.rpc_adapter, conn_handle, driver.BLE_GAP_AUTH_KEY_TYPE_PASSKEY, pk)
    And change it to this:
     pk = util.list_to_uint8_array(b'123456')
            driver.sd_ble_gap_auth_key_reply(adapter.driver.rpc_adapter, conn_handle, driver.BLE_GAP_AUTH_KEY_TYPE_PASSKEY, pk.cast())
    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

Related