repeat pairing fix

This commit is contained in:
2025-10-21 20:21:12 +02:00
parent 678158c302
commit 4112efd60b

View File

@@ -158,6 +158,11 @@ void resetAncsState() {
g_pendingNotifications.clear();
}
void clearDeliveredNotifications() {
if (g_notificationCenter)
g_notificationCenter->clear();
}
PendingNotification* findPending(uint32_t uid) {
for (auto& entry: g_pendingNotifications) {
if (entry.uid == uid)
@@ -1461,12 +1466,23 @@ int gapEventHandler(struct ble_gap_event* event, void* /*arg*/) {
case BLE_GAP_EVENT_REPEAT_PAIRING: {
ble_gap_conn_desc desc{};
if (ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc) == 0) {
ESP_LOGI(kLogTag, "Repeat pairing requested by %02X:%02X:%02X:%02X:%02X:%02X; keeping existing bond",
const int findRc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc);
if (findRc != 0) {
ESP_LOGW(kLogTag, "Repeat pairing but failed to fetch connection descriptor (rc=%d)", findRc);
} else {
ESP_LOGI(kLogTag,
"Repeat pairing requested by %02X:%02X:%02X:%02X:%02X:%02X; deleting existing bond to re-pair",
desc.peer_id_addr.val[0], desc.peer_id_addr.val[1], desc.peer_id_addr.val[2],
desc.peer_id_addr.val[3], desc.peer_id_addr.val[4], desc.peer_id_addr.val[5]);
const int deleteRc = ble_store_util_delete_peer(&desc.peer_id_addr);
if (deleteRc != 0) {
ESP_LOGW(kLogTag, "Failed to delete existing bond (rc=%d)", deleteRc);
}
return BLE_GAP_REPEAT_PAIRING_IGNORE;
}
resetAncsState();
clearDeliveredNotifications();
g_securityRequested = false;
return BLE_GAP_REPEAT_PAIRING_RETRY;
}
default: