From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v3 04/16] shared/rap: Subscribe to Ranging Data when a measurement starts
Date: Thu, 19 Nov 2026 12:16:12 -0500 [thread overview]
Message-ID: <20261119171625.1014004-5-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261119171625.1014004-1-luiz.dentz@gmail.com>
From: Cheng Jiang <cheng.jiang@oss.qualcomm.com>
Reading RAS Features subscribed to Real-time Ranging Data whenever
On-demand ranging was not configured. The subscription also arms the
5 s first segment timer, and at connection time there is normally no
CS procedure running yet, so the timer fires and writes 0x0000 back to
the CCCD. The connection-time subscription therefore only adds an
enable and a disable write that no application asked for, and a test
that expects the IUT to enable Real-time Ranging Data only when told
to (RAP/REQ/RRD/BV-01-C) sees both. It also subscribed to nothing when
the peer does not support Real-time Ranging Data, although the RREQ
has to enable On-demand Ranging Data then (RAP v1.0 4.4.2).
Subscribe at connection time only for the configured On-demand mode.
When StartMeasurement() is called and SetRangingDataMode() has not
subscribed to either mode, subscribe to the configured one, using
On-demand if the peer lacks Real-time Ranging Data.
Assisted-by: Claude:claude-opus-5-5
---
profiles/ranging/rap.c | 6 ++++++
src/shared/rap.c | 28 +++++++++++++++++++++++++---
src/shared/rap.h | 5 +++++
3 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/profiles/ranging/rap.c b/profiles/ranging/rap.c
index f1717d932eab..2d8b1a7a1364 100644
--- a/profiles/ranging/rap.c
+++ b/profiles/ranging/rap.c
@@ -843,6 +843,12 @@ bad_type:
if (settings.role == 0x02)
return dbus_message_new_method_return(msg);
+ /* Nothing is subscribed at connection time unless On-demand is
+ * configured, so subscribe now if SetRangingDataMode() was not called.
+ */
+ if (!bt_rap_ensure_ranging_data(data->rap))
+ DBG("Unable to subscribe to Ranging Data");
+
if (!bt_rap_start_measurement(data->hci_sm, data->conn_handle,
duration_secs))
return g_dbus_create_error(msg, DBUS_ERROR_FAILED,
diff --git a/src/shared/rap.c b/src/shared/rap.c
index 1c4b5239e1ba..bc6f133b5da9 100644
--- a/src/shared/rap.c
+++ b/src/shared/rap.c
@@ -4712,6 +4712,28 @@ bool bt_rap_set_ranging_data_mode(struct bt_rap *rap,
return rap_subscribe_ranging_data(rap, mode);
}
+bool bt_rap_ensure_ranging_data(struct bt_rap *rap)
+{
+ enum bt_rap_ranging_data_mode mode;
+
+ if (!rap || !rap->client)
+ return false;
+
+ if (rap->realtime_notify_id || rap->ondemand_notify_id)
+ return true;
+
+ /* The RREQ has to enable one of the two (RAP v1.0 4.4). Real-time
+ * Ranging Data is optional for the RRSP, so fall back to On-demand
+ * when it is not supported (RAP v1.0 4.4.2).
+ */
+ if (rap->ondemand_mode || !(rap->ras_features & 0x01))
+ mode = BT_RAP_RANGING_DATA_ONDEMAND;
+ else
+ mode = BT_RAP_RANGING_DATA_REALTIME;
+
+ return rap_subscribe_ranging_data(rap, mode);
+}
+
static void read_ras_features(struct bt_rap *rap, bool success,
uint8_t att_ecode,
const uint8_t *value, uint16_t length,
@@ -4771,9 +4793,9 @@ static void read_ras_features(struct bt_rap *rap, bool success,
return;
}
- if (!rap_subscribe_ranging_data(rap, rap->ondemand_mode ?
- BT_RAP_RANGING_DATA_ONDEMAND :
- BT_RAP_RANGING_DATA_REALTIME))
+ if (rap->ondemand_mode &&
+ !rap_subscribe_ranging_data(rap,
+ BT_RAP_RANGING_DATA_ONDEMAND))
DBG(rap, "Failed to subscribe to requested Ranging Data mode");
}
diff --git a/src/shared/rap.h b/src/shared/rap.h
index af4fab057e97..7ee51143c0ef 100644
--- a/src/shared/rap.h
+++ b/src/shared/rap.h
@@ -322,6 +322,11 @@ bool bt_rap_set_ranging_data_mode(struct bt_rap *rap,
enum bt_rap_ranging_data_mode mode,
enum bt_rap_ranging_transport transport);
+/* Subscribe to the configured Ranging Data mode unless one is already
+ * subscribed, falling back to On-demand if the peer lacks Real-time.
+ */
+bool bt_rap_ensure_ranging_data(struct bt_rap *rap);
+
/* Initiator role: stop receiving Real-time Ranging Data. The GATT client
* disables the characteristic CCCD when this is its final subscription.
*/
--
2.56.0
next prev parent reply other threads:[~2026-11-19 17:16 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 17:16 [PATCH BlueZ v3 00/16] Channel Sounding and RAP fixes Luiz Augusto von Dentz
2026-11-19 17:16 ` [PATCH BlueZ v3 01/16] gatt-database: Drop stale device state for removed bonds Luiz Augusto von Dentz
2026-11-19 17:16 ` [PATCH BlueZ v3 02/16] shared/rap: Reset the readable Ranging Counters per connection Luiz Augusto von Dentz
2026-11-19 17:16 ` [PATCH BlueZ v3 03/16] shared/rap: Subscribe on-demand data with the requested transport Luiz Augusto von Dentz
2026-11-19 17:16 ` Luiz Augusto von Dentz [this message]
2026-11-19 17:16 ` [PATCH BlueZ v3 05/16] client/cs: Fix use-after-free in stop_measurement_reply Luiz Augusto von Dentz
2026-11-19 17:16 ` [PATCH BlueZ v3 06/16] shared/hci: Look up the connection handle on the right link Luiz Augusto von Dentz
2026-11-19 17:16 ` [PATCH BlueZ v3 07/16] profiles/ranging: Let the Reflector run the CS setup phase Luiz Augusto von Dentz
2026-11-19 17:16 ` [PATCH BlueZ v3 08/16] profiles/ranging: Let StartMeasurement() pick the Initiator for Both Luiz Augusto von Dentz
2026-11-19 17:16 ` [PATCH BlueZ v3 09/16] profiles/ranging: Take the CS role from Config Complete Luiz Augusto von Dentz
2026-11-19 17:16 ` [PATCH BlueZ v3 10/16] profiles/ranging: Act on a CS configuration created by the peer Luiz Augusto von Dentz
2026-11-19 17:16 ` [PATCH BlueZ v3 11/16] profiles/ranging: Keep a peer-driven setup from being rewound Luiz Augusto von Dentz
2026-11-19 17:16 ` [PATCH BlueZ v3 12/16] profiles/ranging: Defer CS Security Enable until the link is encrypted Luiz Augusto von Dentz
2026-11-19 17:16 ` [PATCH BlueZ v3 13/16] profiles/ranging: Choose the CS antenna configuration from both ends Luiz Augusto von Dentz
2026-11-19 17:16 ` [PATCH BlueZ v3 14/16] profiles/ranging: Do not start a procedure after StopMeasurement() Luiz Augusto von Dentz
2026-11-19 17:16 ` [PATCH BlueZ v3 15/16] shared/rap: Start the Real-time timeout when the procedure starts Luiz Augusto von Dentz
2026-11-19 17:16 ` [PATCH BlueZ v3 16/16] unit/test-rap: Add tests for Ranging Data subscription and counters 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=20261119171625.1014004-5-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.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