+ else
+ {
+ DU_LOG("\nDEBUG --> F1AP : Created APER encoded buffer for RAN function definition \n");
+ for(uint8_t measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
+ {
+ printf("%x",encBuf[measIeIdx]);
+ }
+ ranFunctionDefinition = &ranFuncItem->ranFunctionDefinition;
+ ranFunctionDefinition->size = encBufSize;
+ DU_ALLOC(ranFunctionDefinition->buf, encBufSize);
+ if(ranFunctionDefinition->buf == NULLP)
+ {
+ DU_LOG("\nERROR --> F1AP : Memory allocation failed for RAN function definition buffer");
+ break;
+ }
+ memcpy(ranFunctionDefinition->buf, &encBuf, encBufSize);
+ ret = ROK;
+ break;
+ }
+ }
+ freeE2smKpmRanFunctionDefinition(ranFuncDefinition);
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Builds Ran function add list based on the procedure code
+ *
+ * @details
+ *
+ * Function : BuildRanFunctionAddList
+ *
+ * Functionality: Building RAN addition addition list
+ * In case of ProcedureCodeE2_id_E2setup we add all the RAN Function list
+ * which is present in E2 database.
+ * In the case of other procedures, we just fill the RAN functions whose ID
+ * is contained in recvList
+ *
+ * @params[in]
+ * RAN Function list
+ * Procedure code
+ * Count of ran functions to be added in the list
+ * Received list of RAN functions
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildRanFunctionAddList(RANfunctions_List_t *ranFunctionsList, uint8_t procedureCode, uint8_t count, uint8_t *recvList)
+{
+ uint16_t id;
+ RanFunction *ranFuncDb;
+ uint8_t ranFuncIdx;
+ RANfunction_ItemIEs_t *ranFuncItemIe;
+
+ /* For ProcedureCodeE2_id_E2setup, the number of RAN function list items is
+ * equal to the number of ran function entries stored in the database.
+ * For any other procedure, the RAN function list count is equal
+ * to the count of ran functions obtained from the function's caller */
+
+ if(procedureCode == ProcedureCodeE2_id_E2setup)
+ ranFunctionsList->list.count = duCb.e2apDb.numOfRanFunction;
+ else
+ ranFunctionsList->list.count = count;
+
+ ranFunctionsList->list.size = ranFunctionsList->list.count * sizeof(RANfunction_ItemIEs_t*);
+ DU_ALLOC(ranFunctionsList->list.array, ranFunctionsList->list.size);
+ if(ranFunctionsList->list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
+ return RFAILED;
+ }
+
+ for(ranFuncIdx = 0; ranFuncIdx< ranFunctionsList->list.count; ranFuncIdx++)
+ {
+ DU_ALLOC(ranFunctionsList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
+ if(ranFunctionsList->list.array[ranFuncIdx] == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
+ return RFAILED;
+ }
+ if(procedureCode == ProcedureCodeE2_id_E2setup)
+ {
+ /* Getting all of the RAN function's information from DuCb one by one*/
+ ranFuncDb = &duCb.e2apDb.ranFunction[ranFuncIdx];
+ }
+ else
+ {
+ /* Getting only the RAN function information from DuCb whose Id is
+ * present in the received array */
+ id =recvList[ranFuncIdx];
+ ranFuncDb = &duCb.e2apDb.ranFunction[id-1];
+ }
+ ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncIdx];
+ ranFuncItemIe->id = ProtocolIE_IDE2_id_RANfunction_Item;
+ ranFuncItemIe->criticality = CriticalityE2_ignore;
+ ranFuncItemIe->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
+ BuildRanFunctionItem(&ranFuncItemIe->value.choice.RANfunction_Item, ranFuncDb);
+ }
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @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 = ROK;
+ bool memAllocFailed;
+ 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))!=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 Request Id
+ *
+ * @details
+ *
+ * Function : BuildRicRequestId
+ *
+ * Functionality: Building the Ric Request Id
+ *
+ * @params[in] RICrequestID_t *ricReqId
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t BuildRicRequestId(RICrequestID_t *ricReqId)
+{
+ if(ricReqId == NULLP)
+ {
+ return RFAILED;
+ }
+
+ ricReqId->ricRequestorID = 1;
+ ricReqId->ricInstanceID = 1;
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Fills the mandatory RicAdmitted List Items
+ *
+ * @details
+ *
+ * Function : fillRicAdmitList
+ *
+ * Functionality: Fills the mandatory Ric Admitted List Items
+ *
+ * @params[in] RICaction_Admitted_ItemIEs_t *ricAdmitItems
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t fillRicAdmitList(RICaction_Admitted_ItemIEs_t *ricAdmitItems)
+{
+
+ if(ricAdmitItems != NULLP)
+ {
+ ricAdmitItems->id = ProtocolIE_IDE2_id_RICaction_Admitted_Item;
+ ricAdmitItems->criticality = CriticalityE2_reject;
+ ricAdmitItems->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
+ ricAdmitItems->value.choice.RICaction_Admitted_Item.ricActionID = 1;
+ }
+ else
+ {
+ return RFAILED;
+ }
+ return ROK;
+}
+/*******************************************************************
+ *
+ * @brief Builds the mandatory RicAdmitted List Params
+ *
+ * @details
+ *
+ * Function : BuildRicAdmitList
+ *
+ * Functionality: Builds the mandatory Ric Admitted List Params
+ *
+ * @params[in] RICaction_Admitted_List_t *admitListPtr
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t BuildRicAdmitList(RICaction_Admitted_List_t *admitListPtr)
+{
+ uint8_t idx ;
+ uint8_t elementCnt;
+ uint8_t ret= ROK;
+ elementCnt = 1;
+
+ if(admitListPtr == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for RIC Admit List failed");
+ ret = RFAILED;
+ }
+ else
+ {
+ admitListPtr->list.count = elementCnt;
+ admitListPtr->list.size = elementCnt * sizeof(RICaction_Admitted_ItemIEs_t);
+ DU_ALLOC(admitListPtr->list.array, admitListPtr->list.size);
+ if(admitListPtr->list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for RIC Admit List failed");
+ ret = RFAILED;
+ }
+ else
+ {
+ for(idx=0 ; idx<elementCnt ; idx++ )
+ {
+ DU_ALLOC(admitListPtr->list.array[idx], sizeof(RICaction_Admitted_ItemIEs_t));
+ if(admitListPtr->list.array[idx] == NULLP)
+ {
+ ret = RFAILED;
+ }
+ }
+ if(ret != RFAILED)
+ {
+ idx=0;
+ fillRicAdmitList((RICaction_Admitted_ItemIEs_t *)admitListPtr->list.array[idx]);
+ }
+ }
+ }
+ return ret;
+}
+/*******************************************************************
+ *
+ * @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 idx1=0;
+ RICaction_Admitted_List_t *admitListPtr;
+
+ 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_RICrequestID:
+ break;
+
+ case ProtocolIE_IDE2_id_RANfunctionID:
+ break;
+
+ case ProtocolIE_IDE2_id_RICactions_Admitted:
+ {
+ admitListPtr = &ricSubscriptionRsp->protocolIEs.list.\
+ array[idx]->value.choice.RICaction_Admitted_List;
+ if(admitListPtr->list.array != NULLP)
+ {
+ for(idx1=0 ; idx1<admitListPtr->list.count; idx1++ )
+ {
+ if(admitListPtr->list.array[idx1] != NULLP)
+ {
+ DU_FREE(admitListPtr->list.array[idx1],
+ sizeof(RICaction_Admitted_ItemIEs_t));
+ }
+ }
+ DU_FREE(admitListPtr->list.array, admitListPtr->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 Builds and Send the RicSubscriptionRsp
+ *
+ * @details
+ *
+ * Function : BuildAndSendRicSubscriptionRsp
+ *
+ * functionality:Fills the RicSubscriptionRsp
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+uint8_t FillRicSubscriptionRsp(RICsubscriptionResponse_t *ricSubscriptionRsp )
+{
+ uint8_t idx=0;
+ uint8_t ret = ROK;
+ uint8_t elementCnt = 0;
+ uint8_t BuildRicRequestIdret=ROK;
+ uint8_t BuildRicAdmitListret=ROK;
+
+ elementCnt=3;
+ 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 for FillRicSubscriptionRsp failed");
+ ret = RFAILED;
+ }
+ else
+ {
+ for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
+ {
+ DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array[idx], \
+ sizeof(RICsubscriptionResponse_IEs_t));
+ if(ricSubscriptionRsp->protocolIEs.list.array[idx] == NULLP)
+ {
+ ret = RFAILED;
+ }
+ }
+ if(ret != RFAILED)
+ {
+
+ idx=0;
+ ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
+ ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
+ ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
+ RICsubscriptionRequest_IEs__value_PR_RICrequestID;
+ BuildRicRequestIdret =
+ BuildRicRequestId(&ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RICrequestID);
+ if(BuildRicRequestIdret != ROK)
+ {
+ ret = RFAILED;
+ }
+ else
+ {
+ idx++;
+ ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
+ ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
+ ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
+ RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
+ ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RANfunctionID = 1;
+
+ idx++;
+ ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactions_Admitted;
+ ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
+ ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
+ RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
+ BuildRicAdmitListret =
+ BuildRicAdmitList(&ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RICaction_Admitted_List);
+ if(BuildRicAdmitListret != ROK)
+ {
+ ret = RFAILED;
+ }
+ }
+ }
+ }
+ return ret;
+}
+/*******************************************************************
+ *
+ * @brief Builds and Send the RicSubscriptionRsp
+ *
+ * @details
+ *
+ * Function : BuildAndSendRicSubscriptionRsp
+ *
+ * Functionality:Fills the RicSubscriptionRsp
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildAndSendRicSubscriptionRsp()
+{
+
+ E2AP_PDU_t *e2apRicMsg = NULLP;
+ RICsubscriptionResponse_t *ricSubscriptionRsp=NULLP;
+ asn_enc_rval_t encRetVal;
+ uint8_t ret = RFAILED;
+ uint8_t FillRicricSubscriptionRspret;
+
+ 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;
+
+ FillRicricSubscriptionRspret = FillRicSubscriptionRsp(ricSubscriptionRsp);
+ if(FillRicricSubscriptionRspret != 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 bu aper decoder for e2 setup response
+ *
+ * @details
+ *
+ * Function : freeAperDecodingOfE2SetupRsp
+ *
+ * Functionality: Deallocation of memory allocated bu 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 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 ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
+{
+ uint8_t arrIdx =0, transId=0;
+ uint32_t recvBufLen;
+ E2setupResponse_t *e2SetRspMsg;
+ CmLList *node;
+ E2NodeComponent *e2NodeComponentInfo;
+
+ 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);
+ return RFAILED;
+ }
+ 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:
+ break;
+
+ default:
+ DU_LOG("\nERROR --> E2AP : Invalid IE received in E2SetupRsp:%ld",
+ e2SetRspMsg->protocolIEs.list.array[arrIdx]->id);
+ break;
+ }
+ }
+ freeAperDecodingOfE2SetupRsp(e2SetRspMsg);
+
+ node = searchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD);
+ if(!node)
+ {
+ DU_LOG("\nERROR --> E2AP : Received e2NodeComponentInfo is null");
+ return RFAILED;
+ }
+ else
+ {
+ e2NodeComponentInfo = (E2NodeComponent*)node->node;
+ cmLListDelFrm(&duCb.e2apDb.e2NodeComponentList, node);
+ DU_FREE(e2NodeComponentInfo->componentRequestPart, e2NodeComponentInfo->reqBufSize);
+ DU_FREE(e2NodeComponentInfo->componentResponsePart, e2NodeComponentInfo->rspBufSize);
+ DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
+ DU_FREE(node, sizeof(CmLList));