Bluetooth: Add ATT Prepare Write Request skeleton

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

Change-Id: Ia7210dbe4662afbebe742b5b1a7b8f08999adf2a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2015-05-08 14:31:50 +03:00 committed by Anas Nashif
commit 0fe5fa9fcf
2 changed files with 43 additions and 0 deletions

View file

@ -420,6 +420,30 @@ static void att_write_req(struct bt_conn *conn, struct bt_buf *data)
BT_ATT_ERR_INVALID_HANDLE);
}
static void att_prepare_write_req(struct bt_conn *conn, struct bt_buf *data)
{
struct bt_att_prepare_write_req *req;
uint16_t handle, offset;
if (data->len < sizeof(*req)) {
send_err_rsp(conn, BT_ATT_OP_PREPARE_WRITE_REQ, 0,
BT_ATT_ERR_INVALID_PDU);
return;
}
req = (void *)data->data;
handle = sys_le16_to_cpu(req->handle);
offset = sys_le16_to_cpu(req->offset);
BT_DBG("handle %u offset %u\n", handle);
/* TODO: Generate proper response once a database is defined */
send_err_rsp(conn, BT_ATT_OP_PREPARE_WRITE_REQ, handle,
BT_ATT_ERR_INVALID_HANDLE);
}
static void att_write_cmd(struct bt_conn *conn, struct bt_buf *data)
{
struct bt_att_write_req *req;
@ -498,6 +522,9 @@ void bt_att_recv(struct bt_conn *conn, struct bt_buf *buf)
case BT_ATT_OP_WRITE_REQ:
att_write_req(conn, buf);
break;
case BT_ATT_OP_PREPARE_WRITE_REQ:
att_prepare_write_req(conn, buf);
break;
case BT_ATT_OP_WRITE_CMD:
att_write_cmd(conn, buf);
break;

View file

@ -223,6 +223,22 @@ struct bt_att_write_req {
/* Write Response */
#define BT_ATT_OP_WRITE_RSP 0x13
/* Prepare Write Request */
#define BT_ATT_OP_PREPARE_WRITE_REQ 0x16
struct bt_att_prepare_write_req {
uint16_t handle;
uint16_t offset;
uint8_t value[0];
} PACK_STRUCT;
/* Prepare Write Respond */
#define BT_ATT_OP_PREPARE_WRITE_RSP 0x17
struct bt_att_prepare_write_rsp {
uint16_t handle;
uint16_t offset;
uint8_t value[0];
} PACK_STRUCT;
/* Write Command */
#define BT_ATT_OP_WRITE_CMD 0x52
struct bt_att_write_cmd {