diff --git a/doc/releases/release-notes-2.7.rst b/doc/releases/release-notes-2.7.rst index e824be76642..26846869b89 100644 --- a/doc/releases/release-notes-2.7.rst +++ b/doc/releases/release-notes-2.7.rst @@ -52,6 +52,12 @@ Removed APIs in this release Stable API changes in this release ================================== +* Bluetooth + + * Added :c:struct:`multiple` to the :c:struct:`bt_gatt_read_params` - this + structure contains two members: ``handles``, which was moved from + :c:struct:`bt_gatt_read_params`, and ``variable``. + Kernel ****** diff --git a/include/bluetooth/gatt.h b/include/bluetooth/gatt.h index f3a6ed0e354..301516a69ea 100644 --- a/include/bluetooth/gatt.h +++ b/include/bluetooth/gatt.h @@ -1366,8 +1366,7 @@ struct bt_gatt_read_params { /** Read attribute callback. */ bt_gatt_read_func_t func; /** If equals to 1 single.handle and single.offset are used. - * If >1 Read Multiple Characteristic Values is performed and handles - * are used. + * If greater than 1 multiple.handles are used. * If equals to 0 by_uuid is used for Read Using Characteristic UUID. */ size_t handle_count; @@ -1378,8 +1377,23 @@ struct bt_gatt_read_params { /** Attribute data offset. */ uint16_t offset; } single; - /** Handles to read in Read Multiple Characteristic Values. */ - uint16_t *handles; + struct { + /** Attribute handles to read with Read Multiple + * Characteristic Values. + */ + uint16_t *handles; + /** If true use Read Multiple Variable Length + * Characteristic Values procedure. + * The values of the set of attributes may be of + * variable or unknown length. + * If false use Read Multiple Characteristic Values + * procedure. + * The values of the set of attributes must be of a + * known fixed length, with the exception of the last + * value that can have a variable length. + */ + bool variable; + } multiple; struct { /** First requested handle number. */ uint16_t start_handle; diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index eeb801a7b8a..f9334052b3b 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -3951,7 +3951,7 @@ static int gatt_read_mult_encode(struct net_buf *buf, size_t len, uint8_t i; for (i = 0U; i < params->handle_count; i++) { - net_buf_add_le16(buf, params->handles[i]); + net_buf_add_le16(buf, params->multiple.handles[i]); } return 0; @@ -3979,9 +3979,6 @@ static void gatt_read_mult_vl_rsp(struct bt_conn *conn, uint8_t err, BT_DBG("err 0x%02x", err); if (err || !length) { - if (err == BT_ATT_ERR_NOT_SUPPORTED) { - gatt_read_mult(conn, params); - } params->func(conn, err, params, NULL, 0); return; } @@ -4018,7 +4015,7 @@ static int gatt_read_mult_vl_encode(struct net_buf *buf, size_t len, uint8_t i; for (i = 0U; i < params->handle_count; i++) { - net_buf_add_le16(buf, params->handles[i]); + net_buf_add_le16(buf, params->multiple.handles[i]); } return 0; @@ -4042,13 +4039,15 @@ static int gatt_read_mult(struct bt_conn *conn, { return -ENOTSUP; } +#endif /* CONFIG_BT_GATT_READ_MULTIPLE */ +#if !defined(CONFIG_BT_GATT_READ_MULTIPLE) || !defined(CONFIG_BT_EATT) static int gatt_read_mult_vl(struct bt_conn *conn, struct bt_gatt_read_params *params) { return -ENOTSUP; } -#endif /* CONFIG_BT_GATT_READ_MULTIPLE */ +#endif static int gatt_read_encode(struct net_buf *buf, size_t len, void *user_data) { @@ -4075,11 +4074,11 @@ int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params) } if (params->handle_count > 1) { -#if defined(CONFIG_BT_EATT) - return gatt_read_mult_vl(conn, params); -#else - return gatt_read_mult(conn, params); -#endif /* CONFIG_BT_EATT */ + if (params->multiple.variable) { + return gatt_read_mult_vl(conn, params); + } else { + return gatt_read_mult(conn, params); + } } if (params->single.offset) { diff --git a/subsys/bluetooth/shell/gatt.c b/subsys/bluetooth/shell/gatt.c index 46af078a233..43cc5dd7196 100644 --- a/subsys/bluetooth/shell/gatt.c +++ b/subsys/bluetooth/shell/gatt.c @@ -340,7 +340,8 @@ static int cmd_mread(const struct shell *shell, size_t argc, char *argv[]) read_params.func = read_func; read_params.handle_count = i; - read_params.handles = h; /* not used in read func */ + read_params.multiple.handles = h; + read_params.multiple.variable = true; err = bt_gatt_read(default_conn, &read_params); if (err) { diff --git a/tests/bluetooth/tester/src/gatt.c b/tests/bluetooth/tester/src/gatt.c index c0610c21644..732c1e8638d 100644 --- a/tests/bluetooth/tester/src/gatt.c +++ b/tests/bluetooth/tester/src/gatt.c @@ -1528,7 +1528,8 @@ static void read_multiple(uint8_t *data, uint16_t len) read_params.func = read_cb; read_params.handle_count = i; - read_params.handles = handles; /* not used in read func */ + read_params.multiple.handles = handles; /* not used in read func */ + read_params.multiple.variable = false; /* TODO should be handled as user_data via CONTAINER_OF macro */ btp_opcode = GATT_READ_MULTIPLE;