Skip to content

Commit 63a5f96

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. Signed-off-by: Aleksandr Khromykh <[email protected]>
1 parent 1e1f944 commit 63a5f96

File tree

10 files changed

+45
-35
lines changed

10 files changed

+45
-35
lines changed

include/zephyr/bluetooth/gatt.h

+20-10
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,8 +1121,8 @@ 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,
@@ -1145,7 +1151,10 @@ ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
11451151
*
11461152
* Helper macro to declare a Managed CCC attribute.
11471153
*
1148-
* @param _ccc CCC attribute user data, shall point to a _bt_gatt_ccc.
1154+
* @param _ccc A new @ref bt_gatt_ccc_managed_user_data object with the same lifetime
1155+
* as the results of the call to BT_GATT_CCC_MANAGED.
1156+
* See the documentation of @ref bt_gatt_ccc_managed_user_data on how
1157+
* to initialize it.
11491158
* @param _perm CCC access permissions,
11501159
* a bitmap of @ref bt_gatt_perm values.
11511160
*/
@@ -1163,9 +1172,10 @@ ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
11631172
* @param _perm CCC access permissions,
11641173
* a bitmap of @ref bt_gatt_perm values.
11651174
*/
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)
1175+
#define BT_GATT_CCC(_changed, _perm) \
1176+
BT_GATT_CCC_MANAGED(((struct bt_gatt_ccc_managed_user_data[]){ \
1177+
BT_GATT_CCC_INITIALIZER(_changed, NULL, NULL)}), \
1178+
_perm)
11691179

11701180
/**
11711181
* @brief Client Characteristic Configuration Declaration Macro with write callback.

subsys/bluetooth/audio/audio_internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ ssize_t bt_audio_ccc_cfg_write(struct bt_conn *conn, const struct bt_gatt_attr *
6262

6363
/** Helper to define LE Audio CCC descriptor. */
6464
#define BT_AUDIO_CCC(_changed) \
65-
BT_GATT_CCC_MANAGED(((struct _bt_gatt_ccc[]) \
65+
BT_GATT_CCC_MANAGED(((struct bt_gatt_ccc_managed_user_data[]) \
6666
{BT_GATT_CCC_INITIALIZER(_changed, bt_audio_ccc_cfg_write, NULL)}), \
6767
(BT_GATT_PERM_READ | BT_GATT_PERM_WRITE_ENCRYPT))
6868

subsys/bluetooth/host/gatt.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ 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,
489+
static struct bt_gatt_ccc_managed_user_data sc_ccc = BT_GATT_CCC_INITIALIZER(NULL,
490490
sc_ccc_cfg_write,
491491
NULL);
492492

@@ -1118,7 +1118,7 @@ struct addr_match {
11181118
static uint8_t convert_to_id_on_match(const struct bt_gatt_attr *attr,
11191119
uint16_t handle, void *user_data)
11201120
{
1121-
struct _bt_gatt_ccc *ccc;
1121+
struct bt_gatt_ccc_managed_user_data *ccc;
11221122
struct addr_match *match = user_data;
11231123

11241124
if (!is_host_managed_ccc(attr)) {
@@ -1644,7 +1644,7 @@ static void db_changed(void)
16441644
#endif
16451645
}
16461646

1647-
static void gatt_unregister_ccc(struct _bt_gatt_ccc *ccc)
1647+
static void gatt_unregister_ccc(struct bt_gatt_ccc_managed_user_data *ccc)
16481648
{
16491649
ccc->value = 0;
16501650

@@ -2127,7 +2127,7 @@ struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr)
21272127
}
21282128

21292129
static struct bt_gatt_ccc_cfg *find_ccc_cfg(const struct bt_conn *conn,
2130-
struct _bt_gatt_ccc *ccc)
2130+
struct bt_gatt_ccc_managed_user_data *ccc)
21312131
{
21322132
for (size_t i = 0; i < ARRAY_SIZE(ccc->cfg); i++) {
21332133
struct bt_gatt_ccc_cfg *cfg = &ccc->cfg[i];
@@ -2149,7 +2149,7 @@ ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
21492149
const struct bt_gatt_attr *attr, void *buf,
21502150
uint16_t len, uint16_t offset)
21512151
{
2152-
struct _bt_gatt_ccc *ccc = attr->user_data;
2152+
struct bt_gatt_ccc_managed_user_data *ccc = attr->user_data;
21532153
const struct bt_gatt_ccc_cfg *cfg;
21542154
uint16_t value;
21552155

@@ -2166,7 +2166,7 @@ ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn,
21662166
}
21672167

21682168
static void gatt_ccc_changed(const struct bt_gatt_attr *attr,
2169-
struct _bt_gatt_ccc *ccc)
2169+
struct bt_gatt_ccc_managed_user_data *ccc)
21702170
{
21712171
int i;
21722172
uint16_t value = 0x0000;
@@ -2200,7 +2200,7 @@ ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
22002200
const struct bt_gatt_attr *attr, const void *buf,
22012201
uint16_t len, uint16_t offset, uint8_t flags)
22022202
{
2203-
struct _bt_gatt_ccc *ccc = attr->user_data;
2203+
struct bt_gatt_ccc_managed_user_data *ccc = attr->user_data;
22042204
struct bt_gatt_ccc_cfg *cfg;
22052205
bool value_changed;
22062206
uint16_t value;
@@ -2732,7 +2732,7 @@ static uint8_t notify_cb(const struct bt_gatt_attr *attr, uint16_t handle,
27322732
void *user_data)
27332733
{
27342734
struct notify_data *data = user_data;
2735-
struct _bt_gatt_ccc *ccc;
2735+
struct bt_gatt_ccc_managed_user_data *ccc;
27362736
size_t i;
27372737

27382738
if (!is_host_managed_ccc(attr)) {
@@ -3321,7 +3321,7 @@ static uint8_t update_ccc(const struct bt_gatt_attr *attr, uint16_t handle,
33213321
{
33223322
struct conn_data *data = user_data;
33233323
struct bt_conn *conn = data->conn;
3324-
struct _bt_gatt_ccc *ccc;
3324+
struct bt_gatt_ccc_managed_user_data *ccc;
33253325
size_t i;
33263326
uint8_t err;
33273327

@@ -3383,7 +3383,7 @@ static uint8_t disconnected_cb(const struct bt_gatt_attr *attr, uint16_t handle,
33833383
void *user_data)
33843384
{
33853385
struct bt_conn *conn = user_data;
3386-
struct _bt_gatt_ccc *ccc;
3386+
struct bt_gatt_ccc_managed_user_data *ccc;
33873387
bool value_used;
33883388
size_t i;
33893389

@@ -5724,7 +5724,7 @@ static struct bt_gatt_exchange_params gatt_exchange_params = {
57245724
#define CCC_STORE_MAX 0
57255725
#endif /* defined(CONFIG_BT_SETTINGS_CCC_STORE_MAX) */
57265726

5727-
static struct bt_gatt_ccc_cfg *ccc_find_cfg(struct _bt_gatt_ccc *ccc,
5727+
static struct bt_gatt_ccc_cfg *ccc_find_cfg(struct bt_gatt_ccc_managed_user_data *ccc,
57285728
const bt_addr_le_t *addr,
57295729
uint8_t id)
57305730
{
@@ -5749,7 +5749,7 @@ struct ccc_load {
57495749
size_t count;
57505750
};
57515751

5752-
static void ccc_clear(struct _bt_gatt_ccc *ccc,
5752+
static void ccc_clear(struct bt_gatt_ccc_managed_user_data *ccc,
57535753
const bt_addr_le_t *addr,
57545754
uint8_t id)
57555755
{
@@ -5768,7 +5768,7 @@ static uint8_t ccc_load(const struct bt_gatt_attr *attr, uint16_t handle,
57685768
void *user_data)
57695769
{
57705770
struct ccc_load *load = user_data;
5771-
struct _bt_gatt_ccc *ccc;
5771+
struct bt_gatt_ccc_managed_user_data *ccc;
57725772
struct bt_gatt_ccc_cfg *cfg;
57735773

57745774
if (!is_host_managed_ccc(attr)) {
@@ -6107,7 +6107,7 @@ static uint8_t ccc_save(const struct bt_gatt_attr *attr, uint16_t handle,
61076107
void *user_data)
61086108
{
61096109
struct ccc_save *save = user_data;
6110-
struct _bt_gatt_ccc *ccc;
6110+
struct bt_gatt_ccc_managed_user_data *ccc;
61116111
struct bt_gatt_ccc_cfg *cfg;
61126112

61136113
if (!is_host_managed_ccc(attr)) {
@@ -6390,7 +6390,7 @@ static uint8_t remove_peer_from_attr(const struct bt_gatt_attr *attr,
63906390
uint16_t handle, void *user_data)
63916391
{
63926392
const struct addr_with_id *addr_with_id = user_data;
6393-
struct _bt_gatt_ccc *ccc;
6393+
struct bt_gatt_ccc_managed_user_data *ccc;
63946394
struct bt_gatt_ccc_cfg *cfg;
63956395

63966396
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ 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 =
152+
static struct bt_gatt_ccc_managed_user_data prov_ccc =
153153
BT_GATT_CCC_INITIALIZER(prov_ccc_changed, prov_ccc_write, NULL);
154154

155155
static struct bt_gatt_attr prov_attrs[] = {

subsys/bluetooth/mesh/proxy_srv.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ 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 =
940+
static struct bt_gatt_ccc_managed_user_data proxy_ccc =
941941
BT_GATT_CCC_INITIALIZER(proxy_ccc_changed, proxy_ccc_write, NULL);
942942

943943
static struct bt_gatt_attr proxy_attrs[] = {

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

+3-3
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 \
@@ -178,7 +178,7 @@ extern "C" {
178178
* @param _handle Descriptor attribute handle.
179179
*/
180180
#define BT_GATT_H_CCC(_cfg, _cfg_changed, _handle) \
181-
BT_GATT_H_MANAGED((&(struct _bt_gatt_ccc) \
181+
BT_GATT_H_MANAGED((&(struct bt_gatt_ccc_managed_user_data) \
182182
BT_GATT_CCC_INITIALIZER(_cfg_changed, NULL, NULL)),\
183183
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, _handle)
184184

0 commit comments

Comments
 (0)