Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3887937ybl; Mon, 13 Jan 2020 04:28:08 -0800 (PST) X-Google-Smtp-Source: APXvYqx1tgYeC87LxLFuVdEWlM70idn45B3MRX4bda8zZPHgMKNEEbTkHpN/STIsL59DwmvSuTcF X-Received: by 2002:a9d:6f11:: with SMTP id n17mr12504868otq.126.1578918488152; Mon, 13 Jan 2020 04:28:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578918488; cv=none; d=google.com; s=arc-20160816; b=PiVoCtlFBjkTbGexPW84YV5yw7KbXVYeVS053a6KM8TxBeVucyQyD6mO2i1XYpUE1a 0OzvBTmE+zpOJHOs47+jpoTkXV/PIsDZQikf+tdkLEJnnTQ5Lygl0I4Um723uGfUsPYe l1nURFqoDnXVBdbSOgG0rzxJ1LNGcHQxuyTVzJCKRZeJ7QCCGVFF7DyWJzevYLwWwzTN SSjRZvxV7PTzGh6YRNuOi1+r0K5jzBuZIp4Z8H3bWkU3DEVVLKdZo5G0BOu1vjfv3to5 dpcdZXp86zq6nq+CXkErrklVKci14Rp7K7C7zqRQyHt5vEcZt2OPPebhMefHb/ruuEF6 Npjw== 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 :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=QvN5JmzmAn+sWS392TnYXp0i/9dMEJWaZaNmD4tvczg=; b=Us1wtXaQieOQFX/+AdnGVPFhks9nHF1K8AslsfUN/eC3r4OYxWqdNIL1QoUTUmzjQS 4uI8AtQ+KKiY83jsC+pIq8eXKm+R871GKWvvY4iI6qW9ooC1mpqPo2Vx7nuYWflJ6l1f 8Ql6tjsndyrPqJ2rC1f5hq0Z0n+8H1+USOgBqLa0+GipajucKr13WYltFGoqbMH66y9S I1BKciNElKdVgvJUPKI79A/Dw2SrYIXOPZiQ10dNzrcQC6bRI1hYjyAFgsLL+DpVdydL 4BKILxEzs2azDwSRuQaIHFbgEmOKM56V2ryXvY2dlS4dMXtFN1QevKgZTdhBOeR8PqFm b2Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=vf30F3jR; 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 n8si6773009otr.102.2020.01.13.04.27.45; Mon, 13 Jan 2020 04:28:08 -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=vf30F3jR; 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 S1725832AbgAMM1i (ORCPT + 99 others); Mon, 13 Jan 2020 07:27:38 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:35940 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726399AbgAMM1i (ORCPT ); Mon, 13 Jan 2020 07:27:38 -0500 Received: by mail-lf1-f68.google.com with SMTP id n12so6715714lfe.3 for ; Mon, 13 Jan 2020 04:27:36 -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:in-reply-to:references:mime-version :content-transfer-encoding; bh=QvN5JmzmAn+sWS392TnYXp0i/9dMEJWaZaNmD4tvczg=; b=vf30F3jRzPBhoFO4npNv4n9bJ9UlZZl23kZRIkRQ1z+Y4PvKgbrNXEYNwwidwugu1K lE5KxALiaxWTiQEMu1psqrjoQT7n9YTjXG/euERIcosywu0aFxUDHlQvVG/epaeflvLK Yj9YQuPDPcExVGoTAXGa+4M1wU582EywrE4oGx11MQi+dRC9beHxskyrlDj2EG6bXR50 LQ9QQ199jbk0t9P38qX1ixn2Rl9Y12Wi+Pplpf4XoWLi4HejSlA62nciZbs91u9t3J6m qEe7jstz3V2lBn1atIE5wUZZ1dmtmTTBO/uOFVyMU8o2wLLa9Ct13g62Zdevb05ZcemF aWlg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=QvN5JmzmAn+sWS392TnYXp0i/9dMEJWaZaNmD4tvczg=; b=C0z0sT7JgP/p8+7C3riw+xzeFNE5xxr+SsLtK6MkQT4bjPseNHBmx9yllOTiXCotGD m+tLUC8IPfB19thWIR6X5ZWZs4KsEKMTxGwckR2nZzKo9boqmey2tpP2iWE4qPZaciNz wh+sCQR+ik/KB/gKux2LKtOaxk50vMuiaIU5N66/4O4Kb4du2YV2m6Nm6t62ZP+47UNy tt92czheKC1WGLuj+JDishudHoTl5A1a0Sq1YHqlYfS/NP25PaG/RYy0WHmndK3wcQDU YRJzowKGGIABn2oqfdfOsum2R2xUrzMJ8fOLJI/aSH4S8A+3Ho+B5GbIQqlk19dynsvx ifOw== X-Gm-Message-State: APjAAAUpnBl2r1w1Kf+gGObloURrD9ikZX2oolLbQW58xdY26bjPsxLu v6+SCkoPLUclRvthW8mJUIzwnjl1H6Q= X-Received: by 2002:a19:ec14:: with SMTP id b20mr9298192lfa.63.1578918455862; Mon, 13 Jan 2020 04:27:35 -0800 (PST) Received: from mlowasrzechonek2133.silvair.lan ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id l7sm5571758lfc.80.2020.01.13.04.27.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2020 04:27:35 -0800 (PST) From: =?UTF-8?q?Micha=C5=82=20Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH RESEND BlueZ 1/1] mesh: Add --io option Date: Mon, 13 Jan 2020 13:27:25 +0100 Message-Id: <20200113122726.768-2-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200113122726.768-1-michal.lowas-rzechonek@silvair.com> References: <20200113122726.768-1-michal.lowas-rzechonek@silvair.com> 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. By default, meshd runs with MESH_IO_TYPE_GENERIC and tries to attach to the first available HCI interface. Option "--index=" is now just a shortcut for "--io=generic:" --- mesh/main.c | 99 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 81 insertions(+), 18 deletions(-) diff --git a/mesh/main.c b/mesh/main.c index 010edcf85..243e756f9 100644 --- a/mesh/main.c +++ b/mesh/main.c @@ -40,10 +40,12 @@ 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 +56,23 @@ 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--index Equivalent of `--io=generic:`\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" + "\tgeneric[:]\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 +109,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 +142,44 @@ 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; if (!l_main_init()) return -1; @@ -153,7 +194,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 +201,20 @@ int main(int argc, char *argv[]) switch (opt) { case 'i': - if (strlen(optarg) > 3 && !strncmp(optarg, "hci", 3)) - str = optarg + 3; - else - str = optarg; - if (!isdigit(*str)) { - l_error("Invalid controller index value"); - status = EXIT_FAILURE; + if (io) { + l_error("Use either --index or --io, not both"); + status = EXIT_SUCCESS; goto done; } - - ctlr_index = atoi(str); - + io = l_strdup_printf("generic:%s", optarg); + break; + case 'I': + if (io) { + l_error("Use either --index or --io, not both"); + status = EXIT_SUCCESS; + goto done; + } + io = l_strdup(optarg); break; case 'n': detached = false; @@ -200,6 +242,21 @@ 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 ((io_type == MESH_IO_TYPE_NONE) && !io_opts) { + int *index = l_new(int, 1); + *index = MGMT_INDEX_NONE; + io_type = MESH_IO_TYPE_GENERIC; + io_opts = index; + } if (!detached) umask(0077); @@ -225,6 +282,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