@@ -22,6 +22,7 @@ struct mesh_io_private;
typedef bool (*mesh_io_init_t)(struct mesh_io *io, void *opts,
mesh_io_ready_func_t cb, void *user_data);
typedef bool (*mesh_io_destroy_t)(struct mesh_io *io);
+typedef bool (*mesh_io_restart_t)(struct mesh_io *io);
typedef bool (*mesh_io_caps_t)(struct mesh_io *io, struct mesh_io_caps *caps);
typedef bool (*mesh_io_send_t)(struct mesh_io *io,
struct mesh_io_send_info *info,
@@ -37,6 +38,7 @@ typedef bool (*mesh_io_tx_cancel_t)(struct mesh_io *io, const uint8_t *pattern,
struct mesh_io_api {
mesh_io_init_t init;
mesh_io_destroy_t destroy;
+ mesh_io_restart_t restart;
mesh_io_caps_t caps;
mesh_io_send_t send;
mesh_io_register_t reg;
@@ -769,6 +769,26 @@ static bool find_active(const void *a, const void *b)
return false;
}
+static bool dev_restart(struct mesh_io *io)
+{
+ struct bt_hci_cmd_le_set_scan_enable cmd;
+ struct mesh_io_private *pvt = io->pvt;
+
+ if (!pvt)
+ return false;
+
+ if (l_queue_isempty(pvt->rx_regs))
+ return true;
+
+ pvt->active = l_queue_find(pvt->rx_regs, find_active, NULL);
+ cmd.enable = 0x00; /* Disable scanning */
+ cmd.filter_dup = 0x00; /* Report duplicates */
+ bt_hci_send(pvt->hci, BT_HCI_CMD_LE_SET_SCAN_ENABLE,
+ &cmd, sizeof(cmd), scan_disable_rsp, pvt, NULL);
+
+ return true;
+}
+
static bool recv_register(struct mesh_io *io, const uint8_t *filter,
uint8_t len, mesh_io_recv_func_t cb, void *user_data)
{
@@ -845,6 +865,7 @@ static bool recv_deregister(struct mesh_io *io, const uint8_t *filter,
const struct mesh_io_api mesh_io_generic = {
.init = dev_init,
.destroy = dev_destroy,
+ .restart = dev_restart,
.caps = dev_caps,
.send = send_tx,
.reg = recv_register,
@@ -96,6 +96,14 @@ fail:
return NULL;
}
+void mesh_io_restart(struct mesh_io *io)
+{
+ io = l_queue_find(io_list, match_by_io, io);
+
+ if (io && io->api)
+ io->api->restart(io);
+}
+
void mesh_io_destroy(struct mesh_io *io)
{
io = l_queue_remove_if(io_list, match_by_io, io);
@@ -83,6 +83,7 @@ typedef void (*mesh_io_ready_func_t)(void *user_data, bool result);
struct mesh_io *mesh_io_new(enum mesh_io_type type, void *opts,
mesh_io_ready_func_t cb, void *user_data);
+void mesh_io_restart(struct mesh_io *io);
void mesh_io_destroy(struct mesh_io *io);
bool mesh_io_get_caps(struct mesh_io *io, struct mesh_io_caps *caps);
@@ -66,6 +66,7 @@ struct bt_mesh {
uint16_t req_index;
uint8_t friend_queue_sz;
uint8_t max_filters;
+ bool initialized;
};
struct join_data{
@@ -91,7 +92,8 @@ static struct bt_mesh mesh = {
.lpn_support = false,
.proxy_support = false,
.crpl = DEFAULT_CRPL,
- .friend_queue_sz = DEFAULT_FRIEND_QUEUE_SZ
+ .friend_queue_sz = DEFAULT_FRIEND_QUEUE_SZ,
+ .initialized = false
};
/* We allow only one outstanding Join request */
@@ -168,9 +170,17 @@ static void io_ready_callback(void *user_data, bool result)
{
struct mesh_init_request *req = user_data;
+ if (mesh.initialized) {
+ if (result)
+ mesh_io_restart(mesh.io);
+ return;
+ }
+
if (result)
node_attach_io_all(mesh.io);
+ mesh.initialized = true;
+
req->cb(req->user_data, result);
l_free(req);