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