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