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