6241229d18153d67282a14b1e5fd28b225b5d07f
[o-du/l2.git] / src / du_app / du_mgr_msg_router.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 /* File : du_mgr_msg_router.c */
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 "lsctp.h"
24 #include "legtp.h"
25 #include "lkw.h"
26 #include "kwu.h"
27 #include "lrg.x"
28 #include "lkw.x"
29 #include "kwu.x"
30 #include "du_app_mac_inf.h"
31 #include "du_app_rlc_inf.h"
32 #include "du_cfg.h"
33 #include "du_mgr.h"
34 #include "E2AP-PDU.h"
35 #include "du_sctp.h"
36 #include "F1AP-PDU.h"
37 #include "du_f1ap_msg_hdl.h"
38 #include "du_e2ap_msg_hdl.h"
39 #include "du_app_mac_inf.h"
40 #include "du_ue_mgr.h"
41 #include "du_utils.h"
42
43 uint8_t unpackRlcConfigCfm(RlcConfigCfm func,Pst *pst, Buffer *mBuf);
44 uint8_t cmUnpkLkwCntrlCfm(LkwCntrlCfm func,Pst *pst, Buffer *mBuf);
45 uint8_t cmUnpkLrgCfgCfm(LrgCfgCfm func,Pst *pst, Buffer *mBuf);
46 uint8_t cmUnpkKwuDatInd(KwuDatInd func,Pst *pst, Buffer *mBuf);
47 uint8_t cmUnpkLrgSchCfgCfm(LrgSchCfgCfm func,Pst *pst,Buffer *mBuf);
48 /**************************************************************************
49  * @brief Task Initiation callback function. 
50  *
51  * @details
52  *
53  *     Function : duActvInit 
54  *    
55  *     Functionality:
56  *             This function is supplied as one of parameters during DU APP's 
57  *             task registration. SSI will invoke this function once, after
58  *             it creates and attaches this TAPA Task to a system task.
59  *     
60  * @param[in]  Ent entity, the entity ID of this task.     
61  * @param[in]  Inst inst, the instance ID of this task.
62  * @param[in]  Region region, the region ID registered for memory 
63  *              usage of this task.
64  * @param[in]  Reason reason.
65  * @return ROK     - success
66  *         RFAILED - failure
67  ***************************************************************************/
68 uint8_t duActvInit(Ent entity, Inst inst, Region region, Reason reason)
69 {
70    uint8_t id;
71
72    memset(&duCb, 0, sizeof(DuCb));
73
74    duCb.init.procId  = ODU_GET_PROCID();
75    duCb.init.ent     = entity;
76    duCb.init.inst    = inst;
77    duCb.init.region  = region;
78    duCb.init.reason  = reason;
79    duCb.init.cfgDone = FALSE;
80    duCb.init.pool    = DU_POOL;
81    duCb.init.acnt    = FALSE;
82    duCb.init.trc     = FALSE;
83    duCb.init.usta    = TRUE;
84    duCb.mem.region   = DFLT_REGION;
85    duCb.mem.pool     = DU_POOL;
86
87    duCb.f1Status     = FALSE;
88    duCb.e2Status     = FALSE;
89
90    for(id = 0; id < MAX_NUM_CELL; id ++)
91    {
92       duCb.cfgCellLst[id] = NULL;
93       duCb.actvCellLst[id] = NULL;
94    }
95    duCb.numUe = 0;
96    memset(duCb.ueCcchCtxt, 0, MAX_NUM_UE * sizeof(UeCcchCtxt));
97    duCb.numCfgCells  = 0;
98    duCb.numActvCells = 0;
99    cmLListInit(&duCb.reservedF1apPduList);
100    ODU_SET_PROC_ID(DU_PROC);
101
102    return ROK;
103
104 }
105
106 /**************************************************************************
107 * @brief Function prints the src dest and msg reached to egtp.
108 *
109 * @details
110 *
111 *      Function : callFlowduActvTsk 
112 *
113 *      Functionality:
114 *           Function prints the src dest and msg reached to egtp.
115 *
116 * @param[in]  Pst     *pst, Post structure of the primitive.
117 *
118 * @return void
119 *
120 +***************************************************************************/
121
122 void callFlowduActvTsk(Pst *pst)
123 {
124    char sourceTask[50];
125    char destTask[50]="ENTDUAPP";
126    char message[100];
127    
128    switch(pst->srcEnt)
129    {
130       case ENTDUAPP:
131          {
132             strcpy(sourceTask,"ENTDUAPP");
133             switch(pst->event)
134             {
135                case EVTCFG:
136                   {
137                      strcpy(message,"EVTCFG");
138                      break;
139                   }
140                default:
141                   {
142                      strcpy(message,"Invalid Event");
143                      break;
144                   }
145             }
146
147             break;
148          }
149       case ENTRLC:
150          {
151             strcpy(sourceTask,"ENTRLC");
152             switch(pst->event)
153             {
154                case LKW_EVT_CFG_CFM:
155                   {
156                      strcpy(message,"LKW_EVT_CFG_CFM");
157                      break;
158                   }
159                case LKW_EVT_CNTRL_CFM:
160                   {
161                      strcpy(message,"LKW_EVT_CNTRL_CFM");
162                      break;
163                   }
164                case LKW_EVT_STA_IND:
165                   {
166                      strcpy(message,"LKW_EVT_STA_IND");
167                      break;
168                   }
169                case EVENT_RLC_UE_CREATE_RSP:
170                   {
171                      strcpy(message,"EVENT_RLC_UE_CREATE_RSP");
172                      break;
173                   }
174                case EVENT_RLC_UE_RECONFIG_RSP:
175                   {
176                      strcpy(message,"EVENT_RLC_UE_RECONFIG_RSP");
177                      break;
178                   }
179                case EVENT_RLC_UE_DELETE_RSP:
180                   {
181                      strcpy(message,"EVENT_RLC_UE_DELETE_RSP");
182                      break;
183                   }
184                case EVENT_UL_RRC_MSG_TRANS_TO_DU:
185                   {
186                      strcpy(message,"EVENT_UL_RRC_MSG_TRANS_TO_DU");
187                      break;
188                   }
189                case EVENT_RRC_DELIVERY_MSG_TRANS_TO_DU:
190                   {
191                      strcpy(message,"EVENT_RRC_DELIVERY_MSG_TRANS_TO_DU");
192                      break;
193                   }
194                case EVENT_DL_RRC_MSG_RSP_TO_DU:
195                   {
196                      strcpy(message,"EVENT_DL_RRC_MSG_RSP_TO_DU");
197                      break;
198                   }
199                case EVENT_UL_USER_DATA_TRANS_TO_DU:
200                   {
201                      strcpy(message,"EVENT_UL_USER_DATA_TRANS_TO_DU");
202                      break;
203                   }
204                default:
205                   {
206                      strcpy(message,"Invalid Event");
207                   }
208             }
209             break;
210          }
211       case ENTMAC:
212          {
213             strcpy(sourceTask,"ENTMAC");
214             switch(pst->event)
215             {
216                case EVTCFG:
217                   {
218                      strcpy(message,"EVTCFG");
219                      break;
220                   }
221                case EVTLRGCFGCFM:
222                   {
223                      strcpy(message,"EVTLRGCFGCFM");
224                      break;
225                   }
226                case EVTLRGCNTRLCFM:
227                   {
228                      strcpy(message,"EVTLRGCNTRLCFM");
229                      break;
230                   }
231                case EVTMACSCHGENCFGCFM:
232                   {
233                      strcpy(message,"EVTMACSCHGENCFGCFM");
234                      break;
235                   }
236                case EVENT_MAC_CELL_CONFIG_CFM:
237                   {
238                      strcpy(message,"EVENT_MAC_CELL_CONFIG_CFM");
239                      break;
240                   }
241                case EVENT_MAC_CELL_UP_IND:
242                   {
243                      strcpy(message,"EVENT_MAC_CELL_UP_IND");
244                      break;
245                   }
246                case EVENT_MAC_STOP_IND:
247                   {
248                      strcpy(message,"EVENT_MAC_STOP_IND");
249                      break;
250                   }
251                case EVENT_MAC_UL_CCCH_IND:
252                   {
253                      strcpy(message,"EVENT_MAC_UL_CCCH_IND");
254                      break;
255                   }
256                case EVENT_MAC_UE_CREATE_RSP:
257                   {
258                      strcpy(message,"EVENT_MAC_UE_CREATE_RSP");
259                      break;
260                   }
261                case EVENT_MAC_UE_RECONFIG_RSP:
262                   {
263                      strcpy(message,"EVENT_MAC_UE_RECONFIG_RSP");
264                      break;
265                   }
266                case EVENT_MAC_UE_DELETE_RSP:
267                   {
268                      strcpy(message,"EVENT_MAC_UE_DELETE_RSP");
269                      break;
270                   }
271                case EVENT_MAC_CELL_DELETE_RSP:
272                   {
273                      strcpy(message,"EVENT_MAC_CELL_DELETE_RSP");
274                      break;
275                   }
276                default:
277                   {
278                      strcpy(message,"Invalid Event");
279                      break;
280                   }
281             }
282
283             break;
284          }
285       case ENTSCTP:
286          {
287             strcpy(sourceTask,"ENTSCTP");
288             switch(pst->event)
289             {
290                case EVENT_CU_DATA:
291                   {
292                      strcpy(message,"EVENT_CU_DATA");
293                      break;
294                   }
295                case EVENT_SCTP_NTFY:
296                   {
297                      strcpy(message,"EVENT_SCTP_NTFY");
298                      break;
299                   }
300                case EVENT_RIC_DATA:
301                   {
302                      strcpy(message,"EVENT_RIC_DATA");
303                      break;
304                   }
305                default:
306                   {
307                      strcpy(message,"Invalid Event");
308                      break;
309                   }
310
311             }
312             break;
313          }
314       case ENTEGTP:
315          {
316             strcpy(sourceTask,"ENTEGTP");
317             switch(pst->event)
318             {
319                case EVTCFGCFM:
320                   {
321                      strcpy(message,"EVTCFGCFM");
322                      break;
323                   }
324                case EVTSRVOPENCFM:
325                   {
326                      strcpy(message,"EVTSRVOPENCFM");
327                      break;
328                   }
329                case EVTTNLMGMTCFM:
330                   {
331                      strcpy(message,"EVTTNLMGMTCFM");
332                      break;
333                   }
334                default:
335                   {
336                      strcpy(message,"Invalid Event");
337                      break;
338                   }
339             }
340             break;
341          }
342       default:
343          {
344             strcpy(sourceTask,"Invalid Source Entity Id");
345             break;
346          }
347    }
348    DU_LOG("\nCall Flow: %s -> %s : %s\n", sourceTask, destTask, message);
349 }
350 /**************************************************************************
351  * @brief Task Activation callback function. 
352  *
353  * @details
354  *
355  *      Function : duActvTsk 
356  * 
357  *      Functionality:
358  *           Primitives invoked by DU APP's users/providers through
359  *           a loosely coupled interface arrive here by means of 
360  *           SSI's message handling. This API is registered with
361  *           SSI during the Task Registration of DU APP.
362  *     
363  * @param[in]  Pst     *pst, Post structure of the primitive.     
364  * @param[in]  Buffer *mBuf, Packed primitive parameters in the
365  *  buffer.
366  * @return ROK     - success
367  *         RFAILED - failure
368  *
369  ***************************************************************************/
370 uint8_t duActvTsk(Pst *pst, Buffer *mBuf)
371 {
372    uint8_t ret = ROK;
373    
374 #ifdef CALL_FLOW_DEBUG_LOG   
375    callFlowduActvTsk(pst);
376 #endif
377
378    switch(pst->srcEnt)
379    {
380       case ENTDUAPP:
381          {
382             switch(pst->event)
383             {
384                case EVTCFG:
385                   {
386                      DU_LOG("\n****** Received initial configs at DU APP ******\n");
387                      duProcCfgComplete();
388                      ODU_PUT_MSG_BUF(mBuf);
389                      break;
390                   }
391                default:
392                   {
393                      DU_LOG("\nERROR  -->  DU_APP : Invalid event received at duActvTsk from ENTDUAPP");
394                      ODU_PUT_MSG_BUF(mBuf);
395                      ret = RFAILED;
396                   }
397             }
398
399             break;
400          }
401       case ENTRLC:
402          {
403             switch(pst->event)
404             {
405                case LKW_EVT_CFG_CFM:
406                   {
407                      ret = unpackRlcConfigCfm(DuHdlRlcCfgComplete, pst, mBuf);
408                      break;
409                   }
410                case LKW_EVT_CNTRL_CFM:
411                   {
412                      ret = cmUnpkLkwCntrlCfm(duHdlRlcCntrlCfgComplete, pst, mBuf);
413                      break;
414                   }
415                case LKW_EVT_STA_IND:
416                   {
417                      break;
418                   }
419                case EVENT_RLC_UE_CREATE_RSP:
420                   {
421                      ret = unpackRlcUeCfgRsp(DuProcRlcUeCfgRsp, pst, mBuf);
422                      break;
423                   }
424                case EVENT_RLC_UE_RECONFIG_RSP:
425                   {
426                      ret = unpackRlcUeCfgRsp(DuProcRlcUeCfgRsp, pst, mBuf);
427                      break;
428                   }
429                case EVENT_RLC_UE_DELETE_RSP:
430                   {
431                      ret = unpackRlcUeDeleteRsp(DuProcRlcUeDeleteRsp, pst, mBuf);
432                      break;
433                   }
434                case EVENT_UL_RRC_MSG_TRANS_TO_DU:
435                   {
436                      ret = unpackRlcUlRrcMsgToDu(DuProcRlcUlRrcMsgTrans, pst, mBuf);
437                      break;
438                   }
439                case EVENT_RRC_DELIVERY_MSG_TRANS_TO_DU:
440                   {
441                      ret = unpackRrcDeliveryReportToDu(DuProcRlcRrcDeliveryReport, pst, mBuf);
442                      break;
443                   }
444                case EVENT_DL_RRC_MSG_RSP_TO_DU:
445                   {
446                      ret = unpackRlcDlRrcMsgRspToDu(DuProcRlcDlRrcMsgRsp, pst, mBuf);
447                      break;
448                   }
449                case EVENT_UL_USER_DATA_TRANS_TO_DU:
450                   {
451                      ret = unpackRlcUlUserDataToDu(DuProcRlcUlUserDataTrans, pst, mBuf);
452                      break;
453                   }
454                default:
455                   {
456                      DU_LOG("\nERROR  -->  DU_APP : Invalid event %d received at duActvTsk from ENTRLC", \
457                            pst->event);
458                      ODU_PUT_MSG_BUF(mBuf);
459                      ret = RFAILED;
460                   }
461             }
462             break;
463          }
464       case ENTMAC:
465          {
466             switch(pst->event)
467             {
468                //Config complete
469                case EVTCFG:
470                   {
471                      ODU_PUT_MSG_BUF(mBuf);
472                      break;
473                   }
474                case EVTLRGCFGCFM:
475                   {
476                      ret = cmUnpkLrgCfgCfm(duHdlMacCfgComplete, pst, mBuf);
477                      break;
478                   }
479                case EVTLRGCNTRLCFM:
480                   {
481                      break;
482                   }
483                case EVTMACSCHGENCFGCFM:
484                   {
485                      ret = cmUnpkLrgSchCfgCfm(duHdlSchCfgComplete, pst, mBuf);
486                      break;
487                   }
488                case EVENT_MAC_CELL_CONFIG_CFM:
489                   {
490                      ret = unpackMacCellCfgCfm(duHandleMacCellCfgCfm, pst, mBuf);
491                      break;
492                   }
493                case EVENT_MAC_CELL_UP_IND:
494                   {
495                      ret = unpackMacCellUpInd(duHandleCellUpInd, pst, mBuf);
496                      break;
497                   }
498                case EVENT_MAC_STOP_IND:
499                   {
500                      ret = unpackMacStopInd(duHandleStopInd, pst, mBuf);
501                      break;
502                   }
503                case EVENT_MAC_UL_CCCH_IND:
504                   {
505                      ret = unpackMacUlCcchInd(duHandleUlCcchInd, pst, mBuf);
506                      break;
507                   }
508                case EVENT_MAC_UE_CREATE_RSP:
509                   {
510                      ret = unpackDuMacUeCfgRsp(DuProcMacUeCfgRsp, pst, mBuf); 
511                      break;
512                   }
513                case EVENT_MAC_UE_RECONFIG_RSP:
514                   {
515                      ret = unpackDuMacUeCfgRsp(DuProcMacUeCfgRsp, pst, mBuf); 
516                      break;
517                   }
518                case EVENT_MAC_UE_DELETE_RSP:
519                   {
520                      ret = unpackDuMacUeDeleteRsp(DuProcMacUeDeleteRsp, pst, mBuf);
521                      break;
522                   }
523                case EVENT_MAC_CELL_DELETE_RSP:
524                   {
525                      ret = unpackDuMacCellDeleteRsp(DuProcMacCellDeleteRsp, pst, mBuf);
526                      break;
527                   }
528                default:
529                   {
530                      DU_LOG("\nERROR  -->  DU_APP : Invalid event received at duActvTsk from ENTMAC");
531                      ODU_PUT_MSG_BUF(mBuf);
532                      ret = RFAILED;
533                   }
534             }
535
536             break;
537          }
538       case ENTSCTP:
539          {
540             switch(pst->event)
541             {
542                case EVENT_CU_DATA:
543                   {
544                      F1APMsgHdlr(mBuf);
545                      break;
546                   }
547                case EVENT_SCTP_NTFY:
548                   {
549                      ret = cmUnpkSctpNtfy(duSctpNtfyHdl, pst, mBuf);
550                      break;
551                   }
552                case EVENT_RIC_DATA:
553                   {
554                      E2APMsgHdlr(mBuf);
555                      break;
556                   }
557                default:
558                   {
559                      DU_LOG("\nERROR  -->  DU_APP : Invalid event received at duActvTsk from ENTSCTP");
560                      ret = RFAILED;
561                   }
562
563             }
564             ODU_PUT_MSG_BUF(mBuf);
565             break;
566          }
567       case ENTEGTP:
568          {
569             switch(pst->event)
570             {
571                case EVTCFGCFM:
572                   {
573                      unpackEgtpCfgCfm(duHdlEgtpCfgComplete, mBuf);
574                      break;
575                   }
576                case EVTSRVOPENCFM:
577                   {
578                      unpackEgtpSrvOpenCfm(duHdlEgtpSrvOpenComplete, mBuf);
579                      break;
580                   }
581                case EVTTNLMGMTCFM:
582                   {
583                      unpackEgtpTnlMgmtCfm(duHdlEgtpTnlMgmtCfm, mBuf);
584                      break;
585                   }
586                default:
587                   {
588                      DU_LOG("\nERROR  -->  DU_APP : Invalid event[%d] received at duActvTsk from ENTEGTP", pst->event);
589                      ret = RFAILED;
590                   }
591             }
592             ODU_PUT_MSG_BUF(mBuf);
593             break;
594          }
595       default:
596          {
597             DU_LOG("\nERROR  -->  DU_APP : DU APP can not process message from Entity %d", pst->srcEnt);
598             ODU_PUT_MSG_BUF(mBuf);
599             ret = RFAILED;
600          }
601
602    }
603    ODU_EXIT_TASK();
604    return ret;
605 }
606
607 /**********************************************************************
608   End of file
609  **********************************************************************/