Skip to content

Commit fb199a2

Browse files
tedd-annashif
authored andcommitted
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 <[email protected]>
1 parent 3c6f074 commit fb199a2

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

include/bluetooth/gatt.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,9 +971,14 @@ typedef u8_t (*bt_gatt_read_func_t)(struct bt_conn *conn, u8_t err,
971971
* @param handle_count If equals to 1 single.handle and single.offset
972972
* are used. If >1 Read Multiple Characteristic
973973
* Values is performed and handles are used.
974+
* If equals to 0 by_uuid is used for Read Using
975+
* Characteristic UUID.
974976
* @param handle Attribute handle
975977
* @param offset Attribute data offset
976978
* @param handles Handles to read in Read Multiple Characteristic Values
979+
* @param start_handle First requested handle number
980+
* @param end_handle Last requested handle number
981+
* @param uuid 2 or 16 octet UUID
977982
*/
978983
struct bt_gatt_read_params {
979984
struct bt_att_req _req;
@@ -985,6 +990,11 @@ struct bt_gatt_read_params {
985990
u16_t offset;
986991
} single;
987992
u16_t *handles;
993+
struct {
994+
u16_t start_handle;
995+
u16_t end_handle;
996+
struct bt_uuid *uuid;
997+
} by_uuid;
988998
};
989999
};
9901000

subsys/bluetooth/host/gatt.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2434,6 +2434,34 @@ static int gatt_read_blob(struct bt_conn *conn,
24342434
return gatt_send(conn, buf, gatt_read_rsp, params, NULL);
24352435
}
24362436

2437+
static int gatt_read_uuid(struct bt_conn *conn,
2438+
struct bt_gatt_read_params *params)
2439+
{
2440+
struct net_buf *buf;
2441+
struct bt_att_read_type_req *req;
2442+
2443+
buf = bt_att_create_pdu(conn, BT_ATT_OP_READ_TYPE_REQ, sizeof(*req));
2444+
if (!buf) {
2445+
return -ENOMEM;
2446+
}
2447+
2448+
req = net_buf_add(buf, sizeof(*req));
2449+
req->start_handle = sys_cpu_to_le16(params->by_uuid.start_handle);
2450+
req->end_handle = sys_cpu_to_le16(params->by_uuid.end_handle);
2451+
2452+
if (params->by_uuid.uuid->type == BT_UUID_TYPE_16) {
2453+
net_buf_add_le16(buf, BT_UUID_16(params->by_uuid.uuid)->val);
2454+
} else {
2455+
net_buf_add_mem(buf, BT_UUID_128(params->by_uuid.uuid)->val, 16);
2456+
}
2457+
2458+
BT_DBG("start_handle 0x%04x end_handle 0x%04x uuid %s",
2459+
params->by_uuid.start_handle, params->by_uuid.end_handle,
2460+
bt_uuid_str(params->by_uuid.uuid));
2461+
2462+
return gatt_send(conn, buf, gatt_read_rsp, params, NULL);
2463+
}
2464+
24372465
#if defined(CONFIG_BT_GATT_READ_MULTIPLE)
24382466
static void gatt_read_multiple_rsp(struct bt_conn *conn, u8_t err,
24392467
const void *pdu, u16_t length,
@@ -2487,12 +2515,15 @@ int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params)
24872515

24882516
__ASSERT(conn, "invalid parameters\n");
24892517
__ASSERT(params && params->func, "invalid parameters\n");
2490-
__ASSERT(params->handle_count, "invalid parameters\n");
24912518

24922519
if (conn->state != BT_CONN_CONNECTED) {
24932520
return -ENOTCONN;
24942521
}
24952522

2523+
if (params->handle_count == 0) {
2524+
return gatt_read_uuid(conn, params);
2525+
}
2526+
24962527
if (params->handle_count > 1) {
24972528
return gatt_read_multiple(conn, params);
24982529
}

0 commit comments

Comments
 (0)