Skip to content

Commit

Permalink
fix(ble): enforce maximum length for dynamic device name
Browse files Browse the repository at this point in the history
  • Loading branch information
xudongzheng committed Jan 22, 2025
1 parent 2f58faf commit 2f277a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,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
Expand Down
4 changes: 3 additions & 1 deletion app/src/ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 2f277a5

Please sign in to comment.