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