f66dae78e755381db884797f5ce72825c96b8628
[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                case EVENT_MAC_SLICE_CFG_RSP:
277                   {
278                      strcpy(message,"EVENT_MAC_SLICE_CFG_RSP");
279                      break;
280                   }
281                case EVENT_MAC_SLICE_RECFG_RSP:
282                   {
283                      strcpy(message,"EVENT_MAC_SLICE_RECFG_RSP");
284                      break;
285                   }
286                default:
287                   {
288                      strcpy(message,"Invalid Event");
289                      break;
290                   }
291             }
292
293             break;
294          }
295       case ENTSCTP:
296          {
297             strcpy(sourceTask,"ENTSCTP");
298             switch(pst->event)
299             {
300                case EVENT_CU_DATA:
301                   {
302                      strcpy(message,"EVENT_CU_DATA");
303                      break;
304                   }
305                case EVENT_SCTP_NTFY:
306                   {
307                      strcpy(message,"EVENT_SCTP_NTFY");
308                      break;
309                   }
310                case EVENT_RIC_DATA:
311                   {
312                      strcpy(message,"EVENT_RIC_DATA");
313                      break;
314                   }
315                default:
316                   {
317                      strcpy(message,"Invalid Event");
318                      break;
319                   }
320
321             }
322             break;
323          }
324       case ENTEGTP:
325          {
326             strcpy(sourceTask,"ENTEGTP");
327             switch(pst->event)
328             {
329                case EVTCFGCFM:
330                   {
331                      strcpy(message,"EVTCFGCFM");
332                      break;
333                   }
334                case EVTSRVOPENCFM:
335                   {
336                      strcpy(message,"EVTSRVOPENCFM");
337                      break;
338                   }
339                case EVTTNLMGMTCFM:
340                   {
341                      strcpy(message,"EVTTNLMGMTCFM");
342                      break;
343                   }
344                default:
345                   {
346                      strcpy(message,"Invalid Event");
347                      break;
348                   }
349             }
350             break;
351          }
352       default:
353          {
354             strcpy(sourceTask,"Invalid Source Entity Id");
355             break;
356          }
357    }
358    DU_LOG("\nCall Flow: %s -> %s : %s\n", sourceTask, destTask, message);
359 }
360 /**************************************************************************
361  * @brief Task Activation callback function. 
362  *
363  * @details
364  *
365  *      Function : duActvTsk 
366  * 
367  *      Functionality:
368  *           Primitives invoked by DU APP's users/providers through
369  *           a loosely coupled interface arrive here by means of 
370  *           SSI's message handling. This API is registered with
371  *           SSI during the Task Registration of DU APP.
372  *     
373  * @param[in]  Pst     *pst, Post structure of the primitive.     
374  * @param[in]  Buffer *mBuf, Packed primitive parameters in the
375  *  buffer.
376  * @return ROK     - success
377  *         RFAILED - failure
378  *
379  ***************************************************************************/
380 uint8_t duActvTsk(Pst *pst, Buffer *mBuf)
381 {
382    uint8_t ret = ROK;
383    
384 #ifdef CALL_FLOW_DEBUG_LOG   
385    callFlowduActvTsk(pst);
386 #endif
387
388    switch(pst->srcEnt)
389    {
390       case ENTDUAPP:
391          {
392             switch(pst->event)
393             {
394                case EVTCFG:
395                   {
396                      DU_LOG("\n****** Received initial configs at DU APP ******\n");
397                      duProcCfgComplete();
398                      ODU_PUT_MSG_BUF(mBuf);
399                      break;
400                   }
401                default:
402                   {
403                      DU_LOG("\nERROR  -->  DU_APP : Invalid event received at duActvTsk from ENTDUAPP");
404                      ODU_PUT_MSG_BUF(mBuf);
405                      ret = RFAILED;
406                   }
407             }
408
409             break;
410          }
411       case ENTRLC:
412          {
413             switch(pst->event)
414             {
415                case LKW_EVT_CFG_CFM:
416                   {
417                      ret = unpackRlcConfigCfm(DuHdlRlcCfgComplete, pst, mBuf);
418                      break;
419                   }
420                case LKW_EVT_CNTRL_CFM:
421                   {
422                      ret = cmUnpkLkwCntrlCfm(duHdlRlcCntrlCfgComplete, pst, mBuf);
423                      break;
424                   }
425                case LKW_EVT_STA_IND:
426                   {
427                      break;
428                   }
429                case EVENT_RLC_UE_CREATE_RSP:
430                   {
431                      ret = unpackRlcUeCfgRsp(DuProcRlcUeCfgRsp, pst, mBuf);
432                      break;
433                   }
434                case EVENT_RLC_UE_RECONFIG_RSP:
435                   {
436                      ret = unpackRlcUeCfgRsp(DuProcRlcUeCfgRsp, pst, mBuf);
437                      break;
438                   }
439                case EVENT_RLC_UE_DELETE_RSP:
440                   {
441                      ret = unpackRlcUeDeleteRsp(DuProcRlcUeDeleteRsp, pst, mBuf);
442                      break;
443                   }
444                case EVENT_UL_RRC_MSG_TRANS_TO_DU:
445                   {
446                      ret = unpackRlcUlRrcMsgToDu(DuProcRlcUlRrcMsgTrans, pst, mBuf);
447                      break;
448                   }
449                case EVENT_RRC_DELIVERY_MSG_TRANS_TO_DU:
450                   {
451                      ret = unpackRrcDeliveryReportToDu(DuProcRlcRrcDeliveryReport, pst, mBuf);
452                      break;
453                   }
454                case EVENT_DL_RRC_MSG_RSP_TO_DU:
455                   {
456                      ret = unpackRlcDlRrcMsgRspToDu(DuProcRlcDlRrcMsgRsp, pst, mBuf);
457                      break;
458                   }
459                case EVENT_UL_USER_DATA_TRANS_TO_DU:
460                   {
461                      ret = unpackRlcUlUserDataToDu(DuProcRlcUlUserDataTrans, pst, mBuf);
462                      break;
463                   }
464                case EVENT_RLC_SLICE_PM_TO_DU:
465                   {
466                      ret = unpackRlcSlicePm(DuProcRlcSliceMetrics, pst, mBuf);
467                      break;
468                   }
469                default:
470                   {
471                      DU_LOG("\nERROR  -->  DU_APP : Invalid event %d received at duActvTsk from ENTRLC", \
472                            pst->event);
473                      ODU_PUT_MSG_BUF(mBuf);
474                      ret = RFAILED;
475                   }
476             }
477             break;
478          }
479       case ENTMAC:
480          {
481             switch(pst->event)
482             {
483                //Config complete
484                case EVTCFG:
485                   {
486                      ODU_PUT_MSG_BUF(mBuf);
487                      break;
488                   }
489                case EVTLRGCFGCFM:
490                   {
491                      ret = cmUnpkLrgCfgCfm(duHdlMacCfgComplete, pst, mBuf);
492                      break;
493                   }
494                case EVTLRGCNTRLCFM:
495                   {
496                      break;
497                   }
498                case EVTMACSCHGENCFGCFM:
499                   {
500                      ret = cmUnpkLrgSchCfgCfm(duHdlSchCfgComplete, pst, mBuf);
501                      break;
502                   }
503                case EVENT_MAC_CELL_CONFIG_CFM:
504                   {
505                      ret = unpackMacCellCfgCfm(duHandleMacCellCfgCfm, pst, mBuf);
506                      break;
507                   }
508                case EVENT_MAC_CELL_UP_IND:
509                   {
510                      ret = unpackMacCellUpInd(duHandleCellUpInd, pst, mBuf);
511                      break;
512                   }
513                case EVENT_MAC_STOP_IND:
514                   {
515                      ret = unpackMacStopInd(duHandleStopInd, pst, mBuf);
516                      break;
517                   }
518                case EVENT_MAC_UL_CCCH_IND:
519                   {
520                      ret = unpackMacUlCcchInd(duHandleUlCcchInd, pst, mBuf);
521                      break;
522                   }
523                case EVENT_MAC_UE_CREATE_RSP:
524                   {
525                      ret = unpackDuMacUeCfgRsp(DuProcMacUeCfgRsp, pst, mBuf); 
526                      break;
527                   }
528                case EVENT_MAC_UE_RECONFIG_RSP:
529                   {
530                      ret = unpackDuMacUeCfgRsp(DuProcMacUeCfgRsp, pst, mBuf); 
531                      break;
532                   }
533                case EVENT_MAC_UE_DELETE_RSP:
534                   {
535                      ret = unpackDuMacUeDeleteRsp(DuProcMacUeDeleteRsp, pst, mBuf);
536                      break;
537                   }
538                case EVENT_MAC_CELL_DELETE_RSP:
539                   {
540                      ret = unpackDuMacCellDeleteRsp(DuProcMacCellDeleteRsp, pst, mBuf);
541                      break;
542                   }
543                case EVENT_MAC_SLICE_CFG_RSP:
544                   {
545                      ret = unpackDuMacSliceCfgRsp(DuProcMacSliceCfgRsp, pst, mBuf);
546                      break;
547                   }
548                case EVENT_MAC_SLICE_RECFG_RSP:
549                   {
550                      ret = unpackDuMacSliceReCfgRsp(DuProcMacSliceReCfgRsp, pst, mBuf);
551                      break;
552                   }
553                default:
554                   {
555                      DU_LOG("\nERROR  -->  DU_APP : Invalid event received at duActvTsk from ENTMAC");
556                      ODU_PUT_MSG_BUF(mBuf);
557                      ret = RFAILED;
558                   }
559             }
560
561             break;
562          }
563       case ENTSCTP:
564          {
565             switch(pst->event)
566             {
567                case EVENT_CU_DATA:
568                   {
569                      F1APMsgHdlr(mBuf);
570                      break;
571                   }
572                case EVENT_SCTP_NTFY:
573                   {
574                      ret = cmUnpkSctpNtfy(duSctpNtfyHdl, pst, mBuf);
575                      break;
576                   }
577                case EVENT_RIC_DATA:
578                   {
579                      E2APMsgHdlr(mBuf);
580                      break;
581                   }
582                default:
583                   {
584                      DU_LOG("\nERROR  -->  DU_APP : Invalid event received at duActvTsk from ENTSCTP");
585                      ret = RFAILED;
586                   }
587
588             }
589             ODU_PUT_MSG_BUF(mBuf);
590             break;
591          }
592       case ENTEGTP:
593          {
594             switch(pst->event)
595             {
596                case EVTCFGCFM:
597                   {
598                      unpackEgtpCfgCfm(duHdlEgtpCfgComplete, mBuf);
599                      break;
600                   }
601                case EVTSRVOPENCFM:
602                   {
603                      unpackEgtpSrvOpenCfm(duHdlEgtpSrvOpenComplete, mBuf);
604                      break;
605                   }
606                case EVTTNLMGMTCFM:
607                   {
608                      unpackEgtpTnlMgmtCfm(duHdlEgtpTnlMgmtCfm, mBuf);
609                      break;
610                   }
611                default:
612                   {
613                      DU_LOG("\nERROR  -->  DU_APP : Invalid event[%d] received at duActvTsk from ENTEGTP", pst->event);
614                      ret = RFAILED;
615                   }
616             }
617             ODU_PUT_MSG_BUF(mBuf);
618             break;
619          }
620       default:
621          {
622             DU_LOG("\nERROR  -->  DU_APP : DU APP can not process message from Entity %d", pst->srcEnt);
623             ODU_PUT_MSG_BUF(mBuf);
624             ret = RFAILED;
625          }
626
627    }
628    ODU_EXIT_TASK();
629    return ret;
630 }
631
632 /**********************************************************************
633   End of file
634  **********************************************************************/