Bluetooth: Add ATT Read Request skeleton

This adds the defines for Read PDUs along with initial code to parse
them.

Change-Id: I3ec54a0bf2394b54bd8b08957533f0826bf4a23a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2015-05-07 12:12:46 +03:00 committed by Anas Nashif
commit dfdd657b37
2 changed files with 44 additions and 0 deletions

View file

@ -261,6 +261,35 @@ static void att_read_type_req(struct bt_conn *conn, struct bt_buf *data)
return; return;
} }
static void att_read_req(struct bt_conn *conn, struct bt_buf *data)
{
struct bt_att_read_req *req;
uint16_t handle;
if (data->len != sizeof(*req)) {
send_err_rsp(conn, BT_ATT_OP_READ_REQ, 0,
BT_ATT_ERR_INVALID_PDU);
return;
}
req = (void *)data->data;
handle = sys_le16_to_cpu(req->handle);
BT_DBG("handle %u\n", handle);
if (!handle) {
send_err_rsp(conn, BT_ATT_OP_READ_REQ, 0,
BT_ATT_ERR_INVALID_HANDLE);
return;
}
/* TODO: Generate proper response once a database is defined */
send_err_rsp(conn, BT_ATT_OP_READ_REQ, handle,
BT_ATT_ERR_ATTRIBUTE_NOT_FOUND);
}
void bt_att_recv(struct bt_conn *conn, struct bt_buf *buf) void bt_att_recv(struct bt_conn *conn, struct bt_buf *buf)
{ {
struct bt_att_hdr *hdr = (void *)buf->data; struct bt_att_hdr *hdr = (void *)buf->data;
@ -287,6 +316,9 @@ void bt_att_recv(struct bt_conn *conn, struct bt_buf *buf)
case BT_ATT_OP_READ_TYPE_REQ: case BT_ATT_OP_READ_TYPE_REQ:
att_read_type_req(conn, buf); att_read_type_req(conn, buf);
break; break;
case BT_ATT_OP_READ_REQ:
att_read_req(conn, buf);
break;
default: default:
BT_DBG("Unhandled ATT code %u\n", hdr->code); BT_DBG("Unhandled ATT code %u\n", hdr->code);
send_err_rsp(conn, hdr->code, 0, BT_ATT_ERR_NOT_SUPPORTED); send_err_rsp(conn, hdr->code, 0, BT_ATT_ERR_NOT_SUPPORTED);

View file

@ -153,5 +153,17 @@ struct bt_att_read_type_rsp {
struct bt_att_data data[0]; struct bt_att_data data[0];
} PACK_STRUCT; } PACK_STRUCT;
/* Read Request */
#define BT_ATT_OP_READ_REQ 0x0a
struct bt_att_read_req {
uint16_t handle;
} PACK_STRUCT;
/* Read Response */
#define BT_ATT_OP_READ_RSP 0x0b
struct bt_att_read_rsp {
uint8_t value[0];
} PACK_STRUCT;
void bt_att_recv(struct bt_conn *conn, struct bt_buf *buf); void bt_att_recv(struct bt_conn *conn, struct bt_buf *buf);
struct bt_buf *bt_att_create_pdu(struct bt_conn *conn, uint8_t op, size_t len); struct bt_buf *bt_att_create_pdu(struct bt_conn *conn, uint8_t op, size_t len);