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 Builds Global gNodeB Params
61 * Function : BuildGlobalgNBId
63 * Functionality: Building the Plmn and gNB id
65 * @params[in] GlobalE2node_gNB_ID_t *gNbId
66 * @return ROK - success
69 ******************************************************************/
71 uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
75 uint8_t gnbId = duCb.gnbId;
78 /* fill Global gNB ID Id */
79 gNbId->global_gNB_ID.plmn_id.size = 3 * sizeof(uint8_t);
80 gNbId->global_gNB_ID.plmn_id.buf = NULLP;
81 DU_ALLOC(gNbId->global_gNB_ID.plmn_id.buf , gNbId->global_gNB_ID.plmn_id.size);
82 if(gNbId->global_gNB_ID.plmn_id.buf == NULLP)
84 DU_LOG("\nERROR --> E2AP: Memory allocation failed for Plmn buffer");
89 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
90 gNbId->global_gNB_ID.plmn_id.buf);
91 gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
92 /* Allocate Buffer size */
93 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = byteSize * sizeof(uint8_t);
94 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf = NULLP;
95 DU_ALLOC(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf, \
96 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
97 if(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf == NULLP)
99 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gnb buffer");
104 fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, gnbId);
109 DU_ALLOC( gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
110 if(gNbId->gNB_DU_ID == NULLP)
112 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gNB_DU_ID ");
117 gNbId->gNB_DU_ID->size = sizeof(uint8_t);
118 DU_ALLOC( gNbId->gNB_DU_ID->buf, sizeof(uint8_t));
119 if(gNbId->gNB_DU_ID->buf)
121 gNbId->gNB_DU_ID->buf[0] =duCb.e2apDb.e2NodeId;
125 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gNB_DU_ID buffer");
133 /******************************************************************
135 * @brief Search E2 node component with the help of action type
139 * Function : searchE2NodeComponentInfo
141 * Functionality: Search E2 node component with the help of action type
143 * @params[in] uint8_t componentActionType
146 * ****************************************************************/
148 CmLList *searchE2NodeComponentInfo(InterfaceType interfaceType, uint8_t componentActionType)
150 E2NodeComponent *e2NodeComponentInfo;
153 if(duCb.e2apDb.e2NodeComponentList.count)
155 CM_LLIST_FIRST_NODE(&duCb.e2apDb.e2NodeComponentList, node);
158 e2NodeComponentInfo = (E2NodeComponent*)node->node;
159 if((e2NodeComponentInfo->interfaceType == interfaceType) && (e2NodeComponentInfo->componentActionType == componentActionType))
168 /*******************************************************************
170 * @brief Builds E2 node config addition list
174 * Function : BuildE2NodeConfigAddList
176 * Functionality: Building E2 node config addition list
178 * @params[in] E2nodeComponentConfigAddition_List_t *e2NodeAddList
179 * @return ROK - success
182 ******************************************************************/
184 uint8_t BuildE2NodeConfigAddList(E2nodeComponentConfigAddition_List_t *e2NodeAddList)
188 E2NodeComponent *e2NodeComponentInfo;
189 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItemIe;
190 E2nodeComponentConfigAddition_Item_t *e2NodeAddItem;
192 e2NodeAddList->list.count = 1;
193 e2NodeAddList->list.size = e2NodeAddList->list.count * sizeof(E2nodeComponentConfigAddition_ItemIEs_t *);
194 DU_ALLOC(e2NodeAddList->list.array, e2NodeAddList->list.size);
195 if(e2NodeAddList->list.array == NULLP)
197 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
201 for(arrIdx = 0; arrIdx< e2NodeAddList->list.count; arrIdx++)
203 DU_ALLOC(e2NodeAddList->list.array[arrIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
204 if(e2NodeAddList->list.array[arrIdx] == NULLP)
206 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
211 node = searchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD);
214 DU_LOG("\nERROR --> E2AP : Received e2NodeComponentInfo is null");
217 e2NodeComponentInfo = (E2NodeComponent*)node->node;
220 e2NodeAddItemIe = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[arrIdx];
221 e2NodeAddItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition_Item;
222 e2NodeAddItemIe->criticality = CriticalityE2_reject;
223 e2NodeAddItemIe->value.present = E2nodeComponentConfigAddition_ItemIEs__value_PR_E2nodeComponentConfigAddition_Item;
224 e2NodeAddItem = &e2NodeAddItemIe->value.choice.E2nodeComponentConfigAddition_Item;
226 /* E2nodeComponentInterfaceType */
227 e2NodeAddItem->e2nodeComponentInterfaceType = E2nodeComponentInterfaceType_f1;
229 /* E2 Node Component Request Part */
230 if(e2NodeComponentInfo->componentRequestPart)
232 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size = e2NodeComponentInfo->reqBufSize ;
233 DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
234 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
235 if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf == NULLP)
237 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
241 memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
242 e2NodeComponentInfo->componentRequestPart, e2NodeAddItem->e2nodeComponentConfiguration.\
243 e2nodeComponentRequestPart.size);
247 DU_LOG("\nERROR --> E2AP: componentRequestPart is null ");
252 /* E2 Node Component Response Part */
253 if(e2NodeComponentInfo->componentResponsePart)
255 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size = e2NodeComponentInfo->rspBufSize;
256 DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \
257 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
258 if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf == NULLP)
260 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
263 memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \
264 e2NodeComponentInfo->componentResponsePart, e2NodeAddItem->e2nodeComponentConfiguration.\
265 e2nodeComponentResponsePart.size);
269 DU_LOG("\nERROR --> E2AP: componentResponsePart is null");
273 /* E2 Node Component ID */
274 e2NodeAddItem->e2nodeComponentID.present = E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1;
275 DU_ALLOC(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
276 sizeof(E2nodeComponentInterfaceF1_t));
277 if(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1 == NULLP)
279 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
282 e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size = sizeof(uint8_t);
283 DU_ALLOC(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
284 e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
286 if(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf == NULLP)
288 DU_LOG("\nERROR -->list. E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
291 e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[arrIdx] = e2NodeComponentInfo->componentId;
296 /*******************************************************************
298 * @brief deallocation of E2SM_KPM_RANfunction_Description_t
302 * Function : freeE2smKpmRanFunctionDefinition
304 * Functionality: deallocation of E2SM_KPM_RANfunction_Description_t
306 * @params[in] E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition
309 ******************************************************************/
311 void freeE2smKpmRanFunctionDefinition(E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition)
313 MeasurementInfo_Action_Item_t *measInfoList;
314 uint8_t eventTriggerIdx, reportStyleIdx, measInfoIdx;
315 RANfunction_Name_t *ranFuncName;
316 struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle;
317 struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *eventTriggerStyle;
318 if(ranFunctionDefinition)
320 ranFuncName = &ranFunctionDefinition->ranFunction_Name;
321 /* Free RAN function Name */
322 DU_FREE(ranFuncName->ranFunction_ShortName.buf, ranFuncName->ranFunction_ShortName.size);
323 DU_FREE(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
324 DU_FREE(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
326 /* Sequence of Event Trigger styles */
327 eventTriggerStyle = ranFunctionDefinition->ric_EventTriggerStyle_List;
328 if(eventTriggerStyle)
330 if(eventTriggerStyle->list.array)
332 for(eventTriggerIdx =0;eventTriggerIdx<eventTriggerStyle->list.count; eventTriggerIdx++)
334 if(eventTriggerStyle->list.array[eventTriggerIdx])
336 DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.buf,\
337 eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.size);
338 DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
341 DU_FREE(eventTriggerStyle->list.array, eventTriggerStyle->list.size)
343 DU_FREE(eventTriggerStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
346 /* Sequence of Report styles */
347 ricReportStyle = ranFunctionDefinition->ric_ReportStyle_List;
350 if(ricReportStyle->list.array)
352 for(reportStyleIdx =0;reportStyleIdx<ricReportStyle->list.count; reportStyleIdx++)
354 if(ricReportStyle->list.array[reportStyleIdx])
356 if(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf)
358 DU_FREE(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf,\
359 ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.size);
361 if(ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array)
363 for(measInfoIdx=0; measInfoIdx<ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.count; \
366 measInfoList = ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array[measInfoIdx];
369 DU_FREE(measInfoList->measID, sizeof(long));
370 DU_FREE(measInfoList->measName.buf, measInfoList->measName.size);
371 DU_FREE(measInfoList,sizeof(MeasurementInfo_Action_Item_t));
374 DU_FREE(measInfoList,ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.size);
376 DU_FREE(ricReportStyle->list.array[reportStyleIdx], sizeof(RIC_ReportStyle_Item_t));
379 DU_FREE(ricReportStyle->list.array, ricReportStyle->list.size);
381 DU_FREE(ricReportStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
383 DU_FREE(ranFunctionDefinition, sizeof(E2SM_KPM_RANfunction_Description_t));
387 /*******************************************************************
389 * @brief fill the e2sm ric report style
393 * Function : fillRicReportStyle
395 * Functionality: fill the report style
397 * @params[in] RanFunction *ranFuncDb, struct
398 * E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle
399 * @return ROK - success
402 ******************************************************************/
403 uint8_t fillRicReportStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle)
405 uint8_t styleIdx, measInfoIdx;
406 MeasurementInfo_Action_List_t *measInfo;
409 ricReportStyle->list.count = ranFuncDb->numOfReportStyleSupported;
410 ricReportStyle->list.size = ricReportStyle->list.count * sizeof(RIC_ReportStyle_Item_t*);
411 DU_ALLOC(ricReportStyle->list.array, ricReportStyle->list.size);
412 if(!ricReportStyle->list.array)
414 DU_LOG("\nERROR --> E2AP: Memory allocation failed for ranFuncDefinition %d",__LINE__);
418 for(styleIdx =0;styleIdx<ricReportStyle->list.count; styleIdx++)
420 DU_ALLOC(ricReportStyle->list.array[styleIdx], sizeof(RIC_ReportStyle_Item_t));
421 if(!ricReportStyle->list.array[styleIdx])
423 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
427 /* RIC Report Style Type */
428 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.styleType;
430 /* RIC Report Style Format Type */
431 ricReportStyle->list.array[styleIdx]->ric_ActionFormat_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.formatType;
433 /* RIC Report Style Name */
434 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size = strlen(ranFuncDb->reportStyleList[styleIdx].reportStyle.name);
435 DU_ALLOC(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf,\
436 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
437 if(!ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf)
439 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
442 memcpy(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf, ranFuncDb->reportStyleList[styleIdx].reportStyle.name,\
443 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
445 /* RIC Indication Header Format Type*/
446 ricReportStyle->list.array[styleIdx]->ric_IndicationHeaderFormat_Type = ranFuncDb->ricIndicationHeaderFormat;
448 /* RIC Indication Message Format Type*/
449 ricReportStyle->list.array[styleIdx]->ric_IndicationMessageFormat_Type = ranFuncDb->ricIndicationMessageFormat;
451 /* Measurement Info Action List */
452 CmLListCp measInfoList =ranFuncDb->reportStyleList[styleIdx].measurementInfoList;
453 if(!measInfoList.count)
458 CM_LLIST_FIRST_NODE(&ranFuncDb->reportStyleList[styleIdx].measurementInfoList, node);
459 measInfo = &ricReportStyle->list.array[styleIdx]->measInfo_Action_List;
461 measInfo->list.count = measInfoList.count;
462 measInfo->list.size = measInfoList.count*sizeof(MeasurementInfo_Action_Item_t*);
463 DU_ALLOC(measInfo->list.array, measInfo->list.size);
464 if(!measInfo->list.array)
466 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
470 for(measInfoIdx=0; measInfoIdx<measInfo->list.count; measInfoIdx++)
474 DU_LOG("\nERROR --> E2AP: Measurement info node is null");
478 DU_ALLOC(measInfo->list.array[measInfoIdx],sizeof(MeasurementInfo_Action_Item_t));
479 if(!measInfo->list.array[measInfoIdx])
481 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
484 MeasurementInfoForAction *measInfoForAction= (MeasurementInfoForAction*)node->node;
485 DU_ALLOC(measInfo->list.array[measInfoIdx]->measID, sizeof(long));
486 if(!measInfo->list.array[measInfoIdx]->measID)
488 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
492 memcpy(measInfo->list.array[measInfoIdx]->measID, &measInfoForAction->measurementTypeId,sizeof(long));
493 measInfo->list.array[measInfoIdx]->measName.size= strlen(measInfoForAction->measurementTypeName);
494 DU_ALLOC(measInfo->list.array[measInfoIdx]->measName.buf, measInfo->list.array[measInfoIdx]->measName.size);
495 if(!measInfo->list.array[measInfoIdx]->measName.size)
497 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
501 memcpy(measInfo->list.array[measInfoIdx]->measName.buf, \
502 measInfoForAction->measurementTypeName,\
503 measInfo->list.array[measInfoIdx]->measName.size);
510 /*******************************************************************
512 * @brief fill the ric event trigger style
516 * Function : fillRicEventTriggerStyle
518 * Functionality: fill the ric event trigger style
521 * @return ROK - success
524 ******************************************************************/
525 uint8_t fillRicEventTriggerStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *ricEventTriggerStyle)
529 ricEventTriggerStyle->list.count = ranFuncDb->numOfEventTriggerStyleSupported;
530 ricEventTriggerStyle->list.size = ricEventTriggerStyle->list.count* sizeof(RIC_EventTriggerStyle_Item_t *);
531 DU_ALLOC(ricEventTriggerStyle->list.array, ricEventTriggerStyle->list.size);
532 if(!ricEventTriggerStyle->list.array)
534 DU_LOG("\nERROR --> E2AP: Memory allocation failed for ric_EventTriggerStyle_List %d",__LINE__);
538 for(styleIdx =0;styleIdx<ricEventTriggerStyle->list.count; styleIdx++)
540 DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
541 if(!ricEventTriggerStyle->list.array[styleIdx])
543 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
546 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Type = ranFuncDb->eventTriggerStyleList[styleIdx].styleType;
548 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerFormat_Type = ranFuncDb->eventTriggerStyleList[styleIdx].formatType;
550 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size = strlen(ranFuncDb->eventTriggerStyleList[styleIdx].name);
551 DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,\
552 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
553 if(!ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf)
555 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
558 memcpy(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,ranFuncDb->eventTriggerStyleList[styleIdx].name,\
559 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
565 /*******************************************************************
567 * @brief Builds Ran function item
571 * Function : BuildRanFunctionItem
573 * Functionality: Building RAN function item
576 * RAN function item that has to be filled
577 * Stored RAN Function information
578 * @return ROK - success
581 ******************************************************************/
583 uint8_t BuildRanFunctionItem(RANfunction_Item_t *ranFuncItem, RanFunction *ranFuncDb)
585 uint8_t ret =RFAILED;
586 RANfunctionDefinition_t *ranFunctionDefinition;
587 RANfunction_Name_t *ranFuncName;
588 asn_enc_rval_t encRetVal;
589 E2SM_KPM_RANfunction_Description_t *ranFuncDefinition;
594 ranFuncItem->ranFunctionID = ranFuncDb->id;
596 /* RAN Function Revision*/
597 ranFuncItem->ranFunctionRevision = ranFuncDb->revisionCounter;
599 /* RAN function OID*/
600 ranFuncItem->ranFunctionOID.size = strlen(ranFuncDb->name.serviceModelOID);
601 DU_ALLOC(ranFuncItem->ranFunctionOID.buf, ranFuncItem->ranFunctionOID.size);
602 if(!ranFuncItem->ranFunctionOID.buf)
604 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
607 memcpy(ranFuncItem->ranFunctionOID.buf, ranFuncDb->name.serviceModelOID, ranFuncItem->ranFunctionOID.size);
609 /* RAN function Definition */
610 DU_ALLOC(ranFuncDefinition, sizeof(E2SM_KPM_RANfunction_Description_t));
611 if(!ranFuncDefinition)
613 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
617 /* RAN function Name */
618 ranFuncName = &ranFuncDefinition->ranFunction_Name;
620 /* RAN function ShortName */
621 ranFuncName->ranFunction_ShortName.size = strlen(ranFuncDb->name.shortName);
622 DU_ALLOC(ranFuncName->ranFunction_ShortName.buf, ranFuncName->ranFunction_ShortName.size);
623 if(!ranFuncName->ranFunction_ShortName.buf)
625 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
628 memcpy(ranFuncName->ranFunction_ShortName.buf, ranFuncDb->name.shortName, strlen(ranFuncDb->name.shortName));
630 /* RAN function E2SM_OID */
631 ranFuncName->ranFunction_E2SM_OID.size = strlen(ranFuncDb->name.serviceModelOID);
632 DU_ALLOC(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
633 if(!ranFuncName->ranFunction_E2SM_OID.buf)
635 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
638 memcpy(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncDb->name.serviceModelOID, ranFuncName->ranFunction_E2SM_OID.size);
640 /* RAN Function Name Description */
641 ranFuncName->ranFunction_Description.size = strlen(ranFuncDb->name.description);
642 DU_ALLOC(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
643 if(!ranFuncName->ranFunction_Description.buf)
645 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
648 memcpy(ranFuncName->ranFunction_Description.buf, ranFuncDb->name.description, ranFuncName->ranFunction_Description.size);
650 /* RIC Event Trigger Style List */
651 DU_ALLOC(ranFuncDefinition->ric_EventTriggerStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
652 if(!ranFuncDefinition->ric_EventTriggerStyle_List)
654 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
658 if(fillRicEventTriggerStyle(ranFuncDb, ranFuncDefinition->ric_EventTriggerStyle_List)!=ROK)
660 DU_LOG("\nERROR --> E2AP: failed to fill ric event trigger style");
664 /* RIC Report Style List */
665 DU_ALLOC(ranFuncDefinition->ric_ReportStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
666 if(!ranFuncDefinition->ric_ReportStyle_List)
668 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
671 if(fillRicReportStyle(ranFuncDb, ranFuncDefinition->ric_ReportStyle_List) != ROK)
673 DU_LOG("\nERROR --> E2AP: failed to fill ric report style");
677 /* Encode the F1SetupRequest type as APER */
678 xer_fprint(stdout, &asn_DEF_E2SM_KPM_RANfunction_Description, ranFuncDefinition);
680 memset(encBuf, 0, ENC_BUF_MAX_LEN);
682 encRetVal = aper_encode(&asn_DEF_E2SM_KPM_RANfunction_Description, 0, ranFuncDefinition, PrepFinalEncBuf, encBuf);
685 if(encRetVal.encoded == ENCODE_FAIL)
687 DU_LOG("\nERROR --> F1AP : Could not encode RAN function definition (at %s)\n",\
688 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
693 DU_LOG("\nDEBUG --> F1AP : Created APER encoded buffer for RAN function definition \n");
694 for(uint8_t measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
696 printf("%x",encBuf[measIeIdx]);
698 ranFunctionDefinition = &ranFuncItem->ranFunctionDefinition;
699 ranFunctionDefinition->size = encBufSize;
700 DU_ALLOC(ranFunctionDefinition->buf, encBufSize);
701 if(ranFunctionDefinition->buf == NULLP)
703 DU_LOG("\nERROR --> F1AP : Memory allocation failed for RAN function definition buffer");
706 memcpy(ranFunctionDefinition->buf, &encBuf, encBufSize);
711 freeE2smKpmRanFunctionDefinition(ranFuncDefinition);
715 /*******************************************************************
717 * @brief Builds Ran function add list based on the procedure code
721 * Function : BuildRanFunctionAddList
723 * Functionality: Building RAN addition addition list
724 * In case of ProcedureCodeE2_id_E2setup we add all the RAN Function list
725 * which is present in E2 database.
726 * In the case of other procedures, we just fill the RAN functions whose ID
727 * is contained in recvList
732 * Count of ran functions to be added in the list
733 * Received list of RAN functions
735 * @return ROK - success
738 ******************************************************************/
740 uint8_t BuildRanFunctionAddList(RANfunctions_List_t *ranFunctionsList, uint8_t procedureCode, uint8_t count, RanFuncInfo *recvList)
743 RanFunction *ranFuncDb;
745 RANfunction_ItemIEs_t *ranFuncItemIe;
747 /* For ProcedureCodeE2_id_E2setup, the number of RAN function list items is
748 * equal to the number of ran function entries stored in the database.
749 * For any other procedure, the RAN function list count is equal
750 * to the count of ran functions obtained from the function's caller */
752 if(procedureCode == ProcedureCodeE2_id_E2setup)
753 ranFunctionsList->list.count = duCb.e2apDb.numOfRanFunction;
755 ranFunctionsList->list.count = count;
757 ranFunctionsList->list.size = ranFunctionsList->list.count * sizeof(RANfunction_ItemIEs_t*);
758 DU_ALLOC(ranFunctionsList->list.array, ranFunctionsList->list.size);
759 if(ranFunctionsList->list.array == NULLP)
761 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
765 for(ranFuncIdx = 0; ranFuncIdx< ranFunctionsList->list.count; ranFuncIdx++)
767 DU_ALLOC(ranFunctionsList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
768 if(ranFunctionsList->list.array[ranFuncIdx] == NULLP)
770 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
773 if(procedureCode == ProcedureCodeE2_id_E2setup)
775 /* Getting all of the RAN function's information from DuCb one by one*/
776 ranFuncDb = &duCb.e2apDb.ranFunction[ranFuncIdx];
780 /* Getting only the RAN function information from DuCb whose Id is
781 * present in the received array */
782 id =recvList[ranFuncIdx].id;
783 ranFuncDb = &duCb.e2apDb.ranFunction[id-1];
785 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncIdx];
786 ranFuncItemIe->id = ProtocolIE_IDE2_id_RANfunction_Item;
787 ranFuncItemIe->criticality = CriticalityE2_ignore;
788 ranFuncItemIe->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
789 BuildRanFunctionItem(&ranFuncItemIe->value.choice.RANfunction_Item, ranFuncDb);
794 /*******************************************************************
796 * @brief De Allocate E2 Setup Request Message
800 * Function : FreeE2SetupReq
802 * Functionality: De-Allocating E2 Setup request Message
804 * @params[in] E2AP_PDU_t *e2apMsg
808 * ****************************************************************/
810 void FreeE2SetupReq(E2AP_PDU_t *e2apMsg)
813 uint8_t e2NodeAddListIdx =0, ranFuncAddListIdx;
814 E2setupRequest_t *e2SetupReq;
815 E2nodeComponentConfigAddition_List_t *e2NodeAddList;
816 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem;
817 RANfunctions_List_t *ranFunctionsList;
818 RANfunction_ItemIEs_t *ranFuncItemIe;
819 RANfunction_Item_t *ranFunItem;
821 /* De-allocating Memory */
824 if(e2apMsg->choice.initiatingMessage != NULLP)
826 e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
827 if(e2SetupReq->protocolIEs.list.array != NULLP)
829 for(arrIdx = 0; arrIdx < e2SetupReq->protocolIEs.list.count; arrIdx++)
831 if(e2SetupReq->protocolIEs.list.array[arrIdx] != NULLP)
833 switch(e2SetupReq->protocolIEs.list.array[arrIdx]->id)
835 case ProtocolIE_IDE2_id_TransactionID:
837 case ProtocolIE_IDE2_id_GlobalE2node_ID:
839 if(e2SetupReq->protocolIEs.list.array[arrIdx]->\
840 value.choice.GlobalE2node_ID.choice.gNB != NULLP)
842 GlobalE2node_gNB_ID_t *gNbId = NULLP;
843 gNbId = e2SetupReq->protocolIEs.list.array[arrIdx]->\
844 value.choice.GlobalE2node_ID.choice.gNB;
845 if(gNbId->global_gNB_ID.plmn_id.buf != NULLP)
847 DU_FREE(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf,\
848 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
849 DU_FREE(gNbId->global_gNB_ID.plmn_id.buf,\
850 gNbId->global_gNB_ID.plmn_id.size);
853 if(gNbId->gNB_DU_ID != NULLP)
855 DU_FREE( gNbId->gNB_DU_ID->buf, gNbId->gNB_DU_ID->size);
856 DU_FREE(gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
858 DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
859 choice.GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
863 case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
865 e2NodeAddList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List;
866 if(e2NodeAddList->list.array)
868 for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++)
870 e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[e2NodeAddListIdx];
872 /* Free E2 Node Component Request Part */
873 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
874 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
876 /* Free E2 Node Component Response Part */
877 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.\
878 e2nodeComponentResponsePart.buf, \
879 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
881 /* Free E2 Node Component ID */
882 if(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1)
884 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
885 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
886 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
887 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
888 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
889 sizeof(E2nodeComponentInterfaceF1_t));
891 DU_FREE(e2NodeAddList->list.array[e2NodeAddListIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
893 DU_FREE(e2NodeAddList->list.array, e2NodeAddList->list.size);
897 case ProtocolIE_IDE2_id_RANfunctionsAdded:
899 ranFunctionsList = &(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List);
900 if(ranFunctionsList->list.array)
902 for(ranFuncAddListIdx= 0; ranFuncAddListIdx< ranFunctionsList->list.count; ranFuncAddListIdx++)
904 if(ranFunctionsList->list.array[ranFuncAddListIdx])
906 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncAddListIdx];
907 ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
908 DU_FREE(ranFunItem->ranFunctionOID.buf, ranFunItem->ranFunctionOID.size);
909 DU_FREE(ranFunItem->ranFunctionDefinition.buf, ranFunItem->ranFunctionDefinition.size);
910 DU_FREE(ranFunctionsList->list.array[ranFuncAddListIdx], sizeof(RANfunction_ItemIEs_t));
913 DU_FREE(ranFunctionsList->list.array, ranFunctionsList->list.size);
919 DU_LOG("\nERROR --> E2AP: Invalid event at e2SetupRequet %ld ",\
920 (e2SetupReq->protocolIEs.list.array[arrIdx]->id));
923 DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx], sizeof(E2setupRequestIEs_t));
926 DU_FREE(e2SetupReq->protocolIEs.list.array, e2SetupReq->protocolIEs.list.size);
928 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
930 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
934 /*******************************************************************
936 * @brief Builds and Send the E2SetupRequest
940 * Function : BuildAndSendE2SetupReq
942 * Functionality:Fills the E2SetupRequest
944 * @return ROK - success
947 ******************************************************************/
949 uint8_t BuildAndSendE2SetupReq()
951 uint8_t arrIdx = 0, elementCnt=0;
952 uint8_t transId = 0, ret = ROK;
954 E2AP_PDU_t *e2apMsg = NULLP;
955 E2setupRequest_t *e2SetupReq = NULLP;
956 asn_enc_rval_t encRetVal; /* Encoder return value */
958 DU_LOG("\nINFO --> E2AP : Building E2 Setup Request\n");
961 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
964 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
967 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
968 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
969 if(e2apMsg->choice.initiatingMessage == NULLP)
971 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
974 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
975 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2setup;
976 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_E2setupRequest;
977 e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
980 e2SetupReq->protocolIEs.list.count = elementCnt;
981 e2SetupReq->protocolIEs.list.size = elementCnt * sizeof(E2setupRequestIEs_t*);
983 /* Initialize the E2Setup members */
984 DU_ALLOC(e2SetupReq->protocolIEs.list.array, \
985 e2SetupReq->protocolIEs.list.size);
986 if(e2SetupReq->protocolIEs.list.array == NULLP)
988 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements");
991 for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
993 DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx],\
994 sizeof(E2setupRequestIEs_t));
995 if(e2SetupReq->protocolIEs.list.array[arrIdx] == NULLP)
997 memAllocFailed = true;
998 DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayarrIdx [%d]", arrIdx);
1002 if(memAllocFailed == true)
1008 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
1009 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1010 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
1011 transId = assignTransactionId();
1012 e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
1015 /* GlobalE2node_gNB_ID */
1016 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_GlobalE2node_ID;
1017 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1018 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
1019 e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
1021 DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
1022 GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
1023 if(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
1024 GlobalE2node_ID.choice.gNB == NULLP)
1026 DU_LOG("\nERROR --> E2AP : Memory allocation failed for gNbId");
1031 ret = BuildGlobalgNBId(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
1032 choice.GlobalE2node_ID.choice.gNB);
1035 DU_LOG("\nERROR --> E2AP : Failed to build Global Gnb Id");
1040 /* RAN Functions Added List */
1042 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
1043 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1044 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_RANfunctions_List;
1045 if(BuildRanFunctionAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List), ProcedureCodeE2_id_E2setup, 0, NULL)!=ROK)
1047 DU_LOG("\nERROR --> E2AP : Failed to create RAN Function");
1051 /* E2 Node Component Configuration Addition List */
1053 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition;
1054 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1055 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_E2nodeComponentConfigAddition_List;
1056 if(BuildE2NodeConfigAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List))!=ROK)
1058 DU_LOG("\nERROR --> E2AP : Failed to create E2 Node config list");
1064 /* Prints the Msg formed */
1065 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1067 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1069 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
1071 if(encRetVal.encoded == ENCODE_FAIL)
1073 DU_LOG("\nERROR --> E2AP : Could not encode E2SetupRequest structure (at %s)\n",\
1074 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1079 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupRequest\n");
1080 #ifdef DEBUG_ASN_PRINT
1081 for(int i=0; i< encBufSize; i++)
1083 printf("%x",encBuf[i]);
1087 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
1089 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
1094 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
1095 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
1097 FreeE2SetupReq(e2apMsg);
1099 }/* End of BuildAndSendE2SetupReq */
1101 /*******************************************************************
1103 * @brief Builds Ric Request Id
1107 * Function : BuildRicRequestId
1109 * Functionality: Building the Ric Request Id
1111 * @params[in] RICrequestID_t *ricReqId
1112 * @return ROK - success
1115 * ****************************************************************/
1117 uint8_t BuildRicRequestId(RICrequestID_t *ricReqId)
1119 if(ricReqId == NULLP)
1124 ricReqId->ricRequestorID = 1;
1125 ricReqId->ricInstanceID = 1;
1129 /*******************************************************************
1131 * @brief Fills the mandatory RicAdmitted List Items
1135 * Function : fillRicAdmitList
1137 * Functionality: Fills the mandatory Ric Admitted List Items
1139 * @params[in] RICaction_Admitted_ItemIEs_t *ricAdmitItems
1140 * @return ROK - success
1143 * ****************************************************************/
1145 uint8_t fillRicAdmitList(RICaction_Admitted_ItemIEs_t *ricAdmitItems)
1148 if(ricAdmitItems != NULLP)
1150 ricAdmitItems->id = ProtocolIE_IDE2_id_RICaction_Admitted_Item;
1151 ricAdmitItems->criticality = CriticalityE2_reject;
1152 ricAdmitItems->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
1153 ricAdmitItems->value.choice.RICaction_Admitted_Item.ricActionID = 1;
1161 /*******************************************************************
1163 * @brief Builds the mandatory RicAdmitted List Params
1167 * Function : BuildRicAdmitList
1169 * Functionality: Builds the mandatory Ric Admitted List Params
1171 * @params[in] RICaction_Admitted_List_t *admitListPtr
1172 * @return ROK - success
1175 * ****************************************************************/
1177 uint8_t BuildRicAdmitList(RICaction_Admitted_List_t *admitListPtr)
1184 if(admitListPtr == NULLP)
1186 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC Admit List failed");
1191 admitListPtr->list.count = elementCnt;
1192 admitListPtr->list.size = elementCnt * sizeof(RICaction_Admitted_ItemIEs_t);
1193 DU_ALLOC(admitListPtr->list.array, admitListPtr->list.size);
1194 if(admitListPtr->list.array == NULLP)
1196 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC Admit List failed");
1201 for(idx=0 ; idx<elementCnt ; idx++ )
1203 DU_ALLOC(admitListPtr->list.array[idx], sizeof(RICaction_Admitted_ItemIEs_t));
1204 if(admitListPtr->list.array[idx] == NULLP)
1212 fillRicAdmitList((RICaction_Admitted_ItemIEs_t *)admitListPtr->list.array[idx]);
1218 /*******************************************************************
1220 * @breif Deallocation of BuildAndSendRicSubscriptionRsp memory
1224 * Function : FreeRicSubscriptionRsp
1226 * Functionality:Free the RicSubscriptionRsp
1228 * @param[in] E2AP_PDU_t *e2apRicMsg
1233 ******************************************************************/
1234 void FreeRicSubscriptionRsp(E2AP_PDU_t *e2apRicMsg)
1236 RICsubscriptionResponse_t *ricSubscriptionRsp= NULLP;
1239 RICaction_Admitted_List_t *admitListPtr;
1241 if(e2apRicMsg != NULLP)
1243 if(e2apRicMsg->choice.successfulOutcome != NULLP)
1245 ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
1246 if(ricSubscriptionRsp)
1248 if(ricSubscriptionRsp->protocolIEs.list.array != NULLP)
1250 for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
1252 if(ricSubscriptionRsp->protocolIEs.list.array[idx] != NULLP)
1254 switch(ricSubscriptionRsp->protocolIEs.list.array[idx]->id)
1256 case ProtocolIE_IDE2_id_RICrequestID:
1259 case ProtocolIE_IDE2_id_RANfunctionID:
1262 case ProtocolIE_IDE2_id_RICactions_Admitted:
1264 admitListPtr = &ricSubscriptionRsp->protocolIEs.list.\
1265 array[idx]->value.choice.RICaction_Admitted_List;
1266 if(admitListPtr->list.array != NULLP)
1268 for(idx1=0 ; idx1<admitListPtr->list.count; idx1++ )
1270 if(admitListPtr->list.array[idx1] != NULLP)
1272 DU_FREE(admitListPtr->list.array[idx1],
1273 sizeof(RICaction_Admitted_ItemIEs_t));
1276 DU_FREE(admitListPtr->list.array, admitListPtr->list.size);
1283 DU_FREE(ricSubscriptionRsp->protocolIEs.list.array[idx], \
1284 sizeof(RICsubscriptionResponse_IEs_t));
1287 DU_FREE(ricSubscriptionRsp->protocolIEs.list.array, \
1288 ricSubscriptionRsp->protocolIEs.list.size);
1291 DU_FREE(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
1293 DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
1296 /*******************************************************************
1298 * @brief Builds and Send the RicSubscriptionRsp
1302 * Function : BuildAndSendRicSubscriptionRsp
1304 * functionality:Fills the RicSubscriptionRsp
1306 * @return ROK - success
1309 ******************************************************************/
1310 uint8_t FillRicSubscriptionRsp(RICsubscriptionResponse_t *ricSubscriptionRsp )
1314 uint8_t elementCnt = 0;
1315 uint8_t BuildRicRequestIdret=ROK;
1316 uint8_t BuildRicAdmitListret=ROK;
1319 ricSubscriptionRsp->protocolIEs.list.count = elementCnt;
1320 ricSubscriptionRsp->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionResponse_IEs_t);
1321 DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array, \
1322 ricSubscriptionRsp->protocolIEs.list.size);
1323 if(ricSubscriptionRsp->protocolIEs.list.array == NULLP)
1325 DU_LOG("\nERROR --> E2AP : Memory allocation for FillRicSubscriptionRsp failed");
1330 for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
1332 DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array[idx], \
1333 sizeof(RICsubscriptionResponse_IEs_t));
1334 if(ricSubscriptionRsp->protocolIEs.list.array[idx] == NULLP)
1343 ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
1344 ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1345 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
1346 RICsubscriptionRequest_IEs__value_PR_RICrequestID;
1347 BuildRicRequestIdret =
1348 BuildRicRequestId(&ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RICrequestID);
1349 if(BuildRicRequestIdret != ROK)
1356 ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
1357 ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1358 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
1359 RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
1360 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RANfunctionID = 1;
1363 ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactions_Admitted;
1364 ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1365 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
1366 RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
1367 BuildRicAdmitListret =
1368 BuildRicAdmitList(&ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RICaction_Admitted_List);
1369 if(BuildRicAdmitListret != ROK)
1378 /*******************************************************************
1380 * @brief Builds and Send the RicSubscriptionRsp
1384 * Function : BuildAndSendRicSubscriptionRsp
1386 * Functionality:Fills the RicSubscriptionRsp
1388 * @return ROK - success
1391 ******************************************************************/
1393 uint8_t BuildAndSendRicSubscriptionRsp()
1396 E2AP_PDU_t *e2apRicMsg = NULLP;
1397 RICsubscriptionResponse_t *ricSubscriptionRsp=NULLP;
1398 asn_enc_rval_t encRetVal;
1399 uint8_t ret = RFAILED;
1400 uint8_t FillRicricSubscriptionRspret;
1404 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Response\n");
1406 DU_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t));
1407 if(e2apRicMsg == NULLP)
1409 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1412 e2apRicMsg->present = E2AP_PDU_PR_successfulOutcome;
1413 DU_ALLOC(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
1414 if(e2apRicMsg->choice.successfulOutcome == NULLP)
1416 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC subscription Response failed");
1420 e2apRicMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
1421 e2apRicMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
1422 e2apRicMsg->choice.successfulOutcome->value.present = \
1423 SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse;
1424 ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
1426 FillRicricSubscriptionRspret = FillRicSubscriptionRsp(ricSubscriptionRsp);
1427 if(FillRicricSubscriptionRspret != ROK)
1429 DU_LOG("\nERROR --> E2AP : Memory allocation for RICsubscriptionResponseIE failed");
1433 /* Prints the Msg formed */
1434 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg);
1436 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1438 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apRicMsg, PrepFinalEncBuf,\
1440 if(encRetVal.encoded == ENCODE_FAIL)
1442 DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Response structure (at %s)\n",\
1443 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1448 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC subscription response \n");
1449 #ifdef DEBUG_ASN_PRINT
1450 for(int i=0; i< encBufSize; i++)
1452 printf("%x",encBuf[i]);
1457 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
1459 DU_LOG("\nERROR --> E2AP : Sending RIC Subscription Response failed");
1467 FreeRicSubscriptionRsp(e2apRicMsg);
1472 /******************************************************************
1474 * @brief Deallocation of memory allocated bu aper decoder for e2 setup response
1478 * Function : freeAperDecodingOfE2SetupRsp
1480 * Functionality: Deallocation of memory allocated bu aper decoder for e2
1483 * @params[in] E2setupResponse_t *e2SetRspMsg;
1486 * ****************************************************************/
1487 void freeAperDecodingOfE2SetupRsp(E2setupResponse_t *e2SetRspMsg)
1489 uint8_t arrIdx, e2NodeConfigAddAckListIdx;
1490 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem;
1491 E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAddAckList;
1495 if(e2SetRspMsg->protocolIEs.list.array)
1497 for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
1499 if(e2SetRspMsg->protocolIEs.list.array[arrIdx])
1501 switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
1503 case ProtocolIE_IDE2_id_TransactionID:
1506 case ProtocolIE_IDE2_id_GlobalRIC_ID:
1508 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.pLMN_Identity.buf);
1509 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID.buf);
1513 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
1515 e2NodeConfigAddAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
1516 if(e2NodeConfigAddAckList->list.array )
1518 for(e2NodeConfigAddAckListIdx = 0; e2NodeConfigAddAckListIdx< e2NodeConfigAddAckList->list.count; e2NodeConfigAddAckListIdx++)
1520 if(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx])
1522 e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx];
1523 free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
1524 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf);
1525 free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
1526 e2nodeComponentInterfaceTypeF1);
1527 free(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx]);
1530 free(e2NodeConfigAddAckList->list.array);
1535 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]);
1538 free(e2SetRspMsg->protocolIEs.list.array);
1542 /******************************************************************
1544 * @brief Processes E2 Setup Response sent by RIC
1548 * Function : procE2SetupRsp
1550 * Functionality: Processes E2 Setup Response sent by RIC
1552 * @params[in] E2AP_PDU_t ASN decoded E2AP message
1553 * @return ROK - success
1556 * ****************************************************************/
1557 uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
1559 uint8_t arrIdx =0, transId=0;
1560 uint32_t recvBufLen;
1561 E2setupResponse_t *e2SetRspMsg;
1563 E2NodeComponent *e2NodeComponentInfo;
1565 DU_LOG("\nINFO --> E2AP : E2 Setup Response received");
1566 duCb.e2Status = TRUE; //Set E2 status as true
1567 e2SetRspMsg = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
1569 for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
1571 switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
1573 case ProtocolIE_IDE2_id_TransactionID:
1575 transId = e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
1576 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
1577 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
1579 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
1583 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
1589 case ProtocolIE_IDE2_id_GlobalRIC_ID:
1591 /* To store the Ric Id Params */
1592 recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value\
1593 .choice.GlobalRIC_ID.pLMN_Identity.size);
1594 memcpy(&duCb.e2apDb.ricId.plmnId, e2SetRspMsg->protocolIEs.list.array[arrIdx]\
1595 ->value.choice.GlobalRIC_ID.pLMN_Identity.buf, recvBufLen);
1596 bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID, &duCb.e2apDb.ricId);
1597 /*TODO : duCb.e2apDb.ricId.plmnId memory to be deallocated after the usage */
1601 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
1605 DU_LOG("\nERROR --> E2AP : Invalid IE received in E2SetupRsp:%ld",
1606 e2SetRspMsg->protocolIEs.list.array[arrIdx]->id);
1610 freeAperDecodingOfE2SetupRsp(e2SetRspMsg);
1612 node = searchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD);
1615 DU_LOG("\nERROR --> E2AP : Received e2NodeComponentInfo is null");
1620 e2NodeComponentInfo = (E2NodeComponent*)node->node;
1621 cmLListDelFrm(&duCb.e2apDb.e2NodeComponentList, node);
1622 DU_FREE(e2NodeComponentInfo->componentRequestPart, e2NodeComponentInfo->reqBufSize);
1623 DU_FREE(e2NodeComponentInfo->componentResponsePart, e2NodeComponentInfo->rspBufSize);
1624 DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
1625 DU_FREE(node, sizeof(CmLList));
1628 BuildAndSendE2NodeConfigUpdate();
1632 /*******************************************************************
1634 * @brief Free RIC Subscription Request
1638 * Function : freeAperDecodingOfRicSubsReq
1640 * Functionality : Free RIC Subscription Request
1644 ******************************************************************/
1645 void freeAperDecodingOfRicSubsReq(RICsubscriptionRequest_t *ricSubscriptionReq)
1648 uint8_t elementIdx = 0;
1649 RICsubscriptionDetails_t *subsDetails = NULLP;
1650 RICaction_ToBeSetup_ItemIEs_t *actionItem = NULLP;
1652 if(ricSubscriptionReq->protocolIEs.list.array)
1654 for(idx=0; idx < ricSubscriptionReq->protocolIEs.list.count; idx++)
1656 switch(ricSubscriptionReq->protocolIEs.list.array[idx]->id)
1658 case ProtocolIE_IDE2_id_RICsubscriptionDetails:
1660 subsDetails = &(ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails);
1661 free(subsDetails->ricEventTriggerDefinition.buf);
1663 if(subsDetails->ricAction_ToBeSetup_List.list.array)
1665 for(elementIdx = 0; elementIdx < subsDetails->ricAction_ToBeSetup_List.list.count; elementIdx++)
1667 if(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx])
1669 actionItem = (RICaction_ToBeSetup_ItemIEs_t *)subsDetails->ricAction_ToBeSetup_List.\
1670 list.array[elementIdx];
1671 if(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition)
1673 free(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->buf);
1674 free(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition);
1676 free(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx]);
1679 free(subsDetails->ricAction_ToBeSetup_List.list.array);
1684 free(ricSubscriptionReq->protocolIEs.list.array[idx]);
1686 free(ricSubscriptionReq->protocolIEs.list.array);
1690 /*******************************************************************
1692 * @brief Free Event Trigger Definition
1696 * Function : freeAperDecodingOfEventTriggerDef
1698 * Functionality: Free Event Trigger Definition
1700 * @params[in] E2SM-KPM Event Trigger Definition
1703 * ****************************************************************/
1704 void freeAperDecodingOfEventTriggerDef(E2SM_KPM_EventTriggerDefinition_t *eventTiggerDef)
1708 switch(eventTiggerDef->eventDefinition_formats.present)
1710 case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING:
1713 case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_eventDefinition_Format1:
1714 free(eventTiggerDef->eventDefinition_formats.choice.eventDefinition_Format1);
1720 /*******************************************************************
1722 * @brief Extract E2SM-KPM Event trigger definition
1726 * Function : extractEventTriggerDef
1728 * Functionality : This function :
1729 * - Decodes E2SM-KPM Event Trigger Definition
1730 * - Validates that even trigger style is supported by E2 node
1731 * - Stores event trigger details in local DB
1733 * @params[in] RAN Function Database structure
1734 * RIC Subscription Info to be added to RAN function
1735 * RIC Event Trigger Definition buffer received from RIC
1736 * @return ROK - success
1739 ******************************************************************/
1740 uint8_t extractEventTriggerDef(RanFunction *ranFuncDb, RicSubscription *ricSubscriptionInfo, RICeventTriggerDefinition_t *ricEventTriggerDef)
1742 uint8_t ret = RFAILED;
1743 uint8_t eventIdx = 0;
1744 asn_dec_rval_t rval ={0};
1745 E2SM_KPM_EventTriggerDefinition_t eventTiggerDef, *eventTiggerDefPtr = NULLP;
1747 /* Decoding E2SM-KPM Even Trigger Definition */
1748 eventTiggerDefPtr = &eventTiggerDef;
1749 memset(eventTiggerDefPtr, 0, sizeof(E2SM_KPM_EventTriggerDefinition_t));
1751 rval = aper_decode(0, &asn_DEF_E2SM_KPM_EventTriggerDefinition, (void **)&eventTiggerDefPtr, ricEventTriggerDef->buf,\
1752 ricEventTriggerDef->size, 0, 0);
1753 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
1755 DU_LOG("\nERROR --> E2AP : ASN decode failed for E2SM-KPM Event Trigger Definition");
1759 xer_fprint(stdout, &asn_DEF_E2SM_KPM_EventTriggerDefinition, eventTiggerDefPtr);
1761 /* Validating the received event trigger definition format */
1762 for(eventIdx = 0; eventIdx < ranFuncDb->numOfEventTriggerStyleSupported; eventIdx++)
1764 if((eventTiggerDefPtr->eventDefinition_formats.present != \
1765 E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING) && \
1766 (eventTiggerDefPtr->eventDefinition_formats.present == ranFuncDb->eventTriggerStyleList[eventIdx].formatType))
1768 ricSubscriptionInfo->eventTriggerDefinition.formatType = ranFuncDb->eventTriggerStyleList[eventIdx].formatType;
1769 ricSubscriptionInfo->eventTriggerDefinition.choice.format1.reportingPeriod = \
1770 eventTiggerDefPtr->eventDefinition_formats.choice.eventDefinition_Format1->reportingPeriod;
1777 /* Free E2SM_KPM_EventTriggerDefinition_t */
1778 freeAperDecodingOfEventTriggerDef(eventTiggerDefPtr);
1782 /*******************************************************************
1784 * @brief Free RIC Action Definition
1788 * Function : freeAperDecodingOfRicActionDefinition
1790 * Functionality: Free RIC Action Definition
1792 * @params[in] E2SM-KPM Action definition
1795 * ****************************************************************/
1796 void freeAperDecodingOfRicActionDefinition(E2SM_KPM_ActionDefinition_t *actionDef)
1798 uint8_t elementIdx = 0;
1799 E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
1800 MeasurementInfoItem_t *measItem = NULLP;
1802 switch(actionDef->actionDefinition_formats.present)
1804 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1:
1806 if(actionDef->actionDefinition_formats.choice.actionDefinition_Format1)
1808 actionFormat1 = actionDef->actionDefinition_formats.choice.actionDefinition_Format1;
1809 if(actionFormat1->measInfoList.list.array)
1811 for(elementIdx = 0; elementIdx < actionFormat1->measInfoList.list.count; elementIdx++)
1813 if(actionFormat1->measInfoList.list.array[elementIdx])
1815 measItem = actionFormat1->measInfoList.list.array[elementIdx];
1816 switch(measItem->measType.present)
1818 case MeasurementType_PR_NOTHING:
1821 case MeasurementType_PR_measName:
1823 free(measItem->measType.choice.measName.buf);
1827 case MeasurementType_PR_measID:
1833 free(actionFormat1->measInfoList.list.array);
1835 free(actionFormat1);
1839 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format2:
1840 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format3:
1841 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format4:
1842 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format5:
1848 /*******************************************************************
1850 * @brief Extract Measurement Info list from action definition
1854 * Function : extractMeasInfoList
1856 * Functionality : This function :
1857 * - Traverses Measurement-to-be-subscribed list
1858 * - Validates that each measurement in Measurement-to-be-subscribed
1859 * list is supported in RAN-Function->Measurement-supported list.
1860 * - If all measurements in an action is supported by RAN function,
1861 * it is added to measurement-subscribed list in local DB
1863 * @params[in] Measurement Info supported list by RAN function
1864 * Measurement Info to be subscribed as requested by RIC
1865 * Measurement Info finally subscribed
1866 * Memory failure indicator
1867 * @return ROK - success
1870 ******************************************************************/
1871 uint8_t extractMeasInfoList(CmLListCp *measInfoSupportedList, MeasurementInfoList_t *measInfoToBeSubscribedList, \
1872 CmLListCp *measInfoSubscribedList, bool *memFailure)
1874 uint8_t elementIdx = 0;
1875 MeasurementInfoForAction *measInfoSupportedDb = NULLP;
1876 MeasurementInfo *measInfoSubscribedDb = NULLP, *measInfoToDel = NULLP;
1877 CmLList *supportedMeasNode = NULLP, *measToAddNode = NULLP, *measToDelNode = NULLP;;
1878 MeasurementInfoItem_t *measItem = NULLP;
1880 /* Validate Measurement list is supported by E2 node.
1882 * Traverse and compare the Measurement-Supported List in E2
1883 * node with Measurement-to-be-subscribed list received from RIC.
1884 * If a match is found, add it to measurement-subscription list.
1886 for(elementIdx = 0; elementIdx < measInfoToBeSubscribedList->list.count; elementIdx++)
1888 measInfoSubscribedDb = NULLP;
1889 measToAddNode = NULLP;
1890 measItem = measInfoToBeSubscribedList->list.array[elementIdx];
1892 CM_LLIST_FIRST_NODE(measInfoSupportedList, supportedMeasNode);
1893 while(supportedMeasNode)
1895 measInfoSupportedDb = (MeasurementInfoForAction*)supportedMeasNode->node;
1896 switch(measItem->measType.present)
1898 case MeasurementType_PR_measName:
1900 if(!strcmp(measInfoSupportedDb->measurementTypeName, (char *)measItem->measType.choice.measName.buf))
1902 DU_ALLOC(measInfoSubscribedDb, sizeof(MeasurementInfo));
1907 case MeasurementType_PR_measID:
1909 if(measInfoSupportedDb->measurementTypeId == measItem->measType.choice.measID)
1911 DU_ALLOC(measInfoSubscribedDb, sizeof(MeasurementInfo));
1918 DU_LOG("\nERROR -> DUAPP: Invalid Measurement-type identifier in \
1919 E2SM-KPM Action Definition Format");
1922 } /* End of switch, for measurement type identifier */
1924 /* If measurement type is supported, add to measurement-subscription list */
1925 if(measInfoSubscribedDb)
1927 measInfoSubscribedDb->measurementTypeId = measInfoSupportedDb->measurementTypeId;
1928 memcpy(measInfoSubscribedDb->measurementTypeName, measInfoSupportedDb->measurementTypeName, \
1929 strlen(measInfoSupportedDb->measurementTypeName));
1931 DU_ALLOC(measToAddNode, sizeof(CmLList));
1934 measToAddNode->node = (PTR) measInfoSubscribedDb;
1935 cmLListAdd2Tail(measInfoSubscribedList, measToAddNode);
1937 /* Break out of while loop if measurement info is found in measurement-supported list */
1942 DU_FREE(measInfoSubscribedDb, sizeof(MeasurementInfo));
1943 measInfoSubscribedDb = NULLP;
1949 supportedMeasNode = supportedMeasNode->next;
1951 } /* End of while for traversing measurement-supported list in a report style */
1953 /* If a measurement-to-be-subscribed is not found in measurement-supported list in this report style
1955 * Delete all entries from measurement-subscription list and
1956 * Break out of for loop to search in next report style */
1957 if(!measInfoSubscribedDb)
1959 while(measInfoSubscribedList->count)
1961 measToDelNode = cmLListDelFrm(measInfoSubscribedList, measInfoSubscribedList->first);
1962 measInfoToDel = (MeasurementInfo*)measToDelNode->node;
1963 DU_FREE(measInfoToDel, sizeof(MeasurementInfo));
1964 DU_FREE(measToDelNode, sizeof(CmLList));
1969 } /* End of for loop , traversing measurement-to-be-subscribed list */
1971 /* If all measurement-to-be-subscribed was found in measurement-supported list and
1972 * was added to measurement-subscription list successfully, return from here */
1973 if(measInfoToBeSubscribedList->list.count == measInfoSubscribedList->count)
1979 /*******************************************************************
1981 * @brief Extract E2SM-KPM Action definition
1985 * Function : extractRicActionDef
1987 * Functionality : This function :
1988 * - Decodes E2SM-KPM Action Definition
1989 * - Validates that action is supported by E2 node
1990 * - Stores action details in local DB
1992 * @params[in] RAN Function Database structure
1993 * RIC subscription's Action definition to be added to
1995 * RIC Action Definition buffer received from RIC
1996 * @return ROK - success
1999 ******************************************************************/
2000 uint8_t extractRicActionDef(RanFunction *ranFuncDb, ActionDefinition *actionDefDb, RICactionDefinition_t *ricActionDef)
2002 bool memFailure = false;
2003 uint8_t styleIdx = 0;
2004 asn_dec_rval_t rval ={0};
2006 E2SM_KPM_ActionDefinition_t actionDef, *actionDefPtr = NULLP;
2007 E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
2008 CmLListCp *measInfoSupportedList = NULLP;
2009 CmLListCp *measInfoSubscribedList = NULLP;
2011 /* Decoding E2SM-KPM Action Definition */
2012 actionDefPtr = &actionDef;
2013 memset(actionDefPtr, 0, sizeof(E2SM_KPM_EventTriggerDefinition_t));
2015 rval = aper_decode(0, &asn_DEF_E2SM_KPM_ActionDefinition, (void **)&actionDefPtr, ricActionDef->buf,\
2016 ricActionDef->size, 0, 0);
2017 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
2019 DU_LOG("\nERROR --> E2AP : ASN decode failed for E2SM-KPM Action Definition");
2023 xer_fprint(stdout, &asn_DEF_E2SM_KPM_ActionDefinition, actionDefPtr);
2026 /* Validate if Report style to subscribe is supported by E2 Node */
2027 for(styleIdx= 0; styleIdx < ranFuncDb->numOfReportStyleSupported; styleIdx++)
2029 /* Validate Report style type and report style format type is supported by E2 Node */
2030 if((ranFuncDb->reportStyleList[styleIdx].reportStyle.styleType == actionDefPtr->ric_Style_Type) &&
2031 (ranFuncDb->reportStyleList[styleIdx].reportStyle.formatType == actionDefPtr->actionDefinition_formats.present))
2033 /* Fetch Report stype type and format type */
2034 actionDefDb->styleType = actionDefPtr->ric_Style_Type;
2035 actionDefDb->formatType = actionDefPtr->actionDefinition_formats.present;
2037 switch(actionDefPtr->actionDefinition_formats.present)
2039 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1:
2041 actionFormat1 = actionDefPtr->actionDefinition_formats.choice.actionDefinition_Format1;
2043 /* Fetch granularity period */
2044 actionDefDb->choice.format1.granularityPeriod = actionFormat1->granulPeriod;
2046 /* Validate and add the Measurement to subscription list */
2047 measInfoSupportedList = &ranFuncDb->reportStyleList[styleIdx].measurementInfoList;
2048 measInfoSubscribedList = &actionDefDb->choice.format1.measurementInfoList;
2049 if(extractMeasInfoList(measInfoSupportedList, &actionFormat1->measInfoList, \
2050 measInfoSubscribedList, &memFailure) == ROK)
2054 /* Free E2SM_KPM_ActionDefinition_t */
2055 freeAperDecodingOfRicActionDefinition(actionDefPtr);
2060 break; /* End of E2SM-KPM Action definition format 1 case */
2065 DU_LOG("\nERROR -> DUAPP: Only E2SM-KPM Action Definition Format 1 is supported");
2068 } /* End of switch for E2SM-KPM Action definition formats */
2073 } /* End of for loop, traversing Report-styles-supported list in E2 node */
2075 /* Memset action Db and Free E2SM_KPM_ActionDefinition_t */
2076 memset(actionDefDb, 0, sizeof(ActionDefinition));
2077 freeAperDecodingOfRicActionDefinition(actionDefPtr);
2081 /*******************************************************************
2083 * @brief Extract RIC Action to be setup
2087 * Function : extractRicActionToBeSetup
2089 * Functionality : This function :
2090 * - Validates that each action-to-be-setup is supported by E2 node
2091 * - Stores event trigger details in local DB
2093 * @params[in] RAN Function Database structure
2094 * RIC Subscription Info to be added to RAN function
2095 * RIC Action To Be Setup List received from RIC
2096 * @return ROK - success
2099 ******************************************************************/
2100 uint8_t extractRicActionToBeSetup(RanFunction *ranFuncDb, RicSubscription *ricSubscriptionInfo, RICactions_ToBeSetup_List_t *actionList)
2102 uint8_t actionIdx = 0;
2103 uint8_t ricActionId = 0;
2104 RICaction_ToBeSetup_ItemIEs_t *actionItem = NULLP;
2106 if(actionList->list.array)
2108 for(actionIdx = 0; actionIdx < actionList->list.count; actionIdx++)
2110 actionItem =(RICaction_ToBeSetup_ItemIEs_t *)actionList->list.array[actionIdx];
2111 switch(actionItem->id)
2113 case ProtocolIE_IDE2_id_RICaction_ToBeSetup_Item:
2115 /* If Action type is REPORT and
2116 * If RIC action definition's extraction and validation passes,
2118 * This action is added to action sequence list of subscription info */
2119 if(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionType == RICactionType_report)
2121 ricActionId = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID;
2122 ricSubscriptionInfo->actionSequence[ricActionId-1].id = ricActionId;
2123 ricSubscriptionInfo->actionSequence[ricActionId-1].type = REPORT;
2125 if(extractRicActionDef(ranFuncDb, &ricSubscriptionInfo->actionSequence[ricActionId-1].definition, \
2126 actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition) == ROK)
2128 ricSubscriptionInfo->actionSequence[ricActionId-1].action = CONFIG_ADD;
2129 ricSubscriptionInfo->numOfActions++;
2133 memset(&ricSubscriptionInfo->actionSequence[ricActionId-1], 0, sizeof(ActionInfo));
2134 /* TODO : Since this action addition failed, add to
2135 * reject-action-list in subscription response */
2141 DU_LOG("\nERROR --> E2AP : Invalid IE received in RicSetupLst:%ld",actionItem->id);
2147 /* If there is even 1 action that can be added, return ROK */
2148 if(ricSubscriptionInfo->numOfActions)
2154 /******************************************************************
2156 * @brief Processes RIC Subscription Req sent by RIC
2160 * Function : procRicSubsReq
2162 * Functionality: Processes E2 Setup Response sent by CU
2164 * @params[in] E2AP_PDU_t ASN decoded E2AP message
2165 * @return ROK - success
2168 * ****************************************************************/
2170 uint8_t procRicSubsReq(E2AP_PDU_t *e2apMsg)
2174 uint16_t ranFuncId = 0;
2175 CmLList *ricSubscriptionNode = NULLP;
2176 RanFunction *ranFuncDb = NULLP;
2177 RICsubscriptionRequest_t *ricSubsReq = NULLP;
2178 RICsubscriptionDetails_t *subsDetails = NULLP;
2179 RicSubscription *ricSubscriptionInfo = NULLP;
2181 DU_LOG("\nINFO --> E2AP : RIC Subscription request received");
2182 ricSubsReq = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
2184 for(idx=0; idx<ricSubsReq->protocolIEs.list.count; idx++)
2186 if(ricSubsReq->protocolIEs.list.array[idx])
2188 switch(ricSubsReq->protocolIEs.list.array[idx]->id)
2190 case ProtocolIE_IDE2_id_RICrequestID:
2192 DU_ALLOC(ricSubscriptionInfo, sizeof(RicSubscription));
2193 if(!ricSubscriptionInfo)
2195 DU_LOG("\nERROR --> E2AP : Memory allocation failed for ricSubscriptionInfo");
2199 ricSubscriptionInfo->requestId.requestorId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID;
2200 ricSubscriptionInfo->requestId.instanceId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID;
2205 case ProtocolIE_IDE2_id_RANfunctionID:
2207 ranFuncId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RANfunctionID;
2209 /* Validating RAN Function id */
2210 if(duCb.e2apDb.ranFunction[ranFuncId-1].id == ranFuncId)
2212 ranFuncDb = &duCb.e2apDb.ranFunction[ranFuncId-1];
2216 /* TODO : Send RAN Subcription Failure */
2222 case ProtocolIE_IDE2_id_RICsubscriptionDetails:
2224 subsDetails = &ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails;
2226 /* Decode, Validate and record Event Trigger Definition */
2227 if(extractEventTriggerDef(ranFuncDb, ricSubscriptionInfo, &subsDetails->ricEventTriggerDefinition) != ROK)
2229 /* TODO : Send RAN Subcription Failure */
2234 /* Decode, Validate and record RIC actions */
2235 if(extractRicActionToBeSetup(ranFuncDb, ricSubscriptionInfo, &subsDetails->ricAction_ToBeSetup_List) != ROK)
2237 /* TODO : Send RAN Subcription Failure */
2245 DU_LOG("\nERROR --> E2AP : Invalid IE received in RIC SubsReq:%ld",
2246 ricSubsReq->protocolIEs.list.array[idx]->id);
2255 freeAperDecodingOfRicSubsReq(ricSubsReq);
2259 /* Add RAN subcription detail to RAN function */
2260 DU_ALLOC(ricSubscriptionNode, sizeof(CmLList));
2261 if(ricSubscriptionNode)
2263 ricSubscriptionNode->node = (PTR) ricSubscriptionInfo;
2264 cmLListAdd2Tail(&ranFuncDb->subscriptionList, ricSubscriptionNode);
2267 #ifdef KPI_CALCULATION
2268 /* Send statistics request to other DU entities */
2269 BuildAndSendStatsReq(ranFuncId, ricSubscriptionInfo);
2272 /* TODO : Trigger RIC subscription response once statistics response is
2273 * received from MAC .
2274 * TBD in next gerrit */
2275 ret = BuildAndSendRicSubscriptionRsp();
2277 BuildAndSendRicIndication(ricSubscriptionInfo);
2284 /*******************************************************************
2286 * @brief Free the RicIndication Message
2290 * Function : FreeRicIndication
2292 * Functionality: Free the RicIndication Message
2297 ******************************************************************/
2298 void FreeRicIndication(E2AP_PDU_t *e2apMsg)
2301 RICindication_t *ricIndicationMsg= NULLP;
2303 if(e2apMsg != NULLP)
2305 if(e2apMsg->choice.initiatingMessage != NULLP)
2307 ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
2308 if(ricIndicationMsg!= NULLP)
2310 if(ricIndicationMsg->protocolIEs.list.array != NULLP)
2312 for(idx=0; idx<ricIndicationMsg->protocolIEs.list.count; idx++)
2314 if(ricIndicationMsg->protocolIEs.list.array[idx] != NULLP)
2316 switch(ricIndicationMsg->protocolIEs.list.array[idx]->id)
2318 case ProtocolIE_IDE2_id_RICrequestID:
2321 case ProtocolIE_IDE2_id_RANfunctionID:
2324 case ProtocolIE_IDE2_id_RICactionID:
2327 case ProtocolIE_IDE2_id_RICindicationType:
2330 case ProtocolIE_IDE2_id_RICindicationHeader:
2332 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf,\
2333 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
2336 case ProtocolIE_IDE2_id_RICindicationMessage:
2338 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf,\
2339 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
2345 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx],sizeof(RICindication_IEs_t));
2348 DU_FREE(ricIndicationMsg->protocolIEs.list.array,ricIndicationMsg->protocolIEs.list.size);
2351 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2353 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2357 /*******************************************************************
2359 * brief Fill the RicIndication Message
2363 * Function : FillRicIndication
2365 * Functionality:Fills the RicIndication Message
2367 * @return ROK - success
2370 ******************************************************************/
2371 uint8_t FillRicIndication(RICindication_t *ricIndicationMsg, RicSubscription *ricSubscriptionInfo)
2373 uint8_t elementCnt=0;
2378 ricIndicationMsg->protocolIEs.list.count = elementCnt;
2379 ricIndicationMsg->protocolIEs.list.size = elementCnt * sizeof(RICindication_t);
2380 /* Initialize the Ric Indication members */
2381 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array, \
2382 ricIndicationMsg->protocolIEs.list.size);
2383 if(ricIndicationMsg->protocolIEs.list.array == NULLP)
2385 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
2390 for(idx=0; idx<elementCnt; idx++)
2392 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx],\
2393 sizeof(RICindication_IEs_t));
2394 if(ricIndicationMsg->protocolIEs.list.array[idx] == NULLP)
2396 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
2404 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
2405 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2406 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2407 RICindication_IEs__value_PR_RICrequestID;
2408 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID =ricSubscriptionInfo->requestId.requestorId;
2409 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID = ricSubscriptionInfo->requestId.instanceId;
2412 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
2413 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2414 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2415 RICindication_IEs__value_PR_RANfunctionID;
2416 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RANfunctionID = duCb.e2apDb.ranFunction[0].id;
2419 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactionID;
2420 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2421 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2422 RICindication_IEs__value_PR_RICactionID;
2423 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICactionID = ricSubscriptionInfo->actionSequence[0].id;
2426 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationType;
2427 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2428 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2429 RICindication_IEs__value_PR_RICindicationType;
2430 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationType = ricSubscriptionInfo->actionSequence[0].type;
2433 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationHeader;
2434 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2435 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2436 RICindication_IEs__value_PR_RICindicationHeader;
2437 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size = 3 *
2439 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf ,\
2440 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
2441 if(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf == NULLP)
2443 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
2448 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
2449 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf);
2451 /* TO BE CHANGED: RIC INDICATION DATA */
2452 /* For now filling a dummy octect data, need to tested with PRBs*/
2453 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationMessage;
2454 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2455 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2456 RICindication_IEs__value_PR_RICindicationMessage;
2457 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size = 3 *
2459 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf ,\
2460 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
2461 if(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf == NULLP)
2463 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
2468 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
2469 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf);
2477 /*******************************************************************
2479 * @brief Builds and Send the RicIndication Message
2483 * Function : BuildAndSendRicIndication
2485 * Functionality:Fills the RicIndication Message
2487 * @return ROK - success
2490 ******************************************************************/
2492 uint8_t BuildAndSendRicIndication(RicSubscription *ricSubscriptionInfo)
2494 E2AP_PDU_t *e2apMsg = NULLP;
2495 RICindication_t *ricIndicationMsg=NULLP;
2496 asn_enc_rval_t encRetVal; /* Encoder return value */
2497 uint8_t ret = RFAILED;
2498 uint8_t FillRicIndicationret = ROK;
2502 DU_LOG("\nINFO --> E2AP : Building RIC Indication Message\n");
2504 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2505 if(e2apMsg == NULLP)
2507 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2511 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2512 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2513 if(e2apMsg->choice.initiatingMessage == NULLP)
2515 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2518 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICindication;
2519 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2520 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICindication;
2522 ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
2524 FillRicIndicationret = FillRicIndication(ricIndicationMsg, ricSubscriptionInfo);
2525 if(FillRicIndicationret != ROK)
2529 /* Prints the Msg formed */
2530 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2531 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2533 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
2535 if(encRetVal.encoded == ENCODE_FAIL)
2537 DU_LOG("\nERROR --> E2AP : Could not encode RIC Indication Message (at %s)\n",\
2538 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2543 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Indication Message \n");
2544 #ifdef DEBUG_ASN_PRINT
2545 for(int i=0; i< encBufSize; i++)
2547 printf("%x",encBuf[i]);
2552 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
2554 DU_LOG("\nINFO --> E2AP : Sending RIC Indication Message");
2560 FreeRicIndication(e2apMsg);
2564 /*******************************************************************
2566 * @brief Deallocate the memory allocated for E2nodeConfigurationUpdate msg
2570 * Function : FreeE2NodeConfigUpdate
2573 * - freeing the memory allocated for E2nodeConfigurationUpdate
2575 * @params[in] E2AP_PDU_t *e2apMsg
2576 * @return ROK - success
2579 * ****************************************************************/
2580 void FreeE2NodeConfigUpdate(E2AP_PDU_t *e2apMsg)
2583 E2nodeConfigurationUpdate_t *e2NodeConfigUpdate;
2585 if(e2apMsg != NULLP)
2587 if(e2apMsg->choice.initiatingMessage != NULLP)
2589 e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
2590 if(e2NodeConfigUpdate->protocolIEs.list.array != NULLP)
2592 for(arrIdx = 0; arrIdx < e2NodeConfigUpdate->protocolIEs.list.count; arrIdx++)
2594 DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
2596 DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size);
2598 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2600 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2604 /*******************************************************************
2606 * @brief Buld and send the E2 node config update msg
2610 * Function : BuildAndSendE2NodeConfigUpdate
2613 * - Buld and send the E2 node config update msg
2616 * @return ROK - success
2619 * ****************************************************************/
2621 uint8_t BuildAndSendE2NodeConfigUpdate()
2623 uint8_t arrIdx = 0,elementCnt = 1;
2625 E2AP_PDU_t *e2apMsg = NULLP;
2626 E2nodeConfigurationUpdate_t *e2NodeConfigUpdate = NULLP;
2627 asn_enc_rval_t encRetVal; /* Encoder return value */
2629 DU_LOG("\nINFO --> E2AP : Building E2 Node config update\n");
2632 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2633 if(e2apMsg == NULLP)
2635 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2638 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2639 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2640 if(e2apMsg->choice.initiatingMessage == NULLP)
2642 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2643 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2646 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2647 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
2648 e2apMsg->choice.initiatingMessage->value.present = \
2649 InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate;
2650 e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
2652 e2NodeConfigUpdate->protocolIEs.list.count = elementCnt;
2653 e2NodeConfigUpdate->protocolIEs.list.size = elementCnt * sizeof(E2nodeConfigurationUpdate_IEs_t*);
2654 /* Initialize the Ric Indication members */
2655 DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array, \
2656 e2NodeConfigUpdate->protocolIEs.list.size);
2657 if(e2NodeConfigUpdate->protocolIEs.list.array == NULLP)
2659 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
2663 for(arrIdx =0; arrIdx<elementCnt; arrIdx++)
2665 DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
2666 if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx] == NULLP)
2669 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
2676 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2677 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2678 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_TransactionID;
2679 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = TRANS_ID;
2682 /* Prints the Msg formed */
2683 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2685 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2687 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
2689 if(encRetVal.encoded == ENCODE_FAIL)
2691 DU_LOG("\nERROR --> E2AP : Could not encode E2nodeConfigurationUpdate structure (at %s)\n",\
2692 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2697 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2nodeConfigurationUpdate\n");
2698 #ifdef DEBUG_ASN_PRINT
2699 for(int i=0; i< encBufSize; i++)
2701 printf("%x",encBuf[i]);
2705 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize))
2707 DU_LOG("\nERROR --> E2AP : Sending E2 node config update failed");
2714 FreeE2NodeConfigUpdate(e2apMsg);
2718 /*******************************************************************
2720 * @brief Deallocate the memory allocated for E2ResetRequest msg
2724 * Function : FreeE2ResetRequest
2727 * - freeing the memory allocated for E2ResetRequest
2729 * @params[in] E2AP_PDU_t *e2apMsg
2730 * @return ROK - success
2733 * ****************************************************************/
2734 void FreeE2ResetRequest(E2AP_PDU_t *e2apMsg)
2737 ResetRequestE2_t *resetReq = NULLP;
2739 if(e2apMsg != NULLP)
2741 if(e2apMsg->choice.initiatingMessage != NULLP)
2743 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
2744 if(resetReq->protocolIEs.list.array)
2746 for(ieIdx = 0; ieIdx < resetReq->protocolIEs.list.count; ieIdx++)
2748 DU_FREE(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
2750 DU_FREE(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
2752 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2754 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2758 /*******************************************************************
2760 * @brief Build and send the E2 reset request msg
2764 * Function : BuildAndSendE2ResetRequest
2767 * - Buld and send the E2 reset request msg to RIC
2770 * @return ROK - success
2773 * ****************************************************************/
2774 uint8_t BuildAndSendE2ResetRequest(E2CauseType failureType, E2Cause failureCause)
2776 uint8_t ieIdx = 0, elementCnt = 0, transId = 0;
2777 uint8_t ret = RFAILED;
2778 E2AP_PDU_t *e2apMsg = NULLP;
2779 ResetRequestE2_t *resetReq = NULLP;
2780 asn_enc_rval_t encRetVal; /* Encoder return value */
2782 DU_LOG("\nINFO --> E2AP : Building E2 Reset Request\n");
2786 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2787 if(e2apMsg == NULLP)
2789 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation for E2AP-PDU failed");
2793 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2794 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2795 if(e2apMsg->choice.initiatingMessage == NULLP)
2797 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation for initiatingMessage");
2801 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_Reset;
2802 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2803 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ResetRequestE2;
2804 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
2807 resetReq->protocolIEs.list.count = elementCnt;
2808 resetReq->protocolIEs.list.size = elementCnt * sizeof(ResetRequestIEs_t *);
2810 DU_ALLOC(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
2811 if(!resetReq->protocolIEs.list.array)
2813 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
2814 Reset Request IE array");
2818 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
2820 DU_ALLOC(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
2821 if(!resetReq->protocolIEs.list.array[ieIdx])
2823 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
2824 Reset Request IE array element");
2829 /* In case of failure */
2830 if(ieIdx < elementCnt)
2834 resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2835 resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
2836 resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_TransactionID;
2837 transId = assignTransactionId();
2838 resetReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
2841 resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_CauseE2;
2842 resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_ignore;
2843 resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_CauseE2;
2844 resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.present = failureType;
2845 switch(resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.present)
2847 case CauseE2_PR_NOTHING:
2849 case CauseE2_PR_ricRequest:
2850 resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.ricRequest = failureCause;
2852 case CauseE2_PR_ricService:
2853 resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.ricService = failureCause;
2855 case CauseE2_PR_e2Node:
2856 resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.e2Node = failureCause;
2858 case CauseE2_PR_transport:
2859 resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.transport = failureCause;
2861 case CauseE2_PR_protocol:
2862 resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.protocol = failureCause;
2864 case CauseE2_PR_misc:
2865 resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.misc = failureCause;
2869 /* Prints the Msg formed */
2870 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2872 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2874 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
2876 if(encRetVal.encoded == ENCODE_FAIL)
2878 DU_LOG("\nERROR --> E2AP : Could not encode E2SetupRequest structure (at %s)\n",\
2879 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2884 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupRequest\n");
2885 #ifdef DEBUG_ASN_PRINT
2886 for(int i=0; i< encBufSize; i++)
2888 printf("%x",encBuf[i]);
2892 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
2894 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
2898 /* In case the message is sent successfully, store the transaction info to
2899 * be used when response is received */
2900 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
2901 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
2907 /* Free all memory */
2908 FreeE2ResetRequest(e2apMsg);
2912 /*******************************************************************
2914 * @brief Deallocate the memory allocated for Reset Response msg
2918 * Function : freeAperDecodingOfE2ResetRsp
2921 * - freeing the memory allocated for Reset response
2923 * @params[in] ResetResponseE2_t *resetResponse
2926 * ****************************************************************/
2927 void freeAperDecodingOfE2ResetRsp(ResetResponseE2_t *resetResponse)
2933 if(resetResponse->protocolIEs.list.array)
2935 for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
2937 if(resetResponse->protocolIEs.list.array[ieIdx])
2939 switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
2941 case ProtocolIE_IDE2_id_TransactionID:
2944 case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
2947 free(resetResponse->protocolIEs.list.array[ieIdx]);
2950 free(resetResponse->protocolIEs.list.array);
2955 /******************************************************************
2957 * @brief Processes E2 Reset Response sent by RIC
2961 * Function : procResetResponse
2963 * Functionality: Processes E2 Reset Response sent by RIC
2965 * @params[in] E2AP_PDU_t ASN decoded E2AP message
2966 * @return ROK - success
2969 * ****************************************************************/
2970 uint8_t procResetResponse(E2AP_PDU_t *e2apMsg)
2972 uint8_t ieIdx =0, transId;
2973 ResetResponseE2_t *resetResponse;
2975 DU_LOG("\nINFO --> E2AP : E2 Reset Response received");
2976 resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;;
2978 for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
2980 switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
2982 case ProtocolIE_IDE2_id_TransactionID:
2983 transId = resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
2984 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) && \
2985 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
2987 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
2991 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
2995 case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
2996 /* As per ORAN WG3 E2AP spec v3.0, section 9.2.2
2997 Criticality Diagnostics IE is sent by Near-RT RIC when parts of a received message i.e.
2998 Reset Request in this case, have not been comprehended or were missing, or if the message
2999 contained logical errors.
3001 Processing of this ID should be implemented when negative call flows are to be supported.
3005 DU_LOG("\nERROR --> E2AP : Invalid IE received in E2 Reset Response : %ld",
3006 resetResponse->protocolIEs.list.array[ieIdx]->id);
3011 freeAperDecodingOfE2ResetRsp(resetResponse);
3015 /******************************************************************
3017 * @brief Deallocation of memory allocated bu aper decoder for e2 setup Failure
3021 * Function : freeAperDecodingOfE2SetupFailure
3023 * Functionality: Deallocation of memory allocated bu aper decoder for e2
3026 * @params[in] E2setupFailure_t *e2SetupFailure;
3029 * ****************************************************************/
3030 void freeAperDecodingOfE2SetupFailure(E2setupFailure_t *e2SetupFailure)
3036 if(e2SetupFailure->protocolIEs.list.array)
3038 for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
3040 if(e2SetupFailure->protocolIEs.list.array[arrIdx])
3042 free(e2SetupFailure->protocolIEs.list.array[arrIdx]);
3045 free(e2SetupFailure->protocolIEs.list.array);
3049 /******************************************************************
3051 * @brief Processes E2 Setup Failure sent by RIC
3055 * Function : procE2SetupFailure
3057 * Functionality: Processes E2 Setup failure sent by RIC
3059 * @params[in] E2AP_PDU_t ASN decoded E2AP message
3060 * @return ROK - success
3063 * ****************************************************************/
3064 void procE2SetupFailure(E2AP_PDU_t *e2apMsg)
3066 uint8_t arrIdx =0, transId =0, timerValue=0;
3067 E2setupFailure_t *e2SetupFailure;
3069 DU_LOG("\nINFO --> E2AP : E2 Setup failure received");
3070 e2SetupFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure;
3072 for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
3074 switch(e2SetupFailure->protocolIEs.list.array[arrIdx]->id)
3076 case ProtocolIE_IDE2_id_TransactionID:
3078 transId = e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
3079 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
3080 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
3082 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
3086 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
3091 case ProtocolIE_IDE2_id_TimeToWaitE2:
3093 timerValue = covertE2WaitTimerEnumToValue(e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
3094 if((duChkTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.e2SetupTimer), EVENT_E2_SETUP_TMR)) == FALSE)
3096 duStartTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.e2SetupTimer), EVENT_E2_SETUP_TMR, timerValue);
3100 DU_LOG("\nERROR --> E2AP : EVENT_E2_SETUP_TMR timer is already running");
3108 freeAperDecodingOfE2SetupFailure(e2SetupFailure);
3110 /******************************************************************
3112 * @brief Deallocation of memory allocated bu aper decoder for RIC service Query
3116 * Function : freeAperDecodingOfRicServiceQuery
3118 * Functionality: Deallocation of memory allocated bu aper decoder for RIC
3121 * @params[in] RICserviceQuery_t *ricServiceQuery;
3124 * ****************************************************************/
3126 void freeAperDecodingOfRicServiceQuery(RICserviceQuery_t *ricServiceQuery)
3128 uint8_t arrIdx,ranFuncIdx;
3129 RANfunctionsID_List_t *ranFuncAddedList;
3133 if(ricServiceQuery->protocolIEs.list.array)
3135 for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
3137 if(ricServiceQuery->protocolIEs.list.array[arrIdx])
3139 switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
3141 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
3143 ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
3144 if(ranFuncAddedList->list.array)
3146 for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
3148 free(ranFuncAddedList->list.array[ranFuncIdx]);
3150 free(ranFuncAddedList->list.array);;
3157 free(ricServiceQuery->protocolIEs.list.array[arrIdx]);
3160 free(ricServiceQuery->protocolIEs.list.array);
3164 /*******************************************************************
3166 * @brief Build RanFunction Delete List
3170 * Function : BuildRanFunctionDeleteList
3172 * Functionality: Build RanFunction Delete List
3175 * RANfunctionsID List
3176 * Count of the RAN function
3177 * Received RAN function list
3179 * @return ROK - success
3182 ******************************************************************/
3184 uint8_t BuildRanFunctionDeleteList(RANfunctionsID_List_t *deleteList, uint8_t count, RanFuncInfo *recvdRanFunc)
3186 uint8_t ranFuncIdx=0;
3187 RANfunctionID_ItemIEs_t *delRanFuncItem;
3191 deleteList->list.count = count;
3192 deleteList->list.size = deleteList->list.count * sizeof(RANfunctionID_ItemIEs_t*);
3193 DU_ALLOC(deleteList->list.array, deleteList->list.size);
3194 if(deleteList->list.array == NULLP)
3196 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
3199 for(ranFuncIdx = 0; ranFuncIdx< deleteList->list.count; ranFuncIdx++)
3201 DU_ALLOC(deleteList->list.array[ranFuncIdx], sizeof(RANfunctionID_ItemIEs_t));
3202 if(deleteList->list.array[ranFuncIdx] == NULLP)
3204 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
3207 delRanFuncItem= (RANfunctionID_ItemIEs_t *) deleteList->list.array[ranFuncIdx];
3208 delRanFuncItem->id = ProtocolIE_IDE2_id_RANfunctionID_Item;
3209 delRanFuncItem->criticality = CriticalityE2_ignore;
3210 delRanFuncItem->value.choice.RANfunctionID_Item.ranFunctionID = recvdRanFunc[ranFuncIdx].id;
3211 delRanFuncItem->value.choice.RANfunctionID_Item.ranFunctionRevision = recvdRanFunc[ranFuncIdx].revisionCounter;
3217 /*******************************************************************
3219 * @brief De Allocate Ric Service Update message
3223 * Function : FreeRicServiceUpdate
3225 * Functionality: De-Allocating Ric Service Update message
3227 * @params[in] E2AP_PDU_t *e2apMsg
3231 * ****************************************************************/
3233 void FreeRicServiceUpdate(E2AP_PDU_t *e2apMsg)
3236 uint8_t ranFuncAddListIdx=0, ranFuncDelIdx=0;
3237 RICserviceUpdate_t *ricServiceUpdate;
3238 RANfunctions_List_t *ranFunctionsList;
3239 RANfunction_ItemIEs_t *ranFuncItemIe;
3240 RANfunction_Item_t *ranFunItem;
3241 RANfunctionsID_List_t *deleteList;
3243 /* De-allocating Memory */
3244 if(e2apMsg != NULLP)
3246 if(e2apMsg->choice.initiatingMessage != NULLP)
3248 ricServiceUpdate = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate;
3249 if(ricServiceUpdate->protocolIEs.list.array != NULLP)
3251 for(arrIdx = 0; arrIdx < ricServiceUpdate->protocolIEs.list.count; arrIdx++)
3253 if(ricServiceUpdate->protocolIEs.list.array[arrIdx] != NULLP)
3255 switch(ricServiceUpdate->protocolIEs.list.array[arrIdx]->id)
3257 case ProtocolIE_IDE2_id_TransactionID:
3260 case ProtocolIE_IDE2_id_RANfunctionsAdded:
3261 case ProtocolIE_IDE2_id_RANfunctionsModified:
3263 ranFunctionsList = &(ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List);
3264 if(ranFunctionsList->list.array)
3266 for(ranFuncAddListIdx= 0; ranFuncAddListIdx< ranFunctionsList->list.count; ranFuncAddListIdx++)
3268 if(ranFunctionsList->list.array[ranFuncAddListIdx])
3270 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncAddListIdx];
3271 ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
3272 DU_FREE(ranFunItem->ranFunctionOID.buf, ranFunItem->ranFunctionOID.size);
3273 DU_FREE(ranFunItem->ranFunctionDefinition.buf, ranFunItem->ranFunctionDefinition.size);
3274 DU_FREE(ranFunctionsList->list.array[ranFuncAddListIdx], sizeof(RANfunction_ItemIEs_t));
3277 DU_FREE(ranFunctionsList->list.array, ranFunctionsList->list.size);
3281 case ProtocolIE_IDE2_id_RANfunctionsDeleted:
3283 deleteList= &ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
3284 if(deleteList->list.array)
3286 for(ranFuncDelIdx = 0; ranFuncDelIdx< deleteList->list.count; ranFuncDelIdx++)
3288 DU_FREE(deleteList->list.array[ranFuncDelIdx], sizeof(RANfunctionID_ItemIEs_t));
3290 DU_FREE(deleteList->list.array, deleteList->list.size);
3296 DU_LOG("\nERROR --> E2AP: Invalid event at ricServiceUpdate %ld ",\
3297 (ricServiceUpdate->protocolIEs.list.array[arrIdx]->id));
3300 DU_FREE(ricServiceUpdate->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdate_IEs_t));
3303 DU_FREE(ricServiceUpdate->protocolIEs.list.array, ricServiceUpdate->protocolIEs.list.size);
3305 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
3307 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
3311 /*******************************************************************
3313 * @brief Builds and Send the RicServiceUpdateuest
3317 * Function : BuildAndSendRicServiceUpdate
3319 * Functionality:Fills the RicServiceUpdateuest
3321 * @return ROK - success
3324 ******************************************************************/
3326 uint8_t BuildAndSendRicServiceUpdate(RicServiceUpdate serviceUpdate)
3328 uint8_t arrIdx = 0, elementCnt=0;
3329 uint8_t transId = 0, ret = RFAILED;
3330 bool memAllocFailed =false;
3331 E2AP_PDU_t *e2apMsg = NULLP;
3332 RICserviceUpdate_t *ricServiceUpdate = NULLP;
3333 asn_enc_rval_t encRetVal; /* Encoder return value */
3335 DU_LOG("\nINFO --> E2AP : Building Ric Service Update\n");
3338 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
3339 if(e2apMsg == NULLP)
3341 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
3344 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
3345 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
3346 if(e2apMsg->choice.initiatingMessage == NULLP)
3348 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
3351 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
3352 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICserviceUpdate;
3353 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICserviceUpdate;
3354 ricServiceUpdate = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate;
3356 /* For TransId IE, set elementCnt to 1.
3357 If there is any item in the RAN function add list, RAN function modification list, or RAN function delete list, increment the elementCnt.*/
3360 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
3362 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeModified)
3364 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted)
3367 ricServiceUpdate->protocolIEs.list.count = elementCnt;
3368 ricServiceUpdate->protocolIEs.list.size = elementCnt * sizeof(RICserviceUpdate_IEs_t*);
3370 /* Initialize the E2Setup members */
3371 DU_ALLOC(ricServiceUpdate->protocolIEs.list.array, ricServiceUpdate->protocolIEs.list.size);
3372 if(ricServiceUpdate->protocolIEs.list.array == NULLP)
3374 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements");
3378 for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
3380 DU_ALLOC(ricServiceUpdate->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdate_IEs_t));
3381 if(ricServiceUpdate->protocolIEs.list.array[arrIdx] == NULLP)
3383 memAllocFailed = true;
3384 DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayIdx [%d]", arrIdx);
3388 if(memAllocFailed == true)
3394 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
3395 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3396 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
3397 if(serviceUpdate.dir == E2_NODE_INITIATED)
3398 transId = assignTransactionId();
3400 transId = serviceUpdate.transId;
3401 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
3403 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
3406 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
3407 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3408 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
3409 if(BuildRanFunctionAddList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List,\
3410 e2apMsg->choice.initiatingMessage->procedureCode, serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded, serviceUpdate.recvRanFuncList.ranFunToBeAdded) !=ROK)
3416 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeModified)
3419 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsModified;
3420 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3421 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
3422 if(BuildRanFunctionAddList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List,
3423 e2apMsg->choice.initiatingMessage->procedureCode, serviceUpdate.recvRanFuncList.numOfRanFunToBeModified, serviceUpdate.recvRanFuncList.ranFunToBeModified) !=ROK)
3429 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted)
3432 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsDeleted;
3433 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3434 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctionsID_List;
3435 if(BuildRanFunctionDeleteList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List,\
3436 serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted, serviceUpdate.recvRanFuncList.ranFunToBeDeleted) != ROK)
3441 /* Prints the Msg formed */
3442 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3444 memset(encBuf, 0, ENC_BUF_MAX_LEN);
3446 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
3447 if(encRetVal.encoded == ENCODE_FAIL)
3449 DU_LOG("\nERROR --> E2AP : Could not encode RicServiceUpdateuest structure (at %s)\n",\
3450 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3455 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RicServiceUpdateuest\n");
3456 #ifdef DEBUG_ASN_PRINT
3457 for(int i=0; i< encBufSize; i++)
3459 printf("%x",encBuf[i]);
3463 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
3465 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
3474 if(serviceUpdate.dir == E2_NODE_INITIATED)
3476 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
3477 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
3481 duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].transactionId = transId;
3482 duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
3484 duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.dir = serviceUpdate.dir;
3485 duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.transId =transId;
3486 memcpy(&duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.recvRanFuncList, &serviceUpdate.recvRanFuncList, sizeof(E2TmpRanFunList));
3488 FreeRicServiceUpdate(e2apMsg);
3491 /******************************************************************
3493 * @brief Processes RIC service Query sent by RIC
3497 * Function : procRicServiceQuery
3499 * Functionality: Processes RIC service Query sent by RIC
3501 * @params[in] E2AP_PDU_t ASN decoded E2AP message
3502 * @return ROK - success
3505 * ****************************************************************/
3507 void procRicServiceQuery(E2AP_PDU_t *e2apMsg)
3510 uint16_t arrIdx =0, ranFuncIdx=0,tmpIdx=0;
3511 uint16_t id,revisionCcounter;
3512 bool tmpArray[MAX_RAN_FUNCTION] = {false};
3513 RICserviceQuery_t *ricServiceQuery=NULL;
3514 RicServiceUpdate ricUpdate;
3515 RANfunctionID_ItemIEs_t *ranFuncAddedItemIe;
3516 RANfunctionsID_List_t *ranFuncAddedList;
3518 DU_LOG("\nINFO --> E2AP : RIC Service Query received");
3519 memset(&ricUpdate, 0, sizeof(RicServiceUpdate));
3520 ricUpdate.dir = RIC_INITIATED;
3521 ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
3523 for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
3525 switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
3527 /* TODO completing in next patch/gerrit */
3528 case ProtocolIE_IDE2_id_TransactionID:
3530 ricUpdate.transId = ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
3534 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
3536 ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
3537 if(ranFuncAddedList->list.array)
3539 for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
3541 if(ranFuncAddedList->list.array[ranFuncIdx])
3543 /* Using the RAN function Id, identify the RAN function to be modified or deleted. */
3545 ranFuncAddedItemIe = (RANfunctionID_ItemIEs_t*)ranFuncAddedList->list.array[ranFuncIdx];
3546 id = ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionID;
3547 revisionCcounter = ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionRevision;
3549 if((id != duCb.e2apDb.ranFunction[id-1].id))
3551 action = CONFIG_DEL;
3553 else if((id == duCb.e2apDb.ranFunction[id-1].id)&&(revisionCcounter!=duCb.e2apDb.ranFunction[id-1].revisionCounter))
3555 action = CONFIG_MOD;
3558 if(action == CONFIG_DEL)
3560 ricUpdate.recvRanFuncList.ranFunToBeDeleted[ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted].id = id;
3561 ricUpdate.recvRanFuncList.ranFunToBeDeleted[ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted].revisionCounter = revisionCcounter;
3562 ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted++;
3564 else if(action == CONFIG_MOD)
3566 ricUpdate.recvRanFuncList.ranFunToBeModified[ricUpdate.recvRanFuncList.numOfRanFunToBeModified].id = id;
3567 ricUpdate.recvRanFuncList.ranFunToBeModified[ricUpdate.recvRanFuncList.numOfRanFunToBeModified].revisionCounter = revisionCcounter;
3568 ricUpdate.recvRanFuncList.numOfRanFunToBeModified++;
3571 /* If any ID is set to true, it means that the ID has been used in either modification or deletion list.
3572 * Else we will add the IDs into the added list */
3573 tmpArray[id-1] = true;
3582 /* Traversing the whole RAN function list in ducb to check if any new Ran function ids have been added. */
3583 for(arrIdx =0; arrIdx<MAX_RAN_FUNCTION; arrIdx++)
3585 tmpIdx= ricUpdate.recvRanFuncList.numOfRanFunToBeAdded;
3586 if((duCb.e2apDb.ranFunction[arrIdx].id >0)&&(!tmpArray[arrIdx]))
3588 ricUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].id = duCb.e2apDb.ranFunction[arrIdx].id;
3589 ricUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].revisionCounter = duCb.e2apDb.ranFunction[arrIdx].revisionCounter;
3590 ricUpdate.recvRanFuncList.numOfRanFunToBeAdded++;
3594 if(BuildAndSendRicServiceUpdate(ricUpdate)!= ROK)
3596 DU_LOG("\nERROR --> E2AP : Failed to build and send ric service update message");
3599 freeAperDecodingOfRicServiceQuery(ricServiceQuery);
3602 /******************************************************************
3604 * @brief Deallocation of memory allocated by aper decoder for
3605 * RIC service update ack
3609 * Function : freeAperDecodingOfRicServiceUpdateAck
3611 * Functionality: Deallocation of memory allocated by aper decoder
3612 * for RIC service update ack
3614 * @params[in] RICserviceUpdateAck_t *ricServiceAck;
3617 * ****************************************************************/
3619 void freeAperDecodingOfRicServiceUpdateAck(RICserviceUpdateAcknowledge_t *ricServiceAck)
3621 uint8_t arrIdx=0,ranFuncIdx=0;
3622 RANfunctionsID_List_t *ranFuncAddedList=NULL;
3626 if(ricServiceAck->protocolIEs.list.array)
3628 for(arrIdx=0; arrIdx<ricServiceAck->protocolIEs.list.count; arrIdx++)
3630 if(ricServiceAck->protocolIEs.list.array[arrIdx])
3632 switch(ricServiceAck->protocolIEs.list.array[arrIdx]->id)
3634 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
3636 ranFuncAddedList= &ricServiceAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
3637 if(ranFuncAddedList->list.array)
3639 for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
3641 free(ranFuncAddedList->list.array[ranFuncIdx]);
3643 free(ranFuncAddedList->list.array);
3650 free(ricServiceAck->protocolIEs.list.array[arrIdx]);
3653 free(ricServiceAck->protocolIEs.list.array);
3658 /******************************************************************
3660 * @brief Processes RIC service update ack sent by RIC
3664 * Function : procRicServiceUpdateAck
3666 * Functionality: Processes RIC service update ack sent by RIC
3668 * @params[in] E2AP_PDU_t ASN decoded E2AP message
3669 * @return ROK - success
3672 * ****************************************************************/
3674 void procRicServiceUpdateAck(E2AP_PDU_t *e2apMsg)
3676 uint8_t arrIdx =0, transId =0;
3677 uint16_t id =0, tmpIdx=0, ranFuncIdx=0;
3678 RicServiceUpdate serviceUpdate;
3679 RANfunctionsIDcause_List_t *rejectedList=NULL;
3680 RICserviceUpdateAcknowledge_t *ricServiceAck=NULL;
3681 RANfunctionIDcause_ItemIEs_t *ranFuncRejectedItemIe=NULL;
3683 DU_LOG("\nINFO --> E2AP : RIC service update ack received");
3684 memset(&serviceUpdate, 0, sizeof(RicServiceUpdate));
3685 ricServiceAck = &e2apMsg->choice.successfulOutcome->value.choice.RICserviceUpdateAcknowledge;
3687 for(arrIdx=0; arrIdx<ricServiceAck->protocolIEs.list.count; arrIdx++)
3689 switch(ricServiceAck->protocolIEs.list.array[arrIdx]->id)
3691 case ProtocolIE_IDE2_id_TransactionID:
3693 transId = ricServiceAck->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
3694 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
3695 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
3697 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
3699 else if((duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].transactionId == transId) &&\
3700 (duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
3702 memset(&duCb.e2apDb.e2TransInfo.ricInitTransaction[transId], 0, sizeof(E2TransInfo));
3706 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
3712 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
3715 case ProtocolIE_IDE2_id_RANfunctionsRejected:
3717 rejectedList= &ricServiceAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsIDcause_List;
3718 if(rejectedList->list.array)
3720 for(ranFuncIdx=0;ranFuncIdx<rejectedList->list.count; ranFuncIdx++)
3722 ranFuncRejectedItemIe = (RANfunctionIDcause_ItemIEs_t*)rejectedList->list.array[ranFuncIdx];
3723 id = ranFuncRejectedItemIe->value.choice.RANfunctionIDcause_Item.ranFunctionID;
3724 tmpIdx= serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded;
3725 serviceUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].id = duCb.e2apDb.ranFunction[id-1].id;
3726 serviceUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].revisionCounter = duCb.e2apDb.ranFunction[id-1].revisionCounter;
3727 serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded++;
3736 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
3738 serviceUpdate.dir = E2_NODE_INITIATED;
3739 BuildAndSendRicServiceUpdate(serviceUpdate);
3741 freeAperDecodingOfRicServiceUpdateAck(ricServiceAck);
3744 /******************************************************************
3746 * @brief Deallocation of memory allocated by aper decoder for
3747 * RIC service update failure
3751 * Function : freeAperDecodingOfRicServiceUpdateFailure
3753 * Functionality: Deallocation of memory allocated by aper decoder
3754 * for RIC service update failure
3756 * @params[in] RICserviceUpdateFailure_t *ricServiceFailure;
3759 * ****************************************************************/
3761 void freeAperDecodingOfRicServiceUpdateFailure(RICserviceUpdateFailure_t *ricServiceFailure)
3765 if(ricServiceFailure)
3767 if(ricServiceFailure->protocolIEs.list.array)
3769 for(arrIdx=0; arrIdx<ricServiceFailure->protocolIEs.list.count; arrIdx++)
3771 if(ricServiceFailure->protocolIEs.list.array[arrIdx])
3773 free(ricServiceFailure->protocolIEs.list.array[arrIdx]);
3776 free(ricServiceFailure->protocolIEs.list.array);
3781 /******************************************************************
3783 * @brief Processes RIC service update failure sent by RIC
3787 * Function : procRicServiceUpdateFailure
3789 * Functionality: Processes RIC service update failure sent by RIC
3791 * @params[in] E2AP_PDU_t ASN decoded E2AP message
3792 * @return ROK - success
3795 * ****************************************************************/
3797 void procRicServiceUpdateFailure(E2AP_PDU_t *e2apMsg)
3799 uint8_t arrIdx =0, timerValue=0;
3800 RICserviceUpdateFailure_t *ricServiceFailure=NULL;
3802 DU_LOG("\nINFO --> E2AP : RIC service update failure received");
3803 ricServiceFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICserviceUpdateFailure;
3805 for(arrIdx=0; arrIdx<ricServiceFailure->protocolIEs.list.count; arrIdx++)
3807 switch(ricServiceFailure->protocolIEs.list.array[arrIdx]->id)
3809 case ProtocolIE_IDE2_id_TransactionID:
3813 case ProtocolIE_IDE2_id_TimeToWaitE2:
3815 timerValue = covertE2WaitTimerEnumToValue(ricServiceFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
3816 if((duChkTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer), EVENT_RIC_SERVICE_UPDATE_TMR)) == FALSE)
3818 duStartTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer), EVENT_RIC_SERVICE_UPDATE_TMR, timerValue);
3822 DU_LOG("\nERROR --> E2AP : EVENT_RIC_SERVICE_UPDATE_TMR timer is already running");
3827 case ProtocolIE_IDE2_id_CauseE2:
3834 freeAperDecodingOfRicServiceUpdateFailure(ricServiceFailure);
3837 /*******************************************************************
3839 * @brief Handles received E2AP message and sends back response
3843 * Function : E2APMsgHdlr
3846 * - Decodes received E2AP control message
3847 * - Prepares response message, encodes and sends to SCTP
3850 * @return ROK - success
3853 * ****************************************************************/
3854 void E2APMsgHdlr(Buffer *mBuf)
3857 char *recvBuf = NULLP;
3859 MsgLen recvBufLen =0;
3860 E2AP_PDU_t *e2apMsg = NULLP;
3861 asn_dec_rval_t rval ={0}; /* Decoder return value */
3862 E2AP_PDU_t e2apasnmsg={0} ;
3864 DU_LOG("\nDEBUG --> E2AP : Received E2AP message buffer");
3865 ODU_PRINT_MSG(mBuf, 0,0);
3867 /* Copy mBuf into char array to decode it */
3868 ODU_GET_MSG_LEN(mBuf, &recvBufLen);
3869 DU_ALLOC(recvBuf, (Size)recvBufLen);
3871 if(recvBuf == NULLP)
3873 DU_LOG("\nERROR --> E2AP : Memory allocation failed");
3876 if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
3878 DU_LOG("\nERROR --> E2AP : Failed while copying %d", copyCnt);
3882 #ifdef DEBUG_ASN_PRINT
3883 printf("\nDEBUG --> E2AP : Received flat buffer to be decoded : ");
3884 for(i=0; i< recvBufLen; i++)
3886 printf("%x",recvBuf[i]);
3890 /* Decoding flat buffer into E2AP messsage */
3891 e2apMsg = &e2apasnmsg;
3892 memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
3894 rval = aper_decode(0, &asn_DEF_E2AP_PDU, (void **)&e2apMsg, recvBuf, recvBufLen, 0, 0);
3895 DU_FREE(recvBuf, (Size)recvBufLen);
3897 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
3899 DU_LOG("\nERROR --> E2AP : ASN decode failed");
3903 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3905 switch(e2apMsg->present)
3907 case E2AP_PDU_PR_unsuccessfulOutcome:
3909 switch(e2apMsg->choice.unsuccessfulOutcome->value.present)
3911 case UnsuccessfulOutcomeE2__value_PR_E2setupFailure:
3913 procE2SetupFailure(e2apMsg);
3916 case UnsuccessfulOutcomeE2__value_PR_RICserviceUpdateFailure:
3918 procRicServiceUpdateFailure(e2apMsg);
3923 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_unsuccessfulOutcome [%d]",\
3924 e2apMsg->choice.unsuccessfulOutcome->value.present);
3930 case E2AP_PDU_PR_successfulOutcome:
3932 switch(e2apMsg->choice.successfulOutcome->value.present)
3934 case SuccessfulOutcomeE2__value_PR_E2setupResponse:
3938 procE2SetupRsp(e2apMsg);
3942 case SuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateAcknowledge:
3944 DU_LOG("\nDEBUG --> E2AP : E2 node Config update ack message recevied");
3947 case SuccessfulOutcomeE2__value_PR_ResetResponseE2:
3949 procResetResponse(e2apMsg);
3952 case SuccessfulOutcomeE2__value_PR_RICserviceUpdateAcknowledge:
3954 procRicServiceUpdateAck(e2apMsg);
3961 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_successfulOutcome [%d]",\
3962 e2apMsg->choice.successfulOutcome->value.present);
3965 }/* End of switch(successfulOutcome) */
3966 free(e2apMsg->choice.successfulOutcome);
3970 case E2AP_PDU_PR_initiatingMessage:
3972 switch(e2apMsg->choice.initiatingMessage->value.present)
3974 case InitiatingMessageE2__value_PR_RICsubscriptionRequest:
3976 procRicSubsReq(e2apMsg);
3979 case InitiatingMessageE2__value_PR_RICserviceQuery:
3981 procRicServiceQuery(e2apMsg);
3986 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\
3987 e2apMsg->choice.initiatingMessage->value.present);
3990 }/* End of switch(initiatingMessage) */
3991 free(e2apMsg->choice.initiatingMessage);
3996 DU_LOG("\nERROR --> E2AP : Invalid type of e2apMsg->present [%d]",e2apMsg->present);
4001 }/* End of switch(e2apMsg->present) */
4003 } /* End of E2APMsgHdlr */
4005 /**********************************************************************
4007 **********************************************************************/