88fea7bd10504d18d81791da78b6e76f2be2ec69
[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
177       default:
178          RG_FREE_MSG(mBuf);
179          break;
180    }
181 }
182
183 /**
184  * @brief Task Activation callback function Entity RLC. 
185  *
186  * @details
187  *
188  *     Function : MacHdlRlcEvents
189  *     
190  *     Process Messages received from Entity RLC
191  *     
192  *  @param[in]  Pst     *pst, Post structure of the primitive.     
193  *  @param[in]  Buffer *mBuf, Packed primitive parameters in the buffer.
194  *  @param[in]  Reason reason.
195  *  @return  void
196  **/
197 void MacHdlRlcEvents(Pst *pst, Buffer *mBuf)
198 {
199    switch(pst->event)
200    {
201       case EVTRGUBNDREQ:
202          cmUnpkRguBndReq(RgUiRguBndReq, pst, mBuf);
203          break;
204       case EVTRGUUBNDREQ:
205          cmUnpkRguUbndReq(RgUiRguUbndReq, pst, mBuf);
206          break;
207       case EVENT_DL_DATA_TO_MAC:
208          unpackRlcDlData(MacProcRlcDlData, pst, mBuf);
209          break;
210       case EVENT_BO_STATUS_TO_MAC:
211          unpackRlcBoStatus(MacProcRlcBoStatus, pst, mBuf);
212          break;
213       default:
214          RG_FREE_MSG(mBuf);
215          break;
216    }
217 }
218
219 /**
220  * @brief Task Activation callback function Entity Lower MAC 
221  *
222  * @details
223  *
224  *     Function : MacHdlLwrMacEvents
225  *     
226  *     Process Messages received from Entity Lower MAC
227  *     
228  *  @param[in]  Pst     *pst, Post structure of the primitive.     
229  *  @param[in]  Buffer *mBuf, Packed primitive parameters in the buffer.
230  *  @param[in]  Reason reason.
231  *  @return  void
232  **/
233 void MacHdlLwrMacEvents(Pst *pst, Buffer *mBuf)
234 {
235    switch(pst->event)
236    {
237       case EVENT_SLOT_IND_TO_MAC:
238          unpackSlotInd(fapiMacSlotInd, pst, mBuf);
239          break;
240       case EVENT_STOP_IND_TO_MAC:
241          unpackStopInd(fapiMacStopInd, pst, mBuf);
242          break;
243       case EVENT_RACH_IND_TO_MAC:
244          unpackRachInd(fapiMacRachInd, pst, mBuf);
245          break;
246       case EVENT_CRC_IND_TO_MAC:
247          unpackCrcInd(fapiMacCrcInd, pst, mBuf);
248          break;
249       case EVENT_RX_DATA_IND_TO_MAC:
250          unpackRxDataInd(fapiMacRxDataInd, pst, mBuf);
251          break;
252       case EVENT_UCI_IND_TO_MAC:
253          unpackUciInd(FapiMacUciInd, pst, mBuf);
254          break;
255       default:
256          RG_FREE_MSG(mBuf);
257          break;
258    }
259 }
260
261 #ifdef CALL_FLOW_DEBUG_LOG
262 /**
263 * @brief Function prints src, dest, msg infor about all the msgs that received.
264 *
265 * @details
266 *
267 *     Function : callFlowMacActvTsk 
268 *
269 *     Function prints src, dest, msg infor about all the msgs that received
270 *
271 *  @param[in]  Pst     *pst, Post structure of the primitive.
272 *
273 *  @return  void
274 **/
275
276 void callFlowMacActvTsk(Pst *pst)
277 {
278    char sourceTask[50];
279    char destTask[50]="ENTMAC";
280    char message[100];
281
282    switch(pst->srcEnt)
283    {
284       case ENTDUAPP:
285          {
286             strcpy(sourceTask,"ENTDUAPP");
287             switch(pst->event)
288             {
289 #ifdef LCRGMILRG
290                case EVTLRGCFGREQ:
291                   strcpy(message,"EVTLRGCFGREQ");
292                   break;
293                case EVTMACSCHGENCFGREQ:
294                   strcpy(message,"EVTMACSCHGENCFGREQ");
295                   break;
296 #endif /* LCRGMILRG */
297                case EVENT_MAC_CELL_CONFIG_REQ:
298                   strcpy(message,"EVENT_MAC_CELL_CONFIG_REQ");
299                   break;
300                case EVENT_MAC_CELL_START:
301                   strcpy(message,"EVENT_MAC_CELL_START");
302                   break;
303                case EVENT_MAC_CELL_STOP:
304                   strcpy(message,"EVENT_MAC_CELL_STOP");
305                   break;
306                case EVENT_MAC_DL_CCCH_IND:
307                   strcpy(message,"EVENT_MAC_DL_CCCH_IND");
308                   break;
309                case EVENT_MAC_UE_CREATE_REQ:
310                   strcpy(message,"EVENT_MAC_UE_CREATE_REQ");
311                   break;
312                case EVENT_MAC_UE_RECONFIG_REQ:
313                   strcpy(message,"EVENT_MAC_UE_RECONFIG_REQ");
314                   break;
315                case EVENT_MAC_UE_DELETE_REQ:
316                   strcpy(message,"EVENT_MAC_UE_DELETE_REQ");
317                   break;
318                case EVENT_MAC_CELL_DELETE_REQ:
319                   strcpy(message,"EVENT_MAC_CELL_DELETE_REQ");
320                   break;
321                case EVENT_MAC_SLICE_CFG_REQ:
322                   strcpy(message,"EVENT_MAC_SLICE_CFG_REQ");
323                   break;
324                case EVENT_MAC_SLICE_RECFG_REQ:
325                   strcpy(message,"EVENT_MAC_SLICE_RECFG_REQ");
326                   break;
327                default:
328                   strcpy(message,"Invalid Event");
329                   break;
330             }
331             break;
332          }
333       case ENTRLC:
334          { 
335             strcpy(sourceTask,"ENTRLC");
336             switch(pst->event)
337             {
338 #ifdef LCRGUIRGU
339                case EVTRGUBNDREQ:
340                   strcpy(message,"EVTRGUBNDREQ");
341                   break;
342                case EVTRGUUBNDREQ:
343                   strcpy(message,"EVTRGUUBNDREQ");
344                   break;
345                case EVENT_DL_DATA_TO_MAC:
346                   strcpy(message,"EVENT_DL_DATA_TO_MAC");
347                   break;
348                case EVENT_BO_STATUS_TO_MAC:
349                   strcpy(message,"EVENT_BO_STATUS_TO_MAC");
350                   break;
351 #endif
352                default:
353                   strcpy(message,"Invalid Event");
354                   break;
355             }
356
357             break;
358          }
359       case ENTLWRMAC:
360          {
361             strcpy(sourceTask,"ENTLWRMAC");
362             switch(pst->event)
363             {
364                case EVENT_SLOT_IND_TO_MAC:
365                   strcpy(message,"EVENT_SLOT_IND_TO_MAC");
366                   break;
367                case EVENT_STOP_IND_TO_MAC:
368                   strcpy(message,"EVENT_STOP_IND_TO_MAC");
369                   break;
370                case EVENT_RACH_IND_TO_MAC:
371                   strcpy(message,"EVENT_RACH_IND_TO_MAC");
372                   break;
373                case EVENT_CRC_IND_TO_MAC:
374                   strcpy(message,"EVENT_CRC_IND_TO_MAC");
375                   break;
376                case EVENT_RX_DATA_IND_TO_MAC:
377                   strcpy(message,"EVENT_RX_DATA_IND_TO_MAC");
378                   break;
379                case EVENT_UCI_IND_TO_MAC:
380                   strcpy(message,"EVENT_UCI_IND_TO_MAC");
381                   break;
382                default:
383                   strcpy(message,"Invalid Event");
384                   break;
385             }
386
387             break;
388          }
389       case ENTMAC:
390          {
391             if(pst->srcInst == 1)
392             {
393                strcpy(sourceTask,"ENTSCH");
394                switch(pst->event)
395                {
396                   case EVENT_SLICE_CFG_RSP_TO_MAC:
397                      {
398                         strcpy(message,"EVENT_SLICE_CFG_RSP_TO_MAC");
399                         break;
400                      }
401                   case EVENT_SLICE_RECFG_RSP_TO_MAC:
402                      {
403                         strcpy(message,"EVENT_SLICE_RECFG_RSP_TO_MAC");
404                         break;
405                      }
406                   case EVENT_SCH_CELL_CFG_CFM:
407                      {
408                         strcpy(message,"EVENT_SCH_CELL_CFG_CFM");
409                         break;
410                      }
411                   case EVENT_UE_CONFIG_RSP_TO_MAC:
412                      {
413                         strcpy(message,"EVENT_UE_CONFIG_RSP_TO_MAC");
414                         break;
415                      }
416                   case EVENT_UE_RECONFIG_RSP_TO_MAC:
417                      {
418                         strcpy(message,"EVENT_UE_RECONFIG_RSP_TO_MAC");
419                         break;
420                      }
421                   case EVENT_DL_SCH_INFO:
422                      {
423                         strcpy(message,"EVENT_DL_SCH_INFO");
424                         break;
425                      }
426                   case EVENT_UL_SCH_INFO:
427                      {
428                         strcpy(message,"EVENT_UL_SCH_INFO");
429                         break;
430                      }
431                   case EVENT_RACH_RESOURCE_RESPONSE_TO_MAC:
432                      {
433                         strcpy(message,"EVENT_RACH_RESOURCE_RESPONSE_TO_MAC");
434                         break;
435                      }
436                   case EVENT_DL_PAGING_ALLOC:
437                      {
438                         strcpy(message,"EVENT_DL_PAGING_ALLOC");
439                         break;
440                      }
441                   case EVENT_UE_DELETE_RSP_TO_MAC:
442                      {
443                         strcpy(message,"EVENT_UE_DELETE_RSP_TO_MAC");
444                         break;
445                      }
446                   case EVENT_CELL_DELETE_RSP_TO_MAC:
447                      {
448                         strcpy(message,"EVENT_CELL_DELETE_RSP_TO_MAC");
449                         break;
450                      }
451                   case EVENT_DL_REL_HQ_PROC:
452                      {
453                         strcpy(message,"EVENT_DL_REL_HQ_PROC");
454                         break;
455                      }
456                   default:
457                      strcpy(message,"Invalid Event");
458                      break;
459                }
460             }
461             break;
462          }
463       default:
464          {
465             strcpy(sourceTask,"Invalid Source Entity Id");
466             break;
467          }
468    }
469    DU_LOG("\nCall Flow: %s -> %s : %s\n", sourceTask, destTask, message);
470 }
471 #endif
472
473 \f
474 /**
475  * @brief Task Activation callback function. 
476  *
477  * @details
478  *
479  *     Function : macActvTsk
480  *     
481  *     Primitives invoked by MAC's users/providers through
482  *     a loosely coupled interface arrive here by means of 
483  *     SSI's message handling. This API is registered with
484  *     SSI during the Task Registration of MAC.
485  *     
486  *  @param[in]  Pst     *pst, Post structure of the primitive.     
487  *  @param[in]  Buffer *mBuf, Packed primitive parameters in the buffer.
488  *  @param[in]  Reason reason.
489  *  @return  uint8_t
490  *      -# ROK
491  **/
492 uint8_t macActvTsk(Pst *pst, Buffer *mBuf)
493 {
494
495 #ifdef CALL_FLOW_DEBUG_LOG
496    callFlowMacActvTsk(pst);
497 #endif
498
499    switch(pst->srcEnt)
500    {
501       case ENTDUAPP:
502          MacHdlDuappEvents(pst, mBuf);
503          break;
504       case ENTRLC:
505          MacHdlRlcEvents(pst, mBuf);
506          break;
507       case ENTLWRMAC:
508          MacHdlLwrMacEvents(pst, mBuf);
509          break;
510       default:
511          RG_FREE_MSG(mBuf);
512          break;
513    }
514    ODU_EXIT_TASK();
515    return ROK;
516 }/* end of MacActvTsk */
517
518 /**
519  * @brief Callback function for events from entity SCH
520  *
521  * @details
522  *
523  *     Function :MacMessageRouter
524  *     
525  *     Process Messages received from Entity SCH
526  *     
527  *  @param[in]  Pst     *pst, Post structure of the primitive.     
528  *  @param[in]  Buffer *mBuf, Packed primitive parameters in the buffer.
529  *  @param[in]  Reason reason.
530  *  @return  void
531  **/
532 uint8_t MacMessageRouter(Pst *pst, void *msg)
533 {
534 #ifdef CALL_FLOW_DEBUG_LOG
535    callFlowMacActvTsk(pst);
536 #endif
537
538    switch(pst->event)
539    {
540       case EVENT_SLICE_CFG_RSP_TO_MAC:
541          {
542             MacProcSchSliceCfgRsp(pst, (SchSliceCfgRsp *)msg);
543             break;
544          }
545       case EVENT_SLICE_RECFG_RSP_TO_MAC:
546          {
547             MacProcSchSliceRecfgRsp(pst, (SchSliceRecfgRsp *)msg);
548             break;
549          }
550       case EVENT_SCH_CELL_CFG_CFM:
551          {
552             MacProcSchCellCfgCfm(pst, (SchCellCfgCfm *)msg);
553             break;
554          }
555       case EVENT_UE_CONFIG_RSP_TO_MAC:
556          {
557             MacProcSchUeCfgRsp(pst, (SchUeCfgRsp *)msg);
558             break;
559          }
560       case EVENT_UE_RECONFIG_RSP_TO_MAC:
561          {
562             MacProcSchUeRecfgRsp(pst, (SchUeRecfgRsp *)msg);
563             break;
564          }
565       case EVENT_DL_SCH_INFO:
566          {
567             MacProcDlAlloc(pst, (DlSchedInfo *)msg);
568             break;
569          }
570       case EVENT_UL_SCH_INFO:
571          {
572             MacProcUlSchInfo(pst, (UlSchedInfo *)msg);
573             break;
574          }
575       case EVENT_RACH_RESOURCE_RESPONSE_TO_MAC:
576          {
577             MacProcSchRachRsrcRsp(pst, (SchRachRsrcRsp *)msg);
578             break;
579          }
580       case EVENT_DL_PAGING_ALLOC:
581          {
582             MacProcDlPageAlloc(pst, (DlPageAlloc *)msg);
583             break;
584          }
585       case EVENT_UE_DELETE_RSP_TO_MAC:
586          {
587             MacProcSchUeDeleteRsp(pst, (SchUeDeleteRsp *)msg);
588             break;
589          }
590       case EVENT_CELL_DELETE_RSP_TO_MAC:
591          {
592             MacProcSchCellDeleteRsp(pst, (SchCellDeleteRsp *)msg);
593             break;
594          }
595       case EVENT_DL_REL_HQ_PROC: 
596          {
597             MacSchReleaseDlHarqProc(pst, (SchRlsHqInfo *)msg);
598             break;
599          }
600       default:
601          {
602             return RFAILED;
603          }
604    }
605    return ROK;
606 }
607
608 \f
609 /**********************************************************************
610  
611          End of file
612 **********************************************************************/