Skip to content

Commit 68ea1c4

Browse files
Thalleycarlescufi
authored andcommitted
Bluetooth: CAP: Fix issue with parallel CAP discover
The bt_cap_common_discover function relied on a global variable used to indicate that a discovery was in process. This global variable prevented multiple discoveries to take place on multiple ACL connections, where the intention was to stop multiple discoveries on the same ACL. This has been fixed by moving the variable into the struct bt_cap_common_client, so that it applies per connection, rather than a global check. Signed-off-by: Emil Gydesen <[email protected]>
1 parent d45b462 commit 68ea1c4

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

subsys/bluetooth/audio/cap_common.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ LOG_MODULE_REGISTER(bt_cap_common, CONFIG_BT_CAP_COMMON_LOG_LEVEL);
1717
static struct bt_cap_common_client bt_cap_common_clients[CONFIG_BT_MAX_CONN];
1818
static const struct bt_uuid *cas_uuid = BT_UUID_CAS;
1919
static struct bt_cap_common_proc active_proc;
20-
static bt_cap_common_discover_func_t discover_cb_func;
2120

2221
struct bt_cap_common_proc *bt_cap_common_get_active_proc(void)
2322
{
@@ -258,10 +257,13 @@ struct bt_cap_common_client *bt_cap_common_get_client(enum bt_cap_set_type type,
258257
static void cap_common_discover_complete(struct bt_conn *conn, int err,
259258
const struct bt_csip_set_coordinator_csis_inst *csis_inst)
260259
{
261-
if (discover_cb_func != NULL) {
262-
const bt_cap_common_discover_func_t cb_func = discover_cb_func;
260+
struct bt_cap_common_client *client;
261+
262+
client = bt_cap_common_get_client_by_acl(conn);
263+
if (client != NULL && client->discover_cb_func != NULL) {
264+
const bt_cap_common_discover_func_t cb_func = client->discover_cb_func;
263265

264-
discover_cb_func = NULL;
266+
client->discover_cb_func = NULL;
265267
cb_func(conn, err, csis_inst);
266268
}
267269
}
@@ -386,24 +388,26 @@ static uint8_t bt_cap_common_discover_cas_cb(struct bt_conn *conn, const struct
386388
int bt_cap_common_discover(struct bt_conn *conn, bt_cap_common_discover_func_t func)
387389
{
388390
struct bt_gatt_discover_params *param;
391+
struct bt_cap_common_client *client;
389392
int err;
390393

391-
if (discover_cb_func != NULL) {
394+
client = bt_cap_common_get_client_by_acl(conn);
395+
if (client->discover_cb_func != NULL) {
392396
return -EBUSY;
393397
}
394398

395-
param = &bt_cap_common_clients[bt_conn_index(conn)].param;
399+
param = &client->param;
396400
param->func = bt_cap_common_discover_cas_cb;
397401
param->uuid = cas_uuid;
398402
param->type = BT_GATT_DISCOVER_PRIMARY;
399403
param->start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE;
400404
param->end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE;
401405

402-
discover_cb_func = func;
406+
client->discover_cb_func = func;
403407

404408
err = bt_gatt_discover(conn, param);
405409
if (err != 0) {
406-
discover_cb_func = NULL;
410+
client->discover_cb_func = NULL;
407411

408412
/* Report expected possible errors */
409413
if (err == -ENOTCONN || err == -ENOMEM) {

subsys/bluetooth/audio/cap_internal.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ struct bt_cap_commander_proc_param {
101101
};
102102
};
103103

104+
typedef void (*bt_cap_common_discover_func_t)(
105+
struct bt_conn *conn, int err, const struct bt_csip_set_coordinator_csis_inst *csis_inst);
106+
104107
struct bt_cap_common_proc_param {
105108
union {
106109
#if defined(CONFIG_BT_CAP_INITIATOR_UNICAST)
@@ -133,6 +136,7 @@ struct bt_cap_common_proc {
133136
struct bt_cap_common_client {
134137
struct bt_conn *conn;
135138
struct bt_gatt_discover_params param;
139+
bt_cap_common_discover_func_t discover_cb_func;
136140
uint16_t csis_start_handle;
137141
const struct bt_csip_set_coordinator_csis_inst *csis_inst;
138142
bool cas_found;
@@ -158,7 +162,4 @@ struct bt_cap_common_client *
158162
bt_cap_common_get_client_by_csis(const struct bt_csip_set_coordinator_csis_inst *csis_inst);
159163
struct bt_cap_common_client *bt_cap_common_get_client(enum bt_cap_set_type type,
160164
const union bt_cap_set_member *member);
161-
162-
typedef void (*bt_cap_common_discover_func_t)(
163-
struct bt_conn *conn, int err, const struct bt_csip_set_coordinator_csis_inst *csis_inst);
164165
int bt_cap_common_discover(struct bt_conn *conn, bt_cap_common_discover_func_t func);

0 commit comments

Comments
 (0)