@@ -981,27 +981,33 @@ NET_BUF_SIMPLE_DEFINE_STATIC(ase_buf, CONFIG_BT_L2CAP_TX_MTU);
981981static void ase_process (struct k_work * work )
982982{
983983 struct bt_ascs_ase * ase = CONTAINER_OF (work , struct bt_ascs_ase , work );
984+ struct bt_audio_ep * ep = & ase -> ep ;
985+ const struct bt_audio_iso * audio_iso = ep -> iso ;
986+ struct bt_audio_stream * stream = ep -> stream ;
987+ const uint8_t ep_state = ep -> status .state ;
988+ struct bt_conn * conn = ase -> ascs -> conn ;
984989
985- BT_DBG ("ase %p, ep %p, ep.stream %p" , ase , & ase -> ep , ase -> ep . stream );
990+ BT_DBG ("ase %p, ep %p, ep.stream %p" , ase , ep , stream );
986991
987- if (ase -> ascs -> conn != NULL &&
988- ase -> ascs -> conn -> state == BT_CONN_CONNECTED ) {
989- ascs_ep_get_status (& ase -> ep , & ase_buf );
992+ if (conn != NULL && conn -> state == BT_CONN_CONNECTED ) {
993+ ascs_ep_get_status (ep , & ase_buf );
990994
991- bt_gatt_notify (ase -> ascs -> conn , ase -> ep . server .attr ,
995+ bt_gatt_notify (conn , ep -> server .attr ,
992996 ase_buf .data , ase_buf .len );
993997 }
994998
995- if (ase -> ep .status .state == BT_AUDIO_EP_STATE_RELEASING ) {
996- struct bt_audio_stream * stream = ase -> ep .stream ;
999+ /* Stream shall be NULL in the idle state, and non-NULL otherwise */
1000+ __ASSERT (ep_state == BT_AUDIO_EP_STATE_IDLE ?
1001+ stream == NULL : stream != NULL ,
1002+ "stream is NULL" );
9971003
998- __ASSERT ( stream , "stream is NULL" );
1004+ if ( ep_state == BT_AUDIO_EP_STATE_RELEASING ) {
9991005
1000- if (ase -> ep . iso == NULL ||
1001- ase -> ep . iso -> iso_chan .state == BT_ISO_STATE_DISCONNECTED ) {
1002- ascs_ep_unbind_audio_iso (& ase -> ep );
1006+ if (audio_iso == NULL ||
1007+ audio_iso -> iso_chan .state == BT_ISO_STATE_DISCONNECTED ) {
1008+ ascs_ep_unbind_audio_iso (ep );
10031009 bt_audio_stream_detach (stream );
1004- ascs_ep_set_state (& ase -> ep , BT_AUDIO_EP_STATE_IDLE );
1010+ ascs_ep_set_state (ep , BT_AUDIO_EP_STATE_IDLE );
10051011 } else {
10061012 /* Either the client or the server may disconnect the
10071013 * CISes when entering the releasing state.
@@ -1013,6 +1019,15 @@ static void ase_process(struct k_work *work)
10131019 stream , err );
10141020 }
10151021 }
1022+ } else if (ep_state == BT_AUDIO_EP_STATE_ENABLING ) {
1023+ /* SINK ASEs can autonomously go into the streaming state if
1024+ * the CIS is connected
1025+ */
1026+ if (ep -> dir == BT_AUDIO_DIR_SINK &&
1027+ audio_iso != NULL &&
1028+ audio_iso -> iso_chan .state == BT_ISO_STATE_CONNECTED ) {
1029+ ascs_ep_set_state (ep , BT_AUDIO_EP_STATE_STREAMING );
1030+ }
10161031 }
10171032}
10181033
@@ -1949,16 +1964,6 @@ static int ase_enable(struct bt_ascs_ase *ase, struct bt_ascs_metadata *meta,
19491964
19501965 ascs_ep_set_state (ep , BT_AUDIO_EP_STATE_ENABLING );
19511966
1952-
1953- if (ep -> dir == BT_AUDIO_DIR_SINK ) {
1954- /* SINK ASEs can autonomously go into the streaming state if
1955- * the CIS is connected
1956- */
1957- /* TODO: Verify that CIS is connected and set ep state to
1958- * BT_AUDIO_EP_STATE_STREAMING
1959- */
1960- }
1961-
19621967 ascs_cp_rsp_success (ASE_ID (ase ), BT_ASCS_ENABLE_OP );
19631968
19641969 return 0 ;
0 commit comments