diff --git a/examples/ble_peripheral/ble_app_ancs_c/main.c b/examples/ble_peripheral/ble_app_ancs_c/main.c index 65d5a39..d14535e 100644 --- a/examples/ble_peripheral/ble_app_ancs_c/main.c +++ b/examples/ble_peripheral/ble_app_ancs_c/main.c @@ -168,6 +168,7 @@ static uint8_t m_attr_date[ATTR_DATA_SIZE]; /* static uint8_t m_attr_posaction[ATTR_DATA_SIZE]; /**< Buffer to store attribute data. */ static uint8_t m_attr_negaction[ATTR_DATA_SIZE]; /**< Buffer to store attribute data. */ static uint8_t m_attr_disp_name[ATTR_DATA_SIZE]; /**< Buffer to store attribute data. */ +static bool m_force_service_discovery = false; /**@brief String literals for the iOS notification categories. used then printing to UART. */ static char const * lit_catid[BLE_ANCS_NB_OF_CATEGORY_ID] = @@ -363,8 +364,10 @@ static void pm_evt_handler(pm_evt_t const * p_evt) // Check it the Service Changed characteristic handle exists in our client instance. // If it is invalid, we know service discovery is needed. // (No database was loaded during @ref PM_EVT_BONDED_PEER_CONNECTED) - if (m_gatts_c.srv_changed_char.characteristic.handle_value == BLE_GATT_HANDLE_INVALID) + if (m_gatts_c.srv_changed_char.characteristic.handle_value == BLE_GATT_HANDLE_INVALID || + m_force_service_discovery) { + m_force_service_discovery = false; ret = nrf_ble_gatts_c_handles_assign(&m_gatts_c, p_evt->conn_handle, NULL); APP_ERROR_CHECK(ret); @@ -396,8 +399,19 @@ static void pm_evt_handler(pm_evt_t const * p_evt) if (m_whitelist_peer_cnt < BLE_GAP_WHITELIST_ADDR_MAX_COUNT) { + bool already_added = false; + for (uint8_t i = 0; i < m_whitelist_peer_cnt; i++) { + if (m_whitelist_peers[i] == p_evt->peer_id) { + already_added = true; + break; + } + } + + if (!already_added) + { // Bonded to a new peer, add it to the whitelist. m_whitelist_peers[m_whitelist_peer_cnt++] = p_evt->peer_id; + } // The whitelist has been modified, update it in the Peer Manager. ret = pm_device_identities_list_set(m_whitelist_peers, m_whitelist_peer_cnt); @@ -412,6 +426,14 @@ static void pm_evt_handler(pm_evt_t const * p_evt) } } break; + case PM_EVT_CONN_SEC_CONFIG_REQ: { + // Reject pairing request from an already bonded peer. + pm_conn_sec_config_t conn_sec_config = {.allow_repairing = true}; + pm_conn_sec_config_reply(p_evt->conn_handle, &conn_sec_config); + m_force_service_discovery = true; + } + break; + default: break; }