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