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 "rg.x" /* MAC includes */
87 /* forward references */
89 /***********************************************************
91 * Func : rgRAMFreeUeCb
96 * - Frees UE control block.
104 **********************************************************/
106 PUBLIC Void rgRAMFreeUeCb
112 PUBLIC Void rgRAMFreeUeCb(inst,ue)
119 rgDHMFreeUe(inst,&ue->dl.hqEnt);
121 /*ccpu00117052 - MOD - Passing double pointer for proper NULLP
123 /* De-allocate the Ue */
124 rgFreeSBuf(inst,(Data **)&ue, sizeof(*ue));
126 /* Stack Crash problem for TRACE5 changes. Added the return below */
129 } /* rgRAMFreeUeCb */
132 * @brief Handler for Random Access control block creation.
136 * Function : rgRAMCreateUeCb
137 * Creates a raCb and gives the same to scheduler for its updation.
140 * @param[in] RgCellCb *cell
141 * @param[in] CmLteRnti tmpCrnti
142 * @param[out] RgErrInfo *err
146 PUBLIC RgUeCb* rgRAMCreateUeCb
154 PUBLIC RgUeCb* rgRAMCreateUeCb(cell, tmpCrnti, insert, err)
161 Inst inst = cell->macInst - RG_INST_START;
162 RgUeCb *ueCb = NULLP;
164 TRC2(rgRAMCreateUeCb)
166 RLOG_ARG1(L_INFO,DBG_CELLID,cell->cellId,"CREATE UECB FOR CRNTI:%d",
168 /* Allocate the Ue control block */
169 if (rgAllocSBuf(inst,(Data **)&ueCb, sizeof(*ueCb)) != ROK)
171 RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
172 "Memory allocation FAILED for CRNTI:%d",tmpCrnti);
173 err->errCause = RGERR_RAM_MEM_EXHAUST;
177 /* Inititialize Ue control block */
178 ueCb->ueId = tmpCrnti;
180 /* Initialize the lists of the UE */
185 /* MS_FIX : Remove stale UEs if present */
186 RgUeCb *staleUe = NULLP;
187 /* Insert the created raCb into raCb list of cell */
188 ueCb->rachLstEnt.next = NULLP;
189 ueCb->rachLstEnt.prev = NULLP;
190 ueCb->rachLstEnt.node = (PTR)(ueCb);
191 /* MS_FIX : Remove stale UEs if present */
192 staleUe = rgDBMGetUeCbFromRachLst (cell, tmpCrnti);
195 rgDBMDelUeCbFromRachLst(cell, staleUe);
196 rgRAMFreeUeCb(inst,staleUe);
198 rgDBMInsUeCbInRachLst(cell, ueCb);
202 } /* rgRAMCreateUeCb */
205 * @brief Function for handling cell delete.
209 * Function : rgRAMFreeCell
211 * This function shall be invoked whenever a cell needs to be deleted.
212 * This shall remove raCbs and raReqs stored in cell.
215 * @param[in,out] RgCellCb *cell
220 PUBLIC S16 rgRAMFreeCell
225 PUBLIC S16 rgRAMFreeCell(cell)
229 Inst inst = cell->macInst - RG_INST_START;
234 /* Free CURRENT CRG cfg list */
235 while ((ueCb = rgDBMGetNextUeCbFromRachLst(cell, NULLP)) != NULLP)
237 rgDBMDelUeCbFromRachLst(cell, ueCb);
238 rgRAMFreeUeCb(inst,ueCb);
242 } /* rgRAMFreeCell */
244 * @brief Function for handling RA response scheduled for a subframe.
248 * Function : rgHndlRaResp
250 * This function shall be invoked whenever scheduler is done with the
251 * allocations of random access responses for a subframe RgSchMacSfAllocReq.
255 * This shall invoke RAM to create ueCbs for all the rapIds allocated and
256 * shall invoke MUX to create RAR PDUs for raRntis allocated.
259 * @param[in] RgCellCb *cell,
260 * @param[in] CmLteTimingInfo timingInfo,
261 * @param[in] RgInfRarInfo *rarInfo
262 * @param[in/out] RgErrInfo *err
267 PUBLIC S16 rgHndlRaResp
270 CmLteTimingInfo timingInfo,
271 RgInfRarInfo *rarInfo,
275 PUBLIC S16 rgHndlRaResp(cell, timingInfo, rarInfo, err)
277 CmLteTimingInfo timingInfo;
278 RgInfRarInfo *rarInfo;
289 if(NULLP == rarInfo->raRntiInfo)
294 idx = (timingInfo.subframe % RG_NUM_SUB_FRAMES);
295 dlSf = &cell->subFrms[idx];
297 /* Create RAR PDUs for all the allocated RA-RNTIs */
298 for(idx1 = 0; idx1 < rarInfo->numRaRntis; idx1++)
300 if(ROK == (rgMUXBldRarPdu(cell,
301 &rarInfo->raRntiInfo[idx1], &rarPdu, err)))
303 /* Create RaCbs for all the rapIds allocated */
304 for(idx2 = 0; idx2 < rarInfo->raRntiInfo[idx1].numCrnti; idx2++)
306 if(FALSE == rarInfo->raRntiInfo[idx1].crntiInfo[idx2].isContFree)
308 if(rgRAMCreateUeCb(cell,
309 rarInfo->raRntiInfo[idx1].crntiInfo[idx2].tmpCrnti,
316 /* Store the created RAR PDU */
317 dlSf->raRsp[dlSf->numRaRsp].pdcch.rnti =
318 rarInfo->raRntiInfo[idx1].raRnti;
320 dlSf->raRsp[dlSf->numRaRsp].pdcch.dci =
321 rarInfo->raRntiInfo[idx1].dciInfo;
323 dlSf->raRsp[dlSf->numRaRsp].rar = rarPdu;
324 /* ccpu00132314-ADD-Adding txPower offset for the PDSCH transmission */
325 dlSf->raRsp[dlSf->numRaRsp].txPwrOffset =
326 rarInfo->txPwrOffset;
332 RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"RARNTI:%d Creation of RAR"
333 "PDU for failed", rarInfo->raRntiInfo[idx1].raRnti);
336 } /* end of raRntis loop */
338 } /* end of rgHndlRaResp */
340 /**********************************************************************
343 **********************************************************************/