MAC Clean-up [Issue-ID: ODUHIGH-212]
[o-du/l2.git] / src / du_app / du_mgr_ex_ms.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17  *******************************************************************************/
18
19 /* This file contains message handling functionality for DU APP */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "legtp.h"
23 #include "lkw.h"
24 #include "lrg.x"
25 #include "lkw.x"
26 #include "du_app_mac_inf.h"
27 #include "du_cfg.h"
28 #include "E2AP-PDU.h"
29 #include "du_sctp.h"
30 #include "du_f1ap_msg_hdl.h"
31 #include "du_e2ap_msg_hdl.h"
32 #include "lsctp.h"
33 #include "legtp.h"
34 #include "du_app_mac_inf.h"
35 #include "du_ue_mgr.h"
36 #include "kwu.x"
37
38 extern S16 cmUnpkLkwCfgCfm(LkwCfgCfm func,Pst *pst, Buffer *mBuf);
39 extern S16 cmUnpkLkwCntrlCfm(LkwCntrlCfm func,Pst *pst, Buffer *mBuf);
40 extern S16 cmUnpkLrgCfgCfm(LrgCfgCfm func,Pst *pst, Buffer *mBuf);
41 extern S16 cmUnpkKwuDatInd(KwuDatInd func,Pst *pst, Buffer *mBuf);
42 extern S16 cmUnpkLrgSchCfgCfm(LrgSchCfgCfm func,Pst *pst,Buffer *mBuf);
43 /**************************************************************************
44  * @brief Task Initiation callback function. 
45  *
46  * @details
47  *
48  *     Function : duActvInit 
49  *    
50  *     Functionality:
51  *             This function is supplied as one of parameters during DU APP's 
52  *             task registration. SSI will invoke this function once, after
53  *             it creates and attaches this TAPA Task to a system task.
54  *     
55  * @param[in]  Ent entity, the entity ID of this task.     
56  * @param[in]  Inst inst, the instance ID of this task.
57  * @param[in]  Region region, the region ID registered for memory 
58  *              usage of this task.
59  * @param[in]  Reason reason.
60  * @return ROK     - success
61  *         RFAILED - failure
62  ***************************************************************************/
63 S16 duActvInit(Ent entity, Inst inst, Region region, Reason reason)
64 {
65    uint8_t id;
66
67    memset(&duCb, 0, sizeof(DuCb));
68
69    duCb.init.procId  = SFndProcId();
70    duCb.init.ent     = entity;
71    duCb.init.inst    = inst;
72    duCb.init.region  = region;
73    duCb.init.reason  = reason;
74    duCb.init.cfgDone = FALSE;
75    duCb.init.pool    = DU_POOL;
76    duCb.init.acnt    = FALSE;
77    duCb.init.trc     = FALSE;
78    duCb.init.usta    = TRUE;
79    duCb.mem.region   = DFLT_REGION;
80    duCb.mem.pool     = DU_POOL;
81
82    duCb.f1Status     = FALSE;
83    duCb.e2Status     = FALSE;
84
85    for(id = 0; id < MAX_NUM_CELL; id ++)
86    {
87       duCb.cfgCellLst[id] = NULL;
88       duCb.actvCellLst[id] = NULL;
89    }
90    duCb.numUe = 0;
91    memset(duCb.ueCcchCtxt, 0, MAX_NUM_UE * sizeof(UeCcchCtxt));
92    duCb.numCfgCells  = 0;
93    duCb.numActvCells = 0;
94
95    SSetProcId(DU_PROC);
96
97    return ROK;
98
99 }
100
101 /**************************************************************************
102  * @brief Task Activation callback function. 
103  *
104  * @details
105  *
106  *      Function : duActvTsk 
107  * 
108  *      Functionality:
109  *           Primitives invoked by DU APP's users/providers through
110  *           a loosely coupled interface arrive here by means of 
111  *           SSI's message handling. This API is registered with
112  *           SSI during the Task Registration of DU APP.
113  *     
114  * @param[in]  Pst     *pst, Post structure of the primitive.     
115  * @param[in]  Buffer *mBuf, Packed primitive parameters in the
116  *  buffer.
117  * @return ROK     - success
118  *         RFAILED - failure
119  *
120  ***************************************************************************/
121 S16 duActvTsk(Pst *pst, Buffer *mBuf)
122 {
123    S16 ret = ROK;
124
125    switch(pst->srcEnt)
126    {
127       case ENTDUAPP:
128          {
129             switch(pst->event)
130             {
131                case EVTCFG:
132                   {
133                      DU_LOG("\n****** Received initial configs at DU APP ******\n");
134                      duProcCfgComplete();
135                      SPutMsg(mBuf);
136                      break;
137                   }
138                default:
139                   {
140                      DU_LOG("\nDU_APP : Invalid event received at duActvTsk from ENTDUAPP");
141                      SPutMsg(mBuf);
142                      ret = RFAILED;
143                   }
144             }
145
146             break;
147          }
148       case ENTKW:
149          {
150             switch(pst->event)
151             {
152                case LKW_EVT_CFG_CFM:
153                   {
154                      ret = cmUnpkLkwCfgCfm(duHdlRlcCfgComplete, pst, mBuf);
155                      break;
156                   }
157                case LKW_EVT_CNTRL_CFM:
158                   {
159                      ret = cmUnpkLkwCntrlCfm(duHdlRlcCntrlCfgComplete, pst, mBuf);
160                      break;
161                   }
162                case LKW_EVT_STA_IND:
163                   {
164                      break;
165                   }
166                case KWU_EVT_DAT_IND:
167                   {
168                      ret = cmUnpkKwuDatInd(duHdlRlcUlData, pst, mBuf);
169                      break;
170                   }
171                default:
172                   {
173                      DU_LOG("\nDU_APP : Invalid event %d received at duActvTsk from ENTKW", \
174                            pst->event);
175                      SPutMsg(mBuf);
176                      ret = RFAILED;
177                   }
178             }
179             break;
180          }
181       case ENTRG:
182          {
183             switch(pst->event)
184             {
185                //Config complete
186                case EVTCFG:
187                   {
188                      SPutMsg(mBuf);
189                      break;
190                   }
191                case EVTLRGCFGCFM:
192                   {
193                      ret = cmUnpkLrgCfgCfm(duHdlMacCfgComplete, pst, mBuf);
194                      break;
195                   }
196                case EVTLRGCNTRLCFM:
197                   {
198                      break;
199                   }
200                case EVTMACSCHGENCFGCFM:
201                   {
202                      ret = cmUnpkLrgSchCfgCfm(duHdlSchCfgComplete, pst, mBuf);
203                      break;
204                   }
205                case EVENT_MAC_CELL_CONFIG_CFM:
206                   {
207                      ret = unpackMacCellCfgCfm(duHandleMacCellCfgCfm, pst, mBuf);
208                      break;
209                   }
210                case EVENT_MAC_SLOT_IND:
211                   {
212                      ret = unpackMacSlotInd(duHandleSlotInd, pst, mBuf);
213                      break;
214                   }
215                case EVENT_MAC_STOP_IND:
216                   {
217                      ret = unpackMacStopInd(duHandleStopInd, pst, mBuf);
218                      break;
219                   }
220                case EVENT_MAC_UL_CCCH_IND:
221                   {
222                      ret = unpackMacUlCcchInd(duHandleUlCcchInd, pst, mBuf);
223                      break;
224                   }
225                case EVENT_MAC_UE_CREATE_RSP:
226                   {
227                      ret = unpackDuMacUeCreateRsp(duHandleMacUeCreateRsp, pst, mBuf); 
228                      break;
229                   }
230
231                default:
232                   {
233                      DU_LOG("\nDU_APP : Invalid event received at duActvTsk from ENTRG");
234                      SPutMsg(mBuf);
235                      ret = RFAILED;
236                   }
237             }
238
239             break;
240          }
241       case ENTSCTP:
242          {
243             switch(pst->event)
244             {
245                case EVENT_CU_DATA:
246                   {
247                      F1APMsgHdlr(mBuf);
248                      break;
249                   }
250                case EVENT_SCTP_NTFY:
251                   {
252                      ret = cmUnpkSctpNtfy(duSctpNtfyHdl, pst, mBuf);
253                      break;
254                   }
255                case EVENT_RIC_DATA:
256                   {
257                      E2APMsgHdlr(mBuf);
258                      break;
259                   }
260                default:
261                   {
262                      DU_LOG("\nDU_APP : Invalid event received at duActvTsk from ENTSCTP");
263                      ret = RFAILED;
264                   }
265
266             }
267             SPutMsg(mBuf);
268             break;
269          }
270       case ENTEGTP:
271          {
272             switch(pst->event)
273             {
274                case EVTCFGCFM:
275                   {
276                      unpackEgtpCfgCfm(duHdlEgtpCfgComplete, mBuf);
277                      break;
278                   }
279                case EVTSRVOPENCFM:
280                   {
281                      unpackEgtpSrvOpenCfm(duHdlEgtpSrvOpenComplete, mBuf);
282                      break;
283                   }
284                case EVTTNLMGMTCFM:
285                   {
286                      unpackEgtpTnlMgmtCfm(duHdlEgtpTnlMgmtCfm, mBuf);
287                      break;
288                   }
289                default:
290                   {
291                      DU_LOG("\nDU_APP : Invalid event[%d] received at duActvTsk from ENTEGTP", pst->event);
292                      ret = RFAILED;
293                   }
294             }
295             SPutMsg(mBuf);
296             break;
297          }
298       default:
299          {
300             DU_LOG("\nDU_APP : DU APP can not process message from Entity %d", pst->srcEnt);
301             SPutMsg(mBuf);
302             ret = RFAILED;
303          }
304
305    }
306    SExitTsk();
307    return ret;
308 }
309
310 /**********************************************************************
311   End of file
312  **********************************************************************/