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