@@ -50,6 +50,7 @@ struct bt_bap_unicast_client_ep {
50
50
51
51
/* Bool to help handle different order of CP and ASE notification when releasing */
52
52
bool release_requested ;
53
+ bool cp_ntf_pending ;
53
54
};
54
55
55
56
static const struct bt_uuid * snk_uuid = BT_UUID_PACS_SNK ;
@@ -562,15 +563,19 @@ static int unicast_client_ep_idle_state(struct bt_bap_ep *ep)
562
563
563
564
/* Notify upper layer */
564
565
if (client_ep -> release_requested ) {
565
- /* In case that we get the idle state notification before the CP notification we
566
- * trigger the CP callback now, as after this we won't be able to find the stream
567
- * by the ASE ID
568
- */
569
566
client_ep -> release_requested = false;
570
567
571
- if (unicast_client_cbs != NULL && unicast_client_cbs -> release != NULL ) {
572
- unicast_client_cbs -> release (stream , BT_BAP_ASCS_RSP_CODE_SUCCESS ,
573
- BT_BAP_ASCS_REASON_NONE );
568
+ if (client_ep -> cp_ntf_pending ) {
569
+ /* In case that we get the idle state notification before the CP
570
+ * notification we trigger the CP callback now, as after this we won't be
571
+ * able to find the stream by the ASE ID
572
+ */
573
+ client_ep -> cp_ntf_pending = false;
574
+
575
+ if (unicast_client_cbs != NULL && unicast_client_cbs -> release != NULL ) {
576
+ unicast_client_cbs -> release (stream , BT_BAP_ASCS_RSP_CODE_SUCCESS ,
577
+ BT_BAP_ASCS_REASON_NONE );
578
+ }
574
579
}
575
580
}
576
581
@@ -1307,7 +1312,7 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn,
1307
1312
}
1308
1313
1309
1314
for (uint8_t i = 0U ; i < rsp -> num_ase ; i ++ ) {
1310
- struct bt_bap_unicast_client_ep * client_ep ;
1315
+ struct bt_bap_unicast_client_ep * client_ep = NULL ;
1311
1316
struct bt_ascs_cp_ase_rsp * ase_rsp ;
1312
1317
struct bt_bap_stream * stream ;
1313
1318
@@ -1331,6 +1336,9 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn,
1331
1336
stream = audio_stream_by_ep_id (conn , ase_rsp -> id );
1332
1337
if (stream == NULL ) {
1333
1338
LOG_DBG ("Could not find stream by id %u" , ase_rsp -> id );
1339
+ } else {
1340
+ client_ep = CONTAINER_OF (stream -> ep , struct bt_bap_unicast_client_ep , ep );
1341
+ client_ep -> cp_ntf_pending = false;
1334
1342
}
1335
1343
1336
1344
switch (rsp -> op ) {
@@ -1371,18 +1379,20 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn,
1371
1379
}
1372
1380
break ;
1373
1381
case BT_ASCS_RELEASE_OP :
1374
- if (stream != NULL ) {
1375
- client_ep = CONTAINER_OF (stream -> ep ,
1376
- struct bt_bap_unicast_client_ep , ep );
1377
-
1378
- if (client_ep -> release_requested ) {
1379
- /* Set to false to only handle the callback here */
1382
+ /* client_ep->release_requested is set to false if handled by the
1383
+ * endpoint notification handler
1384
+ */
1385
+ if (client_ep != NULL && client_ep -> release_requested ) {
1386
+ /* If request was reject, do not expect endpoint notifications */
1387
+ if (ase_rsp -> code != BT_BAP_ASCS_RSP_CODE_SUCCESS ) {
1388
+ client_ep -> cp_ntf_pending = false;
1380
1389
client_ep -> release_requested = false;
1381
1390
}
1382
- }
1383
1391
1384
- if (unicast_client_cbs -> release != NULL ) {
1385
- unicast_client_cbs -> release (stream , ase_rsp -> code , ase_rsp -> reason );
1392
+ if (unicast_client_cbs -> release != NULL ) {
1393
+ unicast_client_cbs -> release (stream , ase_rsp -> code ,
1394
+ ase_rsp -> reason );
1395
+ }
1386
1396
}
1387
1397
break ;
1388
1398
default :
@@ -2012,6 +2022,10 @@ int bt_bap_unicast_client_ep_send(struct bt_conn *conn, struct bt_bap_ep *ep,
2012
2022
reset_att_buf (client );
2013
2023
}
2014
2024
2025
+ if (err == 0 ) {
2026
+ client_ep -> cp_ntf_pending = true;
2027
+ }
2028
+
2015
2029
return err ;
2016
2030
}
2017
2031
@@ -2041,6 +2055,8 @@ static void unicast_client_reset(struct bt_bap_ep *ep)
2041
2055
client_ep -> cp_handle = 0U ;
2042
2056
client_ep -> handle = 0U ;
2043
2057
(void )memset (& client_ep -> discover , 0 , sizeof (client_ep -> discover ));
2058
+ client_ep -> release_requested = false;
2059
+ client_ep -> cp_ntf_pending = false;
2044
2060
/* Need to keep the subscribe params intact for the callback */
2045
2061
}
2046
2062
0 commit comments