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 /* This file contains message handling functionality for DU cell management */
20 #include "common_def.h"
27 #include "du_app_mac_inf.h"
28 #include "du_app_rlc_inf.h"
32 #include "du_cell_mgr.h"
33 #include "PCCH-Config.h"
37 #include "AlarmInterface.h"
38 #include "CmInterface.h"
42 DuMacCellDeleteReq packMacCellDeleteReqOpts[] =
44 packDuMacCellDeleteReq, /* Loose coupling */
45 MacProcCellDeleteReq, /* TIght coupling */
46 packDuMacCellDeleteReq /* Light weight-loose coupling */
49 /*******************************************************************
51 * @brief Processes cells to be activated
55 * Function : duProcCellsToBeActivated
58 * - Processes cells to be activated list received in F1SetupRsp
61 * @return ROK - success
64 * ****************************************************************/
65 uint8_t duProcCellsToBeActivated(uint8_t *plmnStr, uint16_t nci, uint16_t nRPci)
68 DuCellCb *cellCb = NULLP;
69 uint8_t cfgIdx, tmpPlmn[4];
71 for(cfgIdx=0; cfgIdx<duCb.numCfgCells; cfgIdx++)
73 memset(tmpPlmn, 0, 4);
74 buildPlmnId(duCb.cfgCellLst[cfgIdx]->cellInfo.nrEcgi.plmn, tmpPlmn);
75 if(duCb.cfgCellLst[cfgIdx]->cellInfo.nrEcgi.cellId == nci &&
76 (strcmp((const char*)tmpPlmn, (const char*)plmnStr) == 0))
78 cellCb = duCb.cfgCellLst[cfgIdx];
83 DU_LOG("\nERROR --> DU APP : No Cell found for NCI %d", nci);
88 cellCb->cellStatus = ACTIVATION_IN_PROGRESS;
89 cellCb->cellInfo.nrPci = nRPci;
91 duCb.actvCellLst[cellCb->cellId -1] = cellCb;
94 if(duBuildAndSendMacCellCfg(cellCb->cellId) != ROK)
96 DU_LOG("\nERROR --> DU APP : macCellCfg build and send failed");
97 /* Delete cell from actvCellList */
98 duCb.actvCellLst[cellCb->cellId -1] = NULLP;
99 --(duCb.numActvCells);
105 /*******************************************************************
107 * @brief Handles DU F1Setup Rsp received in F1AP
111 * Function : duProcF1SetupRsp
114 * - Handles DU F1Setup Rsp received in F1AP
116 * @params[in] Pointer to F1SetupRsp
119 ******************************************************************/
120 void duProcF1SetupRsp()
122 DU_LOG("\nINFO --> DU_APP : F1 Setup Response received");
123 duCb.f1Status = TRUE; //Set F1 status as true
126 /*******************************************************************
128 * @brief Returns cellCb based on cell ID
132 * Function : duGetCellCb
134 * Functionality: Returns DU APP CellCb based on cell ID
136 * @params[in] F1AP_PDU_t ASN decoded F1AP message
137 * @return ROK - success
140 * ****************************************************************/
141 uint8_t duGetCellCb(uint16_t cellId, DuCellCb **cellCb)
145 for(cellIdx=0; cellIdx < MAX_NUM_CELL; cellIdx++)
147 if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->cellId == cellId))
149 *cellCb = duCb.actvCellLst[cellIdx];
156 DU_LOG("\nERROR --> DU APP : Cell Id %d not found in DU APP", cellId);
163 /*****************************************************************
164 * @brief Handles slot indication from MAC
168 * Function : duHandleSlotInd
171 * Handles slot indication from MAC
173 * @params[in] Post structure pointer
174 * SlotTimingInfo *slotIndInfo
175 * @return ROK - success
179 *****************************************************************/
180 uint8_t duHandleSlotInd(Pst *pst, SlotTimingInfo *slotIndInfo)
182 uint8_t cellIdx = 0, ret = ROK;
187 GET_CELL_IDX(slotIndInfo->cellId, cellIdx);
188 duCellCb = duCb.actvCellLst[cellIdx];
192 duCellCb->currSlotInfo.sfn = slotIndInfo->sfn;
193 duCellCb->currSlotInfo.slot = slotIndInfo->slot;
197 DU_LOG("\nERROR --> DU APP : CellId[%d] doesnot exist", slotIndInfo->cellId);
200 DU_FREE_SHRABL_BUF(pst->region, pst->pool, slotIndInfo, sizeof(SlotTimingInfo));
204 DU_LOG("\nERROR --> DU APP : Recevied null pointer from MAC");
209 /*******************************************************************
211 * @brief Handles cell up indication from MAC
215 * Function : duHandleCellUpInd
218 * Handles cell up indication from MAC
220 * @params[in] Post structure pointer
222 * @return ROK - success
225 * ****************************************************************/
226 uint8_t duHandleCellUpInd(Pst *pst, OduCellId *cellId)
228 DuCellCb *cellCb = NULLP;
230 if(cellId->cellId <=0 || cellId->cellId > MAX_NUM_CELL)
232 DU_LOG("\nERROR --> DU APP : Invalid Cell Id %d in duHandleCellUpInd()", cellId->cellId);
236 if(duGetCellCb(cellId->cellId, &cellCb) != ROK)
239 if((cellCb != NULL) && (cellCb->cellStatus == ACTIVATION_IN_PROGRESS))
241 DU_LOG("\nINFO --> DU APP : 5G-NR Cell %d is UP", cellId->cellId);
242 cellCb->cellStatus = ACTIVATED;
243 gCellStatus = CELL_UP;
245 if(duCfgParam.tempSliceCfg.rrmPolicy)
246 BuildAndSendSliceConfigReq(duCfgParam.tempSliceCfg.rrmPolicy, duCfgParam.tempSliceCfg.totalRrmPolicy, duCfgParam.tempSliceCfg.totalSliceCount);
248 DU_LOG("\nINFO --> DU APP : Raise cell UP alarm for cell id=%d", cellId->cellId);
249 raiseCellAlrm(CELL_UP_ALARM_ID, cellId->cellId);
250 setCellOpState(cellId->cellId, ENABLED, ACTIVE);
255 if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
256 DU_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, sizeof(OduCellId));
260 /*******************************************************************
262 * @brief Handle Cell delete response from MAC
266 * Function : DuProcMacCellDeleteRsp
268 * Functionality: Handle Cell delete response from MAC
270 * @params[in] Pointer to MacCellDeleteRsp and Pst
271 * @return ROK - success
274 * ****************************************************************/
276 uint8_t DuProcMacCellDeleteRsp(Pst *pst, MacCellDeleteRsp *deleteRsp)
283 if(deleteRsp->result == SUCCESSFUL_RSP)
285 GET_CELL_IDX(deleteRsp->cellId, cellIdx);
286 DU_LOG("\nINFO --> DU APP : MAC CELL Delete Response : SUCCESS [CELL IDX : %d]", deleteRsp->cellId);
287 if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->cellId == deleteRsp->cellId))
289 memset(duCb.actvCellLst[cellIdx], 0, sizeof(DuCellCb));
290 gCellStatus = CELL_DOWN;
293 DU_LOG("\nINFO --> DU APP : Raise cell down alarm for cell id=%d", deleteRsp->cellId);
294 raiseCellAlrm(CELL_DOWN_ALARM_ID, deleteRsp->cellId);
295 setCellOpState(deleteRsp->cellId, DISABLED, INACTIVE);
300 DU_FREE(duCb.actvCellLst[cellIdx], sizeof(DuCellCb));
305 DU_LOG("\nERROR --> DU APP : DuProcMacCellDeleteRsp(): CellId [%d] doesnot exist", deleteRsp->cellId);
311 DU_LOG("\nERROR --> DU APP : DuProcMacCellDeleteRsp(): MAC CELL Delete Response : FAILED\
312 [CELL IDX : %d]", deleteRsp->cellId);
315 DU_FREE_SHRABL_BUF(pst->region, pst->pool, deleteRsp, sizeof(MacCellDeleteRsp));
319 DU_LOG("\nERROR --> DU APP : DuProcMacCellDeleteRsp(): Received MAC cell delete response is NULL");
325 /*******************************************************************
327 * @brief Sending Cell Delete Req To Mac
331 * Function : sendCellDeleteReqToMac
334 * sending Cell Delete Req To Mac
336 * @params[in] uint16_t cellId
337 * @return ROK - success
341 *****************************************************************/
343 uint8_t sendCellDeleteReqToMac(uint16_t cellId)
347 MacCellDelete *cellDelete = NULLP;
349 DU_ALLOC_SHRABL_BUF(cellDelete, sizeof(MacCellDelete));
352 cellDelete->cellId = cellId;
353 FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_DELETE_REQ);
355 DU_LOG("\nINFO --> DU APP : Sending Cell Delete Request to MAC");
356 /* Processing one Cell at a time to MAC */
357 ret = (*packMacCellDeleteReqOpts[pst.selector])(&pst, cellDelete);
360 DU_LOG("\nERROR --> DU APP : sendCellDeleteReqToMac(): Failed to send Cell delete Req to MAC");
361 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cellDelete, sizeof(MacCellDelete));
366 DU_LOG("\nERROR --> DU APP : sendCellDeleteReqToMac(): Failed to allocate memory");
372 /*******************************************************************
374 * @brief DU preocess Cell Delete Req to MAC
378 * Function : duSendCellDeletReq
380 * Functionality: DU process Cell Delete Req to MAC
382 * @params[in] uint16_t cellId
383 * @return ROK - success
386 * ****************************************************************/
388 uint8_t duSendCellDeletReq(uint16_t cellId)
390 uint16_t cellIdx = 0;
391 DU_LOG("\nINFO --> DU APP : Processing Cell Delete Request ");
392 GET_CELL_IDX(cellId, cellIdx);
394 if(duCb.actvCellLst[cellIdx] == NULLP)
396 DU_LOG("\nERROR --> DU APP : duSendCellDeletReq(): CellId[%d] is not found", cellId);
400 if(duCb.actvCellLst[cellIdx]->cellId != cellId)
402 DU_LOG("\nERROR --> DU APP : duSendCellDeletReq(): CellId[%d] is not found", cellId);
407 if(duCb.actvCellLst[cellIdx]->cellStatus != DELETION_IN_PROGRESS)
409 DU_LOG("\nERROR --> DU APP : duSendCellDeletReq(): CellStatus[%d] of cellId[%d] is not correct.\
410 Expected CellStatus is DELETION_IN_PROGRESS",duCb.actvCellLst[cellIdx]->cellStatus, cellId);
414 if(duBuildAndSendMacCellStop(cellId) == RFAILED)
416 DU_LOG("\nERROR --> DU APP : duSendCellDeletReq(): Failed to build and send cell stop request to MAC for\
424 /*******************************************************************
425 * @brief fill paging information of a UE belongs to a particular cell
429 * Function : FillPagingInfoInCellCb
431 * Functionality: fill paging information of a UE in DuCellCb
433 * @params[in] DuCellCb* cellCb, uint8_t ueId,
434 * DuPagingMsg rcvdF1apPagingParam
436 * @return ROK - success
439 * ****************************************************************/
440 uint8_t FillPagingInfoInCellCb(DuCellCb* cellCb, DuPagingMsg *rcvdF1apPagingParam)
443 uint16_t T=0, N=0, pagingFrame = 0, n = 0;
444 uint16_t currentSfn = 0, sfn = 0, newSfn = 0;
447 DU_LOG("\nINFO --> DU APP : Start filling paging parameters in DuCellCb");
450 /* calculate paging frame and paging offset */
451 duPcchCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.pcchCfg;
452 rcvdF1apPagingParam->pagingFrameOffset = duPcchCfg.pageFrameOffset;
456 * Fill the Value of T (DRX cycle of the UE)
457 * T = min(UE Specific DRX value allocated by upper layers, default DRX
458 * broadcast in System Information) */
459 if((rcvdF1apPagingParam->pagingDrxPres) && (duPcchCfg.dfltPagingCycle > rcvdF1apPagingParam->pagingDrx))
461 T = rcvdF1apPagingParam->pagingDrx;
465 T = duPcchCfg.dfltPagingCycle;
467 rcvdF1apPagingParam->T = T;
469 /* N= number of total paging frames in T */
471 switch(duPcchCfg.nAndPagingFrmOffsetType)
473 case PCCH_Config__nAndPagingFrameOffset_PR_oneT:
476 case PCCH_Config__nAndPagingFrameOffset_PR_halfT:
479 case PCCH_Config__nAndPagingFrameOffset_PR_quarterT:
482 case PCCH_Config__nAndPagingFrameOffset_PR_oneEighthT:
485 case PCCH_Config__nAndPagingFrameOffset_PR_oneSixteenthT:
493 /* calculate the Value of pagingFrame */
494 /*Refer: 38.304 Sec 7.1: (SFN + PF_offset) mod T = (T div N)*(UE_ID mod N)*/
495 //RHS of above formula
496 pagingFrame = (T / N) * ((rcvdF1apPagingParam->ueId) % N);
498 //LHS of above formula
501 pagingFrame = (pagingFrame - rcvdF1apPagingParam->pagingFrameOffset)%T;
503 else /*Paging Frame = 0 so thus PF will be calculated on Paging Cycle*/
505 pagingFrame = (T - rcvdF1apPagingParam->pagingFrameOffset)%T;
508 /*Paging Frame(SFN for Paging) has to be determined from current SFN. */
509 /*For eg: If T =128, PF(Calculated above) = 20; SFN can be 20,148,276,...
510 * If currSFN is running as 200 then (newSFN % T) == (T/N)*(UE_ID%N)
511 *Thus SFN at which paging has to be sent needs to be delayed and newSFN = 276*/
513 currentSfn = cellCb->currSlotInfo.sfn;
515 /*Multiplication Factor(x) to find the next best SFN to process paging*/
517 /*Below calculation will determine in which nth cycle of T (DRX cycle),new PF
518 * may fall(Delayed one)*/
519 if(currentSfn > pagingFrame)
521 n = ((currentSfn - pagingFrame) / T) + 1;
525 n = ((pagingFrame - currentSfn) / T) + 1;
528 newSfn = pagingFrame + T * n;
530 /*When pagingFrame is future from currSFN then pagingFrame will be used
531 * else pagingFrame is delayed thus newSFN will be used.*/
532 if(currentSfn <= pagingFrame)
534 if(pagingFrame > currentSfn + PAGING_SCHED_DELTA)
546 if(newSfn > currentSfn + PAGING_SCHED_DELTA)
550 else /*If newSFN is near to currSFN then delay it more by T*/
556 rcvdF1apPagingParam->pagingFrame = (sfn % 1024);
557 rcvdF1apPagingParam->i_s = ((uint32_t)(floor(rcvdF1apPagingParam->ueId / N)) % ns);
559 DU_LOG("\nINFO --> DU APP : Successfully filled paging parameter in DuCellCb");
560 memcpy(&cellCb->tmpPagingInfoOfUe, rcvdF1apPagingParam, sizeof(DuPagingMsg));
564 DU_LOG("\nINFO --> DU APP : FillPagingInfoInCellCb(): Received null pointer");
571 /**********************************************************************
573 **********************************************************************/