Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ble): enforce maximum length for dynamic device name #2784

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be configurable? The comment implies that the value should always be 16.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the value should not be changed. I didn't calculate the value myself but it should be the maximum Bluetooth advertising payload length minus everything in zmk_ble_ad.

It's getting set here so bt_set_name() and zmk_ble_set_device_name() return an error if the length is exceeded.

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
Loading