msg3 and msg4 changes
[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 "mac_upr_inf_api.h"
59 #include "rg.x"
60 #include "lwr_mac_fsm.h"
61 #include "mac.h"
62
63 /* This file contains message handling functionality for MAC */
64
65 extern MacCb  macCb;
66
67 extern void sendToLowerMac(uint16_t msgType, uint32_t msgLen, void *msg);
68
69 /* Function pointer for sending crc ind from MAC to SCH */
70 MacSchCrcIndFunc macSchCrcIndOpts[]=
71 {
72    packMacSchCrcInd,
73    macSchCrcInd,
74    packMacSchCrcInd
75 };
76
77 /*******************************************************************
78  *
79  * @brief Sends CRC Indication to SCH
80  *
81  * @details
82  *
83  *    Function : sendCrcIndMacToSch 
84  *
85  *    Functionality:
86  *       Sends CRC Indication to SCH
87  *
88  * @params[in] 
89  * @return ROK     - success
90  *         RFAILED - failure
91  *
92   ****************************************************************/
93 int sendCrcIndMacToSch(CrcIndInfo *crcInd)
94 {
95    Pst pst;
96  
97    fillMacToSchPst(&pst);
98    pst.event = EVENT_CRC_IND_TO_SCH;
99  
100    return(*macSchCrcIndOpts[pst.selector])(&pst, crcInd);
101 }
102  
103 /*******************************************************************
104  *
105  * @brief Processes CRC Indication from PHY
106  *
107  * @details
108  *
109  *    Function : fapiMacCrcInd
110  *
111  *    Functionality:
112  *       Processes CRC Indication from PHY
113  *
114  * @params[in] Post Structure Pointer
115  *             Crc Indication Pointer
116  * @return ROK     - success
117  *         RFAILED - failure
118  *
119  * ****************************************************************/
120 uint16_t fapiMacCrcInd(Pst *pst, CrcInd *crcInd)
121 {
122    CrcIndInfo   crcIndInfo;
123  
124    DU_LOG("\nMAC : Received CRC indication");
125
126    /* Considering one pdu and one preamble */ 
127    crcIndInfo.cellId = macCb.macCell->cellId;;
128    crcIndInfo.crnti = crcInd->crcInfo[0].rnti;
129    crcIndInfo.timingInfo.sfn = crcInd->timingInfo.sfn;
130    crcIndInfo.timingInfo.slot = crcInd->timingInfo.slot;
131    crcIndInfo.numCrcInd = crcInd->crcInfo[0].numCb;
132    crcIndInfo.crcInd[0] = crcInd->crcInfo[0].cbCrcStatus[0];
133  
134    return(sendCrcIndMacToSch(&crcIndInfo));
135 }
136  
137 /*******************************************************************
138  *
139  * @brief Process Rx Data Ind at MAC
140  *
141  * @details
142  *
143  *    Function : fapiMacRxDataInd
144  *
145  *    Functionality:
146  *       Process Rx Data Ind at MAC
147  *
148  * @params[in] Post structure
149  *             Rx Data Indication
150  * @return ROK     - success
151  *         RFAILED - failure
152  *
153  * ****************************************************************/
154 uint16_t fapiMacRxDataInd(Pst *pst, RxDataInd *rxDataInd)
155 {
156    uint16_t pduIdx;
157  
158    DU_LOG("\nMAC : Received Rx Data indication");
159    for(pduIdx = 0; pduIdx < rxDataInd->numPdus; pduIdx++)
160    {
161       unpackRxData(rxDataInd->timingInfo, &rxDataInd->pdus[pduIdx]);
162    }
163    return ROK;
164 }
165
166 /*******************************************************************
167  *
168  * @brief Processes DL data from RLC
169  *
170  * @details
171  *
172  *    Function : MacRlcProcDlData 
173  *
174  *    Functionality:
175  *      Processes DL data from RLC
176  *
177  * @params[in] Post structure
178  *             DL data
179  * @return ROK     - success
180  *         RFAILED - failure
181  *
182  * ****************************************************************/
183 uint16_t MacRlcProcDlData(Pst* pst, SpId spId, RlcMacData *dlData)
184 {
185    return ROK;
186 }
187
188 /*******************************************************************
189  *
190  * @brief Processes BO status from RLC
191  *
192  * @details
193  *
194  *    Function : MacRlcProcBOStatus
195  *
196  *    Functionality:
197  *      Processes BO status from RLC
198  *
199  * @params[in] Post structure
200  *             BO status
201  * @return ROK     - success
202  *         RFAILED - failure
203  *
204  * ****************************************************************/
205 uint16_t MacRlcProcBOStatus(Pst* pst, SpId spId, RlcMacBOStatus*      boStatus)
206 {
207    return ROK;
208 }
209
210
211 /*******************************************************************
212  *
213  * @brief Handles cell start reuqest from DU APP
214  *
215  * @details
216  *
217  *    Function : MacHdlCellStartReq
218  *
219  *    Functionality:
220  *      Handles cell start reuqest from DU APP
221  *
222  * @params[in] Post structure pointer
223  *             Cell Start Request info pointer 
224  * @return ROK     - success
225  *         RFAILED - failure
226  *
227  * ****************************************************************/
228 uint16_t MacHdlCellStartReq(Pst *pst, MacCellStartInfo  *cellStartInfo)
229 {
230    DU_LOG("\nMAC : Handling cell start request");
231    sendToLowerMac(START_REQUEST, 0, cellStartInfo);
232
233    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStartInfo, \
234            sizeof(MacCellStartInfo));
235
236    return ROK;
237 }
238
239 /*******************************************************************
240  *
241  * @brief Handles cell stop request from DU APP
242  *
243  * @details
244  *
245  *    Function : MacHdlCellStartReq
246  *
247  *    Functionality:
248  *        Handles cell stop request from DU APP
249  *
250  * @params[in] Post structure pointer
251  *             Mac Cell stop information
252  * @return ROK     - success
253  *         RFAILED - failure
254  *
255  * ****************************************************************/
256 uint16_t MacHdlCellStopReq(Pst *pst, MacCellStopInfo  *cellStopInfo)
257 {
258    #ifdef FAPI
259    DU_LOG("\nMAC : Sending cell stop request to Lower Mac");
260    sendToLowerMac(FAPI_STOP_REQUEST, 0, cellStopInfo);
261    #endif
262
263    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStopInfo, \
264            sizeof(MacCellStopInfo));
265  
266    return ROK;
267 }
268
269 /*******************************************************************
270  *
271  * @brief Handles DL CCCH Ind from DU APP
272  *
273  * @details
274  *
275  *    Function : MacHdlDlCcchInd 
276  *
277  *    Functionality:
278  *      Handles DL CCCH Ind from DU APP
279  *
280  * @params[in] Post structure pointer
281  *             DL CCCH Ind pointer 
282  * @return ROK     - success
283  *         RFAILED - failure
284  *
285  * ****************************************************************/
286 uint16_t MacHdlDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
287 {
288    DU_LOG("\nMAC : Handling DL CCCH IND");
289
290         MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, strlen((const char*)dlCcchIndInfo->dlCcchMsg));
291         MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo, sizeof(DlCcchIndInfo));
292    return ROK;
293
294 }
295
296 /*******************************************************************
297  *
298  * @brief Sends UL CCCH Ind to DU APP
299  *
300  * @details
301  *
302  *    Function : macSendUlCcchInd
303  *
304  *    Functionality:
305  *        MAC sends UL CCCH Ind to DU APP
306  *
307  * @params[in] Post structure pointer
308  *            
309  * @return ROK     - success
310  *         RFAILED - failure
311  *
312  * ****************************************************************/
313 uint16_t macSendUlCcchInd(uint8_t *rrcContainer, uint16_t cellId, uint16_t crnti)
314 {
315    Pst pst;
316         uint8_t ret = ROK;
317    UlCcchIndInfo *ulCcchIndInfo = NULLP;
318
319    MAC_ALLOC_SHRABL_BUF(ulCcchIndInfo, sizeof(UlCcchIndInfo));
320    if(!ulCcchIndInfo)
321    {
322                 DU_LOG("\nMAC: Memory failed in macSendUlCcchInd");
323                 return RFAILED;
324         }
325
326         ulCcchIndInfo->cellId = cellId;
327         ulCcchIndInfo->crnti  = crnti;
328         ulCcchIndInfo->ulCcchMsg = rrcContainer;
329
330         /* Fill Pst */
331         pst.selector  = DU_MAC_LWLC;
332         pst.srcEnt    = ENTRG;
333         pst.dstEnt    = ENTDUAPP;
334         pst.dstInst   = 0;
335         pst.srcInst   = macCb.macInst;
336         pst.dstProcId = rgCb[pst.srcInst].rgInit.procId;
337         pst.srcProcId = rgCb[pst.srcInst].rgInit.procId;
338         pst.region    = MAC_MEM_REGION;
339         pst.pool      = MAC_POOL;
340         pst.event     = EVENT_MAC_UL_CCCH_IND;
341         pst.route     = 0;
342         pst.prior     = 0;
343         pst.intfVer   = 0;
344
345         if(MacDuAppUlCcchInd(&pst, ulCcchIndInfo) != ROK)
346         {
347                 DU_LOG("\nMAC: Failed to send UL CCCH Ind to DU APP");
348                 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg,
349                                 strlen((const char*)ulCcchIndInfo->ulCcchMsg));
350                 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
351                 ret = RFAILED;
352         }
353         return ret;
354 }
355
356
357
358
359 /**********************************************************************
360          End of file
361 **********************************************************************/
362