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 /************************************************************************
25 Desc: C source code for Entry point fucntions
29 **********************************************************************/
32 @brief This file has APIs to handle the random access procedure functionality.
35 static const char* RLOG_MODULE_NAME="MAC";
36 static int RLOG_FILE_ID=132;
37 static int RLOG_MODULE_ID=4096;
39 /* header include files (.h) */
40 #include "envopt.h" /* environment options */
41 #include "envdep.h" /* environment dependent */
42 #include "envind.h" /* environment independent */
44 #include "gen.h" /* general */
45 #include "ssi.h" /* system services */
47 #include "cm_tkns.h" /* Common Token Defines */
48 #include "cm_llist.h" /* Common Link List Defines */
49 #include "cm_hash.h" /* Common Hash List Defines */
50 #include "cm_mblk.h" /* common memory link list library */
51 #include "cm_lte.h" /* Common LTE */
53 #include "rg_env.h" /* MAC Environment Defines */
54 #include "crg.h" /* CRG Interface defines */
55 #include "rgu.h" /* RGU Interface defines */
56 #include "tfu.h" /* TFU Interface defines */
57 #include "rg_sch_inf.h" /* RGR Interface defines */
58 #include "lrg.h" /* LRG Interface defines */
60 #include "rg.h" /* MAC defines */
61 #include "rg_err.h" /* MAC error defines */
63 /* header/extern include files (.x) */
64 #include "gen.x" /* general */
65 #include "ssi.x" /* system services */
66 #include "cm5.x" /* Timer */
67 #include "cm_tkns.x" /* Common Token Definitions */
68 #include "cm_llist.x" /* Common Link List Definitions */
69 #include "cm_lib.x" /* Common Library Definitions */
70 #include "cm_hash.x" /* Common Hash List Definitions */
71 #include "cm_mblk.x" /* common memory link list library */
72 #include "cm_lte.x" /* Common LTE */
74 #include "crg.x" /* CRG Interface includes */
75 #include "rgu.x" /* RGU Interface includes */
76 #include "tfu.x" /* TFU Interface includes */
77 #include "rg_sch_inf.x" /* SCH Interface includes */
78 #include "rg_prg.x" /* PRG Interface includes */
79 #include "lrg.x" /* LRG Interface includes */
81 #include "du_app_mac_inf.h"
82 #include "rg.x" /* MAC includes */
88 /* forward references */
90 /***********************************************************
92 * Func : rgRAMFreeUeCb
97 * - Frees UE control block.
105 **********************************************************/
107 PUBLIC Void rgRAMFreeUeCb
113 PUBLIC Void rgRAMFreeUeCb(inst,ue)
120 rgDHMFreeUe(inst,&ue->dl.hqEnt);
122 /*ccpu00117052 - MOD - Passing double pointer for proper NULLP
124 /* De-allocate the Ue */
125 rgFreeSBuf(inst,(Data **)&ue, sizeof(*ue));
127 /* Stack Crash problem for TRACE5 changes. Added the return below */
130 } /* rgRAMFreeUeCb */
133 * @brief Handler for Random Access control block creation.
137 * Function : rgRAMCreateUeCb
138 * Creates a raCb and gives the same to scheduler for its updation.
141 * @param[in] RgCellCb *cell
142 * @param[in] CmLteRnti tmpCrnti
143 * @param[out] RgErrInfo *err
147 PUBLIC RgUeCb* rgRAMCreateUeCb
155 PUBLIC RgUeCb* rgRAMCreateUeCb(cell, tmpCrnti, insert, err)
162 Inst inst = cell->macInst - RG_INST_START;
163 RgUeCb *ueCb = NULLP;
165 TRC2(rgRAMCreateUeCb)
167 RLOG_ARG1(L_INFO,DBG_CELLID,cell->cellId,"CREATE UECB FOR CRNTI:%d",
169 /* Allocate the Ue control block */
170 if (rgAllocSBuf(inst,(Data **)&ueCb, sizeof(*ueCb)) != ROK)
172 RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
173 "Memory allocation FAILED for CRNTI:%d",tmpCrnti);
174 err->errCause = RGERR_RAM_MEM_EXHAUST;
178 /* Inititialize Ue control block */
179 ueCb->ueId = tmpCrnti;
181 /* Initialize the lists of the UE */
186 /* MS_FIX : Remove stale UEs if present */
187 RgUeCb *staleUe = NULLP;
188 /* Insert the created raCb into raCb list of cell */
189 ueCb->rachLstEnt.next = NULLP;
190 ueCb->rachLstEnt.prev = NULLP;
191 ueCb->rachLstEnt.node = (PTR)(ueCb);
192 /* MS_FIX : Remove stale UEs if present */
193 staleUe = rgDBMGetUeCbFromRachLst (cell, tmpCrnti);
196 rgDBMDelUeCbFromRachLst(cell, staleUe);
197 rgRAMFreeUeCb(inst,staleUe);
199 rgDBMInsUeCbInRachLst(cell, ueCb);
203 } /* rgRAMCreateUeCb */
206 * @brief Function for handling cell delete.
210 * Function : rgRAMFreeCell
212 * This function shall be invoked whenever a cell needs to be deleted.
213 * This shall remove raCbs and raReqs stored in cell.
216 * @param[in,out] RgCellCb *cell
221 PUBLIC S16 rgRAMFreeCell
226 PUBLIC S16 rgRAMFreeCell(cell)
230 Inst inst = cell->macInst - RG_INST_START;
235 /* Free CURRENT CRG cfg list */
236 while ((ueCb = rgDBMGetNextUeCbFromRachLst(cell, NULLP)) != NULLP)
238 rgDBMDelUeCbFromRachLst(cell, ueCb);
239 rgRAMFreeUeCb(inst,ueCb);
243 } /* rgRAMFreeCell */
245 * @brief Function for handling RA response scheduled for a subframe.
249 * Function : rgHndlRaResp
251 * This function shall be invoked whenever scheduler is done with the
252 * allocations of random access responses for a subframe RgSchMacSfAllocReq.
256 * This shall invoke RAM to create ueCbs for all the rapIds allocated and
257 * shall invoke MUX to create RAR PDUs for raRntis allocated.
260 * @param[in] RgCellCb *cell,
261 * @param[in] CmLteTimingInfo timingInfo,
262 * @param[in] RgInfRarInfo *rarInfo
263 * @param[in/out] RgErrInfo *err
268 PUBLIC S16 rgHndlRaResp
271 CmLteTimingInfo timingInfo,
272 RgInfRarInfo *rarInfo,
276 PUBLIC S16 rgHndlRaResp(cell, timingInfo, rarInfo, err)
278 CmLteTimingInfo timingInfo;
279 RgInfRarInfo *rarInfo;
290 if(NULLP == rarInfo->raRntiInfo)
295 idx = (timingInfo.slot % RG_NUM_SUB_FRAMES);
296 dlSf = &cell->subFrms[idx];
298 /* Create RAR PDUs for all the allocated RA-RNTIs */
299 for(idx1 = 0; idx1 < rarInfo->numRaRntis; idx1++)
301 if(ROK == (rgMUXBldRarPdu(cell,
302 &rarInfo->raRntiInfo[idx1], &rarPdu, err)))
304 /* Create RaCbs for all the rapIds allocated */
305 for(idx2 = 0; idx2 < rarInfo->raRntiInfo[idx1].numCrnti; idx2++)
307 if(FALSE == rarInfo->raRntiInfo[idx1].crntiInfo[idx2].isContFree)
309 if(rgRAMCreateUeCb(cell,
310 rarInfo->raRntiInfo[idx1].crntiInfo[idx2].tmpCrnti,
317 /* Store the created RAR PDU */
318 dlSf->raRsp[dlSf->numRaRsp].pdcch.rnti =
319 rarInfo->raRntiInfo[idx1].raRnti;
321 dlSf->raRsp[dlSf->numRaRsp].pdcch.dci =
322 rarInfo->raRntiInfo[idx1].dciInfo;
324 dlSf->raRsp[dlSf->numRaRsp].rar = rarPdu;
325 /* ccpu00132314-ADD-Adding txPower offset for the PDSCH transmission */
326 dlSf->raRsp[dlSf->numRaRsp].txPwrOffset =
327 rarInfo->txPwrOffset;
333 RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"RARNTI:%d Creation of RAR"
334 "PDU for failed", rarInfo->raRntiInfo[idx1].raRnti);
337 } /* end of raRntis loop */
339 } /* end of rgHndlRaResp */
341 /**********************************************************************
344 **********************************************************************/