linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: Manish Mandlik <mmandlik@google.com>
Cc: Marcel Holtmann <marcel@holtmann.org>,
	linux-bluetooth <linux-bluetooth@vger.kernel.org>,
	ChromeOS Bluetooth Upstreaming 
	<chromeos-bluetooth-upstreaming@chromium.org>
Subject: Re: [BlueZ PATCH v4 1/3] doc: Introduce the Adv Monitor Device Found/Lost events
Date: Mon, 8 Nov 2021 14:57:17 -0800	[thread overview]
Message-ID: <CABBYNZLnjgizrau7qYWsHfhW+6eg_goSCLubXe13t+zng+GUsw@mail.gmail.com> (raw)
In-Reply-To: <CAGPPCLD+pYQtK8G303gr_F7xqTvuSXA+4FTRiVf0OzAEUrDgjw@mail.gmail.com>

Hi Manish,

On Sun, Oct 31, 2021 at 10:53 PM Manish Mandlik <mmandlik@google.com> wrote:
>
> Hi Marcel,
>
>
> On Tue, Oct 26, 2021 at 4:33 AM Marcel Holtmann <marcel@holtmann.org> wrote:
>>
>> Hi Manish,
>>
>> > >
>> > > Example
>> > > @@ -4910,3 +4911,50 @@ Controller Resume Event
>> > >       Address_Type. Otherwise, Address and Address_Type will both be zero.
>> > >
>> > >       This event will be sent to all management sockets.
>> > > +
>> > > +
>> > > +Advertisement Monitor Device Found Event
>> > > +========================================
>> > > +
>> > > +     Event code:             0x002f
>> > > +     Controller Index:       <controller_id>
>> > > +     Event Parameters:       Monitor_Handle (2 Octets)
>> > > +                             Address (6 Octets)
>> > > +                             Address_Type (1 Octet)
>> > > +
>> > > +     This event indicates that the controller has started tracking a device
>> > > +     matching an Advertisement Monitor with handle Monitor_Handle.
>> > > +
>> > > +     The address of the device being tracked will be shared in Address and
>> > > +     Address_Type.
>> > > +
>> > > +     Possible values for the Address_Type parameter:
>> > > +             0       Reserved (not in use)
>> > > +             1       LE Public
>> > > +             2       LE Random
>> > > +
>> > > +     This event will be sent to all management sockets.
>> >
>> > My initial thought was actually to include all the fields from Device Found Event here as well. So that in case we are using advertising monitor, we just need to worry about this event only. Thoughts?
>> > The controller sends advertising reports in addition to the MSFT_Monitor_Device event. This event is reported only twice per bt-device (at start and at end of the monitoring); and it includes only the device addr and addr type [1]. To include other fields from the Device Found event, we need to buffer MSFT_Monitor_Device in the kernel and wait for the subsequent advertising report before we can send it to the bluetoothd. I feel this will unnecessarily complicate the logic in the kernel.
>> >
>> > This event will be used to invoke DeviceFound/Lost on the interface only when we are completely offloading monitoring to the controller (i.e. when the Sampling_Period is set to 0xFF). When the Sampling_Period is set to 0xFF, the controller sends only one advertisement report per monitoring period [2]. So, we need to rely on the MSFT_Monitor_Device controller event for RSSI and timeouts tracking. In other cases, as the bluetoothd receives more than one advertisement report, it can perform RSSI and timeouts tracking.
>> >
>> > So, I think it is better to pass on this event as it is to the bluetoothd and let the advertisement monitoring in the bluetoothd handle it. Let me know what you think about this?
>>
>> the kernel has to buffer events related to advertising reports and inquiry results already anyway. That is just the cost of business and it is the job of the kernel to do exactly that.
>>
>> I do not want to dumb down the kernel into a vendor extension passthrough since that is always going to come back and bite you. My current thinking is actually that unless Start Discovery triggers a discovery procedure, device that are monitored, should get its own report out path via mgmt.
>>
>> So the kernel would send Advertising Monitor Device Found Event (most likely with a flag for tracking started) and subsequence events of the same type whenever it gets updated. I mean, the kernel should track the state when a device is tracked anyway. It has to keep track of these things. In case of power down or reset or anything, the kernel needs to generate the Device Lost event to keeps this all in sync. Otherwise userspace is left to figure out what happens. We can not have that. This is similar to when a process dies, the kernel cleans up all open file descriptors. That is the basic paradigm that we have enforced with mgmt. If bluetoothd dies or restarts, we can get back to a state where we now all the details without having to hard reset hardware.
>>
>> One way to lock at this is always from the point of something that is not bluetoothd. Any other user of mgmt API needs to be sound and have a good API contract as well. Kernel APIs that are only designed with one daemon in mind are awful and cause major problems along the road.
>>
>> That all said, we can do this as above, but I would explore the option of doing it with my proposal and really focus on completely offload of the monitoring the controller.
>
>
> Thanks for the explanation. I see your point. Based on that I’d like to propose the following changes to the bluetooth kernel and user space to take all the advantages of the controller offloading whenever available. Let me know if it sounds good?
>
> Existing controller behavior (based on the MSFT extension specification):
> - Whenever the controller starts monitoring a device, it first sends the MSFT_Monitor_Device event with Monitor_State as 1 and provides the matched Monitor_Id and device address.
> - Based on the Sampling_Period configured, it then sends one or more LE Advertisement Reports for that device during the monitoring period.
> - Whenever the controller stops monitoring a device, it again sends the MSFT_Monitor_Device event but with Monitor_State as 0 and provides the Monitor_Id and device address of the device that was being tracked.
>
> Proposed kernel behavior:
> - Upon receipt of the MSFT_Monitor_Device event with Monitor_State 1, the kernel will buffer this event until it receives the subsequent LE Advertisement Report(s).
> - After receiving the first advertisement report for the monitored device, kernel will generate the “Adv Monitor Device Found” MGMT event which is identical to the “Device Found” MGMT event, but will have additional Monitor_Handle information for the matched monitor.
> - A separate Device_Tracked flag is not required since this event itself indicates that the device is being tracked.
> - If the active scanning is in progress, the existing “Device Found” event will also be generated before generating the “Adv Monitor Device Found” event.
> - For the subsequent advertisement reports (if any) for the monitored device, if the active scanning is in progress, only the existing "Device Found" event will be generated; else, only the "Adv Monitor Device Found" event will be generated.
> - Upon receipt of the MSFT_Monitor_Device event with Monitor_State 0, the kernel will generate the “Adv Monitor Device Lost” MGMT event with the Monitor_Handle and device address of the device that was being tracked.
> - Also, in case of power down or reset, the kernel will generate the "Adv Monitor Device Lost" event for the monitored devices.
>
> Proposed user space behavior:
> - Whenever the controller offloading is available, bluetoothd will only use the “Adv Monitor Device Found” and “Adv Monitor Device Lost” event for performing monitoring related functions and SW based filtering will be completely disabled as Monitor_Handle will be available from the kernel/controller and can be used to notify respective applications on DeviceFound/DeviceLost.
> - Whenever the controller offloading is NOT available, bluetoothd will use the existing “Device Found” event and perform SW based filtering as it is doing right now.
> - “Adv Monitor Device Found” event will also be used to create/update the found device when active scanning is NOT in progress.

Are you still working on this or are you waiting for some feedback on
the above, at first glance it looks proper. Btw, it would be great if
these changes are accompanied with mgmt-tester tests since vhci has
support for MSFT commands and we can emulate such code paths.


-- 
Luiz Augusto von Dentz

  parent reply	other threads:[~2021-11-08 22:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-25 19:18 [BlueZ PATCH v4 0/3] Add Advertisement Monitor Device Found/Lost events Manish Mandlik
2021-10-25 19:18 ` [BlueZ PATCH v4 1/3] doc: Introduce the Adv " Manish Mandlik
2021-10-25 19:56   ` Add Advertisement " bluez.test.bot
2021-10-25 20:03   ` [BlueZ PATCH v4 1/3] doc: Introduce the Adv " Marcel Holtmann
     [not found]     ` <CAGPPCLBNN+Eg92=GnmbMBfngLEb=BL6sSkx7O19rYOydAkO8HA@mail.gmail.com>
2021-10-26  8:33       ` Marcel Holtmann
     [not found]         ` <CAGPPCLD+pYQtK8G303gr_F7xqTvuSXA+4FTRiVf0OzAEUrDgjw@mail.gmail.com>
2021-11-08 22:57           ` Luiz Augusto von Dentz [this message]
     [not found]             ` <CAGPPCLBAwp=64hysCeagLQDrwK5b7_nUGS73XB0eDgsGL7yAsQ@mail.gmail.com>
2021-11-09  6:31               ` Luiz Augusto von Dentz
2021-10-25 19:18 ` [BlueZ PATCH v4 2/3] lib: Add definitions of " Manish Mandlik
2021-10-25 19:18 ` [BlueZ PATCH v4 3/3] adv_monitor: Receive the " Manish Mandlik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABBYNZLnjgizrau7qYWsHfhW+6eg_goSCLubXe13t+zng+GUsw@mail.gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=chromeos-bluetooth-upstreaming@chromium.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=mmandlik@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).