X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fric_stub%2Fric_e2ap_msg_hdl.c;h=ec6e0db76ded53b0cb1927dbf9c9424ece79609f;hb=904a5d446b480d71da1bf81f892bab86ab365ce6;hp=565d17f478e39d6737ed8345a6fd2ff06a81d79b;hpb=8660dd47a5ef27b62300fabf6b027852f1d5d026;p=o-du%2Fl2.git diff --git a/src/ric_stub/ric_e2ap_msg_hdl.c b/src/ric_stub/ric_e2ap_msg_hdl.c index 565d17f47..ec6e0db76 100644 --- a/src/ric_stub/ric_e2ap_msg_hdl.c +++ b/src/ric_stub/ric_e2ap_msg_hdl.c @@ -17,38 +17,27 @@ *******************************************************************************/ /* This file contains E2AP message handler functions */ - +#include "common_def.h" +#include "OCTET_STRING.h" +#include "BIT_STRING.h" +#include "odu_common_codec.h" #include "ric_stub_sctp.h" +#include "ric_stub.h" #include "ric_e2ap_msg_hdl.h" #include "GlobalE2node-gNB-ID.h" +#include "ProtocolIE-FieldE2.h" +#include "InitiatingMessageE2.h" +#include "SuccessfulOutcomeE2.h" +#include "UnsuccessfulOutcomeE2.h" +#include "E2AP-PDU.h" +#include "du_log.h" +#include "E2nodeComponentInterfaceF1.h" +#include "E2SM-KPM-RANfunction-Description.h" +#include "RANfunction-Name.h" +#include "RIC-EventTriggerStyle-Item.h" +#include "RIC-ReportStyle-Item.h" +#include "MeasurementInfo-Action-Item.h" -char encBuf[ENC_BUF_MAX_LEN]; -Bool ricSubsStatus; -S16 SendE2APMsg(Region , Pool ); - -/******************************************************************* - * - * @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 */ /******************************************************************* * @@ -67,181 +56,280 @@ static int PrepFinalEncBuf(const void *buffer, size_t size, void *encodedBuf) * * ****************************************************************/ -S16 SendE2APMsg(Region region, Pool pool) +uint8_t SendE2APMsg(Region region, Pool pool, uint32_t duId) { Buffer *mBuf; - if(SGetMsg(region, pool, &mBuf) == ROK) + if(ODU_GET_MSG_BUF(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) + if(sctpSend(duId, mBuf) != ROK) { - DU_LOG("\nF1AP : SCTP Send for E2 failed"); - SPutMsg(mBuf); - RETVALUE(RFAILED); + DU_LOG("\nERROR --> E2AP : SCTP Send for E2 failed"); + ODU_PUT_MSG_BUF(mBuf); + return RFAILED; } } else { - DU_LOG("\nF1AP : SAddPstMsgMult failed"); - SPutMsg(mBuf); - RETVALUE(RFAILED); + DU_LOG("\nERROR --> E2AP : ODU_ADD_POST_MSG_MULT failed"); + ODU_PUT_MSG_BUF(mBuf); + return RFAILED; } - SPutMsg(mBuf); + ODU_PUT_MSG_BUF(mBuf); } else { - DU_LOG("\nF1AP : Failed to allocate memory"); - RETVALUE(RFAILED); + DU_LOG("\nERROR --> E2AP : Failed to allocate memory"); + return RFAILED; } - RETVALUE(ROK); + return ROK; } /* SendE2APMsg */ /******************************************************************* * - * @brief Builds PLMN ID + * @brief Builds Global RIC Id Params * * @details * - * Function : plmnBuildRic + * Function : BuildGlobalRicId * - * Functionality: Building the PLMN ID + * Functionality: Building the Plmn and ric id * - * @params[in] PLMNID plmn - * OCTET_STRING_t *octe + * @params[in] GlobalRIC_ID_t *ricId * @return ROK - success * RFAILED - failure * * ****************************************************************/ -void plmnBuildRic(Plmn plmn, OCTET_STRING_t *octe) +uint8_t BuildGlobalRicId(GlobalRIC_ID_t *ricId) { - U8 mncCnt; - octe->size = 3; - RIC_ALLOC(octe->buf, octe->size * sizeof(U8)); - if(octe->buf == NULLP) - { - RETVALUE(RFAILED); - } - mncCnt = 2; - octe->buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0])); - if(mncCnt == 2) + uint8_t unused = 4; + uint8_t byteSize = 3; + uint8_t ricVal= 1; + if(ricId != NULLP) { - octe->buf[1] = ((0xf0) | (plmn.mcc[2])); - octe->buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0])); + ricId->pLMN_Identity.size = byteSize * sizeof(uint8_t); + RIC_ALLOC(ricId->pLMN_Identity.buf, ricId->pLMN_Identity.size); + buildPlmnId(ricCb.ricCfgParams.plmn , ricId->pLMN_Identity.buf); + /* fill ric Id */ + ricId->ric_ID.size = byteSize * sizeof(uint8_t); + RIC_ALLOC(ricId->ric_ID.buf, ricId->ric_ID.size); + fillBitString(&ricId->ric_ID, unused, byteSize, ricVal); } - else + return ROK; +} + +/******************************************************************* + * + * @brief deallocate the memory allocated in E2SetupResponse + * + * @details + * + * Function : FreeE2SetupRsp + * + * Functionality: deallocate the memory allocated in E2SetupResponse + * + * @params[in] E2AP_PDU_t *e2apMsg + * + * @return void + * ****************************************************************/ +void FreeE2SetupRsp(E2AP_PDU_t *e2apMsg) +{ + uint8_t arrIdx = 0, e2NodeConfigIdx=0, ranFuncIdx=0; + RANfunctionsID_List_t *ranFuncAddedList; + E2setupResponse_t *e2SetupRsp; + E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItemIe; + E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAdditionAckList; + E2nodeComponentInterfaceF1_t *f1InterfaceInfo; + + if(e2apMsg) { - octe->buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2])); - octe->buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1])); + if(e2apMsg->choice.successfulOutcome) + { + e2SetupRsp = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse; + if(e2SetupRsp->protocolIEs.list.array) + { + for(arrIdx=0; arrIdxprotocolIEs.list.count; arrIdx++) + { + switch(e2SetupRsp->protocolIEs.list.array[arrIdx]->id) + { + case ProtocolIE_IDE2_id_RANfunctionsAccepted: + { + ranFuncAddedList= &e2SetupRsp->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List; + if(ranFuncAddedList->list.array) + { + for(ranFuncIdx=0;ranFuncIdxlist.count; ranFuncIdx++) + { + if(ranFuncAddedList->list.array[arrIdx]) + { + RIC_FREE(ranFuncAddedList->list.array[arrIdx], sizeof(RANfunction_ItemIEs_t)); + } + } + RIC_FREE(ranFuncAddedList->list.array, ranFuncAddedList->list.size); + } + break; + } + case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck: + { + e2NodeConfigAdditionAckList =&e2SetupRsp->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List; + if(e2NodeConfigAdditionAckList->list.count) + { + for(e2NodeConfigIdx=0; e2NodeConfigIdxlist.count; e2NodeConfigIdx++) + { + e2NodeAddAckItemIe = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAdditionAckList->list.array[e2NodeConfigIdx]; + if(e2NodeAddAckItemIe) + { + f1InterfaceInfo = e2NodeAddAckItemIe->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1; + if(f1InterfaceInfo) + { + RIC_FREE(f1InterfaceInfo->gNB_DU_ID.buf, f1InterfaceInfo->gNB_DU_ID.size); + RIC_FREE(f1InterfaceInfo, sizeof(E2nodeComponentInterfaceF1_t)); + } + RIC_FREE(e2NodeAddAckItemIe, sizeof(E2nodeComponentConfigAdditionAck_ItemIEs_t)); + } + } + RIC_FREE(e2NodeConfigAdditionAckList->list.array, e2NodeConfigAdditionAckList->list.size); + } + break; + } + } + RIC_FREE(e2SetupRsp->protocolIEs.list.array[arrIdx], sizeof(E2setupResponseIEs_t)); + } + RIC_FREE(e2SetupRsp->protocolIEs.list.array, e2SetupRsp->protocolIEs.list.size); + } + RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t)); + } + RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t)); } } /******************************************************************* * - * @brief Fills the RicId + * @brief Build E2node Component config addition ack list * * @details * - * Function : FillRicId + * Function : BuildE2nodeComponentConfigAdditionAck * - * Functionality: Fills the RicId + * Functionality: deallocate the memory allocated in E2SetupResponse * - * @params[in] BIT_STRING_t *nbid, - * U8 unusedBits - * U8 byteSize - * U8 val + * @params[in] E2nodeComponentConfigAdditionAck_List_t + * *e2NodeConfigAdditionAckList * - * @return ROK - success + * @return ROK - success * RFAILED - failure - * * ****************************************************************/ -S16 FillRicId(BIT_STRING_t *id, U8 unusedBits, U8 byteSize, U8 val) +uint8_t BuildE2nodeComponentConfigAdditionAck(E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAdditionAckList, DuDb *duDb) { - U8 tmp; - id->size = byteSize; - RIC_ALLOC(id->buf, id->size * sizeof(U8)); - if(id->buf == NULLP) + uint8_t arrIdx = 0; + E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem; + + e2NodeConfigAdditionAckList->list.count = 1; + e2NodeConfigAdditionAckList->list.size = e2NodeConfigAdditionAckList->list.count * sizeof(E2nodeComponentConfigAdditionAck_ItemIEs_t*); + RIC_ALLOC(e2NodeConfigAdditionAckList->list.array, e2NodeConfigAdditionAckList->list.size); + if(e2NodeConfigAdditionAckList->list.array == NULLP) + { + DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigAdditionAck %d",__LINE__); + return RFAILED; + } + + for(arrIdx = 0; arrIdx< e2NodeConfigAdditionAckList->list.count; arrIdx++) + { + RIC_ALLOC(e2NodeConfigAdditionAckList->list.array[arrIdx], sizeof(E2nodeComponentConfigAdditionAck_ItemIEs_t)); + if(e2NodeConfigAdditionAckList->list.array[arrIdx] == NULLP) + { + DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigAdditionAck %d",__LINE__); + return RFAILED; + } + } + e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAdditionAckList->list.array[0]; + e2NodeAddAckItem->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck_Item; + e2NodeAddAckItem->criticality = CriticalityE2_reject; + e2NodeAddAckItem->value.present = E2nodeComponentConfigAdditionAck_ItemIEs__value_PR_E2nodeComponentConfigAdditionAck_Item; + e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentInterfaceType = duDb->e2NodeComponent.interfaceType; + + /* >E2 Node Component ID */ + e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.present = E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1; + RIC_ALLOC(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\ + sizeof(E2nodeComponentInterfaceF1_t)); + if(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1 == NULLP) { - RETVALUE(RFAILED); + DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigAdditionAck %d",__LINE__); + return RFAILED; } + e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size = sizeof(uint8_t); + RIC_ALLOC(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\ + e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size); - for (tmp = 0 ; tmp < (byteSize-1); tmp++) + if(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf == NULLP) { - id->buf[tmp] = tmp; + DU_LOG("\nERROR -->list. E2AP: Memory allocation failed for BuildE2nodeComponentConfigAdditionAck %d",__LINE__); + return RFAILED; } - id->buf[byteSize-1] = val; //change this - id->bits_unused = unusedBits; - RETVALUE(ROK); + e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[0] = duDb->e2NodeComponent.componentId; + + /* >E2 Node Component Configuration Acknowledge*/ + e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentConfigurationAck.updateOutcome = \ + E2nodeComponentConfigurationAck__updateOutcome_success; + + return ROK; } /******************************************************************* * - * @brief Builds Global RIC Id Params + * @brief Build RAN function added list * * @details * - * Function : BuildGlobalRicId + * Function : BuildRanFunctionAddedList * - * Functionality: Building the Plmn and ric id + * Functionality: Build RAN function added list * - * @params[in] GlobalRIC_ID_t *ricId - * @return ROK - success - * RFAILED - failure + * @params[in] DuDb *duDb, RANfunctionsID_List_t *ranFuncAddedList * + * @return ROK - success + * RFAILED - failure * ****************************************************************/ -S16 BuildGlobalRicId(GlobalRIC_ID_t *ricId) +uint8_t BuildRanFunctionAddedList(DuDb *duDb, RANfunctionsID_List_t *ranFuncAddedList) { - U8 unused = 4; - U8 byteSize = 3; - U8 val = 1; - if(ricId != NULLP) + uint8_t ranFuncIdx = 0; + RANfunctionID_ItemIEs_t *ranFuncAddedItemIe; + + ranFuncAddedList->list.count = duDb->numOfRanFunction; + ranFuncAddedList->list.size = ranFuncAddedList->list.count*sizeof(RANfunctionID_ItemIEs_t*); + RIC_ALLOC(ranFuncAddedList->list.array, ranFuncAddedList->list.size); + if(ranFuncAddedList->list.array) { - plmnBuildRic(cuCfgParams.plmn , &ricId->pLMN_Identity); - /* fill ric Id */ - FillRicId(&ricId->ric_ID, unused, byteSize, val); + for(ranFuncIdx = 0; ranFuncIdx< ranFuncAddedList->list.count; ranFuncIdx++) + { + RIC_ALLOC(ranFuncAddedList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t)); + if(ranFuncAddedList->list.array[ranFuncIdx] == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for RAN function added list array item"); + return RFAILED; + } + ranFuncAddedItemIe = (RANfunctionID_ItemIEs_t*)ranFuncAddedList->list.array[ranFuncIdx]; + ranFuncAddedItemIe->id = ProtocolIE_IDE2_id_RANfunctionID_Item; + ranFuncAddedItemIe->criticality= CriticalityE2_ignore; + ranFuncAddedItemIe->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item; + ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionID =duDb->ranFunction[ranFuncIdx].id; + ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionRevision=duDb->ranFunction[ranFuncIdx].revisionCounter; + } } - RETVALUE(ROK); -} -#if 0 -RANfunctionID_ItemIEs_t* FillRanFuncItems(RANfunctionID_ItemIEs_t *items) -{ - if(items != NULLP) - { - items->id = ProtocolIE_IDE2_id_RANfunction_Item; - items->criticality = CriticalityE2_reject; - items->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item; - items->value.choice.RANfunctionID_Item.ranFunctionID = 1; - items->value.choice.RANfunctionID_Item.ranFunctionRevision = 4; - } - RETVALUE(items); -} - -S16 BuildRANfuncIdList(RANfunctionsID_List_t *funcIdList) -{ - U8 elementCnt; - RANfunctionID_ItemIEs_t *funcIdItems; - - elementCnt = 1; - funcIdList->list.count = elementCnt; - funcIdList->list.size = elementCnt * sizeof(RANfunctionID_ItemIEs_t); - RIC_ALLOC(funcIdList->list.array, funcIdList->list.size); - if(funcIdList->list.array == NULLP) + else { - DU_LOG("\nE2AP : Memory allocation for RAN Function List failed"); - RETVALUE(RFAILED); + DU_LOG("\nERROR --> E2AP : Memory allocation for RAN function added list array"); + return RFAILED; } - RIC_ALLOC(funcIdList->list.array[0], sizeof(RANfunctionID_ItemIEs_t)); - FillRanFuncItems(funcIdList->list.array[0]); - RETVALUE(ROK); + return ROK; } -#endif /******************************************************************* * @@ -261,104 +349,140 @@ S16 BuildRANfuncIdList(RANfunctionsID_List_t *funcIdList) * RFAILED - failure * * ****************************************************************/ -S16 BuildAndSendE2SetupRsp() +uint8_t BuildAndSendE2SetupRsp(DuDb *duDb, uint8_t transId) { E2AP_PDU_t *e2apMsg = NULL; E2setupResponse_t *e2SetupRsp; asn_enc_rval_t encRetVal; - U8 idx; - U8 elementCnt; - + uint8_t idx; + uint8_t elementCnt; + bool memAllocFailed = false; - DU_LOG("\nE2AP : Building E2 Setup Response\n"); - - RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t)); - if(e2apMsg == NULLP) - { - DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed"); - RETVALUE(RFAILED); - } - e2apMsg->present = E2AP_PDU_PR_successfulOutcome; - RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t)); - if(e2apMsg->choice.successfulOutcome == NULLP) + DU_LOG("\nINFO --> E2AP : Building E2 Setup Response\n"); + while(true) { - DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed"); - RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t)); - RETVALUE(RFAILED); - } - - e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_E2setup; - e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject; - e2apMsg->choice.successfulOutcome->value.present = \ - SuccessfulOutcomeE2__value_PR_E2setupResponse; - e2SetupRsp = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse; + RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t)); + if(e2apMsg == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed"); + break; + } + e2apMsg->present = E2AP_PDU_PR_successfulOutcome; + RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t)); + if(e2apMsg->choice.successfulOutcome == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed"); + break; + } - elementCnt = 1; - e2SetupRsp->protocolIEs.list.count = elementCnt; - e2SetupRsp->protocolIEs.list.size = elementCnt * sizeof(E2setupResponseIEs_t); + e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_E2setup; + e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject; + e2apMsg->choice.successfulOutcome->value.present = \ + SuccessfulOutcomeE2__value_PR_E2setupResponse; + e2SetupRsp = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse; - RIC_ALLOC(e2SetupRsp->protocolIEs.list.array, \ - e2SetupRsp->protocolIEs.list.size); - if(e2SetupRsp->protocolIEs.list.array == NULLP) - { - DU_LOG("\nE2AP : Memory allocation for E2ResponseIEs failed"); - RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t)); - RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t)); - RETVALUE(RFAILED); - } + elementCnt = 4; + e2SetupRsp->protocolIEs.list.count = elementCnt; + e2SetupRsp->protocolIEs.list.size = elementCnt * sizeof(E2setupResponseIEs_t*); - for(idx=0; idxprotocolIEs.list.array[idx], \ - sizeof(E2setupResponseIEs_t)); - if(e2SetupRsp->protocolIEs.list.array[idx] == NULLP) - { - RIC_FREE(e2SetupRsp->protocolIEs.list.array,\ - e2SetupRsp->protocolIEs.list.size); - RIC_FREE(e2apMsg->choice.successfulOutcome, \ - sizeof(SuccessfulOutcomeE2_t)); - RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t)); - RETVALUE(RFAILED); - } - } - /* Global RIC ID */ - idx = 0; - e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_GlobalRIC_ID; - e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject; - e2SetupRsp->protocolIEs.list.array[idx]->value.present = \ - E2setupResponseIEs__value_PR_GlobalRIC_ID; + RIC_ALLOC(e2SetupRsp->protocolIEs.list.array, e2SetupRsp->protocolIEs.list.size); + if(e2SetupRsp->protocolIEs.list.array == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for E2ResponseIEs failed"); + break; + } - BuildGlobalRicId(&(e2SetupRsp->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID)); + for(idx=0; idxprotocolIEs.list.array[idx], sizeof(E2setupResponseIEs_t)); + if(e2SetupRsp->protocolIEs.list.array[idx] == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for E2ResponseIEs failed"); + memAllocFailed = true; + break; + } + } + + if(memAllocFailed == true) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for E2ResponseIEs failed"); + break; + } + /* Trans Id */ + idx = 0; + e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_TransactionID; + e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject; + e2SetupRsp->protocolIEs.list.array[idx]->value.present = E2setupResponseIEs__value_PR_TransactionID; + e2SetupRsp->protocolIEs.list.array[idx]->value.choice.TransactionID = transId; + + /* Global RIC ID */ + idx++; + e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_GlobalRIC_ID; + e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject; + e2SetupRsp->protocolIEs.list.array[idx]->value.present = \ + E2setupResponseIEs__value_PR_GlobalRIC_ID; + + if(BuildGlobalRicId(&(e2SetupRsp->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID))!=ROK) + { + DU_LOG("\nERROR --> E2AP : Failed to build Global Ric Id"); + break; + } + + /* Accepted RAN function Id */ + idx++; + e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionsAccepted; + e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject; + e2SetupRsp->protocolIEs.list.array[idx]->value.present = E2setupResponseIEs__value_PR_RANfunctionsID_List; + if(BuildRanFunctionAddedList(duDb, &e2SetupRsp->protocolIEs.list.array[idx]->value.choice.RANfunctionsID_List)!=ROK) + { + DU_LOG("\nERROR --> E2AP : Failed to build Ran function added list"); + break; + } - xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg); - cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN); - encBufSize = 0; - encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf); + /* E2 Node Component Configuration Addition Acknowledge List*/ + idx++; + e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck; + e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject; + e2SetupRsp->protocolIEs.list.array[idx]->value.present = \ + E2setupResponseIEs__value_PR_E2nodeComponentConfigAdditionAck_List; + if(BuildE2nodeComponentConfigAdditionAck(&e2SetupRsp->protocolIEs.list.array[idx]->value.choice.E2nodeComponentConfigAdditionAck_List, duDb)!=ROK) + { + DU_LOG("\nERROR --> E2AP : Failed to build E2Node Component config addition ack list"); + break; + } - /* Check encode results */ - if(encRetVal.encoded == ENCODE_FAIL) - { - DU_LOG("\nE2AP : Could not encode E2SetupResponse structure (at %s)\n",\ - encRetVal.failed_type ? encRetVal.failed_type->name : "unknown"); - RETVALUE(RFAILED); - } - else - { - DU_LOG("\nE2AP : Created APER encoded buffer for E2SetupResponse\n"); - for(int i=0; i< encBufSize; i++) - { - printf("%x",encBuf[i]); - } - } + xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg); + memset(encBuf, 0, ENC_BUF_MAX_LEN); + encBufSize = 0; + encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf); + /* Check encode results */ + if(encRetVal.encoded == ENCODE_FAIL) + { + DU_LOG("\nERROR --> E2AP : Could not encode E2SetupResponse structure (at %s)\n",\ + encRetVal.failed_type ? encRetVal.failed_type->name : "unknown"); + break; + } + else + { + DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupResponse\n"); + for(int i=0; i< encBufSize; i++) + { + DU_LOG("%x",encBuf[i]); + } + } - if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL) != ROK) - { - DU_LOG("\nF1AP : Sending E2 Setup Response failed"); - RETVALUE(RFAILED); + if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK) + { + DU_LOG("\nERROR --> E2AP : Sending E2 Setup Response failed"); + break; + } + break; } - RETVALUE(ROK); + FreeE2SetupRsp(e2apMsg); + BuildAndSendRicSubscriptionReq(duDb->duId); + return ROK; } /******************************************************************* @@ -377,7 +501,7 @@ S16 BuildAndSendE2SetupRsp() * * ****************************************************************/ -S16 BuildRicRequestId(RICrequestID_t *ricReqId) +uint8_t BuildRicRequestId(RICrequestID_t *ricReqId) { if(ricReqId != NULLP) @@ -385,7 +509,7 @@ S16 BuildRicRequestId(RICrequestID_t *ricReqId) ricReqId->ricRequestorID = 1; ricReqId->ricInstanceID = 1; } - RETVALUE(ROK); + return ROK; } /******************************************************************* @@ -411,7 +535,7 @@ RICaction_ToBeSetup_Item_t* fillSetupItems(RICaction_ToBeSetup_Item_t *setupItem setupItems->ricActionType = RICactionType_report; } - RETVALUE(setupItems); + return (setupItems); } /******************************************************************* @@ -430,7 +554,7 @@ RICaction_ToBeSetup_Item_t* fillSetupItems(RICaction_ToBeSetup_Item_t *setupItem * * ****************************************************************/ -S16 fillSubsDetails(RICaction_ToBeSetup_ItemIEs_t *items) +uint8_t fillSubsDetails(RICaction_ToBeSetup_ItemIEs_t *items) { if(items != NULLP) { @@ -439,7 +563,7 @@ S16 fillSubsDetails(RICaction_ToBeSetup_ItemIEs_t *items) items->value.present = RICaction_ToBeSetup_ItemIEs__value_PR_RICaction_ToBeSetup_Item; fillSetupItems(&(items->value.choice.RICaction_ToBeSetup_Item)); } - RETVALUE(ROK); + return ROK; } /******************************************************************* @@ -458,15 +582,19 @@ S16 fillSubsDetails(RICaction_ToBeSetup_ItemIEs_t *items) * * ****************************************************************/ -S16 BuildRicSubsDetails(RICsubscriptionDetails_t *subsDetails) +uint8_t BuildRicSubsDetails(RICsubscriptionDetails_t *subsDetails) { - U8 elementCnt; + uint8_t elementCnt; if(subsDetails != NULLP) { - /* Plmn is not called */ - plmnBuildRic(cuCfgParams.plmn, &subsDetails->ricEventTriggerDefinition); + /* Octet string to be build here */ + /* Sending PLMN as Octect string */ + uint8_t byteSize = 3; + subsDetails->ricEventTriggerDefinition.size = byteSize * sizeof(uint8_t); + RIC_ALLOC(subsDetails->ricEventTriggerDefinition.buf, subsDetails->ricEventTriggerDefinition.size); + buildPlmnId(ricCb.ricCfgParams.plmn, subsDetails->ricEventTriggerDefinition.buf); elementCnt = 1; subsDetails->ricAction_ToBeSetup_List.list.count = elementCnt; subsDetails->ricAction_ToBeSetup_List.list.size = \ @@ -475,14 +603,14 @@ S16 BuildRicSubsDetails(RICsubscriptionDetails_t *subsDetails) subsDetails->ricAction_ToBeSetup_List.list.size); if(subsDetails->ricAction_ToBeSetup_List.list.array == NULLP) { - DU_LOG("\nE2AP : Memory allocation for RICactionToBeSetup Items failed"); - RETVALUE(RFAILED); + DU_LOG("\nERROR --> E2AP : Memory allocation for RICactionToBeSetup Items failed"); + return RFAILED; } RIC_ALLOC(subsDetails->ricAction_ToBeSetup_List.list.array[0],\ sizeof(RICaction_ToBeSetup_ItemIEs_t)); fillSubsDetails(subsDetails->ricAction_ToBeSetup_List.list.array[0]); } - RETVALUE(ROK); + return ROK; } /******************************************************************* @@ -500,34 +628,33 @@ S16 BuildRicSubsDetails(RICsubscriptionDetails_t *subsDetails) * ******************************************************************/ -S16 BuildAndSendRicSubscriptionReq() +uint8_t BuildAndSendRicSubscriptionReq(uint32_t duId) { - E2AP_PDU_t *e2apRicMsg = NULL; + E2AP_PDU_t *e2apRicMsg = NULL; RICsubscriptionRequest_t *ricSubscriptionReq; - U8 elementCnt; - U8 idx; - U8 ieId; - S16 ret; - asn_enc_rval_t encRetVal; /* Encoder return value */ - ricSubsStatus = TRUE; + uint8_t elementCnt; + uint8_t idx; + uint8_t ieId; + uint8_t ret; + asn_enc_rval_t encRetVal; /* Encoder return value */ - DU_LOG("\nE2AP : Building RIC Subscription Request\n"); + DU_LOG("\nINFO --> E2AP : Building RIC Subscription Request\n"); RIC_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t)); if(e2apRicMsg == NULLP) { - DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed"); - RETVALUE(RFAILED); + DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed"); + return RFAILED; } e2apRicMsg->present = E2AP_PDU_PR_initiatingMessage; RIC_ALLOC(e2apRicMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t)); if(e2apRicMsg->choice.initiatingMessage == NULLP) { - DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed"); + DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed"); RIC_FREE(e2apRicMsg, sizeof(E2AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } e2apRicMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICsubscription; e2apRicMsg->choice.initiatingMessage->criticality = CriticalityE2_reject; @@ -545,10 +672,10 @@ S16 BuildAndSendRicSubscriptionReq() ricSubscriptionReq->protocolIEs.list.size); if(ricSubscriptionReq->protocolIEs.list.array == NULLP) { - DU_LOG("\nE2AP : Memory allocation for RICSubscriptionRequestIEs failed"); + DU_LOG("\nERROR --> E2AP : Memory allocation for RICSubscriptionRequestIEs failed"); RIC_FREE(e2apRicMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t)); RIC_FREE(e2apRicMsg, (Size)sizeof(E2AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } for(idx=0; idxchoice.initiatingMessage, \ sizeof(InitiatingMessageE2_t)); RIC_FREE(e2apRicMsg, sizeof(E2AP_PDU_t)); - RETVALUE(RFAILED); + return RFAILED; } } @@ -603,37 +730,710 @@ S16 BuildAndSendRicSubscriptionReq() /* Prints the Msg formed */ xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg); - cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN); + memset(encBuf, 0, ENC_BUF_MAX_LEN); encBufSize = 0; encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apRicMsg, PrepFinalEncBuf,\ encBuf); if(encRetVal.encoded == ENCODE_FAIL) { - DU_LOG("\nE2AP : Could not encode RicSubscriptionRequest structure (at %s)\n",\ + DU_LOG("\nERROR --> E2AP : Could not encode RicSubscriptionRequest structure (at %s)\n",\ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown"); - RETVALUE(RFAILED); + return RFAILED; } else { - DU_LOG("\nE2AP : Created APER encoded buffer for RicSubscriptionRequest\n"); + DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RicSubscriptionRequest\n"); for(int i=0; i< encBufSize; i++) { - printf("%x",encBuf[i]); + DU_LOG("%x",encBuf[i]); } } /* Sending msg */ - if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL) != ROK) + if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK) { - DU_LOG("\nE2AP : Sending RIC subscription Request failed"); - RETVALUE(RFAILED); + DU_LOG("\nERROR --> E2AP : Sending RIC subscription Request failed"); + return RFAILED; } - RETVALUE(ROK); + return ROK; +} + +/******************************************************************* + * + * @brief Process RicSubscriptionResponse + * + * @details + * + * Function : ProcRicSubscriptionRsp + * + * Functionality: Processes RicSubscriptionRsp + * + * @return ROK - void + * + ******************************************************************/ + +void ProcRicSubscriptionResponse(uint32_t duId) +{ + uint8_t duIdx = 0; + DuDb *duDb; + + DU_LOG("\nINFO --> E2AP : RICsubscriptionResponse Msg Acknowledged"); + + SEARCH_DU_DB(duIdx, duId, duDb); + if(duDb) + duDb->ricSubscribedToDu = true; +} + +/******************************************************************* + * + * @brief deallocate the memory allocated in E2SetupFailure + * + * @details + * + * Function : FreeE2SetupFailure + * + * Functionality: deallocate the memory allocated in E2SetupFailure + * + * @params[in] E2AP_PDU_t *e2apMsg + * + * @return void + * ****************************************************************/ +void FreeE2SetupFailure(E2AP_PDU_t *e2apMsg) +{ + uint8_t arrIdx = 0; + E2setupFailure_t *e2SetupFail; + + if(e2apMsg) + { + if(e2apMsg->choice.unsuccessfulOutcome) + { + e2SetupFail = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure; + if(e2SetupFail->protocolIEs.list.array) + { + for(arrIdx=0; arrIdxprotocolIEs.list.count; arrIdx++) + { + RIC_FREE(e2SetupFail->protocolIEs.list.array[arrIdx], sizeof(E2setupFailureIEs_t)); + } + RIC_FREE(e2SetupFail->protocolIEs.list.array, e2SetupFail->protocolIEs.list.size); + } + RIC_FREE(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t)); + } + RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t)); + } } +/******************************************************************* + * + * @brief Buld and send the E2 Setup failure + * + * @details + * + * Function : BuildAndSendE2SetupFailure + * + * Functionality: + * - Buld and send the E2 Setup failure + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ + +uint8_t BuildAndSendE2SetupFailure(uint32_t duId, uint8_t transId) +{ + E2AP_PDU_t *e2apMsg = NULL; + E2setupFailure_t *e2SetupFailure; + asn_enc_rval_t encRetVal; + uint8_t arrIdx; + uint8_t elementCnt; + bool memAllocFailed = false; + + DU_LOG("\nINFO --> E2AP : Building E2 Setup failure\n"); + while(true) + { + RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t)); + if(e2apMsg == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed"); + break; + } + e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome; + RIC_ALLOC(e2apMsg->choice.unsuccessfulOutcome , sizeof(struct UnsuccessfulOutcomeE2)); + if(e2apMsg->choice.unsuccessfulOutcome == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed"); + break; + } + + e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_E2setup; + e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject; + e2apMsg->choice.unsuccessfulOutcome->value.present = UnsuccessfulOutcomeE2__value_PR_E2setupFailure; + e2SetupFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure; + + elementCnt = 3; + e2SetupFailure->protocolIEs.list.count = elementCnt; + e2SetupFailure->protocolIEs.list.size = elementCnt * sizeof(struct E2setupFailureIEs *); + + RIC_ALLOC(e2SetupFailure->protocolIEs.list.array, e2SetupFailure->protocolIEs.list.size); + if(e2SetupFailure->protocolIEs.list.array == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for E2FailureIEs failed"); + break; + } + + for(arrIdx=0; arrIdxprotocolIEs.list.array[arrIdx], sizeof(struct E2setupFailureIEs)); + if(e2SetupFailure->protocolIEs.list.array[arrIdx] == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for E2FailureIEs failed"); + memAllocFailed = true; + break; + } + } + + if(memAllocFailed == true) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for E2FailureIEs failed"); + break; + } + + /* Trans Id */ + arrIdx = 0; + e2SetupFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID; + e2SetupFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject; + e2SetupFailure->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_TransactionID; + e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId; + + arrIdx++; + e2SetupFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_CauseE2; + e2SetupFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject; + e2SetupFailure->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_CauseE2; + e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.CauseE2.present = CauseE2_PR_protocol; + e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.CauseE2.choice.protocol = CauseE2Protocol_unspecified; + + arrIdx++; + e2SetupFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TimeToWaitE2; + e2SetupFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_ignore; + e2SetupFailure->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_TimeToWaitE2; + e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2 = TimeToWaitE2_v5s; + + xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg); + memset(encBuf, 0, ENC_BUF_MAX_LEN); + encBufSize = 0; + encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf); + + /* Check encode results */ + if(encRetVal.encoded == ENCODE_FAIL) + { + DU_LOG("\nERROR --> E2AP : Could not encode E2 Setup failure structure (at %s)\n",\ + encRetVal.failed_type ? encRetVal.failed_type->name : "unknown"); + break; + } + else + { + DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Setup Failure\n"); + for(int i=0; i< encBufSize; i++) + { + DU_LOG("%x",encBuf[i]); + } + } + + if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK) + { + DU_LOG("\nERROR --> E2AP : Sending E2 Setup Failure failed"); + break; + } + break; + } + + FreeE2SetupFailure(e2apMsg); +} + +/******************************************************************* + * + * @brief process the e2setup request + * + * @details + * + * Function : ProcE2SetupReq + * + * Functionality: process the e2setup request + * + * @return ROK - success + * RFAILED - failure + * + ******************************************************************/ + +uint8_t ProcE2SetupReq(uint32_t *duId, E2setupRequest_t *e2SetupReq) +{ + uint8_t arrIdx = 0, e2NodeAddListIdx =0, duIdx = 0, transId =0, ranFuncIdx; + DuDb *duDb = NULLP; + E2nodeComponentConfigAddition_List_t *e2NodeAddList; + E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem; + RANfunction_ItemIEs_t *ranFuncItemIe; + RANfunction_Item_t *ranFunItem; + RANfunctions_List_t *ranFunctionsList; + + if(e2SetupReq) + { + if(e2SetupReq->protocolIEs.list.array) + { + for(arrIdx=0; arrIdxprotocolIEs.list.count; arrIdx++) + { + if(e2SetupReq->protocolIEs.list.array[arrIdx]) + { + switch(e2SetupReq->protocolIEs.list.array[arrIdx]->id) + { + case ProtocolIE_IDE2_id_TransactionID: + { + transId = e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID; + break; + } + case ProtocolIE_IDE2_id_GlobalE2node_ID: + { + if(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.choice.gNB->gNB_DU_ID) + { + *duId =e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.choice.gNB->gNB_DU_ID->buf[0]; + + SEARCH_DU_DB(duIdx, duId, duDb); + if(duDb == NULLP) + { + duDb = &ricCb.duInfo[ricCb.numDu]; + ricCb.numDu++; + } + memset(duDb, 0, sizeof(DuDb)); + duDb->duId = *duId; + } + break; + } + case ProtocolIE_IDE2_id_RANfunctionsAdded: + { + ranFunctionsList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List; + + if(ranFunctionsList->list.array) + { + for(ranFuncIdx=0;ranFuncIdxlist.count; ranFuncIdx++) + { + ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncIdx]; + ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item; + duDb->ranFunction[duDb->numOfRanFunction].id = ranFunItem->ranFunctionID; + duDb->ranFunction[ duDb->numOfRanFunction].revisionCounter = ranFunItem->ranFunctionRevision; + duDb->numOfRanFunction++; + } + } + break; + } + case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition: + { + e2NodeAddList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List; + if(e2NodeAddList->list.array) + { + for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++) + { + if(e2NodeAddList->list.array[e2NodeAddListIdx]) + { + e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[e2NodeAddListIdx]; + if(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\ + e2nodeComponentInterfaceTypeF1) + { + duDb->e2NodeComponent.interfaceType = F1; + duDb->e2NodeComponent.componentId = e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[0]; + } + } + } + } + break; + } + default: + break; + } + } + } + } + } + if(BuildAndSendE2SetupRsp(duDb, transId) !=ROK) + { + DU_LOG("\nERROR --> E2AP : Failed to build and send E2 setup response"); + return RFAILED; + } + return ROK; +} + +/******************************************************************* + * + * @brief Deallocate the memory allocated for E2nodeConfigurationUpdate msg + * + * @details + * + * Function : FreeE2NodeConfigUpdate + * + * Functionality: + * - freeing the memory allocated for E2nodeConfigurationUpdate + * + * @params[in] E2AP_PDU_t *e2apMsg + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ +void FreeE2NodeConfigUpdateAck(E2AP_PDU_t *e2apMsg) +{ + uint8_t arrIdx =0; + E2nodeConfigurationUpdate_t *e2NodeConfigUpdateAck; + + if(e2apMsg != NULLP) + { + if(e2apMsg->choice.successfulOutcome != NULLP) + { + e2NodeConfigUpdateAck = &e2apMsg->choice.successfulOutcome->value.choice.E2nodeConfigurationUpdateAcknowledge; + if(e2NodeConfigUpdateAck->protocolIEs.list.array != NULLP) + { + for(arrIdx = 0; arrIdx < e2NodeConfigUpdateAck->protocolIEs.list.count; arrIdx++) + { + RIC_FREE(e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_t)); + } + RIC_FREE(e2NodeConfigUpdateAck->protocolIEs.list.array, e2NodeConfigUpdateAck->protocolIEs.list.size); + } + RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t)); + } + RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t)); + } +} + +/******************************************************************* + * + * @brief Buld and send the E2 node config update msg + * + * @details + * + * Function : BuildAndSendE2NodeConfigUpdate + * + * Functionality: + * - Buld and send the E2 node config update msg + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ + +uint8_t BuildAndSendE2NodeConfigUpdateAck(uint32_t duId) +{ + uint8_t arrIdx = 0,elementCnt = 1; + uint8_t ret = ROK; + E2AP_PDU_t *e2apMsg = NULLP; + E2nodeConfigurationUpdateAcknowledge_t *e2NodeConfigUpdateAck = NULLP; + asn_enc_rval_t encRetVal; /* Encoder return value */ + + DU_LOG("\nINFO --> E2AP : Building E2 Node config update Ack Message\n"); + do + { + RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t)); + if(e2apMsg == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed"); + break; + } + e2apMsg->present = E2AP_PDU_PR_successfulOutcome; + RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t)); + if(e2apMsg->choice.successfulOutcome == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed"); + RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t)); + return RFAILED; + } + + e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject; + e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate; + e2apMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateAcknowledge; + e2NodeConfigUpdateAck = &e2apMsg->choice.successfulOutcome->value.choice.E2nodeConfigurationUpdateAcknowledge; + + e2NodeConfigUpdateAck->protocolIEs.list.count = elementCnt; + e2NodeConfigUpdateAck->protocolIEs.list.size = elementCnt * sizeof(E2nodeConfigurationUpdateAcknowledge_IEs_t*); + /* Initialize the Ric Indication members */ + RIC_ALLOC(e2NodeConfigUpdateAck->protocolIEs.list.array, \ + e2NodeConfigUpdateAck->protocolIEs.list.size); + if(e2NodeConfigUpdateAck->protocolIEs.list.array == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdateAck failed"); + break; + } + + for(arrIdx =0; arrIdxprotocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdateAcknowledge_IEs_t)); + if(e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx] == NULLP) + { + + DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdateAck failed"); + break; + } + } + + arrIdx = 0; + /* TransactionID */ + e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID; + e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject; + e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdateAcknowledge_IEs__value_PR_TransactionID; + e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = TRANS_ID; + + + xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg); + + memset(encBuf, 0, ENC_BUF_MAX_LEN); + encBufSize = 0; + encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\ + encBuf); + if(encRetVal.encoded == ENCODE_FAIL) + { + DU_LOG("\nERROR --> E2AP : Could not encode E2 Node config update ack structure (at %s)\n",\ + encRetVal.failed_type ? encRetVal.failed_type->name : "unknown"); + return RFAILED; + } + else + { + DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Node config update ack \n"); + for(int i=0; i< encBufSize; i++) + { + DU_LOG("%x",encBuf[i]); + } + } + + + /* Sending msg */ + if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK) + { + DU_LOG("\nERROR --> E2AP : Failed to send E2 Node config update ack "); + return RFAILED; + } + + break; + }while(true); + + FreeE2NodeConfigUpdateAck(e2apMsg); + return ret; +} + +/******************************************************************* + * + * @brief Deallocate the memory allocated for E2 Reset Response + * + * @details + * + * Function : FreeE2ResetResponse + * + * Functionality: + * - freeing the memory allocated for E2ResetResponse + * + * @params[in] E2AP_PDU_t *e2apMsg + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ +void FreeE2ResetResponse(E2AP_PDU_t *e2apMsg) +{ + uint8_t ieIdx =0; + ResetResponseE2_t *resetResponse; + + if(e2apMsg != NULLP) + { + if(e2apMsg->choice.successfulOutcome != NULLP) + { + resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2; + if(resetResponse->protocolIEs.list.array) + { + for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++) + { + if(resetResponse->protocolIEs.list.array[ieIdx]) + { + RIC_FREE(resetResponse->protocolIEs.list.array[ieIdx], sizeof(ResetResponseIEs_t)); + } + } + RIC_FREE(resetResponse->protocolIEs.list.array, resetResponse->protocolIEs.list.size); + } + RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t)); + } + RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t)); + } +} + +/******************************************************************* + * + * @brief Buld and send the E2 Reset Response msg + * + * @details + * + * Function : BuildAndSendE2ResetResponse + * + * Functionality: + * - Buld and send the E2 Reset Response Message + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ +uint8_t BuildAndSendResetResponse(uint32_t duId, uint8_t transId) +{ + uint8_t ieIdx = 0, elementCnt = 0; + uint8_t ret = RFAILED; + E2AP_PDU_t *e2apMsg = NULLP; + ResetResponseE2_t *resetResponse; + asn_enc_rval_t encRetVal; /* Encoder return value */ + + DU_LOG("\nINFO --> E2AP : Building E2 Reset Response Message\n"); + do + { + RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t)); + if(e2apMsg == NULLP) + { + DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse(): Memory allocation for E2AP-PDU failed"); + break; + } + e2apMsg->present = E2AP_PDU_PR_successfulOutcome; + + RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t)); + if(e2apMsg->choice.successfulOutcome == NULLP) + { + DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse: Memory allocation failed for successfulOutcome"); + RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t)); + return RFAILED; + } + e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_Reset; + e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject; + e2apMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_ResetResponseE2; + resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2; + + elementCnt = 1; + resetResponse->protocolIEs.list.count = elementCnt; + resetResponse->protocolIEs.list.size = elementCnt * sizeof(ResetResponseIEs_t *); + RIC_ALLOC(resetResponse->protocolIEs.list.array, resetResponse->protocolIEs.list.size); + if(!resetResponse->protocolIEs.list.array) + { + DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse: Memory allocation failed for protocol IE array"); + break; + } + + for(ieIdx=0; ieIdx < elementCnt; ieIdx++) + { + RIC_ALLOC(resetResponse->protocolIEs.list.array[ieIdx], sizeof(ResetResponseIEs_t)); + if(!resetResponse->protocolIEs.list.array[ieIdx]) + { + DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse: Memory allocation failed for protocol IE array element"); + break; + } + } + if(ieIdx < elementCnt) + break; + + ieIdx = 0; + resetResponse->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID; + resetResponse->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject; + resetResponse->protocolIEs.list.array[ieIdx]->value.present = ResetResponseIEs__value_PR_TransactionID; + resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId; + + xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg); + + memset(encBuf, 0, ENC_BUF_MAX_LEN); + encBufSize = 0; + encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf); + if(encRetVal.encoded == ENCODE_FAIL) + { + DU_LOG("\nERROR --> E2AP : Could not encode E2 reset response structure (at %s)\n",\ + encRetVal.failed_type ? encRetVal.failed_type->name : "unknown"); + return RFAILED; + } + else + { + DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Reset Response \n"); + for(int i=0; i< encBufSize; i++) + { + DU_LOG("%x",encBuf[i]); + } + } + + /* Sending msg */ + if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK) + { + DU_LOG("\nERROR --> E2AP : Failed to send E2 Reset Response"); + return RFAILED; + } + + ret = ROK; + break; + }while(true); + + FreeE2ResetResponse(e2apMsg); + return ROK; +} + +/******************************************************************* + * + * @brief process the E2 Reset Request + * + * @details + * + * Function : ProcE2ResetReq + * + * Functionality: Process E2 Reset Request + * + * @return ROK - success + * RFAILED - failure + * + ******************************************************************/ + +uint8_t ProcE2ResetReq(uint32_t duId, ResetRequestE2_t *resetReq) +{ + uint8_t ieIdx = 0, duIdx = 0; + uint8_t transId = 0, cause = 0; + DuDb *duDb = NULLP; + + if(resetReq) + { + if(resetReq->protocolIEs.list.array) + { + for(ieIdx=0; ieIdx < resetReq->protocolIEs.list.count; ieIdx++) + { + if(resetReq->protocolIEs.list.array[ieIdx]) + { + switch(resetReq->protocolIEs.list.array[ieIdx]->id) + { + case ProtocolIE_IDE2_id_TransactionID: + transId = resetReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID; + break; + case ProtocolIE_IDE2_id_CauseE2: + DU_LOG("\nDEBUG --> E2AP : Reset reason %d", resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.present); + switch(resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.present) + { + case CauseE2_PR_NOTHING: + break; + case CauseE2_PR_ricRequest: + cause = resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.ricRequest; + break; + case CauseE2_PR_ricService: + cause = resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.ricService; + break; + case CauseE2_PR_e2Node: + cause = resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.e2Node; + break; + case CauseE2_PR_transport: + cause = resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.transport; + break; + case CauseE2_PR_protocol: + cause = resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.protocol; + break; + case CauseE2_PR_misc: + cause = resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.misc; + break; + } + DU_LOG("\nDEBUG --> E2AP : Reset cause %d", cause); + break; + } + } + } + } + } + BuildAndSendResetResponse(duId, transId); + return ROK; +} + /******************************************************************* * * @brief Handles received E2AP message and sends back response @@ -651,106 +1451,117 @@ S16 BuildAndSendRicSubscriptionReq() * RFAILED - failure * * ****************************************************************/ -void E2APMsgHdlr(Buffer *mBuf) +void E2APMsgHdlr(uint32_t *duId, Buffer *mBuf) { - int i; - char *recvBuf; - MsgLen copyCnt; - MsgLen recvBufLen; - E2AP_PDU_t *e2apMsg; - asn_dec_rval_t rval; /* Decoder return value */ - E2AP_PDU_t e2apasnmsg ; + int i; + char *recvBuf; + MsgLen copyCnt; + MsgLen recvBufLen; + E2AP_PDU_t *e2apMsg; + asn_dec_rval_t rval; /* Decoder return value */ + E2AP_PDU_t e2apasnmsg ; - DU_LOG("\nE2AP : Received E2AP message buffer"); - SPrntMsg(mBuf, 0,0); + DU_LOG("\nINFO --> E2AP : Received E2AP message buffer"); + 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_GET_MSG_LEN(mBuf, &recvBufLen); + RIC_ALLOC(recvBuf, (Size)recvBufLen); + + if(recvBuf == NULLP) { - DU_LOG("\nE2AP : Memory allocation failed"); + DU_LOG("\nERROR --> E2AP : 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("\nE2AP : Failed while copying %d", copyCnt); + DU_LOG("\nERROR --> E2AP : Failed while copying %d", copyCnt); return; } - printf("\nE2AP : Received flat buffer to be decoded : "); + DU_LOG("\nDEBUG --> E2AP : Received flat buffer to be decoded : "); for(i=0; i< recvBufLen; i++) { - printf("%x",recvBuf[i]); + DU_LOG("%x",recvBuf[i]); } - /* Decoding flat buffer into F1AP messsage */ + /* Decoding flat buffer into E2AP messsage */ e2apMsg = &e2apasnmsg; memset(e2apMsg, 0, sizeof(E2AP_PDU_t)); rval = aper_decode(0, &asn_DEF_E2AP_PDU, (void **)&e2apMsg, recvBuf, recvBufLen, 0, 0); - SPutSBuf(DFLT_REGION, DFLT_POOL, (Data *)recvBuf, (Size)recvBufLen); + RIC_FREE(recvBuf, (Size)recvBufLen); + if(rval.code == RC_FAIL || rval.code == RC_WMORE) { - DU_LOG("\nE2AP : ASN decode failed"); + DU_LOG("\nERROR --> E2AP : ASN decode failed"); return; } - printf("\n"); + DU_LOG("\n"); xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg); switch(e2apMsg->present) { case E2AP_PDU_PR_initiatingMessage: - { - switch(e2apMsg->choice.initiatingMessage->value.present) { - case InitiatingMessageE2__value_PR_E2setupRequest: + switch(e2apMsg->choice.initiatingMessage->value.present) { - DU_LOG("\nE2AP : E2 setup request received"); - BuildAndSendE2SetupRsp(); - break; - } - case InitiatingMessageE2__value_PR_RICindication: - { - DU_LOG("\nE2AP : RIC Indication Acknowledged"); - break; - } - default: - { - DU_LOG("\nE2AP : Invalid type of intiating message [%d]",e2apMsg->choice.initiatingMessage->value.present); - return; - } - }/* End of switch(initiatingMessage) */ - break; - } + case InitiatingMessageE2__value_PR_E2setupRequest: + { + DU_LOG("\nINFO --> E2AP : E2 setup request received"); + ProcE2SetupReq(duId, &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest); + break; + } + case InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate: + { + DU_LOG("\nINFO --> E2AP : E2 node config update received"); + BuildAndSendE2NodeConfigUpdateAck(*duId); + break; + } + case InitiatingMessageE2__value_PR_ResetRequestE2: + { + DU_LOG("\nINFO --> E2AP : E2 Reset Request received"); + ProcE2ResetReq(*duId, &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2); + break; + } + case InitiatingMessageE2__value_PR_RICindication: + { + DU_LOG("\nINFO --> E2AP : RIC Indication Acknowledged"); + break; + } + default: + { + DU_LOG("\nERROR --> E2AP : Invalid type of intiating message [%d]",e2apMsg->choice.initiatingMessage->value.present); + return; + } + }/* End of switch(initiatingMessage) */ + break; + } case E2AP_PDU_PR_successfulOutcome: - { - switch(e2apMsg->choice.successfulOutcome->value.present) { - case SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse: + switch(e2apMsg->choice.successfulOutcome->value.present) { - DU_LOG("\nE2AP : RICsubscriptionResponse Msg Acknowledged"); - break; + case SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse: + { + ProcRicSubscriptionResponse(*duId); + break; + } + default: + { + DU_LOG("\nERROR --> E2AP : Invalid type of successfulOutcome message [%d]",e2apMsg->choice.successfulOutcome->value.present); + return; + } + break; } - default: - { - DU_LOG("\nE2AP : Invalid type of successfulOutcome message [%d]",e2apMsg->choice.successfulOutcome->value.present); - return; - } - break; + break; } - break; - } default: - { - DU_LOG("\nE2AP : Invalid type message type "); - return; - } - - }/* End of switch(e2apMsg->present) */ + { + DU_LOG("\nERROR --> E2AP : Invalid type message type "); + return; + } - if(!ricSubsStatus) - BuildAndSendRicSubscriptionReq(); - + }/* End of switch(e2apMsg->present) */ } /* End of E2APMsgHdlr */