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