Linux bluetooth development
 help / color / mirror / Atom feed
From: Roland Schober <rolandschober1968@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: luiz.dentz@gmail.com, Roland Schober <rolandschober1968@gmail.com>
Subject: [RFC PATCH v2 3/6] Bluetooth: hci_event: Stop PA when an advertising set times out
Date: Thu,  3 Dec 2026 23:14:02 +0100	[thread overview]
Message-ID: <20261203221405.682222-4-rolandschober1968@gmail.com> (raw)
In-Reply-To: <20261203221405.682222-1-rolandschober1968@gmail.com>

An advertising instance can have a timeout, which the controller is
given as the duration of the advertising set. When it ends, the
controller sends LE Advertising Set Terminated and the instance is
freed.

The controller only ends the advertising of the set, though: the set
stays, and periodic advertising on it goes on until the host disables
it. For an instance with periodic advertising this leaves a train
which nothing stops any more, and LE Set Periodic Advertising
Parameters is refused when the instance is added again.

Remove such an instance with hci_remove_advertising_sync() instead,
which disables periodic advertising and removes the advertising set
before it frees the instance.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Roland Schober <rolandschober1968@gmail.com>
---
 net/bluetooth/hci_event.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 749963d0ce77..8f4a9c261985 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -6674,6 +6674,13 @@ static struct adv_info *hci_le_ext_adv_owner(struct hci_dev *hdev, u8 handle)
 	return NULL;
 }
 
+static int hci_le_ext_adv_term_remove_sync(struct hci_dev *hdev, void *data)
+{
+	u8 instance = PTR_UINT(data);
+
+	return hci_remove_advertising_sync(hdev, NULL, instance, true);
+}
+
 static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data,
 				    struct sk_buff *skb)
 {
@@ -6705,10 +6712,22 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data,
 		if (!adv)
 			goto unlock;
 
-		/* Remove advertising as it has been terminated */
 		instance = adv->instance;
-		hci_free_adv_instance(hdev, adv);
-		mgmt_advertising_removed(NULL, hdev, instance);
+
+		/* The controller goes on with the periodic advertising of a
+		 * set whose advertising has ended. Stopping it and removing
+		 * the set takes commands, so the instance stays until they
+		 * are through.
+		 */
+		if (adv->periodic &&
+		    !hci_cmd_sync_queue(hdev, hci_le_ext_adv_term_remove_sync,
+					UINT_PTR(instance), NULL)) {
+			adv->enabled = false;
+		} else {
+			/* Remove advertising as it has been terminated */
+			hci_free_adv_instance(hdev, adv);
+			mgmt_advertising_removed(NULL, hdev, instance);
+		}
 
 		list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) {
 			if (adv->enabled)
-- 
2.47.3


  parent reply	other threads:[~2026-12-03 22:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 22:13 [RFC PATCH v2 0/6] Bluetooth: Periodic advertising and PAwR over MGMT Roland Schober
2026-12-03 22:14 ` [RFC PATCH v2 1/6] Bluetooth: hci: Add Periodic Advertising with Responses definitions Roland Schober
2026-12-04  2:11   ` Bluetooth: Periodic advertising and PAwR over MGMT bluez.test.bot
2026-12-03 22:14 ` [RFC PATCH v2 2/6] Bluetooth: hci_sync: Disable PA before removing an advertising set Roland Schober
2026-12-03 22:14 ` Roland Schober [this message]
2026-12-03 22:14 ` [RFC PATCH v2 4/6] Bluetooth: MGMT: Add Add Periodic Advertising Parameters command Roland Schober
2026-12-03 22:14 ` [RFC PATCH v2 5/6] Bluetooth: MGMT: Add Add Periodic Advertising Data command Roland Schober
2026-12-03 22:14 ` [RFC PATCH v2 6/6] Bluetooth: MGMT: Add PAwR subevent data and response reports Roland Schober

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=20261203221405.682222-4-rolandschober1968@gmail.com \
    --to=rolandschober1968@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    /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