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

att_db_util: Add API to specify next attribute handle. #647

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexmchughnz
Copy link

Our BTLE usage requires our peripheral to enable / disable certain GATT services at runtime and inform the host device via sending a Notify to the Service Changed characteristic. We are using att_db_util to re-construct the ATT table as needed.

Our ATT table layout is:
{GAP attributes, HID attributes, Custom service attributes}
Depending on what is enabled or disabled, this layout can change to
{GAP attributes, Custom service attributes}, or
{GAP attributes, HID attributes}.

Currently, att_db_util appends all services with an incrementing sequence of handles. This means when we change our layout, the handles associated with the HID and Custom services' attributes change. We have found that not all BTLE hosts respect the Service Changed feature in the way we would like. Therefore, we would like to ensure our services always start at a certain handle value.

I have added a extra method to the API to allow the att_db_next_handle to be moved ahead. This method enables us to ensure specific services always have the same handle:

att_db_util_set_next_handle(0x100);
uint16_t first_hid_handle = att_db_util_add_service_uuid16(ORG_BLUETOOTH_SERVICE_HUMAN_INTERFACE_DEVICE);
assert(first_hid_handle == 0x100);
// add rest of HID attributes

att_db_util_set_next_handle(0x200);
uint16_t first_custom_handle = att_db_util_add_service_uuid128(CUSTOM_SERVICE_UUID128);
assert(first_custom_handle == 0x200);
// add rest of custom service attributes

Additionally, this method allows users to "reserve" handle space for future expansion.
e.g. I could start Custom service 1 at handle 0x100 and Custom service 2 at 0x200. The handle range between 0x100-0x200 can be reserved for future attributes for Custom service 1, without changing the handle values for Custom service 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant