From a7037da4eff60d6da7bb8955fb2a52d8b5220312 Mon Sep 17 00:00:00 2001 From: Christopher Collins Date: Wed, 18 Oct 2017 12:47:32 -0700 Subject: [PATCH] BLE Host - Delay sync callback after IRK restore -Prior to commit- On startup, the host executes the following steps: 1. HCI startup sequence 2. Call sync callback 3. Restore IRKs from flash The problem is that step 3 (IRK restoration) causes a GAP preemption if there are any persisted IRKs. If the application initiates a GAP procedure during the sync callback, it will be immediately preempted. This happens in the bleprph app, for example. -After commit- Don't call the sync callback until after IRK restoration is complete. X-Original-Commit: 28f4a0d78df247d25542801ed79c3f6d9aed4983 --- nimble/host/src/ble_hs.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nimble/host/src/ble_hs.c b/nimble/host/src/ble_hs.c index 6f7c8a44e..c55cb9253 100644 --- a/nimble/host/src/ble_hs.c +++ b/nimble/host/src/ble_hs.c @@ -306,9 +306,6 @@ ble_hs_sync(void) rc = ble_hs_startup_go(); if (rc == 0) { ble_hs_sync_state = BLE_HS_SYNC_STATE_GOOD; - if (ble_hs_cfg.sync_cb != NULL) { - ble_hs_cfg.sync_cb(); - } } else { ble_hs_sync_state = BLE_HS_SYNC_STATE_BAD; } @@ -316,6 +313,13 @@ ble_hs_sync(void) ble_hs_timer_sched(BLE_HS_SYNC_RETRY_RATE); if (rc == 0) { + rc = ble_hs_misc_restore_irks(); + assert(rc == 0); + + if (ble_hs_cfg.sync_cb != NULL) { + ble_hs_cfg.sync_cb(); + } + STATS_INC(ble_hs_stats, sync); } @@ -556,9 +560,6 @@ ble_hs_start(void) ble_hs_sync(); - rc = ble_hs_misc_restore_irks(); - assert(rc == 0); - return 0; }