Skip to content

Commit f3f8380

Browse files
Thalleynashif
authored andcommitted
Bluetooth: BAP: modify when ASCS disconnects the CIS
When an audio stream in a bidirectional CIS is released, it should not disconnect the CIS if there is still a stream for the opposite direction streaming. Only if both streams are not in a streaming state, should ASCS attempt to disconnect the CIS. Signed-off-by: Emil Gydesen <[email protected]>
1 parent bc89eab commit f3f8380

File tree

4 files changed

+55
-50
lines changed

4 files changed

+55
-50
lines changed

subsys/bluetooth/audio/ascs.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,7 @@ void ascs_ep_set_state(struct bt_bap_ep *ep, uint8_t state)
436436

437437
ep->receiver_ready = false;
438438

439-
if (ep->iso == NULL ||
440-
ep->iso->chan.state == BT_ISO_STATE_DISCONNECTED) {
441-
ascs_ep_set_state(ep, BT_BAP_EP_STATE_IDLE);
442-
} else {
439+
if (bt_bap_stream_can_disconnect(stream)) {
443440
/* Either the client or the server may disconnect the
444441
* CISes when entering the releasing state.
445442
*/
@@ -449,6 +446,8 @@ void ascs_ep_set_state(struct bt_bap_ep *ep, uint8_t state)
449446
LOG_ERR("Failed to disconnect stream %p: %d",
450447
stream, err);
451448
}
449+
} else {
450+
ascs_ep_set_state(ep, BT_BAP_EP_STATE_IDLE);
452451
}
453452

454453
break;
@@ -2480,9 +2479,7 @@ static void ase_stop(struct bt_ascs_ase *ase)
24802479
* for that ASE by following the Connected Isochronous Stream Terminate
24812480
* procedure defined in Volume 3, Part C, Section 9.3.15.
24822481
*/
2483-
if (ep->iso != NULL &&
2484-
ep->iso->chan.state != BT_ISO_STATE_DISCONNECTED &&
2485-
ep->iso->chan.state != BT_ISO_STATE_DISCONNECTING) {
2482+
if (bt_bap_stream_can_disconnect(stream)) {
24862483
err = ascs_disconnect_stream(stream);
24872484
if (err < 0) {
24882485
LOG_ERR("Failed to disconnect stream %p: %d", stream, err);

subsys/bluetooth/audio/bap_stream.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,45 @@ int bt_bap_stream_send(struct bt_bap_stream *stream, struct net_buf *buf,
257257
#endif /* CONFIG_BT_AUDIO_TX */
258258

259259
#if defined(CONFIG_BT_BAP_UNICAST)
260+
261+
/** Checks if the stream can terminate the CIS
262+
*
263+
* If the CIS is used for another stream, or if the CIS is not in the connected
264+
* state it will return false.
265+
*/
266+
bool bt_bap_stream_can_disconnect(const struct bt_bap_stream *stream)
267+
{
268+
const struct bt_bap_ep *stream_ep;
269+
enum bt_iso_state iso_state;
270+
271+
if (stream == NULL) {
272+
return false;
273+
}
274+
275+
stream_ep = stream->ep;
276+
277+
if (stream_ep == NULL || stream_ep->iso == NULL) {
278+
return false;
279+
}
280+
281+
iso_state = stream_ep->iso->chan.state;
282+
283+
if (iso_state == BT_ISO_STATE_CONNECTED || iso_state == BT_ISO_STATE_CONNECTING) {
284+
const struct bt_bap_ep *pair_ep;
285+
286+
pair_ep = bt_bap_iso_get_paired_ep(stream_ep);
287+
288+
/* If there are no paired endpoint, or the paired endpoint is
289+
* not in the streaming state, we can disconnect the CIS
290+
*/
291+
if (pair_ep == NULL || pair_ep->status.state != BT_BAP_EP_STATE_STREAMING) {
292+
return true;
293+
}
294+
}
295+
296+
return false;
297+
}
298+
260299
static bool bt_bap_stream_is_broadcast(const struct bt_bap_stream *stream)
261300
{
262301
return (IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SOURCE) &&

subsys/bluetooth/audio/bap_stream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void bt_bap_stream_detach(struct bt_bap_stream *stream);
2727
enum bt_bap_ascs_reason bt_audio_verify_qos(const struct bt_codec_qos *qos);
2828
bool bt_audio_valid_codec_data(const struct bt_codec_data *data);
2929
bool bt_audio_valid_codec(const struct bt_codec *codec);
30-
30+
bool bt_bap_stream_can_disconnect(const struct bt_bap_stream *stream);
3131
enum bt_bap_ascs_reason bt_bap_stream_verify_qos(const struct bt_bap_stream *stream,
3232
const struct bt_codec_qos *qos);
3333

subsys/bluetooth/audio/bap_unicast_client.c

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ BUILD_ASSERT(CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 ||
4040
LOG_MODULE_REGISTER(bt_bap_unicast_client, CONFIG_BT_BAP_UNICAST_CLIENT_LOG_LEVEL);
4141

4242
#define PAC_DIR_UNUSED(dir) ((dir) != BT_AUDIO_DIR_SINK && (dir) != BT_AUDIO_DIR_SOURCE)
43-
4443
struct bt_bap_unicast_client_ep {
4544
uint16_t handle;
4645
uint16_t cp_handle;
@@ -162,44 +161,6 @@ static int unicast_client_send_start(struct bt_bap_ep *ep)
162161

163162
static int unicast_client_ep_idle_state(struct bt_bap_ep *ep);
164163

165-
/** Checks if the stream can terminate the CIS
166-
*
167-
* If the CIS is used for another stream, or if the CIS is not in the connected
168-
* state it will return false.
169-
*/
170-
static bool unicast_client_can_disconnect_stream(const struct bt_bap_stream *stream)
171-
{
172-
const struct bt_bap_ep *stream_ep;
173-
enum bt_iso_state iso_state;
174-
175-
if (stream == NULL) {
176-
return false;
177-
}
178-
179-
stream_ep = stream->ep;
180-
181-
if (stream_ep == NULL || stream_ep->iso == NULL) {
182-
return false;
183-
}
184-
185-
iso_state = stream_ep->iso->chan.state;
186-
187-
if (iso_state == BT_ISO_STATE_CONNECTED || iso_state == BT_ISO_STATE_CONNECTING) {
188-
const struct bt_bap_ep *pair_ep;
189-
190-
pair_ep = bt_bap_iso_get_paired_ep(stream_ep);
191-
192-
/* If there are no paired endpoint, or the paired endpoint is
193-
* not in the streaming state, we can disconnect the CIS
194-
*/
195-
if (pair_ep == NULL || pair_ep->status.state != BT_BAP_EP_STATE_STREAMING) {
196-
return true;
197-
}
198-
}
199-
200-
return false;
201-
}
202-
203164
static struct bt_bap_stream *audio_stream_by_ep_id(const struct bt_conn *conn,
204165
uint8_t id)
205166
{
@@ -581,7 +542,7 @@ static int unicast_client_ep_idle_state(struct bt_bap_ep *ep)
581542
}
582543

583544
/* If CIS is connected, disconnect and wait for CIS disconnection */
584-
if (unicast_client_can_disconnect_stream(stream)) {
545+
if (bt_bap_stream_can_disconnect(stream)) {
585546
int err;
586547

587548
LOG_DBG("Disconnecting stream");
@@ -652,11 +613,19 @@ static void unicast_client_ep_qos_update(struct bt_bap_ep *ep,
652613

653614
static void unicast_client_ep_config_state(struct bt_bap_ep *ep, struct net_buf_simple *buf)
654615
{
616+
struct bt_bap_unicast_client_ep *client_ep =
617+
CONTAINER_OF(ep, struct bt_bap_unicast_client_ep, ep);
655618
struct bt_ascs_ase_status_config *cfg;
656619
struct bt_codec_qos_pref *pref;
657620
struct bt_bap_stream *stream;
658621
void *cc;
659622

623+
if (client_ep->release_requested) {
624+
LOG_DBG("Released was requested, change local state to idle");
625+
ep->status.state = BT_BAP_EP_STATE_IDLE;
626+
unicast_client_ep_idle_state(ep);
627+
}
628+
660629
if (buf->len < sizeof(*cfg)) {
661630
LOG_ERR("Config status too short");
662631
return;
@@ -768,7 +737,7 @@ static void unicast_client_ep_qos_state(struct bt_bap_ep *ep, struct net_buf_sim
768737
stream->qos->latency, stream->qos->pd);
769738

770739
/* Disconnect ISO if connected */
771-
if (unicast_client_can_disconnect_stream(stream)) {
740+
if (bt_bap_stream_can_disconnect(stream)) {
772741
const int err = bt_bap_stream_disconnect(stream);
773742

774743
if (err != 0) {
@@ -931,7 +900,7 @@ static void unicast_client_ep_releasing_state(struct bt_bap_ep *ep, struct net_b
931900

932901
LOG_DBG("dir %s", bt_audio_dir_str(ep->dir));
933902

934-
if (unicast_client_can_disconnect_stream(stream)) {
903+
if (bt_bap_stream_can_disconnect(stream)) {
935904
/* The Unicast Client shall terminate any CIS established for
936905
* that ASE by following the Connected Isochronous Stream
937906
* Terminate procedure defined in Volume 3, Part C,

0 commit comments

Comments
 (0)