Linux bluetooth development
 help / color / mirror / Atom feed
From: Simon Mikuda <simon.mikuda@streamunlimited.com>
To: linux-bluetooth@vger.kernel.org
Cc: Simon Mikuda <simon.mikuda@streamunlimited.com>
Subject: [PATCH BlueZ] adapter: Fix discovery filter RSSI and Pathloss matching
Date: Sun, 22 Nov 2026 11:41:39 +0100	[thread overview]
Message-ID: <20261122104139.714101-1-simon.mikuda@streamunlimited.com> (raw)

is_filter_match() takes a device as close enough if the RSSI threshold
is unset or met, or if the Pathloss threshold is unset or met. Since a
filter cannot set both, the one left unset lets every device through.
The Pathloss threshold, which the kernel cannot apply, is then never
applied at all, and an RSSI threshold only as far as the kernel filter
goes, which holds the lowest threshold of all clients.

To reproduce, discover a device with an RSSI of -60 dBm and a TX power
of 0 dBm, so a path loss of 60 dB, with a Pathloss filter of 59:

  [bluetooth]# scan.transport bredr
  [bluetooth]# scan.pathloss 59
  [bluetooth]# scan on

The device is reported anyway:

  parse_discovery_filter_dict() filtered discovery params:
      transport: 1 rssi: 32767 pathloss: 59 ...
  device_found_callback() hci0 addr 00:AA:01:01:00:42, rssi -60 ...
  device_set_rssi_with_delta() rssi -60
  device_set_tx_power() tx_power 0

Require each threshold that is set to be met.

Fixes: ebcb6aa7c527 ("core/adapter: Filter discovery results")
Assisted-by: Claude:claude-opus-5-5
---
 src/adapter.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 1439642cb..2f2832a8f 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -7610,11 +7610,11 @@ static bool is_filter_match(GSList *discovery_filter, struct eir_data *eir_data,
 
 		if (got_match) {
 			/* we have service match, check proximity */
-			if (item->rssi == DISTANCE_VAL_INVALID ||
-			    item->rssi <= rssi ||
-			    item->pathloss == DISTANCE_VAL_INVALID ||
-			    (eir_data->tx_power != 127 &&
-			     eir_data->tx_power - rssi <= item->pathloss))
+			if ((item->rssi == DISTANCE_VAL_INVALID ||
+			     item->rssi <= rssi) &&
+			    (item->pathloss == DISTANCE_VAL_INVALID ||
+			     (eir_data->tx_power != 127 &&
+			      eir_data->tx_power - rssi <= item->pathloss)))
 				return true;
 
 			got_match = false;

base-commit: 1adfe662efeff12997df9ddd0960dbd0de9c8ea7
-- 
2.43.0


             reply	other threads:[~2026-11-22 10:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 10:41 Simon Mikuda [this message]
2026-11-22 18:27 ` [BlueZ] adapter: Fix discovery filter RSSI and Pathloss matching bluez.test.bot

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=20261122104139.714101-1-simon.mikuda@streamunlimited.com \
    --to=simon.mikuda@streamunlimited.com \
    --cc=linux-bluetooth@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox