diff options
author | Inga Stotland <inga.stotland@intel.com> | 2019-11-14 15:52:10 -0800 |
---|---|---|
committer | Brian Gix <brian.gix@intel.com> | 2019-11-15 09:23:16 -0800 |
commit | dcc46d4cee21a711e781e493ca50cf70b74bd020 (patch) | |
tree | bfe1bdf313cf6ecc4090e452b1708d0c1dacc98a /mesh/mesh.c | |
parent | d64f6c885580ef23eb28e53edf1a007bb3628804 (diff) | |
download | bluez-dcc46d4cee21a711e781e493ca50cf70b74bd020.tar.gz |
mesh: Fix io inititalization sequence
This introduces a chain of callbacks to indicate whether mesh io
is initialized and mesh network is ready to use.
This fixes the reported situation when the receive callbacks
were setup before the HCI was fully initialized. In other words,
BT_HCI_CMD_LE_SET_SCAN_PARAMETERS was called before BT_HCI_CMD_RESET
and, as the result, the callback issueing BT_HCI_CMD_LE_SET_SCAN_ENABLE
command was not called.
Diffstat (limited to 'mesh/mesh.c')
-rw-r--r-- | mesh/mesh.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/mesh/mesh.c b/mesh/mesh.c index 9b2b2073b..55204da56 100644 --- a/mesh/mesh.c +++ b/mesh/mesh.c @@ -70,6 +70,11 @@ struct join_data{ uint8_t *uuid; }; +struct mesh_init_request { + mesh_ready_func_t cb; + void *user_data; +}; + static struct bt_mesh mesh; /* We allow only one outstanding Join request */ @@ -138,9 +143,23 @@ void mesh_unreg_prov_rx(prov_rx_cb_t cb) mesh_io_deregister_recv_cb(mesh.io, MESH_IO_FILTER_PROV); } -bool mesh_init(const char *config_dir, enum mesh_io_type type, void *opts) +static void io_ready_callback(void *user_data, bool result) +{ + struct mesh_init_request *req = user_data; + + if (result) + node_attach_io_all(mesh.io); + + req->cb(req->user_data, result); + + l_free(req); +} + +bool mesh_init(const char *config_dir, enum mesh_io_type type, void *opts, + mesh_ready_func_t cb, void *user_data) { struct mesh_io_caps caps; + struct mesh_init_request *req; if (mesh.io) return true; @@ -159,16 +178,20 @@ bool mesh_init(const char *config_dir, enum mesh_io_type type, void *opts) if (!node_load_from_storage(storage_dir)) return false; - mesh.io = mesh_io_new(type, opts); - if (!mesh.io) + req = l_new(struct mesh_init_request, 1); + req->cb = cb; + req->user_data = user_data; + + mesh.io = mesh_io_new(type, opts, io_ready_callback, req); + if (!mesh.io) { + l_free(req); return false; + } l_debug("io %p", mesh.io); mesh_io_get_caps(mesh.io, &caps); mesh.max_filters = caps.max_num_filters; - node_attach_io_all(mesh.io); - return true; } |