@@ -225,6 +225,10 @@ static void ble_process_rx_msg_status(const uint8_t *data, uint32_t len) {
225
225
tsqueue_enqueue (& drv -> event_queue , (uint8_t * )& event , sizeof (event ),
226
226
NULL );
227
227
228
+ if (drv -> mode_requested == BLE_MODE_PAIRING ) {
229
+ ble_pairing_end (drv );
230
+ }
231
+
228
232
drv -> pairing_allowed = false;
229
233
drv -> pairing_requested = false;
230
234
if (msg .peer_count > 0 ) {
@@ -274,8 +278,12 @@ static void ble_process_rx_msg_status(const uint8_t *data, uint32_t len) {
274
278
drv -> peer_count = msg .peer_count ;
275
279
276
280
if (prev_mode == BLE_MODE_PAIRING && drv -> mode_current != BLE_MODE_PAIRING ) {
277
- // pairing mode ended
278
- ble_pairing_end (drv );
281
+ if (drv -> mode_requested == BLE_MODE_PAIRING ) {
282
+ // unexpected pairing end - restart pairing
283
+ ble_send_advertising_on (drv , false);
284
+ } else {
285
+ ble_pairing_end (drv );
286
+ }
279
287
}
280
288
281
289
if (drv -> mode_requested == BLE_MODE_KEEP_CONNECTION && !drv -> connected ) {
@@ -293,6 +301,12 @@ static void ble_process_rx_msg_status(const uint8_t *data, uint32_t len) {
293
301
}
294
302
}
295
303
304
+ // if there are no peers (i.e. after wiping the bonds), it makes no sense to
305
+ // stay in connectable mode as there is no one that can connect
306
+ if (msg .peer_count == 0 && drv -> mode_requested == BLE_MODE_CONNECTABLE ) {
307
+ drv -> mode_requested = BLE_MODE_OFF ;
308
+ }
309
+
296
310
drv -> status_valid = true;
297
311
}
298
312
0 commit comments