+ while(true)
+ {
+ actionItem->id = ProtocolIE_IDE2_id_RICaction_ToBeSetup_Item;
+ actionItem->criticality = CriticalityE2_ignore;
+ actionItem->value.present = RICaction_ToBeSetup_ItemIEs__value_PR_RICaction_ToBeSetup_Item;
+
+ /* RIC Action ID */
+ actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID = ++ricActionId;
+ ricSubsDb->actionSequence[ricSubsDb->numOfActions].id = \
+ actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID;
+
+ /* RIC Action Type */
+ actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionType = RICactionType_report;
+
+ /* RIC Action Definition */
+ RIC_ALLOC(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition, sizeof(RICactionDefinition_t));
+ if(!actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
+ break;
+ }
+ if(fillRicActionDef(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed at [%s] : line [%d]", __func__, __LINE__);
+ break;
+ }
+
+ ricSubsDb->numOfActions++;
+ return ROK;
+ }
+
+ memset(&ricSubsDb->actionSequence[ricSubsDb->numOfActions], 0, sizeof(ActionInfo));
+ return RFAILED;
+}
+
+/*******************************************************************
+ *
+ * @brief Free Event Trigger Definition
+ *
+ * @details
+ *
+ * Function : FreeEventTriggerDef
+ *
+ * Functionality: Free Event Trigger Definition
+ *
+ * @params[in] E2SM-KPM Event Trigger Definition
+ * @return void
+ *
+ * ****************************************************************/
+void FreeEventTriggerDef(E2SM_KPM_EventTriggerDefinition_t *eventTiggerDef)
+{
+ if(eventTiggerDef)
+ {
+ switch(eventTiggerDef->eventDefinition_formats.present)
+ {
+ case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING:
+ break;
+ case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_eventDefinition_Format1:
+ RIC_FREE(eventTiggerDef->eventDefinition_formats.choice.eventDefinition_Format1, \
+ sizeof(E2SM_KPM_EventTriggerDefinition_Format1_t));
+ break;
+ }
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Fill Event Trigger Definition
+ *
+ * @details
+ *
+ * Function : fillEventTriggerDef
+ *
+ * Functionality: Fill Event Trigger Definition
+ *
+ * @params[in] RIC Event Trigger Definition
+ * @return ROK
+ * RFAILED
+ *
+ * ****************************************************************/
+uint8_t fillEventTriggerDef(RICeventTriggerDefinition_t *ricEventTriggerDef)
+{
+ uint8_t ret = RFAILED;
+ asn_enc_rval_t encRetVal;
+ E2SM_KPM_EventTriggerDefinition_t eventTiggerDef;
+
+ while(true)
+ {
+ /* Fill E2SM-KPM Event Trigger Definition Format 1 */
+ eventTiggerDef.eventDefinition_formats.present = \
+ E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_eventDefinition_Format1;
+
+ RIC_ALLOC(eventTiggerDef.eventDefinition_formats.choice.eventDefinition_Format1, \
+ sizeof(E2SM_KPM_EventTriggerDefinition_Format1_t));
+ if(eventTiggerDef.eventDefinition_formats.choice.eventDefinition_Format1 == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
+ break;
+ }
+
+ eventTiggerDef.eventDefinition_formats.choice.eventDefinition_Format1->reportingPeriod = 1000; /* In ms */
+
+ /* Prints the Msg formed */
+ xer_fprint(stdout, &asn_DEF_E2SM_KPM_EventTriggerDefinition, &eventTiggerDef);
+
+ /* Encode E2SM-KPM Event Trigger Definition */
+ memset(encBuf, 0, ENC_BUF_MAX_LEN);
+ encBufSize = 0;
+ encRetVal = aper_encode(&asn_DEF_E2SM_KPM_EventTriggerDefinition, 0, &eventTiggerDef, PrepFinalEncBuf, encBuf);
+ if(encRetVal.encoded == ENCODE_FAIL)
+ {
+ DU_LOG("\nERROR --> E2AP : Could not encode E2SM-KPM event trigger definition structure (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+
+ /* Copy encoded E2SM-KPM event trigger definition to E2AP octet string buffer */
+ ricEventTriggerDef->size = encBufSize;
+ RIC_ALLOC(ricEventTriggerDef->buf, encBufSize);
+ if(ricEventTriggerDef->buf == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
+ break;
+ }
+ memcpy(ricEventTriggerDef->buf, encBuf, encBufSize);
+
+ ret = ROK;
+ break;
+ }
+
+ FreeEventTriggerDef(&eventTiggerDef);
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief builds RIC Subscription Details
+ *
+ * @details
+ *
+ * Function : BuildsRicSubsDetails
+ *
+ * Functionality: Builds the RIC Subscription Details
+ *
+ * @params[in] RIC Subscription details to be filled
+ * RIC subscriotion DB
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t BuildRicSubsDetails(RICsubscriptionDetails_t *subsDetails, RicSubscription *ricSubsDb)
+{
+ uint8_t elementCnt = 0;
+ uint8_t elementIdx = 0;
+
+ if(subsDetails == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed at [%s] : line [%d]", __func__, __LINE__);
+ return RFAILED;
+ }
+
+ while(true)
+ {
+ /* RIC Event Trigger Definition */
+ if(fillEventTriggerDef(&subsDetails->ricEventTriggerDefinition) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed at [%s] : line [%d]", __func__, __LINE__);
+ break;
+ }
+
+ /* RIC Actions To Be Setup List */
+ elementCnt = 1;
+ subsDetails->ricAction_ToBeSetup_List.list.count = elementCnt;
+ subsDetails->ricAction_ToBeSetup_List.list.size = elementCnt * sizeof(RICaction_ToBeSetup_ItemIEs_t *);
+ RIC_ALLOC(subsDetails->ricAction_ToBeSetup_List.list.array, subsDetails->ricAction_ToBeSetup_List.list.size);
+ if(subsDetails->ricAction_ToBeSetup_List.list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for RICactionToBeSetup Items failed");
+ break;
+ }
+
+ for(elementIdx = 0; elementIdx < elementCnt; elementIdx++)
+ {
+ RIC_ALLOC(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx], sizeof(RICaction_ToBeSetup_ItemIEs_t));
+ if(!subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx])
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
+ break;
+ }
+ }
+ if(elementIdx < elementCnt)
+ break;
+
+ elementIdx = 0;
+ if(fillActionToBeSetup((RICaction_ToBeSetup_ItemIEs_t *)subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx], \
+ ricSubsDb) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed at [%s] : line [%d]", __func__, __LINE__);
+ break;
+ }
+
+ return ROK;
+ }
+ return RFAILED;
+}
+
+/*******************************************************************
+ *
+ * @brief Builds and Send the RicSubscriptionReq
+ *
+ * @details
+ *
+ * Function : BuildAndSendRicSubscriptionReq
+ *
+ * Functionality:Fills the RicSubscriptionReq
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+uint8_t BuildAndSendRicSubscriptionReq(DuDb *duDb)
+{
+ uint8_t ret = RFAILED;
+ E2AP_PDU_t *e2apRicMsg = NULL;
+ RICsubscriptionRequest_t *ricSubscriptionReq;
+ uint8_t elementCnt;
+ uint8_t idx;
+ uint8_t ieId;
+ asn_enc_rval_t encRetVal; /* Encoder return value */
+ RanFunction *ranFuncDb = &duDb->ranFunction[0];
+
+ DU_LOG("\nINFO --> E2AP : Building RIC Subscription Request\n");
+
+ while(true)
+ {
+ RIC_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t));
+ if(e2apRicMsg == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
+ break;
+ }
+
+ e2apRicMsg->present = E2AP_PDU_PR_initiatingMessage;
+ RIC_ALLOC(e2apRicMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ if(e2apRicMsg->choice.initiatingMessage == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
+ break;
+ }
+ e2apRicMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICsubscription;
+ e2apRicMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
+ e2apRicMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICsubscriptionRequest;
+
+ ricSubscriptionReq = &e2apRicMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
+
+ elementCnt = 3;
+ ricSubscriptionReq->protocolIEs.list.count = elementCnt;
+ ricSubscriptionReq->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionRequest_IEs_t);
+
+ /* Initialize the subscription members */
+ RIC_ALLOC(ricSubscriptionReq->protocolIEs.list.array, ricSubscriptionReq->protocolIEs.list.size);
+ if(ricSubscriptionReq->protocolIEs.list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
+ break;
+ }
+
+ for(idx=0; idx<elementCnt; idx++)
+ {
+ RIC_ALLOC(ricSubscriptionReq->protocolIEs.list.array[idx], sizeof(RICsubscriptionRequest_IEs_t));
+ if(ricSubscriptionReq->protocolIEs.list.array[idx] == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
+ break;
+ }
+ }
+ if(idx < elementCnt)
+ break;
+
+ /* Filling RIC Request Id */
+ idx = 0;
+ ricSubscriptionReq->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
+ ricSubscriptionReq->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
+ ricSubscriptionReq->protocolIEs.list.array[idx]->value.present =\
+ RICsubscriptionRequest_IEs__value_PR_RICrequestID;
+ if(BuildNewRicRequestId(&ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICrequestID, \
+ &ranFuncDb->subscriptionList[ranFuncDb->numOfSubscription].requestId) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed at [%d] : Line [%d]", __func__, __LINE__);
+ break;
+ }
+
+
+ /* Filling RAN Function Id */
+ idx++;
+ ricSubscriptionReq->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
+ ricSubscriptionReq->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
+ ricSubscriptionReq->protocolIEs.list.array[idx]->value.present =\
+ RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
+ ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RANfunctionID = ranFuncDb->id;
+
+ /* Filling RIC Subscription Details */
+ idx++;
+ ricSubscriptionReq->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICsubscriptionDetails;
+ ricSubscriptionReq->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
+ ricSubscriptionReq->protocolIEs.list.array[idx]->value.present =\
+ RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails;
+ if(BuildRicSubsDetails(&(ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails),\
+ &ranFuncDb->subscriptionList[ranFuncDb->numOfSubscription]) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed at [%d] : Line [%d]", __func__, __LINE__);
+ break;
+ }
+
+ /* Prints the Msg formed */
+ xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg);
+
+ 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("\nERROR --> E2AP : Could not encode RicSubscriptionRequest structure (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RicSubscriptionRequest\n");
+ for(int i=0; i< encBufSize; i++)
+ {
+ DU_LOG("%x",encBuf[i]);
+ }
+ }
+
+ /* Sending msg */
+ if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Sending RIC subscription Request failed");
+ break;
+ }
+
+ ranFuncDb->numOfSubscription++;
+ ret = ROK;
+ break;
+ }
+
+ if(ret == RFAILED)
+ memset(&ranFuncDb->subscriptionList[ranFuncDb->numOfSubscription], 0, sizeof(RicSubscription));
+ FreeRicSubscriptionReq(e2apRicMsg);
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @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; arrIdx<e2SetupFail->protocolIEs.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; arrIdx<elementCnt; arrIdx++)
+ {
+ RIC_ALLOC(e2SetupFailure->protocolIEs.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; arrIdx<e2SetupReq->protocolIEs.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;ranFuncIdx<ranFunctionsList->list.count; ranFuncIdx++)
+ {
+ ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncIdx];
+ ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
+ duDb->ranFunction[ranFunItem->ranFunctionID-1].id = ranFunItem->ranFunctionID;
+ duDb->ranFunction[ranFunItem->ranFunctionID-1].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; arrIdx<elementCnt; arrIdx++)
+ {
+ RIC_ALLOC(e2NodeConfigUpdateAck->protocolIEs.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 deallocate the memory allocated in building the
+ * Service Query message
+ *
+ * @details
+ *
+ * Function : FreeRicServiceQuery
+ *
+ * Functionality: deallocate the memory allocated in building
+ * Ric Service Query message
+ *
+ * @params[in] E2AP_PDU_t *e2apMsg
+ *
+ * @return void
+ * ****************************************************************/
+
+void FreeRicServiceQuery(E2AP_PDU_t *e2apMsg)
+{
+ uint8_t arrIdx = 0, ranFuncIdx=0;
+ RANfunctionsID_List_t *ranFuncAcceptedList=NULL;
+ RICserviceQuery_t *ricServiceQuery=NULL;
+
+ if(e2apMsg)
+ {
+ if(e2apMsg->choice.initiatingMessage)
+ {
+ ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
+ if(ricServiceQuery->protocolIEs.list.array)
+ {
+ for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
+ {
+ if(ricServiceQuery->protocolIEs.list.array[arrIdx])
+ {
+ switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
+ {
+ case ProtocolIE_IDE2_id_RANfunctionsAccepted:
+ {
+ ranFuncAcceptedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
+ if(ranFuncAcceptedList->list.array)
+ {
+ for(ranFuncIdx=0;ranFuncIdx<ranFuncAcceptedList->list.count; ranFuncIdx++)
+ {
+ RIC_FREE(ranFuncAcceptedList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
+ }
+ RIC_FREE(ranFuncAcceptedList->list.array, ranFuncAcceptedList->list.size);
+ }
+ break;
+ }
+ case RICserviceQuery_IEs__value_PR_TransactionID:
+ {
+ break;
+ }
+ }
+ RIC_FREE(ricServiceQuery->protocolIEs.list.array[arrIdx], sizeof(RICserviceQuery_IEs_t));
+ }
+ }
+ RIC_FREE(ricServiceQuery->protocolIEs.list.array, ricServiceQuery->protocolIEs.list.size);
+ }
+ RIC_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ }
+ RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief build and send the ric service Query
+ *
+ * @details
+ *
+ * Function : BuildAndSendRicServiceQuery
+ *
+ * Functionality: build and send the ric service Query
+ * @return ROK - success
+ * RFAILED - Acknowledge
+ *
+ ******************************************************************/
+
+uint8_t BuildAndSendRicServiceQuery(DuDb *duDb)
+{
+ uint8_t arrIdx;
+ uint8_t elementCnt;
+ uint8_t ret = RFAILED;
+ bool memAllocFailed = false;
+ E2AP_PDU_t *e2apMsg = NULL;
+ asn_enc_rval_t encRetVal;
+ RICserviceQuery_t *ricServiceQuery;
+
+ DU_LOG("\nINFO --> E2AP : Building Ric service Query\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_initiatingMessage;
+ RIC_ALLOC(e2apMsg->choice.initiatingMessage , sizeof(struct InitiatingMessageE2));
+ if(e2apMsg->choice.initiatingMessage == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
+ break;
+ }
+
+ e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICserviceQuery;
+ e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
+ e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICserviceQuery;
+ ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
+
+ elementCnt = 1;
+ /* Fill Accepted RAN function IE If Ran function information is stored in databse */
+ if(duDb->numOfRanFunction)
+ elementCnt++;
+
+ ricServiceQuery->protocolIEs.list.count = elementCnt;
+ ricServiceQuery->protocolIEs.list.size = elementCnt * sizeof(RICserviceQuery_IEs_t*);
+
+ RIC_ALLOC(ricServiceQuery->protocolIEs.list.array, ricServiceQuery->protocolIEs.list.size);
+ if(ricServiceQuery->protocolIEs.list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceQueryIEs failed");
+ break;
+ }
+
+ for(arrIdx=0; arrIdx<elementCnt; arrIdx++)
+ {
+ RIC_ALLOC(ricServiceQuery->protocolIEs.list.array[arrIdx], sizeof(RICserviceQuery_IEs_t));
+ if(ricServiceQuery->protocolIEs.list.array[arrIdx] == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceQueryIEs failed");
+ memAllocFailed = true;
+ break;
+ }
+ }
+ if(memAllocFailed == true)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceQueryIEs failed");
+ break;
+ }
+
+ /* Trans Id */
+ arrIdx = 0;
+ ricServiceQuery->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
+ ricServiceQuery->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ ricServiceQuery->protocolIEs.list.array[arrIdx]->value.present = RICserviceQuery_IEs__value_PR_TransactionID;
+ ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = assignTransactionId(duDb);
+
+ if(duDb->numOfRanFunction)
+ {
+ /* Accepted RAN function Id */
+ arrIdx++;
+ ricServiceQuery->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAccepted;
+ ricServiceQuery->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ ricServiceQuery->protocolIEs.list.array[arrIdx]->value.present = RICserviceQuery_IEs__value_PR_RANfunctionsID_List;
+ if(BuildRanFunctionAcceptedList(duDb, 0, NULL, &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List, ProcedureCodeE2_id_RICserviceQuery)!=ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to build Ran function added list");
+ break;
+ }
+ }
+
+ 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 RIC service Query structure (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC service Query\n");
+ for(int i=0; i< encBufSize; i++)
+ {
+ DU_LOG("%x",encBuf[i]);
+ }
+ }
+
+ if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Sending of RIC service Query failed");
+ break;
+ }
+
+ ret =ROK;
+ break;
+ }
+ FreeRicServiceQuery(e2apMsg);
+ return ret;