+/*******************************************************************
+ *
+ * @brief De Allocate E2 Setup Request Message
+ *
+ * @details
+ *
+ * Function : FreeE2SetupReq
+ *
+ * Functionality: De-Allocating E2 Setup request Message
+ *
+ * @params[in] E2AP_PDU_t *e2apMsg
+
+ * @return void
+ *
+ * ****************************************************************/
+
+void FreeE2SetupReq(E2AP_PDU_t *e2apMsg)
+{
+ uint8_t arrIdx = 0;
+ uint8_t e2NodeAddListIdx =0, ranFuncAddListIdx;
+ E2setupRequest_t *e2SetupReq;
+ E2nodeComponentConfigAddition_List_t *e2NodeAddList;
+ E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem;
+ RANfunctions_List_t *ranFunctionsList;
+ RANfunction_ItemIEs_t *ranFuncItemIe;
+ RANfunction_Item_t *ranFunItem;
+
+ /* De-allocating Memory */
+ if(e2apMsg != NULLP)
+ {
+ if(e2apMsg->choice.initiatingMessage != NULLP)
+ {
+ e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
+ if(e2SetupReq->protocolIEs.list.array != NULLP)
+ {
+ for(arrIdx = 0; arrIdx < e2SetupReq->protocolIEs.list.count; arrIdx++)
+ {
+ if(e2SetupReq->protocolIEs.list.array[arrIdx] != NULLP)
+ {
+ switch(e2SetupReq->protocolIEs.list.array[arrIdx]->id)
+ {
+ case ProtocolIE_IDE2_id_TransactionID:
+ break;
+ case ProtocolIE_IDE2_id_GlobalE2node_ID:
+ {
+ if(e2SetupReq->protocolIEs.list.array[arrIdx]->\
+ value.choice.GlobalE2node_ID.choice.gNB != NULLP)
+ {
+ GlobalE2node_gNB_ID_t *gNbId = NULLP;
+ gNbId = e2SetupReq->protocolIEs.list.array[arrIdx]->\
+ value.choice.GlobalE2node_ID.choice.gNB;
+ if(gNbId->global_gNB_ID.plmn_id.buf != NULLP)
+ {
+ DU_FREE(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf,\
+ gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
+ DU_FREE(gNbId->global_gNB_ID.plmn_id.buf,\
+ gNbId->global_gNB_ID.plmn_id.size);
+ }
+
+ if(gNbId->gNB_DU_ID != NULLP)
+ {
+ DU_FREE( gNbId->gNB_DU_ID->buf, gNbId->gNB_DU_ID->size);
+ DU_FREE(gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
+ }
+ DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
+ choice.GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
+ }
+ break;
+ }
+ case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
+ {
+ e2NodeAddList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List;
+ if(e2NodeAddList->list.array)
+ {
+ for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++)
+ {
+ e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[e2NodeAddListIdx];
+
+ /* Free E2 Node Component Request Part */
+ DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
+ e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
+
+ /* Free E2 Node Component Response Part */
+ DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.\
+ e2nodeComponentResponsePart.buf, \
+ e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
+
+ /* Free E2 Node Component ID */
+ if(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1)
+ {
+ DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
+ e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
+ e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
+ e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
+ DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
+ sizeof(E2nodeComponentInterfaceF1_t));
+ }
+ DU_FREE(e2NodeAddList->list.array[e2NodeAddListIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
+ }
+ DU_FREE(e2NodeAddList->list.array, e2NodeAddList->list.size);
+ }
+ break;
+ }
+ case ProtocolIE_IDE2_id_RANfunctionsAdded:
+ {
+ ranFunctionsList = &(e2SetupReq->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;
+ }
+
+ default:
+ DU_LOG("\nERROR --> E2AP: Invalid event at e2SetupRequet %ld ",\
+ (e2SetupReq->protocolIEs.list.array[arrIdx]->id));
+ break;
+ }
+ DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx], sizeof(E2setupRequestIEs_t));
+ }
+ }
+ DU_FREE(e2SetupReq->protocolIEs.list.array, e2SetupReq->protocolIEs.list.size);
+ }
+ DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ }
+ DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Builds and Send the E2SetupRequest
+ *
+ * @details
+ *
+ * Function : BuildAndSendE2SetupReq
+ *
+ * Functionality:Fills the E2SetupRequest
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildAndSendE2SetupReq()
+{
+ uint8_t arrIdx = 0, elementCnt=0;
+ uint8_t transId = 0, ret = RFAILED;
+ bool memAllocFailed = false;
+ E2AP_PDU_t *e2apMsg = NULLP;
+ E2setupRequest_t *e2SetupReq = NULLP;
+ asn_enc_rval_t encRetVal; /* Encoder return value */
+
+ DU_LOG("\nINFO --> E2AP : Building E2 Setup Request\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_E2setup;
+ e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_E2setupRequest;
+ e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
+
+ elementCnt = 4;
+ e2SetupReq->protocolIEs.list.count = elementCnt;
+ e2SetupReq->protocolIEs.list.size = elementCnt * sizeof(E2setupRequestIEs_t*);
+
+ /* Initialize the E2Setup members */
+ DU_ALLOC(e2SetupReq->protocolIEs.list.array, \
+ e2SetupReq->protocolIEs.list.size);
+ if(e2SetupReq->protocolIEs.list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements");
+ break;
+ }
+ for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
+ {
+ DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx],\
+ sizeof(E2setupRequestIEs_t));
+ if(e2SetupReq->protocolIEs.list.array[arrIdx] == NULLP)
+ {
+ memAllocFailed = true;
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayarrIdx [%d]", arrIdx);
+ break;
+ }
+ }
+ if(memAllocFailed == true)
+ break;
+
+ arrIdx = 0;
+
+ /* TransactionID */
+ e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
+ e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
+ transId = assignTransactionId();
+ e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
+
+ arrIdx++;
+ /* GlobalE2node_gNB_ID */
+ e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_GlobalE2node_ID;
+ e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
+ e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
+
+ DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
+ GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
+ if(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
+ GlobalE2node_ID.choice.gNB == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed for gNbId");
+ break;
+ }
+ else
+ {
+ ret = BuildGlobalgNBId(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
+ choice.GlobalE2node_ID.choice.gNB);
+ if(ret != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to build Global Gnb Id");
+ break;
+ }
+ }
+
+ /* RAN Functions Added List */
+ arrIdx++;
+ e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
+ e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_RANfunctions_List;
+ if(BuildRanFunctionAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List), ProcedureCodeE2_id_E2setup, 0, NULL)!=ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to create RAN Function");
+ break;
+ }
+
+ /* E2 Node Component Configuration Addition List */
+ arrIdx++;
+ e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition;
+ e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_E2nodeComponentConfigAddition_List;
+ if(BuildE2NodeConfigAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List), ProcedureCodeE2_id_E2setup, 0, NULL)!=ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to create E2 Node config list");
+ 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 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;
+ }while(true);
+
+ duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
+ duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
+
+ FreeE2SetupReq(e2apMsg);
+ return ret;
+}/* End of BuildAndSendE2SetupReq */
+
+/*******************************************************************
+ *
+ * @brief Builds RIC Action Admitted List
+ *
+ * @details
+ *
+ * Function : BuildRicActionAdmitList
+ *
+ * Functionality: Builds RIC Action Admitted List
+ *
+ * @params[in] Pointer to RIC Action Admitted List to be filled
+ * Subscription Response information
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t BuildRicActionAdmitList(RICaction_Admitted_List_t *admitList, PendingSubsRspInfo *subsRspInfo)
+{
+ uint8_t idx = 0;
+ uint8_t elementCnt = 0;
+ RICaction_Admitted_ItemIEs_t *admitItem = NULLP;
+
+ elementCnt = subsRspInfo->numOfAcceptedActions;
+
+ admitList->list.count = elementCnt;
+ admitList->list.size = elementCnt * sizeof(RICaction_Admitted_ItemIEs_t *);
+
+ DU_ALLOC(admitList->list.array, admitList->list.size);
+ if(admitList->list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
+ return RFAILED;
+ }
+
+ for(idx=0; idx<elementCnt; idx++)
+ {
+ DU_ALLOC(admitList->list.array[idx], sizeof(RICaction_Admitted_ItemIEs_t));
+ if(admitList->list.array[idx] == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
+ return RFAILED;
+ }
+
+ admitItem = (RICaction_Admitted_ItemIEs_t *)admitList->list.array[idx];
+ admitItem->id = ProtocolIE_IDE2_id_RICaction_Admitted_Item;
+ admitItem->criticality = CriticalityE2_reject;
+ admitItem->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
+ admitItem->value.choice.RICaction_Admitted_Item.ricActionID = subsRspInfo->acceptedActionList[idx];
+ }
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Builds RIC Action Not Admitted List
+ *
+ * @details
+ *
+ * Function : BuildRicActionNotAdmitList
+ *
+ * Functionality: Builds RIC Action Not Admitted List
+ *
+ * @params[in] Pointer to RIC Action Not Admitted List to be filled
+ * Subscription Response information
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t BuildRicActionNotAdmitList(RICaction_NotAdmitted_List_t *notAdmitList, PendingSubsRspInfo *subsRspInfo)
+{
+ uint8_t idx = 0;
+ uint8_t elementCnt = 0;
+ RICaction_NotAdmitted_ItemIEs_t *notAdmitItem = NULLP;
+
+ elementCnt = subsRspInfo->numOfRejectedActions;
+
+ notAdmitList->list.count = elementCnt;
+ notAdmitList->list.size = elementCnt * sizeof(RICaction_NotAdmitted_ItemIEs_t *);
+
+ DU_ALLOC(notAdmitList->list.array, notAdmitList->list.size);
+ if(notAdmitList->list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
+ return RFAILED;
+ }
+
+ for(idx=0; idx<elementCnt; idx++)
+ {
+ DU_ALLOC(notAdmitList->list.array[idx], sizeof(RICaction_NotAdmitted_ItemIEs_t));
+ if(notAdmitList->list.array[idx] == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
+ return RFAILED;
+ }
+
+ notAdmitItem = (RICaction_NotAdmitted_ItemIEs_t *)notAdmitList->list.array[idx];
+ notAdmitItem->id = ProtocolIE_IDE2_id_RICaction_NotAdmitted_Item;
+ notAdmitItem->criticality = CriticalityE2_reject;
+ notAdmitItem->value.present = RICaction_NotAdmitted_ItemIEs__value_PR_RICaction_NotAdmitted_Item;
+ notAdmitItem->value.choice.RICaction_NotAdmitted_Item.ricActionID = \
+ subsRspInfo->rejectedActionList[idx].id;
+ fillE2Cause(¬AdmitItem->value.choice.RICaction_NotAdmitted_Item.cause, \
+ subsRspInfo->rejectedActionList[idx].failureCause);
+ }
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @breif Deallocation of BuildAndSendRicSubscriptionRsp memory
+ *
+ * @details
+ *
+ * Function : FreeRicSubscriptionRsp
+ *
+ * Functionality:Free the RicSubscriptionRsp
+ *
+ * @param[in] E2AP_PDU_t *e2apRicMsg
+ *
+ * @return void
+ *
+ ******************************************************************/
+void FreeRicSubscriptionRsp(E2AP_PDU_t *e2apRicMsg)
+{
+ RICsubscriptionResponse_t *ricSubscriptionRsp= NULLP;
+ uint8_t idx=0;
+ uint8_t listIdx=0;
+ RICaction_Admitted_List_t *admitList = NULLP;
+ RICaction_NotAdmitted_List_t *notAdmitList = NULLP;
+
+ if(e2apRicMsg != NULLP)
+ {
+ if(e2apRicMsg->choice.successfulOutcome != NULLP)
+ {
+ ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
+ if(ricSubscriptionRsp)
+ {
+ if(ricSubscriptionRsp->protocolIEs.list.array != NULLP)
+ {
+ for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
+ {
+ if(ricSubscriptionRsp->protocolIEs.list.array[idx] != NULLP)
+ {
+ switch(ricSubscriptionRsp->protocolIEs.list.array[idx]->id)
+ {
+ case ProtocolIE_IDE2_id_RICactions_Admitted:
+ {
+ admitList = &ricSubscriptionRsp->protocolIEs.list.\
+ array[idx]->value.choice.RICaction_Admitted_List;
+ if(admitList->list.array != NULLP)
+ {
+ for(listIdx=0 ; listIdx < admitList->list.count; listIdx++)
+ {
+ DU_FREE(admitList->list.array[listIdx], sizeof(RICaction_Admitted_ItemIEs_t));
+ }
+ DU_FREE(admitList->list.array, admitList->list.size);
+ }
+ break;
+ }
+ case ProtocolIE_IDE2_id_RICactions_NotAdmitted:
+ {
+ notAdmitList = &ricSubscriptionRsp->protocolIEs.list.\
+ array[idx]->value.choice.RICaction_NotAdmitted_List;
+ if(notAdmitList->list.array != NULLP)
+ {
+ for(listIdx=0 ; listIdx < notAdmitList->list.count; listIdx++)
+ {
+ DU_FREE(notAdmitList->list.array[listIdx], sizeof(RICaction_NotAdmitted_ItemIEs_t));
+ }
+ DU_FREE(notAdmitList->list.array, notAdmitList->list.size);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ DU_FREE(ricSubscriptionRsp->protocolIEs.list.array[idx], sizeof(RICsubscriptionResponse_IEs_t));
+ }
+ }
+ DU_FREE(ricSubscriptionRsp->protocolIEs.list.array, ricSubscriptionRsp->protocolIEs.list.size);
+ }
+ }
+ DU_FREE(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
+ }
+ DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Fill RIC Subscription Response IEs
+ *
+ * @details
+ *
+ * Function : fillRicSubscriptionRsp
+ *
+ * functionality: Fill RIC Subscription Response IEs
+ *
+ * @param Pointer to RIC subscription response
+ * Subscription response information
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+uint8_t fillRicSubscriptionRsp(RICsubscriptionResponse_t *ricSubscriptionRsp, PendingSubsRspInfo *subsRspInfo)
+{
+ uint8_t ieIdx = 0;
+ uint8_t elementCnt = 0;
+ RICsubscriptionResponse_IEs_t *subsRspIe = NULLP;
+
+ elementCnt = 3;
+ if(subsRspInfo->numOfRejectedActions)
+ elementCnt++;
+
+ ricSubscriptionRsp->protocolIEs.list.count = elementCnt;
+ ricSubscriptionRsp->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionResponse_IEs_t);
+ DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array, ricSubscriptionRsp->protocolIEs.list.size);
+ if(ricSubscriptionRsp->protocolIEs.list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed at %s : line %d", __func__, __LINE__);
+ return RFAILED;
+ }
+
+ for(ieIdx=0; ieIdx<ricSubscriptionRsp->protocolIEs.list.count; ieIdx++)
+ {
+ DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array[ieIdx], sizeof(RICsubscriptionResponse_IEs_t));
+ if(ricSubscriptionRsp->protocolIEs.list.array[ieIdx] == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d] : ieIdx [%d]", __func__, __LINE__,ieIdx);
+ return RFAILED;
+ }
+ }
+
+ /* RIC Request ID */
+ ieIdx=0;
+ subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
+ subsRspIe->id = ProtocolIE_IDE2_id_RICrequestID;
+ subsRspIe->criticality = CriticalityE2_reject;
+ subsRspIe->value.present = RICsubscriptionRequest_IEs__value_PR_RICrequestID;
+ subsRspIe->value.choice.RICrequestID.ricRequestorID = subsRspInfo->requestId.requestorId;
+ subsRspIe->value.choice.RICrequestID.ricInstanceID = subsRspInfo->requestId.instanceId;
+
+ /* RAN Function ID */
+ ieIdx++;
+ subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
+ subsRspIe->id = ProtocolIE_IDE2_id_RANfunctionID;
+ subsRspIe->criticality = CriticalityE2_reject;
+ subsRspIe->value.present = RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
+ subsRspIe->value.choice.RANfunctionID = subsRspInfo->ranFuncId;
+
+ /* RIC Action Admitted List */
+ ieIdx++;
+ subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
+ subsRspIe->id = ProtocolIE_IDE2_id_RICactions_Admitted;
+ subsRspIe->criticality = CriticalityE2_reject;
+ subsRspIe->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
+ if(BuildRicActionAdmitList(&subsRspIe->value.choice.RICaction_Admitted_List, subsRspInfo) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to fill RIC Action Admitted List in RIC Subscription Response");
+ return RFAILED;
+ }
+
+ /* RIC Action Not Admitted List */
+ if(subsRspInfo->numOfRejectedActions)
+ {
+ ieIdx++;
+ subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
+ subsRspIe->id = ProtocolIE_IDE2_id_RICactions_NotAdmitted;
+ subsRspIe->criticality = CriticalityE2_reject;
+ subsRspIe->criticality = CriticalityE2_reject;
+ subsRspIe->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_NotAdmitted_List;
+ if(BuildRicActionNotAdmitList(&subsRspIe->value.choice.RICaction_NotAdmitted_List, subsRspInfo) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to fill RIC Action Not Admitted List in RIC Subscription Response");
+ return RFAILED;
+ }
+ }
+
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Builds and Send the RicSubscriptionRsp
+ *
+ * @details
+ *
+ * Function : BuildAndSendRicSubscriptionRsp
+ *
+ * Functionality:Fills the RicSubscriptionRsp
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildAndSendRicSubscriptionRsp(PendingSubsRspInfo *subsRspInfo)
+{
+ uint8_t ret = RFAILED;
+ E2AP_PDU_t *e2apRicMsg = NULLP;
+ RICsubscriptionResponse_t *ricSubscriptionRsp=NULLP;
+ asn_enc_rval_t encRetVal;
+
+ while(true)
+ {
+ DU_LOG("\nINFO --> E2AP : Building RIC Subscription Response\n");
+
+ DU_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t));
+ if(e2apRicMsg == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
+ break;
+ }
+
+ e2apRicMsg->present = E2AP_PDU_PR_successfulOutcome;
+ DU_ALLOC(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
+ if(e2apRicMsg->choice.successfulOutcome == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for RIC subscription Response failed");
+ break;
+ }
+
+ e2apRicMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
+ e2apRicMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
+ e2apRicMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse;
+
+ ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
+
+ if(fillRicSubscriptionRsp(ricSubscriptionRsp, subsRspInfo) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for RICsubscriptionResponseIE failed");
+ break;
+ }
+
+ /* Prints the Msg formed */
+ xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg);
+
+ memset(encBuf, 0, ENC_BUF_MAX_LEN);
+ encBufSize = 0;
+ encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apRicMsg, PrepFinalEncBuf, encBuf);
+ if(encRetVal.encoded == ENCODE_FAIL)
+ {
+ DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Response structure (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC subscription response \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 RIC Subscription Response failed");
+ break;
+ }
+
+ ret = ROK;
+ break;
+
+ }
+
+ FreeRicSubscriptionRsp(e2apRicMsg);
+ return ret;
+}
+
+/******************************************************************
+ *
+ * @brief Deallocation of memory allocated by aper decoder for e2 setup response
+ *
+ * @details
+ *
+ * Function : freeAperDecodingOfE2SetupRsp
+ *
+ * Functionality: Deallocation of memory allocated by aper decoder for e2
+ * setup response
+ *
+ * @params[in] E2setupResponse_t *e2SetRspMsg;
+ * @return void
+ *
+ * ****************************************************************/
+void freeAperDecodingOfE2SetupRsp(E2setupResponse_t *e2SetRspMsg)
+{
+ uint8_t arrIdx, e2NodeConfigAddAckListIdx;
+ E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem;
+ E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAddAckList;
+
+ if(e2SetRspMsg)
+ {
+ if(e2SetRspMsg->protocolIEs.list.array)
+ {
+ for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
+ {
+ if(e2SetRspMsg->protocolIEs.list.array[arrIdx])
+ {
+ switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
+ {
+ case ProtocolIE_IDE2_id_TransactionID:
+ break;
+
+ case ProtocolIE_IDE2_id_GlobalRIC_ID:
+ {
+ free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.pLMN_Identity.buf);
+ free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID.buf);
+ break;
+ }
+
+ case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
+ {
+ e2NodeConfigAddAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
+ if(e2NodeConfigAddAckList->list.array )
+ {
+ for(e2NodeConfigAddAckListIdx = 0; e2NodeConfigAddAckListIdx< e2NodeConfigAddAckList->list.count; e2NodeConfigAddAckListIdx++)
+ {
+ if(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx])
+ {
+ e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx];
+ free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
+ e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf);
+ free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
+ e2nodeComponentInterfaceTypeF1);
+ free(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx]);
+ }
+ }
+ free(e2NodeConfigAddAckList->list.array);
+ }
+ break;
+ }
+ }
+ free(e2SetRspMsg->protocolIEs.list.array[arrIdx]);
+ }
+ }
+ free(e2SetRspMsg->protocolIEs.list.array);
+ }
+ }
+}
+
+/******************************************************************
+ *
+ * @brief handling of e2 noe config update ack ies
+ *
+ * @details
+ *
+ * Function :handleE2NodeConfigUpdateAckIes
+ *
+ * Functionality: handling of e2 noe config update ack ies
+ *
+ * @params[in]
+ * Pointer to the E2 Node cfg
+ * Procedure code
+ * @return void
+******************************************************************/
+
+void handleE2NodeConfigUpdateAckIes(PTR e2NodeCfg, uint8_t procedureCode)
+{
+ CmLList *node=NULLP;
+ E2NodeComponent *e2NodeComponentInfo=NULLP;
+ E2nodeComponentID_t *e2nodeComponentID=NULLP;
+ E2nodeComponentConfigRemovalAck_Item_t *removalAckItem=NULLP;
+ E2nodeComponentConfigUpdateAck_Item_t *updateAckItem=NULLP;
+ E2nodeComponentConfigAdditionAck_Item_t *additionAckItem=NULLP;
+
+ switch(procedureCode)
+ {
+ case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
+ {
+ additionAckItem = (E2nodeComponentConfigAdditionAck_Item_t *)e2NodeCfg;
+ e2nodeComponentID = &additionAckItem->e2nodeComponentID;
+ break;
+ }
+ case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdateAck:
+ {
+ updateAckItem = (E2nodeComponentConfigUpdateAck_Item_t*) e2NodeCfg;
+ e2nodeComponentID = &updateAckItem->e2nodeComponentID;
+ break;
+ }
+ case ProtocolIE_IDE2_id_E2nodeComponentConfigRemovalAck:
+ {
+ removalAckItem= (E2nodeComponentConfigRemovalAck_Item_t*)e2NodeCfg;
+ e2nodeComponentID = &removalAckItem->e2nodeComponentID;
+ break;
+ }
+ }
+
+ switch(e2nodeComponentID->present)
+ {
+ case E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1:
+ {
+ e2NodeComponentInfo = fetchE2NodeComponentInfo(F1, e2nodeComponentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[0], &node);
+ if(!e2NodeComponentInfo)
+ {
+ DU_LOG("\nERROR --> E2AP : Received null e2NodeComponentInfo at line number %d",__LINE__);
+ return;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ switch(procedureCode)
+ {
+ case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
+ {
+ DU_FREE(e2NodeComponentInfo->addConfiguration->componentRequestPart, e2NodeComponentInfo->addConfiguration->reqBufSize);
+ DU_FREE(e2NodeComponentInfo->addConfiguration->componentResponsePart, e2NodeComponentInfo->addConfiguration->rspBufSize);
+ DU_FREE(e2NodeComponentInfo->addConfiguration, sizeof(E2NodeConfig));
+ break;
+ }
+ case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdateAck:
+ {
+ DU_FREE(e2NodeComponentInfo->updateConfiguration->componentRequestPart, e2NodeComponentInfo->updateConfiguration->reqBufSize);
+ DU_FREE(e2NodeComponentInfo->updateConfiguration->componentResponsePart, e2NodeComponentInfo->updateConfiguration->rspBufSize);
+ DU_FREE(e2NodeComponentInfo->updateConfiguration, sizeof(E2NodeConfig));
+ break;
+ }
+ case ProtocolIE_IDE2_id_E2nodeComponentConfigRemovalAck:
+ {
+ cmLListDelFrm(&duCb.e2apDb.e2NodeComponentList, node);
+ if(e2NodeComponentInfo->addConfiguration)
+ {
+ DU_FREE(e2NodeComponentInfo->addConfiguration->componentRequestPart, e2NodeComponentInfo->addConfiguration->reqBufSize);
+ DU_FREE(e2NodeComponentInfo->addConfiguration->componentResponsePart, e2NodeComponentInfo->addConfiguration->rspBufSize);
+ DU_FREE(e2NodeComponentInfo->addConfiguration, sizeof(E2NodeConfig));
+ }
+ if(e2NodeComponentInfo->updateConfiguration)
+ {
+ DU_FREE(e2NodeComponentInfo->updateConfiguration->componentRequestPart, e2NodeComponentInfo->updateConfiguration->reqBufSize);
+ DU_FREE(e2NodeComponentInfo->updateConfiguration->componentResponsePart, e2NodeComponentInfo->updateConfiguration->rspBufSize);
+ DU_FREE(e2NodeComponentInfo->updateConfiguration, sizeof(E2NodeConfig));
+ }
+ DU_FREE(node, sizeof(CmLList));
+ break;
+ }
+ }
+}
+
+/******************************************************************
+ *
+ * @brief Processes E2 Setup Response sent by RIC
+ *
+ * @details
+ *
+ * Function : procE2SetupRsp
+ *
+ * Functionality: Processes E2 Setup Response sent by RIC
+ *
+ * @params[in] E2AP_PDU_t ASN decoded E2AP message
+ * @return void
+ *
+ * ****************************************************************/
+
+void procE2SetupRsp(E2AP_PDU_t *e2apMsg)
+{
+ bool invalidTransId = false;
+ uint8_t arrIdx =0, transId=0, idx=0;
+ uint32_t recvBufLen;
+ E2setupResponse_t *e2SetRspMsg=NULL;
+ E2nodeComponentConfigAdditionAck_List_t *e2NodeCfgAckList=NULL;
+ E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem=NULL;
+
+ DU_LOG("\nINFO --> E2AP : E2 Setup Response received");
+ duCb.e2Status = TRUE; //Set E2 status as true
+ e2SetRspMsg = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
+
+ for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
+ {
+ switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
+ {
+ case ProtocolIE_IDE2_id_TransactionID:
+ {
+ transId = e2SetRspMsg->protocolIEs.list.array[arrIdx]->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_GlobalRIC_ID:
+ {
+ /* To store the Ric Id Params */
+ recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value\
+ .choice.GlobalRIC_ID.pLMN_Identity.size);
+ memcpy(&duCb.e2apDb.ricId.plmnId, e2SetRspMsg->protocolIEs.list.array[arrIdx]\
+ ->value.choice.GlobalRIC_ID.pLMN_Identity.buf, recvBufLen);
+ bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID, &duCb.e2apDb.ricId);
+ /*TODO : duCb.e2apDb.ricId.plmnId memory to be deallocated after the usage */
+ break;
+ }
+
+ case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
+ {
+ e2NodeCfgAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
+ for(idx =0; idx <e2NodeCfgAckList->list.count; idx++)
+ {
+ e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeCfgAckList->list.array[idx];
+ handleE2NodeConfigUpdateAckIes((PTR)&e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item,\
+ ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck);
+ }
+ break;
+ }
+
+ default:
+ {
+ DU_LOG("\nERROR --> E2AP : Invalid IE received in E2SetupRsp:%ld",
+ e2SetRspMsg->protocolIEs.list.array[arrIdx]->id);
+ break;
+ }
+ }
+
+ if(invalidTransId == true)
+ {
+ break;
+ }
+ }
+ freeAperDecodingOfE2SetupRsp(e2SetRspMsg);
+
+ if(invalidTransId == false)
+ {
+ if(duSendE2NodeConfigurationUpdate() != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to send E2 node config update");
+ }
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Free RIC Subscription Request
+ *
+ * @details
+ *
+ * Function : freeAperDecodingOfRicSubsReq
+ *
+ * Functionality : Free RIC Subscription Request
+ *
+ * @return void
+ *
+ ******************************************************************/
+void freeAperDecodingOfRicSubsReq(RICsubscriptionRequest_t *ricSubscriptionReq)
+{
+ uint8_t idx = 0;
+ uint8_t elementIdx = 0;
+ RICsubscriptionDetails_t *subsDetails = NULLP;
+ RICaction_ToBeSetup_ItemIEs_t *actionItem = NULLP;
+
+ if(ricSubscriptionReq->protocolIEs.list.array)
+ {
+ for(idx=0; idx < ricSubscriptionReq->protocolIEs.list.count; idx++)
+ {
+ switch(ricSubscriptionReq->protocolIEs.list.array[idx]->id)
+ {
+ case ProtocolIE_IDE2_id_RICsubscriptionDetails:
+ {
+ subsDetails = &(ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails);
+ free(subsDetails->ricEventTriggerDefinition.buf);
+
+ if(subsDetails->ricAction_ToBeSetup_List.list.array)
+ {
+ for(elementIdx = 0; elementIdx < subsDetails->ricAction_ToBeSetup_List.list.count; elementIdx++)
+ {
+ if(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx])
+ {
+ actionItem = (RICaction_ToBeSetup_ItemIEs_t *)subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx];
+ if(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition)
+ {
+ free(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->buf);
+ free(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition);
+ }
+ free(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx]);
+ }
+ }
+ free(subsDetails->ricAction_ToBeSetup_List.list.array);
+ }
+ break;
+ }
+ }
+ free(ricSubscriptionReq->protocolIEs.list.array[idx]);
+ }
+ free(ricSubscriptionReq->protocolIEs.list.array);
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Free Event Trigger Definition
+ *
+ * @details
+ *
+ * Function : freeAperDecodingOfEventTriggerDef
+ *
+ * Functionality: Free Event Trigger Definition
+ *
+ * @params[in] E2SM-KPM Event Trigger Definition
+ * @return void
+ *
+ * ****************************************************************/
+void freeAperDecodingOfEventTriggerDef(E2SM_KPM_EventTriggerDefinition_t *eventTiggerDef)
+{
+ if(eventTiggerDef)
+ {
+ switch(eventTiggerDef->eventDefinition_formats.present)
+ {
+ case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING:
+ break;
+
+ case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_eventDefinition_Format1:
+ free(eventTiggerDef->eventDefinition_formats.choice.eventDefinition_Format1);
+ break;
+ }
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Extract E2SM-KPM Event trigger definition
+ *
+ * @details
+ *
+ * Function : extractEventTriggerDef
+ *
+ * Functionality : This function :
+ * - Decodes E2SM-KPM Event Trigger Definition
+ * - Validates that even trigger style is supported by E2 node
+ * - Stores event trigger details in local DB
+ *
+ * @params[in] RAN Function Database structure
+ * RIC Subscription Info to be added to RAN function
+ * RIC Event Trigger Definition buffer received from RIC
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+uint8_t extractEventTriggerDef(RanFunction *ranFuncDb, RicSubscription *ricSubscriptionInfo, \
+ RICeventTriggerDefinition_t *ricEventTriggerDef, E2FailureCause *failureCause)
+{
+ uint8_t ret = RFAILED;
+ uint8_t eventIdx = 0;
+ asn_dec_rval_t rval ={0};
+ E2SM_KPM_EventTriggerDefinition_t eventTiggerDef, *eventTiggerDefPtr = NULLP;
+
+ /* Decoding E2SM-KPM Even Trigger Definition */
+ eventTiggerDefPtr = &eventTiggerDef;
+ memset(eventTiggerDefPtr, 0, sizeof(E2SM_KPM_EventTriggerDefinition_t));
+
+ rval = aper_decode(0, &asn_DEF_E2SM_KPM_EventTriggerDefinition, (void **)&eventTiggerDefPtr, ricEventTriggerDef->buf,\
+ ricEventTriggerDef->size, 0, 0);
+ if(rval.code == RC_FAIL || rval.code == RC_WMORE)
+ {
+ DU_LOG("\nERROR --> E2AP : ASN decode failed for E2SM-KPM Event Trigger Definition");
+ failureCause->causeType = E2_PROTOCOL;
+ failureCause->cause = E2_ABSTRACT_SYNTAX_ERROR_FALSELY_CONSTRUCTED_MESSAGE;
+ return RFAILED;
+ }
+ printf("\n");
+ xer_fprint(stdout, &asn_DEF_E2SM_KPM_EventTriggerDefinition, eventTiggerDefPtr);
+
+ /* Validating the received event trigger definition format */
+ for(eventIdx = 0; eventIdx < ranFuncDb->numOfEventTriggerStyleSupported; eventIdx++)
+ {
+ if((eventTiggerDefPtr->eventDefinition_formats.present != \
+ E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING) && \
+ (eventTiggerDefPtr->eventDefinition_formats.present == ranFuncDb->eventTriggerStyleList[eventIdx].formatType))
+ {
+ ricSubscriptionInfo->eventTriggerDefinition.formatType = ranFuncDb->eventTriggerStyleList[eventIdx].formatType;
+ ricSubscriptionInfo->eventTriggerDefinition.choice.format1.reportingPeriod = \
+ eventTiggerDefPtr->eventDefinition_formats.choice.eventDefinition_Format1->reportingPeriod;
+
+ ret = ROK;
+ break;
+ }
+ }
+
+ if(ret == RFAILED)
+ {
+ failureCause->causeType = E2_RIC_REQUEST;
+ failureCause->cause = E2_EVENT_TRIGGER_NOT_SUPPORTED;
+ }
+ /* Free E2SM_KPM_EventTriggerDefinition_t */
+ freeAperDecodingOfEventTriggerDef(eventTiggerDefPtr);
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Free RIC Action Definition
+ *
+ * @details
+ *
+ * Function : freeAperDecodingOfRicActionDefinition
+ *
+ * Functionality: Free RIC Action Definition
+ *
+ * @params[in] E2SM-KPM Action definition
+ * @return void
+ *
+ * ****************************************************************/
+void freeAperDecodingOfRicActionDefinition(E2SM_KPM_ActionDefinition_t *actionDef)
+{
+ uint8_t elementIdx = 0;
+ E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
+ MeasurementInfoItem_t *measItem = NULLP;
+
+ switch(actionDef->actionDefinition_formats.present)
+ {
+ case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1:
+ {
+ if(actionDef->actionDefinition_formats.choice.actionDefinition_Format1)
+ {
+ actionFormat1 = actionDef->actionDefinition_formats.choice.actionDefinition_Format1;
+ if(actionFormat1->measInfoList.list.array)
+ {
+ for(elementIdx = 0; elementIdx < actionFormat1->measInfoList.list.count; elementIdx++)
+ {
+ if(actionFormat1->measInfoList.list.array[elementIdx])
+ {
+ measItem = actionFormat1->measInfoList.list.array[elementIdx];
+ switch(measItem->measType.present)
+ {
+ case MeasurementType_PR_NOTHING:
+ break;
+
+ case MeasurementType_PR_measName:
+ {
+ free(measItem->measType.choice.measName.buf);
+ break;
+ }
+
+ case MeasurementType_PR_measID:
+ break;
+ }
+ free(measItem);
+ }
+ }
+ free(actionFormat1->measInfoList.list.array);
+ }
+ free(actionFormat1);
+ }
+ break;
+ }
+ case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format2:
+ case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format3:
+ case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format4:
+ case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format5:
+ default:
+ break;
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Extract Measurement Info list from action definition
+ *
+ * @details
+ *
+ * Function : extractMeasInfoList
+ *
+ * Functionality : This function :
+ * - Traverses Measurement-to-be-subscribed list
+ * - Validates that each measurement in Measurement-to-be-subscribed
+ * list is supported in RAN-Function->Measurement-supported list.
+ * - If all measurements in an action is supported by RAN function,
+ * it is added to measurement-subscribed list in local DB
+ *
+ * @params[in] Measurement Info supported list by RAN function
+ * Measurement Info to be subscribed as requested by RIC
+ * Measurement Info finally subscribed
+ * Memory failure indicator
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+uint8_t extractMeasInfoList(CmLListCp *measInfoSupportedList, MeasurementInfoList_t *measInfoToBeSubscribedList, \
+ CmLListCp *measInfoSubscribedList, bool *memFailure)
+{
+ uint8_t elementIdx = 0;
+ MeasurementInfoForAction *measInfoSupportedDb = NULLP;
+ MeasurementInfo *measInfoSubscribedDb = NULLP;
+ CmLList *supportedMeasNode = NULLP, *measToAddNode = NULLP;
+ MeasurementInfoItem_t *measItem = NULLP;
+
+ /* Validate Measurement list is supported by E2 node.
+ *
+ * Traverse and compare the Measurement-Supported List in E2
+ * node with Measurement-to-be-subscribed list received from RIC.
+ * If a match is found, add it to measurement-subscription list.
+ */
+ for(elementIdx = 0; elementIdx < measInfoToBeSubscribedList->list.count; elementIdx++)
+ {
+ measInfoSubscribedDb = NULLP;
+ measToAddNode = NULLP;
+ measItem = measInfoToBeSubscribedList->list.array[elementIdx];
+
+ CM_LLIST_FIRST_NODE(measInfoSupportedList, supportedMeasNode);
+ while(supportedMeasNode)
+ {
+ measInfoSupportedDb = (MeasurementInfoForAction*)supportedMeasNode->node;
+ switch(measItem->measType.present)
+ {
+ case MeasurementType_PR_measName:
+ {
+ if(!strcmp(measInfoSupportedDb->measurementTypeName, (char *)measItem->measType.choice.measName.buf))
+ {
+ DU_ALLOC(measInfoSubscribedDb, sizeof(MeasurementInfo));
+ }
+ break;
+ }
+
+ case MeasurementType_PR_measID:
+ {
+ if(measInfoSupportedDb->measurementTypeId == measItem->measType.choice.measID)
+ {
+ DU_ALLOC(measInfoSubscribedDb, sizeof(MeasurementInfo));
+ }
+ break;
+ }
+
+ default:
+ {
+ DU_LOG("\nERROR -> DUAPP: Invalid Measurement-type identifier in \
+ E2SM-KPM Action Definition Format");
+ break;
+ }
+ } /* End of switch, for measurement type identifier */
+
+ /* If measurement type is supported, add to measurement-subscription list */
+ if(measInfoSubscribedDb)
+ {
+ measInfoSubscribedDb->measurementTypeId = measInfoSupportedDb->measurementTypeId;
+ memcpy(measInfoSubscribedDb->measurementTypeName, measInfoSupportedDb->measurementTypeName, \
+ strlen(measInfoSupportedDb->measurementTypeName));
+
+ DU_ALLOC(measToAddNode, sizeof(CmLList));
+ if(measToAddNode)
+ {
+ measToAddNode->node = (PTR) measInfoSubscribedDb;
+ cmLListAdd2Tail(measInfoSubscribedList, measToAddNode);
+
+ /* Break out of while loop if measurement info is found in measurement-supported list */
+ break;
+ }
+ else
+ {
+ DU_FREE(measInfoSubscribedDb, sizeof(MeasurementInfo));
+ measInfoSubscribedDb = NULLP;
+ *memFailure = true;
+ break;
+ }
+ }
+
+ supportedMeasNode = supportedMeasNode->next;
+
+ } /* End of while for traversing measurement-supported list in a report style */
+
+ /* If a measurement-to-be-subscribed is not found in measurement-supported list in this report style
+ * Then :
+ * Delete all entries from measurement-subscription list and
+ * Break out of for loop to search in next report style */
+ if(!measInfoSubscribedDb)
+ {
+ deleteMeasurementInfoList(measInfoSubscribedList);
+ break;
+ }
+
+ } /* End of for loop , traversing measurement-to-be-subscribed list */
+
+ /* If all measurement-to-be-subscribed was found in measurement-supported list and
+ * was added to measurement-subscription list successfully, return from here */
+ if(measInfoToBeSubscribedList->list.count == measInfoSubscribedList->count)
+ return ROK;
+
+ return RFAILED;
+}
+
+/*******************************************************************
+ *
+ * @brief Extract E2SM-KPM Action definition
+ *
+ * @details
+ *
+ * Function : extractRicActionDef
+ *
+ * Functionality : This function :
+ * - Decodes E2SM-KPM Action Definition
+ * - Validates that action is supported by E2 node
+ * - Stores action details in local DB
+ *
+ * @params[in] RAN Function Database structure
+ * RIC subscription's Action definition to be added to
+ * RAN function
+ * RIC Action Definition buffer received from RIC
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+uint8_t extractRicActionDef(RanFunction *ranFuncDb, ActionDefinition *actionDefDb, RICactionDefinition_t *ricActionDef,\
+ E2FailureCause *failureCause)
+{
+ bool memFailure = false;
+ uint8_t styleIdx = 0;
+ asn_dec_rval_t rval ={0};
+
+ E2SM_KPM_ActionDefinition_t actionDef, *actionDefPtr = NULLP;
+ E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
+ CmLListCp *measInfoSupportedList = NULLP;
+ CmLListCp *measInfoSubscribedList = NULLP;
+
+ /* Decoding E2SM-KPM Action Definition */
+ actionDefPtr = &actionDef;
+ memset(actionDefPtr, 0, sizeof(E2SM_KPM_EventTriggerDefinition_t));
+
+ rval = aper_decode(0, &asn_DEF_E2SM_KPM_ActionDefinition, (void **)&actionDefPtr, ricActionDef->buf,\
+ ricActionDef->size, 0, 0);
+ if(rval.code == RC_FAIL || rval.code == RC_WMORE)
+ {
+ DU_LOG("\nERROR --> E2AP : ASN decode failed for E2SM-KPM Action Definition");
+ failureCause->causeType = E2_PROTOCOL;
+ failureCause->cause = E2_ABSTRACT_SYNTAX_ERROR_FALSELY_CONSTRUCTED_MESSAGE;
+ return RFAILED;