88c06893fff3d1045759fac5dc1d1ff25d370195
[o-du/l2.git] / src / 5gnrmac / mac_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
19 /************************************************************************
20  
21      Name:     LTE-MAC layer
22   
23      Type:     C source file
24   
25      Desc:     C source code SSI Interface Implementation
26   
27      File:     mac_msg_router.c
28   
29 **********************************************************************/
30
31 /** @file mac_msg_router.c
32 @brief This file contains the implementation of callback functions 
33 registered with SSI during the LTE MAC Task initialization.
34 */
35 /* header include files -- defines (.h) */
36 #include "common_def.h"
37 #include "rgu.h"           /* RGU defines */
38 #include "tfu.h"           /* RGU defines */
39 #include "lrg.h"           /* layer management defines for LTE-MAC */
40 #include "rgr.h"           /* layer management defines for LTE-MAC */
41 #include "crg.h"           /* CRG interface includes */
42 #include "rg_sch_inf.h"    /* SCH interface includes */
43 #include "rg_prg.h"        /* PRG interface includes */
44 #include "rg_env.h"        /* customisable defines and macros for LTE-MAC */
45 #include "rg.h"            /* defines and macros for MAC */
46 #include "rgr.h"            /* defines and macros for SCH */
47
48
49 /* header/extern include files (.x) */
50 #include "rgu.x"           /* RGU types */
51 #include "tfu.x"           /* RGU types */
52 #include "lrg.x"           /* layer management typedefs for MAC */
53 #include "rgr.x"           /* layer management typedefs for MAC */
54 #include "crg.x"           /* CRG interface typedes */
55 #include "rg_sch_inf.x"    /* SCH interface typedefs */
56 #include "rg_prg.x"        /*PRG interface includes*/
57 #include "du_app_mac_inf.h"
58 #include "rg.x"            /* typedefs for MAC */
59 #include "rlc_mac_inf.h"
60 #include "lwr_mac_upr_inf.h"
61 #include "mac_sch_interface.h"
62 #include "mac.h"
63 #include "mac_ue_mgr.h"
64 #include "mac_harq_dl.h"
65
66 /**
67  * @brief Task Activation callback function Entity DU APP. 
68  *
69  * @details
70  *
71  *     Function : MacHdlDuappEvents
72  *     
73  *     Process Messages received from Entity DU APP
74  *     
75  *  @param[in]  Pst     *pst, Post structure of the primitive.     
76  *  @param[in]  Buffer *mBuf, Packed primitive parameters in the buffer.
77  *  @param[in]  Reason reason.
78  *  @return  void
79  **/
80 void MacHdlDuappEvents(Pst *pst, Buffer *mBuf)
81 {
82    switch(pst->event)
83    {
84 #ifdef LCRGMILRG
85       case EVTLRGCFGREQ:
86          /* Process a config. request */
87          cmUnpkLrgCfgReq(RgMiLrgCfgReq, pst, mBuf);
88          break;
89       case EVTMACSCHGENCFGREQ:
90          /* Process a config. request */
91          cmUnpkLrgSchCfgReq(MacSchGenCfgReq, pst, mBuf);
92          break;
93       case EVTLRGSTSREQ:
94          /* Process a statistics request */
95          cmUnpkLrgStsReq(RgMiLrgStsReq, pst, mBuf);
96          break;
97 #endif /* LCRGMILRG */
98       case EVENT_MAC_CELL_CONFIG_REQ:
99          {
100             /* Process MAC cell config */
101             unpackDuMacCellCfg(MacProcCellCfgReq, pst, mBuf);
102             break;
103          }
104       case EVENT_MAC_CELL_START:
105          {
106             /* Process MAC cell start request */
107             unpackMacCellStart(MacProcCellStart, pst, mBuf);
108             break;
109          }
110       case EVENT_MAC_CELL_STOP:
111          {
112             /* Process MAC cell stop request */
113             unpackMacCellStop(MacProcCellStop, pst, mBuf);
114             break;
115          }
116       case EVENT_MAC_DL_CCCH_IND:
117          {
118             /* Process DL CCCH Ind */
119             unpackMacDlCcchInd(MacProcDlCcchInd, pst, mBuf);
120             break;
121          }
122       case EVENT_MAC_UE_CREATE_REQ:
123          {
124             /* Process Ue Create Request */
125             unpackMacUeCreateReq(MacProcUeCreateReq, pst, mBuf);
126             break;
127          }
128       case EVENT_MAC_UE_RECONFIG_REQ:
129          {
130             /* Process Ue Reconfig Request */
131             unpackMacUeReconfigReq(MacProcUeReconfigReq, pst, mBuf);
132             break;
133          }
134       case EVENT_MAC_UE_DELETE_REQ:
135          {
136             /* Process UE Delete Request */  
137             unpackMacUeDeleteReq(MacProcUeDeleteReq, pst, mBuf);
138             break;
139          }
140       case EVENT_MAC_CELL_DELETE_REQ:
141          {
142             /* Process Cell Delete Request */
143             unpackMacCellDeleteReq(MacProcCellDeleteReq, pst, mBuf);
144             break;
145          }
146       case EVENT_MAC_SLICE_CFG_REQ:
147          {
148             /* Process Slice Configuration Request */
149             unpackMacSliceCfgReq(MacProcSliceCfgReq, pst, mBuf);
150             break;
151          }
152       case EVENT_MAC_SLICE_RECFG_REQ:
153          {
154             /* Process Slice Reconfiguration Request */
155             unpackMacSliceRecfgReq(MacProcSliceRecfgReq, pst, mBuf);
156             break;
157          }
158       case EVENT_MAC_RACH_RESOURCE_REQ:
159          {
160             /* Process Rach Resource Request */
161             unpackMacRachRsrcReq(MacProcRachRsrcReq, pst, mBuf);
162             break;
163          }
164       case EVENT_MAC_RACH_RESOURCE_REL:
165          {
166             /* Process Rach Resource Release */
167             unpackMacRachRsrcRel(MacProcRachRsrcRel, pst, mBuf);
168             break;
169          }
170       case EVENT_MAC_DL_PCCH_IND:
171          {
172             /* Process Pcch indication */
173             unpackMacDlPcchInd(MacProcDlPcchInd, pst, mBuf);
174             break;
175          }
176       case EVENT_MAC_DL_BROADCAST_REQ:
177          {
178             /* Process Dl Broadcast Request */  
179             unpackMacDlBroadcastReq(MacProcDlBroadcastReq, pst, mBuf);
180             break;
181          }
182
183       case EVENT_MAC_UE_RESET_REQ:
184          {
185             /* Process UE Reset Request */  
186             unpackMacUeResetReq(MacProcUeResetReq, pst, mBuf);
187             break;
188          }
189
190       case EVENT_MAC_STATISTICS_REQ:
191          {
192             /* Process Statistics Request */
193             unpackMacStatsReq(MacProcStatsReq, pst, mBuf);
194             break;
195          }
196       
197       case EVENT_MAC_STATS_DELETE_REQ:
198          {
199             /* Process Statistics Delete Request */
200             unpackMacStatsDeleteReq(MacProcStatsDeleteReq, pst, mBuf);
201             break;
202          }
203
204
205       default:
206          RG_FREE_MSG(mBuf);
207          break;
208    }
209 }
210
211 /**
212  * @brief Task Activation callback function Entity RLC. 
213  *
214  * @details
215  *
216  *     Function : MacHdlRlcEvents
217  *     
218  *     Process Messages received from Entity RLC
219  *     
220  *  @param[in]  Pst     *pst, Post structure of the primitive.     
221  *  @param[in]  Buffer *mBuf, Packed primitive parameters in the buffer.
222  *  @param[in]  Reason reason.
223  *  @return  void
224  **/
225 void MacHdlRlcEvents(Pst *pst, Buffer *mBuf)
226 {
227    switch(pst->event)
228    {
229       case EVTRGUBNDREQ:
230          cmUnpkRguBndReq(RgUiRguBndReq, pst, mBuf);
231          break;
232       case EVTRGUUBNDREQ:
233          cmUnpkRguUbndReq(RgUiRguUbndReq, pst, mBuf);
234          break;
235       case EVENT_DL_DATA_TO_MAC:
236          unpackRlcDlData(MacProcRlcDlData, pst, mBuf);
237          break;
238       case EVENT_BO_STATUS_TO_MAC:
239          unpackRlcBoStatus(MacProcRlcBoStatus, pst, mBuf);
240          break;
241       default:
242          RG_FREE_MSG(mBuf);
243          break;
244    }
245 }
246
247 /**
248  * @brief Task Activation callback function Entity Lower MAC 
249  *
250  * @details
251  *
252  *     Function : MacHdlLwrMacEvents
253  *     
254  *     Process Messages received from Entity Lower MAC
255  *     
256  *  @param[in]  Pst     *pst, Post structure of the primitive.     
257  *  @param[in]  Buffer *mBuf, Packed primitive parameters in the buffer.
258  *  @param[in]  Reason reason.
259  *  @return  void
260  **/
261 void MacHdlLwrMacEvents(Pst *pst, Buffer *mBuf)
262 {
263    switch(pst->event)
264    {
265       case EVENT_SLOT_IND_TO_MAC:
266          unpackSlotInd(fapiMacSlotInd, pst, mBuf);
267          break;
268       case EVENT_STOP_IND_TO_MAC:
269          unpackStopInd(fapiMacStopInd, pst, mBuf);
270          break;
271       case EVENT_RACH_IND_TO_MAC:
272          unpackRachInd(fapiMacRachInd, pst, mBuf);
273          break;
274       case EVENT_CRC_IND_TO_MAC:
275          unpackCrcInd(fapiMacCrcInd, pst, mBuf);
276          break;
277       case EVENT_RX_DATA_IND_TO_MAC:
278          unpackRxDataInd(fapiMacRxDataInd, pst, mBuf);
279          break;
280       case EVENT_UCI_IND_TO_MAC:
281          unpackUciInd(FapiMacUciInd, pst, mBuf);
282          break;
283       default:
284          RG_FREE_MSG(mBuf);
285          break;
286    }
287 }
288
289 #ifdef CALL_FLOW_DEBUG_LOG
290 /**
291 * @brief Function prints src, dest, msg infor about all the msgs that received.
292 *
293 * @details
294 *
295 *     Function : callFlowMacActvTsk 
296 *
297 *     Function prints src, dest, msg infor about all the msgs that received
298 *
299 *  @param[in]  Pst     *pst, Post structure of the primitive.
300 *
301 *  @return  void
302 **/
303
304 void callFlowMacActvTsk(Pst *pst)
305 {
306    char sourceTask[50];
307    char destTask[50]="ENTMAC";
308    char message[100];
309
310    switch(pst->srcEnt)
311    {
312       case ENTDUAPP:
313          {
314             strcpy(sourceTask,"ENTDUAPP");
315             switch(pst->event)
316             {
317 #ifdef LCRGMILRG
318                case EVTLRGCFGREQ:
319                   strcpy(message,"EVTLRGCFGREQ");
320                   break;
321                case EVTMACSCHGENCFGREQ:
322                   strcpy(message,"EVTMACSCHGENCFGREQ");
323                   break;
324 #endif /* LCRGMILRG */
325                case EVENT_MAC_CELL_CONFIG_REQ:
326                   strcpy(message,"EVENT_MAC_CELL_CONFIG_REQ");
327                   break;
328                case EVENT_MAC_CELL_START:
329                   strcpy(message,"EVENT_MAC_CELL_START");
330                   break;
331                case EVENT_MAC_CELL_STOP:
332                   strcpy(message,"EVENT_MAC_CELL_STOP");
333                   break;
334                case EVENT_MAC_DL_CCCH_IND:
335                   strcpy(message,"EVENT_MAC_DL_CCCH_IND");
336                   break;
337                case EVENT_MAC_UE_CREATE_REQ:
338                   strcpy(message,"EVENT_MAC_UE_CREATE_REQ");
339                   break;
340                case EVENT_MAC_UE_RECONFIG_REQ:
341                   strcpy(message,"EVENT_MAC_UE_RECONFIG_REQ");
342                   break;
343                case EVENT_MAC_UE_DELETE_REQ:
344                   strcpy(message,"EVENT_MAC_UE_DELETE_REQ");
345                   break;
346                case EVENT_MAC_CELL_DELETE_REQ:
347                   strcpy(message,"EVENT_MAC_CELL_DELETE_REQ");
348                   break;
349                case EVENT_MAC_SLICE_CFG_REQ:
350                   strcpy(message,"EVENT_MAC_SLICE_CFG_REQ");
351                   break;
352                case EVENT_MAC_SLICE_RECFG_REQ:
353                   strcpy(message,"EVENT_MAC_SLICE_RECFG_REQ");
354                   break;
355                case EVENT_MAC_STATISTICS_REQ:
356                   strcpy(message,"EVENT_MAC_STATISTICS_REQ");
357                   break;
358                case EVENT_MAC_STATS_DELETE_REQ:
359                   strcpy(message,"EVENT_MAC_STATS_DELETE_REQ");
360                   break;
361                default:
362                   strcpy(message,"Invalid Event");
363                   break;
364             }
365             break;
366          }
367       case ENTRLC:
368          { 
369             strcpy(sourceTask,"ENTRLC");
370             switch(pst->event)
371             {
372 #ifdef LCRGUIRGU
373                case EVTRGUBNDREQ:
374                   strcpy(message,"EVTRGUBNDREQ");
375                   break;
376                case EVTRGUUBNDREQ:
377                   strcpy(message,"EVTRGUUBNDREQ");
378                   break;
379                case EVENT_DL_DATA_TO_MAC:
380                   strcpy(message,"EVENT_DL_DATA_TO_MAC");
381                   break;
382                case EVENT_BO_STATUS_TO_MAC:
383                   strcpy(message,"EVENT_BO_STATUS_TO_MAC");
384                   break;
385 #endif
386                default:
387                   strcpy(message,"Invalid Event");
388                   break;
389             }
390
391             break;
392          }
393       case ENTLWRMAC:
394          {
395             strcpy(sourceTask,"ENTLWRMAC");
396             switch(pst->event)
397             {
398                case EVENT_SLOT_IND_TO_MAC:
399                   strcpy(message,"EVENT_SLOT_IND_TO_MAC");
400                   break;
401                case EVENT_STOP_IND_TO_MAC:
402                   strcpy(message,"EVENT_STOP_IND_TO_MAC");
403                   break;
404                case EVENT_RACH_IND_TO_MAC:
405                   strcpy(message,"EVENT_RACH_IND_TO_MAC");
406                   break;
407                case EVENT_CRC_IND_TO_MAC:
408                   strcpy(message,"EVENT_CRC_IND_TO_MAC");
409                   break;
410                case EVENT_RX_DATA_IND_TO_MAC:
411                   strcpy(message,"EVENT_RX_DATA_IND_TO_MAC");
412                   break;
413                case EVENT_UCI_IND_TO_MAC:
414                   strcpy(message,"EVENT_UCI_IND_TO_MAC");
415                   break;
416                default:
417                   strcpy(message,"Invalid Event");
418                   break;
419             }
420
421             break;
422          }
423       case ENTMAC:
424          {
425             if(pst->srcInst == 1)
426             {
427                strcpy(sourceTask,"ENTSCH");
428                switch(pst->event)
429                {
430                   case EVENT_SLICE_CFG_RSP_TO_MAC:
431                      {
432                         strcpy(message,"EVENT_SLICE_CFG_RSP_TO_MAC");
433                         break;
434                      }
435                   case EVENT_SLICE_RECFG_RSP_TO_MAC:
436                      {
437                         strcpy(message,"EVENT_SLICE_RECFG_RSP_TO_MAC");
438                         break;
439                      }
440                   case EVENT_SCH_CELL_CFG_CFM:
441                      {
442                         strcpy(message,"EVENT_SCH_CELL_CFG_CFM");
443                         break;
444                      }
445                   case EVENT_UE_CONFIG_RSP_TO_MAC:
446                      {
447                         strcpy(message,"EVENT_UE_CONFIG_RSP_TO_MAC");
448                         break;
449                      }
450                   case EVENT_UE_RECONFIG_RSP_TO_MAC:
451                      {
452                         strcpy(message,"EVENT_UE_RECONFIG_RSP_TO_MAC");
453                         break;
454                      }
455                   case EVENT_DL_SCH_INFO:
456                      {
457                         strcpy(message,"EVENT_DL_SCH_INFO");
458                         break;
459                      }
460                   case EVENT_UL_SCH_INFO:
461                      {
462                         strcpy(message,"EVENT_UL_SCH_INFO");
463                         break;
464                      }
465                   case EVENT_RACH_RESOURCE_RESPONSE_TO_MAC:
466                      {
467                         strcpy(message,"EVENT_RACH_RESOURCE_RESPONSE_TO_MAC");
468                         break;
469                      }
470                   case EVENT_DL_PAGING_ALLOC:
471                      {
472                         strcpy(message,"EVENT_DL_PAGING_ALLOC");
473                         break;
474                      }
475                   case EVENT_UE_DELETE_RSP_TO_MAC:
476                      {
477                         strcpy(message,"EVENT_UE_DELETE_RSP_TO_MAC");
478                         break;
479                      }
480                   case EVENT_CELL_DELETE_RSP_TO_MAC:
481                      {
482                         strcpy(message,"EVENT_CELL_DELETE_RSP_TO_MAC");
483                         break;
484                      }
485                   case EVENT_DL_REL_HQ_PROC:
486                      {
487                         strcpy(message,"EVENT_DL_REL_HQ_PROC");
488                         break;
489                      }
490                   case EVENT_STATISTICS_RSP_TO_MAC:
491                      {
492                         strcpy(message,"EVENT_STATISTICS_RSP_TO_MAC");
493                         break;
494                      }
495                   case EVENT_STATISTICS_IND_TO_MAC:
496                      {
497                         strcpy(message,"EVENT_STATISTICS_IND_TO_MAC");
498                         break;
499                      }
500                   case EVENT_STATISTICS_DELETE_RSP_TO_MAC:
501                      {
502                         strcpy(message,"EVENT_STATISTICS_DELETE_RSP_TO_MAC");
503                         break;
504                      }
505                   default:
506                      strcpy(message,"Invalid Event");
507                      break;
508                }
509             }
510             break;
511          }
512       default:
513          {
514             strcpy(sourceTask,"Invalid Source Entity Id");
515             break;
516          }
517    }
518    DU_LOG("\nCall Flow: %s -> %s : %s\n", sourceTask, destTask, message);
519 }
520 #endif
521
522 \f
523 /**
524  * @brief Task Activation callback function. 
525  *
526  * @details
527  *
528  *     Function : macActvTsk
529  *     
530  *     Primitives invoked by MAC's users/providers through
531  *     a loosely coupled interface arrive here by means of 
532  *     SSI's message handling. This API is registered with
533  *     SSI during the Task Registration of MAC.
534  *     
535  *  @param[in]  Pst     *pst, Post structure of the primitive.     
536  *  @param[in]  Buffer *mBuf, Packed primitive parameters in the buffer.
537  *  @param[in]  Reason reason.
538  *  @return  uint8_t
539  *      -# ROK
540  **/
541 uint8_t macActvTsk(Pst *pst, Buffer *mBuf)
542 {
543
544 #ifdef CALL_FLOW_DEBUG_LOG
545    callFlowMacActvTsk(pst);
546 #endif
547
548    switch(pst->srcEnt)
549    {
550       case ENTDUAPP:
551          MacHdlDuappEvents(pst, mBuf);
552          break;
553       case ENTRLC:
554          MacHdlRlcEvents(pst, mBuf);
555          break;
556       case ENTLWRMAC:
557          MacHdlLwrMacEvents(pst, mBuf);
558          break;
559       default:
560          RG_FREE_MSG(mBuf);
561          break;
562    }
563    ODU_EXIT_TASK();
564    return ROK;
565 }/* end of MacActvTsk */
566
567 /**
568  * @brief Callback function for events from entity SCH
569  *
570  * @details
571  *
572  *     Function :MacMessageRouter
573  *     
574  *     Process Messages received from Entity SCH
575  *     
576  *  @param[in]  Pst     *pst, Post structure of the primitive.     
577  *  @param[in]  Buffer *mBuf, Packed primitive parameters in the buffer.
578  *  @param[in]  Reason reason.
579  *  @return  void
580  **/
581 uint8_t MacMessageRouter(Pst *pst, void *msg)
582 {
583 #ifdef CALL_FLOW_DEBUG_LOG
584    callFlowMacActvTsk(pst);
585 #endif
586
587    switch(pst->event)
588    {
589       case EVENT_SLICE_CFG_RSP_TO_MAC:
590          {
591             MacProcSchSliceCfgRsp(pst, (SchSliceCfgRsp *)msg);
592             break;
593          }
594       case EVENT_SLICE_RECFG_RSP_TO_MAC:
595          {
596             MacProcSchSliceRecfgRsp(pst, (SchSliceRecfgRsp *)msg);
597             break;
598          }
599       case EVENT_SCH_CELL_CFG_CFM:
600          {
601             MacProcSchCellCfgCfm(pst, (SchCellCfgCfm *)msg);
602             break;
603          }
604       case EVENT_UE_CONFIG_RSP_TO_MAC:
605          {
606             MacProcSchUeCfgRsp(pst, (SchUeCfgRsp *)msg);
607             break;
608          }
609       case EVENT_UE_RECONFIG_RSP_TO_MAC:
610          {
611             MacProcSchUeRecfgRsp(pst, (SchUeRecfgRsp *)msg);
612             break;
613          }
614       case EVENT_DL_SCH_INFO:
615          {
616             MacProcDlAlloc(pst, (DlSchedInfo *)msg);
617             break;
618          }
619       case EVENT_UL_SCH_INFO:
620          {
621             MacProcUlSchInfo(pst, (UlSchedInfo *)msg);
622             break;
623          }
624       case EVENT_RACH_RESOURCE_RESPONSE_TO_MAC:
625          {
626             MacProcSchRachRsrcRsp(pst, (SchRachRsrcRsp *)msg);
627             break;
628          }
629       case EVENT_DL_PAGING_ALLOC:
630          {
631             MacProcDlPageAlloc(pst, (DlPageAlloc *)msg);
632             break;
633          }
634       case EVENT_UE_DELETE_RSP_TO_MAC:
635          {
636             MacProcSchUeDeleteRsp(pst, (SchUeDeleteRsp *)msg);
637             break;
638          }
639       case EVENT_CELL_DELETE_RSP_TO_MAC:
640          {
641             MacProcSchCellDeleteRsp(pst, (SchCellDeleteRsp *)msg);
642             break;
643          }
644       case EVENT_DL_REL_HQ_PROC: 
645          {
646             MacSchReleaseDlHarqProc(pst, (SchRlsHqInfo *)msg);
647             break;
648          }
649       case EVENT_STATISTICS_RSP_TO_MAC:
650          {
651             MacProcSchStatsRsp(pst, (SchStatsRsp *)msg);
652             break;
653          }
654       case EVENT_STATISTICS_IND_TO_MAC:
655          {
656             MacProcSchStatsInd(pst, (SchStatsInd *)msg);
657             break;
658          }
659       case EVENT_STATISTICS_DELETE_RSP_TO_MAC:
660          {
661             MacProcSchStatsDeleteRsp(pst, (SchStatsDeleteRsp *)msg);
662             break;
663          }
664       default:
665          {
666             return RFAILED;
667          }
668    }
669    return ROK;
670 }
671
672 \f
673 /**********************************************************************
674  
675          End of file
676 **********************************************************************/