* [PATCH BlueZ v6 1/5] device: Provide Security Level props when kernel supports them
2026-11-26 8:52 [PATCH BlueZ v6 0/5] client/btpclient: Security Level reporting Frédéric Danis
@ 2026-11-26 8:52 ` 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
` (3 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Frédéric Danis @ 2026-11-26 8:52 UTC (permalink / raw)
To: linux-bluetooth
The SecurityLevel and EncryptionType properties should be available in
org.bluez.Device only when kernel supports MGMT_EV_SECURITY_LEVEL_CHANGED
events.
This allows applications to check those properties when they are
meaningful.
---
v1->v2: Retitled from "device: Provide Security Level related props when
supported by kernel" (subject line was exceeding the mailing list's
80-character limit with the series prefix).
src/adapter.c | 4 ++++
src/adapter.h | 1 +
src/device.c | 13 +++++++++++--
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 112312651..12d7e8246 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -11409,6 +11409,10 @@ static void read_commands_complete(uint8_t status, uint16_t length,
DBG("kernel supports suspend/resume events");
kernel_features |= KERNEL_HAS_RESUME_EVT;
break;
+ case MGMT_EV_SECURITY_LEVEL_CHANGED:
+ DBG("kernel supports security level events");
+ kernel_features |= KERNEL_HAS_SECURITY_LEVEL_EVT;
+ break;
}
}
}
diff --git a/src/adapter.h b/src/adapter.h
index 63016c8e1..74e866108 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -294,6 +294,7 @@ enum kernel_features {
KERNEL_HAS_RESUME_EVT = 1 << 4,
KERNEL_HAS_EXT_ADV_ADD_CMDS = 1 << 5,
KERNEL_HAS_CONTROLLER_CAP_CMD = 1 << 6,
+ KERNEL_HAS_SECURITY_LEVEL_EVT = 1 << 7,
};
bool btd_has_kernel_features(uint32_t feature);
diff --git a/src/device.c b/src/device.c
index 36a980d1e..a21819419 100644
--- a/src/device.c
+++ b/src/device.c
@@ -3785,6 +3785,13 @@ static gboolean dev_get_encryption_type(const GDBusPropertyTable *property,
return TRUE;
}
+static gboolean
+dev_security_level_exists(const GDBusPropertyTable *property,
+ void *data)
+{
+ return btd_has_kernel_features(KERNEL_HAS_SECURITY_LEVEL_EVT);
+}
+
static const GDBusPropertyTable device_properties[] = {
{ "Address", "s", dev_property_get_address },
{ "AddressType", "s", property_get_address_type },
@@ -3830,9 +3837,11 @@ static const GDBusPropertyTable device_properties[] = {
dev_property_set_prefer_bearer,
dev_property_prefer_bearer_exists,
G_DBUS_PROPERTY_FLAG_EXPERIMENTAL },
- { "SecurityLevel", "y", dev_get_security_level, NULL, NULL,
+ { "SecurityLevel", "y", dev_get_security_level, NULL,
+ dev_security_level_exists,
G_DBUS_PROPERTY_FLAG_EXPERIMENTAL },
- { "EncryptionType", "y", dev_get_encryption_type, NULL, NULL,
+ { "EncryptionType", "y", dev_get_encryption_type, NULL,
+ dev_security_level_exists,
G_DBUS_PROPERTY_FLAG_EXPERIMENTAL },
{ }
};
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH BlueZ v6 2/5] org.bluez.Device: Make Security Level props optional
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 8:52 ` 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
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Frédéric Danis @ 2026-11-26 8:52 UTC (permalink / raw)
To: linux-bluetooth
The SecurityLevel and EncryptionType properties are available only
when kernel supports MGMT_EV_SECURITY_LEVEL_CHANGED events.
---
doc/org.bluez.Device.rst | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/doc/org.bluez.Device.rst b/doc/org.bluez.Device.rst
index f3e4bfa4a..6a433024e 100644
--- a/doc/org.bluez.Device.rst
+++ b/doc/org.bluez.Device.rst
@@ -490,8 +490,8 @@ Examples:
:bluetoothctl: > bearer <dev> [last-seen/bredr/le]
-byte SecurityLevel [readonly, experimental]
-```````````````````````````````````````````
+byte SecurityLevel [readonly, optional, experimental]
+`````````````````````````````````````````````````````
Indicate the Security Level of a connection.
Possible values:
@@ -511,8 +511,8 @@ Possible values:
:4:
FIPS authenticated pairing with encryption
-byte EncryptionType [readonly, experimental]
-````````````````````````````````````````````
+byte EncryptionType [readonly, optional, experimental]
+``````````````````````````````````````````````````````
Indicate the Encryption type in use for a connection.
Possible values:
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH BlueZ v6 3/5] client/btpclient: Add BTP_EV_GAP_SEC_LEVEL_CHANGED support
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 8:52 ` [PATCH BlueZ v6 2/5] org.bluez.Device: Make Security Level props optional Frédéric Danis
@ 2026-11-26 8:52 ` 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 ` [PATCH BlueZ v6 5/5] client/btpclient: Suppress duplicate BTP security-level events Frédéric Danis
4 siblings, 0 replies; 7+ messages in thread
From: Frédéric Danis @ 2026-11-26 8:52 UTC (permalink / raw)
To: linux-bluetooth
When supported, send BTP_EV_GAP_SEC_LEVEL_CHANGED from org.bluez.Device1
SecurityLevel property changes, mapped to the matching BTP level, and
skip levels with no BTP equivalent (no security/encryption yet).
Postponed this BTP event after device services has been retrieved to be
in sync with auto-pts expectation.
SecurityLevel's BT_SECURITY_MEDIUM only indicates encryption is
desired, not that it is active: also check EncryptionType before
reporting this level as encrypted, and refresh the BTP event on
EncryptionType changes too.
Replay the cached security level when GAP registers, or a device
proxy is added, for a device that is already connected and resolved,
so its security state isn't missed.
This reduces connection time for the BAP tests.
---
v2->v3: Only read and report SecurityLevel when ServicesResolved becomes
true: device_remove_connection() clears ServicesResolved without
clearing the cached sec_level, so the ServicesResolved handler was
emitting a stale security-level-changed event when an encrypted peer
disconnected.
v3->v4: Fetch the device's Address/AddressType D-Bus properties instead
of reading the btp_device struct fields directly, consistent with the
other event builders in this file (btp_gap_device_connection_ev(),
btp_identity_resolved_ev()).
v4->v5: BT_SECURITY_MEDIUM only means encryption is desired, not that
it is active: now also check EncryptionType before reporting this
level, and refresh the event on EncryptionType changes too. Replay
the cached security level in btp_gap_device_found_ev() for devices
that are already connected and resolved when GAP registers or the
proxy is added, so their security state isn't missed. Moved
btp_security_level_changed_ev() before its only caller,
btp_gap_device_found_ev(), to drop its forward declaration.
client/btpclient/gap.c | 75 +++++++++++++++++++++++++++++++++++++++++-
src/shared/btp.h | 11 +++++++
2 files changed, 85 insertions(+), 1 deletion(-)
diff --git a/client/btpclient/gap.c b/client/btpclient/gap.c
index 33a6c1693..2731329ef 100644
--- a/client/btpclient/gap.c
+++ b/client/btpclient/gap.c
@@ -2399,6 +2399,58 @@ failed:
btp_send_error(btp, BTP_GAP_SERVICE, index, status);
}
+static void btp_security_level_changed_ev(struct l_dbus_proxy *proxy)
+{
+ struct btp_device *device = find_device_by_proxy(proxy);
+ struct btp_adapter *adapter = find_adapter_by_device(device);
+ const char *str_addr, *str_addr_type;
+ uint8_t level, enc_type;
+ struct btp_gap_sec_level_changed_ev ev;
+
+ if (!device || !adapter)
+ return;
+
+ if (!l_dbus_proxy_get_property(proxy, "SecurityLevel", "y", &level))
+ return;
+
+ if (!l_dbus_proxy_get_property(proxy, "Address", "s", &str_addr))
+ return;
+
+ if (!l_dbus_proxy_get_property(proxy, "AddressType", "s",
+ &str_addr_type))
+ return;
+
+ str2ba(str_addr, &ev.address);
+ ev.address_type = strcmp(str_addr_type, "public") ?
+ BTP_GAP_ADDR_RANDOM : BTP_GAP_ADDR_PUBLIC;
+ switch (level) {
+ case BT_SECURITY_MEDIUM:
+ /* This level only means encryption is desired, not that it
+ * is active yet: only report it once EncryptionType confirms
+ * encryption is actually in use.
+ */
+ if (!l_dbus_proxy_get_property(proxy, "EncryptionType", "y",
+ &enc_type) ||
+ !enc_type)
+ return;
+
+ ev.sec_level = BTP_GAP_SEC_LEVEL_UNAUTH_ENC;
+ break;
+ case BT_SECURITY_HIGH:
+ ev.sec_level = BTP_GAP_SEC_LEVEL_AUTH_ENC;
+ break;
+ case BT_SECURITY_FIPS:
+ ev.sec_level = BTP_GAP_SEC_LEVEL_AUTH_SC;
+ break;
+ default:
+ /* No security/encryption yet, no BTP level to report. */
+ return;
+ }
+
+ btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_SEC_LEVEL_CHANGED,
+ adapter->index, sizeof(ev), &ev);
+}
+
static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
{
struct btp_device *device = find_device_by_proxy(proxy);
@@ -2518,6 +2570,12 @@ static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_DEVICE_CONNECTED,
adapter->index, sizeof(ev_conn), &ev_conn);
+
+ /* Replay the cached security level for devices that were
+ * already connected and secured before GAP registered or
+ * this proxy was added.
+ */
+ btp_security_level_changed_ev(proxy);
}
}
@@ -2736,6 +2794,19 @@ void gap_property_changed(struct l_dbus_proxy *proxy, const char *name,
*/
if (!prop)
btp_gap_device_connection_ev(proxy, prop);
+ } else if (!strcmp(name, "SecurityLevel") ||
+ !strcmp(name, "EncryptionType")) {
+ bool resolved;
+
+ /* Postpone security level changed event after services
+ * has been resolved.
+ */
+ if (l_dbus_proxy_get_property(proxy,
+ "ServicesResolved", "b", &resolved) &&
+ !resolved)
+ return;
+
+ btp_security_level_changed_ev(proxy);
} else if (!strcmp(name, "AddressType")) {
/* Address property change came first along with address
* type.
@@ -2747,8 +2818,10 @@ void gap_property_changed(struct l_dbus_proxy *proxy, const char *name,
if (!l_dbus_message_get_arguments(msg, "b", &prop))
return;
- if (prop)
+ if (prop) {
btp_gap_device_connection_ev(proxy, prop);
+ btp_security_level_changed_ev(proxy);
+ }
}
}
}
diff --git a/src/shared/btp.h b/src/shared/btp.h
index ee5d7bd21..8cae0e765 100644
--- a/src/shared/btp.h
+++ b/src/shared/btp.h
@@ -296,6 +296,17 @@ struct btp_gap_identity_resolved_ev {
bdaddr_t identity_address;
} __packed;
+#define BTP_GAP_SEC_LEVEL_UNAUTH_ENC 0x01
+#define BTP_GAP_SEC_LEVEL_AUTH_ENC 0x02
+#define BTP_GAP_SEC_LEVEL_AUTH_SC 0x03
+
+#define BTP_EV_GAP_SEC_LEVEL_CHANGED 0x89
+struct btp_gap_sec_level_changed_ev {
+ uint8_t address_type;
+ bdaddr_t address;
+ uint8_t sec_level;
+} __packed;
+
struct btp_gatt_service {
uint16_t start_handle;
uint16_t end_handle;
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH BlueZ v6 4/5] device: Reset Security Level and Encryption Type on disconnect
2026-11-26 8:52 [PATCH BlueZ v6 0/5] client/btpclient: Security Level reporting Frédéric Danis
` (2 preceding siblings ...)
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 ` Frédéric Danis
2026-11-26 8:52 ` [PATCH BlueZ v6 5/5] client/btpclient: Suppress duplicate BTP security-level events Frédéric Danis
4 siblings, 0 replies; 7+ messages in thread
From: Frédéric Danis @ 2026-11-26 8:52 UTC (permalink / raw)
To: linux-bluetooth
SecurityLevel and EncryptionType are retained across disconnects, so
replaying them for a later unsecured reconnect could report the
previous connection's security state. Reset both to zero, with a
PropertiesChanged notification, once the last bearer disconnects.
Assisted-by: Claude:claude-sonnet-5
---
v5->v6: New in v6.
src/device.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/src/device.c b/src/device.c
index a21819419..b7235f56b 100644
--- a/src/device.c
+++ b/src/device.c
@@ -4141,6 +4141,24 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type,
if (device->bredr_state.connected || device->le_state.connected)
return;
+ /* Security level and encryption type are only meaningful for the
+ * current connection: reset them once both bearers are disconnected
+ * so a later reconnect doesn't report a stale value.
+ */
+ if (device->sec_level) {
+ device->sec_level = 0;
+ g_dbus_emit_property_changed(dbus_conn, device->path,
+ DEVICE_INTERFACE,
+ "SecurityLevel");
+ }
+
+ if (device->enc_type) {
+ device->enc_type = 0;
+ g_dbus_emit_property_changed(dbus_conn, device->path,
+ DEVICE_INTERFACE,
+ "EncryptionType");
+ }
+
device_update_last_seen(device, bdaddr_type, true);
g_slist_free_full(device->eir_uuids, g_free);
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH BlueZ v6 5/5] client/btpclient: Suppress duplicate BTP security-level events
2026-11-26 8:52 [PATCH BlueZ v6 0/5] client/btpclient: Security Level reporting Frédéric Danis
` (3 preceding siblings ...)
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
4 siblings, 0 replies; 7+ messages in thread
From: Frédéric Danis @ 2026-11-26 8:52 UTC (permalink / raw)
To: linux-bluetooth
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
^ permalink raw reply related [flat|nested] 7+ messages in thread