[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-428]Slot Indication at DUAPP
[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_SLOT_IND:
248                   {
249                      strcpy(message,"EVENT_MAC_SLOT_IND");
250                      break;
251                   }
252                case EVENT_MAC_STOP_IND:
253                   {
254                      strcpy(message,"EVENT_MAC_STOP_IND");
255                      break;
256                   }
257                case EVENT_MAC_UL_CCCH_IND:
258                   {
259                      strcpy(message,"EVENT_MAC_UL_CCCH_IND");
260                      break;
261                   }
262                case EVENT_MAC_UE_CREATE_RSP:
263                   {
264                      strcpy(message,"EVENT_MAC_UE_CREATE_RSP");
265                      break;
266                   }
267                case EVENT_MAC_UE_RECONFIG_RSP:
268                   {
269                      strcpy(message,"EVENT_MAC_UE_RECONFIG_RSP");
270                      break;
271                   }
272                case EVENT_MAC_UE_DELETE_RSP:
273                   {
274                      strcpy(message,"EVENT_MAC_UE_DELETE_RSP");
275                      break;
276                   }
277                case EVENT_MAC_CELL_DELETE_RSP:
278                   {
279                      strcpy(message,"EVENT_MAC_CELL_DELETE_RSP");
280                      break;
281                   }
282                case EVENT_MAC_SLICE_CFG_RSP:
283                   {
284                      strcpy(message,"EVENT_MAC_SLICE_CFG_RSP");
285                      break;
286                   }
287                case EVENT_MAC_SLICE_RECFG_RSP:
288                   {
289                      strcpy(message,"EVENT_MAC_SLICE_RECFG_RSP");
290                      break;
291                   }
292                default:
293                   {
294                      strcpy(message,"Invalid Event");
295                      break;
296                   }
297             }
298
299             break;
300          }
301       case ENTSCTP:
302          {
303             strcpy(sourceTask,"ENTSCTP");
304             switch(pst->event)
305             {
306                case EVENT_CU_DATA:
307                   {
308                      strcpy(message,"EVENT_CU_DATA");
309                      break;
310                   }
311                case EVENT_SCTP_NTFY:
312                   {
313                      strcpy(message,"EVENT_SCTP_NTFY");
314                      break;
315                   }
316                case EVENT_RIC_DATA:
317                   {
318                      strcpy(message,"EVENT_RIC_DATA");
319                      break;
320                   }
321                default:
322                   {
323                      strcpy(message,"Invalid Event");
324                      break;
325                   }
326
327             }
328             break;
329          }
330       case ENTEGTP:
331          {
332             strcpy(sourceTask,"ENTEGTP");
333             switch(pst->event)
334             {
335                case EVTCFGCFM:
336                   {
337                      strcpy(message,"EVTCFGCFM");
338                      break;
339                   }
340                case EVTSRVOPENCFM:
341                   {
342                      strcpy(message,"EVTSRVOPENCFM");
343                      break;
344                   }
345                case EVTTNLMGMTCFM:
346                   {
347                      strcpy(message,"EVTTNLMGMTCFM");
348                      break;
349                   }
350                default:
351                   {
352                      strcpy(message,"Invalid Event");
353                      break;
354                   }
355             }
356             break;
357          }
358       default:
359          {
360             strcpy(sourceTask,"Invalid Source Entity Id");
361             break;
362          }
363    }
364    DU_LOG("\nCall Flow: %s -> %s : %s\n", sourceTask, destTask, message);
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 = unpackRlcUeCfgRsp(DuProcRlcUeCfgRsp, pst, mBuf);
438                      break;
439                   }
440                case EVENT_RLC_UE_RECONFIG_RSP:
441                   {
442                      ret = unpackRlcUeCfgRsp(DuProcRlcUeCfgRsp, 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_UL_USER_DATA_TRANS_TO_DU:
466                   {
467                      ret = unpackRlcUlUserDataToDu(DuProcRlcUlUserDataTrans, pst, mBuf);
468                      break;
469                   }
470                case EVENT_RLC_SLICE_PM_TO_DU:
471                   {
472                      ret = unpackRlcSlicePm(DuProcRlcSliceMetrics, pst, mBuf);
473                      break;
474                   }
475                default:
476                   {
477                      DU_LOG("\nERROR  -->  DU_APP : Invalid event %d received at duActvTsk from ENTRLC", \
478                            pst->event);
479                      ODU_PUT_MSG_BUF(mBuf);
480                      ret = RFAILED;
481                   }
482             }
483             break;
484          }
485       case ENTMAC:
486          {
487             switch(pst->event)
488             {
489                //Config complete
490                case EVTCFG:
491                   {
492                      ODU_PUT_MSG_BUF(mBuf);
493                      break;
494                   }
495                case EVTLRGCFGCFM:
496                   {
497                      ret = cmUnpkLrgCfgCfm(duHdlMacCfgComplete, pst, mBuf);
498                      break;
499                   }
500                case EVTLRGCNTRLCFM:
501                   {
502                      break;
503                   }
504                case EVTMACSCHGENCFGCFM:
505                   {
506                      ret = cmUnpkLrgSchCfgCfm(duHdlSchCfgComplete, pst, mBuf);
507                      break;
508                   }
509                case EVENT_MAC_CELL_CONFIG_CFM:
510                   {
511                      ret = unpackMacCellCfgCfm(duHandleMacCellCfgCfm, pst, mBuf);
512                      break;
513                   }
514                case EVENT_MAC_CELL_UP_IND:
515                   {
516                      ret = unpackMacCellUpInd(duHandleCellUpInd, pst, mBuf);
517                      break;
518                   }
519                case EVENT_MAC_SLOT_IND:
520                   {
521                      ret = unpackDuMacSlotInd(duHandleSlotInd, pst, mBuf);
522                      break;
523                   }
524                case EVENT_MAC_STOP_IND:
525                   {
526                      ret = unpackMacStopInd(duHandleStopInd, pst, mBuf);
527                      break;
528                   }
529                case EVENT_MAC_UL_CCCH_IND:
530                   {
531                      ret = unpackMacUlCcchInd(duHandleUlCcchInd, pst, mBuf);
532                      break;
533                   }
534                case EVENT_MAC_UE_CREATE_RSP:
535                   {
536                      ret = unpackDuMacUeCfgRsp(DuProcMacUeCfgRsp, pst, mBuf); 
537                      break;
538                   }
539                case EVENT_MAC_UE_RECONFIG_RSP:
540                   {
541                      ret = unpackDuMacUeCfgRsp(DuProcMacUeCfgRsp, pst, mBuf); 
542                      break;
543                   }
544                case EVENT_MAC_UE_DELETE_RSP:
545                   {
546                      ret = unpackDuMacUeDeleteRsp(DuProcMacUeDeleteRsp, pst, mBuf);
547                      break;
548                   }
549                case EVENT_MAC_CELL_DELETE_RSP:
550                   {
551                      ret = unpackDuMacCellDeleteRsp(DuProcMacCellDeleteRsp, pst, mBuf);
552                      break;
553                   }
554                case EVENT_MAC_SLICE_CFG_RSP:
555                   {
556                      ret = unpackDuMacSliceCfgRsp(DuProcMacSliceCfgRsp, pst, mBuf);
557                      break;
558                   }
559                case EVENT_MAC_SLICE_RECFG_RSP:
560                   {
561                      ret = unpackDuMacSliceReCfgRsp(DuProcMacSliceReCfgRsp, pst, mBuf);
562                      break;
563                   }
564                default:
565                   {
566                      DU_LOG("\nERROR  -->  DU_APP : Invalid event received at duActvTsk from ENTMAC");
567                      ODU_PUT_MSG_BUF(mBuf);
568                      ret = RFAILED;
569                   }
570             }
571
572             break;
573          }
574       case ENTSCTP:
575          {
576             switch(pst->event)
577             {
578                case EVENT_CU_DATA:
579                   {
580                      F1APMsgHdlr(mBuf);
581                      break;
582                   }
583                case EVENT_SCTP_NTFY:
584                   {
585                      ret = cmUnpkSctpNtfy(duSctpNtfyHdl, pst, mBuf);
586                      break;
587                   }
588                case EVENT_RIC_DATA:
589                   {
590                      E2APMsgHdlr(mBuf);
591                      break;
592                   }
593                default:
594                   {
595                      DU_LOG("\nERROR  -->  DU_APP : Invalid event received at duActvTsk from ENTSCTP");
596                      ret = RFAILED;
597                   }
598
599             }
600             ODU_PUT_MSG_BUF(mBuf);
601             break;
602          }
603       case ENTEGTP:
604          {
605             switch(pst->event)
606             {
607                case EVTCFGCFM:
608                   {
609                      unpackEgtpCfgCfm(duHdlEgtpCfgComplete, mBuf);
610                      break;
611                   }
612                case EVTSRVOPENCFM:
613                   {
614                      unpackEgtpSrvOpenCfm(duHdlEgtpSrvOpenComplete, mBuf);
615                      break;
616                   }
617                case EVTTNLMGMTCFM:
618                   {
619                      unpackEgtpTnlMgmtCfm(duHdlEgtpTnlMgmtCfm, mBuf);
620                      break;
621                   }
622                default:
623                   {
624                      DU_LOG("\nERROR  -->  DU_APP : Invalid event[%d] received at duActvTsk from ENTEGTP", pst->event);
625                      ret = RFAILED;
626                   }
627             }
628             ODU_PUT_MSG_BUF(mBuf);
629             break;
630          }
631       default:
632          {
633             DU_LOG("\nERROR  -->  DU_APP : DU APP can not process message from Entity %d", pst->srcEnt);
634             ODU_PUT_MSG_BUF(mBuf);
635             ret = RFAILED;
636          }
637
638    }
639    ODU_EXIT_TASK();
640    return ret;
641 }
642
643 /**********************************************************************
644   End of file
645  **********************************************************************/