From: Brian Gix <brian.gix@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: brian.gix@intel.com, inga.stotland@intel.com
Subject: [PATCH 5/7] mesh: Added default "auto" to command line parsing
Date: Wed, 23 Feb 2022 18:06:22 -0800 [thread overview]
Message-ID: <20220224020624.159247-6-brian.gix@intel.com> (raw)
In-Reply-To: <20220224020624.159247-1-brian.gix@intel.com>
While it will still be possible to request the "unit" and "hci"
based transports, "auto" has been added as a default to specify
"best choice" as determined by MGMT based enumeration of available
controllers.
---
mesh/main.c | 39 +++++++++++++++++++++++++++++++++++----
mesh/mesh.c | 6 +++++-
mesh/mesh.h | 2 +-
3 files changed, 41 insertions(+), 6 deletions(-)
diff --git a/mesh/main.c b/mesh/main.c
index dd99c3085..619b17d88 100644
--- a/mesh/main.c
+++ b/mesh/main.c
@@ -123,6 +123,12 @@ static void disconnect_callback(void *user_data)
l_main_quit();
}
+static void kill_to(struct l_timeout *timeout, void *user_data)
+{
+ l_timeout_remove(timeout);
+ l_main_quit();
+}
+
static void signal_handler(uint32_t signo, void *user_data)
{
static bool terminated;
@@ -131,13 +137,38 @@ static void signal_handler(uint32_t signo, void *user_data)
return;
l_info("Terminating");
- l_main_quit();
+ mesh_cleanup(true);
+ l_timeout_create(1, kill_to, NULL, NULL);
terminated = true;
}
static bool parse_io(const char *optarg, enum mesh_io_type *type, void **opts)
{
- if (strstr(optarg, "generic") == optarg) {
+ if (strstr(optarg, "auto") == optarg) {
+ int *index = l_new(int, 1);
+
+ *type = MESH_IO_TYPE_AUTO;
+ *opts = index;
+
+ optarg += strlen("auto");
+ if (!*optarg) {
+ *index = MGMT_INDEX_NONE;
+ return true;
+ }
+
+ if (*optarg != ':')
+ return false;
+
+ optarg++;
+
+ if (sscanf(optarg, "hci%d", index) == 1)
+ return true;
+
+ if (sscanf(optarg, "%d", index) == 1)
+ return true;
+
+ return false;
+ } else if (strstr(optarg, "generic") == optarg) {
int *index = l_new(int, 1);
*type = MESH_IO_TYPE_GENERIC;
@@ -251,7 +282,7 @@ int main(int argc, char *argv[])
}
if (!io)
- io = l_strdup_printf("generic");
+ io = l_strdup_printf("auto");
if (!parse_io(io, &io_type, &io_opts)) {
l_error("Invalid io: %s", io);
@@ -295,7 +326,7 @@ done:
l_free(io);
l_free(io_opts);
- mesh_cleanup();
+ mesh_cleanup(false);
l_dbus_destroy(dbus);
l_main_exit();
diff --git a/mesh/mesh.c b/mesh/mesh.c
index 62d650328..91cf25175 100644
--- a/mesh/mesh.c
+++ b/mesh/mesh.c
@@ -324,11 +324,15 @@ static void free_pending_join_call(bool failed)
join_pending = NULL;
}
-void mesh_cleanup(void)
+void mesh_cleanup(bool signaled)
{
struct l_dbus_message *reply;
mesh_io_destroy(mesh.io);
+ mesh.io = NULL;
+
+ if (signaled)
+ return;
if (join_pending) {
diff --git a/mesh/mesh.h b/mesh/mesh.h
index 0f77ebc58..c30a8d1f0 100644
--- a/mesh/mesh.h
+++ b/mesh/mesh.h
@@ -28,7 +28,7 @@ typedef void (*prov_rx_cb_t)(void *user_data, const uint8_t *data,
bool mesh_init(const char *config_dir, const char *mesh_conf_fname,
enum mesh_io_type type, void *opts,
mesh_ready_func_t cb, void *user_data);
-void mesh_cleanup(void);
+void mesh_cleanup(bool signaled);
bool mesh_dbus_init(struct l_dbus *dbus);
const char *mesh_status_str(uint8_t err);
--
2.35.1
next prev parent reply other threads:[~2022-02-24 2:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-24 2:06 [PATCH 0/7] Kernel based mesh functionality Brian Gix
2022-02-24 2:06 ` [PATCH 1/7] mgmt: Add support for Mesh in the kernel Brian Gix
2022-02-26 9:38 ` Kernel based mesh functionality bluez.test.bot
2022-02-24 2:06 ` [PATCH 2/7] mgmt: Mesh specific structures and defines Brian Gix
2022-02-24 2:06 ` [PATCH 3/7] mesh: Add common MGMT command accessors Brian Gix
2022-02-24 2:06 ` [PATCH 4/7] mesh: rework Mesh-IO for multiple transports Brian Gix
2022-02-24 2:06 ` Brian Gix [this message]
2022-02-24 2:06 ` [PATCH 6/7] mesh: Add new MGMT based IO transport Brian Gix
2022-02-24 2:06 ` [PATCH 7/7] mesh: Make Provisioning requests more IO compatible Brian Gix
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220224020624.159247-6-brian.gix@intel.com \
--to=brian.gix@intel.com \
--cc=inga.stotland@intel.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.