Skip to content

Commit 75348f7

Browse files
committed
Bluetooth: BAP: Unicast: Add common state and ops checks
Add functions to collect the ASE state transtion and ASE operation checks Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
1 parent 9c1fbc8 commit 75348f7

File tree

4 files changed

+270
-379
lines changed

4 files changed

+270
-379
lines changed

subsys/bluetooth/audio/ascs.c

Lines changed: 1 addition & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -608,91 +608,9 @@ int ascs_ep_set_state(struct bt_bap_ep *ep, enum bt_bap_ep_state state)
608608
{
609609
struct bt_ascs_ase *ase = CONTAINER_OF(ep, struct bt_ascs_ase, ep);
610610
const enum bt_bap_ep_state old_state = ep->state;
611-
bool valid_state_transition = false;
612611
int err;
613612

614-
switch (state) {
615-
case BT_BAP_EP_STATE_IDLE:
616-
valid_state_transition = true;
617-
break;
618-
case BT_BAP_EP_STATE_CODEC_CONFIGURED:
619-
switch (old_state) {
620-
case BT_BAP_EP_STATE_IDLE:
621-
case BT_BAP_EP_STATE_CODEC_CONFIGURED:
622-
case BT_BAP_EP_STATE_QOS_CONFIGURED:
623-
case BT_BAP_EP_STATE_RELEASING:
624-
valid_state_transition = true;
625-
break;
626-
default:
627-
break;
628-
} break;
629-
case BT_BAP_EP_STATE_QOS_CONFIGURED:
630-
switch (old_state) {
631-
case BT_BAP_EP_STATE_CODEC_CONFIGURED:
632-
case BT_BAP_EP_STATE_QOS_CONFIGURED:
633-
valid_state_transition = true;
634-
break;
635-
case BT_BAP_EP_STATE_DISABLING:
636-
valid_state_transition = ep->dir == BT_AUDIO_DIR_SOURCE;
637-
break;
638-
case BT_BAP_EP_STATE_ENABLING:
639-
case BT_BAP_EP_STATE_STREAMING:
640-
/* Source ASE transition Streaming->QoS configured is valid on case of CIS
641-
* link-loss.
642-
*/
643-
valid_state_transition =
644-
ep->dir == BT_AUDIO_DIR_SINK || ase->unexpected_iso_link_loss;
645-
break;
646-
default:
647-
break;
648-
} break;
649-
case BT_BAP_EP_STATE_ENABLING:
650-
switch (old_state) {
651-
case BT_BAP_EP_STATE_QOS_CONFIGURED:
652-
case BT_BAP_EP_STATE_ENABLING:
653-
valid_state_transition = true;
654-
break;
655-
default:
656-
break;
657-
} break;
658-
case BT_BAP_EP_STATE_STREAMING:
659-
switch (old_state) {
660-
case BT_BAP_EP_STATE_ENABLING:
661-
case BT_BAP_EP_STATE_STREAMING:
662-
valid_state_transition = true;
663-
break;
664-
default:
665-
break;
666-
} break;
667-
case BT_BAP_EP_STATE_DISABLING:
668-
switch (old_state) {
669-
case BT_BAP_EP_STATE_ENABLING:
670-
case BT_BAP_EP_STATE_STREAMING:
671-
valid_state_transition = ep->dir == BT_AUDIO_DIR_SOURCE;
672-
break;
673-
default:
674-
break;
675-
} break;
676-
case BT_BAP_EP_STATE_RELEASING:
677-
switch (old_state) {
678-
case BT_BAP_EP_STATE_CODEC_CONFIGURED:
679-
case BT_BAP_EP_STATE_QOS_CONFIGURED:
680-
case BT_BAP_EP_STATE_ENABLING:
681-
case BT_BAP_EP_STATE_STREAMING:
682-
valid_state_transition = true;
683-
break;
684-
case BT_BAP_EP_STATE_DISABLING:
685-
valid_state_transition = ep->dir == BT_AUDIO_DIR_SOURCE;
686-
break;
687-
default:
688-
break;
689-
} break;
690-
default:
691-
__ASSERT_PRINT("Unhandled state %d", state);
692-
break;
693-
}
694-
695-
if (!valid_state_transition) {
613+
if (!bt_bap_stream_valid_state_transition(ep, state)) {
696614
BT_ASSERT_MSG(false, "Invalid state transition: %s -> %s",
697615
bt_bap_ep_state_str(old_state), bt_bap_ep_state_str(state));
698616

0 commit comments

Comments
 (0)