Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ v6 0/5] client/btpclient: Security Level reporting
@ 2026-11-26  8:52 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
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Frédéric Danis @ 2026-11-26  8:52 UTC (permalink / raw)
  To: linux-bluetooth

Set org.bluez.Device SecurityLevel and EncryptionType properties to
optional so application can access them only when they are meaningful.

Send BTP_EV_GAP_SEC_LEVEL_CHANGED event from SecurityLevel property
changes once the device's services are resolved, matching the BTP levels
expected by auto-pts.
This reduces connection time for the BAP tests.

v1->v2: Retitled patch 1 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).
v2->v3: Patch 3 (BTP_EV_GAP_SEC_LEVEL_CHANGED support): only read and
  report SecurityLevel when ServicesResolved becomes true, so a stale
  cached level isn't reported as a security-level-changed event when an
  encrypted peer disconnects.
v3->v4: Patch 3 (BTP_EV_GAP_SEC_LEVEL_CHANGED support): 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 gap.c.
v4->v5: Patch 3 (BTP_EV_GAP_SEC_LEVEL_CHANGED support): also check
  EncryptionType before reporting BT_SECURITY_MEDIUM as encrypted, and
  refresh the 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.
v5->v6:
 - New patch 4: reset SecurityLevel and EncryptionType to 0, with
    a PropertiesChanged notification, once the last bearer disconnects,
    so a later unsecured reconnect doesn't report a stale value.
 - New patch 5: track the last BTP security level reported per device
    and skip resending an unchanged value.
    Reset the cached value on disconnect and on each GAP (re-)registration
    so a reconnect or a new registration still gets a fresh replay.

Frédéric Danis (5):
  device: Provide Security Level props when kernel supports them
  org.bluez.Device: Make Security Level props optional
  client/btpclient: Add BTP_EV_GAP_SEC_LEVEL_CHANGED support
  device: Reset Security Level and Encryption Type on disconnect
  client/btpclient: Suppress duplicate BTP security-level events

 client/btpclient/btpclient.h |  1 +
 client/btpclient/gap.c       | 88 +++++++++++++++++++++++++++++++++++-
 doc/org.bluez.Device.rst     |  8 ++--
 src/adapter.c                |  4 ++
 src/adapter.h                |  1 +
 src/device.c                 | 31 ++++++++++++-
 src/shared/btp.h             | 11 +++++
 7 files changed, 137 insertions(+), 7 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH BlueZ v5 1/3] device: Provide Security Level props when kernel supports them
@ 2026-11-25 16:00 Frédéric Danis
  2026-11-25 23:40 ` client/btpclient: Security Level reporting bluez.test.bot
  0 siblings, 1 reply; 15+ messages in thread
From: Frédéric Danis @ 2026-11-25 16:00 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] 15+ messages in thread
* [PATCH BlueZ v4 1/3] device: Provide Security Level props when kernel supports them
@ 2026-11-25  7:57 Frédéric Danis
  2026-11-25 14:48 ` client/btpclient: Security Level reporting bluez.test.bot
  0 siblings, 1 reply; 15+ messages in thread
From: Frédéric Danis @ 2026-11-25  7:57 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] 15+ messages in thread
* [PATCH BlueZ v3 1/3] device: Provide Security Level props when kernel supports them
@ 2026-11-24 12:17 Frédéric Danis
  2026-11-24 20:51 ` client/btpclient: Security Level reporting bluez.test.bot
  0 siblings, 1 reply; 15+ messages in thread
From: Frédéric Danis @ 2026-11-24 12:17 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.
---
 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 1439642cb..f78ea7301 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -11398,6 +11398,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 18e6eaa78..633614c86 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -292,6 +292,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] 15+ messages in thread
* [PATCH BlueZ v2 1/3] device: Provide Security Level props when kernel supports them
@ 2026-11-24 10:00 Frédéric Danis
  2026-11-24 11:30 ` client/btpclient: Security Level reporting bluez.test.bot
  0 siblings, 1 reply; 15+ messages in thread
From: Frédéric Danis @ 2026-11-24 10:00 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 1439642cb..f78ea7301 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -11398,6 +11398,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 18e6eaa78..633614c86 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -292,6 +292,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] 15+ messages in thread
* [PATCH BlueZ 1/3] device: Provide Security Level related props when supported by kernel
@ 2026-11-23 15:31 Frédéric Danis
  2026-11-24  1:39 ` client/btpclient: Security Level reporting bluez.test.bot
  0 siblings, 1 reply; 15+ messages in thread
From: Frédéric Danis @ 2026-11-23 15:31 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.
---
 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 1439642cb..f78ea7301 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -11398,6 +11398,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 18e6eaa78..633614c86 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -292,6 +292,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] 15+ messages in thread

end of thread, other threads:[~2026-11-26 15:14 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH BlueZ v6 5/5] client/btpclient: Suppress duplicate BTP security-level events Frédéric Danis
  -- strict thread matches above, loose matches on Subject: below --
2026-11-25 16:00 [PATCH BlueZ v5 1/3] device: Provide Security Level props when kernel supports them Frédéric Danis
2026-11-25 23:40 ` client/btpclient: Security Level reporting bluez.test.bot
2026-11-25  7:57 [PATCH BlueZ v4 1/3] device: Provide Security Level props when kernel supports them Frédéric Danis
2026-11-25 14:48 ` client/btpclient: Security Level reporting bluez.test.bot
2026-11-25 15:01   ` Luiz Augusto von Dentz
2026-11-24 12:17 [PATCH BlueZ v3 1/3] device: Provide Security Level props when kernel supports them Frédéric Danis
2026-11-24 20:51 ` client/btpclient: Security Level reporting bluez.test.bot
2026-11-24 10:00 [PATCH BlueZ v2 1/3] device: Provide Security Level props when kernel supports them Frédéric Danis
2026-11-24 11:30 ` client/btpclient: Security Level reporting bluez.test.bot
2026-11-24 15:37   ` Luiz Augusto von Dentz
2026-11-24 15:40     ` Frédéric Danis
2026-11-23 15:31 [PATCH BlueZ 1/3] device: Provide Security Level related props when supported by kernel Frédéric Danis
2026-11-24  1:39 ` client/btpclient: Security Level reporting bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox