+ if(formatFailure)
+ break;
+
+ /* Encode E2SM-KPM Indication Header */
+ xer_fprint(stdout, &asn_DEF_E2SM_KPM_IndicationHeader, &e2smKpmIndHdr);
+ memset(encBuf, 0, ENC_BUF_MAX_LEN);
+ encBufSize = 0;
+ encRetVal = aper_encode(&asn_DEF_E2SM_KPM_IndicationHeader, 0, &e2smKpmIndHdr, PrepFinalEncBuf, encBuf);
+ if(encRetVal.encoded == ENCODE_FAIL)
+ {
+ DU_LOG("\nERROR --> E2AP : Could not encode E2SM-KPM Indication Header (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SM-KPM Indication Header \n");
+#ifdef DEBUG_ASN_PRINT
+ for(int i=0; i< encBufSize; i++)
+ {
+ printf("%x",encBuf[i]);
+ }
+#endif
+ }
+
+ /* Copy encoded string to RIC Indication Header buffer */
+ ricIndHdr->size = encBufSize;
+ DU_ALLOC(ricIndHdr->buf, ricIndHdr->size);
+ if(!ricIndHdr->buf)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
+ break;
+ }
+ memset(ricIndHdr->buf, 0, ricIndHdr->size);
+ memcpy(ricIndHdr->buf, encBuf, encBufSize);
+ ret = ROK;
+ break;
+ }
+
+ /* Free E2SM-KPM Indication Header */
+ FreeE2smKpmIndicationHeader(&e2smKpmIndHdr);
+
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * brief Fill the RIC Indication Message
+ *
+ * @details
+ *
+ * Function : fillRicIndication
+ *
+ * Functionality: Fills the RIC Indication Message
+ *
+ * @param RIC Indication Message to be filled
+ * RIC Subscription DB
+ * Action DB
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+uint8_t fillRicIndication(RICindication_t *ricIndicationMsg, RicSubscription *ricSubscriptionInfo, ActionInfo *actionInfo)
+{
+ uint8_t elementCnt = 0, idx = 0;
+ uint8_t ret = ROK;
+
+ elementCnt = 6;
+
+ ricIndicationMsg->protocolIEs.list.count = elementCnt;
+ ricIndicationMsg->protocolIEs.list.size = elementCnt * sizeof(RICindication_IEs_t *);
+
+ /* Initialize the Ric Indication members */
+ DU_ALLOC(ricIndicationMsg->protocolIEs.list.array, ricIndicationMsg->protocolIEs.list.size);
+ if(ricIndicationMsg->protocolIEs.list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
+ return RFAILED;
+ }
+
+ for(idx=0; idx<elementCnt; idx++)
+ {
+ DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx], sizeof(RICindication_IEs_t));
+ if(ricIndicationMsg->protocolIEs.list.array[idx] == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
+ return RFAILED;
+ }
+ }
+
+ /* RIC Request ID */
+ idx = 0;
+ ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
+ ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICrequestID;
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID = \
+ ricSubscriptionInfo->requestId.requestorId;
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID = \
+ ricSubscriptionInfo->requestId.instanceId;
+
+ /* RAN Function ID */
+ idx++;
+ ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
+ ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RANfunctionID;
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RANfunctionID = ricSubscriptionInfo->ranFuncId;
+
+ /* RIC Action ID */
+ idx++;
+ ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactionID;
+ ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICactionID;
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICactionID = actionInfo->actionId;
+
+ /* RIC Indication Type */
+ idx++;
+ ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationType;
+ ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICindicationType;
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationType = actionInfo->type;
+
+ /* RIC Indication Header */
+ idx++;
+ ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationHeader;
+ ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICindicationHeader;
+ if(fillRicIndHeader(&ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader, \
+ ricSubscriptionInfo) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to fill RIC Indication header");
+ return RFAILED;
+ }
+
+ /* RIC Indication Message */
+ idx++;
+ ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationMessage;
+ ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICindicationMessage;
+ if(fillRicIndMsgBuf(&ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage, \
+ actionInfo) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to fill RIC Indication Message");
+ return RFAILED;
+ }
+
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Builds and Send the RicIndication Message
+ *
+ * @details
+ *
+ * Function : BuildAndSendRicIndication
+ *
+ * Functionality:Fills the RicIndication Message
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildAndSendRicIndication(RicSubscription *ricSubscriptionInfo, ActionInfo *actionInfo)
+{
+ uint8_t ret = RFAILED;
+ E2AP_PDU_t *e2apMsg = NULLP;
+ RICindication_t *ricIndicationMsg = NULLP;
+ asn_enc_rval_t encRetVal; /* Encoder return value */
+
+ while(true)
+ {
+ DU_LOG("\nINFO --> E2AP : Building RIC Indication Message\n");
+
+ DU_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;
+ DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ if(e2apMsg->choice.initiatingMessage == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
+ break;
+ }
+ e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICindication;
+ e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
+ e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICindication;
+
+ ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
+
+ if(fillRicIndication(ricIndicationMsg, ricSubscriptionInfo, actionInfo) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to fill RIC Indication message");
+ break;
+ }
+
+ /* Prints the Msg formed */
+ 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 RIC Indication Message (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Indication Message \n");
+#ifdef DEBUG_ASN_PRINT
+ for(int i=0; i< encBufSize; i++)
+ {
+ printf("%x",encBuf[i]);
+ }
+#endif
+ }
+
+ if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
+ {
+ DU_LOG("\nINFO --> E2AP : Sending RIC Indication Message");
+
+ }
+ ret = ROK;
+ break;
+ }
+ FreeRicIndication(e2apMsg);
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief free e2 node component configuration req and rsp
+ *
+ * @details
+ *
+ * Function : freeE2NodeComponentConfiguration
+ *
+ * Functionality:
+ * - free e2 node component configuration req and rsp
+ *
+ * @params[in] E2nodeComponentConfiguration_t *e2nodeComponentConfiguration
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+
+void freeE2NodeComponentConfiguration(E2nodeComponentConfiguration_t *e2nodeComponentConfiguration)
+{
+ /* Free E2 Node Component Request Part */
+ DU_FREE(e2nodeComponentConfiguration->e2nodeComponentRequestPart.buf, e2nodeComponentConfiguration->e2nodeComponentRequestPart.size);
+
+ /* Free E2 Node Component Response Part */
+ DU_FREE(e2nodeComponentConfiguration->e2nodeComponentResponsePart.buf, e2nodeComponentConfiguration->e2nodeComponentResponsePart.size);
+
+}
+
+/*******************************************************************
+ *
+ * @brief free e2 node component component identifier
+ *
+ * @details
+ *
+ * Function : freeE2NodeComponentIdentifier
+ *
+ * Functionality:
+ * - free e2 node component component identifier
+ *
+ * @params[in] E2nodeComponentID_t *componentID
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+
+void freeE2NodeComponentIdentifier(E2nodeComponentID_t *componentID)
+{
+ if(componentID->choice.e2nodeComponentInterfaceTypeF1)
+ {
+ DU_FREE(componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf, componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
+ DU_FREE(componentID->choice.e2nodeComponentInterfaceTypeF1, sizeof(E2nodeComponentInterfaceF1_t));
+ }
+
+}
+
+/*******************************************************************
+ *
+ * @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 FreeE2NodeConfigUpdate(E2AP_PDU_t *e2apMsg)
+{
+ uint8_t arrIdx =0, e2NodeUpdateListIdx=0, e2NodeRemovalListIdx=0, e2NodeAddListIdx=0;
+ E2nodeConfigurationUpdate_t *e2NodeConfigUpdate =NULL;
+ E2nodeComponentConfigUpdate_List_t *e2NodeUpdateList =NULL;
+ E2nodeComponentConfigUpdate_ItemIEs_t *e2NodeUpdateItem =NULL;
+ E2nodeComponentConfigRemoval_List_t *e2NodeRemovalList =NULL;
+ E2nodeComponentConfigRemoval_ItemIEs_t *e2NodeRemovalItem =NULL;
+ E2nodeComponentConfigAddition_List_t *e2NodeAddList =NULL;
+ E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem =NULL;
+
+ if(e2apMsg != NULLP)
+ {
+ if(e2apMsg->choice.initiatingMessage != NULLP)
+ {
+ e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
+ if(e2NodeConfigUpdate->protocolIEs.list.array != NULLP)
+ {
+ for(arrIdx = 0; arrIdx < e2NodeConfigUpdate->protocolIEs.list.count; arrIdx++)
+ {
+ if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx])
+ {
+
+ switch(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id)
+ {
+ case ProtocolIE_IDE2_id_TransactionID:
+ break;
+
+ case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
+ {
+ e2NodeAddList = &e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List;
+ if(e2NodeAddList->list.array)
+ {
+ for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++)
+ {
+ e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[e2NodeAddListIdx];
+
+ freeE2NodeComponentConfiguration(&e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration);
+ freeE2NodeComponentIdentifier(&e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID);
+ DU_FREE(e2NodeAddItem, sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
+ }
+ DU_FREE(e2NodeAddList->list.array, e2NodeAddList->list.size);
+ }
+ break;
+ }
+ case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdate:
+ {
+ e2NodeUpdateList = &e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigUpdate_List;
+ if(e2NodeUpdateList->list.array)
+ {
+ for(e2NodeUpdateListIdx = 0; e2NodeUpdateListIdx< e2NodeUpdateList->list.count; e2NodeUpdateListIdx++)
+ {
+ e2NodeUpdateItem = (E2nodeComponentConfigUpdate_ItemIEs_t *) e2NodeUpdateList->list.array[e2NodeUpdateListIdx];
+
+ freeE2NodeComponentConfiguration(&e2NodeUpdateItem->value.choice.E2nodeComponentConfigUpdate_Item.e2nodeComponentConfiguration);
+ freeE2NodeComponentIdentifier(&e2NodeUpdateItem->value.choice.E2nodeComponentConfigUpdate_Item.e2nodeComponentID);
+ DU_FREE(e2NodeUpdateItem, sizeof(E2nodeComponentConfigUpdate_ItemIEs_t));
+ }
+ DU_FREE(e2NodeUpdateList->list.array, e2NodeUpdateList->list.size);
+ }
+ break;
+ }
+ case ProtocolIE_IDE2_id_E2nodeComponentConfigRemoval:
+ {
+ e2NodeRemovalList = &e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigRemoval_List;
+ if(e2NodeRemovalList->list.array)
+ {
+ for(e2NodeRemovalListIdx = 0; e2NodeRemovalListIdx< e2NodeRemovalList->list.count; e2NodeRemovalListIdx++)
+ {
+ e2NodeRemovalItem = (E2nodeComponentConfigRemoval_ItemIEs_t *) e2NodeRemovalList->list.array[e2NodeRemovalListIdx];
+
+ freeE2NodeComponentIdentifier(&e2NodeRemovalItem->value.choice.E2nodeComponentConfigRemoval_Item.e2nodeComponentID);
+ DU_FREE(e2NodeRemovalItem, sizeof(E2nodeComponentConfigRemoval_ItemIEs_t));
+ }
+ DU_FREE(e2NodeRemovalList->list.array, e2NodeRemovalList->list.size);
+ }
+ break;
+ }
+
+ default:
+ break;
+ }
+ DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
+ }
+ }
+ DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size);
+ }
+ DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ }
+ DU_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
+ *
+ * @params[in]
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t BuildAndSendE2NodeConfigUpdate(E2NodeConfigList *e2NodeList)
+{
+ uint8_t ret = RFAILED;
+ uint8_t arrIdx = 0,elementCnt = 0, transId=0;
+ E2AP_PDU_t *e2apMsg = NULLP;
+ asn_enc_rval_t encRetVal; /* Encoder return value */
+ E2nodeConfigurationUpdate_t *e2NodeConfigUpdate = NULLP;
+
+ DU_LOG("\nINFO --> E2AP : Building E2 Node config update\n");
+ do
+ {
+ DU_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;
+ DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ if(e2apMsg->choice.initiatingMessage == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
+ break;
+ }
+ e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
+ e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
+ e2apMsg->choice.initiatingMessage->value.present = \
+ InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate;
+ e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
+
+ elementCnt =1;
+ if(e2NodeList->addE2NodeCount)
+ elementCnt++;
+ if(e2NodeList->updateE2NodeCount)
+ elementCnt++;
+ if(e2NodeList->removeE2NodeCount)
+ elementCnt++;
+
+ e2NodeConfigUpdate->protocolIEs.list.count = elementCnt;
+ e2NodeConfigUpdate->protocolIEs.list.size = elementCnt * sizeof(E2nodeConfigurationUpdate_IEs_t*);
+ DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size);
+ if(e2NodeConfigUpdate->protocolIEs.list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
+ break;
+ }
+
+ for(arrIdx =0; arrIdx<elementCnt; arrIdx++)
+ {
+ DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
+ if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx] == NULLP)
+ {
+
+ DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
+ break;
+ }
+ }
+
+ if(arrIdx<elementCnt)
+ break;
+
+ arrIdx = 0;
+ e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
+ e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_TransactionID;
+ transId = assignTransactionId();
+ e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
+
+ if(e2NodeList->addE2NodeCount)
+ {
+ arrIdx++;
+ e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition;
+ e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_E2nodeComponentConfigAddition_List;
+ if(BuildE2NodeConfigAddList(&(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List),\
+ ProcedureCodeE2_id_E2nodeConfigurationUpdate, e2NodeList->addE2NodeCount, e2NodeList->addE2Node)!=ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to create E2 Node config list");
+ break;
+ }
+ }
+
+ if(e2NodeList->updateE2NodeCount)
+ {
+ arrIdx++;
+ e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigUpdate;
+ e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_E2nodeComponentConfigUpdate_List;
+ if(BuildE2NodeConfigUpdateList(&e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigUpdate_List,\
+ e2NodeList->updateE2NodeCount, e2NodeList->updateE2Node) != ROK)
+ {
+
+ DU_LOG("\nERROR --> E2AP : Failed to update the E2 node configuration");
+ break;
+ }
+ }
+
+ if(e2NodeList->removeE2NodeCount)
+ {
+ arrIdx++;
+ e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigRemoval;
+ e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_E2nodeComponentConfigRemoval_List;
+ if(BuildE2NodeConfigRemoveList(&e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigRemoval_List,\
+ e2NodeList->removeE2NodeCount, e2NodeList->removeE2Node) != ROK)
+ {
+
+ DU_LOG("\nERROR --> E2AP : Failed to remove the E2 node configuration");
+ break;
+ }
+ }
+
+ /* Prints the Msg formed */
+ 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 E2nodeConfigurationUpdate structure (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2nodeConfigurationUpdate\n");
+#ifdef DEBUG_ASN_PRINT
+ for(int i=0; i< encBufSize; i++)
+ {
+ printf("%x",encBuf[i]);
+ }
+#endif
+ }
+ if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize))
+ {
+ DU_LOG("\nERROR --> E2AP : Sending E2 node config update failed");
+ break;
+ }
+
+ duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
+ duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
+ memcpy(&duCb.e2apDb.e2TimersInfo.e2Timers.e2NodeConfigUpdate.configList, e2NodeList, sizeof(E2NodeConfigList));
+ ret = ROK;
+ break;
+ }while(true);
+
+ FreeE2NodeConfigUpdate(e2apMsg);
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Deallocate the memory allocated for E2ResetRequest msg
+ *
+ * @details
+ *
+ * Function : FreeE2ResetRequest
+ *
+ * Functionality:
+ * - freeing the memory allocated for E2ResetRequest
+ *
+ * @params[in] E2AP_PDU_t *e2apMsg
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+void FreeE2ResetRequest(E2AP_PDU_t *e2apMsg)
+{
+ uint8_t ieIdx =0;
+ ResetRequestE2_t *resetReq = NULLP;
+
+ if(e2apMsg != NULLP)
+ {
+ if(e2apMsg->choice.initiatingMessage != NULLP)
+ {
+ resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
+ if(resetReq->protocolIEs.list.array)
+ {
+ for(ieIdx = 0; ieIdx < resetReq->protocolIEs.list.count; ieIdx++)
+ {
+ DU_FREE(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
+ }
+ DU_FREE(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
+ }
+ DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ }
+ DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Build and send the E2 reset request msg
+ *
+ * @details
+ *
+ * Function : BuildAndSendE2ResetRequest
+ *
+ * Functionality:
+ * - Buld and send the E2 reset request msg to RIC
+ *
+ * @params[in]
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t BuildAndSendE2ResetRequest(E2FailureCause resetCause)
+{
+ uint8_t ieIdx = 0, elementCnt = 0, transId = 0;
+ uint8_t ret = RFAILED;
+ E2AP_PDU_t *e2apMsg = NULLP;
+ ResetRequestE2_t *resetReq = NULLP;
+ asn_enc_rval_t encRetVal; /* Encoder return value */
+
+ DU_LOG("\nINFO --> E2AP : Building E2 Reset Request\n");
+
+ do
+ {
+ DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
+ if(e2apMsg == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation for E2AP-PDU failed");
+ break;
+ }
+
+ e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
+ DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ if(e2apMsg->choice.initiatingMessage == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation for initiatingMessage");
+ break;
+ }
+
+ e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_Reset;
+ e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
+ e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ResetRequestE2;
+ resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
+
+ elementCnt = 2;
+ resetReq->protocolIEs.list.count = elementCnt;
+ resetReq->protocolIEs.list.size = elementCnt * sizeof(ResetRequestIEs_t *);
+
+ DU_ALLOC(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
+ if(!resetReq->protocolIEs.list.array)
+ {
+ DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
+ Reset Request IE array");
+ break;
+ }
+
+ for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
+ {
+ DU_ALLOC(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
+ if(!resetReq->protocolIEs.list.array[ieIdx])
+ {
+ DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
+ Reset Request IE array element");
+ break;
+ }
+ }
+
+ /* In case of failure */
+ if(ieIdx < elementCnt)
+ break;
+
+ ieIdx = 0;
+ resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
+ resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
+ resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_TransactionID;
+ transId = assignTransactionId();
+ resetReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
+
+ ieIdx++;
+ resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_CauseE2;
+ resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_ignore;
+ resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_CauseE2;
+ fillE2Cause(&resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2, resetCause);
+
+ /* Prints the Msg formed */
+ 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 E2SetupRequest structure (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupRequest\n");
+#ifdef DEBUG_ASN_PRINT
+ for(int i=0; i< encBufSize; i++)
+ {
+ printf("%x",encBuf[i]);
+ }
+#endif
+ }
+ if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
+ break;
+ }
+
+ /* In case the message is sent successfully, store the transaction info to
+ * be used when response is received */
+ duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
+ duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
+
+ ret = ROK;
+ break;
+ }while(true);
+
+ /* Free all memory */
+ FreeE2ResetRequest(e2apMsg);
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Deallocate the memory allocated for Reset Response msg
+ *
+ * @details
+ *
+ * Function : freeAperDecodingOfE2ResetRsp
+ *
+ * Functionality:
+ * - freeing the memory allocated for Reset response
+ *
+ * @params[in] ResetResponseE2_t *resetResponse
+ * @return void
+ *
+ * ****************************************************************/
+void freeAperDecodingOfE2ResetRsp(ResetResponseE2_t *resetResponse)
+{
+ uint8_t ieIdx;
+
+ if(resetResponse)
+ {
+ if(resetResponse->protocolIEs.list.array)
+ {
+ for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
+ {
+ if(resetResponse->protocolIEs.list.array[ieIdx])
+ {
+ switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
+ {
+ case ProtocolIE_IDE2_id_TransactionID:
+ break;
+
+ case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
+ break;
+ }
+ free(resetResponse->protocolIEs.list.array[ieIdx]);
+ }
+ }
+ free(resetResponse->protocolIEs.list.array);
+ }
+ }
+}
+
+/******************************************************************
+ *
+ * @brief Processes E2 Reset Response sent by RIC
+ *
+ * @details
+ *
+ * Function : procResetResponse
+ *
+ * Functionality: Processes E2 Reset Response sent by RIC
+ *
+ * @params[in] E2AP_PDU_t ASN decoded E2AP message
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t procResetResponse(E2AP_PDU_t *e2apMsg)
+{
+ uint8_t ieIdx =0, transId;
+ ResetResponseE2_t *resetResponse;
+
+ DU_LOG("\nINFO --> E2AP : E2 Reset Response received");
+ resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;;
+
+ for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
+ {
+ switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
+ {
+ case ProtocolIE_IDE2_id_TransactionID:
+ transId = resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
+ if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) && \
+ (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
+ {
+ memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
+ }
+ else
+ {
+ DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
+ return RFAILED;
+ }
+ break;
+ case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
+ /* As per ORAN WG3 E2AP spec v3.0, section 9.2.2
+ Criticality Diagnostics IE is sent by Near-RT RIC when parts of a received message i.e.
+ Reset Request in this case, have not been comprehended or were missing, or if the message
+ contained logical errors.
+
+ Processing of this ID should be implemented when negative call flows are to be supported.
+ */
+ break;
+ default:
+ DU_LOG("\nERROR --> E2AP : Invalid IE received in E2 Reset Response : %ld",
+ resetResponse->protocolIEs.list.array[ieIdx]->id);
+ break;
+ }
+ }
+
+ freeAperDecodingOfE2ResetRsp(resetResponse);
+ return ROK;
+}
+
+/******************************************************************
+ *
+ * @brief Deallocation of memory allocated by aper decoder for e2 setup Failure
+ *
+ * @details
+ *
+ * Function : freeAperDecodingOfE2SetupFailure
+ *
+ * Functionality: Deallocation of memory allocated by aper decoder for e2
+ * setup Failure
+ *
+ * @params[in] E2setupFailure_t *e2SetupFailure;
+ * @return void
+ *
+ * ****************************************************************/
+void freeAperDecodingOfE2SetupFailure(E2setupFailure_t *e2SetupFailure)
+{
+ uint8_t arrIdx;
+
+ if(e2SetupFailure)
+ {
+ if(e2SetupFailure->protocolIEs.list.array)
+ {
+ for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
+ {
+ if(e2SetupFailure->protocolIEs.list.array[arrIdx])
+ {
+ free(e2SetupFailure->protocolIEs.list.array[arrIdx]);
+ }
+ }
+ free(e2SetupFailure->protocolIEs.list.array);
+ }
+ }
+}
+/******************************************************************
+ *
+ * @brief Processes E2 Setup Failure sent by RIC
+ *
+ * @details
+ *
+ * Function : procE2SetupFailure
+ *
+ * Functionality: Processes E2 Setup failure sent by RIC
+ *
+ * @params[in] E2AP_PDU_t ASN decoded E2AP message
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+void procE2SetupFailure(E2AP_PDU_t *e2apMsg)
+{
+ uint8_t arrIdx =0, transId =0, timerValue=0;
+ E2setupFailure_t *e2SetupFailure;
+
+ DU_LOG("\nINFO --> E2AP : E2 Setup failure received");
+ e2SetupFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure;
+
+ for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
+ {
+ switch(e2SetupFailure->protocolIEs.list.array[arrIdx]->id)
+ {
+ case ProtocolIE_IDE2_id_TransactionID:
+ {
+ transId = e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
+ if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
+ (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
+ {
+ memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
+ }
+ else
+ {
+ DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
+ return ;
+ }
+ break;
+ }
+ case ProtocolIE_IDE2_id_TimeToWaitE2:
+ {
+ timerValue = convertE2WaitTimerEnumToValue(e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
+ if((duChkTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.e2SetupTimer), EVENT_E2_SETUP_TMR)) == FALSE)
+ {
+ duStartTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.e2SetupTimer), EVENT_E2_SETUP_TMR, timerValue);
+ }
+ else
+ {
+ DU_LOG("\nERROR --> E2AP : EVENT_E2_SETUP_TMR timer is already running");
+ return;
+ }
+ break;
+ }
+ }
+ }
+
+ freeAperDecodingOfE2SetupFailure(e2SetupFailure);
+}
+/******************************************************************
+ *
+ * @brief Deallocation of memory allocated by aper decoder for RIC service Query
+ *
+ * @details
+ *
+ * Function : freeAperDecodingOfRicServiceQuery
+ *
+ * Functionality: Deallocation of memory allocated by aper decoder for RIC
+ * service Query
+ *
+ * @params[in] RICserviceQuery_t *ricServiceQuery;
+ * @return void
+ *
+ * ****************************************************************/
+
+void freeAperDecodingOfRicServiceQuery(RICserviceQuery_t *ricServiceQuery)
+{
+ uint8_t arrIdx,ranFuncIdx;
+ RANfunctionsID_List_t *ranFuncAddedList;
+
+ if(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:
+ {
+ ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
+ if(ranFuncAddedList->list.array)
+ {
+ for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
+ {
+ free(ranFuncAddedList->list.array[ranFuncIdx]);
+ }
+ free(ranFuncAddedList->list.array);;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ free(ricServiceQuery->protocolIEs.list.array[arrIdx]);
+ }
+ }
+ free(ricServiceQuery->protocolIEs.list.array);
+ }
+ }
+}
+/*******************************************************************
+ *
+ * @brief Build RanFunction Delete List
+ *
+ * @details
+ *
+ * Function : BuildRanFunctionDeleteList
+ *
+ * Functionality: Build RanFunction Delete List
+ *
+ * @params[in]
+ * RANfunctionsID List
+ * Count of the RAN function
+ * Received RAN function list
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildRanFunctionDeleteList(RANfunctionsID_List_t *deleteList, uint8_t count, RanFuncInfo *recvdRanFunc)
+{
+ uint8_t ranFuncIdx=0;
+ RANfunctionID_ItemIEs_t *delRanFuncItem;
+
+ if(count)
+ {
+ deleteList->list.count = count;
+ deleteList->list.size = deleteList->list.count * sizeof(RANfunctionID_ItemIEs_t*);
+ DU_ALLOC(deleteList->list.array, deleteList->list.size);
+ if(deleteList->list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
+ return RFAILED;
+ }
+ for(ranFuncIdx = 0; ranFuncIdx< deleteList->list.count; ranFuncIdx++)
+ {
+ DU_ALLOC(deleteList->list.array[ranFuncIdx], sizeof(RANfunctionID_ItemIEs_t));
+ if(deleteList->list.array[ranFuncIdx] == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
+ return RFAILED;
+ }
+ delRanFuncItem= (RANfunctionID_ItemIEs_t *) deleteList->list.array[ranFuncIdx];
+ delRanFuncItem->id = ProtocolIE_IDE2_id_RANfunctionID_Item;
+ delRanFuncItem->criticality = CriticalityE2_ignore;
+ delRanFuncItem->value.choice.RANfunctionID_Item.ranFunctionID = recvdRanFunc[ranFuncIdx].id;
+ delRanFuncItem->value.choice.RANfunctionID_Item.ranFunctionRevision = recvdRanFunc[ranFuncIdx].revisionCounter;
+
+ }
+ }
+ return ROK;
+}
+/*******************************************************************
+ *
+ * @brief De Allocate Ric Service Update message
+ *
+ * @details
+ *
+ * Function : FreeRicServiceUpdate
+ *
+ * Functionality: De-Allocating Ric Service Update message
+ *
+ * @params[in] E2AP_PDU_t *e2apMsg
+
+ * @return void
+ *
+ * ****************************************************************/
+
+void FreeRicServiceUpdate(E2AP_PDU_t *e2apMsg)
+{
+ uint8_t arrIdx = 0;
+ uint8_t ranFuncAddListIdx=0, ranFuncDelIdx=0;
+ RICserviceUpdate_t *ricServiceUpdate;
+ RANfunctions_List_t *ranFunctionsList;
+ RANfunction_ItemIEs_t *ranFuncItemIe;
+ RANfunction_Item_t *ranFunItem;
+ RANfunctionsID_List_t *deleteList;
+
+ /* De-allocating Memory */
+ if(e2apMsg != NULLP)
+ {
+ if(e2apMsg->choice.initiatingMessage != NULLP)
+ {
+ ricServiceUpdate = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate;
+ if(ricServiceUpdate->protocolIEs.list.array != NULLP)
+ {
+ for(arrIdx = 0; arrIdx < ricServiceUpdate->protocolIEs.list.count; arrIdx++)
+ {
+ if(ricServiceUpdate->protocolIEs.list.array[arrIdx] != NULLP)
+ {
+ switch(ricServiceUpdate->protocolIEs.list.array[arrIdx]->id)
+ {
+ case ProtocolIE_IDE2_id_TransactionID:
+ break;
+
+ case ProtocolIE_IDE2_id_RANfunctionsAdded:
+ case ProtocolIE_IDE2_id_RANfunctionsModified:
+ {
+ ranFunctionsList = &(ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List);
+ if(ranFunctionsList->list.array)
+ {
+ for(ranFuncAddListIdx= 0; ranFuncAddListIdx< ranFunctionsList->list.count; ranFuncAddListIdx++)
+ {
+ if(ranFunctionsList->list.array[ranFuncAddListIdx])
+ {
+ ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncAddListIdx];
+ ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
+ DU_FREE(ranFunItem->ranFunctionOID.buf, ranFunItem->ranFunctionOID.size);
+ DU_FREE(ranFunItem->ranFunctionDefinition.buf, ranFunItem->ranFunctionDefinition.size);
+ DU_FREE(ranFunctionsList->list.array[ranFuncAddListIdx], sizeof(RANfunction_ItemIEs_t));
+ }
+ }
+ DU_FREE(ranFunctionsList->list.array, ranFunctionsList->list.size);
+ }
+ break;
+ }
+ case ProtocolIE_IDE2_id_RANfunctionsDeleted:
+ {
+ deleteList= &ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
+ if(deleteList->list.array)
+ {
+ for(ranFuncDelIdx = 0; ranFuncDelIdx< deleteList->list.count; ranFuncDelIdx++)
+ {
+ DU_FREE(deleteList->list.array[ranFuncDelIdx], sizeof(RANfunctionID_ItemIEs_t));
+ }
+ DU_FREE(deleteList->list.array, deleteList->list.size);
+
+ }
+ break;
+ }
+ default:
+ DU_LOG("\nERROR --> E2AP: Invalid event at ricServiceUpdate %ld ",\
+ (ricServiceUpdate->protocolIEs.list.array[arrIdx]->id));
+ break;
+ }
+ DU_FREE(ricServiceUpdate->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdate_IEs_t));
+ }
+ }
+ DU_FREE(ricServiceUpdate->protocolIEs.list.array, ricServiceUpdate->protocolIEs.list.size);
+ }
+ DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ }
+ DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Builds and Send the RicServiceUpdateuest
+ *
+ * @details
+ *
+ * Function : BuildAndSendRicServiceUpdate
+ *
+ * Functionality:Fills the RicServiceUpdateuest
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildAndSendRicServiceUpdate(RicServiceUpdate serviceUpdate)
+{
+ uint8_t arrIdx = 0, elementCnt=0;
+ uint8_t transId = 0, ret = RFAILED;
+ bool memAllocFailed =false;
+ E2AP_PDU_t *e2apMsg = NULLP;
+ RICserviceUpdate_t *ricServiceUpdate = NULLP;
+ asn_enc_rval_t encRetVal; /* Encoder return value */
+
+ DU_LOG("\nINFO --> E2AP : Building Ric Service Update\n");
+ do
+ {
+ DU_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;
+ DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ if(e2apMsg->choice.initiatingMessage == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
+ break;
+ }
+ e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
+ e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICserviceUpdate;
+ e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICserviceUpdate;
+ ricServiceUpdate = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate;
+
+ /* For TransId IE, set elementCnt to 1.
+ If there is any item in the RAN function add list, RAN function modification list, or RAN function delete list, increment the elementCnt.*/
+
+ elementCnt =1;
+ if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
+ elementCnt++;
+ if(serviceUpdate.recvRanFuncList.numOfRanFunToBeModified)
+ elementCnt++;
+ if(serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted)
+ elementCnt++;
+
+ ricServiceUpdate->protocolIEs.list.count = elementCnt;
+ ricServiceUpdate->protocolIEs.list.size = elementCnt * sizeof(RICserviceUpdate_IEs_t*);
+
+ /* Initialize the E2Setup members */
+ DU_ALLOC(ricServiceUpdate->protocolIEs.list.array, ricServiceUpdate->protocolIEs.list.size);
+ if(ricServiceUpdate->protocolIEs.list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements");
+ break;
+ }
+
+ for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
+ {
+ DU_ALLOC(ricServiceUpdate->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdate_IEs_t));
+ if(ricServiceUpdate->protocolIEs.list.array[arrIdx] == NULLP)
+ {
+ memAllocFailed = true;
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayIdx [%d]", arrIdx);
+ break;
+ }
+ }
+ if(memAllocFailed == true)
+ break;
+
+ arrIdx = 0;
+
+ /* TransactionID */
+ ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
+ ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
+ if(serviceUpdate.dir == E2_NODE_INITIATED)
+ transId = assignTransactionId();
+ else
+ transId = serviceUpdate.transId;
+ ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
+
+ if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
+ {
+ arrIdx++;
+ ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
+ ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
+ if(BuildRanFunctionAddList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List,\
+ e2apMsg->choice.initiatingMessage->procedureCode, serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded, serviceUpdate.recvRanFuncList.ranFunToBeAdded) !=ROK)
+ {
+ break;
+ }
+ }
+
+ if(serviceUpdate.recvRanFuncList.numOfRanFunToBeModified)
+ {
+ arrIdx++;
+ ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsModified;
+ ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
+ if(BuildRanFunctionAddList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List,
+ e2apMsg->choice.initiatingMessage->procedureCode, serviceUpdate.recvRanFuncList.numOfRanFunToBeModified, serviceUpdate.recvRanFuncList.ranFunToBeModified) !=ROK)
+ {
+ break;
+ }
+ }
+
+ if(serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted)
+ {
+ arrIdx++;
+ ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsDeleted;
+ ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctionsID_List;
+ if(BuildRanFunctionDeleteList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List,\
+ serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted, serviceUpdate.recvRanFuncList.ranFunToBeDeleted) != ROK)
+ {
+ break;
+ }
+ }
+ /* Prints the Msg formed */
+ 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 RicServiceUpdateuest structure (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RicServiceUpdateuest\n");
+#ifdef DEBUG_ASN_PRINT
+ for(int i=0; i< encBufSize; i++)
+ {
+ printf("%x",encBuf[i]);
+ }
+#endif
+ }
+ if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
+ break;
+ }
+ ret = ROK;
+ break;
+ }while(true);
+
+ if(ret == ROK)
+ {
+ if(serviceUpdate.dir == E2_NODE_INITIATED)
+ {
+ duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
+ duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
+ }
+ else
+ {
+ duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].transactionId = transId;
+ duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
+ }
+ duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.dir = serviceUpdate.dir;
+ duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.transId =transId;
+ memcpy(&duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.recvRanFuncList, &serviceUpdate.recvRanFuncList, sizeof(E2TmpRanFunList));
+ }
+ FreeRicServiceUpdate(e2apMsg);
+ return ret;
+}
+/******************************************************************
+ *
+ * @brief Processes RIC service Query sent by RIC
+ *
+ * @details
+ *
+ * Function : procRicServiceQuery
+ *
+ * Functionality: Processes RIC service Query sent by RIC
+ *
+ * @params[in] E2AP_PDU_t ASN decoded E2AP message
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+
+void procRicServiceQuery(E2AP_PDU_t *e2apMsg)
+{
+ ConfigType action;
+ uint16_t arrIdx =0, ranFuncIdx=0,tmpIdx=0;
+ uint16_t id,revisionCcounter;
+ bool tmpArray[MAX_RAN_FUNCTION] = {false};
+ RICserviceQuery_t *ricServiceQuery=NULL;
+ RicServiceUpdate ricUpdate;
+ RANfunctionID_ItemIEs_t *ranFuncAddedItemIe;
+ RANfunctionsID_List_t *ranFuncAddedList;
+
+ DU_LOG("\nINFO --> E2AP : RIC Service Query received");
+ memset(&ricUpdate, 0, sizeof(RicServiceUpdate));
+ ricUpdate.dir = RIC_INITIATED;
+ ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
+
+ for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
+ {
+ switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
+ {
+ /* TODO completing in next patch/gerrit */
+ case ProtocolIE_IDE2_id_TransactionID:
+ {
+ ricUpdate.transId = ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
+ break;
+ }
+
+ case ProtocolIE_IDE2_id_RANfunctionsAccepted:
+ {
+ ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
+ if(ranFuncAddedList->list.array)
+ {
+ for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
+ {
+ if(ranFuncAddedList->list.array[ranFuncIdx])
+ {
+ /* Using the RAN function Id, identify the RAN function to be modified or deleted. */
+
+ ranFuncAddedItemIe = (RANfunctionID_ItemIEs_t*)ranFuncAddedList->list.array[ranFuncIdx];
+ id = ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionID;
+ revisionCcounter = ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionRevision;
+
+ if((id != duCb.e2apDb.ranFunction[id-1].id))
+ {
+ action = CONFIG_DEL;
+ }
+ else if((id == duCb.e2apDb.ranFunction[id-1].id)&&(revisionCcounter!=duCb.e2apDb.ranFunction[id-1].revisionCounter))
+ {
+ action = CONFIG_MOD;
+ }
+
+ if(action == CONFIG_DEL)
+ {
+ ricUpdate.recvRanFuncList.ranFunToBeDeleted[ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted].id = id;
+ ricUpdate.recvRanFuncList.ranFunToBeDeleted[ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted].revisionCounter = revisionCcounter;
+ ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted++;
+ }
+ else if(action == CONFIG_MOD)
+ {
+ ricUpdate.recvRanFuncList.ranFunToBeModified[ricUpdate.recvRanFuncList.numOfRanFunToBeModified].id = id;
+ ricUpdate.recvRanFuncList.ranFunToBeModified[ricUpdate.recvRanFuncList.numOfRanFunToBeModified].revisionCounter = revisionCcounter;
+ ricUpdate.recvRanFuncList.numOfRanFunToBeModified++;
+ }
+
+ /* If any ID is set to true, it means that the ID has been used in either modification or deletion list.
+ * Else we will add the IDs into the added list */
+ tmpArray[id-1] = true;
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ /* Traversing the whole RAN function list in ducb to check if any new Ran function ids have been added. */
+ for(arrIdx =0; arrIdx<MAX_RAN_FUNCTION; arrIdx++)
+ {
+ tmpIdx= ricUpdate.recvRanFuncList.numOfRanFunToBeAdded;
+ if((duCb.e2apDb.ranFunction[arrIdx].id >0)&&(!tmpArray[arrIdx]))
+ {
+ ricUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].id = duCb.e2apDb.ranFunction[arrIdx].id;
+ ricUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].revisionCounter = duCb.e2apDb.ranFunction[arrIdx].revisionCounter;
+ ricUpdate.recvRanFuncList.numOfRanFunToBeAdded++;
+ }
+ }
+
+ if(BuildAndSendRicServiceUpdate(ricUpdate)!= ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to build and send ric service update message");
+ }
+
+ freeAperDecodingOfRicServiceQuery(ricServiceQuery);
+}