From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v6 5/5] client/btpclient: Suppress duplicate BTP security-level events
Date: Thu, 26 Nov 2026 09:52:11 +0100 [thread overview]
Message-ID: <20261126085211.80204-6-frederic.danis@collabora.com> (raw)
In-Reply-To: <20261126085211.80204-1-frederic.danis@collabora.com>
SecurityLevel and EncryptionType can change together for a single
security transition, and btp_gap_device_found_ev() can also replay an
already-reported level on an RSSI update, so the same BTP level could
be sent more than once for a single transition.
Track the last BTP security level reported per device and skip
resending an unchanged value. Reset the cached level on disconnect and
whenever GAP (re-)registers, so a reconnect or a new registration
still gets a fresh replay.
Assisted-by: Claude:claude-sonnet-5
---
v5->v6: New in v6.
client/btpclient/btpclient.h | 1 +
client/btpclient/gap.c | 13 +++++++++++++
2 files changed, 14 insertions(+)
diff --git a/client/btpclient/btpclient.h b/client/btpclient/btpclient.h
index 54f44ae9a..4de9775a2 100644
--- a/client/btpclient/btpclient.h
+++ b/client/btpclient/btpclient.h
@@ -30,6 +30,7 @@ struct btp_device {
struct l_dbus_proxy *proxy;
uint8_t address_type;
bdaddr_t address;
+ uint8_t sec_level;
struct l_queue *services;
struct l_queue *characteristics;
struct l_queue *descriptors;
diff --git a/client/btpclient/gap.c b/client/btpclient/gap.c
index 2731329ef..4f14d1064 100644
--- a/client/btpclient/gap.c
+++ b/client/btpclient/gap.c
@@ -1824,6 +1824,12 @@ static void reg_def_req_default_agent_reply(struct l_dbus_proxy *proxy,
entry = entry->next) {
struct btp_device *device = entry->data;
+ /* Force the cached security level to be resent on
+ * (re-)registration, even if it was already reported
+ * to a previous GAP registration.
+ */
+ device->sec_level = 0;
+
btp_gap_device_found_ev(device->proxy);
}
}
@@ -2447,6 +2453,11 @@ static void btp_security_level_changed_ev(struct l_dbus_proxy *proxy)
return;
}
+ if (device->sec_level == ev.sec_level)
+ return;
+
+ device->sec_level = ev.sec_level;
+
btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_SEC_LEVEL_CHANGED,
adapter->index, sizeof(ev), &ev);
}
@@ -2614,6 +2625,8 @@ static void btp_gap_device_connection_ev(struct l_dbus_proxy *proxy,
} else {
struct btp_gap_device_disconnected_ev ev;
+ device->sec_level = 0;
+
str2ba(str_addr, &ev.address);
ev.address_type = address_type;
--
2.43.0
prev parent reply other threads:[~2026-11-26 8:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 8:52 [PATCH BlueZ v6 0/5] client/btpclient: Security Level reporting Frédéric Danis
2026-11-26 8:52 ` [PATCH BlueZ v6 1/5] device: Provide Security Level props when kernel supports them Frédéric Danis
2026-11-26 15:13 ` client/btpclient: Security Level reporting bluez.test.bot
2026-11-26 8:52 ` [PATCH BlueZ v6 2/5] org.bluez.Device: Make Security Level props optional Frédéric Danis
2026-11-26 8:52 ` [PATCH BlueZ v6 3/5] client/btpclient: Add BTP_EV_GAP_SEC_LEVEL_CHANGED support Frédéric Danis
2026-11-26 8:52 ` [PATCH BlueZ v6 4/5] device: Reset Security Level and Encryption Type on disconnect Frédéric Danis
2026-11-26 8:52 ` Frédéric Danis [this message]
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=20261126085211.80204-6-frederic.danis@collabora.com \
--to=frederic.danis@collabora.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