rymanluk commented on a change in pull request #777: nimble/host: Clear master and slave states on host reset URL: https://github.com/apache/mynewt-nimble/pull/777#discussion_r397811581
########## File path: nimble/host/src/ble_gap.c ########## @@ -1237,6 +1237,53 @@ ble_gap_adv_active_instance(uint8_t instance) return ble_gap_slave[instance].op == BLE_GAP_OP_S_ADV; } +/** + * Clears advertisement and discovery state. This function is necessary + * when the controller loses its active state (e.g. on stack reset). + */ +void +ble_gap_reset_state(int reason) +{ + uint16_t conn_handle; + + while (1) { + conn_handle = ble_hs_atomic_first_conn_handle(); + if (conn_handle == BLE_HS_CONN_HANDLE_NONE) { + break; + } + + ble_gap_conn_broken(conn_handle, reason); + } + +#if NIMBLE_BLE_ADVERTISE +#if MYNEWT_VAL(BLE_EXT_ADV) + uint8_t i; + for (i = 0; i < BLE_ADV_INSTANCES; i++) { + if (ble_gap_adv_active_instance(i)) { + ble_gap_slave_reset_state(i); + /* Indicate to application that advertising has stopped. */ + ble_gap_adv_finished(i, reason, 0, 0); + } + } +#else + if (ble_gap_adv_active_instance(0)) { + ble_gap_slave_reset_state(0); + /* Indicate to application that advertising has stopped. */ + ble_gap_adv_finished(0, reason, 0, 0); + } +#endif +#endif + +#if NIMBLE_BLE_SCAN + ble_gap_master_reset_state(); + if (ble_gap_disc_active()) { + ble_gap_disc_complete(); + } else if (ble_gap_conn_active()) { + ble_gap_master_failed(reason); Review comment: hmm when you look inside ` ble_gap_master_failed` function, there is a switch. Maybe it is worth to add there case for `BLE_GAP_OP_M_DISC` and then call that function? I would also add there `ble_gap_master_reset_state()` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services