From patchwork Thu Oct 29 21:23:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Winkler X-Patchwork-Id: 11867553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99659C2D0A3 for ; Thu, 29 Oct 2020 21:23:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 323A720838 for ; Thu, 29 Oct 2020 21:23:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PNjemyS6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726320AbgJ2VXs (ORCPT ); Thu, 29 Oct 2020 17:23:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbgJ2VXr (ORCPT ); Thu, 29 Oct 2020 17:23:47 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB2F1C0613CF for ; Thu, 29 Oct 2020 14:23:47 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id x85so2632602qka.14 for ; Thu, 29 Oct 2020 14:23:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=txKoRgXFpX5OkMoNQV35XeQq+co/kJjUR3niRDei33Q=; b=PNjemyS6pu+tgo4jjlNOk6+DABURU5fkxZ/HA/21CRZr+BqeQNEImZN+eWwKEpq2zk qKkIT+PCVjm49sTgdOJUrdfkegN8g/EiKhYgnuwFaAvgYwzEAl02QQnK/jJL4eZZxqQf O9gz7S5sydefKcuz78ERv6BU6BsEsZ/zy7/7mPNYs0NoWihVl42DHMWe/ydjg4TuWphZ BN53T/zMf/PqRXhOhXgww0uEOzIvIQF61lOz/DG+YK9wccL/RYiWdPmxwVPQc18mG2qk iS/Xdt/BV5lD/MwjbSrkAltu1COr474a6RSgkQ42fgfahK0QezzQA2f4wJzqBIOJRz9U N8Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=txKoRgXFpX5OkMoNQV35XeQq+co/kJjUR3niRDei33Q=; b=r/4AHMtRGIa03WL8XbkKH9/Dny1Y+CDgFQT06PTAiK5shuTqeLmo+goVmXRkHKH/8y t1BG0SpUU2AlfgdRtvb01wmPq88JSMOspSv0VbwpxFnbFCAHMJ2woHzf5GqMexLlD2Sb kFa/RoFBjZ/zRqUFuB6JtUTG/7ScJvMGSSnTsV5a9bZUPLHF7WyQc1CCe4nc6LdBl0j1 9Uo+WCXNSbDnJnPI0e8HSDIpOm1Bvby7RMlN1zmOHt4RshLmWPvQOolJo0TcN5XnIBcO aEzHqUu1mXWd7KO7K4pKgAL5+rSPgULvP2/0Nwn+FaNNcN3HbC7LxK4OXyvHOXRrstR7 uoWA== X-Gm-Message-State: AOAM533akoh3sRKKfAPfO2ePeF/JcQv5UTFWvP6aB/6u6dmIvSEdbnkk rYqlQDpecTspmY/ILsrmy6b399w8XCAPmWyz1w8T X-Google-Smtp-Source: ABdhPJxWUj090iNAeJmqRNWcSY/dGZq4v/0KPg5SwBkxAfJXllUhjcbtQxN48aWHXPhcMeOxATg6QMSZgwclRYKrM6Ft Sender: "danielwinkler via sendgmr" X-Received: from danielwinkler-linux.mtv.corp.google.com ([2620:15c:202:201:f693:9fff:fef4:4e59]) (user=danielwinkler job=sendgmr) by 2002:a0c:cb02:: with SMTP id o2mr6342760qvk.8.1604006626942; Thu, 29 Oct 2020 14:23:46 -0700 (PDT) Date: Thu, 29 Oct 2020 14:23:26 -0700 In-Reply-To: <20201029212336.3283410-1-danielwinkler@google.com> Message-Id: <20201029141832.Bluez.v5.1.Ifaa96e71a871158e5d9d454073b2b6846eae339f@changeid> Mime-Version: 1.0 References: <20201029212336.3283410-1-danielwinkler@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [Bluez PATCH v5 01/10] doc/advertising-api: update API with new interface From: Daniel Winkler To: luiz.von.dentz@intel.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Daniel Winkler , Sonny Sasaka , Alain Michaud Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This updates the advertising documentation to include the following features: LE Advertising Manager: - New SupportedCapabilities property LE Advertisement: - New min/max interval properties - New tx power property Reviewed-by: Sonny Sasaka Reviewed-by: Alain Michaud --- Changes in v5: - Changed interval API from jiffies to milliseconds for clarity - Changed new dbus endpoints to be experimental Changes in v4: None Changes in v3: None Changes in v2: None doc/advertising-api.txt | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/doc/advertising-api.txt b/doc/advertising-api.txt index b0565eab2..541c57004 100644 --- a/doc/advertising-api.txt +++ b/doc/advertising-api.txt @@ -138,6 +138,31 @@ Properties string Type "2M" "Coded" + uint32 MinInterval [Experimental] + + Minimum advertising interval to be used by the + advertising set, in milliseconds. Acceptable values + are in the range [20ms, 10,485s]. If the provided + MinInterval is larger than the provided MaxInterval, + the registration will return failure. + + uint32 MaxInterval [Experimental] + + Maximum advertising interval to be used by the + advertising set, in milliseconds. Acceptable values + are in the range [20ms, 10,485s]. If the provided + MinInterval is larger than the provided MaxInterval, + the registration will return failure. + + int16 TxPower [Experimental] + + Requested transmission power of this advertising set. + The provided value is used only if the "CanSetTxPower" + feature is enabled on the Advertising Manager. The + provided value must be in range [-127 to +20], where + units are in dBm. + + LE Advertising Manager hierarchy ================================ @@ -209,3 +234,26 @@ Properties byte ActiveInstances Possible values: "1M" "2M" "Coded" + + dict SupportedCapabilities [Experimental] + + Enumerates Advertising-related controller capabilities + useful to the client. + + Possible Values: + + byte MaxAdvLen + + Max advertising data length + + byte MaxScnRspLen + + Max advertising scan response length + + int16 MinTxPower + + Min advertising tx power (dBm) + + int16 MaxTxPower + + Max advertising tx power (dBm) From patchwork Thu Oct 29 21:23:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Winkler X-Patchwork-Id: 11867539 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4A4BC4741F for ; Thu, 29 Oct 2020 21:23:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AB2620838 for ; Thu, 29 Oct 2020 21:23:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EpbRr2t7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726358AbgJ2VXu (ORCPT ); Thu, 29 Oct 2020 17:23:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbgJ2VXt (ORCPT ); Thu, 29 Oct 2020 17:23:49 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EBDEC0613CF for ; Thu, 29 Oct 2020 14:23:49 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id o128so3173417pfg.1 for ; Thu, 29 Oct 2020 14:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=YMRzMvgHdkG2Hyh7CFC6R0i7cVj7SNDSbOorZRCr15c=; b=EpbRr2t7RrwAWqH9rvDBPBCx0XhhWkG5GC7Y1AT8804j7Mc4icjVPDon8m5v+RJz1l BoqxHDzwyHEsmLA8a/vHgzpwxG8HHLSKm0cfMVT95X1sLoCZ/TpySjPHi3nsEFLGbMwG e05m30zorkYOiN7cxV+zXJsr7B47CN/KuqG10C8Bo1NqtWMbXB96CNjQzAwcAoYW++f9 wuc2Oo95BJISTj4c5xlLp3KKPrU3FjEJjW+Eh+xWW5vJuS5Q3MjHBs8RqsM4GRalF04q PhOd6avxEAGFfrlpc8NsyWUUQHKt4vnjb1SgeUF2+keh6kWGTpd+bugbWvLAKvzS8b6k C0Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=YMRzMvgHdkG2Hyh7CFC6R0i7cVj7SNDSbOorZRCr15c=; b=uj1/puWMn3AhgIWxPDMcIY4Eds5pu2j+f6zZtcUxt+g2p6V839hc2V3leCuLI1VL7h 4+gSGdmk2HvVyq7OTw76DwP7iBpuG9luZ4exYu0inwUue8p7OcXBxnXmIVez/TZe9/xU TR6t2+HDVjjUiLrnOvZJrjvTHHQ/BDutzzNh0KX+n52knJgblcGBb236V6m7EspLnhdG QODXinmeuKOZ+Ml9cJC7NlXy6K35bjLT0pZGLqN39HPbjgIi/UOLv/pIvB4f5U/JSu1C ZO5cbs3YEkn3qb+EsBN/3XrqYqZ5nV4MKadBB2geKpy8ivAiUzoAxVbZVNLSP4M0BLUM AoWA== X-Gm-Message-State: AOAM530lky65UnSlNbdj3nENEaHh35Oj4o7efGWmF0AxSPksR0CqSVlK Akrjy2uzYtCLKJp0BS1EYIMpCg26aamrmb2xPnJA X-Google-Smtp-Source: ABdhPJxJlJ+fMel00DRi2xcz81kA+btFf8fyOvPNQ4bIrqOo3ODYDStCoazz91NWvhojJLLkG2pEQWKmtgUpuPkZQXFs Sender: "danielwinkler via sendgmr" X-Received: from danielwinkler-linux.mtv.corp.google.com ([2620:15c:202:201:f693:9fff:fef4:4e59]) (user=danielwinkler job=sendgmr) by 2002:a17:90a:9313:: with SMTP id p19mr1170004pjo.90.1604006629006; Thu, 29 Oct 2020 14:23:49 -0700 (PDT) Date: Thu, 29 Oct 2020 14:23:27 -0700 In-Reply-To: <20201029212336.3283410-1-danielwinkler@google.com> Message-Id: <20201029141832.Bluez.v5.2.If15d3d09724ded2bcc7240d29f6888f2ad12e723@changeid> Mime-Version: 1.0 References: <20201029212336.3283410-1-danielwinkler@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [Bluez PATCH v5 02/10] doc/mgmt-api: Add new Advertising MGMT interfaces to mgmt-api From: Daniel Winkler To: luiz.von.dentz@intel.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Daniel Winkler , Sonny Sasaka , Alain Michaud Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch adds the following to mgmt-api: - Add Extended Advertising Parameters Command - Add Extended Advertising Data Command Reviewed-by: Sonny Sasaka Reviewed-by: Alain Michaud --- Changes in v5: None Changes in v4: - mgmt-api: moved optional params into 'flags' field - mgmt-api: added info for new return parameters for max data size Changes in v3: - Removed Tx Power Selected MGMT event - Changed Read Security Info cmd to Read Controller Capabilities Changes in v2: - Removed extra space in Add Extended Advertising Parameters API doc/mgmt-api.txt | 217 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt index e7a713824..7c899a8fe 100644 --- a/doc/mgmt-api.txt +++ b/doc/mgmt-api.txt @@ -3574,6 +3574,223 @@ Remove Advertisement Monitor Command Busy +Add Extended Advertising Parameters Command +=========================================== + + Command Code: 0x0054 + Controller Index: + Command Parameters: Instance (1 Octet) + Flags (4 Octets) + Params (2 Octets) + Duration (2 Octets) + Timeout (2 Octets) + MinInterval (4 Octets) + MaxInterval (4 Octets) + TxPower (1 Octet) + Return Parameters: Instance (1 Octet) + TxPower (1 Octet) + MaxAdvDataLen (1 Octet) + MaxScanRspLen (1 Octet) + + This command is used to configure the parameters for Bluetooth Low + Energy advertising instance. This command is expected to be followed + by an Add Extended Advertising Data command to complete and enable + the advertising instance. + + Added advertising information with this command will not be visible + immediately if advertising is enabled via the Set Advertising + command. The usage of the Set Advertising command takes precedence + over this command. Instance information is stored and will be + advertised once advertising via Set Advertising has been disabled. + + The Instance identifier is a value between 1 and the number of + supported instances. The value 0 is reserved. + + With the Flags value the type of advertising is controlled and + the following flags are defined: + + 0 Switch into Connectable mode + 1 Advertise as Discoverable + 2 Advertise as Limited Discoverable + 3 Add Flags field to Adv_Data + 4 Add TX Power field to Adv_Data + 5 Add Appearance field to Scan_Rsp + 6 Add Local Name in Scan_Rsp + 7 Secondary Channel with LE 1M + 8 Secondary Channel with LE 2M + 9 Secondary Channel with LE Coded + 12 The Duration parameter should be used + 13 The Timeout parameter should be used + 14 The Interval parameters should be used + 15 The Tx Power parameter should be used + + When the connectable flag is set, then the controller will use + undirected connectable advertising. The value of the connectable + setting can be overwritten this way. This is useful to switch a + controller into connectable mode only for LE operation. This is + similar to the mode 0x02 from the Set Advertising command. + + When the connectable flag is not set, then the controller will + use advertising based on the connectable setting. When using + non-connectable or scannable advertising, the controller will + be programmed with a non-resolvable random address. When the + system is connectable, then the identity address or resolvable + private address will be used. + + Using the connectable flag is useful for peripheral mode support + where BR/EDR (and/or LE) is controlled by Add Device. This allows + making the peripheral connectable without having to interfere + with the global connectable setting. + + Secondary channel flags can be used to advertise in secondary + channel with the corresponding PHYs. These flag bits are mutually + exclusive and setting multiple will result in Invalid Parameter + error. Choosing either LE 1M or LE 2M will result in using + extended advertising on the primary channel with LE 1M and the + respectively LE 1M or LE 2M on the secondary channel. Choosing + LE Coded will result in using extended advertising on the primary + and secondary channels with LE Coded. Choosing none of these flags + will result in legacy advertising. + + To allow future parameters to be optionally extended in this structure, + the flags member has been used to specify which of the structure + fields were purposefully set by the caller. Unspecified parameters will + be given sensible defaults by the kernel before the advertisement is + registered. + + The Duration parameter configures the length of an Instance. The + value is in seconds. The default is 2 seconds. + + If only one advertising Instance has been added, then the Duration + value will be ignored. It only applies for the case where multiple + Instances are configured. In that case every Instance will be + available for the Duration time and after that it switches to + the next one. This is a simple round-robin based approach. + + The Timeout parameter configures the life-time of an Instance. In + case the value 0 is used it indicates no expiration time. If a + timeout value is provided, then the advertising Instance will be + automatically removed when the timeout passes. The value for the + timeout is in seconds. Powering down a controller will invalidate + all advertising Instances and it is not possible to add a new + Instance with a timeout when the controller is powered down. + + When a Timeout is provided, then the Duration subtracts from + the actual Timeout value of that Instance. For example an Instance + with Timeout of 5 and Duration of 2 will be scheduled exactly 3 + times, twice with 2 seconds and once with one second. Other + Instances have no influence on the Timeout. + + MinInterval and MaxInterval define the minimum and maximum advertising + intervals, with units as number of .625ms advertising slots. The Max + interval is expected to be greater than or equal to the Min interval, + and both must have values in the range [0x000020, 0xFFFFFF]. If either + condition is not met, the registration will fail. + + The provided Tx Power parameter will only be used if the controller + supports it, which can be determined by the presence of the + CanSetTxPower member of the Read Advertising Features command. + + The acceptable range for requested Tx Power is defined in the spec + (Version 5.2 | Vol 4, Part E, page 2585) to be [-127, +20] dBm, and the + controller will select a power value up to the requested one. The + transmission power selected by the controller is not guaranteed + to match the requested one, so the reply will contain the power + chosen by the controller. If the requested Tx Power is outside + the valid range, the registration will fail. + + Re-adding an already existing instance (i.e. issuing the Add Extended + Advertising Parameters command with an Instance identifier of an + existing instance) will update that instance's configuration. In this + case where no new instance is added, no Advertising Added event will + be generated. However, if the update of the instance fails, the + instance will be removed, and an Advertising Removed event will be + generated. + + An instance being added or changed while another instance is + being advertised will not be visible immediately but only when + the new/changed instance is being scheduled by the round robin + advertising algorithm. + + Changes to an instance that is currently being advertised will + cancel that instance and switch to the next instance. The changes + will be visible the next time the instance is scheduled for + advertising. In case a single instance is active, this means + that changes will be visible right away. + + The MaxAdvDataLen return parameter indicates how large the data + payload can be in the subsequent Add Extended Advertising Data + Command, as it accounts for the data required for the selected flags. + Similarly, the MaxScanRspLen return parameter indicates how large + the scan response can be. + + LE must already be enabled, and the controller must be powered, + otherwise a "rejected" status will be returned. + + This command generates a Command Complete event on success or a + Command Status event on failure. + + Possible errors: Failed + Rejected + Not Supported + Invalid Parameters + Busy + + +Add Extended Advertising Data Command +===================================== + + Command Code: 0x0055 + Controller Index: + Command Parameters: Instance (1 Octet) + Advertising Data Length (1 Octet) + Scan Response Length (1 Octet) + Advertising Data (0-255 Octets) + Scan Response (0-255 Octets) + Return Parameters: Instance (1 Octet) + + The Add Extended Advertising Data command is used to update the + advertising data of an existing advertising instance known to the + kernel. It is expected to be called after an Add Extended Advertising + Parameters command, as part of the advertisement registration + process. + + If extended advertising is available, this call will initiate HCI + commands to set the instance's advertising data, set scan response + data, and then enable the instance. If extended advertising is + unavailable, the advertising instance structure maintained in kernel + will have its advertising data and scan response updated, and the + instance will either be scheduled immediately or left in the queue + for later advertisement as part of round-robin advertisement rotation + in software. + + If Scan_Rsp_Len is zero and the flags defined in Add Extended + Advertising Parameters command do not have connectable flag set and + the global connectable setting is off, then non-connectable + advertising is used. If Scan_Rsp_Len is larger than zero and + connectable flag is not set and the global advertising is off, + then scannable advertising is used. This small difference is + supported to provide less air traffic for devices implementing + broadcaster role. + + If the Instance provided does not match a known instance, or if the + provided advertising data or scan response are in an unrecognized + format, an "Invalid Parameters" status will be returned. + + If a "Set LE" or Advertising command is still in progress, a "Busy" + status will be returned. + + If the controller is not powered, a "rejected" status will be returned. + + This command generates a Command Complete event on success or a + Command Status event on failure. + + Possible errors: Failed + Rejected + Invalid Parameters + Busy + + Command Complete Event ====================== From patchwork Thu Oct 29 21:23:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Winkler X-Patchwork-Id: 11867541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43ADAC2D0A3 for ; Thu, 29 Oct 2020 21:23:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA40020838 for ; Thu, 29 Oct 2020 21:23:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rkH+5ANf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726423AbgJ2VXw (ORCPT ); Thu, 29 Oct 2020 17:23:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbgJ2VXv (ORCPT ); Thu, 29 Oct 2020 17:23:51 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7407C0613CF for ; Thu, 29 Oct 2020 14:23:51 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id r129so1366582qkd.5 for ; Thu, 29 Oct 2020 14:23:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=CQX7W5tMg0C/rkuxt4IPLmY9UnuctOufHVY1gy1DhcY=; b=rkH+5ANftUy2+0Tcub4lmzHaf95znxzORWBdwDfVsjrfMyWbpmlyH+nKMy9C4GKzR9 bca7t4U+cJWgw2aZWYd4mcdKnWrVUj+zILnRT5buYMKLS6YkiNX5CVdhnHkRUMjiTs/c K0IDImaXfxtElYiJUeJ5g/++VBK4MLSCLy8MB4Q05IRXrZpp1JjVB1hJHb/RlSZIo+7C DuZbTJrGNfwesACmvt6j8WNc7GfvPVTdwyD8Vsw/aMoI6ZEfni/apNZlSBzTtw1J6PuI pZqEPl0JSHfc0xYOfMvMG8ivSceZPT5BXlqNYtGnbmZQKebtEJr3IbBKPl2/gLNOOjFq k9Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=CQX7W5tMg0C/rkuxt4IPLmY9UnuctOufHVY1gy1DhcY=; b=HaCzT4NtQu7iggNvgwqKR0t4eBHc75GLFWr4nzBbaZekBoWo8KSA0WiEpVRJTpa+nJ FR2ubmUvTIdrg5dD/eg6Zghyzvbm+hPkTUrZ/4QMDPqif+DW+xYFgQwRqdXGoYeejvZK +mCg67ukDgpT6P9i4CK8Z3LJcVVkvERpLEtKGcsWUtLjAL1ZCs9DyytvZgTBRqtEBw9O ulTgb2z+ZCPwxJoZeJzHljiDCSAEsKoagJzFvGKV5ihXk4MDrGPs8cwLRjEUH0mQs7Cb adi0PxCSo3vQlVAiz6gfk+D3Mmt5WGS2HsQb3ZbaYV4dBM9VoGKC8DArzS+MPSECWWRb 8JVw== X-Gm-Message-State: AOAM532cul/uHCnw6Jtjpw7z0ZZ9ICXrvLWepCAT/CqjKFCc1q24RxGG WxN52XcaXycjcPpN1cewXf0pWAAt6C2QXD6J36O+ X-Google-Smtp-Source: ABdhPJw6YclMD4UeuteY5UWLCWEx93XYoGTwAsUh3Nh+xbMzecvuO0KwTbTC6Q9GJkpwl6UUkUzglgnbS+skB7j85kkW Sender: "danielwinkler via sendgmr" X-Received: from danielwinkler-linux.mtv.corp.google.com ([2620:15c:202:201:f693:9fff:fef4:4e59]) (user=danielwinkler job=sendgmr) by 2002:ad4:4d46:: with SMTP id m6mr6381820qvm.60.1604006630950; Thu, 29 Oct 2020 14:23:50 -0700 (PDT) Date: Thu, 29 Oct 2020 14:23:28 -0700 In-Reply-To: <20201029212336.3283410-1-danielwinkler@google.com> Message-Id: <20201029141832.Bluez.v5.3.Iabfcf7ec8ac293130a7d903ee8094414256799b3@changeid> Mime-Version: 1.0 References: <20201029212336.3283410-1-danielwinkler@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [Bluez PATCH v5 03/10] doc/mgmt-api: Update controller capabilities MGMT command in mgmt-api From: Daniel Winkler To: luiz.von.dentz@intel.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Daniel Winkler Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch changes Read Security Info MGMT to be called Read Controller Capabilities Command --- Changes in v5: None Changes in v4: - mgmt-api: Move Controller Capabilities MGMT doc into new patch - mgmt-api: Tx Power range put into single capabilities entry Changes in v3: None Changes in v2: None doc/mgmt-api.txt | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt index 7c899a8fe..1aa43d6c3 100644 --- a/doc/mgmt-api.txt +++ b/doc/mgmt-api.txt @@ -3110,19 +3110,19 @@ Set Wideband Speech Command Invalid Index -Read Security Information Command -================================= +Read Controller Capabilities Command +==================================== Command Code: 0x0048 Controller Index: Command Parameters: - Return Parameters: Security_Data_Length (2 Octets) - Security_Data (0-65535 Octets) + Return Parameters: Capabilities_Data_Length (2 Octets) + Capabilities_Data (0-65535 Octets) - This command is used to retrieve the supported security features + This command is used to retrieve the supported capabilities by the controller or the host stack. - The Security_Data_Length and Security_Data parameters provide + The Capabilities_Data_Length and Capabilities_Data parameters provide a list of security settings, features and information. It uses the same format as EIR_Data, but with the namespace defined here. @@ -3131,6 +3131,7 @@ Read Security Information Command 0x01 Flags 0x02 Max Encryption Key Size (BR/EDR) 0x03 Max Encryption Key Size (LE) + 0x04 Supported Tx Power (LE) Flags (data type 0x01) @@ -3146,6 +3147,14 @@ Read Security Information Command present, then it is unknown what the max encryption key size of the controller or host is in use. + Supported LE Tx Power (data type 0x04) + + When present, this 2-octet field provides the min and max + LE Tx power supported by the controller, respectively, as + reported by the LE Read Transmit Power HCI command. If this + field is not available, it indicates that the LE Read + Transmit Power HCI command was not available. + This command generates a Command Complete event on success or a Command Status event on failure. From patchwork Thu Oct 29 21:23:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Winkler X-Patchwork-Id: 11867559 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D22AC4742C for ; Thu, 29 Oct 2020 21:23:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B76B120838 for ; Thu, 29 Oct 2020 21:23:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PmWdaDnf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726439AbgJ2VXy (ORCPT ); Thu, 29 Oct 2020 17:23:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbgJ2VXx (ORCPT ); Thu, 29 Oct 2020 17:23:53 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4179C0613CF for ; Thu, 29 Oct 2020 14:23:53 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id k7so4039283ybm.13 for ; Thu, 29 Oct 2020 14:23:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=Q/yW8CGo6ujkkewo4nJeNplHo7X6JGElLM5ul8fz5ac=; b=PmWdaDnf44Y9Pq2VOQXdi7GU5vmjRXg1qfAnm5FApQRyCn9z4a2VeFOcG/fylfgYuP 6JPVZNgJtkpCPZW8Ui8b7Ob/jYn6VPi5KSigBEIGiNCr4z69cfNx32YqF0Q5EbGjSdOx Xbmi687L0fS1I6PYzRlp7DeF9Z4NTx+sR7/N3Si7gGIMgvn5BhGdoo/BRgFA9N2xTxs3 CESN35dmb9IdPITMhw2O1CFL2MaTB+vUS3LGVQNb1NUr+2IJ2AC/iBB1acOJ8jwrkXkc 37ArM7HfNMm9u5Mb6NfhzsFBDtWveQY9NSG0fxxmOgsp117lmKfZ6scJ+i3X+iuAkZRN OIUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Q/yW8CGo6ujkkewo4nJeNplHo7X6JGElLM5ul8fz5ac=; b=UMmn9zaizYPFGBH2b/7des5i8aBqyQbzVUWfO5LMqmApFHd4NF3GVmG88Nv5IDqRoR N53RiOvLFblGjjf3EacKI1C86Qx9uCwgkK4D/T7RaoKmdPCzgUoHGjhYELD92B9nU3Xr Lr24ZLZRPuxQJsgBbzfwE20xLzUppQI/357ckKEWBUzIQaDzNyLSO6eyY31p28lme0o3 ATJwMijWhQaecIEc6dMDcEcthfsi3kJVKgQSW8SVt3GcqQjE5KDp/IZiswMgH2ztq+i4 CxnNKylASQWOA08eZkCgRZC0+UZwOg7a2AWkrKrVQFTRr37aWY+4Zcx4Sroby1Iepg59 6gbw== X-Gm-Message-State: AOAM532UJMA/+8K/RJdDCwTjEzBcAvcozVFCsKS364WBMm5UwnPc7/jb IFQ69ycytRuf4U+jPSt31OCKeVlAjoZeKzkuMOVz X-Google-Smtp-Source: ABdhPJxOFyX8Wjp+BEnA4Z9CZRVrNP44tJ08uucz1Or4uZ+hG4PprlXJN7Uc9Ntv8yuEMMygT2w02O3rKyKo8jKxOHRx Sender: "danielwinkler via sendgmr" X-Received: from danielwinkler-linux.mtv.corp.google.com ([2620:15c:202:201:f693:9fff:fef4:4e59]) (user=danielwinkler job=sendgmr) by 2002:a5b:ec2:: with SMTP id a2mr8656365ybs.13.1604006632915; Thu, 29 Oct 2020 14:23:52 -0700 (PDT) Date: Thu, 29 Oct 2020 14:23:29 -0700 In-Reply-To: <20201029212336.3283410-1-danielwinkler@google.com> Message-Id: <20201029141832.Bluez.v5.4.I50d9faa25e9da6e71d77c83c7d47a5b135e88799@changeid> Mime-Version: 1.0 References: <20201029212336.3283410-1-danielwinkler@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [Bluez PATCH v5 04/10] advertising: Detect if extended advertising mgmt commands are supported From: Daniel Winkler To: luiz.von.dentz@intel.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Daniel Winkler , Sonny Sasaka , Alain Michaud Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org We need to know if kernel supports the new MGMT interface. To do so, we check the return from adapter's MGMT_OP_READ_COMMANDS call for the new commands. This will later be used to route our requests for new advertisements. The change is tested by manually verifying that the correct MGMT commands are used when the feature is and is not available in kernel. Reviewed-by: Sonny Sasaka Reviewed-by: Alain Michaud --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: - Uses btd_has_kernel_features to detect kernel command support src/adapter.c | 4 ++++ src/adapter.h | 1 + src/advertising.c | 3 +++ 3 files changed, 8 insertions(+) diff --git a/src/adapter.c b/src/adapter.c index c0053000a..0e035172e 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -9640,6 +9640,10 @@ static void read_commands_complete(uint8_t status, uint16_t length, DBG("kernel supports exp features"); kernel_features |= KERNEL_EXP_FEATURES; break; + case MGMT_OP_ADD_EXT_ADV_PARAMS: + DBG("kernel supports ext adv commands"); + kernel_features |= KERNEL_HAS_EXT_ADV_ADD_CMDS; + break; default: break; } diff --git a/src/adapter.h b/src/adapter.h index dcc574857..ace72affd 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -233,6 +233,7 @@ enum kernel_features { KERNEL_SET_SYSTEM_CONFIG = 1 << 2, KERNEL_EXP_FEATURES = 1 << 3, KERNEL_HAS_RESUME_EVT = 1 << 4, + KERNEL_HAS_EXT_ADV_ADD_CMDS = 1 << 5, }; bool btd_has_kernel_features(uint32_t feature); diff --git a/src/advertising.c b/src/advertising.c index c03869e50..7c7599552 100644 --- a/src/advertising.c +++ b/src/advertising.c @@ -48,6 +48,7 @@ struct btd_adv_manager { uint8_t max_ads; uint32_t supported_flags; unsigned int instance_bitmap; + bool extended_add_cmds; }; #define AD_TYPE_BROADCAST 0 @@ -1417,6 +1418,8 @@ static struct btd_adv_manager *manager_create(struct btd_adapter *adapter, manager->mgmt_index = btd_adapter_get_index(adapter); manager->clients = queue_new(); manager->supported_flags = MGMT_ADV_FLAG_LOCAL_NAME; + manager->extended_add_cmds = + btd_has_kernel_features(KERNEL_HAS_EXT_ADV_ADD_CMDS); if (!g_dbus_register_interface(btd_get_dbus_connection(), adapter_get_path(manager->adapter), From patchwork Thu Oct 29 21:23:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Winkler X-Patchwork-Id: 11867547 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AF5DC55178 for ; Thu, 29 Oct 2020 21:23:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38A4120838 for ; Thu, 29 Oct 2020 21:23:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dwnuvDkW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726463AbgJ2VXz (ORCPT ); Thu, 29 Oct 2020 17:23:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbgJ2VXz (ORCPT ); Thu, 29 Oct 2020 17:23:55 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CEB0C0613CF for ; Thu, 29 Oct 2020 14:23:55 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id l188so3121722pfl.23 for ; Thu, 29 Oct 2020 14:23:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=P+SDqtmg4eLZ9mT2fhiYwlVLZMV5m/3vumx5CxGCgm8=; b=dwnuvDkW11YTKmsQMZgTI8w2owcjkIh0Ey3qzfRtkySpH7yfAi8qUP7K9m0gcKyIE6 93aRbgIEU6Rq38x8BzSsvhab6ekyCx11+uXOLC3G1aUkKPCSm7wv65vCJVN4L3nhLKdQ cdSqWKP8sT3FssbQ1Jm/0RQHO8e/jad+5xFkVY2L+w4W/PYcwDGZl4baIzW2SvaDem6f SRQeVmFvzvmfE+GWj3g5LcJ5rowcUdZ4DsaXoyzkeXJu6tU0PuxtjkbzleCd34ARkmYW DGNoCZgGyGIkWFDuyeuqGBz9O/WFjMZ3RtwKwFdNvWqiflr25w0KlSZ0j3GvmyYMXi49 y0Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=P+SDqtmg4eLZ9mT2fhiYwlVLZMV5m/3vumx5CxGCgm8=; b=ns7By4+pyHP/qMS4GFiSKuXwJhu4BVSJy050vk9rjKHW4qN+8odsejlt2MNRUVtET5 g9/33ciXg9FkWHeV1jfXfTA4gUfgttc5+/azLe5yyP4ReBUe4IDkEbhIDZbXsn1xkglO 3uyJ5UBZMB1+O/Sk6UnpkUnNryrh05xpCfFO2oIG95Y1+0xYrtdWhT6GZxenujfiu/vd g5nQT1aOoCtV2pf/XcYVD060gLsCb0Q13lvCYbFS6VMtI6AtNcDjWQuUZNGbB1BicpL4 7gt6X9023EWEFM19Hml7ZKcc64ze9vKHT9pm4NRB5bAVwt2BW6WbiNi6p/uPXQP0GkUC fFVg== X-Gm-Message-State: AOAM531cBdDVp/JJ3lSpnhng/CAsbo/waxULZ69QavJAGG9Q2gylQZRc 9OdtNHISrCUK1B7nfAxUVWCdWXrSE8ijpPbpujG1 X-Google-Smtp-Source: ABdhPJzAXooqtpaZ+hh71tMrvsseHKzEy3icvc6g6KOiyR28W0od8fsCkNMt7yahPDXLICaqU27cQwTgyIAoUZ/9iV+P Sender: "danielwinkler via sendgmr" X-Received: from danielwinkler-linux.mtv.corp.google.com ([2620:15c:202:201:f693:9fff:fef4:4e59]) (user=danielwinkler job=sendgmr) by 2002:aa7:92d4:0:b029:163:e68e:5ffb with SMTP id k20-20020aa792d40000b0290163e68e5ffbmr5792088pfa.40.1604006634850; Thu, 29 Oct 2020 14:23:54 -0700 (PDT) Date: Thu, 29 Oct 2020 14:23:30 -0700 In-Reply-To: <20201029212336.3283410-1-danielwinkler@google.com> Message-Id: <20201029141832.Bluez.v5.5.Ic4a3667da774f5f34477d5168a68a9280657e2da@changeid> Mime-Version: 1.0 References: <20201029212336.3283410-1-danielwinkler@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [Bluez PATCH v5 05/10] advertising: Parse intervals and tx power from adv From: Daniel Winkler To: luiz.von.dentz@intel.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Daniel Winkler , Sonny Sasaka , Alain Michaud Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This change adds parsers for the advertising intervals and tx power properties of the LEAdvertisement1 object. It validates that each field adheres to the 5.2 spec, and that min and max intervals are compatible with each other, i.e. that min interval is less than max interval. A note here for maintainers: The tx power that is sent in the hci parameter command is an int8_t, but as far as I can tell, there is no clean way to use a signed 8-bit integer in dbus. The dbus byte type seems incompatible with negative values in high-level languages (python) without awkward usage manipulation on the client side. For this reason, I chose to use an int16_t type for the tx power dbus field, which is then downcasted to the int8_t in bluetoothd, which at least makes the signed-ness of the type crystal clear to the dbus client that uses it. This change is manually verified by ensuring the intervals and tx power parameters are correctly parsed from the LEAdvertisement1 object, and that the parse fails if the parameters are incorrect or not compatible with each other. Reviewed-by: Sonny Sasaka Reviewed-by: Alain Michaud --- Changes in v5: - Only parse new properties if experimental flag is set Changes in v4: None Changes in v3: None Changes in v2: None src/advertising.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/src/advertising.c b/src/advertising.c index 7c7599552..25d8ba770 100644 --- a/src/advertising.c +++ b/src/advertising.c @@ -54,6 +54,11 @@ struct btd_adv_manager { #define AD_TYPE_BROADCAST 0 #define AD_TYPE_PERIPHERAL 1 +/* BLUETOOTH SPECIFICATION Version 5.2 | Vol 4, Part E, page 2585 + * defines tx power value indicating no preference + */ +#define ADV_TX_POWER_NO_PREFERENCE 0x7F + struct btd_adv_client { struct btd_adv_manager *manager; char *owner; @@ -74,6 +79,9 @@ struct btd_adv_client { struct bt_ad *data; struct bt_ad *scan; uint8_t instance; + uint32_t min_interval; + uint32_t max_interval; + int8_t tx_power; }; struct dbus_obj_match { @@ -937,6 +945,96 @@ static bool parse_secondary(DBusMessageIter *iter, return false; } +static bool parse_min_interval(DBusMessageIter *iter, + struct btd_adv_client *client) +{ + uint32_t min_interval_ms; + + /* Only consider this property if experimental setting is applied */ + if (!g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL) + return true; + + if (!iter) + return false; + + if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT32) + return false; + + dbus_message_iter_get_basic(iter, &min_interval_ms); + + /* Convert ms to jiffies to be used in adv request */ + client->min_interval = min_interval_ms / 0.625; + + /* BLUETOOTH SPECIFICATION Version 5.2 | Vol 4, Part E, page 2584 + * defines acceptable interval range + */ + if (client->min_interval < 0x20 || client->min_interval > 0xFFFFFF) { + client->min_interval = 0; + return false; + } + + return true; +} + +static bool parse_max_interval(DBusMessageIter *iter, + struct btd_adv_client *client) +{ + uint32_t max_interval_ms; + + /* Only consider this property if experimental setting is applied */ + if (!g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL) + return true; + + if (!iter) + return false; + + if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT32) + return false; + + dbus_message_iter_get_basic(iter, &max_interval_ms); + + /* Convert ms to jiffies to be used in adv request */ + client->max_interval = max_interval_ms / 0.625; + + /* BLUETOOTH SPECIFICATION Version 5.2 | Vol 4, Part E, page 2584 + * defines acceptable interval range + */ + if (client->max_interval < 0x20 || client->max_interval > 0xFFFFFF) { + client->max_interval = 0; + return false; + } + + return true; +} + +static bool parse_tx_power(DBusMessageIter *iter, + struct btd_adv_client *client) +{ + int16_t val; + + /* Only consider this property if experimental setting is applied */ + if (!g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL) + return true; + + if (!iter) + return false; + + if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INT16) + return false; + + dbus_message_iter_get_basic(iter, &val); + + /* BLUETOOTH SPECIFICATION Version 5.2 | Vol 4, Part E, page 2585 + * defines acceptable tx power range + */ + if (val < -127 || val > 20) + return false; + + client->tx_power = val; + + return true; +} + static struct adv_parser { const char *name; bool (*func)(DBusMessageIter *iter, struct btd_adv_client *client); @@ -955,6 +1053,9 @@ static struct adv_parser { { "Discoverable", parse_discoverable }, { "DiscoverableTimeout", parse_discoverable_timeout }, { "SecondaryChannel", parse_secondary }, + { "MinInterval", parse_min_interval }, + { "MaxInterval", parse_max_interval }, + { "TxPower", parse_tx_power }, { }, }; @@ -1083,6 +1184,13 @@ static DBusMessage *parse_advertisement(struct btd_adv_client *client) goto fail; } + if (client->min_interval > client->max_interval) { + /* Min interval must not be bigger than max interval */ + error("MinInterval must be less than MaxInterval (%lu > %lu)", + client->min_interval, client->max_interval); + goto fail; + } + err = refresh_adv(client, add_adv_callback, &client->add_adv_id); if (!err) return NULL; @@ -1158,6 +1266,9 @@ static struct btd_adv_client *client_create(struct btd_adv_manager *manager, client->manager = manager; client->appearance = UINT16_MAX; + client->tx_power = ADV_TX_POWER_NO_PREFERENCE; + client->min_interval = 0; + client->max_interval = 0; return client; From patchwork Thu Oct 29 21:23:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Winkler X-Patchwork-Id: 11867545 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C6A5C2D0A3 for ; Thu, 29 Oct 2020 21:23:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 048B02087D for ; Thu, 29 Oct 2020 21:23:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="j2y3+G/m" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726482AbgJ2VX6 (ORCPT ); Thu, 29 Oct 2020 17:23:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbgJ2VX6 (ORCPT ); Thu, 29 Oct 2020 17:23:58 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 996BEC0613CF for ; Thu, 29 Oct 2020 14:23:57 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id r4so2993877pgl.20 for ; Thu, 29 Oct 2020 14:23:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=UoIMXWRFpejcO05qLbJiVgVogYNdnHT7PedX9Ri9C5A=; b=j2y3+G/mhrlGfKKizsIDm+YkuYTK7xjxRFGcKUOQFycrJvedyPJSmzH4YrycS2+4nq 0xF642tevRD29KBB2XNERKwvEWQDbosBluuDs2kXXosY/QNrM919CEdld4V6ubK0byti abFwVvDhRTONvay1uO0MM9VJ6TJGn3u85Gg83L/DjzRyRo3VFsMxjManAHIklBHD7QMz 7opOuz+FcXsa+veyTG5ZhA/Mv9p94QMWv++j2HUYp2nE1J8I/UPdBuJwEnnZwaEpwJxz 3r9U8NNDqroYfNNAf7ET83g6WuuLCLk6+eyiqt6vbWQDZytMMZd0m/sT6KuW1f0TAw83 bvaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=UoIMXWRFpejcO05qLbJiVgVogYNdnHT7PedX9Ri9C5A=; b=M3fpsSqm0iNdFebbsJYNQVCh4Y8JFmCvBwsJJRFm/cz+aIa2CbR0ILpuwlz5N/ExYq OJk9h0OC34wJW6SM6UxRl9f41aBoEWAWGZ16E1vCZFg2MvUiHQN6vnqyOFRNhvfVjxkO S8iKwZdEuYNStv4hmHpc28PKimYmsj6IiTsCmc8HAQrRRI9kH/uktnJBFY3JNV2hf5kM lY+swr5wlLS+xDIdQs6KAZsrBNizK5e3SufqprsjzXaTNNXVf4c6e8sYRRad7shdlP43 cyzz63+wGbqCA/e7gWBNMhWQqixfSbD5hRz8JrS8Sjq0BqNwfgAzN46prMdKNU8UJL8I Vd8w== X-Gm-Message-State: AOAM530frerHSfJwXpmeJU7zYj+j4PTeZVWOxOM/NcV1EE0zqZ+tuzeh BTZY+36pKiJJ9iC2TiUS3Ygo2OtRhW75YEq7qOYc X-Google-Smtp-Source: ABdhPJwih2HQ0TOxFjxNzlqdt66zpMiq4i92b4ybDzC+RY61/096iUUunMw/wpgPveaxhGZUjlKmzbYPhKseayqN6pbN Sender: "danielwinkler via sendgmr" X-Received: from danielwinkler-linux.mtv.corp.google.com ([2620:15c:202:201:f693:9fff:fef4:4e59]) (user=danielwinkler job=sendgmr) by 2002:aa7:9255:0:b029:158:ca2e:3f33 with SMTP id 21-20020aa792550000b0290158ca2e3f33mr6362844pfp.59.1604006637132; Thu, 29 Oct 2020 14:23:57 -0700 (PDT) Date: Thu, 29 Oct 2020 14:23:31 -0700 In-Reply-To: <20201029212336.3283410-1-danielwinkler@google.com> Message-Id: <20201029141832.Bluez.v5.6.Ia49df7ccded97ceb4ff1d1b0decc49d03d088a84@changeid> Mime-Version: 1.0 References: <20201029212336.3283410-1-danielwinkler@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [Bluez PATCH v5 06/10] advertising: Use new mgmt interface for advertising add From: Daniel Winkler To: luiz.von.dentz@intel.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Daniel Winkler , Sonny Sasaka , Alain Michaud Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch allows bluetoothd to use the new extended advertising add mgmt interface if it is available. The new interface will be used by default, as it allows the client to set advertising intervals, and tx power if the controller and kernel support extended advertising. Each new registered advertisement will submit two requests to kernel; the first sets the advertising parameters for the advertising instance, and the second sets the advertising data and scan response for the instance. The parameters MGMT request will return the tx power selected by the controller (if applicable), which is propagated to the client via a dbus Set method. Note: This patch also fixes a small bug in the packet monitor, where the tx power value 0xff is considered as "Host has no preference". However, the spec states this value to be 0x7f. It is corrected in this patch This change has been tested extensively on Hatch (extended advertising) and Kukui (no extended advertising) chromebooks. Manual tests do the following: - Configure advertisement with custom intervals, tx power with valid and invalid values and combinations - Ensure that with valid parameters, they are propagated and set in hci requests. With invalid parameters, ensure that the registration fails. Automatic tests verify 25 advertising usage scenarios involving single and multi-advertising registration, over-registration, parameter validation, etc. These tests don't test new intervals and tx power, but validate that the new MGMT interface does not regress compatibility in these 25 scenarios. Reviewed-by: Sonny Sasaka Reviewed-by: Alain Michaud --- Changes in v5: None Changes in v4: - Moved optional params into flags field - Use returned max data length in adv data length check Changes in v3: - Added selected tx power to MGMT params response Changes in v2: - Cleaned fail path in add_adv_params_callback lib/mgmt.h | 32 +++++++ monitor/packet.c | 4 +- src/advertising.c | 223 ++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 242 insertions(+), 17 deletions(-) diff --git a/lib/mgmt.h b/lib/mgmt.h index 6aa0f5f88..7ab4fb797 100644 --- a/lib/mgmt.h +++ b/lib/mgmt.h @@ -503,6 +503,10 @@ struct mgmt_rp_add_advertising { #define MGMT_ADV_FLAG_SEC_1M (1 << 7) #define MGMT_ADV_FLAG_SEC_2M (1 << 8) #define MGMT_ADV_FLAG_SEC_CODED (1 << 9) +#define MGMT_ADV_PARAM_DURATION (1 << 12) +#define MGMT_ADV_PARAM_TIMEOUT (1 << 13) +#define MGMT_ADV_PARAM_INTERVALS (1 << 14) +#define MGMT_ADV_PARAM_TX_POWER (1 << 15) #define MGMT_OP_REMOVE_ADVERTISING 0x003F struct mgmt_cp_remove_advertising { @@ -700,6 +704,34 @@ struct mgmt_rp_remove_adv_monitor { uint16_t monitor_handle; } __packed; +#define MGMT_OP_ADD_EXT_ADV_PARAMS 0x0054 +struct mgmt_cp_add_ext_adv_params { + uint8_t instance; + uint32_t flags; + uint16_t duration; + uint16_t timeout; + uint32_t min_interval; + uint32_t max_interval; + int8_t tx_power; +} __packed; +struct mgmt_rp_add_ext_adv_params { + uint8_t instance; + int8_t tx_power; + uint8_t max_adv_data_len; + uint8_t max_scan_rsp_len; +} __packed; + +#define MGMT_OP_ADD_EXT_ADV_DATA 0x0055 +struct mgmt_cp_add_ext_adv_data { + uint8_t instance; + uint8_t adv_data_len; + uint8_t scan_rsp_len; + uint8_t data[0]; +} __packed; +struct mgmt_rp_add_ext_adv_data { + uint8_t instance; +} __packed; + #define MGMT_EV_CMD_COMPLETE 0x0001 struct mgmt_ev_cmd_complete { uint16_t opcode; diff --git a/monitor/packet.c b/monitor/packet.c index d83552f74..615c180f8 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -6979,8 +6979,8 @@ static void le_set_ext_adv_params_cmd(const void *data, uint8_t size) print_peer_addr_type("Peer address type", cmd->peer_addr_type); print_addr("Peer address", cmd->peer_addr, cmd->peer_addr_type); print_adv_filter_policy("Filter policy", cmd->filter_policy); - if (cmd->tx_power == 0xff) - print_field("TX power: Host has no preference (0xff)"); + if (cmd->tx_power == 0x7f) + print_field("TX power: Host has no preference (0x7f)"); else print_power_level(cmd->tx_power, NULL); diff --git a/src/advertising.c b/src/advertising.c index 25d8ba770..428cd9562 100644 --- a/src/advertising.c +++ b/src/advertising.c @@ -82,6 +82,7 @@ struct btd_adv_client { uint32_t min_interval; uint32_t max_interval; int8_t tx_power; + mgmt_request_func_t refresh_done_func; }; struct dbus_obj_match { @@ -788,19 +789,9 @@ static uint8_t *generate_scan_rsp(struct btd_adv_client *client, return bt_ad_generate(client->scan, len); } -static int refresh_adv(struct btd_adv_client *client, mgmt_request_func_t func, - unsigned int *mgmt_id) +static int get_adv_flags(struct btd_adv_client *client) { - struct mgmt_cp_add_advertising *cp; - uint8_t param_len; - uint8_t *adv_data; - size_t adv_data_len; - uint8_t *scan_rsp; - size_t scan_rsp_len = -1; uint32_t flags = 0; - unsigned int mgmt_ret; - - DBG("Refreshing advertisement: %s", client->path); if (client->type == AD_TYPE_PERIPHERAL) { flags = MGMT_ADV_FLAG_CONNECTABLE; @@ -812,6 +803,26 @@ static int refresh_adv(struct btd_adv_client *client, mgmt_request_func_t func, flags |= client->flags; + return flags; +} + +static int refresh_legacy_adv(struct btd_adv_client *client, + mgmt_request_func_t func, + unsigned int *mgmt_id) +{ + struct mgmt_cp_add_advertising *cp; + uint8_t param_len; + uint8_t *adv_data; + size_t adv_data_len; + uint8_t *scan_rsp; + size_t scan_rsp_len = -1; + uint32_t flags = 0; + unsigned int mgmt_ret; + + DBG("Refreshing advertisement: %s", client->path); + + flags = get_adv_flags(client); + adv_data = generate_adv_data(client, &flags, &adv_data_len); if (!adv_data || (adv_data_len > calc_max_adv_len(client, flags))) { error("Advertising data too long or couldn't be generated."); @@ -864,6 +875,75 @@ static int refresh_adv(struct btd_adv_client *client, mgmt_request_func_t func, return 0; } +static void add_adv_params_callback(uint8_t status, uint16_t length, + const void *param, void *user_data); + +static int refresh_extended_adv(struct btd_adv_client *client, + mgmt_request_func_t func, unsigned int *mgmt_id) +{ + struct mgmt_cp_add_ext_adv_params cp; + uint32_t flags = 0; + uint16_t included_params = 0; + unsigned int mgmt_ret = 0; + + DBG("Refreshing advertisement parameters: %s", client->path); + + flags = get_adv_flags(client); + + memset(&cp, 0, sizeof(cp)); + cp.instance = client->instance; + + /* Not all advertising instances will use all possible parameters. The + * included_params bit field tells the kernel which parameters are + * relevant, and sensible defaults will be used for the rest + */ + + if (client->duration) { + cp.duration = client->duration; + flags |= MGMT_ADV_PARAM_DURATION; + } + + if (client->min_interval && client->max_interval) { + cp.min_interval = client->min_interval; + cp.max_interval = client->max_interval; + flags |= MGMT_ADV_PARAM_INTERVALS; + } + + if (client->tx_power != ADV_TX_POWER_NO_PREFERENCE) { + cp.tx_power = client->tx_power; + flags |= MGMT_ADV_PARAM_TX_POWER; + } + + cp.flags = htobl(flags); + + mgmt_ret = mgmt_send(client->manager->mgmt, MGMT_OP_ADD_EXT_ADV_PARAMS, + client->manager->mgmt_index, sizeof(cp), &cp, + add_adv_params_callback, client, NULL); + + if (!mgmt_ret) { + error("Failed to request extended advertising parameters"); + return -EINVAL; + } + + /* Store callback, called after we set advertising data */ + client->refresh_done_func = func; + + if (mgmt_id) + *mgmt_id = mgmt_ret; + + + return 0; +} + +static int refresh_advertisement(struct btd_adv_client *client, + mgmt_request_func_t func, unsigned int *mgmt_id) +{ + if (client->manager->extended_add_cmds) + return refresh_extended_adv(client, func, mgmt_id); + + return refresh_legacy_adv(client, func, mgmt_id); +} + static gboolean client_discoverable_timeout(void *user_data) { struct btd_adv_client *client = user_data; @@ -874,7 +954,7 @@ static gboolean client_discoverable_timeout(void *user_data) bt_ad_clear_flags(client->data); - refresh_adv(client, NULL, NULL); + refresh_advertisement(client, NULL, NULL); return FALSE; } @@ -1070,7 +1150,8 @@ static void properties_changed(GDBusProxy *proxy, const char *name, continue; if (parser->func(iter, client)) { - refresh_adv(client, NULL, NULL); + refresh_advertisement(client, NULL, NULL); + break; } } @@ -1133,6 +1214,112 @@ done: add_client_complete(client, status); } +static void add_adv_params_callback(uint8_t status, uint16_t length, + const void *param, void *user_data) +{ + struct btd_adv_client *client = user_data; + const struct mgmt_rp_add_ext_adv_params *rp = param; + struct mgmt_cp_add_ext_adv_data *cp = NULL; + uint8_t param_len; + uint8_t *adv_data = NULL; + size_t adv_data_len; + uint8_t *scan_rsp = NULL; + size_t scan_rsp_len = -1; + uint32_t flags = 0; + unsigned int mgmt_ret; + dbus_int16_t tx_power; + + if (status) + goto fail; + + if (!param || length < sizeof(*rp)) { + status = MGMT_STATUS_FAILED; + goto fail; + } + + DBG("Refreshing advertisement data: %s", client->path); + + /* Update tx power held by client */ + tx_power = rp->tx_power; + if (tx_power != ADV_TX_POWER_NO_PREFERENCE) + g_dbus_proxy_set_property_basic(client->proxy, "TxPower", + DBUS_TYPE_INT16, &tx_power, NULL, NULL, NULL); + + client->instance = rp->instance; + + flags = get_adv_flags(client); + + adv_data = generate_adv_data(client, &flags, &adv_data_len); + if (!adv_data || (adv_data_len > rp->max_adv_data_len)) { + error("Advertising data too long or couldn't be generated."); + goto fail; + } + + scan_rsp = generate_scan_rsp(client, &flags, &scan_rsp_len); + if ((!scan_rsp && scan_rsp_len) || + scan_rsp_len > rp->max_scan_rsp_len) { + error("Scan data couldn't be generated."); + goto fail; + } + + param_len = sizeof(struct mgmt_cp_add_advertising) + adv_data_len + + scan_rsp_len; + + cp = malloc0(param_len); + if (!cp) { + error("Couldn't allocate for MGMT!"); + goto fail; + } + + cp->instance = client->instance; + cp->adv_data_len = adv_data_len; + cp->scan_rsp_len = scan_rsp_len; + memcpy(cp->data, adv_data, adv_data_len); + memcpy(cp->data + adv_data_len, scan_rsp, scan_rsp_len); + + free(adv_data); + free(scan_rsp); + adv_data = NULL; + scan_rsp = NULL; + + /* Submit request to update instance data */ + mgmt_ret = mgmt_send(client->manager->mgmt, MGMT_OP_ADD_EXT_ADV_DATA, + client->manager->mgmt_index, param_len, cp, + client->refresh_done_func, client, NULL); + + /* Clear the callback */ + client->refresh_done_func = NULL; + + if (!mgmt_ret) { + error("Failed to add Advertising Data"); + goto fail; + } + + if (client->add_adv_id) + client->add_adv_id = mgmt_ret; + + free(cp); + cp = NULL; + + return; + +fail: + if (adv_data) + free(adv_data); + + if (scan_rsp) + free(scan_rsp); + + if (cp) + free(cp); + + if (!status) + status = -EINVAL; + + /* Failure for any reason ends this advertising request */ + add_client_complete(client, status); +} + static DBusMessage *parse_advertisement(struct btd_adv_client *client) { struct adv_parser *parser; @@ -1191,7 +1378,9 @@ static DBusMessage *parse_advertisement(struct btd_adv_client *client) goto fail; } - err = refresh_adv(client, add_adv_callback, &client->add_adv_id); + err = refresh_advertisement(client, add_adv_callback, + &client->add_adv_id); + if (!err) return NULL; @@ -1270,6 +1459,8 @@ static struct btd_adv_client *client_create(struct btd_adv_manager *manager, client->min_interval = 0; client->max_interval = 0; + client->refresh_done_func = NULL; + return client; fail: @@ -1586,7 +1777,9 @@ void btd_adv_manager_destroy(struct btd_adv_manager *manager) static void manager_refresh(void *data, void *user_data) { - refresh_adv(data, user_data, NULL); + struct btd_adv_client *client = data; + + refresh_advertisement(client, user_data, NULL); } void btd_adv_manager_refresh(struct btd_adv_manager *manager) From patchwork Thu Oct 29 21:23:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Winkler X-Patchwork-Id: 11867549 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F412C4741F for ; Thu, 29 Oct 2020 21:24:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C11E320838 for ; Thu, 29 Oct 2020 21:24:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Vh/F7xBe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726528AbgJ2VYA (ORCPT ); Thu, 29 Oct 2020 17:24:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbgJ2VYA (ORCPT ); Thu, 29 Oct 2020 17:24:00 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E988EC0613CF for ; Thu, 29 Oct 2020 14:23:59 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id y11so4066427ybm.22 for ; Thu, 29 Oct 2020 14:23:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=u+Hok0SjaVZEId5o72brIfJOgIbEOMTDJClF83T+CY4=; b=Vh/F7xBegU1FfPUFGcyS30Y6G+a6T1tsaheDs3xy2BdRkK7+AKVWyo3T0GMTGtIHa8 4qizXz5CUWsReFnbEUdVHdFqOHneUMjVPrt1aB4vXLG2ldGZlqZHHirjeOFD+FZ2pgcU ZRhDPqEx6Sf8a3RbntIpkT1FsgWl3nl5DNBHvGkAFK3upUZuS8MDeqVTQ8Q71hOUs/7X ClVNZJMkdq47JJUFM1EiDQgLoUhwnsT0klWGd/SFa3ilKDc5fl/7SwKBL9PaJ9azrju2 13DKdUeoAoQaVkQtKGnD5rNM6/xm4Mj7dFVn+6u5DiCqnHNnKYLQl8xbdR13j3kYZUG/ +I9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=u+Hok0SjaVZEId5o72brIfJOgIbEOMTDJClF83T+CY4=; b=DxtZLb3iDrhxJ5//3cAc5RIj8NhpL+QoyygqrXwiNYY38kwu6oNdbO3OhzQpM75+Q8 3l8Oo6VNWBftXEezc+WEhxT6LSG+mvE81USXtm6DvgwfIFriYsYWTgkLkvZVaOPDDDyV cV11FneCC5ITQvgxjhDkBr5Zn6GoSv5cr2pIVp0zdTXWbY8No8DfKjeOQxewI3LdtFVh Q/BKqTp1vWrGeOjUiG39fn+v/qJfYh2jWGHdM2dQygaTs24JQoAGAAxvwiVyCZ5kmDe5 3UEalDTcS4KnBluMXFzcAJCpLLLLdiMXBsvEziDwSaPRluj2bARfJb0kFisivWMkifg+ gFIQ== X-Gm-Message-State: AOAM532KhZ2zD0IQXvBCfHjGJewPELzJA1adaKytYv4IdVyRM9oeMhuX dEQPARXCbqDfWlwSr2ntnb5PtMqFiJPPBvxLULiy X-Google-Smtp-Source: ABdhPJzloO06Rc1pCI6wNiz0o9UvZCTR/TkketSx06MknJnl8Houk9URHc07vqVJ4mNrCH5AcNXuRbsns9/w7gopWGcf Sender: "danielwinkler via sendgmr" X-Received: from danielwinkler-linux.mtv.corp.google.com ([2620:15c:202:201:f693:9fff:fef4:4e59]) (user=danielwinkler job=sendgmr) by 2002:a25:2fc2:: with SMTP id v185mr8194365ybv.107.1604006639187; Thu, 29 Oct 2020 14:23:59 -0700 (PDT) Date: Thu, 29 Oct 2020 14:23:32 -0700 In-Reply-To: <20201029212336.3283410-1-danielwinkler@google.com> Message-Id: <20201029141832.Bluez.v5.7.I187f71748b9bd93f6bf97ec4a195216109c3ea06@changeid> Mime-Version: 1.0 References: <20201029212336.3283410-1-danielwinkler@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [Bluez PATCH v5 07/10] advertising: Query LE TX range at manager initialization From: Daniel Winkler To: luiz.von.dentz@intel.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Daniel Winkler , Sonny Sasaka , Alain Michaud Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch calls the new MGMT command to get controller capabilities, and parses the min and max LE tx power range when the manager is initialized. This will be used to populate a client-facing dbus entry so that the client will know the advertising capabilities of the controller before registering an advertisement. This patch is tested by manually verifying the data is parsed correctly from the MGMT response. Reviewed-by: Sonny Sasaka Reviewed-by: Alain Michaud --- Changes in v5: - Verify capabilities MGMT command is supported before calling it Changes in v4: - Move tx power range into single capability field Changes in v3: None Changes in v2: None lib/mgmt.h | 14 ++++++++---- src/adapter.c | 4 ++++ src/adapter.h | 1 + src/advertising.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ tools/btmgmt.c | 12 +++++----- 5 files changed, 77 insertions(+), 10 deletions(-) diff --git a/lib/mgmt.h b/lib/mgmt.h index 7ab4fb797..f37f7e654 100644 --- a/lib/mgmt.h +++ b/lib/mgmt.h @@ -599,10 +599,16 @@ struct mgmt_cp_set_blocked_keys { struct mgmt_blocked_key_info keys[0]; } __packed; -#define MGMT_OP_READ_SECURITY_INFO 0x0048 -struct mgmt_rp_read_security_info { - uint16_t sec_len; - uint8_t sec[0]; +#define MGMT_CAP_SEC_FLAGS 0x01 +#define MGMT_CAP_MAX_ENC_KEY_SIZE 0x02 +#define MGMT_CAP_SMP_MAX_ENC_KEY_SIZE 0x03 +#define MGMT_CAP_LE_TX_PWR 0x04 + +#define MGMT_OP_READ_CONTROLLER_CAP 0x0048 +#define MGMT_READ_CONTROLLER_CAP_SIZE 0 +struct mgmt_rp_read_controller_cap { + uint16_t cap_len; + uint8_t cap[0]; } __packed; #define MGMT_OP_READ_EXP_FEATURES_INFO 0x0049 diff --git a/src/adapter.c b/src/adapter.c index 0e035172e..f21598feb 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -9644,6 +9644,10 @@ static void read_commands_complete(uint8_t status, uint16_t length, DBG("kernel supports ext adv commands"); kernel_features |= KERNEL_HAS_EXT_ADV_ADD_CMDS; break; + case MGMT_OP_READ_CONTROLLER_CAP: + DBG("kernel supports controller cap command"); + kernel_features |= KERNEL_HAS_CONTROLLER_CAP_CMD; + break; default: break; } diff --git a/src/adapter.h b/src/adapter.h index ace72affd..e5750a37b 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -234,6 +234,7 @@ enum kernel_features { KERNEL_EXP_FEATURES = 1 << 3, KERNEL_HAS_RESUME_EVT = 1 << 4, KERNEL_HAS_EXT_ADV_ADD_CMDS = 1 << 5, + KERNEL_HAS_CONTROLLER_CAP_CMD = 1 << 6, }; bool btd_has_kernel_features(uint32_t feature); diff --git a/src/advertising.c b/src/advertising.c index 428cd9562..5ed2edf44 100644 --- a/src/advertising.c +++ b/src/advertising.c @@ -49,6 +49,8 @@ struct btd_adv_manager { uint32_t supported_flags; unsigned int instance_bitmap; bool extended_add_cmds; + int8_t min_tx_power; + int8_t max_tx_power; }; #define AD_TYPE_BROADCAST 0 @@ -1701,6 +1703,49 @@ static void read_adv_features_callback(uint8_t status, uint16_t length, remove_advertising(manager, 0); } +static void read_controller_cap_complete(uint8_t status, uint16_t length, + const void *param, void *user_data) +{ + struct btd_adv_manager *manager = user_data; + const struct mgmt_rp_read_controller_cap *rp = param; + const uint8_t *ptr = rp->cap; + size_t offset = 0; + uint8_t tag_len; + uint8_t tag_type; + + if (status || !param) { + error("Failed to read advertising features: %s (0x%02x)", + mgmt_errstr(status), status); + return; + } + + if (sizeof(rp->cap_len) + rp->cap_len != length) { + error("Controller capabilities malformed, size %lu != %u", + sizeof(rp->cap_len) + rp->cap_len, length); + return; + } + + while (offset < rp->cap_len) { + tag_len = ptr[offset++]; + tag_type = ptr[offset++]; + + switch (tag_type) { + case MGMT_CAP_LE_TX_PWR: + if ((tag_len - sizeof(tag_type)) != + 2*sizeof(manager->min_tx_power)) { + error("TX power had unexpected length %d", + tag_len); + break; + } + memcpy(&manager->min_tx_power, &ptr[offset], tag_len); + memcpy(&manager->max_tx_power, &ptr[offset+1], tag_len); + } + + /* Step to the next entry */ + offset += (tag_len - sizeof(tag_type)); + } +} + static struct btd_adv_manager *manager_create(struct btd_adapter *adapter, struct mgmt *mgmt) { @@ -1722,6 +1767,8 @@ static struct btd_adv_manager *manager_create(struct btd_adapter *adapter, manager->supported_flags = MGMT_ADV_FLAG_LOCAL_NAME; manager->extended_add_cmds = btd_has_kernel_features(KERNEL_HAS_EXT_ADV_ADD_CMDS); + manager->min_tx_power = ADV_TX_POWER_NO_PREFERENCE; + manager->max_tx_power = ADV_TX_POWER_NO_PREFERENCE; if (!g_dbus_register_interface(btd_get_dbus_connection(), adapter_get_path(manager->adapter), @@ -1738,6 +1785,15 @@ static struct btd_adv_manager *manager_create(struct btd_adapter *adapter, goto fail; } + /* Query controller capabilities. This will be used to display valid + * advertising tx power range to the client. + */ + if (g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL && + btd_has_kernel_features(KERNEL_HAS_CONTROLLER_CAP_CMD)) + mgmt_send(manager->mgmt, MGMT_OP_READ_CONTROLLER_CAP, + manager->mgmt_index, 0, NULL, + read_controller_cap_complete, manager, NULL); + return manager; fail: diff --git a/tools/btmgmt.c b/tools/btmgmt.c index b0b837d34..2f7cb2efc 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -1518,7 +1518,7 @@ static void cmd_extinfo(int argc, char **argv) static void sec_info_rsp(uint8_t status, uint16_t len, const void *param, void *user_data) { - const struct mgmt_rp_read_security_info *rp = param; + const struct mgmt_rp_read_controller_cap *rp = param; uint16_t index = PTR_TO_UINT(user_data); if (status != 0) { @@ -1533,7 +1533,7 @@ static void sec_info_rsp(uint8_t status, uint16_t len, const void *param, } print("Primary controller (hci%u)", index); - print("\tSecurity info length: %u", le16_to_cpu(rp->sec_len)); + print("\tSecurity info length: %u", le16_to_cpu(rp->cap_len)); done: pending_index--; @@ -1576,11 +1576,11 @@ static void sec_index_rsp(uint8_t status, uint16_t len, const void *param, if (rp->entry[i].type != 0x00) continue; - if (!mgmt_send(mgmt, MGMT_OP_READ_SECURITY_INFO, + if (!mgmt_send(mgmt, MGMT_OP_READ_CONTROLLER_CAP, index, 0, NULL, sec_info_rsp, UINT_TO_PTR(index), NULL)) { - error("Unable to send read_security_info cmd"); - return bt_shell_noninteractive_quit(EXIT_FAILURE); + error("Unable to send read_security_info cmd"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); } pending_index++; } @@ -1602,7 +1602,7 @@ static void cmd_secinfo(int argc, char **argv) return; } - if (!mgmt_send(mgmt, MGMT_OP_READ_SECURITY_INFO, mgmt_index, 0, NULL, + if (!mgmt_send(mgmt, MGMT_OP_READ_CONTROLLER_CAP, mgmt_index, 0, NULL, sec_info_rsp, UINT_TO_PTR(mgmt_index), NULL)) { error("Unable to send read_security_info cmd"); From patchwork Thu Oct 29 21:23:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Winkler X-Patchwork-Id: 11867551 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54987C2D0A3 for ; Thu, 29 Oct 2020 21:24:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E897F20838 for ; Thu, 29 Oct 2020 21:24:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="i/+C17SH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726581AbgJ2VYD (ORCPT ); Thu, 29 Oct 2020 17:24:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbgJ2VYD (ORCPT ); Thu, 29 Oct 2020 17:24:03 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB647C0613CF for ; Thu, 29 Oct 2020 14:24:01 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id x125so4064321yba.17 for ; Thu, 29 Oct 2020 14:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=/6ckWU4P9kOQQn4bPjgVIjuXAYYlJBgep6JJu1NnBoY=; b=i/+C17SHZp7eXw+vkDJdmMaF/wDTufbCR3cQFRsU3B/JkSAtjA0xdKYnutSR/xBS/k lTrPHieG6SMQ3kL6gATMXhfE+enMkRY0egVrAtbgj8b1CV7XgMzOah6EYEgismQCvhDC cZ+XgCzGStDBim0f0ubTzfUhT77fS0grsRq7uGdlBxwjq5+6J0dxM5bTQvSN+n7E/W2B 95f8S91C5/oGiw81SDqsqcsPQqTPCXLFoT+5cVGuSnOQ26QCUsT8uO9BE/QYXf6iw1fN nOM90Fvj5vRdq5Z/DnnClPuGt8M1tpBEspgG07nIbcb+ku1Fu3iXiytC4K/OVhyFm1Xl s9Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=/6ckWU4P9kOQQn4bPjgVIjuXAYYlJBgep6JJu1NnBoY=; b=HeqM+8nPfR1Oci/uC3sn+rcESmMww9Cl0N2eParYOI1Uc5rNivdW5svo/rZIidjxNT Gm8IESombwjw7u55QSiIzkndPyfIsFJqXeOOvR7n+6CRQ1tiv1ufKCXu49v2HQQYFGhk 3f2hNbBl9OVC/w6P2tv3xmA7VOKuaDkJ5tI2YOjsCE7PT4z0VV0TpW+uC2rCjf0a3zK5 HxBN/bFkwzlBUYBaLUtV49Q+EB+5HfLnkKsMxYnyT+lXhaKxWZvq4etJEQGzQJzPq9g1 bsUP4+nmPLqqEuCrVz1wWUMeu9MjISI7zR4P57+piIEHW7lE20/dERBrLf/hV51+F0rW ujPg== X-Gm-Message-State: AOAM530yK1BxtwEPKRL9bu72RFyoKPbsYiAad6TSZHGVij9YveMGII9O ttqUb/cBwC3niwfK3j2g5riOpchUXryms3oBDg4I X-Google-Smtp-Source: ABdhPJxNRmrh0Gyqpv3ywdqwJjjippEClYmorC1gk6CseM4WKNM0Z5G/1YvTYIbfUa6N9yqAt1Y4r/j8khmV9uZ0ZJqs Sender: "danielwinkler via sendgmr" X-Received: from danielwinkler-linux.mtv.corp.google.com ([2620:15c:202:201:f693:9fff:fef4:4e59]) (user=danielwinkler job=sendgmr) by 2002:a25:2284:: with SMTP id i126mr8649810ybi.454.1604006641042; Thu, 29 Oct 2020 14:24:01 -0700 (PDT) Date: Thu, 29 Oct 2020 14:23:33 -0700 In-Reply-To: <20201029212336.3283410-1-danielwinkler@google.com> Message-Id: <20201029141832.Bluez.v5.8.I4e536cf2c9b6c5571b4b3800dfb8338fce8e4421@changeid> Mime-Version: 1.0 References: <20201029212336.3283410-1-danielwinkler@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [Bluez PATCH v5 08/10] advertising: Expose SupportedCapabilities for advertising From: Daniel Winkler To: luiz.von.dentz@intel.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Daniel Winkler , Sonny Sasaka , Alain Michaud Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org To help our advertising clients understand the device capabilities, this patch adds a SupportedCapabilities dbus endpoint for the advertising manager. The primary reason behind this is to provide the valid LE tx power range the controller supports (populated if controller supports BT5), so a client can know the valid power range before requesting a tx power for their advertisement. I also thought it would be useful to indicate the max advertising data length and scan response length in this endpoint, since some clients will find it useful to set their advertising data (currently experimental feature) or scan response data (possible future feature) directly. This patch has been tested on Hatch (BT5 support) and Kukui (No BT5 support) chromebooks to verify that the dbus endpoint contains the correct data. Reviewed-by: Sonny Sasaka Reviewed-by: Alain Michaud --- Changes in v5: - Make SupportedCapabilities experimental Changes in v4: None Changes in v3: None Changes in v2: None src/advertising.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/advertising.c b/src/advertising.c index 5ed2edf44..62fb3b939 100644 --- a/src/advertising.c +++ b/src/advertising.c @@ -1641,12 +1641,47 @@ static gboolean get_supported_secondary(const GDBusPropertyTable *property, return TRUE; } +static gboolean get_supported_cap(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct btd_adv_manager *manager = data; + DBusMessageIter dict; + int16_t min_tx_power = manager->min_tx_power; + int16_t max_tx_power = manager->max_tx_power; + + dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + DBUS_TYPE_VARIANT_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, + &dict); + + if (min_tx_power != ADV_TX_POWER_NO_PREFERENCE) + dict_append_entry(&dict, "MinTxPower", DBUS_TYPE_INT16, + &min_tx_power); + + if (max_tx_power != ADV_TX_POWER_NO_PREFERENCE) + dict_append_entry(&dict, "MaxTxPower", DBUS_TYPE_INT16, + &max_tx_power); + + dict_append_entry(&dict, "MaxAdvLen", DBUS_TYPE_BYTE, + &manager->max_adv_len); + dict_append_entry(&dict, "MaxScnRspLen", DBUS_TYPE_BYTE, + &manager->max_scan_rsp_len); + + dbus_message_iter_close_container(iter, &dict); + + return TRUE; +} + static const GDBusPropertyTable properties[] = { { "ActiveInstances", "y", get_active_instances, NULL, NULL }, { "SupportedInstances", "y", get_instances, NULL, NULL }, { "SupportedIncludes", "as", get_supported_includes, NULL, NULL }, { "SupportedSecondaryChannels", "as", get_supported_secondary, NULL, secondary_exits }, + { "SupportedCapabilities", "a{sv}", get_supported_cap, NULL, NULL, + G_DBUS_PROPERTY_FLAG_EXPERIMENTAL}, { } }; From patchwork Thu Oct 29 21:23:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Winkler X-Patchwork-Id: 11867557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6090CC4741F for ; Thu, 29 Oct 2020 21:24:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 011AC20838 for ; Thu, 29 Oct 2020 21:24:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="s68fTeMa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726598AbgJ2VYF (ORCPT ); Thu, 29 Oct 2020 17:24:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbgJ2VYF (ORCPT ); Thu, 29 Oct 2020 17:24:05 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAE71C0613CF for ; Thu, 29 Oct 2020 14:24:03 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id a184so4088367ybg.10 for ; Thu, 29 Oct 2020 14:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=qKOSAfxbo2WQ7eoCYPvc65pmopU6F6CL3Vl9PMf/9bg=; b=s68fTeMaWjls9cuyb2O73+E6i0w+Dx3Fh0grXjFRDPEIQrcI1xYcT0xF6RNV37j0iz X9ISzQH6KBzA7/0SZvlQa/2eRhGXtGLmMoSyNnL244Z0pvjZMzYOPjB1y07d5GBi/yzj n1lCu6PeFljn6xUVQjW7emKgDBzHIJvqcff5XwNvOfJT61e/+JxwY+dG8QDY014pn/4R 6ieVI03c5LcT10YMmvJtzAzISbK1VHHgtuspqTkJrt9Ijfvs2YbF71uOZZCqTaacnGco chLbfxhdMwA5Pe8FXliOydphJHIFXIXUOK+SEQugoDpT0D0MkaV8Z96Pel2/ZC91EGY7 Fjxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=qKOSAfxbo2WQ7eoCYPvc65pmopU6F6CL3Vl9PMf/9bg=; b=Vlfkq3Zg5Oqz6bUHb3+mAav0uMwqM6w01yg6G/8Iiesaxt+cOXLMwFewgQtEoqlT15 LFCTRLTPcPGLbKN3A12ap31bRxzEMU29WoHCF+HqeKu++wLy7TUBXpn9PY+xq9PWlgEK fEPT/nOM0NPkZ4TdWcuqU7rHcUb5VvgOTl/bbNkz9IeUh0ZEC0bTKGZS1aWrD78684a3 7DGb3USVWjn0qN3/PBbXdqYHM7C809ueVMCwnVf/7iv2FQJnXis1F4n9ZuqUpWl1P8Ty MMHKhyXljQg8P2C0Fx452a0Ioz4NZLbEmfezIkj8uQQXoQeECBPS0eAuYz41eivSvm+R 7oFw== X-Gm-Message-State: AOAM533nZ8qxW9zYapw1gPuYqThqhodaxY9wnUTBMjyYCcBns07k3lPW WKTvIn9eBIrUck8AHiSE8XIatdjZdyq83HRs35n/ X-Google-Smtp-Source: ABdhPJxzqbCSMXhotdsqw1DTmPWVdadxvszxewDwkXaPUvhv0nBL/3SD1OSimOfhShSMhnP/zL+T0JtDlFCjTyuzY2Ms Sender: "danielwinkler via sendgmr" X-Received: from danielwinkler-linux.mtv.corp.google.com ([2620:15c:202:201:f693:9fff:fef4:4e59]) (user=danielwinkler job=sendgmr) by 2002:a25:7306:: with SMTP id o6mr7942824ybc.310.1604006642966; Thu, 29 Oct 2020 14:24:02 -0700 (PDT) Date: Thu, 29 Oct 2020 14:23:34 -0700 In-Reply-To: <20201029212336.3283410-1-danielwinkler@google.com> Message-Id: <20201029141832.Bluez.v5.9.Ic9eec7749b769aa5bf73a0d8e9a31be83f232f1c@changeid> Mime-Version: 1.0 References: <20201029212336.3283410-1-danielwinkler@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [Bluez PATCH v5 09/10] client: Add SupportedCapabilities to bluetoothctl From: Daniel Winkler To: luiz.von.dentz@intel.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Daniel Winkler , Sonny Sasaka , Alain Michaud Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch adds the new "SupportedCapabilities" property to the bluetoothctl "show" view. The change is tested by verifying bluetoothctl shows the desired properties. Reviewed-by: Sonny Sasaka Reviewed-by: Alain Michaud --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None client/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/client/main.c b/client/main.c index 60f1eb86e..9403f1af6 100644 --- a/client/main.c +++ b/client/main.c @@ -941,6 +941,7 @@ static void cmd_show(int argc, char *argv[]) print_property(adapter->ad_proxy, "SupportedInstances"); print_property(adapter->ad_proxy, "SupportedIncludes"); print_property(adapter->ad_proxy, "SupportedSecondaryChannels"); + print_property(adapter->ad_proxy, "SupportedCapabilities"); } if (adapter->adv_monitor_proxy) { From patchwork Thu Oct 29 21:23:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Winkler X-Patchwork-Id: 11867555 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3ABF7C4742C for ; Thu, 29 Oct 2020 21:24:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D12D720838 for ; Thu, 29 Oct 2020 21:24:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FgDriqeZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726606AbgJ2VYG (ORCPT ); Thu, 29 Oct 2020 17:24:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726590AbgJ2VYF (ORCPT ); Thu, 29 Oct 2020 17:24:05 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B700C0613CF for ; Thu, 29 Oct 2020 14:24:05 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id a24so3140020pfh.20 for ; Thu, 29 Oct 2020 14:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=+EZS+0iqfqUdZXX+nBYUo2f3rJ8zcuppXhxUZFI276Q=; b=FgDriqeZ/rv0j7Tf3XHHXrFbkwwxZQyb9rNlR3l8KWBZ/fGw2aa0vDcvkxQ4GasDDh 9WB/xlkRF7H/+z1SldUKp5wh/6TtgVHn0rJ6YamX2nG9JghTGbW/IhU0NQeYZKxfj6Z+ jQ/42m9J5qAhvGPffl+HjRauVAydH592pqMmHIWd+h9WXnBwx2gRslyjY8R6tgBukE99 ttDI7VYAbd37NmM3OwRP/+0GgrNHNk1k2YN1SirFZRAZpRkX31NwkzWrv7k1ITvoL9J8 gxMO06HswbRTyVYa5k9WBQBWFK/w3Mjsw+9i7G51HhzPwxq2TUpfoYJHGMzADM9knJvG Jdlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+EZS+0iqfqUdZXX+nBYUo2f3rJ8zcuppXhxUZFI276Q=; b=aEXKKAR1jLGKjxVcIG3+wpyv3ZxvgISvLVzvCmdf3VqV1CG4egCw+XznbQ1GMcwGBX k7zLA6ZjTzj9dHQBfJ5R31sVttY7DeGyUmA65H0/HMk8VwfqRKhsgybzqwIZjAffZ/ss O4K3Hrhapc9iZHqKVLrQAULSwnvM3W3Bhy19PFwlGW+5Ls9QuFZ7xL+6euMe0O/JJ8v6 GuYpp5AKt7QKJJnJNPgd4MS7ZTuDwLulQHLC11zsmop4EJxrqcc2KBYDIb37+44syFuF esKZzWO5yo9Py+Hu7alnPGyPzqTL/sDA3C9echlhaNzTCI6/J+lg5OKMzN4G7eRUCRul lxgQ== X-Gm-Message-State: AOAM530FBGJ/Ya5qcmTPOE9miPKS2XbsECtcjOTiXg8zDKsSQY5ynF/b o3X5VC7cmJc/DY+xmGVmzj+mIP/2wq8TlYStsWD3 X-Google-Smtp-Source: ABdhPJzvCHA1ZjK/3oWRSD6PXAn/6DCB5Iy7ob72rKI7wxPZw4nnZs8AMVYpthVIppQDIWHUiDPJiqLqrFH46Wl539wU Sender: "danielwinkler via sendgmr" X-Received: from danielwinkler-linux.mtv.corp.google.com ([2620:15c:202:201:f693:9fff:fef4:4e59]) (user=danielwinkler job=sendgmr) by 2002:a62:8cd2:0:b029:163:b01f:405d with SMTP id m201-20020a628cd20000b0290163b01f405dmr6393394pfd.48.1604006645097; Thu, 29 Oct 2020 14:24:05 -0700 (PDT) Date: Thu, 29 Oct 2020 14:23:35 -0700 In-Reply-To: <20201029212336.3283410-1-danielwinkler@google.com> Message-Id: <20201029141832.Bluez.v5.10.I2884e6456c272dadb3d70a629674027f23b0393e@changeid> Mime-Version: 1.0 References: <20201029212336.3283410-1-danielwinkler@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [Bluez PATCH v5 10/10] monitor: Add new MGMT adv commands and events to monitor From: Daniel Winkler To: luiz.von.dentz@intel.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Daniel Winkler , Sonny Sasaka , Alain Michaud Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This change adds the following to packet monitor: -Add Ext Adv Params command and response -Add Ext Adv Data command and response This patch was manually tested by registering advertisements with various features and verifying in btmon log. Reviewed-by: Sonny Sasaka Reviewed-by: Alain Michaud --- Changes in v5: None Changes in v4: None Changes in v3: - Removed Tx Power Selected MGMT event from monitor Changes in v2: None monitor/packet.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/monitor/packet.c b/monitor/packet.c index 615c180f8..b67510f6d 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -11844,8 +11844,16 @@ 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" }, + { 12, "Use provided duration parameter" }, + { 13, "Use provided timeout parameter" }, + { 14, "Use provided interval parameters" }, + { 15, "Use provided tx power parameter" }, { } }; +#define MGMT_ADV_PARAM_DURATION (1 << 12) +#define MGMT_ADV_PARAM_TIMEOUT (1 << 13) +#define MGMT_ADV_PARAM_INTERVALS (1 << 14) +#define MGMT_ADV_PARAM_TX_POWER (1 << 15) static void mgmt_print_adv_flags(uint32_t flags) { @@ -13150,6 +13158,57 @@ static void mgmt_set_device_flags_rsp(const void *data, uint16_t size) mgmt_print_address(data, type); } +static void mgmt_add_ext_adv_params_cmd(const void *data, uint16_t size) +{ + uint8_t instance = get_u8(data); + uint32_t flags = get_le32(data + 1); + uint16_t duration = get_le16(data + 5); + uint16_t timeout = get_le16(data + 7); + uint8_t *min_interval = (uint8_t *)(data + 9); + uint8_t *max_interval = (uint8_t *)(data + 13); + int8_t tx_power = get_s8(data + 17); + + print_field("Instance: %u", instance); + mgmt_print_adv_flags(flags); + print_field("Duration: %u", duration); + print_field("Timeout: %u", timeout); + print_ext_slot_625("Min advertising interval", min_interval); + print_ext_slot_625("Max advertising interval", max_interval); + print_power_level(tx_power, NULL); +} + +static void mgmt_add_ext_adv_params_rsp(const void *data, uint16_t size) +{ + uint8_t instance = get_u8(data); + int8_t tx_power = get_s8(data + 1); + uint8_t max_adv_data_len = get_u8(data+2); + uint8_t max_scan_rsp_len = get_u8(data+3); + + print_field("Instance: %u", instance); + print_power_level(tx_power, NULL); + print_field("Available adv data len: %u", max_adv_data_len); + print_field("Available scan rsp data len: %u", max_scan_rsp_len); +} + +static void mgmt_add_ext_adv_data_cmd(const void *data, uint16_t size) +{ + uint8_t instance = get_u8(data); + uint8_t adv_data_len = get_u8(data + 1); + uint8_t scan_rsp_len = get_u8(data + 2); + + print_field("Instance: %u", instance); + print_field("Advertising data length: %u", adv_data_len); + print_eir(data + 3, adv_data_len, false); + print_field("Scan response length: %u", scan_rsp_len); + print_eir(data + 3 + adv_data_len, scan_rsp_len, false); +} + +static void mgmt_add_ext_adv_data_rsp(const void *data, uint16_t size) +{ + uint8_t instance = get_u8(data); + + print_field("Instance: %u", instance); +} struct mgmt_data { uint16_t opcode; @@ -13382,6 +13441,12 @@ static const struct mgmt_data mgmt_command_table[] = { { 0x0050, "Set Device Flags", mgmt_set_device_flags_cmd, 11, true, mgmt_set_device_flags_rsp, 7, true}, + { 0x0054, "Add Ext Adv Params", + mgmt_add_ext_adv_params_cmd, 18, false, + mgmt_add_ext_adv_params_rsp, 4, true }, + { 0x0055, "Add Ext Adv Data", + mgmt_add_ext_adv_data_cmd, 3, false, + mgmt_add_ext_adv_data_rsp, 1, true }, { } };