Bluetooth: GATT: Add bt_gatt_read_multiple

Introduction of GATT client API to enable read attributes
determined by set of handles.

< ACL Data TX: Handle 64 flags 0x00 dlen 21
      ATT: Read Multiple Request (0x0e) len 16
        Handle: 0x0001
        Handle: 0x0002
        Handle: 0x0003
        Handle: 0x0004
        Handle: 0x0005
        Handle: 0x0006
        Handle: 0x000a
        Handle: 0x000b
> ACL Data RX: Handle 64 flags 0x02 dlen 27
      ATT: Read Multiple Response (0x0f) len 22
        00 18 02 03 00 00 2a 54 65 73 74 20 70 65 72 69  ......
        70 68 65 72 61 6c

Change-Id: Ic8e6edcf79a63bc52cb4c657e5b09529fa87879e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
This commit is contained in:
Arkadiusz Lichwa 2015-07-09 10:14:31 +02:00 committed by Anas Nashif
commit 70c7e8825c
3 changed files with 52 additions and 0 deletions

View file

@ -737,4 +737,19 @@ int bt_gatt_read(struct bt_conn *conn, uint16_t handle, uint16_t offset,
*/
void bt_gatt_cancel(struct bt_conn *conn);
/** @brief Read Multiple Attribute Values by set of handles
*
* Routine to be used to retrieve set of attributes values determined by set of
* handles in one call.
*
* @param conn Connection object.
* @param handles Set of valid handles to attributes.
* @param count Number of handles to be read.
* @param func User callback routine to get retrieved values.
*
* @return 0 in case of success or negative value in case of error.
*/
int bt_gatt_read_multiple(struct bt_conn *conn, const uint16_t *handles,
size_t count, bt_gatt_read_func_t func);
#endif /* __BT_GATT_H */

View file

@ -1233,6 +1233,14 @@ static uint8_t att_handle_read_blob_rsp(struct bt_conn *conn,
return att_handle_rsp(conn, buf->data, buf->len, 0);
}
static uint8_t att_handle_read_mult_rsp(struct bt_conn *conn,
struct bt_buf *buf)
{
BT_DBG("\n");
return att_handle_rsp(conn, buf->data, buf->len, 0);
}
static const struct {
uint8_t op;
uint8_t (*func)(struct bt_conn *conn, struct bt_buf *buf);
@ -1266,6 +1274,8 @@ static const struct {
sizeof(struct bt_att_read_blob_rsp) },
{ BT_ATT_OP_READ_MULT_REQ, att_read_mult_req,
BT_ATT_READ_MULT_MIN_LEN_REQ },
{ BT_ATT_OP_READ_MULT_RSP, att_handle_read_mult_rsp,
sizeof(struct bt_att_read_mult_rsp) },
{ BT_ATT_OP_READ_GROUP_REQ, att_read_group_req,
sizeof(struct bt_att_read_group_req) },
{ BT_ATT_OP_WRITE_REQ, att_write_req,

View file

@ -925,3 +925,30 @@ void bt_gatt_cancel(struct bt_conn *conn)
{
bt_att_cancel(conn);
}
int bt_gatt_read_multiple(struct bt_conn *conn, const uint16_t *handles,
size_t count, bt_gatt_read_func_t func)
{
struct bt_buf *buf;
uint8_t i;
if (!conn && conn->state != BT_CONN_CONNECTED) {
return -ENOTCONN;
}
if (!handles || count < 2 || !func) {
return -EINVAL;
}
buf = bt_att_create_pdu(conn, BT_ATT_OP_READ_MULT_REQ,
count * sizeof(*handles));
if (!buf) {
return -ENOMEM;
}
for (i = 0; i < count; i++) {
bt_buf_add_le16(buf, handles[i]);
}
return gatt_send(conn, buf, att_read_rsp, func, NULL);
}