c78102a34915bf1aefeb4d492fc825eff73cd453
[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    duCb.gnbDuUeF1apIdGenerator = 0;
100    cmLListInit(&duCb.reservedF1apPduList);
101    ODU_SET_PROC_ID(DU_PROC);
102
103    return ROK;
104
105 }
106
107 #ifdef CALL_FLOW_DEBUG_LOG   
108 /**************************************************************************
109 * @brief Function prints the src dest and msg reached to egtp.
110 *
111 * @details
112 *
113 *      Function : callFlowduActvTsk 
114 *
115 *      Functionality:
116 *           Function prints the src dest and msg reached to egtp.
117 *
118 * @param[in]  Pst     *pst, Post structure of the primitive.
119 *
120 * @return void
121 *
122 +***************************************************************************/
123
124 void callFlowduActvTsk(Pst *pst)
125 {
126    char sourceTask[50];
127    char destTask[50]="ENTDUAPP";
128    char message[100];
129    
130    switch(pst->srcEnt)
131    {
132       case ENTDUAPP:
133          {
134             strcpy(sourceTask,"ENTDUAPP");
135             switch(pst->event)
136             {
137                case EVTCFG:
138                   {
139                      strcpy(message,"EVTCFG");
140                      break;
141                   }
142                default:
143                   {
144                      strcpy(message,"Invalid Event");
145                      break;
146                   }
147             }
148
149             break;
150          }
151       case ENTRLC:
152          {
153             strcpy(sourceTask,"ENTRLC");
154             switch(pst->event)
155             {
156                case LKW_EVT_CFG_CFM:
157                   {
158                      strcpy(message,"LKW_EVT_CFG_CFM");
159                      break;
160                   }
161                case LKW_EVT_CNTRL_CFM:
162                   {
163                      strcpy(message,"LKW_EVT_CNTRL_CFM");
164                      break;
165                   }
166                case LKW_EVT_STA_IND:
167                   {
168                      strcpy(message,"LKW_EVT_STA_IND");
169                      break;
170                   }
171                case EVENT_RLC_UE_CREATE_RSP:
172                   {
173                      strcpy(message,"EVENT_RLC_UE_CREATE_RSP");
174                      break;
175                   }
176                case EVENT_RLC_UE_RECONFIG_RSP:
177                   {
178                      strcpy(message,"EVENT_RLC_UE_RECONFIG_RSP");
179                      break;
180                   }
181                case EVENT_RLC_UE_DELETE_RSP:
182                   {
183                      strcpy(message,"EVENT_RLC_UE_DELETE_RSP");
184                      break;
185                   }
186                case EVENT_UL_RRC_MSG_TRANS_TO_DU:
187                   {
188                      strcpy(message,"EVENT_UL_RRC_MSG_TRANS_TO_DU");
189                      break;
190                   }
191                case EVENT_RRC_DELIVERY_MSG_TRANS_TO_DU:
192                   {
193                      strcpy(message,"EVENT_RRC_DELIVERY_MSG_TRANS_TO_DU");
194                      break;
195                   }
196                case EVENT_DL_RRC_MSG_RSP_TO_DU:
197                   {
198                      strcpy(message,"EVENT_DL_RRC_MSG_RSP_TO_DU");
199                      break;
200                   }
201                case EVENT_UL_USER_DATA_TRANS_TO_DU:
202                   {
203                      strcpy(message,"EVENT_UL_USER_DATA_TRANS_TO_DU");
204                      break;
205                   }
206                default:
207                   {
208                      strcpy(message,"Invalid Event");
209                   }
210             }
211             break;
212          }
213       case ENTMAC:
214          {
215             strcpy(sourceTask,"ENTMAC");
216             switch(pst->event)
217             {
218                case EVTCFG:
219                   {
220                      strcpy(message,"EVTCFG");
221                      break;
222                   }
223                case EVTLRGCFGCFM:
224                   {
225                      strcpy(message,"EVTLRGCFGCFM");
226                      break;
227                   }
228                case EVTMACSCHGENCFGCFM:
229                   {
230                      strcpy(message,"EVTMACSCHGENCFGCFM");
231                      break;
232                   }
233                case EVENT_MAC_CELL_CONFIG_CFM:
234                   {
235                      strcpy(message,"EVENT_MAC_CELL_CONFIG_CFM");
236                      break;
237                   }
238                case EVENT_MAC_CELL_UP_IND:
239                   {
240                      strcpy(message,"EVENT_MAC_CELL_UP_IND");
241                      break;
242                   }
243                case EVENT_MAC_SLOT_IND:
244                   {
245                      strcpy(message,"EVENT_MAC_SLOT_IND");
246                      break;
247                   }
248                case EVENT_MAC_STOP_IND:
249                   {
250                      strcpy(message,"EVENT_MAC_STOP_IND");
251                      break;
252                   }
253                case EVENT_MAC_UL_CCCH_IND:
254                   {
255                      strcpy(message,"EVENT_MAC_UL_CCCH_IND");
256                      break;
257                   }
258                case EVENT_MAC_UE_CREATE_RSP:
259                   {
260                      strcpy(message,"EVENT_MAC_UE_CREATE_RSP");
261                      break;
262                   }
263                case EVENT_MAC_UE_RECONFIG_RSP:
264                   {
265                      strcpy(message,"EVENT_MAC_UE_RECONFIG_RSP");
266                      break;
267                   }
268                case EVENT_MAC_UE_DELETE_RSP:
269                   {
270                      strcpy(message,"EVENT_MAC_UE_DELETE_RSP");
271                      break;
272                   }
273                case EVENT_MAC_CELL_DELETE_RSP:
274                   {
275                      strcpy(message,"EVENT_MAC_CELL_DELETE_RSP");
276                      break;
277                   }
278                case EVENT_MAC_SLICE_CFG_RSP:
279                   {
280                      strcpy(message,"EVENT_MAC_SLICE_CFG_RSP");
281                      break;
282                   }
283                case EVENT_MAC_SLICE_RECFG_RSP:
284                   {
285                      strcpy(message,"EVENT_MAC_SLICE_RECFG_RSP");
286                      break;
287                   }
288                default:
289                   {
290                      strcpy(message,"Invalid Event");
291                      break;
292                   }
293             }
294
295             break;
296          }
297       case ENTSCTP:
298          {
299             strcpy(sourceTask,"ENTSCTP");
300             switch(pst->event)
301             {
302                case EVENT_CU_DATA:
303                   {
304                      strcpy(message,"EVENT_CU_DATA");
305                      break;
306                   }
307                case EVENT_SCTP_NTFY:
308                   {
309                      strcpy(message,"EVENT_SCTP_NTFY");
310                      break;
311                   }
312                case EVENT_RIC_DATA:
313                   {
314                      strcpy(message,"EVENT_RIC_DATA");
315                      break;
316                   }
317                default:
318                   {
319                      strcpy(message,"Invalid Event");
320                      break;
321                   }
322
323             }
324             break;
325          }
326       case ENTEGTP:
327          {
328             strcpy(sourceTask,"ENTEGTP");
329             switch(pst->event)
330             {
331                case EVTCFGCFM:
332                   {
333                      strcpy(message,"EVTCFGCFM");
334                      break;
335                   }
336                case EVTSRVOPENCFM:
337                   {
338                      strcpy(message,"EVTSRVOPENCFM");
339                      break;
340                   }
341                case EVTTNLMGMTCFM:
342                   {
343                      strcpy(message,"EVTTNLMGMTCFM");
344                      break;
345                   }
346                default:
347                   {
348                      strcpy(message,"Invalid Event");
349                      break;
350                   }
351             }
352             break;
353          }
354       default:
355          {
356             strcpy(sourceTask,"Invalid Source Entity Id");
357             break;
358          }
359    }
360    DU_LOG("\nCall Flow: %s -> %s : %s\n", sourceTask, destTask, message);
361 }
362 #endif
363
364 /**************************************************************************
365  * @brief Task Activation callback function. 
366  *
367  * @details
368  *
369  *      Function : duActvTsk 
370  * 
371  *      Functionality:
372  *           Primitives invoked by DU APP's users/providers through
373  *           a loosely coupled interface arrive here by means of 
374  *           SSI's message handling. This API is registered with
375  *           SSI during the Task Registration of DU APP.
376  *     
377  * @param[in]  Pst     *pst, Post structure of the primitive.     
378  * @param[in]  Buffer *mBuf, Packed primitive parameters in the
379  *  buffer.
380  * @return ROK     - success
381  *         RFAILED - failure
382  *
383  ***************************************************************************/
384 uint8_t duActvTsk(Pst *pst, Buffer *mBuf)
385 {
386    uint8_t ret = ROK;
387    
388 #ifdef CALL_FLOW_DEBUG_LOG   
389    callFlowduActvTsk(pst);
390 #endif
391
392    switch(pst->srcEnt)
393    {
394       case ENTDUAPP:
395          {
396             switch(pst->event)
397             {
398                case EVTCFG:
399                   {
400                      DU_LOG("\n****** Received initial configs at DU APP ******\n");
401                      duProcCfgComplete();
402                      ODU_PUT_MSG_BUF(mBuf);
403                      break;
404                   }
405                default:
406                   {
407                      DU_LOG("\nERROR  -->  DU_APP : Invalid event received at duActvTsk from ENTDUAPP");
408                      ODU_PUT_MSG_BUF(mBuf);
409                      ret = RFAILED;
410                   }
411             }
412
413             break;
414          }
415       case ENTRLC:
416          {
417             switch(pst->event)
418             {
419                case LKW_EVT_CFG_CFM:
420                   {
421                      ret = unpackRlcConfigCfm(DuHdlRlcCfgComplete, pst, mBuf);
422                      break;
423                   }
424                case LKW_EVT_CNTRL_CFM:
425                   {
426                      ret = cmUnpkLkwCntrlCfm(duHdlRlcCntrlCfgComplete, pst, mBuf);
427                      break;
428                   }
429                case LKW_EVT_STA_IND:
430                   {
431                      break;
432                   }
433                case EVENT_RLC_UE_CREATE_RSP:
434                   {
435                      ret = unpackRlcUeCfgRsp(DuProcRlcUeCfgRsp, pst, mBuf);
436                      break;
437                   }
438                case EVENT_RLC_UE_RECONFIG_RSP:
439                   {
440                      ret = unpackRlcUeCfgRsp(DuProcRlcUeCfgRsp, pst, mBuf);
441                      break;
442                   }
443                case EVENT_RLC_UE_DELETE_RSP:
444                   {
445                      ret = unpackRlcUeDeleteRsp(DuProcRlcUeDeleteRsp, pst, mBuf);
446                      break;
447                   }
448                case EVENT_UL_RRC_MSG_TRANS_TO_DU:
449                   {
450                      ret = unpackRlcUlRrcMsgToDu(DuProcRlcUlRrcMsgTrans, pst, mBuf);
451                      break;
452                   }
453                case EVENT_RRC_DELIVERY_MSG_TRANS_TO_DU:
454                   {
455                      ret = unpackRrcDeliveryReportToDu(DuProcRlcRrcDeliveryReport, pst, mBuf);
456                      break;
457                   }
458                case EVENT_DL_RRC_MSG_RSP_TO_DU:
459                   {
460                      ret = unpackRlcDlRrcMsgRspToDu(DuProcRlcDlRrcMsgRsp, pst, mBuf);
461                      break;
462                   }
463                case EVENT_RLC_MAX_RETRANSMISSION:
464                   {
465                      ret = unpackRlcMaxRetransInd(DuProcRlcMaxRetransInd, pst, mBuf);
466                      break;
467                   }
468                case EVENT_UL_USER_DATA_TRANS_TO_DU:
469                   {
470                      ret = unpackRlcUlUserDataToDu(DuProcRlcUlUserDataTrans, pst, mBuf);
471                      break;
472                   }
473                case EVENT_RLC_SLICE_PM_TO_DU:
474                   {
475                      ret = unpackRlcSlicePm(DuProcRlcSliceMetrics, pst, mBuf);
476                      break;
477                   }
478                case EVENT_RLC_UE_REESTABLISH_RSP:
479                   {
480                      ret = unpackRlcUeReestablishRsp(DuProcRlcUeReestablishRsp, pst, mBuf);
481                      break;
482                   }
483                default:
484                   {
485                      DU_LOG("\nERROR  -->  DU_APP : Invalid event %d received at duActvTsk from ENTRLC", \
486                            pst->event);
487                      ODU_PUT_MSG_BUF(mBuf);
488                      ret = RFAILED;
489                   }
490             }
491             break;
492          }
493       case ENTMAC:
494          {
495             switch(pst->event)
496             {
497                //Config complete
498                case EVTCFG:
499                   {
500                      ODU_PUT_MSG_BUF(mBuf);
501                      break;
502                   }
503                case EVTLRGCFGCFM:
504                   {
505                      ret = cmUnpkLrgCfgCfm(duHdlMacCfgComplete, pst, mBuf);
506                      break;
507                   }
508                case EVTMACSCHGENCFGCFM:
509                   {
510                      ret = cmUnpkLrgSchCfgCfm(duHdlSchCfgComplete, pst, mBuf);
511                      break;
512                   }
513                case EVENT_MAC_CELL_CONFIG_CFM:
514                   {
515                      ret = unpackMacCellCfgCfm(duHandleMacCellCfgCfm, pst, mBuf);
516                      break;
517                   }
518                case EVENT_MAC_CELL_UP_IND:
519                   {
520                      ret = unpackMacCellUpInd(duHandleCellUpInd, pst, mBuf);
521                      break;
522                   }
523                case EVENT_MAC_SLOT_IND:
524                   {
525                      ret = unpackDuMacSlotInd(duHandleSlotInd, pst, mBuf);
526                      break;
527                   }
528                case EVENT_MAC_STOP_IND:
529                   {
530                      ret = unpackMacStopInd(duHandleStopInd, pst, mBuf);
531                      break;
532                   }
533                case EVENT_MAC_UL_CCCH_IND:
534                   {
535                      ret = unpackMacUlCcchInd(duHandleUlCcchInd, pst, mBuf);
536                      break;
537                   }
538                case EVENT_MAC_UE_CREATE_RSP:
539                   {
540                      ret = unpackDuMacUeCfgRsp(DuProcMacUeCfgRsp, pst, mBuf); 
541                      break;
542                   }
543                case EVENT_MAC_UE_RECONFIG_RSP:
544                   {
545                      ret = unpackDuMacUeRecfgRsp(DuProcMacUeRecfgRsp, pst, mBuf); 
546                      break;
547                   }
548                case EVENT_MAC_UE_DELETE_RSP:
549                   {
550                      ret = unpackDuMacUeDeleteRsp(DuProcMacUeDeleteRsp, pst, mBuf);
551                      break;
552                   }
553                case EVENT_MAC_CELL_DELETE_RSP:
554                   {
555                      ret = unpackDuMacCellDeleteRsp(DuProcMacCellDeleteRsp, pst, mBuf);
556                      break;
557                   }
558                case EVENT_MAC_SLICE_CFG_RSP:
559                   {
560                      ret = unpackDuMacSliceCfgRsp(DuProcMacSliceCfgRsp, pst, mBuf);
561                      break;
562                   }
563                case EVENT_MAC_UE_SYNC_STATUS_IND:
564                   {
565                      ret = unpackDuMacUeSyncStatusInd(DuProcMacUeSyncStatusInd, pst, mBuf);
566                      break;
567                                                                                                 }
568                case EVENT_MAC_SLICE_RECFG_RSP:
569                   {
570                      ret = unpackDuMacSliceRecfgRsp(DuProcMacSliceRecfgRsp, pst, mBuf);
571                      break;
572                   }
573                case EVENT_MAC_RACH_RESOURCE_RSP:
574                   {
575                      ret = unpackDuMacRachRsrcRsp(DuProcMacRachRsrcRsp, pst, mBuf);
576                      break;
577                   }
578                case EVENT_MAC_UE_RESET_RSP:
579                   {
580                      ret = unpackDuMacUeResetRsp(DuProcMacUeResetRsp, pst, mBuf);
581                      break;
582                   }
583                default:
584                   {
585                      DU_LOG("\nERROR  -->  DU_APP : Invalid event received at duActvTsk from ENTMAC");
586                      ODU_PUT_MSG_BUF(mBuf);
587                      ret = RFAILED;
588                   }
589             }
590
591             break;
592          }
593       case ENTSCTP:
594          {
595             switch(pst->event)
596             {
597                case EVENT_CU_DATA:
598                   {
599                      F1APMsgHdlr(mBuf);
600                      break;
601                   }
602                case EVENT_SCTP_NTFY:
603                   {
604                      ret = cmUnpkSctpNtfy(duSctpNtfyHdl, pst, mBuf);
605                      break;
606                   }
607                case EVENT_RIC_DATA:
608                   {
609                      E2APMsgHdlr(mBuf);
610                      break;
611                   }
612                default:
613                   {
614                      DU_LOG("\nERROR  -->  DU_APP : Invalid event received at duActvTsk from ENTSCTP");
615                      ret = RFAILED;
616                   }
617
618             }
619             ODU_PUT_MSG_BUF(mBuf);
620             break;
621          }
622       case ENTEGTP:
623          {
624             switch(pst->event)
625             {
626                case EVTCFGCFM:
627                   {
628                      unpackEgtpCfgCfm(duHdlEgtpCfgComplete, mBuf);
629                      break;
630                   }
631                case EVTSRVOPENCFM:
632                   {
633                      unpackEgtpSrvOpenCfm(duHdlEgtpSrvOpenComplete, mBuf);
634                      break;
635                   }
636                case EVTTNLMGMTCFM:
637                   {
638                      unpackEgtpTnlMgmtCfm(duHdlEgtpTnlMgmtCfm, mBuf);
639                      break;
640                   }
641                default:
642                   {
643                      DU_LOG("\nERROR  -->  DU_APP : Invalid event[%d] received at duActvTsk from ENTEGTP", pst->event);
644                      ret = RFAILED;
645                   }
646             }
647             ODU_PUT_MSG_BUF(mBuf);
648             break;
649          }
650       default:
651          {
652             DU_LOG("\nERROR  -->  DU_APP : DU APP can not process message from Entity %d", pst->srcEnt);
653             ODU_PUT_MSG_BUF(mBuf);
654             ret = RFAILED;
655          }
656
657    }
658    ODU_EXIT_TASK();
659    return ret;
660 }
661
662 /**********************************************************************
663   End of file
664  **********************************************************************/