Skip to content
Commit 9e5e23d1 authored by Pavel Vasilyev's avatar Pavel Vasilyev Committed by Benjamin Cabé
Browse files

bluetooth: host: hci_core: prioritize LE Conn Complete event handling



During debugging multiple.sh test, a race condition was observed where
advertiser state on Host and Controler was desynchronized.

Below is the sequence of actions led to this issue:

0. Host has queued few priority events at this moment.
1. Controller establishes a connection and stops the advertiser.
2. Controller sends to Host BT_HCI_EVT_LE_ENH_CONN_COMPLETE.
3. Host deprioritizes BT_HCI_EVT_LE_ENH_CONN_COMPLETE event and doesn't
   process it immediately.
4. Controller sends to Host other priority events which are processed
   immediately.
5. Host wants to disable the advertiser in order to update the Resolving
   List (see `bt_id_add`).
6. Host sends to Controller BT_HCI_OP_LE_SET_ADV_ENABLE(Disable)
   command.
7. Controller sends to Host BT_HCI_EVT_CMD_COMPLETE event on
   BT_HCI_OP_LE_SET_ADV_ENABLE command.
8. Host prioritizes this BT_HCI_EVT_CMD_COMPLETE event, processes it
   immediately and clears `BT_ADV_ENABLED` flag for the advertiser.
   Note that Controller already has the advertiser disabled after
   establishing connection on step 1.
9. Host sends few commands in a row and Controller sends
   BT_HCI_EVT_CMD_COMPLETE events that are prioritized (see
   `bt_id_add`).
10. Host wants to re-enable the advertiser after updating the Resolving
    List.
11. Host sends to Controller BT_HCI_OP_LE_SET_ADV_ENABLE(Enable)
    command.
12. Controller sends to Host BT_HCI_EVT_CMD_COMPLETE event on
    BT_HCI_OP_LE_SET_ADV_ENABLE.
13. Host prioritizes this BT_HCI_EVT_CMD_COMPLETE, processes it
    immediately and sets `BT_ADV_ENABLED` flag for the advertiser.
14. Controller has the advertiser enabled.
15. Host now processes the delayed BT_HCI_EVT_LE_ENH_CONN_COMPLETE
    event.
16. Host resets the advertiser state, thinking the Controller's
    advertiser is also stopped.

This commit prioritizes LE Connection Complete and LE Enhanced
Connection Complete events to drop advertiser state on Host immediately
once the corresponding event was received.

Signed-off-by: default avatarPavel Vasilyev <pavel.vasilyev@nordicsemi.no>
parent 6f3248b3
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment