-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Bluetooth: GATT: Use offset when GAP name is updated #100235
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
base: main
Are you sure you want to change the base?
Conversation
The offset in write_name function used by GAP service was really ignoring offset value. This commit updates it to use the offset in similar way how it is done in write_appearance function. Signed-off-by: Radosław Koppel <[email protected]>
|
| const char *current_name = bt_get_name(); | ||
| size_t current_name_len = strlen(current_name); | ||
|
|
||
| if (offset >= CONFIG_BT_DEVICE_NAME_MAX) { | ||
| if (offset > current_name_len) { | ||
| return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); | ||
| } | ||
|
|
||
| if (offset + len > CONFIG_BT_DEVICE_NAME_MAX) { | ||
| return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); | ||
| } | ||
|
|
||
| memcpy(value, buf, len); | ||
| memcpy(value, current_name, current_name_len + 1); | ||
| memcpy(value + offset, buf, len); | ||
|
|
||
| value[len] = '\0'; | ||
| value[offset + len] = '\0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the + offset changes that seem valid, but why do we care about current_name and current_name_len?
| size_t current_name_len = strlen(current_name); | ||
|
|
||
| if (offset >= CONFIG_BT_DEVICE_NAME_MAX) { | ||
| if (offset > current_name_len) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong, but isn't offset only used in long writes? Which require the characteristic to have BT_GATT_PERM_PREPARE_WRITE, but BT_GATT_CHARACTERISTIC(BT_UUID_GAP_DEVICE_NAME does not have that?
So in the current implementation, offset cannot be anything but 0



The offset in write_name function used by GAP service was really ignoring offset value.
This commit updates it to use the offset in similar way how it is done in write_appearance function.
Note: We should implement this solution or check if offset == 0.
Current implementation first allows offset > 0 and then totally ignores it when setting the name.