diff options
author | MichaĆ Lowas-Rzechonek <michal.lowas-rzechonek@silvair.com> | 2019-06-24 09:32:28 +0200 |
---|---|---|
committer | Brian Gix <brian.gix@intel.com> | 2019-06-24 09:04:44 -0700 |
commit | 12b984d1d4d47a8fd5bc8455d586bb208b804ebf (patch) | |
tree | 9ea739eea2eeffafcdfd5186e3f9d8f76ed2aae6 /mesh/mesh-io-generic.c | |
parent | ee70e5e070505e7caef66e9446ac586c378bde0f (diff) | |
download | bluez-12b984d1d4d47a8fd5bc8455d586bb208b804ebf.tar.gz |
mesh: Move HCI handling to mesh-io-generic
This patch separates 'mesh' module from 'mesh_io', particularly
regarding configuration and initialization.
Main code is no longer aware of MGMT and HCI usage - querying available
HCI interfaces now happens in mesh-io-generic.
MGMT code is now extracted into mesh-mgmt module, which mesh-io-generic
uses to query interfaces.
Diffstat (limited to 'mesh/mesh-io-generic.c')
-rw-r--r-- | mesh/mesh-io-generic.c | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/mesh/mesh-io-generic.c b/mesh/mesh-io-generic.c index 756dceabc..42aaa0947 100644 --- a/mesh/mesh-io-generic.c +++ b/mesh/mesh-io-generic.c @@ -26,7 +26,10 @@ #include "monitor/bt.h" #include "src/shared/hci.h" +#include "lib/bluetooth.h" +#include "lib/mgmt.h" +#include "mesh/mesh-mgmt.h" #include "mesh/mesh-io.h" #include "mesh/mesh-io-api.h" #include "mesh/mesh-io-generic.h" @@ -278,40 +281,52 @@ static void configure_hci(struct mesh_io_private *io) sizeof(cmd), hci_generic_callback, NULL, NULL); } -static bool dev_init(uint16_t index, struct mesh_io *io) +static bool hci_init(struct mesh_io *io) { - struct mesh_io_private *tmp; - - if (!io || io->pvt) + io->pvt->hci = bt_hci_new_user_channel(io->pvt->index); + if (!io->pvt->hci) { + l_error("Failed to start mesh io (hci %u)", io->pvt->index); return false; + } - tmp = l_new(struct mesh_io_private, 1); + configure_hci(io->pvt); - if (tmp == NULL) - return false; + 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); + return true; +} + +static void read_info(int index, void *user_data) +{ + struct mesh_io *io = user_data; - tmp->rx_regs = l_queue_new(); - tmp->tx_pkts = l_queue_new(); - if (!tmp->rx_regs || !tmp->tx_pkts) - goto fail; + if (io->pvt->index != MGMT_INDEX_NONE && + index != io->pvt->index) { + l_debug("Ignore index %d", index); + return; + } - tmp->hci = bt_hci_new_user_channel(index); - if (!tmp->hci) - goto fail; + io->pvt->index = index; + hci_init(io); +} - configure_hci(tmp); +static bool dev_init(struct mesh_io *io, void *opts) +{ + if (!io || io->pvt) + return false; - bt_hci_register(tmp->hci, BT_HCI_EVT_LE_META_EVENT, - event_callback, io, NULL); + io->pvt = l_new(struct mesh_io_private, 1); + io->pvt->index = *(int *)opts; - io->pvt = tmp; - return true; + io->pvt->rx_regs = l_queue_new(); + io->pvt->tx_pkts = l_queue_new(); -fail: - l_queue_destroy(tmp->rx_regs, l_free); - l_queue_destroy(tmp->tx_pkts, l_free); - l_free(tmp); - return false; + if (io->pvt->index == MGMT_INDEX_NONE) + return mesh_mgmt_list(read_info, io); + else + return hci_init(io); } static bool dev_destroy(struct mesh_io *io) |