diff --git a/Firmware/components/backend-esp/src/time_sync_service.cpp b/Firmware/components/backend-esp/src/time_sync_service.cpp index d6444e7..197b7de 100644 --- a/Firmware/components/backend-esp/src/time_sync_service.cpp +++ b/Firmware/components/backend-esp/src/time_sync_service.cpp @@ -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) @@ -192,7 +197,7 @@ void finalizePending(uint32_t uid) { continue; cardboy::sdk::INotificationCenter::Notification note{}; - note.timestamp = static_cast(time(nullptr)); + note.timestamp = static_cast(time(nullptr)); note.externalId = uid; if (!it->title.empty()) { note.title = it->title; @@ -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: