Bluetooth: GATT: Add flag to indicate write command

Application may need to handle the write differently depending on the
write operation so this adds a flag called BT_GATT_WRITE_FLAG_CMD which
can then be checked by the callback, for instance one can respond with
BT_ATT_ERR_WRITE_REQ_REJECTED when that flag is not set which should
indicate to the client to use write command instead.

Fixes #11206

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2018-11-14 11:09:24 +02:00 committed by Johan Hedberg
commit ae05089946
2 changed files with 13 additions and 1 deletions

View file

@ -91,6 +91,13 @@ enum {
* authorized but no data shall be written.
*/
BT_GATT_WRITE_FLAG_PREPARE = BIT(0),
/** Attribute write command flag
*
* If set, indicates that write operation is a command (Write without
* response) which doesn't generate any response.
*/
BT_GATT_WRITE_FLAG_CMD = BIT(1),
};
/** @brief GATT Attribute structure. */

View file

@ -1199,6 +1199,7 @@ static u8_t write_cb(const struct bt_gatt_attr *attr, void *user_data)
{
struct write_data *data = user_data;
int write;
u8_t flags = 0;
BT_DBG("handle 0x%04x offset %u", attr->handle, data->offset);
@ -1208,9 +1209,13 @@ static u8_t write_cb(const struct bt_gatt_attr *attr, void *user_data)
return BT_GATT_ITER_STOP;
}
if (!data->op) {
flags |= BT_GATT_WRITE_FLAG_CMD;
}
/* Read attribute value and store in the buffer */
write = attr->write(data->conn, attr, data->value, data->len,
data->offset, 0);
data->offset, flags);
if (write < 0 || write != data->len) {
data->err = err_to_att(write);
return BT_GATT_ITER_STOP;