Bluetooth: Fix read attr respond with invalid handle error
If no attribute with given handle is found in database then invalid handle error should be set and returned. If attribute is found then pre-set invalid handle error will be cleared. Change-Id: I4119877bb72693e18003399f9b6764666f801fe4 Signed-off-by: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@tieto.com>
This commit is contained in:
parent
fb6c412b8d
commit
dabb5d49d5
1 changed files with 9 additions and 0 deletions
|
@ -671,6 +671,12 @@ static uint8_t read_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||||
|
|
||||||
data->rsp = bt_buf_add(data->buf, sizeof(*data->rsp));
|
data->rsp = bt_buf_add(data->buf, sizeof(*data->rsp));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If any attribute is founded in handle range it means that error
|
||||||
|
* should be changed from pre-set: invalid handle error to no error.
|
||||||
|
*/
|
||||||
|
data->err = 0x00;
|
||||||
|
|
||||||
if (!attr->read) {
|
if (!attr->read) {
|
||||||
data->err = BT_ATT_ERR_READ_NOT_PERMITTED;
|
data->err = BT_ATT_ERR_READ_NOT_PERMITTED;
|
||||||
return BT_GATT_ITER_STOP;
|
return BT_GATT_ITER_STOP;
|
||||||
|
@ -714,6 +720,9 @@ static uint8_t att_read_rsp(struct bt_conn *conn, uint8_t op, uint8_t rsp,
|
||||||
data.conn = conn;
|
data.conn = conn;
|
||||||
data.offset = offset;
|
data.offset = offset;
|
||||||
|
|
||||||
|
/* Pre-set error if no attr will be found in handle */
|
||||||
|
data.err = BT_ATT_ERR_INVALID_HANDLE;
|
||||||
|
|
||||||
bt_gatt_foreach_attr(handle, handle, read_cb, &data);
|
bt_gatt_foreach_attr(handle, handle, read_cb, &data);
|
||||||
|
|
||||||
/* In case of error discard data and respond with an error */
|
/* In case of error discard data and respond with an error */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue