Bluetooth: GATT: Add support for Read Using Characteristic UUID
This patch adds support for Read Using Characteristic UUID which is one of the procedure to read the characteristic value especially when the client only knows the characteristic UUID and does not know the handle of the characteristic. Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
This commit is contained in:
parent
32367c0dfc
commit
100f671bca
2 changed files with 42 additions and 1 deletions
|
@ -977,9 +977,14 @@ typedef u8_t (*bt_gatt_read_func_t)(struct bt_conn *conn, u8_t err,
|
||||||
* @param handle_count If equals to 1 single.handle and single.offset
|
* @param handle_count If equals to 1 single.handle and single.offset
|
||||||
* are used. If >1 Read Multiple Characteristic
|
* are used. If >1 Read Multiple Characteristic
|
||||||
* Values is performed and handles are used.
|
* Values is performed and handles are used.
|
||||||
|
* If equals to 0 by_uuid is used for Read Using
|
||||||
|
* Characteristic UUID.
|
||||||
* @param handle Attribute handle
|
* @param handle Attribute handle
|
||||||
* @param offset Attribute data offset
|
* @param offset Attribute data offset
|
||||||
* @param handles Handles to read in Read Multiple Characteristic Values
|
* @param handles Handles to read in Read Multiple Characteristic Values
|
||||||
|
* @param start_handle First requested handle number
|
||||||
|
* @param end_handle Last requested handle number
|
||||||
|
* @param uuid 2 or 16 octet UUID
|
||||||
*/
|
*/
|
||||||
struct bt_gatt_read_params {
|
struct bt_gatt_read_params {
|
||||||
struct bt_att_req _req;
|
struct bt_att_req _req;
|
||||||
|
@ -991,6 +996,11 @@ struct bt_gatt_read_params {
|
||||||
u16_t offset;
|
u16_t offset;
|
||||||
} single;
|
} single;
|
||||||
u16_t *handles;
|
u16_t *handles;
|
||||||
|
struct {
|
||||||
|
u16_t start_handle;
|
||||||
|
u16_t end_handle;
|
||||||
|
struct bt_uuid *uuid;
|
||||||
|
} by_uuid;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2460,6 +2460,34 @@ static int gatt_read_blob(struct bt_conn *conn,
|
||||||
return gatt_send(conn, buf, gatt_read_rsp, params, NULL);
|
return gatt_send(conn, buf, gatt_read_rsp, params, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int gatt_read_uuid(struct bt_conn *conn,
|
||||||
|
struct bt_gatt_read_params *params)
|
||||||
|
{
|
||||||
|
struct net_buf *buf;
|
||||||
|
struct bt_att_read_type_req *req;
|
||||||
|
|
||||||
|
buf = bt_att_create_pdu(conn, BT_ATT_OP_READ_TYPE_REQ, sizeof(*req));
|
||||||
|
if (!buf) {
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
req = net_buf_add(buf, sizeof(*req));
|
||||||
|
req->start_handle = sys_cpu_to_le16(params->by_uuid.start_handle);
|
||||||
|
req->end_handle = sys_cpu_to_le16(params->by_uuid.end_handle);
|
||||||
|
|
||||||
|
if (params->by_uuid.uuid->type == BT_UUID_TYPE_16) {
|
||||||
|
net_buf_add_le16(buf, BT_UUID_16(params->by_uuid.uuid)->val);
|
||||||
|
} else {
|
||||||
|
net_buf_add_mem(buf, BT_UUID_128(params->by_uuid.uuid)->val, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
BT_DBG("start_handle 0x%04x end_handle 0x%04x uuid %s",
|
||||||
|
params->by_uuid.start_handle, params->by_uuid.end_handle,
|
||||||
|
bt_uuid_str(params->by_uuid.uuid));
|
||||||
|
|
||||||
|
return gatt_send(conn, buf, gatt_read_rsp, params, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BT_GATT_READ_MULTIPLE)
|
#if defined(CONFIG_BT_GATT_READ_MULTIPLE)
|
||||||
static void gatt_read_multiple_rsp(struct bt_conn *conn, u8_t err,
|
static void gatt_read_multiple_rsp(struct bt_conn *conn, u8_t err,
|
||||||
const void *pdu, u16_t length,
|
const void *pdu, u16_t length,
|
||||||
|
@ -2513,12 +2541,15 @@ int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params)
|
||||||
|
|
||||||
__ASSERT(conn, "invalid parameters\n");
|
__ASSERT(conn, "invalid parameters\n");
|
||||||
__ASSERT(params && params->func, "invalid parameters\n");
|
__ASSERT(params && params->func, "invalid parameters\n");
|
||||||
__ASSERT(params->handle_count, "invalid parameters\n");
|
|
||||||
|
|
||||||
if (conn->state != BT_CONN_CONNECTED) {
|
if (conn->state != BT_CONN_CONNECTED) {
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params->handle_count == 0) {
|
||||||
|
return gatt_read_uuid(conn, params);
|
||||||
|
}
|
||||||
|
|
||||||
if (params->handle_count > 1) {
|
if (params->handle_count > 1) {
|
||||||
return gatt_read_multiple(conn, params);
|
return gatt_read_multiple(conn, params);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue