Skip to content

Commit e5e2e06

Browse files
committed
fix(core): fine tune BLE behavior after unexpected events
i.e. where the is nRF reset, we want to restart the pairing if there was paring mode before [no changelog]
1 parent 1f58816 commit e5e2e06

File tree

1 file changed

+16
-2
lines changed
  • core/embed/io/ble/stm32

1 file changed

+16
-2
lines changed

core/embed/io/ble/stm32/ble.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ static void ble_process_rx_msg_status(const uint8_t *data, uint32_t len) {
225225
tsqueue_enqueue(&drv->event_queue, (uint8_t *)&event, sizeof(event),
226226
NULL);
227227

228+
if (drv->mode_requested == BLE_MODE_PAIRING) {
229+
ble_pairing_end(drv);
230+
}
231+
228232
drv->pairing_allowed = false;
229233
drv->pairing_requested = false;
230234
if (msg.peer_count > 0) {
@@ -274,8 +278,12 @@ static void ble_process_rx_msg_status(const uint8_t *data, uint32_t len) {
274278
drv->peer_count = msg.peer_count;
275279

276280
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+
}
279287
}
280288

281289
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) {
293301
}
294302
}
295303

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+
296310
drv->status_valid = true;
297311
}
298312

0 commit comments

Comments
 (0)