From 46b78bb1d58d05062e82ff4b2b4ada8f825f6945 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Tue, 17 Jan 2023 12:22:51 +0100 Subject: [PATCH] Bluetooth: Mesh: Stop scanner before resetting mesh When we receive Node Reset message, we schedule work in the system workqueue to call bt_mesh_reset(). In bt_mesh_reset() we call bt_conn_disconnect() to disconnect proxy client. bt_conn_disconnect() will put a buffer to a pool and call k_sem_take to let BT HCI TX thread process this buffer. Because we stop scanner after disconnecting the proxy, we can still receive a message at this point. Since BT RX thread has higher priority than the system workqueue, if we receive a message while in bt_mesh_reset(), it will be processed when we call bt_conn_disconnect(). Stop scanner before resetting the mesh to avoid processing of a received mesh message while in the process of resetting mesh. Signed-off-by: Pavel Vasilyev --- subsys/bluetooth/mesh/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/main.c b/subsys/bluetooth/mesh/main.c index 71975580baf..0e24bfe3b95 100644 --- a/subsys/bluetooth/mesh/main.c +++ b/subsys/bluetooth/mesh/main.c @@ -189,6 +189,8 @@ void bt_mesh_reset(void) memset(bt_mesh.flags, 0, sizeof(bt_mesh.flags)); atomic_set_bit(bt_mesh.flags, BT_MESH_INIT); + bt_mesh_scan_disable(); + /* If this fails, the work handler will return early on the next * execution, as the device is not provisioned. If the device is * reprovisioned, the timer is always restarted. @@ -231,7 +233,6 @@ void bt_mesh_reset(void) (void)memset(bt_mesh.dev_key, 0, sizeof(bt_mesh.dev_key)); - bt_mesh_scan_disable(); bt_mesh_beacon_disable(); bt_mesh_comp_unprovision();