@@ -47,6 +47,9 @@ struct bt_bap_unicast_client_ep {
47
47
struct bt_gatt_subscribe_params subscribe ;
48
48
struct bt_gatt_discover_params discover ;
49
49
struct bt_bap_ep ep ;
50
+
51
+ /* Bool to help handle different order of CP and ASE notification when releasing */
52
+ bool release_requested ;
50
53
};
51
54
52
55
static const struct bt_uuid * snk_uuid = BT_UUID_PACS_SNK ;
@@ -514,6 +517,8 @@ static struct bt_bap_ep *unicast_client_ep_get(struct bt_conn *conn, enum bt_aud
514
517
515
518
static void unicast_client_ep_idle_state (struct bt_bap_ep * ep )
516
519
{
520
+ struct bt_bap_unicast_client_ep * client_ep =
521
+ CONTAINER_OF (ep , struct bt_bap_unicast_client_ep , ep );
517
522
struct bt_bap_stream * stream = ep -> stream ;
518
523
const struct bt_bap_stream_ops * ops ;
519
524
@@ -538,6 +543,19 @@ static void unicast_client_ep_idle_state(struct bt_bap_ep *ep)
538
543
bt_bap_stream_reset (stream );
539
544
540
545
/* Notify upper layer */
546
+ if (client_ep -> release_requested ) {
547
+ /* In case that we get the idle state notification before the CP notification we
548
+ * trigger the CP callback now, as after this we won't be able to find the stream
549
+ * by the ASE ID
550
+ */
551
+ client_ep -> release_requested = false;
552
+
553
+ if (unicast_client_cbs -> release != NULL ) {
554
+ unicast_client_cbs -> release (stream , BT_BAP_ASCS_RSP_CODE_SUCCESS ,
555
+ BT_BAP_ASCS_REASON_NONE );
556
+ }
557
+ }
558
+
541
559
ops = stream -> ops ;
542
560
if (ops != NULL && ops -> released != NULL ) {
543
561
ops -> released (stream );
@@ -1244,6 +1262,7 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn,
1244
1262
rsp = net_buf_simple_pull_mem (& buf , sizeof (* rsp ));
1245
1263
1246
1264
for (uint8_t i = 0U ; i < rsp -> num_ase ; i ++ ) {
1265
+ struct bt_bap_unicast_client_ep * client_ep ;
1247
1266
struct bt_ascs_cp_ase_rsp * ase_rsp ;
1248
1267
struct bt_bap_stream * stream ;
1249
1268
@@ -1270,6 +1289,8 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn,
1270
1289
continue ;
1271
1290
}
1272
1291
1292
+ client_ep = CONTAINER_OF (stream -> ep , struct bt_bap_unicast_client_ep , ep );
1293
+
1273
1294
switch (rsp -> op ) {
1274
1295
case BT_ASCS_CONFIG_OP :
1275
1296
if (unicast_client_cbs -> config != NULL ) {
@@ -1308,7 +1329,12 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn,
1308
1329
}
1309
1330
break ;
1310
1331
case BT_ASCS_RELEASE_OP :
1311
- if (unicast_client_cbs -> release != NULL ) {
1332
+ if (client_ep -> release_requested ) {
1333
+ /* Set to false to only handle the callback here */
1334
+ client_ep -> release_requested = false;
1335
+ }
1336
+
1337
+ if (unicast_client_cbs -> config != NULL ) {
1312
1338
unicast_client_cbs -> release (stream , ase_rsp -> code , ase_rsp -> reason );
1313
1339
}
1314
1340
break ;
@@ -2699,6 +2725,7 @@ int bt_bap_unicast_client_stop(struct bt_bap_stream *stream)
2699
2725
2700
2726
int bt_bap_unicast_client_release (struct bt_bap_stream * stream )
2701
2727
{
2728
+ struct bt_bap_unicast_client_ep * client_ep ;
2702
2729
struct bt_bap_ep * ep = stream -> ep ;
2703
2730
struct net_buf_simple * buf ;
2704
2731
struct bt_ascs_disable_op * req ;
@@ -2731,7 +2758,15 @@ int bt_bap_unicast_client_release(struct bt_bap_stream *stream)
2731
2758
return 0 ;
2732
2759
}
2733
2760
2734
- return bt_bap_unicast_client_ep_send (stream -> conn , ep , buf );
2761
+ err = bt_bap_unicast_client_ep_send (stream -> conn , ep , buf );
2762
+ if (err != 0 ) {
2763
+ return err ;
2764
+ }
2765
+
2766
+ client_ep = CONTAINER_OF (ep , struct bt_bap_unicast_client_ep , ep );
2767
+ client_ep -> release_requested = true;
2768
+
2769
+ return 0 ;
2735
2770
}
2736
2771
2737
2772
static uint8_t unicast_client_cp_discover_func (struct bt_conn * conn ,
0 commit comments