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 *******************************************************************************/
19 /* This file contains E2AP message handler functions */
20 #include "common_def.h"
21 #include "OCTET_STRING.h"
22 #include "BIT_STRING.h"
23 #include "odu_common_codec.h"
24 #include "ric_stub_sctp.h"
26 #include "ric_e2ap_msg_hdl.h"
27 #include "GlobalE2node-gNB-ID.h"
28 #include "ProtocolIE-FieldE2.h"
29 #include "InitiatingMessageE2.h"
30 #include "SuccessfulOutcomeE2.h"
31 #include "UnsuccessfulOutcomeE2.h"
34 #include "E2nodeComponentInterfaceF1.h"
35 #include "E2SM-KPM-RANfunction-Description.h"
36 #include "RANfunction-Name.h"
37 #include "RIC-EventTriggerStyle-Item.h"
38 #include "RIC-ReportStyle-Item.h"
39 #include "MeasurementInfo-Action-Item.h"
40 #include "MeasurementInfoItem.h"
41 #include "E2SM-KPM-ActionDefinition-Format1.h"
42 #include "E2SM-KPM-ActionDefinition.h"
43 #include "E2SM-KPM-EventTriggerDefinition-Format1.h"
44 #include "E2SM-KPM-EventTriggerDefinition.h"
46 /*******************************************************************
48 * @brief Printing Type and Cause of failure
52 * Function : printE2ErrorCause
54 * Functionality: Printing Type and Cause of failure
56 * @params[in] E2 Cause
59 ******************************************************************/
61 void printE2ErrorCause(CauseE2_t *cause)
63 switch(cause->present)
65 case CauseE2_PR_ricRequest:
67 DU_LOG("Failure_Type [%s] Cause [%ld]", "RIC_Request", cause->choice.ricRequest);
70 case CauseE2_PR_ricService:
72 DU_LOG("Failure_Type [%s] Cause [%ld]", "RIC_Service", cause->choice.ricService);
75 case CauseE2_PR_e2Node:
77 DU_LOG("Failure_Type [%s] Cause [%ld]", "E2_Node", cause->choice.e2Node);
80 case CauseE2_PR_transport:
82 DU_LOG("Failure_Type [%s] Cause [%ld]", "Transport", cause->choice.transport);
85 case CauseE2_PR_protocol:
87 DU_LOG("Failure_Type [%s] Cause [%ld]", "Protocol", cause->choice.protocol);
92 DU_LOG("Failure_Type [%s] Cause [%ld]", "Miscellaneous", cause->choice.misc);
97 DU_LOG("Failure_Type and Cause unknown");
103 /*******************************************************************
105 * @brief fill E2 failure cause
109 * Function : fillE2FailureCause
111 * Functionality: fill E2 failure cause
112 * @return ROK - success
115 ******************************************************************/
117 void fillE2FailureCause(CauseE2_t *cause, CauseE2_PR causePresent, uint8_t reason)
119 cause->present = causePresent;
121 switch(cause->present)
123 case CauseE2_PR_ricRequest:
124 cause->choice.ricRequest = reason;
126 case CauseE2_PR_ricService:
127 cause->choice.ricService = reason;
129 case CauseE2_PR_e2Node:
130 cause->choice.e2Node = reason;
132 case CauseE2_PR_transport:
133 cause->choice.transport = reason;
135 case CauseE2_PR_protocol:
136 cause->choice.protocol = reason;
138 case CauseE2_PR_misc:
139 cause->choice.misc = reason;
142 cause->choice.misc = CauseE2Misc_unspecified;
147 /*******************************************************************
149 * @brief Assigns new transaction id to RIC initiated procedure
153 * Function : assignTransactionId
155 * Functionality: Assigns new transaction id to a RIC initiated
158 * @params[in] Region region
160 * @return ROK - success
163 * ****************************************************************/
165 uint8_t assignTransactionId(DuDb *duDb)
167 uint8_t currTransId = duDb->ricTransIdCounter;
169 /* Update to next valid value */
170 duDb->ricTransIdCounter++;
171 if(duDb->ricTransIdCounter == MAX_NUM_TRANSACTION)
172 duDb->ricTransIdCounter = 0;
177 /*******************************************************************
179 * @brief Sends E2 msg over SCTP
183 * Function : SendE2APMsg
185 * Functionality: Sends E2 msg over SCTP
187 * @params[in] Region region
189 * @return ROK - success
192 * ****************************************************************/
194 uint8_t SendE2APMsg(Region region, Pool pool, uint32_t duId)
198 if(ODU_GET_MSG_BUF(region, pool, &mBuf) == ROK)
200 if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
202 ODU_PRINT_MSG(mBuf, 0,0);
204 if(sctpSend(duId, mBuf) != ROK)
206 DU_LOG("\nERROR --> E2AP : SCTP Send for E2 failed");
207 ODU_PUT_MSG_BUF(mBuf);
213 DU_LOG("\nERROR --> E2AP : ODU_ADD_POST_MSG_MULT failed");
214 ODU_PUT_MSG_BUF(mBuf);
217 ODU_PUT_MSG_BUF(mBuf);
221 DU_LOG("\nERROR --> E2AP : Failed to allocate memory");
228 /*******************************************************************
230 * @brief Deallocate the memory allocated for RemovalRequest msg
234 * Function : FreeRemovalRequest
237 * - freeing the memory allocated for RemovalRequest
239 * @params[in] E2AP_PDU_t *e2apMsg
240 * @return ROK - success
243 * ****************************************************************/
244 void FreeRemovalRequest(E2AP_PDU_t *e2apMsg)
247 E2RemovalRequest_t *removalReq = NULLP;
251 if(e2apMsg->choice.initiatingMessage != NULLP)
253 removalReq = &e2apMsg->choice.initiatingMessage->value.choice.E2RemovalRequest;
254 if(removalReq->protocolIEs.list.array)
256 for(ieIdx = 0; ieIdx < removalReq->protocolIEs.list.count; ieIdx++)
258 RIC_FREE(removalReq->protocolIEs.list.array[ieIdx], sizeof(E2RemovalRequestIEs_t));
260 RIC_FREE(removalReq->protocolIEs.list.array, removalReq->protocolIEs.list.size);
262 RIC_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
264 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
268 /*******************************************************************
270 * @brief Build and send the removal request msg
274 * Function : BuildAndSendRemovalRequest
277 * - Buld and send the removal request msg to E2 node
283 * @return ROK - success
286 * ****************************************************************/
287 uint8_t BuildAndSendRemovalRequest(DuDb *duDb)
289 uint8_t ieIdx = 0, elementCnt = 0, transId = 0;
290 uint8_t ret = RFAILED;
291 E2AP_PDU_t *e2apMsg = NULLP;
292 E2RemovalRequest_t *removalReq = NULLP;
293 asn_enc_rval_t encRetVal; /* Encoder return value */
295 DU_LOG("\nINFO --> E2AP : Building Removal Request\n");
299 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
302 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
306 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
307 RIC_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
308 if(e2apMsg->choice.initiatingMessage == NULLP)
310 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
314 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2removal;
315 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
316 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_E2RemovalRequest;
317 removalReq = &e2apMsg->choice.initiatingMessage->value.choice.E2RemovalRequest;
320 removalReq->protocolIEs.list.count = elementCnt;
321 removalReq->protocolIEs.list.size = elementCnt * sizeof(E2RemovalRequestIEs_t *);
323 RIC_ALLOC(removalReq->protocolIEs.list.array, removalReq->protocolIEs.list.size);
324 if(!removalReq->protocolIEs.list.array)
326 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
330 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
332 RIC_ALLOC(removalReq->protocolIEs.list.array[ieIdx], sizeof(E2RemovalRequestIEs_t));
333 if(!removalReq->protocolIEs.list.array[ieIdx])
335 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
340 /* In case of failure */
341 if(ieIdx < elementCnt)
345 removalReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
346 removalReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
347 removalReq->protocolIEs.list.array[ieIdx]->value.present = E2RemovalRequestIEs__value_PR_TransactionID;
348 transId = assignTransactionId(duDb);
349 removalReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
351 /* Prints the Msg formed */
352 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
354 memset(encBuf, 0, ENC_BUF_MAX_LEN);
356 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
358 if(encRetVal.encoded == ENCODE_FAIL)
360 DU_LOG("\nERROR --> E2AP : Could not encode removal request structure (at %s)\n",\
361 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
366 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for removal request\n");
367 #ifdef DEBUG_ASN_PRINT
368 for(int i=0; i< encBufSize; i++)
370 printf("%x",encBuf[i]);
374 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
376 DU_LOG("\nERROR --> E2AP : Sending removal request failed");
385 /* Free all memory */
386 FreeRemovalRequest(e2apMsg);
390 /*******************************************************************
392 * @brief Fetches RAN Function DB
396 * Function : fetchRanFuncFromRanFuncId
398 * Functionality: Fetches RAN function DB from E2AP DB using
401 * @params[in] RAN Function ID
402 * @return RAN Function DB
403 * NULL, in case of failure
405 * ****************************************************************/
406 RanFunction *fetchRanFuncFromRanFuncId(DuDb *duDb, uint16_t ranFuncId)
408 RanFunction *ranFuncDb = NULLP;
410 /* Fetch RAN Function DB */
411 if(duDb->ranFunction[ranFuncId-1].id == ranFuncId)
413 ranFuncDb = &duDb->ranFunction[ranFuncId-1];
417 DU_LOG("\nERROR --> DU_APP : fetchRanFuncFromRanFuncId: Invalid RAN Function ID[%d]", ranFuncId);
423 /*******************************************************************
425 * @brief Fetch subscripton DB
429 * Function : fetchSubsInfoFromRicReqId
431 * Functionality: Fetches subscription DB from RAN Function DB
432 * using RIC Request ID
434 * @params[in] RIC Request ID
436 * Pointer to RIC Subscription node to be searched
437 * @return RIC Subscription from RAN Function's subcription list
438 * NULL, in case of failure
440 * ****************************************************************/
441 RicSubscription *fetchSubsInfoFromRicReqId(RicRequestId ricReqId, RanFunction *ranFuncDb, CmLList **ricSubscriptionNode)
443 RicSubscription *ricSubscriptionInfo = NULLP;
445 /* Fetch subscription detail in RAN Function DB */
446 CM_LLIST_FIRST_NODE(&ranFuncDb->subscriptionList, *ricSubscriptionNode);
447 while(*ricSubscriptionNode)
449 ricSubscriptionInfo = (RicSubscription *)((*ricSubscriptionNode)->node);
450 if(ricSubscriptionInfo && (ricSubscriptionInfo->requestId.requestorId == ricReqId.requestorId) &&
451 (ricSubscriptionInfo->requestId.instanceId == ricReqId.instanceId))
455 *ricSubscriptionNode = (*ricSubscriptionNode)->next;
456 ricSubscriptionInfo = NULLP;
459 if(!ricSubscriptionInfo)
461 DU_LOG("\nERROR --> E2AP : fetchSubsInfoFromRicReqId: Subscription not found for Requestor ID [%d] \
462 Instance ID [%d] in RAN Function ID [%d]", ricReqId.requestorId, ricReqId.instanceId, ranFuncDb->id);
465 return ricSubscriptionInfo;
468 /*******************************************************************
470 * @brief Fetch Action details
474 * Function : fetchActionInfoFromActionId
476 * Functionality: Fetch action details from RIC subscription DB
479 * @params[in] Action ID
480 * RIC Subscription DB
481 * @return Action Info DB
482 * NULL, in case of failure
484 * ****************************************************************/
485 ActionInfo *fetchActionInfoFromActionId(uint8_t actionId, RicSubscription *ricSubscriptionInfo)
487 ActionInfo *actionInfoDb = NULLP;
488 if(ricSubscriptionInfo->actionSequence[actionId].actionId == actionId)
490 actionInfoDb = &ricSubscriptionInfo->actionSequence[actionId];
494 DU_LOG("\nERROR --> E2AP : fetchActionInfoFromActionId: Action Id [%d] not found in \
495 subscription info [Requestor id : %d] [Instance Id : %d]", actionId,\
496 ricSubscriptionInfo->requestId.requestorId, ricSubscriptionInfo->requestId.instanceId);
502 /******************************************************************
504 * @brief Search E2 node component with the help of interface type
509 * Function : fetchE2NodeComponentInfo
511 * Functionality: Search E2 node component
516 * Pointer to E2 component node to be searched
519 * ****************************************************************/
521 E2NodeComponent *fetchE2NodeComponentInfo(DuDb *duDb, InterfaceType interfaceType,CmLList **e2ComponentNode)
523 E2NodeComponent *e2NodeComponentInfo=NULLP;
525 if(duDb->e2NodeComponent.count)
527 CM_LLIST_FIRST_NODE(&duDb->e2NodeComponent, *e2ComponentNode);
528 while(*e2ComponentNode)
530 e2NodeComponentInfo = (E2NodeComponent*)((*e2ComponentNode)->node);
531 if((e2NodeComponentInfo->interfaceType == interfaceType))
536 *e2ComponentNode = (*e2ComponentNode)->next;
537 e2NodeComponentInfo = NULLP;
540 return e2NodeComponentInfo;
543 /*******************************************************************
545 * @brief update E2 node config list
549 * Function : updateE2NodeConfigList
552 * - update E2 node config list
556 * Configuration which need to update in Database
558 * @return ROK - success
561 * ****************************************************************/
562 uint8_t updateE2NodeConfigList(DuDb **duDb, uint8_t protocolId, E2NodeConfigItem *tmpCfg)
565 E2NodeComponent * e2NodeComponentInfo;
566 bool configFound= false;
570 case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
572 /* Adding the new e2 node component in DB*/
573 RIC_ALLOC(e2NodeComponentInfo, sizeof(E2NodeComponent));
574 e2NodeComponentInfo->interfaceType = tmpCfg->componentInfo.interfaceType;
575 e2NodeComponentInfo->componentId =tmpCfg->componentInfo.componentId;
576 RIC_ALLOC(node, sizeof(CmLList));
579 node->node = (PTR) e2NodeComponentInfo;
580 cmLListAdd2Tail(&(*duDb)->e2NodeComponent, node);
585 DU_LOG("\nERROR --> E2AP : Memory allocation failed for e2NodeComponentList node");
586 RIC_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
591 case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdate:
593 /* searching for information in a database */
594 e2NodeComponentInfo = fetchE2NodeComponentInfo((*duDb),tmpCfg->componentInfo.interfaceType, &node);
595 if(!e2NodeComponentInfo)
597 DU_LOG("\nERROR --> E2AP : Failed to find the e2 component node");
600 /* If the node is present then update the value */
601 e2NodeComponentInfo->componentId =tmpCfg->componentInfo.componentId;
605 case ProtocolIE_IDE2_id_E2nodeComponentConfigRemoval:
607 /* searching for information in a database */
608 e2NodeComponentInfo = fetchE2NodeComponentInfo((*duDb),tmpCfg->componentInfo.interfaceType, &node);
609 if(!e2NodeComponentInfo)
611 DU_LOG("\nERROR --> E2AP : Failed to find the e2 component node");
614 /* Delete the node from the list */
615 e2NodeComponentInfo->componentId = tmpCfg->componentInfo.componentId;
616 cmLListDelFrm(&(*duDb)->e2NodeComponent, node);
617 RIC_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
623 /* If the configuration update was successful, then mark the isSuccessful as
624 * true; otherwise, mark it as false. */
625 if(configFound == true)
626 tmpCfg->isSuccessful = true;
628 tmpCfg->isSuccessful = false;
633 /*******************************************************************
635 * @brief Handling the E2 node configuration depending on the add,
636 * update, or remove configuration type
640 * Function : handleE2NodeComponentAction
643 * - Handling the E2 node configuration depending on the add,
644 * update, or remove configuration type
647 * Pointer to e2NodeCfg which has info
649 * E2NodeConfigItem to be filled
651 * @return ROK - success
654 * ****************************************************************/
656 uint8_t handleE2NodeComponentAction(DuDb *duDb, PTR e2NodeCfg, uint8_t protocolId, E2NodeConfigItem *storeCfg)
658 uint8_t configFound = ROK;
659 E2NodeConfigItem tmpCfg;
660 E2nodeComponentID_t componentId;
661 E2nodeComponentInterfaceType_t interface;
662 E2nodeComponentConfigAddition_Item_t *addCfg=NULL;
663 E2nodeComponentConfigUpdate_Item_t *updateCfg=NULL;
664 E2nodeComponentConfigRemoval_Item_t *removeCfg=NULL;
666 /* fetching the interface and component id information from the e2NodeCfg */
667 memset(storeCfg, 0, sizeof(E2NodeConfigItem));
668 storeCfg->isSuccessful=false;
669 memset(&tmpCfg, 0, sizeof(E2NodeConfigItem));
673 case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
675 addCfg = (E2nodeComponentConfigAddition_Item_t *)e2NodeCfg;
676 interface = addCfg->e2nodeComponentInterfaceType;
677 componentId = addCfg->e2nodeComponentID;
680 case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdate:
682 updateCfg = (E2nodeComponentConfigUpdate_Item_t *)e2NodeCfg;
683 interface = updateCfg->e2nodeComponentInterfaceType;
684 componentId = updateCfg->e2nodeComponentID;
687 case ProtocolIE_IDE2_id_E2nodeComponentConfigRemoval:
689 removeCfg = (E2nodeComponentConfigRemoval_Item_t*)e2NodeCfg;
690 interface = removeCfg->e2nodeComponentInterfaceType;
691 componentId = removeCfg->e2nodeComponentID;
696 /* Storing the information in temporary structure */
697 tmpCfg.componentInfo.interfaceType = interface;
699 switch(componentId.present)
701 case E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1:
703 if(componentId.choice.e2nodeComponentInterfaceTypeF1)
705 tmpCfg.componentInfo.componentId = componentId.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[0];
715 /* Updating the database configuration */
716 configFound = updateE2NodeConfigList(&duDb, protocolId, &tmpCfg);
718 memcpy(storeCfg, &tmpCfg,sizeof(E2NodeConfigItem));
723 /*******************************************************************
725 * @brief deallocate memory allocated in E2 Node Config Update Failure
729 * Function : FreeE2ConfigUpdateFail
731 * Functionality: deallocate memory allocated in E2 Node Config Update Failure
733 * @params[in] E2AP_PDU_t *e2apMsg
736 * ****************************************************************/
738 void FreeE2ConfigUpdateFail(E2AP_PDU_t *e2apMsg)
741 E2nodeConfigurationUpdateFailure_t *e2NodeCfgUpdFail=NULL;
745 if(e2apMsg->choice.unsuccessfulOutcome)
747 e2NodeCfgUpdFail = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2nodeConfigurationUpdateFailure;
748 if(e2NodeCfgUpdFail->protocolIEs.list.array)
750 for(arrIdx=0; arrIdx<e2NodeCfgUpdFail->protocolIEs.list.count; arrIdx++)
752 RIC_FREE(e2NodeCfgUpdFail->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdateFailure_IEs_t));
754 RIC_FREE(e2NodeCfgUpdFail->protocolIEs.list.array, e2NodeCfgUpdFail->protocolIEs.list.size);
756 RIC_FREE(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
758 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
762 /*******************************************************************
764 * @brief Buld and send the E2 Node Config Update failure
768 * Function : BuildAndSendE2NodeConfigUpdateFailure
771 * - Buld and send the E2 Node Config Update failure
772 * @return ROK - success
775 * ****************************************************************/
777 uint8_t BuildAndSendE2NodeConfigUpdateFailure(uint32_t duId, uint8_t transId, uint8_t causeInfo, uint8_t causeReason)
779 E2AP_PDU_t *e2apMsg = NULL;
780 asn_enc_rval_t encRetVal;
782 uint8_t elementCnt=0;
783 bool memAllocFailed = false;
784 E2nodeConfigurationUpdateFailure_t *e2NodeCfgUpdateFail=NULL;
786 DU_LOG("\nINFO --> E2AP : Building E2 Node Config Update failure\n");
789 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
792 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
795 e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome;
796 RIC_ALLOC(e2apMsg->choice.unsuccessfulOutcome , sizeof(struct UnsuccessfulOutcomeE2));
797 if(e2apMsg->choice.unsuccessfulOutcome == NULLP)
799 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
803 e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
804 e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject;
805 e2apMsg->choice.unsuccessfulOutcome->value.present = UnsuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateFailure;
806 e2NodeCfgUpdateFail = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2nodeConfigurationUpdateFailure;
809 e2NodeCfgUpdateFail->protocolIEs.list.count = elementCnt;
810 e2NodeCfgUpdateFail->protocolIEs.list.size = elementCnt * sizeof(struct E2nodeConfigurationUpdateFailure_IEs *);
812 RIC_ALLOC(e2NodeCfgUpdateFail->protocolIEs.list.array, e2NodeCfgUpdateFail->protocolIEs.list.size);
813 if(e2NodeCfgUpdateFail->protocolIEs.list.array == NULLP)
815 DU_LOG("\nERROR --> E2AP : Memory allocation for E2 node config update failure array failed");
819 for(arrIdx=0; arrIdx<elementCnt; arrIdx++)
821 RIC_ALLOC(e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx], sizeof(struct E2nodeConfigurationUpdateFailure_IEs));
822 if(e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx] == NULLP)
824 DU_LOG("\nERROR --> E2AP : Memory allocation for E2 node config update failure IEs failed");
825 memAllocFailed = true;
830 if(memAllocFailed == true)
837 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
838 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
839 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_TransactionID;
840 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
843 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_CauseE2;
844 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
845 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_CauseE2;
846 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.choice.CauseE2.present = causeInfo;
847 if(causeInfo == CauseE2_PR_e2Node)
848 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.choice.CauseE2.choice.e2Node = causeReason;
850 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.choice.CauseE2.choice.misc = causeReason;
853 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TimeToWaitE2;
854 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_ignore;
855 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_TimeToWaitE2;
856 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2 = TimeToWaitE2_v5s;
858 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
859 memset(encBuf, 0, ENC_BUF_MAX_LEN);
861 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
863 /* Check encode results */
864 if(encRetVal.encoded == ENCODE_FAIL)
866 DU_LOG("\nERROR --> E2AP : Could not encode E2 Node Config Update failure structure (at %s)\n",\
867 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
872 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Node Config Update Failure\n");
873 for(int i=0; i< encBufSize; i++)
875 DU_LOG("%x",encBuf[i]);
879 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
881 DU_LOG("\nERROR --> E2AP : Sending E2 Node Config Update Failure failed");
887 FreeE2ConfigUpdateFail(e2apMsg);
891 /*******************************************************************
893 * @brief process the E2 node configuration update
897 * Function : ProcE2NodeConfigUpdate
899 * Functionality: Process E2 node configuration update
903 * Pointer to E2nodeConfigurationUpdate
906 ******************************************************************/
908 void ProcE2NodeConfigUpdate(uint32_t duId, E2nodeConfigurationUpdate_t *e2NodeConfigUpdate)
911 E2NodeConfigList tmpE2NodeList;
913 uint8_t ieIdx = 0, duIdx = 0, elementCnt=0, transId = 0;
914 E2nodeComponentConfigAddition_List_t *e2NodeAddList=NULL;
915 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItemIe=NULL;
916 E2nodeComponentConfigAddition_Item_t *e2NodeAddItem=NULL;
917 E2nodeComponentConfigUpdate_List_t *e2NodeUpdateList=NULLP;
918 E2nodeComponentConfigUpdate_ItemIEs_t *e2NodeUpdateItemIe=NULLP;
919 E2nodeComponentConfigUpdate_Item_t *e2NodeUpdateItem =NULLP;
920 E2nodeComponentConfigRemoval_List_t *e2NodeRemoveList=NULL;
921 E2nodeComponentConfigRemoval_ItemIEs_t *e2NodeRemovalItemIe=NULL;
922 E2nodeComponentConfigRemoval_Item_t *e2NodeRemovalItem=NULL;
924 SEARCH_DU_DB(duIdx, duId, duDb);
927 DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
931 memset(&tmpE2NodeList, 0, sizeof(E2NodeConfigList));
932 if(!e2NodeConfigUpdate)
934 DU_LOG("\nERROR --> E2AP : e2NodeConfigUpdate pointer is null");
937 if(!e2NodeConfigUpdate->protocolIEs.list.array)
939 DU_LOG("\nERROR --> E2AP : e2NodeConfigUpdate array pointer is null");
943 elementCnt = e2NodeConfigUpdate->protocolIEs.list.count;
944 for(ieIdx=0; ieIdx < e2NodeConfigUpdate->protocolIEs.list.count; ieIdx++)
946 if(!e2NodeConfigUpdate->protocolIEs.list.array[ieIdx])
948 DU_LOG("\nERROR --> E2AP : e2NodeConfigUpdate array idx %d pointer is null",arrIdx);
952 switch(e2NodeConfigUpdate->protocolIEs.list.array[ieIdx]->id)
954 case ProtocolIE_IDE2_id_TransactionID:
956 transId = e2NodeConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
957 if(transId < 0 || transId > 255)
959 DU_LOG("\nERROR --> E2AP : Received invalid transId %d",transId);
965 case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
967 e2NodeAddList =&e2NodeConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.E2nodeComponentConfigAddition_List;
968 if(e2NodeAddList->list.array)
970 for(arrIdx = 0; arrIdx< e2NodeAddList->list.count; arrIdx++)
972 e2NodeAddItemIe = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[arrIdx];
973 e2NodeAddItem = &e2NodeAddItemIe->value.choice.E2nodeComponentConfigAddition_Item;
974 /* Storing the E2 node information in DB */
975 if(handleE2NodeComponentAction(duDb, (PTR)e2NodeAddItem, ProtocolIE_IDE2_id_E2nodeComponentConfigAddition,\
976 &tmpE2NodeList.addedE2Node[tmpE2NodeList.addedE2NodeCount++]) != ROK)
978 DU_LOG("\nERROR --> E2AP : Processing of E2 node component idx %d failed",arrIdx);
985 case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdate:
987 e2NodeUpdateList =&e2NodeConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.E2nodeComponentConfigUpdate_List;
988 if(e2NodeUpdateList->list.array)
990 for(arrIdx = 0; arrIdx< e2NodeUpdateList->list.count; arrIdx++)
992 e2NodeUpdateItemIe = (E2nodeComponentConfigUpdate_ItemIEs_t*) e2NodeUpdateList->list.array[arrIdx];
993 e2NodeUpdateItem = &e2NodeUpdateItemIe->value.choice.E2nodeComponentConfigUpdate_Item;
995 /* Updating the E2 node information in DB */
996 if(handleE2NodeComponentAction(duDb, (PTR)e2NodeUpdateItem, ProtocolIE_IDE2_id_E2nodeComponentConfigUpdate,\
997 &tmpE2NodeList.updatedE2Node[tmpE2NodeList.updatedE2NodeCount++]) != ROK)
999 DU_LOG("\nERROR --> E2AP : Processing of E2 node component idx %d failed",arrIdx);
1006 case ProtocolIE_IDE2_id_E2nodeComponentConfigRemoval:
1008 e2NodeRemoveList = &e2NodeConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.E2nodeComponentConfigRemoval_List;
1009 if(e2NodeRemoveList->list.array)
1011 for(arrIdx = 0; arrIdx< e2NodeRemoveList->list.count; arrIdx++)
1013 e2NodeRemovalItemIe = (E2nodeComponentConfigRemoval_ItemIEs_t *) e2NodeRemoveList->list.array[arrIdx];
1014 e2NodeRemovalItem = &e2NodeRemovalItemIe->value.choice.E2nodeComponentConfigRemoval_Item;
1016 /* Removing the E2 node information in DB */
1017 if(handleE2NodeComponentAction(duDb, (PTR)e2NodeRemovalItem, ProtocolIE_IDE2_id_E2nodeComponentConfigRemoval,\
1018 &tmpE2NodeList.removedE2Node[tmpE2NodeList.removedE2NodeCount++]) != ROK)
1020 DU_LOG("\nERROR --> E2AP : Processing of E2 node component idx %d failed",arrIdx);
1033 /* If all of the IEs are processed successfully, we will send an e2 node
1034 * config update ack message.
1035 * else we will be sendinf e2 node config update failure */
1036 if(elementCnt == ieIdx)
1038 if(BuildAndSendE2NodeConfigUpdateAck(duDb, transId, &tmpE2NodeList) !=ROK)
1040 DU_LOG("\nERROR --> E2AP : Failed to build and send E2 node config ack");
1046 if(BuildAndSendE2NodeConfigUpdateFailure(duDb->duId, transId, CauseE2_PR_misc, CauseE2Misc_unspecified) != ROK)
1048 DU_LOG("\nERROR --> E2AP : Failed to build and send E2 node config Failure");
1053 /*******************************************************************
1055 * @brief Builds Global RIC Id Params
1059 * Function : BuildGlobalRicId
1061 * Functionality: Building the Plmn and ric id
1063 * @params[in] GlobalRIC_ID_t *ricId
1064 * @return ROK - success
1067 * ****************************************************************/
1069 uint8_t BuildGlobalRicId(GlobalRIC_ID_t *ricId)
1072 uint8_t byteSize = 3;
1076 ricId->pLMN_Identity.size = byteSize * sizeof(uint8_t);
1077 RIC_ALLOC(ricId->pLMN_Identity.buf, ricId->pLMN_Identity.size);
1078 buildPlmnId(ricCb.ricCfgParams.plmn , ricId->pLMN_Identity.buf);
1080 ricId->ric_ID.size = byteSize * sizeof(uint8_t);
1081 RIC_ALLOC(ricId->ric_ID.buf, ricId->ric_ID.size);
1082 fillBitString(&ricId->ric_ID, unused, byteSize, ricVal);
1087 /*******************************************************************
1089 * @brief deallocate the memory allocated in E2SetupResponse
1093 * Function : FreeE2SetupRsp
1095 * Functionality: deallocate the memory allocated in E2SetupResponse
1097 * @params[in] E2AP_PDU_t *e2apMsg
1100 * ****************************************************************/
1101 void FreeE2SetupRsp(E2AP_PDU_t *e2apMsg)
1103 uint8_t arrIdx = 0, e2NodeConfigIdx=0, ranFuncIdx=0;
1104 RANfunctionsID_List_t *ranFuncAcceptedList=NULL;
1105 E2setupResponse_t *e2SetupRsp=NULL;
1106 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItemIe=NULL;
1107 E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAdditionAckList=NULL;
1108 E2nodeComponentInterfaceF1_t *f1InterfaceInfo=NULL;
1112 if(e2apMsg->choice.successfulOutcome)
1114 e2SetupRsp = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
1115 if(e2SetupRsp->protocolIEs.list.array)
1117 for(arrIdx=0; arrIdx<e2SetupRsp->protocolIEs.list.count; arrIdx++)
1119 switch(e2SetupRsp->protocolIEs.list.array[arrIdx]->id)
1121 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
1123 ranFuncAcceptedList= &e2SetupRsp->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
1124 if(ranFuncAcceptedList->list.array)
1126 for(ranFuncIdx=0;ranFuncIdx<ranFuncAcceptedList->list.count; ranFuncIdx++)
1128 if(ranFuncAcceptedList->list.array[ranFuncIdx])
1130 RIC_FREE(ranFuncAcceptedList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
1133 RIC_FREE(ranFuncAcceptedList->list.array, ranFuncAcceptedList->list.size);
1137 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
1139 e2NodeConfigAdditionAckList =&e2SetupRsp->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
1140 if(e2NodeConfigAdditionAckList->list.count)
1142 for(e2NodeConfigIdx=0; e2NodeConfigIdx<e2NodeConfigAdditionAckList->list.count; e2NodeConfigIdx++)
1144 e2NodeAddAckItemIe = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAdditionAckList->list.array[e2NodeConfigIdx];
1145 if(e2NodeAddAckItemIe)
1147 f1InterfaceInfo = e2NodeAddAckItemIe->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1;
1150 RIC_FREE(f1InterfaceInfo->gNB_DU_ID.buf, f1InterfaceInfo->gNB_DU_ID.size);
1151 RIC_FREE(f1InterfaceInfo, sizeof(E2nodeComponentInterfaceF1_t));
1153 RIC_FREE(e2NodeAddAckItemIe, sizeof(E2nodeComponentConfigAdditionAck_ItemIEs_t));
1156 RIC_FREE(e2NodeConfigAdditionAckList->list.array, e2NodeConfigAdditionAckList->list.size);
1161 RIC_FREE(e2SetupRsp->protocolIEs.list.array[arrIdx], sizeof(E2setupResponseIEs_t));
1163 RIC_FREE(e2SetupRsp->protocolIEs.list.array, e2SetupRsp->protocolIEs.list.size);
1165 RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
1167 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
1171 /*******************************************************************
1173 * @brief fill e2 node configuration for ack msg
1177 * Function : fillE2NodeConfigAck
1180 * - fill e2 node configuration for ack msg
1183 * Pointer to e2NodeCfg to be filled
1185 * E2 Node Component information
1186 * Is successful or failure response
1187 * @return ROK - success
1190 * ****************************************************************/
1192 uint8_t fillE2NodeConfigAck(PTR e2NodeCfg, uint8_t procedureCode, E2NodeComponent *componentInfo, bool isSuccessful)
1194 E2nodeComponentID_t *e2nodeComponentID=NULLP;
1195 E2nodeComponentInterfaceType_t *e2nodeComponentInterfaceType=NULLP;
1196 E2nodeComponentConfigurationAck_t *e2nodeComponentConfigurationAck=NULLP;
1197 E2nodeComponentConfigRemovalAck_Item_t *removalAckItem=NULLP;
1198 E2nodeComponentConfigUpdateAck_Item_t *updateAckItem=NULLP;
1199 E2nodeComponentConfigAdditionAck_Item_t *additionAckItem=NULLP;
1201 /* filling the interface type, component id, configuration ack based on the
1202 * e2 node configuration add, update, delete type */
1203 switch(procedureCode)
1205 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
1207 additionAckItem = (E2nodeComponentConfigAdditionAck_Item_t *)e2NodeCfg;
1208 e2nodeComponentInterfaceType = &((E2nodeComponentConfigAdditionAck_Item_t *)e2NodeCfg)->e2nodeComponentInterfaceType;
1209 e2nodeComponentID = &additionAckItem->e2nodeComponentID;
1210 e2nodeComponentConfigurationAck = &additionAckItem->e2nodeComponentConfigurationAck;
1213 case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdateAck:
1215 updateAckItem = (E2nodeComponentConfigUpdateAck_Item_t*) e2NodeCfg;
1216 e2nodeComponentInterfaceType = &updateAckItem->e2nodeComponentInterfaceType;
1217 e2nodeComponentID = &updateAckItem->e2nodeComponentID;
1218 e2nodeComponentConfigurationAck = &updateAckItem->e2nodeComponentConfigurationAck;
1221 case ProtocolIE_IDE2_id_E2nodeComponentConfigRemovalAck:
1223 removalAckItem= (E2nodeComponentConfigRemovalAck_Item_t*)e2NodeCfg;
1224 e2nodeComponentInterfaceType = &removalAckItem->e2nodeComponentInterfaceType;
1225 e2nodeComponentID = &removalAckItem->e2nodeComponentID;
1226 e2nodeComponentConfigurationAck = &removalAckItem->e2nodeComponentConfigurationAck;
1231 /* >E2 Node Component interface type */
1232 if(componentInfo->interfaceType>=NG && componentInfo->interfaceType<=X2)
1234 *e2nodeComponentInterfaceType = componentInfo->interfaceType;
1238 DU_LOG("\nERROR --> E2AP: Received an invalid interface value %d",componentInfo->interfaceType);
1242 if(*e2nodeComponentInterfaceType == E2nodeComponentInterfaceType_f1)
1244 /* >E2 Node Component ID */
1245 e2nodeComponentID->present = E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1;
1246 RIC_ALLOC(e2nodeComponentID->choice.e2nodeComponentInterfaceTypeF1, sizeof(E2nodeComponentInterfaceF1_t));
1247 if(e2nodeComponentID->choice.e2nodeComponentInterfaceTypeF1 == NULLP)
1249 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigUpdateAck %d",__LINE__);
1252 e2nodeComponentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size = sizeof(uint8_t);
1253 RIC_ALLOC(e2nodeComponentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf, e2nodeComponentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
1255 if(e2nodeComponentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf == NULLP)
1257 DU_LOG("\nERROR -->list. E2AP: Memory allocation failed for BuildE2nodeComponentConfigUpdateAck %d",__LINE__);
1260 e2nodeComponentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[0] = componentInfo->componentId;
1265 /* >E2 Node Component Configuration Acknowledge*/
1266 e2nodeComponentConfigurationAck->updateOutcome = E2nodeComponentConfigurationAck__updateOutcome_success;
1270 /* >E2 Node Component Configuration Acknowledge*/
1271 e2nodeComponentConfigurationAck->updateOutcome = E2nodeComponentConfigurationAck__updateOutcome_failure;
1272 RIC_ALLOC(e2nodeComponentConfigurationAck->failureCauseE2, sizeof(struct CauseE2));
1273 if(e2nodeComponentConfigurationAck->failureCauseE2)
1275 fillE2FailureCause(e2nodeComponentConfigurationAck->failureCauseE2, CauseE2_PR_e2Node, CauseE2node_e2node_component_unknown);
1279 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigUpdateAck %d",__LINE__);
1286 /*******************************************************************
1288 * @brief Build E2node Component config addition ack list
1292 * Function : BuildE2nodeComponentConfigAdditionAck
1294 * Functionality: Build E2node Component config addition ack list
1297 * E2nodeComponentConfigAdditionAck_List to be filled
1298 * Count of e2 node to be added
1299 * list of e2 node cfg to be added
1301 * @return ROK - success
1303 * ****************************************************************/
1305 uint8_t BuildE2nodeComponentConfigAdditionAck(E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAdditionAckList, \
1306 uint16_t addedE2NodeCount, E2NodeConfigItem *addedE2Node)
1308 E2NodeComponent *e2NodeComponentInfo=NULLP;
1309 CmLList *node=NULLP;
1310 uint16_t arrIdx = 0;
1311 E2nodeComponentConfigAdditionAck_Item_t *e2NodeAddAckItem=NULLP;
1312 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItemIe=NULLP;
1314 e2NodeConfigAdditionAckList->list.count = addedE2NodeCount;
1316 e2NodeConfigAdditionAckList->list.size = e2NodeConfigAdditionAckList->list.count * sizeof(E2nodeComponentConfigAdditionAck_ItemIEs_t*);
1317 RIC_ALLOC(e2NodeConfigAdditionAckList->list.array, e2NodeConfigAdditionAckList->list.size);
1318 if(e2NodeConfigAdditionAckList->list.array == NULLP)
1320 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigAdditionAck %d",__LINE__);
1324 for(arrIdx = 0; arrIdx< e2NodeConfigAdditionAckList->list.count; arrIdx++)
1326 RIC_ALLOC(e2NodeConfigAdditionAckList->list.array[arrIdx], sizeof(E2nodeComponentConfigAdditionAck_ItemIEs_t));
1327 if(e2NodeConfigAdditionAckList->list.array[arrIdx] == NULLP)
1329 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigAdditionAck %d",__LINE__);
1332 e2NodeAddAckItemIe = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAdditionAckList->list.array[arrIdx];
1333 e2NodeAddAckItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck_Item;
1334 e2NodeAddAckItemIe->criticality = CriticalityE2_reject;
1335 e2NodeAddAckItemIe->value.present = E2nodeComponentConfigAdditionAck_ItemIEs__value_PR_E2nodeComponentConfigAdditionAck_Item;
1336 e2NodeAddAckItem = &e2NodeAddAckItemIe->value.choice.E2nodeComponentConfigAdditionAck_Item;
1338 /* Filling the e2 node config addition ack item */
1339 fillE2NodeConfigAck((PTR)&e2NodeAddAckItemIe->value.choice.E2nodeComponentConfigAdditionAck_Item, ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck,\
1340 &addedE2Node[arrIdx].componentInfo, addedE2Node[arrIdx].isSuccessful);
1345 /*******************************************************************
1347 * @brief Build RAN function accepted list
1351 * Function : BuildRanFunctionAcceptedList
1353 * Functionality: Build RAN function accepted list
1354 * ->For ProcedureCodeE2_id_E2setup or ProcedureCodeE2_id_RICserviceQuery
1355 * we add all the RAN Function list which is present in RIC database.
1356 * ->For any other procedures, we just fill the RAN functions whose ID
1357 * is present in the recvList
1361 * Count of ran functions to be accepted in the list
1362 * Received list of RAN functions
1366 * @return ROK - success
1368 * ****************************************************************/
1370 uint8_t BuildRanFunctionAcceptedList(DuDb *duDb, uint8_t count, RanFunction *ranFunAcceptedList, RANfunctionsID_List_t *ranFuncAcceptedList, uint8_t procedureCode)
1372 uint16_t ranFuncIdx = 0;
1373 RANfunctionID_ItemIEs_t *ranFuncAcceptedItemIe=NULL;
1375 /* For ProcedureCodeE2_id_E2setup and ProcedureCodeE2_id_RICserviceQuery,
1376 * the number of RAN function list items is equal to the number of
1377 * ran function entries stored in the database.
1378 * For any other procedure, the RAN function list count is equal
1379 * to the count of ran functions obtained from the function's caller */
1381 if((procedureCode == ProcedureCodeE2_id_RICserviceQuery)||(procedureCode == ProcedureCodeE2_id_E2setup))
1382 ranFuncAcceptedList->list.count = duDb->numOfRanFunction;
1384 ranFuncAcceptedList->list.count = count;
1386 ranFuncAcceptedList->list.size = ranFuncAcceptedList->list.count*sizeof(RANfunctionID_ItemIEs_t*);
1387 RIC_ALLOC(ranFuncAcceptedList->list.array, ranFuncAcceptedList->list.size);
1388 if(ranFuncAcceptedList->list.array)
1390 for(ranFuncIdx = 0; ranFuncIdx< ranFuncAcceptedList->list.count; ranFuncIdx++)
1392 RIC_ALLOC(ranFuncAcceptedList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
1393 if(ranFuncAcceptedList->list.array[ranFuncIdx] == NULLP)
1395 DU_LOG("\nERROR --> E2AP : Memory allocation for RAN function added list array item");
1398 ranFuncAcceptedItemIe = (RANfunctionID_ItemIEs_t*)ranFuncAcceptedList->list.array[ranFuncIdx];
1399 ranFuncAcceptedItemIe->id = ProtocolIE_IDE2_id_RANfunctionID_Item;
1400 ranFuncAcceptedItemIe->criticality= CriticalityE2_ignore;
1401 ranFuncAcceptedItemIe->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item;
1402 if((procedureCode == ProcedureCodeE2_id_RICserviceQuery)||(procedureCode == ProcedureCodeE2_id_E2setup))
1404 /* filling the RAN function information with the help of DuDb */
1405 ranFuncAcceptedItemIe->value.choice.RANfunctionID_Item.ranFunctionID = duDb->ranFunction[ranFuncIdx].id;
1406 ranFuncAcceptedItemIe->value.choice.RANfunctionID_Item.ranFunctionRevision= duDb->ranFunction[ranFuncIdx].revisionCounter;
1410 /* filling the the RAN function information with the help received list of RAN functions */
1411 ranFuncAcceptedItemIe->value.choice.RANfunctionID_Item.ranFunctionID = ranFunAcceptedList[ranFuncIdx].id;
1412 ranFuncAcceptedItemIe->value.choice.RANfunctionID_Item.ranFunctionRevision= ranFunAcceptedList[ranFuncIdx].revisionCounter;
1418 DU_LOG("\nERROR --> E2AP : Memory allocation for RAN function added list array");
1424 /*******************************************************************
1426 * @brief Builds and sends the E2SetupResponse
1430 * Function : BuildAndSendE2SetupRsp
1432 * Functionality: Builds and sends the E2SetupResponse
1437 * List of E2node cofniguration which needs to be send
1439 * @return ROK - success
1442 * ****************************************************************/
1444 uint8_t BuildAndSendE2SetupRsp(DuDb *duDb, uint8_t transId, E2NodeConfigList e2NodeList)
1446 E2AP_PDU_t *e2apMsg = NULL;
1447 E2setupResponse_t *e2SetupRsp;
1448 asn_enc_rval_t encRetVal;
1451 bool memAllocFailed = false;
1453 DU_LOG("\nINFO --> E2AP : Building E2 Setup Response\n");
1456 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
1457 if(e2apMsg == NULLP)
1459 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1462 e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
1463 RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
1464 if(e2apMsg->choice.successfulOutcome == NULLP)
1466 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1470 e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_E2setup;
1471 e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
1472 e2apMsg->choice.successfulOutcome->value.present = \
1473 SuccessfulOutcomeE2__value_PR_E2setupResponse;
1474 e2SetupRsp = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
1477 /* Fill Accepted RAN function IE If Ran function information is stored in databse */
1478 if(duDb->numOfRanFunction)
1481 e2SetupRsp->protocolIEs.list.count = elementCnt;
1482 e2SetupRsp->protocolIEs.list.size = elementCnt * sizeof(E2setupResponseIEs_t*);
1484 RIC_ALLOC(e2SetupRsp->protocolIEs.list.array, e2SetupRsp->protocolIEs.list.size);
1485 if(e2SetupRsp->protocolIEs.list.array == NULLP)
1487 DU_LOG("\nERROR --> E2AP : Memory allocation for E2ResponseIEs failed");
1491 for(idx=0; idx<elementCnt; idx++)
1493 RIC_ALLOC(e2SetupRsp->protocolIEs.list.array[idx], sizeof(E2setupResponseIEs_t));
1494 if(e2SetupRsp->protocolIEs.list.array[idx] == NULLP)
1496 DU_LOG("\nERROR --> E2AP : Memory allocation for E2ResponseIEs failed");
1497 memAllocFailed = true;
1502 if(memAllocFailed == true)
1504 DU_LOG("\nERROR --> E2AP : Memory allocation for E2ResponseIEs failed");
1509 e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_TransactionID;
1510 e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1511 e2SetupRsp->protocolIEs.list.array[idx]->value.present = E2setupResponseIEs__value_PR_TransactionID;
1512 e2SetupRsp->protocolIEs.list.array[idx]->value.choice.TransactionID = transId;
1516 e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_GlobalRIC_ID;
1517 e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1518 e2SetupRsp->protocolIEs.list.array[idx]->value.present = E2setupResponseIEs__value_PR_GlobalRIC_ID;
1520 if(BuildGlobalRicId(&(e2SetupRsp->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID))!=ROK)
1522 DU_LOG("\nERROR --> E2AP : Failed to build Global Ric Id");
1526 if(duDb->numOfRanFunction)
1528 /* Accepted RAN function Id */
1530 e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionsAccepted;
1531 e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1532 e2SetupRsp->protocolIEs.list.array[idx]->value.present = E2setupResponseIEs__value_PR_RANfunctionsID_List;
1533 if(BuildRanFunctionAcceptedList(duDb, 0, NULL, &e2SetupRsp->protocolIEs.list.array[idx]->value.choice.RANfunctionsID_List, ProcedureCodeE2_id_E2setup)!=ROK)
1535 DU_LOG("\nERROR --> E2AP : Failed to build Ran function added list");
1540 /* E2 Node Component Configuration Addition Acknowledge List*/
1542 e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck;
1543 e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1544 e2SetupRsp->protocolIEs.list.array[idx]->value.present = \
1545 E2setupResponseIEs__value_PR_E2nodeComponentConfigAdditionAck_List;
1546 if(BuildE2nodeComponentConfigAdditionAck(&e2SetupRsp->protocolIEs.list.array[idx]->\
1547 value.choice.E2nodeComponentConfigAdditionAck_List, e2NodeList.addedE2NodeCount, e2NodeList.addedE2Node) != ROK)
1549 DU_LOG("\nERROR --> E2AP : Failed to build E2Node Component config addition ack list");
1553 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1554 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1556 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
1558 /* Check encode results */
1559 if(encRetVal.encoded == ENCODE_FAIL)
1561 DU_LOG("\nERROR --> E2AP : Could not encode E2SetupResponse structure (at %s)\n",\
1562 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1567 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupResponse\n");
1568 for(int i=0; i< encBufSize; i++)
1570 DU_LOG("%x",encBuf[i]);
1574 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
1576 DU_LOG("\nERROR --> E2AP : Sending E2 Setup Response failed");
1582 FreeE2SetupRsp(e2apMsg);
1583 BuildAndSendRicSubscriptionReq(duDb);
1587 /*******************************************************************
1589 * @brief Free RIC Subscription Details
1593 * Function : FreeRicSubsDetails
1595 * Functionality: Free the RIC Subscription Details
1597 * @params[in] RICsubscriptionDetails_t *subsDetails
1600 * ****************************************************************/
1601 void FreeRicSubsDetails(RICsubscriptionDetails_t *subsDetails)
1603 uint8_t elementIdx = 0;
1604 RICaction_ToBeSetup_ItemIEs_t *actionItem = NULLP;
1606 RIC_FREE(subsDetails->ricEventTriggerDefinition.buf, subsDetails->ricEventTriggerDefinition.size);
1608 if(subsDetails->ricAction_ToBeSetup_List.list.array)
1610 for(elementIdx = 0; elementIdx < subsDetails->ricAction_ToBeSetup_List.list.count; elementIdx++)
1612 if(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx])
1614 actionItem = (RICaction_ToBeSetup_ItemIEs_t *)subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx];
1615 if(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition)
1617 RIC_FREE(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->buf, \
1618 actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->size);
1619 RIC_FREE(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition, sizeof(RICactionDefinition_t));
1621 RIC_FREE(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx], sizeof(RICaction_ToBeSetup_ItemIEs_t))
1624 RIC_FREE(subsDetails->ricAction_ToBeSetup_List.list.array, subsDetails->ricAction_ToBeSetup_List.list.size);
1628 /*******************************************************************
1630 * @brief Free RIC Subscription Request
1634 * Function : FreeRicSubscriptionReq
1636 * Functionality : Free RIC Subscription Request
1638 * @return ROK - success
1641 ******************************************************************/
1642 void FreeRicSubscriptionReq(E2AP_PDU_t *e2apRicMsg)
1645 RICsubscriptionRequest_t *ricSubscriptionReq;
1649 if(e2apRicMsg->choice.initiatingMessage)
1651 ricSubscriptionReq = &e2apRicMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
1652 if(ricSubscriptionReq->protocolIEs.list.array)
1654 for(idx=0; idx < ricSubscriptionReq->protocolIEs.list.count; idx++)
1656 switch(ricSubscriptionReq->protocolIEs.list.array[idx]->id)
1658 case ProtocolIE_IDE2_id_RICsubscriptionDetails:
1660 FreeRicSubsDetails(&(ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails));
1664 RIC_FREE(ricSubscriptionReq->protocolIEs.list.array[idx], sizeof(RICsubscriptionRequest_IEs_t));
1666 RIC_FREE(ricSubscriptionReq->protocolIEs.list.array, ricSubscriptionReq->protocolIEs.list.size);
1668 RIC_FREE(e2apRicMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1670 RIC_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
1674 /*******************************************************************
1676 * @brief Builds Ric Request Id
1680 * Function : BuildNewRicRequestId
1682 * Functionality: Assign new Ric Request ID
1684 * @params[in] RIC request ID to be sent
1685 * RIC request ID stored in DB
1686 * @return ROK - success
1689 * ****************************************************************/
1691 uint8_t BuildNewRicRequestId(RICrequestID_t *ricReqId, RicRequestId *reqIdDb)
1693 static uint16_t requestorId = 0;
1694 static uint16_t instanceId = 0;
1696 if(ricReqId != NULLP)
1698 ricReqId->ricRequestorID = ++requestorId;
1699 ricReqId->ricInstanceID = ++instanceId;
1701 reqIdDb->requestorId = ricReqId->ricRequestorID;
1702 reqIdDb->instanceId = ricReqId->ricInstanceID;
1707 /*******************************************************************
1709 * @brief Free RIC Action Definition
1713 * Function : FreeRicActionDefinition
1715 * Functionality: Free RIC Action Definition
1717 * @params[in] E2SM-KPM Action definition
1720 * ****************************************************************/
1721 void FreeRicActionDefinition(E2SM_KPM_ActionDefinition_t actionDef)
1723 uint8_t elementIdx = 0;
1724 E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
1725 MeasurementInfoItem_t *measItem = NULLP;
1727 switch(actionDef.actionDefinition_formats.present)
1729 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1:
1731 if(actionDef.actionDefinition_formats.choice.actionDefinition_Format1)
1733 actionFormat1 = actionDef.actionDefinition_formats.choice.actionDefinition_Format1;
1734 if(actionFormat1->measInfoList.list.array)
1736 for(elementIdx = 0; elementIdx < actionFormat1->measInfoList.list.count; elementIdx++)
1738 if(actionFormat1->measInfoList.list.array[elementIdx])
1740 measItem = actionFormat1->measInfoList.list.array[elementIdx];
1741 switch(measItem->measType.present)
1743 case MeasurementType_PR_NOTHING:
1744 case MeasurementType_PR_measID:
1746 case MeasurementType_PR_measName:
1748 RIC_FREE(measItem->measType.choice.measName.buf, measItem->measType.choice.measName.size)
1752 RIC_FREE(measItem, sizeof(MeasurementInfoItem_t));
1755 RIC_FREE(actionFormat1->measInfoList.list.array, actionFormat1->measInfoList.list.size);
1757 RIC_FREE(actionFormat1, sizeof(E2SM_KPM_ActionDefinition_Format1_t));
1762 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format2:
1763 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format3:
1764 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format4:
1765 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format5:
1766 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_NOTHING:
1771 /*******************************************************************
1773 * @brief Fill RIC Action Definition
1777 * Function : fillRicActionDef
1779 * Functionality: Fill RIC Action Definition
1781 * @params[in] RIC Action definition
1785 * ****************************************************************/
1786 uint8_t fillRicActionDef(RICactionDefinition_t *ricActionDef)
1788 uint8_t ret = RFAILED;
1789 asn_enc_rval_t encRetVal;
1790 uint8_t elementCnt = 0, elementIdx = 0;
1791 char *measurementTypeName[] = {"RRU.PrbTotDl", "RRU.PrbTotUl"};
1792 E2SM_KPM_ActionDefinition_t actionDef;
1793 E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
1794 MeasurementInfoItem_t *measItem = NULLP;
1798 /* Fill E2SM-KPM Action Definition Format 1 */
1800 /* RIC Stype Type */
1801 actionDef.ric_Style_Type = RIC_STYLE_TYPE;
1803 /* RIC Action Definition Format 1 */
1804 actionDef.actionDefinition_formats.present = \
1805 E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1;
1807 RIC_ALLOC(actionDef.actionDefinition_formats.choice.actionDefinition_Format1, \
1808 sizeof(E2SM_KPM_ActionDefinition_Format1_t));
1809 if(actionDef.actionDefinition_formats.choice.actionDefinition_Format1 == NULLP)
1811 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1814 actionFormat1 = actionDef.actionDefinition_formats.choice.actionDefinition_Format1;
1816 /* Measurement Info List */
1818 actionFormat1->measInfoList.list.count = elementCnt;
1819 actionFormat1->measInfoList.list.size = elementCnt * sizeof(MeasurementInfoItem_t *);
1820 RIC_ALLOC(actionFormat1->measInfoList.list.array, actionFormat1->measInfoList.list.size);
1821 if(actionFormat1->measInfoList.list.array == NULL)
1823 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1827 for(elementIdx = 0; elementIdx < elementCnt; elementIdx++)
1829 RIC_ALLOC(actionFormat1->measInfoList.list.array[elementIdx], sizeof(MeasurementInfoItem_t));
1830 if(actionFormat1->measInfoList.list.array[elementIdx] == NULLP)
1832 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1836 measItem = actionFormat1->measInfoList.list.array[elementIdx];
1837 measItem->measType.present = MeasurementType_PR_measName;
1839 measItem->measType.choice.measName.size = strlen(measurementTypeName[elementIdx]);
1840 RIC_ALLOC(measItem->measType.choice.measName.buf, measItem->measType.choice.measName.size);
1841 if(measItem->measType.choice.measName.buf == NULLP)
1843 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1846 memcpy(measItem->measType.choice.measName.buf, measurementTypeName[elementIdx], measItem->measType.choice.measName.size);
1848 if(elementIdx < elementCnt)
1851 /* Granularity Period */
1852 actionFormat1->granulPeriod = RIC_ACTION_GRANULARITY_PERIOD; /* In ms */
1854 /* Prints the Msg formed */
1855 xer_fprint(stdout, &asn_DEF_E2SM_KPM_ActionDefinition, &actionDef);
1857 /* Encode E2SM-KPM RIC Action Definition */
1858 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1860 encRetVal = aper_encode(&asn_DEF_E2SM_KPM_ActionDefinition, 0, &actionDef, PrepFinalEncBuf, encBuf);
1861 if(encRetVal.encoded == ENCODE_FAIL)
1863 DU_LOG("\nERROR --> E2AP : Could not encode E2SM-KPM action definition structure (at %s)\n",\
1864 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1868 /* Copty encoded E2SM-KPM RIC action definition to E2AP octet string buffer */
1869 ricActionDef->size = encBufSize;
1870 RIC_ALLOC(ricActionDef->buf, encBufSize);
1871 if(ricActionDef->buf == NULLP)
1873 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1876 memcpy(ricActionDef->buf, encBuf, encBufSize);
1882 FreeRicActionDefinition(actionDef);
1886 /*******************************************************************
1888 * @brief Fills RIC Action To Be Setup Item
1892 * Function : fillActionToBeSetup
1894 * Functionality: Fill the RIC Action To Be Setup Ite,
1895 * RIC subscription DB
1897 * @params[in] RICaction_ToBeSetup_ItemIEs_t *items
1898 * @return ROK - success
1901 * ****************************************************************/
1902 uint8_t fillActionToBeSetup(RICaction_ToBeSetup_ItemIEs_t *actionItem, RicSubscription *ricSubsDb)
1904 static uint8_t ricActionId = 0;
1906 if(actionItem == NULLP)
1908 DU_LOG("\nERROR --> E2AP : Failed at [%s] : line [%d]", __func__, __LINE__);
1914 actionItem->id = ProtocolIE_IDE2_id_RICaction_ToBeSetup_Item;
1915 actionItem->criticality = CriticalityE2_ignore;
1916 actionItem->value.present = RICaction_ToBeSetup_ItemIEs__value_PR_RICaction_ToBeSetup_Item;
1919 actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID = ricActionId;
1920 ricSubsDb->actionSequence[ricActionId].actionId = \
1921 actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID;
1924 /* RIC Action Type */
1925 actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionType = RICactionType_report;
1927 /* RIC Action Definition */
1928 RIC_ALLOC(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition, sizeof(RICactionDefinition_t));
1929 if(!actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition)
1931 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1934 if(fillRicActionDef(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition) != ROK)
1936 DU_LOG("\nERROR --> E2AP : Failed at [%s] : line [%d]", __func__, __LINE__);
1940 ricSubsDb->numOfActions++;
1944 memset(&ricSubsDb->actionSequence[ricActionId], 0, sizeof(ActionInfo));
1945 ricSubsDb->actionSequence[ricActionId].actionId = -1;
1949 /*******************************************************************
1951 * @brief Free Event Trigger Definition
1955 * Function : FreeEventTriggerDef
1957 * Functionality: Free Event Trigger Definition
1959 * @params[in] E2SM-KPM Event Trigger Definition
1962 * ****************************************************************/
1963 void FreeEventTriggerDef(E2SM_KPM_EventTriggerDefinition_t *eventTiggerDef)
1967 switch(eventTiggerDef->eventDefinition_formats.present)
1969 case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING:
1971 case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_eventDefinition_Format1:
1972 RIC_FREE(eventTiggerDef->eventDefinition_formats.choice.eventDefinition_Format1, \
1973 sizeof(E2SM_KPM_EventTriggerDefinition_Format1_t));
1979 /*******************************************************************
1981 * @brief Fill Event Trigger Definition
1985 * Function : fillEventTriggerDef
1987 * Functionality: Fill Event Trigger Definition
1989 * @params[in] RIC Event Trigger Definition
1993 * ****************************************************************/
1994 uint8_t fillEventTriggerDef(RICeventTriggerDefinition_t *ricEventTriggerDef)
1996 uint8_t ret = RFAILED;
1997 asn_enc_rval_t encRetVal;
1998 E2SM_KPM_EventTriggerDefinition_t eventTiggerDef;
2002 /* Fill E2SM-KPM Event Trigger Definition Format 1 */
2003 eventTiggerDef.eventDefinition_formats.present = \
2004 E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_eventDefinition_Format1;
2006 RIC_ALLOC(eventTiggerDef.eventDefinition_formats.choice.eventDefinition_Format1, \
2007 sizeof(E2SM_KPM_EventTriggerDefinition_Format1_t));
2008 if(eventTiggerDef.eventDefinition_formats.choice.eventDefinition_Format1 == NULLP)
2010 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
2014 eventTiggerDef.eventDefinition_formats.choice.eventDefinition_Format1->reportingPeriod = 1000; /* In ms */
2016 /* Prints the Msg formed */
2017 xer_fprint(stdout, &asn_DEF_E2SM_KPM_EventTriggerDefinition, &eventTiggerDef);
2019 /* Encode E2SM-KPM Event Trigger Definition */
2020 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2022 encRetVal = aper_encode(&asn_DEF_E2SM_KPM_EventTriggerDefinition, 0, &eventTiggerDef, PrepFinalEncBuf, encBuf);
2023 if(encRetVal.encoded == ENCODE_FAIL)
2025 DU_LOG("\nERROR --> E2AP : Could not encode E2SM-KPM event trigger definition structure (at %s)\n",\
2026 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2030 /* Copy encoded E2SM-KPM event trigger definition to E2AP octet string buffer */
2031 ricEventTriggerDef->size = encBufSize;
2032 RIC_ALLOC(ricEventTriggerDef->buf, encBufSize);
2033 if(ricEventTriggerDef->buf == NULLP)
2035 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
2038 memcpy(ricEventTriggerDef->buf, encBuf, encBufSize);
2044 FreeEventTriggerDef(&eventTiggerDef);
2048 /*******************************************************************
2050 * @brief builds RIC Subscription Details
2054 * Function : BuildsRicSubsDetails
2056 * Functionality: Builds the RIC Subscription Details
2058 * @params[in] RIC Subscription details to be filled
2059 * RIC subscriotion DB
2060 * @return ROK - success
2063 * ****************************************************************/
2065 uint8_t BuildRicSubsDetails(RICsubscriptionDetails_t *subsDetails, RicSubscription *ricSubsInfo)
2067 uint8_t elementCnt = 0;
2068 uint8_t elementIdx = 0;
2070 if(subsDetails == NULLP)
2072 DU_LOG("\nERROR --> E2AP : Failed at [%s] : line [%d]", __func__, __LINE__);
2078 /* RIC Event Trigger Definition */
2079 if(fillEventTriggerDef(&subsDetails->ricEventTriggerDefinition) != ROK)
2081 DU_LOG("\nERROR --> E2AP : Failed at [%s] : line [%d]", __func__, __LINE__);
2085 /* RIC Actions To Be Setup List */
2087 subsDetails->ricAction_ToBeSetup_List.list.count = elementCnt;
2088 subsDetails->ricAction_ToBeSetup_List.list.size = elementCnt * sizeof(RICaction_ToBeSetup_ItemIEs_t *);
2089 RIC_ALLOC(subsDetails->ricAction_ToBeSetup_List.list.array, subsDetails->ricAction_ToBeSetup_List.list.size);
2090 if(subsDetails->ricAction_ToBeSetup_List.list.array == NULLP)
2092 DU_LOG("\nERROR --> E2AP : Memory allocation for RICactionToBeSetup Items failed");
2096 for(elementIdx = 0; elementIdx < elementCnt; elementIdx++)
2098 RIC_ALLOC(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx], sizeof(RICaction_ToBeSetup_ItemIEs_t));
2099 if(!subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx])
2101 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
2105 if(elementIdx < elementCnt)
2110 if(fillActionToBeSetup((RICaction_ToBeSetup_ItemIEs_t *)subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx], \
2111 ricSubsInfo) != ROK)
2113 DU_LOG("\nERROR --> E2AP : Failed at [%s] : line [%d]", __func__, __LINE__);
2122 /*******************************************************************
2124 * @brief Builds and Send the RicSubscriptionReq
2128 * Function : BuildAndSendRicSubscriptionReq
2130 * Functionality:Fills the RicSubscriptionReq
2132 * @return ROK - success
2135 ******************************************************************/
2136 uint8_t BuildAndSendRicSubscriptionReq(DuDb *duDb)
2138 uint8_t ret = RFAILED;
2139 uint8_t elementCnt = 0;
2141 uint8_t actionIdx = 0;
2142 asn_enc_rval_t encRetVal; /* Encoder return value */
2143 E2AP_PDU_t *e2apRicMsg = NULL;
2144 RICsubscriptionRequest_t *ricSubscriptionReq;
2145 RanFunction *ranFuncDb = &duDb->ranFunction[0];
2146 CmLList *ricSubsNode = NULLP;
2147 RicSubscription *ricSubsInfo = NULLP;
2149 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Request\n");
2151 /* Allocate memory to store RIC subscription info in RIC DB */
2152 RIC_ALLOC(ricSubsInfo, sizeof(RicSubscription));
2155 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
2158 for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
2160 ricSubsInfo->actionSequence[actionIdx].actionId = -1;
2165 RIC_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t));
2166 if(e2apRicMsg == NULLP)
2168 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
2172 e2apRicMsg->present = E2AP_PDU_PR_initiatingMessage;
2173 RIC_ALLOC(e2apRicMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2174 if(e2apRicMsg->choice.initiatingMessage == NULLP)
2176 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
2179 e2apRicMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICsubscription;
2180 e2apRicMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2181 e2apRicMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICsubscriptionRequest;
2183 ricSubscriptionReq = &e2apRicMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
2186 ricSubscriptionReq->protocolIEs.list.count = elementCnt;
2187 ricSubscriptionReq->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionRequest_IEs_t);
2189 /* Initialize the subscription members */
2190 RIC_ALLOC(ricSubscriptionReq->protocolIEs.list.array, ricSubscriptionReq->protocolIEs.list.size);
2191 if(ricSubscriptionReq->protocolIEs.list.array == NULLP)
2193 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
2197 for(idx=0; idx<elementCnt; idx++)
2199 RIC_ALLOC(ricSubscriptionReq->protocolIEs.list.array[idx], sizeof(RICsubscriptionRequest_IEs_t));
2200 if(ricSubscriptionReq->protocolIEs.list.array[idx] == NULLP)
2202 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
2206 if(idx < elementCnt)
2209 /* Filling RIC Request Id */
2211 ricSubscriptionReq->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
2212 ricSubscriptionReq->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2213 ricSubscriptionReq->protocolIEs.list.array[idx]->value.present =\
2214 RICsubscriptionRequest_IEs__value_PR_RICrequestID;
2215 if(BuildNewRicRequestId(&ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICrequestID, \
2216 &ricSubsInfo->requestId) != ROK)
2218 DU_LOG("\nERROR --> E2AP : Failed at [%s] : Line [%d]", __func__, __LINE__);
2223 /* Filling RAN Function Id */
2225 ricSubscriptionReq->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
2226 ricSubscriptionReq->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2227 ricSubscriptionReq->protocolIEs.list.array[idx]->value.present =\
2228 RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
2229 ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RANfunctionID = ranFuncDb->id;
2230 ricSubsInfo->ranFuncId = ranFuncDb->id;
2232 /* Filling RIC Subscription Details */
2234 ricSubscriptionReq->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICsubscriptionDetails;
2235 ricSubscriptionReq->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2236 ricSubscriptionReq->protocolIEs.list.array[idx]->value.present =\
2237 RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails;
2238 if(BuildRicSubsDetails(&(ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails),\
2239 ricSubsInfo) != ROK)
2241 DU_LOG("\nERROR --> E2AP : Failed at [%s] : Line [%d]", __func__, __LINE__);
2245 /* Prints the Msg formed */
2246 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg);
2248 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2250 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apRicMsg, PrepFinalEncBuf, encBuf);
2251 if(encRetVal.encoded == ENCODE_FAIL)
2253 DU_LOG("\nERROR --> E2AP : Could not encode RicSubscriptionRequest structure (at %s)\n",\
2254 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2259 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RicSubscriptionRequest\n");
2260 for(int i=0; i< encBufSize; i++)
2262 DU_LOG("%x",encBuf[i]);
2267 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
2269 DU_LOG("\nERROR --> E2AP : Sending RIC subscription Request failed");
2273 /* Add RIC Subscription Info to RAN Function's RIC Subscription List */
2274 RIC_ALLOC(ricSubsNode , sizeof(CmLList));
2277 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
2280 ricSubsNode->node = (PTR)ricSubsInfo;
2281 cmLListAdd2Tail(&ranFuncDb->subscriptionList, ricSubsNode);
2289 RIC_FREE(ricSubsInfo, sizeof(RicSubscription));
2290 RIC_FREE(ricSubsNode , sizeof(CmLList));
2293 FreeRicSubscriptionReq(e2apRicMsg);
2297 /*******************************************************************
2299 * @brief Process RicSubscriptionResponse
2303 * Function : ProcRicSubscriptionRsp
2305 * Functionality: Processes RicSubscriptionRsp
2307 * @return ROK - void
2309 ******************************************************************/
2311 void ProcRicSubscriptionResponse(uint32_t duId, RICsubscriptionResponse_t *ricSubscriptionRsp)
2313 uint8_t duIdx = 0, ieIdx = 0, notAdmitIdx = 0;
2314 uint8_t ranFuncId = 0, actionId = 0;
2316 bool ricReqIdDecoded = false;
2317 RicRequestId ricReqId;
2318 RanFunction *ranFuncDb = NULLP;
2319 RicSubscription *ricSubs = NULLP;
2320 CmLList *ricSubsNode = NULLP;
2321 ActionInfo *action = NULLP;
2322 RICsubscriptionResponse_IEs_t *ricSubsRspIe = NULLP;
2323 RICaction_NotAdmitted_List_t *notAdmitList = NULLP;
2325 DU_LOG("\nINFO --> E2AP : RIC Subscription Response received");
2328 SEARCH_DU_DB(duIdx, duId, duDb);
2331 DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
2335 memset(&ricReqId, 0, sizeof(RicRequestId));
2336 if(ricSubscriptionRsp)
2338 if(ricSubscriptionRsp->protocolIEs.list.array)
2340 for(ieIdx=0; ieIdx<ricSubscriptionRsp->protocolIEs.list.count; ieIdx++)
2342 if(ricSubscriptionRsp->protocolIEs.list.array[ieIdx])
2344 ricSubsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
2345 switch(ricSubscriptionRsp->protocolIEs.list.array[ieIdx]->id)
2347 case ProtocolIE_IDE2_id_RICrequestID:
2349 ricReqId.requestorId = ricSubsRspIe->value.choice.RICrequestID.ricRequestorID;
2350 ricReqId.instanceId = ricSubsRspIe->value.choice.RICrequestID.ricInstanceID;
2351 ricReqIdDecoded = true;
2354 case ProtocolIE_IDE2_id_RANfunctionID:
2356 ranFuncId = ricSubsRspIe->value.choice.RANfunctionID;
2357 ranFuncDb = fetchRanFuncFromRanFuncId(duDb, ranFuncId);
2360 DU_LOG("\nERROR --> E2AP : ProcRicSubscriptionResponse: RAN Function ID [%d] not found", ranFuncId);
2365 case ProtocolIE_IDE2_id_RICactions_Admitted:
2369 case ProtocolIE_IDE2_id_RICactions_NotAdmitted:
2371 if(!(ranFuncDb && ricReqIdDecoded))
2374 notAdmitList = &ricSubsRspIe->value.choice.RICaction_NotAdmitted_List;
2375 for(notAdmitIdx = 0; notAdmitIdx < notAdmitList->list.count; notAdmitIdx++)
2377 actionId = ((RICaction_NotAdmitted_ItemIEs_t *)(notAdmitList->list.array[notAdmitIdx]))->\
2378 value.choice.RICaction_NotAdmitted_Item.ricActionID;
2380 /* Remove action from RAN Function's subscription list */
2381 ricSubs = fetchSubsInfoFromRicReqId(ricReqId, ranFuncDb, &ricSubsNode);
2384 action = fetchActionInfoFromActionId(actionId, ricSubs);
2387 memset(action, 0, sizeof(ActionInfo));
2388 ricSubs->actionSequence[actionId].actionId = -1;
2389 ricSubs->numOfActions--;
2402 /*******************************************************************
2404 * @brief deallocate the memory allocated in E2SetupFailure
2408 * Function : FreeE2SetupFailure
2410 * Functionality: deallocate the memory allocated in E2SetupFailure
2412 * @params[in] E2AP_PDU_t *e2apMsg
2415 * ****************************************************************/
2416 void FreeE2SetupFailure(E2AP_PDU_t *e2apMsg)
2419 E2setupFailure_t *e2SetupFail;
2423 if(e2apMsg->choice.unsuccessfulOutcome)
2425 e2SetupFail = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure;
2426 if(e2SetupFail->protocolIEs.list.array)
2428 for(arrIdx=0; arrIdx<e2SetupFail->protocolIEs.list.count; arrIdx++)
2430 RIC_FREE(e2SetupFail->protocolIEs.list.array[arrIdx], sizeof(E2setupFailureIEs_t));
2432 RIC_FREE(e2SetupFail->protocolIEs.list.array, e2SetupFail->protocolIEs.list.size);
2434 RIC_FREE(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
2436 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2440 /*******************************************************************
2442 * @brief Buld and send the E2 Setup failure
2446 * Function : BuildAndSendE2SetupFailure
2449 * - Buld and send the E2 Setup failure
2450 * @return ROK - success
2453 * ****************************************************************/
2455 uint8_t BuildAndSendE2SetupFailure(uint32_t duId, uint8_t transId)
2457 uint8_t ret = RFAILED;
2458 E2AP_PDU_t *e2apMsg = NULL;
2459 E2setupFailure_t *e2SetupFailure;
2460 asn_enc_rval_t encRetVal;
2463 bool memAllocFailed = false;
2465 DU_LOG("\nINFO --> E2AP : Building E2 Setup failure\n");
2468 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2469 if(e2apMsg == NULLP)
2471 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2474 e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome;
2475 RIC_ALLOC(e2apMsg->choice.unsuccessfulOutcome , sizeof(struct UnsuccessfulOutcomeE2));
2476 if(e2apMsg->choice.unsuccessfulOutcome == NULLP)
2478 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2482 e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_E2setup;
2483 e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject;
2484 e2apMsg->choice.unsuccessfulOutcome->value.present = UnsuccessfulOutcomeE2__value_PR_E2setupFailure;
2485 e2SetupFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure;
2488 e2SetupFailure->protocolIEs.list.count = elementCnt;
2489 e2SetupFailure->protocolIEs.list.size = elementCnt * sizeof(struct E2setupFailureIEs *);
2491 RIC_ALLOC(e2SetupFailure->protocolIEs.list.array, e2SetupFailure->protocolIEs.list.size);
2492 if(e2SetupFailure->protocolIEs.list.array == NULLP)
2494 DU_LOG("\nERROR --> E2AP : Memory allocation for E2FailureIEs failed");
2498 for(arrIdx=0; arrIdx<elementCnt; arrIdx++)
2500 RIC_ALLOC(e2SetupFailure->protocolIEs.list.array[arrIdx], sizeof(struct E2setupFailureIEs));
2501 if(e2SetupFailure->protocolIEs.list.array[arrIdx] == NULLP)
2503 DU_LOG("\nERROR --> E2AP : Memory allocation for E2FailureIEs failed");
2504 memAllocFailed = true;
2509 if(memAllocFailed == true)
2511 DU_LOG("\nERROR --> E2AP : Memory allocation for E2FailureIEs failed");
2517 e2SetupFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2518 e2SetupFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2519 e2SetupFailure->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_TransactionID;
2520 e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
2523 e2SetupFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_CauseE2;
2524 e2SetupFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2525 e2SetupFailure->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_CauseE2;
2526 e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.CauseE2.present = CauseE2_PR_protocol;
2527 e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.CauseE2.choice.protocol = CauseE2Protocol_unspecified;
2530 e2SetupFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TimeToWaitE2;
2531 e2SetupFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_ignore;
2532 e2SetupFailure->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_TimeToWaitE2;
2533 e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2 = TimeToWaitE2_v5s;
2535 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2536 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2538 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
2540 /* Check encode results */
2541 if(encRetVal.encoded == ENCODE_FAIL)
2543 DU_LOG("\nERROR --> E2AP : Could not encode E2 Setup failure structure (at %s)\n",\
2544 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2549 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Setup Failure\n");
2550 for(int i=0; i< encBufSize; i++)
2552 DU_LOG("%x",encBuf[i]);
2556 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
2558 DU_LOG("\nERROR --> E2AP : Sending E2 Setup Failure failed");
2566 FreeE2SetupFailure(e2apMsg);
2570 /*******************************************************************
2572 * @brief process the e2setup request
2576 * Function : ProcE2SetupReq
2578 * Functionality: process the e2setup request
2582 ******************************************************************/
2584 void ProcE2SetupReq(uint32_t *duId, E2setupRequest_t *e2SetupReq)
2586 uint8_t arrIdx = 0, duIdx = 0, transId =0;
2587 uint16_t ranFuncIdx=0, e2NodeAddListIdx =0;
2588 E2NodeConfigList tmpE2NodeList;
2590 bool ieProcessingFailed = false;
2591 E2nodeComponentConfigAddition_List_t *e2NodeAddList=NULLP;
2592 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem=NULLP;
2593 RANfunction_ItemIEs_t *ranFuncItemIe=NULLP;
2594 RANfunction_Item_t *ranFunItem=NULLP;
2595 RANfunctions_List_t *ranFunctionsList=NULLP;
2597 memset(&tmpE2NodeList, 0, sizeof(E2NodeConfigList));
2600 DU_LOG("\nERROR --> E2AP : e2SetupReq pointer is null");
2603 if(!e2SetupReq->protocolIEs.list.array)
2605 DU_LOG("\nERROR --> E2AP : e2SetupReq array pointer is null");
2609 for(arrIdx=0; arrIdx<e2SetupReq->protocolIEs.list.count; arrIdx++)
2611 if(e2SetupReq->protocolIEs.list.array[arrIdx])
2613 switch(e2SetupReq->protocolIEs.list.array[arrIdx]->id)
2615 case ProtocolIE_IDE2_id_TransactionID:
2617 transId = e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
2620 case ProtocolIE_IDE2_id_GlobalE2node_ID:
2622 if(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.choice.gNB->gNB_DU_ID)
2624 *duId =e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.choice.gNB->gNB_DU_ID->buf[0];
2626 SEARCH_DU_DB(duIdx, *duId, duDb);
2629 duDb = &ricCb.duInfo[ricCb.numDu];
2632 memset(duDb, 0, sizeof(DuDb));
2637 case ProtocolIE_IDE2_id_RANfunctionsAdded:
2639 ranFunctionsList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List;
2641 if(ranFunctionsList->list.array)
2643 for(ranFuncIdx=0;ranFuncIdx<ranFunctionsList->list.count; ranFuncIdx++)
2645 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncIdx];
2646 ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
2647 duDb->ranFunction[ranFunItem->ranFunctionID-1].id = ranFunItem->ranFunctionID;
2648 duDb->ranFunction[ranFunItem->ranFunctionID-1].revisionCounter = ranFunItem->ranFunctionRevision;
2649 cmLListInit(&duDb->ranFunction[ranFunItem->ranFunctionID-1].subscriptionList);
2650 duDb->numOfRanFunction++;
2655 case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
2657 e2NodeAddList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List;
2658 if(e2NodeAddList->list.array)
2660 for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++)
2662 if(e2NodeAddList->list.array[e2NodeAddListIdx])
2664 /* Storing the E2 node information in DB */
2665 e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *)e2NodeAddList->list.array[e2NodeAddListIdx];
2666 if(handleE2NodeComponentAction(duDb, (PTR)&e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item,\
2667 ProtocolIE_IDE2_id_E2nodeComponentConfigAddition, &tmpE2NodeList.addedE2Node[tmpE2NodeList.addedE2NodeCount++]) != ROK)
2669 DU_LOG("\nERROR --> E2AP : Processing of E2 node component idx %d failed",e2NodeAddListIdx);
2683 if(BuildAndSendE2SetupRsp(duDb, transId, tmpE2NodeList) !=ROK)
2685 DU_LOG("\nERROR --> E2AP : Failed to build and send E2 setup response");
2688 /*******************************************************************
2690 * @brief Deallocate the memory allocated for E2 Reset Response
2694 * Function : FreeE2ResetResponse
2697 * - freeing the memory allocated for E2ResetResponse
2699 * @params[in] E2AP_PDU_t *e2apMsg
2700 * @return ROK - success
2703 * ****************************************************************/
2704 void FreeE2ResetResponse(E2AP_PDU_t *e2apMsg)
2707 ResetResponseE2_t *resetResponse =NULLP;
2709 if(e2apMsg != NULLP)
2711 if(e2apMsg->choice.successfulOutcome != NULLP)
2713 resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;
2714 if(resetResponse->protocolIEs.list.array)
2716 for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
2718 if(resetResponse->protocolIEs.list.array[ieIdx])
2720 RIC_FREE(resetResponse->protocolIEs.list.array[ieIdx], sizeof(ResetResponseIEs_t));
2723 RIC_FREE(resetResponse->protocolIEs.list.array, resetResponse->protocolIEs.list.size);
2725 RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
2727 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2731 /*******************************************************************
2733 * @brief Buld and send the Reset Response msg
2737 * Function : BuildAndSendResetResponse
2740 * - Buld and send the Reset Response Message
2745 * @return ROK - success
2748 * ****************************************************************/
2749 uint8_t BuildAndSendResetResponse(uint32_t duId, uint8_t transId)
2751 uint8_t ieIdx = 0, elementCnt = 0;
2752 uint8_t ret = RFAILED;
2753 E2AP_PDU_t *e2apMsg = NULLP;
2754 ResetResponseE2_t *resetResponse=NULL;
2755 asn_enc_rval_t encRetVal; /* Encoder return value */
2757 DU_LOG("\nINFO --> E2AP : Building E2 Reset Response Message\n");
2760 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2761 if(e2apMsg == NULLP)
2763 DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse(): Memory allocation for E2AP-PDU failed");
2766 e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
2768 RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
2769 if(e2apMsg->choice.successfulOutcome == NULLP)
2771 DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse: Memory allocation failed for successfulOutcome");
2775 e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_Reset;
2776 e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
2777 e2apMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_ResetResponseE2;
2778 resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;
2781 resetResponse->protocolIEs.list.count = elementCnt;
2782 resetResponse->protocolIEs.list.size = elementCnt * sizeof(ResetResponseIEs_t *);
2783 RIC_ALLOC(resetResponse->protocolIEs.list.array, resetResponse->protocolIEs.list.size);
2784 if(!resetResponse->protocolIEs.list.array)
2786 DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse: Memory allocation failed for protocol IE array");
2790 for(ieIdx=0; ieIdx < elementCnt; ieIdx++)
2792 RIC_ALLOC(resetResponse->protocolIEs.list.array[ieIdx], sizeof(ResetResponseIEs_t));
2793 if(!resetResponse->protocolIEs.list.array[ieIdx])
2795 DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse: Memory allocation failed for protocol IE array element");
2799 if(ieIdx < elementCnt)
2803 resetResponse->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2804 resetResponse->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
2805 resetResponse->protocolIEs.list.array[ieIdx]->value.present = ResetResponseIEs__value_PR_TransactionID;
2806 resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
2808 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2810 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2812 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
2813 if(encRetVal.encoded == ENCODE_FAIL)
2815 DU_LOG("\nERROR --> E2AP : Could not encode E2 reset response structure (at %s)\n",\
2816 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2821 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Reset Response \n");
2822 for(int i=0; i< encBufSize; i++)
2824 DU_LOG("%x",encBuf[i]);
2829 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
2831 DU_LOG("\nERROR --> E2AP : Failed to send E2 Reset Response");
2839 FreeE2ResetResponse(e2apMsg);
2843 /*******************************************************************
2845 * @brief deallocate the memory allocated in building the
2846 * Service Query message
2850 * Function : FreeRicServiceQuery
2852 * Functionality: deallocate the memory allocated in building
2853 * Ric Service Query message
2855 * @params[in] E2AP_PDU_t *e2apMsg
2858 * ****************************************************************/
2860 void FreeRicServiceQuery(E2AP_PDU_t *e2apMsg)
2862 uint8_t arrIdx = 0, ranFuncIdx=0;
2863 RANfunctionsID_List_t *ranFuncAcceptedList=NULL;
2864 RICserviceQuery_t *ricServiceQuery=NULL;
2868 if(e2apMsg->choice.initiatingMessage)
2870 ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
2871 if(ricServiceQuery->protocolIEs.list.array)
2873 for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
2875 if(ricServiceQuery->protocolIEs.list.array[arrIdx])
2877 switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
2879 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
2881 ranFuncAcceptedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
2882 if(ranFuncAcceptedList->list.array)
2884 for(ranFuncIdx=0;ranFuncIdx<ranFuncAcceptedList->list.count; ranFuncIdx++)
2886 RIC_FREE(ranFuncAcceptedList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
2888 RIC_FREE(ranFuncAcceptedList->list.array, ranFuncAcceptedList->list.size);
2892 case RICserviceQuery_IEs__value_PR_TransactionID:
2897 RIC_FREE(ricServiceQuery->protocolIEs.list.array[arrIdx], sizeof(RICserviceQuery_IEs_t));
2900 RIC_FREE(ricServiceQuery->protocolIEs.list.array, ricServiceQuery->protocolIEs.list.size);
2902 RIC_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2904 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2908 /*******************************************************************
2910 * @brief build and send the ric service Query
2914 * Function : BuildAndSendRicServiceQuery
2916 * Functionality: build and send the ric service Query
2917 * @return ROK - success
2918 * RFAILED - Acknowledge
2920 ******************************************************************/
2922 uint8_t BuildAndSendRicServiceQuery(DuDb *duDb)
2926 uint8_t ret = RFAILED;
2927 bool memAllocFailed = false;
2928 E2AP_PDU_t *e2apMsg = NULL;
2929 asn_enc_rval_t encRetVal;
2930 RICserviceQuery_t *ricServiceQuery;
2932 DU_LOG("\nINFO --> E2AP : Building Ric service Query\n");
2935 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2936 if(e2apMsg == NULLP)
2938 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2941 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2942 RIC_ALLOC(e2apMsg->choice.initiatingMessage , sizeof(struct InitiatingMessageE2));
2943 if(e2apMsg->choice.initiatingMessage == NULLP)
2945 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2949 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICserviceQuery;
2950 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2951 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICserviceQuery;
2952 ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
2955 /* Fill Accepted RAN function IE If Ran function information is stored in databse */
2956 if(duDb->numOfRanFunction)
2959 ricServiceQuery->protocolIEs.list.count = elementCnt;
2960 ricServiceQuery->protocolIEs.list.size = elementCnt * sizeof(RICserviceQuery_IEs_t*);
2962 RIC_ALLOC(ricServiceQuery->protocolIEs.list.array, ricServiceQuery->protocolIEs.list.size);
2963 if(ricServiceQuery->protocolIEs.list.array == NULLP)
2965 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceQueryIEs failed");
2969 for(arrIdx=0; arrIdx<elementCnt; arrIdx++)
2971 RIC_ALLOC(ricServiceQuery->protocolIEs.list.array[arrIdx], sizeof(RICserviceQuery_IEs_t));
2972 if(ricServiceQuery->protocolIEs.list.array[arrIdx] == NULLP)
2974 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceQueryIEs failed");
2975 memAllocFailed = true;
2979 if(memAllocFailed == true)
2981 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceQueryIEs failed");
2987 ricServiceQuery->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2988 ricServiceQuery->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2989 ricServiceQuery->protocolIEs.list.array[arrIdx]->value.present = RICserviceQuery_IEs__value_PR_TransactionID;
2990 ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = assignTransactionId(duDb);
2992 if(duDb->numOfRanFunction)
2994 /* Accepted RAN function Id */
2996 ricServiceQuery->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAccepted;
2997 ricServiceQuery->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2998 ricServiceQuery->protocolIEs.list.array[arrIdx]->value.present = RICserviceQuery_IEs__value_PR_RANfunctionsID_List;
2999 if(BuildRanFunctionAcceptedList(duDb, 0, NULL, &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List, ProcedureCodeE2_id_RICserviceQuery)!=ROK)
3001 DU_LOG("\nERROR --> E2AP : Failed to build Ran function added list");
3006 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3007 memset(encBuf, 0, ENC_BUF_MAX_LEN);
3009 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
3011 /* Check encode results */
3012 if(encRetVal.encoded == ENCODE_FAIL)
3014 DU_LOG("\nERROR --> E2AP : Could not encode RIC service Query structure (at %s)\n",\
3015 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3020 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC service Query\n");
3021 for(int i=0; i< encBufSize; i++)
3023 DU_LOG("%x",encBuf[i]);
3027 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
3029 DU_LOG("\nERROR --> E2AP : Sending of RIC service Query failed");
3036 FreeRicServiceQuery(e2apMsg);
3040 /*******************************************************************
3042 * @brief deallocate the memory allocated in RicServiceUpdateFailure
3046 * Function : FreeRicServiceUpdateFailure
3048 * Functionality: deallocate the memory allocated in RicServiceUpdatefailure
3050 * @params[in] E2AP_PDU_t *e2apMsg
3053 * ****************************************************************/
3055 void FreeRicServiceUpdateFailure(E2AP_PDU_t *e2apMsg)
3058 RICserviceUpdateFailure_t *ricServiceUpdateFailure=NULL;
3062 if(e2apMsg->choice.unsuccessfulOutcome)
3064 ricServiceUpdateFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICserviceUpdateFailure;
3065 if(ricServiceUpdateFailure->protocolIEs.list.array)
3067 for(arrIdx=0; arrIdx<ricServiceUpdateFailure->protocolIEs.list.count; arrIdx++)
3069 RIC_FREE(ricServiceUpdateFailure->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdateFailure_IEs_t));
3071 RIC_FREE(ricServiceUpdateFailure->protocolIEs.list.array, ricServiceUpdateFailure->protocolIEs.list.size);
3073 RIC_FREE(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
3075 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
3079 /*******************************************************************
3081 * @brief build and send the ric service update failure
3085 * Function : BuildAndSendRicServiceUpdateFailure
3087 * Functionality: build and send the ric service update failure
3088 * @return ROK - success
3091 ******************************************************************/
3093 uint8_t BuildAndSendRicServiceUpdateFailure(uint32_t duId, int8_t transId, CauseE2_PR causePresent, uint8_t reason)
3096 E2AP_PDU_t *e2apMsg = NULL;
3097 asn_enc_rval_t encRetVal;
3098 uint8_t ret = RFAILED;
3100 uint8_t elementCnt=0;
3101 RICserviceUpdateFailure_t *ricServiceFailure=NULL;
3103 DU_LOG("\nINFO --> E2AP : Building Ric service update failure\n");
3106 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
3107 if(e2apMsg == NULLP)
3109 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
3112 e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome;
3113 RIC_ALLOC(e2apMsg->choice.unsuccessfulOutcome , sizeof(struct UnsuccessfulOutcomeE2));
3114 if(e2apMsg->choice.unsuccessfulOutcome == NULLP)
3116 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
3120 e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_RICserviceUpdate;
3121 e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject;
3122 e2apMsg->choice.unsuccessfulOutcome->value.present = UnsuccessfulOutcomeE2__value_PR_RICserviceUpdateFailure;
3123 ricServiceFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICserviceUpdateFailure;
3126 ricServiceFailure->protocolIEs.list.count = elementCnt;
3127 ricServiceFailure->protocolIEs.list.size = elementCnt * sizeof(RICserviceUpdateFailure_IEs_t *);
3129 RIC_ALLOC(ricServiceFailure->protocolIEs.list.array, ricServiceFailure->protocolIEs.list.size);
3130 if(ricServiceFailure->protocolIEs.list.array == NULLP)
3132 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceFailureIEs failed");
3136 for(arrIdx=0; arrIdx<elementCnt; arrIdx++)
3138 RIC_ALLOC(ricServiceFailure->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdateFailure_IEs_t));
3139 if(ricServiceFailure->protocolIEs.list.array[arrIdx] == NULLP)
3141 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceFailureIEs failed");
3145 if(arrIdx<elementCnt)
3147 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceFailureIEs failed");
3153 ricServiceFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
3154 ricServiceFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3155 ricServiceFailure->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdateFailure_IEs__value_PR_TransactionID;
3156 ricServiceFailure->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
3159 ricServiceFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_CauseE2;
3160 ricServiceFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3161 ricServiceFailure->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdateFailure_IEs__value_PR_CauseE2;
3162 fillE2FailureCause(&ricServiceFailure->protocolIEs.list.array[arrIdx]->value.choice.CauseE2, causePresent, reason);
3165 ricServiceFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TimeToWaitE2;
3166 ricServiceFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_ignore;
3167 ricServiceFailure->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdateFailure_IEs__value_PR_TimeToWaitE2;
3168 ricServiceFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2 = TimeToWaitE2_v5s;
3170 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3171 memset(encBuf, 0, ENC_BUF_MAX_LEN);
3173 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
3175 /* Check encode results */
3176 if(encRetVal.encoded == ENCODE_FAIL)
3178 DU_LOG("\nERROR --> E2AP : Could not encode RIC service update failure structure (at %s)\n",\
3179 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3184 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC service update Failure\n");
3185 for(int i=0; i< encBufSize; i++)
3187 DU_LOG("%x",encBuf[i]);
3191 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
3193 DU_LOG("\nERROR --> E2AP : Sending RIC service update failed");
3200 FreeRicServiceUpdateFailure(e2apMsg);
3205 /*******************************************************************
3207 * @brief deallocate the memory allocated in RicServiceUpdateAck(
3211 * Function : FreeRicServiceUpdateAck
3213 * Functionality: deallocate the memory allocated in RicServiceUpdateAck
3215 * @params[in] E2AP_PDU_t *e2apMsg
3218 * ****************************************************************/
3220 void FreeRicServiceUpdateAck(E2AP_PDU_t *e2apMsg)
3222 uint8_t arrIdx = 0, ranFuncIdx=0;
3223 RANfunctionsID_List_t *acceptedList=NULL;
3224 RICserviceUpdateAcknowledge_t *ricServiceUpdateAck=NULL;
3225 RANfunctionsIDcause_List_t *rejectedList=NULL;
3229 if(e2apMsg->choice.successfulOutcome)
3231 ricServiceUpdateAck = &e2apMsg->choice.successfulOutcome->value.choice.RICserviceUpdateAcknowledge;
3232 if(ricServiceUpdateAck->protocolIEs.list.array)
3234 for(arrIdx=0; arrIdx<ricServiceUpdateAck->protocolIEs.list.count; arrIdx++)
3236 if(ricServiceUpdateAck->protocolIEs.list.array[arrIdx])
3238 switch(ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->id)
3240 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
3242 acceptedList= &ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
3243 if(acceptedList->list.array)
3245 for(ranFuncIdx=0;ranFuncIdx<acceptedList->list.count; ranFuncIdx++)
3247 RIC_FREE(acceptedList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
3249 RIC_FREE(acceptedList->list.array, acceptedList->list.size);
3254 case ProtocolIE_IDE2_id_RANfunctionsRejected:
3256 rejectedList= &ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsIDcause_List;
3257 if(rejectedList->list.array)
3259 for(ranFuncIdx=0;ranFuncIdx<rejectedList->list.count; ranFuncIdx++)
3261 RIC_FREE(rejectedList->list.array[ranFuncIdx], sizeof(RANfunctionIDcause_ItemIEs_t));
3263 RIC_FREE(rejectedList->list.array, rejectedList->list.size);
3268 RIC_FREE(ricServiceUpdateAck->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdateAcknowledge_IEs_t));
3271 RIC_FREE(ricServiceUpdateAck->protocolIEs.list.array, ricServiceUpdateAck->protocolIEs.list.size);
3273 RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
3275 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
3279 /*******************************************************************
3281 * @brief Build RAN function rejected list
3285 * Function : BuildRanFunctionRejectedList
3287 * Functionality: Build RAN function rejected list
3290 * Count of ran functions to be rejected in the list
3291 * Received list of RAN functions
3293 * @return ROK - success
3295 * ****************************************************************/
3297 uint8_t BuildRanFunctionRejectedList(uint8_t count, RanFunction *ranFunRejectedList, RANfunctionsIDcause_List_t *ranFuncRejectedList)
3299 uint8_t ranFuncIdx = 0;
3300 RANfunctionIDcause_ItemIEs_t *ranFuncRejectedItemIe=NULL;
3302 ranFuncRejectedList->list.count = count;
3304 ranFuncRejectedList->list.size = ranFuncRejectedList->list.count*sizeof(RANfunctionIDcause_ItemIEs_t*);
3305 RIC_ALLOC(ranFuncRejectedList->list.array, ranFuncRejectedList->list.size);
3306 if(ranFuncRejectedList->list.array == NULLP)
3308 DU_LOG("\nERROR --> E2AP : Memory allocation for RAN function rejected list array");
3312 for(ranFuncIdx = 0; ranFuncIdx< ranFuncRejectedList->list.count; ranFuncIdx++)
3314 RIC_ALLOC(ranFuncRejectedList->list.array[ranFuncIdx], sizeof(RANfunctionIDcause_ItemIEs_t));
3315 if(ranFuncRejectedList->list.array[ranFuncIdx] == NULLP)
3317 DU_LOG("\nERROR --> E2AP : Memory allocation for RAN function rejected list array item");
3320 ranFuncRejectedItemIe = (RANfunctionIDcause_ItemIEs_t*)ranFuncRejectedList->list.array[ranFuncIdx];
3321 ranFuncRejectedItemIe->id = ProtocolIE_IDE2_id_RANfunctionIEcause_Item;
3322 ranFuncRejectedItemIe->criticality= CriticalityE2_ignore;
3323 ranFuncRejectedItemIe->value.present = RANfunctionIDcause_ItemIEs__value_PR_RANfunctionIDcause_Item;
3324 ranFuncRejectedItemIe->value.choice.RANfunctionIDcause_Item.ranFunctionID = ranFunRejectedList[ranFuncIdx].id;
3325 fillE2FailureCause(&ranFuncRejectedItemIe->value.choice.RANfunctionIDcause_Item.cause, CauseE2_PR_ricService,\
3326 CauseE2RICservice_ran_function_not_supported);
3332 /*******************************************************************
3334 * @brief build and send the ric service update Acknowledge
3338 * Function : BuildAndSendRicServiceUpdateAcknowledge
3340 * Functionality: build and send the ric service update Acknowledge
3341 * @return ROK - success
3342 * RFAILED - Acknowledge
3344 ******************************************************************/
3346 uint8_t BuildAndSendRicServiceUpdateAcknowledge(DuDb *duDb, int8_t transId, RicTmpRanFunList ricRanFuncList)
3348 E2AP_PDU_t *e2apMsg = NULL;
3349 asn_enc_rval_t encRetVal;
3350 uint8_t arrIdx=0, elementCnt=0, ret=RFAILED;;
3351 RICserviceUpdateAcknowledge_t *ricServiceUpdateAck=NULL;
3353 DU_LOG("\nINFO --> E2AP : Building Ric service update Acknowledge\n");
3356 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
3357 if(e2apMsg == NULLP)
3359 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
3362 e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
3363 RIC_ALLOC(e2apMsg->choice.successfulOutcome , sizeof(struct SuccessfulOutcomeE2));
3364 if(e2apMsg->choice.successfulOutcome == NULLP)
3366 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
3370 e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICserviceUpdate;
3371 e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
3372 e2apMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_RICserviceUpdateAcknowledge;
3373 ricServiceUpdateAck = &e2apMsg->choice.successfulOutcome->value.choice.RICserviceUpdateAcknowledge;
3376 if(ricRanFuncList.numOfRanFunAccepted)
3378 if(ricRanFuncList.numOfRanFuneRejected)
3382 ricServiceUpdateAck->protocolIEs.list.count = elementCnt;
3383 ricServiceUpdateAck->protocolIEs.list.size = elementCnt * sizeof(RICserviceUpdateAcknowledge_IEs_t*);
3385 RIC_ALLOC(ricServiceUpdateAck->protocolIEs.list.array, ricServiceUpdateAck->protocolIEs.list.size);
3386 if(ricServiceUpdateAck->protocolIEs.list.array == NULLP)
3388 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceUpdateAckIEs failed");
3392 for(arrIdx=0; arrIdx<elementCnt; arrIdx++)
3394 RIC_ALLOC(ricServiceUpdateAck->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdateAcknowledge_IEs_t));
3395 if(ricServiceUpdateAck->protocolIEs.list.array[arrIdx] == NULLP)
3397 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceUpdateAckIEs failed");
3401 if(arrIdx<elementCnt)
3403 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceUpdateAckIEs failed");
3409 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
3410 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3411 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdateAcknowledge_IEs__value_PR_TransactionID;
3412 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
3414 if(ricRanFuncList.numOfRanFunAccepted)
3416 /* Accepted RAN function List */
3418 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAccepted;
3419 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3420 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdateAcknowledge_IEs__value_PR_RANfunctionsID_List;
3421 if(BuildRanFunctionAcceptedList(duDb, ricRanFuncList.numOfRanFunAccepted, ricRanFuncList.ranFunAcceptedList,\
3422 &ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List, ProcedureCodeE2_id_RICserviceUpdate)!=ROK)
3424 DU_LOG("\nERROR --> E2AP : Failed to build Ran function added list");
3429 if(ricRanFuncList.numOfRanFuneRejected)
3431 /* RAN Functions Rejected List */
3433 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsRejected;
3434 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3435 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdateAcknowledge_IEs__value_PR_RANfunctionsIDcause_List;
3436 if(BuildRanFunctionRejectedList(ricRanFuncList.numOfRanFuneRejected, ricRanFuncList.ranFunRejectedList, \
3437 &ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsIDcause_List)!=ROK)
3439 DU_LOG("\nERROR --> E2AP : Failed to build Ran function rejected list");
3445 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3446 memset(encBuf, 0, ENC_BUF_MAX_LEN);
3448 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
3450 /* Check encode results */
3451 if(encRetVal.encoded == ENCODE_FAIL)
3453 DU_LOG("\nERROR --> E2AP : Could not encode RIC service update Acknowledge structure (at %s)\n",\
3454 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3459 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC service update Acknowledge\n");
3460 for(int i=0; i< encBufSize; i++)
3462 DU_LOG("%x",encBuf[i]);
3466 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
3468 DU_LOG("\nERROR --> E2AP : Sending RIC service update ack failed");
3474 FreeRicServiceUpdateAck(e2apMsg);
3478 /*******************************************************************
3480 * @brief process the RIC service update
3484 * Function : ProcRicserviceUpdate
3486 * Functionality: process the RIC service update
3488 * @return ROK - success
3491 ******************************************************************/
3493 void ProcRicServiceUpdate(uint32_t duId, RICserviceUpdate_t *ricServiceUpdate)
3495 RicTmpRanFunList ricRanFuncList;
3498 uint8_t duIdx = 0, elementCnt =0, arrIdx = 0;
3499 uint16_t ranFuncIdx = 0, failedRanFuncCount=0, recvdRanFuncCount=0;
3500 RanFunction *ranFuncDb = NULLP;
3501 RANfunction_ItemIEs_t *ranFuncItemIe =NULL;
3502 RANfunction_Item_t *ranFuncItem =NULL;
3503 RANfunctionID_Item_t *ranFuncIdItem=NULL;
3504 RANfunctions_List_t *ranFuncList=NULL;
3505 RANfunctionsID_List_t *deleteList=NULL;
3506 RANfunctionID_ItemIEs_t *delRanFuncItem=NULL;
3508 SEARCH_DU_DB(duIdx, duId, duDb);
3511 DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
3514 memset(&ricRanFuncList, 0, sizeof(RicTmpRanFunList));
3516 if(!ricServiceUpdate)
3518 DU_LOG("\nERROR --> E2AP : ricServiceUpdate pointer is null");
3522 if(!ricServiceUpdate->protocolIEs.list.array)
3524 DU_LOG("\nERROR --> E2AP : ricServiceUpdate array pointer is null");
3527 elementCnt = ricServiceUpdate->protocolIEs.list.count;
3528 for(arrIdx=0; arrIdx<ricServiceUpdate->protocolIEs.list.count; arrIdx++)
3530 if(!ricServiceUpdate->protocolIEs.list.array[arrIdx])
3532 DU_LOG("\nERROR --> E2AP : ricServiceUpdate array idx %d pointer is null",arrIdx);
3536 switch(ricServiceUpdate->protocolIEs.list.array[arrIdx]->id)
3538 case ProtocolIE_IDE2_id_TransactionID:
3540 transId = ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
3542 if(transId < 0 || transId > 255)
3544 DU_LOG("\nERROR --> E2AP : Received invalid transId %d",transId);
3550 case ProtocolIE_IDE2_id_RANfunctionsAdded:
3552 ranFuncList = &ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List;
3554 if(ranFuncList->list.array)
3556 for(ranFuncIdx=0;ranFuncIdx<ranFuncList->list.count; ranFuncIdx++)
3558 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFuncList->list.array[ranFuncIdx];
3559 ranFuncItem = &ranFuncItemIe->value.choice.RANfunction_Item;
3561 /* Adding the ran function in temporary list */
3562 ricRanFuncList.ranFunAcceptedList[ricRanFuncList.numOfRanFunAccepted].id = ranFuncItem->ranFunctionID;
3563 ricRanFuncList.ranFunAcceptedList[ricRanFuncList.numOfRanFunAccepted].revisionCounter = ranFuncItem->ranFunctionRevision;
3564 ricRanFuncList.numOfRanFunAccepted++;
3566 /* Adding the new ran function in DB*/
3567 duDb->ranFunction[ranFuncItem->ranFunctionID-1].id = ranFuncItem->ranFunctionID;
3568 duDb->ranFunction[ranFuncItem->ranFunctionID-1].revisionCounter = ranFuncItem->ranFunctionRevision;
3569 duDb->numOfRanFunction++;
3571 /* Calculating total number of ran fuctions which are received for addition */
3572 recvdRanFuncCount++;
3578 case ProtocolIE_IDE2_id_RANfunctionsModified:
3581 ranFuncList = &ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List;
3582 if(ranFuncList->list.array)
3584 for(ranFuncIdx = 0; ranFuncIdx< ranFuncList->list.count; ranFuncIdx++)
3586 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFuncList->list.array[ranFuncIdx];
3587 ranFuncItem = &ranFuncItemIe->value.choice.RANfunction_Item;
3588 if(fetchRanFuncFromRanFuncId(duDb, ranFuncItem->ranFunctionID) == NULLP)
3590 /* Calculating total number of ran fuctions which are not present */
3591 failedRanFuncCount++;
3593 /* Adding the ran function in temporary list */
3594 ricRanFuncList.ranFunRejectedList[ricRanFuncList.numOfRanFuneRejected].id = ranFuncItem->ranFunctionID;
3595 ricRanFuncList.numOfRanFuneRejected++;
3600 /* Adding the ran function in temporary list */
3601 ricRanFuncList.ranFunAcceptedList[ricRanFuncList.numOfRanFunAccepted].id = ranFuncItem->ranFunctionID;
3602 ricRanFuncList.ranFunAcceptedList[ricRanFuncList.numOfRanFunAccepted].revisionCounter = ranFuncItem->ranFunctionRevision;
3603 ricRanFuncList.numOfRanFunAccepted++;
3605 /* Updating the new ran function in DB*/
3606 duDb->ranFunction[ranFuncItem->ranFunctionID-1].revisionCounter = ranFuncItem->ranFunctionRevision;
3608 /* Calculating total number of ran fuctions which are received for modification */
3609 recvdRanFuncCount++;
3614 case ProtocolIE_IDE2_id_RANfunctionsDeleted:
3617 deleteList = &ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
3618 if(deleteList->list.array)
3620 for(ranFuncIdx = 0; ranFuncIdx< deleteList->list.count; ranFuncIdx++)
3622 delRanFuncItem = (RANfunctionID_ItemIEs_t*) deleteList->list.array[ranFuncIdx];
3623 ranFuncIdItem = &delRanFuncItem->value.choice.RANfunctionID_Item;
3624 ranFuncDb = fetchRanFuncFromRanFuncId(duDb, ranFuncIdItem->ranFunctionID);
3627 memset(ranFuncDb, 0, sizeof(RanFunction));
3628 duDb->numOfRanFunction--;
3631 /* Calculating total number of ran fuctions which are received for deletion */
3632 recvdRanFuncCount++;
3640 DU_LOG("\nERROR --> E2AP : IE [%ld] is not supported",ricServiceUpdate->protocolIEs.list.array[arrIdx]->id);
3646 /* Sending RIC Service Update Failed if all RAN Functions received fail or if any IE processing fails
3647 * Else sending RIC Service Update Acknowledge */
3648 if((elementCnt > arrIdx) ||((recvdRanFuncCount > 0) && (recvdRanFuncCount == failedRanFuncCount)))
3650 if(BuildAndSendRicServiceUpdateFailure(duDb->duId, transId, CauseE2_PR_misc, CauseE2Misc_unspecified) != ROK)
3652 DU_LOG("\nERROR --> E2AP : Failed to build and send RIC service update Failure");
3658 if(BuildAndSendRicServiceUpdateAcknowledge(duDb, transId, ricRanFuncList) != ROK)
3660 DU_LOG("\nERROR --> E2AP : Failed to build and send RIC service update acknowledge");
3666 /*******************************************************************
3668 * @brief Processing RIC subscription failure from DU
3672 * Function : ProcRicSubscriptionFailure
3674 * Functionality: Processing RIC subscription failure from DU
3676 * @param ID of DU from which message was sent
3677 * RIC Subscription failure message
3678 * @return ROK - success
3681 ******************************************************************/
3682 uint8_t ProcRicSubscriptionFailure(uint32_t duId, RICsubscriptionFailure_t *ricSubscriptionFailure)
3684 uint8_t ieIdx = 0, duIdx = 0;
3685 uint8_t ranFuncId = 0;
3687 RanFunction *ranFuncDb = NULLP;
3688 RicSubscription *ricSubs = NULLP;
3689 CmLList *ricSubsNode = NULLP;
3690 RicRequestId ricReqId;
3691 RICsubscriptionFailure_IEs_t *ricSubsFailIe = NULLP;
3693 DU_LOG("\nINFO --> E2AP : Received RIC subscription failure");
3695 SEARCH_DU_DB(duIdx, duId, duDb);
3698 DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
3702 memset(&ricReqId, 0, sizeof(RicRequestId));
3703 if(ricSubscriptionFailure)
3705 if(ricSubscriptionFailure->protocolIEs.list.array)
3707 for(ieIdx=0; ieIdx<ricSubscriptionFailure->protocolIEs.list.count; ieIdx++)
3709 if(ricSubscriptionFailure->protocolIEs.list.array[ieIdx])
3711 ricSubsFailIe = ricSubscriptionFailure->protocolIEs.list.array[ieIdx];
3712 switch(ricSubscriptionFailure->protocolIEs.list.array[ieIdx]->id)
3714 case ProtocolIE_IDE2_id_RICrequestID:
3716 ricReqId.requestorId = ricSubsFailIe->value.choice.RICrequestID.ricRequestorID;
3717 ricReqId.instanceId = ricSubsFailIe->value.choice.RICrequestID.ricInstanceID;
3720 case ProtocolIE_IDE2_id_RANfunctionID:
3722 ranFuncId = ricSubsFailIe->value.choice.RANfunctionID;
3723 ranFuncDb = fetchRanFuncFromRanFuncId(duDb, ranFuncId);
3726 DU_LOG("\nERROR --> E2AP : ProcRicSubscriptionFailure : RAN Function Id [%d] not found", ranFuncId);
3731 /* Remove subscription entry from RAN Function */
3732 ricSubs = fetchSubsInfoFromRicReqId(ricReqId, ranFuncDb, &ricSubsNode);
3735 cmLListDelFrm(&ranFuncDb->subscriptionList, ricSubsNode);
3736 deleteRicSubscriptionNode(ricSubsNode);
3741 case ProtocolIE_IDE2_id_CauseE2:
3743 /* No handling required as of now since this is a stub */
3753 /*******************************************************************
3755 * @brief Free RIC Subscription Modification Refuse
3759 * Function : FreeRicSubsModRefuse
3761 * Functionality: Free RIC Subscription Modification Refuse
3763 * @param E2AP Message PDU to be freed
3766 ******************************************************************/
3767 void FreeRicSubsModRefuse(E2AP_PDU_t *e2apMsg)
3770 RICsubscriptionModificationRefuse_t *ricSubsModRefuse = NULLP;
3774 if(e2apMsg->choice.unsuccessfulOutcome)
3776 ricSubsModRefuse = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionModificationRefuse;
3777 if(ricSubsModRefuse->protocolIEs.list.array)
3779 for(ieIdx = 0; ieIdx < ricSubsModRefuse->protocolIEs.list.count; ieIdx++)
3781 RIC_FREE(ricSubsModRefuse->protocolIEs.list.array[ieIdx], sizeof(RICsubscriptionModificationRefuse_IEs_t));
3783 RIC_FREE(ricSubsModRefuse->protocolIEs.list.array, ricSubsModRefuse->protocolIEs.list.size);
3785 RIC_FREE(e2apMsg->choice.unsuccessfulOutcome , sizeof(UnsuccessfulOutcomeE2_t));
3787 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
3791 /*******************************************************************
3793 * @brief Build And Send RIC Subscription Modification Refuse
3797 * Function : BuildAndSendRicSubsModRefuse
3799 * Functionality: Build And Send RIC Subscription Modification Refuse
3802 * RIC Request ID of subscription
3806 * @return ROK - success
3809 ******************************************************************/
3810 uint8_t BuildAndSendRicSubsModRefuse(uint32_t duId, RicRequestId ricReqId, uint16_t ranFuncId, CauseE2_PR causeType, \
3813 uint8_t ieIdx = 0, elementCnt = 0;
3814 uint8_t ret = RFAILED;
3815 E2AP_PDU_t *e2apMsg = NULL;
3816 asn_enc_rval_t encRetVal;
3817 RICsubscriptionModificationRefuse_t *ricSubsModRefuse = NULLP;
3818 RICsubscriptionModificationRefuse_IEs_t *ricSubsModRefuseIe = NULLP;
3820 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Modification Refuse\n");
3823 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
3824 if(e2apMsg == NULLP)
3826 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
3829 e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome;
3830 RIC_ALLOC(e2apMsg->choice.unsuccessfulOutcome , sizeof(UnsuccessfulOutcomeE2_t));
3831 if(e2apMsg->choice.unsuccessfulOutcome == NULLP)
3833 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
3837 e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscriptionModificationRequired;
3838 e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject;
3839 e2apMsg->choice.unsuccessfulOutcome->value.present = \
3840 UnsuccessfulOutcomeE2__value_PR_RICsubscriptionModificationRefuse;
3841 ricSubsModRefuse = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionModificationRefuse;
3844 ricSubsModRefuse->protocolIEs.list.count = elementCnt;
3845 ricSubsModRefuse->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionModificationRefuse_IEs_t *);
3846 RIC_ALLOC(ricSubsModRefuse->protocolIEs.list.array, ricSubsModRefuse->protocolIEs.list.size);
3847 if(!ricSubsModRefuse->protocolIEs.list.array)
3849 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
3853 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
3855 RIC_ALLOC(ricSubsModRefuse->protocolIEs.list.array[ieIdx], sizeof(RICsubscriptionModificationRefuse_IEs_t));
3856 if(!ricSubsModRefuse->protocolIEs.list.array[ieIdx])
3858 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
3863 /* RIC Request ID */
3865 ricSubsModRefuseIe = ricSubsModRefuse->protocolIEs.list.array[ieIdx];
3866 ricSubsModRefuseIe->id = ProtocolIE_IDE2_id_RICrequestID;
3867 ricSubsModRefuseIe->criticality = CriticalityE2_reject;
3868 ricSubsModRefuseIe->value.present = RICsubscriptionModificationRefuse_IEs__value_PR_RICrequestID;
3869 ricSubsModRefuseIe->value.choice.RICrequestID.ricRequestorID = ricReqId.requestorId;
3870 ricSubsModRefuseIe->value.choice.RICrequestID.ricInstanceID = ricReqId.instanceId;
3872 /* RAN Function ID */
3874 ricSubsModRefuseIe = ricSubsModRefuse->protocolIEs.list.array[ieIdx];
3875 ricSubsModRefuseIe->id = ProtocolIE_IDE2_id_RANfunctionID;
3876 ricSubsModRefuseIe->criticality = CriticalityE2_reject;
3877 ricSubsModRefuseIe->value.present = RICsubscriptionModificationRefuse_IEs__value_PR_RANfunctionID;
3878 ricSubsModRefuseIe->value.choice.RANfunctionID = ranFuncId;
3882 ricSubsModRefuseIe = ricSubsModRefuse->protocolIEs.list.array[ieIdx];
3883 ricSubsModRefuseIe->id = ProtocolIE_IDE2_id_CauseE2;
3884 ricSubsModRefuseIe->criticality = CriticalityE2_reject;
3885 ricSubsModRefuseIe->value.present = RICsubscriptionModificationRefuse_IEs__value_PR_CauseE2;
3886 fillE2FailureCause(&ricSubsModRefuseIe->value.choice.CauseE2, causeType, cause);
3888 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3889 memset(encBuf, 0, ENC_BUF_MAX_LEN);
3891 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
3893 /* Check encode results */
3894 if(encRetVal.encoded == ENCODE_FAIL)
3896 DU_LOG("\nERROR --> E2AP : Could not encode RIC subscription modification refuse (at %s)\n",\
3897 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3902 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC subscription modification refuse\n");
3903 for(int i=0; i< encBufSize; i++)
3905 DU_LOG("%x",encBuf[i]);
3909 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
3911 DU_LOG("\nERROR --> E2AP : Failed to send RIC Subscription Modification Refused");
3918 FreeRicSubsModRefuse(e2apMsg);
3922 /*******************************************************************
3924 * @brief Free memory for RIC Subscription Modification Confirm
3928 * Function : FreeRicSubsModConfirm
3930 * Functionality: Free memory for RIC subscription modification
3933 * @param E2AP Message PDU to be freed
3936 ******************************************************************/
3937 void FreeRicSubsModConfirm(E2AP_PDU_t *e2apMsg)
3939 uint8_t ieIdx = 0, arrIdx=0;
3940 RICsubscriptionModificationConfirm_t *ricSubsModCfm = NULLP;
3941 RICsubscriptionModificationConfirm_IEs_t *ricSubsModCfmIe = NULLP;
3942 RICactions_ConfirmedForModification_List_t *modCfmList = NULLP;
3943 RICactions_RefusedToBeModified_List_t *modRefusedList = NULLP;
3944 RICactions_ConfirmedForRemoval_List_t *rmvCfmList = NULLP;
3945 RICactions_RefusedToBeRemoved_List_t *rmvFailList = NULLP;
3949 if(e2apMsg->choice.successfulOutcome)
3951 ricSubsModCfm = &e2apMsg->choice.successfulOutcome->value.choice.RICsubscriptionModificationConfirm;
3952 if(ricSubsModCfm->protocolIEs.list.array)
3954 for(ieIdx = 0; ieIdx < ricSubsModCfm->protocolIEs.list.count; ieIdx++)
3956 if(ricSubsModCfm->protocolIEs.list.array[ieIdx])
3958 ricSubsModCfmIe = ricSubsModCfm->protocolIEs.list.array[ieIdx];
3959 switch(ricSubsModCfmIe->id)
3961 case ProtocolIE_IDE2_id_RICactionsConfirmedForModification_List:
3963 modCfmList = &ricSubsModCfmIe->value.choice.RICactions_ConfirmedForModification_List;
3964 if(modCfmList->list.array)
3966 for(arrIdx = 0; arrIdx < modCfmList->list.count; arrIdx++)
3968 RIC_FREE(modCfmList->list.array[arrIdx], \
3969 sizeof(RICaction_ConfirmedForModification_ItemIEs_t));
3971 RIC_FREE(modCfmList->list.array, modCfmList->list.size);
3976 case ProtocolIE_IDE2_id_RICactionsRefusedToBeModified_List:
3978 modRefusedList = &ricSubsModCfmIe->value.choice.RICactions_RefusedToBeModified_List;
3979 if(modRefusedList->list.array)
3981 for(arrIdx = 0; arrIdx < modRefusedList->list.count; arrIdx++)
3983 RIC_FREE(modRefusedList->list.array[arrIdx], \
3984 sizeof(RICaction_RefusedToBeModified_ItemIEs_t));
3986 RIC_FREE(modRefusedList->list.array, modRefusedList->list.size);
3991 case ProtocolIE_IDE2_id_RICactionsConfirmedForRemoval_List:
3993 rmvCfmList = &ricSubsModCfmIe->value.choice.RICactions_ConfirmedForRemoval_List;
3994 if(rmvCfmList->list.array)
3996 for(arrIdx = 0; arrIdx < rmvCfmList->list.count; arrIdx++)
3998 RIC_FREE(rmvCfmList->list.array[arrIdx], \
3999 sizeof(RICaction_ConfirmedForRemoval_ItemIEs_t));
4001 RIC_FREE(rmvCfmList->list.array, rmvCfmList->list.size);
4006 case ProtocolIE_IDE2_id_RICactionsRefusedToBeRemoved_List:
4008 rmvFailList = &ricSubsModCfmIe->value.choice.RICactions_RefusedToBeRemoved_List;
4009 if(rmvFailList->list.array)
4011 for(arrIdx = 0; arrIdx < rmvFailList->list.count; arrIdx++)
4013 RIC_ALLOC(rmvFailList->list.array[arrIdx], \
4014 sizeof(RICaction_RefusedToBeRemoved_ItemIEs_t));
4016 RIC_FREE(rmvFailList->list.array, rmvFailList->list.size);
4025 RIC_FREE(ricSubsModCfmIe, sizeof(RICsubscriptionModificationConfirm_IEs_t));
4028 RIC_FREE(ricSubsModCfm->protocolIEs.list.array, ricSubsModCfm->protocolIEs.list.size);
4030 RIC_FREE(e2apMsg->choice.successfulOutcome , sizeof(SuccessfulOutcomeE2_t));
4032 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
4036 /*******************************************************************
4038 * @brief Fill the list of actions confirmed for modification
4042 * Function : fillActionModConfirmedList
4044 * Functionality: Fill the list of actions confirmed for modification
4046 * @param List to be filled
4048 * Source list of actions
4049 * @return ROK - success
4052 ******************************************************************/
4053 uint8_t fillActionModConfirmedList(RICactions_ConfirmedForModification_List_t *modCfmList, uint8_t numActions, \
4054 uint8_t *actionModifiedList)
4057 RICaction_ConfirmedForModification_ItemIEs_t *modCfmListItem = NULLP;
4059 modCfmList->list.count = numActions;
4060 modCfmList->list.size = numActions * sizeof(RICaction_ConfirmedForModification_ItemIEs_t *);
4061 RIC_ALLOC(modCfmList->list.array, modCfmList->list.size);
4062 if(!modCfmList->list.array)
4064 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
4068 for(arrIdx = 0; arrIdx < modCfmList->list.count; arrIdx++)
4070 RIC_ALLOC(modCfmList->list.array[arrIdx], sizeof(RICaction_ConfirmedForModification_ItemIEs_t));
4071 if(!modCfmList->list.array[arrIdx])
4073 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
4077 modCfmListItem = (RICaction_ConfirmedForModification_ItemIEs_t *)modCfmList->list.array[arrIdx];
4078 modCfmListItem->id = ProtocolIE_IDE2_id_RICaction_ConfirmedForModification_Item;
4079 modCfmListItem->criticality = CriticalityE2_ignore;
4080 modCfmListItem->value.present = \
4081 RICaction_ConfirmedForModification_ItemIEs__value_PR_RICaction_ConfirmedForModification_Item;
4082 modCfmListItem->value.choice.RICaction_ConfirmedForModification_Item.ricActionID = actionModifiedList[arrIdx];
4088 /*******************************************************************
4090 * @brief Fill the list of actions refused to be modified
4094 * Function : fillActionModRefusedList
4096 * Functionality: Fill the list of actions refused to be modified
4098 * @param List to be filled
4100 * Source list of actions refused tobe modified
4101 * @return ROK - success
4104 ******************************************************************/
4105 uint8_t fillActionModRefusedList(RICactions_RefusedToBeModified_List_t *modRefusedList, uint8_t numActions, \
4106 ActionFailed *actionModFailedList)
4109 RICaction_RefusedToBeModified_ItemIEs_t *modRefusedListItem = NULLP;
4111 modRefusedList->list.count = numActions;
4112 modRefusedList->list.size = numActions * sizeof(RICaction_RefusedToBeModified_ItemIEs_t *);
4113 RIC_ALLOC(modRefusedList->list.array, modRefusedList->list.size);
4114 if(!modRefusedList->list.array)
4116 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
4120 for(arrIdx = 0; arrIdx < modRefusedList->list.count; arrIdx++)
4122 RIC_ALLOC(modRefusedList->list.array[arrIdx], sizeof(RICaction_RefusedToBeModified_ItemIEs_t));
4123 if(!modRefusedList->list.array[arrIdx])
4125 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
4129 modRefusedListItem = (RICaction_RefusedToBeModified_ItemIEs_t *)modRefusedList->list.array[arrIdx];
4130 modRefusedListItem->id = ProtocolIE_IDE2_id_RICaction_RefusedToBeModified_Item;
4131 modRefusedListItem->criticality = CriticalityE2_ignore;
4132 modRefusedListItem->value.present = \
4133 RICaction_RefusedToBeModified_ItemIEs__value_PR_RICaction_RefusedToBeModified_Item;
4134 modRefusedListItem->value.choice.RICaction_RefusedToBeModified_Item.ricActionID = \
4135 actionModFailedList[arrIdx].actionId;
4136 fillE2FailureCause(&modRefusedListItem->value.choice.RICaction_RefusedToBeModified_Item.cause, \
4137 actionModFailedList[arrIdx].failureType, actionModFailedList[arrIdx].cause);
4143 /*******************************************************************
4145 * @brief Fill the list of action confirmed for removal
4149 * Function : fillActionRemovalConfirmedList
4151 * Functionality: Fill the list of action confirmed for removal
4153 * @param List to be filled
4155 * Source list of actions removed
4156 * @return ROK - success
4159 ******************************************************************/
4160 uint8_t fillActionRemovalConfirmedList(RICactions_ConfirmedForRemoval_List_t *rmvCfmList, uint8_t numActions, \
4161 uint8_t *actionRemovedList)
4164 RICaction_ConfirmedForRemoval_ItemIEs_t *rmvCfmListItem = NULLP;
4166 rmvCfmList->list.count = numActions;
4167 rmvCfmList->list.size = numActions * sizeof(RICaction_ConfirmedForRemoval_ItemIEs_t *);
4168 RIC_ALLOC(rmvCfmList->list.array, rmvCfmList->list.size);
4169 if(!rmvCfmList->list.array)
4171 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
4175 for(arrIdx = 0; arrIdx < rmvCfmList->list.count; arrIdx++)
4177 RIC_ALLOC(rmvCfmList->list.array[arrIdx], sizeof(RICaction_ConfirmedForRemoval_ItemIEs_t));
4178 if(!rmvCfmList->list.array[arrIdx])
4180 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
4184 rmvCfmListItem = (RICaction_ConfirmedForRemoval_ItemIEs_t *)rmvCfmList->list.array[arrIdx];
4185 rmvCfmListItem->id = ProtocolIE_IDE2_id_RICaction_ConfirmedForRemoval_Item;
4186 rmvCfmListItem->criticality = CriticalityE2_ignore;
4187 rmvCfmListItem->value.present = \
4188 RICaction_ConfirmedForRemoval_ItemIEs__value_PR_RICaction_ConfirmedForRemoval_Item;
4189 rmvCfmListItem->value.choice.RICaction_ConfirmedForRemoval_Item.ricActionID = actionRemovedList[arrIdx];
4195 /*******************************************************************
4197 * @brief Fill the list of actions refused to be removed
4201 * Function : fillActionRemovalRefusedList
4203 * Functionality: Fill the list of actions refused to be removed
4205 * @param List to be filled
4207 * Source list of actions refused to be removed
4208 * @return ROK - success
4211 ******************************************************************/
4212 uint8_t fillActionRemovalRefusedList(RICactions_RefusedToBeRemoved_List_t *rmvFailList, \
4213 uint8_t numActions, ActionFailed *actionRmvlFailList)
4216 RICaction_RefusedToBeRemoved_ItemIEs_t *rmvFailListItem = NULLP;
4218 rmvFailList->list.count = numActions;
4219 rmvFailList->list.size = numActions * sizeof(RICaction_RefusedToBeRemoved_ItemIEs_t *);
4220 RIC_ALLOC(rmvFailList->list.array, rmvFailList->list.size);
4221 if(!rmvFailList->list.array)
4223 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
4227 for(arrIdx = 0; arrIdx < rmvFailList->list.count; arrIdx++)
4229 RIC_ALLOC(rmvFailList->list.array[arrIdx], sizeof(RICaction_RefusedToBeRemoved_ItemIEs_t));
4230 if(!rmvFailList->list.array[arrIdx])
4232 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
4236 rmvFailListItem = (RICaction_RefusedToBeRemoved_ItemIEs_t *)rmvFailList->list.array[arrIdx];
4237 rmvFailListItem->id = ProtocolIE_IDE2_id_RICaction_RefusedToBeRemoved_Item;
4238 rmvFailListItem->criticality = CriticalityE2_ignore;
4239 rmvFailListItem->value.present = \
4240 RICaction_RefusedToBeRemoved_ItemIEs__value_PR_RICaction_RefusedToBeRemoved_Item;
4241 rmvFailListItem->value.choice.RICaction_RefusedToBeRemoved_Item.ricActionID = actionRmvlFailList[arrIdx].actionId;
4242 fillE2FailureCause(&rmvFailListItem->value.choice.RICaction_RefusedToBeRemoved_Item.cause, \
4243 actionRmvlFailList[arrIdx].failureType, actionRmvlFailList[arrIdx].cause);
4250 /*******************************************************************
4252 * @brief Build And Send RIC Subscription Modification Confirm
4256 * Function : BuildAndSendRicSubsModConfirm
4258 * Functionality: Build And Send RIC Subscription Modification Confirm
4261 * RIC Request ID of subscription
4263 * Temporary source action list
4264 * @return ROK - success
4267 ******************************************************************/
4268 uint8_t BuildAndSendRicSubsModConfirm(uint32_t duId, RicRequestId ricReqId, uint16_t ranFuncId, RicTmpActionList tmpActionList)
4270 uint8_t ieIdx = 0, elementCnt = 0;
4271 uint8_t ret = RFAILED;
4272 E2AP_PDU_t *e2apMsg = NULLP;
4273 asn_enc_rval_t encRetVal;
4274 RICsubscriptionModificationConfirm_t *ricSubsModCfm = NULLP;
4275 RICsubscriptionModificationConfirm_IEs_t *ricSubsModCfmIe = NULLP;
4277 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Modification Confirm\n");
4280 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
4281 if(e2apMsg == NULLP)
4283 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
4287 /* Successful Outcome */
4288 e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
4289 RIC_ALLOC(e2apMsg->choice.successfulOutcome , sizeof(SuccessfulOutcomeE2_t));
4290 if(e2apMsg->choice.successfulOutcome == NULLP)
4292 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
4296 e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscriptionModificationRequired;
4297 e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
4298 e2apMsg->choice.successfulOutcome->value.present = \
4299 SuccessfulOutcomeE2__value_PR_RICsubscriptionModificationConfirm;
4300 ricSubsModCfm = &e2apMsg->choice.successfulOutcome->value.choice.RICsubscriptionModificationConfirm;
4303 if(tmpActionList.numActionModified)
4305 if(tmpActionList.numActionModFailed)
4307 if(tmpActionList.numActionRemoved)
4309 if(tmpActionList.numActionRemovalFailed)
4312 ricSubsModCfm->protocolIEs.list.count = elementCnt;
4313 ricSubsModCfm->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionModificationConfirm_IEs_t *);
4314 RIC_ALLOC(ricSubsModCfm->protocolIEs.list.array, ricSubsModCfm->protocolIEs.list.size);
4315 if(!ricSubsModCfm->protocolIEs.list.array)
4317 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
4321 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
4323 RIC_ALLOC(ricSubsModCfm->protocolIEs.list.array[ieIdx], sizeof(RICsubscriptionModificationConfirm_IEs_t));
4324 if(!ricSubsModCfm->protocolIEs.list.array[ieIdx])
4326 DU_LOG("\nERROR --> E2AP : Memory allocation failed for %s at line %d", __func__, __LINE__);
4331 /* RIC Request ID */
4333 ricSubsModCfmIe = ricSubsModCfm->protocolIEs.list.array[ieIdx];
4334 ricSubsModCfmIe->id = ProtocolIE_IDE2_id_RICrequestID;
4335 ricSubsModCfmIe->criticality = CriticalityE2_reject;
4336 ricSubsModCfmIe->value.present = RICsubscriptionModificationConfirm_IEs__value_PR_RICrequestID;
4337 ricSubsModCfmIe->value.choice.RICrequestID.ricRequestorID = ricReqId.requestorId;
4338 ricSubsModCfmIe->value.choice.RICrequestID.ricInstanceID = ricReqId.instanceId;
4340 /* RAN Function ID */
4342 ricSubsModCfmIe = ricSubsModCfm->protocolIEs.list.array[ieIdx];
4343 ricSubsModCfmIe->id = ProtocolIE_IDE2_id_RANfunctionID;
4344 ricSubsModCfmIe->criticality = CriticalityE2_reject;
4345 ricSubsModCfmIe->value.present = RICsubscriptionModificationConfirm_IEs__value_PR_RANfunctionID;
4346 ricSubsModCfmIe->value.choice.RANfunctionID = ranFuncId;
4348 /* RIC Actions List confirmed for modification */
4349 if(tmpActionList.numActionModified)
4352 ricSubsModCfmIe = ricSubsModCfm->protocolIEs.list.array[ieIdx];
4353 ricSubsModCfmIe->id = ProtocolIE_IDE2_id_RICactionsConfirmedForModification_List;
4354 ricSubsModCfmIe->criticality = CriticalityE2_ignore;
4355 ricSubsModCfmIe->value.present = \
4356 RICsubscriptionModificationConfirm_IEs__value_PR_RICactions_ConfirmedForModification_List;
4357 if(fillActionModConfirmedList(&ricSubsModCfmIe->value.choice.RICactions_ConfirmedForModification_List, \
4358 tmpActionList.numActionModified, tmpActionList.actionModifiedList) != ROK)
4360 DU_LOG("\nERROR --> E2AP : %s: Failed to fill RIC Actions Confirmed for Modification List", __func__);
4365 /* RIC Actions List refured to be modified */
4366 if(tmpActionList.numActionModFailed)
4369 ricSubsModCfmIe = ricSubsModCfm->protocolIEs.list.array[ieIdx];
4370 ricSubsModCfmIe->id = ProtocolIE_IDE2_id_RICactionsRefusedToBeModified_List;
4371 ricSubsModCfmIe->criticality = CriticalityE2_ignore;
4372 ricSubsModCfmIe->value.present = \
4373 RICsubscriptionModificationConfirm_IEs__value_PR_RICactions_RefusedToBeModified_List;
4374 if(fillActionModRefusedList(&ricSubsModCfmIe->value.choice.RICactions_RefusedToBeModified_List, \
4375 tmpActionList.numActionModFailed, tmpActionList.actionModFailedList) != ROK)
4377 DU_LOG("\nERROR --> E2AP : %s: Failed to fill RIC Actions Refused to be Modified List", __func__);
4382 /* RIC Actions List confirmed for removal */
4383 if(tmpActionList.numActionRemoved)
4386 ricSubsModCfmIe = ricSubsModCfm->protocolIEs.list.array[ieIdx];
4387 ricSubsModCfmIe->id = ProtocolIE_IDE2_id_RICactionsConfirmedForRemoval_List;
4388 ricSubsModCfmIe->criticality = CriticalityE2_ignore;
4389 ricSubsModCfmIe->value.present = \
4390 RICsubscriptionModificationConfirm_IEs__value_PR_RICactions_ConfirmedForRemoval_List;
4391 if(fillActionRemovalConfirmedList(&ricSubsModCfmIe->value.choice.RICactions_ConfirmedForRemoval_List, \
4392 tmpActionList.numActionRemoved, tmpActionList.actionRemovedList) != ROK)
4394 DU_LOG("\nERROR --> E2AP : %s: Failed to fill RIC Actions Confirmed for Removal List", __func__);
4399 /* RIC Actions List Refused to be removed */
4400 if(tmpActionList.numActionRemovalFailed)
4403 ricSubsModCfmIe = ricSubsModCfm->protocolIEs.list.array[ieIdx];
4404 ricSubsModCfmIe->id = ProtocolIE_IDE2_id_RICactionsRefusedToBeRemoved_List;
4405 ricSubsModCfmIe->criticality = CriticalityE2_ignore;
4406 ricSubsModCfmIe->value.present = \
4407 RICsubscriptionModificationConfirm_IEs__value_PR_RICactions_RefusedToBeRemoved_List;
4408 if(fillActionRemovalRefusedList(&ricSubsModCfmIe->value.choice.RICactions_RefusedToBeRemoved_List, \
4409 tmpActionList.numActionRemovalFailed, tmpActionList.actionRemovalFailedList) != ROK)
4411 DU_LOG("\nERROR --> E2AP : %s: Failed to fill RIC Actions Failed to be Removed List", __func__);
4416 /* Print and encode E2AP Message PDU */
4417 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
4418 memset(encBuf, 0, ENC_BUF_MAX_LEN);
4420 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
4422 /* Check encode results */
4423 if(encRetVal.encoded == ENCODE_FAIL)
4425 DU_LOG("\nERROR --> E2AP : Could not encode RIC subscription modification confirm (at %s)\n",\
4426 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
4431 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC subscription modification confirm\n");
4432 for(int i=0; i< encBufSize; i++)
4434 DU_LOG("%x",encBuf[i]);
4438 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
4440 DU_LOG("\nERROR --> E2AP : Failed to send RIC Subscription Modification Confirm");
4448 FreeRicSubsModConfirm(e2apMsg);
4452 /*******************************************************************
4454 * @brief Processing of RIC Subscription Modification Required
4458 * Function : ProcRicSubsModReqd
4460 * Functionality: Processing of RIC Subscription Modification Required
4461 * As of now, we do not identify any scenario where this message
4462 * shall be sent by DU. Hence, bare minimum handling has been
4466 * RIC Subscription Modification Required IEs
4467 * @return ROK-success
4470 ******************************************************************/
4471 uint8_t ProcRicSubsModReqd(uint32_t duId, RICsubscriptionModificationRequired_t *ricSubsModReqd)
4473 uint8_t ieIdx = 0, actionIdx = 0, duIdx = 0;
4477 RicRequestId ricReqId;
4478 RanFunction *ranFuncDb = NULLP;
4479 RicSubscription *ricSubs = NULLP;
4480 CmLList *ricSubsNode = NULLP;
4481 ActionInfo *action = NULLP;
4482 RICsubscriptionModificationRequired_IEs_t *ricSubsModReqdIe = NULLP;
4483 RICactions_RequiredToBeModified_List_t *actionToBeModList = NULLP;
4484 RICactions_RequiredToBeRemoved_List_t *actionToBeRmvList = NULLP;
4485 RICaction_RequiredToBeModified_ItemIEs_t *actionToBeMod = NULLP;
4486 RICaction_RequiredToBeRemoved_ItemIEs_t *actionToBeRmv = NULLP;
4487 RicTmpActionList tmpActionList;
4489 memset(&ricReqId, 0, sizeof(RicRequestId));
4490 memset(&tmpActionList, 0, sizeof(RicTmpActionList));
4492 SEARCH_DU_DB(duIdx, duId, duDb);
4495 DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
4499 for(ieIdx = 0; ieIdx < ricSubsModReqd->protocolIEs.list.count; ieIdx++)
4501 ricSubsModReqdIe = ricSubsModReqd->protocolIEs.list.array[ieIdx];
4502 switch(ricSubsModReqdIe->id)
4504 case ProtocolIE_IDE2_id_RICrequestID:
4506 ricReqId.requestorId = ricSubsModReqdIe->value.choice.RICrequestID.ricRequestorID;
4507 ricReqId.instanceId = ricSubsModReqdIe->value.choice.RICrequestID.ricInstanceID;
4510 case ProtocolIE_IDE2_id_RANfunctionID:
4512 ranFuncId = ricSubsModReqdIe->value.choice.RANfunctionID;
4513 ranFuncDb = fetchRanFuncFromRanFuncId(duDb, ranFuncId);
4516 /* If RIC Subscription not found, send RIC Subscription modification refuse to DU */
4517 DU_LOG("\nERROR --> E2AP : ProcRicSubsModReqd: RIC Subscription not found");
4518 BuildAndSendRicSubsModRefuse(duId, ricReqId, ranFuncId, CauseE2_PR_ricRequest, \
4519 CauseE2RICrequest_ran_function_id_invalid);
4523 ricSubs = fetchSubsInfoFromRicReqId(ricReqId, ranFuncDb, &ricSubsNode);
4526 /* If RAN Function not found, send RIC Subscription modification refuse to DU */
4527 DU_LOG("\nERROR --> E2AP : ProcRicSubsModReqd: RAN Function ID [%d] not found",ranFuncId);
4528 BuildAndSendRicSubsModRefuse(duId, ricReqId, ranFuncId, \
4529 CauseE2_PR_ricRequest, CauseE2RICrequest_request_id_unknown);
4534 case ProtocolIE_IDE2_id_RICactionsRequiredToBeModified_List:
4536 actionToBeModList = &ricSubsModReqdIe->value.choice.RICactions_RequiredToBeModified_List;
4537 for(actionIdx = 0; actionIdx < actionToBeModList->list.count; actionIdx++)
4539 actionToBeMod = (RICaction_RequiredToBeModified_ItemIEs_t *)actionToBeModList->list.array[actionIdx];
4540 actionId = actionToBeMod->value.choice.RICaction_RequiredToBeModified_Item.ricActionID;
4541 action = fetchActionInfoFromActionId(actionId, ricSubs);
4544 /* No modification required as of now, hence directly adding to the list */
4545 tmpActionList.actionModifiedList[tmpActionList.numActionModified++] = actionId;
4549 tmpActionList.actionModFailedList[tmpActionList.numActionModFailed].actionId = actionId;
4550 tmpActionList.actionModFailedList[tmpActionList.numActionModFailed].failureType = \
4551 CauseE2_PR_ricRequest;
4552 tmpActionList.actionModFailedList[tmpActionList.numActionModFailed].cause = \
4553 CauseE2RICrequest_action_not_supported;
4554 tmpActionList.numActionModFailed++;
4559 case ProtocolIE_IDE2_id_RICactionsRequiredToBeRemoved_List:
4561 actionToBeRmvList = &ricSubsModReqdIe->value.choice.RICactions_RequiredToBeRemoved_List;
4562 for(actionIdx = 0; actionIdx < actionToBeRmvList->list.count; actionIdx++)
4564 actionToBeRmv = (RICaction_RequiredToBeRemoved_ItemIEs_t *)actionToBeRmvList->list.array[actionIdx];
4565 actionId = actionToBeRmv->value.choice.RICaction_RequiredToBeRemoved_Item.ricActionID;
4566 action = fetchActionInfoFromActionId(actionId, ricSubs);
4569 tmpActionList.actionRemovedList[tmpActionList.numActionRemoved++] = actionId;
4570 memset(action, 0, sizeof(ActionInfo));
4571 action->actionId = -1;
4572 ricSubs->numOfActions--;
4582 /* If none of the action modification/removal is supported,
4583 * send RIC Subscription Modification Refuse
4585 * send RIC Subscription Modification Confirm
4587 if(tmpActionList.numActionModified || tmpActionList.numActionRemoved)
4589 BuildAndSendRicSubsModConfirm(duId, ricReqId, ranFuncId, tmpActionList);
4593 BuildAndSendRicSubsModRefuse(duId, ricReqId, ranFuncId, CauseE2_PR_ricRequest, \
4594 CauseE2RICrequest_action_not_supported);
4600 /*******************************************************************
4602 * @brief Free the ErrorIndication Message
4606 * Function : FreeRicIndication
4608 * Functionality: Free the ErrorIndication Message
4613 ******************************************************************/
4614 void FreeErrorIndication(E2AP_PDU_t *e2apMsg)
4617 ErrorIndicationE2_t *errorIndicationMsg= NULLP;
4619 if(e2apMsg != NULLP)
4621 if(e2apMsg->choice.initiatingMessage != NULLP)
4623 errorIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.ErrorIndicationE2;
4624 if(errorIndicationMsg!= NULLP)
4626 if(errorIndicationMsg->protocolIEs.list.array != NULLP)
4628 for(arrIdx=0; arrIdx<errorIndicationMsg->protocolIEs.list.count; arrIdx++)
4630 RIC_FREE(errorIndicationMsg->protocolIEs.list.array[arrIdx],sizeof(ErrorIndicationE2_t));
4632 RIC_FREE(errorIndicationMsg->protocolIEs.list.array,errorIndicationMsg->protocolIEs.list.size);
4635 RIC_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
4637 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
4642 /*******************************************************************
4644 * @brief Builds and Send the ErrorIndication Message
4648 * Function : BuildAndSendErrorIndication
4650 * Functionality:Fills the ErrorIndication Message
4658 * @return ROK - success
4661 ******************************************************************/
4663 uint8_t BuildAndSendErrorIndication(uint32_t duId, int8_t transId, RicRequestId requestId, uint16_t ranFuncId, uint8_t reason)
4665 uint8_t elementCnt =0, arrIdx=0, ret = RFAILED;
4666 E2AP_PDU_t *e2apMsg = NULLP;
4667 ErrorIndicationE2_t *errorIndicationMsg=NULLP;
4668 asn_enc_rval_t encRetVal; /* Encoder return value */
4672 DU_LOG("\nINFO --> E2AP : Building Error Indication Message\n");
4674 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
4675 if(e2apMsg == NULLP)
4677 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed in %s at line %d",__func__, __LINE__);
4681 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
4682 RIC_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
4683 if(e2apMsg->choice.initiatingMessage == NULLP)
4685 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed in %s at line %d",__func__, __LINE__);
4688 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_ErrorIndicationE2;
4689 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
4690 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ErrorIndicationE2;
4692 errorIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.ErrorIndicationE2;
4694 /* Element count is 2 for TransactionID/RICrequestID and Cause.
4695 * If the RAN function id is present, the count will be increased.*/
4700 errorIndicationMsg->protocolIEs.list.count = elementCnt;
4701 errorIndicationMsg->protocolIEs.list.size = elementCnt * sizeof(ErrorIndicationE2_IEs_t*);
4703 /* Initialize the E2Setup members */
4704 RIC_ALLOC(errorIndicationMsg->protocolIEs.list.array, errorIndicationMsg->protocolIEs.list.size);
4705 if(errorIndicationMsg->protocolIEs.list.array == NULLP)
4707 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements in %s at line %d",__func__, __LINE__);
4710 for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
4712 RIC_ALLOC(errorIndicationMsg->protocolIEs.list.array[arrIdx], sizeof(ErrorIndicationE2_IEs_t));
4713 if(errorIndicationMsg->protocolIEs.list.array[arrIdx] == NULLP)
4715 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array Idx %d in %s at line %d",arrIdx,__func__, __LINE__);
4719 if(arrIdx < elementCnt)
4724 if(transId >=0 && transId<=255)
4727 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
4728 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
4729 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_TransactionID;
4730 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
4735 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RICrequestID;
4736 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
4737 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_RICrequestID;
4738 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RICrequestID.ricRequestorID = requestId.requestorId;
4739 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RICrequestID.ricInstanceID = requestId.instanceId;
4744 /* RAN Function ID */
4746 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionID;
4747 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
4748 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_RANfunctionID;
4749 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionID = ranFuncId;
4754 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_CauseE2;
4755 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_ignore;
4756 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_CauseE2;
4757 fillE2FailureCause(&errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.CauseE2, CauseE2_PR_misc, reason);
4760 /* Prints the Msg formed */
4761 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
4762 memset(encBuf, 0, ENC_BUF_MAX_LEN);
4764 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
4766 if(encRetVal.encoded == ENCODE_FAIL)
4768 DU_LOG("\nERROR --> E2AP : Could not encode Error Indication Message (at %s)\n",\
4769 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
4774 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for Error Indication Message \n");
4775 #ifdef DEBUG_ASN_PRINT
4776 for(int i=0; i< encBufSize; i++)
4778 printf("%x",encBuf[i]);
4783 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
4785 DU_LOG("\nINFO --> E2AP : Sending Error Indication Message");
4791 FreeErrorIndication(e2apMsg);
4795 /*******************************************************************
4797 * @brief Deallocate the memory allocated for ResetRequest msg
4801 * Function : FreeResetRequest
4804 * - freeing the memory allocated for ResetRequest
4806 * @params[in] E2AP_PDU_t *e2apMsg
4807 * @return ROK - success
4810 * ****************************************************************/
4811 void FreeResetRequest(E2AP_PDU_t *e2apMsg)
4814 ResetRequestE2_t *resetReq = NULLP;
4816 if(e2apMsg != NULLP)
4818 if(e2apMsg->choice.initiatingMessage != NULLP)
4820 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
4821 if(resetReq->protocolIEs.list.array)
4823 for(ieIdx = 0; ieIdx < resetReq->protocolIEs.list.count; ieIdx++)
4825 RIC_FREE(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
4827 RIC_FREE(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
4829 RIC_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
4831 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
4835 /*******************************************************************
4837 * @brief Build and send the reset request msg
4841 * Function : BuildAndSendResetRequest
4844 * - Buld and send the reset request msg to E2 node
4850 * @return ROK - success
4853 * ****************************************************************/
4854 uint8_t BuildAndSendResetRequest(DuDb *duDb, CauseE2_PR causePresent, uint8_t reason)
4856 uint8_t ieIdx = 0, elementCnt = 0, transId = 0;
4857 uint8_t ret = RFAILED;
4858 E2AP_PDU_t *e2apMsg = NULLP;
4859 ResetRequestE2_t *resetReq = NULLP;
4860 asn_enc_rval_t encRetVal; /* Encoder return value */
4862 DU_LOG("\nINFO --> E2AP : Building Reset Request\n");
4866 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
4867 if(e2apMsg == NULLP)
4869 DU_LOG("\nERROR --> E2AP : BuildAndSendResetRequest(): Memory allocation for E2AP-PDU failed");
4873 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
4874 RIC_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
4875 if(e2apMsg->choice.initiatingMessage == NULLP)
4877 DU_LOG("\nERROR --> E2AP : BuildAndSendResetRequest(): Memory allocation for initiatingMessage");
4881 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_Reset;
4882 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
4883 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ResetRequestE2;
4884 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
4887 resetReq->protocolIEs.list.count = elementCnt;
4888 resetReq->protocolIEs.list.size = elementCnt * sizeof(ResetRequestIEs_t *);
4890 RIC_ALLOC(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
4891 if(!resetReq->protocolIEs.list.array)
4893 DU_LOG("\nERROR --> E2AP : BuildAndSendResetRequest(): Memory allocation failed for \
4894 Reset Request IE array");
4898 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
4900 RIC_ALLOC(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
4901 if(!resetReq->protocolIEs.list.array[ieIdx])
4903 DU_LOG("\nERROR --> E2AP : BuildAndSendResetRequest(): Memory allocation failed for \
4904 Reset Request IE array element");
4909 /* In case of failure */
4910 if(ieIdx < elementCnt)
4914 resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
4915 resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
4916 resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_TransactionID;
4917 transId = assignTransactionId(duDb);
4918 resetReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
4921 resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_CauseE2;
4922 resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_ignore;
4923 resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_CauseE2;
4924 fillE2FailureCause(&resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2, causePresent, reason);
4926 /* Prints the Msg formed */
4927 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
4929 memset(encBuf, 0, ENC_BUF_MAX_LEN);
4931 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
4933 if(encRetVal.encoded == ENCODE_FAIL)
4935 DU_LOG("\nERROR --> E2AP : Could not encode reset request structure (at %s)\n",\
4936 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
4941 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for reset request\n");
4942 #ifdef DEBUG_ASN_PRINT
4943 for(int i=0; i< encBufSize; i++)
4945 printf("%x",encBuf[i]);
4949 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
4951 DU_LOG("\nERROR --> E2AP : Sending reset request failed");
4960 /* Free all memory */
4961 FreeResetRequest(e2apMsg);
4965 /******************************************************************
4967 * @brief Delete Ric subscription node
4971 * Function : deleteRicSubscriptionNode
4973 * Functionality: Delete Ric subscription node
4975 * @params[in] Ric subscription info
4979 * ****************************************************************/
4980 void deleteRicSubscriptionNode(CmLList *subscriptionNode)
4982 uint8_t actionIdx=0;
4983 RicSubscription *ricSubscriptionInfo = NULLP;
4985 ricSubscriptionInfo = (RicSubscription*)subscriptionNode->node;
4987 for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
4989 if(ricSubscriptionInfo->actionSequence[actionIdx].actionId > -1)
4991 memset(&ricSubscriptionInfo->actionSequence[actionIdx], 0, sizeof(ActionInfo));
4994 memset(ricSubscriptionInfo, 0, sizeof(RicSubscription));
4995 RIC_FREE(subscriptionNode->node, sizeof(RicSubscription));
4996 RIC_FREE(subscriptionNode, sizeof(CmLList));
4999 /*******************************************************************
5001 * @brief Delete RIC subscription List
5005 * Function : deleteRicSubscriptionList
5007 * Functionality: Delete RIC subscription list
5009 * @params[in] RIC Subscription list
5013 ******************************************************************/
5014 void deleteRicSubscriptionList(CmLListCp *subscriptionList)
5016 CmLList *subscriptionNode = NULLP;
5018 CM_LLIST_FIRST_NODE(subscriptionList, subscriptionNode);
5019 while(subscriptionNode)
5021 cmLListDelFrm(subscriptionList, subscriptionNode);
5022 deleteRicSubscriptionNode(subscriptionNode);
5023 CM_LLIST_FIRST_NODE(subscriptionList, subscriptionNode);
5027 /*******************************************************************
5029 * @brief process the E2 Reset Response
5033 * Function : ProcResetResponse
5035 * Functionality: Process E2 Reset Response
5039 * Pointer to reset response
5042 ******************************************************************/
5044 void ProcResetResponse(uint32_t duId, ResetResponseE2_t *resetRsp)
5046 uint8_t ieIdx = 0, duIdx =0;
5048 RanFunction *ranFuncDb = NULLP;
5049 uint16_t ranFuncIdx = 0;
5051 SEARCH_DU_DB(duIdx, duId, duDb);
5054 DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
5060 DU_LOG("\nERROR --> E2AP : resetRsp pointer is null");
5064 if(!resetRsp->protocolIEs.list.array)
5066 DU_LOG("\nERROR --> E2AP : resetRsp array pointer is null");
5070 for(ieIdx=0; ieIdx < resetRsp->protocolIEs.list.count; ieIdx++)
5072 if(resetRsp->protocolIEs.list.array[ieIdx])
5074 switch(resetRsp->protocolIEs.list.array[ieIdx]->id)
5076 case ProtocolIE_IDE2_id_TransactionID:
5078 for(ranFuncIdx = 0; ranFuncIdx < MAX_RAN_FUNCTION; ranFuncIdx++)
5080 ranFuncDb = &duDb->ranFunction[ranFuncIdx];
5081 if(ranFuncDb->id > 0)
5083 deleteRicSubscriptionList(&ranFuncDb->subscriptionList);
5088 case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
5098 /*******************************************************************
5100 * @brief process the E2 Reset Request
5104 * Function : ProcResetRequest
5106 * Functionality: Process E2 Reset Request
5110 * Pointer to reset response
5113 ******************************************************************/
5115 void ProcResetRequest(uint32_t duId, ResetRequestE2_t *resetReq)
5117 uint8_t ieIdx = 0, duIdx =0, transId=0;
5119 RanFunction *ranFuncDb = NULLP;
5120 uint16_t ranFuncIdx = 0;
5122 SEARCH_DU_DB(duIdx, duId, duDb);
5125 DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
5131 DU_LOG("\nERROR --> E2AP : resetReq pointer is null");
5135 if(!resetReq->protocolIEs.list.array)
5137 DU_LOG("\nERROR --> E2AP : resetReq array pointer is null");
5141 for(ieIdx=0; ieIdx < resetReq->protocolIEs.list.count; ieIdx++)
5143 if(resetReq->protocolIEs.list.array[ieIdx])
5145 switch(resetReq->protocolIEs.list.array[ieIdx]->id)
5147 case ProtocolIE_IDE2_id_TransactionID:
5149 transId = resetReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
5152 case ProtocolIE_IDE2_id_CauseE2:
5154 for(ranFuncIdx = 0; ranFuncIdx < MAX_RAN_FUNCTION; ranFuncIdx++)
5156 ranFuncDb = &duDb->ranFunction[ranFuncIdx];
5157 if(ranFuncDb->id > 0)
5159 deleteRicSubscriptionList(&ranFuncDb->subscriptionList);
5168 if(BuildAndSendResetResponse(duId, transId) !=ROK)
5170 DU_LOG("\nERROR --> E2AP : Failed to build and send reset response");
5174 /*******************************************************************
5176 * @brief Free RIC Subscription Delete Request Message
5180 * Function : FreeRicSubscriptionDeleteRequest
5182 * Functionality: Free RIC Subscription Delete Request
5184 * @param E2AP Message PDU
5187 ******************************************************************/
5188 void FreeRicSubscriptionDeleteRequest(E2AP_PDU_t *e2apMsg)
5190 uint8_t ieIdx = 0, arrIdx = 0;
5191 RICsubscriptionDeleteRequest_t *ricSubsDelReq = NULLP;
5195 if(e2apMsg->choice.initiatingMessage)
5197 ricSubsDelReq = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionDeleteRequest;
5198 if(ricSubsDelReq->protocolIEs.list.array)
5200 for(ieIdx = 0; ieIdx < ricSubsDelReq->protocolIEs.list.count; ieIdx++)
5202 RIC_FREE(ricSubsDelReq->protocolIEs.list.array[ieIdx], sizeof(RICsubscriptionDeleteRequired_IEs_t));
5204 RIC_FREE(ricSubsDelReq->protocolIEs.list.array, ricSubsDelReq->protocolIEs.list.size);
5206 RIC_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
5208 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));;
5212 /*******************************************************************
5214 * @brief Builds and Send RIC Subscription delete request
5218 * Function : BuildAndSendRicSubscriptionDeleteRequest
5220 * Functionality: Build and send RIC subscription delete request.
5223 * RIC subscription info to be deleted
5224 * @return ROK - success
5227 ******************************************************************/
5228 uint8_t BuildAndSendRicSubscriptionDeleteRequest(uint32_t duId, RicSubscription *ricSubsDb)
5230 uint8_t elementCnt = 0, ieIdx = 0, ret = RFAILED;
5231 E2AP_PDU_t *e2apMsg = NULLP;
5232 RICsubscriptionDeleteRequest_t *ricSubsDelReq = NULLP;
5233 RICsubscriptionDeleteRequest_IEs_t *ricSubsDelReqIe = NULLP;
5234 asn_enc_rval_t encRetVal; /* Encoder return value */
5238 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Delete Request Message\n");
5240 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
5241 if(e2apMsg == NULLP)
5243 DU_LOG("\nERROR --> E2AP : %s: Memory allocation for E2AP-PDU failed at line %d",__func__, __LINE__);
5247 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
5248 RIC_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
5249 if(e2apMsg->choice.initiatingMessage == NULLP)
5251 DU_LOG("\nERROR --> E2AP : %s: Memory allocation for E2AP-PDU failed at line %d",__func__, __LINE__);
5254 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICsubscriptionDelete;
5255 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
5256 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICsubscriptionDeleteRequest;
5258 ricSubsDelReq = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionDeleteRequest;
5261 ricSubsDelReq->protocolIEs.list.count = elementCnt;
5262 ricSubsDelReq->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionDeleteRequest_IEs_t *);
5264 RIC_ALLOC(ricSubsDelReq->protocolIEs.list.array, ricSubsDelReq->protocolIEs.list.size);
5265 if(ricSubsDelReq->protocolIEs.list.array == NULLP)
5267 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed for array elements at line %d",__func__, __LINE__);
5271 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
5273 RIC_ALLOC(ricSubsDelReq->protocolIEs.list.array[ieIdx], sizeof(RICsubscriptionDeleteRequest_IEs_t));
5274 if(ricSubsDelReq->protocolIEs.list.array[ieIdx] == NULLP)
5276 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed for index [%d] at line %d", \
5277 __func__, ieIdx, __LINE__);
5281 if(ieIdx < elementCnt)
5284 /* RIC Request ID */
5286 ricSubsDelReqIe = ricSubsDelReq->protocolIEs.list.array[ieIdx];
5287 ricSubsDelReqIe->id = ProtocolIE_IDE2_id_RICrequestID;
5288 ricSubsDelReqIe->criticality = CriticalityE2_reject;
5289 ricSubsDelReqIe->value.present = RICsubscriptionDeleteRequest_IEs__value_PR_RICrequestID;
5290 ricSubsDelReqIe->value.choice.RICrequestID.ricRequestorID = ricSubsDb->requestId.requestorId;
5291 ricSubsDelReqIe->value.choice.RICrequestID.ricInstanceID = ricSubsDb->requestId.instanceId;
5293 /* RAN Function ID */
5295 ricSubsDelReqIe = ricSubsDelReq->protocolIEs.list.array[ieIdx];
5296 ricSubsDelReqIe->id = ProtocolIE_IDE2_id_RANfunctionID;
5297 ricSubsDelReqIe->criticality = CriticalityE2_reject;
5298 ricSubsDelReqIe->value.present = RICsubscriptionDeleteRequest_IEs__value_PR_RANfunctionID;
5299 ricSubsDelReqIe->value.choice.RANfunctionID = ricSubsDb->ranFuncId;
5301 /* Prints the Msg formed */
5302 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
5303 memset(encBuf, 0, ENC_BUF_MAX_LEN);
5305 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
5306 if(encRetVal.encoded == ENCODE_FAIL)
5308 DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Delete Request Message (at %s)\n",\
5309 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
5314 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Subscription Delete Request Message \n");
5315 #ifdef DEBUG_ASN_PRINT
5316 for(int i=0; i< encBufSize; i++)
5318 printf("%x",encBuf[i]);
5323 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
5325 DU_LOG("\nERROR --> E2AP : Failed to send RIC Susbcription Delete Request Message");
5333 FreeRicSubscriptionDeleteRequest(e2apMsg);
5337 /*******************************************************************
5339 * @brief Processing of RIC Subscription Delete Required
5343 * Function : ProcRicSubsDeleteReqd
5345 * Functionality: Processing of RIC Subscription Delete Required
5346 * When received, RIC stub will initiate the RIC subscription
5347 * deletion procedure towards DU
5350 * RIC Subscription Delete Required IEs
5351 * @return ROK-success
5354 ******************************************************************/
5355 uint8_t ProcRicSubsDeleteReqd(uint32_t duId, RICsubscriptionDeleteRequired_t *ricSubsDelRqd)
5357 uint8_t ieIdx = 0, duIdx = 0;
5358 uint16_t arrIdx = 0;
5360 RicRequestId ricReqId;
5361 RanFunction *ranFuncDb = NULLP;
5362 RicSubscription *subsDb = NULLP;
5363 CmLList *ricSubsNode = NULLP;
5365 RICsubscriptionDeleteRequired_IEs_t *ricSubsDelRqdIe = NULLP;
5366 RICsubscription_List_withCause_t *ricSubsList = NULLP;
5367 RICsubscription_withCause_Item_t *subsItem = NULLP;
5369 memset(&ricReqId, 0, sizeof(RicRequestId));
5373 DU_LOG("\nERROR --> E2AP : %s: Received NULL message", __func__);
5377 SEARCH_DU_DB(duIdx, duId, duDb);
5380 DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
5384 for(ieIdx = 0; ieIdx < ricSubsDelRqd->protocolIEs.list.count; ieIdx++)
5386 ricSubsDelRqdIe = ricSubsDelRqd->protocolIEs.list.array[ieIdx];
5387 switch(ricSubsDelRqdIe->id)
5389 case ProtocolIE_IDE2_id_RICsubscriptionToBeRemoved:
5391 ricSubsList = &ricSubsDelRqdIe->value.choice.RICsubscription_List_withCause;
5392 for(arrIdx = 0; arrIdx < ricSubsList->list.count; arrIdx++)
5394 subsItem = &(((RICsubscription_withCause_ItemIEs_t *)ricSubsList->list.array[arrIdx])->\
5395 value.choice.RICsubscription_withCause_Item);
5396 ranFuncDb = fetchRanFuncFromRanFuncId(duDb, subsItem->ranFunctionID);
5399 DU_LOG("\nERROR --> E2AP : %s: RAN Function ID [%ld] not found", __func__, subsItem->ranFunctionID);
5403 ricReqId.requestorId = subsItem->ricRequestID.ricRequestorID;
5404 ricReqId.instanceId = subsItem->ricRequestID.ricInstanceID;
5405 subsDb = fetchSubsInfoFromRicReqId(ricReqId, ranFuncDb, &ricSubsNode);
5408 DU_LOG("\nERROR --> E2AP : %s: RIC Subscription not found for Requestor_ID [%ld] Instance_ID [%ld]", \
5409 __func__, subsItem->ricRequestID.ricRequestorID, subsItem->ricRequestID.ricInstanceID);
5413 /* Delete RIC Subcription from RAN Function */
5414 cmLListDelFrm(&ranFuncDb->subscriptionList, ricSubsNode);
5416 /* Send RIC Subscription delete request and then free any memory
5417 * allocated to store subscription info at RIC */
5418 BuildAndSendRicSubscriptionDeleteRequest(duId, (RicSubscription *)ricSubsNode->node);
5419 deleteRicSubscriptionNode(ricSubsNode);
5432 /*******************************************************************
5434 * @brief Deallocate memory allocated for E2nodeConfigurationUpdate
5438 * Function : freeE2NodeConfigItem
5441 * - freeing the memory allocated for E2nodeConfigurationUpdate
5444 * uint8_t protocolIe
5445 * PTR to e2NodeCfg which is to be freed
5446 * @return ROK - success
5449 * ****************************************************************/
5451 void freeE2NodeConfigItem(uint8_t protocolIe, PTR e2NodeCfg)
5453 E2nodeComponentConfigurationAck_t *cfgAck =NULLP;
5454 E2nodeComponentInterfaceF1_t *f1InterfaceInfo=NULLP;
5455 E2nodeComponentConfigAdditionAck_Item_t *e2NodeAdditionAckItemIe=NULLP;
5456 E2nodeComponentConfigRemovalAck_Item_t *e2NodeRemovalAckItemIe=NULLP;
5457 E2nodeComponentConfigUpdateAck_Item_t *e2NodeUpdateAckItemIe=NULLP;
5459 /* Extracting the component interface and configuration ack information from
5460 * e2NodeCfg based on the protocol id */
5463 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
5465 e2NodeAdditionAckItemIe= (E2nodeComponentConfigAdditionAck_Item_t*)e2NodeCfg;
5466 switch(e2NodeAdditionAckItemIe->e2nodeComponentInterfaceType)
5468 case E2nodeComponentInterfaceType_f1:
5470 f1InterfaceInfo = e2NodeAdditionAckItemIe->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1;
5479 cfgAck = &e2NodeAdditionAckItemIe->e2nodeComponentConfigurationAck;
5482 case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdateAck:
5484 e2NodeUpdateAckItemIe = (E2nodeComponentConfigUpdateAck_Item_t*)e2NodeCfg;
5485 switch(e2NodeUpdateAckItemIe->e2nodeComponentInterfaceType)
5487 case E2nodeComponentInterfaceType_f1:
5489 f1InterfaceInfo = e2NodeUpdateAckItemIe->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1;
5497 cfgAck = &e2NodeUpdateAckItemIe->e2nodeComponentConfigurationAck;
5500 case ProtocolIE_IDE2_id_E2nodeComponentConfigRemovalAck:
5502 e2NodeRemovalAckItemIe= (E2nodeComponentConfigRemovalAck_Item_t*)e2NodeCfg;
5503 switch(e2NodeRemovalAckItemIe->e2nodeComponentInterfaceType)
5505 case E2nodeComponentInterfaceType_f1:
5507 f1InterfaceInfo = e2NodeRemovalAckItemIe->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1;
5515 cfgAck = &e2NodeRemovalAckItemIe->e2nodeComponentConfigurationAck;
5519 /* Freeing the memory allocated to component interface and configuration ack */
5522 RIC_FREE(f1InterfaceInfo->gNB_DU_ID.buf, f1InterfaceInfo->gNB_DU_ID.size);
5523 RIC_FREE(f1InterfaceInfo, sizeof(E2nodeComponentInterfaceF1_t));
5526 switch(cfgAck->updateOutcome)
5528 case E2nodeComponentConfigurationAck__updateOutcome_success:
5530 case E2nodeComponentConfigurationAck__updateOutcome_failure:
5532 RIC_FREE(cfgAck->failureCauseE2, sizeof(CauseE2_t));
5539 /*******************************************************************
5541 * @brief Deallocate the memory allocated for E2nodeConfigurationUpdate msg
5545 * Function : FreeE2NodeConfigUpdate
5548 * - freeing the memory allocated for E2nodeConfigurationUpdate
5550 * @params[in] E2AP_PDU_t *e2apMsg
5551 * @return ROK - success
5554 * ****************************************************************/
5556 void FreeE2NodeConfigUpdateAck(E2AP_PDU_t *e2apMsg)
5558 uint8_t arrIdx =0, e2NodeConfigIdx=0;
5559 E2nodeConfigurationUpdateAcknowledge_t *updateAckMsg=NULL;
5560 E2nodeComponentConfigUpdateAck_ItemIEs_t *updateAckItemIe=NULL;
5561 E2nodeComponentConfigUpdateAck_List_t *updateAckList=NULL;
5562 E2nodeComponentConfigRemovalAck_ItemIEs_t *removalAckItemIe=NULL;
5563 E2nodeComponentConfigRemovalAck_List_t *removalAckList=NULL;
5564 E2nodeComponentConfigAdditionAck_ItemIEs_t *additionAckItemIte=NULL;
5565 E2nodeComponentConfigAdditionAck_List_t *additionAckList=NULL;
5567 if(e2apMsg != NULLP)
5569 if(e2apMsg->choice.successfulOutcome != NULLP)
5571 updateAckMsg = &e2apMsg->choice.successfulOutcome->value.choice.E2nodeConfigurationUpdateAcknowledge;
5572 if(updateAckMsg->protocolIEs.list.array != NULLP)
5574 for(arrIdx = 0; arrIdx < updateAckMsg->protocolIEs.list.count; arrIdx++)
5576 if(updateAckMsg->protocolIEs.list.array[arrIdx])
5578 switch(updateAckMsg->protocolIEs.list.array[arrIdx]->id)
5580 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
5582 additionAckList =&updateAckMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
5583 if(additionAckList->list.array)
5585 for(e2NodeConfigIdx=0; e2NodeConfigIdx<additionAckList->list.count; e2NodeConfigIdx++)
5587 additionAckItemIte = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) additionAckList->list.array[e2NodeConfigIdx];
5588 if(additionAckItemIte)
5590 freeE2NodeConfigItem(ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck,\
5591 (PTR)&additionAckItemIte->value.choice.E2nodeComponentConfigAdditionAck_Item);
5592 RIC_FREE(additionAckItemIte, sizeof(E2nodeComponentConfigAdditionAck_ItemIEs_t));
5595 RIC_FREE(additionAckList->list.array, additionAckList->list.size);
5599 case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdateAck:
5601 updateAckList =&updateAckMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigUpdateAck_List;
5602 if(updateAckList->list.array)
5604 for(e2NodeConfigIdx=0; e2NodeConfigIdx<updateAckList->list.count; e2NodeConfigIdx++)
5606 updateAckItemIe = (E2nodeComponentConfigUpdateAck_ItemIEs_t*) updateAckList->list.array[e2NodeConfigIdx];
5609 freeE2NodeConfigItem(ProtocolIE_IDE2_id_E2nodeComponentConfigUpdateAck,\
5610 (PTR)&updateAckItemIe->value.choice.E2nodeComponentConfigUpdateAck_Item);
5611 RIC_FREE(updateAckItemIe, sizeof(E2nodeComponentConfigUpdateAck_ItemIEs_t));
5614 RIC_FREE(updateAckList->list.array, updateAckList->list.size);
5618 case ProtocolIE_IDE2_id_E2nodeComponentConfigRemovalAck:
5620 removalAckList =&updateAckMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigRemovalAck_List;
5621 if(removalAckList->list.array)
5623 for(e2NodeConfigIdx=0; e2NodeConfigIdx<removalAckList->list.count; e2NodeConfigIdx++)
5625 removalAckItemIe = (E2nodeComponentConfigRemovalAck_ItemIEs_t*) removalAckList->list.array[e2NodeConfigIdx];
5626 if(removalAckItemIe)
5628 freeE2NodeConfigItem(ProtocolIE_IDE2_id_E2nodeComponentConfigRemovalAck,\
5629 (PTR)&removalAckItemIe->value.choice.E2nodeComponentConfigRemovalAck_Item);
5630 RIC_FREE(removalAckItemIe, sizeof(E2nodeComponentConfigRemovalAck_ItemIEs_t));
5633 RIC_FREE(removalAckList->list.array, removalAckList->list.size);
5638 RIC_FREE(updateAckMsg->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdateAcknowledge_IEs_t));
5641 RIC_FREE(updateAckMsg->protocolIEs.list.array, updateAckMsg->protocolIEs.list.size);
5643 RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
5645 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
5649 /*******************************************************************
5651 * @brief Build E2node Component config Removal ack list
5655 * Function : BuildE2nodeComponentConfigRemovalAck
5657 * Functionality: Build the e2 node remove ack
5660 * E2nodeComponentConfigRemovalAck_List_t to be filled
5661 * Count of e2 node to be removed
5662 * list of e2 node cfg to be removed
5664 * @return ROK - success
5666 * ****************************************************************/
5668 uint8_t BuildE2nodeComponentConfigRemovalAck(E2nodeComponentConfigRemovalAck_List_t *e2NodeConfigRemovalAckList,\
5669 uint16_t removalE2NodeCount, E2NodeConfigItem *removaldE2Node)
5672 E2nodeComponentConfigRemovalAck_ItemIEs_t *e2NodeRemovalAckItem=NULL;
5674 /* Filling the e2 node config removal ack list */
5675 e2NodeConfigRemovalAckList->list.count = removalE2NodeCount;
5676 e2NodeConfigRemovalAckList->list.size = e2NodeConfigRemovalAckList->list.count * sizeof(E2nodeComponentConfigRemovalAck_ItemIEs_t*);
5677 RIC_ALLOC(e2NodeConfigRemovalAckList->list.array, e2NodeConfigRemovalAckList->list.size);
5678 if(e2NodeConfigRemovalAckList->list.array == NULLP)
5680 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigRemovalAck %d",__LINE__);
5684 for(arrIdx = 0; arrIdx< e2NodeConfigRemovalAckList->list.count; arrIdx++)
5686 RIC_ALLOC(e2NodeConfigRemovalAckList->list.array[arrIdx], sizeof(E2nodeComponentConfigRemovalAck_ItemIEs_t));
5687 if(e2NodeConfigRemovalAckList->list.array[arrIdx] == NULLP)
5689 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigRemovalAck %d",__LINE__);
5692 e2NodeRemovalAckItem = (E2nodeComponentConfigRemovalAck_ItemIEs_t*) e2NodeConfigRemovalAckList->list.array[arrIdx];
5693 e2NodeRemovalAckItem->id = ProtocolIE_IDE2_id_E2nodeComponentConfigRemovalAck_Item;
5694 e2NodeRemovalAckItem->criticality = CriticalityE2_reject;
5695 e2NodeRemovalAckItem->value.present = E2nodeComponentConfigRemovalAck_ItemIEs__value_PR_E2nodeComponentConfigRemovalAck_Item;
5697 /* Filling the e2 node config removal ack item */
5698 fillE2NodeConfigAck((PTR)&e2NodeRemovalAckItem->value.choice.E2nodeComponentConfigRemovalAck_Item, ProtocolIE_IDE2_id_E2nodeComponentConfigRemovalAck,\
5699 &removaldE2Node[arrIdx].componentInfo, removaldE2Node[arrIdx].isSuccessful);
5704 /*******************************************************************
5706 * @brief Build E2node Component config update ack list
5710 * Function : BuildE2nodeComponentConfigUpdateAck
5712 * Functionality: Build E2node Component config update ack list
5715 * E2nodeComponentConfigUpdateAck_List to be filled
5716 * Count of e2 node to be update
5717 * list of e2 node cfg to be update
5719 * @return ROK - success
5721 * ****************************************************************/
5723 uint8_t BuildE2nodeComponentConfigUpdateAck(E2nodeComponentConfigUpdateAck_List_t *e2NodeConfigUpdateAckList,\
5724 uint16_t updatedE2NodeCount, E2NodeConfigItem *updatedE2Node)
5727 E2nodeComponentConfigUpdateAck_ItemIEs_t *e2NodeUpdateAckItem=NULL;
5729 /* Filling the e2 node config update ack list */
5730 e2NodeConfigUpdateAckList->list.count = updatedE2NodeCount;
5731 e2NodeConfigUpdateAckList->list.size = e2NodeConfigUpdateAckList->list.count * sizeof(E2nodeComponentConfigUpdateAck_ItemIEs_t*);
5732 RIC_ALLOC(e2NodeConfigUpdateAckList->list.array, e2NodeConfigUpdateAckList->list.size);
5733 if(e2NodeConfigUpdateAckList->list.array == NULLP)
5735 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigUpdateAck %d",__LINE__);
5739 for(arrIdx = 0; arrIdx< e2NodeConfigUpdateAckList->list.count; arrIdx++)
5741 RIC_ALLOC(e2NodeConfigUpdateAckList->list.array[arrIdx], sizeof(E2nodeComponentConfigUpdateAck_ItemIEs_t));
5742 if(e2NodeConfigUpdateAckList->list.array[arrIdx] == NULLP)
5744 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigUpdateAck %d",__LINE__);
5747 e2NodeUpdateAckItem = (E2nodeComponentConfigUpdateAck_ItemIEs_t*) e2NodeConfigUpdateAckList->list.array[arrIdx];
5748 e2NodeUpdateAckItem->id = ProtocolIE_IDE2_id_E2nodeComponentConfigUpdateAck_Item;
5749 e2NodeUpdateAckItem->criticality = CriticalityE2_reject;
5750 e2NodeUpdateAckItem->value.present = E2nodeComponentConfigUpdateAck_ItemIEs__value_PR_E2nodeComponentConfigUpdateAck_Item;
5752 /* Filling the e2 node config update ack item */
5753 fillE2NodeConfigAck((PTR)&e2NodeUpdateAckItem->value.choice.E2nodeComponentConfigUpdateAck_Item, ProtocolIE_IDE2_id_E2nodeComponentConfigUpdateAck,\
5754 &updatedE2Node[arrIdx].componentInfo, updatedE2Node[arrIdx].isSuccessful);
5760 /*******************************************************************
5762 * @brief Buld and send the E2 node config update ack msg
5766 * Function : BuildAndSendE2NodeConfigUpdateAck
5769 * - Buld and send the E2 node config update ack msg
5773 * list of E2 node cfg which needs to fill in IEs
5774 * @return ROK - success
5777 * ****************************************************************/
5779 uint8_t BuildAndSendE2NodeConfigUpdateAck(DuDb *duDb, uint8_t transId, E2NodeConfigList *e2NodeList)
5781 uint8_t ret = RFAILED;
5782 uint8_t arrIdx = 0,elementCnt = 0;
5783 E2AP_PDU_t *e2apMsg = NULLP;
5784 asn_enc_rval_t encRetVal;
5785 E2nodeConfigurationUpdateAcknowledge_t *e2NodeConfigUpdateAck = NULLP;
5787 DU_LOG("\nINFO --> E2AP : Building E2 Node config update Ack Message\n");
5790 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
5791 if(e2apMsg == NULLP)
5793 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__,__LINE__);
5796 e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
5797 RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
5798 if(e2apMsg->choice.successfulOutcome == NULLP)
5800 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__,__LINE__);
5804 e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
5805 e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
5806 e2apMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateAcknowledge;
5807 e2NodeConfigUpdateAck = &e2apMsg->choice.successfulOutcome->value.choice.E2nodeConfigurationUpdateAcknowledge;
5810 if(e2NodeList->addedE2NodeCount)
5812 if(e2NodeList->updatedE2NodeCount)
5814 if(e2NodeList->removedE2NodeCount)
5817 e2NodeConfigUpdateAck->protocolIEs.list.count = elementCnt;
5818 e2NodeConfigUpdateAck->protocolIEs.list.size = elementCnt * sizeof(E2nodeConfigurationUpdateAcknowledge_IEs_t*);
5819 RIC_ALLOC(e2NodeConfigUpdateAck->protocolIEs.list.array, e2NodeConfigUpdateAck->protocolIEs.list.size);
5820 if(e2NodeConfigUpdateAck->protocolIEs.list.array == NULLP)
5822 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__,__LINE__);
5826 for(arrIdx =0; arrIdx<elementCnt; arrIdx++)
5828 RIC_ALLOC(e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdateAcknowledge_IEs_t));
5829 if(e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx] == NULLP)
5832 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__,__LINE__);
5837 if(arrIdx<elementCnt)
5841 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
5842 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
5843 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdateAcknowledge_IEs__value_PR_TransactionID;
5844 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
5846 if(e2NodeList->addedE2NodeCount)
5849 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck;
5850 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
5851 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdateAcknowledge_IEs__value_PR_E2nodeComponentConfigAdditionAck_List;
5852 if(BuildE2nodeComponentConfigAdditionAck(&e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List,\
5853 e2NodeList->addedE2NodeCount, e2NodeList->addedE2Node)!=ROK)
5856 DU_LOG("\nERROR --> E2AP : Failed to build E2Node Component config addition ack list");
5860 if(e2NodeList->updatedE2NodeCount)
5863 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigUpdateAck;
5864 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
5865 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdateAcknowledge_IEs__value_PR_E2nodeComponentConfigUpdateAck_List;
5866 if(BuildE2nodeComponentConfigUpdateAck(&e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigUpdateAck_List,\
5867 e2NodeList->updatedE2NodeCount, e2NodeList->updatedE2Node)!=ROK)
5870 DU_LOG("\nERROR --> E2AP : Failed to build E2Node Component config update ack list");
5874 if(e2NodeList->removedE2NodeCount)
5877 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigRemovalAck;
5878 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
5879 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdateAcknowledge_IEs__value_PR_E2nodeComponentConfigRemovalAck_List;
5880 if(BuildE2nodeComponentConfigRemovalAck(&e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigRemovalAck_List,\
5881 e2NodeList->removedE2NodeCount, e2NodeList->removedE2Node)!=ROK)
5884 DU_LOG("\nERROR --> E2AP : Failed to build E2Node Component config removal ack list");
5888 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
5890 memset(encBuf, 0, ENC_BUF_MAX_LEN);
5892 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
5894 if(encRetVal.encoded == ENCODE_FAIL)
5896 DU_LOG("\nERROR --> E2AP : Could not encode E2 Node config update ack structure (at %s)\n",\
5897 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
5902 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Node config update ack \n");
5903 for(int i=0; i< encBufSize; i++)
5905 DU_LOG("%x",encBuf[i]);
5911 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
5913 DU_LOG("\nERROR --> E2AP : Failed to send E2 Node config update ack ");
5920 FreeE2NodeConfigUpdateAck(e2apMsg);
5925 /******************************************************************
5927 * @brief Processes the E2 removal failure msg
5931 * Function : procE2RemovalFailure
5933 * Functionality: Processes the E2 removal failure msg
5936 * E2 Removal Failure information
5940 * ****************************************************************/
5941 void ProcE2RemovalFailure(E2RemovalFailure_t *e2RemovalFailure)
5943 uint8_t ieIdx = 0, transId=0;
5944 CauseE2_t *cause = NULLP;
5946 if(!e2RemovalFailure)
5948 DU_LOG("\nERROR --> E2AP : e2RemovalFailure pointer is null");
5952 if(!e2RemovalFailure->protocolIEs.list.array)
5954 DU_LOG("\nERROR --> E2AP : e2RemovalFailure array pointer is null");
5958 for(ieIdx=0; ieIdx < e2RemovalFailure->protocolIEs.list.count; ieIdx++)
5960 if(e2RemovalFailure->protocolIEs.list.array[ieIdx])
5962 switch(e2RemovalFailure->protocolIEs.list.array[ieIdx]->id)
5964 case ProtocolIE_IDE2_id_TransactionID:
5966 transId = e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
5967 DU_LOG("\nERROR --> E2AP : Received transID %d", transId);
5970 case ProtocolIE_IDE2_id_CauseE2:
5972 cause = &e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.choice.CauseE2;
5973 printE2ErrorCause(cause);
5978 DU_LOG("\nERROR --> E2AP : Received Invalid Ie [%d]", e2RemovalFailure->protocolIEs.list.array[ieIdx]->id);
5986 /*******************************************************************
5988 * @brief process the E2 node information from ric db
5992 * Function : deleteE2NodeInfo
5994 * Functionality: process the E2 node information from ric db
6001 ******************************************************************/
6002 void deleteE2NodeInfo(DuDb *duDb)
6004 uint16_t ranFuncIdx =0;
6005 RanFunction *ranFuncDb=NULLP;
6007 DU_LOG("\nINFO --> E2AP : Removing all the E2 node information");
6008 for(ranFuncIdx = 0; ranFuncIdx < MAX_RAN_FUNCTION; ranFuncIdx++)
6010 ranFuncDb = &duDb->ranFunction[ranFuncIdx];
6011 if(ranFuncDb->id > 0)
6013 deleteRicSubscriptionList(&ranFuncDb->subscriptionList);
6017 cmInetClose(&sctpCb.e2LstnSockFd);
6020 /*******************************************************************
6022 * @brief process the E2 Removal Response
6026 * Function : ProcE2RemovalResponse
6028 * Functionality: Process E2 Removal Response
6032 * Pointer to removal response
6035 ******************************************************************/
6037 void ProcE2RemovalResponse(uint32_t duId, E2RemovalResponse_t *removalRsp)
6039 uint8_t ieIdx = 0, duIdx =0;
6042 SEARCH_DU_DB(duIdx, duId, duDb);
6045 DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
6051 DU_LOG("\nERROR --> E2AP : removalRsp pointer is null");
6055 if(!removalRsp->protocolIEs.list.array)
6057 DU_LOG("\nERROR --> E2AP : removalRsp array pointer is null");
6061 for(ieIdx=0; ieIdx < removalRsp->protocolIEs.list.count; ieIdx++)
6063 if(removalRsp->protocolIEs.list.array[ieIdx])
6065 switch(removalRsp->protocolIEs.list.array[ieIdx]->id)
6067 case ProtocolIE_IDE2_id_TransactionID:
6069 deleteE2NodeInfo(duDb);
6074 DU_LOG("\nERROR --> E2AP : Received Invalid Ie [%ld]", removalRsp->protocolIEs.list.array[ieIdx]->id);
6081 /*******************************************************************
6083 * @brief Deallocate the memory allocated for E2 Removal Failure
6087 * Function : FreeE2RemovalFailure
6090 * - freeing the memory allocated for E2RemovalFailure
6092 * @params[in] E2AP_PDU_t *e2apMsg
6095 * ****************************************************************/
6096 void FreeE2RemovalFailure(E2AP_PDU_t *e2apMsg)
6099 E2RemovalFailure_t *e2RemovalFailure=NULLP;
6101 if(e2apMsg != NULLP)
6103 if(e2apMsg->choice.unsuccessfulOutcome != NULLP)
6105 e2RemovalFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2RemovalFailure;
6106 if(e2RemovalFailure->protocolIEs.list.array)
6108 for(ieIdx=0; ieIdx < e2RemovalFailure->protocolIEs.list.count; ieIdx++)
6110 if(e2RemovalFailure->protocolIEs.list.array[ieIdx])
6112 RIC_FREE(e2RemovalFailure->protocolIEs.list.array[ieIdx], sizeof(E2RemovalFailureIEs_t));
6115 RIC_FREE(e2RemovalFailure->protocolIEs.list.array, e2RemovalFailure->protocolIEs.list.size);
6117 RIC_FREE(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
6119 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
6123 /*******************************************************************
6125 * @brief Buld and send the E2 Removal Failure msg
6129 * Function : BuildAndSendE2RemovalFailure
6132 * - Buld and send the E2 Removal Failure Message
6138 * @return ROK - success
6141 * ****************************************************************/
6143 uint8_t BuildAndSendRemovalFailure(uint32_t duId, uint16_t transId, CauseE2_PR causePresent, uint8_t reason)
6145 uint8_t ieIdx = 0, elementCnt = 0;
6146 uint8_t ret = RFAILED;
6147 E2AP_PDU_t *e2apMsg = NULLP;
6148 E2RemovalFailure_t *e2RemovalFailure=NULLP;
6149 asn_enc_rval_t encRetVal; /* Encoder return value */
6151 DU_LOG("\nINFO --> E2AP : Building E2 Removal Failure Message\n");
6154 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
6155 if(e2apMsg == NULLP)
6157 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
6160 e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome;
6162 RIC_ALLOC(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
6163 if(e2apMsg->choice.unsuccessfulOutcome == NULLP)
6165 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
6169 e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_E2removal;
6170 e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject;
6171 e2apMsg->choice.unsuccessfulOutcome->value.present = UnsuccessfulOutcomeE2__value_PR_E2RemovalFailure;
6172 e2RemovalFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2RemovalFailure;
6175 e2RemovalFailure->protocolIEs.list.count = elementCnt;
6176 e2RemovalFailure->protocolIEs.list.size = elementCnt * sizeof(E2RemovalFailureIEs_t *);
6177 RIC_ALLOC(e2RemovalFailure->protocolIEs.list.array, e2RemovalFailure->protocolIEs.list.size);
6178 if(!e2RemovalFailure->protocolIEs.list.array)
6180 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
6184 for(ieIdx=0; ieIdx < elementCnt; ieIdx++)
6186 RIC_ALLOC(e2RemovalFailure->protocolIEs.list.array[ieIdx], sizeof(E2RemovalFailureIEs_t));
6187 if(!e2RemovalFailure->protocolIEs.list.array[ieIdx])
6189 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
6193 if(ieIdx < elementCnt)
6197 e2RemovalFailure->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
6198 e2RemovalFailure->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
6199 e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.present = E2RemovalFailureIEs__value_PR_TransactionID;
6200 e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
6204 e2RemovalFailure->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_CauseE2;
6205 e2RemovalFailure->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_ignore;
6206 e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.present = ErrorIndicationE2_IEs__value_PR_CauseE2;
6207 fillE2FailureCause(&e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.choice.CauseE2, causePresent, reason);
6209 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
6211 memset(encBuf, 0, ENC_BUF_MAX_LEN);
6213 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
6214 if(encRetVal.encoded == ENCODE_FAIL)
6216 DU_LOG("\nERROR --> E2AP : Could not encode E2 removal failure structure (at %s)\n",\
6217 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
6222 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Removal Failure \n");
6223 for(int i=0; i< encBufSize; i++)
6225 DU_LOG("%x",encBuf[i]);
6230 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
6232 DU_LOG("\nERROR --> E2AP : Failed to send E2 Removal Failure");
6240 FreeE2RemovalFailure(e2apMsg);
6244 /*******************************************************************
6246 * @brief Deallocate the memory allocated for E2 Removal Response
6250 * Function : FreeE2RemovalResponse
6253 * - freeing the memory allocated for E2RemovalResponse
6255 * @params[in] E2AP_PDU_t *e2apMsg
6256 * @return ROK - success
6259 * ****************************************************************/
6260 void FreeE2RemovalResponse(E2AP_PDU_t *e2apMsg)
6263 E2RemovalResponse_t *e2RemovalResponse=NULLP;
6265 if(e2apMsg != NULLP)
6267 if(e2apMsg->choice.successfulOutcome != NULLP)
6269 e2RemovalResponse = &e2apMsg->choice.successfulOutcome->value.choice.E2RemovalResponse;
6270 if(e2RemovalResponse->protocolIEs.list.array)
6272 for(ieIdx=0; ieIdx < e2RemovalResponse->protocolIEs.list.count; ieIdx++)
6274 if(e2RemovalResponse->protocolIEs.list.array[ieIdx])
6276 RIC_FREE(e2RemovalResponse->protocolIEs.list.array[ieIdx], sizeof(E2RemovalResponseIEs_t));
6279 RIC_FREE(e2RemovalResponse->protocolIEs.list.array, e2RemovalResponse->protocolIEs.list.size);
6281 RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
6283 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
6287 /*******************************************************************
6289 * @brief Buld and send the E2 Removal Response msg
6293 * Function : BuildAndSendE2RemovalResponse
6296 * - Buld and send the E2 Removal Response Message
6300 * @return ROK - success
6303 * ****************************************************************/
6304 uint8_t BuildAndSendRemovalResponse(uint32_t duId, uint16_t transId)
6306 uint8_t ieIdx = 0, elementCnt = 0;
6307 uint8_t ret = RFAILED, duIdx =0;
6308 E2AP_PDU_t *e2apMsg = NULLP;
6310 E2RemovalResponse_t *e2RemovalResponse=NULLP;
6311 asn_enc_rval_t encRetVal; /* Encoder return value */
6313 DU_LOG("\nINFO --> E2AP : Building E2 Removal Response Message\n");
6316 SEARCH_DU_DB(duIdx, duId, duDb);
6319 DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
6323 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
6324 if(e2apMsg == NULLP)
6326 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
6329 e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
6331 RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
6332 if(e2apMsg->choice.successfulOutcome == NULLP)
6334 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
6338 e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_E2removal;
6339 e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
6340 e2apMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_E2RemovalResponse;
6341 e2RemovalResponse = &e2apMsg->choice.successfulOutcome->value.choice.E2RemovalResponse;
6344 e2RemovalResponse->protocolIEs.list.count = elementCnt;
6345 e2RemovalResponse->protocolIEs.list.size = elementCnt * sizeof(E2RemovalResponseIEs_t *);
6346 RIC_ALLOC(e2RemovalResponse->protocolIEs.list.array, e2RemovalResponse->protocolIEs.list.size);
6347 if(!e2RemovalResponse->protocolIEs.list.array)
6349 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
6353 for(ieIdx=0; ieIdx < elementCnt; ieIdx++)
6355 RIC_ALLOC(e2RemovalResponse->protocolIEs.list.array[ieIdx], sizeof(E2RemovalResponseIEs_t));
6356 if(!e2RemovalResponse->protocolIEs.list.array[ieIdx])
6358 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
6362 if(ieIdx < elementCnt)
6366 e2RemovalResponse->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
6367 e2RemovalResponse->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
6368 e2RemovalResponse->protocolIEs.list.array[ieIdx]->value.present = E2RemovalResponseIEs__value_PR_TransactionID;
6369 e2RemovalResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
6371 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
6373 memset(encBuf, 0, ENC_BUF_MAX_LEN);
6375 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
6376 if(encRetVal.encoded == ENCODE_FAIL)
6378 DU_LOG("\nERROR --> E2AP : Could not encode E2 removal response structure (at %s)\n",\
6379 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
6384 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Removal Response \n");
6385 for(int i=0; i< encBufSize; i++)
6387 DU_LOG("%x",encBuf[i]);
6392 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
6394 DU_LOG("\nERROR --> E2AP : Failed to send E2 Removal Response");
6402 FreeE2RemovalResponse(e2apMsg);
6403 deleteE2NodeInfo(duDb);
6407 /*******************************************************************
6409 * @brief Process Removal req received from RIC
6413 * Function : procE2RemovalRequest
6415 * Functionality: Process Removal req received from RIC
6419 * E2 Removal Request
6422 ******************************************************************/
6424 void procE2RemovalRequest(uint32_t duId, E2RemovalRequest_t *removalReq)
6427 uint16_t transId =0;
6429 DU_LOG("\nINFO --> E2AP : E2 Removal request received");
6431 for(arrIdx=0; arrIdx<removalReq->protocolIEs.list.count; arrIdx++)
6433 switch(removalReq->protocolIEs.list.array[arrIdx]->id)
6435 case ProtocolIE_IDE2_id_TransactionID:
6437 transId = removalReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
6442 DU_LOG("\nERROR --> E2AP : Invalid IE recevied [%d]", transId);
6448 if(transId>=0 && transId<=255)
6450 if(BuildAndSendRemovalResponse(duId, transId) != ROK)
6452 DU_LOG("\nERROR --> E2AP : Failed to build and send Removal response");
6457 if(BuildAndSendRemovalFailure(duId, transId, CauseE2_PR_protocol, CauseE2Protocol_abstract_syntax_error_falsely_constructed_message) != ROK)
6459 DU_LOG("\nERROR --> E2AP : Failed to build and send Removal response");
6464 /*******************************************************************
6466 * @brief Handles received E2AP message and sends back response
6470 * Function : E2APMsgHdlr
6473 * - Decodes received E2AP control message
6474 * - Prepares response message, encodes and sends to SCTP
6477 * @return ROK - success
6480 * ****************************************************************/
6481 void E2APMsgHdlr(uint32_t *duId, Buffer *mBuf)
6487 E2AP_PDU_t *e2apMsg;
6488 asn_dec_rval_t rval; /* Decoder return value */
6489 E2AP_PDU_t e2apasnmsg ;
6491 DU_LOG("\nINFO --> E2AP : Received E2AP message buffer");
6492 ODU_PRINT_MSG(mBuf, 0,0);
6494 /* Copy mBuf into char array to decode it */
6495 ODU_GET_MSG_LEN(mBuf, &recvBufLen);
6496 RIC_ALLOC(recvBuf, (Size)recvBufLen);
6498 if(recvBuf == NULLP)
6500 DU_LOG("\nERROR --> E2AP : Memory allocation failed");
6503 if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
6505 DU_LOG("\nERROR --> E2AP : Failed while copying %d", copyCnt);
6509 DU_LOG("\nDEBUG --> E2AP : Received flat buffer to be decoded : ");
6510 for(i=0; i< recvBufLen; i++)
6512 DU_LOG("%x",recvBuf[i]);
6515 /* Decoding flat buffer into E2AP messsage */
6516 e2apMsg = &e2apasnmsg;
6517 memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
6519 rval = aper_decode(0, &asn_DEF_E2AP_PDU, (void **)&e2apMsg, recvBuf, recvBufLen, 0, 0);
6520 RIC_FREE(recvBuf, (Size)recvBufLen);
6522 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
6524 DU_LOG("\nERROR --> E2AP : ASN decode failed");
6528 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
6530 switch(e2apMsg->present)
6532 case E2AP_PDU_PR_initiatingMessage:
6534 switch(e2apMsg->choice.initiatingMessage->value.present)
6536 case InitiatingMessageE2__value_PR_E2setupRequest:
6538 DU_LOG("\nINFO --> E2AP : E2 setup request received");
6539 ProcE2SetupReq(duId, &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest);
6542 case InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate:
6544 DU_LOG("\nINFO --> E2AP : E2 node config update received");
6545 ProcE2NodeConfigUpdate(*duId, &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate);
6548 case InitiatingMessageE2__value_PR_ResetRequestE2:
6550 DU_LOG("\nINFO --> E2AP : E2 Reset Request received");
6551 ProcResetRequest(*duId, &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2);
6554 case InitiatingMessageE2__value_PR_RICindication:
6556 DU_LOG("\nINFO --> E2AP : RIC Indication received");
6559 case InitiatingMessageE2__value_PR_RICserviceUpdate:
6561 DU_LOG("\nINFO --> E2AP : RIC Service update received");
6562 ProcRicServiceUpdate(*duId, &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate);
6565 case InitiatingMessageE2__value_PR_RICsubscriptionModificationRequired:
6567 DU_LOG("\nINFO --> E2AP : RIC Subscription Modification Required");
6568 ProcRicSubsModReqd(*duId, \
6569 &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionModificationRequired);
6572 case InitiatingMessageE2__value_PR_RICsubscriptionDeleteRequired:
6574 DU_LOG("\nINFO --> E2AP : RIC Subscription Delete Required");
6575 ProcRicSubsDeleteReqd(*duId, \
6576 &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionDeleteRequired);
6580 case InitiatingMessageE2__value_PR_ErrorIndicationE2:
6582 DU_LOG("\nINFO --> E2AP : Error indication received");
6585 case InitiatingMessageE2__value_PR_E2RemovalRequest:
6587 DU_LOG("\nINFO --> E2AP : E2 Removal request received");
6588 procE2RemovalRequest(*duId,\
6589 &e2apMsg->choice.initiatingMessage->value.choice.E2RemovalRequest);
6594 DU_LOG("\nERROR --> E2AP : Invalid type of intiating message [%d]", \
6595 e2apMsg->choice.initiatingMessage->value.present);
6598 }/* End of switch(initiatingMessage) */
6601 case E2AP_PDU_PR_successfulOutcome:
6603 switch(e2apMsg->choice.successfulOutcome->value.present)
6605 case SuccessfulOutcomeE2__value_PR_ResetResponseE2:
6607 DU_LOG("\nINFO --> E2AP : Reset response received");
6608 ProcResetResponse(*duId, &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2);
6611 case SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse:
6613 ProcRicSubscriptionResponse(*duId, \
6614 &e2apMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse);
6617 case SuccessfulOutcomeE2__value_PR_E2RemovalResponse:
6619 ProcE2RemovalResponse(*duId, &e2apMsg->choice.successfulOutcome->value.choice.E2RemovalResponse);
6624 DU_LOG("\nERROR --> E2AP : Invalid type of successfulOutcome message [%d]", \
6625 e2apMsg->choice.successfulOutcome->value.present);
6632 case E2AP_PDU_PR_unsuccessfulOutcome:
6634 switch(e2apMsg->choice.successfulOutcome->value.present)
6636 case UnsuccessfulOutcomeE2__value_PR_RICsubscriptionFailure:
6638 ProcRicSubscriptionFailure(*duId, \
6639 &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionFailure);
6642 case UnsuccessfulOutcomeE2__value_PR_E2RemovalFailure:
6644 ProcE2RemovalFailure(&e2apMsg->choice.unsuccessfulOutcome->value.choice.E2RemovalFailure);
6649 DU_LOG("\nERROR --> E2AP : Invalid type of unsuccessfulOutcome message [%d]", \
6650 e2apMsg->choice.unsuccessfulOutcome->value.present);
6658 DU_LOG("\nERROR --> E2AP : Invalid type message type ");
6662 }/* End of switch(e2apMsg->present) */
6663 } /* End of E2APMsgHdlr */
6666 /**********************************************************************
6668 **********************************************************************/