Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6384720ybl; Wed, 15 Jan 2020 03:51:43 -0800 (PST) X-Google-Smtp-Source: APXvYqxqPkqo3mg3SsLZynF4CHrsmp2RMQmsh6GY1V247zTqbfq6Ol4hSsDfQ9PL7kvuzHYtu0Ra X-Received: by 2002:a9d:7e8a:: with SMTP id m10mr2293750otp.27.1579089103452; Wed, 15 Jan 2020 03:51:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579089103; cv=none; d=google.com; s=arc-20160816; b=GiyorSedB61icps1TLHTkXrobPVpFH0kk0os5368Zaw9hnzQoQwqM+LgP3WW8Huj8M xRoXoUtpOvZRhSdQua+qP5ypIh9iHk396TAlBT2EdeIR/QMRknVKw8d07FOxGBKD0vWd WF/k1JtCfEa1hrYKn3mbA3uN2PaYutqL92r+0gH6aQcfHyIc7gbGEwDroYv57kzI1xAB oILVZVdrjVdFnUEGdfK5XsjvBeY0DF+8sPEDS2DcF9KmHtpFmiqeNIwWMdBjpm9pD1fy OPpuU+nWeVAMgaSnfC5RY/rkTFmp9lUywBp9c0v3FTGjYXKG9xkYBj+gIXkSInmvrEeX 24oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=3kAW6CuXLik4Dd8lYpo4G/qEALqscxuKG5AZ67rZeM8=; b=evkEx+oUD048icDaULAQKPvSvfAPKZZYvW6Y2RdZSnlpsK+WXjQr3lsurrzcC9+lmn qNIpXcwOoqCTrZNieTI0GgMLUAOyb3qyDLJJ/nLeFqXjGzHL2lMdpX+X/FXWGXlyohC7 DYDVpxmvFq6Lzy+1aLbi1uOrMh7RyH1zC+f2ElUI9ANxpbffkGxYt/u4j/6AZpS5m5kZ n/b0Yka1TQwOGCwJ04vdsUUhB2WZDKqHxDgQDknnF8UWCPNV1WDVu0S4dZviXzpnkW9E 2fnhXOXVNb7AKywxvndvBd5UFH8XDwRIuoye8mEOebU5a2S/O80pfHg1+TxOvtTs6lla SmKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=u71rJnqk; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si10777500otp.111.2020.01.15.03.51.14; Wed, 15 Jan 2020 03:51:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=u71rJnqk; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730134AbgAOLu7 (ORCPT + 99 others); Wed, 15 Jan 2020 06:50:59 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:44322 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729892AbgAOLu7 (ORCPT ); Wed, 15 Jan 2020 06:50:59 -0500 Received: by mail-wr1-f68.google.com with SMTP id q10so15431813wrm.11 for ; Wed, 15 Jan 2020 03:50:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=3kAW6CuXLik4Dd8lYpo4G/qEALqscxuKG5AZ67rZeM8=; b=u71rJnqkXryBSbATFcdu4mAAAhZvMQI+K4CYbTeeZSnmkBfvLqEyQg+DuvzQNpfaVp 2SDQNgX/raf7T1WCg9ToUwpvHU55t3kxIrY+OEQdoSF6sVu4RXV9vrzbKR9q/h0KRNcB EoJBfj1ZBM+Vihh6FuQYNc6DtSNdGpStii7LN3qDKFIxObusGG964LQxWioRnseKOyt0 FPME2VuoJbOYbCxiChePap1syFDCyH7RWEUrdxWxAHxFXTy1NITvbdEzrQZ53KufqBHq G8+JN29+mVFxvJhHh22q+Q8ReGHQD7gFzJHOoPa2X/rOw47kfZT3JhM7cU6N29oStgUM PoDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=3kAW6CuXLik4Dd8lYpo4G/qEALqscxuKG5AZ67rZeM8=; b=IcdgUONoD1vgUacP8SNjWl6FJs57TU+HiICm6Su6G7fZF62rpebNW3JE0sHWhKkpZb VF3ahvNttyXWXvPic1ozLZIT1d0NvPqPCTgifEvIh0KKQ7PxcQDqn3EzSeUTSWYXmQ96 788FChflb9P5XQ4uPTaTR7PUtE23Gue3VEpkmDsLT1IHvhXcuYUpc1pqMnYiifkyKOAf t5IrUxFNiMbc22ZxijH2Nl/NUQ1EwdE0wjznN5VQFnUR+d5+CCvliaRCEl6ON+qQH1tn CgLU0FtUkNS/GzLTiqL7hHB5JRMeot7fbKkAqckurANBtM3ZfxULps00tUvoDbaQVjdo k0iQ== X-Gm-Message-State: APjAAAX5qDUPxjQEoV32WKXxGyYYQGiifPkMt/khMVaMbwp5cwc6dN5e 628a35rBM83F+ELxQcg14dHgMRGw4Cw= X-Received: by 2002:adf:fe43:: with SMTP id m3mr31606022wrs.213.1579089054519; Wed, 15 Jan 2020 03:50:54 -0800 (PST) Received: from mlowasrzechonek2133.silvair.lan ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id z123sm24405987wme.18.2020.01.15.03.50.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2020 03:50:53 -0800 (PST) From: =?UTF-8?q?Micha=C5=82=20Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3] mesh: Rename --index to --io, allow additional io types types. Date: Wed, 15 Jan 2020 12:50:49 +0100 Message-Id: <20200115115049.27504-1-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This allows specifying io type and options when invoking the daemon. When no "-i" is passed, meshd still runs with MESH_IO_TYPE_GENERIC and tries to attach to the first available HCI interface. Options "-i " and "-i hci" are just shortcuts for "--io=generic:" and "--io=generic:hci", respectively. --- v3: Remove superfluous default configuration from main() mesh/main.c | 86 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 66 insertions(+), 20 deletions(-) diff --git a/mesh/main.c b/mesh/main.c index 010edcf85..598398e9a 100644 --- a/mesh/main.c +++ b/mesh/main.c @@ -40,10 +40,11 @@ static const char *config_dir; static const char *mesh_conf_fname; -static int ctlr_index = MGMT_INDEX_NONE; +static enum mesh_io_type io_type; +static void *io_opts; static const struct option main_options[] = { - { "index", required_argument, NULL, 'i' }, + { "io", required_argument, NULL, 'i' }, { "config", optional_argument, NULL, 'c' }, { "nodetach", no_argument, NULL, 'n' }, { "debug", no_argument, NULL, 'd' }, @@ -54,16 +55,22 @@ static const struct option main_options[] = { static void usage(void) { - l_info(""); - l_info("Usage:\n" + fprintf(stderr, + "Usage:\n" "\tbluetooth-meshd [options]\n"); - l_info("Options:\n" - "\t--index Use specified controller\n" + fprintf(stderr, + "Options:\n" + "\t--io Use specified io (default: generic)\n" "\t--config 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] | generic[:[hci]])\n" + "\t\tUse generic HCI io on interface hci, or the first\n" + "\t\tavailable one\n"); } static void do_debug(const char *str, void *user_data) @@ -100,8 +107,8 @@ static void request_name_callback(struct l_dbus *dbus, bool success, return; } - if (!mesh_init(config_dir, mesh_conf_fname, MESH_IO_TYPE_GENERIC, - &ctlr_index, mesh_ready_callback, dbus)) { + if (!mesh_init(config_dir, mesh_conf_fname, io_type, io_opts, + mesh_ready_callback, dbus)) { l_error("Failed to initialize mesh"); l_main_quit(); } @@ -133,12 +140,45 @@ static void signal_handler(uint32_t signo, void *user_data) terminated = true; } +static bool parse_io(const char *optarg, enum mesh_io_type *type, void **opts) +{ + if (strstr(optarg, "generic") == optarg) { + int *index = l_new(int, 1); + + *type = MESH_IO_TYPE_GENERIC; + *opts = index; + + optarg += strlen("generic"); + 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; + } + + return false; +} + int main(int argc, char *argv[]) { int status; bool detached = true; bool dbus_debug = false; struct l_dbus *dbus = NULL; + char *io = NULL; + int hci_index; if (!l_main_init()) return -1; @@ -153,7 +193,6 @@ int main(int argc, char *argv[]) for (;;) { int opt; - const char *str; opt = getopt_long(argc, argv, "i:c:f:ndbh", main_options, NULL); if (opt < 0) @@ -161,18 +200,11 @@ int main(int argc, char *argv[]) switch (opt) { case 'i': - if (strlen(optarg) > 3 && !strncmp(optarg, "hci", 3)) - str = optarg + 3; + if (sscanf(optarg, "hci%d", &hci_index) == 1 || + sscanf(optarg, "%d", &hci_index) == 1) + io = l_strdup_printf("generic:%s", optarg); else - str = optarg; - if (!isdigit(*str)) { - l_error("Invalid controller index value"); - status = EXIT_FAILURE; - goto done; - } - - ctlr_index = atoi(str); - + io = l_strdup(optarg); break; case 'n': detached = false; @@ -200,6 +232,14 @@ int main(int argc, char *argv[]) } } + if (!io) + io = l_strdup_printf("generic"); + + if (!parse_io(io, &io_type, &io_opts)) { + l_error("Invalid io: %s", io); + status = EXIT_FAILURE; + goto done; + } if (!detached) umask(0077); @@ -225,6 +265,12 @@ int main(int argc, char *argv[]) status = l_main_run_with_signal(signal_handler, NULL); done: + if (io) + l_free(io); + + if (io_opts) + l_free(io_opts); + mesh_cleanup(); l_dbus_destroy(dbus); l_main_exit(); -- 2.20.1