Linux bluetooth development
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 10/16] profiles/ranging: Act on a CS configuration created by the peer
Date: Wed, 18 Nov 2026 14:58:38 -0500	[thread overview]
Message-ID: <20261118195846.393710-11-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261118195846.393710-1-luiz.dentz@gmail.com>

From: Cheng Jiang <cheng.jiang@oss.qualcomm.com>

LE CS Config Complete is also generated when the local Controller has
responded to a configuration request from the remote one (Core v6.2
Vol 4 Part E 7.7.65.42). The handler required CS_STATE_WAIT_CONFIG_CMPLT
before parsing the event, which is only reached between the Set Default
Settings response and Config Complete of a StartMeasurement(). A remote
Initiator does not wait for that: it can create the configuration as
soon as the link is up, before the local setup phase has run, or again
after an earlier procedure. The event was then dropped along with the
role it carries, Security Enable Complete and Procedure Enable Complete
failed their own state checks, and no ranging data was produced.

Parse Config Complete in any state. Every state machine on the adapter
receives the CS events of all links, which the state check used to
hide, so ignore Config Complete and Security Enable Complete events
whose handle is not mapped to this state machine, so that they cannot
overwrite this link's role or advance its state.

A successful removal (action 0x00) leaves the remaining parameters
undefined, yet it went on to the role check and, if the undefined role
happened to be permitted, to Security Enable. Ignore it whatever the
state.

Assisted-by: Claude:claude-opus-5-5
---
 profiles/ranging/rap_hci.c | 42 +++++++++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/profiles/ranging/rap_hci.c b/profiles/ranging/rap_hci.c
index ef01e60c559a..39b167ba80d1 100644
--- a/profiles/ranging/rap_hci.c
+++ b/profiles/ranging/rap_hci.c
@@ -882,13 +882,6 @@ static void rap_cs_config_cmplt_evt(const void *data, uint8_t size,
 
 	DBG("size=0x%02X", size);
 
-	/* State Check */
-	if (cs_get_current_state(sm) != CS_STATE_WAIT_CONFIG_CMPLT) {
-		DBG("Event received in Wrong State!! ");
-		DBG("Expected : CS_STATE_WAIT_CONFIG_CMPLT");
-		return;
-	}
-
 	/* Pull the entire structure at once */
 	evt = util_iov_pull_mem(&iov, sizeof(*evt));
 	if (!evt) {
@@ -898,6 +891,35 @@ static void rap_cs_config_cmplt_evt(const void *data, uint8_t size,
 
 	DBG("status=0x%02X, handle=0x%04X", evt->status, evt->handle);
 
+	/* Every state machine on this adapter sees every CS event, so ignore
+	 * the ones for other links: acting on them would overwrite this
+	 * link's negotiated role and advance its state.
+	 */
+	if (!find_mapping_by_handle(sm, evt->handle)) {
+		DBG("Not for this link, ignoring");
+		return;
+	}
+
+	/* Action 0x00 reports that the configuration was removed, and leaves
+	 * the remaining parameters undefined (Core v6.2 Vol 4 Part E
+	 * 7.7.65.42), so there is no role or configuration to act on.
+	 */
+	if (evt->status == 0 && evt->action == 0x00) {
+		DBG("Config %u removed", evt->config_id);
+		return;
+	}
+
+	/* This event is also generated when the local Controller responded to a
+	 * configuration request from the remote one, which is how a Reflector
+	 * learns a procedure is being set up for it. The peer can do that
+	 * before the setup phase has run here, or after an earlier procedure,
+	 * so do not require WAIT_CONFIG_CMPLT, which only the local setup
+	 * phase reaches.
+	 */
+	if (cs_get_current_state(sm) != CS_STATE_WAIT_CONFIG_CMPLT)
+		DBG("Config created by the peer while in %s",
+			state_names[cs_get_current_state(sm)]);
+
 	/* Both sides asked for a configuration at the same time. The Central
 	 * rejects the Peripheral's request with LL Procedure Collision (0x23)
 	 * and completes its own, which the Peripheral handles instead (Core
@@ -1044,6 +1066,12 @@ static void rap_cs_sec_enable_cmplt_evt(const void *data, uint8_t size,
 	DBG("status=0x%02X, handle=0x%04X",
 		rap_ev.status, handle);
 
+	/* Shared HCI channel: drop events belonging to another link. */
+	if (!find_mapping_by_handle(sm, handle)) {
+		DBG("Not for this link, ignoring");
+		return;
+	}
+
 	if (rap_ev.status == 0) {
 		/* Success - proceed to configuration */
 		cs_set_state(sm, CS_STATE_WAIT_PROC_CMPLT);
-- 
2.56.0


  parent reply	other threads:[~2026-11-18 19:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 19:58 [PATCH BlueZ v2 00/16] Channel Sounding and RAP fixes Luiz Augusto von Dentz
2026-11-18 19:58 ` [PATCH BlueZ v2 01/16] gatt-database: Drop stale device state for removed bonds Luiz Augusto von Dentz
2026-11-19  1:57   ` Channel Sounding and RAP fixes bluez.test.bot
2026-11-18 19:58 ` [PATCH BlueZ v2 02/16] shared/rap: Reset the readable Ranging Counters per connection Luiz Augusto von Dentz
2026-11-18 19:58 ` [PATCH BlueZ v2 03/16] shared/rap: Subscribe on-demand data with the requested transport Luiz Augusto von Dentz
2026-11-18 19:58 ` [PATCH BlueZ v2 04/16] shared/rap: Subscribe to Ranging Data when a measurement starts Luiz Augusto von Dentz
2026-11-18 19:58 ` [PATCH BlueZ v2 05/16] client/cs: Fix use-after-free in stop_measurement_reply Luiz Augusto von Dentz
2026-11-18 19:58 ` [PATCH BlueZ v2 06/16] shared/hci: Look up the connection handle on the right link Luiz Augusto von Dentz
2026-11-18 19:58 ` [PATCH BlueZ v2 07/16] profiles/ranging: Let the Reflector run the CS setup phase Luiz Augusto von Dentz
2026-11-18 19:58 ` [PATCH BlueZ v2 08/16] profiles/ranging: Let StartMeasurement() pick the Initiator for Both Luiz Augusto von Dentz
2026-11-18 19:58 ` [PATCH BlueZ v2 09/16] profiles/ranging: Take the CS role from Config Complete Luiz Augusto von Dentz
2026-11-18 19:58 ` Luiz Augusto von Dentz [this message]
2026-11-18 19:58 ` [PATCH BlueZ v2 11/16] profiles/ranging: Keep a peer-driven setup from being rewound Luiz Augusto von Dentz
2026-11-18 19:58 ` [PATCH BlueZ v2 12/16] profiles/ranging: Defer CS Security Enable until the link is encrypted Luiz Augusto von Dentz
2026-11-18 19:58 ` [PATCH BlueZ v2 13/16] profiles/ranging: Choose the CS antenna configuration from both ends Luiz Augusto von Dentz
2026-11-18 19:58 ` [PATCH BlueZ v2 14/16] profiles/ranging: Do not start a procedure after StopMeasurement() Luiz Augusto von Dentz
2026-11-18 19:58 ` [PATCH BlueZ v2 15/16] shared/rap: Start the Real-time timeout when the procedure starts Luiz Augusto von Dentz
2026-11-18 19:58 ` [PATCH BlueZ v2 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=20261118195846.393710-11-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