1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
18 #include "common_def.h"
24 #include "du_app_mac_inf.h"
25 #include "du_app_rlc_inf.h"
26 #include "du_e2ap_mgr.h"
27 #include "du_e2ap_msg_hdl.h"
30 #include "du_mgr_main.h"
32 #include "GlobalE2node-gNB-ID.h"
33 #include "ProtocolIE-FieldE2.h"
34 #include "E2setupRequest.h"
35 #include "InitiatingMessageE2.h"
36 #include "SuccessfulOutcomeE2.h"
37 #include "UnsuccessfulOutcomeE2.h"
39 #include "odu_common_codec.h"
40 #include "E2nodeComponentInterfaceF1.h"
41 #include "E2setupRequest.h"
42 #include "du_e2_conversions.h"
43 #include "E2SM-KPM-RANfunction-Description.h"
44 #include "RANfunction-Name.h"
45 #include "RIC-EventTriggerStyle-Item.h"
46 #include "RIC-ReportStyle-Item.h"
47 #include "MeasurementInfo-Action-Item.h"
48 #include "E2SM-KPM-EventTriggerDefinition.h"
49 #include "E2SM-KPM-EventTriggerDefinition-Format1.h"
50 #include "E2SM-KPM-ActionDefinition.h"
51 #include "E2SM-KPM-ActionDefinition-Format1.h"
52 #include "MeasurementInfoItem.h"
53 #include "RANfunctionsIDcause-List.h"
54 #include "MeasurementRecord.h"
55 #include "MeasurementData.h"
56 #include "MeasurementRecordItem.h"
57 #include "MeasurementDataItem.h"
58 #include "E2SM-KPM-IndicationMessage-Format1.h"
59 #include "E2SM-KPM-IndicationMessage.h"
60 #include "E2SM-KPM-IndicationHeader.h"
61 #include "E2SM-KPM-IndicationHeader-Format1.h"
62 #include "LabelInfoItem.h"
64 /*******************************************************************
66 * @brief Fill E2 Failure Cause
70 * Function : fillE2Cause
72 * Functionality: Fill E2 Failure Cause
74 * @params[in] E2 Cause pointer to be filled in
75 * E2 Cause to be filled from
78 ******************************************************************/
79 void fillE2Cause(CauseE2_t *e2Cause, E2FailureCause failureCause)
81 e2Cause->present = failureCause.causeType;
82 switch(e2Cause->present)
84 case CauseE2_PR_ricRequest:
86 e2Cause->choice.ricRequest = failureCause.cause;
89 case CauseE2_PR_ricService:
91 e2Cause->choice.ricService = failureCause.cause;
94 case CauseE2_PR_e2Node:
96 e2Cause->choice.e2Node = failureCause.cause;
99 case CauseE2_PR_transport:
101 e2Cause->choice.transport = failureCause.cause;
104 case CauseE2_PR_protocol:
106 e2Cause->choice.protocol = failureCause.cause;
109 case CauseE2_PR_misc:
111 e2Cause->choice.misc = failureCause.cause;
114 case CauseE2_PR_NOTHING:
120 /*******************************************************************
122 * @brief Free the ErrorIndication Message
126 * Function : FreeRicIndication
128 * Functionality: Free the ErrorIndication Message
131 * E2AP_PDU is to freed
134 ******************************************************************/
135 void FreeErrorIndication(E2AP_PDU_t *e2apMsg)
138 ErrorIndicationE2_t *errorIndicationMsg= NULLP;
142 if(e2apMsg->choice.initiatingMessage != NULLP)
144 errorIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.ErrorIndicationE2;
145 if(errorIndicationMsg!= NULLP)
147 if(errorIndicationMsg->protocolIEs.list.array != NULLP)
149 for(arrIdx=0; arrIdx<errorIndicationMsg->protocolIEs.list.count; arrIdx++)
151 DU_FREE(errorIndicationMsg->protocolIEs.list.array[arrIdx],sizeof(ErrorIndicationE2_t));
153 DU_FREE(errorIndicationMsg->protocolIEs.list.array,errorIndicationMsg->protocolIEs.list.size);
156 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
158 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
162 /*******************************************************************
164 * @brief Builds and Send the ErrorIndication Message
168 * Function : BuildAndSendErrorIndication
170 * Functionality:Fills the ErrorIndication Message
177 * @return ROK - success
180 ******************************************************************/
182 uint8_t BuildAndSendErrorIndication(int8_t transId, RicRequestId requestId, uint16_t ranFuncId, E2FailureCause failureCause)
184 uint8_t elementCnt =0, arrIdx=0, ret = RFAILED;
185 E2AP_PDU_t *e2apMsg = NULLP;
186 ErrorIndicationE2_t *errorIndicationMsg=NULLP;
187 asn_enc_rval_t encRetVal; /* Encoder return value */
191 DU_LOG("\nINFO --> E2AP : Building Error Indication Message\n");
193 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
196 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed in %s at line %d",__func__, __LINE__);
200 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
201 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
202 if(e2apMsg->choice.initiatingMessage == NULLP)
204 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed in %s at line %d",__func__, __LINE__);
207 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_ErrorIndicationE2;
208 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
209 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ErrorIndicationE2;
211 errorIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.ErrorIndicationE2;
213 /* Element count is 2 for TransactionID/RICrequestID and Cause.
214 * If the RAN function id is present, the count will be increased.*/
221 errorIndicationMsg->protocolIEs.list.count = elementCnt;
222 errorIndicationMsg->protocolIEs.list.size = elementCnt * sizeof(ErrorIndicationE2_IEs_t*);
224 /* Initialize the E2Setup members */
225 DU_ALLOC(errorIndicationMsg->protocolIEs.list.array, errorIndicationMsg->protocolIEs.list.size);
226 if(errorIndicationMsg->protocolIEs.list.array == NULLP)
228 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements in %s at line %d",__func__, __LINE__);
232 for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
234 DU_ALLOC(errorIndicationMsg->protocolIEs.list.array[arrIdx], sizeof(ErrorIndicationE2_IEs_t));
235 if(errorIndicationMsg->protocolIEs.list.array[arrIdx] == NULLP)
237 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array [%d] elements in %s at line %d", arrIdx, __func__, __LINE__);
241 if(arrIdx < elementCnt)
246 if(transId >=0 && transId<=255)
249 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
250 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
251 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_TransactionID;
252 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
257 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RICrequestID;
258 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
259 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_RICrequestID;
260 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RICrequestID.ricRequestorID = requestId.requestorId;
261 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RICrequestID.ricInstanceID = requestId.instanceId;
266 /* RAN Function ID */
268 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionID;
269 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
270 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_RANfunctionID;
271 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionID = ranFuncId;
276 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_CauseE2;
277 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_ignore;
278 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_CauseE2;
279 fillE2Cause(&errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.CauseE2, failureCause);
281 /* Prints the Msg formed */
282 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
283 memset(encBuf, 0, ENC_BUF_MAX_LEN);
285 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
287 if(encRetVal.encoded == ENCODE_FAIL)
289 DU_LOG("\nERROR --> E2AP : Could not encode Error Indication Message (at %s)\n",\
290 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
295 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for Error Indication Message \n");
296 #ifdef DEBUG_ASN_PRINT
297 for(int i=0; i< encBufSize; i++)
299 printf("%x",encBuf[i]);
304 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
306 DU_LOG("\nINFO --> E2AP : Sending Error Indication Message");
312 FreeErrorIndication(e2apMsg);
316 /******************************************************************
318 * @brief Deallocation of memory allocated by aper decoder for e2
319 * Config Update Failure
323 * Function : freeAperDecodingOfE2Node Config UpdateFailure
325 * Functionality: Deallocation of memory allocated by aper decoder
326 * for e2 Config Update Failure
328 * @params[in] E2nodeConfigurationUpdateFailure_t to be deallocated
331 * ****************************************************************/
333 void freeAperDecodingOfE2NodeConfigUpdateFailure(E2nodeConfigurationUpdateFailure_t *e2NodeCfgUpdFail)
339 if(e2NodeCfgUpdFail->protocolIEs.list.array)
341 for(arrIdx=0; arrIdx<e2NodeCfgUpdFail->protocolIEs.list.count; arrIdx++)
343 if(e2NodeCfgUpdFail->protocolIEs.list.array[arrIdx])
345 free(e2NodeCfgUpdFail->protocolIEs.list.array[arrIdx]);
348 free(e2NodeCfgUpdFail->protocolIEs.list.array);
353 /******************************************************************
355 * @brief Processes E2 Node Config Update Failure sent by RIC
359 * Function : procE2NodeConfigUpdateFailure
361 * Functionality: Processes E2 Node Config Update failure sent by RIC
363 * @params[in] E2AP_PDU_t ASN decoded E2AP message
364 * @return ROK - success
367 * ****************************************************************/
369 void procE2NodeConfigUpdateFailure(E2AP_PDU_t *e2apMsg)
371 uint8_t arrIdx =0, transId =0, timerValue=0;
372 E2nodeConfigurationUpdateFailure_t *e2NodeCfgUpdFail=NULL;
374 DU_LOG("\nINFO --> E2AP : E2 Node Config Update failure received");
375 e2NodeCfgUpdFail = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2nodeConfigurationUpdateFailure;
377 for(arrIdx=0; arrIdx<e2NodeCfgUpdFail->protocolIEs.list.count; arrIdx++)
379 switch(e2NodeCfgUpdFail->protocolIEs.list.array[arrIdx]->id)
381 case ProtocolIE_IDE2_id_TransactionID:
383 transId = e2NodeCfgUpdFail->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
384 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
385 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
387 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
391 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
395 case ProtocolIE_IDE2_id_TimeToWaitE2:
397 timerValue = convertE2WaitTimerEnumToValue(e2NodeCfgUpdFail->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
398 if((duChkTmr((PTR)&(duCb.e2apDb), EVENT_E2_NODE_CONFIG_UPDATE_TMR)) == FALSE)
400 duStartTmr((PTR)&(duCb.e2apDb), EVENT_E2_NODE_CONFIG_UPDATE_TMR, timerValue);
404 DU_LOG("\nERROR --> E2AP : EVENT_E2_NODE_CONFIG_UPDATE_TMR timer is already running");
411 freeAperDecodingOfE2NodeConfigUpdateFailure(e2NodeCfgUpdFail);
414 /*******************************************************************
416 * @brief Builds Global gNodeB Params
420 * Function : BuildGlobalgNBId
422 * Functionality: Building the Plmn and gNB id
424 * @params[in] GlobalE2node_gNB_ID_t *gNbId
425 * @return ROK - success
428 ******************************************************************/
430 uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
433 uint8_t byteSize = 4;
434 uint8_t gnbId = duCb.gnbId;
437 /* fill Global gNB ID Id */
438 gNbId->global_gNB_ID.plmn_id.size = 3 * sizeof(uint8_t);
439 gNbId->global_gNB_ID.plmn_id.buf = NULLP;
440 DU_ALLOC(gNbId->global_gNB_ID.plmn_id.buf , gNbId->global_gNB_ID.plmn_id.size);
441 if(gNbId->global_gNB_ID.plmn_id.buf == NULLP)
443 DU_LOG("\nERROR --> E2AP: Memory allocation failed for Plmn buffer");
448 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
449 gNbId->global_gNB_ID.plmn_id.buf);
450 gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
451 /* Allocate Buffer size */
452 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = byteSize * sizeof(uint8_t);
453 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf = NULLP;
454 DU_ALLOC(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf, \
455 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
456 if(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf == NULLP)
458 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gnb buffer");
463 fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, gnbId);
468 DU_ALLOC( gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
469 if(gNbId->gNB_DU_ID == NULLP)
471 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gNB_DU_ID ");
476 gNbId->gNB_DU_ID->size = sizeof(uint8_t);
477 DU_ALLOC( gNbId->gNB_DU_ID->buf, sizeof(uint8_t));
478 if(gNbId->gNB_DU_ID->buf)
480 gNbId->gNB_DU_ID->buf[0] =duCb.e2apDb.e2NodeId;
484 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gNB_DU_ID buffer");
492 /*******************************************************************
494 * @brief fill the E2 node config information
498 * Function : fillE2NodeConfig
500 * Functionality: fill E2 node config information
503 * Pointer to e2NodeCfg to be filled
504 * E2 Node Component information
505 * Type of configuration
506 * @return ROK - success
509 ******************************************************************/
511 uint8_t fillE2NodeConfig(PTR e2NodeCfg, E2NodeComponent *e2NodeComponentInfo, ConfigType configType)
513 E2nodeComponentInterfaceType_t *interfaceType=NULLP;
514 E2nodeComponentID_t *componentID =NULLP;
515 E2nodeComponentConfiguration_t *configuration=NULLP;
516 E2nodeComponentConfigAddition_Item_t *e2NodeAddItem=NULL;
517 E2nodeComponentConfigUpdate_Item_t *e2NodeUpdateItem =NULL;
518 E2nodeComponentConfigRemoval_Item_t *e2NodeRemovalItem=NULL;
524 e2NodeAddItem = (E2nodeComponentConfigAddition_Item_t*)e2NodeCfg;
525 interfaceType = &e2NodeAddItem->e2nodeComponentInterfaceType;
526 componentID = &e2NodeAddItem->e2nodeComponentID;
527 configuration = &e2NodeAddItem->e2nodeComponentConfiguration;
532 e2NodeUpdateItem = (E2nodeComponentConfigUpdate_Item_t *) e2NodeCfg;
533 interfaceType = &e2NodeUpdateItem->e2nodeComponentInterfaceType;
534 componentID = &e2NodeUpdateItem->e2nodeComponentID;
535 configuration = &e2NodeUpdateItem->e2nodeComponentConfiguration;
540 e2NodeRemovalItem = (E2nodeComponentConfigRemoval_Item_t*) e2NodeCfg;
541 interfaceType = &e2NodeRemovalItem->e2nodeComponentInterfaceType;
542 componentID = &e2NodeRemovalItem->e2nodeComponentID;
547 DU_LOG("\nERROR --> E2AP : Configuration type %d does not supported ", configType);
551 /* E2nodeComponentInterfaceType */
552 *interfaceType = convertInterfaceToE2ComponentInterfaceType(e2NodeComponentInfo->interfaceType);
554 /* We now only support the F1 interface out of these interfaces
555 * (NG,XN,E1,F1,W1,S1,X2), therefore only the F1 component identifier was filled in. */
557 if(*interfaceType == F1)
559 /* E2 Node Component ID */
560 componentID->present = E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1;
561 DU_ALLOC(componentID->choice.e2nodeComponentInterfaceTypeF1,sizeof(E2nodeComponentInterfaceF1_t));
562 if(componentID->choice.e2nodeComponentInterfaceTypeF1 == NULLP)
564 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at line %d",__func__,__LINE__);
567 componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size = sizeof(uint8_t);
568 DU_ALLOC(componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
569 componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
571 if(componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf == NULLP)
573 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at line %d",__func__,__LINE__);
576 memcpy(componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf, &e2NodeComponentInfo->componentId,\
577 componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
580 if(configType == CONFIG_DEL)
582 /* We don't need to fill out the E2 Node Component Request and Response
583 * information in the case of CONFIG_DEL, therefore returning ROK from here. */
587 /* E2 Node Component Request Part */
588 if(e2NodeComponentInfo->componentRequestPart)
590 configuration->e2nodeComponentRequestPart.size = e2NodeComponentInfo->reqBufSize ;
591 DU_ALLOC(configuration->e2nodeComponentRequestPart.buf,\
592 configuration->e2nodeComponentRequestPart.size);
593 if(configuration->e2nodeComponentRequestPart.buf == NULLP)
595 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at line %d",__func__,__LINE__);
599 memcpy(configuration->e2nodeComponentRequestPart.buf,\
600 e2NodeComponentInfo->componentRequestPart, configuration->\
601 e2nodeComponentRequestPart.size);
605 DU_LOG("\nERROR --> E2AP: componentRequestPart is null ");
609 /* E2 Node Component Response Part */
610 if(e2NodeComponentInfo->componentResponsePart)
612 configuration->e2nodeComponentResponsePart.size = e2NodeComponentInfo->rspBufSize;
613 DU_ALLOC(configuration->e2nodeComponentResponsePart.buf, configuration->e2nodeComponentResponsePart.size);
614 if(configuration->e2nodeComponentResponsePart.buf == NULLP)
616 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at line %d",__func__,__LINE__);
619 memcpy(configuration->e2nodeComponentResponsePart.buf, e2NodeComponentInfo->componentResponsePart, configuration->\
620 e2nodeComponentResponsePart.size);
624 DU_LOG("\nERROR --> E2AP: componentResponsePart is null");
631 /*******************************************************************
633 * @brief Builds E2 node config addition list
637 * Function : BuildE2NodeConfigAddList
639 * Functionality: Building E2 node config addition list
642 * E2nodeComponentConfigAddition_List_t to be filled
644 * Count of E2 node to be added in the list
645 * Received list of E2 node configuration
647 * @return ROK - success
650 ******************************************************************/
652 uint8_t BuildE2NodeConfigAddList(E2nodeComponentConfigAddition_List_t *e2NodeAddList, uint8_t procedureCode, uint16_t count, E2NodeConfigItem *e2NodeList)
656 E2NodeComponent *e2NodeComponentInfo=NULL;
657 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItemIe=NULL;
658 E2nodeComponentConfigAddition_Item_t *e2NodeAddItem=NULL;
661 /* For ProcedureCodeE2_id_E2setup, the number of E2 node configuration list items is
662 * equal to the number of E2 node configuration entries stored in the database.
663 * For any other procedure, the E2 node configuration list count is equal
664 * to the count of E2 node configuration obtained from the function's caller */
666 if(procedureCode == ProcedureCodeE2_id_E2setup)
667 e2NodeAddList->list.count = duCb.e2apDb.e2NodeComponentList.count;
669 e2NodeAddList->list.count = count;
671 e2NodeAddList->list.size = e2NodeAddList->list.count * sizeof(E2nodeComponentConfigAddition_ItemIEs_t *);
672 DU_ALLOC(e2NodeAddList->list.array, e2NodeAddList->list.size);
673 if(e2NodeAddList->list.array == NULLP)
675 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
679 for(arrIdx = 0; arrIdx< e2NodeAddList->list.count; arrIdx++)
681 DU_ALLOC(e2NodeAddList->list.array[arrIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
682 if(e2NodeAddList->list.array[arrIdx] == NULLP)
684 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
688 if(procedureCode == ProcedureCodeE2_id_E2setup)
690 /* Getting all of the E2 node configuration's information from DuCb one by one*/
693 CM_LLIST_FIRST_NODE(&duCb.e2apDb.e2NodeComponentList, node);
701 DU_LOG("\nERROR --> E2AP : E2 node component list node is null");
704 e2NodeComponentInfo = (E2NodeComponent*)node->node;
708 /* Getting only those E2 node configuration from DuCb whose interface
709 * and action type is present in the received array */
710 e2NodeComponentInfo = fetchE2NodeComponentInfo(e2NodeList[arrIdx].interface, e2NodeList[arrIdx].actionType, &node);
713 if(!e2NodeComponentInfo)
715 DU_LOG("\nERROR --> E2AP : Received null e2NodeComponentInfo at line number %d",__LINE__);
719 e2NodeAddItemIe = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[arrIdx];
720 e2NodeAddItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition_Item;
721 e2NodeAddItemIe->criticality = CriticalityE2_reject;
722 e2NodeAddItemIe->value.present = E2nodeComponentConfigAddition_ItemIEs__value_PR_E2nodeComponentConfigAddition_Item;
723 e2NodeAddItem = &e2NodeAddItemIe->value.choice.E2nodeComponentConfigAddition_Item;
724 if(fillE2NodeConfig((PTR)e2NodeAddItem, e2NodeComponentInfo, CONFIG_ADD) != ROK)
726 DU_LOG("\nERROR --> E2AP : Failed to fill the E2 node configuration");
733 /*******************************************************************
735 * @brief Builds E2 node config update list
739 * Function : BuildE2NodeConfigUpdateList
741 * Functionality: Building E2 node config update list
744 * E2nodeComponentConfigUpdate_List_t to be filled
745 * Count of E2 node to be update in the list
746 * Received list of E2 node configuration
748 * @return ROK - success
751 ******************************************************************/
753 uint8_t BuildE2NodeConfigUpdateList(E2nodeComponentConfigUpdate_List_t *e2NodeUpdateList, uint16_t count, E2NodeConfigItem *updateE2Node)
757 E2NodeComponent *e2NodeComponentInfo =NULL;
758 E2nodeComponentConfigUpdate_ItemIEs_t *e2NodeUpdateItemIe =NULL;
759 E2nodeComponentConfigUpdate_Item_t *e2NodeUpdateItem =NULL;
761 e2NodeUpdateList->list.count = count;
762 e2NodeUpdateList->list.size = e2NodeUpdateList->list.count * sizeof(E2nodeComponentConfigUpdate_ItemIEs_t *);
763 DU_ALLOC(e2NodeUpdateList->list.array, e2NodeUpdateList->list.size);
764 if(e2NodeUpdateList->list.array == NULLP)
766 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigUpdateList %d",__LINE__);
770 for(arrIdx = 0; arrIdx< e2NodeUpdateList->list.count; arrIdx++)
772 DU_ALLOC(e2NodeUpdateList->list.array[arrIdx], sizeof(E2nodeComponentConfigUpdate_ItemIEs_t));
773 if(e2NodeUpdateList->list.array[arrIdx] == NULLP)
775 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigUpdateList %d",__LINE__);
779 e2NodeComponentInfo= fetchE2NodeComponentInfo(updateE2Node[arrIdx].interface, updateE2Node[arrIdx].actionType, &node);
780 if(!e2NodeComponentInfo)
782 DU_LOG("\nERROR --> E2AP : Received null e2NodeComponentInfo at line number %d",__LINE__);
786 e2NodeUpdateItemIe = (E2nodeComponentConfigUpdate_ItemIEs_t *) e2NodeUpdateList->list.array[arrIdx];
787 e2NodeUpdateItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigUpdate_Item;
788 e2NodeUpdateItemIe->criticality = CriticalityE2_reject;
789 e2NodeUpdateItemIe->value.present = E2nodeComponentConfigUpdate_ItemIEs__value_PR_E2nodeComponentConfigUpdate_Item;
790 e2NodeUpdateItem = &e2NodeUpdateItemIe->value.choice.E2nodeComponentConfigUpdate_Item;
792 if(fillE2NodeConfig((PTR)e2NodeUpdateItem, e2NodeComponentInfo, CONFIG_MOD) != ROK)
794 DU_LOG("\nERROR --> E2AP : Failed to fill the E2 node configuration");
804 /*******************************************************************
806 * @brief Builds E2 node config remove list
810 * Function :BuildE2NodeConfigRemoveList
812 * Functionality: Building E2 node config remove list
815 * E2nodeComponentConfigRemoval_List_t to be filled
816 * Count of E2 node to be remove in the list
817 * Received list of E2 node configuration
818 * @return ROK - success
821 ******************************************************************/
823 uint8_t BuildE2NodeConfigRemoveList(E2nodeComponentConfigRemoval_List_t *e2NodeRemoveList, uint16_t count, E2NodeConfigItem *updateE2Node)
827 E2NodeComponent *e2NodeComponentInfo=NULL;
828 E2nodeComponentConfigRemoval_ItemIEs_t *e2NodeRemovalItemIe=NULL;
829 E2nodeComponentConfigRemoval_Item_t *e2NodeRemovalItem=NULL;
831 e2NodeRemoveList->list.count = count;
832 e2NodeRemoveList->list.size = e2NodeRemoveList->list.count * sizeof(E2nodeComponentConfigRemoval_ItemIEs_t *);
833 DU_ALLOC(e2NodeRemoveList->list.array, e2NodeRemoveList->list.size);
834 if(e2NodeRemoveList->list.array == NULLP)
836 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigRemoveList %d",__LINE__);
840 for(arrIdx = 0; arrIdx< e2NodeRemoveList->list.count; arrIdx++)
842 DU_ALLOC(e2NodeRemoveList->list.array[arrIdx], sizeof(E2nodeComponentConfigRemoval_ItemIEs_t));
843 if(e2NodeRemoveList->list.array[arrIdx] == NULLP)
845 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigRemoveList %d",__LINE__);
849 e2NodeComponentInfo= fetchE2NodeComponentInfo(updateE2Node[arrIdx].interface, updateE2Node[arrIdx].actionType, &node);
850 if(!e2NodeComponentInfo)
852 DU_LOG("\nERROR --> E2AP : Received null e2NodeComponentInfo at line number %d",__LINE__);
856 e2NodeRemovalItemIe = (E2nodeComponentConfigRemoval_ItemIEs_t *) e2NodeRemoveList->list.array[arrIdx];
857 e2NodeRemovalItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigRemoval_Item;
858 e2NodeRemovalItemIe->criticality = CriticalityE2_reject;
859 e2NodeRemovalItemIe->value.present = E2nodeComponentConfigRemoval_ItemIEs__value_PR_E2nodeComponentConfigRemoval_Item;
860 e2NodeRemovalItem = &e2NodeRemovalItemIe->value.choice.E2nodeComponentConfigRemoval_Item;
862 if(fillE2NodeConfig((PTR)e2NodeRemovalItem, e2NodeComponentInfo, CONFIG_DEL) != ROK)
864 DU_LOG("\nERROR --> E2AP : Failed to fill the E2 node configuration");
871 /*******************************************************************
873 * @brief deallocation of E2SM_KPM_RANfunction_Description_t
877 * Function : freeE2smKpmRanFunctionDefinition
879 * Functionality: deallocation of E2SM_KPM_RANfunction_Description_t
881 * @params[in] E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition
884 ******************************************************************/
886 void freeE2smKpmRanFunctionDefinition(E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition)
888 MeasurementInfo_Action_Item_t *measInfoList;
889 uint8_t eventTriggerIdx, reportStyleIdx, measInfoIdx;
890 RANfunction_Name_t *ranFuncName;
891 struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle;
892 struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *eventTriggerStyle;
893 if(ranFunctionDefinition)
895 ranFuncName = &ranFunctionDefinition->ranFunction_Name;
896 /* Free RAN function Name */
897 DU_FREE(ranFuncName->ranFunction_ShortName.buf, ranFuncName->ranFunction_ShortName.size);
898 DU_FREE(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
899 DU_FREE(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
901 /* Sequence of Event Trigger styles */
902 eventTriggerStyle = ranFunctionDefinition->ric_EventTriggerStyle_List;
903 if(eventTriggerStyle)
905 if(eventTriggerStyle->list.array)
907 for(eventTriggerIdx =0;eventTriggerIdx<eventTriggerStyle->list.count; eventTriggerIdx++)
909 if(eventTriggerStyle->list.array[eventTriggerIdx])
911 DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.buf,\
912 eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.size);
913 DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
916 DU_FREE(eventTriggerStyle->list.array, eventTriggerStyle->list.size)
918 DU_FREE(eventTriggerStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
921 /* Sequence of Report styles */
922 ricReportStyle = ranFunctionDefinition->ric_ReportStyle_List;
925 if(ricReportStyle->list.array)
927 for(reportStyleIdx =0;reportStyleIdx<ricReportStyle->list.count; reportStyleIdx++)
929 if(ricReportStyle->list.array[reportStyleIdx])
931 if(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf)
933 DU_FREE(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf,\
934 ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.size);
936 if(ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array)
938 for(measInfoIdx=0; measInfoIdx<ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.count; \
941 measInfoList = ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array[measInfoIdx];
944 DU_FREE(measInfoList->measID, sizeof(long));
945 DU_FREE(measInfoList->measName.buf, measInfoList->measName.size);
946 DU_FREE(measInfoList,sizeof(MeasurementInfo_Action_Item_t));
949 DU_FREE(measInfoList,ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.size);
951 DU_FREE(ricReportStyle->list.array[reportStyleIdx], sizeof(RIC_ReportStyle_Item_t));
954 DU_FREE(ricReportStyle->list.array, ricReportStyle->list.size);
956 DU_FREE(ricReportStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
958 DU_FREE(ranFunctionDefinition, sizeof(E2SM_KPM_RANfunction_Description_t));
962 /*******************************************************************
964 * @brief fill the e2sm ric report style
968 * Function : fillRicReportStyle
970 * Functionality: fill the report style
972 * @params[in] RanFunction *ranFuncDb, struct
973 * E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle
974 * @return ROK - success
977 ******************************************************************/
978 uint8_t fillRicReportStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle)
980 uint8_t styleIdx, measInfoIdx;
981 MeasurementInfo_Action_List_t *measInfo;
984 ricReportStyle->list.count = ranFuncDb->numOfReportStyleSupported;
985 ricReportStyle->list.size = ricReportStyle->list.count * sizeof(RIC_ReportStyle_Item_t*);
986 DU_ALLOC(ricReportStyle->list.array, ricReportStyle->list.size);
987 if(!ricReportStyle->list.array)
989 DU_LOG("\nERROR --> E2AP: Memory allocation failed for ranFuncDefinition %d",__LINE__);
993 for(styleIdx =0;styleIdx<ricReportStyle->list.count; styleIdx++)
995 DU_ALLOC(ricReportStyle->list.array[styleIdx], sizeof(RIC_ReportStyle_Item_t));
996 if(!ricReportStyle->list.array[styleIdx])
998 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1002 /* RIC Report Style Type */
1003 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.styleType;
1005 /* RIC Report Style Format Type */
1006 ricReportStyle->list.array[styleIdx]->ric_ActionFormat_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.formatType;
1008 /* RIC Report Style Name */
1009 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size = strlen(ranFuncDb->reportStyleList[styleIdx].reportStyle.name);
1010 DU_ALLOC(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf,\
1011 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
1012 if(!ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf)
1014 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1017 memcpy(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf, ranFuncDb->reportStyleList[styleIdx].reportStyle.name,\
1018 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
1020 /* RIC Indication Header Format Type*/
1021 ricReportStyle->list.array[styleIdx]->ric_IndicationHeaderFormat_Type = ranFuncDb->ricIndicationHeaderFormat;
1023 /* RIC Indication Message Format Type*/
1024 ricReportStyle->list.array[styleIdx]->ric_IndicationMessageFormat_Type = ranFuncDb->ricIndicationMessageFormat;
1026 /* Measurement Info Action List */
1027 CmLListCp measInfoList =ranFuncDb->reportStyleList[styleIdx].measurementInfoList;
1028 if(!measInfoList.count)
1033 CM_LLIST_FIRST_NODE(&ranFuncDb->reportStyleList[styleIdx].measurementInfoList, node);
1034 measInfo = &ricReportStyle->list.array[styleIdx]->measInfo_Action_List;
1036 measInfo->list.count = measInfoList.count;
1037 measInfo->list.size = measInfoList.count*sizeof(MeasurementInfo_Action_Item_t*);
1038 DU_ALLOC(measInfo->list.array, measInfo->list.size);
1039 if(!measInfo->list.array)
1041 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1045 for(measInfoIdx=0; measInfoIdx<measInfo->list.count; measInfoIdx++)
1049 DU_LOG("\nERROR --> E2AP: Measurement info node is null");
1053 DU_ALLOC(measInfo->list.array[measInfoIdx],sizeof(MeasurementInfo_Action_Item_t));
1054 if(!measInfo->list.array[measInfoIdx])
1056 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1059 MeasurementInfoForAction *measInfoForAction= (MeasurementInfoForAction*)node->node;
1060 DU_ALLOC(measInfo->list.array[measInfoIdx]->measID, sizeof(long));
1061 if(!measInfo->list.array[measInfoIdx]->measID)
1063 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1067 memcpy(measInfo->list.array[measInfoIdx]->measID, &measInfoForAction->measurementTypeId,sizeof(long));
1068 measInfo->list.array[measInfoIdx]->measName.size= strlen(measInfoForAction->measurementTypeName);
1069 DU_ALLOC(measInfo->list.array[measInfoIdx]->measName.buf, measInfo->list.array[measInfoIdx]->measName.size);
1070 if(!measInfo->list.array[measInfoIdx]->measName.size)
1072 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1076 memcpy(measInfo->list.array[measInfoIdx]->measName.buf, \
1077 measInfoForAction->measurementTypeName,\
1078 measInfo->list.array[measInfoIdx]->measName.size);
1085 /*******************************************************************
1087 * @brief fill the ric event trigger style
1091 * Function : fillRicEventTriggerStyle
1093 * Functionality: fill the ric event trigger style
1096 * @return ROK - success
1099 ******************************************************************/
1100 uint8_t fillRicEventTriggerStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *ricEventTriggerStyle)
1104 ricEventTriggerStyle->list.count = ranFuncDb->numOfEventTriggerStyleSupported;
1105 ricEventTriggerStyle->list.size = ricEventTriggerStyle->list.count* sizeof(RIC_EventTriggerStyle_Item_t *);
1106 DU_ALLOC(ricEventTriggerStyle->list.array, ricEventTriggerStyle->list.size);
1107 if(!ricEventTriggerStyle->list.array)
1109 DU_LOG("\nERROR --> E2AP: Memory allocation failed for ric_EventTriggerStyle_List %d",__LINE__);
1113 for(styleIdx =0;styleIdx<ricEventTriggerStyle->list.count; styleIdx++)
1115 DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
1116 if(!ricEventTriggerStyle->list.array[styleIdx])
1118 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1121 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Type = ranFuncDb->eventTriggerStyleList[styleIdx].styleType;
1123 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerFormat_Type = ranFuncDb->eventTriggerStyleList[styleIdx].formatType;
1125 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size = strlen(ranFuncDb->eventTriggerStyleList[styleIdx].name);
1126 DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,\
1127 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
1128 if(!ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf)
1130 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1133 memcpy(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,ranFuncDb->eventTriggerStyleList[styleIdx].name,\
1134 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
1140 /*******************************************************************
1142 * @brief Builds Ran function item
1146 * Function : BuildRanFunctionItem
1148 * Functionality: Building RAN function item
1151 * RAN function item that has to be filled
1152 * Stored RAN Function information
1153 * @return ROK - success
1156 ******************************************************************/
1158 uint8_t BuildRanFunctionItem(RANfunction_Item_t *ranFuncItem, RanFunction *ranFuncDb)
1160 uint8_t ret =RFAILED;
1161 RANfunctionDefinition_t *ranFunctionDefinition;
1162 RANfunction_Name_t *ranFuncName;
1163 asn_enc_rval_t encRetVal;
1164 E2SM_KPM_RANfunction_Description_t *ranFuncDefinition;
1168 /* RAN function Id*/
1169 ranFuncItem->ranFunctionID = ranFuncDb->id;
1171 /* RAN Function Revision*/
1172 ranFuncItem->ranFunctionRevision = ranFuncDb->revisionCounter;
1174 /* RAN function OID*/
1175 ranFuncItem->ranFunctionOID.size = strlen(ranFuncDb->name.serviceModelOID);
1176 DU_ALLOC(ranFuncItem->ranFunctionOID.buf, ranFuncItem->ranFunctionOID.size);
1177 if(!ranFuncItem->ranFunctionOID.buf)
1179 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1182 memcpy(ranFuncItem->ranFunctionOID.buf, ranFuncDb->name.serviceModelOID, ranFuncItem->ranFunctionOID.size);
1184 /* RAN function Definition */
1185 DU_ALLOC(ranFuncDefinition, sizeof(E2SM_KPM_RANfunction_Description_t));
1186 if(!ranFuncDefinition)
1188 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1192 /* RAN function Name */
1193 ranFuncName = &ranFuncDefinition->ranFunction_Name;
1195 /* RAN function ShortName */
1196 ranFuncName->ranFunction_ShortName.size = strlen(ranFuncDb->name.shortName);
1197 DU_ALLOC(ranFuncName->ranFunction_ShortName.buf, ranFuncName->ranFunction_ShortName.size);
1198 if(!ranFuncName->ranFunction_ShortName.buf)
1200 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1203 memcpy(ranFuncName->ranFunction_ShortName.buf, ranFuncDb->name.shortName, strlen(ranFuncDb->name.shortName));
1205 /* RAN function E2SM_OID */
1206 ranFuncName->ranFunction_E2SM_OID.size = strlen(ranFuncDb->name.serviceModelOID);
1207 DU_ALLOC(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
1208 if(!ranFuncName->ranFunction_E2SM_OID.buf)
1210 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1213 memcpy(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncDb->name.serviceModelOID, ranFuncName->ranFunction_E2SM_OID.size);
1215 /* RAN Function Name Description */
1216 ranFuncName->ranFunction_Description.size = strlen(ranFuncDb->name.description);
1217 DU_ALLOC(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
1218 if(!ranFuncName->ranFunction_Description.buf)
1220 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1223 memcpy(ranFuncName->ranFunction_Description.buf, ranFuncDb->name.description, ranFuncName->ranFunction_Description.size);
1225 /* RIC Event Trigger Style List */
1226 DU_ALLOC(ranFuncDefinition->ric_EventTriggerStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
1227 if(!ranFuncDefinition->ric_EventTriggerStyle_List)
1229 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1233 if(fillRicEventTriggerStyle(ranFuncDb, ranFuncDefinition->ric_EventTriggerStyle_List)!=ROK)
1235 DU_LOG("\nERROR --> E2AP: failed to fill ric event trigger style");
1239 /* RIC Report Style List */
1240 DU_ALLOC(ranFuncDefinition->ric_ReportStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
1241 if(!ranFuncDefinition->ric_ReportStyle_List)
1243 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1246 if(fillRicReportStyle(ranFuncDb, ranFuncDefinition->ric_ReportStyle_List) != ROK)
1248 DU_LOG("\nERROR --> E2AP: failed to fill ric report style");
1252 /* Encode the F1SetupRequest type as APER */
1253 xer_fprint(stdout, &asn_DEF_E2SM_KPM_RANfunction_Description, ranFuncDefinition);
1255 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1257 encRetVal = aper_encode(&asn_DEF_E2SM_KPM_RANfunction_Description, 0, ranFuncDefinition, PrepFinalEncBuf, encBuf);
1259 /* Encode results */
1260 if(encRetVal.encoded == ENCODE_FAIL)
1262 DU_LOG("\nERROR --> F1AP : Could not encode RAN function definition (at %s)\n",\
1263 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1268 DU_LOG("\nDEBUG --> F1AP : Created APER encoded buffer for RAN function definition \n");
1269 for(uint8_t measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
1271 printf("%x",encBuf[measIeIdx]);
1273 ranFunctionDefinition = &ranFuncItem->ranFunctionDefinition;
1274 ranFunctionDefinition->size = encBufSize;
1275 DU_ALLOC(ranFunctionDefinition->buf, encBufSize);
1276 if(ranFunctionDefinition->buf == NULLP)
1278 DU_LOG("\nERROR --> F1AP : Memory allocation failed for RAN function definition buffer");
1281 memcpy(ranFunctionDefinition->buf, &encBuf, encBufSize);
1286 freeE2smKpmRanFunctionDefinition(ranFuncDefinition);
1290 /*******************************************************************
1292 * @brief Builds Ran function add list based on the procedure code
1296 * Function : BuildRanFunctionAddList
1298 * Functionality: Building RAN addition addition list
1299 * In case of ProcedureCodeE2_id_E2setup we add all the RAN Function list
1300 * which is present in E2 database.
1301 * In the case of other procedures, we just fill the RAN functions whose ID
1302 * is contained in recvList
1307 * Count of ran functions to be added in the list
1308 * Received list of RAN functions
1310 * @return ROK - success
1313 ******************************************************************/
1315 uint8_t BuildRanFunctionAddList(RANfunctions_List_t *ranFunctionsList, uint8_t procedureCode, uint8_t count, RanFuncInfo *recvList)
1318 RanFunction *ranFuncDb;
1320 RANfunction_ItemIEs_t *ranFuncItemIe;
1322 /* For ProcedureCodeE2_id_E2setup, the number of RAN function list items is
1323 * equal to the number of ran function entries stored in the database.
1324 * For any other procedure, the RAN function list count is equal
1325 * to the count of ran functions obtained from the function's caller */
1327 if(procedureCode == ProcedureCodeE2_id_E2setup)
1328 ranFunctionsList->list.count = duCb.e2apDb.numOfRanFunction;
1330 ranFunctionsList->list.count = count;
1332 ranFunctionsList->list.size = ranFunctionsList->list.count * sizeof(RANfunction_ItemIEs_t*);
1333 DU_ALLOC(ranFunctionsList->list.array, ranFunctionsList->list.size);
1334 if(ranFunctionsList->list.array == NULLP)
1336 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
1340 for(ranFuncIdx = 0; ranFuncIdx< ranFunctionsList->list.count; ranFuncIdx++)
1342 DU_ALLOC(ranFunctionsList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
1343 if(ranFunctionsList->list.array[ranFuncIdx] == NULLP)
1345 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
1348 if(procedureCode == ProcedureCodeE2_id_E2setup)
1350 /* Getting all of the RAN function's information from DuCb one by one*/
1351 ranFuncDb = &duCb.e2apDb.ranFunction[ranFuncIdx];
1355 /* Getting only the RAN function information from DuCb whose Id is
1356 * present in the received array */
1357 id =recvList[ranFuncIdx].id;
1358 ranFuncDb = &duCb.e2apDb.ranFunction[id-1];
1360 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncIdx];
1361 ranFuncItemIe->id = ProtocolIE_IDE2_id_RANfunction_Item;
1362 ranFuncItemIe->criticality = CriticalityE2_ignore;
1363 ranFuncItemIe->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
1364 BuildRanFunctionItem(&ranFuncItemIe->value.choice.RANfunction_Item, ranFuncDb);
1369 /*******************************************************************
1371 * @brief De Allocate E2 Setup Request Message
1375 * Function : FreeE2SetupReq
1377 * Functionality: De-Allocating E2 Setup request Message
1379 * @params[in] E2AP_PDU_t *e2apMsg
1383 * ****************************************************************/
1385 void FreeE2SetupReq(E2AP_PDU_t *e2apMsg)
1388 uint8_t e2NodeAddListIdx =0, ranFuncAddListIdx;
1389 E2setupRequest_t *e2SetupReq;
1390 E2nodeComponentConfigAddition_List_t *e2NodeAddList;
1391 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem;
1392 RANfunctions_List_t *ranFunctionsList;
1393 RANfunction_ItemIEs_t *ranFuncItemIe;
1394 RANfunction_Item_t *ranFunItem;
1396 /* De-allocating Memory */
1397 if(e2apMsg != NULLP)
1399 if(e2apMsg->choice.initiatingMessage != NULLP)
1401 e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
1402 if(e2SetupReq->protocolIEs.list.array != NULLP)
1404 for(arrIdx = 0; arrIdx < e2SetupReq->protocolIEs.list.count; arrIdx++)
1406 if(e2SetupReq->protocolIEs.list.array[arrIdx] != NULLP)
1408 switch(e2SetupReq->protocolIEs.list.array[arrIdx]->id)
1410 case ProtocolIE_IDE2_id_TransactionID:
1412 case ProtocolIE_IDE2_id_GlobalE2node_ID:
1414 if(e2SetupReq->protocolIEs.list.array[arrIdx]->\
1415 value.choice.GlobalE2node_ID.choice.gNB != NULLP)
1417 GlobalE2node_gNB_ID_t *gNbId = NULLP;
1418 gNbId = e2SetupReq->protocolIEs.list.array[arrIdx]->\
1419 value.choice.GlobalE2node_ID.choice.gNB;
1420 if(gNbId->global_gNB_ID.plmn_id.buf != NULLP)
1422 DU_FREE(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf,\
1423 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
1424 DU_FREE(gNbId->global_gNB_ID.plmn_id.buf,\
1425 gNbId->global_gNB_ID.plmn_id.size);
1428 if(gNbId->gNB_DU_ID != NULLP)
1430 DU_FREE( gNbId->gNB_DU_ID->buf, gNbId->gNB_DU_ID->size);
1431 DU_FREE(gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
1433 DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
1434 choice.GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
1438 case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
1440 e2NodeAddList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List;
1441 if(e2NodeAddList->list.array)
1443 for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++)
1445 e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[e2NodeAddListIdx];
1447 /* Free E2 Node Component Request Part */
1448 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
1449 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
1451 /* Free E2 Node Component Response Part */
1452 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.\
1453 e2nodeComponentResponsePart.buf, \
1454 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
1456 /* Free E2 Node Component ID */
1457 if(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1)
1459 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
1460 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
1461 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
1462 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
1463 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
1464 sizeof(E2nodeComponentInterfaceF1_t));
1466 DU_FREE(e2NodeAddList->list.array[e2NodeAddListIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
1468 DU_FREE(e2NodeAddList->list.array, e2NodeAddList->list.size);
1472 case ProtocolIE_IDE2_id_RANfunctionsAdded:
1474 ranFunctionsList = &(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List);
1475 if(ranFunctionsList->list.array)
1477 for(ranFuncAddListIdx= 0; ranFuncAddListIdx< ranFunctionsList->list.count; ranFuncAddListIdx++)
1479 if(ranFunctionsList->list.array[ranFuncAddListIdx])
1481 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncAddListIdx];
1482 ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
1483 DU_FREE(ranFunItem->ranFunctionOID.buf, ranFunItem->ranFunctionOID.size);
1484 DU_FREE(ranFunItem->ranFunctionDefinition.buf, ranFunItem->ranFunctionDefinition.size);
1485 DU_FREE(ranFunctionsList->list.array[ranFuncAddListIdx], sizeof(RANfunction_ItemIEs_t));
1488 DU_FREE(ranFunctionsList->list.array, ranFunctionsList->list.size);
1494 DU_LOG("\nERROR --> E2AP: Invalid event at e2SetupRequet %ld ",\
1495 (e2SetupReq->protocolIEs.list.array[arrIdx]->id));
1498 DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx], sizeof(E2setupRequestIEs_t));
1501 DU_FREE(e2SetupReq->protocolIEs.list.array, e2SetupReq->protocolIEs.list.size);
1503 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1505 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
1509 /*******************************************************************
1511 * @brief Builds and Send the E2SetupRequest
1515 * Function : BuildAndSendE2SetupReq
1517 * Functionality:Fills the E2SetupRequest
1519 * @return ROK - success
1522 ******************************************************************/
1524 uint8_t BuildAndSendE2SetupReq()
1526 uint8_t arrIdx = 0, elementCnt=0;
1527 uint8_t transId = 0, ret = ROK;
1528 bool memAllocFailed;
1529 E2AP_PDU_t *e2apMsg = NULLP;
1530 E2setupRequest_t *e2SetupReq = NULLP;
1531 asn_enc_rval_t encRetVal; /* Encoder return value */
1533 DU_LOG("\nINFO --> E2AP : Building E2 Setup Request\n");
1536 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
1537 if(e2apMsg == NULLP)
1539 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1542 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
1543 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1544 if(e2apMsg->choice.initiatingMessage == NULLP)
1546 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1549 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
1550 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2setup;
1551 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_E2setupRequest;
1552 e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
1555 e2SetupReq->protocolIEs.list.count = elementCnt;
1556 e2SetupReq->protocolIEs.list.size = elementCnt * sizeof(E2setupRequestIEs_t*);
1558 /* Initialize the E2Setup members */
1559 DU_ALLOC(e2SetupReq->protocolIEs.list.array, \
1560 e2SetupReq->protocolIEs.list.size);
1561 if(e2SetupReq->protocolIEs.list.array == NULLP)
1563 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements");
1566 for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
1568 DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx],\
1569 sizeof(E2setupRequestIEs_t));
1570 if(e2SetupReq->protocolIEs.list.array[arrIdx] == NULLP)
1572 memAllocFailed = true;
1573 DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayarrIdx [%d]", arrIdx);
1577 if(memAllocFailed == true)
1583 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
1584 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1585 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
1586 transId = assignTransactionId();
1587 e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
1590 /* GlobalE2node_gNB_ID */
1591 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_GlobalE2node_ID;
1592 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1593 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
1594 e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
1596 DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
1597 GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
1598 if(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
1599 GlobalE2node_ID.choice.gNB == NULLP)
1601 DU_LOG("\nERROR --> E2AP : Memory allocation failed for gNbId");
1606 ret = BuildGlobalgNBId(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
1607 choice.GlobalE2node_ID.choice.gNB);
1610 DU_LOG("\nERROR --> E2AP : Failed to build Global Gnb Id");
1615 /* RAN Functions Added List */
1617 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
1618 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1619 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_RANfunctions_List;
1620 if(BuildRanFunctionAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List), ProcedureCodeE2_id_E2setup, 0, NULL)!=ROK)
1622 DU_LOG("\nERROR --> E2AP : Failed to create RAN Function");
1626 /* E2 Node Component Configuration Addition List */
1628 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition;
1629 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1630 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_E2nodeComponentConfigAddition_List;
1631 if(BuildE2NodeConfigAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List), ProcedureCodeE2_id_E2setup, 0, NULL)!=ROK)
1633 DU_LOG("\nERROR --> E2AP : Failed to create E2 Node config list");
1639 /* Prints the Msg formed */
1640 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1642 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1644 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
1646 if(encRetVal.encoded == ENCODE_FAIL)
1648 DU_LOG("\nERROR --> E2AP : Could not encode E2SetupRequest structure (at %s)\n",\
1649 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1654 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupRequest\n");
1655 #ifdef DEBUG_ASN_PRINT
1656 for(int i=0; i< encBufSize; i++)
1658 printf("%x",encBuf[i]);
1662 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
1664 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
1669 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
1670 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
1672 FreeE2SetupReq(e2apMsg);
1674 }/* End of BuildAndSendE2SetupReq */
1676 /*******************************************************************
1678 * @brief Builds RIC Action Admitted List
1682 * Function : BuildRicActionAdmitList
1684 * Functionality: Builds RIC Action Admitted List
1686 * @params[in] Pointer to RIC Action Admitted List to be filled
1687 * Subscription Response information
1688 * @return ROK - success
1691 * ****************************************************************/
1692 uint8_t BuildRicActionAdmitList(RICaction_Admitted_List_t *admitList, PendingSubsRspInfo *subsRspInfo)
1695 uint8_t elementCnt = 0;
1696 RICaction_Admitted_ItemIEs_t *admitItem = NULLP;
1698 elementCnt = subsRspInfo->numOfAcceptedActions;
1700 admitList->list.count = elementCnt;
1701 admitList->list.size = elementCnt * sizeof(RICaction_Admitted_ItemIEs_t *);
1703 DU_ALLOC(admitList->list.array, admitList->list.size);
1704 if(admitList->list.array == NULLP)
1706 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1710 for(idx=0; idx<elementCnt; idx++)
1712 DU_ALLOC(admitList->list.array[idx], sizeof(RICaction_Admitted_ItemIEs_t));
1713 if(admitList->list.array[idx] == NULLP)
1715 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1719 admitItem = (RICaction_Admitted_ItemIEs_t *)admitList->list.array[idx];
1720 admitItem->id = ProtocolIE_IDE2_id_RICaction_Admitted_Item;
1721 admitItem->criticality = CriticalityE2_reject;
1722 admitItem->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
1723 admitItem->value.choice.RICaction_Admitted_Item.ricActionID = subsRspInfo->acceptedActionList[idx];
1728 /*******************************************************************
1730 * @brief Builds RIC Action Not Admitted List
1734 * Function : BuildRicActionNotAdmitList
1736 * Functionality: Builds RIC Action Not Admitted List
1738 * @params[in] Pointer to RIC Action Not Admitted List to be filled
1739 * Subscription Response information
1740 * @return ROK - success
1743 * ****************************************************************/
1744 uint8_t BuildRicActionNotAdmitList(RICaction_NotAdmitted_List_t *notAdmitList, PendingSubsRspInfo *subsRspInfo)
1747 uint8_t elementCnt = 0;
1748 RICaction_NotAdmitted_ItemIEs_t *notAdmitItem = NULLP;
1750 elementCnt = subsRspInfo->numOfRejectedActions;
1752 notAdmitList->list.count = elementCnt;
1753 notAdmitList->list.size = elementCnt * sizeof(RICaction_NotAdmitted_ItemIEs_t *);
1755 DU_ALLOC(notAdmitList->list.array, notAdmitList->list.size);
1756 if(notAdmitList->list.array == NULLP)
1758 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1762 for(idx=0; idx<elementCnt; idx++)
1764 DU_ALLOC(notAdmitList->list.array[idx], sizeof(RICaction_NotAdmitted_ItemIEs_t));
1765 if(notAdmitList->list.array[idx] == NULLP)
1767 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1771 notAdmitItem = (RICaction_NotAdmitted_ItemIEs_t *)notAdmitList->list.array[idx];
1772 notAdmitItem->id = ProtocolIE_IDE2_id_RICaction_NotAdmitted_Item;
1773 notAdmitItem->criticality = CriticalityE2_reject;
1774 notAdmitItem->value.present = RICaction_NotAdmitted_ItemIEs__value_PR_RICaction_NotAdmitted_Item;
1775 notAdmitItem->value.choice.RICaction_NotAdmitted_Item.ricActionID = \
1776 subsRspInfo->rejectedActionList[idx].id;
1777 fillE2Cause(¬AdmitItem->value.choice.RICaction_NotAdmitted_Item.cause, \
1778 subsRspInfo->rejectedActionList[idx].failureCause);
1783 /*******************************************************************
1785 * @breif Deallocation of BuildAndSendRicSubscriptionRsp memory
1789 * Function : FreeRicSubscriptionRsp
1791 * Functionality:Free the RicSubscriptionRsp
1793 * @param[in] E2AP_PDU_t *e2apRicMsg
1797 ******************************************************************/
1798 void FreeRicSubscriptionRsp(E2AP_PDU_t *e2apRicMsg)
1800 RICsubscriptionResponse_t *ricSubscriptionRsp= NULLP;
1803 RICaction_Admitted_List_t *admitList = NULLP;
1804 RICaction_NotAdmitted_List_t *notAdmitList = NULLP;
1806 if(e2apRicMsg != NULLP)
1808 if(e2apRicMsg->choice.successfulOutcome != NULLP)
1810 ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
1811 if(ricSubscriptionRsp)
1813 if(ricSubscriptionRsp->protocolIEs.list.array != NULLP)
1815 for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
1817 if(ricSubscriptionRsp->protocolIEs.list.array[idx] != NULLP)
1819 switch(ricSubscriptionRsp->protocolIEs.list.array[idx]->id)
1821 case ProtocolIE_IDE2_id_RICactions_Admitted:
1823 admitList = &ricSubscriptionRsp->protocolIEs.list.\
1824 array[idx]->value.choice.RICaction_Admitted_List;
1825 if(admitList->list.array != NULLP)
1827 for(listIdx=0 ; listIdx < admitList->list.count; listIdx++)
1829 DU_FREE(admitList->list.array[listIdx], sizeof(RICaction_Admitted_ItemIEs_t));
1831 DU_FREE(admitList->list.array, admitList->list.size);
1835 case ProtocolIE_IDE2_id_RICactions_NotAdmitted:
1837 notAdmitList = &ricSubscriptionRsp->protocolIEs.list.\
1838 array[idx]->value.choice.RICaction_NotAdmitted_List;
1839 if(notAdmitList->list.array != NULLP)
1841 for(listIdx=0 ; listIdx < notAdmitList->list.count; listIdx++)
1843 DU_FREE(notAdmitList->list.array[listIdx], sizeof(RICaction_NotAdmitted_ItemIEs_t));
1845 DU_FREE(notAdmitList->list.array, notAdmitList->list.size);
1852 DU_FREE(ricSubscriptionRsp->protocolIEs.list.array[idx], sizeof(RICsubscriptionResponse_IEs_t));
1855 DU_FREE(ricSubscriptionRsp->protocolIEs.list.array, ricSubscriptionRsp->protocolIEs.list.size);
1858 DU_FREE(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
1860 DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
1864 /*******************************************************************
1866 * @brief Fill RIC Subscription Response IEs
1870 * Function : fillRicSubscriptionRsp
1872 * functionality: Fill RIC Subscription Response IEs
1874 * @param Pointer to RIC subscription response
1875 * Subscription response information
1876 * @return ROK - success
1879 ******************************************************************/
1880 uint8_t fillRicSubscriptionRsp(RICsubscriptionResponse_t *ricSubscriptionRsp, PendingSubsRspInfo *subsRspInfo)
1883 uint8_t elementCnt = 0;
1884 RICsubscriptionResponse_IEs_t *subsRspIe = NULLP;
1887 if(subsRspInfo->numOfRejectedActions)
1890 ricSubscriptionRsp->protocolIEs.list.count = elementCnt;
1891 ricSubscriptionRsp->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionResponse_IEs_t);
1892 DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array, ricSubscriptionRsp->protocolIEs.list.size);
1893 if(ricSubscriptionRsp->protocolIEs.list.array == NULLP)
1895 DU_LOG("\nERROR --> E2AP : Memory allocation failed at %s : line %d", __func__, __LINE__);
1899 for(ieIdx=0; ieIdx<ricSubscriptionRsp->protocolIEs.list.count; ieIdx++)
1901 DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array[ieIdx], sizeof(RICsubscriptionResponse_IEs_t));
1902 if(ricSubscriptionRsp->protocolIEs.list.array[ieIdx] == NULLP)
1904 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d] : ieIdx [%d]", __func__, __LINE__,ieIdx);
1909 /* RIC Request ID */
1911 subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
1912 subsRspIe->id = ProtocolIE_IDE2_id_RICrequestID;
1913 subsRspIe->criticality = CriticalityE2_reject;
1914 subsRspIe->value.present = RICsubscriptionRequest_IEs__value_PR_RICrequestID;
1915 subsRspIe->value.choice.RICrequestID.ricRequestorID = subsRspInfo->requestId.requestorId;
1916 subsRspIe->value.choice.RICrequestID.ricInstanceID = subsRspInfo->requestId.instanceId;
1918 /* RAN Function ID */
1920 subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
1921 subsRspIe->id = ProtocolIE_IDE2_id_RANfunctionID;
1922 subsRspIe->criticality = CriticalityE2_reject;
1923 subsRspIe->value.present = RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
1924 subsRspIe->value.choice.RANfunctionID = subsRspInfo->ranFuncId;
1926 /* RIC Action Admitted List */
1928 subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
1929 subsRspIe->id = ProtocolIE_IDE2_id_RICactions_Admitted;
1930 subsRspIe->criticality = CriticalityE2_reject;
1931 subsRspIe->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
1932 if(BuildRicActionAdmitList(&subsRspIe->value.choice.RICaction_Admitted_List, subsRspInfo) != ROK)
1934 DU_LOG("\nERROR --> E2AP : Failed to fill RIC Action Admitted List in RIC Subscription Response");
1938 /* RIC Action Not Admitted List */
1939 if(subsRspInfo->numOfRejectedActions)
1942 subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
1943 subsRspIe->id = ProtocolIE_IDE2_id_RICactions_NotAdmitted;
1944 subsRspIe->criticality = CriticalityE2_reject;
1945 subsRspIe->criticality = CriticalityE2_reject;
1946 subsRspIe->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_NotAdmitted_List;
1947 if(BuildRicActionNotAdmitList(&subsRspIe->value.choice.RICaction_NotAdmitted_List, subsRspInfo) != ROK)
1949 DU_LOG("\nERROR --> E2AP : Failed to fill RIC Action Not Admitted List in RIC Subscription Response");
1957 /*******************************************************************
1959 * @brief Builds and Send the RicSubscriptionRsp
1963 * Function : BuildAndSendRicSubscriptionRsp
1965 * Functionality:Fills the RicSubscriptionRsp
1967 * @return ROK - success
1970 ******************************************************************/
1972 uint8_t BuildAndSendRicSubscriptionRsp(PendingSubsRspInfo *subsRspInfo)
1974 uint8_t ret = RFAILED;
1975 E2AP_PDU_t *e2apRicMsg = NULLP;
1976 RICsubscriptionResponse_t *ricSubscriptionRsp=NULLP;
1977 asn_enc_rval_t encRetVal;
1981 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Response\n");
1983 DU_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t));
1984 if(e2apRicMsg == NULLP)
1986 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1990 e2apRicMsg->present = E2AP_PDU_PR_successfulOutcome;
1991 DU_ALLOC(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
1992 if(e2apRicMsg->choice.successfulOutcome == NULLP)
1994 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC subscription Response failed");
1998 e2apRicMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
1999 e2apRicMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
2000 e2apRicMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse;
2002 ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
2004 if(fillRicSubscriptionRsp(ricSubscriptionRsp, subsRspInfo) != ROK)
2006 DU_LOG("\nERROR --> E2AP : Memory allocation for RICsubscriptionResponseIE failed");
2010 /* Prints the Msg formed */
2011 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg);
2013 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2015 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apRicMsg, PrepFinalEncBuf, encBuf);
2016 if(encRetVal.encoded == ENCODE_FAIL)
2018 DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Response structure (at %s)\n",\
2019 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2024 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC subscription response \n");
2025 #ifdef DEBUG_ASN_PRINT
2026 for(int i=0; i< encBufSize; i++)
2028 printf("%x",encBuf[i]);
2033 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
2035 DU_LOG("\nERROR --> E2AP : Sending RIC Subscription Response failed");
2044 FreeRicSubscriptionRsp(e2apRicMsg);
2048 /******************************************************************
2050 * @brief Deallocation of memory allocated by aper decoder for e2 setup response
2054 * Function : freeAperDecodingOfE2SetupRsp
2056 * Functionality: Deallocation of memory allocated by aper decoder for e2
2059 * @params[in] E2setupResponse_t *e2SetRspMsg;
2062 * ****************************************************************/
2063 void freeAperDecodingOfE2SetupRsp(E2setupResponse_t *e2SetRspMsg)
2065 uint8_t arrIdx, e2NodeConfigAddAckListIdx;
2066 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem;
2067 E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAddAckList;
2071 if(e2SetRspMsg->protocolIEs.list.array)
2073 for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
2075 if(e2SetRspMsg->protocolIEs.list.array[arrIdx])
2077 switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
2079 case ProtocolIE_IDE2_id_TransactionID:
2082 case ProtocolIE_IDE2_id_GlobalRIC_ID:
2084 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.pLMN_Identity.buf);
2085 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID.buf);
2089 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
2091 e2NodeConfigAddAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
2092 if(e2NodeConfigAddAckList->list.array )
2094 for(e2NodeConfigAddAckListIdx = 0; e2NodeConfigAddAckListIdx< e2NodeConfigAddAckList->list.count; e2NodeConfigAddAckListIdx++)
2096 if(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx])
2098 e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx];
2099 free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
2100 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf);
2101 free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
2102 e2nodeComponentInterfaceTypeF1);
2103 free(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx]);
2106 free(e2NodeConfigAddAckList->list.array);
2111 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]);
2114 free(e2SetRspMsg->protocolIEs.list.array);
2118 /******************************************************************
2120 * @brief Processes E2 Setup Response sent by RIC
2124 * Function : procE2SetupRsp
2126 * Functionality: Processes E2 Setup Response sent by RIC
2128 * @params[in] E2AP_PDU_t ASN decoded E2AP message
2129 * @return ROK - success
2132 * ****************************************************************/
2134 uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
2136 uint8_t arrIdx =0, transId=0, idx=0;
2137 uint32_t recvBufLen;
2138 E2setupResponse_t *e2SetRspMsg=NULL;
2140 E2NodeComponent *e2NodeComponentInfo=NULL;
2141 E2nodeComponentConfigAdditionAck_List_t *e2NodeCfgAckList=NULL;
2142 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem=NULL;
2144 DU_LOG("\nINFO --> E2AP : E2 Setup Response received");
2145 duCb.e2Status = TRUE; //Set E2 status as true
2146 e2SetRspMsg = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
2148 for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
2150 switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
2152 case ProtocolIE_IDE2_id_TransactionID:
2154 transId = e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
2155 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
2156 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
2158 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
2162 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
2168 case ProtocolIE_IDE2_id_GlobalRIC_ID:
2170 /* To store the Ric Id Params */
2171 recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value\
2172 .choice.GlobalRIC_ID.pLMN_Identity.size);
2173 memcpy(&duCb.e2apDb.ricId.plmnId, e2SetRspMsg->protocolIEs.list.array[arrIdx]\
2174 ->value.choice.GlobalRIC_ID.pLMN_Identity.buf, recvBufLen);
2175 bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID, &duCb.e2apDb.ricId);
2176 /*TODO : duCb.e2apDb.ricId.plmnId memory to be deallocated after the usage */
2180 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
2182 e2NodeCfgAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
2183 for(idx =0; idx <e2NodeCfgAckList->list.count; idx++)
2185 e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeCfgAckList->list.array[idx];
2186 switch(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.present)
2188 case E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1:
2190 e2NodeComponentInfo = fetchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD, &node);
2191 if(!e2NodeComponentInfo)
2193 DU_LOG("\nERROR --> E2AP : Received null e2NodeComponentInfo at line number %d",__LINE__);
2198 cmLListDelFrm(&duCb.e2apDb.e2NodeComponentList, node);
2199 DU_FREE(e2NodeComponentInfo->componentRequestPart, e2NodeComponentInfo->reqBufSize);
2200 DU_FREE(e2NodeComponentInfo->componentResponsePart, e2NodeComponentInfo->rspBufSize);
2201 DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
2202 DU_FREE(node, sizeof(CmLList));
2214 DU_LOG("\nERROR --> E2AP : Invalid IE received in E2SetupRsp:%ld",
2215 e2SetRspMsg->protocolIEs.list.array[arrIdx]->id);
2219 freeAperDecodingOfE2SetupRsp(e2SetRspMsg);
2221 if(duSendE2NodeConfigurationUpdate() != ROK)
2223 DU_LOG("\nERROR --> E2AP : Failed to send E2 node config update");
2229 /*******************************************************************
2231 * @brief Free RIC Subscription Request
2235 * Function : freeAperDecodingOfRicSubsReq
2237 * Functionality : Free RIC Subscription Request
2241 ******************************************************************/
2242 void freeAperDecodingOfRicSubsReq(RICsubscriptionRequest_t *ricSubscriptionReq)
2245 uint8_t elementIdx = 0;
2246 RICsubscriptionDetails_t *subsDetails = NULLP;
2247 RICaction_ToBeSetup_ItemIEs_t *actionItem = NULLP;
2249 if(ricSubscriptionReq->protocolIEs.list.array)
2251 for(idx=0; idx < ricSubscriptionReq->protocolIEs.list.count; idx++)
2253 switch(ricSubscriptionReq->protocolIEs.list.array[idx]->id)
2255 case ProtocolIE_IDE2_id_RICsubscriptionDetails:
2257 subsDetails = &(ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails);
2258 free(subsDetails->ricEventTriggerDefinition.buf);
2260 if(subsDetails->ricAction_ToBeSetup_List.list.array)
2262 for(elementIdx = 0; elementIdx < subsDetails->ricAction_ToBeSetup_List.list.count; elementIdx++)
2264 if(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx])
2266 actionItem = (RICaction_ToBeSetup_ItemIEs_t *)subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx];
2267 if(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition)
2269 free(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->buf);
2270 free(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition);
2272 free(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx]);
2275 free(subsDetails->ricAction_ToBeSetup_List.list.array);
2280 free(ricSubscriptionReq->protocolIEs.list.array[idx]);
2282 free(ricSubscriptionReq->protocolIEs.list.array);
2286 /*******************************************************************
2288 * @brief Free Event Trigger Definition
2292 * Function : freeAperDecodingOfEventTriggerDef
2294 * Functionality: Free Event Trigger Definition
2296 * @params[in] E2SM-KPM Event Trigger Definition
2299 * ****************************************************************/
2300 void freeAperDecodingOfEventTriggerDef(E2SM_KPM_EventTriggerDefinition_t *eventTiggerDef)
2304 switch(eventTiggerDef->eventDefinition_formats.present)
2306 case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING:
2309 case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_eventDefinition_Format1:
2310 free(eventTiggerDef->eventDefinition_formats.choice.eventDefinition_Format1);
2316 /*******************************************************************
2318 * @brief Extract E2SM-KPM Event trigger definition
2322 * Function : extractEventTriggerDef
2324 * Functionality : This function :
2325 * - Decodes E2SM-KPM Event Trigger Definition
2326 * - Validates that even trigger style is supported by E2 node
2327 * - Stores event trigger details in local DB
2329 * @params[in] RAN Function Database structure
2330 * RIC Subscription Info to be added to RAN function
2331 * RIC Event Trigger Definition buffer received from RIC
2332 * @return ROK - success
2335 ******************************************************************/
2336 uint8_t extractEventTriggerDef(RanFunction *ranFuncDb, RicSubscription *ricSubscriptionInfo, \
2337 RICeventTriggerDefinition_t *ricEventTriggerDef, E2FailureCause *failureCause)
2339 uint8_t ret = RFAILED;
2340 uint8_t eventIdx = 0;
2341 asn_dec_rval_t rval ={0};
2342 E2SM_KPM_EventTriggerDefinition_t eventTiggerDef, *eventTiggerDefPtr = NULLP;
2344 /* Decoding E2SM-KPM Even Trigger Definition */
2345 eventTiggerDefPtr = &eventTiggerDef;
2346 memset(eventTiggerDefPtr, 0, sizeof(E2SM_KPM_EventTriggerDefinition_t));
2348 rval = aper_decode(0, &asn_DEF_E2SM_KPM_EventTriggerDefinition, (void **)&eventTiggerDefPtr, ricEventTriggerDef->buf,\
2349 ricEventTriggerDef->size, 0, 0);
2350 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
2352 DU_LOG("\nERROR --> E2AP : ASN decode failed for E2SM-KPM Event Trigger Definition");
2353 failureCause->causeType = E2_PROTOCOL;
2354 failureCause->cause = E2_ABSTRACT_SYNTAX_ERROR_FALSELY_CONSTRUCTED_MESSAGE;
2358 xer_fprint(stdout, &asn_DEF_E2SM_KPM_EventTriggerDefinition, eventTiggerDefPtr);
2360 /* Validating the received event trigger definition format */
2361 for(eventIdx = 0; eventIdx < ranFuncDb->numOfEventTriggerStyleSupported; eventIdx++)
2363 if((eventTiggerDefPtr->eventDefinition_formats.present != \
2364 E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING) && \
2365 (eventTiggerDefPtr->eventDefinition_formats.present == ranFuncDb->eventTriggerStyleList[eventIdx].formatType))
2367 ricSubscriptionInfo->eventTriggerDefinition.formatType = ranFuncDb->eventTriggerStyleList[eventIdx].formatType;
2368 ricSubscriptionInfo->eventTriggerDefinition.choice.format1.reportingPeriod = \
2369 eventTiggerDefPtr->eventDefinition_formats.choice.eventDefinition_Format1->reportingPeriod;
2378 failureCause->causeType = E2_RIC_REQUEST;
2379 failureCause->cause = E2_EVENT_TRIGGER_NOT_SUPPORTED;
2381 /* Free E2SM_KPM_EventTriggerDefinition_t */
2382 freeAperDecodingOfEventTriggerDef(eventTiggerDefPtr);
2386 /*******************************************************************
2388 * @brief Free RIC Action Definition
2392 * Function : freeAperDecodingOfRicActionDefinition
2394 * Functionality: Free RIC Action Definition
2396 * @params[in] E2SM-KPM Action definition
2399 * ****************************************************************/
2400 void freeAperDecodingOfRicActionDefinition(E2SM_KPM_ActionDefinition_t *actionDef)
2402 uint8_t elementIdx = 0;
2403 E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
2404 MeasurementInfoItem_t *measItem = NULLP;
2406 switch(actionDef->actionDefinition_formats.present)
2408 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1:
2410 if(actionDef->actionDefinition_formats.choice.actionDefinition_Format1)
2412 actionFormat1 = actionDef->actionDefinition_formats.choice.actionDefinition_Format1;
2413 if(actionFormat1->measInfoList.list.array)
2415 for(elementIdx = 0; elementIdx < actionFormat1->measInfoList.list.count; elementIdx++)
2417 if(actionFormat1->measInfoList.list.array[elementIdx])
2419 measItem = actionFormat1->measInfoList.list.array[elementIdx];
2420 switch(measItem->measType.present)
2422 case MeasurementType_PR_NOTHING:
2425 case MeasurementType_PR_measName:
2427 free(measItem->measType.choice.measName.buf);
2431 case MeasurementType_PR_measID:
2437 free(actionFormat1->measInfoList.list.array);
2439 free(actionFormat1);
2443 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format2:
2444 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format3:
2445 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format4:
2446 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format5:
2452 /*******************************************************************
2454 * @brief Extract Measurement Info list from action definition
2458 * Function : extractMeasInfoList
2460 * Functionality : This function :
2461 * - Traverses Measurement-to-be-subscribed list
2462 * - Validates that each measurement in Measurement-to-be-subscribed
2463 * list is supported in RAN-Function->Measurement-supported list.
2464 * - If all measurements in an action is supported by RAN function,
2465 * it is added to measurement-subscribed list in local DB
2467 * @params[in] Measurement Info supported list by RAN function
2468 * Measurement Info to be subscribed as requested by RIC
2469 * Measurement Info finally subscribed
2470 * Memory failure indicator
2471 * @return ROK - success
2474 ******************************************************************/
2475 uint8_t extractMeasInfoList(CmLListCp *measInfoSupportedList, MeasurementInfoList_t *measInfoToBeSubscribedList, \
2476 CmLListCp *measInfoSubscribedList, bool *memFailure)
2478 uint8_t elementIdx = 0;
2479 MeasurementInfoForAction *measInfoSupportedDb = NULLP;
2480 MeasurementInfo *measInfoSubscribedDb = NULLP, *measInfoToDel = NULLP;
2481 CmLList *supportedMeasNode = NULLP, *measToAddNode = NULLP, *measToDelNode = NULLP;;
2482 MeasurementInfoItem_t *measItem = NULLP;
2484 /* Validate Measurement list is supported by E2 node.
2486 * Traverse and compare the Measurement-Supported List in E2
2487 * node with Measurement-to-be-subscribed list received from RIC.
2488 * If a match is found, add it to measurement-subscription list.
2490 for(elementIdx = 0; elementIdx < measInfoToBeSubscribedList->list.count; elementIdx++)
2492 measInfoSubscribedDb = NULLP;
2493 measToAddNode = NULLP;
2494 measItem = measInfoToBeSubscribedList->list.array[elementIdx];
2496 CM_LLIST_FIRST_NODE(measInfoSupportedList, supportedMeasNode);
2497 while(supportedMeasNode)
2499 measInfoSupportedDb = (MeasurementInfoForAction*)supportedMeasNode->node;
2500 switch(measItem->measType.present)
2502 case MeasurementType_PR_measName:
2504 if(!strcmp(measInfoSupportedDb->measurementTypeName, (char *)measItem->measType.choice.measName.buf))
2506 DU_ALLOC(measInfoSubscribedDb, sizeof(MeasurementInfo));
2511 case MeasurementType_PR_measID:
2513 if(measInfoSupportedDb->measurementTypeId == measItem->measType.choice.measID)
2515 DU_ALLOC(measInfoSubscribedDb, sizeof(MeasurementInfo));
2522 DU_LOG("\nERROR -> DUAPP: Invalid Measurement-type identifier in \
2523 E2SM-KPM Action Definition Format");
2526 } /* End of switch, for measurement type identifier */
2528 /* If measurement type is supported, add to measurement-subscription list */
2529 if(measInfoSubscribedDb)
2531 measInfoSubscribedDb->measurementTypeId = measInfoSupportedDb->measurementTypeId;
2532 memcpy(measInfoSubscribedDb->measurementTypeName, measInfoSupportedDb->measurementTypeName, \
2533 strlen(measInfoSupportedDb->measurementTypeName));
2535 DU_ALLOC(measToAddNode, sizeof(CmLList));
2538 measToAddNode->node = (PTR) measInfoSubscribedDb;
2539 cmLListAdd2Tail(measInfoSubscribedList, measToAddNode);
2541 /* Break out of while loop if measurement info is found in measurement-supported list */
2546 DU_FREE(measInfoSubscribedDb, sizeof(MeasurementInfo));
2547 measInfoSubscribedDb = NULLP;
2553 supportedMeasNode = supportedMeasNode->next;
2555 } /* End of while for traversing measurement-supported list in a report style */
2557 /* If a measurement-to-be-subscribed is not found in measurement-supported list in this report style
2559 * Delete all entries from measurement-subscription list and
2560 * Break out of for loop to search in next report style */
2561 if(!measInfoSubscribedDb)
2563 while(measInfoSubscribedList->count)
2565 measToDelNode = cmLListDelFrm(measInfoSubscribedList, measInfoSubscribedList->first);
2566 measInfoToDel = (MeasurementInfo*)measToDelNode->node;
2567 DU_FREE(measInfoToDel, sizeof(MeasurementInfo));
2568 DU_FREE(measToDelNode, sizeof(CmLList));
2573 } /* End of for loop , traversing measurement-to-be-subscribed list */
2575 /* If all measurement-to-be-subscribed was found in measurement-supported list and
2576 * was added to measurement-subscription list successfully, return from here */
2577 if(measInfoToBeSubscribedList->list.count == measInfoSubscribedList->count)
2583 /*******************************************************************
2585 * @brief Extract E2SM-KPM Action definition
2589 * Function : extractRicActionDef
2591 * Functionality : This function :
2592 * - Decodes E2SM-KPM Action Definition
2593 * - Validates that action is supported by E2 node
2594 * - Stores action details in local DB
2596 * @params[in] RAN Function Database structure
2597 * RIC subscription's Action definition to be added to
2599 * RIC Action Definition buffer received from RIC
2600 * @return ROK - success
2603 ******************************************************************/
2604 uint8_t extractRicActionDef(RanFunction *ranFuncDb, ActionDefinition *actionDefDb, RICactionDefinition_t *ricActionDef,\
2605 E2FailureCause *failureCause)
2607 bool memFailure = false;
2608 uint8_t styleIdx = 0;
2609 asn_dec_rval_t rval ={0};
2611 E2SM_KPM_ActionDefinition_t actionDef, *actionDefPtr = NULLP;
2612 E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
2613 CmLListCp *measInfoSupportedList = NULLP;
2614 CmLListCp *measInfoSubscribedList = NULLP;
2616 /* Decoding E2SM-KPM Action Definition */
2617 actionDefPtr = &actionDef;
2618 memset(actionDefPtr, 0, sizeof(E2SM_KPM_EventTriggerDefinition_t));
2620 rval = aper_decode(0, &asn_DEF_E2SM_KPM_ActionDefinition, (void **)&actionDefPtr, ricActionDef->buf,\
2621 ricActionDef->size, 0, 0);
2622 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
2624 DU_LOG("\nERROR --> E2AP : ASN decode failed for E2SM-KPM Action Definition");
2625 failureCause->causeType = E2_PROTOCOL;
2626 failureCause->cause = E2_ABSTRACT_SYNTAX_ERROR_FALSELY_CONSTRUCTED_MESSAGE;
2630 xer_fprint(stdout, &asn_DEF_E2SM_KPM_ActionDefinition, actionDefPtr);
2633 /* Validate if Report style to subscribe is supported by E2 Node */
2634 for(styleIdx= 0; styleIdx < ranFuncDb->numOfReportStyleSupported; styleIdx++)
2636 /* Validate Report style type and report style format type is supported by E2 Node */
2637 if((ranFuncDb->reportStyleList[styleIdx].reportStyle.styleType == actionDefPtr->ric_Style_Type) &&
2638 (ranFuncDb->reportStyleList[styleIdx].reportStyle.formatType == actionDefPtr->actionDefinition_formats.present))
2640 /* Fetch Report stype type and format type */
2641 actionDefDb->styleType = actionDefPtr->ric_Style_Type;
2642 actionDefDb->formatType = actionDefPtr->actionDefinition_formats.present;
2644 switch(actionDefPtr->actionDefinition_formats.present)
2646 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1:
2648 actionFormat1 = actionDefPtr->actionDefinition_formats.choice.actionDefinition_Format1;
2650 /* Fetch granularity period */
2651 actionDefDb->choice.format1.granularityPeriod = actionFormat1->granulPeriod;
2653 /* Validate and add the Measurement to subscription list */
2654 measInfoSupportedList = &ranFuncDb->reportStyleList[styleIdx].measurementInfoList;
2655 measInfoSubscribedList = &actionDefDb->choice.format1.measurementInfoList;
2656 if(extractMeasInfoList(measInfoSupportedList, &actionFormat1->measInfoList, \
2657 measInfoSubscribedList, &memFailure) == ROK)
2661 /* Free E2SM_KPM_ActionDefinition_t */
2662 freeAperDecodingOfRicActionDefinition(actionDefPtr);
2667 break; /* End of E2SM-KPM Action definition format 1 case */
2672 DU_LOG("\nERROR -> DUAPP: Only E2SM-KPM Action Definition Format 1 is supported");
2675 } /* End of switch for E2SM-KPM Action definition formats */
2680 failureCause->causeType = E2_MISCELLANEOUS;
2681 failureCause->cause = E2_MISCELLANEOUS_CAUSE_UNSPECIFIED;
2684 } /* End of for loop, traversing Report-styles-supported list in E2 node */
2686 /* Memset action Db and Free E2SM_KPM_ActionDefinition_t */
2687 memset(actionDefDb, 0, sizeof(ActionDefinition));
2688 freeAperDecodingOfRicActionDefinition(actionDefPtr);
2690 if(failureCause->causeType == E2_NOTHING)
2692 failureCause->causeType = E2_RIC_REQUEST;
2693 failureCause->cause = E2_ACTION_NOT_SUPPORTED;
2698 /*******************************************************************
2700 * @brief Extract RIC Action to be setup
2704 * Function : extractRicActionToBeSetup
2706 * Functionality : This function :
2707 * - Validates that each action-to-be-setup is supported by E2 node
2708 * - Stores event trigger details in local DB
2710 * @params[in] RAN Function Database structure
2711 * RIC Subscription Info to be added to RAN function
2712 * RIC Action To Be Setup List received from RIC
2713 * @return ROK - success
2716 ******************************************************************/
2717 uint8_t extractRicActionToBeSetup(RanFunction *ranFuncDb, RicSubscription *ricSubscriptionInfo, \
2718 RICactions_ToBeSetup_List_t *actionList, E2FailureCause *failureCause, PendingSubsRspInfo *subsRsp)
2720 uint8_t actionIdx = 0;
2721 uint8_t ricActionId = 0;
2722 RICaction_ToBeSetup_ItemIEs_t *actionItem = NULLP;
2724 if(actionList->list.array)
2726 for(actionIdx = 0; actionIdx < actionList->list.count; actionIdx++)
2728 actionItem =(RICaction_ToBeSetup_ItemIEs_t *)actionList->list.array[actionIdx];
2729 switch(actionItem->id)
2731 case ProtocolIE_IDE2_id_RICaction_ToBeSetup_Item:
2733 /* If Action type is REPORT and
2734 * If RIC action definition's extraction and validation passes,
2736 * This action is added to action sequence list of subscription info */
2737 ricActionId = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID;
2739 if(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionType == RICactionType_report)
2741 ricSubscriptionInfo->actionSequence[ricActionId].actionId = ricActionId;
2742 ricSubscriptionInfo->actionSequence[ricActionId].type = REPORT;
2744 if(extractRicActionDef(ranFuncDb, &ricSubscriptionInfo->actionSequence[ricActionId].definition, \
2745 actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition, failureCause) == ROK)
2747 ricSubscriptionInfo->actionSequence[ricActionId].action = CONFIG_ADD;
2748 ricSubscriptionInfo->numOfActions++;
2753 /* In case of any failure, action is rejected
2754 * Added to rejected-action-list in subscription response */
2755 memset(&ricSubscriptionInfo->actionSequence[ricActionId], 0, sizeof(ActionInfo));
2756 ricSubscriptionInfo->actionSequence[ricActionId].actionId = -1;
2758 subsRsp->rejectedActionList[subsRsp->numOfRejectedActions].id = ricActionId;
2759 if(failureCause->causeType == E2_NOTHING)
2761 failureCause->causeType = E2_RIC_REQUEST;
2762 failureCause->cause = E2_ACTION_NOT_SUPPORTED;
2764 memcpy(&subsRsp->rejectedActionList[subsRsp->numOfRejectedActions].failureCause, \
2765 failureCause, sizeof(E2FailureCause));
2766 subsRsp->numOfRejectedActions++;
2770 DU_LOG("\nERROR --> E2AP : Invalid IE received in RicSetupLst:%ld",actionItem->id);
2776 /* If there is even 1 action that can be added, return ROK */
2777 if(ricSubscriptionInfo->numOfActions)
2780 if(failureCause->causeType == E2_NOTHING)
2782 failureCause->causeType = E2_RIC_REQUEST;
2783 failureCause->cause = E2_ACTION_NOT_SUPPORTED;
2788 /******************************************************************
2790 * @brief Processes RIC Subscription Req sent by RIC
2794 * Function : procRicSubscriptionRequest
2796 * Functionality: Processes RIC Subscription Request from RIC
2798 * @params[in] E2AP_PDU_t ASN decoded E2AP message
2799 * @return ROK - success
2802 * ****************************************************************/
2803 uint8_t procRicSubscriptionRequest(E2AP_PDU_t *e2apMsg)
2805 uint8_t idx = 0, actionIdx = 0;
2807 uint16_t ranFuncId = 0;
2808 RicRequestId ricReqId;
2809 CmLList *ricSubscriptionNode = NULLP;
2810 RanFunction *ranFuncDb = NULLP;
2811 RICsubscriptionRequest_t *ricSubsReq = NULLP;
2812 RICsubscriptionDetails_t *subsDetails = NULLP;
2813 RicSubscription *ricSubscriptionInfo = NULLP;
2814 E2FailureCause failureCause;
2816 DU_LOG("\nINFO --> E2AP : RIC Subscription request received");
2818 memset(&failureCause, 0, sizeof(E2FailureCause));
2819 memset(&ricReqId, 0, sizeof(RicRequestId));
2821 ricSubsReq = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
2822 for(idx=0; idx<ricSubsReq->protocolIEs.list.count; idx++)
2824 if(ricSubsReq->protocolIEs.list.array[idx])
2826 switch(ricSubsReq->protocolIEs.list.array[idx]->id)
2828 case ProtocolIE_IDE2_id_RICrequestID:
2830 ricReqId.requestorId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID;
2831 ricReqId.instanceId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID;
2836 case ProtocolIE_IDE2_id_RANfunctionID:
2838 ranFuncId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RANfunctionID;
2840 /* Validating RAN Function id */
2841 ranFuncDb = fetchRanFuncFromRanFuncId(ranFuncId);
2845 failureCause.causeType = E2_RIC_REQUEST;
2846 failureCause.cause = E2_RAN_FUNCTION_ID_INVALID;
2851 if(ranFuncDb->numPendingSubsRsp >= MAX_PENDING_SUBSCRIPTION_RSP)
2853 failureCause.causeType = E2_RIC_REQUEST;
2854 failureCause.cause = E2_FUNCTION_RESOURCE_LIMIT;
2859 DU_ALLOC(ricSubscriptionInfo, sizeof(RicSubscription));
2860 if(!ricSubscriptionInfo)
2862 DU_LOG("\nERROR --> E2AP : Memory allocation failed for ricSubscriptionInfo");
2863 failureCause.causeType = E2_MISCELLANEOUS;
2864 failureCause.cause = E2_MISCELLANEOUS_CAUSE_UNSPECIFIED;
2868 ricSubscriptionInfo->requestId.requestorId = ricReqId.requestorId;
2869 ricSubscriptionInfo->requestId.instanceId = ricReqId.instanceId;
2870 ricSubscriptionInfo->ranFuncId = ranFuncId;
2872 for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
2874 ricSubscriptionInfo->actionSequence[actionIdx].actionId = -1;
2877 memset(&ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp], 0, sizeof(PendingSubsRspInfo));
2878 memcpy(&ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp].requestId,
2879 &ricReqId, sizeof(RicRequestId));
2880 ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp].ranFuncId = ranFuncId;
2884 case ProtocolIE_IDE2_id_RICsubscriptionDetails:
2886 subsDetails = &ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails;
2888 /* Decode, Validate and record Event Trigger Definition */
2889 if(extractEventTriggerDef(ranFuncDb, ricSubscriptionInfo, &subsDetails->ricEventTriggerDefinition, \
2890 &failureCause) != ROK)
2896 /* Decode, Validate and record RIC actions */
2897 if(extractRicActionToBeSetup(ranFuncDb, ricSubscriptionInfo, &subsDetails->ricAction_ToBeSetup_List, \
2898 &failureCause, &ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp]) != ROK)
2907 DU_LOG("\nERROR --> E2AP : Invalid IE received in RIC SubsReq:%ld",
2908 ricSubsReq->protocolIEs.list.array[idx]->id);
2917 freeAperDecodingOfRicSubsReq(ricSubsReq);
2921 cmInitTimers(&(ricSubscriptionInfo->ricSubsReportTimer), 1);
2923 /* Add RAN subcription detail to RAN function */
2924 DU_ALLOC(ricSubscriptionNode, sizeof(CmLList));
2925 if(ricSubscriptionNode)
2927 ricSubscriptionNode->node = (PTR) ricSubscriptionInfo;
2928 cmLListAdd2Tail(&ranFuncDb->subscriptionList, ricSubscriptionNode);
2931 ranFuncDb->numPendingSubsRsp++;
2933 #ifdef KPI_CALCULATION
2934 /* Send statistics request to other DU entities */
2935 BuildAndSendStatsReq(ricSubscriptionInfo);
2940 DU_FREE(ricSubscriptionInfo, sizeof(RicSubscription));
2944 memset(&ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp], 0, sizeof(PendingSubsRspInfo));
2947 /* Send RIC Subcription Failure */
2948 BuildAndSendRicSubscriptionFailure(ricReqId, ranFuncId, failureCause);
2954 /******************************************************************
2956 * @brief Free RIC Subscription Failure
2960 * Function : FreeRicSubscriptionFailure
2962 * Functionality: Free RIC Subscription Failure
2964 * @params[in] E2AP PDU
2967 * ****************************************************************/
2968 void FreeRicSubscriptionFailure(E2AP_PDU_t *e2apMsg)
2970 uint8_t elemIdx = 0;
2971 RICsubscriptionFailure_t *ricSubscriptionFailure = NULLP;
2975 if(e2apMsg->choice.unsuccessfulOutcome)
2977 ricSubscriptionFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionFailure;
2978 if(ricSubscriptionFailure->protocolIEs.list.array)
2980 for(elemIdx = 0; elemIdx < ricSubscriptionFailure->protocolIEs.list.count; elemIdx++)
2982 DU_ALLOC(ricSubscriptionFailure->protocolIEs.list.array[elemIdx], sizeof(RICsubscriptionFailure_IEs_t));
2984 DU_ALLOC(ricSubscriptionFailure->protocolIEs.list.array, ricSubscriptionFailure->protocolIEs.list.size);
2986 DU_ALLOC(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
2988 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2992 /******************************************************************
2994 * @brief Fill and Send RIC Subscription Failure to RIC
2998 * Function : BuildAndSendRicSubscriptionFailure
3000 * Functionality: Fill and Send RIC Subscription Failure to RIC
3002 * @params[in] RIC Request ID
3005 * @return ROK - success
3008 * ****************************************************************/
3009 uint8_t BuildAndSendRicSubscriptionFailure(RicRequestId ricReqId, uint16_t ranFuncId, E2FailureCause failureCause)
3011 uint8_t ret = RFAILED;
3012 uint8_t elementCnt = 0, elemIdx = 0;
3013 E2AP_PDU_t *e2apMsg = NULLP;
3014 asn_enc_rval_t encRetVal; /* Encoder return value */
3015 RICsubscriptionFailure_t *ricSubscriptionFailure = NULLP;
3016 RICsubscriptionFailure_IEs_t *ricSubsFailIe = NULLP;
3020 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Failure\n");
3022 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
3023 if(e2apMsg == NULLP)
3025 DU_LOG("\nERROR --> E2AP : Memory allocation at [%s] : Line [%d]", __func__, __LINE__);
3029 e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome;
3030 DU_ALLOC(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
3031 if(e2apMsg->choice.unsuccessfulOutcome == NULLP)
3033 DU_LOG("\nERROR --> E2AP : Memory allocation at [%s] : Line [%d]", __func__, __LINE__);
3036 e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
3037 e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject;
3038 e2apMsg->choice.unsuccessfulOutcome->value.present = UnsuccessfulOutcomeE2__value_PR_RICsubscriptionFailure;
3040 ricSubscriptionFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionFailure;
3043 ricSubscriptionFailure->protocolIEs.list.count = elementCnt;
3044 ricSubscriptionFailure->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionFailure_IEs_t *);
3045 DU_ALLOC(ricSubscriptionFailure->protocolIEs.list.array, ricSubscriptionFailure->protocolIEs.list.size);
3046 if(!ricSubscriptionFailure->protocolIEs.list.array)
3048 DU_LOG("\nERROR --> E2AP : Memory allocation at [%s] : Line [%d]", __func__, __LINE__);
3052 for(elemIdx = 0; elemIdx < elementCnt; elemIdx++)
3054 DU_ALLOC(ricSubscriptionFailure->protocolIEs.list.array[elemIdx], sizeof(RICsubscriptionFailure_IEs_t));
3055 if(!ricSubscriptionFailure->protocolIEs.list.array[elemIdx])
3057 DU_LOG("\nERROR --> E2AP : Memory allocation at [%s] : Line [%d] for IE at index [%d]", \
3058 __func__, __LINE__, elemIdx);
3062 if(elemIdx < elementCnt)
3067 /* RIC Request ID */
3068 ricSubsFailIe = ricSubscriptionFailure->protocolIEs.list.array[elemIdx++];
3069 ricSubsFailIe->id = ProtocolIE_IDE2_id_RICrequestID;
3070 ricSubsFailIe->criticality = CriticalityE2_reject;
3071 ricSubsFailIe->value.present = RICsubscriptionFailure_IEs__value_PR_RICrequestID;
3072 ricSubsFailIe->value.choice.RICrequestID.ricRequestorID = ricReqId.requestorId;
3073 ricSubsFailIe->value.choice.RICrequestID.ricInstanceID = ricReqId.instanceId;
3075 /* RAN Function ID */
3076 ricSubsFailIe = ricSubscriptionFailure->protocolIEs.list.array[elemIdx++];
3077 ricSubsFailIe->id = ProtocolIE_IDE2_id_RANfunctionID;
3078 ricSubsFailIe->criticality = CriticalityE2_reject;
3079 ricSubsFailIe->value.present = RICsubscriptionFailure_IEs__value_PR_RANfunctionID;
3080 ricSubsFailIe->value.choice.RANfunctionID = ranFuncId;
3083 ricSubsFailIe = ricSubscriptionFailure->protocolIEs.list.array[elemIdx++];
3084 ricSubsFailIe->id = ProtocolIE_IDE2_id_CauseE2;
3085 ricSubsFailIe->criticality = CriticalityE2_reject;
3086 ricSubsFailIe->value.present = RICsubscriptionFailure_IEs__value_PR_CauseE2;
3087 fillE2Cause(&ricSubsFailIe->value.choice.CauseE2, failureCause);
3089 /* Prints the Msg formed */
3090 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3091 memset(encBuf, 0, ENC_BUF_MAX_LEN);
3093 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
3094 if(encRetVal.encoded == ENCODE_FAIL)
3096 DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Failure Message (at %s)\n",\
3097 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3102 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Subscription Failure Message \n");
3103 #ifdef DEBUG_ASN_PRINT
3104 for(int i=0; i< encBufSize; i++)
3106 printf("%x",encBuf[i]);
3111 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
3113 DU_LOG("\nINFO --> E2AP : Sending RIC Subscription Failure");
3119 FreeRicSubscriptionFailure(e2apMsg);
3123 /*******************************************************************
3125 * @brief Free the RicIndication Message
3129 * Function : FreeRicIndication
3131 * Functionality: Free the RicIndication Message
3136 ******************************************************************/
3137 void FreeRicIndication(E2AP_PDU_t *e2apMsg)
3140 RICindication_t *ricIndicationMsg= NULLP;
3142 if(e2apMsg != NULLP)
3144 if(e2apMsg->choice.initiatingMessage != NULLP)
3146 ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
3147 if(ricIndicationMsg!= NULLP)
3149 if(ricIndicationMsg->protocolIEs.list.array != NULLP)
3151 for(idx=0; idx<ricIndicationMsg->protocolIEs.list.count; idx++)
3153 if(ricIndicationMsg->protocolIEs.list.array[idx] != NULLP)
3155 switch(ricIndicationMsg->protocolIEs.list.array[idx]->id)
3157 case ProtocolIE_IDE2_id_RICrequestID:
3158 case ProtocolIE_IDE2_id_RANfunctionID:
3159 case ProtocolIE_IDE2_id_RICactionID:
3160 case ProtocolIE_IDE2_id_RICindicationType:
3163 case ProtocolIE_IDE2_id_RICindicationHeader:
3165 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf,\
3166 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
3169 case ProtocolIE_IDE2_id_RICindicationMessage:
3171 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf,\
3172 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
3178 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx],sizeof(RICindication_IEs_t));
3181 DU_FREE(ricIndicationMsg->protocolIEs.list.array,ricIndicationMsg->protocolIEs.list.size);
3184 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
3186 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
3190 /*******************************************************************
3192 * @brief Free measurement record
3196 * Function : freeMeasRecord
3198 * Functionality: Free all measurement recorded for a measurement
3199 * within an action in a RIC subscription
3201 * @param Measurement data to be freed
3204 ******************************************************************/
3205 void freeMeasData(MeasurementData_t *measData)
3207 uint8_t measIdx = 0, measRecIdx = 0;
3208 MeasurementRecord_t *measRecord = NULLP;
3210 if(measData->list.array)
3212 for(measIdx = 0; measIdx < measData->list.count; measIdx++)
3214 if(measData->list.array[measIdx])
3216 measRecord = &measData->list.array[measIdx]->measRecord;
3217 if(measRecord->list.array)
3219 for(measRecIdx = 0; measRecIdx < measRecord->list.count; measRecIdx++)
3221 DU_FREE(measRecord->list.array[measRecIdx], sizeof(MeasurementRecordItem_t));
3223 DU_FREE(measRecord->list.array, measRecord->list.size);
3225 DU_FREE(measData->list.array[measIdx], sizeof(MeasurementDataItem_t));
3228 DU_FREE(measData->list.array, measData->list.size);
3232 /*******************************************************************
3234 * @brief Fill measurement info list
3238 * Function : freeMeasInfoList
3240 * Functionality: Fills all measurement info within an action
3241 * in a RIC subscription
3243 * @param Measurement Info list to be freed
3246 ******************************************************************/
3247 void freeMeasInfoList(MeasurementInfoList_t *measInfoList)
3249 uint8_t measInfoIdx = 0;
3251 if(measInfoList->list.array)
3253 for(measInfoIdx = 0; measInfoIdx < measInfoList->list.count; measInfoIdx++)
3255 if(measInfoList->list.array[measInfoIdx])
3257 DU_FREE(measInfoList->list.array[measInfoIdx]->measType.choice.measName.buf, \
3258 measInfoList->list.array[measInfoIdx]->measType.choice.measName.size);
3260 DU_FREE(measInfoList->list.array[measInfoIdx], measInfoList->list.size);
3263 DU_FREE(measInfoList->list.array, measInfoList->list.size);
3267 /*******************************************************************
3269 * @brief Free E2SM-KPM Indication Message
3273 * Function : FreeE2smKpmIndicationMessage
3275 * Functionality: Free E2SM-KPM Indication Message
3277 * @param E2SM-KPM Indication message to be freed
3280 ******************************************************************/
3281 void FreeE2smKpmIndicationMessage(E2SM_KPM_IndicationMessage_t *e2smKpmIndMsg)
3283 E2SM_KPM_IndicationMessage_Format1_t *format1Msg = NULLP;
3285 switch(e2smKpmIndMsg->indicationMessage_formats.present)
3287 case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format1:
3289 if(e2smKpmIndMsg->indicationMessage_formats.choice.indicationMessage_Format1)
3291 format1Msg = e2smKpmIndMsg->indicationMessage_formats.choice.indicationMessage_Format1;
3293 /* Measurement Data */
3294 freeMeasData(&format1Msg->measData);
3296 /* Measurement Info List */
3297 if(format1Msg->measInfoList)
3299 freeMeasInfoList(format1Msg->measInfoList);
3300 DU_FREE(format1Msg->measInfoList, sizeof(MeasurementInfoList_t));
3303 /* Granularity Period */
3304 DU_FREE(format1Msg->granulPeriod, sizeof(GranularityPeriod_t));
3306 DU_FREE(format1Msg, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
3311 case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_NOTHING:
3312 case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format2:
3318 /*******************************************************************
3320 * @brief Fill measurement record
3324 * Function : fillMeasRecord
3326 * Functionality: Fills all measurement value for a measurement
3327 * within an action in a RIC subscription
3329 * @param Measurement record to be filled
3330 * Measurement database with measurement records
3331 * @return ROK - success
3334 ******************************************************************/
3335 uint8_t fillMeasRecord(MeasurementRecord_t *measRecord, MeasurementInfo *measInfoDb)
3337 uint8_t measRecIdx = 0;
3338 CmLList *measValNode = NULLP;
3341 measRecord->list.count = measInfoDb->measuredValue.count;
3342 measRecord->list.size = measRecord->list.count * sizeof(MeasurementRecordItem_t *);
3344 DU_ALLOC(measRecord->list.array, measRecord->list.size);
3345 if(!measRecord->list.array)
3347 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3351 for(measRecIdx = 0; measRecIdx < measRecord->list.count; measRecIdx++)
3353 DU_ALLOC(measRecord->list.array[measRecIdx], sizeof(MeasurementRecordItem_t));
3354 if(!measRecord->list.array[measRecIdx])
3356 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3362 CM_LLIST_FIRST_NODE(&measInfoDb->measuredValue, measValNode);
3365 measVal = *(double *)measValNode->node;
3366 if(measVal == (int)measVal)
3368 measRecord->list.array[measRecIdx]->present = MeasurementRecordItem_PR_integer;
3369 measRecord->list.array[measRecIdx]->choice.integer = (int)measVal;
3373 measRecord->list.array[measRecIdx]->present = MeasurementRecordItem_PR_real;
3374 measRecord->list.array[measRecIdx]->choice.real = measVal;
3378 /* Once the measurement record is added to the message, delete it from DB */
3379 cmLListDelFrm(&measInfoDb->measuredValue, measValNode);
3380 DU_FREE(measValNode->node, sizeof(double));
3381 DU_FREE(measValNode, sizeof(CmLList));
3383 CM_LLIST_FIRST_NODE(&measInfoDb->measuredValue, measValNode);
3390 /*******************************************************************
3392 * @brief Fills measuerement data
3396 * Function : fillMeasData
3398 * Functionality: Fill all measurement recorded for all measurements
3399 * in an action in a RIC subscription
3401 * @param Measurement data to be filled
3402 * Measurement info list from an action DB
3403 * @return ROK - success
3406 ******************************************************************/
3407 uint8_t fillMeasData(MeasurementData_t *measData, CmLListCp *measInfoListDb)
3409 uint8_t measIdx = 0;
3410 CmLList *measInfoNode = NULLP;
3411 MeasurementInfo *measInfoDb = NULLP;
3412 MeasurementRecord_t *measRecord = NULLP;
3414 measData->list.count = measInfoListDb->count;
3415 measData->list.size = measData->list.count * sizeof(MeasurementDataItem_t *);
3417 DU_ALLOC(measData->list.array, measData->list.size);
3418 if(!measData->list.array)
3420 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3425 CM_LLIST_FIRST_NODE(measInfoListDb, measInfoNode);
3428 measInfoDb = (MeasurementInfo *)measInfoNode->node;
3431 DU_ALLOC(measData->list.array[measIdx], sizeof(MeasurementDataItem_t));
3432 if(!measData->list.array[measIdx])
3434 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3438 measRecord = &measData->list.array[measIdx]->measRecord;
3439 if(fillMeasRecord(measRecord, measInfoDb) != ROK)
3441 DU_LOG("\nERROR --> E2AP : Failed to fill measurement record");
3446 measInfoNode = measInfoNode->next;
3452 /*******************************************************************
3454 * @brief Fill all measurement info
3458 * Function : fillMeasInfoList
3460 * Functionality: Fills all measurement info belonging to an action
3461 * in a RIC subscription
3463 * @param Measurement Info list to be filled
3464 * Measurement Info list from E2AP DB
3465 * @return ROK - success
3468 ******************************************************************/
3469 uint8_t fillMeasInfoList(MeasurementInfoList_t *measInfoList, CmLListCp *measInfoListDb)
3471 uint8_t measInfoIdx = 0;
3472 CmLList *measInfoNode = NULLP;
3473 MeasurementInfo *measInfoDb = NULLP;
3474 MeasurementInfoItem_t *measInfoItem = NULLP;
3476 measInfoList->list.count = measInfoListDb->count;
3477 measInfoList->list.size = measInfoList->list.count * sizeof(MeasurementInfoItem_t *);
3479 DU_ALLOC(measInfoList->list.array, measInfoList->list.size);
3480 if(!measInfoList->list.array)
3482 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3487 CM_LLIST_FIRST_NODE(measInfoListDb, measInfoNode);
3490 DU_ALLOC(measInfoList->list.array[measInfoIdx], sizeof(MeasurementInfoItem_t));
3491 if(!measInfoList->list.array[measInfoIdx])
3493 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3497 measInfoItem = measInfoList->list.array[measInfoIdx];
3498 measInfoDb = (MeasurementInfo *)measInfoNode->node;
3501 /* Measurement Type */
3502 measInfoItem->measType.present = MeasurementType_PR_measName;
3503 measInfoItem->measType.choice.measName.size = strlen(measInfoDb->measurementTypeName);
3505 DU_ALLOC(measInfoItem->measType.choice.measName.buf, measInfoItem->measType.choice.measName.size);
3506 if(!measInfoItem->measType.choice.measName.buf)
3508 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3512 memcpy(measInfoItem->measType.choice.measName.buf, measInfoDb->measurementTypeName,\
3513 measInfoItem->measType.choice.measName.size);
3517 measInfoNode = measInfoNode->next;
3524 /*******************************************************************
3526 * @brief Fill E2SM-KPM Indication Message Format 1
3530 * Function : fillE2smKpmIndMsgFormat1
3532 * Functionality: Fill E2SM-KPM Indication Message Format 1
3534 * @param Format 1 Message to be filled
3535 * Action Definition format 1 from E2AP DB
3536 * @return ROK - success
3539 ******************************************************************/
3540 uint8_t fillE2smKpmIndMsgFormat1(E2SM_KPM_IndicationMessage_Format1_t *format1Msg, ActionDefFormat1 *format1)
3542 /* Measurement Data */
3543 if(fillMeasData(&format1Msg->measData, &format1->measurementInfoList) != ROK)
3545 DU_LOG("\nERROR --> E2AP : Failed to fill measurement data");
3549 /* Measurement Information */
3550 DU_ALLOC(format1Msg->measInfoList, sizeof(MeasurementInfoList_t));
3551 if(!format1Msg->measInfoList)
3553 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3557 if(fillMeasInfoList(format1Msg->measInfoList, &format1->measurementInfoList) != ROK)
3559 DU_LOG("\nERROR --> E2AP : Failed to fill measurement information list");
3563 /* Granularity Period */
3564 DU_ALLOC(format1Msg->granulPeriod, sizeof(GranularityPeriod_t));
3565 if(!format1Msg->granulPeriod)
3567 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3570 *(format1Msg->granulPeriod) = format1->granularityPeriod;
3575 /*******************************************************************
3577 * @brief Fill RIC Indication Message buffer
3581 * Function : fillRicIndMsgBuf
3583 * Functionality: Fill E2SM-KPM Indication Message
3584 * Encode this message and copy to RIC Indication Message buffer
3586 * @param RIC Indication Message buffer to be filled
3587 * Source action info from E2AP DB
3588 * @return ROK - success
3591 ******************************************************************/
3592 uint8_t fillRicIndMsgBuf(RICindicationMessage_t *ricIndMsgBuf, ActionInfo *actionInfo)
3594 uint8_t ret = RFAILED;
3595 bool failedInFormat = false;
3596 E2SM_KPM_IndicationMessage_t e2smKpmIndMsg;
3597 asn_enc_rval_t encRetVal; /* Encoder return value */
3599 memset(&e2smKpmIndMsg, 0, sizeof(E2SM_KPM_IndicationMessage_t));
3603 /* E2SM-KPM Indication message format type */
3604 e2smKpmIndMsg.indicationMessage_formats.present = actionInfo->definition.formatType;
3605 switch(e2smKpmIndMsg.indicationMessage_formats.present)
3607 case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format1:
3609 /* E2SM-KPM Indication message format 1 */
3610 DU_ALLOC(e2smKpmIndMsg.indicationMessage_formats.choice.indicationMessage_Format1, \
3611 sizeof(E2SM_KPM_IndicationMessage_Format1_t));
3612 if(!e2smKpmIndMsg.indicationMessage_formats.choice.indicationMessage_Format1)
3614 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3615 failedInFormat = true;
3619 if(fillE2smKpmIndMsgFormat1(e2smKpmIndMsg.indicationMessage_formats.choice.indicationMessage_Format1, \
3620 &actionInfo->definition.choice.format1) != ROK)
3622 DU_LOG("\nERROR --> E2AP : Failed to fill E2SM-KPM Indication message format 1");
3623 failedInFormat = true;
3629 case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_NOTHING:
3630 case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format2:
3633 DU_LOG("\nERROR --> E2AP : fillRicIndMsgBuf: Only Format 1 supported");
3634 failedInFormat = true;
3642 /* Encode E2SM-KPM Indication Message */
3643 xer_fprint(stdout, &asn_DEF_E2SM_KPM_IndicationMessage, &e2smKpmIndMsg);
3644 memset(encBuf, 0, ENC_BUF_MAX_LEN);
3646 encRetVal = aper_encode(&asn_DEF_E2SM_KPM_IndicationMessage, 0, &e2smKpmIndMsg, PrepFinalEncBuf, encBuf);
3647 if(encRetVal.encoded == ENCODE_FAIL)
3649 DU_LOG("\nERROR --> E2AP : Could not encode E2SM-KPM Indication Message (at %s)\n",\
3650 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3655 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SM-KPM Indication Message \n");
3656 #ifdef DEBUG_ASN_PRINT
3657 for(int i=0; i< encBufSize; i++)
3659 printf("%x",encBuf[i]);
3664 /* Copy encoded string to RIC Indication Message buffer */
3665 ricIndMsgBuf->size = encBufSize;
3666 DU_ALLOC(ricIndMsgBuf->buf, ricIndMsgBuf->size);
3667 if(!ricIndMsgBuf->buf)
3669 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3672 memset(ricIndMsgBuf->buf, 0, ricIndMsgBuf->size);
3673 memcpy(ricIndMsgBuf->buf, encBuf, encBufSize);
3679 /* Free E2SM-KPM Indication Message */
3680 FreeE2smKpmIndicationMessage(&e2smKpmIndMsg);
3685 /*******************************************************************
3687 * @brief Free E2SM-KPM Indication Header
3691 * Function : FreeE2smKpmIndicationHeader
3693 * Functionality: Free E2SM-KPM Indication Header
3695 * @param E2SM-KPM Indication Header to be free
3698 ******************************************************************/
3699 void FreeE2smKpmIndicationHeader(E2SM_KPM_IndicationHeader_t *e2smKpmIndHdr)
3701 E2SM_KPM_IndicationHeader_Format1_t *format1 = NULLP;
3705 switch(e2smKpmIndHdr->indicationHeader_formats.present)
3707 case E2SM_KPM_IndicationHeader__indicationHeader_formats_PR_indicationHeader_Format1:
3709 if(e2smKpmIndHdr->indicationHeader_formats.choice.indicationHeader_Format1)
3711 format1 = e2smKpmIndHdr->indicationHeader_formats.choice.indicationHeader_Format1;
3713 DU_FREE(format1->colletStartTime.buf, format1->colletStartTime.size);
3714 DU_FREE(format1, sizeof(E2SM_KPM_IndicationHeader_Format1_t));
3718 case E2SM_KPM_IndicationHeader__indicationHeader_formats_PR_NOTHING:
3725 /*******************************************************************
3727 * @brief Fill RIC Indication Header buffer
3731 * Function : fillRicIndHeader
3733 * Functionality: Fill E2SM-KPM Indication Header
3734 * Encode this message and copy to RIC Indication Header buffer
3736 * @param RIC Indication Header buffer to be filled
3737 * Source RIC subscription info from E2AP DB
3738 * @return ROK - success
3741 ******************************************************************/
3742 uint8_t fillRicIndHeader(RICindicationHeader_t *ricIndHdr, RicSubscription *ricSubsInfo)
3744 uint8_t ret = RFAILED;
3745 uint8_t secBufIdx = 0, milliSecBufIdx = 0;
3747 bool formatFailure = false;
3748 RanFunction *ranFunc = NULLP;
3749 ReportStartTime *startTime = NULLP;
3750 E2SM_KPM_IndicationHeader_t e2smKpmIndHdr;
3751 E2SM_KPM_IndicationHeader_Format1_t *format1 = NULLP;
3752 asn_enc_rval_t encRetVal; /* Encoder return value */
3756 ranFunc = fetchRanFuncFromRanFuncId(ricSubsInfo->ranFuncId);
3757 if(ranFunc == NULLP)
3759 DU_LOG("\nERROR --> E2AP : RAN Function ID [%d] not found", ricSubsInfo->ranFuncId);
3763 memset(&e2smKpmIndHdr, 0, sizeof(E2SM_KPM_IndicationHeader_t));
3765 e2smKpmIndHdr.indicationHeader_formats.present = ranFunc->ricIndicationHeaderFormat;
3766 switch(e2smKpmIndHdr.indicationHeader_formats.present)
3768 case E2SM_KPM_IndicationHeader__indicationHeader_formats_PR_indicationHeader_Format1:
3770 DU_ALLOC(e2smKpmIndHdr.indicationHeader_formats.choice.indicationHeader_Format1, \
3771 sizeof(E2SM_KPM_IndicationHeader_Format1_t));
3772 if(!e2smKpmIndHdr.indicationHeader_formats.choice.indicationHeader_Format1)
3774 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3775 formatFailure = true;
3778 format1 = e2smKpmIndHdr.indicationHeader_formats.choice.indicationHeader_Format1;
3780 /* Fetch reporting period start time from DB */
3781 switch(ricSubsInfo->eventTriggerDefinition.formatType)
3785 startTime = &ricSubsInfo->eventTriggerDefinition.choice.format1.startTime;
3789 format1->colletStartTime.size = 8 * sizeof(uint8_t);
3790 DU_ALLOC(format1->colletStartTime.buf, format1->colletStartTime.size);
3791 if(!format1->colletStartTime.buf)
3793 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3794 formatFailure = true;
3798 /* As per O-RAN.WG3.E2SM-KPM-R003-v03.00, section 8.3.12 and
3799 * RFC 5905, section 6 :
3800 * Time stamp has a 64-bit format where first 32-bit is seconds
3801 * and next 32-bit is fraction in picosecond-level.
3802 * This fraction has been rounded in microseconds.
3805 * Storing 32-bit seconds at MSB 0-3 and
3806 * 32-bit milliseconds at next 4 bytes i.e. bytes 4-7
3810 for(byteIdx = 3; byteIdx >= 0; byteIdx--)
3812 format1->colletStartTime.buf[secBufIdx++] = startTime->timeInSec >> (8*byteIdx);
3813 format1->colletStartTime.buf[milliSecBufIdx++] = startTime->timeInMilliSec >> (8*byteIdx);
3818 case E2SM_KPM_IndicationHeader__indicationHeader_formats_PR_NOTHING:
3821 DU_LOG("\nERROR --> E2AP : Only E2SM-KPM Indication Header Format 1 supported");
3822 formatFailure = true;
3830 /* Encode E2SM-KPM Indication Header */
3831 xer_fprint(stdout, &asn_DEF_E2SM_KPM_IndicationHeader, &e2smKpmIndHdr);
3832 memset(encBuf, 0, ENC_BUF_MAX_LEN);
3834 encRetVal = aper_encode(&asn_DEF_E2SM_KPM_IndicationHeader, 0, &e2smKpmIndHdr, PrepFinalEncBuf, encBuf);
3835 if(encRetVal.encoded == ENCODE_FAIL)
3837 DU_LOG("\nERROR --> E2AP : Could not encode E2SM-KPM Indication Header (at %s)\n",\
3838 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3843 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SM-KPM Indication Header \n");
3844 #ifdef DEBUG_ASN_PRINT
3845 for(int i=0; i< encBufSize; i++)
3847 printf("%x",encBuf[i]);
3852 /* Copy encoded string to RIC Indication Header buffer */
3853 ricIndHdr->size = encBufSize;
3854 DU_ALLOC(ricIndHdr->buf, ricIndHdr->size);
3857 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3860 memset(ricIndHdr->buf, 0, ricIndHdr->size);
3861 memcpy(ricIndHdr->buf, encBuf, encBufSize);
3866 /* Free E2SM-KPM Indication Header */
3867 FreeE2smKpmIndicationHeader(&e2smKpmIndHdr);
3872 /*******************************************************************
3874 * brief Fill the RIC Indication Message
3878 * Function : fillRicIndication
3880 * Functionality: Fills the RIC Indication Message
3882 * @param RIC Indication Message to be filled
3883 * RIC Subscription DB
3885 * @return ROK - success
3888 ******************************************************************/
3889 uint8_t fillRicIndication(RICindication_t *ricIndicationMsg, RicSubscription *ricSubscriptionInfo, ActionInfo *actionInfo)
3891 uint8_t elementCnt = 0, idx = 0;
3896 ricIndicationMsg->protocolIEs.list.count = elementCnt;
3897 ricIndicationMsg->protocolIEs.list.size = elementCnt * sizeof(RICindication_IEs_t *);
3899 /* Initialize the Ric Indication members */
3900 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array, ricIndicationMsg->protocolIEs.list.size);
3901 if(ricIndicationMsg->protocolIEs.list.array == NULLP)
3903 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3907 for(idx=0; idx<elementCnt; idx++)
3909 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx], sizeof(RICindication_IEs_t));
3910 if(ricIndicationMsg->protocolIEs.list.array[idx] == NULLP)
3912 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3917 /* RIC Request ID */
3919 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
3920 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
3921 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICrequestID;
3922 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID = \
3923 ricSubscriptionInfo->requestId.requestorId;
3924 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID = \
3925 ricSubscriptionInfo->requestId.instanceId;
3927 /* RAN Function ID */
3929 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
3930 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
3931 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RANfunctionID;
3932 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RANfunctionID = ricSubscriptionInfo->ranFuncId;
3936 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactionID;
3937 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
3938 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICactionID;
3939 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICactionID = actionInfo->actionId;
3941 /* RIC Indication Type */
3943 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationType;
3944 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
3945 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICindicationType;
3946 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationType = actionInfo->type;
3948 /* RIC Indication Header */
3950 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationHeader;
3951 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
3952 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICindicationHeader;
3953 if(fillRicIndHeader(&ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader, \
3954 ricSubscriptionInfo) != ROK)
3956 DU_LOG("\nERROR --> E2AP : Failed to fill RIC Indication header");
3960 /* RIC Indication Message */
3962 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationMessage;
3963 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
3964 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICindicationMessage;
3965 if(fillRicIndMsgBuf(&ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage, \
3968 DU_LOG("\nERROR --> E2AP : Failed to fill RIC Indication Message");
3975 /*******************************************************************
3977 * @brief Builds and Send the RicIndication Message
3981 * Function : BuildAndSendRicIndication
3983 * Functionality:Fills the RicIndication Message
3985 * @return ROK - success
3988 ******************************************************************/
3990 uint8_t BuildAndSendRicIndication(RicSubscription *ricSubscriptionInfo, ActionInfo *actionInfo)
3992 uint8_t ret = RFAILED;
3993 E2AP_PDU_t *e2apMsg = NULLP;
3994 RICindication_t *ricIndicationMsg = NULLP;
3995 asn_enc_rval_t encRetVal; /* Encoder return value */
3999 DU_LOG("\nINFO --> E2AP : Building RIC Indication Message\n");
4001 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
4002 if(e2apMsg == NULLP)
4004 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
4008 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
4009 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
4010 if(e2apMsg->choice.initiatingMessage == NULLP)
4012 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
4015 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICindication;
4016 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
4017 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICindication;
4019 ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
4021 if(fillRicIndication(ricIndicationMsg, ricSubscriptionInfo, actionInfo) != ROK)
4023 DU_LOG("\nERROR --> E2AP : Failed to fill RIC Indication message");
4027 /* Prints the Msg formed */
4028 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
4029 memset(encBuf, 0, ENC_BUF_MAX_LEN);
4031 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
4033 if(encRetVal.encoded == ENCODE_FAIL)
4035 DU_LOG("\nERROR --> E2AP : Could not encode RIC Indication Message (at %s)\n",\
4036 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
4041 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Indication Message \n");
4042 #ifdef DEBUG_ASN_PRINT
4043 for(int i=0; i< encBufSize; i++)
4045 printf("%x",encBuf[i]);
4050 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
4052 DU_LOG("\nINFO --> E2AP : Sending RIC Indication Message");
4058 FreeRicIndication(e2apMsg);
4062 /*******************************************************************
4064 * @brief free e2 node component configuration req and rsp
4068 * Function : freeE2NodeComponentConfiguration
4071 * - free e2 node component configuration req and rsp
4073 * @params[in] E2nodeComponentConfiguration_t *e2nodeComponentConfiguration
4074 * @return ROK - success
4077 * ****************************************************************/
4079 void freeE2NodeComponentConfiguration(E2nodeComponentConfiguration_t *e2nodeComponentConfiguration)
4081 /* Free E2 Node Component Request Part */
4082 DU_FREE(e2nodeComponentConfiguration->e2nodeComponentRequestPart.buf, e2nodeComponentConfiguration->e2nodeComponentRequestPart.size);
4084 /* Free E2 Node Component Response Part */
4085 DU_FREE(e2nodeComponentConfiguration->e2nodeComponentResponsePart.buf, e2nodeComponentConfiguration->e2nodeComponentResponsePart.size);
4089 /*******************************************************************
4091 * @brief free e2 node component component identifier
4095 * Function : freeE2NodeComponentIdentifier
4098 * - free e2 node component component identifier
4100 * @params[in] E2nodeComponentID_t *componentID
4101 * @return ROK - success
4104 * ****************************************************************/
4106 void freeE2NodeComponentIdentifier(E2nodeComponentID_t *componentID)
4108 if(componentID->choice.e2nodeComponentInterfaceTypeF1)
4110 DU_FREE(componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf, componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
4111 DU_FREE(componentID->choice.e2nodeComponentInterfaceTypeF1, sizeof(E2nodeComponentInterfaceF1_t));
4116 /*******************************************************************
4118 * @brief Deallocate the memory allocated for E2nodeConfigurationUpdate msg
4122 * Function : FreeE2NodeConfigUpdate
4125 * - freeing the memory allocated for E2nodeConfigurationUpdate
4127 * @params[in] E2AP_PDU_t *e2apMsg
4128 * @return ROK - success
4131 * ****************************************************************/
4133 void FreeE2NodeConfigUpdate(E2AP_PDU_t *e2apMsg)
4135 uint8_t arrIdx =0, e2NodeUpdateListIdx=0, e2NodeRemovalListIdx=0, e2NodeAddListIdx=0;
4136 E2nodeConfigurationUpdate_t *e2NodeConfigUpdate =NULL;
4137 E2nodeComponentConfigUpdate_List_t *e2NodeUpdateList =NULL;
4138 E2nodeComponentConfigUpdate_ItemIEs_t *e2NodeUpdateItem =NULL;
4139 E2nodeComponentConfigRemoval_List_t *e2NodeRemovalList =NULL;
4140 E2nodeComponentConfigRemoval_ItemIEs_t *e2NodeRemovalItem =NULL;
4141 E2nodeComponentConfigAddition_List_t *e2NodeAddList =NULL;
4142 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem =NULL;
4144 if(e2apMsg != NULLP)
4146 if(e2apMsg->choice.initiatingMessage != NULLP)
4148 e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
4149 if(e2NodeConfigUpdate->protocolIEs.list.array != NULLP)
4151 for(arrIdx = 0; arrIdx < e2NodeConfigUpdate->protocolIEs.list.count; arrIdx++)
4153 if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx])
4156 switch(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id)
4158 case ProtocolIE_IDE2_id_TransactionID:
4161 case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
4163 e2NodeAddList = &e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List;
4164 if(e2NodeAddList->list.array)
4166 for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++)
4168 e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[e2NodeAddListIdx];
4170 freeE2NodeComponentConfiguration(&e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration);
4171 freeE2NodeComponentIdentifier(&e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID);
4172 DU_FREE(e2NodeAddItem, sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
4174 DU_FREE(e2NodeAddList->list.array, e2NodeAddList->list.size);
4178 case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdate:
4180 e2NodeUpdateList = &e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigUpdate_List;
4181 if(e2NodeUpdateList->list.array)
4183 for(e2NodeUpdateListIdx = 0; e2NodeUpdateListIdx< e2NodeUpdateList->list.count; e2NodeUpdateListIdx++)
4185 e2NodeUpdateItem = (E2nodeComponentConfigUpdate_ItemIEs_t *) e2NodeUpdateList->list.array[e2NodeUpdateListIdx];
4187 freeE2NodeComponentConfiguration(&e2NodeUpdateItem->value.choice.E2nodeComponentConfigUpdate_Item.e2nodeComponentConfiguration);
4188 freeE2NodeComponentIdentifier(&e2NodeUpdateItem->value.choice.E2nodeComponentConfigUpdate_Item.e2nodeComponentID);
4189 DU_FREE(e2NodeUpdateItem, sizeof(E2nodeComponentConfigUpdate_ItemIEs_t));
4191 DU_FREE(e2NodeUpdateList->list.array, e2NodeUpdateList->list.size);
4195 case ProtocolIE_IDE2_id_E2nodeComponentConfigRemoval:
4197 e2NodeRemovalList = &e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigRemoval_List;
4198 if(e2NodeRemovalList->list.array)
4200 for(e2NodeRemovalListIdx = 0; e2NodeRemovalListIdx< e2NodeRemovalList->list.count; e2NodeRemovalListIdx++)
4202 e2NodeRemovalItem = (E2nodeComponentConfigRemoval_ItemIEs_t *) e2NodeRemovalList->list.array[e2NodeRemovalListIdx];
4204 freeE2NodeComponentIdentifier(&e2NodeRemovalItem->value.choice.E2nodeComponentConfigRemoval_Item.e2nodeComponentID);
4205 DU_FREE(e2NodeRemovalItem, sizeof(E2nodeComponentConfigRemoval_ItemIEs_t));
4207 DU_FREE(e2NodeRemovalList->list.array, e2NodeRemovalList->list.size);
4215 DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
4218 DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size);
4220 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
4222 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
4226 /*******************************************************************
4228 * @brief Buld and send the E2 node config update msg
4232 * Function : BuildAndSendE2NodeConfigUpdate
4235 * - Buld and send the E2 node config update msg
4238 * @return ROK - success
4241 * ****************************************************************/
4243 uint8_t BuildAndSendE2NodeConfigUpdate(E2NodeConfigList *e2NodeList)
4245 uint8_t ret = RFAILED;
4246 uint8_t arrIdx = 0,elementCnt = 0, transId=0;
4247 E2AP_PDU_t *e2apMsg = NULLP;
4248 asn_enc_rval_t encRetVal; /* Encoder return value */
4249 E2nodeConfigurationUpdate_t *e2NodeConfigUpdate = NULLP;
4251 DU_LOG("\nINFO --> E2AP : Building E2 Node config update\n");
4254 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
4255 if(e2apMsg == NULLP)
4257 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
4261 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
4262 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
4263 if(e2apMsg->choice.initiatingMessage == NULLP)
4265 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
4268 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
4269 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
4270 e2apMsg->choice.initiatingMessage->value.present = \
4271 InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate;
4272 e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
4275 if(e2NodeList->addE2NodeCount)
4277 if(e2NodeList->updateE2NodeCount)
4279 if(e2NodeList->removeE2NodeCount)
4282 e2NodeConfigUpdate->protocolIEs.list.count = elementCnt;
4283 e2NodeConfigUpdate->protocolIEs.list.size = elementCnt * sizeof(E2nodeConfigurationUpdate_IEs_t*);
4284 DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size);
4285 if(e2NodeConfigUpdate->protocolIEs.list.array == NULLP)
4287 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
4291 for(arrIdx =0; arrIdx<elementCnt; arrIdx++)
4293 DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
4294 if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx] == NULLP)
4297 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
4302 if(arrIdx<elementCnt)
4306 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
4307 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
4308 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_TransactionID;
4309 transId = assignTransactionId();
4310 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
4312 if(e2NodeList->addE2NodeCount)
4315 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition;
4316 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
4317 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_E2nodeComponentConfigAddition_List;
4318 if(BuildE2NodeConfigAddList(&(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List),\
4319 ProcedureCodeE2_id_E2nodeConfigurationUpdate, e2NodeList->addE2NodeCount, e2NodeList->addE2Node)!=ROK)
4321 DU_LOG("\nERROR --> E2AP : Failed to create E2 Node config list");
4326 if(e2NodeList->updateE2NodeCount)
4329 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigUpdate;
4330 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
4331 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_E2nodeComponentConfigUpdate_List;
4332 if(BuildE2NodeConfigUpdateList(&e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigUpdate_List,\
4333 e2NodeList->updateE2NodeCount, e2NodeList->updateE2Node) != ROK)
4336 DU_LOG("\nERROR --> E2AP : Failed to update the E2 node configuration");
4341 if(e2NodeList->removeE2NodeCount)
4344 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigRemoval;
4345 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
4346 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_E2nodeComponentConfigRemoval_List;
4347 if(BuildE2NodeConfigRemoveList(&e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigRemoval_List,\
4348 e2NodeList->removeE2NodeCount, e2NodeList->removeE2Node) != ROK)
4351 DU_LOG("\nERROR --> E2AP : Failed to remove the E2 node configuration");
4356 /* Prints the Msg formed */
4357 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
4359 memset(encBuf, 0, ENC_BUF_MAX_LEN);
4361 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
4362 if(encRetVal.encoded == ENCODE_FAIL)
4364 DU_LOG("\nERROR --> E2AP : Could not encode E2nodeConfigurationUpdate structure (at %s)\n",\
4365 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
4370 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2nodeConfigurationUpdate\n");
4371 #ifdef DEBUG_ASN_PRINT
4372 for(int i=0; i< encBufSize; i++)
4374 printf("%x",encBuf[i]);
4378 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize))
4380 DU_LOG("\nERROR --> E2AP : Sending E2 node config update failed");
4384 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
4385 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
4386 memcpy(&duCb.e2apDb.e2TimersInfo.e2Timers.e2NodeConfigUpdate.configList, e2NodeList, sizeof(E2NodeConfigList));
4391 FreeE2NodeConfigUpdate(e2apMsg);
4395 /*******************************************************************
4397 * @brief Deallocate the memory allocated for E2ResetRequest msg
4401 * Function : FreeE2ResetRequest
4404 * - freeing the memory allocated for E2ResetRequest
4406 * @params[in] E2AP_PDU_t *e2apMsg
4407 * @return ROK - success
4410 * ****************************************************************/
4411 void FreeE2ResetRequest(E2AP_PDU_t *e2apMsg)
4414 ResetRequestE2_t *resetReq = NULLP;
4416 if(e2apMsg != NULLP)
4418 if(e2apMsg->choice.initiatingMessage != NULLP)
4420 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
4421 if(resetReq->protocolIEs.list.array)
4423 for(ieIdx = 0; ieIdx < resetReq->protocolIEs.list.count; ieIdx++)
4425 DU_FREE(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
4427 DU_FREE(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
4429 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
4431 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
4435 /*******************************************************************
4437 * @brief Build and send the E2 reset request msg
4441 * Function : BuildAndSendE2ResetRequest
4444 * - Buld and send the E2 reset request msg to RIC
4447 * @return ROK - success
4450 * ****************************************************************/
4451 uint8_t BuildAndSendE2ResetRequest(E2FailureCause resetCause)
4453 uint8_t ieIdx = 0, elementCnt = 0, transId = 0;
4454 uint8_t ret = RFAILED;
4455 E2AP_PDU_t *e2apMsg = NULLP;
4456 ResetRequestE2_t *resetReq = NULLP;
4457 asn_enc_rval_t encRetVal; /* Encoder return value */
4459 DU_LOG("\nINFO --> E2AP : Building E2 Reset Request\n");
4463 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
4464 if(e2apMsg == NULLP)
4466 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation for E2AP-PDU failed");
4470 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
4471 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
4472 if(e2apMsg->choice.initiatingMessage == NULLP)
4474 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation for initiatingMessage");
4478 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_Reset;
4479 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
4480 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ResetRequestE2;
4481 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
4484 resetReq->protocolIEs.list.count = elementCnt;
4485 resetReq->protocolIEs.list.size = elementCnt * sizeof(ResetRequestIEs_t *);
4487 DU_ALLOC(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
4488 if(!resetReq->protocolIEs.list.array)
4490 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
4491 Reset Request IE array");
4495 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
4497 DU_ALLOC(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
4498 if(!resetReq->protocolIEs.list.array[ieIdx])
4500 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
4501 Reset Request IE array element");
4506 /* In case of failure */
4507 if(ieIdx < elementCnt)
4511 resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
4512 resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
4513 resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_TransactionID;
4514 transId = assignTransactionId();
4515 resetReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
4518 resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_CauseE2;
4519 resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_ignore;
4520 resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_CauseE2;
4521 fillE2Cause(&resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2, resetCause);
4523 /* Prints the Msg formed */
4524 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
4526 memset(encBuf, 0, ENC_BUF_MAX_LEN);
4528 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
4530 if(encRetVal.encoded == ENCODE_FAIL)
4532 DU_LOG("\nERROR --> E2AP : Could not encode E2SetupRequest structure (at %s)\n",\
4533 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
4538 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupRequest\n");
4539 #ifdef DEBUG_ASN_PRINT
4540 for(int i=0; i< encBufSize; i++)
4542 printf("%x",encBuf[i]);
4546 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
4548 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
4552 /* In case the message is sent successfully, store the transaction info to
4553 * be used when response is received */
4554 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
4555 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
4561 /* Free all memory */
4562 FreeE2ResetRequest(e2apMsg);
4566 /*******************************************************************
4568 * @brief Deallocate the memory allocated for Reset Response msg
4572 * Function : freeAperDecodingOfE2ResetRsp
4575 * - freeing the memory allocated for Reset response
4577 * @params[in] ResetResponseE2_t *resetResponse
4580 * ****************************************************************/
4581 void freeAperDecodingOfE2ResetRsp(ResetResponseE2_t *resetResponse)
4587 if(resetResponse->protocolIEs.list.array)
4589 for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
4591 if(resetResponse->protocolIEs.list.array[ieIdx])
4593 switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
4595 case ProtocolIE_IDE2_id_TransactionID:
4598 case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
4601 free(resetResponse->protocolIEs.list.array[ieIdx]);
4604 free(resetResponse->protocolIEs.list.array);
4609 /******************************************************************
4611 * @brief Processes E2 Reset Response sent by RIC
4615 * Function : procResetResponse
4617 * Functionality: Processes E2 Reset Response sent by RIC
4619 * @params[in] E2AP_PDU_t ASN decoded E2AP message
4620 * @return ROK - success
4623 * ****************************************************************/
4624 uint8_t procResetResponse(E2AP_PDU_t *e2apMsg)
4626 uint8_t ieIdx =0, transId;
4627 ResetResponseE2_t *resetResponse;
4629 DU_LOG("\nINFO --> E2AP : E2 Reset Response received");
4630 resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;;
4632 for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
4634 switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
4636 case ProtocolIE_IDE2_id_TransactionID:
4637 transId = resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
4638 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) && \
4639 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
4641 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
4645 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
4649 case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
4650 /* As per ORAN WG3 E2AP spec v3.0, section 9.2.2
4651 Criticality Diagnostics IE is sent by Near-RT RIC when parts of a received message i.e.
4652 Reset Request in this case, have not been comprehended or were missing, or if the message
4653 contained logical errors.
4655 Processing of this ID should be implemented when negative call flows are to be supported.
4659 DU_LOG("\nERROR --> E2AP : Invalid IE received in E2 Reset Response : %ld",
4660 resetResponse->protocolIEs.list.array[ieIdx]->id);
4665 freeAperDecodingOfE2ResetRsp(resetResponse);
4669 /******************************************************************
4671 * @brief Deallocation of memory allocated by aper decoder for e2 setup Failure
4675 * Function : freeAperDecodingOfE2SetupFailure
4677 * Functionality: Deallocation of memory allocated by aper decoder for e2
4680 * @params[in] E2setupFailure_t *e2SetupFailure;
4683 * ****************************************************************/
4684 void freeAperDecodingOfE2SetupFailure(E2setupFailure_t *e2SetupFailure)
4690 if(e2SetupFailure->protocolIEs.list.array)
4692 for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
4694 if(e2SetupFailure->protocolIEs.list.array[arrIdx])
4696 free(e2SetupFailure->protocolIEs.list.array[arrIdx]);
4699 free(e2SetupFailure->protocolIEs.list.array);
4703 /******************************************************************
4705 * @brief Processes E2 Setup Failure sent by RIC
4709 * Function : procE2SetupFailure
4711 * Functionality: Processes E2 Setup failure sent by RIC
4713 * @params[in] E2AP_PDU_t ASN decoded E2AP message
4714 * @return ROK - success
4717 * ****************************************************************/
4718 void procE2SetupFailure(E2AP_PDU_t *e2apMsg)
4720 uint8_t arrIdx =0, transId =0, timerValue=0;
4721 E2setupFailure_t *e2SetupFailure;
4723 DU_LOG("\nINFO --> E2AP : E2 Setup failure received");
4724 e2SetupFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure;
4726 for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
4728 switch(e2SetupFailure->protocolIEs.list.array[arrIdx]->id)
4730 case ProtocolIE_IDE2_id_TransactionID:
4732 transId = e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
4733 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
4734 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
4736 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
4740 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
4745 case ProtocolIE_IDE2_id_TimeToWaitE2:
4747 timerValue = convertE2WaitTimerEnumToValue(e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
4748 if((duChkTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.e2SetupTimer), EVENT_E2_SETUP_TMR)) == FALSE)
4750 duStartTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.e2SetupTimer), EVENT_E2_SETUP_TMR, timerValue);
4754 DU_LOG("\nERROR --> E2AP : EVENT_E2_SETUP_TMR timer is already running");
4762 freeAperDecodingOfE2SetupFailure(e2SetupFailure);
4764 /******************************************************************
4766 * @brief Deallocation of memory allocated by aper decoder for RIC service Query
4770 * Function : freeAperDecodingOfRicServiceQuery
4772 * Functionality: Deallocation of memory allocated by aper decoder for RIC
4775 * @params[in] RICserviceQuery_t *ricServiceQuery;
4778 * ****************************************************************/
4780 void freeAperDecodingOfRicServiceQuery(RICserviceQuery_t *ricServiceQuery)
4782 uint8_t arrIdx,ranFuncIdx;
4783 RANfunctionsID_List_t *ranFuncAddedList;
4787 if(ricServiceQuery->protocolIEs.list.array)
4789 for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
4791 if(ricServiceQuery->protocolIEs.list.array[arrIdx])
4793 switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
4795 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
4797 ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
4798 if(ranFuncAddedList->list.array)
4800 for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
4802 free(ranFuncAddedList->list.array[ranFuncIdx]);
4804 free(ranFuncAddedList->list.array);;
4811 free(ricServiceQuery->protocolIEs.list.array[arrIdx]);
4814 free(ricServiceQuery->protocolIEs.list.array);
4818 /*******************************************************************
4820 * @brief Build RanFunction Delete List
4824 * Function : BuildRanFunctionDeleteList
4826 * Functionality: Build RanFunction Delete List
4829 * RANfunctionsID List
4830 * Count of the RAN function
4831 * Received RAN function list
4833 * @return ROK - success
4836 ******************************************************************/
4838 uint8_t BuildRanFunctionDeleteList(RANfunctionsID_List_t *deleteList, uint8_t count, RanFuncInfo *recvdRanFunc)
4840 uint8_t ranFuncIdx=0;
4841 RANfunctionID_ItemIEs_t *delRanFuncItem;
4845 deleteList->list.count = count;
4846 deleteList->list.size = deleteList->list.count * sizeof(RANfunctionID_ItemIEs_t*);
4847 DU_ALLOC(deleteList->list.array, deleteList->list.size);
4848 if(deleteList->list.array == NULLP)
4850 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
4853 for(ranFuncIdx = 0; ranFuncIdx< deleteList->list.count; ranFuncIdx++)
4855 DU_ALLOC(deleteList->list.array[ranFuncIdx], sizeof(RANfunctionID_ItemIEs_t));
4856 if(deleteList->list.array[ranFuncIdx] == NULLP)
4858 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
4861 delRanFuncItem= (RANfunctionID_ItemIEs_t *) deleteList->list.array[ranFuncIdx];
4862 delRanFuncItem->id = ProtocolIE_IDE2_id_RANfunctionID_Item;
4863 delRanFuncItem->criticality = CriticalityE2_ignore;
4864 delRanFuncItem->value.choice.RANfunctionID_Item.ranFunctionID = recvdRanFunc[ranFuncIdx].id;
4865 delRanFuncItem->value.choice.RANfunctionID_Item.ranFunctionRevision = recvdRanFunc[ranFuncIdx].revisionCounter;
4871 /*******************************************************************
4873 * @brief De Allocate Ric Service Update message
4877 * Function : FreeRicServiceUpdate
4879 * Functionality: De-Allocating Ric Service Update message
4881 * @params[in] E2AP_PDU_t *e2apMsg
4885 * ****************************************************************/
4887 void FreeRicServiceUpdate(E2AP_PDU_t *e2apMsg)
4890 uint8_t ranFuncAddListIdx=0, ranFuncDelIdx=0;
4891 RICserviceUpdate_t *ricServiceUpdate;
4892 RANfunctions_List_t *ranFunctionsList;
4893 RANfunction_ItemIEs_t *ranFuncItemIe;
4894 RANfunction_Item_t *ranFunItem;
4895 RANfunctionsID_List_t *deleteList;
4897 /* De-allocating Memory */
4898 if(e2apMsg != NULLP)
4900 if(e2apMsg->choice.initiatingMessage != NULLP)
4902 ricServiceUpdate = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate;
4903 if(ricServiceUpdate->protocolIEs.list.array != NULLP)
4905 for(arrIdx = 0; arrIdx < ricServiceUpdate->protocolIEs.list.count; arrIdx++)
4907 if(ricServiceUpdate->protocolIEs.list.array[arrIdx] != NULLP)
4909 switch(ricServiceUpdate->protocolIEs.list.array[arrIdx]->id)
4911 case ProtocolIE_IDE2_id_TransactionID:
4914 case ProtocolIE_IDE2_id_RANfunctionsAdded:
4915 case ProtocolIE_IDE2_id_RANfunctionsModified:
4917 ranFunctionsList = &(ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List);
4918 if(ranFunctionsList->list.array)
4920 for(ranFuncAddListIdx= 0; ranFuncAddListIdx< ranFunctionsList->list.count; ranFuncAddListIdx++)
4922 if(ranFunctionsList->list.array[ranFuncAddListIdx])
4924 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncAddListIdx];
4925 ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
4926 DU_FREE(ranFunItem->ranFunctionOID.buf, ranFunItem->ranFunctionOID.size);
4927 DU_FREE(ranFunItem->ranFunctionDefinition.buf, ranFunItem->ranFunctionDefinition.size);
4928 DU_FREE(ranFunctionsList->list.array[ranFuncAddListIdx], sizeof(RANfunction_ItemIEs_t));
4931 DU_FREE(ranFunctionsList->list.array, ranFunctionsList->list.size);
4935 case ProtocolIE_IDE2_id_RANfunctionsDeleted:
4937 deleteList= &ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
4938 if(deleteList->list.array)
4940 for(ranFuncDelIdx = 0; ranFuncDelIdx< deleteList->list.count; ranFuncDelIdx++)
4942 DU_FREE(deleteList->list.array[ranFuncDelIdx], sizeof(RANfunctionID_ItemIEs_t));
4944 DU_FREE(deleteList->list.array, deleteList->list.size);
4950 DU_LOG("\nERROR --> E2AP: Invalid event at ricServiceUpdate %ld ",\
4951 (ricServiceUpdate->protocolIEs.list.array[arrIdx]->id));
4954 DU_FREE(ricServiceUpdate->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdate_IEs_t));
4957 DU_FREE(ricServiceUpdate->protocolIEs.list.array, ricServiceUpdate->protocolIEs.list.size);
4959 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
4961 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
4965 /*******************************************************************
4967 * @brief Builds and Send the RicServiceUpdateuest
4971 * Function : BuildAndSendRicServiceUpdate
4973 * Functionality:Fills the RicServiceUpdateuest
4975 * @return ROK - success
4978 ******************************************************************/
4980 uint8_t BuildAndSendRicServiceUpdate(RicServiceUpdate serviceUpdate)
4982 uint8_t arrIdx = 0, elementCnt=0;
4983 uint8_t transId = 0, ret = RFAILED;
4984 bool memAllocFailed =false;
4985 E2AP_PDU_t *e2apMsg = NULLP;
4986 RICserviceUpdate_t *ricServiceUpdate = NULLP;
4987 asn_enc_rval_t encRetVal; /* Encoder return value */
4989 DU_LOG("\nINFO --> E2AP : Building Ric Service Update\n");
4992 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
4993 if(e2apMsg == NULLP)
4995 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
4998 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
4999 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
5000 if(e2apMsg->choice.initiatingMessage == NULLP)
5002 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
5005 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
5006 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICserviceUpdate;
5007 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICserviceUpdate;
5008 ricServiceUpdate = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate;
5010 /* For TransId IE, set elementCnt to 1.
5011 If there is any item in the RAN function add list, RAN function modification list, or RAN function delete list, increment the elementCnt.*/
5014 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
5016 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeModified)
5018 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted)
5021 ricServiceUpdate->protocolIEs.list.count = elementCnt;
5022 ricServiceUpdate->protocolIEs.list.size = elementCnt * sizeof(RICserviceUpdate_IEs_t*);
5024 /* Initialize the E2Setup members */
5025 DU_ALLOC(ricServiceUpdate->protocolIEs.list.array, ricServiceUpdate->protocolIEs.list.size);
5026 if(ricServiceUpdate->protocolIEs.list.array == NULLP)
5028 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements");
5032 for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
5034 DU_ALLOC(ricServiceUpdate->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdate_IEs_t));
5035 if(ricServiceUpdate->protocolIEs.list.array[arrIdx] == NULLP)
5037 memAllocFailed = true;
5038 DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayIdx [%d]", arrIdx);
5042 if(memAllocFailed == true)
5048 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
5049 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
5050 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
5051 if(serviceUpdate.dir == E2_NODE_INITIATED)
5052 transId = assignTransactionId();
5054 transId = serviceUpdate.transId;
5055 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
5057 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
5060 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
5061 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
5062 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
5063 if(BuildRanFunctionAddList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List,\
5064 e2apMsg->choice.initiatingMessage->procedureCode, serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded, serviceUpdate.recvRanFuncList.ranFunToBeAdded) !=ROK)
5070 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeModified)
5073 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsModified;
5074 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
5075 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
5076 if(BuildRanFunctionAddList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List,
5077 e2apMsg->choice.initiatingMessage->procedureCode, serviceUpdate.recvRanFuncList.numOfRanFunToBeModified, serviceUpdate.recvRanFuncList.ranFunToBeModified) !=ROK)
5083 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted)
5086 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsDeleted;
5087 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
5088 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctionsID_List;
5089 if(BuildRanFunctionDeleteList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List,\
5090 serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted, serviceUpdate.recvRanFuncList.ranFunToBeDeleted) != ROK)
5095 /* Prints the Msg formed */
5096 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
5098 memset(encBuf, 0, ENC_BUF_MAX_LEN);
5100 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
5101 if(encRetVal.encoded == ENCODE_FAIL)
5103 DU_LOG("\nERROR --> E2AP : Could not encode RicServiceUpdateuest structure (at %s)\n",\
5104 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
5109 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RicServiceUpdateuest\n");
5110 #ifdef DEBUG_ASN_PRINT
5111 for(int i=0; i< encBufSize; i++)
5113 printf("%x",encBuf[i]);
5117 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
5119 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
5128 if(serviceUpdate.dir == E2_NODE_INITIATED)
5130 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
5131 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
5135 duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].transactionId = transId;
5136 duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
5138 duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.dir = serviceUpdate.dir;
5139 duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.transId =transId;
5140 memcpy(&duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.recvRanFuncList, &serviceUpdate.recvRanFuncList, sizeof(E2TmpRanFunList));
5142 FreeRicServiceUpdate(e2apMsg);
5145 /******************************************************************
5147 * @brief Processes RIC service Query sent by RIC
5151 * Function : procRicServiceQuery
5153 * Functionality: Processes RIC service Query sent by RIC
5155 * @params[in] E2AP_PDU_t ASN decoded E2AP message
5156 * @return ROK - success
5159 * ****************************************************************/
5161 void procRicServiceQuery(E2AP_PDU_t *e2apMsg)
5164 uint16_t arrIdx =0, ranFuncIdx=0,tmpIdx=0;
5165 uint16_t id,revisionCcounter;
5166 bool tmpArray[MAX_RAN_FUNCTION] = {false};
5167 RICserviceQuery_t *ricServiceQuery=NULL;
5168 RicServiceUpdate ricUpdate;
5169 RANfunctionID_ItemIEs_t *ranFuncAddedItemIe;
5170 RANfunctionsID_List_t *ranFuncAddedList;
5172 DU_LOG("\nINFO --> E2AP : RIC Service Query received");
5173 memset(&ricUpdate, 0, sizeof(RicServiceUpdate));
5174 ricUpdate.dir = RIC_INITIATED;
5175 ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
5177 for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
5179 switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
5181 /* TODO completing in next patch/gerrit */
5182 case ProtocolIE_IDE2_id_TransactionID:
5184 ricUpdate.transId = ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
5188 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
5190 ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
5191 if(ranFuncAddedList->list.array)
5193 for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
5195 if(ranFuncAddedList->list.array[ranFuncIdx])
5197 /* Using the RAN function Id, identify the RAN function to be modified or deleted. */
5199 ranFuncAddedItemIe = (RANfunctionID_ItemIEs_t*)ranFuncAddedList->list.array[ranFuncIdx];
5200 id = ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionID;
5201 revisionCcounter = ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionRevision;
5203 if((id != duCb.e2apDb.ranFunction[id-1].id))
5205 action = CONFIG_DEL;
5207 else if((id == duCb.e2apDb.ranFunction[id-1].id)&&(revisionCcounter!=duCb.e2apDb.ranFunction[id-1].revisionCounter))
5209 action = CONFIG_MOD;
5212 if(action == CONFIG_DEL)
5214 ricUpdate.recvRanFuncList.ranFunToBeDeleted[ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted].id = id;
5215 ricUpdate.recvRanFuncList.ranFunToBeDeleted[ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted].revisionCounter = revisionCcounter;
5216 ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted++;
5218 else if(action == CONFIG_MOD)
5220 ricUpdate.recvRanFuncList.ranFunToBeModified[ricUpdate.recvRanFuncList.numOfRanFunToBeModified].id = id;
5221 ricUpdate.recvRanFuncList.ranFunToBeModified[ricUpdate.recvRanFuncList.numOfRanFunToBeModified].revisionCounter = revisionCcounter;
5222 ricUpdate.recvRanFuncList.numOfRanFunToBeModified++;
5225 /* If any ID is set to true, it means that the ID has been used in either modification or deletion list.
5226 * Else we will add the IDs into the added list */
5227 tmpArray[id-1] = true;
5236 /* Traversing the whole RAN function list in ducb to check if any new Ran function ids have been added. */
5237 for(arrIdx =0; arrIdx<MAX_RAN_FUNCTION; arrIdx++)
5239 tmpIdx= ricUpdate.recvRanFuncList.numOfRanFunToBeAdded;
5240 if((duCb.e2apDb.ranFunction[arrIdx].id >0)&&(!tmpArray[arrIdx]))
5242 ricUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].id = duCb.e2apDb.ranFunction[arrIdx].id;
5243 ricUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].revisionCounter = duCb.e2apDb.ranFunction[arrIdx].revisionCounter;
5244 ricUpdate.recvRanFuncList.numOfRanFunToBeAdded++;
5248 if(BuildAndSendRicServiceUpdate(ricUpdate)!= ROK)
5250 DU_LOG("\nERROR --> E2AP : Failed to build and send ric service update message");
5253 freeAperDecodingOfRicServiceQuery(ricServiceQuery);
5256 /******************************************************************
5258 * @brief Deallocation of memory allocated by aper decoder for
5259 * RIC service update ack
5263 * Function : freeAperDecodingOfRicServiceUpdateAck
5265 * Functionality: Deallocation of memory allocated by aper decoder
5266 * for RIC service update ack
5268 * @params[in] RICserviceUpdateAck_t *ricServiceAck;
5271 * ****************************************************************/
5273 void freeAperDecodingOfRicServiceUpdateAck(RICserviceUpdateAcknowledge_t *ricServiceAck)
5275 uint8_t arrIdx=0,ranFuncIdx=0;
5276 RANfunctionsID_List_t *ranFuncAddedList=NULL;
5280 if(ricServiceAck->protocolIEs.list.array)
5282 for(arrIdx=0; arrIdx<ricServiceAck->protocolIEs.list.count; arrIdx++)
5284 if(ricServiceAck->protocolIEs.list.array[arrIdx])
5286 switch(ricServiceAck->protocolIEs.list.array[arrIdx]->id)
5288 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
5290 ranFuncAddedList= &ricServiceAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
5291 if(ranFuncAddedList->list.array)
5293 for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
5295 free(ranFuncAddedList->list.array[ranFuncIdx]);
5297 free(ranFuncAddedList->list.array);
5304 free(ricServiceAck->protocolIEs.list.array[arrIdx]);
5307 free(ricServiceAck->protocolIEs.list.array);
5312 /******************************************************************
5314 * @brief Processes RIC service update ack sent by RIC
5318 * Function : procRicServiceUpdateAck
5320 * Functionality: Processes RIC service update ack sent by RIC
5322 * @params[in] E2AP_PDU_t ASN decoded E2AP message
5323 * @return ROK - success
5326 * ****************************************************************/
5328 void procRicServiceUpdateAck(E2AP_PDU_t *e2apMsg)
5330 uint8_t arrIdx =0, transId =0;
5331 uint16_t id =0, tmpIdx=0, ranFuncIdx=0;
5332 RicServiceUpdate serviceUpdate;
5333 RANfunctionsIDcause_List_t *rejectedList=NULL;
5334 RICserviceUpdateAcknowledge_t *ricServiceAck=NULL;
5335 RANfunctionIDcause_ItemIEs_t *ranFuncRejectedItemIe=NULL;
5337 DU_LOG("\nINFO --> E2AP : RIC service update ack received");
5338 memset(&serviceUpdate, 0, sizeof(RicServiceUpdate));
5339 ricServiceAck = &e2apMsg->choice.successfulOutcome->value.choice.RICserviceUpdateAcknowledge;
5341 for(arrIdx=0; arrIdx<ricServiceAck->protocolIEs.list.count; arrIdx++)
5343 switch(ricServiceAck->protocolIEs.list.array[arrIdx]->id)
5345 case ProtocolIE_IDE2_id_TransactionID:
5347 transId = ricServiceAck->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
5348 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
5349 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
5351 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
5353 else if((duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].transactionId == transId) &&\
5354 (duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
5356 memset(&duCb.e2apDb.e2TransInfo.ricInitTransaction[transId], 0, sizeof(E2TransInfo));
5360 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
5366 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
5369 case ProtocolIE_IDE2_id_RANfunctionsRejected:
5371 rejectedList= &ricServiceAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsIDcause_List;
5372 if(rejectedList->list.array)
5374 for(ranFuncIdx=0;ranFuncIdx<rejectedList->list.count; ranFuncIdx++)
5376 ranFuncRejectedItemIe = (RANfunctionIDcause_ItemIEs_t*)rejectedList->list.array[ranFuncIdx];
5377 id = ranFuncRejectedItemIe->value.choice.RANfunctionIDcause_Item.ranFunctionID;
5378 tmpIdx= serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded;
5379 serviceUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].id = duCb.e2apDb.ranFunction[id-1].id;
5380 serviceUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].revisionCounter = duCb.e2apDb.ranFunction[id-1].revisionCounter;
5381 serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded++;
5390 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
5392 serviceUpdate.dir = E2_NODE_INITIATED;
5393 BuildAndSendRicServiceUpdate(serviceUpdate);
5395 freeAperDecodingOfRicServiceUpdateAck(ricServiceAck);
5398 /******************************************************************
5400 * @brief Deallocation of memory allocated by aper decoder for
5401 * RIC service update failure
5405 * Function : freeAperDecodingOfRicServiceUpdateFailure
5407 * Functionality: Deallocation of memory allocated by aper decoder
5408 * for RIC service update failure
5410 * @params[in] RICserviceUpdateFailure_t *ricServiceFailure;
5413 * ****************************************************************/
5415 void freeAperDecodingOfRicServiceUpdateFailure(RICserviceUpdateFailure_t *ricServiceFailure)
5419 if(ricServiceFailure)
5421 if(ricServiceFailure->protocolIEs.list.array)
5423 for(arrIdx=0; arrIdx<ricServiceFailure->protocolIEs.list.count; arrIdx++)
5425 if(ricServiceFailure->protocolIEs.list.array[arrIdx])
5427 free(ricServiceFailure->protocolIEs.list.array[arrIdx]);
5430 free(ricServiceFailure->protocolIEs.list.array);
5435 /******************************************************************
5437 * @brief Processes RIC service update failure sent by RIC
5441 * Function : procRicServiceUpdateFailure
5443 * Functionality: Processes RIC service update failure sent by RIC
5445 * @params[in] E2AP_PDU_t ASN decoded E2AP message
5446 * @return ROK - success
5449 * ****************************************************************/
5451 void procRicServiceUpdateFailure(E2AP_PDU_t *e2apMsg)
5453 uint8_t arrIdx =0, timerValue=0;
5454 RICserviceUpdateFailure_t *ricServiceFailure=NULL;
5456 DU_LOG("\nINFO --> E2AP : RIC service update failure received");
5457 ricServiceFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICserviceUpdateFailure;
5459 for(arrIdx=0; arrIdx<ricServiceFailure->protocolIEs.list.count; arrIdx++)
5461 switch(ricServiceFailure->protocolIEs.list.array[arrIdx]->id)
5463 case ProtocolIE_IDE2_id_TransactionID:
5467 case ProtocolIE_IDE2_id_TimeToWaitE2:
5469 timerValue = convertE2WaitTimerEnumToValue(ricServiceFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
5470 if((duChkTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer), EVENT_RIC_SERVICE_UPDATE_TMR)) == FALSE)
5472 duStartTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer), EVENT_RIC_SERVICE_UPDATE_TMR, timerValue);
5476 DU_LOG("\nERROR --> E2AP : EVENT_RIC_SERVICE_UPDATE_TMR timer is already running");
5481 case ProtocolIE_IDE2_id_CauseE2:
5488 freeAperDecodingOfRicServiceUpdateFailure(ricServiceFailure);
5491 /******************************************************************
5493 * @brief DU Send E2 Node Configuration Update
5497 * Function : duSendE2NodeConfigurationUpdate
5499 * Functionality: DU Send E2 Node Configuration Update
5501 * @return ROK - success
5504 * ****************************************************************/
5506 uint8_t duSendE2NodeConfigurationUpdate()
5508 E2NodeConfigList e2NodeList;
5509 CmLList *node =NULL;
5510 E2NodeComponent *e2NodeComponentInfo=NULL;
5512 memset(&e2NodeList, 0, sizeof(E2NodeConfigList));
5513 CM_LLIST_FIRST_NODE(&duCb.e2apDb.e2NodeComponentList, node);
5516 e2NodeComponentInfo = (E2NodeComponent*)node->node;
5518 if(e2NodeComponentInfo->componentRequestPart && e2NodeComponentInfo->componentResponsePart)
5520 switch(e2NodeComponentInfo->componentActionType)
5522 case E2_NODE_COMPONENT_ADD:
5524 e2NodeList.addE2Node[e2NodeList.addE2NodeCount].interface = e2NodeComponentInfo->interfaceType;
5525 e2NodeList.addE2Node[e2NodeList.addE2NodeCount].actionType = e2NodeComponentInfo->componentActionType;
5526 e2NodeList.removeE2NodeCount++;
5529 case E2_NODE_COMPONENT_UPDATE:
5531 e2NodeList.updateE2Node[e2NodeList.updateE2NodeCount].interface = e2NodeComponentInfo->interfaceType;
5532 e2NodeList.updateE2Node[e2NodeList.updateE2NodeCount].actionType = e2NodeComponentInfo->componentActionType;
5533 e2NodeList.updateE2NodeCount++;
5537 case E2_NODE_COMPONENT_DEL:
5539 e2NodeList.removeE2Node[e2NodeList.removeE2NodeCount].interface = e2NodeComponentInfo->interfaceType;
5540 e2NodeList.removeE2Node[e2NodeList.removeE2NodeCount].actionType = e2NodeComponentInfo->componentActionType;
5541 e2NodeList.removeE2NodeCount++;
5549 if(BuildAndSendE2NodeConfigUpdate(&e2NodeList) !=ROK)
5551 DU_LOG("\nERROR --> E2AP : Failed to build and send e2 node config update message to RIC_stub");
5557 /*******************************************************************
5559 * @brief Free RIC Subscription Modification Required
5563 * Function : FreeRicSubsModRequired
5565 * Functionality: Freqq RIC Subscription Modification required
5567 * @param E2AP Message PDU to be freed
5570 ******************************************************************/
5571 void FreeRicSubsModRequired(E2AP_PDU_t *e2apMsg)
5573 uint8_t ieIdx = 0, arrIdx = 0;
5574 RICsubscriptionModificationRequired_t *ricSubsModReqd = NULLP;
5575 RICsubscriptionModificationRequired_IEs_t *ricSubsModReqdIe = NULLP;
5576 RICactions_RequiredToBeModified_List_t *actionToBeModList = NULLP;
5577 RICactions_RequiredToBeRemoved_List_t *actionToBeRmvList = NULLP;
5581 if(e2apMsg->choice.initiatingMessage)
5583 ricSubsModReqd = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionModificationRequired;
5584 if(ricSubsModReqd->protocolIEs.list.array)
5586 for(ieIdx = 0; ieIdx < ricSubsModReqd->protocolIEs.list.count; ieIdx++)
5588 if(ricSubsModReqd->protocolIEs.list.array[ieIdx])
5590 ricSubsModReqdIe = ricSubsModReqd->protocolIEs.list.array[ieIdx];
5591 switch(ricSubsModReqdIe->id)
5593 case ProtocolIE_IDE2_id_RICactionsRequiredToBeModified_List:
5595 actionToBeModList = &ricSubsModReqdIe->value.choice.RICactions_RequiredToBeModified_List;
5596 if(actionToBeModList->list.array)
5598 for(arrIdx = 0; arrIdx < actionToBeModList->list.count; arrIdx++)
5600 DU_FREE(actionToBeModList->list.array[arrIdx], \
5601 sizeof(RICaction_RequiredToBeModified_ItemIEs_t));
5603 DU_FREE(actionToBeModList->list.array, actionToBeModList->list.size);
5608 case ProtocolIE_IDE2_id_RICactionsRequiredToBeRemoved_List:
5610 actionToBeRmvList = &ricSubsModReqdIe->value.choice.RICactions_RequiredToBeRemoved_List;
5611 if(actionToBeRmvList->list.array)
5613 for(arrIdx = 0; arrIdx < actionToBeRmvList->list.count; arrIdx++)
5615 DU_FREE(actionToBeRmvList->list.array[arrIdx], \
5616 sizeof(RICaction_RequiredToBeRemoved_ItemIEs_t));
5618 DU_FREE(actionToBeRmvList->list.array, actionToBeRmvList->list.size);
5626 DU_FREE(ricSubsModReqd->protocolIEs.list.array[ieIdx], \
5627 sizeof(RICsubscriptionModificationRequired_IEs_t));
5630 DU_FREE(ricSubsModReqd->protocolIEs.list.array, ricSubsModReqd->protocolIEs.list.size);
5632 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
5634 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
5638 /* A RIC Subscription includes RIC subsequent action only for RIC Insert service.
5639 * However, E2SM-KPM supports only RIC Report service.
5640 * Hence there is no subsequent action in RIC subscription that may require modification.
5641 * So commenting the action-modification IEs for the time being
5644 /*******************************************************************
5646 * @brief Fill Action required to be modified list
5650 * Function : FillActionReqdToBeModList
5652 * Functionality: Fill Action required to be modified list
5654 * @param RIC Actions Required To Be Modified List to be filled
5655 * Number of actions to be modified
5656 * RIC Subscription DB
5657 * @return ROK - success
5660 ******************************************************************/
5661 uint8_t FillActionReqdToBeModList(RICactions_RequiredToBeModified_List_t *actionToBeModList, uint8_t numActionsMod, \
5662 RicSubscription *ricSubscription)
5664 uint8_t arrIdx = 0, actionIdx = 0;
5665 RICaction_RequiredToBeModified_ItemIEs_t *actionToBeMod = NULL;
5667 actionToBeModList->list.count = numActionsMod;
5668 actionToBeModList->list.size = numActionsMod * sizeof(RICaction_RequiredToBeModified_ItemIEs_t *);
5669 DU_ALLOC(actionToBeModList->list.array, actionToBeModList->list.size);
5670 if(!actionToBeModList->list.array)
5672 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
5677 for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
5679 if(ricSubscription->actionSequence[actionIdx].action == CONFIG_MOD)
5681 DU_ALLOC(actionToBeModList->list.array[arrIdx], sizeof(RICaction_RequiredToBeModified_ItemIEs_t));
5682 if(!actionToBeModList->list.array[arrIdx])
5684 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
5687 actionToBeMod = (RICaction_RequiredToBeModified_ItemIEs_t *)actionToBeModList->list.array[arrIdx];
5689 actionToBeMod->id = ProtocolIE_IDE2_id_RICaction_RequiredToBeModified_Item;
5690 actionToBeMod->criticality = CriticalityE2_reject;
5691 actionToBeMod->value.present = \
5692 RICaction_RequiredToBeModified_ItemIEs__value_PR_RICaction_RequiredToBeModified_Item;
5693 actionToBeMod->value.choice.RICaction_RequiredToBeModified_Item.ricActionID = \
5694 ricSubscription->actionSequence[actionIdx].actionId;
5695 actionToBeMod->value.choice.RICaction_RequiredToBeModified_Item.ricTimeToWait = RICtimeToWait_w5ms;
5705 /*******************************************************************
5707 * @brief Fill Action required to be removed list
5711 * Function : FillActionReqdToBeRmvList
5713 * Functionality: Fill Action required to be removed list
5715 * @param RIC Actions Required To Be Removed List to be filled
5716 * Number of actions to be removed
5717 * RIC Subscription DB
5718 * @return ROK - success
5721 ******************************************************************/
5722 uint8_t FillActionReqdToBeRmvList(RICactions_RequiredToBeRemoved_List_t *actionToBeRmvList, uint8_t numActionsRmv, \
5723 RicSubscription *ricSubscription)
5725 uint8_t arrIdx = 0, actionIdx = 0;
5726 RICaction_RequiredToBeRemoved_ItemIEs_t *actionToBeRmv = NULL;
5728 actionToBeRmvList->list.count = numActionsRmv;
5729 actionToBeRmvList->list.size = numActionsRmv * sizeof(RICaction_RequiredToBeRemoved_ItemIEs_t *);
5730 DU_ALLOC(actionToBeRmvList->list.array, actionToBeRmvList->list.size);
5731 if(!actionToBeRmvList->list.array)
5733 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed at line %d", __func__, __LINE__);
5738 for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
5740 if(ricSubscription->actionSequence[actionIdx].action == CONFIG_DEL)
5742 DU_ALLOC(actionToBeRmvList->list.array[arrIdx], sizeof(RICaction_RequiredToBeRemoved_ItemIEs_t));
5743 if(!actionToBeRmvList->list.array[arrIdx])
5745 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed at line %d", __func__, __LINE__);
5748 actionToBeRmv = (RICaction_RequiredToBeRemoved_ItemIEs_t *)actionToBeRmvList->list.array[arrIdx];
5750 actionToBeRmv->id = ProtocolIE_IDE2_id_RICaction_RequiredToBeRemoved_Item;
5751 actionToBeRmv->criticality = CriticalityE2_reject;
5752 actionToBeRmv->value.present = \
5753 RICaction_RequiredToBeRemoved_ItemIEs__value_PR_RICaction_RequiredToBeRemoved_Item;
5754 actionToBeRmv->value.choice.RICaction_RequiredToBeRemoved_Item.ricActionID = \
5755 ricSubscription->actionSequence[actionIdx].actionId;
5756 fillE2Cause(&actionToBeRmv->value.choice.RICaction_RequiredToBeRemoved_Item.cause, \
5757 ricSubscription->actionSequence[actionIdx].failureCause);
5766 /*******************************************************************
5768 * @brief Fill RIC Subscription Modification Required IEs
5772 * Function : FillRicSubsModRequired
5774 * Functionality: Fill RIC Subscription Modification Required IEs
5776 * @param RIC Subscription Modification Required IEs to be filled
5777 * RIC Subscription DB
5778 * @return ROK - success
5781 ******************************************************************/
5782 uint8_t FillRicSubsModRequired(RICsubscriptionModificationRequired_t *ricSubsModReqd, RicSubscription *ricSubscription)
5784 uint8_t ieIdx = 0, elementCnt=0, actionIdx = 0;
5785 uint8_t numActionsMod = 0, numActionsRmv = 0;
5786 RICsubscriptionModificationRequired_IEs_t *ricSubsModReqdIe = NULLP;
5787 RICactions_RequiredToBeModified_List_t *actionToBeModList = NULLP;
5788 RICactions_RequiredToBeRemoved_List_t *actionToBeRmvList = NULLP;
5790 /* Count number of Actions to be modified or deleted */
5791 for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
5793 if(ricSubscription->actionSequence[actionIdx].action == CONFIG_MOD)
5795 else if(ricSubscription->actionSequence[actionIdx].action == CONFIG_DEL)
5799 /* Count number of IEs to be added to messages */
5806 ricSubsModReqd->protocolIEs.list.count = elementCnt;
5807 ricSubsModReqd->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionModificationRequired_IEs_t *);
5808 DU_ALLOC(ricSubsModReqd->protocolIEs.list.array, ricSubsModReqd->protocolIEs.list.size);
5809 if(!ricSubsModReqd->protocolIEs.list.array)
5811 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed at line %d", __func__, __LINE__);
5815 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
5817 DU_ALLOC(ricSubsModReqd->protocolIEs.list.array[ieIdx], sizeof(RICsubscriptionModificationRequired_IEs_t));
5818 if(!ricSubsModReqd->protocolIEs.list.array[ieIdx])
5820 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed at line %d", __func__, __LINE__);
5825 /* RIC Request ID */
5827 ricSubsModReqdIe = ricSubsModReqd->protocolIEs.list.array[ieIdx];
5828 ricSubsModReqdIe->id = ProtocolIE_IDE2_id_RICrequestID;
5829 ricSubsModReqdIe->criticality = CriticalityE2_reject;
5830 ricSubsModReqdIe->value.present = RICsubscriptionModificationRequired_IEs__value_PR_RICrequestID;
5831 ricSubsModReqdIe->value.choice.RICrequestID.ricRequestorID = ricSubscription->requestId.requestorId;
5832 ricSubsModReqdIe->value.choice.RICrequestID.ricInstanceID = ricSubscription->requestId.instanceId;
5834 /* RAN Function ID */
5836 ricSubsModReqdIe = ricSubsModReqd->protocolIEs.list.array[ieIdx];
5837 ricSubsModReqdIe->id = ProtocolIE_IDE2_id_RANfunctionID;
5838 ricSubsModReqdIe->criticality = CriticalityE2_reject;
5839 ricSubsModReqdIe->value.present = RICsubscriptionModificationRequired_IEs__value_PR_RANfunctionID;
5840 ricSubsModReqdIe->value.choice.RANfunctionID = ricSubscription->ranFuncId;
5842 /* A RIC Subscription includes RIC subsequent action only for RIC Insert service.
5843 * However, E2SM-KPM supports only RIC Report service.
5844 * Hence there is no subsequent action in RIC subscription that may require modification.
5845 * So commenting the action-modification IEs for the time being
5848 /* RIC Actions Required to be Modified */
5852 ricSubsModReqdIe = ricSubsModReqd->protocolIEs.list.array[ieIdx];
5853 ricSubsModReqdIe->id = ProtocolIE_IDE2_id_RICactionsRequiredToBeModified_List;
5854 ricSubsModReqdIe->criticality = CriticalityE2_reject;
5855 ricSubsModReqdIe->value.present = \
5856 RICsubscriptionModificationRequired_IEs__value_PR_RICactions_RequiredToBeModified_List;
5857 actionToBeModList = &ricSubsModReqdIe->value.choice.RICactions_RequiredToBeModified_List;
5859 if(FillActionReqdToBeModList(actionToBeModList, numActionsMod, ricSubscription) != ROK)
5861 DU_LOG("\nERROR --> E2AP : %s: Failed to fill actions required to be modified list", __func__);
5867 /* RIC Actions Required to be removed */
5871 ricSubsModReqdIe = ricSubsModReqd->protocolIEs.list.array[ieIdx];
5872 ricSubsModReqdIe->id = ProtocolIE_IDE2_id_RICactionsRequiredToBeRemoved_List;
5873 ricSubsModReqdIe->criticality = CriticalityE2_reject;
5874 ricSubsModReqdIe->value.present = \
5875 RICsubscriptionModificationRequired_IEs__value_PR_RICactions_RequiredToBeRemoved_List;
5876 actionToBeRmvList = &ricSubsModReqdIe->value.choice.RICactions_RequiredToBeRemoved_List;
5878 if(FillActionReqdToBeRmvList(actionToBeRmvList, numActionsRmv, ricSubscription) != ROK)
5880 DU_LOG("\nERROR --> E2AP : %s: Failed to fill actions required to be removed list", __func__);
5888 /*******************************************************************
5890 * @brief Builds and Send RIC Subscription Modification Required
5895 * Function : BuildAndSendRicSubsModRequired
5897 * Functionality: Builds and Send RIC Subscription Modification
5900 * @param RIC Subscription DB
5901 * @return ROK - success
5904 ******************************************************************/
5905 uint8_t BuildAndSendRicSubsModRequired(RicSubscription *ricSubscription)
5907 uint8_t ret = RFAILED;
5908 E2AP_PDU_t *e2apMsg = NULLP;
5909 RICsubscriptionModificationRequired_t *ricSubsModReqd = NULLP;
5910 asn_enc_rval_t encRetVal; /* Encoder return value */
5912 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Modification Required \n");
5915 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
5916 if(e2apMsg == NULLP)
5918 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed at line %d", __func__, __LINE__);
5922 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
5923 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
5924 if(e2apMsg->choice.initiatingMessage == NULLP)
5926 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed at line %d", __func__, __LINE__);
5929 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
5930 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICsubscriptionModificationRequired;
5931 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICsubscriptionModificationRequired;
5933 ricSubsModReqd = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionModificationRequired;
5935 if(FillRicSubsModRequired(ricSubsModReqd, ricSubscription) != ROK)
5937 DU_LOG("\nERROR --> E2AP : %s: Failed to fill RIC Subscription Modification Required IEs", __func__);
5942 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
5944 memset(encBuf, 0, ENC_BUF_MAX_LEN);
5946 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
5947 if(encRetVal.encoded == ENCODE_FAIL)
5949 DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Modifiction Required structure (at %s)\n",\
5950 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
5955 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Subscription Modification Required \n");
5956 #ifdef DEBUG_ASN_PRINT
5957 for(int i=0; i< encBufSize; i++)
5959 printf("%x",encBuf[i]);
5963 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
5965 DU_LOG("\nERROR --> E2AP : Sending RIC Subscription Modification Required failed");
5972 /* Free RIC Subscription modification required */
5973 FreeRicSubsModRequired(e2apMsg);
5977 /*******************************************************************
5979 * @brief Free APER decoding of RIC Subscription Modification Confirm
5983 * Function : freeAperDecodingOfRicSubsModConfirm
5985 * Functionality: Free APER decoding of RIC Subscription
5986 * Modification Confirm
5988 * @param E2AP Message PDU
5991 ******************************************************************/
5992 void freeAperDecodingOfRicSubsModConfirm(E2AP_PDU_t *e2apMsg)
5994 uint8_t ieIdx = 0, arrIdx=0;
5995 RICsubscriptionModificationConfirm_t *ricSubsModCfm = NULLP;
5996 RICsubscriptionModificationConfirm_IEs_t *ricSubsModCfmIe = NULLP;
5997 RICactions_ConfirmedForModification_List_t *modCfmList = NULLP;
5998 RICactions_RefusedToBeModified_List_t *modRefusedList = NULLP;
5999 RICactions_ConfirmedForRemoval_List_t *rmvCfmList = NULLP;
6000 RICactions_RefusedToBeRemoved_List_t *rmvFailList = NULLP;
6002 if(e2apMsg && e2apMsg->choice.successfulOutcome)
6004 ricSubsModCfm = &e2apMsg->choice.successfulOutcome->value.choice.RICsubscriptionModificationConfirm;
6005 if(ricSubsModCfm->protocolIEs.list.array)
6007 for(ieIdx = 0; ieIdx < ricSubsModCfm->protocolIEs.list.count; ieIdx++)
6009 if(ricSubsModCfm->protocolIEs.list.array[ieIdx])
6011 ricSubsModCfmIe = ricSubsModCfm->protocolIEs.list.array[ieIdx];
6012 switch(ricSubsModCfmIe->id)
6014 case ProtocolIE_IDE2_id_RICactionsConfirmedForModification_List:
6016 modCfmList = &ricSubsModCfmIe->value.choice.RICactions_ConfirmedForModification_List;
6017 if(modCfmList->list.array)
6019 for(arrIdx = 0; arrIdx < modCfmList->list.count; arrIdx++)
6021 if(modCfmList->list.array[arrIdx])
6022 free(modCfmList->list.array[arrIdx]);
6024 free(modCfmList->list.array);
6029 case ProtocolIE_IDE2_id_RICactionsRefusedToBeModified_List:
6031 modRefusedList = &ricSubsModCfmIe->value.choice.RICactions_RefusedToBeModified_List;
6032 if(modRefusedList->list.array)
6034 for(arrIdx = 0; arrIdx < modRefusedList->list.count; arrIdx++)
6036 if(modRefusedList->list.array[arrIdx])
6037 free(modRefusedList->list.array[arrIdx]);
6039 free(modRefusedList->list.array);
6044 case ProtocolIE_IDE2_id_RICactionsConfirmedForRemoval_List:
6046 rmvCfmList = &ricSubsModCfmIe->value.choice.RICactions_ConfirmedForRemoval_List;
6047 if(rmvCfmList->list.array)
6049 for(arrIdx = 0; arrIdx < rmvCfmList->list.count; arrIdx++)
6051 if(rmvCfmList->list.array[arrIdx])
6052 free(rmvCfmList->list.array[arrIdx]);
6054 free(rmvCfmList->list.array);
6059 case ProtocolIE_IDE2_id_RICactionsRefusedToBeRemoved_List:
6061 rmvFailList = &ricSubsModCfmIe->value.choice.RICactions_RefusedToBeRemoved_List;
6062 if(rmvFailList->list.array)
6064 for(arrIdx = 0; arrIdx < rmvFailList->list.count; arrIdx++)
6066 if(rmvFailList->list.array[arrIdx])
6067 free(rmvFailList->list.array[arrIdx]);
6069 free(rmvFailList->list.array);
6078 free(ricSubsModCfmIe);
6081 free(ricSubsModCfm->protocolIEs.list.array);
6086 /*******************************************************************
6088 * @brief Process RIC Subscription Modification Confirm Message
6092 * Function : procRicSubscriptionModificationConfirm
6094 * Functionality: Process RIC Subscription Modification Confirm
6095 * Message received from RIC.
6097 * @param E2AP Message PDU
6100 ******************************************************************/
6101 void procRicSubscriptionModificationConfirm(E2AP_PDU_t *e2apMsg)
6103 uint8_t actionId = 0, ieIdx = 0, arrIdx = 0;
6104 uint16_t ranFuncId = 0;
6105 bool procFailure = false;
6106 RicRequestId ricReqId;
6107 RanFunction *ranFuncDb = NULLP;
6108 CmLList *ricSubsNode = NULLP;
6109 RicSubscription *ricSubsDb = NULLP;
6110 ActionInfo *actionDb = NULLP;
6112 RICsubscriptionModificationConfirm_t *ricSubsModCfm = NULLP;
6113 RICsubscriptionModificationConfirm_IEs_t *ricSubsModCfmIe = NULLP;
6115 RICactions_ConfirmedForModification_List_t *modCfmList = NULLP;
6116 RICaction_ConfirmedForModification_ItemIEs_t *modCfmListItem = NULLP;
6118 RICactions_RefusedToBeModified_List_t *modRefusedList = NULLP;
6119 RICaction_RefusedToBeModified_ItemIEs_t *modRefusedListItem = NULLP;
6121 RICactions_ConfirmedForRemoval_List_t *rmvCfmList = NULLP;
6122 RICaction_ConfirmedForRemoval_ItemIEs_t *rmvCfmListItem = NULLP;
6124 RICactions_RefusedToBeRemoved_List_t *rmvFailList = NULLP;
6125 RICaction_RefusedToBeRemoved_ItemIEs_t *rmvFailListItem = NULLP;
6127 DU_LOG("\nINFO --> E2AP : %s: Received RIC Subscription Modification Confirm", __func__);
6132 DU_LOG("\nERROR --> E2AP : %s: E2AP Message is NULL", __func__);
6136 if(!e2apMsg->choice.successfulOutcome)
6138 DU_LOG("\nERROR --> E2AP : %s: Successful Outcome in E2AP message is NULL", __func__);
6142 ricSubsModCfm = &e2apMsg->choice.successfulOutcome->value.choice.RICsubscriptionModificationConfirm;
6143 if(!ricSubsModCfm->protocolIEs.list.array)
6145 DU_LOG("\nERROR --> E2AP : %s: Array conatining E2AP message IEs is null", __func__);
6149 for(ieIdx = 0; ieIdx < ricSubsModCfm->protocolIEs.list.count; ieIdx++)
6151 if(!ricSubsModCfm->protocolIEs.list.array[ieIdx])
6153 DU_LOG("\nERROR --> E2AP : %s: IE at index [%d] in E2AP message IEs list is null", __func__, ieIdx);
6157 ricSubsModCfmIe = ricSubsModCfm->protocolIEs.list.array[ieIdx];
6158 switch(ricSubsModCfmIe->id)
6160 case ProtocolIE_IDE2_id_RICrequestID:
6162 memset(&ricReqId, 0, sizeof(RicRequestId));
6163 ricReqId.requestorId = ricSubsModCfmIe->value.choice.RICrequestID.ricRequestorID;
6164 ricReqId.instanceId = ricSubsModCfmIe->value.choice.RICrequestID.ricInstanceID;
6168 case ProtocolIE_IDE2_id_RANfunctionID:
6170 ranFuncId = ricSubsModCfmIe->value.choice.RANfunctionID;
6171 ranFuncDb = fetchRanFuncFromRanFuncId(ranFuncId);
6174 DU_LOG("\nERROR --> E2AP : %s: RAN Function ID [%d] not found", __func__, ranFuncId);
6179 ricSubsDb = fetchSubsInfoFromRicReqId(ricReqId, ranFuncDb, &ricSubsNode);
6182 DU_LOG("\nERROR --> E2AP : %s: RIC Subscription not found for Requestor_ID [%d] Instance_ID [%d]",\
6183 __func__, ricReqId.requestorId, ricReqId.instanceId);
6191 /* A RIC Subscription includes RIC subsequent action only for RIC Insert service.
6192 * However, E2SM-KPM supports only RIC Report service.
6193 * Hence there is no subsequent action in RIC subscription that may require modification.
6194 * So commenting the action-modification IEs for the time being
6197 case ProtocolIE_IDE2_id_RICactionsConfirmedForModification_List:
6199 modCfmList = &ricSubsModCfmIe->value.choice.RICactions_ConfirmedForModification_List;
6200 for(arrIdx = 0; arrIdx < modCfmList->list.count; arrIdx++)
6202 modCfmListItem = (RICaction_ConfirmedForModification_ItemIEs_t *)modCfmList->list.array[arrIdx];
6203 actionId = modCfmListItem->value.choice.RICaction_ConfirmedForModification_Item.ricActionID;
6205 actionDb = fetchActionInfoFromActionId(actionId, ricSubsDb);
6208 DU_LOG("\nERROR --> E2AP : %s: Action ID [%d] not found", __func__, actionId);
6212 actionDb->action = CONFIG_UNKNOWN;
6213 /* Further handling can be added here in future once the
6214 * use case of this procedure is identified */
6221 case ProtocolIE_IDE2_id_RICactionsRefusedToBeModified_List:
6223 modRefusedList = &ricSubsModCfmIe->value.choice.RICactions_RefusedToBeModified_List;
6224 for(arrIdx = 0; arrIdx < modRefusedList->list.count; arrIdx++)
6226 modRefusedListItem = (RICaction_RefusedToBeModified_ItemIEs_t *)modRefusedList->list.array[arrIdx];
6227 actionId = modRefusedListItem->value.choice.RICaction_RefusedToBeModified_Item.ricActionID;
6228 actionDb = fetchActionInfoFromActionId(actionId, ricSubsDb);
6231 DU_LOG("\nERROR --> E2AP : %s: Action ID [%d] not found", __func__, actionId);
6235 /* Spec doesnt mention if in case of failure, DU should retry for modify action
6236 * Hence, chaging the action from CONFIG_MOD to CONFIG_UNKNOWN
6238 actionDb->action = CONFIG_UNKNOWN;
6246 case ProtocolIE_IDE2_id_RICactionsConfirmedForRemoval_List:
6248 rmvCfmList = &ricSubsModCfmIe->value.choice.RICactions_ConfirmedForRemoval_List;
6249 for(arrIdx = 0; arrIdx < rmvCfmList->list.count; arrIdx++)
6251 rmvCfmListItem = (RICaction_ConfirmedForRemoval_ItemIEs_t *)rmvCfmList->list.array[arrIdx];
6252 actionId = rmvCfmListItem->value.choice.RICaction_ConfirmedForRemoval_Item.ricActionID;
6253 actionDb = fetchActionInfoFromActionId(actionId, ricSubsDb);
6256 DU_LOG("\nERROR --> E2AP : %s: Action ID [%d] not found", __func__, actionId);
6260 memset(actionDb, 0, sizeof(ActionInfo));
6261 actionDb->actionId = -1;
6262 ricSubsDb->numOfActions--;
6263 /* Further handling can include :
6264 * Deletion of this action from all DU layers
6272 case ProtocolIE_IDE2_id_RICactionsRefusedToBeRemoved_List:
6274 rmvFailList = &ricSubsModCfmIe->value.choice.RICactions_RefusedToBeRemoved_List;
6275 for(arrIdx = 0; arrIdx < rmvFailList->list.count; arrIdx++)
6277 rmvFailListItem = (RICaction_RefusedToBeRemoved_ItemIEs_t *)rmvFailList->list.array[arrIdx];
6278 actionId = rmvFailListItem->value.choice.RICaction_RefusedToBeRemoved_Item.ricActionID;
6279 actionDb = fetchActionInfoFromActionId(actionId, ricSubsDb);
6282 DU_LOG("\nERROR --> E2AP : %s: Action ID [%d] not found", __func__, actionId);
6286 actionDb->action = CONFIG_UNKNOWN;
6295 } /* End of switch for Protocol IE Id */
6299 } /* End of for loop for Protocol IE list */
6304 freeAperDecodingOfRicSubsModConfirm(e2apMsg);
6308 /*******************************************************************
6310 * @brief Handles received E2AP message and sends back response
6314 * Function : E2APMsgHdlr
6317 * - Decodes received E2AP control message
6318 * - Prepares response message, encodes and sends to SCTP
6321 * @return ROK - success
6324 * ****************************************************************/
6325 void E2APMsgHdlr(Buffer *mBuf)
6328 char *recvBuf = NULLP;
6330 MsgLen recvBufLen =0;
6331 E2AP_PDU_t *e2apMsg = NULLP;
6332 asn_dec_rval_t rval ={0}; /* Decoder return value */
6333 E2AP_PDU_t e2apasnmsg={0} ;
6335 DU_LOG("\nDEBUG --> E2AP : Received E2AP message buffer");
6336 ODU_PRINT_MSG(mBuf, 0,0);
6338 /* Copy mBuf into char array to decode it */
6339 ODU_GET_MSG_LEN(mBuf, &recvBufLen);
6340 DU_ALLOC(recvBuf, (Size)recvBufLen);
6342 if(recvBuf == NULLP)
6344 DU_LOG("\nERROR --> E2AP : Memory allocation failed");
6347 if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
6349 DU_LOG("\nERROR --> E2AP : Failed while copying %d", copyCnt);
6353 #ifdef DEBUG_ASN_PRINT
6354 printf("\nDEBUG --> E2AP : Received flat buffer to be decoded : ");
6355 for(i=0; i< recvBufLen; i++)
6357 printf("%x",recvBuf[i]);
6361 /* Decoding flat buffer into E2AP messsage */
6362 e2apMsg = &e2apasnmsg;
6363 memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
6365 rval = aper_decode(0, &asn_DEF_E2AP_PDU, (void **)&e2apMsg, recvBuf, recvBufLen, 0, 0);
6366 DU_FREE(recvBuf, (Size)recvBufLen);
6368 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
6370 DU_LOG("\nERROR --> E2AP : ASN decode failed");
6374 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
6376 switch(e2apMsg->present)
6378 case E2AP_PDU_PR_unsuccessfulOutcome:
6380 switch(e2apMsg->choice.unsuccessfulOutcome->value.present)
6382 case UnsuccessfulOutcomeE2__value_PR_E2setupFailure:
6384 procE2SetupFailure(e2apMsg);
6387 case UnsuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateFailure:
6389 procE2NodeConfigUpdateFailure(e2apMsg);
6392 case UnsuccessfulOutcomeE2__value_PR_RICserviceUpdateFailure:
6394 procRicServiceUpdateFailure(e2apMsg);
6399 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_unsuccessfulOutcome [%d]",\
6400 e2apMsg->choice.unsuccessfulOutcome->value.present);
6404 free(e2apMsg->choice.unsuccessfulOutcome);
6407 case E2AP_PDU_PR_successfulOutcome:
6409 switch(e2apMsg->choice.successfulOutcome->value.present)
6411 case SuccessfulOutcomeE2__value_PR_E2setupResponse:
6415 procE2SetupRsp(e2apMsg);
6419 case SuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateAcknowledge:
6421 DU_LOG("\nDEBUG --> E2AP : E2 node Config update ack message recevied");
6424 case SuccessfulOutcomeE2__value_PR_ResetResponseE2:
6426 procResetResponse(e2apMsg);
6429 case SuccessfulOutcomeE2__value_PR_RICserviceUpdateAcknowledge:
6431 procRicServiceUpdateAck(e2apMsg);
6434 case SuccessfulOutcomeE2__value_PR_RICsubscriptionModificationConfirm:
6436 procRicSubscriptionModificationConfirm(e2apMsg);
6442 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_successfulOutcome [%d]",\
6443 e2apMsg->choice.successfulOutcome->value.present);
6446 }/* End of switch(successfulOutcome) */
6447 free(e2apMsg->choice.successfulOutcome);
6451 case E2AP_PDU_PR_initiatingMessage:
6453 switch(e2apMsg->choice.initiatingMessage->value.present)
6455 case InitiatingMessageE2__value_PR_RICsubscriptionRequest:
6457 procRicSubscriptionRequest(e2apMsg);
6460 case InitiatingMessageE2__value_PR_RICserviceQuery:
6462 procRicServiceQuery(e2apMsg);
6465 case InitiatingMessageE2__value_PR_ErrorIndicationE2:
6467 DU_LOG("\nINFO --> E2AP : Error indication received");
6472 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\
6473 e2apMsg->choice.initiatingMessage->value.present);
6476 }/* End of switch(initiatingMessage) */
6477 free(e2apMsg->choice.initiatingMessage);
6482 DU_LOG("\nERROR --> E2AP : Invalid type of e2apMsg->present [%d]",e2apMsg->present);
6487 }/* End of switch(e2apMsg->present) */
6489 } /* End of E2APMsgHdlr */
6491 /**********************************************************************
6493 **********************************************************************/