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