summaryrefslogtreecommitdiff
path: root/mesh/mesh-io-generic.c
diff options
context:
space:
mode:
authorBrian Gix <brian.gix@intel.com>2022-09-22 15:31:02 -0700
committerBrian Gix <brian.gix@intel.com>2022-09-26 13:14:47 -0700
commit9966cb8b6999a5f54fc13acbd7e1526512a84342 (patch)
tree340ca4b754716a30e8fb29a07423e31c8f704864 /mesh/mesh-io-generic.c
parent491be481a91c39d31f7908da8a2beea60237646e (diff)
downloadbluez-9966cb8b6999a5f54fc13acbd7e1526512a84342.tar.gz
mesh: Add new kernel MGMT based IO transport
1. Re-structures MGMT handling such that it is used to detect kernel support of the mesh MGMT opcodes and events before selecting between using MGMT or the legacy raw HCI socket method. 2. Re-structures main() to allow command line to prefer MGMT over HCI or visa versa, plus optionally pass an explicte controller. 3. Adds mesh-io-mgmt as a transport.
Diffstat (limited to 'mesh/mesh-io-generic.c')
-rw-r--r--mesh/mesh-io-generic.c47
1 files changed, 11 insertions, 36 deletions
diff --git a/mesh/mesh-io-generic.c b/mesh/mesh-io-generic.c
index 2d7ef261e..827128ec8 100644
--- a/mesh/mesh-io-generic.c
+++ b/mesh/mesh-io-generic.c
@@ -19,6 +19,7 @@
#include "monitor/bt.h"
#include "src/shared/hci.h"
+#include "src/shared/mgmt.h"
#include "lib/bluetooth.h"
#include "lib/mgmt.h"
@@ -29,14 +30,12 @@
#include "mesh/mesh-io-generic.h"
struct mesh_io_private {
+ struct mesh_io *io;
struct bt_hci *hci;
- void *user_data;
- mesh_io_ready_func_t ready_callback;
struct l_timeout *tx_timeout;
struct l_queue *rx_regs;
struct l_queue *tx_pkts;
struct tx_pkt *tx;
- uint16_t index;
uint16_t interval;
bool sending;
bool active;
@@ -385,16 +384,13 @@ static void hci_init(void *user_data)
{
struct mesh_io *io = user_data;
bool result = true;
- bool restarted = false;
- if (io->pvt->hci) {
- restarted = true;
+ if (io->pvt->hci)
bt_hci_unref(io->pvt->hci);
- }
- io->pvt->hci = bt_hci_new_user_channel(io->pvt->index);
+ io->pvt->hci = bt_hci_new_user_channel(io->index);
if (!io->pvt->hci) {
- l_error("Failed to start mesh io (hci %u): %s", io->pvt->index,
+ l_error("Failed to start mesh io (hci %u): %s", io->index,
strerror(errno));
result = false;
}
@@ -405,47 +401,26 @@ static void hci_init(void *user_data)
bt_hci_register(io->pvt->hci, BT_HCI_EVT_LE_META_EVENT,
event_callback, io, NULL);
- l_debug("Started mesh on hci %u", io->pvt->index);
+ l_debug("Started mesh on hci %u", io->index);
- if (restarted)
- restart_scan(io->pvt);
+ restart_scan(io->pvt);
}
- if (io->pvt->ready_callback)
- io->pvt->ready_callback(io->pvt->user_data, result);
+ if (io->ready)
+ io->ready(io->user_data, result);
}
-static void read_info(int index, void *user_data)
-{
- struct mesh_io *io = user_data;
-
- if (io->pvt->index != MGMT_INDEX_NONE &&
- index != io->pvt->index) {
- l_debug("Ignore index %d", index);
- return;
- }
-
- io->pvt->index = index;
- hci_init(io);
-}
-
-static bool dev_init(struct mesh_io *io, void *opts,
- mesh_io_ready_func_t cb, void *user_data)
+static bool dev_init(struct mesh_io *io, void *opts, void *user_data)
{
if (!io || io->pvt)
return false;
io->pvt = l_new(struct mesh_io_private, 1);
- io->pvt->index = *(int *)opts;
io->pvt->rx_regs = l_queue_new();
io->pvt->tx_pkts = l_queue_new();
- io->pvt->ready_callback = cb;
- io->pvt->user_data = user_data;
-
- if (io->pvt->index == MGMT_INDEX_NONE)
- return mesh_mgmt_list(read_info, io);
+ io->pvt->io = io;
l_idle_oneshot(hci_init, io, NULL);