X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fcu_stub%2Fcu_f1ap_msg_hdl.c;h=b574bcbb5eb0330aa5231ffa1af1dd11a88a656c;hb=4d45b914f9e94203603d3b9fdbcb1aad361301dd;hp=4313f699d37040d88f374a3c72d44da6ccfe7aa1;hpb=ef711b0830aedde36f4a1beceed146d08e77ce58;p=o-du%2Fl2.git diff --git a/src/cu_stub/cu_f1ap_msg_hdl.c b/src/cu_stub/cu_f1ap_msg_hdl.c index 4313f699d..b574bcbb5 100644 --- a/src/cu_stub/cu_f1ap_msg_hdl.c +++ b/src/cu_stub/cu_f1ap_msg_hdl.c @@ -17,36 +17,13 @@ *******************************************************************************/ /* This file contains F1AP message handler functions */ - +#include "common_def.h" +#include "OCTET_STRING.h" +#include "BIT_STRING.h" +#include "odu_common_codec.h" #include "cu_stub_sctp.h" #include "cu_f1ap_msg_hdl.h" -char encBuf[ENC_BUF_MAX_LEN]; - -/******************************************************************* - * - * @brief Writes the encoded chunks into a buffer - * - * @details - * - * Function : PrepFinalEncBuf - * - * Functionality:Fills the encoded buffer - * - * @params[in] void *buffer,initial encoded data - * @params[in] size_t size,size of buffer - * @params[in] void *encodedBuf,final buffer - * @return ROK - success - * RFAILED - failure - * - * ****************************************************************/ -static int PrepFinalEncBuf(const void *buffer, size_t size, void *encodedBuf) -{ - memcpy(encodedBuf + encBufSize, buffer, size); - encBufSize += size; - return 0; -} /* PrepFinalEncBuf */ - /******************************************************************* * * @brief Sends F1 msg over SCTP @@ -65,56 +42,38 @@ static int PrepFinalEncBuf(const void *buffer, size_t size, void *encodedBuf) * ****************************************************************/ S16 SendF1APMsg(Region region, Pool pool) { - Buffer *mBuf; + Buffer *mBuf = NULLP; - if(SGetMsg(region, pool, &mBuf) == ROK) + if(ODU_GET_MSG(region, pool, &mBuf) == ROK) { - if(SAddPstMsgMult((Data *)encBuf, encBufSize, mBuf) == ROK) + if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK) { - SPrntMsg(mBuf, 0,0); + ODU_PRINT_MSG(mBuf, 0,0); if(sctpSend(mBuf) != ROK) { DU_LOG("\nF1AP : SCTP Send failed"); - SPutMsg(mBuf); - RETVALUE(RFAILED); + ODU_PUT_MSG(mBuf); + return RFAILED; } } else { - DU_LOG("\nF1AP : SAddPstMsgMult failed"); - SPutMsg(mBuf); - RETVALUE(RFAILED); + DU_LOG("\nF1AP : ODU_ADD_POST_MSG_MULT failed"); + ODU_PUT_MSG(mBuf); + return RFAILED; } - SPutMsg(mBuf); + ODU_PUT_MSG(mBuf); } else { DU_LOG("\nF1AP : Failed to allocate memory"); - RETVALUE(RFAILED); + return RFAILED; } - RETVALUE(ROK); + return ROK; } /* SendF1APMsg */ - -void plmnBuildCU(Plmn plmn, OCTET_STRING_t *octe) -{ - U8 mncCnt; - mncCnt = 2; - octe->buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0])); - if(mncCnt == 2) - { - octe->buf[1] = ((0xf0) | (plmn.mcc[2])); - octe->buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0])); - } - else - { - octe->buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2])); - octe->buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1])); - } -} - /******************************************************************* * * @brief Builds NRCell ID @@ -141,7 +100,7 @@ S16 BuildNrCellId(BIT_STRING_t *nrcell) nrcell->buf[4] = 16; nrcell->bits_unused = 4; nrcell->size = 5 * sizeof(uint8_t); - RETVALUE(ROK); + return ROK; } /******************************************************************** @@ -179,7 +138,7 @@ S16 BuildAndSendF1SetupRsp() if(f1apMsg == NULLP) { DU_LOG("\nF1AP : Memory allocation for F1AP-PDU failed"); - RETVALUE(RFAILED); + return RFAILED; } f1apMsg->present = F1AP_PDU_PR_successfulOutcome; @@ -188,7 +147,7 @@ S16 BuildAndSendF1SetupRsp() { DU_LOG("\nF1AP : Memory allocation for F1AP-PDU failed"); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_F1Setup; @@ -208,7 +167,7 @@ S16 BuildAndSendF1SetupRsp() DU_LOG("\nF1AP : Memory allocation for F1ResponseIEs failed"); CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } for(idx=0; idxchoice.successfulOutcome, \ sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } } @@ -257,7 +216,7 @@ S16 BuildAndSendF1SetupRsp() CU_FREE(f1apMsg->choice.successfulOutcome,\ sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } strcpy((char*)cuName->buf, (char*)cuCfgParams.cuName); @@ -288,7 +247,7 @@ S16 BuildAndSendF1SetupRsp() elementCnt * sizeof(F1SetupResponseIEs_t *)); CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } for(idy=0; idychoice.successfulOutcome, \ sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } } cellToActivate->list.array[0]->id = \ @@ -345,9 +304,9 @@ S16 BuildAndSendF1SetupRsp() CU_FREE(f1apMsg->choice.successfulOutcome, \ sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } - plmnBuildCU(cuCfgParams.plmn , &cellToActivate->list.array[0]->value.choice.\ + buildPlmnId(cuCfgParams.plmn , &cellToActivate->list.array[0]->value.choice.\ Cells_to_be_Activated_List_Item.nRCGI.pLMN_Identity); cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\ nRCGI.nRCellIdentity.size = 5; @@ -379,7 +338,7 @@ S16 BuildAndSendF1SetupRsp() CU_FREE(f1apMsg->choice.successfulOutcome, \ sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } BuildNrCellId(&(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity)); /* RRC Version */ @@ -405,7 +364,7 @@ S16 BuildAndSendF1SetupRsp() elementCnt * sizeof(F1SetupResponseIEs_t *)); CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } /* Need to check RRC Version */ @@ -425,7 +384,7 @@ S16 BuildAndSendF1SetupRsp() elementCnt * sizeof(F1SetupResponseIEs_t *)); CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } rrcVer->iE_Extensions->list.count = 1; rrcVer->iE_Extensions->list.size = sizeof(struct RRC_Version_ExtIEs *); @@ -446,7 +405,7 @@ S16 BuildAndSendF1SetupRsp() elementCnt * sizeof(F1SetupResponseIEs_t *)); CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } CU_ALLOC(rrcVer->iE_Extensions->list.array[0],\ sizeof(struct RRC_Version_ExtIEs)); @@ -467,7 +426,7 @@ S16 BuildAndSendF1SetupRsp() elementCnt * sizeof(F1SetupResponseIEs_t *)); CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } rrcVer->iE_Extensions->list.array[0]->id = \ ProtocolIE_ID_id_latest_RRC_Version_Enhanced; @@ -499,7 +458,7 @@ S16 BuildAndSendF1SetupRsp() elementCnt * sizeof(F1SetupResponseIEs_t *)); CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.\ Latest_RRC_Version_Enhanced.buf[0] = 0; @@ -531,7 +490,7 @@ S16 BuildAndSendF1SetupRsp() { DU_LOG("\nF1AP : Could not encode F1SetupResponse structure (at %s)\n",\ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown"); - RETVALUE(RFAILED); + return RFAILED; } else { @@ -546,10 +505,10 @@ S16 BuildAndSendF1SetupRsp() if(SendF1APMsg(CU_APP_MEM_REG, CU_POOL) != ROK) { DU_LOG("\nF1AP : Sending F1 Setup Response failed"); - RETVALUE(RFAILED); + return RFAILED; } - RETVALUE(ROK); + return ROK; }/* End of BuildAndSendF1SetupRsp */ /******************************************************************* @@ -586,7 +545,7 @@ S16 BuildAndSendDUUpdateAck() if(f1apMsg == NULLP) { DU_LOG("\nF1AP : Memory allocation for F1AP-PDU failed"); - RETVALUE(RFAILED); + return RFAILED; } f1apMsg->present = F1AP_PDU_PR_successfulOutcome; @@ -596,7 +555,7 @@ S16 BuildAndSendDUUpdateAck() { DU_LOG("\nF1AP : Memory allocation for F1AP-PDU failed"); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_gNBDUConfigurationUpdate; @@ -615,7 +574,7 @@ S16 BuildAndSendDUUpdateAck() DU_LOG("\nF1AP : Memory allocation for DuUpdateAcknowledgeIEs failed"); CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg,(Size)sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } for(idx=0; idxprotocolIEs.list.array, elementCnt * sizeof(GNBDUConfigurationUpdateAcknowledgeIEs_t *)); CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } } @@ -657,7 +616,7 @@ S16 BuildAndSendDUUpdateAck() if(enRetVal.encoded == ENCODE_FAIL) { DU_LOG("\nF1AP : Could not encode DUConfigUpdateAcknowledge structure (at %s)",enRetVal.failed_type ? enRetVal.failed_type->name : "unknown"); - RETVALUE(RFAILED); + return RFAILED; } else { @@ -672,165 +631,409 @@ S16 BuildAndSendDUUpdateAck() if(SendF1APMsg(CU_APP_MEM_REG, CU_POOL) != ROK) { DU_LOG("\nF1AP : Sending GNB-DU Config Update Ack failed"); - RETVALUE(RFAILED); + return RFAILED; } - RETVALUE(ROK); + return ROK; }/* End of BuildAndSendDUUpdateAck*/ /******************************************************************* * - * @brief Builds and sends the DLRRCMessageTransfer + * @brief Fills Radio Bearer Config * * @details * - * Function : BuildAndSendDLRRCMessageTransfer + * Function : fillRadioBearerConfig * - * Functionality: Constructs the DL RRC Message Transfer and sends - * it to the CU through SCTP. + * Functionality: Fills Radio Bearer Config * - * @params[in] + * @params[in] SRB_ToAddModList * * * @return ROK - success * RFAILED - failure * * ****************************************************************/ -S16 BuildAndSendDLRRCMessageTransfer() +uint8_t fillRadioBearerConfig(SRB_ToAddModList_t *bearerCfg) { - S16 ret; - U8 elementCnt; - U8 ieId; - U8 idx; - F1AP_PDU_t *f1apMsg = NULL; - DLRRCMessageTransfer_t *dlRRCMsg; - asn_enc_rval_t encRetVal; /* Encoder return value */ + uint8_t elementCnt; + uint8_t idx; + uint8_t ied; + if(bearerCfg != NULLP) + { + elementCnt = 1; + bearerCfg->list.count = elementCnt; + bearerCfg->list.size =\ + elementCnt * sizeof(SRB_ToAddMod_t *); + CU_ALLOC(bearerCfg->list.array, bearerCfg->list.size); + if(bearerCfg->list.array != NULLP) + { + for(idx = 0; idx < elementCnt; idx++) + { + CU_ALLOC(bearerCfg->list.array[idx], sizeof(SRB_ToAddMod_t)); + if(bearerCfg->list.array[idx] == NULLP) + { + for(ied = 0; ied < idx; ied++) + { + CU_FREE(bearerCfg->list.array[idx], sizeof(SRB_ToAddMod_t)); + } + CU_FREE(bearerCfg->list.array, bearerCfg->list.size); + return RFAILED; + } + } + } + else + { + return RFAILED; + } + idx = 0; + bearerCfg->list.array[idx]->srb_Identity = SRB1; + } + return ROK; +} - DU_LOG("\n F1AP : Building DL RRC Message Transfer Message\n"); +/******************************************************************* + * + * @brief Fills Master CellGroup Info + * + * @details + * + * Function : fillMasterCellGroup + * + * Functionality: Fills Master Cell Group IE + * + * @params[in] RRCSetup_IEs_t * + * + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ - CU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t)); - if(f1apMsg == NULLP) +uint8_t fillMasterCellGroup(OCTET_STRING_t *masterCellGroup) +{ + uint8_t ret = ROK; + masterCellGroup->buf = NULLP; + if(f1apMsgDb.duToCuContainer.buf) { - DU_LOG(" F1AP : Memory allocation for F1AP-PDU failed"); - RETVALUE(RFAILED); + masterCellGroup->size = f1apMsgDb.duToCuContainer.size; + CU_ALLOC(masterCellGroup->buf, masterCellGroup->size); + if(masterCellGroup->buf != NULLP) + { + memcpy(masterCellGroup->buf, f1apMsgDb.duToCuContainer.buf,\ + masterCellGroup->size); + } + else + { + ret = RFAILED; + } } - - f1apMsg->present = F1AP_PDU_PR_initiatingMessage; - CU_ALLOC(f1apMsg->choice.initiatingMessage, - sizeof(InitiatingMessage_t)); - if(f1apMsg->choice.initiatingMessage == NULLP) + else { - DU_LOG(" F1AP : Memory allocation for F1AP-PDU failed"); - CU_FREE(f1apMsg,sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); - } + ret = RFAILED; + } + return ret; +} - f1apMsg->choice.initiatingMessage->procedureCode = \ - ProcedureCode_id_DLRRCMessageTransfer; - f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore; - f1apMsg->choice.initiatingMessage->value.present = \ - InitiatingMessage__value_PR_DLRRCMessageTransfer; - dlRRCMsg = - &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer; - elementCnt = 3; - dlRRCMsg->protocolIEs.list.count = elementCnt; - dlRRCMsg->protocolIEs.list.size = \ - elementCnt * sizeof(DLRRCMessageTransferIEs_t *); - - /* Initialize the F1Setup members */ - CU_ALLOC(dlRRCMsg->protocolIEs.list.array, \ - elementCnt * sizeof(DLRRCMessageTransferIEs_t *)); - if(dlRRCMsg->protocolIEs.list.array == NULLP) - { - DU_LOG(" F1AP : Memory allocation for DL RRC MessageTransferIEs failed"); - CU_FREE(f1apMsg->choice.initiatingMessage, - sizeof(InitiatingMessage_t)); - CU_FREE(f1apMsg,(Size)sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); - } +/******************************************************************* + * + * @brief Fills RRC setup IE + * + * @details + * + * Function : fillRRCSetupIE + * + * Functionality: Fills RRC Setup IE + * + * @params[in] RRCSetup_IEs_t * + * + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ - for(idx=0; idxprotocolIEs.list.array[idx],\ - sizeof(DLRRCMessageTransferIEs_t)); - if(dlRRCMsg->protocolIEs.list.array[idx] == NULLP) +uint8_t fillRRCSetupIE(RRCSetup_IEs_t *rrcSetupIE) +{ + uint8_t ret = ROK; + if(rrcSetupIE) + { + CU_ALLOC(rrcSetupIE->radioBearerConfig.srb_ToAddModList, sizeof(SRB_ToAddModList_t)); + if(rrcSetupIE->radioBearerConfig.srb_ToAddModList != NULLP) { - for(ieId=0; ieIdradioBearerConfig.srb_ToAddModList); + } + if(!ret) + { + ret = fillMasterCellGroup(&rrcSetupIE->masterCellGroup); + } + else + { + CU_FREE(rrcSetupIE->radioBearerConfig.srb_ToAddModList, sizeof(SRB_ToAddModList_t)); + ret = RFAILED; + } + } + return ret; +} +/******************************************************************* + * + * @brief Builds RRC Container IE required for DLRRCMessageTransfer + * + * @details + * + * Function : BuildDLRRCContainer + * + * Functionality: Builds RRC Container IE required for + * DLRRCMessageTransfer + * + * @params[in] + * + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ + +uint8_t BuildDLRRCContainer(RRCContainer_t *rrcContainer) +{ + uint8_t ret = ROK; + uint16_t idx2; + DL_CCCH_Message_t dl_CCCH_Msg; + asn_enc_rval_t encRetVal; + + if(rrcContainer != NULLP) + { + dl_CCCH_Msg.message.present = DL_CCCH_MessageType_PR_c1; + + CU_ALLOC(dl_CCCH_Msg.message.choice.c1 , sizeof(DL_CCCH_MessageType_t)); + if(dl_CCCH_Msg.message.choice.c1 != NULLP) + { + dl_CCCH_Msg.message.choice.c1->present = DL_CCCH_MessageType__c1_PR_rrcSetup; + CU_ALLOC(dl_CCCH_Msg.message.choice.c1->choice.rrcSetup, sizeof(RRCSetup_t)); + if(dl_CCCH_Msg.message.choice.c1->choice.rrcSetup != NULLP) + { + dl_CCCH_Msg.message.choice.c1->choice.rrcSetup->rrc_TransactionIdentifier = 0; + dl_CCCH_Msg.message.choice.c1->choice.rrcSetup->criticalExtensions.\ + present = RRCSetup__criticalExtensions_PR_rrcSetup; + /* Fill RRC Setup IE */ + CU_ALLOC(dl_CCCH_Msg.message.choice.c1->choice.rrcSetup->\ + criticalExtensions.choice.rrcSetup, sizeof(RRCSetup_IEs_t)); + if(dl_CCCH_Msg.message.choice.c1->choice.rrcSetup->\ + criticalExtensions.choice.rrcSetup != NULLP) + { + ret = fillRRCSetupIE(dl_CCCH_Msg.message.choice.c1->choice.rrcSetup->\ + criticalExtensions.choice.rrcSetup); + + if(!ret) + { + /* encode DL-CCCH message into RRC Container */ + xer_fprint(stdout, &asn_DEF_DL_CCCH_MessageType, &dl_CCCH_Msg); + cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN); + encBufSize = 0; + encRetVal = aper_encode(&asn_DEF_DL_CCCH_MessageType, 0, &dl_CCCH_Msg, PrepFinalEncBuf, encBuf); + /* Encode results */ + if(encRetVal.encoded == ENCODE_FAIL) + { + DU_LOG( "\n F1AP : Could not encode RRCContainer (at %s)\n",\ + encRetVal.failed_type ? encRetVal.failed_type->name : "unknown"); + return RFAILED; + } + else + { + DU_LOG("\n F1AP : Created APER encoded buffer for RRCContainer\n"); + for(int i = 0; i< encBufSize; i++) + { + printf("%x",encBuf[i]); + } + rrcContainer->size = encBufSize; + CU_ALLOC(rrcContainer->buf, rrcContainer->size); + if(rrcContainer->buf != NULLP) + { + memset(rrcContainer->buf, 0, encBufSize); + for(idx2 = 0; idx2 < encBufSize; idx2++) + { + rrcContainer->buf[idx2] = encBuf[idx2]; + } + } + } + } + else + { + ret = RFAILED; + } + } + else + { + DU_LOG("\nF1AP: Memory Alloc failed for RRC Setup Msg"); + ret = RFAILED; + } + } + else { - CU_FREE(dlRRCMsg->protocolIEs.list.array[ieId],\ - sizeof(DLRRCMessageTransferIEs_t)); + DU_LOG("\nF1AP: Memory Alloc failed for RRC Msg"); + ret = RFAILED; } - CU_FREE(dlRRCMsg->protocolIEs.list.array,\ - elementCnt * sizeof(DLRRCMessageTransferIEs_t *)); - CU_FREE(f1apMsg->choice.initiatingMessage,\ - sizeof(InitiatingMessage_t)); - CU_FREE(f1apMsg,sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + } + else + { + DU_LOG("\nF1AP: Memory Alloc failed for DL Ccch Msg choice"); + ret = RFAILED; } + } + else + { + DU_LOG("\nF1AP: Memory Alloc failed for DlCcch Msg"); + ret = RFAILED; } + return ret; +} - idx = 0; - - /*GNB CU UE F1AP ID*/ - dlRRCMsg->protocolIEs.list.array[idx]->id = \ - ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; - dlRRCMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject; - dlRRCMsg->protocolIEs.list.array[idx]->value.present = \ - DLRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID; - dlRRCMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = CU_ID; - - /*GNB DU UE F1AP ID*/ - idx++; - dlRRCMsg->protocolIEs.list.array[idx]->id = \ - ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID; - dlRRCMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject; - dlRRCMsg->protocolIEs.list.array[idx]->value.present = \ - DLRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID; - dlRRCMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = DU_ID; +/******************************************************************* + * + * @brief Builds and sends the DLRRCMessageTransfer + * + * @details + * + * Function : BuildAndSendDLRRCMessageTransfer + * + * Functionality: Constructs the DL RRC Message Transfer and sends + * it to the CU through SCTP. + * + * @params[in] + * + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ +S16 BuildAndSendDLRRCMessageTransfer() +{ + uint8_t ret = ROK ; + uint8_t elementCnt = 0; + uint8_t ieId; + uint8_t idx; + uint16_t idx2; + F1AP_PDU_t *f1apMsg = NULLP; + DLRRCMessageTransfer_t *dlRRCMsg = NULLP; + asn_enc_rval_t encRetVal; /* Encoder return value */ + + DU_LOG("\n F1AP : Building DL RRC Message Transfer Message\n"); + + CU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t)); + if(f1apMsg == NULLP) + { + DU_LOG(" F1AP : Memory allocation for F1AP-PDU failed"); + return RFAILED; + } - /*SRBID*/ - idx++; - dlRRCMsg->protocolIEs.list.array[idx]->id = \ - ProtocolIE_ID_id_SRBID; - dlRRCMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject; - dlRRCMsg->protocolIEs.list.array[idx]->value.present = \ - DLRRCMessageTransferIEs__value_PR_SRBID; - dlRRCMsg->protocolIEs.list.array[idx]->value.choice.SRBID = DL_SRBID; + f1apMsg->present = F1AP_PDU_PR_initiatingMessage; + CU_ALLOC(f1apMsg->choice.initiatingMessage, + sizeof(InitiatingMessage_t)); + if(f1apMsg->choice.initiatingMessage == NULLP) + { + DU_LOG(" F1AP : Memory allocation for F1AP-PDU failed"); + CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); + return RFAILED; + } - /*RRCContainer*/ - //YET TO FILL + f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_DLRRCMessageTransfer; + f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore; + f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_DLRRCMessageTransfer; + dlRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer; - xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg); + elementCnt = 4; + dlRRCMsg->protocolIEs.list.count = elementCnt; + dlRRCMsg->protocolIEs.list.size = elementCnt * sizeof(DLRRCMessageTransferIEs_t *); - /* Encode the F1SetupRequest type as APER */ - cmMemset((U8 *)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( "\n F1AP : Could not encode DL RRC Message Transfer structure (at %s)\n",\ - encRetVal.failed_type ? encRetVal.failed_type->name : "unknown"); - RETVALUE(RFAILED); - } - else - { - DU_LOG("\n F1AP : Created APER encoded buffer for DL RRC Message transfer\n"); - for(int i=0; i< encBufSize; i++) - { - printf("%x",encBuf[i]); - } - } + /* Initialize the F1Setup members */ + CU_ALLOC(dlRRCMsg->protocolIEs.list.array, dlRRCMsg->protocolIEs.list.size); + if(dlRRCMsg->protocolIEs.list.array == NULLP) + { + DU_LOG(" F1AP : Memory allocation for DL RRC MessageTransferIEs failed"); + CU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t)); + CU_FREE(f1apMsg, sizeof(F1AP_PDU_t)); + return RFAILED; + } - /* Sending msg */ - if(SendF1APMsg(CU_APP_MEM_REG,CU_POOL) != ROK) - { - DU_LOG("\n F1AP : Sending DL RRC Message Transfer Failed"); - RETVALUE(RFAILED); - } + for(idx=0; idxprotocolIEs.list.array[idx], sizeof(DLRRCMessageTransferIEs_t)); + if(dlRRCMsg->protocolIEs.list.array[idx] == NULLP) + { + for(ieId=0; ieIdprotocolIEs.list.array[ieId],\ + sizeof(DLRRCMessageTransferIEs_t)); + } + CU_FREE(dlRRCMsg->protocolIEs.list.array,\ + dlRRCMsg->protocolIEs.list.size); + CU_FREE(f1apMsg->choice.initiatingMessage,\ + sizeof(InitiatingMessage_t)); + CU_FREE(f1apMsg,sizeof(F1AP_PDU_t)); + return RFAILED; + } + } - RETVALUE(ROK); + /* GNB CU UE F1AP ID */ + idx = 0; + dlRRCMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; + dlRRCMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject; + dlRRCMsg->protocolIEs.list.array[idx]->value.present = \ + DLRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID; + dlRRCMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = CU_ID; + + /* GNB DU UE F1AP ID */ + idx++; + dlRRCMsg->protocolIEs.list.array[idx]->id = \ + ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID; + dlRRCMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject; + dlRRCMsg->protocolIEs.list.array[idx]->value.present = \ + DLRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID; + dlRRCMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = DU_ID; + + /* SRBID */ + idx++; + dlRRCMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_SRBID; + dlRRCMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject; + dlRRCMsg->protocolIEs.list.array[idx]->value.present = \ + DLRRCMessageTransferIEs__value_PR_SRBID; + dlRRCMsg->protocolIEs.list.array[idx]->value.choice.SRBID = SRB1; + + /* RRCContainer */ + idx++; + dlRRCMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_RRCContainer; + dlRRCMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject; + dlRRCMsg->protocolIEs.list.array[idx]->value.present = \ + DLRRCMessageTransferIEs__value_PR_RRCContainer; + BuildDLRRCContainer(&dlRRCMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer); + + xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg); + + /* Encode the F1SetupRequest type as APER */ + cmMemset((U8 *)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( "\n F1AP : Could not encode DL RRC Message Transfer structure (at %s)\n",\ + encRetVal.failed_type ? encRetVal.failed_type->name : "unknown"); + return RFAILED; + } + else + { + DU_LOG("\n F1AP : Created APER encoded buffer for DL RRC Message transfer\n"); + for(int i=0; i< encBufSize; i++) + { + printf("%x",encBuf[i]); + } + } + + /* Sending msg */ + if(SendF1APMsg(CU_APP_MEM_REG,CU_POOL) != ROK) + { + DU_LOG("\n F1AP : Sending DL RRC Message Transfer Failed"); + return RFAILED; + } + + return ROK; }/* End of BuildAndSendDLRRCMessageTransfer */ @@ -870,7 +1073,7 @@ S16 BuildAndSendUESetRsp() if(f1apMsg == NULLP) { DU_LOG(" F1AP : Memory allocation for F1AP-PDU failed"); - RETVALUE(RFAILED); + return RFAILED; } f1apMsg->present = F1AP_PDU_PR_successfulOutcome; @@ -880,7 +1083,7 @@ S16 BuildAndSendUESetRsp() { DU_LOG(" F1AP : Memory allocation for F1AP-PDU failed"); CU_FREE(f1apMsg,sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } f1apMsg->choice.successfulOutcome->procedureCode = \ @@ -904,7 +1107,7 @@ S16 BuildAndSendUESetRsp() CU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg,(Size)sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } for(idx=0; idxchoice.successfulOutcome,\ sizeof(SuccessfulOutcome_t)); CU_FREE(f1apMsg,sizeof(F1AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } } @@ -959,7 +1162,7 @@ S16 BuildAndSendUESetRsp() { DU_LOG( "\n F1AP : Could not encode UE Context Setup Request structure (at %s)\n",\ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown"); - RETVALUE(RFAILED); + return RFAILED; } else { @@ -974,11 +1177,68 @@ S16 BuildAndSendUESetRsp() if(SendF1APMsg(CU_APP_MEM_REG,CU_POOL) != ROK) { DU_LOG("\n F1AP : Sending UE Context Setup Request Failed"); - RETVALUE(RFAILED); + return RFAILED; } - RETVALUE(ROK); + return ROK; }/* End of BuildAndSendUESetRsp */ + + +uint8_t procInitULRRCMsg(F1AP_PDU_t *f1apMsg) +{ + uint8_t idx; + uint8_t ret =ROK; + InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP; + DU_LOG("\n filling the required values in DB in procInitULRRCMsg"); + + initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer; + + for(idx=0; idx < initULRRCMsg->protocolIEs.list.count; idx++) + { + switch(initULRRCMsg->protocolIEs.list.array[idx]->id) + { + case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID: + break; + case ProtocolIE_ID_id_NRCGI: + break; + case ProtocolIE_ID_id_C_RNTI: + break; + case ProtocolIE_ID_id_RRCContainer: + break; + case ProtocolIE_ID_id_DUtoCURRCContainer: + { + if((initULRRCMsg->protocolIEs.list.array[idx]->value.choice\ + .DUtoCURRCContainer.size > 0) && (initULRRCMsg->protocolIEs\ + .list.array[idx]->value.choice.DUtoCURRCContainer.buf != NULLP)) + { + DU_LOG("\n Received Du to Cu RRC Container "); + f1apMsgDb.duToCuContainer.size = initULRRCMsg->protocolIEs\ + .list.array[idx]->value.choice.DUtoCURRCContainer.size; + CU_ALLOC(f1apMsgDb.duToCuContainer.buf, \ + f1apMsgDb.duToCuContainer.size); + if(f1apMsgDb.duToCuContainer.buf != NULLP) + { + memcpy(f1apMsgDb.duToCuContainer.buf, initULRRCMsg->protocolIEs\ + .list.array[idx]->value.choice.DUtoCURRCContainer.buf, f1apMsgDb\ + .duToCuContainer.size); + } + } + else + { + DU_LOG("\n Failed to receive Du to Cu RRC Container "); + ret = RFAILED; + } + break; + } + default: + DU_LOG("\n Invalid Event %ld", initULRRCMsg->protocolIEs.list.array[idx]->id); + break; + } + } + if(!ret) + ret = BuildAndSendDLRRCMessageTransfer(); + return ret; +} /******************************************************************* * * @brief Handles received F1AP message and sends back response @@ -1002,21 +1262,23 @@ void F1APMsgHdlr(Buffer *mBuf) char *recvBuf; MsgLen copyCnt; MsgLen recvBufLen; - F1AP_PDU_t *f1apMsg; + F1AP_PDU_t *f1apMsg = NULLP; asn_dec_rval_t rval; /* Decoder return value */ F1AP_PDU_t f1apasnmsg ; DU_LOG("\nF1AP : Received F1AP message buffer"); - SPrntMsg(mBuf, 0,0); + ODU_PRINT_MSG(mBuf, 0,0); /* Copy mBuf into char array to decode it */ - SFndLenMsg(mBuf, &recvBufLen); - if(SGetSBuf(DFLT_REGION, DFLT_POOL, (Data **)&recvBuf, (Size)recvBufLen) != ROK) + ODU_FIND_MSG_LEN(mBuf, &recvBufLen); + CU_ALLOC(recvBuf, (Size)recvBufLen); + + if(recvBuf == NULLP) { DU_LOG("\nF1AP : Memory allocation failed"); return; } - if(SCpyMsgFix(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK) + if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK) { DU_LOG("\nF1AP : Failed while copying %d", copyCnt); return; @@ -1033,7 +1295,8 @@ void F1APMsgHdlr(Buffer *mBuf) memset(f1apMsg, 0, sizeof(F1AP_PDU_t)); rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0); - SPutSBuf(DFLT_REGION, DFLT_POOL, (Data *)recvBuf, (Size)recvBufLen); + CU_FREE(recvBuf, (Size)recvBufLen); + if(rval.code == RC_FAIL || rval.code == RC_WMORE) { DU_LOG("\nF1AP : ASN decode failed"); @@ -1052,7 +1315,7 @@ void F1APMsgHdlr(Buffer *mBuf) { DU_LOG("\nF1AP : F1 setup request received"); BuildAndSendF1SetupRsp(); - break; + break; } case InitiatingMessage__value_PR_GNBDUConfigurationUpdate: @@ -1061,7 +1324,12 @@ void F1APMsgHdlr(Buffer *mBuf) BuildAndSendDUUpdateAck(); break; } - + case InitiatingMessage__value_PR_InitialULRRCMessageTransfer: + { + DU_LOG("\nF1AP : Received InitialULRRCMessageTransfer"); + procInitULRRCMsg(f1apMsg); + break; + } default: { DU_LOG("\nF1AP : Invalid type of intiating message [%d]",f1apMsg->choice.initiatingMessage->value.present);