1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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 *******************************************************************************/
19 /* header include files -- defines (.h) */
21 #include "envopt.h" /* environment options */
22 #include "envdep.h" /* environment dependent */
23 #include "envind.h" /* environment independent */
24 #include "gen.h" /* general layer */
25 #include "ssi.h" /* system services */
26 #include "cm5.h" /* common timers defines */
27 #include "cm_hash.h" /* common hash list defines */
28 #include "cm_llist.h" /* common linked list defines */
29 #include "cm_mblk.h" /* memory management */
30 #include "cm_tkns.h" /* common tokens */
31 #include "cm_lte.h" /* common tokens */
34 #include "rg_sch_inf.h"
42 /* header/extern include files (.x) */
43 #include "gen.x" /* general layer typedefs */
44 #include "ssi.x" /* system services typedefs */
45 #include "cm5.x" /* common timers */
46 #include "cm_hash.x" /* common hash list */
47 #include "cm_lib.x" /* common library */
48 #include "cm_llist.x" /* common linked list */
49 #include "cm_mblk.x" /* memory management */
50 #include "cm_tkns.x" /* common tokens */
51 #include "cm_lte.x" /* common tokens */
54 #include "rg_sch_inf.x"
58 #include "du_app_mac_inf.h"
59 #include "mac_upr_inf_api.h"
61 #include "lwr_mac_fsm.h"
64 /* This file contains message handling functionality for MAC */
68 extern void sendToLowerMac(uint16_t msgType, uint32_t msgLen, void *msg);
69 uint16_t buildMacPdu(RlcMacData *dlData);
71 /* Function pointer for sending crc ind from MAC to SCH */
72 MacSchCrcIndFunc macSchCrcIndOpts[]=
79 /* Function pointer for sending DL RLC BO Info from MAC to SCH */
80 MacSchDlRlcBoInfoFunc macSchDlRlcBoInfoOpts[]=
82 packMacSchDlRlcBoInfo,
87 /*******************************************************************
89 * @brief Sends DL BO Info to SCH
93 * Function : sendDlRlcBoInfoMacToSch
96 * Sends DL BO Info to SCH
99 * @return ROK - success
102 ****************************************************************/
103 int sendDlRlcBoInfoMacToSch(DlRlcBOInfo *dlBoInfo)
107 fillMacToSchPst(&pst);
108 pst.event = EVENT_DL_RLC_BO_INFO_TO_SCH;
110 return(*macSchDlRlcBoInfoOpts[pst.selector])(&pst, dlBoInfo);
113 /*******************************************************************
115 * @brief Sends CRC Indication to SCH
119 * Function : sendCrcIndMacToSch
122 * Sends CRC Indication to SCH
125 * @return ROK - success
128 ****************************************************************/
129 int sendCrcIndMacToSch(CrcIndInfo *crcInd)
133 fillMacToSchPst(&pst);
134 pst.event = EVENT_CRC_IND_TO_SCH;
136 return(*macSchCrcIndOpts[pst.selector])(&pst, crcInd);
139 /*******************************************************************
141 * @brief Processes CRC Indication from PHY
145 * Function : fapiMacCrcInd
148 * Processes CRC Indication from PHY
150 * @params[in] Post Structure Pointer
151 * Crc Indication Pointer
152 * @return ROK - success
155 * ****************************************************************/
156 uint16_t fapiMacCrcInd(Pst *pst, CrcInd *crcInd)
158 CrcIndInfo crcIndInfo;
160 DU_LOG("\nMAC : Received CRC indication");
162 /* Considering one pdu and one preamble */
163 crcIndInfo.cellId = macCb.macCell->cellId;;
164 crcIndInfo.crnti = crcInd->crcInfo[0].rnti;
165 crcIndInfo.timingInfo.sfn = crcInd->timingInfo.sfn;
166 crcIndInfo.timingInfo.slot = crcInd->timingInfo.slot;
167 crcIndInfo.numCrcInd = crcInd->crcInfo[0].numCb;
168 crcIndInfo.crcInd[0] = crcInd->crcInfo[0].cbCrcStatus[0];
170 return(sendCrcIndMacToSch(&crcIndInfo));
173 /*******************************************************************
175 * @brief Process Rx Data Ind at MAC
179 * Function : fapiMacRxDataInd
182 * Process Rx Data Ind at MAC
184 * @params[in] Post structure
186 * @return ROK - success
189 * ****************************************************************/
190 uint16_t fapiMacRxDataInd(Pst *pst, RxDataInd *rxDataInd)
194 DU_LOG("\nMAC : Received Rx Data indication");
196 /* TODO : compare the handle received in RxDataInd with handle send in PUSCH
197 * PDU, which is stored in raCb */
199 for(pduIdx = 0; pduIdx < rxDataInd->numPdus; pduIdx++)
201 unpackRxData(&rxDataInd->pdus[pduIdx]);
206 /*******************************************************************
208 * @brief Processes DL data from RLC
212 * Function : MacRlcProcDlData
215 * Processes DL data from RLC
217 * @params[in] Post structure
219 * @return ROK - success
222 * ****************************************************************/
223 uint16_t MacRlcProcDlData(Pst* pst, SpId spId, RlcMacData *dlData)
228 /*******************************************************************
230 * @brief Processes BO status from RLC
234 * Function : MacRlcProcBOStatus
237 * Processes BO status from RLC
239 * @params[in] Post structure
241 * @return ROK - success
244 * ****************************************************************/
245 uint16_t MacRlcProcBOStatus(Pst* pst, SpId spId, RlcMacBOStatus* boStatus)
251 /*******************************************************************
253 * @brief Handles cell start reuqest from DU APP
257 * Function : MacHdlCellStartReq
260 * Handles cell start reuqest from DU APP
262 * @params[in] Post structure pointer
263 * Cell Start Request info pointer
264 * @return ROK - success
267 * ****************************************************************/
268 uint16_t MacHdlCellStartReq(Pst *pst, MacCellStartInfo *cellStartInfo)
270 DU_LOG("\nMAC : Handling cell start request");
271 sendToLowerMac(START_REQUEST, 0, cellStartInfo);
273 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStartInfo, \
274 sizeof(MacCellStartInfo));
279 /*******************************************************************
281 * @brief Handles cell stop request from DU APP
285 * Function : MacHdlCellStartReq
288 * Handles cell stop request from DU APP
290 * @params[in] Post structure pointer
291 * Mac Cell stop information
292 * @return ROK - success
295 * ****************************************************************/
296 uint16_t MacHdlCellStopReq(Pst *pst, MacCellStopInfo *cellStopInfo)
299 DU_LOG("\nMAC : Sending cell stop request to Lower Mac");
300 sendToLowerMac(FAPI_STOP_REQUEST, 0, cellStopInfo);
303 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStopInfo, \
304 sizeof(MacCellStopInfo));
309 /*******************************************************************
311 * @brief Handles DL CCCH Ind from DU APP
315 * Function : MacHdlDlCcchInd
318 * Handles DL CCCH Ind from DU APP
320 * @params[in] Post structure pointer
321 * DL CCCH Ind pointer
322 * @return ROK - success
325 * ****************************************************************/
326 uint16_t MacHdlDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
329 DlRlcBOInfo dlBoInfo;
330 memset(&dlBoInfo, 0, sizeof(DlRlcBOInfo));
332 DU_LOG("\nMAC : Handling DL CCCH IND");
334 /* TODO : Fill DL RLC Buffer status info */
335 dlBoInfo.cellId = dlCcchIndInfo->cellId;
336 dlBoInfo.crnti = dlCcchIndInfo->crnti;
339 if(dlCcchIndInfo->msgType == RRC_SETUP)
341 dlBoInfo.boInfo[dlBoInfo.numLc].lcId = SRB_ID_0; // SRB ID 0 for msg4
342 dlBoInfo.boInfo[SRB_ID_0].dataVolume = \
343 dlCcchIndInfo->dlCcchMsgLen;
346 /* storing Msg4 Pdu in raCb */
347 if(macCb.macCell->macRaCb[0].crnti == dlCcchIndInfo->crnti)
349 macCb.macCell->macRaCb[0].msg4PduLen = dlCcchIndInfo->dlCcchMsgLen;
350 MAC_ALLOC(macCb.macCell->macRaCb[0].msg4Pdu, macCb.macCell->macRaCb[0]\
352 if(macCb.macCell->macRaCb[0].msg4Pdu)
354 for(idx = 0; idx < dlCcchIndInfo->dlCcchMsgLen; idx++)
356 macCb.macCell->macRaCb[0].msg4Pdu[idx] =\
357 dlCcchIndInfo->dlCcchMsg[idx];
362 sendDlRlcBoInfoMacToSch(&dlBoInfo);
364 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, \
365 dlCcchIndInfo->dlCcchMsgLen);
366 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo, sizeof(DlCcchIndInfo));
371 /*******************************************************************
373 * @brief Sends UL CCCH Ind to DU APP
377 * Function : macSendUlCcchInd
380 * MAC sends UL CCCH Ind to DU APP
382 * @params[in] Post structure pointer
384 * @return ROK - success
387 * ****************************************************************/
388 uint16_t macSendUlCcchInd(uint8_t *rrcContainer, uint16_t cellId, uint16_t crnti)
392 UlCcchIndInfo *ulCcchIndInfo = NULLP;
394 MAC_ALLOC_SHRABL_BUF(ulCcchIndInfo, sizeof(UlCcchIndInfo));
397 DU_LOG("\nMAC: Memory failed in macSendUlCcchInd");
401 ulCcchIndInfo->cellId = cellId;
402 ulCcchIndInfo->crnti = crnti;
403 ulCcchIndInfo->ulCcchMsg = rrcContainer;
406 pst.selector = DU_MAC_LWLC;
408 pst.dstEnt = ENTDUAPP;
410 pst.srcInst = macCb.macInst;
411 pst.dstProcId = rgCb[pst.srcInst].rgInit.procId;
412 pst.srcProcId = rgCb[pst.srcInst].rgInit.procId;
413 pst.region = MAC_MEM_REGION;
415 pst.event = EVENT_MAC_UL_CCCH_IND;
420 if(MacDuAppUlCcchInd(&pst, ulCcchIndInfo) != ROK)
422 DU_LOG("\nMAC: Failed to send UL CCCH Ind to DU APP");
423 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg,
424 strlen((const char*)ulCcchIndInfo->ulCcchMsg));
425 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
431 /*******************************************************************
433 * @brief Handles Ue Create Request from DU APP
437 * Function : MacHdlUeCreateReq
440 * Handles Ue create Request from DU APP
442 * @params[in] Post structure pointer
444 * @return ROK - success
447 * ****************************************************************/
448 uint8_t MacHdlUeCreateReq(Pst *pst, MacUeCfg *ueCfg)
450 /* TODO : Create MAC UE Context.
451 Copy Tx Pdu from raCb
453 Send MacUeContext to SCH */
454 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueCfg, sizeof(MacUeCfg));
458 /**********************************************************************
460 **********************************************************************/