Bluetooth: host: Add helper function to find an attribute from its uuid
Expose a helper function to the application that searches the local database for the given attribute from its UUID. Provide arguments to limit the search that matches the service declaration to make it easy to limit the search to a specific service. Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
parent
3ad3a72caf
commit
b4ce2ba481
2 changed files with 33 additions and 0 deletions
|
@ -433,6 +433,24 @@ static inline void bt_gatt_foreach_attr(uint16_t start_handle, uint16_t end_hand
|
|||
*/
|
||||
struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr);
|
||||
|
||||
/** @brief Find Attribute by UUID.
|
||||
*
|
||||
* Find the attribute with the matching UUID.
|
||||
* To limit the search to a service set the attr to the service attributes and
|
||||
* the attr_count to the service attribute count .
|
||||
*
|
||||
* @param attr Pointer to an attribute that serves as the starting point
|
||||
* for the search of a match for the UUID.
|
||||
* Passing NULL will search the entire range.
|
||||
* @param attr_count The number of attributes from the starting point to
|
||||
* search for a match for the UUID.
|
||||
* Set to 0 to search until the end.
|
||||
* @param uuid UUID to match.
|
||||
*/
|
||||
struct bt_gatt_attr *bt_gatt_find_by_uuid(const struct bt_gatt_attr *attr,
|
||||
uint16_t attr_count,
|
||||
const struct bt_uuid *uuid);
|
||||
|
||||
/** @brief Get Attribute handle.
|
||||
*
|
||||
* @param attr Attribute object.
|
||||
|
|
|
@ -2254,6 +2254,21 @@ static bool gatt_find_by_uuid(struct notify_data *found,
|
|||
return found->attr ? true : false;
|
||||
}
|
||||
|
||||
struct bt_gatt_attr *bt_gatt_find_by_uuid(const struct bt_gatt_attr *attr,
|
||||
uint16_t attr_count,
|
||||
const struct bt_uuid *uuid)
|
||||
{
|
||||
struct bt_gatt_attr *found = NULL;
|
||||
uint16_t start_handle = bt_gatt_attr_value_handle(attr);
|
||||
uint16_t end_handle = start_handle && attr_count ?
|
||||
start_handle + attr_count : 0xffff;
|
||||
|
||||
bt_gatt_foreach_attr_type(start_handle, end_handle, uuid, NULL, 1,
|
||||
find_next, &found);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
int bt_gatt_notify_cb(struct bt_conn *conn,
|
||||
struct bt_gatt_notify_params *params)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue