Skip to content

Commit 52a0322

Browse files
KyraLengfeldnordicjm
authored andcommitted
[nrf fromtree] Bluetooth: Host: improve GATT documentation
The gatt docs are very sparce, this commit adds imrpovements for the GATT server API part. Others will follow. Signed-off-by: Kyra Lengfeld <[email protected]> (cherry picked from commit 775cc35)
1 parent de6651f commit 52a0322

File tree

1 file changed

+80
-20
lines changed
  • include/zephyr/bluetooth

1 file changed

+80
-20
lines changed

include/zephyr/bluetooth/gatt.h

Lines changed: 80 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -573,14 +573,14 @@ void bt_gatt_cb_register(struct bt_gatt_cb *cb);
573573
*
574574
* @param cb Callback struct.
575575
*
576-
* @return Zero on success or negative error code otherwise
576+
* @return Zero on success or negative error code otherwise.
577577
*/
578578
int bt_gatt_authorization_cb_register(const struct bt_gatt_authorization_cb *cb);
579579

580580
/** @brief Register GATT service.
581581
*
582-
* Register GATT service. Applications can make use of
583-
* macros such as ``BT_GATT_PRIMARY_SERVICE``, ``BT_GATT_CHARACTERISTIC``,
582+
* To register a GATT service, applications can make use of macros such as
583+
* ``BT_GATT_PRIMARY_SERVICE``, ``BT_GATT_CHARACTERISTIC``,
584584
* ``BT_GATT_DESCRIPTOR``, etc.
585585
*
586586
* When using @kconfig{CONFIG_BT_SETTINGS} then all services that should have
@@ -621,6 +621,9 @@ int bt_gatt_service_unregister(struct bt_gatt_service *svc);
621621
*/
622622
bool bt_gatt_service_is_registered(const struct bt_gatt_service *svc);
623623

624+
/** @brief to be used as return values for @ref bt_gatt_attr_func_t and @ref bt_gatt_read_func_t
625+
* type callbacks.
626+
*/
624627
enum {
625628
BT_GATT_ITER_STOP = 0,
626629
BT_GATT_ITER_CONTINUE,
@@ -645,7 +648,8 @@ typedef uint8_t (*bt_gatt_attr_func_t)(const struct bt_gatt_attr *attr,
645648
* Iterate attributes in the given range matching given UUID and/or data.
646649
*
647650
* @param start_handle Start handle.
648-
* @param end_handle End handle.
651+
* @param end_handle End handle. Often set to start_handle + attr_count or
652+
* BT_ATT_LAST_ATTRIBUTE_HANDLE.
649653
* @param uuid UUID to match, passing NULL skips UUID matching.
650654
* @param attr_data Attribute data to match, passing NULL skips data matching.
651655
* @param num_matches Number matches, passing 0 makes it unlimited.
@@ -892,6 +896,16 @@ ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn,
892896
const struct bt_gatt_attr *attr, void *buf,
893897
uint16_t len, uint16_t offset);
894898

899+
/** @brief Gatt Characterisitc Initialization Macro.
900+
*
901+
* Helper macro used within the @ref BT_GATT_CHARACTERISTIC macro in the GATT attribute declaration
902+
* to set the attribute user data.
903+
*
904+
* @param _uuid Characteristic attribute uuid.
905+
* @param _handle Characcteristic attribute handle at init.
906+
* @param _props Characteristic attribute properties,
907+
* a bitmap of ``BT_GATT_CHRC_*`` macros.
908+
*/
895909
#define BT_GATT_CHRC_INIT(_uuid, _handle, _props) \
896910
{ \
897911
.uuid = _uuid, \
@@ -924,6 +938,17 @@ ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn,
924938
})), \
925939
BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _user_data)
926940

941+
/**
942+
* @brief BT_GATT_CCC_MAX is defined depending on whether
943+
* @kconfig{CONFIG_BT_SETTINGS_CCC_LAZY_LOADING} or @kconfig{CONFIG_BT_CONN} is set.
944+
*
945+
* @kconfig{CONFIG_BT_SETTINGS_CCC_LAZY_LOADING} will set BT_GATT_CCC_MAX to
946+
* @kconfig{CONFIG_BT_MAX_CONN}
947+
* @kconfig{CONFIG_BT_CONN} will set BT_GATT_CCC_MAX to @kconfig{CONFIG_BT_MAX_PAIRED} +
948+
* @kconfig{CONFIG_BT_MAX_CONN}
949+
* If neither are set, BT_GATT_CCC_MAX is 0.
950+
*
951+
*/
927952
#if defined(CONFIG_BT_SETTINGS_CCC_LAZY_LOADING)
928953
#define BT_GATT_CCC_MAX (CONFIG_BT_MAX_CONN)
929954
#elif defined(CONFIG_BT_CONN)
@@ -932,13 +957,21 @@ ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn,
932957
#define BT_GATT_CCC_MAX 0
933958
#endif
934959

935-
/** @brief GATT CCC configuration entry. */
960+
/** @brief GATT CCC configuration entry.
961+
*
962+
* bt_gatt_ccc_cfg is used within @ref bt_gatt_attr_read_ccc and @ref bt_gatt_attr_write_ccc to
963+
* read and write the ccc configurations respectively.
964+
*
965+
*/
936966
struct bt_gatt_ccc_cfg {
937967
/** Local identity, BT_ID_DEFAULT in most cases. */
938968
uint8_t id;
939969
/** Remote peer address. */
940970
bt_addr_le_t peer;
941-
/** Configuration value. */
971+
/** @brief Configuration value
972+
* Value used to enable or disable notifications or indications for a specific
973+
* characteristic.
974+
*/
942975
uint16_t value;
943976
};
944977

@@ -989,8 +1022,6 @@ struct _bt_gatt_ccc {
9891022
* Read CCC attribute value from local database storing the result into buffer
9901023
* after encoding it.
9911024
*
992-
* @note Only use this with attributes which user_data is a _bt_gatt_ccc.
993-
*
9941025
* @param conn Connection object.
9951026
* @param attr Attribute to read.
9961027
* @param buf Buffer to store the value read.
@@ -1000,6 +1031,11 @@ struct _bt_gatt_ccc {
10001031
* @return number of bytes read in case of success or negative values in
10011032
* case of error.
10021033
*/
1034+
/** @cond INTERNAL_HIDDEN
1035+
* @note Only use this with attributes which user_data is a _bt_gatt_ccc.
1036+
* _bt_gatt_ccc being the internal representation of CCC value.
1037+
*/
1038+
/** @endcond */
10031039
ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
10041040
const struct bt_gatt_attr *attr, void *buf,
10051041
uint16_t len, uint16_t offset);
@@ -1008,8 +1044,6 @@ ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
10081044
*
10091045
* Write value in the buffer into CCC attribute.
10101046
*
1011-
* @note Only use this with attributes which user_data is a _bt_gatt_ccc.
1012-
*
10131047
* @param conn Connection object.
10141048
* @param attr Attribute to read.
10151049
* @param buf Buffer to store the value read.
@@ -1020,6 +1054,11 @@ ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
10201054
* @return number of bytes written in case of success or negative values in
10211055
* case of error.
10221056
*/
1057+
/** @cond INTERNAL_HIDDEN
1058+
* @note Only use this with attributes which user_data is a _bt_gatt_ccc.
1059+
* _bt_gatt_ccc being the internal representation of CCC value.
1060+
*/
1061+
/** @endcond */
10231062
ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
10241063
const struct bt_gatt_attr *attr, const void *buf,
10251064
uint16_t len, uint16_t offset, uint8_t flags);
@@ -1139,7 +1178,7 @@ ssize_t bt_gatt_attr_read_cud(struct bt_conn *conn,
11391178
* Read CPF attribute value from local database storing the result into buffer
11401179
* after encoding it.
11411180
*
1142-
* @note Only use this with attributes which user_data is a bt_gatt_pf.
1181+
* @note Only use this with attributes which user_data is a @ref bt_gatt_cpf.
11431182
*
11441183
* @param conn Connection object
11451184
* @param attr Attribute to read
@@ -1211,6 +1250,10 @@ ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn,
12111250
*/
12121251
typedef void (*bt_gatt_complete_func_t) (struct bt_conn *conn, void *user_data);
12131252

1253+
/** @brief GATT notification parameters
1254+
*
1255+
* See also @ref bt_gatt_notify_cb and @ref bt_gatt_notify_multiple, using this parameter.
1256+
*/
12141257
struct bt_gatt_notify_params {
12151258
/** @brief Notification Attribute UUID type
12161259
*
@@ -1232,7 +1275,8 @@ struct bt_gatt_notify_params {
12321275
bt_gatt_complete_func_t func;
12331276
/** Notification Value callback user data */
12341277
void *user_data;
1235-
#if defined(CONFIG_BT_EATT)
1278+
#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1279+
/** Att channel options. */
12361280
enum bt_att_chan_opt chan_opt;
12371281
#endif /* CONFIG_BT_EATT */
12381282
};
@@ -1406,10 +1450,22 @@ typedef void (*bt_gatt_indicate_func_t)(struct bt_conn *conn,
14061450
struct bt_gatt_indicate_params *params,
14071451
uint8_t err);
14081452

1453+
/** @typedef bt_gatt_indicate_params_destroy_t
1454+
* @brief Callback to destroy or clean up the GATT Indicate Value parameters.
1455+
*
1456+
* This callback function is invoked to clean up any resources associated with the
1457+
* `bt_gatt_indicate_params` structure once the GATT indication operation is completed.
1458+
*
1459+
* @param params Pointer to the GATT Indicate parameters structure to be cleaned up.
1460+
*/
14091461
typedef void (*bt_gatt_indicate_params_destroy_t)(
14101462
struct bt_gatt_indicate_params *params);
14111463

1412-
/** @brief GATT Indicate Value parameters */
1464+
/** @brief GATT Indicate Value parameters
1465+
*
1466+
* See also @ref bt_gatt_indicate, using this parameter.
1467+
*
1468+
*/
14131469
struct bt_gatt_indicate_params {
14141470
/** @brief Indicate Attribute UUID type
14151471
*
@@ -1433,7 +1489,8 @@ struct bt_gatt_indicate_params {
14331489
uint16_t len;
14341490
/** Private reference counter */
14351491
uint8_t _ref;
1436-
#if defined(CONFIG_BT_EATT)
1492+
#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1493+
/** Att channel options. */
14371494
enum bt_att_chan_opt chan_opt;
14381495
#endif /* CONFIG_BT_EATT */
14391496
};
@@ -1466,10 +1523,9 @@ struct bt_gatt_indicate_params {
14661523
int bt_gatt_indicate(struct bt_conn *conn,
14671524
struct bt_gatt_indicate_params *params);
14681525

1469-
14701526
/** @brief Check if connection have subscribed to attribute
14711527
*
1472-
* Check if connection has subscribed to attribute value change.
1528+
* Check if the connection has subscribed to an attribute value change.
14731529
*
14741530
* The attribute object can be the so called Characteristic Declaration,
14751531
* which is usually declared with BT_GATT_CHARACTERISTIC followed
@@ -1684,7 +1740,8 @@ struct bt_gatt_discover_params {
16841740
/** Only for stack-internal use, used for automatic discovery. */
16851741
struct bt_gatt_subscribe_params *sub_params;
16861742
#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
1687-
#if defined(CONFIG_BT_EATT)
1743+
#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1744+
/** Att channel options. */
16881745
enum bt_att_chan_opt chan_opt;
16891746
#endif /* CONFIG_BT_EATT */
16901747
};
@@ -1791,7 +1848,8 @@ struct bt_gatt_read_params {
17911848
const struct bt_uuid *uuid;
17921849
} by_uuid;
17931850
};
1794-
#if defined(CONFIG_BT_EATT)
1851+
#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1852+
/** Att channel options. */
17951853
enum bt_att_chan_opt chan_opt;
17961854
#endif /* CONFIG_BT_EATT */
17971855
/** Internal */
@@ -1866,7 +1924,8 @@ struct bt_gatt_write_params {
18661924
const void *data;
18671925
/** Length of the data */
18681926
uint16_t length;
1869-
#if defined(CONFIG_BT_EATT)
1927+
#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
1928+
/** Att channel options. */
18701929
enum bt_att_chan_opt chan_opt;
18711930
#endif /* CONFIG_BT_EATT */
18721931
};
@@ -2074,7 +2133,8 @@ struct bt_gatt_subscribe_params {
20742133
ATOMIC_DEFINE(flags, BT_GATT_SUBSCRIBE_NUM_FLAGS);
20752134

20762135
sys_snode_t node;
2077-
#if defined(CONFIG_BT_EATT)
2136+
#if defined(CONFIG_BT_EATT) || defined(__DOXYGEN__)
2137+
/** Att channel options. */
20782138
enum bt_att_chan_opt chan_opt;
20792139
#endif /* CONFIG_BT_EATT */
20802140
};

0 commit comments

Comments
 (0)