From feb38e2ccdac2d60709f09a8457a7a01a0ba97bf Mon Sep 17 00:00:00 2001 From: Xudong Zheng <7pkvm5aw@slicealias.com> Date: Tue, 21 Jan 2025 00:52:01 -0500 Subject: [PATCH] fix(ble): enforce maximum length for dynamic device name --- app/Kconfig | 5 +++++ app/src/ble.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Kconfig b/app/Kconfig index 5fc03822a02..c1d88a584f7 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -238,6 +238,11 @@ config BT_PERIPHERAL_PREF_LATENCY config BT_PERIPHERAL_PREF_TIMEOUT default 400 +# The device name should be 16 characters or less so it fits within the +# advertising data. +config BT_DEVICE_NAME_MAX + default 16 + endif # ZMK_BLE endmenu # Output Types diff --git a/app/src/ble.c b/app/src/ble.c index 02d8901b982..7176bd0a67c 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -66,7 +66,9 @@ static uint8_t active_profile; #define DEVICE_NAME CONFIG_BT_DEVICE_NAME #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) -BUILD_ASSERT(DEVICE_NAME_LEN <= 16, "ERROR: BLE device name is too long. Max length: 16"); +BUILD_ASSERT( + DEVICE_NAME_LEN <= CONFIG_BT_DEVICE_NAME_MAX, + "ERROR: BLE device name is too long. Max length: " STRINGIFY(CONFIG_BT_DEVICE_NAME_MAX)); static struct bt_data zmk_ble_ad[] = { BT_DATA_BYTES(BT_DATA_GAP_APPEARANCE, 0xC1, 0x03),