Skip to content

Commit f5d0240

Browse files
committed
Bluetooth: BAP: Fix bad state check for broadcast sink
The state check used != instead of == to very that it entered the streaming state for all streams. Signed-off-by: Emil Gydesen <[email protected]>
1 parent b9fc4cc commit f5d0240

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

subsys/bluetooth/audio/bap_broadcast_sink.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -295,31 +295,30 @@ static void broadcast_sink_iso_recv(struct bt_iso_chan *chan,
295295
}
296296
}
297297

298-
/** Gets the "highest" state of all BIS in the broadcast sink */
299-
static enum bt_bap_ep_state broadcast_sink_get_state(struct bt_bap_broadcast_sink *sink)
298+
static bool broadcast_sink_is_in_state(struct bt_bap_broadcast_sink *sink,
299+
enum bt_bap_ep_state state)
300300
{
301-
enum bt_bap_ep_state state = BT_BAP_EP_STATE_IDLE;
302301
struct bt_bap_stream *stream;
303302

304303
if (sink == NULL) {
305304
LOG_DBG("sink is NULL");
306305

307-
return state;
306+
return state == BT_BAP_EP_STATE_IDLE;
308307
}
309308

310309
if (sys_slist_is_empty(&sink->streams)) {
311310
LOG_DBG("Sink does not have any streams");
312311

313-
return state;
312+
return state == BT_BAP_EP_STATE_IDLE;
314313
}
315314

316315
SYS_SLIST_FOR_EACH_CONTAINER(&sink->streams, stream, _node) {
317-
if (stream->ep != NULL) {
318-
state = MAX(state, stream->ep->status.state);
316+
if (stream->ep != NULL && stream->ep->status.state != state) {
317+
return false;
319318
}
320319
}
321320

322-
return state;
321+
return true;
323322
}
324323

325324
static void broadcast_sink_iso_connected(struct bt_iso_chan *chan)
@@ -362,7 +361,7 @@ static void broadcast_sink_iso_connected(struct bt_iso_chan *chan)
362361
LOG_WRN("No callback for started set");
363362
}
364363

365-
if (broadcast_sink_get_state(sink) != BT_BAP_EP_STATE_STREAMING) {
364+
if (broadcast_sink_is_in_state(sink, BT_BAP_EP_STATE_STREAMING)) {
366365
update_recv_state_big_synced(sink);
367366
}
368367
}
@@ -1291,7 +1290,6 @@ int bt_bap_broadcast_sink_sync(struct bt_bap_broadcast_sink *sink, uint32_t inde
12911290

12921291
int bt_bap_broadcast_sink_stop(struct bt_bap_broadcast_sink *sink)
12931292
{
1294-
enum bt_bap_ep_state state;
12951293
int err;
12961294

12971295
CHECKIF(sink == NULL) {
@@ -1304,9 +1302,8 @@ int bt_bap_broadcast_sink_stop(struct bt_bap_broadcast_sink *sink)
13041302
return -EALREADY;
13051303
}
13061304

1307-
state = broadcast_sink_get_state(sink);
1308-
if (state != BT_BAP_EP_STATE_STREAMING && state != BT_BAP_EP_STATE_QOS_CONFIGURED) {
1309-
LOG_DBG("Broadcast sink %p invalid state: %u", sink, state);
1305+
if (broadcast_sink_is_in_state(sink, BT_BAP_EP_STATE_IDLE)) {
1306+
LOG_DBG("Broadcast sink %p in idle state", sink);
13101307
return -EBADMSG;
13111308
}
13121309

@@ -1324,16 +1321,14 @@ int bt_bap_broadcast_sink_stop(struct bt_bap_broadcast_sink *sink)
13241321

13251322
int bt_bap_broadcast_sink_delete(struct bt_bap_broadcast_sink *sink)
13261323
{
1327-
enum bt_bap_ep_state state;
13281324

13291325
CHECKIF(sink == NULL) {
13301326
LOG_DBG("sink is NULL");
13311327
return -EINVAL;
13321328
}
13331329

1334-
state = broadcast_sink_get_state(sink);
1335-
if (state != BT_BAP_EP_STATE_IDLE) {
1336-
LOG_DBG("Broadcast sink %p invalid state: %u", sink, state);
1330+
if (!broadcast_sink_is_in_state(sink, BT_BAP_EP_STATE_IDLE)) {
1331+
LOG_DBG("Broadcast sink %p not in idle state", sink);
13371332
return -EBADMSG;
13381333
}
13391334

0 commit comments

Comments
 (0)