Skip to content

Commit ec2c5b0

Browse files
Thalleynashif
authored andcommitted
Bluetooth: GATT: Replace magic number 0 with macro for auto ccc
Replace the magic number 0 with a #defined value for the auto CCC discovery feature. Signed-off-by: Emil Gydesen <[email protected]>
1 parent aaaffd2 commit ec2c5b0

File tree

18 files changed

+34
-45
lines changed

18 files changed

+34
-45
lines changed

include/zephyr/bluetooth/gatt.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,9 @@ enum {
16441644
BT_GATT_DISCOVER_STD_CHAR_DESC,
16451645
};
16461646

1647+
/** Handle value to denote that the CCC will be automatically discovered */
1648+
#define BT_GATT_AUTO_DISCOVER_CCC_HANDLE 0x0000U
1649+
16471650
/** @brief GATT Discover Attributes parameters */
16481651
struct bt_gatt_discover_params {
16491652
/** Discover UUID type */
@@ -2049,7 +2052,7 @@ struct bt_gatt_subscribe_params {
20492052
#if defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__)
20502053
/** Subscribe End handle (for automatic discovery) */
20512054
uint16_t end_handle;
2052-
/** Discover parameters used when ccc_handle = 0 */
2055+
/** Discover parameters used when ccc_handle = @ref BT_GATT_AUTO_DISCOVER_CCC_HANDLE */
20532056
struct bt_gatt_discover_params *disc_params;
20542057
#endif /* defined(CONFIG_BT_GATT_AUTO_DISCOVER_CCC) || defined(__DOXYGEN__) */
20552058
/** Subscribe value */

samples/bluetooth/central_otc/src/main.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ static int subscribe_func(void)
313313
oacp_sub_params = &otc.oacp_sub_params;
314314
oacp_sub_params->disc_params = &otc.oacp_sub_disc_params;
315315
if (oacp_sub_params) {
316-
/* With ccc_handle == 0 it will use auto discovery */
317-
oacp_sub_params->ccc_handle = 0;
316+
oacp_sub_params->ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
318317
oacp_sub_params->end_handle = otc.end_handle;
319318
oacp_sub_params->value = BT_GATT_CCC_INDICATE;
320319
oacp_sub_params->value_handle = otc.oacp_handle;
@@ -330,8 +329,7 @@ static int subscribe_func(void)
330329
olcp_sub_params = &otc.olcp_sub_params;
331330
olcp_sub_params->disc_params = &otc.olcp_sub_disc_params;
332331
if (olcp_sub_params) {
333-
/* With ccc_handle == 0 it will use auto discovery */
334-
olcp_sub_params->ccc_handle = 0;
332+
olcp_sub_params->ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
335333
olcp_sub_params->end_handle = otc.end_handle;
336334
olcp_sub_params->value = BT_GATT_CCC_INDICATE;
337335
olcp_sub_params->value_handle = otc.olcp_handle;

subsys/bluetooth/audio/bap_broadcast_assistant.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,8 @@ static uint8_t char_discover_func(struct bt_conn *conn,
701701
}
702702

703703
if (sub_params != NULL) {
704-
/* With ccc_handle == 0 it will use auto discovery */
705704
sub_params->end_handle = inst->end_handle;
706-
sub_params->ccc_handle = 0;
705+
sub_params->ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
707706
sub_params->value = BT_GATT_CCC_NOTIFY;
708707
sub_params->value_handle = attr->handle + 1;
709708
sub_params->notify = notify_handler;

subsys/bluetooth/audio/bap_unicast_client.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@ static int unicast_client_ep_subscribe(struct bt_conn *conn, struct bt_bap_ep *e
16561656
}
16571657

16581658
client_ep->subscribe.value_handle = client_ep->handle;
1659-
client_ep->subscribe.ccc_handle = 0x0000;
1659+
client_ep->subscribe.ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
16601660
client_ep->subscribe.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE;
16611661
client_ep->subscribe.disc_params = &client_ep->discover;
16621662
client_ep->subscribe.notify = unicast_client_ep_notify;
@@ -1749,7 +1749,7 @@ static void unicast_client_ep_set_cp(struct bt_conn *conn, uint16_t handle)
17491749
int err;
17501750

17511751
client->cp_subscribe.value_handle = handle;
1752-
client->cp_subscribe.ccc_handle = 0x0000;
1752+
client->cp_subscribe.ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
17531753
client->cp_subscribe.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE;
17541754
client->cp_subscribe.disc_params = &client->disc_params;
17551755
client->cp_subscribe.notify = unicast_client_cp_notify;
@@ -3777,7 +3777,7 @@ static uint8_t unicast_client_pacs_avail_ctx_discover_cb(struct bt_conn *conn,
37773777
if (sub_params->value_handle == 0) {
37783778
LOG_DBG("Subscribing to handle %u", value_handle);
37793779
sub_params->value_handle = value_handle;
3780-
sub_params->ccc_handle = 0x0000; /* auto discover ccc */
3780+
sub_params->ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
37813781
sub_params->end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE;
37823782
sub_params->disc_params = &uni_cli_insts[index].avail_ctx_cc_disc;
37833783
sub_params->notify = unicast_client_pacs_avail_ctx_notify_cb;
@@ -3976,7 +3976,7 @@ static uint8_t unicast_client_pacs_location_discover_cb(struct bt_conn *conn,
39763976
}
39773977

39783978
sub_params->value_handle = value_handle;
3979-
sub_params->ccc_handle = 0x0000; /* auto discover ccc */
3979+
sub_params->ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
39803980
sub_params->end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE;
39813981
sub_params->disc_params = &uni_cli_insts[index].loc_cc_disc;
39823982
sub_params->notify = unicast_client_pacs_location_notify_cb;

subsys/bluetooth/audio/csip_set_coordinator.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,7 @@ static uint8_t discover_func(struct bt_conn *conn,
764764
if (sub_params->value != 0) {
765765
int err;
766766

767-
/* With ccc_handle == 0 it will use auto discovery */
768-
sub_params->ccc_handle = 0;
767+
sub_params->ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
769768
sub_params->end_handle = client->cur_inst->end_handle;
770769
sub_params->value_handle = chrc->value_handle;
771770
sub_params->notify = notify_handler;

subsys/bluetooth/audio/has_client.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ static int active_index_subscribe(struct bt_has_client *inst, uint16_t value_han
441441
inst->active_index_subscription.notify = active_preset_notify_cb;
442442
inst->active_index_subscription.subscribe = active_index_subscribe_cb;
443443
inst->active_index_subscription.value_handle = value_handle;
444-
inst->active_index_subscription.ccc_handle = 0x0000;
444+
inst->active_index_subscription.ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
445445
inst->active_index_subscription.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE;
446446
inst->active_index_subscription.disc_params = &inst->params.discover;
447447
inst->active_index_subscription.value = BT_GATT_CCC_NOTIFY;
@@ -543,7 +543,7 @@ static int control_point_subscribe(struct bt_has_client *inst, uint16_t value_ha
543543
inst->control_point_subscription.notify = control_point_notify_cb;
544544
inst->control_point_subscription.subscribe = control_point_subscribe_cb;
545545
inst->control_point_subscription.value_handle = value_handle;
546-
inst->control_point_subscription.ccc_handle = 0x0000;
546+
inst->control_point_subscription.ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
547547
inst->control_point_subscription.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE;
548548
inst->control_point_subscription.disc_params = &inst->params.discover;
549549
atomic_set_bit(inst->control_point_subscription.flags, BT_GATT_SUBSCRIBE_FLAG_VOLATILE);
@@ -739,7 +739,7 @@ static int features_subscribe(struct bt_has_client *inst, uint16_t value_handle)
739739
inst->features_subscription.notify = features_notify_cb;
740740
inst->features_subscription.subscribe = features_subscribe_cb;
741741
inst->features_subscription.value_handle = value_handle;
742-
inst->features_subscription.ccc_handle = 0x0000;
742+
inst->features_subscription.ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
743743
inst->features_subscription.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE;
744744
inst->features_subscription.disc_params = &inst->params.discover;
745745
inst->features_subscription.value = BT_GATT_CCC_NOTIFY;

subsys/bluetooth/audio/mcc.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,8 +1439,7 @@ static uint8_t discover_otc_char_func(struct bt_conn *conn,
14391439
}
14401440

14411441
if (sub_params) {
1442-
/* With ccc_handle == 0 it will use auto discovery */
1443-
sub_params->ccc_handle = 0;
1442+
sub_params->ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
14441443
sub_params->end_handle = mcs_inst->otc.end_handle;
14451444
sub_params->value = BT_GATT_CCC_INDICATE;
14461445
sub_params->value_handle = chrc->value_handle;
@@ -1605,8 +1604,7 @@ static int do_subscribe(struct mcs_instance_t *mcs_inst, struct bt_conn *conn,
16051604
uint16_t handle,
16061605
struct bt_gatt_subscribe_params *sub_params)
16071606
{
1608-
/* With ccc_handle == 0 it will use auto discovery */
1609-
sub_params->ccc_handle = 0;
1607+
sub_params->ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
16101608
sub_params->end_handle = mcs_inst->end_handle;
16111609
sub_params->value_handle = handle;
16121610
sub_params->notify = mcs_notify_handler;

subsys/bluetooth/audio/micp_mic_ctlr.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,7 @@ static uint8_t micp_discover_func(struct bt_conn *conn,
423423
if (sub_params != NULL) {
424424
int err;
425425

426-
/* With ccc_handle == 0 it will use auto discovery */
427-
sub_params->ccc_handle = 0;
426+
sub_params->ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
428427
sub_params->end_handle = mic_ctlr->end_handle;
429428
sub_params->value = BT_GATT_CCC_NOTIFY;
430429
sub_params->value_handle = chrc->value_handle;

subsys/bluetooth/audio/tbs_client.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,8 +1692,7 @@ static uint8_t discover_func(struct bt_conn *conn,
16921692
if (sub_params->value != 0) {
16931693
int err;
16941694

1695-
/* Setting ccc_handle = will use auto discovery feature */
1696-
sub_params->ccc_handle = 0;
1695+
sub_params->ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
16971696
sub_params->end_handle = current_inst->end_handle;
16981697
sub_params->notify = notify_handler;
16991698
atomic_set_bit(sub_params->flags, BT_GATT_SUBSCRIBE_FLAG_VOLATILE);

subsys/bluetooth/audio/vcp_vol_ctlr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static uint8_t vcs_discover_func(struct bt_conn *conn,
480480
if (sub_params != NULL) {
481481
sub_params->value = BT_GATT_CCC_NOTIFY;
482482
sub_params->value_handle = chrc->value_handle;
483-
sub_params->ccc_handle = 0;
483+
sub_params->ccc_handle = BT_GATT_AUTO_DISCOVER_CCC_HANDLE;
484484
sub_params->end_handle = vol_ctlr->end_handle;
485485
sub_params->notify = vcp_vol_ctlr_notify_handler;
486486
atomic_set_bit(sub_params->flags, BT_GATT_SUBSCRIBE_FLAG_VOLATILE);

0 commit comments

Comments
 (0)