Skip to content

Commit fa67619

Browse files
committed
bluetooth: rename _bt_gatt_ccc and clarify usage
Bluetooth had two public types with similar name _bt_gatt_ccc and bt_gatt_ccc, but for absolutely different purposes. That caused misunderstanding of relationship of them and cases where to use which one. Commit changes name of _bt_gatt_ccc to more suitable by usage and improves documentation of it. Additionally, it changes name of BT_GATT_CCC_INITIALIZER to correspond the type name. Signed-off-by: Aleksandr Khromykh <[email protected]>
1 parent 1e1f944 commit fa67619

File tree

11 files changed

+73
-53
lines changed

11 files changed

+73
-53
lines changed

doc/releases/migration-guide-4.2.rst

+6
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ Bluetooth Host
243243
each role may be different. Any existing uses/checks for ``BT_ISO_CHAN_TYPE_CONNECTED``
244244
can be replaced with an ``||`` of the two. (:github:`75549`)
245245

246+
* The ``struct _bt_gatt_ccc`` in :zephyr_file:`include/zephyr/bluetooth/gatt.h` has been renamed to
247+
struct :c:struct:`bt_gatt_ccc_managed_user_data`. (:github:`88652`)
248+
249+
* The macro ``BT_GATT_CCC_INITIALIZER`` in :zephyr_file:`include/zephyr/bluetooth/gatt.h`
250+
has been renamed to :c:macro:`BT_GATT_CCC_MANAGED_USER_DATA_INIT`. (:github:`88652`)
251+
246252
Bluetooth Classic
247253
=================
248254

include/zephyr/bluetooth/gatt.h

+33-19
Original file line numberDiff line numberDiff line change
@@ -1035,8 +1035,14 @@ struct bt_gatt_ccc_cfg {
10351035
uint16_t value;
10361036
};
10371037

1038-
/** Internal representation of CCC value */
1039-
struct _bt_gatt_ccc {
1038+
/** Macro to keep old name for deprecation period. */
1039+
#define _bt_gatt_ccc bt_gatt_ccc_managed_user_data __DEPRECATED_MACRO
1040+
1041+
/** @brief Internal representation of CCC value.
1042+
*
1043+
* @note Only use this as an argument for @ref BT_GATT_CCC_MANAGED
1044+
*/
1045+
struct bt_gatt_ccc_managed_user_data {
10401046
/** Configuration for each connection */
10411047
struct bt_gatt_ccc_cfg cfg[BT_GATT_CCC_MAX];
10421048

@@ -1092,8 +1098,8 @@ struct _bt_gatt_ccc {
10921098
* case of error.
10931099
*/
10941100
/** @cond INTERNAL_HIDDEN
1095-
* @note Only use this with attributes which user_data is a _bt_gatt_ccc.
1096-
* _bt_gatt_ccc being the internal representation of CCC value.
1101+
* @note Only use this with attributes which user_data is a bt_gatt_ccc_managed_user_data.
1102+
* @ref bt_gatt_ccc_managed_user_data being the internal representation of CCC value.
10971103
*/
10981104
/** @endcond */
10991105
ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
@@ -1115,14 +1121,17 @@ ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
11151121
* case of error.
11161122
*/
11171123
/** @cond INTERNAL_HIDDEN
1118-
* @note Only use this with attributes which user_data is a _bt_gatt_ccc.
1119-
* _bt_gatt_ccc being the internal representation of CCC value.
1124+
* @note Only use this with attributes which user_data is a bt_gatt_ccc_managed_user_data.
1125+
* @ref bt_gatt_ccc_managed_user_data being the internal representation of CCC value.
11201126
*/
11211127
/** @endcond */
11221128
ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
11231129
const struct bt_gatt_attr *attr, const void *buf,
11241130
uint16_t len, uint16_t offset, uint8_t flags);
11251131

1132+
/** Macro to keep old name for deprecation period. */
1133+
#define BT_GATT_CCC_INITIALIZER BT_GATT_CCC_MANAGED_USER_DATA_INIT __DEPRECATED_MACRO
1134+
11261135
/**
11271136
* @brief Initialize Client Characteristic Configuration Declaration Macro.
11281137
*
@@ -1132,20 +1141,23 @@ ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
11321141
* @param _write Configuration write callback.
11331142
* @param _match Configuration match callback.
11341143
*/
1135-
#define BT_GATT_CCC_INITIALIZER(_changed, _write, _match) \
1136-
{ \
1137-
.cfg = {}, \
1138-
.cfg_changed = _changed, \
1139-
.cfg_write = _write, \
1140-
.cfg_match = _match, \
1144+
#define BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, _write, _match) \
1145+
{ \
1146+
.cfg = {}, \
1147+
.cfg_changed = _changed, \
1148+
.cfg_write = _write, \
1149+
.cfg_match = _match, \
11411150
}
11421151

11431152
/**
11441153
* @brief Managed Client Characteristic Configuration Declaration Macro.
11451154
*
11461155
* Helper macro to declare a Managed CCC attribute.
11471156
*
1148-
* @param _ccc CCC attribute user data, shall point to a _bt_gatt_ccc.
1157+
* @param _ccc A new @ref bt_gatt_ccc_managed_user_data object with the same lifetime
1158+
* as the results of the call to BT_GATT_CCC_MANAGED.
1159+
* See the documentation of @ref bt_gatt_ccc_managed_user_data on how
1160+
* to initialize it.
11491161
* @param _perm CCC access permissions,
11501162
* a bitmap of @ref bt_gatt_perm values.
11511163
*/
@@ -1163,9 +1175,10 @@ ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
11631175
* @param _perm CCC access permissions,
11641176
* a bitmap of @ref bt_gatt_perm values.
11651177
*/
1166-
#define BT_GATT_CCC(_changed, _perm) \
1167-
BT_GATT_CCC_MANAGED(((struct _bt_gatt_ccc[]) \
1168-
{BT_GATT_CCC_INITIALIZER(_changed, NULL, NULL)}), _perm)
1178+
#define BT_GATT_CCC(_changed, _perm) \
1179+
BT_GATT_CCC_MANAGED(((struct bt_gatt_ccc_managed_user_data[]){ \
1180+
BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, NULL, NULL)}), \
1181+
_perm)
11691182

11701183
/**
11711184
* @brief Client Characteristic Configuration Declaration Macro with write callback.
@@ -1177,9 +1190,10 @@ ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
11771190
* @param _perm CCC access permissions,
11781191
* a bitmap of @ref bt_gatt_perm values.
11791192
*/
1180-
#define BT_GATT_CCC_WITH_WRITE_CB(_changed, _write, _perm) \
1181-
BT_GATT_CCC_MANAGED(((struct _bt_gatt_ccc[]) \
1182-
{BT_GATT_CCC_INITIALIZER(_changed, _write, NULL) }), _perm)
1193+
#define BT_GATT_CCC_WITH_WRITE_CB(_changed, _write, _perm) \
1194+
BT_GATT_CCC_MANAGED(((struct bt_gatt_ccc_managed_user_data[]){ \
1195+
BT_GATT_CCC_MANAGED_USER_DATA_INIT(_changed, _write, NULL)}), \
1196+
_perm)
11831197

11841198
/** @brief Read Characteristic Extended Properties Attribute helper
11851199
*

subsys/bluetooth/audio/audio_internal.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ ssize_t bt_audio_ccc_cfg_write(struct bt_conn *conn, const struct bt_gatt_attr *
6161
uint16_t value);
6262

6363
/** Helper to define LE Audio CCC descriptor. */
64-
#define BT_AUDIO_CCC(_changed) \
65-
BT_GATT_CCC_MANAGED(((struct _bt_gatt_ccc[]) \
66-
{BT_GATT_CCC_INITIALIZER(_changed, bt_audio_ccc_cfg_write, NULL)}), \
64+
#define BT_AUDIO_CCC(_changed) \
65+
BT_GATT_CCC_MANAGED( \
66+
((struct bt_gatt_ccc_managed_user_data[]){BT_GATT_CCC_MANAGED_USER_DATA_INIT( \
67+
_changed, bt_audio_ccc_cfg_write, NULL)}), \
6768
(BT_GATT_PERM_READ | BT_GATT_PERM_WRITE_ENCRYPT))
6869

6970
static inline const char *bt_audio_dir_str(enum bt_audio_dir dir)

subsys/bluetooth/host/gatt.c

+16-17
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,8 @@ static ssize_t sc_ccc_cfg_write(struct bt_conn *conn,
486486
return sizeof(value);
487487
}
488488

489-
static struct _bt_gatt_ccc sc_ccc = BT_GATT_CCC_INITIALIZER(NULL,
490-
sc_ccc_cfg_write,
491-
NULL);
489+
static struct bt_gatt_ccc_managed_user_data sc_ccc =
490+
BT_GATT_CCC_MANAGED_USER_DATA_INIT(NULL, sc_ccc_cfg_write, NULL);
492491

493492
/* Do not shuffle the values in this enum, they are used as bit offsets when
494493
* saving the CF flags to NVS (i.e. NVS persists between FW upgrades).
@@ -1118,7 +1117,7 @@ struct addr_match {
11181117
static uint8_t convert_to_id_on_match(const struct bt_gatt_attr *attr,
11191118
uint16_t handle, void *user_data)
11201119
{
1121-
struct _bt_gatt_ccc *ccc;
1120+
struct bt_gatt_ccc_managed_user_data *ccc;
11221121
struct addr_match *match = user_data;
11231122

11241123
if (!is_host_managed_ccc(attr)) {
@@ -1644,7 +1643,7 @@ static void db_changed(void)
16441643
#endif
16451644
}
16461645

1647-
static void gatt_unregister_ccc(struct _bt_gatt_ccc *ccc)
1646+
static void gatt_unregister_ccc(struct bt_gatt_ccc_managed_user_data *ccc)
16481647
{
16491648
ccc->value = 0;
16501649

@@ -2127,7 +2126,7 @@ struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr)
21272126
}
21282127

21292128
static struct bt_gatt_ccc_cfg *find_ccc_cfg(const struct bt_conn *conn,
2130-
struct _bt_gatt_ccc *ccc)
2129+
struct bt_gatt_ccc_managed_user_data *ccc)
21312130
{
21322131
for (size_t i = 0; i < ARRAY_SIZE(ccc->cfg); i++) {
21332132
struct bt_gatt_ccc_cfg *cfg = &ccc->cfg[i];
@@ -2149,7 +2148,7 @@ ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
21492148
const struct bt_gatt_attr *attr, void *buf,
21502149
uint16_t len, uint16_t offset)
21512150
{
2152-
struct _bt_gatt_ccc *ccc = attr->user_data;
2151+
struct bt_gatt_ccc_managed_user_data *ccc = attr->user_data;
21532152
const struct bt_gatt_ccc_cfg *cfg;
21542153
uint16_t value;
21552154

@@ -2166,7 +2165,7 @@ ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
21662165
}
21672166

21682167
static void gatt_ccc_changed(const struct bt_gatt_attr *attr,
2169-
struct _bt_gatt_ccc *ccc)
2168+
struct bt_gatt_ccc_managed_user_data *ccc)
21702169
{
21712170
int i;
21722171
uint16_t value = 0x0000;
@@ -2200,7 +2199,7 @@ ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
22002199
const struct bt_gatt_attr *attr, const void *buf,
22012200
uint16_t len, uint16_t offset, uint8_t flags)
22022201
{
2203-
struct _bt_gatt_ccc *ccc = attr->user_data;
2202+
struct bt_gatt_ccc_managed_user_data *ccc = attr->user_data;
22042203
struct bt_gatt_ccc_cfg *cfg;
22052204
bool value_changed;
22062205
uint16_t value;
@@ -2732,7 +2731,7 @@ static uint8_t notify_cb(const struct bt_gatt_attr *attr, uint16_t handle,
27322731
void *user_data)
27332732
{
27342733
struct notify_data *data = user_data;
2735-
struct _bt_gatt_ccc *ccc;
2734+
struct bt_gatt_ccc_managed_user_data *ccc;
27362735
size_t i;
27372736

27382737
if (!is_host_managed_ccc(attr)) {
@@ -3321,7 +3320,7 @@ static uint8_t update_ccc(const struct bt_gatt_attr *attr, uint16_t handle,
33213320
{
33223321
struct conn_data *data = user_data;
33233322
struct bt_conn *conn = data->conn;
3324-
struct _bt_gatt_ccc *ccc;
3323+
struct bt_gatt_ccc_managed_user_data *ccc;
33253324
size_t i;
33263325
uint8_t err;
33273326

@@ -3383,7 +3382,7 @@ static uint8_t disconnected_cb(const struct bt_gatt_attr *attr, uint16_t handle,
33833382
void *user_data)
33843383
{
33853384
struct bt_conn *conn = user_data;
3386-
struct _bt_gatt_ccc *ccc;
3385+
struct bt_gatt_ccc_managed_user_data *ccc;
33873386
bool value_used;
33883387
size_t i;
33893388

@@ -5724,7 +5723,7 @@ static struct bt_gatt_exchange_params gatt_exchange_params = {
57245723
#define CCC_STORE_MAX 0
57255724
#endif /* defined(CONFIG_BT_SETTINGS_CCC_STORE_MAX) */
57265725

5727-
static struct bt_gatt_ccc_cfg *ccc_find_cfg(struct _bt_gatt_ccc *ccc,
5726+
static struct bt_gatt_ccc_cfg *ccc_find_cfg(struct bt_gatt_ccc_managed_user_data *ccc,
57285727
const bt_addr_le_t *addr,
57295728
uint8_t id)
57305729
{
@@ -5749,7 +5748,7 @@ struct ccc_load {
57495748
size_t count;
57505749
};
57515750

5752-
static void ccc_clear(struct _bt_gatt_ccc *ccc,
5751+
static void ccc_clear(struct bt_gatt_ccc_managed_user_data *ccc,
57535752
const bt_addr_le_t *addr,
57545753
uint8_t id)
57555754
{
@@ -5768,7 +5767,7 @@ static uint8_t ccc_load(const struct bt_gatt_attr *attr, uint16_t handle,
57685767
void *user_data)
57695768
{
57705769
struct ccc_load *load = user_data;
5771-
struct _bt_gatt_ccc *ccc;
5770+
struct bt_gatt_ccc_managed_user_data *ccc;
57725771
struct bt_gatt_ccc_cfg *cfg;
57735772

57745773
if (!is_host_managed_ccc(attr)) {
@@ -6107,7 +6106,7 @@ static uint8_t ccc_save(const struct bt_gatt_attr *attr, uint16_t handle,
61076106
void *user_data)
61086107
{
61096108
struct ccc_save *save = user_data;
6110-
struct _bt_gatt_ccc *ccc;
6109+
struct bt_gatt_ccc_managed_user_data *ccc;
61116110
struct bt_gatt_ccc_cfg *cfg;
61126111

61136112
if (!is_host_managed_ccc(attr)) {
@@ -6390,7 +6389,7 @@ static uint8_t remove_peer_from_attr(const struct bt_gatt_attr *attr,
63906389
uint16_t handle, void *user_data)
63916390
{
63926391
const struct addr_with_id *addr_with_id = user_data;
6393-
struct _bt_gatt_ccc *ccc;
6392+
struct bt_gatt_ccc_managed_user_data *ccc;
63946393
struct bt_gatt_ccc_cfg *cfg;
63956394

63966395
if (!is_host_managed_ccc(attr)) {

subsys/bluetooth/host/shell/gatt.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ static int cmd_show_db(const struct shell *sh, size_t argc, char *argv[])
740740
total_len = stats.svc_count * sizeof(struct bt_gatt_service);
741741
total_len += stats.chrc_count * sizeof(struct bt_gatt_chrc);
742742
total_len += stats.attr_count * sizeof(struct bt_gatt_attr);
743-
total_len += stats.ccc_count * sizeof(struct _bt_gatt_ccc);
743+
total_len += stats.ccc_count * sizeof(struct bt_gatt_ccc_managed_user_data);
744744

745745
shell_print(sh, "=================================================");
746746
shell_print(sh, "Total: %u services %u attributes (%zu bytes)",

subsys/bluetooth/mesh/pb_gatt_srv.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ static ssize_t prov_ccc_write(struct bt_conn *conn,
149149
}
150150

151151
/* Mesh Provisioning Service Declaration */
152-
static struct _bt_gatt_ccc prov_ccc =
153-
BT_GATT_CCC_INITIALIZER(prov_ccc_changed, prov_ccc_write, NULL);
152+
static struct bt_gatt_ccc_managed_user_data prov_ccc =
153+
BT_GATT_CCC_MANAGED_USER_DATA_INIT(prov_ccc_changed, prov_ccc_write, NULL);
154154

155155
static struct bt_gatt_attr prov_attrs[] = {
156156
BT_GATT_PRIMARY_SERVICE(BT_UUID_MESH_PROV),

subsys/bluetooth/mesh/proxy_srv.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,8 @@ static ssize_t proxy_ccc_write(struct bt_conn *conn,
937937
}
938938

939939
/* Mesh Proxy Service Declaration */
940-
static struct _bt_gatt_ccc proxy_ccc =
941-
BT_GATT_CCC_INITIALIZER(proxy_ccc_changed, proxy_ccc_write, NULL);
940+
static struct bt_gatt_ccc_managed_user_data proxy_ccc =
941+
BT_GATT_CCC_MANAGED_USER_DATA_INIT(proxy_ccc_changed, proxy_ccc_write, NULL);
942942

943943
static struct bt_gatt_attr proxy_attrs[] = {
944944
BT_GATT_PRIMARY_SERVICE(BT_UUID_MESH_PROXY),

subsys/bluetooth/services/ots/ots_internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct bt_gatt_ots_object {
120120
struct bt_gatt_ots_indicate {
121121
struct bt_gatt_indicate_params params;
122122
struct bt_gatt_attr attr;
123-
struct _bt_gatt_ccc ccc;
123+
struct bt_gatt_ccc_managed_user_data ccc;
124124
bool is_enabled;
125125
struct k_work work;
126126
uint8_t res[OACP_OLCP_RES_MAX_SIZE];

subsys/bluetooth/services/ots/ots_oacp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ void bt_gatt_ots_oacp_cfg_changed(const struct bt_gatt_attr *attr,
728728
uint16_t value)
729729
{
730730
struct bt_gatt_ots_indicate *oacp_ind =
731-
CONTAINER_OF((struct _bt_gatt_ccc *) attr->user_data,
731+
CONTAINER_OF((struct bt_gatt_ccc_managed_user_data *) attr->user_data,
732732
struct bt_gatt_ots_indicate, ccc);
733733

734734
LOG_DBG("Object Action Control Point CCCD value: 0x%04X", value);

subsys/bluetooth/services/ots/ots_olcp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ void bt_gatt_ots_olcp_cfg_changed(const struct bt_gatt_attr *attr,
311311
uint16_t value)
312312
{
313313
struct bt_gatt_ots_indicate *olcp_ind =
314-
CONTAINER_OF((struct _bt_gatt_ccc *) attr->user_data,
314+
CONTAINER_OF((struct bt_gatt_ccc_managed_user_data *) attr->user_data,
315315
struct bt_gatt_ots_indicate, ccc);
316316

317317
LOG_DBG("Object List Control Point CCCD value: 0x%04X", value);

tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/gatt_macs.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ extern "C" {
138138
*
139139
* Helper macro to declare a Managed CCC attribute.
140140
*
141-
* @param _ccc CCC attribute user data, shall point to a _bt_gatt_ccc.
141+
* @param _ccc CCC attribute user data, shall point to a bt_gatt_ccc_managed_user_data.
142142
* @param _perm CCC access permissions.
143143
* @param _handle Descriptor attribute handle.
144144
*/
@@ -161,7 +161,7 @@ extern "C" {
161161
* BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, \
162162
* bt_gatt_attr_read_ccc, \
163163
* bt_gatt_attr_write_ccc, \
164-
* (&(struct _bt_gatt_ccc) { \
164+
* (&(struct bt_gatt_ccc_managed_user_data) { \
165165
* .cfg = _cfg, \
166166
* .cfg_len = ARRAY_SIZE(_cfg), \
167167
* .cfg_changed = _cfg_changed \
@@ -177,10 +177,10 @@ extern "C" {
177177
* @param _cfg_changed Configuration changed callback.
178178
* @param _handle Descriptor attribute handle.
179179
*/
180-
#define BT_GATT_H_CCC(_cfg, _cfg_changed, _handle) \
181-
BT_GATT_H_MANAGED((&(struct _bt_gatt_ccc) \
182-
BT_GATT_CCC_INITIALIZER(_cfg_changed, NULL, NULL)),\
183-
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, _handle)
180+
#define BT_GATT_H_CCC(_cfg, _cfg_changed, _handle) \
181+
BT_GATT_H_MANAGED((&(struct bt_gatt_ccc_managed_user_data) \
182+
BT_GATT_CCC_MANAGED_USER_DATA_INIT(_cfg_changed, NULL, NULL)), \
183+
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, _handle)
184184

185185
/**
186186
* @brief Characteristic Extended Properties Declaration Macro.

0 commit comments

Comments
 (0)