MAC PDU de-mux and warning fixes
[o-du/l2.git] / src / 5gnrmac / mac_msg_hdl.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 /* header include files -- defines (.h)  */
20 #include "envopt.h"        /* environment options */
21 #include "envdep.h"        /* environment dependent */
22 #include "envind.h"        /* environment independent */
23 #include "gen.h"           /* general layer */
24 #include "ssi.h"           /* system services */
25 #include "cm5.h"           /* common timers defines */
26 #include "cm_hash.h"       /* common hash list defines */
27 #include "cm_llist.h"      /* common linked list defines */
28 #include "cm_mblk.h"       /* memory management */
29 #include "cm_tkns.h"       /* common tokens */
30 #include "cm_lte.h"        /* common tokens */
31 #include "rgu.h"
32 #include "tfu.h"
33 #include "rg_sch_inf.h"
34 #include "rg_env.h"
35 #include "lrg.h"
36 #include "crg.h"
37 #include "rg.h"
38 #include "du_log.h"
39 #include "lwr_mac.h"
40
41 /* header/extern include files (.x) */
42 #include "gen.x"           /* general layer typedefs */
43 #include "ssi.x"           /* system services typedefs */
44 #include "cm5.x"           /* common timers */
45 #include "cm_hash.x"       /* common hash list */
46 #include "cm_lib.x"        /* common library */
47 #include "cm_llist.x"      /* common linked list */
48 #include "cm_mblk.x"       /* memory management */
49 #include "cm_tkns.x"       /* common tokens */
50 #include "cm_lte.x"        /* common tokens */
51 #include "rgu.x"
52 #include "tfu.x"
53 #include "rg_sch_inf.x"
54 #include "lrg.x"
55 #include "crg.x"
56 #include "rg_prg.x"
57 #include "du_app_mac_inf.h"
58 #include "rg.x"
59 #include "lwr_mac_fsm.h"
60 #include "mac.h"
61
62 /* This file contains message handling functionality for MAC */
63
64 extern void sendToLowerMac(uint16_t msgType, uint32_t msgLen, void *msg);
65
66 /* Function pointer for sending crc ind from MAC to SCH */
67 MacSchCrcIndFunc macSchCrcIndOpts[]=
68 {
69    packMacSchCrcInd,
70    macSchCrcInd,
71    packMacSchCrcInd
72 };
73
74 /*******************************************************************
75  *
76  * @brief Sends CRC Indication to SCH
77  *
78  * @details
79  *
80  *    Function : sendCrcIndMacToSch 
81  *
82  *    Functionality:
83  *       Sends CRC Indication to SCH
84  *
85  * @params[in] 
86  * @return ROK     - success
87  *         RFAILED - failure
88  *
89   ****************************************************************/
90 int sendCrcIndMacToSch(CrcIndInfo *crcInd)
91 {
92    Pst pst;
93  
94    fillMacToSchPst(&pst);
95    pst.event = EVENT_CRC_IND_TO_SCH;
96  
97    return(*macSchCrcIndOpts[pst.selector])(&pst, crcInd);
98 }
99  
100 /*******************************************************************
101  *
102  * @brief Processes CRC Indication from PHY
103  *
104  * @details
105  *
106  *    Function : fapiMacCrcInd
107  *
108  *    Functionality:
109  *       Processes CRC Indication from PHY
110  *
111  * @params[in] Post Structure Pointer
112  *             Crc Indication Pointer
113  * @return ROK     - success
114  *         RFAILED - failure
115  *
116  * ****************************************************************/
117 uint16_t fapiMacCrcInd(Pst *pst, CrcInd *crcInd)
118 {
119    CrcIndInfo   crcIndInfo;
120  
121    DU_LOG("\nMAC : Received CRC indication");
122
123    /* Considering one pdu and one preamble */ 
124    crcIndInfo.cellId = macCb.macCell->cellId;;
125    crcIndInfo.crnti = crcInd->crcInfo[0].rnti;
126    crcIndInfo.timingInfo.sfn = crcInd->timingInfo.sfn;
127    crcIndInfo.timingInfo.slot = crcInd->timingInfo.slot;
128    crcIndInfo.numCrcInd = crcInd->crcInfo[0].numCb;
129    crcIndInfo.crcInd[0] = crcInd->crcInfo[0].cbCrcStatus[0];
130  
131    return(sendCrcIndMacToSch(&crcIndInfo));
132 }
133  
134 /*******************************************************************
135  *
136  * @brief Process Rx Data Ind at MAC
137  *
138  * @details
139  *
140  *    Function : fapiMacRxDataInd
141  *
142  *    Functionality:
143  *       Process Rx Data Ind at MAC
144  *
145  * @params[in] Post structure
146  *             Rx Data Indication
147  * @return ROK     - success
148  *         RFAILED - failure
149  *
150  * ****************************************************************/
151 uint16_t fapiMacRxDataInd(Pst *pst, RxDataInd *rxDataInd)
152 {
153    uint16_t pduIdx;
154  
155    DU_LOG("\nMAC : Received Rx Data indication");
156    for(pduIdx = 0; pduIdx < rxDataInd->numPdus; pduIdx++)
157    {
158       unpackRxData(rxDataInd->timingInfo, &rxDataInd->pdus[pduIdx]);
159    }
160    return ROK;
161 }
162
163 /*******************************************************************
164  *
165  * @brief Processes DL data from RLC
166  *
167  * @details
168  *
169  *    Function : MacRlcProcDlData 
170  *
171  *    Functionality:
172  *      Processes DL data from RLC
173  *
174  * @params[in] Post structure
175  *             DL data
176  * @return ROK     - success
177  *         RFAILED - failure
178  *
179  * ****************************************************************/
180 uint16_t MacRlcProcDlData(Pst* pst, SpId spId, RlcMacData *dlData)
181 {
182    return ROK;
183 }
184
185 /*******************************************************************
186  *
187  * @brief Processes BO status from RLC
188  *
189  * @details
190  *
191  *    Function : MacRlcProcBOStatus
192  *
193  *    Functionality:
194  *      Processes BO status from RLC
195  *
196  * @params[in] Post structure
197  *             BO status
198  * @return ROK     - success
199  *         RFAILED - failure
200  *
201  * ****************************************************************/
202 uint16_t MacRlcProcBOStatus(Pst* pst, SpId spId, RlcMacBOStatus*      boStatus)
203 {
204    return ROK;
205 }
206
207
208 /*******************************************************************
209  *
210  * @brief Handles cell start reuqest from DU APP
211  *
212  * @details
213  *
214  *    Function : MacHdlCellStartReq
215  *
216  *    Functionality:
217  *      Handles cell start reuqest from DU APP
218  *
219  * @params[in] Post structure pointer
220  *             Cell Start Request info pointer 
221  * @return ROK     - success
222  *         RFAILED - failure
223  *
224  * ****************************************************************/
225 uint16_t MacHdlCellStartReq(Pst *pst, MacCellStartInfo  *cellStartInfo)
226 {
227    DU_LOG("\nMAC : Handling cell start request");
228    sendToLowerMac(START_REQUEST, 0, cellStartInfo);
229
230    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStartInfo, \
231            sizeof(MacCellStartInfo));
232
233    return ROK;
234 }
235
236 /*******************************************************************
237  *
238  * @brief Handles cell stop request from DU APP
239  *
240  * @details
241  *
242  *    Function : MacHdlCellStartReq
243  *
244  *    Functionality:
245  *        Handles cell stop request from DU APP
246  *
247  * @params[in] Post structure pointer
248  *             Mac Cell stop information
249  * @return ROK     - success
250  *         RFAILED - failure
251  *
252  * ****************************************************************/
253 uint16_t MacHdlCellStopReq(Pst *pst, MacCellStopInfo  *cellStopInfo)
254 {
255    #ifdef FAPI
256    DU_LOG("\nMAC : Sending cell stop request to Lower Mac");
257    sendToLowerMac(FAPI_STOP_REQUEST, 0, cellStopInfo);
258    #endif
259
260    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStopInfo, \
261            sizeof(MacCellStopInfo));
262  
263    return ROK;
264 }
265
266 /**********************************************************************
267          End of file
268 **********************************************************************/
269