All of lore.kernel.org
 help / color / mirror / Atom feed
From: Manish Mandlik <mmandlik@google.com>
To: marcel@holtmann.org, luiz.dentz@gmail.com
Cc: chromeos-bluetooth-upstreaming@chromium.org,
	linux-bluetooth@vger.kernel.org,
	Manish Mandlik <mmandlik@google.com>,
	Miao-chen Chou <mcchou@chromium.org>
Subject: [BlueZ PATCH 6/9] adv_monitor: Do not merge monitors with non-overlapping RSSI
Date: Sun, 20 Mar 2022 18:37:00 -0700	[thread overview]
Message-ID: <20220320183445.BlueZ.6.Idb90bd382a52c8c0bc6fb5d936a9d5e5afac1fb5@changeid> (raw)
In-Reply-To: <20220320183445.BlueZ.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid>

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

 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 77b8ea10d..85231557e 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.35.1.894.gb6a874cedc-goog


  parent reply	other threads:[~2022-03-21  1:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-21  1:36 [BlueZ PATCH 1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering Manish Mandlik
2022-03-21  1:36 ` [BlueZ PATCH 2/9] adv_monitor: Don't send DeviceFound for already found devices Manish Mandlik
2022-03-21  1:36 ` [BlueZ PATCH 3/9] adv_monitor: Clear tracked devices on resume Manish Mandlik
2022-03-21  1:36 ` [BlueZ PATCH 4/9] adv_monitor: Do not remove the device while monitoring Manish Mandlik
2022-03-21  1:36 ` [BlueZ PATCH 5/9] monitor: Display AdvMonitor DeviceFound/Lost events Manish Mandlik
2022-03-21  4:31   ` Paul Menzel
2022-03-21  1:37 ` Manish Mandlik [this message]
2022-03-21  1:37 ` [BlueZ PATCH 7/9] adv_monitor: Add the monitor Release reason Manish Mandlik
2022-03-22  0:48   ` Luiz Augusto von Dentz
     [not found]     ` <CAGPPCLDeQB6vQAHYw22sV8b6UsOjhpz5SJKnZ+MMq-DHFAbXZQ@mail.gmail.com>
2022-04-13 21:37       ` Luiz Augusto von Dentz
2022-03-21  1:37 ` [BlueZ PATCH 8/9] client: Display the AdvMonitor " Manish Mandlik
2022-03-21  1:37 ` [BlueZ PATCH 9/9] test: " Manish Mandlik
2022-03-21  4:02 ` [BlueZ,1/9] adv_monitor: Disable RSSIHighTimeout for SW based filtering bluez.test.bot
2022-03-29 20:19   ` Luiz Augusto von Dentz

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20220320183445.BlueZ.6.Idb90bd382a52c8c0bc6fb5d936a9d5e5afac1fb5@changeid \
    --to=mmandlik@google.com \
    --cc=chromeos-bluetooth-upstreaming@chromium.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=mcchou@chromium.org \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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.