1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "avctp_ctrl.h"
16 #include "avctp_ctrl_act.h"
17 #include "avctp_st.h"
18 #include "log.h"
19 
20 /*****************************************************************************
21  * Type  Define
22  ****************************************************************************/
23 /* type for state table action functions */
24 typedef uint16_t (*AvctCtrlAction_t)(AvctCbDev *cbDev, const AvctEvtData *data);
25 
26 /*****************************************************************************
27  * Globle Data  Define
28  ****************************************************************************/
29 const AvctCtrlAction_t C_AVCT_CTRL_ACTION[] = {
30     AvctCbCtrlChConn,         /* AVCT_CHANNEL_CONN */
31     AvctCbCtrlChBind,         /* AVCT_CHANNEL_BIND */
32     AvctCbCtrlChBindFail,     /* AVCT_CHANNEL_BIND_FAIL */
33     AvctCbCtrlChDisconn,      /* AVCT_CHANNEL_DISCONNECT */
34     AvctCbCtrlChUnbind,       /* AVCT_CHANNEL_UNBIND */
35     AvctCbCtrlChCheckDisconn, /* AVCT_CHANNEL_CHECK_DISCONNECT */
36     AvctCbCtrlSendMsg,        /* AVCT_SEND_MSG */
37     AvctCbCtrlDiscardMsg,     /* AVCT_DISCARD_MSG */
38     AvctCbCtrlChConnInd,      /* AVCT_CONN_IND */
39     AvctCbCtrlChConnFail,     /* AVCT_CONN_FAIL */
40     AvctCbCtrlChCloseInd,     /* AVCT_DISCONN_IND */
41     AvctCbCtrlChCloseCfm,     /* AVCT_DISCONN_CFM */
42     AvctCbCtrlRevMsg,         /* AVCT_REV_MSG */
43     AvctCbCtrlDiscardRevMsg,  /* AVCT_DISCARD_REV_MSG */
44     AvctCbCtrlChBusyInd,      /* AVCT_BUSY_IND */
45 };
46 
47 /*****************************************************************************
48  * Function
49  ****************************************************************************/
50 /*
51  * Function     AvctCbCtrlEvt
52  * Description  This function is called to sent event to event table,and call
53  * the action. Param[in]   cbCtrl  point of the control channel block
54  * Param[in]   event  event iD
55  * Param[in]   data  date to send
56  * Return      void
57  */
AvctCbCtrlEvt(AvctCbDev * cbDev,uint8_t event,const AvctEvtData * data)58 uint16_t AvctCbCtrlEvt(AvctCbDev *cbDev, uint8_t event, const AvctEvtData *data)
59 {
60     LOG_DEBUG("[AVCT] %{public}s: EventID(%hhu),curState(%hhu)", __func__, event, cbDev->cbCtrl->stState);
61     uint16_t ret = AVCT_SUCCESS;
62     AvctCbCh *cbCtrl = cbDev->cbCtrl;
63     uint8_t curSt = cbCtrl->stState;
64     uint8_t nextSt = AvctGetNextStation(curSt, event);
65     uint8_t action = AvctGetEvtAction(curSt, event);
66     /* Set next state */
67     cbCtrl->stState = nextSt;
68 
69     /* excute actoin */
70     if (action != AVCT_IGNORE) {
71         ret = (*C_AVCT_CTRL_ACTION[action])(cbDev, data);
72     }
73     return ret;
74 }