From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v1 2/2] main.conf: Add GATT.Security option
Date: Wed, 1 Apr 2026 10:26:27 -0400 [thread overview]
Message-ID: <20260401142627.1944044-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20260401142627.1944044-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds GATT.Security option which by default is set to auto to
detect if encryption/authentication is required on demand, but if
Testing is set enables the user to enter a desirable security level.
In case the security level is low it then proceeds to disable checking
GATT attribute permissions for server operations.
---
src/btd.h | 1 +
src/device.c | 13 ++++++++++---
src/main.c | 35 +++++++++++++++++++++++++++++++++++
src/main.conf | 8 ++++++++
4 files changed, 54 insertions(+), 3 deletions(-)
diff --git a/src/btd.h b/src/btd.h
index 1b521706d05e..c84a600d109a 100644
--- a/src/btd.h
+++ b/src/btd.h
@@ -158,6 +158,7 @@ struct btd_opts {
uint8_t gatt_channels;
bool gatt_client;
enum bt_gatt_export_t gatt_export;
+ bool gatt_seclevel;
enum mps_mode_t mps;
struct btd_avdtp_opts avdtp;
diff --git a/src/device.c b/src/device.c
index 3ea683667bd8..c7f218808fb9 100644
--- a/src/device.c
+++ b/src/device.c
@@ -6296,7 +6296,7 @@ static void gatt_client_init(struct btd_device *device)
if (btd_opts.gatt_channels > 1)
features |= BT_GATT_CHRC_CLI_FEAT_EATT;
- if (device->bonding) {
+ if (!btd_opts.gatt_seclevel && device->bonding) {
DBG("Elevating security level since bonding is in progress");
bt_att_set_security(device->att, BT_ATT_SECURITY_MEDIUM);
}
@@ -6438,7 +6438,8 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io)
return false;
}
- if (sec_level == BT_IO_SEC_LOW && dev->le_state.paired) {
+ if (!btd_opts.gatt_seclevel && sec_level == BT_IO_SEC_LOW &&
+ dev->le_state.paired) {
DBG("Elevating security level since LTK is available");
sec_level = BT_IO_SEC_MEDIUM;
@@ -6478,6 +6479,10 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io)
bt_att_set_remote_key(dev->att, dev->remote_csrk->key,
remote_counter, dev);
+ /* Force security level if it has been set */
+ if (btd_opts.gatt_seclevel)
+ bt_att_set_security(dev->att, btd_opts.gatt_seclevel);
+
database = btd_adapter_get_database(dev->adapter);
dst = device_get_address(dev);
@@ -6593,7 +6598,9 @@ int device_connect_le(struct btd_device *dev)
/* Set as initiator */
dev->le_state.initiator = true;
- if (dev->le_state.paired)
+ if (btd_opts.gatt_seclevel)
+ sec_level = btd_opts.gatt_seclevel;
+ else if (dev->le_state.paired)
sec_level = BT_IO_SEC_MEDIUM;
else
sec_level = BT_IO_SEC_LOW;
diff --git a/src/main.c b/src/main.c
index 59df0ad4ca3a..818f7c06ef66 100644
--- a/src/main.c
+++ b/src/main.c
@@ -152,6 +152,7 @@ static const char *gatt_options[] = {
"Channels",
"Client",
"ExportClaimedServices",
+ "Security",
NULL
};
@@ -1112,6 +1113,38 @@ static void parse_gatt_export(GKeyFile *config)
g_free(str);
}
+static uint8_t parse_gatt_seclevel_str(const char *str)
+{
+ if (!strcmp(str, "auto"))
+ return BT_ATT_SECURITY_AUTO;
+ else if (!strcmp(str, "low") || !strcmp(str, "1"))
+ return BT_ATT_SECURITY_LOW;
+ else if (!strcmp(str, "medium") || !strcmp(str, "2"))
+ return BT_ATT_SECURITY_MEDIUM;
+ else if (!strcmp(str, "high") || !strcmp(str, "3"))
+ return BT_ATT_SECURITY_HIGH;
+ else if (!strcmp(str, "fips") || !strcmp(str, "4"))
+ return BT_ATT_SECURITY_FIPS;
+
+ DBG("Invalid value for Security=%s", str);
+ return BT_ATT_SECURITY_AUTO;
+}
+
+static void parse_gatt_seclevel(GKeyFile *config)
+{
+ char *str = NULL;
+
+ if (!btd_opts.testing)
+ return;
+
+ parse_config_string(config, "GATT", "Security", &str);
+ if (!str)
+ return;
+
+ btd_opts.gatt_seclevel = parse_gatt_seclevel_str(str);
+ g_free(str);
+}
+
static void parse_gatt(GKeyFile *config)
{
parse_gatt_cache(config);
@@ -1122,6 +1155,7 @@ static void parse_gatt(GKeyFile *config)
1, 6);
parse_config_bool(config, "GATT", "Client", &btd_opts.gatt_client);
parse_gatt_export(config);
+ parse_gatt_seclevel(config);
}
static void parse_csis_sirk(GKeyFile *config)
@@ -1269,6 +1303,7 @@ static void init_defaults(void)
btd_opts.gatt_channels = 1;
btd_opts.gatt_client = true;
btd_opts.gatt_export = BT_GATT_EXPORT_READ_ONLY;
+ btd_opts.gatt_seclevel = BT_ATT_SECURITY_AUTO;
btd_opts.avdtp.session_mode = BT_IO_MODE_BASIC;
btd_opts.avdtp.stream_mode = BT_IO_MODE_BASIC;
diff --git a/src/main.conf b/src/main.conf
index 724c4b44fc75..d31dd1b8f91d 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -291,6 +291,14 @@
# Default: read-only
#ExportClaimedServices = read-only
+# Security level:
+# Sets security level of ATT channel, setting security anything other than
+# auto requires Testing to be set, setting to low disables GATT server
+# attribite permissions.
+# Possible values: auto, [low=1, medium=2, high=3, fips=4 (Testing = true)]
+# Default = auto
+# Security = auto
+
[CSIS]
# SIRK - Set Identification Resolution Key which is common for all the
# sets. They SIRK key is used to identify its sets. This can be any
--
2.53.0
next prev parent reply other threads:[~2026-04-01 14:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-01 14:26 [PATCH BlueZ v1 1/2] shared/gatt-server: Add bt_gatt_server_set_permissions Luiz Augusto von Dentz
2026-04-01 14:26 ` Luiz Augusto von Dentz [this message]
2026-04-01 15:53 ` [BlueZ,v1,1/2] " bluez.test.bot
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=20260401142627.1944044-2-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