+ /* Measurement Type */
+ measInfoItem->measType.present = MeasurementType_PR_measName;
+ measInfoItem->measType.choice.measName.size = strlen(measInfoDb->measurementTypeName);
+
+ DU_ALLOC(measInfoItem->measType.choice.measName.buf, measInfoItem->measType.choice.measName.size);
+ if(!measInfoItem->measType.choice.measName.buf)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
+ return RFAILED;
+ }
+
+ memcpy(measInfoItem->measType.choice.measName.buf, measInfoDb->measurementTypeName,\
+ measInfoItem->measType.choice.measName.size);
+
+ measInfoIdx++;
+ }
+ measInfoNode = measInfoNode->next;
+ measInfoDb = NULLP;
+ }
+
+ return ROK;
+}
+
+ /*******************************************************************
+ *
+ * @brief Fill E2SM-KPM Indication Message Format 1
+ *
+ * @details
+ *
+ * Function : fillE2smKpmIndMsgFormat1
+ *
+ * Functionality: Fill E2SM-KPM Indication Message Format 1
+ *
+ * @param Format 1 Message to be filled
+ * Action Definition format 1 from E2AP DB
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+uint8_t fillE2smKpmIndMsgFormat1(E2SM_KPM_IndicationMessage_Format1_t *format1Msg, ActionDefFormat1 *format1)
+{
+ /* Measurement Data */
+ if(fillMeasData(&format1Msg->measData, &format1->measurementInfoList) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to fill measurement data");
+ return RFAILED;
+ }
+
+ /* Measurement Information */
+ DU_ALLOC(format1Msg->measInfoList, sizeof(MeasurementInfoList_t));
+ if(!format1Msg->measInfoList)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
+ return RFAILED;
+ }
+
+ if(fillMeasInfoList(format1Msg->measInfoList, &format1->measurementInfoList) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to fill measurement information list");
+ return RFAILED;
+ }
+
+ /* Granularity Period */
+ DU_ALLOC(format1Msg->granulPeriod, sizeof(GranularityPeriod_t));
+ if(!format1Msg->granulPeriod)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
+ return RFAILED;
+ }
+ *(format1Msg->granulPeriod) = format1->granularityPeriod;
+
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Fill RIC Indication Message buffer
+ *
+ * @details
+ *
+ * Function : fillRicIndMsgBuf
+ *
+ * Functionality: Fill E2SM-KPM Indication Message
+ * Encode this message and copy to RIC Indication Message buffer
+ *
+ * @param RIC Indication Message buffer to be filled
+ * Source action info from E2AP DB
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+uint8_t fillRicIndMsgBuf(RICindicationMessage_t *ricIndMsgBuf, ActionInfo *actionInfo)
+{
+ uint8_t ret = RFAILED;
+ bool failedInFormat = false;
+ E2SM_KPM_IndicationMessage_t e2smKpmIndMsg;
+ asn_enc_rval_t encRetVal; /* Encoder return value */
+
+ memset(&e2smKpmIndMsg, 0, sizeof(E2SM_KPM_IndicationMessage_t));
+
+ while(true)
+ {
+ /* E2SM-KPM Indication message format type */
+ e2smKpmIndMsg.indicationMessage_formats.present = actionInfo->definition.formatType;
+ switch(e2smKpmIndMsg.indicationMessage_formats.present)
+ {
+ case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format1:
+ {
+ /* E2SM-KPM Indication message format 1 */
+ DU_ALLOC(e2smKpmIndMsg.indicationMessage_formats.choice.indicationMessage_Format1, \
+ sizeof(E2SM_KPM_IndicationMessage_Format1_t));
+ if(!e2smKpmIndMsg.indicationMessage_formats.choice.indicationMessage_Format1)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
+ failedInFormat = true;
+ break;
+ }
+
+ if(fillE2smKpmIndMsgFormat1(e2smKpmIndMsg.indicationMessage_formats.choice.indicationMessage_Format1, \
+ &actionInfo->definition.choice.format1) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to fill E2SM-KPM Indication message format 1");
+ failedInFormat = true;
+ break;
+ }
+ break;
+ }
+
+ case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_NOTHING:
+ case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format2:
+ default:
+ {
+ DU_LOG("\nERROR --> E2AP : fillRicIndMsgBuf: Only Format 1 supported");
+ failedInFormat = true;
+ break;
+ }
+ }
+
+ if(failedInFormat)
+ break;
+
+ /* Encode E2SM-KPM Indication Message */
+ xer_fprint(stdout, &asn_DEF_E2SM_KPM_IndicationMessage, &e2smKpmIndMsg);
+ memset(encBuf, 0, ENC_BUF_MAX_LEN);
+ encBufSize = 0;
+ encRetVal = aper_encode(&asn_DEF_E2SM_KPM_IndicationMessage, 0, &e2smKpmIndMsg, PrepFinalEncBuf, encBuf);
+ if(encRetVal.encoded == ENCODE_FAIL)
+ {
+ DU_LOG("\nERROR --> E2AP : Could not encode E2SM-KPM Indication Message (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 Message \n");
+#ifdef DEBUG_ASN_PRINT
+ for(int i=0; i< encBufSize; i++)
+ {
+ printf("%x",encBuf[i]);
+ }
+#endif
+ }
+
+ /* Copy encoded string to RIC Indication Message buffer */
+ ricIndMsgBuf->size = encBufSize;
+ DU_ALLOC(ricIndMsgBuf->buf, ricIndMsgBuf->size);
+ if(!ricIndMsgBuf->buf)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
+ break;
+ }
+ memset(ricIndMsgBuf->buf, 0, ricIndMsgBuf->size);
+ memcpy(ricIndMsgBuf->buf, encBuf, encBufSize);
+
+ ret = ROK;
+ break;
+ }
+
+ /* Free E2SM-KPM Indication Message */
+ FreeE2smKpmIndicationMessage(&e2smKpmIndMsg);
+
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Free E2SM-KPM Indication Header
+ *
+ * @details
+ *
+ * Function : FreeE2smKpmIndicationHeader
+ *
+ * Functionality: Free E2SM-KPM Indication Header
+ *
+ * @param E2SM-KPM Indication Header to be free
+ * @return void
+ *
+ ******************************************************************/
+void FreeE2smKpmIndicationHeader(E2SM_KPM_IndicationHeader_t *e2smKpmIndHdr)
+{
+ E2SM_KPM_IndicationHeader_Format1_t *format1 = NULLP;
+
+ if(e2smKpmIndHdr)
+ {
+ switch(e2smKpmIndHdr->indicationHeader_formats.present)
+ {
+ case E2SM_KPM_IndicationHeader__indicationHeader_formats_PR_indicationHeader_Format1:
+ {
+ if(e2smKpmIndHdr->indicationHeader_formats.choice.indicationHeader_Format1)
+ {
+ format1 = e2smKpmIndHdr->indicationHeader_formats.choice.indicationHeader_Format1;
+
+ DU_FREE(format1->colletStartTime.buf, format1->colletStartTime.size);
+ DU_FREE(format1, sizeof(E2SM_KPM_IndicationHeader_Format1_t));
+ }
+ break;
+ }
+ case E2SM_KPM_IndicationHeader__indicationHeader_formats_PR_NOTHING:
+ default:
+ break;
+ }
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Fill RIC Indication Header buffer
+ *
+ * @details
+ *
+ * Function : fillRicIndHeader
+ *
+ * Functionality: Fill E2SM-KPM Indication Header
+ * Encode this message and copy to RIC Indication Header buffer
+ *
+ * @param RIC Indication Header buffer to be filled
+ * Source RIC subscription info from E2AP DB
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+uint8_t fillRicIndHeader(RICindicationHeader_t *ricIndHdr, RicSubscription *ricSubsInfo)
+{
+ uint8_t ret = RFAILED;
+ uint8_t secBufIdx = 0, milliSecBufIdx = 0;
+ int8_t byteIdx = 0;
+ bool formatFailure = false;
+ RanFunction *ranFunc = NULLP;
+ ReportStartTime *startTime = NULLP;
+ E2SM_KPM_IndicationHeader_t e2smKpmIndHdr;
+ E2SM_KPM_IndicationHeader_Format1_t *format1 = NULLP;
+ asn_enc_rval_t encRetVal; /* Encoder return value */
+
+ while(true)
+ {
+ ranFunc = fetchRanFuncFromRanFuncId(ricSubsInfo->ranFuncId);
+ if(ranFunc == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : RAN Function ID [%d] not found", ricSubsInfo->ranFuncId);
+ break;
+ }
+
+ memset(&e2smKpmIndHdr, 0, sizeof(E2SM_KPM_IndicationHeader_t));
+
+ e2smKpmIndHdr.indicationHeader_formats.present = ranFunc->ricIndicationHeaderFormat;
+ switch(e2smKpmIndHdr.indicationHeader_formats.present)
+ {
+ case E2SM_KPM_IndicationHeader__indicationHeader_formats_PR_indicationHeader_Format1:
+ {
+ DU_ALLOC(e2smKpmIndHdr.indicationHeader_formats.choice.indicationHeader_Format1, \
+ sizeof(E2SM_KPM_IndicationHeader_Format1_t));
+ if(!e2smKpmIndHdr.indicationHeader_formats.choice.indicationHeader_Format1)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
+ formatFailure = true;
+ break;
+ }
+ format1 = e2smKpmIndHdr.indicationHeader_formats.choice.indicationHeader_Format1;
+
+ /* Fetch reporting period start time from DB */
+ switch(ricSubsInfo->eventTriggerDefinition.formatType)
+ {
+ case 1:
+ {
+ startTime = &ricSubsInfo->eventTriggerDefinition.choice.format1.startTime;
+ }
+ }
+
+ format1->colletStartTime.size = 8 * sizeof(uint8_t);
+ DU_ALLOC(format1->colletStartTime.buf, format1->colletStartTime.size);
+ if(!format1->colletStartTime.buf)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
+ formatFailure = true;
+ break;
+ }
+
+ /* As per O-RAN.WG3.E2SM-KPM-R003-v03.00, section 8.3.12 and
+ * RFC 5905, section 6 :
+ * Time stamp has a 64-bit format where first 32-bit is seconds
+ * and next 32-bit is fraction in picosecond-level.
+ * This fraction has been rounded in microseconds.
+ *
+ * Hence,
+ * Storing 32-bit seconds at MSB 0-3 and
+ * 32-bit milliseconds at next 4 bytes i.e. bytes 4-7
+ */
+ secBufIdx = 0;
+ milliSecBufIdx = 4;
+ for(byteIdx = 3; byteIdx >= 0; byteIdx--)
+ {
+ format1->colletStartTime.buf[secBufIdx++] = startTime->timeInSec >> (8*byteIdx);
+ format1->colletStartTime.buf[milliSecBufIdx++] = startTime->timeInMilliSec >> (8*byteIdx);
+ }
+ break;
+ }
+
+ case E2SM_KPM_IndicationHeader__indicationHeader_formats_PR_NOTHING:
+ default:
+ {
+ DU_LOG("\nERROR --> E2AP : Only E2SM-KPM Indication Header Format 1 supported");
+ formatFailure = true;
+ break;
+ }
+ }
+
+ 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]
+ * Reset cause
+ * @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 reset request structure (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for reset request\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 void
+ *
+ * ****************************************************************/
+void procResetResponse(E2AP_PDU_t *e2apMsg)
+{
+ bool invalidTransId=false;
+ uint8_t ieIdx =0, transId =0;
+ uint16_t ranFuncIdx=0;
+ ResetResponseE2_t *resetResponse =NULLP;
+
+ 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);
+ invalidTransId = true;
+ }
+ break;
+ }
+ case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
+ {
+ for(ranFuncIdx=0; ranFuncIdx<MAX_RAN_FUNCTION; ranFuncIdx++)
+ {
+ if(duCb.e2apDb.ranFunction[ranFuncIdx].id >0)
+ {
+ deleteRicSubscriptionList(&(duCb.e2apDb.ranFunction[ranFuncIdx].subscriptionList));
+ memset(&(duCb.e2apDb.ranFunction[ranFuncIdx].pendingSubsRspInfo), 0, MAX_PENDING_SUBSCRIPTION_RSP*sizeof(PendingSubsRspInfo));
+ }
+ }
+ break;
+ }
+ default:
+ {
+ DU_LOG("\nERROR --> E2AP : Invalid IE received in E2 Reset Response : %ld",
+ resetResponse->protocolIEs.list.array[ieIdx]->id);
+ break;
+ }
+ }
+
+ if(invalidTransId == true)
+ {
+ break;
+ }
+ }
+
+ freeAperDecodingOfE2ResetRsp(resetResponse);
+}
+
+/******************************************************************
+ *
+ * @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.*/