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>}

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

    from pc_ble_driver_py import config
    from time import sleep
    from threading import Thread
    
    #config.__conn_ic_id__ = 'NRF52'; port = 'COM13'
    config.__conn_ic_id__ = 'NRF51'; port = 'COM10'
    
    from pc_ble_driver_py.ble_adapter import *
    from pc_ble_driver_py.ble_driver import *
    
    class PasskeyTest(BLEDriverObserver):
        def __init__(self, adapter):
            adapter.driver.observer_register(self)
            self.adapter = adapter
        def on_gap_evt_connected(self, ble_driver, conn_handle, **kwargs):
            print('connected')
            self.conn_handle = conn_handle
            Thread(target=self.adapter.authenticate,
                args=(conn_handle, None),
                kwargs={'bond': True, 'mitm': True, 'io_caps': BLEGapIOCaps.keyboard_only}).start()
        def on_gap_evt_auth_key_request(self, ble_driver, conn_handle, key_type):
            print('passkey request')
            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)
        def on_rpc_log_entry(self, ble_driver, severity, message):
            print(message)
    
    
    adapter = BLEAdapter(BLEDriver(serial_port=port, log_severity_level='debug'))
    observer = PasskeyTest(adapter)
    adapter.open()
    if config.__conn_ic_id__ == 'NRF51':
        enable_params = BLEEnableParams(
            vs_uuid_count=1,
            service_changed=0,
            periph_conn_count=0,
            central_conn_count=1,
            central_sec_count=1)
    else:
        enable_params = None
    adapter.driver.ble_enable(enable_params)
    addr = BLEGapAddr(BLEGapAddr.Types.random_static, bytes.fromhex('EA97AFB59913'))
    adapter.connect(addr)
    sleep(2) # to log any events
    
    Successfully opened COM10. Baud rate: 1000000. Flow control: none. Parity: none.
    State change: STATE_START -> STATE_RESET
           1 ->  [N/A] type:          RESERVED_5 reliable: no seq#:0 ack#:0 payload_length:0 data_integrity:0 err_code:0x0
    State change: STATE_RESET -> STATE_UNINITIALIZED
           2 ->  [01 7e ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0x0 [SYNC]
        1/ 0 <-  [02 7d ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0x0 [SYNC_RESP]
    State change: STATE_UNINITIALIZED -> STATE_INITIALIZED
           3 ->  [03 fc 11 ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:3 data_integrity:0 err_code:0x0 [CONFIG [ sliding-window-size:1 out-of-frame:0 data-integrity-check-type:1 version-number:0 ]]
        2/ 0 <-  [01 7e ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0x0 [SYNC]
           4 ->  [02 7d ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0x0 [SYNC_RESP]
           5 ->  [03 fc 11 ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:3 data_integrity:0 err_code:0x0 [CONFIG [ sliding-window-size:1 out-of-frame:0 data-integrity-check-type:1 version-number:0 ]]
        3/ 0 <-  [04 7b 11 ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:3 data_integrity:0 err_code:0x0 [CONFIG_RESP [ sliding-window-size:1 out-of-frame:0 data-integrity-check-type:1 version-number:0 ]]
    State change: STATE_INITIALIZED -> STATE_ACTIVE
           6 ->  [00 60 01 01 00 00 00 01 01 00 00 00 00 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:0 ack#:0 payload_length:e data_integrity:1 header_checksum:52 err_code:0x0
        4/ 0 <-  [03 fc 11 ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:3 data_integrity:0 err_code:0x0 [CONFIG [ sliding-window-size:1 out-of-frame:0 data-integrity-check-type:1 version-number:0 ]]
           7 ->  [04 7b 11 ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:3 data_integrity:0 err_code:0x0 [CONFIG_RESP [ sliding-window-size:1 out-of-frame:0 data-integrity-check-type:1 version-number:0 ]]
           8 ->  [00 60 01 01 00 00 00 01 01 00 00 00 00 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:0 ack#:0 payload_length:e data_integrity:1 header_checksum:52 err_code:0x0
        5/ 0 <-  [N/A] type:                 ACK reliable: no seq#:0 ack#:1 payload_length:0 data_integrity:0 err_code:0x0
        6/ 0 <-  [01 60 00 00 00 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:0 ack#:1 payload_length:6 data_integrity:1 header_checksum:ca err_code:0x0
           9 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:1 payload_length:0 data_integrity:0 err_code:0x0
          10 ->  [00 8c 01 01 13 99 b5 af 97 ea 01 01 00 40 01 f0 00 0a 00 01 0c 00 18 00 00 00 90 01 ] type:     VENDOR_SPECIFIC reliable:yes seq#:1 ack#:1 payload_length:1c data_integrity:1 header_checksum:68 err_code:0x0
        7/ 0 <-  [N/A] type:                 ACK reliable: no seq#:0 ack#:2 payload_length:0 data_integrity:0 err_code:0x0
        8/ 0 <-  [01 8c 00 00 00 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:1 ack#:2 payload_length:6 data_integrity:1 header_checksum:c1 err_code:0x0
          11 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:2 payload_length:0 data_integrity:0 err_code:0x0
        9/ 0 <-  [02 10 00 00 00 01 13 99 b5 af 97 ea 01 97 f4 e5 c6 3b c4 02 00 18 00 18 00 00 00 90 01 ] type:     VENDOR_SPECIFIC reliable:yes seq#:2 ack#:2 payload_length:1d data_integrity:1 header_checksum:4f err_code:0x0
          12 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:3 payload_length:0 data_integrity:0 err_code:0x0
    connected
          13 ->  [00 7e 00 00 01 23 07 10 01 01 ] type:     VENDOR_SPECIFIC reliable:yes seq#:2 ack#:3 payload_length:a data_integrity:1 header_checksum:78 err_code:0x0
       10/ 0 <-  [N/A] type:                 ACK reliable: no seq#:0 ack#:3 payload_length:0 data_integrity:0 err_code:0x0
       11/ 0 <-  [01 7e 00 00 00 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:3 ack#:3 payload_length:6 data_integrity:1 header_checksum:b7 err_code:0x0
          14 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:4 payload_length:0 data_integrity:0 err_code:0x0
       12/ 0 <-  [02 13 00 00 00 03 00 10 01 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:4 ack#:3 payload_length:a data_integrity:1 header_checksum:76 err_code:0x0
          15 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:5 payload_length:0 data_integrity:0 err_code:0x0
          16 ->  [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#:3 ack#:5 payload_length:113 data_integrity:1 header_checksum:c6 err_code:0x0
       13/ 0 <-  [N/A] type:                 ACK reliable: no seq#:0 ack#:4 payload_length:0 data_integrity:0 err_code:0x0
       14/ 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#:5 ack#:4 payload_length:113 data_integrity:1 header_checksum:cc err_code:0x0
          17 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:6 payload_length:0 data_integrity:0 err_code:0x0
       15/ 0 <-  [02 17 00 00 00 01 ] type:     VENDOR_SPECIFIC reliable:yes seq#:6 ack#:4 payload_length:6 data_integrity:1 header_checksum:ac err_code:0x0
          18 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:7 payload_length:0 data_integrity:0 err_code:0x0
    passkey request
          19 ->  [00 80 00 00 01 01 31 32 33 34 35 36 ] type:     VENDOR_SPECIFIC reliable:yes seq#:4 ack#:7 payload_length:c data_integrity:1 header_checksum:36 err_code:0x0
       16/ 0 <-  [N/A] type:                 ACK reliable: no seq#:0 ack#:5 payload_length:0 data_integrity:0 err_code:0x0
       17/ 0 <-  [01 80 00 00 00 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:7 ack#:5 payload_length:6 data_integrity:1 header_checksum:a3 err_code:0x0
          20 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:0 payload_length:0 data_integrity:0 err_code:0x0
       18/ 0 <-  [02 19 00 00 00 84 01 00 01 00 07 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#:0 ack#:5 payload_length:117 data_integrity:1 header_checksum:89 err_code:0x0
          21 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:1 payload_length:0 data_integrity:0 err_code:0x0
       19/ 0 <-  [02 11 00 00 00 13 ] type:     VENDOR_SPECIFIC reliable:yes seq#:1 ack#:5 payload_length:6 data_integrity:1 header_checksum:a9 err_code:0x0
          22 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:2 payload_length:0 data_integrity:0 err_code:0x0
    
    Successfully opened COM10. Baud rate: 1000000. Flow control: none. Parity: none.
    State change: STATE_START -> STATE_RESET
           1 ->  [N/A] type:          RESERVED_5 reliable: no seq#:0 ack#:0 payload_length:0 data_integrity:0 err_code:0x0
    State change: STATE_RESET -> STATE_UNINITIALIZED
           2 ->  [01 7e ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0x0 [SYNC]
        1/ 0 <-  [02 7d ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0x0 [SYNC_RESP]
    State change: STATE_UNINITIALIZED -> STATE_INITIALIZED
           3 ->  [03 fc 11 ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:3 data_integrity:0 err_code:0x0 [CONFIG [ sliding-window-size:1 out-of-frame:0 data-integrity-check-type:1 version-number:0 ]]
        2/ 0 <-  [01 7e ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0x0 [SYNC]
           4 ->  [02 7d ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:2 data_integrity:0 err_code:0x0 [SYNC_RESP]
           5 ->  [03 fc 11 ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:3 data_integrity:0 err_code:0x0 [CONFIG [ sliding-window-size:1 out-of-frame:0 data-integrity-check-type:1 version-number:0 ]]
        3/ 0 <-  [04 7b 11 ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:3 data_integrity:0 err_code:0x0 [CONFIG_RESP [ sliding-window-size:1 out-of-frame:0 data-integrity-check-type:1 version-number:0 ]]
    State change: STATE_INITIALIZED -> STATE_ACTIVE
           6 ->  [00 60 01 01 00 00 00 01 01 00 00 00 00 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:0 ack#:0 payload_length:e data_integrity:1 header_checksum:52 err_code:0x0
        4/ 0 <-  [03 fc 11 ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:3 data_integrity:0 err_code:0x0 [CONFIG [ sliding-window-size:1 out-of-frame:0 data-integrity-check-type:1 version-number:0 ]]
           7 ->  [04 7b 11 ] type: LINK_CONTROL_PACKET reliable: no seq#:0 ack#:0 payload_length:3 data_integrity:0 err_code:0x0 [CONFIG_RESP [ sliding-window-size:1 out-of-frame:0 data-integrity-check-type:1 version-number:0 ]]
           8 ->  [00 60 01 01 00 00 00 01 01 00 00 00 00 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:0 ack#:0 payload_length:e data_integrity:1 header_checksum:52 err_code:0x0
        5/ 0 <-  [N/A] type:                 ACK reliable: no seq#:0 ack#:1 payload_length:0 data_integrity:0 err_code:0x0
        6/ 0 <-  [01 60 00 00 00 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:0 ack#:1 payload_length:6 data_integrity:1 header_checksum:ca err_code:0x0
           9 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:1 payload_length:0 data_integrity:0 err_code:0x0
          10 ->  [00 8c 01 01 13 99 b5 af 97 ea 01 01 00 40 01 f0 00 0a 00 01 0c 00 18 00 00 00 90 01 ] type:     VENDOR_SPECIFIC reliable:yes seq#:1 ack#:1 payload_length:1c data_integrity:1 header_checksum:68 err_code:0x0
        7/ 0 <-  [N/A] type:                 ACK reliable: no seq#:0 ack#:2 payload_length:0 data_integrity:0 err_code:0x0
        8/ 0 <-  [01 8c 00 00 00 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:1 ack#:2 payload_length:6 data_integrity:1 header_checksum:c1 err_code:0x0
          11 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:2 payload_length:0 data_integrity:0 err_code:0x0
        9/ 0 <-  [02 10 00 00 00 01 13 99 b5 af 97 ea 01 97 f4 e5 c6 3b c4 02 00 18 00 18 00 00 00 90 01 ] type:     VENDOR_SPECIFIC reliable:yes seq#:2 ack#:2 payload_length:1d data_integrity:1 header_checksum:4f err_code:0x0
          12 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:3 payload_length:0 data_integrity:0 err_code:0x0
    connected
          13 ->  [00 7e 00 00 01 23 07 10 01 01 ] type:     VENDOR_SPECIFIC reliable:yes seq#:2 ack#:3 payload_length:a data_integrity:1 header_checksum:78 err_code:0x0
       10/ 0 <-  [N/A] type:                 ACK reliable: no seq#:0 ack#:3 payload_length:0 data_integrity:0 err_code:0x0
       11/ 0 <-  [01 7e 00 00 00 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:3 ack#:3 payload_length:6 data_integrity:1 header_checksum:b7 err_code:0x0
          14 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:4 payload_length:0 data_integrity:0 err_code:0x0
       12/ 0 <-  [02 13 00 00 00 03 00 10 01 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:4 ack#:3 payload_length:a data_integrity:1 header_checksum:76 err_code:0x0
          15 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:5 payload_length:0 data_integrity:0 err_code:0x0
          16 ->  [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#:3 ack#:5 payload_length:113 data_integrity:1 header_checksum:c6 err_code:0x0
       13/ 0 <-  [N/A] type:                 ACK reliable: no seq#:0 ack#:4 payload_length:0 data_integrity:0 err_code:0x0
       14/ 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#:5 ack#:4 payload_length:113 data_integrity:1 header_checksum:cc err_code:0x0
          17 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:6 payload_length:0 data_integrity:0 err_code:0x0
       15/ 0 <-  [02 17 00 00 00 01 ] type:     VENDOR_SPECIFIC reliable:yes seq#:6 ack#:4 payload_length:6 data_integrity:1 header_checksum:ac err_code:0x0
          18 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:7 payload_length:0 data_integrity:0 err_code:0x0
    passkey request
          19 ->  [00 80 00 00 01 01 31 32 33 34 88 37 ] type:     VENDOR_SPECIFIC reliable:yes seq#:4 ack#:7 payload_length:c data_integrity:1 header_checksum:36 err_code:0x0
       16/ 0 <-  [N/A] type:                 ACK reliable: no seq#:0 ack#:5 payload_length:0 data_integrity:0 err_code:0x0
       17/ 0 <-  [01 80 00 00 00 00 ] type:     VENDOR_SPECIFIC reliable:yes seq#:7 ack#:5 payload_length:6 data_integrity:1 header_checksum:a3 err_code:0x0
          20 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:0 payload_length:0 data_integrity:0 err_code:0x0
       18/ 0 <-  [02 19 00 00 00 84 01 00 01 00 07 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#:0 ack#:5 payload_length:117 data_integrity:1 header_checksum:89 err_code:0x0
          21 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:1 payload_length:0 data_integrity:0 err_code:0x0
       19/ 0 <-  [02 11 00 00 00 13 ] type:     VENDOR_SPECIFIC reliable:yes seq#:1 ack#:5 payload_length:6 data_integrity:1 header_checksum:a9 err_code:0x0
          22 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:2 payload_length:0 data_integrity:0 err_code:0x0
    

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

    uint32_t sd_ble_gap_auth_key_reply(adapter_t *adapter, uint16_t conn_handle,
        uint8_t               key_type,
        uint8_t const * const key)
    {
        const encode_function_t encode_function = [&](uint8_t *buffer, uint32_t *length) -> uint32_t {
            printf("encode key:%02X %02X %02X %02X %02X %02X\n", 
                   key[0],key[1],key[2],key[3],key[4],key[5]);
            return ble_gap_auth_key_reply_req_enc(
                conn_handle,
                key_type,
                key,
                buffer,
                length);
        };
    
        const decode_function_t decode_function = [&](uint8_t *buffer, const uint32_t length, uint32_t *result) -> uint32_t {
            return ble_gap_auth_key_reply_rsp_dec(
                buffer,
                length,
                result);
        };
    
        printf("sd_ble_gap_auth_key_reply key:%02X %02X %02X %02X %02X %02X\n", 
                   key[0],key[1],key[2],key[3],key[4],key[5]);
    
        return gap_encode_decode(adapter, encode_function, decode_function);
    }

    Here's the output from a failure:

    passkey request
    sd_ble_gap_auth_key_reply key:31 32 33 34 35 36
    encode key:31 32 33 34 10 40
          19 ->  [N/A] type:                 ACK reliable: no seq#:0 ack#:7 payload_length:0 data_integrity:0 err_code:0x0
          20 ->  [00 80 00 00 01 01 31 32 33 34 10 40 ] type:     VENDOR_SPECIFIC reliable:yes seq#:4 ack#:7 payload_length:c data_integrity:1 header_checksum:36 err_code:0x0

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

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

    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

Related