+ uint8_t ret =RFAILED;
+ RANfunctionDefinition_t *ranFunctionDefinition;
+ RANfunction_Name_t *ranFuncName;
+ asn_enc_rval_t encRetVal;
+ E2SM_KPM_RANfunction_Description_t *ranFuncDefinition;
+
+ while(true)
+ {
+ /* RAN function Id*/
+ ranFuncItem->ranFunctionID = ranFuncDb->id;
+
+ /* RAN Function Revision*/
+ ranFuncItem->ranFunctionRevision = ranFuncDb->revisionCounter;
+
+ /* RAN function OID*/
+ ranFuncItem->ranFunctionOID.size = strlen(ranFuncDb->name.serviceModelOID);
+ DU_ALLOC(ranFuncItem->ranFunctionOID.buf, ranFuncItem->ranFunctionOID.size);
+ if(!ranFuncItem->ranFunctionOID.buf)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ break;
+ }
+ memcpy(ranFuncItem->ranFunctionOID.buf, ranFuncDb->name.serviceModelOID, ranFuncItem->ranFunctionOID.size);
+
+ /* RAN function Definition */
+ DU_ALLOC(ranFuncDefinition, sizeof(E2SM_KPM_RANfunction_Description_t));
+ if(!ranFuncDefinition)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ break;
+ }
+
+ /* RAN function Name */
+ ranFuncName = &ranFuncDefinition->ranFunction_Name;
+
+ /* RAN function ShortName */
+ ranFuncName->ranFunction_ShortName.size = strlen(ranFuncDb->name.shortName);
+ DU_ALLOC(ranFuncName->ranFunction_ShortName.buf, ranFuncName->ranFunction_ShortName.size);
+ if(!ranFuncName->ranFunction_ShortName.buf)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ break;
+ }
+ memcpy(ranFuncName->ranFunction_ShortName.buf, ranFuncDb->name.shortName, strlen(ranFuncDb->name.shortName));
+
+ /* RAN function E2SM_OID */
+ ranFuncName->ranFunction_E2SM_OID.size = strlen(ranFuncDb->name.serviceModelOID);
+ DU_ALLOC(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
+ if(!ranFuncName->ranFunction_E2SM_OID.buf)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ break;
+ }
+ memcpy(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncDb->name.serviceModelOID, ranFuncName->ranFunction_E2SM_OID.size);
+
+ /* RAN Function Name Description */
+ ranFuncName->ranFunction_Description.size = strlen(ranFuncDb->name.description);
+ DU_ALLOC(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
+ if(!ranFuncName->ranFunction_Description.buf)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ break;
+ }
+ memcpy(ranFuncName->ranFunction_Description.buf, ranFuncDb->name.description, ranFuncName->ranFunction_Description.size);
+
+ /* RIC Event Trigger Style List */
+ DU_ALLOC(ranFuncDefinition->ric_EventTriggerStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
+ if(!ranFuncDefinition->ric_EventTriggerStyle_List)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ break;
+ }
+
+ if(fillRicEventTriggerStyle(ranFuncDb, ranFuncDefinition->ric_EventTriggerStyle_List)!=ROK)
+ {
+ DU_LOG("\nERROR --> E2AP: failed to fill ric event trigger style");
+ break;
+ }
+
+ /* RIC Report Style List */
+ DU_ALLOC(ranFuncDefinition->ric_ReportStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
+ if(!ranFuncDefinition->ric_ReportStyle_List)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ break;
+ }
+ if(fillRicReportStyle(ranFuncDb, ranFuncDefinition->ric_ReportStyle_List) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP: failed to fill ric report style");
+ break;
+ }
+
+ /* Encode the F1SetupRequest type as APER */
+ xer_fprint(stdout, &asn_DEF_E2SM_KPM_RANfunction_Description, ranFuncDefinition);
+
+ memset(encBuf, 0, ENC_BUF_MAX_LEN);
+ encBufSize = 0;
+ encRetVal = aper_encode(&asn_DEF_E2SM_KPM_RANfunction_Description, 0, ranFuncDefinition, PrepFinalEncBuf, encBuf);
+
+ /* Encode results */
+ if(encRetVal.encoded == ENCODE_FAIL)
+ {
+ DU_LOG("\nERROR --> F1AP : Could not encode RAN function definition (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ 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, RanFuncInfo *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].id;
+ 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)
+ {