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:
Joakim Andersson 2021-06-16 12:38:44 +02:00 committed by Anas Nashif
commit 3ad3a72caf
2 changed files with 34 additions and 18 deletions

View file

@ -928,9 +928,17 @@ ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn,
typedef void (*bt_gatt_complete_func_t) (struct bt_conn *conn, void *user_data);
struct bt_gatt_notify_params {
/** Notification Attribute UUID type */
/** @brief Notification Attribute UUID type
*
* Optional, use to search for an attribute with matching UUID when
* the attribute object pointer is not known.
*/
const struct bt_uuid *uuid;
/** Notification Attribute object*/
/** @brief Notification Attribute object
*
* Optional if uuid is provided, in this case it will be used as start
* range to search for the attribute with the given UUID.
*/
const struct bt_gatt_attr *attr;
/** Notification Value data */
const void *data;
@ -955,7 +963,7 @@ struct bt_gatt_notify_params {
* @option{CONFIG_BT_CONN_TX_MAX} option.
*
* Alternatively it is possible to notify by UUID by setting it on the
* parameters, when using this method the attribute given is used as the
* parameters, when using this method the attribute if provided is used as the
* start range when looking up for possible matches.
*
* @param conn Connection object.
@ -1068,9 +1076,17 @@ typedef void (*bt_gatt_indicate_params_destroy_t)(
/** @brief GATT Indicate Value parameters */
struct bt_gatt_indicate_params {
/** Notification Attribute UUID type */
/** @brief Indicate Attribute UUID type
*
* Optional, use to search for an attribute with matching UUID when
* the attribute object pointer is not known.
*/
const struct bt_uuid *uuid;
/** Indicate Attribute object*/
/** @brief Indicate Attribute object
*
* Optional if uuid is provided, in this case it will be used as start
* range to search for the attribute with the given UUID.
*/
const struct bt_gatt_attr *attr;
/** Indicate Value callback */
bt_gatt_indicate_func_t func;
@ -1097,7 +1113,7 @@ struct bt_gatt_indicate_params {
* BT_GATT_CHARACTERISTIC.
*
* Alternatively it is possible to indicate by UUID by setting it on the
* parameters, when using this method the attribute given is used as the
* parameters, when using this method the attribute if provided is used as the
* start range when looking up for possible matches.
*
* @note This procedure is asynchronous therefore the parameters need to

View file

@ -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 */