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