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"
34 #include "PagingUE-Identity.h"
35 #include "PagingRecord.h"
36 #include "PagingRecordList.h"
37 #include "PagingRrc.h"
38 #include "PCCH-MessageType.h"
39 #include "PCCH-Message.h"
40 #include "odu_common_codec.h"
44 #include "AlarmInterface.h"
45 #include "CmInterface.h"
49 DuMacCellDeleteReq packMacCellDeleteReqOpts[] =
51 packDuMacCellDeleteReq, /* Loose coupling */
52 MacProcCellDeleteReq, /* TIght coupling */
53 packDuMacCellDeleteReq /* Light weight-loose coupling */
56 DuMacDlPcchInd packMacDlPcchIndOpts[] =
58 packDuMacDlPcchInd, /* Loose coupling */
59 MacProcDlPcchInd, /* TIght coupling */
60 packDuMacDlPcchInd /* Light weight-loose coupling */
63 /*******************************************************************
65 * @brief Processes cells to be activated
69 * Function : duProcCellsToBeActivated
72 * - Processes cells to be activated list received in F1SetupRsp
75 * @return ROK - success
78 * ****************************************************************/
79 uint8_t duProcCellsToBeActivated(uint8_t *plmnStr, uint16_t nci, uint16_t nRPci)
82 DuCellCb *cellCb = NULLP;
83 uint8_t cfgIdx, tmpPlmn[4];
85 for(cfgIdx=0; cfgIdx<duCb.numCfgCells; cfgIdx++)
87 memset(tmpPlmn, 0, 4);
88 buildPlmnId(duCb.cfgCellLst[cfgIdx]->cellInfo.nrEcgi.plmn, tmpPlmn);
89 if(duCb.cfgCellLst[cfgIdx]->cellInfo.nrEcgi.cellId == nci &&
90 (strcmp((const char*)tmpPlmn, (const char*)plmnStr) == 0))
92 cellCb = duCb.cfgCellLst[cfgIdx];
97 DU_LOG("\nERROR --> DU APP : No Cell found for NCI %d", nci);
102 cellCb->cellStatus = ACTIVATION_IN_PROGRESS;
103 cellCb->cellInfo.nrPci = nRPci;
105 if((cmHashListInit(&(cellCb->pagingInfoMap), MAX_SFN, sizeof(DuPagInfoList),\
106 FALSE, CM_HASH_KEYTYPE_CONID, DU_APP_MEM_REGION, DU_POOL)) != ROK)
108 DU_LOG("ERROR --> DU APP: Failed to Initialize the Paging Hash Map");
111 duCb.actvCellLst[cellCb->cellId -1] = cellCb;
114 if(duBuildAndSendMacCellCfg(cellCb->cellId) != ROK)
116 DU_LOG("\nERROR --> DU APP : macCellCfg build and send failed");
117 /* Delete cell from actvCellList */
118 duCb.actvCellLst[cellCb->cellId -1] = NULLP;
119 --(duCb.numActvCells);
125 /*******************************************************************
127 * @brief Handles DU F1Setup Rsp received in F1AP
131 * Function : duProcF1SetupRsp
134 * - Handles DU F1Setup Rsp received in F1AP
136 * @params[in] Pointer to F1SetupRsp
139 ******************************************************************/
140 void duProcF1SetupRsp()
142 DU_LOG("\nINFO --> DU_APP : F1 Setup Response received");
143 duCb.f1Status = TRUE; //Set F1 status as true
146 /*******************************************************************
148 * @brief Returns cellCb based on cell ID
152 * Function : duGetCellCb
154 * Functionality: Returns DU APP CellCb based on cell ID
156 * @params[in] F1AP_PDU_t ASN decoded F1AP message
157 * @return ROK - success
160 * ****************************************************************/
161 uint8_t duGetCellCb(uint16_t cellId, DuCellCb **cellCb)
165 for(cellIdx=0; cellIdx < MAX_NUM_CELL; cellIdx++)
167 if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->cellId == cellId))
169 *cellCb = duCb.actvCellLst[cellIdx];
176 DU_LOG("\nERROR --> DU APP : Cell Id %d not found in DU APP", cellId);
183 /******************************************************************************
184 * @brief Check Paging Record for a Particular Paging Frame
188 * Function : checkPagingRecord
191 * Check Paging Record for a Particular Paging Frame
193 * @params[in] DuCellCb *cellCb
195 * @return ROK/RFAILURE (uint8_t return)
198 ******************************************************************************/
199 uint8_t checkPagingRecord(DuCellCb *cellCb)
202 DuPagInfoList *pagInfoLLFromPF = NULLP;
203 DuPagUeList *pagInfo = NULLP;
205 /*DUAPP may send PagingReq to MAC for future SFN so that Schedular can
206 * schedule Paging on the exact occurence of the Slot.*/
207 pf = (cellCb->currSlotInfo.sfn + PAGING_SCHED_DELTA) % MAX_SFN;
209 pagInfoLLFromPF = findPagingInfoFromMap(pf, &(cellCb->pagingInfoMap));
210 if(pagInfoLLFromPF == NULLP)
212 /*No Page is present for pf thus exiting*/
218 pagInfo = handlePageInfoLL(pf, NULLD, &(pagInfoLLFromPF->pagInfoList), TRAVERSE_ALL);
221 if(BuildAndSendDlPcchIndToMac(cellCb->cellId, pf, pagInfo->i_s, &(pagInfo->pagUeList)) != ROK)
223 DU_LOG("\nERROR --> DU APP: Issue in Building Page RRC PDU i_s:%d",pagInfo->i_s);
226 handlePageInfoLL(pf, pagInfo->i_s, &(pagInfoLLFromPF->pagInfoList), DELETE);
228 if(pagInfoLLFromPF->pagInfoList.first == NULLP)
232 }while(pagInfo != NULLP);
234 cmHashListDelete(&(cellCb->pagingInfoMap), (PTR)pagInfoLLFromPF);
235 DU_FREE(pagInfoLLFromPF, sizeof(DuPagInfoList));
239 /******************************************************************
241 * @brief Send pcch indication to MAC
245 * Function : sendDlPcchIndToMac
247 * Functionality: Send pcch indication to MAC
249 * @Params[in] MacPcchInd *pcchInd
250 * @return ROK - success
253 * ****************************************************************/
255 uint8_t sendDlPcchIndToMac(MacPcchInd *pcchInd)
263 FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_DL_PCCH_IND);
265 DU_LOG("\nDEBUG --> DU_APP: Sending DL PCCH indication to MAC for cellId[%d] at PF[%d]",\
266 pcchInd->cellId, pcchInd->pf);
267 ret = (*packMacDlPcchIndOpts[pst.selector])(&pst, pcchInd);
270 DU_LOG("\nERROR --> DU APP : sendDlPcchIndToMac(): Failed to DL PCCH indication to MAC");
275 DU_LOG("\nERROR --> DU_APP: sendDlPcchIndToMac(): Received pcchInd is NULLP");
282 /*****************************************************************
283 * @brief Handles slot indication from MAC
287 * Function : duHandleSlotInd
290 * Handles slot indication from MAC
292 * @params[in] Post structure pointer
293 * SlotTimingInfo *slotIndInfo
294 * @return ROK - success
298 *****************************************************************/
299 uint8_t duHandleSlotInd(Pst *pst, SlotTimingInfo *slotIndInfo)
301 uint8_t cellIdx = 0, ret = ROK;
302 DuCellCb *duCellCb = NULLP;
306 GET_CELL_IDX(slotIndInfo->cellId, cellIdx);
307 duCellCb = duCb.actvCellLst[cellIdx];
311 duCellCb->currSlotInfo.sfn = slotIndInfo->sfn;
312 duCellCb->currSlotInfo.slot = slotIndInfo->slot;
313 checkPagingRecord(duCellCb);
317 DU_LOG("\nERROR --> DU APP : CellId[%d] doesnot exist", slotIndInfo->cellId);
320 DU_FREE_SHRABL_BUF(pst->region, pst->pool, slotIndInfo, sizeof(SlotTimingInfo));
324 DU_LOG("\nERROR --> DU APP : Recevied null pointer from MAC");
329 /*******************************************************************
331 * @brief Handles cell up indication from MAC
335 * Function : duHandleCellUpInd
338 * Handles cell up indication from MAC
340 * @params[in] Post structure pointer
342 * @return ROK - success
345 * ****************************************************************/
346 uint8_t duHandleCellUpInd(Pst *pst, OduCellId *cellId)
348 DuCellCb *cellCb = NULLP;
350 if(cellId->cellId <=0 || cellId->cellId > MAX_NUM_CELL)
352 DU_LOG("\nERROR --> DU APP : Invalid Cell Id %d in duHandleCellUpInd()", cellId->cellId);
356 if(duGetCellCb(cellId->cellId, &cellCb) != ROK)
359 if((cellCb != NULL) && (cellCb->cellStatus == ACTIVATION_IN_PROGRESS))
361 DU_LOG("\nINFO --> DU APP : 5G-NR Cell %d is UP", cellId->cellId);
362 cellCb->cellStatus = ACTIVATED;
363 gCellStatus = CELL_UP;
365 if(duCfgParam.tempSliceCfg.rrmPolicy)
366 BuildAndSendSliceConfigReq(duCfgParam.tempSliceCfg.rrmPolicy, duCfgParam.tempSliceCfg.totalRrmPolicy, duCfgParam.tempSliceCfg.totalSliceCount);
368 DU_LOG("\nINFO --> DU APP : Raise cell UP alarm for cell id=%d", cellId->cellId);
369 raiseCellAlrm(CELL_UP_ALARM_ID, cellId->cellId);
370 setCellOpState(cellId->cellId, ENABLED, ACTIVE);
375 if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
376 DU_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, sizeof(OduCellId));
380 /*******************************************************************
382 * @brief Handle Cell delete response from MAC
386 * Function : DuProcMacCellDeleteRsp
388 * Functionality: Handle Cell delete response from MAC
390 * @params[in] Pointer to MacCellDeleteRsp and Pst
391 * @return ROK - success
394 * ****************************************************************/
396 uint8_t DuProcMacCellDeleteRsp(Pst *pst, MacCellDeleteRsp *deleteRsp)
399 uint16_t cellIdx=0, pfIdx=0;
400 DuPagInfoList *pagInfoLLFromPF=NULLP;
404 if(deleteRsp->result == SUCCESSFUL_RSP)
406 GET_CELL_IDX(deleteRsp->cellId, cellIdx);
407 DU_LOG("\nINFO --> DU APP : MAC CELL Delete Response : SUCCESS [CELL IDX : %d]", deleteRsp->cellId);
408 if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->cellId == deleteRsp->cellId))
410 for(pfIdx =0; pfIdx < MAX_SFN; pfIdx++)
412 pagInfoLLFromPF = findPagingInfoFromMap(pfIdx, &(duCb.actvCellLst[cellIdx]->pagingInfoMap));
415 cmHashListDelete(&(duCb.actvCellLst[cellIdx]->pagingInfoMap), (PTR)pagInfoLLFromPF);
416 DU_FREE(pagInfoLLFromPF, sizeof(DuPagInfoList));
420 memset(duCb.actvCellLst[cellIdx], 0, sizeof(DuCellCb));
421 gCellStatus = CELL_DOWN;
424 DU_LOG("\nINFO --> DU APP : Raise cell down alarm for cell id=%d", deleteRsp->cellId);
425 raiseCellAlrm(CELL_DOWN_ALARM_ID, deleteRsp->cellId);
426 setCellOpState(deleteRsp->cellId, DISABLED, INACTIVE);
431 DU_FREE(duCb.actvCellLst[cellIdx], sizeof(DuCellCb));
436 DU_LOG("\nERROR --> DU APP : DuProcMacCellDeleteRsp(): CellId [%d] doesnot exist", deleteRsp->cellId);
442 DU_LOG("\nERROR --> DU APP : DuProcMacCellDeleteRsp(): MAC CELL Delete Response : FAILED\
443 [CELL IDX : %d]", deleteRsp->cellId);
446 DU_FREE_SHRABL_BUF(pst->region, pst->pool, deleteRsp, sizeof(MacCellDeleteRsp));
450 DU_LOG("\nERROR --> DU APP : DuProcMacCellDeleteRsp(): Received MAC cell delete response is NULL");
456 /*******************************************************************
458 * @brief Sending Cell Delete Req To Mac
462 * Function : sendCellDeleteReqToMac
465 * sending Cell Delete Req To Mac
467 * @params[in] uint16_t cellId
468 * @return ROK - success
472 *****************************************************************/
474 uint8_t sendCellDeleteReqToMac(uint16_t cellId)
478 MacCellDelete *cellDelete = NULLP;
480 DU_ALLOC_SHRABL_BUF(cellDelete, sizeof(MacCellDelete));
483 cellDelete->cellId = cellId;
484 FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_DELETE_REQ);
486 DU_LOG("\nINFO --> DU APP : Sending Cell Delete Request to MAC");
487 /* Processing one Cell at a time to MAC */
488 ret = (*packMacCellDeleteReqOpts[pst.selector])(&pst, cellDelete);
491 DU_LOG("\nERROR --> DU APP : sendCellDeleteReqToMac(): Failed to send Cell delete Req to MAC");
492 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cellDelete, sizeof(MacCellDelete));
497 DU_LOG("\nERROR --> DU APP : sendCellDeleteReqToMac(): Failed to allocate memory");
503 /*******************************************************************
505 * @brief DU preocess Cell Delete Req to MAC
509 * Function : duSendCellDeletReq
511 * Functionality: DU process Cell Delete Req to MAC
513 * @params[in] uint16_t cellId
514 * @return ROK - success
517 * ****************************************************************/
519 uint8_t duSendCellDeletReq(uint16_t cellId)
521 uint16_t cellIdx = 0;
522 DU_LOG("\nINFO --> DU APP : Processing Cell Delete Request ");
523 GET_CELL_IDX(cellId, cellIdx);
525 if(duCb.actvCellLst[cellIdx] == NULLP)
527 DU_LOG("\nERROR --> DU APP : duSendCellDeletReq(): CellId[%d] is not found", cellId);
531 if(duCb.actvCellLst[cellIdx]->cellId != cellId)
533 DU_LOG("\nERROR --> DU APP : duSendCellDeletReq(): CellId[%d] is not found", cellId);
538 if(duCb.actvCellLst[cellIdx]->cellStatus != DELETION_IN_PROGRESS)
540 DU_LOG("\nERROR --> DU APP : duSendCellDeletReq(): CellStatus[%d] of cellId[%d] is not correct.\
541 Expected CellStatus is DELETION_IN_PROGRESS",duCb.actvCellLst[cellIdx]->cellStatus, cellId);
545 if(duBuildAndSendMacCellStop(cellId) == RFAILED)
547 DU_LOG("\nERROR --> DU APP : duSendCellDeletReq(): Failed to build and send cell stop request to MAC for\
555 /*******************************************************************
556 * @brief Free PCCH PDU structure
560 * Function : freePcchPdu
562 * Functionality: Free PCCH PDU structure
564 * @params[in] PCCH_Message_t *pcchMsg
568 * ****************************************************************/
569 void freePcchPdu(PCCH_Message_t *pcchMsg)
571 PagingRrc_t *pagingMsg = NULLP;
572 uint8_t recordIdx = 0;
576 if(pcchMsg->message.choice.c1 != NULLP)
578 pagingMsg = pcchMsg->message.choice.c1->choice.paging;
579 if(pagingMsg != NULLP)
581 if(pagingMsg->pagingRecordList)
583 if(pagingMsg->pagingRecordList->list.array != NULLP)
585 for(recordIdx = 0; recordIdx < pagingMsg->pagingRecordList->list.count; recordIdx++)
587 if(pagingMsg->pagingRecordList->list.array[recordIdx] != NULLP)
589 DU_FREE(pagingMsg->pagingRecordList->list.array[recordIdx]->ue_Identity.choice.ng_5G_S_TMSI.buf,\
590 pagingMsg->pagingRecordList->list.array[recordIdx]->ue_Identity.choice.ng_5G_S_TMSI.size);
591 DU_FREE(pagingMsg->pagingRecordList->list.array[recordIdx], sizeof(PagingRecord_t));
594 DU_FREE(pagingMsg->pagingRecordList->list.array, pagingMsg->pagingRecordList->list.size);
596 DU_FREE(pagingMsg->pagingRecordList, sizeof(PagingRecordList_t));
598 DU_FREE(pcchMsg->message.choice.c1->choice.paging, sizeof(PagingRrc_t));
600 DU_FREE(pcchMsg->message.choice.c1 , sizeof(PCCH_MessageType_t));
602 DU_FREE(pcchMsg , sizeof(PCCH_Message_t));
606 /*******************************************************************
607 * @brief Builds the Pcch RRC PDU and forwards it to MAC
611 * Function : BuildAndSendDlPcchIndToMac
613 * Functionality: Builds the Pcch RRC PDU[As per Spec 38.331, Annexure A]
614 * and forwards it to MAC as Buffer along with PF and i_s
616 * @params[in] uint16_t cellId, uint16_t pf, uint8_t i_s,CmLListCp *pageUeLL
618 * @return ROK - success
621 * ****************************************************************/
622 uint8_t BuildAndSendDlPcchIndToMac(uint16_t cellId, uint16_t pf, uint8_t i_s, CmLListCp *pageUeLL)
624 CmLList *node = NULLP, *next = NULLP;
625 DuPagUeRecord *ueRecord = NULLP;
626 PCCH_Message_t *pcchMsg = NULLP;
627 asn_enc_rval_t encRetVal;
628 PagingRrc_t *pagingMsg = NULLP;
629 MacPcchInd *macPcchInd = NULLP;
630 uint8_t recordIdx = 0, ret = RFAILED;
632 /*As per 38.473 Sec 9.3.1.39,5G-S-TMSI :48 Bits >> Bytes and 0 UnusedBits */
633 uint8_t totalByteInTmsi = 6, unusedBitsInTmsi = 0;
635 if(pageUeLL == NULLP || pageUeLL->count == 0)
637 DU_LOG("\nERROR --> DU APP: UE Page Record LL is empty");
643 memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
644 DU_ALLOC(pcchMsg , sizeof(PCCH_Message_t));
647 DU_LOG("\nERROR --> DU APP: BuildAndSendDlPcchIndToMac(): (pccchMsg) Memory Alloction failed!");
650 pcchMsg->message.present = PCCH_MessageType_PR_c1;
651 DU_ALLOC(pcchMsg->message.choice.c1 , sizeof(PCCH_MessageType_t));
652 if(pcchMsg->message.choice.c1 == NULLP)
654 DU_LOG("\nERROR --> DU APP: BuildAndSendDlPcchIndToMac(); (C1) Memory Alloction failed!");
657 pcchMsg->message.choice.c1->present = PCCH_MessageType__c1_PR_paging;
658 DU_ALLOC(pcchMsg->message.choice.c1->choice.paging, sizeof(PagingRrc_t));
660 pagingMsg = pcchMsg->message.choice.c1->choice.paging;
661 if(pagingMsg == NULLP)
663 DU_LOG("\nERROR --> DU APP: BuildAndSendDlPcchIndToMac(); (Paging) Memory Alloction failed!");
666 DU_ALLOC(pagingMsg->pagingRecordList, sizeof(PagingRecordList_t));
667 if(pagingMsg->pagingRecordList == NULLP)
669 DU_LOG("\nERROR --> DU APP: BuildAndSendDlPcchIndToMac(); (Paging Record List) Memory Alloction failed!");
673 pagingMsg->pagingRecordList->list.count = pageUeLL->count;
675 /*As per Spec 38.331, maxNrofPageRec : 32 [Maximum number of page records]*/
676 if(pageUeLL->count > MAX_PAGING_UE_RECORDS)
678 pagingMsg->pagingRecordList->list.count = MAX_PAGING_UE_RECORDS;
681 pagingMsg->pagingRecordList->list.size = pageUeLL->count * (sizeof(PagingRecord_t *));
682 DU_ALLOC(pagingMsg->pagingRecordList->list.array, pagingMsg->pagingRecordList->list.size);
683 if(pagingMsg->pagingRecordList->list.array == NULLP)
685 DU_LOG("\nERROR --> DU APP: BuildAndSendDlPcchIndToMac(); (Array) Memory Alloction failed!");
688 for(recordIdx = 0; recordIdx < pageUeLL->count; recordIdx++)
690 DU_ALLOC(pagingMsg->pagingRecordList->list.array[recordIdx], sizeof(PagingRecord_t));
691 if(pagingMsg->pagingRecordList->list.array[recordIdx] == NULLP)
693 DU_LOG("\nERROR --> DU APP: BuildAndSendDlPcchIndToMac(); (Record) Memory Alloction failed!");
698 node = pageUeLL->first;
699 while(node && (recordIdx < MAX_PAGING_UE_RECORDS))
702 ueRecord = (DuPagUeRecord *)node->node;
705 /*TODO : When Connected Mode Paging will be supported then I_RNTI will be introduced*/
706 pagingMsg->pagingRecordList->list.array[recordIdx]->ue_Identity.present = PagingUE_Identity_PR_ng_5G_S_TMSI;
707 pagingMsg->pagingRecordList->list.array[recordIdx]->ue_Identity.choice.ng_5G_S_TMSI.size = totalByteInTmsi*sizeof(uint8_t);
708 DU_ALLOC(pagingMsg->pagingRecordList->list.array[recordIdx]->ue_Identity.choice.ng_5G_S_TMSI.buf,\
709 pagingMsg->pagingRecordList->list.array[recordIdx]->ue_Identity.choice.ng_5G_S_TMSI.size);
710 if(pagingMsg->pagingRecordList->list.array[recordIdx]->ue_Identity.choice.ng_5G_S_TMSI.buf == NULLP)
712 DU_LOG("\nERROR --> DU APP: BuildAndSendDlPcchIndToMac(); (5gsTmsi buffer) Memory Allocation failed!");
715 fillBitString(&pagingMsg->pagingRecordList->list.array[recordIdx]->ue_Identity.choice.ng_5G_S_TMSI,\
716 unusedBitsInTmsi, totalByteInTmsi, ueRecord->sTmsi);
720 if(duDelNodeFromLList(pageUeLL, node) == ROK)
721 DU_FREE(ueRecord, sizeof(DuPagUeRecord));
724 if(node != NULLP && (recordIdx < MAX_PAGING_UE_RECORDS))
726 /*This leg is hit because Whole UE REcord List was not traversed as
727 * some issue happened thus exiting the main while*/
730 xer_fprint(stdout, &asn_DEF_PCCH_Message, pcchMsg);
731 memset(encBuf, 0, ENC_BUF_MAX_LEN);
733 /* Encode the PCCH RRC PDU as APER */
734 encRetVal = aper_encode(&asn_DEF_PCCH_Message, 0, pcchMsg, PrepFinalEncBuf,\
737 if(encRetVal.encoded == ENCODE_FAIL)
739 DU_LOG("\nERROR --> F1AP : Could not encode Paging structure (at %s)\n",\
740 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
745 DU_LOG("\nDEBUG --> F1AP : Created APER encoded buffer for RRC PDU for Pcch indication \n");
747 DU_ALLOC_SHRABL_BUF(macPcchInd, sizeof(MacPcchInd));
748 if(macPcchInd == NULLP)
750 DU_LOG("\nERROR --> DU APP: BuildAndSendDlPcchIndToMac(); (macPcchInd) Memory Alloction failed!");
754 macPcchInd->cellId = cellId;
756 macPcchInd->i_s = i_s;
757 macPcchInd->pduLen = encBufSize;
758 DU_ALLOC_SHRABL_BUF(macPcchInd->pcchPdu, macPcchInd->pduLen);
759 if(macPcchInd->pcchPdu == NULLP)
761 DU_LOG("\nERROR --> DU APP: BuildAndSendDlPcchIndToMac(); (PcchPDU) Memory Alloction failed!");
764 memcpy(macPcchInd->pcchPdu, encBuf, macPcchInd->pduLen);
765 ret = sendDlPcchIndToMac(macPcchInd);
768 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, macPcchInd->pcchPdu, macPcchInd->pduLen);
769 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, macPcchInd, sizeof(MacPcchInd));
776 freePcchPdu(pcchMsg);
780 /*******************************************************************
781 * @brief Keeping the record of Paging having a particular SFN and index associated
785 * Function : insertPagingRecord
787 * Functionality: Insert record of Paging assoc with particular SFN and index associated
789 * @params[in] DuCellCb* cellCb, uint16_t iterations
790 * DuPagingMsg rcvdF1apPagingParam
792 * @return ROK - success
795 * ****************************************************************/
796 uint8_t insertPagingRecord(DuCellCb* cellCb, DuPagingMsg *rcvdF1apPagingParam, uint16_t iterations)
798 uint16_t maxIterations = 0;
799 DuPagInfoList *pagInfoLLFromPF = NULLP;
800 DuPagUeList *pageUeLL = NULLP;
801 DuPagUeRecord *ueRecord = NULLP;
804 printPageList(&(cellCb->pagingInfoMap));
807 /*MAX Iteration : A UE can be paged at every T frames thus MAX determines
808 *how many Paging Frame(s) can be considered for Paging this UE*/
809 maxIterations = MAX_SFN/rcvdF1apPagingParam->T;
810 if(iterations >= maxIterations)
812 DU_LOG("\nERROR --> DU APP: MAX Iterations reached for UEID:%d, thus Paging is dropped!", rcvdF1apPagingParam->pagUeId);
816 /*[Step1]: Extracting the PF from the HasMap between PF and PagingInfoList*/
817 pagInfoLLFromPF = findPagingInfoFromMap(rcvdF1apPagingParam->pagingFrame, &(cellCb->pagingInfoMap));
818 if(pagInfoLLFromPF != NULLP)
820 /*[Step2]: Extracting the PageInfo List for the Paging Indices(i_s)*/
821 pageUeLL = handlePageInfoLL(rcvdF1apPagingParam->pagingFrame, rcvdF1apPagingParam->i_s, \
822 &(pagInfoLLFromPF->pagInfoList), CREATE);
824 if(pageUeLL != NULLP)
826 /*[Step3]: Check whether MAX UE Record against this PF and i_s has reached(Spec 38.331, Annexure A)*/
827 if(pageUeLL->pagUeList.count < MAX_PAGING_UE_RECORDS)
829 /*[Step4]: Insert the Paging Record to the end of the UE record List*/
830 ueRecord = handlePageUeLL(rcvdF1apPagingParam->pagUeId, rcvdF1apPagingParam->sTmsi,\
831 &(pageUeLL->pagUeList), CREATE);
833 if(ueRecord == NULLP)
835 DU_LOG("\nERROR --> DU APP: Unable to create UE Record in PagingList");
838 DU_LOG("\nDEBUG --> DU APP: UE Record created successfully in PagingList");
843 /*Since MAX Page record has reached for this PF thus calculating and
844 *moving this UE to next Paging Cycle*/
845 DU_LOG("\nINFO --> DU APP: Max Page Record reached for PagingFrame:%d",rcvdF1apPagingParam->pagingFrame);
846 rcvdF1apPagingParam->pagingFrame = ((rcvdF1apPagingParam->pagingFrame + rcvdF1apPagingParam->T) % MAX_SFN);
849 return insertPagingRecord(cellCb, rcvdF1apPagingParam, iterations);
853 /*Reaching here means that PF has no entry in the PageLists,
854 *Thus creating, Updating and inseritng the Paging Map, List and UE record.*/
856 DU_ALLOC(pagInfoLLFromPF, sizeof(DuPagInfoList));
858 if(pagInfoLLFromPF == NULLP)
860 DU_LOG("\nERROR --> DU APP: PageInfo Map allocation failed.");
863 pagInfoLLFromPF->pf = rcvdF1apPagingParam->pagingFrame;
864 pageUeLL = handlePageInfoLL(rcvdF1apPagingParam->pagingFrame, rcvdF1apPagingParam->i_s, &(pagInfoLLFromPF->pagInfoList), CREATE);
865 ueRecord = handlePageUeLL(rcvdF1apPagingParam->pagUeId, rcvdF1apPagingParam->sTmsi, &(pageUeLL->pagUeList), CREATE);
866 if(cmHashListInsert(&(cellCb->pagingInfoMap), (PTR)pagInfoLLFromPF, (uint8_t *)&(pagInfoLLFromPF->pf), sizeof(uint16_t)) == RFAILED)
868 DU_LOG("\nERROR --> DU APP: Hash Map Insertion Failed for PF:%d.",rcvdF1apPagingParam->pagingFrame);
872 printPageList(&(cellCb->pagingInfoMap));
880 /*******************************************************************
881 * @brief Calculate and fill paging information of a UE belongs to a particular cell
885 * Function : calcAndFillPagingInfoInCellCb
887 * Functionality: Calculate PO and i_s and
888 * fill paging information of a UE in DuCellCb
890 * @params[in] DuCellCb* cellCb, uint8_t pagUeId,
891 * DuPagingMsg rcvdF1apPagingParam
893 * @return ROK - success
896 * ****************************************************************/
897 uint8_t calcAndFillPagingInfoInCellCb(DuCellCb* cellCb, DuPagingMsg *rcvdF1apPagingParam)
900 uint16_t T=0, N=0, pagingFrame = 0, n = 0;
901 uint16_t currentSfn = 0, sfn = 0, newSfn = 0;
906 /* calculate paging frame and paging offset */
907 duPcchCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.pcchCfg;
908 rcvdF1apPagingParam->pagingFrameOffset = duPcchCfg.pageFrameOffset;
912 * Fill the Value of T (DRX cycle of the UE)
913 * T = min(UE Specific DRX value allocated by upper layers, default DRX
914 * broadcast in System Information) */
915 if((rcvdF1apPagingParam->pagingDrxPres) && (duPcchCfg.dfltPagingCycle > rcvdF1apPagingParam->pagingDrx))
917 T = rcvdF1apPagingParam->pagingDrx;
921 T = duPcchCfg.dfltPagingCycle;
923 rcvdF1apPagingParam->T = T;
925 /* N= number of total paging frames in T */
927 switch(duPcchCfg.nAndPagingFrmOffsetType)
929 case PCCH_Config__nAndPagingFrameOffset_PR_oneT:
932 case PCCH_Config__nAndPagingFrameOffset_PR_halfT:
935 case PCCH_Config__nAndPagingFrameOffset_PR_quarterT:
938 case PCCH_Config__nAndPagingFrameOffset_PR_oneEighthT:
941 case PCCH_Config__nAndPagingFrameOffset_PR_oneSixteenthT:
949 /* calculate the Value of pagingFrame */
950 /*Refer: 38.304 Sec 7.1: (SFN + PF_offset) mod T = (T div N)*(UE_ID mod N)*/
951 //RHS of above formula
952 pagingFrame = (T / N) * ((rcvdF1apPagingParam->pagUeId) % N);
954 //LHS of above formula
957 pagingFrame = (pagingFrame - rcvdF1apPagingParam->pagingFrameOffset)%T;
959 else /*Paging Frame = 0 so thus PF will be calculated on Paging Cycle*/
961 pagingFrame = (T - rcvdF1apPagingParam->pagingFrameOffset)%T;
964 /*Paging Frame(SFN for Paging) has to be determined from current SFN. */
965 /*For eg: If T =128, PF(Calculated above) = 20; SFN can be 20,148,276,...
966 * If currSFN is running as 200 then (newSFN % T) == (T/N)*(UE_ID%N)
967 *Thus SFN at which paging has to be sent needs to be delayed and newSFN = 276*/
969 currentSfn = cellCb->currSlotInfo.sfn;
971 /*Multiplication Factor(x) to find the next best SFN to process paging*/
973 /*Below calculation will determine in which nth cycle of T (DRX cycle),new PF
974 * may fall(Delayed one)*/
975 if(currentSfn > pagingFrame)
977 n = ((currentSfn - pagingFrame) / T) + 1;
981 n = ((pagingFrame - currentSfn) / T) + 1;
984 newSfn = pagingFrame + T * n;
986 /*When pagingFrame is future from currSFN then pagingFrame will be used
987 * else pagingFrame is delayed thus newSFN will be used.*/
988 if(currentSfn <= pagingFrame)
990 if(pagingFrame > currentSfn + PAGING_SCHED_DELTA)
1002 if(newSfn > currentSfn + PAGING_SCHED_DELTA)
1006 else /*If newSFN is near to currSFN then delay it more by T*/
1008 newSfn = newSfn + T;
1012 rcvdF1apPagingParam->pagingFrame = (sfn % MAX_SFN);
1013 rcvdF1apPagingParam->i_s = ((uint32_t)(floor(rcvdF1apPagingParam->pagUeId / N)) % ns);
1015 DU_LOG("\nINFO --> DU APP : Successfully filled paging parameter in DuCellCb");
1016 memcpy(&cellCb->tmpPagingInfoOfUe, rcvdF1apPagingParam, sizeof(DuPagingMsg));
1020 DU_LOG("\nINFO --> DU APP : calcAndFillPagingInfoInCellCb(): Received null pointer");
1026 /*******************************************************************
1027 * @brief Paging Processing on a particular cell
1031 * Function : processPagingMsg
1033 * Functionality: Process Paging on a particular cell
1035 * @params[in] uint16_t cellId
1036 * DuPagingMsg rcvdF1apPagingParam
1038 * @return ROK - success
1041 * ****************************************************************/
1042 uint8_t processPagingMsg(uint16_t cellId, DuPagingMsg *rcvdF1apPagingParam)
1044 uint16_t cellIdx = 0, iteration = 0;
1046 GET_CELL_IDX(cellId, cellIdx);
1048 if(duCb.actvCellLst[cellIdx] == NULLP || duCb.actvCellLst[cellIdx]->cellId != cellId)
1050 DU_LOG("\nERROR --> DU APP : processPagingMsg(): CellId[%d] is not found", cellId);
1054 if(calcAndFillPagingInfoInCellCb(duCb.actvCellLst[cellIdx], rcvdF1apPagingParam) != ROK)
1056 DU_LOG("\nERROR --> DU APP : CellCb:%d not present to fill UE Paging Information",cellId);
1059 if(insertPagingRecord(duCb.actvCellLst[cellIdx], rcvdF1apPagingParam, iteration) != ROK)
1061 DU_LOG("\nERROR --> DU APP : Insertion Failed ofUE Paging Information");
1067 /**********************************************************************
1069 **********************************************************************/