apps/bttester: add lost bond event

When we receive GAP event BLE_GAP_EVENT_REPEAT_PAIRING it means
that we sent security request, but bond is lost - peer sent pair
request in return, which means it doesn't have keys anymore. Bond is
also lost when we sent encryption request and peer responded with
Ecnryption Change event with error 'PIN or Key Missing'. Inform
Upper tester about it.
This commit is contained in:
Krzysztof Kopyściński
2022-05-26 11:19:30 +02:00
committed by Szymon Janc
parent fa0354dd78
commit 86c0a66542
2 changed files with 24 additions and 0 deletions
+6
View File
@@ -412,6 +412,12 @@ struct gap_pairing_consent_req_ev {
uint8_t address[6];
} __packed;
#define GAP_EV_BOND_LOST 0x8b
struct gap_bond_lost_ev {
uint8_t address_type;
uint8_t address[6];
} __packed;
/* GATT Service */
/* commands */
#define GATT_READ_SUPPORTED_COMMANDS 0x01
+18
View File
@@ -1025,6 +1025,20 @@ static void le_encryption_changed(struct ble_gap_conn_desc *desc)
CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
}
static void bond_lost(uint16_t conn_handle)
{
struct gap_bond_lost_ev ev;
struct ble_gap_conn_desc desc;
int rc;
rc = ble_gap_conn_find(conn_handle, &desc);
assert(rc == 0);
memcpy(ev.address, &desc.peer_id_addr, sizeof(ev.address));
ev.address_type = desc.peer_id_addr.type;
tester_send(BTP_SERVICE_ID_GAP, GAP_EV_BOND_LOST, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
}
static void print_bytes(const uint8_t *bytes, int len)
{
int i;
@@ -1133,6 +1147,9 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
assert(rc == 0);
print_conn_desc(&desc);
le_encryption_changed(&desc);
if (event->enc_change.status == BLE_HS_HCI_ERR(BLE_ERR_PINKEY_MISSING)) {
bond_lost(event->enc_change.conn_handle);
}
break;
case BLE_GAP_EVENT_PASSKEY_ACTION:
console_printf("passkey action event; action=%d",
@@ -1201,6 +1218,7 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
assert(rc == 0);
rc = ble_store_util_delete_peer(&desc.peer_id_addr);
assert(rc == 0);
bond_lost(event->repeat_pairing.conn_handle);
return BLE_GAP_REPEAT_PAIRING_RETRY;
case BLE_GAP_EVENT_CONN_UPDATE:
console_printf("connection update event; status=%d ",