Skip to content

Commit 00bfac0

Browse files
KKopyscinskicfriedt
authored andcommitted
Bluetooth: gatt: Add option to read multiple without variable length
Currently, with EATT enabled, when bt_gatt_read is called with multiple handles first it'll try to use gatt_read_mult_vl, and if it fails gatt_read_mult will be used to try again. Add option to skip the gatt_read_mult_vl and use gatt_read_mult right away. This is needed by tests that expect BT_ATT_OP_READ_MULT_REQ but support variable lenght, thus don't return BT_ATT_ERR_NOT_SUPPORTED. Removed fallback from read multiple vl to read multiple on BT_ATT_ERR_NOT_SUPPORTED error. This was affecting: GATT/CL/GAR/BV-05-C, GATT/CL/GAR/BI-18-C, GATT/CL/GAR/BI-19-C, GATT/CL/GAR/BI-20-C, GATT/CL/GAR/BI-21-C, GATT/CL/GAR/BI-22-C Signed-off-by: Krzysztof Kopyściński <[email protected]>
1 parent e4dc8ed commit 00bfac0

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

doc/releases/release-notes-2.7.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ Removed APIs in this release
5252
Stable API changes in this release
5353
==================================
5454

55+
* Bluetooth
56+
57+
* Added :c:struct:`multiple` to the :c:struct:`bt_gatt_read_params` - this
58+
structure contains two members: ``handles``, which was moved from
59+
:c:struct:`bt_gatt_read_params`, and ``variable``.
60+
5561
Kernel
5662
******
5763

include/bluetooth/gatt.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,8 +1366,7 @@ struct bt_gatt_read_params {
13661366
/** Read attribute callback. */
13671367
bt_gatt_read_func_t func;
13681368
/** If equals to 1 single.handle and single.offset are used.
1369-
* If >1 Read Multiple Characteristic Values is performed and handles
1370-
* are used.
1369+
* If greater than 1 multiple.handles are used.
13711370
* If equals to 0 by_uuid is used for Read Using Characteristic UUID.
13721371
*/
13731372
size_t handle_count;
@@ -1378,8 +1377,23 @@ struct bt_gatt_read_params {
13781377
/** Attribute data offset. */
13791378
uint16_t offset;
13801379
} single;
1381-
/** Handles to read in Read Multiple Characteristic Values. */
1382-
uint16_t *handles;
1380+
struct {
1381+
/** Attribute handles to read with Read Multiple
1382+
* Characteristic Values.
1383+
*/
1384+
uint16_t *handles;
1385+
/** If true use Read Multiple Variable Length
1386+
* Characteristic Values procedure.
1387+
* The values of the set of attributes may be of
1388+
* variable or unknown length.
1389+
* If false use Read Multiple Characteristic Values
1390+
* procedure.
1391+
* The values of the set of attributes must be of a
1392+
* known fixed length, with the exception of the last
1393+
* value that can have a variable length.
1394+
*/
1395+
bool variable;
1396+
} multiple;
13831397
struct {
13841398
/** First requested handle number. */
13851399
uint16_t start_handle;

subsys/bluetooth/host/gatt.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3951,7 +3951,7 @@ static int gatt_read_mult_encode(struct net_buf *buf, size_t len,
39513951
uint8_t i;
39523952

39533953
for (i = 0U; i < params->handle_count; i++) {
3954-
net_buf_add_le16(buf, params->handles[i]);
3954+
net_buf_add_le16(buf, params->multiple.handles[i]);
39553955
}
39563956

39573957
return 0;
@@ -3979,9 +3979,6 @@ static void gatt_read_mult_vl_rsp(struct bt_conn *conn, uint8_t err,
39793979
BT_DBG("err 0x%02x", err);
39803980

39813981
if (err || !length) {
3982-
if (err == BT_ATT_ERR_NOT_SUPPORTED) {
3983-
gatt_read_mult(conn, params);
3984-
}
39853982
params->func(conn, err, params, NULL, 0);
39863983
return;
39873984
}
@@ -4018,7 +4015,7 @@ static int gatt_read_mult_vl_encode(struct net_buf *buf, size_t len,
40184015
uint8_t i;
40194016

40204017
for (i = 0U; i < params->handle_count; i++) {
4021-
net_buf_add_le16(buf, params->handles[i]);
4018+
net_buf_add_le16(buf, params->multiple.handles[i]);
40224019
}
40234020

40244021
return 0;
@@ -4042,13 +4039,15 @@ static int gatt_read_mult(struct bt_conn *conn,
40424039
{
40434040
return -ENOTSUP;
40444041
}
4042+
#endif /* CONFIG_BT_GATT_READ_MULTIPLE */
40454043

4044+
#if !defined(CONFIG_BT_GATT_READ_MULTIPLE) || !defined(CONFIG_BT_EATT)
40464045
static int gatt_read_mult_vl(struct bt_conn *conn,
40474046
struct bt_gatt_read_params *params)
40484047
{
40494048
return -ENOTSUP;
40504049
}
4051-
#endif /* CONFIG_BT_GATT_READ_MULTIPLE */
4050+
#endif
40524051

40534052
static int gatt_read_encode(struct net_buf *buf, size_t len, void *user_data)
40544053
{
@@ -4075,11 +4074,11 @@ int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params)
40754074
}
40764075

40774076
if (params->handle_count > 1) {
4078-
#if defined(CONFIG_BT_EATT)
4079-
return gatt_read_mult_vl(conn, params);
4080-
#else
4081-
return gatt_read_mult(conn, params);
4082-
#endif /* CONFIG_BT_EATT */
4077+
if (params->multiple.variable) {
4078+
return gatt_read_mult_vl(conn, params);
4079+
} else {
4080+
return gatt_read_mult(conn, params);
4081+
}
40834082
}
40844083

40854084
if (params->single.offset) {

subsys/bluetooth/shell/gatt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ static int cmd_mread(const struct shell *shell, size_t argc, char *argv[])
340340

341341
read_params.func = read_func;
342342
read_params.handle_count = i;
343-
read_params.handles = h; /* not used in read func */
343+
read_params.multiple.handles = h;
344+
read_params.multiple.variable = true;
344345

345346
err = bt_gatt_read(default_conn, &read_params);
346347
if (err) {

tests/bluetooth/tester/src/gatt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,8 @@ static void read_multiple(uint8_t *data, uint16_t len)
15281528

15291529
read_params.func = read_cb;
15301530
read_params.handle_count = i;
1531-
read_params.handles = handles; /* not used in read func */
1531+
read_params.multiple.handles = handles; /* not used in read func */
1532+
read_params.multiple.variable = false;
15321533

15331534
/* TODO should be handled as user_data via CONTAINER_OF macro */
15341535
btp_opcode = GATT_READ_MULTIPLE;

0 commit comments

Comments
 (0)