Bluetooth: host: Allow attribute as NULL with notify / indicate by UUID
Allow to pass attribute as NULL pointer when using notify or indicate by UUID. This will use the entire handle value range to search for an attribute with a matching UUID. Document optional parameters, and clarify attr and uuid usage in the variable declaration in the struct for clarification. Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
parent
d1beff0d8c
commit
3ad3a72caf
2 changed files with 34 additions and 18 deletions
|
@ -2260,28 +2260,28 @@ int bt_gatt_notify_cb(struct bt_conn *conn,
|
|||
struct notify_data data;
|
||||
|
||||
__ASSERT(params, "invalid parameters\n");
|
||||
__ASSERT(params->attr, "invalid parameters\n");
|
||||
__ASSERT(params->attr || params->uuid, "invalid parameters\n");
|
||||
|
||||
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
data.attr = params->attr;
|
||||
|
||||
if (conn && conn->state != BT_CONN_CONNECTED) {
|
||||
return -ENOTCONN;
|
||||
}
|
||||
|
||||
data.attr = params->attr;
|
||||
data.handle = bt_gatt_attr_get_handle(data.attr);
|
||||
if (!data.handle) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* Lookup UUID if it was given */
|
||||
if (params->uuid) {
|
||||
if (!gatt_find_by_uuid(&data, params->uuid)) {
|
||||
return -ENOENT;
|
||||
}
|
||||
} else {
|
||||
if (!data.handle) {
|
||||
return -ENOENT;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if attribute is a characteristic then adjust the handle */
|
||||
|
@ -2336,28 +2336,28 @@ int bt_gatt_indicate(struct bt_conn *conn,
|
|||
struct notify_data data;
|
||||
|
||||
__ASSERT(params, "invalid parameters\n");
|
||||
__ASSERT(params->attr, "invalid parameters\n");
|
||||
__ASSERT(params->attr || params->uuid, "invalid parameters\n");
|
||||
|
||||
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
data.attr = params->attr;
|
||||
|
||||
if (conn && conn->state != BT_CONN_CONNECTED) {
|
||||
return -ENOTCONN;
|
||||
}
|
||||
|
||||
data.attr = params->attr;
|
||||
data.handle = bt_gatt_attr_get_handle(data.attr);
|
||||
if (!data.handle) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* Lookup UUID if it was given */
|
||||
if (params->uuid) {
|
||||
if (!gatt_find_by_uuid(&data, params->uuid)) {
|
||||
return -ENOENT;
|
||||
}
|
||||
} else {
|
||||
if (!data.handle) {
|
||||
return -ENOENT;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if attribute is a characteristic then adjust the handle */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue