mesh: Update the behavior of --io option
authorInga Stotland <inga.stotland@gmail.com>
Fri, 5 May 2023 19:39:31 +0000 (12:39 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 5 Jan 2024 10:41:34 +0000 (16:11 +0530)
This aligns the behavior of command line option --io to
add new "auto" value and modify the behavior of "generic"
value:

*auto* - Use first available controller: via MGMT interface
if kernel supports it, otherwise, via raw HCI socket (i.e.,
default to *generic*).

*generic:[hci]<index>* - Use generic HCI io on interface hci<index>

The default value is now *auto*, whereas *generic* is used
only if the specific HCI controller is explicitly specified.

mesh/bluetooth-meshd.rst.in
mesh/main.c
mesh/mesh-io-generic.c
mesh/mesh-io.c
mesh/mesh-mgmt.c
mesh/mesh-mgmt.h

index 06cdb69..7615367 100644 (file)
@@ -36,14 +36,17 @@ OPTIONS
 -i <type>, --io <type>
     Specifies I/O interface type:
 
-    *hci<index>* - Use generic HCI io on interface hci<index>,
-    or, if no idex is specified, the first available one.
+    *auto* - Use first available controller: via MGMT interface
+    if kernel supports it, otherwise, via raw HCI socket.
+
+    *generic:[hci]<index>* - Use generic HCI io on interface
+    hci<index>.
 
     *unit:<fd_path>*- Specifies open file descriptor for
     daemon testing.
 
-    By default, if no type is specified, uses generic I/O
-    on the first available HCI interface.
+    By default, if no type is specified, uses auto I/O
+    on the first available controller.
 
 -c <file>, --config <file>
     Specifies an explicit config file path instead of relying on the
index ec2400c..d8389a1 100644 (file)
@@ -51,6 +51,12 @@ static const struct option main_options[] = {
        { }
 };
 
+static const char *io_usage =
+              "\t(auto | generic:[hci]<index> | unit:<fd_path>)\n"
+              "\t\tauto - Use first available controller (MGMT or raw HCI)\n"
+              "\t\tgeneric - Use raw HCI io on interface hci<index>\n"
+              "\t\tunit - Use test IO (for automatic testing only)\n";
+
 static void usage(void)
 {
        fprintf(stderr,
@@ -58,18 +64,14 @@ static void usage(void)
               "\tbluetooth-meshd [options]\n");
        fprintf(stderr,
                "Options:\n"
-              "\t--io <io>         Use specified io (default: generic)\n"
+              "\t--io <io>         Use specified io (default: auto)\n"
               "\t--config          Daemon configuration directory\n"
               "\t--storage         Mesh node(s) configuration directory\n"
               "\t--nodetach        Run in foreground\n"
               "\t--debug           Enable debug output\n"
               "\t--dbus-debug      Enable D-Bus debugging\n"
               "\t--help            Show %s information\n", __func__);
-       fprintf(stderr,
-              "io:\n"
-              "\t([hci]<index> | generic[:[hci]<index>] | unit:<fd_path>)\n"
-              "\t\tUse generic HCI io on interface hci<index>, or the first\n"
-              "\t\tavailable one\n");
+       fprintf(stderr, "\n\t io: %s", io_usage);
 }
 
 static void do_debug(const char *str, void *user_data)
@@ -167,21 +169,8 @@ static bool parse_io(const char *optarg, enum mesh_io_type *type, void **opts)
                *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;
+               *index = MGMT_INDEX_NONE;
+               return true;
 
                return false;
                } else if (strstr(optarg, "generic") == optarg) {
@@ -191,12 +180,7 @@ static bool parse_io(const char *optarg, enum mesh_io_type *type, void **opts)
                *type = MESH_IO_TYPE_GENERIC;
 
                optarg += strlen("generic");
-               if (!*optarg) {
-                       *index = MGMT_INDEX_NONE;
-                       return true;
-               }
-
-               if (*optarg != ':')
+               if (!*optarg || *optarg != ':')
                        return false;
 
                optarg++;
@@ -311,7 +295,7 @@ int main(int argc, char *argv[])
                io = l_strdup_printf("auto");
 
        if (!parse_io(io, &io_type, &io_opts)) {
-               l_error("Invalid io: %s", io);
+               l_error("Invalid io: %s\n%s", io, io_usage);
                status = EXIT_FAILURE;
                goto done;
        }
index 2c026c7..fdffa5e 100644 (file)
@@ -391,6 +391,9 @@ static void hci_init(void *user_data)
        if (io->pvt->hci)
                bt_hci_unref(io->pvt->hci);
 
+       /* Clear controller HCI list to suppress mgmt interface warnings */
+       mesh_mgmt_clear();
+
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        if (io->pvt->use_raw) {
                l_debug("Use HCI RAW channel");
index baba32d..67fbdbe 100644 (file)
@@ -71,12 +71,20 @@ static void ctl_alert(int index, bool up, bool pwr, bool mesh, void *user_data)
 {
        enum mesh_io_type type = L_PTR_TO_UINT(user_data);
        const struct mesh_io_api *api = NULL;
-       l_warn("up:%d pwr: %d mesh: %d", up, pwr, mesh);
+       l_warn("index %u up:%d pwr: %d mesh: %d", index, up, pwr, mesh);
 
        /* If specific IO controller requested, honor it */
-       if (default_io->favored_index != MGMT_INDEX_NONE &&
-                                       default_io->favored_index != index)
-               return;
+       if (default_io->favored_index != MGMT_INDEX_NONE) {
+               if (default_io->favored_index != index)
+                       return;
+
+               if (!up | pwr) {
+                       l_warn("HCI%u failed to start generic IO %s",
+                               index, pwr ? ": already powered on" : "");
+                       if (default_io->ready)
+                               default_io->ready(default_io->user_data, false);
+               }
+       }
 
        if (!up && default_io->index == index) {
                /* Our controller has disappeared */
@@ -103,7 +111,6 @@ static void ctl_alert(int index, bool up, bool pwr, bool mesh, void *user_data)
                default_io->index = index;
                default_io->api = api;
                api->init(default_io, &index, default_io->user_data);
-
                l_queue_foreach(default_io->rx_regs, refresh_rx, default_io);
        }
 }
index 33c69cc..cd2528b 100644 (file)
@@ -311,3 +311,8 @@ bool mesh_mgmt_unregister(unsigned int id)
 {
        return mgmt_unregister(mgmt_mesh, id);
 }
+
+void mesh_mgmt_clear(void)
+{
+       l_queue_clear(ctl_list, l_free);
+}
index 811f87e..2cfc0fd 100644 (file)
@@ -22,6 +22,7 @@ unsigned int mesh_mgmt_register(uint16_t event, uint16_t index,
                                void *user_data, mgmt_destroy_func_t destroy);
 bool mesh_mgmt_unregister(unsigned int id);
 void mesh_mgmt_destroy(void);
+void mesh_mgmt_clear(void);
 
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
 bool set_powered(uint16_t mode, int index);