* [PATCH BlueZ v3 0/2] Fix mgmt endianness on big-endian hosts
@ 2026-12-02 15:17 Nicolas Thibert
2026-12-02 15:17 ` [PATCH BlueZ v3 1/2] adapter: Fix key_count endianness in MGMT_OP_SET_BLOCKED_KEYS Nicolas Thibert
2026-12-02 15:17 ` [PATCH BlueZ v3 2/2] advertising: Fix duration and interval endianness Nicolas Thibert
0 siblings, 2 replies; 3+ messages in thread
From: Nicolas Thibert @ 2026-12-02 15:17 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Luiz Augusto von Dentz
Several mgmt command fields are written in host byte order instead of
little-endian, which breaks them on big-endian hosts (tested on MIPS
big-endian, OpenWrt/ath79).
v3:
- Split the set_blocked_keys() fix into its own patch, as it is for a
different command (requested by Luiz).
- No code change since v2.
v2:
- Use cpu_to_le16()/cpu_to_le32() instead of htobs()/htobl(), as
requested by Luiz.
Nicolas Thibert (2):
adapter: Fix key_count endianness in MGMT_OP_SET_BLOCKED_KEYS
advertising: Fix duration and interval endianness
src/adapter.c | 5 +++--
src/advertising.c | 8 ++++----
2 files changed, 7 insertions(+), 6 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH BlueZ v3 1/2] adapter: Fix key_count endianness in MGMT_OP_SET_BLOCKED_KEYS
2026-12-02 15:17 [PATCH BlueZ v3 0/2] Fix mgmt endianness on big-endian hosts Nicolas Thibert
@ 2026-12-02 15:17 ` Nicolas Thibert
2026-12-02 15:17 ` [PATCH BlueZ v3 2/2] advertising: Fix duration and interval endianness Nicolas Thibert
1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Thibert @ 2026-12-02 15:17 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Luiz Augusto von Dentz
set_blocked_keys() writes the native-endian key count directly into
the __le16 key_count field of struct mgmt_cp_set_blocked_keys, without
cpu_to_le16(). This is a no-op on little-endian hosts, which is why it
has gone unnoticed, but corrupts the value on big-endian hosts.
Confirmed live on MIPS big-endian (OpenWrt/ath79): key_count=2 is read
by the kernel as 512 (0x0200), and the command fails with "expected
8706 bytes, got 36 bytes" in dmesg and "Failed to set blocked keys:
Invalid Parameters" in the bluetoothd logs. With the fix, the command
succeeds.
---
src/adapter.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 1ec1c70..7bdabf9 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -10553,10 +10553,11 @@ static bool set_blocked_keys(struct btd_adapter *adapter)
sizeof(blocked_keys)] = { 0 };
struct mgmt_cp_set_blocked_keys *cp =
(struct mgmt_cp_set_blocked_keys *)buffer;
+ const uint16_t key_count = ARRAY_SIZE(blocked_keys);
int i;
- cp->key_count = ARRAY_SIZE(blocked_keys);
- for (i = 0; i < cp->key_count; ++i) {
+ cp->key_count = cpu_to_le16(key_count);
+ for (i = 0; i < key_count; ++i) {
cp->keys[i].type = blocked_keys[i].type;
memcpy(cp->keys[i].val, blocked_keys[i].val,
sizeof(cp->keys[i].val));
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH BlueZ v3 2/2] advertising: Fix duration and interval endianness
2026-12-02 15:17 [PATCH BlueZ v3 0/2] Fix mgmt endianness on big-endian hosts Nicolas Thibert
2026-12-02 15:17 ` [PATCH BlueZ v3 1/2] adapter: Fix key_count endianness in MGMT_OP_SET_BLOCKED_KEYS Nicolas Thibert
@ 2026-12-02 15:17 ` Nicolas Thibert
1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Thibert @ 2026-12-02 15:17 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Luiz Augusto von Dentz
refresh_legacy_adv() and refresh_extended_adv() write the native-endian
duration and min/max intervals directly into the __le16/__le32 fields
of the MGMT_OP_ADD_ADVERTISING and MGMT_OP_ADD_EXT_ADV_PARAMS
commands, without cpu_to_le16()/cpu_to_le32(). This is a no-op on
little-endian hosts, but corrupts the values on big-endian hosts.
It is inert with the default values (0 stays 0), but A/B tested live on
MIPS big-endian (OpenWrt/ath79) with bluetoothctl's advertise submenu
and an explicit "interval 100 100": without the fix, the device stops
being discoverable by a BLE scanner as soon as a non-default interval
is requested; with the fix, it is discoverable again.
---
src/advertising.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/advertising.c b/src/advertising.c
index d07068c..ecb730c 100644
--- a/src/advertising.c
+++ b/src/advertising.c
@@ -1060,7 +1060,7 @@ static int refresh_legacy_adv(struct btd_adv_client *client,
cp->flags = htobl(flags);
cp->instance = client->instance;
- cp->duration = client->duration;
+ cp->duration = cpu_to_le16(client->duration);
cp->adv_data_len = adv_data_len;
cp->scan_rsp_len = scan_rsp_len;
memcpy(cp->data, adv_data, adv_data_len);
@@ -1111,13 +1111,13 @@ static int refresh_extended_adv(struct btd_adv_client *client,
*/
if (client->duration) {
- cp.duration = client->duration;
+ cp.duration = cpu_to_le16(client->duration);
flags |= MGMT_ADV_PARAM_DURATION;
}
if (client->min_interval && client->max_interval) {
- cp.min_interval = client->min_interval;
- cp.max_interval = client->max_interval;
+ cp.min_interval = cpu_to_le32(client->min_interval);
+ cp.max_interval = cpu_to_le32(client->max_interval);
flags |= MGMT_ADV_PARAM_INTERVALS;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-02 15:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 15:17 [PATCH BlueZ v3 0/2] Fix mgmt endianness on big-endian hosts Nicolas Thibert
2026-12-02 15:17 ` [PATCH BlueZ v3 1/2] adapter: Fix key_count endianness in MGMT_OP_SET_BLOCKED_KEYS Nicolas Thibert
2026-12-02 15:17 ` [PATCH BlueZ v3 2/2] advertising: Fix duration and interval endianness Nicolas Thibert
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.