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