From patchwork Thu Jun 16 19:58:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12884718 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2265ECCA47C for ; Thu, 16 Jun 2022 19:58:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378459AbiFPT6L (ORCPT ); Thu, 16 Jun 2022 15:58:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237406AbiFPT6K (ORCPT ); Thu, 16 Jun 2022 15:58:10 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84DF92A402 for ; Thu, 16 Jun 2022 12:58:09 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id k5-20020a17090a404500b001e8875e6242so2377430pjg.5 for ; Thu, 16 Jun 2022 12:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=zYbMI0BpEdMu15hoQt6cBSlzn5rY9vTNCM/MaXO5eCk=; b=KngWZvASIk1ihgzr6uaIFQE9KQy4SET7rWiAFD4xDneAu09EGigRc3UyPf/NVuojTK /z2yYvINOCNE/1bf4DZxmBIbhDN1WHV3IPO7uWuh15Nk3XkWzctj2fMJVQzYplf+/Ed9 XmoMUVA1smfwUV/K50y5EfB4l9YCCMd+tOC/60wiapqZMqr+howQhJtArGIso+nw/G5a xdfu16BdokoYgIyryO1/Pg3y/UMDKtsAlx9B1t42JQz5nqPMDlzvaE3rF5vZjm5OIss4 sS4BiNTLix83Md9l2P7OK4ZvonTzFTsvEXumDlJtPcuH78192fAGYZDWrmP7U5D4oSaO meQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=zYbMI0BpEdMu15hoQt6cBSlzn5rY9vTNCM/MaXO5eCk=; b=742jBfznm4OJh/dWbgvfAH0a0Rl80JEAPZreE0aFaDU/vRMAsNSHMObir3JxPSzqkv LhZQDQ8oFrkUczYRezPTaI4wkckGKeYa+ATQBaPSIV7qiO8NQLXHetsMjI1X0/NY9tkw C34jZbQfimFliViXogB4VDZ5DaEJ5OOou8E91cyLxbTkOZkJfhs3wrfnTp8bKcE6RVOR PBhOkFZ6/zDXZgwF9CL0sckT9QMFMnKNhDxd4aeX3cNl2wP95uaR5ZTZPfd/9e7sBzHZ xTRe+JhcqNK+qcDnqmYqZPBGNzlzUyWRH2o6t14lStIjpkNRA7MZTr+/7xPOcGdw2gEO 3ZVg== X-Gm-Message-State: AJIora8+BDohV5K7Shlw7b7xrzfsTsgJ8KzOaLNgjqxDwDSLL8hCRsJB nXjwZw1rXG5+WTFlviatwbscA6P/xCU= X-Google-Smtp-Source: AGRyM1uFBAxz7JACz041MP+QKKkS42KAM8DpB3AVaPS+tyxYZS2TzlN7JpjGEH5EUHUQTUcJoRFoBQ== X-Received: by 2002:a17:90a:6284:b0:1df:4595:57af with SMTP id d4-20020a17090a628400b001df459557afmr6693943pjj.188.1655409488760; Thu, 16 Jun 2022 12:58:08 -0700 (PDT) Received: from han1-ubuntu-dev.. ([192.102.209.8]) by smtp.gmail.com with ESMTPSA id q23-20020a170902edd700b0016a034ae481sm89285plk.176.2022.06.16.12.58.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 12:58:08 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 1/3] doc/mgmt-api: Update for Add Extended Advertisement Command Date: Thu, 16 Jun 2022 12:58:01 -0700 Message-Id: <20220616195803.99346-1-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch aligns the input parameter for Add Extended Advertisement command with actual data struct and add missing flag descriptions. --- doc/mgmt-api.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt index a429f0ef3..23ea42228 100644 --- a/doc/mgmt-api.txt +++ b/doc/mgmt-api.txt @@ -3593,7 +3593,6 @@ Add Extended Advertising Parameters Command Controller Index: Command Parameters: Instance (1 Octet) Flags (4 Octets) - Params (2 Octets) Duration (2 Octets) Timeout (2 Octets) MinInterval (4 Octets) @@ -3631,6 +3630,8 @@ Add Extended Advertising Parameters Command 7 Secondary Channel with LE 1M 8 Secondary Channel with LE 2M 9 Secondary Channel with LE Coded + 10 Indicate tx power can be specified + 11 Indicate HW supports the advertising offload 12 The Duration parameter should be used 13 The Timeout parameter should be used 14 The Interval parameters should be used From patchwork Thu Jun 16 19:58:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12884719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05B08CCA47C for ; Thu, 16 Jun 2022 19:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378467AbiFPT6M (ORCPT ); Thu, 16 Jun 2022 15:58:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237406AbiFPT6L (ORCPT ); Thu, 16 Jun 2022 15:58:11 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B7E827CD5 for ; Thu, 16 Jun 2022 12:58:10 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id d129so2156540pgc.9 for ; Thu, 16 Jun 2022 12:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=DzmLhs2KN8/2XxlIjby9SAzcf+GgCxBXb2K7PJixntg=; b=HSeKh4KUeHzjz/+pClcOUADYFfJzMYz1lD/TfMHStj67ePeGQakI0sHGaAz6jK9+UB aBeh3fETvJCQ2dc4Lru6kExteW0jCDkQ4Yr9fWZsGZVN+gQZLQJvuxGSB+tr/sjejAFn BB9cASphSAyAZcv4brxjkdAT+AikOEqdUxPxILj+yNA57xxXkawLPdbSuqRmv00WSqWF 7FiAmy7+Lx/pi8OAD6vH4k9yncMsxbhHyAMrYq71hDQ+qQyxiZdzoAef8E5nf9jm6/4U wX4bd0YeZBR6UpiOySEWxE7FvmAmn+tiXKcAKZReaPIgtuWaSSfFrw1/Dm9m2zLf6Csk YSrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DzmLhs2KN8/2XxlIjby9SAzcf+GgCxBXb2K7PJixntg=; b=7zJ3ZkUoXtwEmG6o+oUDJHMsshCKxnH1bGcOytH/ysIMJxoyzgeBhq2gwuWI2aDuZZ +rSXC9M5GmYECVtd0EvWKIu3u+GD8ljgb+UXUIvuwOrOz5MiQMJuGL0vntxFEQckCEvf 9HaO/oYqVKPdpv9cLSGboOAQ3abN1Y+n3Yrv1a8xvKMPLJfnLHLMU3dOM2gzKvKzs7AT 4XWPfZnXK0UWNEGZirGDNiAiQhsF/9qY6+fukeCK2Q5/IMEzdkFQ14ncpxf+/WRjhHS6 L8YT5Ejv104SF4JTNbk/shd0D0xpT0KIUdDiY4JbJVXNEanZ8hVEX4wluY3TSG8ryl4b Pw6A== X-Gm-Message-State: AJIora/IgME4R2CnnHisnxy1WcNpBXDo+NhlDvbJ+3OjavuTMBoajmRk d/Rp0E+F8DE4PVqNY2dYJHIZbg86mA4= X-Google-Smtp-Source: AGRyM1vweFgxyhj+jq8///7kpZrRyORZpS4u2huwBh713ZBqeiYl+oOLTkaJWrsVP8Tz1mDia8vIjw== X-Received: by 2002:a62:1744:0:b0:51b:ab76:e8c4 with SMTP id 65-20020a621744000000b0051bab76e8c4mr6239208pfx.42.1655409489922; Thu, 16 Jun 2022 12:58:09 -0700 (PDT) Received: from han1-ubuntu-dev.. ([192.102.209.8]) by smtp.gmail.com with ESMTPSA id q23-20020a170902edd700b0016a034ae481sm89285plk.176.2022.06.16.12.58.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 12:58:09 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 2/3] monitor: Update flag information for Extended Advertismement Date: Thu, 16 Jun 2022 12:58:02 -0700 Message-Id: <20220616195803.99346-2-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220616195803.99346-1-hj.tedd.an@gmail.com> References: <20220616195803.99346-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch updates the missing flag details for Advertisement flags @ MGMT Event: Command Complete (0x0001) plen 11 Read Advertising Features (0x003d) plen 8 Status: Success (0x00) Flags: 0x0001ffff ... Unknown advertising flag (0x00010c00) ... --- monitor/packet.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/monitor/packet.c b/monitor/packet.c index bd9efd2c7..3d081c544 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -12667,10 +12667,13 @@ static const struct bitfield_data mgmt_adv_flags_table[] = { { 7, "Advertise in 1M on Secondary channel" }, { 8, "Advertise in 2M on Secondary channel" }, { 9, "Advertise in CODED on Secondary channel" }, + { 10, "Support setting Tx Power" }, + { 11, "Support HW offload" }, { 12, "Use provided duration parameter" }, { 13, "Use provided timeout parameter" }, { 14, "Use provided interval parameters" }, { 15, "Use provided tx power parameter" }, + { 16, "Contain Scan Response Data" }, { } }; #define MGMT_ADV_PARAM_DURATION (1 << 12) From patchwork Thu Jun 16 19:58:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12884720 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7717BC433EF for ; Thu, 16 Jun 2022 19:58:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378481AbiFPT6T (ORCPT ); Thu, 16 Jun 2022 15:58:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378469AbiFPT6N (ORCPT ); Thu, 16 Jun 2022 15:58:13 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F31762A719 for ; Thu, 16 Jun 2022 12:58:11 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id r1so2083030plo.10 for ; Thu, 16 Jun 2022 12:58:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=BYvMPzooqLhsj7GljNraofl+4iLwxPDzg6NSJeDYJCA=; b=NlSl/bknRQIumhPMB3WwbSvg+EyyddWI8p+FIs1PWQpTLF6yGJVVYKIztt/FOcKrI3 QlhsN5EW4/8f8ZstRAEmeY8eYdXIbowF0Y4WJY/GGLunz8pgshYHmsdgLwVrpdk0XH/x PiWImXAkcfXp99A2aceAvOmwDWQpX1fbn5iisGmcV8ClcLfYlDt8Iw7p/kmEA5jaqdvz POM7Rw9ch6sAIr5NkuKSCkgISbJ7We0UMfc1CZS+uHSuDLY0hMzmsrkyNdJIdMARGld+ c6kyjU3x4KouGlfkWh+v3guQft57soy1AjWbnXf4EnuUcS8nULhzMOrb/KdJir2siIYQ ErCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BYvMPzooqLhsj7GljNraofl+4iLwxPDzg6NSJeDYJCA=; b=u1nSWoM2WGIg4A5c+PNmxCcbRwpnvJkH1RgoA6i7Dk2E9neGAtvlHVRFXnOU+tXw+T D4CzkFnK58f4YN7WwSTD+YU9crkGkYQVyEYy9mt9p2xj2AUz4te5xsDB0B7U2j8QSF9t s48EVWMRCYPflnPvl8robM4AcbQ7K8stc9c/LLzhwF22bJomxtuD98gv+UZjeC3H57je cZVCq5dAibWX/GMUKwB5IsbKVy41Cuth/bZkHfir4f7/2JpXem5KmzlFd7yO/RLusSYP J/Rtf9/HRsHMgyvT12x+tRqjg4iHJLcdoQtKpI13CjG5H8jMZxQVpsx+wPIuDA/IIU8i UCCQ== X-Gm-Message-State: AJIora/5o+wF2Ku2uDhy3l2Co2vmJfaTVabqRMxW/ny/ajw90Es+ppLt D5eFVvqmkfzd2JMeDcCrxDk8xXEnrDI= X-Google-Smtp-Source: AGRyM1vWtCC9SSoHVOPaEJIfIbl8MNpl2xYEnFPTQ9rf2r6GzRtTQAf4mLb6iaIrKyswDOVKdUs6aA== X-Received: by 2002:a17:902:f60c:b0:16a:239:bcf7 with SMTP id n12-20020a170902f60c00b0016a0239bcf7mr933405plg.130.1655409491172; Thu, 16 Jun 2022 12:58:11 -0700 (PDT) Received: from han1-ubuntu-dev.. ([192.102.209.8]) by smtp.gmail.com with ESMTPSA id q23-20020a170902edd700b0016a034ae481sm89285plk.176.2022.06.16.12.58.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 12:58:10 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 3/3] tools/btmgmt: Add support Add Ext Adv command Date: Thu, 16 Jun 2022 12:58:03 -0700 Message-Id: <20220616195803.99346-3-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220616195803.99346-1-hj.tedd.an@gmail.com> References: <20220616195803.99346-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch adds new command to support the following MGMT API: Add Extended Advertising Parameters Command Add Extended Advertising Data Command --- tools/btmgmt.c | 377 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 377 insertions(+) diff --git a/tools/btmgmt.c b/tools/btmgmt.c index 8f63f12ba..3bf2c21c1 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -4891,6 +4891,377 @@ static void cmd_clr_adv(int argc, char **argv) cmd_rm_adv(2, rm_argv); } +static void add_ext_adv_params_rsp(uint8_t status, uint16_t len, + const void *param, void *user_data) +{ + const struct mgmt_rp_add_ext_adv_params *rp = param; + + if (status != 0) { + error("Add Ext Adv Params failed status 0x%02x (%s)", + status, mgmt_errstr(status)); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + if (len != sizeof(*rp)) { + error("Invalid Add Ext Adv Params response length (%u)", len); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + print("Instance added: %u", rp->instance); + print("Tx Power: %u", rp->tx_power); + print("Max adv data len: %u", rp->max_adv_data_len); + print("Max scan resp len: %u", rp->max_scan_rsp_len); + + return bt_shell_noninteractive_quit(EXIT_SUCCESS); +} + +static void add_ext_adv_params_usage(void) +{ + bt_shell_usage(); + print("Options:\n" + "\t -d, --duration Duration in seconds\n" + "\t -t, --timeout Timeout in seconds\n" + "\t -r, --min-interval Minimum interval\n" + "\t -x, --max-interval Maximum interval\n" + "\t -w, --tx-power Tx power\n" + "\t -P, --phy Phy type, Specify 1M/2M/CODED\n" + "\t -c, --connectable \"connectable\" flag\n" + "\t -g, --general-discov \"general-discoverable\" flag\n" + "\t -l, --limited-discov \"limited-discoverable\" flag\n" + "\t -m, --managed-flags \"managed-flags\" flag\n" + "\t -p, --add-tx-power \"tx-power\" flag\n" + "\t -a, --scan-rsp-appearance \"appearance\" flag\n" + "\t -n, --scan-rsp-local-name \"local-name\" flag\n" + "\t -s, --adv-scan-rsp \"scan resp in adv\" flag\n" + "\t -h, --help Show help\n" + "e.g.:\n" + "\tadd-ext-adv-params -r 0x801 -x 0x802 -P 2M -g 1"); +} + +static struct option add_ext_adv_params_options[] = { + { "help", 0, 0, 'h' }, + { "duration", 1, 0, 'd' }, + { "timeout", 1, 0, 't' }, + { "min-internal", 1, 0, 'r' }, + { "max-interval", 1, 0, 'x' }, + { "tx-power", 1, 0, 'w' }, + { "phy", 1, 0, 'P' }, + { "connectable", 0, 0, 'c' }, + { "general-discov", 0, 0, 'g' }, + { "limited-discov", 0, 0, 'l' }, + { "scan-rsp-local-name", 0, 0, 'n' }, + { "scan-rsp-appearance", 0, 0, 'a' }, + { "managed-flags", 0, 0, 'm' }, + { "add-tx-power", 0, 0, 'p' }, + { "adv-scan-rsp", 0, 0, 's' }, + { 0, 0, 0, 0} +}; + +static void cmd_add_ext_adv_params(int argc, char **argv) +{ + struct mgmt_cp_add_ext_adv_params *cp = NULL; + int opt; + uint16_t timeout = 0, duration = 0; + uint8_t instance; + bool success = false; + bool quit = true; + uint32_t flags = 0; + uint32_t min_interval = 0; + uint32_t max_interval = 0; + uint8_t tx_power = 0; + uint16_t index; + + while ((opt = getopt_long(argc, argv, "d:t:r:x:w:P:cglmpansh", + add_ext_adv_params_options, NULL)) != -1) { + switch (opt) { + case 'd': + duration = strtol(optarg, NULL, 0); + flags |= MGMT_ADV_PARAM_DURATION; + break; + case 't': + timeout = strtol(optarg, NULL, 0); + flags |= MGMT_ADV_PARAM_TIMEOUT; + break; + case 'r': + min_interval = strtol(optarg, NULL, 0); + break; + case 'x': + max_interval = strtol(optarg, NULL, 0); + break; + case 'w': + tx_power = strtol(optarg, NULL, 0); + flags |= MGMT_ADV_PARAM_TX_POWER; + break; + case 'P': + if (strcasecmp(optarg, "1M") == 0) + flags |= MGMT_ADV_FLAG_SEC_1M; + else if (strcasecmp(optarg, "2M") == 0) + flags |= MGMT_ADV_FLAG_SEC_2M; + else if (strcasecmp(optarg, "CODED") == 0) + flags |= MGMT_ADV_FLAG_SEC_CODED; + else + goto done; + break; + case 'c': + flags |= MGMT_ADV_FLAG_CONNECTABLE; + break; + case 'g': + flags |= MGMT_ADV_FLAG_DISCOV; + break; + case 'l': + flags |= MGMT_ADV_FLAG_LIMITED_DISCOV; + break; + case 'n': + flags |= MGMT_ADV_FLAG_LOCAL_NAME; + break; + case 'a': + flags |= MGMT_ADV_FLAG_APPEARANCE; + break; + case 'm': + flags |= MGMT_ADV_FLAG_MANAGED_FLAGS; + break; + case 'p': + flags |= MGMT_ADV_FLAG_TX_POWER; + break; + case 's': + flags |= MGMT_ADV_PARAM_SCAN_RSP; + break; + case 'h': + success = true; + /* fall through */ + default: + add_ext_adv_params_usage(); + optind = 0; + goto done; + } + } + + argc -= optind; + argv += optind; + optind = 0; + + if (argc != 1) { + add_ext_adv_params_usage(); + goto done; + } + + /* Only if both min_interval and max_interval are defined */ + if (min_interval && max_interval) + flags |= MGMT_ADV_PARAM_INTERVALS; + + instance = strtol(argv[0], NULL, 0); + + index = mgmt_index; + if (index == MGMT_INDEX_NONE) + index = 0; + + cp = malloc0(sizeof(*cp)); + if (!cp) + goto done; + + cp->instance = instance; + put_le32(flags, &cp->flags); + put_le16(timeout, &cp->timeout); + put_le16(duration, &cp->duration); + put_le32(min_interval, &cp->min_interval); + put_le32(max_interval, &cp->max_interval); + cp->tx_power = tx_power; + + if (!mgmt_send(mgmt, MGMT_OP_ADD_EXT_ADV_PARAMS, index, sizeof(*cp), cp, + add_ext_adv_params_rsp, NULL, NULL)) { + error("Unable to send \"Add Ext Advertising Params\" command"); + goto done; + } + + quit = false; + +done: + free(cp); + + if (quit) + bt_shell_noninteractive_quit(success ? + EXIT_SUCCESS : EXIT_FAILURE); +} + +static void add_ext_adv_data_rsp(uint8_t status, uint16_t len, + const void *param, void *user_data) +{ + const struct mgmt_rp_add_ext_adv_data *rp = param; + + if (status != 0) { + error("Add Ext Advertising Data failed with status 0x%02x (%s)", + status, mgmt_errstr(status)); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + if (len != sizeof(*rp)) { + error("Invalid Add Ext Advertising Data response length (%u)", + len); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + print("Instance added: %u", rp->instance); + + return bt_shell_noninteractive_quit(EXIT_SUCCESS); +} + +static void add_ext_adv_data_usage(void) +{ + bt_shell_usage(); + print("Options:\n" + "\t -u, --uuid Service UUID\n" + "\t -d, --adv-data Advertising Data bytes\n" + "\t -s, --scan-rsp Scan Response Data bytes\n" + "e.g.:\n" + "\tadd-ext-adv-data -u 180d -u 180f -d 080954657374204C45 1"); +} + +static struct option add_ext_adv_data_options[] = { + { "help", 0, 0, 'h' }, + { "uuid", 1, 0, 'u' }, + { "adv-data", 1, 0, 'd' }, + { "scan-rsp", 1, 0, 's' }, + { 0, 0, 0, 0} +}; + +static void cmd_add_ext_adv_data(int argc, char **argv) +{ + struct mgmt_cp_add_ext_adv_data *cp = NULL; + int opt; + uint8_t *adv_data = NULL, *scan_rsp = NULL; + size_t adv_len = 0, scan_rsp_len = 0; + size_t cp_len; + uint8_t uuids[MAX_AD_UUID_BYTES]; + size_t uuid_bytes = 0; + uint8_t uuid_type = 0; + uint8_t instance; + uuid_t uuid; + bool success = false; + bool quit = true; + uint16_t index; + + while ((opt = getopt_long(argc, argv, "+u:d:s:h", + add_ext_adv_data_options, NULL)) != -1) { + switch (opt) { + case 'u': + if (bt_string2uuid(&uuid, optarg) < 0) { + print("Invalid UUID: %s", optarg); + goto done; + } + + if (uuid_type && uuid_type != uuid.type) { + print("UUID types must be consistent"); + goto done; + } + + if (uuid.type == SDP_UUID16) { + if (uuid_bytes + 2 >= MAX_AD_UUID_BYTES) { + print("Too many UUIDs"); + goto done; + } + + put_le16(uuid.value.uuid16, uuids + uuid_bytes); + uuid_bytes += 2; + } else if (uuid.type == SDP_UUID128) { + if (uuid_bytes + 16 >= MAX_AD_UUID_BYTES) { + print("Too many UUIDs"); + goto done; + } + + bswap_128(uuid.value.uuid128.data, + uuids + uuid_bytes); + uuid_bytes += 16; + } else { + printf("Unsupported UUID type"); + goto done; + } + + if (!uuid_type) + uuid_type = uuid.type; + + break; + case 'd': + if (adv_len) { + print("Only one adv-data option allowed"); + goto done; + } + + if (!parse_bytes(optarg, &adv_data, &adv_len)) + goto done; + break; + case 's': + if (scan_rsp_len) { + print("Only one scan-rsp option allowed"); + goto done; + } + + if (!parse_bytes(optarg, &scan_rsp, &scan_rsp_len)) + goto done; + break; + case 'h': + success = true; + /* fall through */ + default: + add_ext_adv_data_usage(); + optind = 0; + goto done; + } + } + + argc -= optind; + argv += optind; + optind = 0; + + if (argc != 1) { + add_ext_adv_data_usage(); + goto done; + } + + if (uuid_bytes) + uuid_bytes += 2; + + instance = strtol(argv[0], NULL, 0); + + index = mgmt_index; + if (index == MGMT_INDEX_NONE) + index = 0; + + cp_len = sizeof(*cp) + uuid_bytes + adv_len + scan_rsp_len; + cp = malloc0(cp_len); + if (!cp) + goto done; + + cp->instance = instance; + cp->adv_data_len = adv_len + uuid_bytes; + cp->scan_rsp_len = scan_rsp_len; + + if (uuid_bytes) { + cp->data[0] = uuid_bytes - 1; + cp->data[1] = uuid_type == SDP_UUID16 ? 0x03 : 0x07; + memcpy(cp->data + 2, uuids, uuid_bytes - 2); + } + + memcpy(cp->data + uuid_bytes, adv_data, adv_len); + memcpy(cp->data + uuid_bytes + adv_len, scan_rsp, scan_rsp_len); + + if (!mgmt_send(mgmt, MGMT_OP_ADD_EXT_ADV_DATA, index, cp_len, cp, + add_ext_adv_data_rsp, NULL, NULL)) { + error("Unable to send \"Add Ext Advertising Data\" command"); + goto done; + } + + quit = false; + +done: + free(adv_data); + free(scan_rsp); + free(cp); + + if (quit) + bt_shell_noninteractive_quit(success ? + EXIT_SUCCESS : EXIT_FAILURE); +} + static void appearance_rsp(uint8_t status, uint16_t len, const void *param, void *user_data) { @@ -5618,6 +5989,12 @@ static const struct bt_shell_menu main_menu = { cmd_rm_adv, "Remove advertising instance" }, { "clr-adv", NULL, cmd_clr_adv, "Clear advertising instances" }, + { "add-ext-adv-params", "[options] ", + cmd_add_ext_adv_params, + "Add extended advertising params" }, + { "add-ext-adv-data", "[options] ", + cmd_add_ext_adv_data, + "Add extended advertising data" }, { "appearance", "", cmd_appearance, "Set appearance" }, { "phy", "[LE1MTX] [LE1MRX] [LE2MTX] [LE2MRX] "