* [Bluez PATCH v3 0/2] Bluetooth: Fix scannable broadcast advertising on extended APIs
@ 2021-03-16 22:49 Daniel Winkler
2021-03-16 22:49 ` [Bluez PATCH v3 1/2] advertising: Create and use scannable adv param flag Daniel Winkler
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Daniel Winkler @ 2021-03-16 22:49 UTC (permalink / raw)
To: linux-bluetooth, luiz.dentz
Cc: chromeos-bluetooth-upstreaming, Daniel Winkler
Hello Maintainers,
We have discovered that when userspace registers a broadcast
(non-connectable) advertisement with scan response data, it exposes a
limitation in the new extended MGMT APIs. At the time that the
parameters are registered with the controller, kernel does not yet have
the advertising data and scan response (coming in a separate MGMT call),
and will default to a non-scannable PDU. When the MGMT call for
data/scan response is received, the controller will either fail when we
request to set the scan response, or return success and not use it.
This series along with another in kernel will allow userspace to pass a
flag with the params request indicating if the advertisement contains a
scan response. This allows kernel to register the parameters correctly
with the controller.
The patch is tested with a scannable broadcast advertisement on Hatch
and Kukui chromebooks (ext and non-ext capabilities) and ensuring a
peripheral device can detect the scan response.
Best,
Daniel
Changes in v3:
- Use helpers to determine scannable rather than generating earlier
Changes in v2:
- Check kernel supports flag before setting it
Daniel Winkler (2):
advertising: Create and use scannable adv param flag
doc/mgmt-api: Update documentation for scan_rsp param flag
doc/mgmt-api.txt | 5 +++++
lib/mgmt.h | 1 +
src/advertising.c | 24 +++++++++++++++++++++++-
src/shared/ad.c | 17 +++++++++++++++++
src/shared/ad.h | 2 ++
5 files changed, 48 insertions(+), 1 deletion(-)
--
2.31.0.rc2.261.g7f71774620-goog
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bluez PATCH v3 1/2] advertising: Create and use scannable adv param flag
2021-03-16 22:49 [Bluez PATCH v3 0/2] Bluetooth: Fix scannable broadcast advertising on extended APIs Daniel Winkler
@ 2021-03-16 22:49 ` Daniel Winkler
2021-03-16 22:49 ` [Bluez PATCH v3 2/2] doc/mgmt-api: Update documentation for scan_rsp " Daniel Winkler
2021-03-22 16:32 ` [Bluez PATCH v3 0/2] Bluetooth: Fix scannable broadcast advertising on extended APIs Daniel Winkler
2 siblings, 0 replies; 5+ messages in thread
From: Daniel Winkler @ 2021-03-16 22:49 UTC (permalink / raw)
To: linux-bluetooth, luiz.dentz
Cc: chromeos-bluetooth-upstreaming, Daniel Winkler, Sonny Sasaka,
Miao-chen Chou
In order for the advertising parameters hci request to indicate that an
advertising set uses a scannable PDU, we pass a scannable flag along
with the initial parameters MGMT request. This flag is populated based
on the existence of any scan response data requested by the client.
Without this patch, a broadcast advertisement with a scan response will
either be rejected by the controller, or will ignore the requested scan
response. The patch is tested by performing the above and confirming
that the scan response is retrievable from a peer as expected.
Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
---
Changes in v3:
- Use helpers to determine scannable rather than generating earlier
Changes in v2:
- Check kernel supports flag before setting it
lib/mgmt.h | 1 +
src/advertising.c | 24 +++++++++++++++++++++++-
src/shared/ad.c | 17 +++++++++++++++++
src/shared/ad.h | 2 ++
4 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/lib/mgmt.h b/lib/mgmt.h
index 76a03c9c2..7b1b9ab54 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -507,6 +507,7 @@ struct mgmt_rp_add_advertising {
#define MGMT_ADV_PARAM_TIMEOUT (1 << 13)
#define MGMT_ADV_PARAM_INTERVALS (1 << 14)
#define MGMT_ADV_PARAM_TX_POWER (1 << 15)
+#define MGMT_ADV_PARAM_SCAN_RSP (1 << 16)
#define MGMT_OP_REMOVE_ADVERTISING 0x003F
struct mgmt_cp_remove_advertising {
diff --git a/src/advertising.c b/src/advertising.c
index d76e97a74..4ea0e60ee 100644
--- a/src/advertising.c
+++ b/src/advertising.c
@@ -793,6 +793,22 @@ static uint8_t *generate_scan_rsp(struct btd_adv_client *client,
return bt_ad_generate(client->scan, len);
}
+static bool adv_client_has_scan_response(struct btd_adv_client *client,
+ uint32_t flags)
+{
+ /* The local name isn't added into the bt_ad structure until
+ * generate_scan_rsp is called, so we must check these conditions as
+ * well.
+ */
+ if (!(flags & MGMT_ADV_FLAG_LOCAL_NAME) &&
+ !client->name &&
+ bt_ad_is_empty(client->scan)) {
+ return false;
+ }
+
+ return true;
+}
+
static int get_adv_flags(struct btd_adv_client *client)
{
uint32_t flags = 0;
@@ -917,7 +933,13 @@ static int refresh_extended_adv(struct btd_adv_client *client,
flags |= MGMT_ADV_PARAM_TX_POWER;
}
- cp.flags = htobl(flags);
+ /* Indicate that this instance will be configured as scannable */
+ if (adv_client_has_scan_response(client, flags) &&
+ client->manager->supported_flags & MGMT_ADV_PARAM_SCAN_RSP) {
+ flags |= MGMT_ADV_PARAM_SCAN_RSP;
+ }
+
+ cp.flags = cpu_to_le32(flags);
mgmt_ret = mgmt_send(client->manager->mgmt, MGMT_OP_ADD_EXT_ADV_PARAMS,
client->manager->mgmt_index, sizeof(cp), &cp,
diff --git a/src/shared/ad.c b/src/shared/ad.c
index 23c8c34f4..d40d15331 100644
--- a/src/shared/ad.c
+++ b/src/shared/ad.c
@@ -552,6 +552,23 @@ uint8_t *bt_ad_generate(struct bt_ad *ad, size_t *length)
return adv_data;
}
+bool bt_ad_is_empty(struct bt_ad *ad)
+{
+ /* If any of the bt_ad fields are non-empty or don't have the default
+ * value, then bt_ad_generate will return a non-empty buffer
+ */
+ if (!ad->name &&
+ ad->appearance == UINT16_MAX &&
+ queue_isempty(ad->service_uuids) &&
+ queue_isempty(ad->manufacturer_data) &&
+ queue_isempty(ad->solicit_uuids) &&
+ queue_isempty(ad->service_data) &&
+ queue_isempty(ad->data)) {
+ return true;
+ }
+ return false;
+}
+
static bool queue_add_uuid(struct queue *queue, const bt_uuid_t *uuid)
{
bt_uuid_t *new_uuid;
diff --git a/src/shared/ad.h b/src/shared/ad.h
index 13adcb406..84ef9dee9 100644
--- a/src/shared/ad.h
+++ b/src/shared/ad.h
@@ -105,6 +105,8 @@ void bt_ad_unref(struct bt_ad *ad);
uint8_t *bt_ad_generate(struct bt_ad *ad, size_t *length);
+bool bt_ad_is_empty(struct bt_ad *ad);
+
bool bt_ad_add_service_uuid(struct bt_ad *ad, const bt_uuid_t *uuid);
bool bt_ad_remove_service_uuid(struct bt_ad *ad, bt_uuid_t *uuid);
--
2.31.0.rc2.261.g7f71774620-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Bluez PATCH v3 2/2] doc/mgmt-api: Update documentation for scan_rsp param flag
2021-03-16 22:49 [Bluez PATCH v3 0/2] Bluetooth: Fix scannable broadcast advertising on extended APIs Daniel Winkler
2021-03-16 22:49 ` [Bluez PATCH v3 1/2] advertising: Create and use scannable adv param flag Daniel Winkler
@ 2021-03-16 22:49 ` Daniel Winkler
2021-03-22 16:32 ` [Bluez PATCH v3 0/2] Bluetooth: Fix scannable broadcast advertising on extended APIs Daniel Winkler
2 siblings, 0 replies; 5+ messages in thread
From: Daniel Winkler @ 2021-03-16 22:49 UTC (permalink / raw)
To: linux-bluetooth, luiz.dentz
Cc: chromeos-bluetooth-upstreaming, Daniel Winkler, Alain Michaud,
Sonny Sasaka
This patch adds the new scannable flag to the Add Extended Advertising
Parameters MGMT API documentation.
Reviewed-by: Alain Michaud <alainm@chromium.org>
Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
---
Changes in v3: None
Changes in v2: None
doc/mgmt-api.txt | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
index 1736ef009..cab1fffc5 100644
--- a/doc/mgmt-api.txt
+++ b/doc/mgmt-api.txt
@@ -3632,6 +3632,7 @@ Add Extended Advertising Parameters Command
13 The Timeout parameter should be used
14 The Interval parameters should be used
15 The Tx Power parameter should be used
+ 16 The advertisement will contain a scan response
When the connectable flag is set, then the controller will use
undirected connectable advertising. The value of the connectable
@@ -3708,6 +3709,10 @@ Add Extended Advertising Parameters Command
chosen by the controller. If the requested Tx Power is outside
the valid range, the registration will fail.
+ When flag bit 16 is enabled, it indicates that the subsequent request
+ to set advertising data will contain a scan response, and that the
+ parameters should set a PDU type that is scannable.
+
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
--
2.31.0.rc2.261.g7f71774620-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Bluez PATCH v3 0/2] Bluetooth: Fix scannable broadcast advertising on extended APIs
2021-03-16 22:49 [Bluez PATCH v3 0/2] Bluetooth: Fix scannable broadcast advertising on extended APIs Daniel Winkler
2021-03-16 22:49 ` [Bluez PATCH v3 1/2] advertising: Create and use scannable adv param flag Daniel Winkler
2021-03-16 22:49 ` [Bluez PATCH v3 2/2] doc/mgmt-api: Update documentation for scan_rsp " Daniel Winkler
@ 2021-03-22 16:32 ` Daniel Winkler
2021-03-22 20:19 ` Luiz Augusto von Dentz
2 siblings, 1 reply; 5+ messages in thread
From: Daniel Winkler @ 2021-03-22 16:32 UTC (permalink / raw)
To: BlueZ, Luiz Augusto von Dentz; +Cc: chromeos-bluetooth-upstreaming
Hi Maintainers,
Friendly reminder to review this V3 patch at your convenience.
Thanks!
Daniel
On Tue, Mar 16, 2021 at 3:50 PM Daniel Winkler <danielwinkler@google.com> wrote:
>
> Hello Maintainers,
>
> We have discovered that when userspace registers a broadcast
> (non-connectable) advertisement with scan response data, it exposes a
> limitation in the new extended MGMT APIs. At the time that the
> parameters are registered with the controller, kernel does not yet have
> the advertising data and scan response (coming in a separate MGMT call),
> and will default to a non-scannable PDU. When the MGMT call for
> data/scan response is received, the controller will either fail when we
> request to set the scan response, or return success and not use it.
>
> This series along with another in kernel will allow userspace to pass a
> flag with the params request indicating if the advertisement contains a
> scan response. This allows kernel to register the parameters correctly
> with the controller.
>
> The patch is tested with a scannable broadcast advertisement on Hatch
> and Kukui chromebooks (ext and non-ext capabilities) and ensuring a
> peripheral device can detect the scan response.
>
> Best,
> Daniel
>
> Changes in v3:
> - Use helpers to determine scannable rather than generating earlier
>
> Changes in v2:
> - Check kernel supports flag before setting it
>
> Daniel Winkler (2):
> advertising: Create and use scannable adv param flag
> doc/mgmt-api: Update documentation for scan_rsp param flag
>
> doc/mgmt-api.txt | 5 +++++
> lib/mgmt.h | 1 +
> src/advertising.c | 24 +++++++++++++++++++++++-
> src/shared/ad.c | 17 +++++++++++++++++
> src/shared/ad.h | 2 ++
> 5 files changed, 48 insertions(+), 1 deletion(-)
>
> --
> 2.31.0.rc2.261.g7f71774620-goog
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Bluez PATCH v3 0/2] Bluetooth: Fix scannable broadcast advertising on extended APIs
2021-03-22 16:32 ` [Bluez PATCH v3 0/2] Bluetooth: Fix scannable broadcast advertising on extended APIs Daniel Winkler
@ 2021-03-22 20:19 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2021-03-22 20:19 UTC (permalink / raw)
To: Daniel Winkler; +Cc: BlueZ, chromeos-bluetooth-upstreaming
Hi Daniel,
On Mon, Mar 22, 2021 at 9:32 AM Daniel Winkler <danielwinkler@google.com> wrote:
>
> Hi Maintainers,
>
> Friendly reminder to review this V3 patch at your convenience.
>
> Thanks!
> Daniel
>
>
> On Tue, Mar 16, 2021 at 3:50 PM Daniel Winkler <danielwinkler@google.com> wrote:
> >
> > Hello Maintainers,
> >
> > We have discovered that when userspace registers a broadcast
> > (non-connectable) advertisement with scan response data, it exposes a
> > limitation in the new extended MGMT APIs. At the time that the
> > parameters are registered with the controller, kernel does not yet have
> > the advertising data and scan response (coming in a separate MGMT call),
> > and will default to a non-scannable PDU. When the MGMT call for
> > data/scan response is received, the controller will either fail when we
> > request to set the scan response, or return success and not use it.
> >
> > This series along with another in kernel will allow userspace to pass a
> > flag with the params request indicating if the advertisement contains a
> > scan response. This allows kernel to register the parameters correctly
> > with the controller.
> >
> > The patch is tested with a scannable broadcast advertisement on Hatch
> > and Kukui chromebooks (ext and non-ext capabilities) and ensuring a
> > peripheral device can detect the scan response.
> >
> > Best,
> > Daniel
> >
> > Changes in v3:
> > - Use helpers to determine scannable rather than generating earlier
> >
> > Changes in v2:
> > - Check kernel supports flag before setting it
> >
> > Daniel Winkler (2):
> > advertising: Create and use scannable adv param flag
> > doc/mgmt-api: Update documentation for scan_rsp param flag
> >
> > doc/mgmt-api.txt | 5 +++++
> > lib/mgmt.h | 1 +
> > src/advertising.c | 24 +++++++++++++++++++++++-
> > src/shared/ad.c | 17 +++++++++++++++++
> > src/shared/ad.h | 2 ++
> > 5 files changed, 48 insertions(+), 1 deletion(-)
> >
> > --
> > 2.31.0.rc2.261.g7f71774620-goog
> >
Applied, thanks.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-03-22 20:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-16 22:49 [Bluez PATCH v3 0/2] Bluetooth: Fix scannable broadcast advertising on extended APIs Daniel Winkler
2021-03-16 22:49 ` [Bluez PATCH v3 1/2] advertising: Create and use scannable adv param flag Daniel Winkler
2021-03-16 22:49 ` [Bluez PATCH v3 2/2] doc/mgmt-api: Update documentation for scan_rsp " Daniel Winkler
2021-03-22 16:32 ` [Bluez PATCH v3 0/2] Bluetooth: Fix scannable broadcast advertising on extended APIs Daniel Winkler
2021-03-22 20:19 ` Luiz Augusto von Dentz
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.