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 *******************************************************************************/
18 /* header include files (.h) */
19 #include "common_def.h"
22 #include "du_app_mac_inf.h"
23 #include "mac_sch_interface.h"
24 #include "lwr_mac_upr_inf.h"
26 #include "mac_utils.h"
28 /* Function pointer for sending rach ind from MAC to SCH */
29 MacSchRachIndFunc macSchRachIndOpts[]=
31 packMacSchRachInd, /* packing for loosely coupled */
32 MacSchRachInd, /* packing for tightly coupled */
33 packMacSchRachInd /* packing for light weight loosely coupled */
36 /* Function pointer for sending RACH resource request from MAC to SCH */
37 MacSchRachRsrcReqFunc macSchRachRsrcReqOpts[] =
39 packMacSchRachRsrcReq, /* packing for loosely coupled */
40 MacSchRachRsrcReq, /* packing for tightly coupled */
41 packMacSchRachRsrcReq /* packing for light weight loosely coupled */
44 /* Function pointer for sending RACH resource response from MAC to DU APP */
45 MacDuRachRsrcRspFunc macDuRachRsrcRspOpts[] =
47 packDuMacRachRsrcRsp, /* packing for loosely coupled */
48 DuProcMacRachRsrcRsp, /* packing for tightly coupled */
49 packDuMacRachRsrcRsp /* packing for light weight loosly coupled */
52 /*******************************************************************
54 * @brief Sends RACH indication to SCH
58 * Function : sendRachIndMacToSch
61 * Sends RACH indication to SCH
63 * @params[in] RACH indication info
64 * @return ROK - success
67 * ****************************************************************/
68 uint8_t sendRachIndMacToSch(RachIndInfo *rachInd)
72 FILL_PST_MAC_TO_SCH(pst, EVENT_RACH_IND_TO_SCH);
73 return(*macSchRachIndOpts[pst.selector])(&pst, rachInd);
76 /*******************************************************************
78 * @brief Processes RACH indication from PHY
82 * Function : fapiMacRachInd
85 * Processes RACH indication from PHY
87 * @params[in] Post structure
88 * Rach indication message
89 * @return ROK - success
92 * ****************************************************************/
93 uint8_t fapiMacRachInd(Pst *pst, RachInd *rachInd)
97 RachIndInfo *rachIndInfo;
99 DU_LOG("\nINFO --> MAC : Received RACH indication");
100 /* Considering one pdu and one preamble */
104 MAC_ALLOC(rachIndInfo, sizeof(RachIndInfo));
107 DU_LOG("\nERROR --> MAC : Memory allocation failure in fapiMacRachInd");
108 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rachInd, sizeof(RachInd));
112 rachIndInfo->cellId = rachInd->cellId;
113 rachIndInfo->timingInfo.sfn = rachInd->timingInfo.sfn;
114 rachIndInfo->timingInfo.slot = rachInd->timingInfo.slot;
115 rachIndInfo->slotIdx = rachInd->rachPdu[pduIdx].slotIdx;
116 rachIndInfo->symbolIdx = rachInd->rachPdu[pduIdx].symbolIdx;
117 rachIndInfo->freqIdx = rachInd->rachPdu[pduIdx].freqIdx;
118 rachIndInfo->preambleIdx = rachInd->rachPdu[pduIdx].preamInfo[preambleIdx].preamIdx;
119 rachIndInfo->timingAdv = rachInd->rachPdu[pduIdx].preamInfo[preambleIdx].timingAdv;
121 /* Store the value in macRaCb */
122 createMacRaCb(rachIndInfo);
124 /* Free sharable buffer used to send RACH Indication from lower MAC to MAC */
125 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rachInd, sizeof(RachInd));
127 /* Send RACH Indication to SCH */
128 return(sendRachIndMacToSch(rachIndInfo));
131 /*******************************************************************
133 * @brief Processes RACH Resource request from DU APP
137 * Function : MacProcRachRsrcReq
139 * Functionality: Processes RACH resource request from DU APP.
140 * Fills and sends RACH resource request towards SCH.
142 * @params[in] Post structure
143 * RACH resource request
144 * @return ROK - success
147 * ****************************************************************/
148 uint8_t MacProcRachRsrcReq(Pst *pst, MacRachRsrcReq *rachRsrcReq)
150 uint8_t ret = RFAILED;
151 uint16_t cellIdx = 0;
153 MacCellCb *cellCb = NULLP;
154 MacUeCb *ueCb = NULLP;
155 SchRachRsrcReq *schRachRsrcReq = NULLP;
157 DU_LOG("\nINFO --> MAC : Recieved RACH Resource Request for Cell ID [%d] UE ID [%d]",\
158 rachRsrcReq->cellId, rachRsrcReq->ueId);
161 GET_CELL_IDX(rachRsrcReq->cellId, cellIdx);
162 if(macCb.macCell[cellIdx] && (macCb.macCell[cellIdx]->cellId == rachRsrcReq->cellId))
164 cellCb = macCb.macCell[cellIdx];
167 if(cellCb->ueCb[rachRsrcReq->ueId-1].ueId == rachRsrcReq->ueId)
169 ueCb = &cellCb->ueCb[rachRsrcReq->ueId-1];
170 /* Allocate memory to RACH resource request to be sent to SCH */
171 MAC_ALLOC(schRachRsrcReq, sizeof(SchRachRsrcReq));
174 /* Fill SCH RACH resource request from information received from DU APP to MAC */
175 schRachRsrcReq->cellId = rachRsrcReq->cellId;
176 schRachRsrcReq->crnti = ueCb->crnti;
177 schRachRsrcReq->numSsb = rachRsrcReq->numSsb;
178 memcpy(schRachRsrcReq->ssbIdx, rachRsrcReq->ssbIdx, sizeof(schRachRsrcReq->ssbIdx));
180 /* Send RACH resource request from MAC to SCH */
181 FILL_PST_MAC_TO_SCH(schPst, EVENT_RACH_RESOURCE_REQUEST_TO_SCH);
182 ret = (*macSchRachRsrcReqOpts[schPst.selector])(&schPst, schRachRsrcReq);
185 DU_LOG("\nERROR --> MAC : Memory allocation failed for RACH resource request to SCH");
188 DU_LOG("\nERROR --> MAC : UE ID [%d] not found", rachRsrcReq->ueId);
191 DU_LOG("\nERROR --> MAC : Cell ID [%d] not found", rachRsrcReq->cellId);
193 /* Free sharable buffer used to send RACH reource request from DU APP to MAC */
194 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rachRsrcReq, sizeof(MacRachRsrcReq));
198 /*******************************************************************
200 * @brief Processes RACH Resource response from SCH
204 * Function : MacProcSchRachRsrcRsp
206 * Functionality: Processes RACH resource response from SCH
207 * Fills and sends RACH resource response towards DU APP
209 * @params[in] Post structure
210 * RACH resource response
211 * @return ROK - success
214 * ****************************************************************/
215 uint8_t MacProcSchRachRsrcRsp(Pst *pst, SchRachRsrcRsp *schRachRsrcRsp)
217 uint16_t cellIdx = 0;
219 MacRachRsrcRsp *rachRsrcRsp = NULLP;
220 MacCellCb *cellCb = NULLP;
221 MacUeCb *ueCb = NULLP;
223 DU_LOG("\nINFO --> MAC : Received RACH resource response from SCH : Cell ID [%d] CRNTI [%d]", \
224 schRachRsrcRsp->cellId, schRachRsrcRsp->crnti);
226 /* Fill RACH resource response to send to DU APP */
227 MAC_ALLOC_SHRABL_BUF(rachRsrcRsp, sizeof(MacRachRsrcRsp));
230 DU_LOG("\nERROR --> MAC : Memory allocation failed for RACH resource response");
231 MAC_FREE(schRachRsrcRsp, sizeof(SchRachRsrcRsp));
234 rachRsrcRsp->cellId = schRachRsrcRsp->cellId;
235 GET_UE_ID(schRachRsrcRsp->crnti, rachRsrcRsp->ueId);
236 rachRsrcRsp->result = MAC_DU_APP_RSP_OK;
238 /* Fill Pst structure to send RACH resource response from MAC to DU APP */
239 FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_RACH_RESOURCE_RSP);
241 /* If negative response is received from SCH, send it further to DU APP */
242 if(schRachRsrcRsp->result == RSP_NOK)
244 DU_LOG("\nINFO --> MAC : RACH Resource response from SCH : Result [FAILURE]");
245 rachRsrcRsp->result = MAC_DU_APP_RSP_NOK;
249 DU_LOG("\nINFO --> MAC : RACH Resource response from SCH : Result [SUCCESS]");
252 GET_CELL_IDX(schRachRsrcRsp->cellId, cellIdx);
253 if(macCb.macCell[cellIdx] && (macCb.macCell[cellIdx]->cellId == schRachRsrcRsp->cellId))
255 cellCb = macCb.macCell[cellIdx];
258 if(cellCb->ueCb[rachRsrcRsp->ueId-1].crnti == schRachRsrcRsp->crnti)
259 ueCb = &cellCb->ueCb[rachRsrcRsp->ueId-1];
262 DU_LOG("\nERROR --> MAC : CRNTI [%d] not found", schRachRsrcRsp->crnti);
263 rachRsrcRsp->result = MAC_DU_APP_RSP_NOK;
268 DU_LOG("\nERROR --> MAC : Cell ID [%d] not found", schRachRsrcRsp->cellId);
269 rachRsrcRsp->result = MAC_DU_APP_RSP_NOK;
273 /* TODO : Check if ra-preamble index is to be stored in UE CB */
275 /* Fill SSB RACH resource info if SCH has sent a positive response and
276 * processing of SCH RACH resource response at MAC has been successful so far */
277 if(rachRsrcRsp->result == MAC_DU_APP_RSP_OK)
279 rachRsrcRsp->newCrnti = ueCb->crnti;
280 rachRsrcRsp->cfraResource.numSsb = schRachRsrcRsp->cfraResource.numSsb;
281 memcpy(rachRsrcRsp->cfraResource.ssbResource, schRachRsrcRsp->cfraResource.ssbResource, \
282 rachRsrcRsp->cfraResource.numSsb * sizeof(MacCfraSsbResource));
285 /* Free SCH RACH resource response */
286 MAC_FREE(schRachRsrcRsp, sizeof(SchRachRsrcRsp));
288 /* Send RACH resource response to DU APP */
289 FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_RACH_RESOURCE_RSP);
290 return (*macDuRachRsrcRspOpts[rspPst.selector])(&rspPst, rachRsrcRsp);
293 /* spec-38.211 Table 6.3.3.1-7 */
294 uint8_t UnrestrictedSetNcsTable[MAX_ZERO_CORR_CFG_IDX] =
295 {0, 2, 4, 6, 8, 10, 12, 13, 15, 17, 19, 23, 27, 34, 46, 69};
297 /*******************************************************************
299 * @brief Processes UL scheduling info from SCH
303 * Function : MacProcUlSchInfo
305 * Functionality: Processes UL scheduling info from SCH
307 * @params[in] Post structure
309 * @return ROK - success
312 * ****************************************************************/
313 uint8_t MacProcUlSchInfo(Pst *pst, UlSchedInfo *ulSchedInfo)
317 #ifdef CALL_FLOW_DEBUG_LOG
318 DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_UL_SCH_INFO\n");
321 GET_CELL_IDX(ulSchedInfo->cellId, cellIdx);
322 if(ulSchedInfo != NULLP)
324 MacUlSlot *currUlSlot =
325 &macCb.macCell[cellIdx]->ulSlot[ulSchedInfo->slotIndInfo.slot % MAX_SLOTS];
326 memcpy(&currUlSlot->ulInfo, ulSchedInfo, sizeof(UlSchedInfo));
331 /**********************************************************************
333 **********************************************************************/