All of lore.kernel.org
 help / color / mirror / Atom feed
* [BlueZ PATCH v2 1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering
@ 2022-04-13 20:54 Manish Mandlik
  2022-04-13 20:54 ` [BlueZ PATCH v2 2/9] adv_monitor: Don't send DeviceFound for already found devices Manish Mandlik
                   ` (8 more replies)
  0 siblings, 9 replies; 13+ messages in thread
From: Manish Mandlik @ 2022-04-13 20:54 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: chromeos-bluetooth-upstreaming, linux-bluetooth, Manish Mandlik,
	Miao-chen Chou

Controller offloading does not support High RSSI Timeout. Disable High
RSSI Timeout for SW based filtering as well to provide a consistent
behavior between SW based and controller based monitoring.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
---

(no changes since v1)

 doc/advertisement-monitor-api.txt | 5 +++++
 src/adv_monitor.c                 | 6 ++++++
 2 files changed, 11 insertions(+)

diff --git a/doc/advertisement-monitor-api.txt b/doc/advertisement-monitor-api.txt
index 9189f2cce..942d44b2f 100644
--- a/doc/advertisement-monitor-api.txt
+++ b/doc/advertisement-monitor-api.txt
@@ -79,6 +79,11 @@ Properties	string Type [read-only]
 			in-range (found). Valid range is 1 to 300 (seconds),
 			while 0 indicates unset.
 
+			NOTE: Controller offloading does not support High RSSI
+			Timeout. So, to provide a consistent behavior between
+			SW based and controller based monitoring, this property
+			has been disabled and deprecated.
+
 		Uint16 RSSISamplingPeriod [read-only, optional]
 
 			Grouping rules on how to propagate the received
diff --git a/src/adv_monitor.c b/src/adv_monitor.c
index 33f4d9619..a1778248f 100644
--- a/src/adv_monitor.c
+++ b/src/adv_monitor.c
@@ -860,6 +860,12 @@ static bool parse_rssi_and_timeout(struct adv_monitor *monitor,
 	monitor->rssi.low_rssi_timeout = l_rssi_timeout;
 	monitor->rssi.sampling_period = sampling_period;
 
+	/* Controller offloading does not support High RSSI Timeout. Disable
+	 * High RSSI Timeout for SW based filtering to provide a consistent
+	 * behavior between SW based and controller based monitoring.
+	 */
+	monitor->rssi.high_rssi_timeout = ADV_MONITOR_UNSET_TIMEOUT;
+
 done:
 	DBG("Adv Monitor at %s initiated with high RSSI threshold %d, high "
 		"RSSI threshold timeout %d, low RSSI threshold %d, low RSSI "
-- 
2.36.0.rc0.470.gd361397f0d-goog


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

* [BlueZ PATCH v2 2/9] adv_monitor: Don't send DeviceFound for already found devices
  2022-04-13 20:54 [BlueZ PATCH v2 1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering Manish Mandlik
@ 2022-04-13 20:54 ` Manish Mandlik
  2022-04-13 20:54 ` [BlueZ PATCH v2 3/9] adv_monitor: Clear tracked devices on resume Manish Mandlik
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Manish Mandlik @ 2022-04-13 20:54 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: chromeos-bluetooth-upstreaming, linux-bluetooth, Manish Mandlik,
	Miao-chen Chou

When monitors with same patterns are merged, BlueZ removes the existing
monitor from the kernel and re-registers it with updated/merged RSSI
parameters. The controller then triggers a new Device Found event for
the device that matches the updated monitor. Don't notify the D-Bus
client again with another DeviceFound for that device.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
---

(no changes since v1)

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

diff --git a/src/adv_monitor.c b/src/adv_monitor.c
index a1778248f..a7763df10 100644
--- a/src/adv_monitor.c
+++ b/src/adv_monitor.c
@@ -188,6 +188,11 @@ static void merged_pattern_send_add(
 static void merged_pattern_send_remove(
 			struct adv_monitor_merged_pattern *merged_pattern);
 
+static bool monitor_device_match(const void *a, const void *b);
+static struct adv_monitor_device *monitor_device_create(
+			struct adv_monitor *monitor,
+			struct btd_device *device);
+
 const struct adv_monitor_type {
 	enum monitor_type type;
 	const char *name;
@@ -1555,8 +1560,26 @@ static void notify_device_found_per_monitor(void *data, void *user_data)
 {
 	struct adv_monitor *monitor = data;
 	struct monitored_device_info *info = user_data;
+	struct adv_monitor_device *dev = NULL;
+	uint16_t adapter_id = monitor->app->manager->adapter_id;
 
 	if (monitor->merged_pattern->monitor_handle == info->monitor_handle) {
+		dev = queue_find(monitor->devices, monitor_device_match,
+				 info->device);
+		if (!dev) {
+			dev = monitor_device_create(monitor, info->device);
+			if (!dev) {
+				btd_error(adapter_id, "Failed to create "
+					  "Adv Monitor device object.");
+				return;
+			}
+		}
+
+		if (dev->found)
+			return;
+
+		dev->found = true;
+
 		DBG("Calling DeviceFound() on Adv Monitor of owner %s "
 		    "at path %s", monitor->app->owner, monitor->path);
 
@@ -1652,8 +1675,25 @@ static void notify_device_lost_per_monitor(void *data, void *user_data)
 {
 	struct adv_monitor *monitor = data;
 	struct monitored_device_info *info = user_data;
+	struct adv_monitor_device *dev = NULL;
+	uint16_t adapter_id = monitor->app->manager->adapter_id;
 
 	if (monitor->merged_pattern->monitor_handle == info->monitor_handle) {
+		dev = queue_find(monitor->devices, monitor_device_match,
+				 info->device);
+		if (!dev) {
+			btd_error(adapter_id, "Adv Monitor device object "
+				  "not found.");
+			return;
+		}
+
+		if (!dev->found) {
+			btd_error(adapter_id, "Device not tracked.");
+			return;
+		}
+
+		dev->found = false;
+
 		DBG("Calling DeviceLost() on Adv Monitor of owner %s "
 		    "at path %s", monitor->app->owner, monitor->path);
 
-- 
2.36.0.rc0.470.gd361397f0d-goog


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

* [BlueZ PATCH v2 3/9] adv_monitor: Clear tracked devices on resume
  2022-04-13 20:54 [BlueZ PATCH v2 1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering Manish Mandlik
  2022-04-13 20:54 ` [BlueZ PATCH v2 2/9] adv_monitor: Don't send DeviceFound for already found devices Manish Mandlik
@ 2022-04-13 20:54 ` Manish Mandlik
  2022-04-13 20:54 ` [BlueZ PATCH v2 4/9] adv_monitor: Do not remove the device while monitoring Manish Mandlik
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Manish Mandlik @ 2022-04-13 20:54 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: chromeos-bluetooth-upstreaming, linux-bluetooth, Manish Mandlik,
	Miao-chen Chou

Clear any tracked devices on system resume. Matched devices will be
found again if they are in range after resume.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
---

Changes in v2:
- Fix compiler error by replacing btd_adv_monitor_offload_supported()
  with btd_adv_monitor_offload_enabled().

 src/adapter.c     |  1 +
 src/adv_monitor.c | 19 +++++++++++++++++++
 src/adv_monitor.h |  2 ++
 3 files changed, 22 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index 97ce26f8e..2ae8a9ae9 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -9183,6 +9183,7 @@ static void controller_resume_callback(uint16_t index, uint16_t length,
 	info("Controller resume with wake event 0x%x", ev->wake_reason);
 
 	controller_resume_notify(adapter);
+	btd_adv_monitor_resume(adapter->adv_monitor_manager);
 }
 
 static void device_blocked_callback(uint16_t index, uint16_t length,
diff --git a/src/adv_monitor.c b/src/adv_monitor.c
index a7763df10..18ce839e9 100644
--- a/src/adv_monitor.c
+++ b/src/adv_monitor.c
@@ -2248,6 +2248,7 @@ static void clear_device_lost_timer(void *data, void *user_data)
 	if (dev->lost_timer) {
 		timeout_remove(dev->lost_timer);
 		dev->lost_timer = 0;
+		dev->found = false;
 
 		monitor = dev->monitor;
 
@@ -2289,3 +2290,21 @@ void btd_adv_monitor_power_down(struct btd_adv_monitor_manager *manager)
 	/* Clear any running DeviceLost timers in case of power down */
 	queue_foreach(manager->apps, clear_lost_timers_from_app, NULL);
 }
+
+/* Handles wake from system suspend scenario */
+void btd_adv_monitor_resume(struct btd_adv_monitor_manager *manager)
+{
+	if (!manager) {
+		error("Unexpected NULL btd_adv_monitor_manager object upon "
+				"system resume");
+		return;
+	}
+
+	/* Clear any tracked devices on system resume. Matched devices will be
+	 * found again if they are in range after resume. (No need to do this if
+	 * the controller based monitoring is supported as the kernel clears all
+	 * monitored devices on resume.
+	 */
+	if (!btd_adv_monitor_offload_enabled(manager))
+		queue_foreach(manager->apps, clear_lost_timers_from_app, NULL);
+}
diff --git a/src/adv_monitor.h b/src/adv_monitor.h
index c6bb8a68a..3b5b1200a 100644
--- a/src/adv_monitor.h
+++ b/src/adv_monitor.h
@@ -42,4 +42,6 @@ void btd_adv_monitor_device_remove(struct btd_adv_monitor_manager *manager,
 
 void btd_adv_monitor_power_down(struct btd_adv_monitor_manager *manager);
 
+void btd_adv_monitor_resume(struct btd_adv_monitor_manager *manager);
+
 #endif /* __ADV_MONITOR_H */
-- 
2.36.0.rc0.470.gd361397f0d-goog


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

* [BlueZ PATCH v2 4/9] adv_monitor: Do not remove the device while monitoring
  2022-04-13 20:54 [BlueZ PATCH v2 1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering Manish Mandlik
  2022-04-13 20:54 ` [BlueZ PATCH v2 2/9] adv_monitor: Don't send DeviceFound for already found devices Manish Mandlik
  2022-04-13 20:54 ` [BlueZ PATCH v2 3/9] adv_monitor: Clear tracked devices on resume Manish Mandlik
@ 2022-04-13 20:54 ` Manish Mandlik
  2022-04-13 20:54 ` [BlueZ PATCH v2 5/9] monitor: Display AdvMonitor DeviceFound/Lost events Manish Mandlik
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Manish Mandlik @ 2022-04-13 20:54 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: chromeos-bluetooth-upstreaming, linux-bluetooth, Manish Mandlik,
	Miao-chen Chou

Bluetoothd clears temporary devices if they are not seen for 30 seconds.
When controller offloading is enabled and SamplingPeriod is set to 0xFF,
the controller sends only one advertisement report per device during the
monitoring period. In such a case, don't remove the temporary devices if
they are being monitored.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
---

(no changes since v1)

 src/adv_monitor.c |  4 ++++
 src/device.c      | 22 +++++++++++++++++++++-
 src/device.h      |  1 +
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/adv_monitor.c b/src/adv_monitor.c
index 18ce839e9..c01f8b154 100644
--- a/src/adv_monitor.c
+++ b/src/adv_monitor.c
@@ -1663,6 +1663,8 @@ static void adv_monitor_device_found_callback(uint16_t index, uint16_t length,
 			return;
 		}
 
+		btd_device_set_monitored(info.device, true);
+
 		/* Check for matched monitor in all apps */
 		info.monitor_handle = handle;
 		queue_foreach(manager->apps, notify_device_found_per_app,
@@ -1745,6 +1747,8 @@ static void adv_monitor_device_lost_callback(uint16_t index, uint16_t length,
 	/* Check for matched monitor in all apps */
 	info.monitor_handle = handle;
 	queue_foreach(manager->apps, notify_device_lost_per_app, &info);
+
+	btd_device_set_monitored(info.device, false);
 }
 
 /* Allocates a manager object */
diff --git a/src/device.c b/src/device.c
index 3992f9a0c..00d0cc2fb 100644
--- a/src/device.c
+++ b/src/device.c
@@ -218,6 +218,7 @@ struct btd_device {
 	GSList		*services;		/* List of btd_service */
 	GSList		*pending;		/* Pending services */
 	GSList		*watches;		/* List of disconnect_data */
+	bool		monitored;		/* Tracked by Adv Monitor */
 	bool		temporary;
 	bool		connectable;
 	unsigned int	disconn_timer;
@@ -3206,11 +3207,30 @@ static bool device_disappeared(gpointer user_data)
 
 	dev->temporary_timer = 0;
 
-	btd_adapter_remove_device(dev->adapter, dev);
+	/* Do not remove the device if it is being tracked by an Advertisement
+	 * Monitor. It will be removed when the Advertisement Monitor stops
+	 * tracking that device.
+	 */
+	if (!dev->monitored)
+		btd_adapter_remove_device(dev->adapter, dev);
 
 	return FALSE;
 }
 
+void btd_device_set_monitored(struct btd_device *device, bool monitored)
+{
+	if (!device)
+		return;
+
+	device->monitored = monitored;
+
+	/* If the device is not being monitored and the temporary_timer has
+	 * already expired, it indicates that the device can be removed.
+	 */
+	if (!monitored && device->temporary && !device->temporary_timer)
+		device_disappeared(device);
+}
+
 static void set_temporary_timer(struct btd_device *dev, unsigned int timeout)
 {
 	clear_temporary_timer(dev);
diff --git a/src/device.h b/src/device.h
index 071576d6b..0a4103747 100644
--- a/src/device.h
+++ b/src/device.h
@@ -87,6 +87,7 @@ bool device_is_connectable(struct btd_device *device);
 bool device_is_paired(struct btd_device *device, uint8_t bdaddr_type);
 bool device_is_bonded(struct btd_device *device, uint8_t bdaddr_type);
 gboolean device_is_trusted(struct btd_device *device);
+void btd_device_set_monitored(struct btd_device *device, bool monitored);
 void device_set_paired(struct btd_device *dev, uint8_t bdaddr_type);
 void device_set_unpaired(struct btd_device *dev, uint8_t bdaddr_type);
 void btd_device_set_temporary(struct btd_device *device, bool temporary);
-- 
2.36.0.rc0.470.gd361397f0d-goog


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

* [BlueZ PATCH v2 5/9] monitor: Display AdvMonitor DeviceFound/Lost events
  2022-04-13 20:54 [BlueZ PATCH v2 1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering Manish Mandlik
                   ` (2 preceding siblings ...)
  2022-04-13 20:54 ` [BlueZ PATCH v2 4/9] adv_monitor: Do not remove the device while monitoring Manish Mandlik
@ 2022-04-13 20:54 ` Manish Mandlik
  2022-04-13 20:54 ` [BlueZ PATCH v2 6/9] adv_monitor: Do not merge monitors with non-overlapping RSSI Manish Mandlik
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Manish Mandlik @ 2022-04-13 20:54 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: chromeos-bluetooth-upstreaming, linux-bluetooth, Manish Mandlik,
	Miao-chen Chou

Display information about MGMT_EV_ADV_MONITOR_DEVICE_FOUND and
MGMT_EV_ADV_MONITOR_DEVICE_LOST events in the btmon output.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
---

(no changes since v1)

 monitor/packet.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/monitor/packet.c b/monitor/packet.c
index b7431b57d..6f615f7ba 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -14103,6 +14103,31 @@ static void mgmt_device_found_evt(const void *data, uint16_t size)
 	print_eir(data + 14, size - 14, false);
 }
 
+static void mgmt_adv_monitor_device_found_evt(const void *data, uint16_t size)
+{
+	uint16_t handle = get_le16(data);
+	uint8_t address_type = get_u8(data + 8);
+	int8_t rssi = get_s8(data + 9);
+	uint32_t flags = get_le32(data + 10);
+	uint16_t data_len = get_le16(data + 14);
+
+	print_field("Handle: %u", handle);
+	mgmt_print_address(data + 2, address_type);
+	print_rssi(rssi);
+	mgmt_print_device_flags(flags);
+	print_field("Data length: %u", data_len);
+	print_eir(data + 16, size - 16, false);
+}
+
+static void mgmt_adv_monitor_device_lost_evt(const void *data, uint16_t size)
+{
+	uint16_t handle = get_le16(data);
+	uint8_t address_type = get_u8(data + 8);
+
+	print_field("Handle: %u", handle);
+	mgmt_print_address(data + 2, address_type);
+}
+
 static void mgmt_discovering_evt(const void *data, uint16_t size)
 {
 	uint8_t type = get_u8(data);
@@ -14414,6 +14439,10 @@ static const struct mgmt_data mgmt_event_table[] = {
 			mgmt_controller_suspend_evt, 1, true },
 	{ 0x002e, "Controller Resumed",
 			mgmt_controller_resume_evt, 8, true },
+	{ 0x002f, "Adv Monitor Device Found",
+			mgmt_adv_monitor_device_found_evt, 16, false },
+	{ 0x0030, "Adv Monitor Device Lost",
+			mgmt_adv_monitor_device_lost_evt, 9, true },
 	{ }
 };
 
-- 
2.36.0.rc0.470.gd361397f0d-goog


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

* [BlueZ PATCH v2 6/9] adv_monitor: Do not merge monitors with non-overlapping RSSI
  2022-04-13 20:54 [BlueZ PATCH v2 1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering Manish Mandlik
                   ` (3 preceding siblings ...)
  2022-04-13 20:54 ` [BlueZ PATCH v2 5/9] monitor: Display AdvMonitor DeviceFound/Lost events Manish Mandlik
@ 2022-04-13 20:54 ` Manish Mandlik
  2022-04-13 20:54 ` [BlueZ PATCH v2 7/9] adv_monitor: Add the monitor Release reason Manish Mandlik
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Manish Mandlik @ 2022-04-13 20:54 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: chromeos-bluetooth-upstreaming, linux-bluetooth, Manish Mandlik,
	Miao-chen Chou

Merging two monitors with different RSSI thresholds is not possible
if their RSSI ranges do not overlap.

Example:
         Monitor 1: -40 -80         Result: Merge with updated RSSI
         Monitor 2: -60 -100                thresholds -60 -100

         Monitor 1: -40 -100        Result: Merge with updated RSSI
         Monitor 2: -60 -80                 thresholds -60 -100

         Monitor 1: -40 -60         Result: Do not merge
         Monitor 2: -80 -100

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
---

(no changes since v1)

 src/adv_monitor.c | 58 ++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 50 insertions(+), 8 deletions(-)

diff --git a/src/adv_monitor.c b/src/adv_monitor.c
index c01f8b154..d88e1bbbb 100644
--- a/src/adv_monitor.c
+++ b/src/adv_monitor.c
@@ -251,6 +251,46 @@ static void merged_pattern_free(void *data)
 	free(merged_pattern);
 }
 
+/* Checks if merging monitors with different RSSI Thresh is possible or not */
+static bool merge_is_possible(
+			struct adv_monitor_merged_pattern *existing_pattern,
+			struct adv_monitor *monitor)
+{
+	const struct queue_entry *q_entry;
+	struct adv_monitor *q_data;
+
+	/* Merging two monitors with different RSSI thresholds is not possible
+	 * if their RSSI ranges do not overlap.
+	 */
+
+	q_entry = queue_get_entries(existing_pattern->monitors);
+
+	while (q_entry) {
+		q_data = q_entry->data;
+
+		if (q_data->rssi.low_rssi >= monitor->rssi.high_rssi ||
+		    monitor->rssi.low_rssi >= q_data->rssi.high_rssi)
+			goto fail;
+
+		q_entry = q_entry->next;
+	}
+
+	return true;
+
+fail:
+	monitor->state = MONITOR_STATE_FAILED;
+	merged_pattern_free(monitor->merged_pattern);
+	monitor->merged_pattern = NULL;
+
+	btd_error(monitor->app->manager->adapter_id,
+			"Adv Monitor at path %s is in conflict with "
+			"an existing Adv Monitor at path %s",
+			g_dbus_proxy_get_path(monitor->proxy),
+			g_dbus_proxy_get_path(q_data->proxy));
+
+	return false;
+}
+
 /* Returns the smaller of the two integers |a| and |b| which is not equal to the
  * |unset| value. If both are unset, return unset.
  */
@@ -291,14 +331,9 @@ static void merge_rssi(const struct rssi_parameters *a,
 	 */
 	merged->high_rssi_timeout = 0;
 
-	/* Sampling period is not implemented yet in userspace. There is no
-	 * good value if the two values are different, so just choose 0 for
-	 * always reporting, to avoid missing packets.
-	 */
-	if (a->sampling_period != b->sampling_period)
-		merged->sampling_period = 0;
-	else
-		merged->sampling_period = a->sampling_period;
+	merged->sampling_period = get_smaller_not_unset(a->sampling_period,
+					b->sampling_period,
+					ADV_MONITOR_UNSET_SAMPLING_PERIOD);
 }
 
 /* Two merged_pattern are considered equal if all the following are true:
@@ -1249,6 +1284,13 @@ static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data)
 						monitor->merged_pattern);
 		merged_pattern_add(monitor->merged_pattern);
 	} else {
+		if (!merge_is_possible(existing_pattern, monitor)) {
+			monitor_destroy(monitor);
+			DBG("Adv Monitor at path %s released due to existing "
+				"monitor", path);
+			return;
+		}
+
 		/* Since there is a matching pattern, abandon the one we have */
 		merged_pattern_free(monitor->merged_pattern);
 		monitor->merged_pattern = existing_pattern;
-- 
2.36.0.rc0.470.gd361397f0d-goog


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

* [BlueZ PATCH v2 7/9] adv_monitor: Add the monitor Release reason
  2022-04-13 20:54 [BlueZ PATCH v2 1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering Manish Mandlik
                   ` (4 preceding siblings ...)
  2022-04-13 20:54 ` [BlueZ PATCH v2 6/9] adv_monitor: Do not merge monitors with non-overlapping RSSI Manish Mandlik
@ 2022-04-13 20:54 ` Manish Mandlik
  2022-04-13 21:48   ` Luiz Augusto von Dentz
  2022-04-13 20:54 ` [BlueZ PATCH v2 8/9] client: Display the AdvMonitor " Manish Mandlik
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 13+ messages in thread
From: Manish Mandlik @ 2022-04-13 20:54 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: chromeos-bluetooth-upstreaming, linux-bluetooth, Manish Mandlik,
	Miao-chen Chou

Adv Monitor is released for various reasons. For example, incorrect RSSI
parameters, incorrect monitor type, non-overlapping RSSI thresholds,
etc.

Return this release reason along with the Release event for the better
visibility to clients.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
---

(no changes since v1)

 doc/advertisement-monitor-api.txt | 12 ++++++-
 src/adv_monitor.c                 | 56 ++++++++++++++++++++++++++++---
 2 files changed, 63 insertions(+), 5 deletions(-)

diff --git a/doc/advertisement-monitor-api.txt b/doc/advertisement-monitor-api.txt
index 942d44b2f..fcbd9c5c2 100644
--- a/doc/advertisement-monitor-api.txt
+++ b/doc/advertisement-monitor-api.txt
@@ -17,12 +17,22 @@ Service		org.bluez
 Interface	org.bluez.AdvertisementMonitor1 [experimental]
 Object path	freely definable
 
-Methods		void Release() [noreply]
+Methods		void Release(Int8 reason) [noreply]
 
 			This gets called as a signal for a client to perform
 			clean-up when (1)a monitor cannot be activated after it
 			was exposed or (2)a monitor has been deactivated.
 
+			Possible reasons:  0  Unknown reason
+					   1  Invalid monitor type
+					   2  Invalid RSSI parameter(s)
+					   3  Invalid pattern(s)
+					   4  Monitor already exists
+					   5  Kernel failed to add monitor
+					   6  Kernel failed to remove monitor
+					   7  Monitor removed by kernel
+					   8  App unregistered/destroyed
+
 		void Activate() [noreply]
 
 			After a monitor was exposed, this gets called as a
diff --git a/src/adv_monitor.c b/src/adv_monitor.c
index d88e1bbbb..9e67d984b 100644
--- a/src/adv_monitor.c
+++ b/src/adv_monitor.c
@@ -90,6 +90,18 @@ enum monitor_state {
 	MONITOR_STATE_RELEASED,	/* Dbus Object removed by app */
 };
 
+enum monitor_release_reason {
+	REASON_UNKNOWN,
+	REASON_INVALID_TYPE,
+	REASON_INVALID_RSSI_PARAMS,
+	REASON_INVALID_PATTERNS,
+	REASON_ALREADY_EXISTS,
+	REASON_FAILED_TO_ADD,
+	REASON_FAILED_TO_REMOVE,
+	REASON_REMOVED_BY_KERNEL,
+	REASON_APP_DESTROYED,
+};
+
 enum merged_pattern_state {
 	MERGED_PATTERN_STATE_ADDING,	/* Adding pattern to kernel */
 	MERGED_PATTERN_STATE_REMOVING,	/* Removing pattern from kernel */
@@ -113,6 +125,7 @@ struct adv_monitor {
 	char *path;
 
 	enum monitor_state state;	/* MONITOR_STATE_* */
+	enum monitor_release_reason release_reason;
 
 	struct rssi_parameters rssi;	/* RSSI parameter for this monitor */
 	struct adv_monitor_merged_pattern *merged_pattern;
@@ -137,6 +150,7 @@ struct adv_monitor_merged_pattern {
 	struct queue *patterns;		/* List of bt_ad_pattern objects */
 	enum merged_pattern_state current_state; /* MERGED_PATTERN_STATE_* */
 	enum merged_pattern_state next_state;	 /* MERGED_PATTERN_STATE_* */
+	enum monitor_release_reason release_reason;
 };
 
 /* Some data like last_seen, timer/timeout values need to be maintained
@@ -541,6 +555,18 @@ static void monitor_free(struct adv_monitor *monitor)
 	free(monitor);
 }
 
+/* Includes monitor release reason into the dbus message */
+static void report_release_reason_setup(DBusMessageIter *iter, void *user_data)
+{
+	const struct adv_monitor *monitor = user_data;
+	int8_t release_reason = REASON_UNKNOWN;
+
+	if (monitor)
+		release_reason = monitor->release_reason;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, &release_reason);
+}
+
 /* Calls Release() method of the remote Adv Monitor */
 static void monitor_release(struct adv_monitor *monitor)
 {
@@ -560,8 +586,9 @@ static void monitor_release(struct adv_monitor *monitor)
 	DBG("Calling Release() on Adv Monitor of owner %s at path %s",
 		monitor->app->owner, monitor->path);
 
-	g_dbus_proxy_method_call(monitor->proxy, "Release", NULL, NULL, NULL,
-					NULL);
+	g_dbus_proxy_method_call(monitor->proxy, "Release",
+					report_release_reason_setup, NULL,
+					monitor, NULL);
 }
 
 /* Removes monitor from the merged_pattern. This would result in removing it
@@ -635,13 +662,20 @@ static void monitor_destroy(void *data)
 static void app_destroy(void *data)
 {
 	struct adv_monitor_app *app = data;
+	const struct queue_entry *e;
 
 	if (!app)
 		return;
 
 	DBG("Destroy Adv Monitor app %s at path %s", app->owner, app->path);
 
-	queue_destroy(app->monitors, monitor_destroy);
+	for (e = queue_get_entries(app->monitors); e; e = e->next) {
+		struct adv_monitor *m = e->data;
+
+		m->release_reason = REASON_APP_DESTROYED;
+		monitor_destroy(m);
+	}
+	queue_destroy(app->monitors, NULL);
 
 	if (app->reg) {
 		app_reply_msg(app, btd_error_failed(app->reg,
@@ -793,6 +827,7 @@ static bool parse_monitor_type(struct adv_monitor *monitor, const char *path)
 	}
 
 failed:
+	monitor->release_reason = REASON_INVALID_TYPE;
 	btd_error(adapter_id,
 			"Invalid argument of property Type of the Adv Monitor "
 			"at path %s", path);
@@ -919,6 +954,7 @@ done:
 	return true;
 
 failed:
+	monitor->release_reason = REASON_INVALID_RSSI_PARAMS;
 	btd_error(adapter_id,
 			"Invalid argument of RSSI thresholds and timeouts "
 			"of the Adv Monitor at path %s",
@@ -1005,6 +1041,7 @@ static bool parse_patterns(struct adv_monitor *monitor, const char *path)
 	return true;
 
 failed:
+	monitor->release_reason = REASON_INVALID_PATTERNS;
 	btd_error(adapter_id, "Invalid argument of property Patterns of the "
 			"Adv Monitor at path %s", path);
 
@@ -1053,6 +1090,7 @@ static void merged_pattern_destroy_monitors(
 		struct adv_monitor *monitor = e->data;
 
 		monitor->merged_pattern = NULL;
+		monitor->release_reason = merged_pattern->release_reason;
 		monitor_destroy(monitor);
 	}
 }
@@ -1086,6 +1124,7 @@ static void remove_adv_monitor_cb(uint8_t status, uint16_t length,
 	return;
 
 fail:
+	merged_pattern->release_reason = REASON_FAILED_TO_REMOVE;
 	merged_pattern_destroy_monitors(merged_pattern);
 	merged_pattern_free(merged_pattern);
 }
@@ -1142,6 +1181,7 @@ static void add_adv_patterns_monitor_cb(uint8_t status, uint16_t length,
 	return;
 
 fail:
+	merged_pattern->release_reason = REASON_FAILED_TO_ADD;
 	merged_pattern_destroy_monitors(merged_pattern);
 	merged_pattern_free(merged_pattern);
 }
@@ -1285,6 +1325,7 @@ static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data)
 		merged_pattern_add(monitor->merged_pattern);
 	} else {
 		if (!merge_is_possible(existing_pattern, monitor)) {
+			monitor->release_reason = REASON_ALREADY_EXISTS;
 			monitor_destroy(monitor);
 			DBG("Adv Monitor at path %s released due to existing "
 				"monitor", path);
@@ -1551,6 +1592,7 @@ static void remove_merged_pattern(void *data, void *user_data)
 {
 	struct adv_monitor_merged_pattern *merged_pattern = data;
 	uint16_t *handle = user_data;
+	const struct queue_entry *e;
 
 	if (!handle)
 		return;
@@ -1562,8 +1604,14 @@ static void remove_merged_pattern(void *data, void *user_data)
 	DBG("Adv monitor with handle:0x%04x removed by kernel",
 		merged_pattern->monitor_handle);
 
+	for (e = queue_get_entries(merged_pattern->monitors); e; e = e->next) {
+		struct adv_monitor *m = e->data;
+
+		m->release_reason = REASON_REMOVED_BY_KERNEL;
+		monitor_destroy(m);
+	}
 	queue_foreach(merged_pattern->monitors, monitor_state_removed, NULL);
-	queue_destroy(merged_pattern->monitors, monitor_destroy);
+	queue_destroy(merged_pattern->monitors, NULL);
 	merged_pattern_free(merged_pattern);
 }
 
-- 
2.36.0.rc0.470.gd361397f0d-goog


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

* [BlueZ PATCH v2 8/9] client: Display the AdvMonitor Release reason
  2022-04-13 20:54 [BlueZ PATCH v2 1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering Manish Mandlik
                   ` (5 preceding siblings ...)
  2022-04-13 20:54 ` [BlueZ PATCH v2 7/9] adv_monitor: Add the monitor Release reason Manish Mandlik
@ 2022-04-13 20:54 ` Manish Mandlik
  2022-04-13 20:54 ` [BlueZ PATCH v2 9/9] test: " Manish Mandlik
  2022-04-15  9:34 ` [BlueZ,v2,1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering bluez.test.bot
  8 siblings, 0 replies; 13+ messages in thread
From: Manish Mandlik @ 2022-04-13 20:54 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: chromeos-bluetooth-upstreaming, linux-bluetooth, Manish Mandlik,
	Miao-chen Chou

Bluetoothd returns the release reason when a monitor is released. Read
the release reason received as part of the Release event and print it
using the bluetoothctl.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
---

(no changes since v1)

 client/adv_monitor.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/client/adv_monitor.c b/client/adv_monitor.c
index 792379fc4..6ee9d2b42 100644
--- a/client/adv_monitor.c
+++ b/client/adv_monitor.c
@@ -72,9 +72,13 @@ static DBusMessage *release_adv_monitor(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
 	struct adv_monitor *adv_monitor = user_data;
+	int8_t release_reason;
 
-	bt_shell_printf("Advertisement monitor %d released\n",
-							adv_monitor->idx);
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_BYTE, &release_reason,
+							DBUS_TYPE_INVALID);
+	bt_shell_printf("Advertisement monitor %d released (reason: %d)\n",
+							adv_monitor->idx,
+							release_reason);
 	remove_adv_monitor(adv_monitor, conn);
 
 	return dbus_message_new_method_return(msg);
@@ -117,7 +121,8 @@ static DBusMessage *device_lost_adv_monitor(DBusConnection *conn,
 }
 
 static const GDBusMethodTable adv_monitor_methods[] = {
-	{ GDBUS_ASYNC_METHOD("Release", NULL, NULL, release_adv_monitor) },
+	{ GDBUS_ASYNC_METHOD("Release", GDBUS_ARGS({"reason", "y"}),
+			NULL, release_adv_monitor) },
 	{ GDBUS_ASYNC_METHOD("Activate", NULL, NULL, activate_adv_monitor) },
 	{ GDBUS_ASYNC_METHOD("DeviceFound", GDBUS_ARGS({ "device", "o" }),
 			NULL, device_found_adv_monitor) },
-- 
2.36.0.rc0.470.gd361397f0d-goog


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

* [BlueZ PATCH v2 9/9] test: Display the AdvMonitor Release reason
  2022-04-13 20:54 [BlueZ PATCH v2 1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering Manish Mandlik
                   ` (6 preceding siblings ...)
  2022-04-13 20:54 ` [BlueZ PATCH v2 8/9] client: Display the AdvMonitor " Manish Mandlik
@ 2022-04-13 20:54 ` Manish Mandlik
  2022-04-15  9:34 ` [BlueZ,v2,1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering bluez.test.bot
  8 siblings, 0 replies; 13+ messages in thread
From: Manish Mandlik @ 2022-04-13 20:54 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: chromeos-bluetooth-upstreaming, linux-bluetooth, Manish Mandlik,
	Miao-chen Chou

Bluetoothd returns the release reason when a monitor is released. Read
the release reason received as part of the Release event and print it
using the example python app.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
---

(no changes since v1)

 test/example-adv-monitor | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/test/example-adv-monitor b/test/example-adv-monitor
index a405fc7b0..b01114c6b 100644
--- a/test/example-adv-monitor
+++ b/test/example-adv-monitor
@@ -117,10 +117,11 @@ class AdvMonitor(dbus.service.Object):
 
 
     @dbus.service.method(ADV_MONITOR_IFACE,
-                         in_signature='',
+                         in_signature='y',
                          out_signature='')
-    def Release(self):
-        print('{}: Monitor Released'.format(self.path))
+    def Release(self, reason):
+        print('{}: Monitor Released (reason: {})'.format(self.path,
+                                                         format(reason, 'd')))
 
 
     @dbus.service.method(ADV_MONITOR_IFACE,
@@ -352,7 +353,10 @@ def test(bus, mainloop, advmon_mgr, app_id):
     # Run until user hits the 'Enter' key. If any peer device is advertising
     # during this time, DeviceFound() should get triggered for monitors
     # matching the advertisements.
-    raw_input('Press "Enter" key to quit...\n')
+    try:
+        raw_input('Press "Enter" key to quit...\n')  # python2
+    except:
+        input('Press "Enter" key to quit...\n')  # python3
 
     # Remove a monitor. DeviceFound() for this monitor should not get
     # triggered any more.
-- 
2.36.0.rc0.470.gd361397f0d-goog


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

* Re: [BlueZ PATCH v2 7/9] adv_monitor: Add the monitor Release reason
  2022-04-13 20:54 ` [BlueZ PATCH v2 7/9] adv_monitor: Add the monitor Release reason Manish Mandlik
@ 2022-04-13 21:48   ` Luiz Augusto von Dentz
       [not found]     ` <CAGPPCLB1j+KV_ZCY7xQe9sHheWWAQPxaRF9pH9R53mAVdmQfHg@mail.gmail.com>
  0 siblings, 1 reply; 13+ messages in thread
From: Luiz Augusto von Dentz @ 2022-04-13 21:48 UTC (permalink / raw)
  To: Manish Mandlik
  Cc: Marcel Holtmann, ChromeOS Bluetooth Upstreaming, linux-bluetooth,
	Miao-chen Chou

Hi Manish,

On Wed, Apr 13, 2022 at 1:55 PM Manish Mandlik <mmandlik@google.com> wrote:
>
> Adv Monitor is released for various reasons. For example, incorrect RSSI
> parameters, incorrect monitor type, non-overlapping RSSI thresholds,
> etc.
>
> Return this release reason along with the Release event for the better
> visibility to clients.
>
> Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
> ---
>
> (no changes since v1)
>
>  doc/advertisement-monitor-api.txt | 12 ++++++-
>  src/adv_monitor.c                 | 56 ++++++++++++++++++++++++++++---
>  2 files changed, 63 insertions(+), 5 deletions(-)
>
> diff --git a/doc/advertisement-monitor-api.txt b/doc/advertisement-monitor-api.txt
> index 942d44b2f..fcbd9c5c2 100644
> --- a/doc/advertisement-monitor-api.txt
> +++ b/doc/advertisement-monitor-api.txt
> @@ -17,12 +17,22 @@ Service             org.bluez
>  Interface      org.bluez.AdvertisementMonitor1 [experimental]
>  Object path    freely definable
>
> -Methods                void Release() [noreply]
> +Methods                void Release(Int8 reason) [noreply]
>
>                         This gets called as a signal for a client to perform
>                         clean-up when (1)a monitor cannot be activated after it
>                         was exposed or (2)a monitor has been deactivated.
>
> +                       Possible reasons:  0  Unknown reason
> +                                          1  Invalid monitor type
> +                                          2  Invalid RSSI parameter(s)
> +                                          3  Invalid pattern(s)
> +                                          4  Monitor already exists
> +                                          5  Kernel failed to add monitor
> +                                          6  Kernel failed to remove monitor
> +                                          7  Monitor removed by kernel
> +                                          8  App unregistered/destroyed

I don't really like this, this is only really useful for debugging but
once the code is stable it becomes pretty useless because the likes of
btmon would already collect errors from bluetoothd so you can already
debug with that, instead this just enables debugging on the
application layer but I don't see how it would help to recover anyway
so given this back to the user is probably a bad idea. Btw if you have
an App unregistered/destroyed the daemon most likely won't be able to
reach the object, so I wonder what is it for?

>                 void Activate() [noreply]
>
>                         After a monitor was exposed, this gets called as a
> diff --git a/src/adv_monitor.c b/src/adv_monitor.c
> index d88e1bbbb..9e67d984b 100644
> --- a/src/adv_monitor.c
> +++ b/src/adv_monitor.c
> @@ -90,6 +90,18 @@ enum monitor_state {
>         MONITOR_STATE_RELEASED, /* Dbus Object removed by app */
>  };
>
> +enum monitor_release_reason {
> +       REASON_UNKNOWN,
> +       REASON_INVALID_TYPE,
> +       REASON_INVALID_RSSI_PARAMS,
> +       REASON_INVALID_PATTERNS,
> +       REASON_ALREADY_EXISTS,
> +       REASON_FAILED_TO_ADD,
> +       REASON_FAILED_TO_REMOVE,
> +       REASON_REMOVED_BY_KERNEL,
> +       REASON_APP_DESTROYED,
> +};
> +
>  enum merged_pattern_state {
>         MERGED_PATTERN_STATE_ADDING,    /* Adding pattern to kernel */
>         MERGED_PATTERN_STATE_REMOVING,  /* Removing pattern from kernel */
> @@ -113,6 +125,7 @@ struct adv_monitor {
>         char *path;
>
>         enum monitor_state state;       /* MONITOR_STATE_* */
> +       enum monitor_release_reason release_reason;
>
>         struct rssi_parameters rssi;    /* RSSI parameter for this monitor */
>         struct adv_monitor_merged_pattern *merged_pattern;
> @@ -137,6 +150,7 @@ struct adv_monitor_merged_pattern {
>         struct queue *patterns;         /* List of bt_ad_pattern objects */
>         enum merged_pattern_state current_state; /* MERGED_PATTERN_STATE_* */
>         enum merged_pattern_state next_state;    /* MERGED_PATTERN_STATE_* */
> +       enum monitor_release_reason release_reason;
>  };
>
>  /* Some data like last_seen, timer/timeout values need to be maintained
> @@ -541,6 +555,18 @@ static void monitor_free(struct adv_monitor *monitor)
>         free(monitor);
>  }
>
> +/* Includes monitor release reason into the dbus message */
> +static void report_release_reason_setup(DBusMessageIter *iter, void *user_data)
> +{
> +       const struct adv_monitor *monitor = user_data;
> +       int8_t release_reason = REASON_UNKNOWN;
> +
> +       if (monitor)
> +               release_reason = monitor->release_reason;
> +
> +       dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, &release_reason);
> +}
> +
>  /* Calls Release() method of the remote Adv Monitor */
>  static void monitor_release(struct adv_monitor *monitor)
>  {
> @@ -560,8 +586,9 @@ static void monitor_release(struct adv_monitor *monitor)
>         DBG("Calling Release() on Adv Monitor of owner %s at path %s",
>                 monitor->app->owner, monitor->path);
>
> -       g_dbus_proxy_method_call(monitor->proxy, "Release", NULL, NULL, NULL,
> -                                       NULL);
> +       g_dbus_proxy_method_call(monitor->proxy, "Release",
> +                                       report_release_reason_setup, NULL,
> +                                       monitor, NULL);
>  }
>
>  /* Removes monitor from the merged_pattern. This would result in removing it
> @@ -635,13 +662,20 @@ static void monitor_destroy(void *data)
>  static void app_destroy(void *data)
>  {
>         struct adv_monitor_app *app = data;
> +       const struct queue_entry *e;
>
>         if (!app)
>                 return;
>
>         DBG("Destroy Adv Monitor app %s at path %s", app->owner, app->path);
>
> -       queue_destroy(app->monitors, monitor_destroy);
> +       for (e = queue_get_entries(app->monitors); e; e = e->next) {
> +               struct adv_monitor *m = e->data;
> +
> +               m->release_reason = REASON_APP_DESTROYED;
> +               monitor_destroy(m);
> +       }
> +       queue_destroy(app->monitors, NULL);
>
>         if (app->reg) {
>                 app_reply_msg(app, btd_error_failed(app->reg,
> @@ -793,6 +827,7 @@ static bool parse_monitor_type(struct adv_monitor *monitor, const char *path)
>         }
>
>  failed:
> +       monitor->release_reason = REASON_INVALID_TYPE;
>         btd_error(adapter_id,
>                         "Invalid argument of property Type of the Adv Monitor "
>                         "at path %s", path);
> @@ -919,6 +954,7 @@ done:
>         return true;
>
>  failed:
> +       monitor->release_reason = REASON_INVALID_RSSI_PARAMS;
>         btd_error(adapter_id,
>                         "Invalid argument of RSSI thresholds and timeouts "
>                         "of the Adv Monitor at path %s",
> @@ -1005,6 +1041,7 @@ static bool parse_patterns(struct adv_monitor *monitor, const char *path)
>         return true;
>
>  failed:
> +       monitor->release_reason = REASON_INVALID_PATTERNS;
>         btd_error(adapter_id, "Invalid argument of property Patterns of the "
>                         "Adv Monitor at path %s", path);
>
> @@ -1053,6 +1090,7 @@ static void merged_pattern_destroy_monitors(
>                 struct adv_monitor *monitor = e->data;
>
>                 monitor->merged_pattern = NULL;
> +               monitor->release_reason = merged_pattern->release_reason;
>                 monitor_destroy(monitor);
>         }
>  }
> @@ -1086,6 +1124,7 @@ static void remove_adv_monitor_cb(uint8_t status, uint16_t length,
>         return;
>
>  fail:
> +       merged_pattern->release_reason = REASON_FAILED_TO_REMOVE;
>         merged_pattern_destroy_monitors(merged_pattern);
>         merged_pattern_free(merged_pattern);
>  }
> @@ -1142,6 +1181,7 @@ static void add_adv_patterns_monitor_cb(uint8_t status, uint16_t length,
>         return;
>
>  fail:
> +       merged_pattern->release_reason = REASON_FAILED_TO_ADD;
>         merged_pattern_destroy_monitors(merged_pattern);
>         merged_pattern_free(merged_pattern);
>  }
> @@ -1285,6 +1325,7 @@ static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data)
>                 merged_pattern_add(monitor->merged_pattern);
>         } else {
>                 if (!merge_is_possible(existing_pattern, monitor)) {
> +                       monitor->release_reason = REASON_ALREADY_EXISTS;
>                         monitor_destroy(monitor);
>                         DBG("Adv Monitor at path %s released due to existing "
>                                 "monitor", path);
> @@ -1551,6 +1592,7 @@ static void remove_merged_pattern(void *data, void *user_data)
>  {
>         struct adv_monitor_merged_pattern *merged_pattern = data;
>         uint16_t *handle = user_data;
> +       const struct queue_entry *e;
>
>         if (!handle)
>                 return;
> @@ -1562,8 +1604,14 @@ static void remove_merged_pattern(void *data, void *user_data)
>         DBG("Adv monitor with handle:0x%04x removed by kernel",
>                 merged_pattern->monitor_handle);
>
> +       for (e = queue_get_entries(merged_pattern->monitors); e; e = e->next) {
> +               struct adv_monitor *m = e->data;
> +
> +               m->release_reason = REASON_REMOVED_BY_KERNEL;
> +               monitor_destroy(m);
> +       }
>         queue_foreach(merged_pattern->monitors, monitor_state_removed, NULL);
> -       queue_destroy(merged_pattern->monitors, monitor_destroy);
> +       queue_destroy(merged_pattern->monitors, NULL);
>         merged_pattern_free(merged_pattern);
>  }
>
> --
> 2.36.0.rc0.470.gd361397f0d-goog
>


-- 
Luiz Augusto von Dentz

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

* Re: [BlueZ PATCH v2 7/9] adv_monitor: Add the monitor Release reason
       [not found]     ` <CAGPPCLB1j+KV_ZCY7xQe9sHheWWAQPxaRF9pH9R53mAVdmQfHg@mail.gmail.com>
@ 2022-04-13 22:42       ` Luiz Augusto von Dentz
       [not found]         ` <CAGPPCLBaoP=dXKp53F7Q3Pg4pnSELdkt_ns9Aw-A-yYk6Vs0yw@mail.gmail.com>
  0 siblings, 1 reply; 13+ messages in thread
From: Luiz Augusto von Dentz @ 2022-04-13 22:42 UTC (permalink / raw)
  To: Manish Mandlik
  Cc: Marcel Holtmann, ChromeOS Bluetooth Upstreaming, linux-bluetooth,
	Miao-chen Chou

Hi Manish,

On Wed, Apr 13, 2022 at 3:27 PM Manish Mandlik <mmandlik@google.com> wrote:
>
> Hi Luiz,
>
> On Wed, Apr 13, 2022 at 2:48 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote:
>>
>> Hi Manish,
>>
>> On Wed, Apr 13, 2022 at 1:55 PM Manish Mandlik <mmandlik@google.com> wrote:
>> >
>> > Adv Monitor is released for various reasons. For example, incorrect RSSI
>> > parameters, incorrect monitor type, non-overlapping RSSI thresholds,
>> > etc.
>> >
>> > Return this release reason along with the Release event for the better
>> > visibility to clients.
>> >
>> > Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
>> > ---
>> >
>> > (no changes since v1)
>> >
>> >  doc/advertisement-monitor-api.txt | 12 ++++++-
>> >  src/adv_monitor.c                 | 56 ++++++++++++++++++++++++++++---
>> >  2 files changed, 63 insertions(+), 5 deletions(-)
>> >
>> > diff --git a/doc/advertisement-monitor-api.txt b/doc/advertisement-monitor-api.txt
>> > index 942d44b2f..fcbd9c5c2 100644
>> > --- a/doc/advertisement-monitor-api.txt
>> > +++ b/doc/advertisement-monitor-api.txt
>> > @@ -17,12 +17,22 @@ Service             org.bluez
>> >  Interface      org.bluez.AdvertisementMonitor1 [experimental]
>> >  Object path    freely definable
>> >
>> > -Methods                void Release() [noreply]
>> > +Methods                void Release(Int8 reason) [noreply]
>> >
>> >                         This gets called as a signal for a client to perform
>> >                         clean-up when (1)a monitor cannot be activated after it
>> >                         was exposed or (2)a monitor has been deactivated.
>> >
>> > +                       Possible reasons:  0  Unknown reason
>> > +                                          1  Invalid monitor type
>> > +                                          2  Invalid RSSI parameter(s)
>> > +                                          3  Invalid pattern(s)
>> > +                                          4  Monitor already exists
>> > +                                          5  Kernel failed to add monitor
>> > +                                          6  Kernel failed to remove monitor
>> > +                                          7  Monitor removed by kernel
>> > +                                          8  App unregistered/destroyed
>>
>> I don't really like this, this is only really useful for debugging but
>> once the code is stable it becomes pretty useless because the likes of
>> btmon would already collect errors from bluetoothd so you can already
>> debug with that, instead this just enables debugging on the
>> application layer but I don't see how it would help to recover anyway
>> so given this back to the user is probably a bad idea. Btw if you have
>> an App unregistered/destroyed the daemon most likely won't be able to
>> reach the object, so I wonder what is it for?
>
> This was added to give applications more visibility into why a monitor was not accepted. I agree that once the code is stable, most of the release reasons may become useless. However, the reason code "4 - Monitor already exists" may still happen. If more than one application creates monitors for the same pattern but with different RSSI parameters, BlueZ merges those monitors and sends it to the kernel as controllers do not accept monitors with the duplicate patterns. So, if RSSI parameters do not overlap with the existing monitors, BlueZ cannot merge such monitors and hence needs to release it. This error code will help applications to capture such scenarios and update the RSSI parameters accordingly on the fly.

Not sure how the application will be able to correct the RSSI to fit
if it doesn't have access to all other monitors active in the system,
and even in case you have access to other monitors then you could
check this beforehand. I'm afraid we will need to find a way to make
this work transparently, perhaps have the RSSI updated either on the
application (strict) or in controller (relax).

>
> For the reason code "8 - App unregistered/destroyed", Release may not get delivered if the app is already destroyed. But applications can unregister Advertisement Monitor interface with BlueZ even if they are not exiting. In such a case, Release will be delivered for all previously active monitors of that application. This may help to notify applications to remove the monitor D-Bus objects if they want.

Well that removes the App destroyed then, also in case of Unregister
we normally don't attempt to reach out the object if it has been
unregistered since it is the application that is initiating the action
it should be aware that it has to release these objects so we avoid
extra traffic on D-Bus, specially in case the application is being
terminated and decide to call Unregister in the process, which it
probably shouldn't since we would cleanup anyway when it disconnects
from D-Bus, in fact I consider Unregister as a group Release and if
the application wants to register one by one then it should use
ObjectManager.InterfacesRemoves so its proxies are individually
removed.

Release is only really useful when initiated by the daemon itself,
like the adapter being unregistered, etc.

>>
>> >                 void Activate() [noreply]
>> >
>> >                         After a monitor was exposed, this gets called as a
>> > diff --git a/src/adv_monitor.c b/src/adv_monitor.c
>> > index d88e1bbbb..9e67d984b 100644
>> > --- a/src/adv_monitor.c
>> > +++ b/src/adv_monitor.c
>> > @@ -90,6 +90,18 @@ enum monitor_state {
>> >         MONITOR_STATE_RELEASED, /* Dbus Object removed by app */
>> >  };
>> >
>> > +enum monitor_release_reason {
>> > +       REASON_UNKNOWN,
>> > +       REASON_INVALID_TYPE,
>> > +       REASON_INVALID_RSSI_PARAMS,
>> > +       REASON_INVALID_PATTERNS,
>> > +       REASON_ALREADY_EXISTS,
>> > +       REASON_FAILED_TO_ADD,
>> > +       REASON_FAILED_TO_REMOVE,
>> > +       REASON_REMOVED_BY_KERNEL,
>> > +       REASON_APP_DESTROYED,
>> > +};
>> > +
>> >  enum merged_pattern_state {
>> >         MERGED_PATTERN_STATE_ADDING,    /* Adding pattern to kernel */
>> >         MERGED_PATTERN_STATE_REMOVING,  /* Removing pattern from kernel */
>> > @@ -113,6 +125,7 @@ struct adv_monitor {
>> >         char *path;
>> >
>> >         enum monitor_state state;       /* MONITOR_STATE_* */
>> > +       enum monitor_release_reason release_reason;
>> >
>> >         struct rssi_parameters rssi;    /* RSSI parameter for this monitor */
>> >         struct adv_monitor_merged_pattern *merged_pattern;
>> > @@ -137,6 +150,7 @@ struct adv_monitor_merged_pattern {
>> >         struct queue *patterns;         /* List of bt_ad_pattern objects */
>> >         enum merged_pattern_state current_state; /* MERGED_PATTERN_STATE_* */
>> >         enum merged_pattern_state next_state;    /* MERGED_PATTERN_STATE_* */
>> > +       enum monitor_release_reason release_reason;
>> >  };
>> >
>> >  /* Some data like last_seen, timer/timeout values need to be maintained
>> > @@ -541,6 +555,18 @@ static void monitor_free(struct adv_monitor *monitor)
>> >         free(monitor);
>> >  }
>> >
>> > +/* Includes monitor release reason into the dbus message */
>> > +static void report_release_reason_setup(DBusMessageIter *iter, void *user_data)
>> > +{
>> > +       const struct adv_monitor *monitor = user_data;
>> > +       int8_t release_reason = REASON_UNKNOWN;
>> > +
>> > +       if (monitor)
>> > +               release_reason = monitor->release_reason;
>> > +
>> > +       dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, &release_reason);
>> > +}
>> > +
>> >  /* Calls Release() method of the remote Adv Monitor */
>> >  static void monitor_release(struct adv_monitor *monitor)
>> >  {
>> > @@ -560,8 +586,9 @@ static void monitor_release(struct adv_monitor *monitor)
>> >         DBG("Calling Release() on Adv Monitor of owner %s at path %s",
>> >                 monitor->app->owner, monitor->path);
>> >
>> > -       g_dbus_proxy_method_call(monitor->proxy, "Release", NULL, NULL, NULL,
>> > -                                       NULL);
>> > +       g_dbus_proxy_method_call(monitor->proxy, "Release",
>> > +                                       report_release_reason_setup, NULL,
>> > +                                       monitor, NULL);
>> >  }
>> >
>> >  /* Removes monitor from the merged_pattern. This would result in removing it
>> > @@ -635,13 +662,20 @@ static void monitor_destroy(void *data)
>> >  static void app_destroy(void *data)
>> >  {
>> >         struct adv_monitor_app *app = data;
>> > +       const struct queue_entry *e;
>> >
>> >         if (!app)
>> >                 return;
>> >
>> >         DBG("Destroy Adv Monitor app %s at path %s", app->owner, app->path);
>> >
>> > -       queue_destroy(app->monitors, monitor_destroy);
>> > +       for (e = queue_get_entries(app->monitors); e; e = e->next) {
>> > +               struct adv_monitor *m = e->data;
>> > +
>> > +               m->release_reason = REASON_APP_DESTROYED;
>> > +               monitor_destroy(m);
>> > +       }
>> > +       queue_destroy(app->monitors, NULL);
>> >
>> >         if (app->reg) {
>> >                 app_reply_msg(app, btd_error_failed(app->reg,
>> > @@ -793,6 +827,7 @@ static bool parse_monitor_type(struct adv_monitor *monitor, const char *path)
>> >         }
>> >
>> >  failed:
>> > +       monitor->release_reason = REASON_INVALID_TYPE;
>> >         btd_error(adapter_id,
>> >                         "Invalid argument of property Type of the Adv Monitor "
>> >                         "at path %s", path);
>> > @@ -919,6 +954,7 @@ done:
>> >         return true;
>> >
>> >  failed:
>> > +       monitor->release_reason = REASON_INVALID_RSSI_PARAMS;
>> >         btd_error(adapter_id,
>> >                         "Invalid argument of RSSI thresholds and timeouts "
>> >                         "of the Adv Monitor at path %s",
>> > @@ -1005,6 +1041,7 @@ static bool parse_patterns(struct adv_monitor *monitor, const char *path)
>> >         return true;
>> >
>> >  failed:
>> > +       monitor->release_reason = REASON_INVALID_PATTERNS;
>> >         btd_error(adapter_id, "Invalid argument of property Patterns of the "
>> >                         "Adv Monitor at path %s", path);
>> >
>> > @@ -1053,6 +1090,7 @@ static void merged_pattern_destroy_monitors(
>> >                 struct adv_monitor *monitor = e->data;
>> >
>> >                 monitor->merged_pattern = NULL;
>> > +               monitor->release_reason = merged_pattern->release_reason;
>> >                 monitor_destroy(monitor);
>> >         }
>> >  }
>> > @@ -1086,6 +1124,7 @@ static void remove_adv_monitor_cb(uint8_t status, uint16_t length,
>> >         return;
>> >
>> >  fail:
>> > +       merged_pattern->release_reason = REASON_FAILED_TO_REMOVE;
>> >         merged_pattern_destroy_monitors(merged_pattern);
>> >         merged_pattern_free(merged_pattern);
>> >  }
>> > @@ -1142,6 +1181,7 @@ static void add_adv_patterns_monitor_cb(uint8_t status, uint16_t length,
>> >         return;
>> >
>> >  fail:
>> > +       merged_pattern->release_reason = REASON_FAILED_TO_ADD;
>> >         merged_pattern_destroy_monitors(merged_pattern);
>> >         merged_pattern_free(merged_pattern);
>> >  }
>> > @@ -1285,6 +1325,7 @@ static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data)
>> >                 merged_pattern_add(monitor->merged_pattern);
>> >         } else {
>> >                 if (!merge_is_possible(existing_pattern, monitor)) {
>> > +                       monitor->release_reason = REASON_ALREADY_EXISTS;
>> >                         monitor_destroy(monitor);
>> >                         DBG("Adv Monitor at path %s released due to existing "
>> >                                 "monitor", path);
>> > @@ -1551,6 +1592,7 @@ static void remove_merged_pattern(void *data, void *user_data)
>> >  {
>> >         struct adv_monitor_merged_pattern *merged_pattern = data;
>> >         uint16_t *handle = user_data;
>> > +       const struct queue_entry *e;
>> >
>> >         if (!handle)
>> >                 return;
>> > @@ -1562,8 +1604,14 @@ static void remove_merged_pattern(void *data, void *user_data)
>> >         DBG("Adv monitor with handle:0x%04x removed by kernel",
>> >                 merged_pattern->monitor_handle);
>> >
>> > +       for (e = queue_get_entries(merged_pattern->monitors); e; e = e->next) {
>> > +               struct adv_monitor *m = e->data;
>> > +
>> > +               m->release_reason = REASON_REMOVED_BY_KERNEL;
>> > +               monitor_destroy(m);
>> > +       }
>> >         queue_foreach(merged_pattern->monitors, monitor_state_removed, NULL);
>> > -       queue_destroy(merged_pattern->monitors, monitor_destroy);
>> > +       queue_destroy(merged_pattern->monitors, NULL);
>> >         merged_pattern_free(merged_pattern);
>> >  }
>> >
>> > --
>> > 2.36.0.rc0.470.gd361397f0d-goog
>> >
>>
>>
>> --
>> Luiz Augusto von Dentz
>
>
> Regards,
> Manish.



-- 
Luiz Augusto von Dentz

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

* RE: [BlueZ,v2,1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering
  2022-04-13 20:54 [BlueZ PATCH v2 1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering Manish Mandlik
                   ` (7 preceding siblings ...)
  2022-04-13 20:54 ` [BlueZ PATCH v2 9/9] test: " Manish Mandlik
@ 2022-04-15  9:34 ` bluez.test.bot
  8 siblings, 0 replies; 13+ messages in thread
From: bluez.test.bot @ 2022-04-15  9:34 UTC (permalink / raw)
  To: linux-bluetooth, mmandlik

[-- Attachment #1: Type: text/plain, Size: 1000 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=632021

---Test result---

Test Summary:
CheckPatch                    PASS      13.07 seconds
GitLint                       PASS      8.92 seconds
Prep - Setup ELL              PASS      42.51 seconds
Build - Prep                  PASS      0.67 seconds
Build - Configure             PASS      8.45 seconds
Build - Make                  PASS      1277.32 seconds
Make Check                    PASS      11.44 seconds
Make Check w/Valgrind         PASS      448.86 seconds
Make Distcheck                PASS      234.77 seconds
Build w/ext ELL - Configure   PASS      8.45 seconds
Build w/ext ELL - Make        PASS      1244.94 seconds
Incremental Build with patchesPASS      11371.40 seconds



---
Regards,
Linux Bluetooth


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

* Re: [BlueZ PATCH v2 7/9] adv_monitor: Add the monitor Release reason
       [not found]         ` <CAGPPCLBaoP=dXKp53F7Q3Pg4pnSELdkt_ns9Aw-A-yYk6Vs0yw@mail.gmail.com>
@ 2022-04-20 20:02           ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 13+ messages in thread
From: Luiz Augusto von Dentz @ 2022-04-20 20:02 UTC (permalink / raw)
  To: Manish Mandlik
  Cc: Marcel Holtmann, ChromeOS Bluetooth Upstreaming, linux-bluetooth,
	Miao-chen Chou

Hi Manish,

On Wed, Apr 20, 2022 at 10:51 AM Manish Mandlik <mmandlik@google.com> wrote:
>
> Hi Luiz,
>
> On Wed, Apr 13, 2022 at 3:42 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote:
>>
>> Hi Manish,
>>
>> On Wed, Apr 13, 2022 at 3:27 PM Manish Mandlik <mmandlik@google.com> wrote:
>> >
>> > Hi Luiz,
>> >
>> > On Wed, Apr 13, 2022 at 2:48 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote:
>> >>
>> >> Hi Manish,
>> >>
>> >> On Wed, Apr 13, 2022 at 1:55 PM Manish Mandlik <mmandlik@google.com> wrote:
>> >> >
>> >> > Adv Monitor is released for various reasons. For example, incorrect RSSI
>> >> > parameters, incorrect monitor type, non-overlapping RSSI thresholds,
>> >> > etc.
>> >> >
>> >> > Return this release reason along with the Release event for the better
>> >> > visibility to clients.
>> >> >
>> >> > Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
>> >> > ---
>> >> >
>> >> > (no changes since v1)
>> >> >
>> >> >  doc/advertisement-monitor-api.txt | 12 ++++++-
>> >> >  src/adv_monitor.c                 | 56 ++++++++++++++++++++++++++++---
>> >> >  2 files changed, 63 insertions(+), 5 deletions(-)
>> >> >
>> >> > diff --git a/doc/advertisement-monitor-api.txt b/doc/advertisement-monitor-api.txt
>> >> > index 942d44b2f..fcbd9c5c2 100644
>> >> > --- a/doc/advertisement-monitor-api.txt
>> >> > +++ b/doc/advertisement-monitor-api.txt
>> >> > @@ -17,12 +17,22 @@ Service             org.bluez
>> >> >  Interface      org.bluez.AdvertisementMonitor1 [experimental]
>> >> >  Object path    freely definable
>> >> >
>> >> > -Methods                void Release() [noreply]
>> >> > +Methods                void Release(Int8 reason) [noreply]
>> >> >
>> >> >                         This gets called as a signal for a client to perform
>> >> >                         clean-up when (1)a monitor cannot be activated after it
>> >> >                         was exposed or (2)a monitor has been deactivated.
>> >> >
>> >> > +                       Possible reasons:  0  Unknown reason
>> >> > +                                          1  Invalid monitor type
>> >> > +                                          2  Invalid RSSI parameter(s)
>> >> > +                                          3  Invalid pattern(s)
>> >> > +                                          4  Monitor already exists
>> >> > +                                          5  Kernel failed to add monitor
>> >> > +                                          6  Kernel failed to remove monitor
>> >> > +                                          7  Monitor removed by kernel
>> >> > +                                          8  App unregistered/destroyed
>> >>
>> >> I don't really like this, this is only really useful for debugging but
>> >> once the code is stable it becomes pretty useless because the likes of
>> >> btmon would already collect errors from bluetoothd so you can already
>> >> debug with that, instead this just enables debugging on the
>> >> application layer but I don't see how it would help to recover anyway
>> >> so given this back to the user is probably a bad idea. Btw if you have
>> >> an App unregistered/destroyed the daemon most likely won't be able to
>> >> reach the object, so I wonder what is it for?
>> >
>> > This was added to give applications more visibility into why a monitor was not accepted. I agree that once the code is stable, most of the release reasons may become useless. However, the reason code "4 - Monitor already exists" may still happen. If more than one application creates monitors for the same pattern but with different RSSI parameters, BlueZ merges those monitors and sends it to the kernel as controllers do not accept monitors with the duplicate patterns. So, if RSSI parameters do not overlap with the existing monitors, BlueZ cannot merge such monitors and hence needs to release it. This error code will help applications to capture such scenarios and update the RSSI parameters accordingly on the fly.
>>
>> Not sure how the application will be able to correct the RSSI to fit
>> if it doesn't have access to all other monitors active in the system,
>> and even in case you have access to other monitors then you could
>> check this beforehand. I'm afraid we will need to find a way to make
>> this work transparently, perhaps have the RSSI updated either on the
>> application (strict) or in controller (relax).
>
> All monitors are exposed on org.bluez.AdvertisementMonitor1 interface and applications can check all monitors on that interface. However, multiple applications adding monitors with the same pattern won't be a common case. So, it will be an overhead to check all other monitors while creating a new monitor every time. BlueZ anyway updates the RSSI if there is an overlap of the RSSI parameters. The failure case would occur only when there is no overlap. So I feel providing a release reason along with a Release() method call would rather be an optimised approach and the application can read through all other monitors only if BlueZ notifies of a conflict. Let me know what you think about this.

If I got you right you want the daemon to check if there are any
conflicts for the application and if there is than call Release with
the error code, but still we don't inform what the conflict is or
rather what is the RSSI that can be used to resolve the conflict which
comes back to my initial response that this should be resolved by the
daemon somehow and if the application is not happy with the resulting
RSSI then it just unregister which should make this less error prone.

>>
>>
>> >
>> > For the reason code "8 - App unregistered/destroyed", Release may not get delivered if the app is already destroyed. But applications can unregister Advertisement Monitor interface with BlueZ even if they are not exiting. In such a case, Release will be delivered for all previously active monitors of that application. This may help to notify applications to remove the monitor D-Bus objects if they want.
>>
>> Well that removes the App destroyed then, also in case of Unregister
>> we normally don't attempt to reach out the object if it has been
>> unregistered since it is the application that is initiating the action
>> it should be aware that it has to release these objects so we avoid
>> extra traffic on D-Bus, specially in case the application is being
>> terminated and decide to call Unregister in the process, which it
>> probably shouldn't since we would cleanup anyway when it disconnects
>> from D-Bus, in fact I consider Unregister as a group Release and if
>> the application wants to register one by one then it should use
>> ObjectManager.InterfacesRemoves so its proxies are individually
>> removed.
>
> Ack. I'll remove this release reason and I'll also create another patch to remove calling the Release() on monitor objects in such a case from the existing code.
>
>>
>> Release is only really useful when initiated by the daemon itself,
>> like the adapter being unregistered, etc.
>>
>> >>
>> >> >                 void Activate() [noreply]
>> >> >
>> >> >                         After a monitor was exposed, this gets called as a
>> >> > diff --git a/src/adv_monitor.c b/src/adv_monitor.c
>> >> > index d88e1bbbb..9e67d984b 100644
>> >> > --- a/src/adv_monitor.c
>> >> > +++ b/src/adv_monitor.c
>> >> > @@ -90,6 +90,18 @@ enum monitor_state {
>> >> >         MONITOR_STATE_RELEASED, /* Dbus Object removed by app */
>> >> >  };
>> >> >
>> >> > +enum monitor_release_reason {
>> >> > +       REASON_UNKNOWN,
>> >> > +       REASON_INVALID_TYPE,
>> >> > +       REASON_INVALID_RSSI_PARAMS,
>> >> > +       REASON_INVALID_PATTERNS,
>> >> > +       REASON_ALREADY_EXISTS,
>> >> > +       REASON_FAILED_TO_ADD,
>> >> > +       REASON_FAILED_TO_REMOVE,
>> >> > +       REASON_REMOVED_BY_KERNEL,
>> >> > +       REASON_APP_DESTROYED,
>> >> > +};
>> >> > +
>> >> >  enum merged_pattern_state {
>> >> >         MERGED_PATTERN_STATE_ADDING,    /* Adding pattern to kernel */
>> >> >         MERGED_PATTERN_STATE_REMOVING,  /* Removing pattern from kernel */
>> >> > @@ -113,6 +125,7 @@ struct adv_monitor {
>> >> >         char *path;
>> >> >
>> >> >         enum monitor_state state;       /* MONITOR_STATE_* */
>> >> > +       enum monitor_release_reason release_reason;
>> >> >
>> >> >         struct rssi_parameters rssi;    /* RSSI parameter for this monitor */
>> >> >         struct adv_monitor_merged_pattern *merged_pattern;
>> >> > @@ -137,6 +150,7 @@ struct adv_monitor_merged_pattern {
>> >> >         struct queue *patterns;         /* List of bt_ad_pattern objects */
>> >> >         enum merged_pattern_state current_state; /* MERGED_PATTERN_STATE_* */
>> >> >         enum merged_pattern_state next_state;    /* MERGED_PATTERN_STATE_* */
>> >> > +       enum monitor_release_reason release_reason;
>> >> >  };
>> >> >
>> >> >  /* Some data like last_seen, timer/timeout values need to be maintained
>> >> > @@ -541,6 +555,18 @@ static void monitor_free(struct adv_monitor *monitor)
>> >> >         free(monitor);
>> >> >  }
>> >> >
>> >> > +/* Includes monitor release reason into the dbus message */
>> >> > +static void report_release_reason_setup(DBusMessageIter *iter, void *user_data)
>> >> > +{
>> >> > +       const struct adv_monitor *monitor = user_data;
>> >> > +       int8_t release_reason = REASON_UNKNOWN;
>> >> > +
>> >> > +       if (monitor)
>> >> > +               release_reason = monitor->release_reason;
>> >> > +
>> >> > +       dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, &release_reason);
>> >> > +}
>> >> > +
>> >> >  /* Calls Release() method of the remote Adv Monitor */
>> >> >  static void monitor_release(struct adv_monitor *monitor)
>> >> >  {
>> >> > @@ -560,8 +586,9 @@ static void monitor_release(struct adv_monitor *monitor)
>> >> >         DBG("Calling Release() on Adv Monitor of owner %s at path %s",
>> >> >                 monitor->app->owner, monitor->path);
>> >> >
>> >> > -       g_dbus_proxy_method_call(monitor->proxy, "Release", NULL, NULL, NULL,
>> >> > -                                       NULL);
>> >> > +       g_dbus_proxy_method_call(monitor->proxy, "Release",
>> >> > +                                       report_release_reason_setup, NULL,
>> >> > +                                       monitor, NULL);
>> >> >  }
>> >> >
>> >> >  /* Removes monitor from the merged_pattern. This would result in removing it
>> >> > @@ -635,13 +662,20 @@ static void monitor_destroy(void *data)
>> >> >  static void app_destroy(void *data)
>> >> >  {
>> >> >         struct adv_monitor_app *app = data;
>> >> > +       const struct queue_entry *e;
>> >> >
>> >> >         if (!app)
>> >> >                 return;
>> >> >
>> >> >         DBG("Destroy Adv Monitor app %s at path %s", app->owner, app->path);
>> >> >
>> >> > -       queue_destroy(app->monitors, monitor_destroy);
>> >> > +       for (e = queue_get_entries(app->monitors); e; e = e->next) {
>> >> > +               struct adv_monitor *m = e->data;
>> >> > +
>> >> > +               m->release_reason = REASON_APP_DESTROYED;
>> >> > +               monitor_destroy(m);
>> >> > +       }
>> >> > +       queue_destroy(app->monitors, NULL);
>> >> >
>> >> >         if (app->reg) {
>> >> >                 app_reply_msg(app, btd_error_failed(app->reg,
>> >> > @@ -793,6 +827,7 @@ static bool parse_monitor_type(struct adv_monitor *monitor, const char *path)
>> >> >         }
>> >> >
>> >> >  failed:
>> >> > +       monitor->release_reason = REASON_INVALID_TYPE;
>> >> >         btd_error(adapter_id,
>> >> >                         "Invalid argument of property Type of the Adv Monitor "
>> >> >                         "at path %s", path);
>> >> > @@ -919,6 +954,7 @@ done:
>> >> >         return true;
>> >> >
>> >> >  failed:
>> >> > +       monitor->release_reason = REASON_INVALID_RSSI_PARAMS;
>> >> >         btd_error(adapter_id,
>> >> >                         "Invalid argument of RSSI thresholds and timeouts "
>> >> >                         "of the Adv Monitor at path %s",
>> >> > @@ -1005,6 +1041,7 @@ static bool parse_patterns(struct adv_monitor *monitor, const char *path)
>> >> >         return true;
>> >> >
>> >> >  failed:
>> >> > +       monitor->release_reason = REASON_INVALID_PATTERNS;
>> >> >         btd_error(adapter_id, "Invalid argument of property Patterns of the "
>> >> >                         "Adv Monitor at path %s", path);
>> >> >
>> >> > @@ -1053,6 +1090,7 @@ static void merged_pattern_destroy_monitors(
>> >> >                 struct adv_monitor *monitor = e->data;
>> >> >
>> >> >                 monitor->merged_pattern = NULL;
>> >> > +               monitor->release_reason = merged_pattern->release_reason;
>> >> >                 monitor_destroy(monitor);
>> >> >         }
>> >> >  }
>> >> > @@ -1086,6 +1124,7 @@ static void remove_adv_monitor_cb(uint8_t status, uint16_t length,
>> >> >         return;
>> >> >
>> >> >  fail:
>> >> > +       merged_pattern->release_reason = REASON_FAILED_TO_REMOVE;
>> >> >         merged_pattern_destroy_monitors(merged_pattern);
>> >> >         merged_pattern_free(merged_pattern);
>> >> >  }
>> >> > @@ -1142,6 +1181,7 @@ static void add_adv_patterns_monitor_cb(uint8_t status, uint16_t length,
>> >> >         return;
>> >> >
>> >> >  fail:
>> >> > +       merged_pattern->release_reason = REASON_FAILED_TO_ADD;
>> >> >         merged_pattern_destroy_monitors(merged_pattern);
>> >> >         merged_pattern_free(merged_pattern);
>> >> >  }
>> >> > @@ -1285,6 +1325,7 @@ static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data)
>> >> >                 merged_pattern_add(monitor->merged_pattern);
>> >> >         } else {
>> >> >                 if (!merge_is_possible(existing_pattern, monitor)) {
>> >> > +                       monitor->release_reason = REASON_ALREADY_EXISTS;
>> >> >                         monitor_destroy(monitor);
>> >> >                         DBG("Adv Monitor at path %s released due to existing "
>> >> >                                 "monitor", path);
>> >> > @@ -1551,6 +1592,7 @@ static void remove_merged_pattern(void *data, void *user_data)
>> >> >  {
>> >> >         struct adv_monitor_merged_pattern *merged_pattern = data;
>> >> >         uint16_t *handle = user_data;
>> >> > +       const struct queue_entry *e;
>> >> >
>> >> >         if (!handle)
>> >> >                 return;
>> >> > @@ -1562,8 +1604,14 @@ static void remove_merged_pattern(void *data, void *user_data)
>> >> >         DBG("Adv monitor with handle:0x%04x removed by kernel",
>> >> >                 merged_pattern->monitor_handle);
>> >> >
>> >> > +       for (e = queue_get_entries(merged_pattern->monitors); e; e = e->next) {
>> >> > +               struct adv_monitor *m = e->data;
>> >> > +
>> >> > +               m->release_reason = REASON_REMOVED_BY_KERNEL;
>> >> > +               monitor_destroy(m);
>> >> > +       }
>> >> >         queue_foreach(merged_pattern->monitors, monitor_state_removed, NULL);
>> >> > -       queue_destroy(merged_pattern->monitors, monitor_destroy);
>> >> > +       queue_destroy(merged_pattern->monitors, NULL);
>> >> >         merged_pattern_free(merged_pattern);
>> >> >  }
>> >> >
>> >> > --
>> >> > 2.36.0.rc0.470.gd361397f0d-goog
>> >> >
>> >>
>> >>
>> >> --
>> >> Luiz Augusto von Dentz
>> >
>> >
>> > Regards,
>> > Manish.
>>
>>
>>
>> --
>> Luiz Augusto von Dentz
>
>
> Regards,
> Manish.



-- 
Luiz Augusto von Dentz

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

end of thread, other threads:[~2022-04-20 20:02 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-13 20:54 [BlueZ PATCH v2 1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering Manish Mandlik
2022-04-13 20:54 ` [BlueZ PATCH v2 2/9] adv_monitor: Don't send DeviceFound for already found devices Manish Mandlik
2022-04-13 20:54 ` [BlueZ PATCH v2 3/9] adv_monitor: Clear tracked devices on resume Manish Mandlik
2022-04-13 20:54 ` [BlueZ PATCH v2 4/9] adv_monitor: Do not remove the device while monitoring Manish Mandlik
2022-04-13 20:54 ` [BlueZ PATCH v2 5/9] monitor: Display AdvMonitor DeviceFound/Lost events Manish Mandlik
2022-04-13 20:54 ` [BlueZ PATCH v2 6/9] adv_monitor: Do not merge monitors with non-overlapping RSSI Manish Mandlik
2022-04-13 20:54 ` [BlueZ PATCH v2 7/9] adv_monitor: Add the monitor Release reason Manish Mandlik
2022-04-13 21:48   ` Luiz Augusto von Dentz
     [not found]     ` <CAGPPCLB1j+KV_ZCY7xQe9sHheWWAQPxaRF9pH9R53mAVdmQfHg@mail.gmail.com>
2022-04-13 22:42       ` Luiz Augusto von Dentz
     [not found]         ` <CAGPPCLBaoP=dXKp53F7Q3Pg4pnSELdkt_ns9Aw-A-yYk6Vs0yw@mail.gmail.com>
2022-04-20 20:02           ` Luiz Augusto von Dentz
2022-04-13 20:54 ` [BlueZ PATCH v2 8/9] client: Display the AdvMonitor " Manish Mandlik
2022-04-13 20:54 ` [BlueZ PATCH v2 9/9] test: " Manish Mandlik
2022-04-15  9:34 ` [BlueZ,v2,1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering bluez.test.bot

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.