Skip to content

Commit fc21528

Browse files
MariuszSkamracarlescufi
authored andcommitted
Bluetooth: audio: tbs_client: Fix missing discovery complete event
This fixes missing Fix bt_tbs_client_cb.discover call that has been observed when CONFIG_BT_TBS_CLIENT_CCID was disabled. In such case the discovery proces was not finished from application point of view, as the callback was not called. Signed-off-by: Mariusz Skamra <[email protected]>
1 parent 2b27b4e commit fc21528

File tree

1 file changed

+48
-38
lines changed

1 file changed

+48
-38
lines changed

subsys/bluetooth/audio/tbs_client.c

+48-38
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static const struct bt_tbs_client_cb *tbs_client_cbs;
6161

6262
static struct bt_tbs_server_inst srv_insts[CONFIG_BT_MAX_CONN];
6363

64-
static void discover_next_instance(struct bt_conn *conn, uint8_t index);
64+
static void discover_next_instance(struct bt_conn *conn);
6565

6666
typedef bool (*tbs_instance_find_func_t)(struct bt_tbs_instance *inst, void *user_data);
6767

@@ -1346,7 +1346,6 @@ static uint8_t disc_read_ccid_cb(struct bt_conn *conn, uint8_t err,
13461346
const void *data, uint16_t length)
13471347
{
13481348
struct bt_tbs_instance *inst = CONTAINER_OF(params, struct bt_tbs_instance, read_params);
1349-
struct bt_tbs_server_inst *srv_inst = &srv_insts[bt_conn_index(conn)];
13501349
uint8_t inst_index = tbs_index(conn, inst);
13511350
int cb_err = err;
13521351

@@ -1369,21 +1368,7 @@ static uint8_t disc_read_ccid_cb(struct bt_conn *conn, uint8_t err,
13691368
if (cb_err != 0) {
13701369
tbs_client_discover_complete(conn, cb_err);
13711370
} else {
1372-
if (IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS) && inst_index == BT_TBS_GTBS_INDEX) {
1373-
LOG_DBG("Setup complete GTBS");
1374-
1375-
inst_index = 0;
1376-
} else {
1377-
inst_index++;
1378-
1379-
LOG_DBG("Setup complete for %u / %u TBS", inst_index, inst_cnt(srv_inst));
1380-
}
1381-
1382-
if (inst_index < inst_cnt(srv_inst)) {
1383-
discover_next_instance(conn, inst_index);
1384-
} else {
1385-
tbs_client_discover_complete(conn, 0);
1386-
}
1371+
discover_next_instance(conn);
13871372
}
13881373

13891374
return BT_GATT_ITER_STOP;
@@ -1420,6 +1405,8 @@ static uint8_t discover_func(struct bt_conn *conn,
14201405
#if defined(CONFIG_BT_TBS_CLIENT_CCID)
14211406
/* Read the CCID as the last part of discovering a TBS instance */
14221407
tbs_client_disc_read_ccid(conn);
1408+
#else
1409+
discover_next_instance(conn);
14231410
#endif /* defined(CONFIG_BT_TBS_CLIENT_CCID) */
14241411

14251412
return BT_GATT_ITER_STOP;
@@ -1570,28 +1557,51 @@ static uint8_t discover_func(struct bt_conn *conn,
15701557
return BT_GATT_ITER_CONTINUE;
15711558
}
15721559

1573-
static void discover_next_instance(struct bt_conn *conn, uint8_t index)
1560+
static struct bt_tbs_instance *get_next_instance(struct bt_conn *conn,
1561+
struct bt_tbs_server_inst *srv_inst)
1562+
{
1563+
uint8_t inst_index;
1564+
1565+
if (srv_inst->current_inst != NULL) {
1566+
inst_index = tbs_index(conn, srv_inst->current_inst);
1567+
if (inst_index == BT_TBS_GTBS_INDEX) {
1568+
inst_index = 0;
1569+
} else {
1570+
inst_index++;
1571+
}
1572+
1573+
return tbs_inst_by_index(conn, inst_index);
1574+
}
1575+
1576+
inst_index = gtbs_found(srv_inst) ? BT_TBS_GTBS_INDEX : 0;
1577+
1578+
return tbs_inst_by_index(conn, inst_index);
1579+
}
1580+
1581+
static void discover_next_instance(struct bt_conn *conn)
15741582
{
15751583
int err;
15761584
uint8_t conn_index = bt_conn_index(conn);
15771585
struct bt_tbs_server_inst *srv_inst = &srv_insts[conn_index];
15781586

1579-
srv_inst->current_inst = tbs_inst_by_index(conn, index);
1580-
if (srv_inst->current_inst != NULL) {
1581-
(void)memset(&srv_inst->discover_params, 0, sizeof(srv_inst->discover_params));
1582-
srv_inst->discover_params.uuid = NULL;
1583-
srv_inst->discover_params.start_handle = srv_inst->current_inst->start_handle;
1584-
srv_inst->discover_params.end_handle = srv_inst->current_inst->end_handle;
1585-
srv_inst->discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC;
1586-
srv_inst->discover_params.func = discover_func;
1587-
1588-
err = bt_gatt_discover(conn, &srv_inst->discover_params);
1589-
if (err != 0) {
1590-
tbs_client_discover_complete(conn, err);
1591-
}
1592-
} else {
1593-
__ASSERT_PRINT("srv_inst->current_inst was NULL for conn %p and index %u", conn,
1594-
index);
1587+
srv_inst->current_inst = get_next_instance(conn, srv_inst);
1588+
if (srv_inst->current_inst == NULL) {
1589+
tbs_client_discover_complete(conn, 0);
1590+
return;
1591+
}
1592+
1593+
LOG_DBG("inst_index %u", tbs_index(conn, srv_inst->current_inst));
1594+
1595+
(void)memset(&srv_inst->discover_params, 0, sizeof(srv_inst->discover_params));
1596+
srv_inst->discover_params.uuid = NULL;
1597+
srv_inst->discover_params.start_handle = srv_inst->current_inst->start_handle;
1598+
srv_inst->discover_params.end_handle = srv_inst->current_inst->end_handle;
1599+
srv_inst->discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC;
1600+
srv_inst->discover_params.func = discover_func;
1601+
1602+
err = bt_gatt_discover(conn, &srv_inst->discover_params);
1603+
if (err != 0) {
1604+
tbs_client_discover_complete(conn, err);
15951605
}
15961606
}
15971607

@@ -1604,10 +1614,10 @@ static void primary_discover_complete(struct bt_tbs_server_inst *server, struct
16041614
LOG_DBG("Discover complete, found %u instances", inst_cnt(server));
16051615
}
16061616

1607-
if (gtbs_found(server)) {
1608-
discover_next_instance(conn, BT_TBS_GTBS_INDEX);
1609-
} else if (inst_cnt(server) > 0) {
1610-
discover_next_instance(conn, 0);
1617+
server->current_inst = NULL;
1618+
1619+
if (gtbs_found(server) || inst_cnt(server) > 0) {
1620+
discover_next_instance(conn);
16111621
} else {
16121622
tbs_client_discover_complete(conn, 0);
16131623
}

0 commit comments

Comments
 (0)