Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1351956rwr; Fri, 5 May 2023 12:45:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4UzPfWINW3ddCT03EdTVpInT9OazVhSAvCN83M/7Lm0E/uKhL0PRFWZsiPWsjqbcCHGWJB X-Received: by 2002:a17:90a:34c2:b0:247:1605:6e1a with SMTP id m2-20020a17090a34c200b0024716056e1amr3475174pjf.0.1683315914105; Fri, 05 May 2023 12:45:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683315914; cv=none; d=google.com; s=arc-20160816; b=gvEI1GWmlMeNUZ3BLSf7DiCP1UpkuEKDtJ+JRRPTV1rnjWYqzcNNnwNOTL8aWGu0t/ 4cJDkRjUTeRjjYchM9SCHqm1MVEsgvDUu/hVVPHHoM+qdRwlmh8PFOpIuAoKhJYbeVyx EJHZ/L4PjQMvmZpkg4mD7200ZWni8Fw8QbgFqL5+oYsBvRKW1B0hLRP7os4k0LwLn9b3 a2WYu2FAVQQdrKlMTfvDdsbSKOv25YVkZxbk4elEQmkO+O+NI27Eayj28qumObCyAsaW oRPrQqMnlUMl7a9k0ijWNEYlszLrc/xJgSjpVvNbJx4vc08p6ybRPwZlEnf1Qg5PU1Qw UHNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=QhQNBWqC9lqK4IiI6j/CljW1RluY+lMC35YxnIdFeQs=; b=NX6iVCyIEohJTlJcBP9QqrzrkYJ2seCiwSccyGdnEENgV5r12uEMs05bujkr4IfLCW WTXzj/3DZ0vaZDKeSa06Uv9l7mYn5xI5/u8d/2QbJdF9+BsXp4nFF/Inpct7dEwx5EmV B5FkYro+KAC9Pfg+SIcQuiwXg/0wU8kpeJyf76/V9CiHc3nQXrGw89OUjcK+UxemlVyp rWbFN8IqUSdA5v4Dynv99EfEG43v2egc6dtCCBxsiaHUO7cCRAZ1mIOCJG6IfMBSxUHz QCQvcHJbOui1H6rZ/A9ezvUSs432BKAiR/u2ADtuBu2DEZ/RWepYFfAR/YBUidqJw/sH 2Zpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=C1znX96v; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r21-20020a638f55000000b0052c40c2a985si2610678pgn.647.2023.05.05.12.44.48; Fri, 05 May 2023 12:45:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=C1znX96v; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233461AbjEETkG (ORCPT + 99 others); Fri, 5 May 2023 15:40:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233472AbjEETkC (ORCPT ); Fri, 5 May 2023 15:40:02 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D835C4C19 for ; Fri, 5 May 2023 12:39:59 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-64115eef620so22025727b3a.1 for ; Fri, 05 May 2023 12:39:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683315599; x=1685907599; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=QhQNBWqC9lqK4IiI6j/CljW1RluY+lMC35YxnIdFeQs=; b=C1znX96vq2D6zsGiCDdHB+tkXRrYdsBeWp/G6KOgex9O31MwkSQ9ShRdIPImidoqCz wsFFtGwT9r9+dZH9Z8Ws/dFwW/MADKcT756QtmNVa+5K4JBFnpOjTzzK2ywJtPtvX3ti BgKtl00bz45CAXP2q1y2erGcK3o1oYkXReQ67wyM8q6z4GJ95yDqGIVrNa3u+igeYJS/ Wn2vMAiR8jFKRyMUFbDz8YUM9EVFDaX6hSo24Pur5Kyp79RfMLnLvHQ4FFuZQj6FgeBG v3XYrzg2Y5p4tO1g/AOHdF5ElrH1f4CRwGjSnCZdFZFlOpIzoNgdim3vJmfWZ5L3v6lK 5dxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683315599; x=1685907599; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QhQNBWqC9lqK4IiI6j/CljW1RluY+lMC35YxnIdFeQs=; b=cpj6o6WeMjB9vqNVpmawvW+Q4wfDlxjTDVS5CDcvLHBSRURz6AGjDOlKYrzAoo6buo dd7Dwy0qdZOxa/R1AN8WThr0ob+RYLhRLCo74DlmbZCcvKdxOjZcgS2RM1qLm96ah9Ad g0S/84DMemrvKBf1MYDLbvC+z3qHou4oRvuq2hNksZpYo6s9ubrigzrOS9cbGV5jOtiV 6g9Zet1t0pjjcFUtN0Ym3Lw0x0LmLWYvolJ1vc4e4zo8GHgmv8kZiV9we7IOr7tSAIVR 3l1LA0EO95g9FQ/9gNpEOhzQgTsfI/Iu0ZRNgrJj6XpkhdJvtmO0tknBBrakxQMUWJrV 4vXA== X-Gm-Message-State: AC+VfDwp8bydD9SK7DWOqDKiRDp9f+oZawbw1Y3hZymGY86xNbubUByI lXTVClmsq4aqd/hLtyWVS1KZheEejZxpvw== X-Received: by 2002:a17:902:d505:b0:1a6:f93a:a136 with SMTP id b5-20020a170902d50500b001a6f93aa136mr9771664plg.22.1683315598938; Fri, 05 May 2023 12:39:58 -0700 (PDT) Received: from fedora.. ([2601:601:a480:c78::1000]) by smtp.googlemail.com with ESMTPSA id jk1-20020a170903330100b0019e60c645b1sm2140801plb.305.2023.05.05.12.39.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 12:39:58 -0700 (PDT) From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@gmail.com, Inga Stotland Subject: [PATCH BlueZ] mesh: Update the behavior of --io option Date: Fri, 5 May 2023 12:39:31 -0700 Message-Id: <20230505193931.106760-1-inga.stotland@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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]* - Use generic HCI io on interface hci The default value is now *auto*, whereas *generic* is used only if the specific HCI controller is explicitly specified. --- mesh/bluetooth-meshd.rst.in | 11 ++++++---- mesh/main.c | 40 +++++++++++-------------------------- mesh/mesh-io-generic.c | 3 +++ mesh/mesh-io.c | 17 +++++++++++----- mesh/mesh-mgmt.c | 5 +++++ mesh/mesh-mgmt.h | 1 + 6 files changed, 40 insertions(+), 37 deletions(-) diff --git a/mesh/bluetooth-meshd.rst.in b/mesh/bluetooth-meshd.rst.in index 06cdb69da..761536711 100644 --- a/mesh/bluetooth-meshd.rst.in +++ b/mesh/bluetooth-meshd.rst.in @@ -36,14 +36,17 @@ OPTIONS -i , --io Specifies I/O interface type: - *hci* - Use generic HCI io on interface hci, - 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]* - Use generic HCI io on interface + hci. *unit:*- 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 , --config Specifies an explicit config file path instead of relying on the diff --git a/mesh/main.c b/mesh/main.c index 3bca020a0..145bcfa98 100644 --- a/mesh/main.c +++ b/mesh/main.c @@ -48,6 +48,12 @@ static const struct option main_options[] = { { } }; +static const char *io_usage = + "\t(auto | generic:[hci] | unit:)\n" + "\t\tauto - Use first available controller (MGMT or raw HCI)\n" + "\t\tgeneric - Use raw HCI io on interface hci\n" + "\t\tunit - Use test IO (for automatic testing only)\n"; + static void usage(void) { fprintf(stderr, @@ -55,18 +61,14 @@ static void usage(void) "\tbluetooth-meshd [options]\n"); fprintf(stderr, "Options:\n" - "\t--io Use specified io (default: generic)\n" + "\t--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] | generic[:[hci]] | unit:)\n" - "\t\tUse generic HCI io on interface hci, 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) @@ -157,21 +159,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) { @@ -181,12 +170,7 @@ static bool parse_io(const char *optarg, enum mesh_io_type *type, void **opts) *opts = index; optarg += strlen("generic"); - if (!*optarg) { - *index = MGMT_INDEX_NONE; - return true; - } - - if (*optarg != ':') + if (!*optarg || *optarg != ':') return false; optarg++; @@ -291,7 +275,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; } diff --git a/mesh/mesh-io-generic.c b/mesh/mesh-io-generic.c index 93a56275b..00932ade7 100644 --- a/mesh/mesh-io-generic.c +++ b/mesh/mesh-io-generic.c @@ -380,6 +380,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(); + io->pvt->hci = bt_hci_new_user_channel(io->index); if (!io->pvt->hci) { l_error("Failed to start mesh io (hci %u): %s", io->index, diff --git a/mesh/mesh-io.c b/mesh/mesh-io.c index 48e3f4226..b953bf4cf 100644 --- a/mesh/mesh-io.c +++ b/mesh/mesh-io.c @@ -72,12 +72,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 */ @@ -104,7 +112,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); } } diff --git a/mesh/mesh-mgmt.c b/mesh/mesh-mgmt.c index d37aeb5ac..fd21a168a 100644 --- a/mesh/mesh-mgmt.c +++ b/mesh/mesh-mgmt.c @@ -271,3 +271,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); +} diff --git a/mesh/mesh-mgmt.h b/mesh/mesh-mgmt.h index a3cd72faf..570282297 100644 --- a/mesh/mesh-mgmt.h +++ b/mesh/mesh-mgmt.h @@ -22,3 +22,4 @@ 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); -- 2.40.1