+ memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
+ }
+ else
+ {
+ DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
+ }
+ break;
+ }
+ case ProtocolIE_IDE2_id_TimeToWaitE2:
+ {
+ timerValue = convertE2WaitTimerEnumToValue(e2NodeCfgUpdFail->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
+ if((duChkTmr((PTR)&(duCb.e2apDb), EVENT_E2_NODE_CONFIG_UPDATE_TMR)) == FALSE)
+ {
+ duStartTmr((PTR)&(duCb.e2apDb), EVENT_E2_NODE_CONFIG_UPDATE_TMR, timerValue);
+ }
+ else
+ {
+ DU_LOG("\nERROR --> E2AP : EVENT_E2_NODE_CONFIG_UPDATE_TMR timer is already running");
+ }
+ break;
+ }
+ }
+ }
+
+ freeAperDecodingOfE2NodeConfigUpdateFailure(e2NodeCfgUpdFail);
+}
+
+/*******************************************************************
+ *
+ * @brief Builds Global gNodeB Params
+ *
+ * @details
+ *
+ * Function : BuildGlobalgNBId
+ *
+ * Functionality: Building the Plmn and gNB id
+ *
+ * @params[in] GlobalE2node_gNB_ID_t *gNbId
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
+{
+ uint8_t unused = 0;
+ uint8_t byteSize = 4;
+ uint8_t gnbId = duCb.gnbId;
+ uint8_t ret = ROK;
+
+ /* fill Global gNB ID Id */
+ gNbId->global_gNB_ID.plmn_id.size = 3 * sizeof(uint8_t);
+ gNbId->global_gNB_ID.plmn_id.buf = NULLP;
+ DU_ALLOC(gNbId->global_gNB_ID.plmn_id.buf , gNbId->global_gNB_ID.plmn_id.size);
+ if(gNbId->global_gNB_ID.plmn_id.buf == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed for Plmn buffer");
+ ret = RFAILED;
+ }
+ else
+ {
+ buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
+ gNbId->global_gNB_ID.plmn_id.buf);
+ gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
+ /* Allocate Buffer size */
+ gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = byteSize * sizeof(uint8_t);
+ gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf = NULLP;
+ DU_ALLOC(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf, \
+ gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
+ if(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed for gnb buffer");
+ ret = RFAILED;
+ }
+ else
+ {
+ fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, gnbId);
+ }
+ }
+
+ /* fill gNB-DU ID */
+ DU_ALLOC( gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
+ if(gNbId->gNB_DU_ID == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed for gNB_DU_ID ");
+ ret = RFAILED;
+ }
+ else
+ {
+ gNbId->gNB_DU_ID->size = sizeof(uint8_t);
+ DU_ALLOC( gNbId->gNB_DU_ID->buf, sizeof(uint8_t));
+ if(gNbId->gNB_DU_ID->buf)
+ {
+ gNbId->gNB_DU_ID->buf[0] =duCb.e2apDb.e2NodeId;
+ }
+ else
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed for gNB_DU_ID buffer");
+ ret = RFAILED;
+ }
+ }
+
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief fill the E2 node config information
+ *
+ * @details
+ *
+ * Function : fillE2NodeConfig
+ *
+ * Functionality: fill E2 node config information
+ *
+ * @params[in]
+ * Pointer to e2NodeCfg to be filled
+ * E2 Node Component information
+ * Type of configuration
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t fillE2NodeConfig(PTR e2NodeCfg, E2NodeComponent *e2NodeComponentInfo, ConfigType configType)
+{
+ E2nodeComponentInterfaceType_t *interfaceType=NULLP;
+ E2nodeComponentID_t *componentID =NULLP;
+ E2nodeComponentConfiguration_t *configuration=NULLP;
+ E2nodeComponentConfigAddition_Item_t *e2NodeAddItem=NULL;
+ E2nodeComponentConfigUpdate_Item_t *e2NodeUpdateItem =NULL;
+ E2nodeComponentConfigRemoval_Item_t *e2NodeRemovalItem=NULL;
+
+ switch(configType)
+ {
+ case CONFIG_ADD:
+ {
+ e2NodeAddItem = (E2nodeComponentConfigAddition_Item_t*)e2NodeCfg;
+ interfaceType = &e2NodeAddItem->e2nodeComponentInterfaceType;
+ componentID = &e2NodeAddItem->e2nodeComponentID;
+ configuration = &e2NodeAddItem->e2nodeComponentConfiguration;
+ break;
+ }
+ case CONFIG_MOD:
+ {
+ e2NodeUpdateItem = (E2nodeComponentConfigUpdate_Item_t *) e2NodeCfg;
+ interfaceType = &e2NodeUpdateItem->e2nodeComponentInterfaceType;
+ componentID = &e2NodeUpdateItem->e2nodeComponentID;
+ configuration = &e2NodeUpdateItem->e2nodeComponentConfiguration;
+ break;
+ }
+ case CONFIG_DEL:
+ {
+ e2NodeRemovalItem = (E2nodeComponentConfigRemoval_Item_t*) e2NodeCfg;
+ interfaceType = &e2NodeRemovalItem->e2nodeComponentInterfaceType;
+ componentID = &e2NodeRemovalItem->e2nodeComponentID;
+ break;
+ }
+ default:
+ {
+ DU_LOG("\nERROR --> E2AP : Configuration type %d does not supported ", configType);
+ return RFAILED;
+ }
+ }
+ /* E2nodeComponentInterfaceType */
+ *interfaceType = convertInterfaceToE2ComponentInterfaceType(e2NodeComponentInfo->interfaceType);
+
+ /* We now only support the F1 interface out of these interfaces
+ * (NG,XN,E1,F1,W1,S1,X2), therefore only the F1 component identifier was filled in. */
+
+ if(*interfaceType == F1)
+ {
+ /* E2 Node Component ID */
+ componentID->present = E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1;
+ DU_ALLOC(componentID->choice.e2nodeComponentInterfaceTypeF1,sizeof(E2nodeComponentInterfaceF1_t));
+ if(componentID->choice.e2nodeComponentInterfaceTypeF1 == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at line %d",__func__,__LINE__);
+ return RFAILED;
+ }
+ componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size = sizeof(uint8_t);
+ DU_ALLOC(componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
+ componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
+
+ if(componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at line %d",__func__,__LINE__);
+ return RFAILED;
+ }
+ memcpy(componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf, &e2NodeComponentInfo->componentId,\
+ componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
+ }
+
+ if(configType == CONFIG_DEL)
+ {
+ /* We don't need to fill out the E2 Node Component Request and Response
+ * information in the case of CONFIG_DEL, therefore returning ROK from here. */
+ return ROK;
+ }
+
+ /* E2 Node Component Request Part */
+ if(e2NodeComponentInfo->componentRequestPart)
+ {
+ configuration->e2nodeComponentRequestPart.size = e2NodeComponentInfo->reqBufSize ;
+ DU_ALLOC(configuration->e2nodeComponentRequestPart.buf,\
+ configuration->e2nodeComponentRequestPart.size);
+ if(configuration->e2nodeComponentRequestPart.buf == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at line %d",__func__,__LINE__);
+ return RFAILED;
+ }
+
+ memcpy(configuration->e2nodeComponentRequestPart.buf,\
+ e2NodeComponentInfo->componentRequestPart, configuration->\
+ e2nodeComponentRequestPart.size);
+ }
+ else
+ {
+ DU_LOG("\nERROR --> E2AP: componentRequestPart is null ");
+ return RFAILED;
+ }
+
+ /* E2 Node Component Response Part */
+ if(e2NodeComponentInfo->componentResponsePart)
+ {
+ configuration->e2nodeComponentResponsePart.size = e2NodeComponentInfo->rspBufSize;
+ DU_ALLOC(configuration->e2nodeComponentResponsePart.buf, configuration->e2nodeComponentResponsePart.size);
+ if(configuration->e2nodeComponentResponsePart.buf == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at line %d",__func__,__LINE__);
+ return RFAILED;
+ }
+ memcpy(configuration->e2nodeComponentResponsePart.buf, e2NodeComponentInfo->componentResponsePart, configuration->\
+ e2nodeComponentResponsePart.size);
+ }
+ else
+ {
+ DU_LOG("\nERROR --> E2AP: componentResponsePart is null");
+ return RFAILED;
+ }
+
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Builds E2 node config addition list
+ *
+ * @details
+ *
+ * Function : BuildE2NodeConfigAddList
+ *
+ * Functionality: Building E2 node config addition list
+ *
+ * @params[in]
+ * E2nodeComponentConfigAddition_List_t to be filled
+ * Procedure Code
+ * Count of E2 node to be added in the list
+ * Received list of E2 node configuration
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildE2NodeConfigAddList(E2nodeComponentConfigAddition_List_t *e2NodeAddList, uint8_t procedureCode, uint16_t count, E2NodeConfigItem *e2NodeList)
+{
+ uint8_t arrIdx = 0;
+ CmLList *node =NULL;
+ E2NodeComponent *e2NodeComponentInfo=NULL;
+ E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItemIe=NULL;
+ E2nodeComponentConfigAddition_Item_t *e2NodeAddItem=NULL;
+
+
+ /* For ProcedureCodeE2_id_E2setup, the number of E2 node configuration list items is
+ * equal to the number of E2 node configuration entries stored in the database.
+ * For any other procedure, the E2 node configuration list count is equal
+ * to the count of E2 node configuration obtained from the function's caller */
+
+ if(procedureCode == ProcedureCodeE2_id_E2setup)
+ e2NodeAddList->list.count = duCb.e2apDb.e2NodeComponentList.count;
+ else
+ e2NodeAddList->list.count = count;
+
+ e2NodeAddList->list.size = e2NodeAddList->list.count * sizeof(E2nodeComponentConfigAddition_ItemIEs_t *);
+ DU_ALLOC(e2NodeAddList->list.array, e2NodeAddList->list.size);
+ if(e2NodeAddList->list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
+ return RFAILED;
+ }
+
+ for(arrIdx = 0; arrIdx< e2NodeAddList->list.count; arrIdx++)
+ {
+ DU_ALLOC(e2NodeAddList->list.array[arrIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
+ if(e2NodeAddList->list.array[arrIdx] == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
+ return RFAILED;
+ }
+
+ if(procedureCode == ProcedureCodeE2_id_E2setup)
+ {
+ /* Getting all of the E2 node configuration's information from DuCb one by one*/
+ if(arrIdx == 0)
+ {
+ CM_LLIST_FIRST_NODE(&duCb.e2apDb.e2NodeComponentList, node);
+ }
+ else
+ {
+ node = node->next;
+ }
+ if(!node)
+ {
+ DU_LOG("\nERROR --> E2AP : E2 node component list node is null");
+ return RFAILED;
+ }
+ e2NodeComponentInfo = (E2NodeComponent*)node->node;
+ }
+ else
+ {
+ /* Getting only those E2 node configuration from DuCb whose interface
+ * and action type is present in the received array */
+ e2NodeComponentInfo = fetchE2NodeComponentInfo(e2NodeList[arrIdx].interface, e2NodeList[arrIdx].actionType, &node);
+ }
+
+ if(!e2NodeComponentInfo)
+ {
+ DU_LOG("\nERROR --> E2AP : Received null e2NodeComponentInfo at line number %d",__LINE__);
+ return RFAILED;
+ }
+
+ e2NodeAddItemIe = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[arrIdx];
+ e2NodeAddItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition_Item;
+ e2NodeAddItemIe->criticality = CriticalityE2_reject;
+ e2NodeAddItemIe->value.present = E2nodeComponentConfigAddition_ItemIEs__value_PR_E2nodeComponentConfigAddition_Item;
+ e2NodeAddItem = &e2NodeAddItemIe->value.choice.E2nodeComponentConfigAddition_Item;
+ if(fillE2NodeConfig((PTR)e2NodeAddItem, e2NodeComponentInfo, CONFIG_ADD) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to fill the E2 node configuration");
+ return RFAILED;
+ }
+ }
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Builds E2 node config update list
+ *
+ * @details
+ *
+ * Function : BuildE2NodeConfigUpdateList
+ *
+ * Functionality: Building E2 node config update list
+ *
+ * @params[in]
+ * E2nodeComponentConfigUpdate_List_t to be filled
+ * Count of E2 node to be update in the list
+ * Received list of E2 node configuration
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildE2NodeConfigUpdateList(E2nodeComponentConfigUpdate_List_t *e2NodeUpdateList, uint16_t count, E2NodeConfigItem *updateE2Node)
+{
+ uint8_t arrIdx = 0;
+ CmLList *node =NULL;
+ E2NodeComponent *e2NodeComponentInfo =NULL;
+ E2nodeComponentConfigUpdate_ItemIEs_t *e2NodeUpdateItemIe =NULL;
+ E2nodeComponentConfigUpdate_Item_t *e2NodeUpdateItem =NULL;
+
+ e2NodeUpdateList->list.count = count;
+ e2NodeUpdateList->list.size = e2NodeUpdateList->list.count * sizeof(E2nodeComponentConfigUpdate_ItemIEs_t *);
+ DU_ALLOC(e2NodeUpdateList->list.array, e2NodeUpdateList->list.size);
+ if(e2NodeUpdateList->list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigUpdateList %d",__LINE__);
+ return RFAILED;
+ }
+
+ for(arrIdx = 0; arrIdx< e2NodeUpdateList->list.count; arrIdx++)
+ {
+ DU_ALLOC(e2NodeUpdateList->list.array[arrIdx], sizeof(E2nodeComponentConfigUpdate_ItemIEs_t));
+ if(e2NodeUpdateList->list.array[arrIdx] == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigUpdateList %d",__LINE__);
+ return RFAILED;
+ }
+
+ e2NodeComponentInfo= fetchE2NodeComponentInfo(updateE2Node[arrIdx].interface, updateE2Node[arrIdx].actionType, &node);
+ if(!e2NodeComponentInfo)
+ {
+ DU_LOG("\nERROR --> E2AP : Received null e2NodeComponentInfo at line number %d",__LINE__);
+ return RFAILED;
+ }
+
+ e2NodeUpdateItemIe = (E2nodeComponentConfigUpdate_ItemIEs_t *) e2NodeUpdateList->list.array[arrIdx];
+ e2NodeUpdateItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigUpdate_Item;
+ e2NodeUpdateItemIe->criticality = CriticalityE2_reject;
+ e2NodeUpdateItemIe->value.present = E2nodeComponentConfigUpdate_ItemIEs__value_PR_E2nodeComponentConfigUpdate_Item;
+ e2NodeUpdateItem = &e2NodeUpdateItemIe->value.choice.E2nodeComponentConfigUpdate_Item;
+
+ if(fillE2NodeConfig((PTR)e2NodeUpdateItem, e2NodeComponentInfo, CONFIG_MOD) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to fill the E2 node configuration");
+ return RFAILED;
+ }
+
+ }
+ return ROK;
+
+}
+
+
+/*******************************************************************
+ *
+ * @brief Builds E2 node config remove list
+ *
+ * @details
+ *
+ * Function :BuildE2NodeConfigRemoveList
+ *
+ * Functionality: Building E2 node config remove list
+ *
+ * @params[in]
+ * E2nodeComponentConfigRemoval_List_t to be filled
+ * Count of E2 node to be remove in the list
+ * Received list of E2 node configuration
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildE2NodeConfigRemoveList(E2nodeComponentConfigRemoval_List_t *e2NodeRemoveList, uint16_t count, E2NodeConfigItem *updateE2Node)
+{
+ uint8_t arrIdx = 0;
+ CmLList *node=NULL;
+ E2NodeComponent *e2NodeComponentInfo=NULL;
+ E2nodeComponentConfigRemoval_ItemIEs_t *e2NodeRemovalItemIe=NULL;
+ E2nodeComponentConfigRemoval_Item_t *e2NodeRemovalItem=NULL;
+
+ e2NodeRemoveList->list.count = count;
+ e2NodeRemoveList->list.size = e2NodeRemoveList->list.count * sizeof(E2nodeComponentConfigRemoval_ItemIEs_t *);
+ DU_ALLOC(e2NodeRemoveList->list.array, e2NodeRemoveList->list.size);
+ if(e2NodeRemoveList->list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigRemoveList %d",__LINE__);
+ return RFAILED;
+ }
+
+ for(arrIdx = 0; arrIdx< e2NodeRemoveList->list.count; arrIdx++)
+ {
+ DU_ALLOC(e2NodeRemoveList->list.array[arrIdx], sizeof(E2nodeComponentConfigRemoval_ItemIEs_t));
+ if(e2NodeRemoveList->list.array[arrIdx] == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigRemoveList %d",__LINE__);
+ return RFAILED;
+ }
+
+ e2NodeComponentInfo= fetchE2NodeComponentInfo(updateE2Node[arrIdx].interface, updateE2Node[arrIdx].actionType, &node);
+ if(!e2NodeComponentInfo)
+ {
+ DU_LOG("\nERROR --> E2AP : Received null e2NodeComponentInfo at line number %d",__LINE__);
+ return RFAILED;
+ }
+
+ e2NodeRemovalItemIe = (E2nodeComponentConfigRemoval_ItemIEs_t *) e2NodeRemoveList->list.array[arrIdx];
+ e2NodeRemovalItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigRemoval_Item;
+ e2NodeRemovalItemIe->criticality = CriticalityE2_reject;
+ e2NodeRemovalItemIe->value.present = E2nodeComponentConfigRemoval_ItemIEs__value_PR_E2nodeComponentConfigRemoval_Item;
+ e2NodeRemovalItem = &e2NodeRemovalItemIe->value.choice.E2nodeComponentConfigRemoval_Item;
+
+ if(fillE2NodeConfig((PTR)e2NodeRemovalItem, e2NodeComponentInfo, CONFIG_DEL) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to fill the E2 node configuration");
+ return RFAILED;
+ }
+
+ }
+ return ROK;
+}
+/*******************************************************************
+ *
+ * @brief deallocation of E2SM_KPM_RANfunction_Description_t
+ *
+ * @details
+ *
+ * Function : freeE2smKpmRanFunctionDefinition
+ *
+ * Functionality: deallocation of E2SM_KPM_RANfunction_Description_t
+ *
+ * @params[in] E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition
+ * @return void
+ *
+ ******************************************************************/
+
+void freeE2smKpmRanFunctionDefinition(E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition)
+{
+ MeasurementInfo_Action_Item_t *measInfoList;
+ uint8_t eventTriggerIdx, reportStyleIdx, measInfoIdx;
+ RANfunction_Name_t *ranFuncName;
+ struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle;
+ struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *eventTriggerStyle;
+ if(ranFunctionDefinition)
+ {
+ ranFuncName = &ranFunctionDefinition->ranFunction_Name;
+ /* Free RAN function Name */
+ DU_FREE(ranFuncName->ranFunction_ShortName.buf, ranFuncName->ranFunction_ShortName.size);
+ DU_FREE(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
+ DU_FREE(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
+
+ /* Sequence of Event Trigger styles */
+ eventTriggerStyle = ranFunctionDefinition->ric_EventTriggerStyle_List;
+ if(eventTriggerStyle)
+ {
+ if(eventTriggerStyle->list.array)
+ {
+ for(eventTriggerIdx =0;eventTriggerIdx<eventTriggerStyle->list.count; eventTriggerIdx++)
+ {
+ if(eventTriggerStyle->list.array[eventTriggerIdx])
+ {
+ DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.buf,\
+ eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.size);
+ DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
+ }
+ }
+ DU_FREE(eventTriggerStyle->list.array, eventTriggerStyle->list.size)
+ }
+ DU_FREE(eventTriggerStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
+ }
+
+ /* Sequence of Report styles */
+ ricReportStyle = ranFunctionDefinition->ric_ReportStyle_List;
+ if(ricReportStyle)
+ {
+ if(ricReportStyle->list.array)
+ {
+ for(reportStyleIdx =0;reportStyleIdx<ricReportStyle->list.count; reportStyleIdx++)
+ {
+ if(ricReportStyle->list.array[reportStyleIdx])
+ {
+ if(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf)
+ {
+ DU_FREE(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf,\
+ ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.size);
+ }
+ if(ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array)
+ {
+ for(measInfoIdx=0; measInfoIdx<ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.count; \
+ measInfoIdx++)
+ {
+ measInfoList = ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array[measInfoIdx];
+ if(measInfoList)
+ {
+ DU_FREE(measInfoList->measID, sizeof(long));
+ DU_FREE(measInfoList->measName.buf, measInfoList->measName.size);
+ DU_FREE(measInfoList,sizeof(MeasurementInfo_Action_Item_t));
+ }
+ }
+ DU_FREE(measInfoList,ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.size);
+ }
+ DU_FREE(ricReportStyle->list.array[reportStyleIdx], sizeof(RIC_ReportStyle_Item_t));
+ }
+ }
+ DU_FREE(ricReportStyle->list.array, ricReportStyle->list.size);
+ }
+ DU_FREE(ricReportStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
+ }
+ DU_FREE(ranFunctionDefinition, sizeof(E2SM_KPM_RANfunction_Description_t));
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief fill the e2sm ric report style
+ *
+ * @details
+ *
+ * Function : fillRicReportStyle
+ *
+ * Functionality: fill the report style
+ *
+ * @params[in] RanFunction *ranFuncDb, struct
+ * E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+uint8_t fillRicReportStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle)
+{
+ uint8_t styleIdx, measInfoIdx;
+ MeasurementInfo_Action_List_t *measInfo;
+ CmLList *node;
+
+ ricReportStyle->list.count = ranFuncDb->numOfReportStyleSupported;
+ ricReportStyle->list.size = ricReportStyle->list.count * sizeof(RIC_ReportStyle_Item_t*);
+ DU_ALLOC(ricReportStyle->list.array, ricReportStyle->list.size);
+ if(!ricReportStyle->list.array)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed for ranFuncDefinition %d",__LINE__);
+ return RFAILED;
+ }
+
+ for(styleIdx =0;styleIdx<ricReportStyle->list.count; styleIdx++)
+ {
+ DU_ALLOC(ricReportStyle->list.array[styleIdx], sizeof(RIC_ReportStyle_Item_t));
+ if(!ricReportStyle->list.array[styleIdx])
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ return RFAILED;
+ }
+
+ /* RIC Report Style Type */
+ ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.styleType;
+
+ /* RIC Report Style Format Type */
+ ricReportStyle->list.array[styleIdx]->ric_ActionFormat_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.formatType;
+
+ /* RIC Report Style Name */
+ ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size = strlen(ranFuncDb->reportStyleList[styleIdx].reportStyle.name);
+ DU_ALLOC(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf,\
+ ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
+ if(!ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ return RFAILED;
+ }
+ memcpy(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf, ranFuncDb->reportStyleList[styleIdx].reportStyle.name,\
+ ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
+
+ /* RIC Indication Header Format Type*/
+ ricReportStyle->list.array[styleIdx]->ric_IndicationHeaderFormat_Type = ranFuncDb->ricIndicationHeaderFormat;
+
+ /* RIC Indication Message Format Type*/
+ ricReportStyle->list.array[styleIdx]->ric_IndicationMessageFormat_Type = ranFuncDb->ricIndicationMessageFormat;
+
+ /* Measurement Info Action List */
+ CmLListCp measInfoList =ranFuncDb->reportStyleList[styleIdx].measurementInfoList;
+ if(!measInfoList.count)
+ {
+ continue;
+ }
+
+ CM_LLIST_FIRST_NODE(&ranFuncDb->reportStyleList[styleIdx].measurementInfoList, node);
+ measInfo = &ricReportStyle->list.array[styleIdx]->measInfo_Action_List;
+
+ measInfo->list.count = measInfoList.count;
+ measInfo->list.size = measInfoList.count*sizeof(MeasurementInfo_Action_Item_t*);
+ DU_ALLOC(measInfo->list.array, measInfo->list.size);
+ if(!measInfo->list.array)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ return RFAILED;
+ }
+
+ for(measInfoIdx=0; measInfoIdx<measInfo->list.count; measInfoIdx++)
+ {
+ if(!node)
+ {
+ DU_LOG("\nERROR --> E2AP: Measurement info node is null");
+ return RFAILED;
+ }
+
+ DU_ALLOC(measInfo->list.array[measInfoIdx],sizeof(MeasurementInfo_Action_Item_t));
+ if(!measInfo->list.array[measInfoIdx])
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ return RFAILED;
+ }
+ MeasurementInfoForAction *measInfoForAction= (MeasurementInfoForAction*)node->node;
+ DU_ALLOC(measInfo->list.array[measInfoIdx]->measID, sizeof(long));
+ if(!measInfo->list.array[measInfoIdx]->measID)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ return RFAILED;
+ }
+
+ memcpy(measInfo->list.array[measInfoIdx]->measID, &measInfoForAction->measurementTypeId,sizeof(long));
+ measInfo->list.array[measInfoIdx]->measName.size= strlen(measInfoForAction->measurementTypeName);
+ DU_ALLOC(measInfo->list.array[measInfoIdx]->measName.buf, measInfo->list.array[measInfoIdx]->measName.size);
+ if(!measInfo->list.array[measInfoIdx]->measName.size)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ return RFAILED;
+ }
+
+ memcpy(measInfo->list.array[measInfoIdx]->measName.buf, \
+ measInfoForAction->measurementTypeName,\
+ measInfo->list.array[measInfoIdx]->measName.size);
+ node = node->next;
+ }
+
+ }
+ return ROK;
+}
+/*******************************************************************
+ *
+ * @brief fill the ric event trigger style
+ *
+ * @details
+ *
+ * Function : fillRicEventTriggerStyle
+ *
+ * Functionality: fill the ric event trigger style
+ *
+ * @params[in]
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+uint8_t fillRicEventTriggerStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *ricEventTriggerStyle)
+{
+ uint8_t styleIdx;
+
+ ricEventTriggerStyle->list.count = ranFuncDb->numOfEventTriggerStyleSupported;
+ ricEventTriggerStyle->list.size = ricEventTriggerStyle->list.count* sizeof(RIC_EventTriggerStyle_Item_t *);
+ DU_ALLOC(ricEventTriggerStyle->list.array, ricEventTriggerStyle->list.size);
+ if(!ricEventTriggerStyle->list.array)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed for ric_EventTriggerStyle_List %d",__LINE__);
+ return RFAILED;
+ }
+
+ for(styleIdx =0;styleIdx<ricEventTriggerStyle->list.count; styleIdx++)
+ {
+ DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
+ if(!ricEventTriggerStyle->list.array[styleIdx])
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ return RFAILED;
+ }
+ ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Type = ranFuncDb->eventTriggerStyleList[styleIdx].styleType;
+
+ ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerFormat_Type = ranFuncDb->eventTriggerStyleList[styleIdx].formatType;
+
+ ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size = strlen(ranFuncDb->eventTriggerStyleList[styleIdx].name);
+ DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,\
+ ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
+ if(!ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf)
+ {
+ DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+ return RFAILED;
+ }
+ memcpy(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,ranFuncDb->eventTriggerStyleList[styleIdx].name,\
+ ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
+
+ }
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Builds Ran function item
+ *
+ * @details
+ *
+ * Function : BuildRanFunctionItem
+ *
+ * Functionality: Building RAN function item
+ *
+ * @params[in]
+ * RAN function item that has to be filled
+ * Stored RAN Function information
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildRanFunctionItem(RANfunction_Item_t *ranFuncItem, RanFunction *ranFuncDb)
+{
+ 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), 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 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, idx=0;
+ uint32_t recvBufLen;
+ E2setupResponse_t *e2SetRspMsg=NULL;
+ CmLList *node=NULL;
+ E2NodeComponent *e2NodeComponentInfo=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);
+ 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:
+ {
+ 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];
+ switch(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.present)
+ {
+ case E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1:
+ {
+ e2NodeComponentInfo = fetchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD, &node);
+ if(!e2NodeComponentInfo)