All of lore.kernel.org
 help / color / mirror / Atom feed
* [BlueZ PATCH v2 0/3] Update Device Found event and add Adv Monitor Device Lost event
@ 2021-10-13 12:42 Manish Mandlik
  2021-10-13 12:42 ` [BlueZ PATCH v2 1/3] doc: Introduce the " Manish Mandlik
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Manish Mandlik @ 2021-10-13 12:42 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: chromeos-bluetooth-upstreaming, linux-bluetooth, Manish Mandlik


Hello Bt-Maintainers,

Bluetooth Advertisement Monitor API was introduced to support background
scanning and proximity detection based on the application specified RSSI
thresholds and content filters on LE advertisement packets.

To optimize the power consumption, the API offloads the content
filtering and RSSI tracking to the controller if the controller
offloading support is available. However, this monitoring is not
completely offloaded as the bluetoothd also handles RSSI thresholds and
timeouts in order to fulfill high/low thresholds/timeouts filtering with
D-bus clients.

There is further room to achieve better power optimization by supporting
the controller event HCI_VS_MSFT_LE_Monitor_Device_Event to fulfill true
monitor offloading. This is currently not supported as it was originally
desired to minimize the changes to the MGMT interface and reuse the
existing MGMT event - MGMT_EV_DEVICE_FOUND to pass advertisements to
bluetoothd and let bluetoothd handle the RSSI thresholds and timeouts in
order to fulfill the D-bus API requirements for the client.

This patch series adds a flag in the exiting 'Device Found' event to
indicate that the device is being tracked by an Advertisement Monitor.
Kernel updates this flag based on the receipt of the controller event
HCI_VS_MSFT_LE_Monitor_Device_Event. A new MGMT event - 'Device Lost'
has been added to indicate that the controller has stopped tracking a
device already being tracked.

Please let me know what you think about this or if you have any further
questions.

Thanks,
Manish.

Changes in v2:
- Instead of creating a new 'Device Tracking' event, add a flag 'Device
  Tracked' in the existing 'Device Found' event and add a new 'Device
  Lost' event to indicate that the controller has stopped tracking that
  device.
- Instead of creating a new 'Device Tracking' event, add a flag 'Device
  Tracked' in the existing 'Device Found' event and add a new 'Device
  Lost' event to indicate that the controller has stopped tracking that
  device.
- Update function name adv_monitor_tracking_callback() to
  adv_monitor_device_lost_callback() as it will receive only Device Lost
  event.

Manish Mandlik (3):
  doc: Introduce the Adv Monitor Device Lost event
  lib: Add definition of the Adv Monitor Device Lost event
  adv_monitor: Receive the Device Lost event

 doc/mgmt-api.txt  | 32 +++++++++++++++++++++++++++++++-
 lib/mgmt.h        |  9 +++++++++
 src/adv_monitor.c | 25 +++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 1 deletion(-)

-- 
2.33.0.882.g93a45727a2-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [BlueZ PATCH v2 1/3] doc: Introduce the Adv Monitor Device Lost event
  2021-10-13 12:42 [BlueZ PATCH v2 0/3] Update Device Found event and add Adv Monitor Device Lost event Manish Mandlik
@ 2021-10-13 12:42 ` Manish Mandlik
  2021-10-13 13:15   ` Marcel Holtmann
  2021-10-13 13:40   ` Update Device Found event and add " bluez.test.bot
  2021-10-13 12:42 ` [BlueZ PATCH v2 2/3] lib: Add definition of the " Manish Mandlik
  2021-10-13 12:42 ` [BlueZ PATCH v2 3/3] adv_monitor: Receive the " Manish Mandlik
  2 siblings, 2 replies; 7+ messages in thread
From: Manish Mandlik @ 2021-10-13 12:42 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: chromeos-bluetooth-upstreaming, linux-bluetooth, Manish Mandlik

Add a flag 'Device Tracked' to the existing 'Device Found' event to
indicate that the controller has started tracking the device matching
an Advertisement Monitor with handle 'Monitor_Handle'.

Add a new event 'Adv Monitor Device Lost' to indicate that the
controller has stopped tracking that particular device.

---

Changes in v2:
- Instead of creating a new 'Device Tracking' event, add a flag 'Device
  Tracked' in the existing 'Device Found' event and add a new 'Device
  Lost' event to indicate that the controller has stopped tracking that
  device.

 doc/mgmt-api.txt | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
index 5355fedb0..0fd884ed0 100644
--- a/doc/mgmt-api.txt
+++ b/doc/mgmt-api.txt
@@ -107,7 +107,8 @@ Configuration command, Default Runtime Configuration Changed event, Get
 Device Flags command, Set Device Flags command, Device Flags Changed event,
 Read Advertisement Monitor Features command, Add Advertisement Patterns
 Monitor command, Remove Advertisement Monitor command, Advertisement Monitor
-Added event and Advertisement Monitor Removed event.
+Added event, Advertisement Monitor Removed event, Updated Device Found event
+and Added Advertisement Monitor Device Lost event.
 
 
 Example
@@ -4247,6 +4248,7 @@ Device Found Event
 				Address_Type (1 Octet)
 				RSSI (1 Octet)
 				Flags (4 Octets)
+				Monitor_Handle (2 Octets)
 				EIR_Data_Length (2 Octets)
 				EIR_Data (0-65535 Octets)
 
@@ -4263,6 +4265,7 @@ Device Found Event
 		1	Legacy Pairing
 		2	Not Connectable
 		3	Reserved (not in use)
+		4	Device Tracked
 
 	For the RSSI field a value of 127 indicates that the RSSI is
 	not available. That can happen with Bluetooth 1.1 and earlier
@@ -4285,6 +4288,10 @@ Device Found Event
 	accept any connections. This can be indicated by Low Energy
 	devices that are in broadcaster role.
 
+	The Device Tracked flag indicates that the controller has started
+	monitoring a particular device matching the Advertisement Monitor
+	with handle Monitor_Handle.
+
 
 Discovering Event
 =================
@@ -4910,3 +4917,26 @@ 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 Lost 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 stopped tracking the
+	device that was being tracked by 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	BR/EDR
+		1	LE Public
+		2	LE Random
+
+	This event will be sent to all management sockets.
-- 
2.33.0.882.g93a45727a2-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [BlueZ PATCH v2 2/3] lib: Add definition of the Adv Monitor Device Lost event
  2021-10-13 12:42 [BlueZ PATCH v2 0/3] Update Device Found event and add Adv Monitor Device Lost event Manish Mandlik
  2021-10-13 12:42 ` [BlueZ PATCH v2 1/3] doc: Introduce the " Manish Mandlik
@ 2021-10-13 12:42 ` Manish Mandlik
  2021-10-13 12:42 ` [BlueZ PATCH v2 3/3] adv_monitor: Receive the " Manish Mandlik
  2 siblings, 0 replies; 7+ messages in thread
From: Manish Mandlik @ 2021-10-13 12:42 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: chromeos-bluetooth-upstreaming, linux-bluetooth, Manish Mandlik

This patch adds a flag to the Device Found event to indicate that the
controller is tracking a device and adds definition of the new Device
Lost event to indicate that the controller has stopped tracking that
device.

---

Changes in v2:
- Instead of creating a new 'Device Tracking' event, add a flag 'Device
  Tracked' in the existing 'Device Found' event and add a new 'Device
  Lost' event to indicate that the controller has stopped tracking that
  device.

 lib/mgmt.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/mgmt.h b/lib/mgmt.h
index 0a6349321..70e3d31f9 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -856,12 +856,14 @@ struct mgmt_ev_auth_failed {
 #define MGMT_DEV_FOUND_CONFIRM_NAME	0x01
 #define MGMT_DEV_FOUND_LEGACY_PAIRING	0x02
 #define MGMT_DEV_FOUND_NOT_CONNECTABLE	0x04
+#define MGMT_DEV_FOUND_MONITORING	0x10
 
 #define MGMT_EV_DEVICE_FOUND		0x0012
 struct mgmt_ev_device_found {
 	struct mgmt_addr_info addr;
 	int8_t rssi;
 	uint32_t flags;
+	uint16_t monitor_handle;
 	uint16_t eir_len;
 	uint8_t eir[0];
 } __packed;
@@ -1014,6 +1016,12 @@ struct mgmt_ev_controller_resume {
 	uint8_t wake_reason;
 } __packed;
 
+#define MGMT_EV_ADV_MONITOR_DEVICE_LOST		0x002f
+struct mgmt_ev_adv_monitor_device_lost {
+	uint16_t monitor_handle;
+	struct mgmt_addr_info addr;
+} __packed;
+
 static const char *mgmt_op[] = {
 	"<0x0000>",
 	"Read Version",
@@ -1152,6 +1160,7 @@ static const char *mgmt_ev[] = {
 	"Advertisement Monitor Removed",
 	"Controller Suspend",
 	"Controller Resume",
+	"Advertisement Monitor Device Lost",		/* 0x002f */
 };
 
 static const char *mgmt_status[] = {
-- 
2.33.0.882.g93a45727a2-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [BlueZ PATCH v2 3/3] adv_monitor: Receive the Device Lost event
  2021-10-13 12:42 [BlueZ PATCH v2 0/3] Update Device Found event and add Adv Monitor Device Lost event Manish Mandlik
  2021-10-13 12:42 ` [BlueZ PATCH v2 1/3] doc: Introduce the " Manish Mandlik
  2021-10-13 12:42 ` [BlueZ PATCH v2 2/3] lib: Add definition of the " Manish Mandlik
@ 2021-10-13 12:42 ` Manish Mandlik
  2 siblings, 0 replies; 7+ messages in thread
From: Manish Mandlik @ 2021-10-13 12:42 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: chromeos-bluetooth-upstreaming, linux-bluetooth, Manish Mandlik

This patch registers a callback function to receive Advertisement
Monitor Device Lost event.

Test performed:
- verified by logs that Monitor Device is received from the controller
  and sent to the bluetoothd when the controller starts/stops monitoring
  a bluetooth device.

---

Changes in v2:
- Update function name adv_monitor_tracking_callback() to
  adv_monitor_device_lost_callback() as it will receive only Device Lost
  event.

 src/adv_monitor.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/adv_monitor.c b/src/adv_monitor.c
index 715ac5904..13042786c 100644
--- a/src/adv_monitor.c
+++ b/src/adv_monitor.c
@@ -1531,6 +1531,27 @@ static void adv_monitor_removed_callback(uint16_t index, uint16_t length,
 		ev->monitor_handle);
 }
 
+/* Processes Adv Monitor tracking event from kernel */
+static void adv_monitor_device_lost_callback(uint16_t index, uint16_t length,
+					  const void *param, void *user_data)
+{
+	struct btd_adv_monitor_manager *manager = user_data;
+	const struct mgmt_ev_adv_monitor_device_lost *ev = param;
+	uint16_t handle = le16_to_cpu(ev->monitor_handle);
+	const uint16_t adapter_id = manager->adapter_id;
+	char addr[18];
+
+	if (length < sizeof(*ev)) {
+		btd_error(adapter_id,
+				"Wrong size of Adv Monitor Device Lost event");
+		return;
+	}
+
+	ba2str(&ev->addr.bdaddr, addr);
+	DBG("Adv monitor with handle 0x%04x stopped tracking the device %s",
+			handle, addr);
+}
+
 /* Allocates a manager object */
 static struct btd_adv_monitor_manager *manager_new(
 						struct btd_adapter *adapter,
@@ -1555,6 +1576,10 @@ static struct btd_adv_monitor_manager *manager_new(
 			manager->adapter_id, adv_monitor_removed_callback,
 			manager, NULL);
 
+	mgmt_register(manager->mgmt, MGMT_EV_ADV_MONITOR_DEVICE_LOST,
+			manager->adapter_id, adv_monitor_device_lost_callback,
+			manager, NULL);
+
 	return manager;
 }
 
-- 
2.33.0.882.g93a45727a2-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [BlueZ PATCH v2 1/3] doc: Introduce the Adv Monitor Device Lost event
  2021-10-13 12:42 ` [BlueZ PATCH v2 1/3] doc: Introduce the " Manish Mandlik
@ 2021-10-13 13:15   ` Marcel Holtmann
  2021-10-14 18:06     ` Luiz Augusto von Dentz
  2021-10-13 13:40   ` Update Device Found event and add " bluez.test.bot
  1 sibling, 1 reply; 7+ messages in thread
From: Marcel Holtmann @ 2021-10-13 13:15 UTC (permalink / raw)
  To: Manish Mandlik
  Cc: Luiz Augusto von Dentz, CrosBT Upstreaming, linux-bluetooth

Hi Manish,

> Add a flag 'Device Tracked' to the existing 'Device Found' event to
> indicate that the controller has started tracking the device matching
> an Advertisement Monitor with handle 'Monitor_Handle'.
> 
> Add a new event 'Adv Monitor Device Lost' to indicate that the
> controller has stopped tracking that particular device.
> 
> ---
> 
> Changes in v2:
> - Instead of creating a new 'Device Tracking' event, add a flag 'Device
>  Tracked' in the existing 'Device Found' event and add a new 'Device
>  Lost' event to indicate that the controller has stopped tracking that
>  device.
> 
> doc/mgmt-api.txt | 32 +++++++++++++++++++++++++++++++-
> 1 file changed, 31 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
> index 5355fedb0..0fd884ed0 100644
> --- a/doc/mgmt-api.txt
> +++ b/doc/mgmt-api.txt
> @@ -107,7 +107,8 @@ Configuration command, Default Runtime Configuration Changed event, Get
> Device Flags command, Set Device Flags command, Device Flags Changed event,
> Read Advertisement Monitor Features command, Add Advertisement Patterns
> Monitor command, Remove Advertisement Monitor command, Advertisement Monitor
> -Added event and Advertisement Monitor Removed event.
> +Added event, Advertisement Monitor Removed event, Updated Device Found event
> +and Added Advertisement Monitor Device Lost event.
> 
> 
> Example
> @@ -4247,6 +4248,7 @@ Device Found Event
> 				Address_Type (1 Octet)
> 				RSSI (1 Octet)
> 				Flags (4 Octets)
> +				Monitor_Handle (2 Octets)
> 				EIR_Data_Length (2 Octets)
> 				EIR_Data (0-65535 Octets)

you can not do this. This breaks ABI.

Regards

Marcel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Update Device Found event and add Adv Monitor Device Lost event
  2021-10-13 12:42 ` [BlueZ PATCH v2 1/3] doc: Introduce the " Manish Mandlik
  2021-10-13 13:15   ` Marcel Holtmann
@ 2021-10-13 13:40   ` bluez.test.bot
  1 sibling, 0 replies; 7+ messages in thread
From: bluez.test.bot @ 2021-10-13 13:40 UTC (permalink / raw)
  To: linux-bluetooth, mmandlik

[-- Attachment #1: Type: text/plain, Size: 885 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=562679

---Test result---

Test Summary:
CheckPatch                    PASS      4.43 seconds
GitLint                       PASS      2.88 seconds
Prep - Setup ELL              PASS      46.60 seconds
Build - Prep                  PASS      0.52 seconds
Build - Configure             PASS      8.49 seconds
Build - Make                  PASS      200.15 seconds
Make Check                    PASS      10.19 seconds
Make Distcheck                PASS      239.36 seconds
Build w/ext ELL - Configure   PASS      8.59 seconds
Build w/ext ELL - Make        PASS      188.50 seconds



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [BlueZ PATCH v2 1/3] doc: Introduce the Adv Monitor Device Lost event
  2021-10-13 13:15   ` Marcel Holtmann
@ 2021-10-14 18:06     ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2021-10-14 18:06 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: Manish Mandlik, CrosBT Upstreaming, linux-bluetooth

Hi Marcel, Manish,

On Wed, Oct 13, 2021 at 6:15 AM Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Manish,
>
> > Add a flag 'Device Tracked' to the existing 'Device Found' event to
> > indicate that the controller has started tracking the device matching
> > an Advertisement Monitor with handle 'Monitor_Handle'.
> >
> > Add a new event 'Adv Monitor Device Lost' to indicate that the
> > controller has stopped tracking that particular device.
> >
> > ---
> >
> > Changes in v2:
> > - Instead of creating a new 'Device Tracking' event, add a flag 'Device
> >  Tracked' in the existing 'Device Found' event and add a new 'Device
> >  Lost' event to indicate that the controller has stopped tracking that
> >  device.
> >
> > doc/mgmt-api.txt | 32 +++++++++++++++++++++++++++++++-
> > 1 file changed, 31 insertions(+), 1 deletion(-)
> >
> > diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
> > index 5355fedb0..0fd884ed0 100644
> > --- a/doc/mgmt-api.txt
> > +++ b/doc/mgmt-api.txt
> > @@ -107,7 +107,8 @@ Configuration command, Default Runtime Configuration Changed event, Get
> > Device Flags command, Set Device Flags command, Device Flags Changed event,
> > Read Advertisement Monitor Features command, Add Advertisement Patterns
> > Monitor command, Remove Advertisement Monitor command, Advertisement Monitor
> > -Added event and Advertisement Monitor Removed event.
> > +Added event, Advertisement Monitor Removed event, Updated Device Found event
> > +and Added Advertisement Monitor Device Lost event.
> >
> >
> > Example
> > @@ -4247,6 +4248,7 @@ Device Found Event
> >                               Address_Type (1 Octet)
> >                               RSSI (1 Octet)
> >                               Flags (4 Octets)
> > +                             Monitor_Handle (2 Octets)
> >                               EIR_Data_Length (2 Octets)
> >                               EIR_Data (0-65535 Octets)
>
> you can not do this. This breaks ABI.

I was going to say that, we can't be adding parameters to existing
commands/events as that is not backward compatible (old bluetoothd
won't be able to parse them properly). That said, I wonder why it
needs the handle though? Wouldn't a flag be enough to indicate that
has been found via monitor filtering or do we need to know the exact
monitor rule that has triggered it?

Btw, afaik monitor handles as 1 octet not 2.

-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-10-14 18:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13 12:42 [BlueZ PATCH v2 0/3] Update Device Found event and add Adv Monitor Device Lost event Manish Mandlik
2021-10-13 12:42 ` [BlueZ PATCH v2 1/3] doc: Introduce the " Manish Mandlik
2021-10-13 13:15   ` Marcel Holtmann
2021-10-14 18:06     ` Luiz Augusto von Dentz
2021-10-13 13:40   ` Update Device Found event and add " bluez.test.bot
2021-10-13 12:42 ` [BlueZ PATCH v2 2/3] lib: Add definition of the " Manish Mandlik
2021-10-13 12:42 ` [BlueZ PATCH v2 3/3] adv_monitor: Receive the " Manish Mandlik

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.