+ return ret;
+}
+
+/*****************************************************************i
+ *
+* @brief Free memory allocated for UE Context Release Command
+*
+* @details
+*
+* Function : FreeUeContextReleaseCommand
+*
+* Functionality:
+* - Free memory allocated for UE Context Release Command
+*
+* @params[in] F1AP_PDU_t *f1apMsg
+* @return void
+*
+* *************************************************************/
+void FreeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
+{
+ uint8_t ieIdx;
+ UEContextReleaseCommand_t *ueReleaseCommand = NULLP;
+
+ if(f1apMsg)
+ {
+ if(f1apMsg->choice.initiatingMessage)
+ {
+ ueReleaseCommand =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
+ if(ueReleaseCommand->protocolIEs.list.array)
+ {
+ for(ieIdx=0 ; ieIdx<ueReleaseCommand->protocolIEs.list.count; ieIdx++)
+ {
+ CU_FREE(ueReleaseCommand->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseCommand_t));
+ }
+ CU_FREE(ueReleaseCommand->protocolIEs.list.array, ueReleaseCommand->protocolIEs.list.size);
+ }
+ CU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
+ }
+ CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
+ }
+}
+/*******************************************************************
+ *
+ * @brief Builds the Ue Context Release Command
+ *
+ * @details
+*
+* Function : BuildAndSendUeContextReleaseCommand
+*
+* Functionality: Constructs the Ue Context Release Command
+*
+* @params[in]
+*
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+uint8_t BuildAndSendUeContextReleaseCommand(uint32_t duId, uint8_t cuUeF1apId, uint8_t duUeF1apId)
+{
+ bool memAllocFailed = false;
+ uint8_t ieIdx = 0,elementCnt = 0, ret = RFAILED, bufLen=0;
+ F1AP_PDU_t *f1apMsg = NULLP;
+ UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
+
+ asn_enc_rval_t encRetVal;
+ DU_LOG("\nINFO --> F1AP : Building Ue context release command\n");
+
+ while(true)
+ {
+ CU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
+ if(f1apMsg == NULLP)
+ {
+ DU_LOG("\nERROR --> F1AP : BuildAndSendUeContextReleaseCommand(): Memory allocation for F1AP-PDU");
+ break;
+ }
+
+ f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
+
+ CU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
+ if(f1apMsg->choice.initiatingMessage == NULLP)
+ {
+ DU_LOG("\nERROR --> F1AP : BuildAndSendUeContextReleaseCommand(): Memory allocation for F1AP-PDU failed ");
+ break;
+ }
+ f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextRelease;
+ f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
+ f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_UEContextReleaseCommand;
+
+ ueContextReleaseCommand =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
+
+ elementCnt = 4;
+ ueContextReleaseCommand->protocolIEs.list.count = elementCnt;
+ ueContextReleaseCommand->protocolIEs.list.size = elementCnt*sizeof(UEContextReleaseCommand_t*);
+
+ /* Initialize the UE context modification members */
+ CU_ALLOC(ueContextReleaseCommand->protocolIEs.list.array, ueContextReleaseCommand->protocolIEs.list.size);
+ if(ueContextReleaseCommand->protocolIEs.list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> F1AP : BuildAndSendUeContextReleaseCommand():Memory allocation failed");
+ break;
+ }
+
+ for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
+ {
+ CU_ALLOC(ueContextReleaseCommand->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseCommand_t));
+ if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx] == NULLP)
+ {
+ DU_LOG("\nERROR --> F1AP : BuildAndSendUeContextReleaseCommand(): Memory allocation failed ");
+ memAllocFailed = true;
+ break;
+ }
+ }
+
+ if(memAllocFailed == true)
+ {
+ break;
+ }
+ ieIdx=0;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.present = \
+ UEContextReleaseCommandIEs__value_PR_GNB_CU_UE_F1AP_ID;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =cuUeF1apId;
+
+ ieIdx++;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.present=\
+ UEContextReleaseCommandIEs__value_PR_GNB_DU_UE_F1AP_ID;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =duUeF1apId;
+
+ ieIdx++;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_Cause;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.present=\
+ UEContextReleaseCommandIEs__value_PR_Cause;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.Cause.present = Cause_PR_radioNetwork;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.Cause.choice.radioNetwork=\
+ CauseRadioNetwork_normal_release;
+
+ /* RRC Container for RRC release */
+ ieIdx++;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_RRCContainer;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.present = \
+ UEContextReleaseCommandIEs__value_PR_RRCContainer;
+ char secModeBuf[7]={ 0x00, 0x05, 0x13, 0x00, 0x00, 0x00, 0x00};
+ bufLen =7;
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = bufLen;
+ CU_ALLOC(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
+ ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
+ if(!ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
+ {
+ DU_LOG("\nERROR --> F1AP : Memory allocation for BuildAndSendUeContextReleaseCommand failed");
+ break;
+ }
+ memset(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, 0, bufLen);
+ memcpy(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, secModeBuf, bufLen);
+
+ xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
+
+ /* Encode the UE Context Release Command type as APER */
+ memset(encBuf, 0, ENC_BUF_MAX_LEN);
+ encBufSize = 0;
+ encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
+ encBuf);
+
+ /* Encode results */
+ if(encRetVal.encoded == ENCODE_FAIL)
+ {
+ DU_LOG("\nERROR --> F1AP : Could not encode Release Command structure (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> F1AP : Created APER encoded buffer for Ue Context Release Command\n");
+ for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
+ {
+ DU_LOG("%x",encBuf[ieIdx]);
+ }
+ }
+
+ /* TODO : Hardcoding DU ID to 1 for messages other than F1 Setup Response. This will be made generic in future gerrit */
+ if(SendF1APMsg(CU_APP_MEM_REG, CU_POOL, duId) != ROK)
+ {
+ DU_LOG("\nERROR --> F1AP : Sending Ue context Release Command failed");
+ break;
+ }
+
+ ret = ROK;
+ break;
+
+ }
+ FreeUeContextReleaseCommand(f1apMsg);
+ return ret;
+}
+/*******************************************************************
+*
+* @brief process Ue context release request
+*
+* @details
+*
+* Function : procUeContextReleaseReq
+*
+* Functionality:
+* - process Ue context release request
+*
+* @params[in] F1AP_PDU_t *f1apMsg
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+uint8_t procUeContextReleaseReq(uint32_t duId, F1AP_PDU_t *f1apMsg)
+{
+ uint8_t ieIdx=0, duUeF1apId=0,cuUeF1apId=0;
+
+ UEContextReleaseRequest_t *ueReleaseReq = NULLP;
+ ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
+
+ for(ieIdx=0; ieIdx < ueReleaseReq->protocolIEs.list.count; ieIdx++)
+ {
+ switch(ueReleaseReq->protocolIEs.list.array[ieIdx]->id)
+ {
+ case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
+ {
+ cuUeF1apId = ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
+ break;
+ }
+ case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
+ {
+ duUeF1apId = ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ if(BuildAndSendUeContextReleaseCommand(duId, cuUeF1apId, duUeF1apId) != ROK)
+ {
+ DU_LOG("\nERROR --> F1AP : procUeContextReleaseReq(): Failed to build Ue Context Release Command ");
+ return RFAILED;
+ }
+ return ROK;
+}
+/*******************************************************************
+*
+* @brief processing of Gnb-DU config update
+*
+* @details
+*
+* Function : procGnbDuUpdate
+*
+* Functionality:
+* - processing of Gnb-DU config update
+*
+* @params[in] F1AP_PDU_t *f1apMsg
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+uint8_t procGnbDuUpdate(uint32_t duId, F1AP_PDU_t *f1apMsg)
+{
+ bool cellToBeDelete = false;
+ uint8_t ieIdx = 0, ueIdx = 0;
+ uint16_t cellId;
+ DuDb *duDb;
+ CuCellCb *cellCb;
+ GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
+
+ duCfgUpdate = &f1apMsg->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
+ for(ieIdx=0; ieIdx < duCfgUpdate->protocolIEs.list.count; ieIdx++)
+ {
+ switch(duCfgUpdate->protocolIEs.list.array[ieIdx]->id)
+ {
+ case ProtocolIE_ID_id_TransactionID:
+ break;
+ case ProtocolIE_ID_id_Served_Cells_To_Modify_List:
+ break;
+ case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
+ {
+ struct Served_Cells_To_Delete_ItemIEs *deleteItemIe = \
+ (struct Served_Cells_To_Delete_ItemIEs *)duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
+ Served_Cells_To_Delete_List.list.array[0];
+ cellId = deleteItemIe->value.choice.Served_Cells_To_Delete_Item.oldNRCGI.nRCellIdentity.buf[4] >>\
+ deleteItemIe->value.choice.Served_Cells_To_Delete_Item.oldNRCGI.nRCellIdentity.bits_unused;
+ cellToBeDelete = true;
+ break;
+ }
+ case ProtocolIE_ID_id_gNB_DU_ID:
+ break;
+ }
+ }
+ if(BuildAndSendDUUpdateAck(duId) != ROK)
+ {
+ DU_LOG("ERROR --> F1AP : Failed to build and send DUUpdateAck");
+ return RFAILED;
+ }
+#if 0
+ /* We don't require F1 Reset message in Cell Up and Broadcast Procedure flow, So that's why
+ * commented this trigger for now */
+
+ if(cellToBeDelete == false)
+ {
+ DU_LOG("\nINFO --> F1AP : Sending F1 reset request");
+ if(BuildAndSendF1ResetReq() != ROK)
+ {
+ DU_LOG("ERROR --> F1AP : Failed to build and send F1 reset request");
+ return RFAILED;
+ }
+ }
+#endif
+ if(cellToBeDelete == true)
+ {
+ duDb = getDuDb(duId);
+ cellCb = getCellCb(duDb, cellId);
+ for(ueIdx = 0; ueIdx < cellCb->numUe; ueIdx++)
+ {
+ CU_FREE(cellCb->ueCb[ueIdx]->f1apMsgDb.duToCuContainer.buf, cellCb->ueCb[ueIdx]->f1apMsgDb.duToCuContainer.size);
+ memset(cellCb->ueCb[ueIdx], 0, sizeof(CuUeCb));
+ }
+ }
+
+ return ROK;
+}
+
+/*******************************************************************
+*
+* @brief storing slice list in CU database
+*
+* @details
+*
+* Function : buildSliceList
+*
+* Functionality:
+* - storing slice list in CU database
+*
+* @params[in] SliceSupportList_t *sliceSupportList
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+uint8_t buildSliceList(SliceSupportList_t *sliceSupportList)
+{
+ uint8_t sliceListIdx = 0;
+
+ if(sliceSupportList)
+ {
+ if(sliceSupportList->list.array)
+ {
+ cuCb.numSnssaiSupported = sliceSupportList->list.count;
+ for(sliceListIdx=0; sliceListIdx<sliceSupportList->list.count; sliceListIdx++)
+ {
+ if(sliceSupportList->list.array[sliceListIdx])
+ {
+ CU_ALLOC(cuCb.snssaiList[sliceListIdx], sizeof(Snssai));
+ if(cuCb.snssaiList[sliceListIdx] == NULLP)
+ {
+ DU_LOG("\nERROR --> CU_STUB: buildSliceList(): Memory allocation failed");
+ return RFAILED;
+ }
+ if(sliceSupportList->list.array[sliceListIdx]->sNSSAI.sST.buf)
+ {
+ memcpy(&cuCb.snssaiList[sliceListIdx]->sst, sliceSupportList->list.array[sliceListIdx]->\
+ sNSSAI.sST.buf, sliceSupportList->list.array[sliceListIdx]->sNSSAI.sST.size);
+ }
+ if(sliceSupportList->list.array[sliceListIdx]->sNSSAI.sD->size)
+ {
+ memcpy(&cuCb.snssaiList[sliceListIdx]->sd,\
+ sliceSupportList->list.array[sliceListIdx]->sNSSAI.sD->buf,\
+ sliceSupportList->list.array[sliceListIdx]->sNSSAI.sD->size);
+ }
+ }
+ }
+ }
+ }
+ return ROK;
+}
+
+/****************************************************************
+ * @brief Function to process Drb Setup Mod List
+ *
+ * @details
+ *
+ * Function : procDrbSetupModList
+ *
+ * Functionality:
+ * - Function to process DRB Setup Mod List
+ *
+ * @params[in]
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t procDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
+{
+ uint8_t arrIdx = 0;
+ uint32_t teId = 0;
+ struct DRBs_SetupMod_ItemIEs *drbItemIe = NULLP;
+
+ if(drbSetupList != NULLP)
+ {
+ for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
+ {
+ drbItemIe = ((struct DRBs_SetupMod_ItemIEs *)drbSetupList->list.array[arrIdx]);
+ if(drbItemIe->value.present == DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item)
+ {
+ /* extracting teId */
+ teId = extractTeId(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
+ if(teId > 0)
+ {
+ if(addDrbTunnels(teId)== ROK)
+ {
+ DU_LOG("\nDEBUG --> EGTP: Tunnel Added for TeId %d", teId);
+ }
+ }
+ else
+ return RFAILED;
+ }
+ }
+ }
+ return ROK;
+}
+
+/*******************************************************************
+*
+* @brief processing of GNB_DU_Served_Cells Plmn list information
+*
+* @details
+*
+* Function : procServedCellPlmnList
+*
+* Functionality:
+* - processing of GNB_DU_Served_Cells Plmn list information for storing
+* SNSSAI list
+*
+* @params[in] F1AP_PDU_t *f1apMsg
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+uint8_t procServedCellPlmnList(ServedPLMNs_List_t *srvPlmn)
+{
+ uint8_t srvPlmnIdx=0, ieExtensionsLstIdx=0;
+ ProtocolExtensionContainer_4624P3_t **ieExtend;
+
+ if(srvPlmn->list.array)
+ {
+ for(srvPlmnIdx=0; srvPlmnIdx<srvPlmn->list.count; srvPlmnIdx++)
+ {
+ if(srvPlmn->list.array[srvPlmnIdx])
+ {
+ ieExtend = &srvPlmn->list.array[srvPlmnIdx]->iE_Extensions;
+ if(*ieExtend)
+ {
+ if((*ieExtend)->list.array)
+ {
+ for(ieExtensionsLstIdx = 0; ieExtensionsLstIdx<(*ieExtend)->list.count; ieExtensionsLstIdx++)
+ {
+ if((*ieExtend)->list.array[ieExtensionsLstIdx])
+ {
+ switch((*ieExtend)->list.array[ieExtensionsLstIdx]->id )
+ {
+ case ProtocolIE_ID_id_TAISliceSupportList:
+ {
+ if(buildSliceList(&(*ieExtend)->list.array[ieExtensionsLstIdx]->\
+ extensionValue.choice.SliceSupportList) != ROK)
+ {
+ DU_LOG("\nERROR --> CU_STUB: procServedCellPlmnList(): Failed to build slice List");
+ return RFAILED;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return ROK;
+}
+
+/****************************************************************
+ * @brief Function to process Ue Context Modification Response
+ *
+ * @details
+ *
+ * Function : procUeContextModificationResponse
+ *
+ * Functionality:
+ * - Function to process Ue Context Modification Response
+ *
+ * @params[in]
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t procUeContextModificationResponse(F1AP_PDU_t *f1apMsg)
+{
+ uint8_t idx, duUeF1apId;
+ UEContextModificationResponse_t *ueCtxtModRsp = NULLP;
+ ueCtxtModRsp = &f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
+
+ for(idx=0; idx < ueCtxtModRsp->protocolIEs.list.count; idx++)
+ {
+ switch(ueCtxtModRsp->protocolIEs.list.array[idx]->id)
+ {
+ case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
+ {
+ duUeF1apId = ueCtxtModRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
+ break;
+ }
+ case ProtocolIE_ID_id_DRBs_SetupMod_List:
+ {
+ /* Adding Tunnels for successful DRB */
+ procDrbSetupModList(&ueCtxtModRsp->protocolIEs.list.array[idx]->value.choice.DRBs_SetupMod_List);
+ break;
+
+ }
+ }
+ }