1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
18 #include "common_def.h"
24 #include "du_app_mac_inf.h"
25 #include "du_app_rlc_inf.h"
26 #include "du_e2ap_mgr.h"
27 #include "du_e2ap_msg_hdl.h"
30 #include "du_mgr_main.h"
32 #include "GlobalE2node-gNB-ID.h"
33 #include "ProtocolIE-FieldE2.h"
34 #include "E2setupRequest.h"
35 #include "InitiatingMessageE2.h"
36 #include "SuccessfulOutcomeE2.h"
37 #include "UnsuccessfulOutcomeE2.h"
39 #include "odu_common_codec.h"
40 #include "E2nodeComponentInterfaceF1.h"
41 #include "E2setupRequest.h"
42 #include "du_e2_conversions.h"
43 #include "E2SM-KPM-RANfunction-Description.h"
44 #include "RANfunction-Name.h"
45 #include "RIC-EventTriggerStyle-Item.h"
46 #include "RIC-ReportStyle-Item.h"
47 #include "MeasurementInfo-Action-Item.h"
48 #include "E2SM-KPM-EventTriggerDefinition.h"
49 #include "E2SM-KPM-EventTriggerDefinition-Format1.h"
50 #include "E2SM-KPM-ActionDefinition.h"
51 #include "E2SM-KPM-ActionDefinition-Format1.h"
52 #include "MeasurementInfoItem.h"
53 #include "RANfunctionsIDcause-List.h"
55 /*******************************************************************
57 * @brief Fill E2 Failure Cause
61 * Function : fillE2Cause
63 * Functionality: Fill E2 Failure Cause
65 * @params[in] E2 Cause pointer to be filled in
66 * E2 Cause to be filled from
69 ******************************************************************/
70 void fillE2Cause(CauseE2_t *e2Cause, E2FailureCause failureCause)
72 e2Cause->present = failureCause.causeType;
73 switch(e2Cause->present)
75 case CauseE2_PR_ricRequest:
77 e2Cause->choice.ricRequest = failureCause.cause;
80 case CauseE2_PR_ricService:
82 e2Cause->choice.ricService = failureCause.cause;
85 case CauseE2_PR_e2Node:
87 e2Cause->choice.e2Node = failureCause.cause;
90 case CauseE2_PR_transport:
92 e2Cause->choice.transport = failureCause.cause;
95 case CauseE2_PR_protocol:
97 e2Cause->choice.protocol = failureCause.cause;
100 case CauseE2_PR_misc:
102 e2Cause->choice.misc = failureCause.cause;
105 case CauseE2_PR_NOTHING:
111 /*******************************************************************
113 * @brief Builds Global gNodeB Params
117 * Function : BuildGlobalgNBId
119 * Functionality: Building the Plmn and gNB id
121 * @params[in] GlobalE2node_gNB_ID_t *gNbId
122 * @return ROK - success
125 ******************************************************************/
127 uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
130 uint8_t byteSize = 4;
131 uint8_t gnbId = duCb.gnbId;
134 /* fill Global gNB ID Id */
135 gNbId->global_gNB_ID.plmn_id.size = 3 * sizeof(uint8_t);
136 gNbId->global_gNB_ID.plmn_id.buf = NULLP;
137 DU_ALLOC(gNbId->global_gNB_ID.plmn_id.buf , gNbId->global_gNB_ID.plmn_id.size);
138 if(gNbId->global_gNB_ID.plmn_id.buf == NULLP)
140 DU_LOG("\nERROR --> E2AP: Memory allocation failed for Plmn buffer");
145 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
146 gNbId->global_gNB_ID.plmn_id.buf);
147 gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
148 /* Allocate Buffer size */
149 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = byteSize * sizeof(uint8_t);
150 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf = NULLP;
151 DU_ALLOC(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf, \
152 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
153 if(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf == NULLP)
155 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gnb buffer");
160 fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, gnbId);
165 DU_ALLOC( gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
166 if(gNbId->gNB_DU_ID == NULLP)
168 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gNB_DU_ID ");
173 gNbId->gNB_DU_ID->size = sizeof(uint8_t);
174 DU_ALLOC( gNbId->gNB_DU_ID->buf, sizeof(uint8_t));
175 if(gNbId->gNB_DU_ID->buf)
177 gNbId->gNB_DU_ID->buf[0] =duCb.e2apDb.e2NodeId;
181 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gNB_DU_ID buffer");
189 /******************************************************************
191 * @brief Search E2 node component with the help of action type
195 * Function : searchE2NodeComponentInfo
197 * Functionality: Search E2 node component with the help of action type
199 * @params[in] uint8_t componentActionType
202 * ****************************************************************/
204 CmLList *searchE2NodeComponentInfo(InterfaceType interfaceType, uint8_t componentActionType)
206 E2NodeComponent *e2NodeComponentInfo;
209 if(duCb.e2apDb.e2NodeComponentList.count)
211 CM_LLIST_FIRST_NODE(&duCb.e2apDb.e2NodeComponentList, node);
214 e2NodeComponentInfo = (E2NodeComponent*)node->node;
215 if((e2NodeComponentInfo->interfaceType == interfaceType) && (e2NodeComponentInfo->componentActionType == componentActionType))
224 /*******************************************************************
226 * @brief Builds E2 node config addition list
230 * Function : BuildE2NodeConfigAddList
232 * Functionality: Building E2 node config addition list
234 * @params[in] E2nodeComponentConfigAddition_List_t *e2NodeAddList
235 * @return ROK - success
238 ******************************************************************/
240 uint8_t BuildE2NodeConfigAddList(E2nodeComponentConfigAddition_List_t *e2NodeAddList)
244 E2NodeComponent *e2NodeComponentInfo;
245 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItemIe;
246 E2nodeComponentConfigAddition_Item_t *e2NodeAddItem;
248 e2NodeAddList->list.count = 1;
249 e2NodeAddList->list.size = e2NodeAddList->list.count * sizeof(E2nodeComponentConfigAddition_ItemIEs_t *);
250 DU_ALLOC(e2NodeAddList->list.array, e2NodeAddList->list.size);
251 if(e2NodeAddList->list.array == NULLP)
253 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
257 for(arrIdx = 0; arrIdx< e2NodeAddList->list.count; arrIdx++)
259 DU_ALLOC(e2NodeAddList->list.array[arrIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
260 if(e2NodeAddList->list.array[arrIdx] == NULLP)
262 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
267 node = searchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD);
270 DU_LOG("\nERROR --> E2AP : Received e2NodeComponentInfo is null");
273 e2NodeComponentInfo = (E2NodeComponent*)node->node;
276 e2NodeAddItemIe = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[arrIdx];
277 e2NodeAddItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition_Item;
278 e2NodeAddItemIe->criticality = CriticalityE2_reject;
279 e2NodeAddItemIe->value.present = E2nodeComponentConfigAddition_ItemIEs__value_PR_E2nodeComponentConfigAddition_Item;
280 e2NodeAddItem = &e2NodeAddItemIe->value.choice.E2nodeComponentConfigAddition_Item;
282 /* E2nodeComponentInterfaceType */
283 e2NodeAddItem->e2nodeComponentInterfaceType = E2nodeComponentInterfaceType_f1;
285 /* E2 Node Component Request Part */
286 if(e2NodeComponentInfo->componentRequestPart)
288 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size = e2NodeComponentInfo->reqBufSize ;
289 DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
290 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
291 if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf == NULLP)
293 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
297 memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
298 e2NodeComponentInfo->componentRequestPart, e2NodeAddItem->e2nodeComponentConfiguration.\
299 e2nodeComponentRequestPart.size);
303 DU_LOG("\nERROR --> E2AP: componentRequestPart is null ");
308 /* E2 Node Component Response Part */
309 if(e2NodeComponentInfo->componentResponsePart)
311 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size = e2NodeComponentInfo->rspBufSize;
312 DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \
313 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
314 if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf == NULLP)
316 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
319 memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \
320 e2NodeComponentInfo->componentResponsePart, e2NodeAddItem->e2nodeComponentConfiguration.\
321 e2nodeComponentResponsePart.size);
325 DU_LOG("\nERROR --> E2AP: componentResponsePart is null");
329 /* E2 Node Component ID */
330 e2NodeAddItem->e2nodeComponentID.present = E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1;
331 DU_ALLOC(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
332 sizeof(E2nodeComponentInterfaceF1_t));
333 if(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1 == NULLP)
335 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
338 e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size = sizeof(uint8_t);
339 DU_ALLOC(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
340 e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
342 if(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf == NULLP)
344 DU_LOG("\nERROR -->list. E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
347 e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[arrIdx] = e2NodeComponentInfo->componentId;
352 /*******************************************************************
354 * @brief deallocation of E2SM_KPM_RANfunction_Description_t
358 * Function : freeE2smKpmRanFunctionDefinition
360 * Functionality: deallocation of E2SM_KPM_RANfunction_Description_t
362 * @params[in] E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition
365 ******************************************************************/
367 void freeE2smKpmRanFunctionDefinition(E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition)
369 MeasurementInfo_Action_Item_t *measInfoList;
370 uint8_t eventTriggerIdx, reportStyleIdx, measInfoIdx;
371 RANfunction_Name_t *ranFuncName;
372 struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle;
373 struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *eventTriggerStyle;
374 if(ranFunctionDefinition)
376 ranFuncName = &ranFunctionDefinition->ranFunction_Name;
377 /* Free RAN function Name */
378 DU_FREE(ranFuncName->ranFunction_ShortName.buf, ranFuncName->ranFunction_ShortName.size);
379 DU_FREE(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
380 DU_FREE(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
382 /* Sequence of Event Trigger styles */
383 eventTriggerStyle = ranFunctionDefinition->ric_EventTriggerStyle_List;
384 if(eventTriggerStyle)
386 if(eventTriggerStyle->list.array)
388 for(eventTriggerIdx =0;eventTriggerIdx<eventTriggerStyle->list.count; eventTriggerIdx++)
390 if(eventTriggerStyle->list.array[eventTriggerIdx])
392 DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.buf,\
393 eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.size);
394 DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
397 DU_FREE(eventTriggerStyle->list.array, eventTriggerStyle->list.size)
399 DU_FREE(eventTriggerStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
402 /* Sequence of Report styles */
403 ricReportStyle = ranFunctionDefinition->ric_ReportStyle_List;
406 if(ricReportStyle->list.array)
408 for(reportStyleIdx =0;reportStyleIdx<ricReportStyle->list.count; reportStyleIdx++)
410 if(ricReportStyle->list.array[reportStyleIdx])
412 if(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf)
414 DU_FREE(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf,\
415 ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.size);
417 if(ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array)
419 for(measInfoIdx=0; measInfoIdx<ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.count; \
422 measInfoList = ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array[measInfoIdx];
425 DU_FREE(measInfoList->measID, sizeof(long));
426 DU_FREE(measInfoList->measName.buf, measInfoList->measName.size);
427 DU_FREE(measInfoList,sizeof(MeasurementInfo_Action_Item_t));
430 DU_FREE(measInfoList,ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.size);
432 DU_FREE(ricReportStyle->list.array[reportStyleIdx], sizeof(RIC_ReportStyle_Item_t));
435 DU_FREE(ricReportStyle->list.array, ricReportStyle->list.size);
437 DU_FREE(ricReportStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
439 DU_FREE(ranFunctionDefinition, sizeof(E2SM_KPM_RANfunction_Description_t));
443 /*******************************************************************
445 * @brief fill the e2sm ric report style
449 * Function : fillRicReportStyle
451 * Functionality: fill the report style
453 * @params[in] RanFunction *ranFuncDb, struct
454 * E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle
455 * @return ROK - success
458 ******************************************************************/
459 uint8_t fillRicReportStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle)
461 uint8_t styleIdx, measInfoIdx;
462 MeasurementInfo_Action_List_t *measInfo;
465 ricReportStyle->list.count = ranFuncDb->numOfReportStyleSupported;
466 ricReportStyle->list.size = ricReportStyle->list.count * sizeof(RIC_ReportStyle_Item_t*);
467 DU_ALLOC(ricReportStyle->list.array, ricReportStyle->list.size);
468 if(!ricReportStyle->list.array)
470 DU_LOG("\nERROR --> E2AP: Memory allocation failed for ranFuncDefinition %d",__LINE__);
474 for(styleIdx =0;styleIdx<ricReportStyle->list.count; styleIdx++)
476 DU_ALLOC(ricReportStyle->list.array[styleIdx], sizeof(RIC_ReportStyle_Item_t));
477 if(!ricReportStyle->list.array[styleIdx])
479 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
483 /* RIC Report Style Type */
484 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.styleType;
486 /* RIC Report Style Format Type */
487 ricReportStyle->list.array[styleIdx]->ric_ActionFormat_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.formatType;
489 /* RIC Report Style Name */
490 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size = strlen(ranFuncDb->reportStyleList[styleIdx].reportStyle.name);
491 DU_ALLOC(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf,\
492 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
493 if(!ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf)
495 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
498 memcpy(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf, ranFuncDb->reportStyleList[styleIdx].reportStyle.name,\
499 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
501 /* RIC Indication Header Format Type*/
502 ricReportStyle->list.array[styleIdx]->ric_IndicationHeaderFormat_Type = ranFuncDb->ricIndicationHeaderFormat;
504 /* RIC Indication Message Format Type*/
505 ricReportStyle->list.array[styleIdx]->ric_IndicationMessageFormat_Type = ranFuncDb->ricIndicationMessageFormat;
507 /* Measurement Info Action List */
508 CmLListCp measInfoList =ranFuncDb->reportStyleList[styleIdx].measurementInfoList;
509 if(!measInfoList.count)
514 CM_LLIST_FIRST_NODE(&ranFuncDb->reportStyleList[styleIdx].measurementInfoList, node);
515 measInfo = &ricReportStyle->list.array[styleIdx]->measInfo_Action_List;
517 measInfo->list.count = measInfoList.count;
518 measInfo->list.size = measInfoList.count*sizeof(MeasurementInfo_Action_Item_t*);
519 DU_ALLOC(measInfo->list.array, measInfo->list.size);
520 if(!measInfo->list.array)
522 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
526 for(measInfoIdx=0; measInfoIdx<measInfo->list.count; measInfoIdx++)
530 DU_LOG("\nERROR --> E2AP: Measurement info node is null");
534 DU_ALLOC(measInfo->list.array[measInfoIdx],sizeof(MeasurementInfo_Action_Item_t));
535 if(!measInfo->list.array[measInfoIdx])
537 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
540 MeasurementInfoForAction *measInfoForAction= (MeasurementInfoForAction*)node->node;
541 DU_ALLOC(measInfo->list.array[measInfoIdx]->measID, sizeof(long));
542 if(!measInfo->list.array[measInfoIdx]->measID)
544 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
548 memcpy(measInfo->list.array[measInfoIdx]->measID, &measInfoForAction->measurementTypeId,sizeof(long));
549 measInfo->list.array[measInfoIdx]->measName.size= strlen(measInfoForAction->measurementTypeName);
550 DU_ALLOC(measInfo->list.array[measInfoIdx]->measName.buf, measInfo->list.array[measInfoIdx]->measName.size);
551 if(!measInfo->list.array[measInfoIdx]->measName.size)
553 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
557 memcpy(measInfo->list.array[measInfoIdx]->measName.buf, \
558 measInfoForAction->measurementTypeName,\
559 measInfo->list.array[measInfoIdx]->measName.size);
566 /*******************************************************************
568 * @brief fill the ric event trigger style
572 * Function : fillRicEventTriggerStyle
574 * Functionality: fill the ric event trigger style
577 * @return ROK - success
580 ******************************************************************/
581 uint8_t fillRicEventTriggerStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *ricEventTriggerStyle)
585 ricEventTriggerStyle->list.count = ranFuncDb->numOfEventTriggerStyleSupported;
586 ricEventTriggerStyle->list.size = ricEventTriggerStyle->list.count* sizeof(RIC_EventTriggerStyle_Item_t *);
587 DU_ALLOC(ricEventTriggerStyle->list.array, ricEventTriggerStyle->list.size);
588 if(!ricEventTriggerStyle->list.array)
590 DU_LOG("\nERROR --> E2AP: Memory allocation failed for ric_EventTriggerStyle_List %d",__LINE__);
594 for(styleIdx =0;styleIdx<ricEventTriggerStyle->list.count; styleIdx++)
596 DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
597 if(!ricEventTriggerStyle->list.array[styleIdx])
599 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
602 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Type = ranFuncDb->eventTriggerStyleList[styleIdx].styleType;
604 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerFormat_Type = ranFuncDb->eventTriggerStyleList[styleIdx].formatType;
606 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size = strlen(ranFuncDb->eventTriggerStyleList[styleIdx].name);
607 DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,\
608 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
609 if(!ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf)
611 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
614 memcpy(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,ranFuncDb->eventTriggerStyleList[styleIdx].name,\
615 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
621 /*******************************************************************
623 * @brief Builds Ran function item
627 * Function : BuildRanFunctionItem
629 * Functionality: Building RAN function item
632 * RAN function item that has to be filled
633 * Stored RAN Function information
634 * @return ROK - success
637 ******************************************************************/
639 uint8_t BuildRanFunctionItem(RANfunction_Item_t *ranFuncItem, RanFunction *ranFuncDb)
641 uint8_t ret =RFAILED;
642 RANfunctionDefinition_t *ranFunctionDefinition;
643 RANfunction_Name_t *ranFuncName;
644 asn_enc_rval_t encRetVal;
645 E2SM_KPM_RANfunction_Description_t *ranFuncDefinition;
650 ranFuncItem->ranFunctionID = ranFuncDb->id;
652 /* RAN Function Revision*/
653 ranFuncItem->ranFunctionRevision = ranFuncDb->revisionCounter;
655 /* RAN function OID*/
656 ranFuncItem->ranFunctionOID.size = strlen(ranFuncDb->name.serviceModelOID);
657 DU_ALLOC(ranFuncItem->ranFunctionOID.buf, ranFuncItem->ranFunctionOID.size);
658 if(!ranFuncItem->ranFunctionOID.buf)
660 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
663 memcpy(ranFuncItem->ranFunctionOID.buf, ranFuncDb->name.serviceModelOID, ranFuncItem->ranFunctionOID.size);
665 /* RAN function Definition */
666 DU_ALLOC(ranFuncDefinition, sizeof(E2SM_KPM_RANfunction_Description_t));
667 if(!ranFuncDefinition)
669 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
673 /* RAN function Name */
674 ranFuncName = &ranFuncDefinition->ranFunction_Name;
676 /* RAN function ShortName */
677 ranFuncName->ranFunction_ShortName.size = strlen(ranFuncDb->name.shortName);
678 DU_ALLOC(ranFuncName->ranFunction_ShortName.buf, ranFuncName->ranFunction_ShortName.size);
679 if(!ranFuncName->ranFunction_ShortName.buf)
681 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
684 memcpy(ranFuncName->ranFunction_ShortName.buf, ranFuncDb->name.shortName, strlen(ranFuncDb->name.shortName));
686 /* RAN function E2SM_OID */
687 ranFuncName->ranFunction_E2SM_OID.size = strlen(ranFuncDb->name.serviceModelOID);
688 DU_ALLOC(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
689 if(!ranFuncName->ranFunction_E2SM_OID.buf)
691 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
694 memcpy(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncDb->name.serviceModelOID, ranFuncName->ranFunction_E2SM_OID.size);
696 /* RAN Function Name Description */
697 ranFuncName->ranFunction_Description.size = strlen(ranFuncDb->name.description);
698 DU_ALLOC(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
699 if(!ranFuncName->ranFunction_Description.buf)
701 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
704 memcpy(ranFuncName->ranFunction_Description.buf, ranFuncDb->name.description, ranFuncName->ranFunction_Description.size);
706 /* RIC Event Trigger Style List */
707 DU_ALLOC(ranFuncDefinition->ric_EventTriggerStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
708 if(!ranFuncDefinition->ric_EventTriggerStyle_List)
710 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
714 if(fillRicEventTriggerStyle(ranFuncDb, ranFuncDefinition->ric_EventTriggerStyle_List)!=ROK)
716 DU_LOG("\nERROR --> E2AP: failed to fill ric event trigger style");
720 /* RIC Report Style List */
721 DU_ALLOC(ranFuncDefinition->ric_ReportStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
722 if(!ranFuncDefinition->ric_ReportStyle_List)
724 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
727 if(fillRicReportStyle(ranFuncDb, ranFuncDefinition->ric_ReportStyle_List) != ROK)
729 DU_LOG("\nERROR --> E2AP: failed to fill ric report style");
733 /* Encode the F1SetupRequest type as APER */
734 xer_fprint(stdout, &asn_DEF_E2SM_KPM_RANfunction_Description, ranFuncDefinition);
736 memset(encBuf, 0, ENC_BUF_MAX_LEN);
738 encRetVal = aper_encode(&asn_DEF_E2SM_KPM_RANfunction_Description, 0, ranFuncDefinition, PrepFinalEncBuf, encBuf);
741 if(encRetVal.encoded == ENCODE_FAIL)
743 DU_LOG("\nERROR --> F1AP : Could not encode RAN function definition (at %s)\n",\
744 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
749 DU_LOG("\nDEBUG --> F1AP : Created APER encoded buffer for RAN function definition \n");
750 for(uint8_t measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
752 printf("%x",encBuf[measIeIdx]);
754 ranFunctionDefinition = &ranFuncItem->ranFunctionDefinition;
755 ranFunctionDefinition->size = encBufSize;
756 DU_ALLOC(ranFunctionDefinition->buf, encBufSize);
757 if(ranFunctionDefinition->buf == NULLP)
759 DU_LOG("\nERROR --> F1AP : Memory allocation failed for RAN function definition buffer");
762 memcpy(ranFunctionDefinition->buf, &encBuf, encBufSize);
767 freeE2smKpmRanFunctionDefinition(ranFuncDefinition);
771 /*******************************************************************
773 * @brief Builds Ran function add list based on the procedure code
777 * Function : BuildRanFunctionAddList
779 * Functionality: Building RAN addition addition list
780 * In case of ProcedureCodeE2_id_E2setup we add all the RAN Function list
781 * which is present in E2 database.
782 * In the case of other procedures, we just fill the RAN functions whose ID
783 * is contained in recvList
788 * Count of ran functions to be added in the list
789 * Received list of RAN functions
791 * @return ROK - success
794 ******************************************************************/
796 uint8_t BuildRanFunctionAddList(RANfunctions_List_t *ranFunctionsList, uint8_t procedureCode, uint8_t count, RanFuncInfo *recvList)
799 RanFunction *ranFuncDb;
801 RANfunction_ItemIEs_t *ranFuncItemIe;
803 /* For ProcedureCodeE2_id_E2setup, the number of RAN function list items is
804 * equal to the number of ran function entries stored in the database.
805 * For any other procedure, the RAN function list count is equal
806 * to the count of ran functions obtained from the function's caller */
808 if(procedureCode == ProcedureCodeE2_id_E2setup)
809 ranFunctionsList->list.count = duCb.e2apDb.numOfRanFunction;
811 ranFunctionsList->list.count = count;
813 ranFunctionsList->list.size = ranFunctionsList->list.count * sizeof(RANfunction_ItemIEs_t*);
814 DU_ALLOC(ranFunctionsList->list.array, ranFunctionsList->list.size);
815 if(ranFunctionsList->list.array == NULLP)
817 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
821 for(ranFuncIdx = 0; ranFuncIdx< ranFunctionsList->list.count; ranFuncIdx++)
823 DU_ALLOC(ranFunctionsList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
824 if(ranFunctionsList->list.array[ranFuncIdx] == NULLP)
826 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
829 if(procedureCode == ProcedureCodeE2_id_E2setup)
831 /* Getting all of the RAN function's information from DuCb one by one*/
832 ranFuncDb = &duCb.e2apDb.ranFunction[ranFuncIdx];
836 /* Getting only the RAN function information from DuCb whose Id is
837 * present in the received array */
838 id =recvList[ranFuncIdx].id;
839 ranFuncDb = &duCb.e2apDb.ranFunction[id-1];
841 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncIdx];
842 ranFuncItemIe->id = ProtocolIE_IDE2_id_RANfunction_Item;
843 ranFuncItemIe->criticality = CriticalityE2_ignore;
844 ranFuncItemIe->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
845 BuildRanFunctionItem(&ranFuncItemIe->value.choice.RANfunction_Item, ranFuncDb);
850 /*******************************************************************
852 * @brief De Allocate E2 Setup Request Message
856 * Function : FreeE2SetupReq
858 * Functionality: De-Allocating E2 Setup request Message
860 * @params[in] E2AP_PDU_t *e2apMsg
864 * ****************************************************************/
866 void FreeE2SetupReq(E2AP_PDU_t *e2apMsg)
869 uint8_t e2NodeAddListIdx =0, ranFuncAddListIdx;
870 E2setupRequest_t *e2SetupReq;
871 E2nodeComponentConfigAddition_List_t *e2NodeAddList;
872 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem;
873 RANfunctions_List_t *ranFunctionsList;
874 RANfunction_ItemIEs_t *ranFuncItemIe;
875 RANfunction_Item_t *ranFunItem;
877 /* De-allocating Memory */
880 if(e2apMsg->choice.initiatingMessage != NULLP)
882 e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
883 if(e2SetupReq->protocolIEs.list.array != NULLP)
885 for(arrIdx = 0; arrIdx < e2SetupReq->protocolIEs.list.count; arrIdx++)
887 if(e2SetupReq->protocolIEs.list.array[arrIdx] != NULLP)
889 switch(e2SetupReq->protocolIEs.list.array[arrIdx]->id)
891 case ProtocolIE_IDE2_id_TransactionID:
893 case ProtocolIE_IDE2_id_GlobalE2node_ID:
895 if(e2SetupReq->protocolIEs.list.array[arrIdx]->\
896 value.choice.GlobalE2node_ID.choice.gNB != NULLP)
898 GlobalE2node_gNB_ID_t *gNbId = NULLP;
899 gNbId = e2SetupReq->protocolIEs.list.array[arrIdx]->\
900 value.choice.GlobalE2node_ID.choice.gNB;
901 if(gNbId->global_gNB_ID.plmn_id.buf != NULLP)
903 DU_FREE(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf,\
904 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
905 DU_FREE(gNbId->global_gNB_ID.plmn_id.buf,\
906 gNbId->global_gNB_ID.plmn_id.size);
909 if(gNbId->gNB_DU_ID != NULLP)
911 DU_FREE( gNbId->gNB_DU_ID->buf, gNbId->gNB_DU_ID->size);
912 DU_FREE(gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
914 DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
915 choice.GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
919 case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
921 e2NodeAddList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List;
922 if(e2NodeAddList->list.array)
924 for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++)
926 e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[e2NodeAddListIdx];
928 /* Free E2 Node Component Request Part */
929 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
930 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
932 /* Free E2 Node Component Response Part */
933 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.\
934 e2nodeComponentResponsePart.buf, \
935 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
937 /* Free E2 Node Component ID */
938 if(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1)
940 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
941 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
942 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
943 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
944 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
945 sizeof(E2nodeComponentInterfaceF1_t));
947 DU_FREE(e2NodeAddList->list.array[e2NodeAddListIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
949 DU_FREE(e2NodeAddList->list.array, e2NodeAddList->list.size);
953 case ProtocolIE_IDE2_id_RANfunctionsAdded:
955 ranFunctionsList = &(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List);
956 if(ranFunctionsList->list.array)
958 for(ranFuncAddListIdx= 0; ranFuncAddListIdx< ranFunctionsList->list.count; ranFuncAddListIdx++)
960 if(ranFunctionsList->list.array[ranFuncAddListIdx])
962 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncAddListIdx];
963 ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
964 DU_FREE(ranFunItem->ranFunctionOID.buf, ranFunItem->ranFunctionOID.size);
965 DU_FREE(ranFunItem->ranFunctionDefinition.buf, ranFunItem->ranFunctionDefinition.size);
966 DU_FREE(ranFunctionsList->list.array[ranFuncAddListIdx], sizeof(RANfunction_ItemIEs_t));
969 DU_FREE(ranFunctionsList->list.array, ranFunctionsList->list.size);
975 DU_LOG("\nERROR --> E2AP: Invalid event at e2SetupRequet %ld ",\
976 (e2SetupReq->protocolIEs.list.array[arrIdx]->id));
979 DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx], sizeof(E2setupRequestIEs_t));
982 DU_FREE(e2SetupReq->protocolIEs.list.array, e2SetupReq->protocolIEs.list.size);
984 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
986 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
990 /*******************************************************************
992 * @brief Builds and Send the E2SetupRequest
996 * Function : BuildAndSendE2SetupReq
998 * Functionality:Fills the E2SetupRequest
1000 * @return ROK - success
1003 ******************************************************************/
1005 uint8_t BuildAndSendE2SetupReq()
1007 uint8_t arrIdx = 0, elementCnt=0;
1008 uint8_t transId = 0, ret = ROK;
1009 bool memAllocFailed;
1010 E2AP_PDU_t *e2apMsg = NULLP;
1011 E2setupRequest_t *e2SetupReq = NULLP;
1012 asn_enc_rval_t encRetVal; /* Encoder return value */
1014 DU_LOG("\nINFO --> E2AP : Building E2 Setup Request\n");
1017 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
1018 if(e2apMsg == NULLP)
1020 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1023 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
1024 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1025 if(e2apMsg->choice.initiatingMessage == NULLP)
1027 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1030 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
1031 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2setup;
1032 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_E2setupRequest;
1033 e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
1036 e2SetupReq->protocolIEs.list.count = elementCnt;
1037 e2SetupReq->protocolIEs.list.size = elementCnt * sizeof(E2setupRequestIEs_t*);
1039 /* Initialize the E2Setup members */
1040 DU_ALLOC(e2SetupReq->protocolIEs.list.array, \
1041 e2SetupReq->protocolIEs.list.size);
1042 if(e2SetupReq->protocolIEs.list.array == NULLP)
1044 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements");
1047 for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
1049 DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx],\
1050 sizeof(E2setupRequestIEs_t));
1051 if(e2SetupReq->protocolIEs.list.array[arrIdx] == NULLP)
1053 memAllocFailed = true;
1054 DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayarrIdx [%d]", arrIdx);
1058 if(memAllocFailed == true)
1064 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
1065 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1066 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
1067 transId = assignTransactionId();
1068 e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
1071 /* GlobalE2node_gNB_ID */
1072 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_GlobalE2node_ID;
1073 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1074 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
1075 e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
1077 DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
1078 GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
1079 if(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
1080 GlobalE2node_ID.choice.gNB == NULLP)
1082 DU_LOG("\nERROR --> E2AP : Memory allocation failed for gNbId");
1087 ret = BuildGlobalgNBId(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
1088 choice.GlobalE2node_ID.choice.gNB);
1091 DU_LOG("\nERROR --> E2AP : Failed to build Global Gnb Id");
1096 /* RAN Functions Added List */
1098 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
1099 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1100 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_RANfunctions_List;
1101 if(BuildRanFunctionAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List), ProcedureCodeE2_id_E2setup, 0, NULL)!=ROK)
1103 DU_LOG("\nERROR --> E2AP : Failed to create RAN Function");
1107 /* E2 Node Component Configuration Addition List */
1109 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition;
1110 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1111 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_E2nodeComponentConfigAddition_List;
1112 if(BuildE2NodeConfigAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List))!=ROK)
1114 DU_LOG("\nERROR --> E2AP : Failed to create E2 Node config list");
1120 /* Prints the Msg formed */
1121 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1123 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1125 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
1127 if(encRetVal.encoded == ENCODE_FAIL)
1129 DU_LOG("\nERROR --> E2AP : Could not encode E2SetupRequest structure (at %s)\n",\
1130 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1135 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupRequest\n");
1136 #ifdef DEBUG_ASN_PRINT
1137 for(int i=0; i< encBufSize; i++)
1139 printf("%x",encBuf[i]);
1143 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
1145 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
1150 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
1151 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
1153 FreeE2SetupReq(e2apMsg);
1155 }/* End of BuildAndSendE2SetupReq */
1157 /*******************************************************************
1159 * @brief Builds RIC Action Admitted List
1163 * Function : BuildRicActionAdmitList
1165 * Functionality: Builds RIC Action Admitted List
1167 * @params[in] Pointer to RIC Action Admitted List to be filled
1168 * Subscription Response information
1169 * @return ROK - success
1172 * ****************************************************************/
1173 uint8_t BuildRicActionAdmitList(RICaction_Admitted_List_t *admitList, PendingSubsRspInfo *subsRspInfo)
1176 uint8_t elementCnt = 0;
1177 RICaction_Admitted_ItemIEs_t *admitItem = NULLP;
1179 elementCnt = subsRspInfo->numOfAcceptedActions;
1181 admitList->list.count = elementCnt;
1182 admitList->list.size = elementCnt * sizeof(RICaction_Admitted_ItemIEs_t *);
1184 DU_ALLOC(admitList->list.array, admitList->list.size);
1185 if(admitList->list.array == NULLP)
1187 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1191 for(idx=0; idx<elementCnt; idx++)
1193 DU_ALLOC(admitList->list.array[idx], sizeof(RICaction_Admitted_ItemIEs_t));
1194 if(admitList->list.array[idx] == NULLP)
1196 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1200 admitItem = (RICaction_Admitted_ItemIEs_t *)admitList->list.array[idx];
1201 admitItem->id = ProtocolIE_IDE2_id_RICaction_Admitted_Item;
1202 admitItem->criticality = CriticalityE2_reject;
1203 admitItem->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
1204 admitItem->value.choice.RICaction_Admitted_Item.ricActionID = subsRspInfo->acceptedActionList[idx];
1209 /*******************************************************************
1211 * @brief Builds RIC Action Not Admitted List
1215 * Function : BuildRicActionNotAdmitList
1217 * Functionality: Builds RIC Action Not Admitted List
1219 * @params[in] Pointer to RIC Action Not Admitted List to be filled
1220 * Subscription Response information
1221 * @return ROK - success
1224 * ****************************************************************/
1225 uint8_t BuildRicActionNotAdmitList(RICaction_NotAdmitted_List_t *notAdmitList, PendingSubsRspInfo *subsRspInfo)
1228 uint8_t elementCnt = 0;
1229 RICaction_NotAdmitted_ItemIEs_t *notAdmitItem = NULLP;
1231 elementCnt = subsRspInfo->numOfRejectedActions;
1233 notAdmitList->list.count = elementCnt;
1234 notAdmitList->list.size = elementCnt * sizeof(RICaction_NotAdmitted_ItemIEs_t *);
1236 DU_ALLOC(notAdmitList->list.array, notAdmitList->list.size);
1237 if(notAdmitList->list.array == NULLP)
1239 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1243 for(idx=0; idx<elementCnt; idx++)
1245 DU_ALLOC(notAdmitList->list.array[idx], sizeof(RICaction_NotAdmitted_ItemIEs_t));
1246 if(notAdmitList->list.array[idx] == NULLP)
1248 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1252 notAdmitItem = (RICaction_NotAdmitted_ItemIEs_t *)notAdmitList->list.array[idx];
1253 notAdmitItem->id = ProtocolIE_IDE2_id_RICaction_NotAdmitted_Item;
1254 notAdmitItem->criticality = CriticalityE2_reject;
1255 notAdmitItem->value.present = RICaction_NotAdmitted_ItemIEs__value_PR_RICaction_NotAdmitted_Item;
1256 notAdmitItem->value.choice.RICaction_NotAdmitted_Item.ricActionID = \
1257 subsRspInfo->rejectedActionList[idx].id;
1258 fillE2Cause(¬AdmitItem->value.choice.RICaction_NotAdmitted_Item.cause, \
1259 subsRspInfo->rejectedActionList[idx].failureCause);
1264 /*******************************************************************
1266 * @breif Deallocation of BuildAndSendRicSubscriptionRsp memory
1270 * Function : FreeRicSubscriptionRsp
1272 * Functionality:Free the RicSubscriptionRsp
1274 * @param[in] E2AP_PDU_t *e2apRicMsg
1278 ******************************************************************/
1279 void FreeRicSubscriptionRsp(E2AP_PDU_t *e2apRicMsg)
1281 RICsubscriptionResponse_t *ricSubscriptionRsp= NULLP;
1284 RICaction_Admitted_List_t *admitList = NULLP;
1285 RICaction_NotAdmitted_List_t *notAdmitList = NULLP;
1287 if(e2apRicMsg != NULLP)
1289 if(e2apRicMsg->choice.successfulOutcome != NULLP)
1291 ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
1292 if(ricSubscriptionRsp)
1294 if(ricSubscriptionRsp->protocolIEs.list.array != NULLP)
1296 for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
1298 if(ricSubscriptionRsp->protocolIEs.list.array[idx] != NULLP)
1300 switch(ricSubscriptionRsp->protocolIEs.list.array[idx]->id)
1302 case ProtocolIE_IDE2_id_RICactions_Admitted:
1304 admitList = &ricSubscriptionRsp->protocolIEs.list.\
1305 array[idx]->value.choice.RICaction_Admitted_List;
1306 if(admitList->list.array != NULLP)
1308 for(listIdx=0 ; listIdx < admitList->list.count; listIdx++)
1310 DU_FREE(admitList->list.array[listIdx], sizeof(RICaction_Admitted_ItemIEs_t));
1312 DU_FREE(admitList->list.array, admitList->list.size);
1316 case ProtocolIE_IDE2_id_RICactions_NotAdmitted:
1318 notAdmitList = &ricSubscriptionRsp->protocolIEs.list.\
1319 array[idx]->value.choice.RICaction_NotAdmitted_List;
1320 if(notAdmitList->list.array != NULLP)
1322 for(listIdx=0 ; listIdx < notAdmitList->list.count; listIdx++)
1324 DU_FREE(notAdmitList->list.array[listIdx], sizeof(RICaction_NotAdmitted_ItemIEs_t));
1326 DU_FREE(notAdmitList->list.array, notAdmitList->list.size);
1333 DU_FREE(ricSubscriptionRsp->protocolIEs.list.array[idx], sizeof(RICsubscriptionResponse_IEs_t));
1336 DU_FREE(ricSubscriptionRsp->protocolIEs.list.array, ricSubscriptionRsp->protocolIEs.list.size);
1339 DU_FREE(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
1341 DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
1345 /*******************************************************************
1347 * @brief Fill RIC Subscription Response IEs
1351 * Function : fillRicSubscriptionRsp
1353 * functionality: Fill RIC Subscription Response IEs
1355 * @param Pointer to RIC subscription response
1356 * Subscription response information
1357 * @return ROK - success
1360 ******************************************************************/
1361 uint8_t fillRicSubscriptionRsp(RICsubscriptionResponse_t *ricSubscriptionRsp, PendingSubsRspInfo *subsRspInfo)
1364 uint8_t elementCnt = 0;
1365 RICsubscriptionResponse_IEs_t *subsRspIe = NULLP;
1368 if(subsRspInfo->numOfRejectedActions)
1371 ricSubscriptionRsp->protocolIEs.list.count = elementCnt;
1372 ricSubscriptionRsp->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionResponse_IEs_t);
1373 DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array, ricSubscriptionRsp->protocolIEs.list.size);
1374 if(ricSubscriptionRsp->protocolIEs.list.array == NULLP)
1376 DU_LOG("\nERROR --> E2AP : Memory allocation failed at %s : line %d", __func__, __LINE__);
1380 for(ieIdx=0; ieIdx<ricSubscriptionRsp->protocolIEs.list.count; ieIdx++)
1382 DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array[ieIdx], sizeof(RICsubscriptionResponse_IEs_t));
1383 if(ricSubscriptionRsp->protocolIEs.list.array[ieIdx] == NULLP)
1385 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d] : ieIdx [%d]", __func__, __LINE__,ieIdx);
1390 /* RIC Request ID */
1392 subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
1393 subsRspIe->id = ProtocolIE_IDE2_id_RICrequestID;
1394 subsRspIe->criticality = CriticalityE2_reject;
1395 subsRspIe->value.present = RICsubscriptionRequest_IEs__value_PR_RICrequestID;
1396 subsRspIe->value.choice.RICrequestID.ricRequestorID = subsRspInfo->requestId.requestorId;
1397 subsRspIe->value.choice.RICrequestID.ricInstanceID = subsRspInfo->requestId.instanceId;
1399 /* RAN Function ID */
1401 subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
1402 subsRspIe->id = ProtocolIE_IDE2_id_RANfunctionID;
1403 subsRspIe->criticality = CriticalityE2_reject;
1404 subsRspIe->value.present = RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
1405 subsRspIe->value.choice.RANfunctionID = subsRspInfo->ranFuncId;
1407 /* RIC Action Admitted List */
1409 subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
1410 subsRspIe->id = ProtocolIE_IDE2_id_RICactions_Admitted;
1411 subsRspIe->criticality = CriticalityE2_reject;
1412 subsRspIe->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
1413 if(BuildRicActionAdmitList(&subsRspIe->value.choice.RICaction_Admitted_List, subsRspInfo) != ROK)
1415 DU_LOG("\nERROR --> E2AP : Failed to fill RIC Action Admitted List in RIC Subscription Response");
1419 /* RIC Action Not Admitted List */
1420 if(subsRspInfo->numOfRejectedActions)
1423 subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
1424 subsRspIe->id = ProtocolIE_IDE2_id_RICactions_NotAdmitted;
1425 subsRspIe->criticality = CriticalityE2_reject;
1426 subsRspIe->criticality = CriticalityE2_reject;
1427 subsRspIe->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_NotAdmitted_List;
1428 if(BuildRicActionNotAdmitList(&subsRspIe->value.choice.RICaction_NotAdmitted_List, subsRspInfo) != ROK)
1430 DU_LOG("\nERROR --> E2AP : Failed to fill RIC Action Not Admitted List in RIC Subscription Response");
1438 /*******************************************************************
1440 * @brief Builds and Send the RicSubscriptionRsp
1444 * Function : BuildAndSendRicSubscriptionRsp
1446 * Functionality:Fills the RicSubscriptionRsp
1448 * @return ROK - success
1451 ******************************************************************/
1453 uint8_t BuildAndSendRicSubscriptionRsp(PendingSubsRspInfo *subsRspInfo)
1455 uint8_t ret = RFAILED;
1456 E2AP_PDU_t *e2apRicMsg = NULLP;
1457 RICsubscriptionResponse_t *ricSubscriptionRsp=NULLP;
1458 asn_enc_rval_t encRetVal;
1462 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Response\n");
1464 DU_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t));
1465 if(e2apRicMsg == NULLP)
1467 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1471 e2apRicMsg->present = E2AP_PDU_PR_successfulOutcome;
1472 DU_ALLOC(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
1473 if(e2apRicMsg->choice.successfulOutcome == NULLP)
1475 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC subscription Response failed");
1479 e2apRicMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
1480 e2apRicMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
1481 e2apRicMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse;
1483 ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
1485 if(fillRicSubscriptionRsp(ricSubscriptionRsp, subsRspInfo) != ROK)
1487 DU_LOG("\nERROR --> E2AP : Memory allocation for RICsubscriptionResponseIE failed");
1491 /* Prints the Msg formed */
1492 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg);
1494 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1496 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apRicMsg, PrepFinalEncBuf, encBuf);
1497 if(encRetVal.encoded == ENCODE_FAIL)
1499 DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Response structure (at %s)\n",\
1500 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1505 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC subscription response \n");
1506 #ifdef DEBUG_ASN_PRINT
1507 for(int i=0; i< encBufSize; i++)
1509 printf("%x",encBuf[i]);
1514 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
1516 DU_LOG("\nERROR --> E2AP : Sending RIC Subscription Response failed");
1525 FreeRicSubscriptionRsp(e2apRicMsg);
1529 /******************************************************************
1531 * @brief Deallocation of memory allocated bu aper decoder for e2 setup response
1535 * Function : freeAperDecodingOfE2SetupRsp
1537 * Functionality: Deallocation of memory allocated bu aper decoder for e2
1540 * @params[in] E2setupResponse_t *e2SetRspMsg;
1543 * ****************************************************************/
1544 void freeAperDecodingOfE2SetupRsp(E2setupResponse_t *e2SetRspMsg)
1546 uint8_t arrIdx, e2NodeConfigAddAckListIdx;
1547 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem;
1548 E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAddAckList;
1552 if(e2SetRspMsg->protocolIEs.list.array)
1554 for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
1556 if(e2SetRspMsg->protocolIEs.list.array[arrIdx])
1558 switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
1560 case ProtocolIE_IDE2_id_TransactionID:
1563 case ProtocolIE_IDE2_id_GlobalRIC_ID:
1565 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.pLMN_Identity.buf);
1566 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID.buf);
1570 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
1572 e2NodeConfigAddAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
1573 if(e2NodeConfigAddAckList->list.array )
1575 for(e2NodeConfigAddAckListIdx = 0; e2NodeConfigAddAckListIdx< e2NodeConfigAddAckList->list.count; e2NodeConfigAddAckListIdx++)
1577 if(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx])
1579 e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx];
1580 free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
1581 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf);
1582 free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
1583 e2nodeComponentInterfaceTypeF1);
1584 free(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx]);
1587 free(e2NodeConfigAddAckList->list.array);
1592 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]);
1595 free(e2SetRspMsg->protocolIEs.list.array);
1599 /******************************************************************
1601 * @brief Processes E2 Setup Response sent by RIC
1605 * Function : procE2SetupRsp
1607 * Functionality: Processes E2 Setup Response sent by RIC
1609 * @params[in] E2AP_PDU_t ASN decoded E2AP message
1610 * @return ROK - success
1613 * ****************************************************************/
1614 uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
1616 uint8_t arrIdx =0, transId=0;
1617 uint32_t recvBufLen;
1618 E2setupResponse_t *e2SetRspMsg;
1620 E2NodeComponent *e2NodeComponentInfo;
1622 DU_LOG("\nINFO --> E2AP : E2 Setup Response received");
1623 duCb.e2Status = TRUE; //Set E2 status as true
1624 e2SetRspMsg = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
1626 for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
1628 switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
1630 case ProtocolIE_IDE2_id_TransactionID:
1632 transId = e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
1633 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
1634 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
1636 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
1640 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
1646 case ProtocolIE_IDE2_id_GlobalRIC_ID:
1648 /* To store the Ric Id Params */
1649 recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value\
1650 .choice.GlobalRIC_ID.pLMN_Identity.size);
1651 memcpy(&duCb.e2apDb.ricId.plmnId, e2SetRspMsg->protocolIEs.list.array[arrIdx]\
1652 ->value.choice.GlobalRIC_ID.pLMN_Identity.buf, recvBufLen);
1653 bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID, &duCb.e2apDb.ricId);
1654 /*TODO : duCb.e2apDb.ricId.plmnId memory to be deallocated after the usage */
1658 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
1662 DU_LOG("\nERROR --> E2AP : Invalid IE received in E2SetupRsp:%ld",
1663 e2SetRspMsg->protocolIEs.list.array[arrIdx]->id);
1667 freeAperDecodingOfE2SetupRsp(e2SetRspMsg);
1669 node = searchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD);
1672 DU_LOG("\nERROR --> E2AP : Received e2NodeComponentInfo is null");
1677 e2NodeComponentInfo = (E2NodeComponent*)node->node;
1678 cmLListDelFrm(&duCb.e2apDb.e2NodeComponentList, node);
1679 DU_FREE(e2NodeComponentInfo->componentRequestPart, e2NodeComponentInfo->reqBufSize);
1680 DU_FREE(e2NodeComponentInfo->componentResponsePart, e2NodeComponentInfo->rspBufSize);
1681 DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
1682 DU_FREE(node, sizeof(CmLList));
1685 BuildAndSendE2NodeConfigUpdate();
1689 /*******************************************************************
1691 * @brief Free RIC Subscription Request
1695 * Function : freeAperDecodingOfRicSubsReq
1697 * Functionality : Free RIC Subscription Request
1701 ******************************************************************/
1702 void freeAperDecodingOfRicSubsReq(RICsubscriptionRequest_t *ricSubscriptionReq)
1705 uint8_t elementIdx = 0;
1706 RICsubscriptionDetails_t *subsDetails = NULLP;
1707 RICaction_ToBeSetup_ItemIEs_t *actionItem = NULLP;
1709 if(ricSubscriptionReq->protocolIEs.list.array)
1711 for(idx=0; idx < ricSubscriptionReq->protocolIEs.list.count; idx++)
1713 switch(ricSubscriptionReq->protocolIEs.list.array[idx]->id)
1715 case ProtocolIE_IDE2_id_RICsubscriptionDetails:
1717 subsDetails = &(ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails);
1718 free(subsDetails->ricEventTriggerDefinition.buf);
1720 if(subsDetails->ricAction_ToBeSetup_List.list.array)
1722 for(elementIdx = 0; elementIdx < subsDetails->ricAction_ToBeSetup_List.list.count; elementIdx++)
1724 if(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx])
1726 actionItem = (RICaction_ToBeSetup_ItemIEs_t *)subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx];
1727 if(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition)
1729 free(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->buf);
1730 free(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition);
1732 free(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx]);
1735 free(subsDetails->ricAction_ToBeSetup_List.list.array);
1740 free(ricSubscriptionReq->protocolIEs.list.array[idx]);
1742 free(ricSubscriptionReq->protocolIEs.list.array);
1746 /*******************************************************************
1748 * @brief Free Event Trigger Definition
1752 * Function : freeAperDecodingOfEventTriggerDef
1754 * Functionality: Free Event Trigger Definition
1756 * @params[in] E2SM-KPM Event Trigger Definition
1759 * ****************************************************************/
1760 void freeAperDecodingOfEventTriggerDef(E2SM_KPM_EventTriggerDefinition_t *eventTiggerDef)
1764 switch(eventTiggerDef->eventDefinition_formats.present)
1766 case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING:
1769 case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_eventDefinition_Format1:
1770 free(eventTiggerDef->eventDefinition_formats.choice.eventDefinition_Format1);
1776 /*******************************************************************
1778 * @brief Extract E2SM-KPM Event trigger definition
1782 * Function : extractEventTriggerDef
1784 * Functionality : This function :
1785 * - Decodes E2SM-KPM Event Trigger Definition
1786 * - Validates that even trigger style is supported by E2 node
1787 * - Stores event trigger details in local DB
1789 * @params[in] RAN Function Database structure
1790 * RIC Subscription Info to be added to RAN function
1791 * RIC Event Trigger Definition buffer received from RIC
1792 * @return ROK - success
1795 ******************************************************************/
1796 uint8_t extractEventTriggerDef(RanFunction *ranFuncDb, RicSubscription *ricSubscriptionInfo, \
1797 RICeventTriggerDefinition_t *ricEventTriggerDef, E2FailureCause *failureCause)
1799 uint8_t ret = RFAILED;
1800 uint8_t eventIdx = 0;
1801 asn_dec_rval_t rval ={0};
1802 E2SM_KPM_EventTriggerDefinition_t eventTiggerDef, *eventTiggerDefPtr = NULLP;
1804 /* Decoding E2SM-KPM Even Trigger Definition */
1805 eventTiggerDefPtr = &eventTiggerDef;
1806 memset(eventTiggerDefPtr, 0, sizeof(E2SM_KPM_EventTriggerDefinition_t));
1808 rval = aper_decode(0, &asn_DEF_E2SM_KPM_EventTriggerDefinition, (void **)&eventTiggerDefPtr, ricEventTriggerDef->buf,\
1809 ricEventTriggerDef->size, 0, 0);
1810 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
1812 DU_LOG("\nERROR --> E2AP : ASN decode failed for E2SM-KPM Event Trigger Definition");
1813 failureCause->causeType = E2_PROTOCOL;
1814 failureCause->cause = E2_ABSTRACT_SYNTAX_ERROR_FALSELY_CONSTRUCTED_MESSAGE;
1818 xer_fprint(stdout, &asn_DEF_E2SM_KPM_EventTriggerDefinition, eventTiggerDefPtr);
1820 /* Validating the received event trigger definition format */
1821 for(eventIdx = 0; eventIdx < ranFuncDb->numOfEventTriggerStyleSupported; eventIdx++)
1823 if((eventTiggerDefPtr->eventDefinition_formats.present != \
1824 E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING) && \
1825 (eventTiggerDefPtr->eventDefinition_formats.present == ranFuncDb->eventTriggerStyleList[eventIdx].formatType))
1827 ricSubscriptionInfo->eventTriggerDefinition.formatType = ranFuncDb->eventTriggerStyleList[eventIdx].formatType;
1828 ricSubscriptionInfo->eventTriggerDefinition.choice.format1.reportingPeriod = \
1829 eventTiggerDefPtr->eventDefinition_formats.choice.eventDefinition_Format1->reportingPeriod;
1838 failureCause->causeType = E2_RIC_REQUEST;
1839 failureCause->cause = E2_EVENT_TRIGGER_NOT_SUPPORTED;
1841 /* Free E2SM_KPM_EventTriggerDefinition_t */
1842 freeAperDecodingOfEventTriggerDef(eventTiggerDefPtr);
1846 /*******************************************************************
1848 * @brief Free RIC Action Definition
1852 * Function : freeAperDecodingOfRicActionDefinition
1854 * Functionality: Free RIC Action Definition
1856 * @params[in] E2SM-KPM Action definition
1859 * ****************************************************************/
1860 void freeAperDecodingOfRicActionDefinition(E2SM_KPM_ActionDefinition_t *actionDef)
1862 uint8_t elementIdx = 0;
1863 E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
1864 MeasurementInfoItem_t *measItem = NULLP;
1866 switch(actionDef->actionDefinition_formats.present)
1868 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1:
1870 if(actionDef->actionDefinition_formats.choice.actionDefinition_Format1)
1872 actionFormat1 = actionDef->actionDefinition_formats.choice.actionDefinition_Format1;
1873 if(actionFormat1->measInfoList.list.array)
1875 for(elementIdx = 0; elementIdx < actionFormat1->measInfoList.list.count; elementIdx++)
1877 if(actionFormat1->measInfoList.list.array[elementIdx])
1879 measItem = actionFormat1->measInfoList.list.array[elementIdx];
1880 switch(measItem->measType.present)
1882 case MeasurementType_PR_NOTHING:
1885 case MeasurementType_PR_measName:
1887 free(measItem->measType.choice.measName.buf);
1891 case MeasurementType_PR_measID:
1897 free(actionFormat1->measInfoList.list.array);
1899 free(actionFormat1);
1903 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format2:
1904 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format3:
1905 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format4:
1906 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format5:
1912 /*******************************************************************
1914 * @brief Extract Measurement Info list from action definition
1918 * Function : extractMeasInfoList
1920 * Functionality : This function :
1921 * - Traverses Measurement-to-be-subscribed list
1922 * - Validates that each measurement in Measurement-to-be-subscribed
1923 * list is supported in RAN-Function->Measurement-supported list.
1924 * - If all measurements in an action is supported by RAN function,
1925 * it is added to measurement-subscribed list in local DB
1927 * @params[in] Measurement Info supported list by RAN function
1928 * Measurement Info to be subscribed as requested by RIC
1929 * Measurement Info finally subscribed
1930 * Memory failure indicator
1931 * @return ROK - success
1934 ******************************************************************/
1935 uint8_t extractMeasInfoList(CmLListCp *measInfoSupportedList, MeasurementInfoList_t *measInfoToBeSubscribedList, \
1936 CmLListCp *measInfoSubscribedList, bool *memFailure)
1938 uint8_t elementIdx = 0;
1939 MeasurementInfoForAction *measInfoSupportedDb = NULLP;
1940 MeasurementInfo *measInfoSubscribedDb = NULLP, *measInfoToDel = NULLP;
1941 CmLList *supportedMeasNode = NULLP, *measToAddNode = NULLP, *measToDelNode = NULLP;;
1942 MeasurementInfoItem_t *measItem = NULLP;
1944 /* Validate Measurement list is supported by E2 node.
1946 * Traverse and compare the Measurement-Supported List in E2
1947 * node with Measurement-to-be-subscribed list received from RIC.
1948 * If a match is found, add it to measurement-subscription list.
1950 for(elementIdx = 0; elementIdx < measInfoToBeSubscribedList->list.count; elementIdx++)
1952 measInfoSubscribedDb = NULLP;
1953 measToAddNode = NULLP;
1954 measItem = measInfoToBeSubscribedList->list.array[elementIdx];
1956 CM_LLIST_FIRST_NODE(measInfoSupportedList, supportedMeasNode);
1957 while(supportedMeasNode)
1959 measInfoSupportedDb = (MeasurementInfoForAction*)supportedMeasNode->node;
1960 switch(measItem->measType.present)
1962 case MeasurementType_PR_measName:
1964 if(!strcmp(measInfoSupportedDb->measurementTypeName, (char *)measItem->measType.choice.measName.buf))
1966 DU_ALLOC(measInfoSubscribedDb, sizeof(MeasurementInfo));
1971 case MeasurementType_PR_measID:
1973 if(measInfoSupportedDb->measurementTypeId == measItem->measType.choice.measID)
1975 DU_ALLOC(measInfoSubscribedDb, sizeof(MeasurementInfo));
1982 DU_LOG("\nERROR -> DUAPP: Invalid Measurement-type identifier in \
1983 E2SM-KPM Action Definition Format");
1986 } /* End of switch, for measurement type identifier */
1988 /* If measurement type is supported, add to measurement-subscription list */
1989 if(measInfoSubscribedDb)
1991 measInfoSubscribedDb->measurementTypeId = measInfoSupportedDb->measurementTypeId;
1992 memcpy(measInfoSubscribedDb->measurementTypeName, measInfoSupportedDb->measurementTypeName, \
1993 strlen(measInfoSupportedDb->measurementTypeName));
1995 DU_ALLOC(measToAddNode, sizeof(CmLList));
1998 measToAddNode->node = (PTR) measInfoSubscribedDb;
1999 cmLListAdd2Tail(measInfoSubscribedList, measToAddNode);
2001 /* Break out of while loop if measurement info is found in measurement-supported list */
2006 DU_FREE(measInfoSubscribedDb, sizeof(MeasurementInfo));
2007 measInfoSubscribedDb = NULLP;
2013 supportedMeasNode = supportedMeasNode->next;
2015 } /* End of while for traversing measurement-supported list in a report style */
2017 /* If a measurement-to-be-subscribed is not found in measurement-supported list in this report style
2019 * Delete all entries from measurement-subscription list and
2020 * Break out of for loop to search in next report style */
2021 if(!measInfoSubscribedDb)
2023 while(measInfoSubscribedList->count)
2025 measToDelNode = cmLListDelFrm(measInfoSubscribedList, measInfoSubscribedList->first);
2026 measInfoToDel = (MeasurementInfo*)measToDelNode->node;
2027 DU_FREE(measInfoToDel, sizeof(MeasurementInfo));
2028 DU_FREE(measToDelNode, sizeof(CmLList));
2033 } /* End of for loop , traversing measurement-to-be-subscribed list */
2035 /* If all measurement-to-be-subscribed was found in measurement-supported list and
2036 * was added to measurement-subscription list successfully, return from here */
2037 if(measInfoToBeSubscribedList->list.count == measInfoSubscribedList->count)
2043 /*******************************************************************
2045 * @brief Extract E2SM-KPM Action definition
2049 * Function : extractRicActionDef
2051 * Functionality : This function :
2052 * - Decodes E2SM-KPM Action Definition
2053 * - Validates that action is supported by E2 node
2054 * - Stores action details in local DB
2056 * @params[in] RAN Function Database structure
2057 * RIC subscription's Action definition to be added to
2059 * RIC Action Definition buffer received from RIC
2060 * @return ROK - success
2063 ******************************************************************/
2064 uint8_t extractRicActionDef(RanFunction *ranFuncDb, ActionDefinition *actionDefDb, RICactionDefinition_t *ricActionDef,\
2065 E2FailureCause *failureCause)
2067 bool memFailure = false;
2068 uint8_t styleIdx = 0;
2069 asn_dec_rval_t rval ={0};
2071 E2SM_KPM_ActionDefinition_t actionDef, *actionDefPtr = NULLP;
2072 E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
2073 CmLListCp *measInfoSupportedList = NULLP;
2074 CmLListCp *measInfoSubscribedList = NULLP;
2076 /* Decoding E2SM-KPM Action Definition */
2077 actionDefPtr = &actionDef;
2078 memset(actionDefPtr, 0, sizeof(E2SM_KPM_EventTriggerDefinition_t));
2080 rval = aper_decode(0, &asn_DEF_E2SM_KPM_ActionDefinition, (void **)&actionDefPtr, ricActionDef->buf,\
2081 ricActionDef->size, 0, 0);
2082 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
2084 DU_LOG("\nERROR --> E2AP : ASN decode failed for E2SM-KPM Action Definition");
2085 failureCause->causeType = E2_PROTOCOL;
2086 failureCause->cause = E2_ABSTRACT_SYNTAX_ERROR_FALSELY_CONSTRUCTED_MESSAGE;
2090 xer_fprint(stdout, &asn_DEF_E2SM_KPM_ActionDefinition, actionDefPtr);
2093 /* Validate if Report style to subscribe is supported by E2 Node */
2094 for(styleIdx= 0; styleIdx < ranFuncDb->numOfReportStyleSupported; styleIdx++)
2096 /* Validate Report style type and report style format type is supported by E2 Node */
2097 if((ranFuncDb->reportStyleList[styleIdx].reportStyle.styleType == actionDefPtr->ric_Style_Type) &&
2098 (ranFuncDb->reportStyleList[styleIdx].reportStyle.formatType == actionDefPtr->actionDefinition_formats.present))
2100 /* Fetch Report stype type and format type */
2101 actionDefDb->styleType = actionDefPtr->ric_Style_Type;
2102 actionDefDb->formatType = actionDefPtr->actionDefinition_formats.present;
2104 switch(actionDefPtr->actionDefinition_formats.present)
2106 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1:
2108 actionFormat1 = actionDefPtr->actionDefinition_formats.choice.actionDefinition_Format1;
2110 /* Fetch granularity period */
2111 actionDefDb->choice.format1.granularityPeriod = actionFormat1->granulPeriod;
2113 /* Validate and add the Measurement to subscription list */
2114 measInfoSupportedList = &ranFuncDb->reportStyleList[styleIdx].measurementInfoList;
2115 measInfoSubscribedList = &actionDefDb->choice.format1.measurementInfoList;
2116 if(extractMeasInfoList(measInfoSupportedList, &actionFormat1->measInfoList, \
2117 measInfoSubscribedList, &memFailure) == ROK)
2121 /* Free E2SM_KPM_ActionDefinition_t */
2122 freeAperDecodingOfRicActionDefinition(actionDefPtr);
2127 break; /* End of E2SM-KPM Action definition format 1 case */
2132 DU_LOG("\nERROR -> DUAPP: Only E2SM-KPM Action Definition Format 1 is supported");
2135 } /* End of switch for E2SM-KPM Action definition formats */
2140 failureCause->causeType = E2_MISCELLANEOUS;
2141 failureCause->cause = E2_MISCELLANEOUS_CAUSE_UNSPECIFIED;
2144 } /* End of for loop, traversing Report-styles-supported list in E2 node */
2146 /* Memset action Db and Free E2SM_KPM_ActionDefinition_t */
2147 memset(actionDefDb, 0, sizeof(ActionDefinition));
2148 freeAperDecodingOfRicActionDefinition(actionDefPtr);
2150 if(failureCause->causeType == E2_NOTHING)
2152 failureCause->causeType = E2_RIC_REQUEST;
2153 failureCause->cause = E2_ACTION_NOT_SUPPORTED;
2158 /*******************************************************************
2160 * @brief Extract RIC Action to be setup
2164 * Function : extractRicActionToBeSetup
2166 * Functionality : This function :
2167 * - Validates that each action-to-be-setup is supported by E2 node
2168 * - Stores event trigger details in local DB
2170 * @params[in] RAN Function Database structure
2171 * RIC Subscription Info to be added to RAN function
2172 * RIC Action To Be Setup List received from RIC
2173 * @return ROK - success
2176 ******************************************************************/
2177 uint8_t extractRicActionToBeSetup(RanFunction *ranFuncDb, RicSubscription *ricSubscriptionInfo, \
2178 RICactions_ToBeSetup_List_t *actionList, E2FailureCause *failureCause, PendingSubsRspInfo *subsRsp)
2180 uint8_t actionIdx = 0;
2181 uint8_t ricActionId = 0;
2182 RICaction_ToBeSetup_ItemIEs_t *actionItem = NULLP;
2184 if(actionList->list.array)
2186 for(actionIdx = 0; actionIdx < actionList->list.count; actionIdx++)
2188 actionItem =(RICaction_ToBeSetup_ItemIEs_t *)actionList->list.array[actionIdx];
2189 switch(actionItem->id)
2191 case ProtocolIE_IDE2_id_RICaction_ToBeSetup_Item:
2193 /* If Action type is REPORT and
2194 * If RIC action definition's extraction and validation passes,
2196 * This action is added to action sequence list of subscription info */
2197 ricActionId = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID;
2199 if(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionType == RICactionType_report)
2201 ricSubscriptionInfo->actionSequence[ricActionId-1].id = ricActionId;
2202 ricSubscriptionInfo->actionSequence[ricActionId-1].type = REPORT;
2204 if(extractRicActionDef(ranFuncDb, &ricSubscriptionInfo->actionSequence[ricActionId-1].definition, \
2205 actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition, failureCause) == ROK)
2207 ricSubscriptionInfo->actionSequence[ricActionId-1].action = CONFIG_ADD;
2208 ricSubscriptionInfo->numOfActions++;
2213 /* In case of any failure, action is rejected
2214 * Added to rejected-action-list in subscription response */
2215 memset(&ricSubscriptionInfo->actionSequence[ricActionId-1], 0, sizeof(ActionInfo));
2216 subsRsp->rejectedActionList[subsRsp->numOfRejectedActions].id = ricActionId;
2217 if(failureCause->causeType == E2_NOTHING)
2219 failureCause->causeType = E2_RIC_REQUEST;
2220 failureCause->cause = E2_ACTION_NOT_SUPPORTED;
2222 memcpy(&subsRsp->rejectedActionList[subsRsp->numOfRejectedActions].failureCause, \
2223 failureCause, sizeof(E2FailureCause));
2224 subsRsp->numOfRejectedActions++;
2228 DU_LOG("\nERROR --> E2AP : Invalid IE received in RicSetupLst:%ld",actionItem->id);
2234 /* If there is even 1 action that can be added, return ROK */
2235 if(ricSubscriptionInfo->numOfActions)
2238 if(failureCause->causeType == E2_NOTHING)
2240 failureCause->causeType = E2_RIC_REQUEST;
2241 failureCause->cause = E2_ACTION_NOT_SUPPORTED;
2246 /******************************************************************
2248 * @brief Processes RIC Subscription Req sent by RIC
2252 * Function : procRicSubscriptionRequest
2254 * Functionality: Processes RIC Subscription Request from RIC
2256 * @params[in] E2AP_PDU_t ASN decoded E2AP message
2257 * @return ROK - success
2260 * ****************************************************************/
2261 uint8_t procRicSubscriptionRequest(E2AP_PDU_t *e2apMsg)
2265 uint16_t ranFuncId = 0;
2266 RicRequestId ricReqId;
2267 CmLList *ricSubscriptionNode = NULLP;
2268 RanFunction *ranFuncDb = NULLP;
2269 RICsubscriptionRequest_t *ricSubsReq = NULLP;
2270 RICsubscriptionDetails_t *subsDetails = NULLP;
2271 RicSubscription *ricSubscriptionInfo = NULLP;
2272 E2FailureCause failureCause;
2274 DU_LOG("\nINFO --> E2AP : RIC Subscription request received");
2276 memset(&failureCause, 0, sizeof(E2FailureCause));
2277 memset(&ricReqId, 0, sizeof(RicRequestId));
2279 ricSubsReq = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
2280 for(idx=0; idx<ricSubsReq->protocolIEs.list.count; idx++)
2282 if(ricSubsReq->protocolIEs.list.array[idx])
2284 switch(ricSubsReq->protocolIEs.list.array[idx]->id)
2286 case ProtocolIE_IDE2_id_RICrequestID:
2288 ricReqId.requestorId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID;
2289 ricReqId.instanceId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID;
2294 case ProtocolIE_IDE2_id_RANfunctionID:
2296 ranFuncId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RANfunctionID;
2298 /* Validating RAN Function id */
2299 if(duCb.e2apDb.ranFunction[ranFuncId-1].id == ranFuncId)
2301 ranFuncDb = &duCb.e2apDb.ranFunction[ranFuncId-1];
2303 if(ranFuncDb->numPendingSubsRsp >= MAX_PENDING_SUBSCRIPTION_RSP)
2305 failureCause.causeType = E2_RIC_REQUEST;
2306 failureCause.cause = E2_FUNCTION_RESOURCE_LIMIT;
2311 DU_ALLOC(ricSubscriptionInfo, sizeof(RicSubscription));
2312 if(!ricSubscriptionInfo)
2314 DU_LOG("\nERROR --> E2AP : Memory allocation failed for ricSubscriptionInfo");
2315 failureCause.causeType = E2_MISCELLANEOUS;
2316 failureCause.cause = E2_MISCELLANEOUS_CAUSE_UNSPECIFIED;
2320 ricSubscriptionInfo->requestId.requestorId = ricReqId.requestorId;
2321 ricSubscriptionInfo->requestId.instanceId = ricReqId.instanceId;
2323 memset(&ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp], 0, sizeof(PendingSubsRspInfo));
2324 memcpy(&ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp].requestId,
2325 &ricReqId, sizeof(RicRequestId));
2326 ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp].ranFuncId = ranFuncId;
2330 failureCause.causeType = E2_RIC_REQUEST;
2331 failureCause.cause = E2_RAN_FUNCTION_ID_INVALID;
2337 case ProtocolIE_IDE2_id_RICsubscriptionDetails:
2339 subsDetails = &ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails;
2341 /* Decode, Validate and record Event Trigger Definition */
2342 if(extractEventTriggerDef(ranFuncDb, ricSubscriptionInfo, &subsDetails->ricEventTriggerDefinition, \
2343 &failureCause) != ROK)
2349 /* Decode, Validate and record RIC actions */
2350 if(extractRicActionToBeSetup(ranFuncDb, ricSubscriptionInfo, &subsDetails->ricAction_ToBeSetup_List, \
2351 &failureCause, &ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp]) != ROK)
2360 DU_LOG("\nERROR --> E2AP : Invalid IE received in RIC SubsReq:%ld",
2361 ricSubsReq->protocolIEs.list.array[idx]->id);
2370 freeAperDecodingOfRicSubsReq(ricSubsReq);
2374 /* Add RAN subcription detail to RAN function */
2375 DU_ALLOC(ricSubscriptionNode, sizeof(CmLList));
2376 if(ricSubscriptionNode)
2378 ricSubscriptionNode->node = (PTR) ricSubscriptionInfo;
2379 cmLListAdd2Tail(&ranFuncDb->subscriptionList, ricSubscriptionNode);
2382 ranFuncDb->numPendingSubsRsp++;
2384 #ifdef KPI_CALCULATION
2385 /* Send statistics request to other DU entities */
2386 BuildAndSendStatsReq(ranFuncId, ricSubscriptionInfo);
2389 /* TODO : Trigger RIC Indication once statistics indication is
2390 * received from MAC .
2391 * TBD in future gerrit */
2392 //BuildAndSendRicIndication(ricSubscriptionInfo);
2396 DU_FREE(ricSubscriptionInfo, sizeof(RicSubscription));
2400 memset(&ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp], 0, sizeof(PendingSubsRspInfo));
2403 /* Send RIC Subcription Failure */
2404 BuildAndSendRicSubscriptionFailure(ricReqId, ranFuncId, failureCause);
2410 /******************************************************************
2412 * @brief Free RIC Subscription Failure
2416 * Function : FreeRicSubscriptionFailure
2418 * Functionality: Free RIC Subscription Failure
2420 * @params[in] E2AP PDU
2423 * ****************************************************************/
2424 void FreeRicSubscriptionFailure(E2AP_PDU_t *e2apMsg)
2426 uint8_t elemIdx = 0;
2427 RICsubscriptionFailure_t *ricSubscriptionFailure = NULLP;
2431 if(e2apMsg->choice.unsuccessfulOutcome)
2433 ricSubscriptionFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionFailure;
2434 if(ricSubscriptionFailure->protocolIEs.list.array)
2436 for(elemIdx = 0; elemIdx < ricSubscriptionFailure->protocolIEs.list.count; elemIdx++)
2438 DU_ALLOC(ricSubscriptionFailure->protocolIEs.list.array[elemIdx], sizeof(RICsubscriptionFailure_IEs_t));
2440 DU_ALLOC(ricSubscriptionFailure->protocolIEs.list.array, ricSubscriptionFailure->protocolIEs.list.size);
2442 DU_ALLOC(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
2444 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2448 /******************************************************************
2450 * @brief Fill and Send RIC Subscription Failure to RIC
2454 * Function : BuildAndSendRicSubscriptionFailure
2456 * Functionality: Fill and Send RIC Subscription Failure to RIC
2458 * @params[in] RIC Request ID
2461 * @return ROK - success
2464 * ****************************************************************/
2465 uint8_t BuildAndSendRicSubscriptionFailure(RicRequestId ricReqId, uint16_t ranFuncId, E2FailureCause failureCause)
2467 uint8_t ret = RFAILED;
2468 uint8_t elementCnt = 0, elemIdx = 0;
2469 E2AP_PDU_t *e2apMsg = NULLP;
2470 asn_enc_rval_t encRetVal; /* Encoder return value */
2471 RICsubscriptionFailure_t *ricSubscriptionFailure = NULLP;
2472 RICsubscriptionFailure_IEs_t *ricSubsFailIe = NULLP;
2476 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Failure\n");
2478 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2479 if(e2apMsg == NULLP)
2481 DU_LOG("\nERROR --> E2AP : Memory allocation at [%s] : Line [%d]", __func__, __LINE__);
2485 e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome;
2486 DU_ALLOC(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
2487 if(e2apMsg->choice.unsuccessfulOutcome == NULLP)
2489 DU_LOG("\nERROR --> E2AP : Memory allocation at [%s] : Line [%d]", __func__, __LINE__);
2492 e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
2493 e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject;
2494 e2apMsg->choice.unsuccessfulOutcome->value.present = UnsuccessfulOutcomeE2__value_PR_RICsubscriptionFailure;
2496 ricSubscriptionFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionFailure;
2499 ricSubscriptionFailure->protocolIEs.list.count = elementCnt;
2500 ricSubscriptionFailure->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionFailure_IEs_t *);
2501 DU_ALLOC(ricSubscriptionFailure->protocolIEs.list.array, ricSubscriptionFailure->protocolIEs.list.size);
2502 if(!ricSubscriptionFailure->protocolIEs.list.array)
2504 DU_LOG("\nERROR --> E2AP : Memory allocation at [%s] : Line [%d]", __func__, __LINE__);
2508 for(elemIdx = 0; elemIdx < elementCnt; elemIdx++)
2510 DU_ALLOC(ricSubscriptionFailure->protocolIEs.list.array[elemIdx], sizeof(RICsubscriptionFailure_IEs_t));
2511 if(!ricSubscriptionFailure->protocolIEs.list.array[elemIdx])
2513 DU_LOG("\nERROR --> E2AP : Memory allocation at [%s] : Line [%d] for IE at index [%d]", \
2514 __func__, __LINE__, elemIdx);
2518 if(elemIdx < elementCnt)
2523 /* RIC Request ID */
2524 ricSubsFailIe = ricSubscriptionFailure->protocolIEs.list.array[elemIdx++];
2525 ricSubsFailIe->id = ProtocolIE_IDE2_id_RICrequestID;
2526 ricSubsFailIe->criticality = CriticalityE2_reject;
2527 ricSubsFailIe->value.present = RICsubscriptionFailure_IEs__value_PR_RICrequestID;
2528 ricSubsFailIe->value.choice.RICrequestID.ricRequestorID = ricReqId.requestorId;
2529 ricSubsFailIe->value.choice.RICrequestID.ricInstanceID = ricReqId.instanceId;
2531 /* RAN Function ID */
2532 ricSubsFailIe = ricSubscriptionFailure->protocolIEs.list.array[elemIdx++];
2533 ricSubsFailIe->id = ProtocolIE_IDE2_id_RANfunctionID;
2534 ricSubsFailIe->criticality = CriticalityE2_reject;
2535 ricSubsFailIe->value.present = RICsubscriptionFailure_IEs__value_PR_RANfunctionID;
2536 ricSubsFailIe->value.choice.RANfunctionID = ranFuncId;
2539 ricSubsFailIe = ricSubscriptionFailure->protocolIEs.list.array[elemIdx++];
2540 ricSubsFailIe->id = ProtocolIE_IDE2_id_CauseE2;
2541 ricSubsFailIe->criticality = CriticalityE2_reject;
2542 ricSubsFailIe->value.present = RICsubscriptionFailure_IEs__value_PR_CauseE2;
2543 fillE2Cause(&ricSubsFailIe->value.choice.CauseE2, failureCause);
2545 /* Prints the Msg formed */
2546 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2547 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2549 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
2550 if(encRetVal.encoded == ENCODE_FAIL)
2552 DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Failure Message (at %s)\n",\
2553 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2558 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Subscription Failure Message \n");
2559 #ifdef DEBUG_ASN_PRINT
2560 for(int i=0; i< encBufSize; i++)
2562 printf("%x",encBuf[i]);
2567 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
2569 DU_LOG("\nINFO --> E2AP : Sending RIC Subscription Failure");
2575 FreeRicSubscriptionFailure(e2apMsg);
2579 /*******************************************************************
2581 * @brief Free the RicIndication Message
2585 * Function : FreeRicIndication
2587 * Functionality: Free the RicIndication Message
2592 ******************************************************************/
2593 void FreeRicIndication(E2AP_PDU_t *e2apMsg)
2596 RICindication_t *ricIndicationMsg= NULLP;
2598 if(e2apMsg != NULLP)
2600 if(e2apMsg->choice.initiatingMessage != NULLP)
2602 ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
2603 if(ricIndicationMsg!= NULLP)
2605 if(ricIndicationMsg->protocolIEs.list.array != NULLP)
2607 for(idx=0; idx<ricIndicationMsg->protocolIEs.list.count; idx++)
2609 if(ricIndicationMsg->protocolIEs.list.array[idx] != NULLP)
2611 switch(ricIndicationMsg->protocolIEs.list.array[idx]->id)
2613 case ProtocolIE_IDE2_id_RICrequestID:
2616 case ProtocolIE_IDE2_id_RANfunctionID:
2619 case ProtocolIE_IDE2_id_RICactionID:
2622 case ProtocolIE_IDE2_id_RICindicationType:
2625 case ProtocolIE_IDE2_id_RICindicationHeader:
2627 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf,\
2628 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
2631 case ProtocolIE_IDE2_id_RICindicationMessage:
2633 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf,\
2634 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
2640 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx],sizeof(RICindication_IEs_t));
2643 DU_FREE(ricIndicationMsg->protocolIEs.list.array,ricIndicationMsg->protocolIEs.list.size);
2646 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2648 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2652 /*******************************************************************
2654 * brief Fill the RicIndication Message
2658 * Function : FillRicIndication
2660 * Functionality:Fills the RicIndication Message
2662 * @return ROK - success
2665 ******************************************************************/
2666 uint8_t FillRicIndication(RICindication_t *ricIndicationMsg, RicSubscription *ricSubscriptionInfo)
2668 uint8_t elementCnt=0;
2673 ricIndicationMsg->protocolIEs.list.count = elementCnt;
2674 ricIndicationMsg->protocolIEs.list.size = elementCnt * sizeof(RICindication_t);
2675 /* Initialize the Ric Indication members */
2676 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array, \
2677 ricIndicationMsg->protocolIEs.list.size);
2678 if(ricIndicationMsg->protocolIEs.list.array == NULLP)
2680 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
2685 for(idx=0; idx<elementCnt; idx++)
2687 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx],\
2688 sizeof(RICindication_IEs_t));
2689 if(ricIndicationMsg->protocolIEs.list.array[idx] == NULLP)
2691 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
2699 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
2700 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2701 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2702 RICindication_IEs__value_PR_RICrequestID;
2703 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID =ricSubscriptionInfo->requestId.requestorId;
2704 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID = ricSubscriptionInfo->requestId.instanceId;
2707 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
2708 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2709 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2710 RICindication_IEs__value_PR_RANfunctionID;
2711 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RANfunctionID = duCb.e2apDb.ranFunction[0].id;
2714 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactionID;
2715 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2716 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2717 RICindication_IEs__value_PR_RICactionID;
2718 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICactionID = ricSubscriptionInfo->actionSequence[0].id;
2721 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationType;
2722 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2723 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2724 RICindication_IEs__value_PR_RICindicationType;
2725 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationType = ricSubscriptionInfo->actionSequence[0].type;
2728 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationHeader;
2729 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2730 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2731 RICindication_IEs__value_PR_RICindicationHeader;
2732 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size = 3 *
2734 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf ,\
2735 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
2736 if(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf == NULLP)
2738 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
2743 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
2744 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf);
2746 /* TO BE CHANGED: RIC INDICATION DATA */
2747 /* For now filling a dummy octect data, need to tested with PRBs*/
2748 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationMessage;
2749 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2750 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2751 RICindication_IEs__value_PR_RICindicationMessage;
2752 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size = 3 *
2754 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf ,\
2755 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
2756 if(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf == NULLP)
2758 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
2763 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
2764 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf);
2772 /*******************************************************************
2774 * @brief Builds and Send the RicIndication Message
2778 * Function : BuildAndSendRicIndication
2780 * Functionality:Fills the RicIndication Message
2782 * @return ROK - success
2785 ******************************************************************/
2787 uint8_t BuildAndSendRicIndication(RicSubscription *ricSubscriptionInfo)
2789 E2AP_PDU_t *e2apMsg = NULLP;
2790 RICindication_t *ricIndicationMsg=NULLP;
2791 asn_enc_rval_t encRetVal; /* Encoder return value */
2792 uint8_t ret = RFAILED;
2793 uint8_t FillRicIndicationret = ROK;
2797 DU_LOG("\nINFO --> E2AP : Building RIC Indication Message\n");
2799 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2800 if(e2apMsg == NULLP)
2802 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2806 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2807 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2808 if(e2apMsg->choice.initiatingMessage == NULLP)
2810 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2813 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICindication;
2814 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2815 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICindication;
2817 ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
2819 FillRicIndicationret = FillRicIndication(ricIndicationMsg, ricSubscriptionInfo);
2820 if(FillRicIndicationret != ROK)
2824 /* Prints the Msg formed */
2825 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2826 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2828 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
2830 if(encRetVal.encoded == ENCODE_FAIL)
2832 DU_LOG("\nERROR --> E2AP : Could not encode RIC Indication Message (at %s)\n",\
2833 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2838 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Indication Message \n");
2839 #ifdef DEBUG_ASN_PRINT
2840 for(int i=0; i< encBufSize; i++)
2842 printf("%x",encBuf[i]);
2847 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
2849 DU_LOG("\nINFO --> E2AP : Sending RIC Indication Message");
2855 FreeRicIndication(e2apMsg);
2859 /*******************************************************************
2861 * @brief Deallocate the memory allocated for E2nodeConfigurationUpdate msg
2865 * Function : FreeE2NodeConfigUpdate
2868 * - freeing the memory allocated for E2nodeConfigurationUpdate
2870 * @params[in] E2AP_PDU_t *e2apMsg
2871 * @return ROK - success
2874 * ****************************************************************/
2875 void FreeE2NodeConfigUpdate(E2AP_PDU_t *e2apMsg)
2878 E2nodeConfigurationUpdate_t *e2NodeConfigUpdate;
2880 if(e2apMsg != NULLP)
2882 if(e2apMsg->choice.initiatingMessage != NULLP)
2884 e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
2885 if(e2NodeConfigUpdate->protocolIEs.list.array != NULLP)
2887 for(arrIdx = 0; arrIdx < e2NodeConfigUpdate->protocolIEs.list.count; arrIdx++)
2889 DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
2891 DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size);
2893 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2895 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2899 /*******************************************************************
2901 * @brief Buld and send the E2 node config update msg
2905 * Function : BuildAndSendE2NodeConfigUpdate
2908 * - Buld and send the E2 node config update msg
2911 * @return ROK - success
2914 * ****************************************************************/
2916 uint8_t BuildAndSendE2NodeConfigUpdate()
2918 uint8_t arrIdx = 0,elementCnt = 1;
2920 E2AP_PDU_t *e2apMsg = NULLP;
2921 E2nodeConfigurationUpdate_t *e2NodeConfigUpdate = NULLP;
2922 asn_enc_rval_t encRetVal; /* Encoder return value */
2924 DU_LOG("\nINFO --> E2AP : Building E2 Node config update\n");
2927 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2928 if(e2apMsg == NULLP)
2930 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2933 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2934 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2935 if(e2apMsg->choice.initiatingMessage == NULLP)
2937 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2938 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2941 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2942 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
2943 e2apMsg->choice.initiatingMessage->value.present = \
2944 InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate;
2945 e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
2947 e2NodeConfigUpdate->protocolIEs.list.count = elementCnt;
2948 e2NodeConfigUpdate->protocolIEs.list.size = elementCnt * sizeof(E2nodeConfigurationUpdate_IEs_t*);
2949 /* Initialize the Ric Indication members */
2950 DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array, \
2951 e2NodeConfigUpdate->protocolIEs.list.size);
2952 if(e2NodeConfigUpdate->protocolIEs.list.array == NULLP)
2954 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
2958 for(arrIdx =0; arrIdx<elementCnt; arrIdx++)
2960 DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
2961 if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx] == NULLP)
2964 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
2971 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2972 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2973 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_TransactionID;
2974 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = TRANS_ID;
2977 /* Prints the Msg formed */
2978 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2980 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2982 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
2984 if(encRetVal.encoded == ENCODE_FAIL)
2986 DU_LOG("\nERROR --> E2AP : Could not encode E2nodeConfigurationUpdate structure (at %s)\n",\
2987 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2992 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2nodeConfigurationUpdate\n");
2993 #ifdef DEBUG_ASN_PRINT
2994 for(int i=0; i< encBufSize; i++)
2996 printf("%x",encBuf[i]);
3000 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize))
3002 DU_LOG("\nERROR --> E2AP : Sending E2 node config update failed");
3009 FreeE2NodeConfigUpdate(e2apMsg);
3013 /*******************************************************************
3015 * @brief Deallocate the memory allocated for E2ResetRequest msg
3019 * Function : FreeE2ResetRequest
3022 * - freeing the memory allocated for E2ResetRequest
3024 * @params[in] E2AP_PDU_t *e2apMsg
3025 * @return ROK - success
3028 * ****************************************************************/
3029 void FreeE2ResetRequest(E2AP_PDU_t *e2apMsg)
3032 ResetRequestE2_t *resetReq = NULLP;
3034 if(e2apMsg != NULLP)
3036 if(e2apMsg->choice.initiatingMessage != NULLP)
3038 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
3039 if(resetReq->protocolIEs.list.array)
3041 for(ieIdx = 0; ieIdx < resetReq->protocolIEs.list.count; ieIdx++)
3043 DU_FREE(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
3045 DU_FREE(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
3047 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
3049 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
3053 /*******************************************************************
3055 * @brief Build and send the E2 reset request msg
3059 * Function : BuildAndSendE2ResetRequest
3062 * - Buld and send the E2 reset request msg to RIC
3065 * @return ROK - success
3068 * ****************************************************************/
3069 uint8_t BuildAndSendE2ResetRequest(E2FailureCause resetCause)
3071 uint8_t ieIdx = 0, elementCnt = 0, transId = 0;
3072 uint8_t ret = RFAILED;
3073 E2AP_PDU_t *e2apMsg = NULLP;
3074 ResetRequestE2_t *resetReq = NULLP;
3075 asn_enc_rval_t encRetVal; /* Encoder return value */
3077 DU_LOG("\nINFO --> E2AP : Building E2 Reset Request\n");
3081 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
3082 if(e2apMsg == NULLP)
3084 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation for E2AP-PDU failed");
3088 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
3089 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
3090 if(e2apMsg->choice.initiatingMessage == NULLP)
3092 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation for initiatingMessage");
3096 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_Reset;
3097 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
3098 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ResetRequestE2;
3099 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
3102 resetReq->protocolIEs.list.count = elementCnt;
3103 resetReq->protocolIEs.list.size = elementCnt * sizeof(ResetRequestIEs_t *);
3105 DU_ALLOC(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
3106 if(!resetReq->protocolIEs.list.array)
3108 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
3109 Reset Request IE array");
3113 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
3115 DU_ALLOC(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
3116 if(!resetReq->protocolIEs.list.array[ieIdx])
3118 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
3119 Reset Request IE array element");
3124 /* In case of failure */
3125 if(ieIdx < elementCnt)
3129 resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
3130 resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
3131 resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_TransactionID;
3132 transId = assignTransactionId();
3133 resetReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
3136 resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_CauseE2;
3137 resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_ignore;
3138 resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_CauseE2;
3139 fillE2Cause(&resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2, resetCause);
3141 /* Prints the Msg formed */
3142 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3144 memset(encBuf, 0, ENC_BUF_MAX_LEN);
3146 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
3148 if(encRetVal.encoded == ENCODE_FAIL)
3150 DU_LOG("\nERROR --> E2AP : Could not encode E2SetupRequest structure (at %s)\n",\
3151 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3156 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupRequest\n");
3157 #ifdef DEBUG_ASN_PRINT
3158 for(int i=0; i< encBufSize; i++)
3160 printf("%x",encBuf[i]);
3164 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
3166 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
3170 /* In case the message is sent successfully, store the transaction info to
3171 * be used when response is received */
3172 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
3173 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
3179 /* Free all memory */
3180 FreeE2ResetRequest(e2apMsg);
3184 /*******************************************************************
3186 * @brief Deallocate the memory allocated for Reset Response msg
3190 * Function : freeAperDecodingOfE2ResetRsp
3193 * - freeing the memory allocated for Reset response
3195 * @params[in] ResetResponseE2_t *resetResponse
3198 * ****************************************************************/
3199 void freeAperDecodingOfE2ResetRsp(ResetResponseE2_t *resetResponse)
3205 if(resetResponse->protocolIEs.list.array)
3207 for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
3209 if(resetResponse->protocolIEs.list.array[ieIdx])
3211 switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
3213 case ProtocolIE_IDE2_id_TransactionID:
3216 case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
3219 free(resetResponse->protocolIEs.list.array[ieIdx]);
3222 free(resetResponse->protocolIEs.list.array);
3227 /******************************************************************
3229 * @brief Processes E2 Reset Response sent by RIC
3233 * Function : procResetResponse
3235 * Functionality: Processes E2 Reset Response sent by RIC
3237 * @params[in] E2AP_PDU_t ASN decoded E2AP message
3238 * @return ROK - success
3241 * ****************************************************************/
3242 uint8_t procResetResponse(E2AP_PDU_t *e2apMsg)
3244 uint8_t ieIdx =0, transId;
3245 ResetResponseE2_t *resetResponse;
3247 DU_LOG("\nINFO --> E2AP : E2 Reset Response received");
3248 resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;;
3250 for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
3252 switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
3254 case ProtocolIE_IDE2_id_TransactionID:
3255 transId = resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
3256 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) && \
3257 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
3259 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
3263 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
3267 case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
3268 /* As per ORAN WG3 E2AP spec v3.0, section 9.2.2
3269 Criticality Diagnostics IE is sent by Near-RT RIC when parts of a received message i.e.
3270 Reset Request in this case, have not been comprehended or were missing, or if the message
3271 contained logical errors.
3273 Processing of this ID should be implemented when negative call flows are to be supported.
3277 DU_LOG("\nERROR --> E2AP : Invalid IE received in E2 Reset Response : %ld",
3278 resetResponse->protocolIEs.list.array[ieIdx]->id);
3283 freeAperDecodingOfE2ResetRsp(resetResponse);
3287 /******************************************************************
3289 * @brief Deallocation of memory allocated bu aper decoder for e2 setup Failure
3293 * Function : freeAperDecodingOfE2SetupFailure
3295 * Functionality: Deallocation of memory allocated bu aper decoder for e2
3298 * @params[in] E2setupFailure_t *e2SetupFailure;
3301 * ****************************************************************/
3302 void freeAperDecodingOfE2SetupFailure(E2setupFailure_t *e2SetupFailure)
3308 if(e2SetupFailure->protocolIEs.list.array)
3310 for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
3312 if(e2SetupFailure->protocolIEs.list.array[arrIdx])
3314 free(e2SetupFailure->protocolIEs.list.array[arrIdx]);
3317 free(e2SetupFailure->protocolIEs.list.array);
3321 /******************************************************************
3323 * @brief Processes E2 Setup Failure sent by RIC
3327 * Function : procE2SetupFailure
3329 * Functionality: Processes E2 Setup failure sent by RIC
3331 * @params[in] E2AP_PDU_t ASN decoded E2AP message
3332 * @return ROK - success
3335 * ****************************************************************/
3336 void procE2SetupFailure(E2AP_PDU_t *e2apMsg)
3338 uint8_t arrIdx =0, transId =0, timerValue=0;
3339 E2setupFailure_t *e2SetupFailure;
3341 DU_LOG("\nINFO --> E2AP : E2 Setup failure received");
3342 e2SetupFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure;
3344 for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
3346 switch(e2SetupFailure->protocolIEs.list.array[arrIdx]->id)
3348 case ProtocolIE_IDE2_id_TransactionID:
3350 transId = e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
3351 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
3352 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
3354 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
3358 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
3363 case ProtocolIE_IDE2_id_TimeToWaitE2:
3365 timerValue = covertE2WaitTimerEnumToValue(e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
3366 if((duChkTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.e2SetupTimer), EVENT_E2_SETUP_TMR)) == FALSE)
3368 duStartTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.e2SetupTimer), EVENT_E2_SETUP_TMR, timerValue);
3372 DU_LOG("\nERROR --> E2AP : EVENT_E2_SETUP_TMR timer is already running");
3380 freeAperDecodingOfE2SetupFailure(e2SetupFailure);
3382 /******************************************************************
3384 * @brief Deallocation of memory allocated bu aper decoder for RIC service Query
3388 * Function : freeAperDecodingOfRicServiceQuery
3390 * Functionality: Deallocation of memory allocated bu aper decoder for RIC
3393 * @params[in] RICserviceQuery_t *ricServiceQuery;
3396 * ****************************************************************/
3398 void freeAperDecodingOfRicServiceQuery(RICserviceQuery_t *ricServiceQuery)
3400 uint8_t arrIdx,ranFuncIdx;
3401 RANfunctionsID_List_t *ranFuncAddedList;
3405 if(ricServiceQuery->protocolIEs.list.array)
3407 for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
3409 if(ricServiceQuery->protocolIEs.list.array[arrIdx])
3411 switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
3413 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
3415 ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
3416 if(ranFuncAddedList->list.array)
3418 for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
3420 free(ranFuncAddedList->list.array[ranFuncIdx]);
3422 free(ranFuncAddedList->list.array);;
3429 free(ricServiceQuery->protocolIEs.list.array[arrIdx]);
3432 free(ricServiceQuery->protocolIEs.list.array);
3436 /*******************************************************************
3438 * @brief Build RanFunction Delete List
3442 * Function : BuildRanFunctionDeleteList
3444 * Functionality: Build RanFunction Delete List
3447 * RANfunctionsID List
3448 * Count of the RAN function
3449 * Received RAN function list
3451 * @return ROK - success
3454 ******************************************************************/
3456 uint8_t BuildRanFunctionDeleteList(RANfunctionsID_List_t *deleteList, uint8_t count, RanFuncInfo *recvdRanFunc)
3458 uint8_t ranFuncIdx=0;
3459 RANfunctionID_ItemIEs_t *delRanFuncItem;
3463 deleteList->list.count = count;
3464 deleteList->list.size = deleteList->list.count * sizeof(RANfunctionID_ItemIEs_t*);
3465 DU_ALLOC(deleteList->list.array, deleteList->list.size);
3466 if(deleteList->list.array == NULLP)
3468 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
3471 for(ranFuncIdx = 0; ranFuncIdx< deleteList->list.count; ranFuncIdx++)
3473 DU_ALLOC(deleteList->list.array[ranFuncIdx], sizeof(RANfunctionID_ItemIEs_t));
3474 if(deleteList->list.array[ranFuncIdx] == NULLP)
3476 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
3479 delRanFuncItem= (RANfunctionID_ItemIEs_t *) deleteList->list.array[ranFuncIdx];
3480 delRanFuncItem->id = ProtocolIE_IDE2_id_RANfunctionID_Item;
3481 delRanFuncItem->criticality = CriticalityE2_ignore;
3482 delRanFuncItem->value.choice.RANfunctionID_Item.ranFunctionID = recvdRanFunc[ranFuncIdx].id;
3483 delRanFuncItem->value.choice.RANfunctionID_Item.ranFunctionRevision = recvdRanFunc[ranFuncIdx].revisionCounter;
3489 /*******************************************************************
3491 * @brief De Allocate Ric Service Update message
3495 * Function : FreeRicServiceUpdate
3497 * Functionality: De-Allocating Ric Service Update message
3499 * @params[in] E2AP_PDU_t *e2apMsg
3503 * ****************************************************************/
3505 void FreeRicServiceUpdate(E2AP_PDU_t *e2apMsg)
3508 uint8_t ranFuncAddListIdx=0, ranFuncDelIdx=0;
3509 RICserviceUpdate_t *ricServiceUpdate;
3510 RANfunctions_List_t *ranFunctionsList;
3511 RANfunction_ItemIEs_t *ranFuncItemIe;
3512 RANfunction_Item_t *ranFunItem;
3513 RANfunctionsID_List_t *deleteList;
3515 /* De-allocating Memory */
3516 if(e2apMsg != NULLP)
3518 if(e2apMsg->choice.initiatingMessage != NULLP)
3520 ricServiceUpdate = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate;
3521 if(ricServiceUpdate->protocolIEs.list.array != NULLP)
3523 for(arrIdx = 0; arrIdx < ricServiceUpdate->protocolIEs.list.count; arrIdx++)
3525 if(ricServiceUpdate->protocolIEs.list.array[arrIdx] != NULLP)
3527 switch(ricServiceUpdate->protocolIEs.list.array[arrIdx]->id)
3529 case ProtocolIE_IDE2_id_TransactionID:
3532 case ProtocolIE_IDE2_id_RANfunctionsAdded:
3533 case ProtocolIE_IDE2_id_RANfunctionsModified:
3535 ranFunctionsList = &(ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List);
3536 if(ranFunctionsList->list.array)
3538 for(ranFuncAddListIdx= 0; ranFuncAddListIdx< ranFunctionsList->list.count; ranFuncAddListIdx++)
3540 if(ranFunctionsList->list.array[ranFuncAddListIdx])
3542 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncAddListIdx];
3543 ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
3544 DU_FREE(ranFunItem->ranFunctionOID.buf, ranFunItem->ranFunctionOID.size);
3545 DU_FREE(ranFunItem->ranFunctionDefinition.buf, ranFunItem->ranFunctionDefinition.size);
3546 DU_FREE(ranFunctionsList->list.array[ranFuncAddListIdx], sizeof(RANfunction_ItemIEs_t));
3549 DU_FREE(ranFunctionsList->list.array, ranFunctionsList->list.size);
3553 case ProtocolIE_IDE2_id_RANfunctionsDeleted:
3555 deleteList= &ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
3556 if(deleteList->list.array)
3558 for(ranFuncDelIdx = 0; ranFuncDelIdx< deleteList->list.count; ranFuncDelIdx++)
3560 DU_FREE(deleteList->list.array[ranFuncDelIdx], sizeof(RANfunctionID_ItemIEs_t));
3562 DU_FREE(deleteList->list.array, deleteList->list.size);
3568 DU_LOG("\nERROR --> E2AP: Invalid event at ricServiceUpdate %ld ",\
3569 (ricServiceUpdate->protocolIEs.list.array[arrIdx]->id));
3572 DU_FREE(ricServiceUpdate->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdate_IEs_t));
3575 DU_FREE(ricServiceUpdate->protocolIEs.list.array, ricServiceUpdate->protocolIEs.list.size);
3577 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
3579 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
3583 /*******************************************************************
3585 * @brief Builds and Send the RicServiceUpdateuest
3589 * Function : BuildAndSendRicServiceUpdate
3591 * Functionality:Fills the RicServiceUpdateuest
3593 * @return ROK - success
3596 ******************************************************************/
3598 uint8_t BuildAndSendRicServiceUpdate(RicServiceUpdate serviceUpdate)
3600 uint8_t arrIdx = 0, elementCnt=0;
3601 uint8_t transId = 0, ret = RFAILED;
3602 bool memAllocFailed =false;
3603 E2AP_PDU_t *e2apMsg = NULLP;
3604 RICserviceUpdate_t *ricServiceUpdate = NULLP;
3605 asn_enc_rval_t encRetVal; /* Encoder return value */
3607 DU_LOG("\nINFO --> E2AP : Building Ric Service Update\n");
3610 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
3611 if(e2apMsg == NULLP)
3613 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
3616 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
3617 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
3618 if(e2apMsg->choice.initiatingMessage == NULLP)
3620 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
3623 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
3624 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICserviceUpdate;
3625 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICserviceUpdate;
3626 ricServiceUpdate = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate;
3628 /* For TransId IE, set elementCnt to 1.
3629 If there is any item in the RAN function add list, RAN function modification list, or RAN function delete list, increment the elementCnt.*/
3632 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
3634 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeModified)
3636 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted)
3639 ricServiceUpdate->protocolIEs.list.count = elementCnt;
3640 ricServiceUpdate->protocolIEs.list.size = elementCnt * sizeof(RICserviceUpdate_IEs_t*);
3642 /* Initialize the E2Setup members */
3643 DU_ALLOC(ricServiceUpdate->protocolIEs.list.array, ricServiceUpdate->protocolIEs.list.size);
3644 if(ricServiceUpdate->protocolIEs.list.array == NULLP)
3646 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements");
3650 for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
3652 DU_ALLOC(ricServiceUpdate->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdate_IEs_t));
3653 if(ricServiceUpdate->protocolIEs.list.array[arrIdx] == NULLP)
3655 memAllocFailed = true;
3656 DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayIdx [%d]", arrIdx);
3660 if(memAllocFailed == true)
3666 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
3667 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3668 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
3669 if(serviceUpdate.dir == E2_NODE_INITIATED)
3670 transId = assignTransactionId();
3672 transId = serviceUpdate.transId;
3673 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
3675 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
3678 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
3679 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3680 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
3681 if(BuildRanFunctionAddList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List,\
3682 e2apMsg->choice.initiatingMessage->procedureCode, serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded, serviceUpdate.recvRanFuncList.ranFunToBeAdded) !=ROK)
3688 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeModified)
3691 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsModified;
3692 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3693 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
3694 if(BuildRanFunctionAddList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List,
3695 e2apMsg->choice.initiatingMessage->procedureCode, serviceUpdate.recvRanFuncList.numOfRanFunToBeModified, serviceUpdate.recvRanFuncList.ranFunToBeModified) !=ROK)
3701 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted)
3704 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsDeleted;
3705 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3706 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctionsID_List;
3707 if(BuildRanFunctionDeleteList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List,\
3708 serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted, serviceUpdate.recvRanFuncList.ranFunToBeDeleted) != ROK)
3713 /* Prints the Msg formed */
3714 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3716 memset(encBuf, 0, ENC_BUF_MAX_LEN);
3718 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
3719 if(encRetVal.encoded == ENCODE_FAIL)
3721 DU_LOG("\nERROR --> E2AP : Could not encode RicServiceUpdateuest structure (at %s)\n",\
3722 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3727 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RicServiceUpdateuest\n");
3728 #ifdef DEBUG_ASN_PRINT
3729 for(int i=0; i< encBufSize; i++)
3731 printf("%x",encBuf[i]);
3735 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
3737 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
3746 if(serviceUpdate.dir == E2_NODE_INITIATED)
3748 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
3749 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
3753 duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].transactionId = transId;
3754 duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
3756 duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.dir = serviceUpdate.dir;
3757 duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.transId =transId;
3758 memcpy(&duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.recvRanFuncList, &serviceUpdate.recvRanFuncList, sizeof(E2TmpRanFunList));
3760 FreeRicServiceUpdate(e2apMsg);
3763 /******************************************************************
3765 * @brief Processes RIC service Query sent by RIC
3769 * Function : procRicServiceQuery
3771 * Functionality: Processes RIC service Query sent by RIC
3773 * @params[in] E2AP_PDU_t ASN decoded E2AP message
3774 * @return ROK - success
3777 * ****************************************************************/
3779 void procRicServiceQuery(E2AP_PDU_t *e2apMsg)
3782 uint16_t arrIdx =0, ranFuncIdx=0,tmpIdx=0;
3783 uint16_t id,revisionCcounter;
3784 bool tmpArray[MAX_RAN_FUNCTION] = {false};
3785 RICserviceQuery_t *ricServiceQuery=NULL;
3786 RicServiceUpdate ricUpdate;
3787 RANfunctionID_ItemIEs_t *ranFuncAddedItemIe;
3788 RANfunctionsID_List_t *ranFuncAddedList;
3790 DU_LOG("\nINFO --> E2AP : RIC Service Query received");
3791 memset(&ricUpdate, 0, sizeof(RicServiceUpdate));
3792 ricUpdate.dir = RIC_INITIATED;
3793 ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
3795 for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
3797 switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
3799 /* TODO completing in next patch/gerrit */
3800 case ProtocolIE_IDE2_id_TransactionID:
3802 ricUpdate.transId = ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
3806 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
3808 ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
3809 if(ranFuncAddedList->list.array)
3811 for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
3813 if(ranFuncAddedList->list.array[ranFuncIdx])
3815 /* Using the RAN function Id, identify the RAN function to be modified or deleted. */
3817 ranFuncAddedItemIe = (RANfunctionID_ItemIEs_t*)ranFuncAddedList->list.array[ranFuncIdx];
3818 id = ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionID;
3819 revisionCcounter = ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionRevision;
3821 if((id != duCb.e2apDb.ranFunction[id-1].id))
3823 action = CONFIG_DEL;
3825 else if((id == duCb.e2apDb.ranFunction[id-1].id)&&(revisionCcounter!=duCb.e2apDb.ranFunction[id-1].revisionCounter))
3827 action = CONFIG_MOD;
3830 if(action == CONFIG_DEL)
3832 ricUpdate.recvRanFuncList.ranFunToBeDeleted[ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted].id = id;
3833 ricUpdate.recvRanFuncList.ranFunToBeDeleted[ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted].revisionCounter = revisionCcounter;
3834 ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted++;
3836 else if(action == CONFIG_MOD)
3838 ricUpdate.recvRanFuncList.ranFunToBeModified[ricUpdate.recvRanFuncList.numOfRanFunToBeModified].id = id;
3839 ricUpdate.recvRanFuncList.ranFunToBeModified[ricUpdate.recvRanFuncList.numOfRanFunToBeModified].revisionCounter = revisionCcounter;
3840 ricUpdate.recvRanFuncList.numOfRanFunToBeModified++;
3843 /* If any ID is set to true, it means that the ID has been used in either modification or deletion list.
3844 * Else we will add the IDs into the added list */
3845 tmpArray[id-1] = true;
3854 /* Traversing the whole RAN function list in ducb to check if any new Ran function ids have been added. */
3855 for(arrIdx =0; arrIdx<MAX_RAN_FUNCTION; arrIdx++)
3857 tmpIdx= ricUpdate.recvRanFuncList.numOfRanFunToBeAdded;
3858 if((duCb.e2apDb.ranFunction[arrIdx].id >0)&&(!tmpArray[arrIdx]))
3860 ricUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].id = duCb.e2apDb.ranFunction[arrIdx].id;
3861 ricUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].revisionCounter = duCb.e2apDb.ranFunction[arrIdx].revisionCounter;
3862 ricUpdate.recvRanFuncList.numOfRanFunToBeAdded++;
3866 if(BuildAndSendRicServiceUpdate(ricUpdate)!= ROK)
3868 DU_LOG("\nERROR --> E2AP : Failed to build and send ric service update message");
3871 freeAperDecodingOfRicServiceQuery(ricServiceQuery);
3874 /******************************************************************
3876 * @brief Deallocation of memory allocated by aper decoder for
3877 * RIC service update ack
3881 * Function : freeAperDecodingOfRicServiceUpdateAck
3883 * Functionality: Deallocation of memory allocated by aper decoder
3884 * for RIC service update ack
3886 * @params[in] RICserviceUpdateAck_t *ricServiceAck;
3889 * ****************************************************************/
3891 void freeAperDecodingOfRicServiceUpdateAck(RICserviceUpdateAcknowledge_t *ricServiceAck)
3893 uint8_t arrIdx=0,ranFuncIdx=0;
3894 RANfunctionsID_List_t *ranFuncAddedList=NULL;
3898 if(ricServiceAck->protocolIEs.list.array)
3900 for(arrIdx=0; arrIdx<ricServiceAck->protocolIEs.list.count; arrIdx++)
3902 if(ricServiceAck->protocolIEs.list.array[arrIdx])
3904 switch(ricServiceAck->protocolIEs.list.array[arrIdx]->id)
3906 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
3908 ranFuncAddedList= &ricServiceAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
3909 if(ranFuncAddedList->list.array)
3911 for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
3913 free(ranFuncAddedList->list.array[ranFuncIdx]);
3915 free(ranFuncAddedList->list.array);
3922 free(ricServiceAck->protocolIEs.list.array[arrIdx]);
3925 free(ricServiceAck->protocolIEs.list.array);
3930 /******************************************************************
3932 * @brief Processes RIC service update ack sent by RIC
3936 * Function : procRicServiceUpdateAck
3938 * Functionality: Processes RIC service update ack sent by RIC
3940 * @params[in] E2AP_PDU_t ASN decoded E2AP message
3941 * @return ROK - success
3944 * ****************************************************************/
3946 void procRicServiceUpdateAck(E2AP_PDU_t *e2apMsg)
3948 uint8_t arrIdx =0, transId =0;
3949 uint16_t id =0, tmpIdx=0, ranFuncIdx=0;
3950 RicServiceUpdate serviceUpdate;
3951 RANfunctionsIDcause_List_t *rejectedList=NULL;
3952 RICserviceUpdateAcknowledge_t *ricServiceAck=NULL;
3953 RANfunctionIDcause_ItemIEs_t *ranFuncRejectedItemIe=NULL;
3955 DU_LOG("\nINFO --> E2AP : RIC service update ack received");
3956 memset(&serviceUpdate, 0, sizeof(RicServiceUpdate));
3957 ricServiceAck = &e2apMsg->choice.successfulOutcome->value.choice.RICserviceUpdateAcknowledge;
3959 for(arrIdx=0; arrIdx<ricServiceAck->protocolIEs.list.count; arrIdx++)
3961 switch(ricServiceAck->protocolIEs.list.array[arrIdx]->id)
3963 case ProtocolIE_IDE2_id_TransactionID:
3965 transId = ricServiceAck->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
3966 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
3967 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
3969 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
3971 else if((duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].transactionId == transId) &&\
3972 (duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
3974 memset(&duCb.e2apDb.e2TransInfo.ricInitTransaction[transId], 0, sizeof(E2TransInfo));
3978 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
3984 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
3987 case ProtocolIE_IDE2_id_RANfunctionsRejected:
3989 rejectedList= &ricServiceAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsIDcause_List;
3990 if(rejectedList->list.array)
3992 for(ranFuncIdx=0;ranFuncIdx<rejectedList->list.count; ranFuncIdx++)
3994 ranFuncRejectedItemIe = (RANfunctionIDcause_ItemIEs_t*)rejectedList->list.array[ranFuncIdx];
3995 id = ranFuncRejectedItemIe->value.choice.RANfunctionIDcause_Item.ranFunctionID;
3996 tmpIdx= serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded;
3997 serviceUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].id = duCb.e2apDb.ranFunction[id-1].id;
3998 serviceUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].revisionCounter = duCb.e2apDb.ranFunction[id-1].revisionCounter;
3999 serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded++;
4008 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
4010 serviceUpdate.dir = E2_NODE_INITIATED;
4011 BuildAndSendRicServiceUpdate(serviceUpdate);
4013 freeAperDecodingOfRicServiceUpdateAck(ricServiceAck);
4016 /******************************************************************
4018 * @brief Deallocation of memory allocated by aper decoder for
4019 * RIC service update failure
4023 * Function : freeAperDecodingOfRicServiceUpdateFailure
4025 * Functionality: Deallocation of memory allocated by aper decoder
4026 * for RIC service update failure
4028 * @params[in] RICserviceUpdateFailure_t *ricServiceFailure;
4031 * ****************************************************************/
4033 void freeAperDecodingOfRicServiceUpdateFailure(RICserviceUpdateFailure_t *ricServiceFailure)
4037 if(ricServiceFailure)
4039 if(ricServiceFailure->protocolIEs.list.array)
4041 for(arrIdx=0; arrIdx<ricServiceFailure->protocolIEs.list.count; arrIdx++)
4043 if(ricServiceFailure->protocolIEs.list.array[arrIdx])
4045 free(ricServiceFailure->protocolIEs.list.array[arrIdx]);
4048 free(ricServiceFailure->protocolIEs.list.array);
4053 /******************************************************************
4055 * @brief Processes RIC service update failure sent by RIC
4059 * Function : procRicServiceUpdateFailure
4061 * Functionality: Processes RIC service update failure sent by RIC
4063 * @params[in] E2AP_PDU_t ASN decoded E2AP message
4064 * @return ROK - success
4067 * ****************************************************************/
4069 void procRicServiceUpdateFailure(E2AP_PDU_t *e2apMsg)
4071 uint8_t arrIdx =0, timerValue=0;
4072 RICserviceUpdateFailure_t *ricServiceFailure=NULL;
4074 DU_LOG("\nINFO --> E2AP : RIC service update failure received");
4075 ricServiceFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICserviceUpdateFailure;
4077 for(arrIdx=0; arrIdx<ricServiceFailure->protocolIEs.list.count; arrIdx++)
4079 switch(ricServiceFailure->protocolIEs.list.array[arrIdx]->id)
4081 case ProtocolIE_IDE2_id_TransactionID:
4085 case ProtocolIE_IDE2_id_TimeToWaitE2:
4087 timerValue = covertE2WaitTimerEnumToValue(ricServiceFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
4088 if((duChkTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer), EVENT_RIC_SERVICE_UPDATE_TMR)) == FALSE)
4090 duStartTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer), EVENT_RIC_SERVICE_UPDATE_TMR, timerValue);
4094 DU_LOG("\nERROR --> E2AP : EVENT_RIC_SERVICE_UPDATE_TMR timer is already running");
4099 case ProtocolIE_IDE2_id_CauseE2:
4106 freeAperDecodingOfRicServiceUpdateFailure(ricServiceFailure);
4109 /*******************************************************************
4111 * @brief Handles received E2AP message and sends back response
4115 * Function : E2APMsgHdlr
4118 * - Decodes received E2AP control message
4119 * - Prepares response message, encodes and sends to SCTP
4122 * @return ROK - success
4125 * ****************************************************************/
4126 void E2APMsgHdlr(Buffer *mBuf)
4129 char *recvBuf = NULLP;
4131 MsgLen recvBufLen =0;
4132 E2AP_PDU_t *e2apMsg = NULLP;
4133 asn_dec_rval_t rval ={0}; /* Decoder return value */
4134 E2AP_PDU_t e2apasnmsg={0} ;
4136 DU_LOG("\nDEBUG --> E2AP : Received E2AP message buffer");
4137 ODU_PRINT_MSG(mBuf, 0,0);
4139 /* Copy mBuf into char array to decode it */
4140 ODU_GET_MSG_LEN(mBuf, &recvBufLen);
4141 DU_ALLOC(recvBuf, (Size)recvBufLen);
4143 if(recvBuf == NULLP)
4145 DU_LOG("\nERROR --> E2AP : Memory allocation failed");
4148 if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
4150 DU_LOG("\nERROR --> E2AP : Failed while copying %d", copyCnt);
4154 #ifdef DEBUG_ASN_PRINT
4155 printf("\nDEBUG --> E2AP : Received flat buffer to be decoded : ");
4156 for(i=0; i< recvBufLen; i++)
4158 printf("%x",recvBuf[i]);
4162 /* Decoding flat buffer into E2AP messsage */
4163 e2apMsg = &e2apasnmsg;
4164 memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
4166 rval = aper_decode(0, &asn_DEF_E2AP_PDU, (void **)&e2apMsg, recvBuf, recvBufLen, 0, 0);
4167 DU_FREE(recvBuf, (Size)recvBufLen);
4169 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
4171 DU_LOG("\nERROR --> E2AP : ASN decode failed");
4175 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
4177 switch(e2apMsg->present)
4179 case E2AP_PDU_PR_unsuccessfulOutcome:
4181 switch(e2apMsg->choice.unsuccessfulOutcome->value.present)
4183 case UnsuccessfulOutcomeE2__value_PR_E2setupFailure:
4185 procE2SetupFailure(e2apMsg);
4190 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_unsuccessfulOutcome [%d]",\
4191 e2apMsg->choice.unsuccessfulOutcome->value.present);
4197 case E2AP_PDU_PR_successfulOutcome:
4199 switch(e2apMsg->choice.successfulOutcome->value.present)
4201 case SuccessfulOutcomeE2__value_PR_E2setupResponse:
4205 procE2SetupRsp(e2apMsg);
4209 case SuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateAcknowledge:
4211 DU_LOG("\nDEBUG --> E2AP : E2 node Config update ack message recevied");
4214 case SuccessfulOutcomeE2__value_PR_ResetResponseE2:
4216 procResetResponse(e2apMsg);
4219 case SuccessfulOutcomeE2__value_PR_RICserviceUpdateAcknowledge:
4221 procRicServiceUpdateAck(e2apMsg);
4228 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_successfulOutcome [%d]",\
4229 e2apMsg->choice.successfulOutcome->value.present);
4232 }/* End of switch(successfulOutcome) */
4233 free(e2apMsg->choice.successfulOutcome);
4237 case E2AP_PDU_PR_initiatingMessage:
4239 switch(e2apMsg->choice.initiatingMessage->value.present)
4241 case InitiatingMessageE2__value_PR_RICsubscriptionRequest:
4243 procRicSubscriptionRequest(e2apMsg);
4246 case InitiatingMessageE2__value_PR_RICserviceQuery:
4248 procRicServiceQuery(e2apMsg);
4253 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\
4254 e2apMsg->choice.initiatingMessage->value.present);
4257 }/* End of switch(initiatingMessage) */
4258 free(e2apMsg->choice.initiatingMessage);
4263 DU_LOG("\nERROR --> E2AP : Invalid type of e2apMsg->present [%d]",e2apMsg->present);
4268 }/* End of switch(e2apMsg->present) */
4270 } /* End of E2APMsgHdlr */
4272 /**********************************************************************
4274 **********************************************************************/