mbox series

[Bluez,0/3] Bluetooth: Fix scannable broadcast advertising on extended APIs

Message ID 20210303192012.1695032-1-danielwinkler@google.com
Headers show
Series Bluetooth: Fix scannable broadcast advertising on extended APIs | expand

Message

Daniel Winkler March 3, 2021, 7:20 p.m. UTC
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


Daniel Winkler (3):
  advertising: Generate advertising data earlier in pipeline
  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 | 83 ++++++++++++++++++++++++++---------------------
 3 files changed, 52 insertions(+), 37 deletions(-)

Comments

Luiz Augusto von Dentz March 4, 2021, 6:59 p.m. UTC | #1
Hi Daniel,

On Wed, Mar 3, 2021 at 11:20 AM Daniel Winkler <danielwinkler@google.com> wrote:
>
> 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.
>
> 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: Alain Michaud <alainm@chromium.org>
> Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
>
> ---
>
>  lib/mgmt.h        | 1 +
>  src/advertising.c | 4 ++++
>  2 files changed, 5 insertions(+)
>
> 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 f3dc357a1..38cef565f 100644
> --- a/src/advertising.c
> +++ b/src/advertising.c
> @@ -945,6 +945,10 @@ static int refresh_extended_adv(struct btd_adv_client *client,
>                 return -EINVAL;
>         }
>
> +       /* Indicate that this instance will be configured as scannable */
> +       if (client->scan_rsp_len)
> +               flags |= MGMT_ADV_PARAM_SCAN_RSP;
> +

Don't we need to check if the flag is actually supported by the kernel?

>         cp.flags = htobl(flags);

For new code it is prefered to use the function from src/shared/util.h
(cpu_to_*).

>         mgmt_ret = mgmt_send(client->manager->mgmt, MGMT_OP_ADD_EXT_ADV_PARAMS,
> --
> 2.30.1.766.gb4fecdf3b7-goog
>
Daniel Winkler March 4, 2021, 8:27 p.m. UTC | #2
Hello Luiz,

Thank you for the catch and suggestion. I have just sent out a v2 to
address your recommendations.

Thanks!
Daniel


On Thu, Mar 4, 2021 at 10:59 AM Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>

> Hi Daniel,

>

> On Wed, Mar 3, 2021 at 11:20 AM Daniel Winkler <danielwinkler@google.com> wrote:

> >

> > 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.

> >

> > 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: Alain Michaud <alainm@chromium.org>

> > Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>

> >

> > ---

> >

> >  lib/mgmt.h        | 1 +

> >  src/advertising.c | 4 ++++

> >  2 files changed, 5 insertions(+)

> >

> > 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 f3dc357a1..38cef565f 100644

> > --- a/src/advertising.c

> > +++ b/src/advertising.c

> > @@ -945,6 +945,10 @@ static int refresh_extended_adv(struct btd_adv_client *client,

> >                 return -EINVAL;

> >         }

> >

> > +       /* Indicate that this instance will be configured as scannable */

> > +       if (client->scan_rsp_len)

> > +               flags |= MGMT_ADV_PARAM_SCAN_RSP;

> > +

>

> Don't we need to check if the flag is actually supported by the kernel?

>

> >         cp.flags = htobl(flags);

>

> For new code it is prefered to use the function from src/shared/util.h

> (cpu_to_*).

>

> >         mgmt_ret = mgmt_send(client->manager->mgmt, MGMT_OP_ADD_EXT_ADV_PARAMS,

> > --

> > 2.30.1.766.gb4fecdf3b7-goog

> >

>

>

> --

> Luiz Augusto von Dentz