Bluetooth: gatt: Add missing error handling

The attribute protocol Read By Type is used to perform
Read Using Characteristic UUID procedure. This procedure
is used to read characteristic value if Characteristic Value UUID
is known, while handle is not known.
Errors received from application like Insufficient Encryption
Key Size must be send as a response to Read By Type Request

> ACL Data RX: Handle 64 flags 0x02 dlen 11                                                                                                                          [hci0] 94382.244804
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x0003-0x0003
        Attribute type: Unknown (0xaa51)
< ACL Data TX: Handle 64 flags 0x00 dlen 9                                                                                                                           [hci0] 94382.255987
      ATT: Error Response (0x01) len 4
        Read By Type Request (0x08)
        Handle: 0x0003
        Error: Insufficient Encryption Key Size (0x0c)

With this patch we can pass TC_GAR_SR_BI_11_C test.

Change-Id: Id47109f673cb725b2edd9cc0e154cc055fc8d0ef
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
This commit is contained in:
Mariusz Skamra 2015-11-17 12:26:40 +01:00 committed by Anas Nashif
commit 9fecda938a

View file

@ -554,6 +554,22 @@ static uint8_t check_perm(struct bt_conn *conn, const struct bt_gatt_attr *attr,
return 0;
}
static uint8_t err_to_att(int err)
{
BT_DBG("%d", err);
switch (err) {
case -EINVAL:
return BT_ATT_ERR_INVALID_OFFSET;
case -EFBIG:
return BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
case -EACCES:
return BT_ATT_ERR_ENCRYPTION_KEY_SIZE;
default:
return BT_ATT_ERR_UNLIKELY;
}
}
struct read_type_data {
struct bt_att *att;
struct bt_uuid *uuid;
@ -609,7 +625,7 @@ static uint8_t read_type_cb(const struct bt_gatt_attr *attr, void *user_data)
read = attr->read(conn, attr, data->buf->data + data->buf->len,
att->chan.tx.mtu - data->buf->len, 0);
if (read < 0) {
/* TODO: Handle read errors */
data->err = err_to_att(read);
return BT_GATT_ITER_STOP;
}
@ -701,22 +717,6 @@ static uint8_t att_read_type_req(struct bt_att *att, struct net_buf *buf)
return att_read_type_rsp(att, &uuid, start_handle, end_handle);
}
static uint8_t err_to_att(int err)
{
BT_DBG("%d", err);
switch (err) {
case -EINVAL:
return BT_ATT_ERR_INVALID_OFFSET;
case -EFBIG:
return BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
case -EACCES:
return BT_ATT_ERR_ENCRYPTION_KEY_SIZE;
default:
return BT_ATT_ERR_UNLIKELY;
}
}
struct read_data {
struct bt_att *att;
uint16_t offset;