Skip to content

Commit d0409e0

Browse files
KyraLengfeldnordicjm
authored andcommitted
[nrf fromtree] Bluetooth: Host: improve more² GATT documentation
This commit adds improvements for the GATT client API part. Signed-off-by: Kyra Lengfeld <[email protected]> (cherry picked from commit b136f6d)
1 parent ba29fe8 commit d0409e0

File tree

1 file changed

+37
-57
lines changed
  • include/zephyr/bluetooth

1 file changed

+37
-57
lines changed

include/zephyr/bluetooth/gatt.h

Lines changed: 37 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ enum bt_gatt_perm {
103103
#define BT_GATT_ERR(_att_err) (-(_att_err))
104104

105105
/** GATT attribute write flags */
106-
enum {
106+
enum bt_gatt_attr_write_flag {
107107
/** @brief Attribute prepare write flag
108108
*
109109
* If set, write callback should only check if the device is
@@ -198,7 +198,7 @@ typedef ssize_t (*bt_gatt_attr_read_func_t)(struct bt_conn *conn,
198198
* @param buf Buffer with the data to write
199199
* @param len Number of bytes in the buffer
200200
* @param offset Offset to start writing from
201-
* @param flags Flags (``BT_GATT_WRITE_FLAG_*``)
201+
* @param flags Flags of type @ref bt_gatt_attr_write_flag
202202
*
203203
* @return Number of bytes written, or in case of an error
204204
* ``BT_GATT_ERR()`` with a specific ``BT_ATT_ERR_*`` error code.
@@ -1114,7 +1114,7 @@ ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
11141114
* @param buf Buffer to store the value read.
11151115
* @param len Buffer length.
11161116
* @param offset Start offset.
1117-
* @param flags Write flags.
1117+
* @param flags Write flags, see @ref bt_gatt_attr_write_flag.
11181118
*
11191119
* @return number of bytes written in case of success or negative values in
11201120
* case of error.
@@ -1123,12 +1123,11 @@ ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
11231123
* @note Only use this with attributes which user_data is a _bt_gatt_ccc.
11241124
* _bt_gatt_ccc being the internal representation of CCC value.
11251125
*/
1126-
/** @endcond */
1126+
/** @endcond */
11271127
ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
11281128
const struct bt_gatt_attr *attr, const void *buf,
11291129
uint16_t len, uint16_t offset, uint8_t flags);
11301130

1131-
11321131
/**
11331132
* @brief Initialize Client Characteristic Configuration Declaration Macro.
11341133
*
@@ -1645,26 +1644,30 @@ uint16_t bt_gatt_get_uatt_mtu(struct bt_conn *conn);
16451644
* @{
16461645
*/
16471646

1648-
/** @brief GATT Exchange MTU parameters */
1647+
/** @brief GATT Exchange MTU parameters
1648+
*
1649+
* Used with @ref bt_gatt_exchange_mtu() to initiate an MTU exchange. The
1650+
* response is handled in the callback @p func, which is called upon
1651+
* completion from the 'config BT_RECV_CONTEXT' context.
1652+
*
1653+
* @p params must remain valid until the callback executes.
1654+
*/
16491655
struct bt_gatt_exchange_params {
1650-
/** Response callback */
1656+
/** Callback for MTU exchange response */
16511657
void (*func)(struct bt_conn *conn, uint8_t err,
16521658
struct bt_gatt_exchange_params *params);
16531659
};
16541660

16551661
/** @brief Exchange MTU
16561662
*
1657-
* This client procedure can be used to set the MTU to the maximum possible
1658-
* size the buffers can hold.
1659-
*
1660-
* @note Shall only be used once per connection.
1661-
*
1662-
* The Response comes in callback @p params->func. The callback is run from
1663-
* the context specified by 'config BT_RECV_CONTEXT'.
1664-
* @p params must remain valid until start of callback.
1663+
* Once per connection, this client procedure can be used to set the MTU to
1664+
* the maximum possible size the buffers can hold.
16651665
*
1666-
* This function will block while the ATT request queue is full, except when
1667-
* called from the BT RX thread, as this would cause a deadlock.
1666+
* As the response comes in callback @p params->func, for example
1667+
* @ref bt_gatt_get_mtu can be invoked in the mtu_exchange-callback to read
1668+
* out the new negotiated ATT connection MTU. The callback is run from the
1669+
* context specified by 'config BT_RECV_CONTEXT' and @p params must remain
1670+
* valid until start of callback.
16681671
*
16691672
* @param conn Connection object.
16701673
* @param params Exchange MTU parameters.
@@ -1674,7 +1677,7 @@ struct bt_gatt_exchange_params {
16741677
*
16751678
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
16761679
* Allow a pending request to resolve before retrying, or call this function
1677-
* outside the BT RX thread to get blocking behavior. Queue size is controlled
1680+
* from a separate thread to get blocking behavior. Queue size is controlled
16781681
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
16791682
*
16801683
* @retval -EALREADY The MTU exchange procedure has been already performed.
@@ -1733,7 +1736,7 @@ typedef uint8_t (*bt_gatt_discover_func_t)(struct bt_conn *conn,
17331736
struct bt_gatt_discover_params *params);
17341737

17351738
/** GATT Discover types */
1736-
enum {
1739+
enum bt_gatt_discover_type {
17371740
/** Discover Primary Services. */
17381741
BT_GATT_DISCOVER_PRIMARY,
17391742
/** Discover Secondary Services. */
@@ -1834,9 +1837,6 @@ struct bt_gatt_discover_params {
18341837
* the BT RX thread. @p params must remain valid until start of callback where
18351838
* iter `attr` is `NULL` or callback will return `BT_GATT_ITER_STOP`.
18361839
*
1837-
* This function will block while the ATT request queue is full, except when
1838-
* called from the BT RX thread, as this would cause a deadlock.
1839-
*
18401840
* @param conn Connection object.
18411841
* @param params Discover parameters.
18421842
*
@@ -1845,7 +1845,7 @@ struct bt_gatt_discover_params {
18451845
*
18461846
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
18471847
* Allow a pending request to resolve before retrying, or call this function
1848-
* outside the BT RX thread to get blocking behavior. Queue size is controlled
1848+
* from a separate thread to get blocking behavior. Queue size is controlled
18491849
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
18501850
*/
18511851
int bt_gatt_discover(struct bt_conn *conn,
@@ -1924,11 +1924,11 @@ struct bt_gatt_read_params {
19241924

19251925
/** @brief Read Attribute Value by handle
19261926
*
1927-
* This procedure read the attribute value and return it to the callback.
1927+
* This procedure reads the attribute value and returns it to the callback.
19281928
*
19291929
* When reading attributes by UUID the callback can be called multiple times
1930-
* depending on how many instances of given the UUID exists with the
1931-
* start_handle being updated for each instance.
1930+
* depending on how many instances of a given UUID exists with the start_handle
1931+
* being updated for each instance.
19321932
*
19331933
* To perform a GATT Long Read procedure, start with a Characteristic Value
19341934
* Read (by setting @c offset @c 0 and @c handle_count @c 1) and then return
@@ -1950,9 +1950,6 @@ struct bt_gatt_read_params {
19501950
* the context specified by 'config BT_RECV_CONTEXT'.
19511951
* @p params must remain valid until start of callback.
19521952
*
1953-
* This function will block while the ATT request queue is full, except when
1954-
* called from the BT RX thread, as this would cause a deadlock.
1955-
*
19561953
* @param conn Connection object.
19571954
* @param params Read parameters.
19581955
*
@@ -1961,7 +1958,7 @@ struct bt_gatt_read_params {
19611958
*
19621959
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
19631960
* Allow a pending request to resolve before retrying, or call this function
1964-
* outside the BT RX thread to get blocking behavior. Queue size is controlled
1961+
* from a separate thread to get blocking behavior. Queue size is controlled
19651962
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
19661963
*/
19671964
int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params);
@@ -2002,11 +1999,6 @@ struct bt_gatt_write_params {
20021999
* the context specified by 'config BT_RECV_CONTEXT'.
20032000
* @p params must remain valid until start of callback.
20042001
*
2005-
* This function will block while the ATT request queue is full, except when
2006-
* called from Bluetooth event context. When called from Bluetooth context,
2007-
* this function will instead instead return `-ENOMEM` if it would block to
2008-
* avoid a deadlock.
2009-
*
20102002
* @param conn Connection object.
20112003
* @param params Write parameters.
20122004
*
@@ -2015,8 +2007,8 @@ struct bt_gatt_write_params {
20152007
*
20162008
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
20172009
* Allow a pending request to resolve before retrying, or call this function
2018-
* outside Bluetooth event context to get blocking behavior. Queue size is
2019-
* controlled by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
2010+
* from a separate thread to get blocking behavior. Queue size is controlled
2011+
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
20202012
*/
20212013
int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params);
20222014

@@ -2032,22 +2024,19 @@ int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params);
20322024
* The number of pending callbacks can be increased with the
20332025
* @kconfig{CONFIG_BT_CONN_TX_MAX} option.
20342026
*
2035-
* This function will block while the ATT request queue is full, except when
2036-
* called from the BT RX thread, as this would cause a deadlock.
2037-
*
20382027
* @param conn Connection object.
20392028
* @param handle Attribute handle.
20402029
* @param data Data to be written.
20412030
* @param length Data length.
2042-
* @param sign Whether to sign data
2031+
* @param sign Whether to sign data.
20432032
* @param func Transmission complete callback.
20442033
* @param user_data User data to be passed back to callback.
20452034
*
20462035
* @retval 0 Successfully queued request.
20472036
*
20482037
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
20492038
* Allow a pending request to resolve before retrying, or call this function
2050-
* outside the BT RX thread to get blocking behavior. Queue size is controlled
2039+
* from a separate thread to get blocking behavior. Queue size is controlled
20512040
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
20522041
*/
20532042
int bt_gatt_write_without_response_cb(struct bt_conn *conn, uint16_t handle,
@@ -2060,20 +2049,17 @@ int bt_gatt_write_without_response_cb(struct bt_conn *conn, uint16_t handle,
20602049
* This procedure write the attribute value without requiring an
20612050
* acknowledgment that the write was successfully performed
20622051
*
2063-
* This function will block while the ATT request queue is full, except when
2064-
* called from the BT RX thread, as this would cause a deadlock.
2065-
*
20662052
* @param conn Connection object.
20672053
* @param handle Attribute handle.
20682054
* @param data Data to be written.
20692055
* @param length Data length.
2070-
* @param sign Whether to sign data
2056+
* @param sign Whether to sign data.
20712057
*
20722058
* @retval 0 Successfully queued request.
20732059
*
20742060
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
20752061
* Allow a pending request to resolve before retrying, or call this function
2076-
* outside the BT RX thread to get blocking behavior. Queue size is controlled
2062+
* from a separate thread to get blocking behavior. Queue size is controlled
20772063
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
20782064
*/
20792065
static inline int bt_gatt_write_without_response(struct bt_conn *conn,
@@ -2117,7 +2103,7 @@ typedef void (*bt_gatt_subscribe_func_t)(struct bt_conn *conn, uint8_t err,
21172103
struct bt_gatt_subscribe_params *params);
21182104

21192105
/** Subscription flags */
2120-
enum {
2106+
enum bt_gatt_sub_flag {
21212107
/** @brief Persistence flag
21222108
*
21232109
* If set, indicates that the subscription is not saved
@@ -2195,7 +2181,7 @@ struct bt_gatt_subscribe_params {
21952181
*/
21962182
bt_security_t min_security;
21972183
#endif
2198-
/** Subscription flags */
2184+
/** Subscription flags, see @ref bt_gatt_sub_flag */
21992185
ATOMIC_DEFINE(flags, BT_GATT_SUBSCRIBE_NUM_FLAGS);
22002186

22012187
/** @cond INTERNAL_HIDDEN
@@ -2227,9 +2213,6 @@ struct bt_gatt_subscribe_params {
22272213
* valid while subscribed and cannot be reused for additional subscriptions
22282214
* whilst active.
22292215
*
2230-
* This function will block while the ATT request queue is full, except when
2231-
* called from the BT RX thread, as this would cause a deadlock.
2232-
*
22332216
* @param conn Connection object.
22342217
* @param params Subscribe parameters.
22352218
*
@@ -2238,7 +2221,7 @@ struct bt_gatt_subscribe_params {
22382221
*
22392222
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
22402223
* Allow a pending request to resolve before retrying, or call this function
2241-
* outside the BT RX thread to get blocking behavior. Queue size is controlled
2224+
* from a separate thread to get blocking behavior. Queue size is controlled
22422225
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
22432226
*
22442227
* @retval -EALREADY if there already exist a subscription using the @p params.
@@ -2278,9 +2261,6 @@ int bt_gatt_resubscribe(uint8_t id, const bt_addr_le_t *peer,
22782261
* The Response comes in callback @p params->func. The callback is run from
22792262
* the BT RX thread.
22802263
*
2281-
* This function will block while the ATT request queue is full, except when
2282-
* called from the BT RX thread, as this would cause a deadlock.
2283-
*
22842264
* @param conn Connection object.
22852265
* @param params Subscribe parameters. The parameters shall be a @ref bt_gatt_subscribe_params from
22862266
* a previous call to bt_gatt_subscribe().
@@ -2290,7 +2270,7 @@ int bt_gatt_resubscribe(uint8_t id, const bt_addr_le_t *peer,
22902270
*
22912271
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
22922272
* Allow a pending request to resolve before retrying, or call this function
2293-
* outside the BT RX thread to get blocking behavior. Queue size is controlled
2273+
* from a separate thread to get blocking behavior. Queue size is controlled
22942274
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
22952275
*/
22962276
int bt_gatt_unsubscribe(struct bt_conn *conn,

0 commit comments

Comments
 (0)