Skip to content

Commit ea267b0

Browse files
authored
fix(ble): enforce maximum length for dynamic device name (#2784)
1 parent 2fe55c4 commit ea267b0

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

app/Kconfig

+5
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ config BT_PERIPHERAL_PREF_LATENCY
238238
config BT_PERIPHERAL_PREF_TIMEOUT
239239
default 400
240240

241+
# The device name should be 16 characters or less so it fits within the
242+
# advertising data.
243+
config BT_DEVICE_NAME_MAX
244+
default 16
245+
241246
endif # ZMK_BLE
242247

243248
endmenu # Output Types

app/src/ble.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ static uint8_t active_profile;
6666
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
6767
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
6868

69-
BUILD_ASSERT(DEVICE_NAME_LEN <= 16, "ERROR: BLE device name is too long. Max length: 16");
69+
BUILD_ASSERT(
70+
DEVICE_NAME_LEN <= CONFIG_BT_DEVICE_NAME_MAX,
71+
"ERROR: BLE device name is too long. Max length: " STRINGIFY(CONFIG_BT_DEVICE_NAME_MAX));
7072

7173
static struct bt_data zmk_ble_ad[] = {
7274
BT_DATA_BYTES(BT_DATA_GAP_APPEARANCE, 0xC1, 0x03),

0 commit comments

Comments
 (0)