@@ -61,7 +61,7 @@ static const struct bt_tbs_client_cb *tbs_client_cbs;
61
61
62
62
static struct bt_tbs_server_inst srv_insts [CONFIG_BT_MAX_CONN ];
63
63
64
- static void discover_next_instance (struct bt_conn * conn , uint8_t index );
64
+ static void discover_next_instance (struct bt_conn * conn );
65
65
66
66
typedef bool (* tbs_instance_find_func_t )(struct bt_tbs_instance * inst , void * user_data );
67
67
@@ -1346,7 +1346,6 @@ static uint8_t disc_read_ccid_cb(struct bt_conn *conn, uint8_t err,
1346
1346
const void * data , uint16_t length )
1347
1347
{
1348
1348
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 )];
1350
1349
uint8_t inst_index = tbs_index (conn , inst );
1351
1350
int cb_err = err ;
1352
1351
@@ -1369,21 +1368,7 @@ static uint8_t disc_read_ccid_cb(struct bt_conn *conn, uint8_t err,
1369
1368
if (cb_err != 0 ) {
1370
1369
tbs_client_discover_complete (conn , cb_err );
1371
1370
} 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 );
1387
1372
}
1388
1373
1389
1374
return BT_GATT_ITER_STOP ;
@@ -1420,6 +1405,8 @@ static uint8_t discover_func(struct bt_conn *conn,
1420
1405
#if defined(CONFIG_BT_TBS_CLIENT_CCID )
1421
1406
/* Read the CCID as the last part of discovering a TBS instance */
1422
1407
tbs_client_disc_read_ccid (conn );
1408
+ #else
1409
+ discover_next_instance (conn );
1423
1410
#endif /* defined(CONFIG_BT_TBS_CLIENT_CCID) */
1424
1411
1425
1412
return BT_GATT_ITER_STOP ;
@@ -1570,28 +1557,51 @@ static uint8_t discover_func(struct bt_conn *conn,
1570
1557
return BT_GATT_ITER_CONTINUE ;
1571
1558
}
1572
1559
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 )
1574
1582
{
1575
1583
int err ;
1576
1584
uint8_t conn_index = bt_conn_index (conn );
1577
1585
struct bt_tbs_server_inst * srv_inst = & srv_insts [conn_index ];
1578
1586
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 );
1595
1605
}
1596
1606
}
1597
1607
@@ -1604,10 +1614,10 @@ static void primary_discover_complete(struct bt_tbs_server_inst *server, struct
1604
1614
LOG_DBG ("Discover complete, found %u instances" , inst_cnt (server ));
1605
1615
}
1606
1616
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 );
1611
1621
} else {
1612
1622
tbs_client_discover_complete (conn , 0 );
1613
1623
}
0 commit comments