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"
54 /*******************************************************************
56 * @brief Builds Global gNodeB Params
60 * Function : BuildGlobalgNBId
62 * Functionality: Building the Plmn and gNB id
64 * @params[in] GlobalE2node_gNB_ID_t *gNbId
65 * @return ROK - success
68 ******************************************************************/
70 uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
74 uint8_t gnbId = duCb.gnbId;
77 /* fill Global gNB ID Id */
78 gNbId->global_gNB_ID.plmn_id.size = 3 * sizeof(uint8_t);
79 gNbId->global_gNB_ID.plmn_id.buf = NULLP;
80 DU_ALLOC(gNbId->global_gNB_ID.plmn_id.buf , gNbId->global_gNB_ID.plmn_id.size);
81 if(gNbId->global_gNB_ID.plmn_id.buf == NULLP)
83 DU_LOG("\nERROR --> E2AP: Memory allocation failed for Plmn buffer");
88 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
89 gNbId->global_gNB_ID.plmn_id.buf);
90 gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
91 /* Allocate Buffer size */
92 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = byteSize * sizeof(uint8_t);
93 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf = NULLP;
94 DU_ALLOC(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf, \
95 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
96 if(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf == NULLP)
98 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gnb buffer");
103 fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, gnbId);
108 DU_ALLOC( gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
109 if(gNbId->gNB_DU_ID == NULLP)
111 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gNB_DU_ID ");
116 gNbId->gNB_DU_ID->size = sizeof(uint8_t);
117 DU_ALLOC( gNbId->gNB_DU_ID->buf, sizeof(uint8_t));
118 if(gNbId->gNB_DU_ID->buf)
120 gNbId->gNB_DU_ID->buf[0] =duCb.e2apDb.e2NodeId;
124 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gNB_DU_ID buffer");
132 /******************************************************************
134 * @brief Search E2 node component with the help of action type
138 * Function : searchE2NodeComponentInfo
140 * Functionality: Search E2 node component with the help of action type
142 * @params[in] uint8_t componentActionType
145 * ****************************************************************/
147 CmLList *searchE2NodeComponentInfo(InterfaceType interfaceType, uint8_t componentActionType)
149 E2NodeComponent *e2NodeComponentInfo;
152 if(duCb.e2apDb.e2NodeComponentList.count)
154 CM_LLIST_FIRST_NODE(&duCb.e2apDb.e2NodeComponentList, node);
157 e2NodeComponentInfo = (E2NodeComponent*)node->node;
158 if((e2NodeComponentInfo->interfaceType == interfaceType) && (e2NodeComponentInfo->componentActionType == componentActionType))
167 /*******************************************************************
169 * @brief Builds E2 node config addition list
173 * Function : BuildE2NodeConfigAddList
175 * Functionality: Building E2 node config addition list
177 * @params[in] E2nodeComponentConfigAddition_List_t *e2NodeAddList
178 * @return ROK - success
181 ******************************************************************/
183 uint8_t BuildE2NodeConfigAddList(E2nodeComponentConfigAddition_List_t *e2NodeAddList)
187 E2NodeComponent *e2NodeComponentInfo;
188 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItemIe;
189 E2nodeComponentConfigAddition_Item_t *e2NodeAddItem;
191 e2NodeAddList->list.count = 1;
192 e2NodeAddList->list.size = e2NodeAddList->list.count * sizeof(E2nodeComponentConfigAddition_ItemIEs_t *);
193 DU_ALLOC(e2NodeAddList->list.array, e2NodeAddList->list.size);
194 if(e2NodeAddList->list.array == NULLP)
196 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
200 for(arrIdx = 0; arrIdx< e2NodeAddList->list.count; arrIdx++)
202 DU_ALLOC(e2NodeAddList->list.array[arrIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
203 if(e2NodeAddList->list.array[arrIdx] == NULLP)
205 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
210 node = searchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD);
213 DU_LOG("\nERROR --> E2AP : Received e2NodeComponentInfo is null");
216 e2NodeComponentInfo = (E2NodeComponent*)node->node;
219 e2NodeAddItemIe = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[arrIdx];
220 e2NodeAddItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition_Item;
221 e2NodeAddItemIe->criticality = CriticalityE2_reject;
222 e2NodeAddItemIe->value.present = E2nodeComponentConfigAddition_ItemIEs__value_PR_E2nodeComponentConfigAddition_Item;
223 e2NodeAddItem = &e2NodeAddItemIe->value.choice.E2nodeComponentConfigAddition_Item;
225 /* E2nodeComponentInterfaceType */
226 e2NodeAddItem->e2nodeComponentInterfaceType = E2nodeComponentInterfaceType_f1;
228 /* E2 Node Component Request Part */
229 if(e2NodeComponentInfo->componentRequestPart)
231 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size = e2NodeComponentInfo->reqBufSize ;
232 DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
233 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
234 if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf == NULLP)
236 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
240 memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
241 e2NodeComponentInfo->componentRequestPart, e2NodeAddItem->e2nodeComponentConfiguration.\
242 e2nodeComponentRequestPart.size);
246 DU_LOG("\nERROR --> E2AP: componentRequestPart is null ");
251 /* E2 Node Component Response Part */
252 if(e2NodeComponentInfo->componentResponsePart)
254 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size = e2NodeComponentInfo->rspBufSize;
255 DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \
256 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
257 if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf == NULLP)
259 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
262 memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \
263 e2NodeComponentInfo->componentResponsePart, e2NodeAddItem->e2nodeComponentConfiguration.\
264 e2nodeComponentResponsePart.size);
268 DU_LOG("\nERROR --> E2AP: componentResponsePart is null");
272 /* E2 Node Component ID */
273 e2NodeAddItem->e2nodeComponentID.present = E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1;
274 DU_ALLOC(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
275 sizeof(E2nodeComponentInterfaceF1_t));
276 if(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1 == NULLP)
278 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
281 e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size = sizeof(uint8_t);
282 DU_ALLOC(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
283 e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
285 if(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf == NULLP)
287 DU_LOG("\nERROR -->list. E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
290 e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[arrIdx] = e2NodeComponentInfo->componentId;
295 /*******************************************************************
297 * @brief deallocation of E2SM_KPM_RANfunction_Description_t
301 * Function : freeE2smKpmRanFunctionDefinition
303 * Functionality: deallocation of E2SM_KPM_RANfunction_Description_t
305 * @params[in] E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition
308 ******************************************************************/
310 void freeE2smKpmRanFunctionDefinition(E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition)
312 MeasurementInfo_Action_Item_t *measInfoList;
313 uint8_t eventTriggerIdx, reportStyleIdx, measInfoIdx;
314 RANfunction_Name_t *ranFuncName;
315 struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle;
316 struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *eventTriggerStyle;
317 if(ranFunctionDefinition)
319 ranFuncName = &ranFunctionDefinition->ranFunction_Name;
320 /* Free RAN function Name */
321 DU_FREE(ranFuncName->ranFunction_ShortName.buf, ranFuncName->ranFunction_ShortName.size);
322 DU_FREE(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
323 DU_FREE(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
325 /* Sequence of Event Trigger styles */
326 eventTriggerStyle = ranFunctionDefinition->ric_EventTriggerStyle_List;
327 if(eventTriggerStyle)
329 if(eventTriggerStyle->list.array)
331 for(eventTriggerIdx =0;eventTriggerIdx<eventTriggerStyle->list.count; eventTriggerIdx++)
333 if(eventTriggerStyle->list.array[eventTriggerIdx])
335 DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.buf,\
336 eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.size);
337 DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
340 DU_FREE(eventTriggerStyle->list.array, eventTriggerStyle->list.size)
342 DU_FREE(eventTriggerStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
345 /* Sequence of Report styles */
346 ricReportStyle = ranFunctionDefinition->ric_ReportStyle_List;
349 if(ricReportStyle->list.array)
351 for(reportStyleIdx =0;reportStyleIdx<ricReportStyle->list.count; reportStyleIdx++)
353 if(ricReportStyle->list.array[reportStyleIdx])
355 if(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf)
357 DU_FREE(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf,\
358 ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.size);
360 if(ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array)
362 for(measInfoIdx=0; measInfoIdx<ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.count; \
365 measInfoList = ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array[measInfoIdx];
368 DU_FREE(measInfoList->measID, sizeof(long));
369 DU_FREE(measInfoList->measName.buf, measInfoList->measName.size);
370 DU_FREE(measInfoList,sizeof(MeasurementInfo_Action_Item_t));
373 DU_FREE(measInfoList,ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.size);
375 DU_FREE(ricReportStyle->list.array[reportStyleIdx], sizeof(RIC_ReportStyle_Item_t));
378 DU_FREE(ricReportStyle->list.array, ricReportStyle->list.size);
380 DU_FREE(ricReportStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
382 DU_FREE(ranFunctionDefinition, sizeof(E2SM_KPM_RANfunction_Description_t));
386 /*******************************************************************
388 * @brief fill the e2sm ric report style
392 * Function : fillRicReportStyle
394 * Functionality: fill the report style
396 * @params[in] RanFunction *ranFuncDb, struct
397 * E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle
398 * @return ROK - success
401 ******************************************************************/
402 uint8_t fillRicReportStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle)
404 uint8_t styleIdx, measInfoIdx;
405 MeasurementInfo_Action_List_t *measInfo;
408 ricReportStyle->list.count = ranFuncDb->numOfReportStyleSupported;
409 ricReportStyle->list.size = ricReportStyle->list.count * sizeof(RIC_ReportStyle_Item_t*);
410 DU_ALLOC(ricReportStyle->list.array, ricReportStyle->list.size);
411 if(!ricReportStyle->list.array)
413 DU_LOG("\nERROR --> E2AP: Memory allocation failed for ranFuncDefinition %d",__LINE__);
417 for(styleIdx =0;styleIdx<ricReportStyle->list.count; styleIdx++)
419 DU_ALLOC(ricReportStyle->list.array[styleIdx], sizeof(RIC_ReportStyle_Item_t));
420 if(!ricReportStyle->list.array[styleIdx])
422 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
426 /* RIC Report Style Type */
427 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.styleType;
429 /* RIC Report Style Format Type */
430 ricReportStyle->list.array[styleIdx]->ric_ActionFormat_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.formatType;
432 /* RIC Report Style Name */
433 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size = strlen(ranFuncDb->reportStyleList[styleIdx].reportStyle.name);
434 DU_ALLOC(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf,\
435 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
436 if(!ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf)
438 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
441 memcpy(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf, ranFuncDb->reportStyleList[styleIdx].reportStyle.name,\
442 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
444 /* RIC Indication Header Format Type*/
445 ricReportStyle->list.array[styleIdx]->ric_IndicationHeaderFormat_Type = ranFuncDb->ricIndicationHeaderFormat;
447 /* RIC Indication Message Format Type*/
448 ricReportStyle->list.array[styleIdx]->ric_IndicationMessageFormat_Type = ranFuncDb->ricIndicationMessageFormat;
450 /* Measurement Info Action List */
451 CmLListCp measInfoList =ranFuncDb->reportStyleList[styleIdx].measurementInfoList;
452 if(!measInfoList.count)
457 CM_LLIST_FIRST_NODE(&ranFuncDb->reportStyleList[styleIdx].measurementInfoList, node);
458 measInfo = &ricReportStyle->list.array[styleIdx]->measInfo_Action_List;
460 measInfo->list.count = measInfoList.count;
461 measInfo->list.size = measInfoList.count*sizeof(MeasurementInfo_Action_Item_t*);
462 DU_ALLOC(measInfo->list.array, measInfo->list.size);
463 if(!measInfo->list.array)
465 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
469 for(measInfoIdx=0; measInfoIdx<measInfo->list.count; measInfoIdx++)
473 DU_LOG("\nERROR --> E2AP: Measurement info node is null");
477 DU_ALLOC(measInfo->list.array[measInfoIdx],sizeof(MeasurementInfo_Action_Item_t));
478 if(!measInfo->list.array[measInfoIdx])
480 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
483 MeasurementInfoForAction *measInfoForAction= (MeasurementInfoForAction*)node->node;
484 DU_ALLOC(measInfo->list.array[measInfoIdx]->measID, sizeof(long));
485 if(!measInfo->list.array[measInfoIdx]->measID)
487 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
491 memcpy(measInfo->list.array[measInfoIdx]->measID, &measInfoForAction->measurementTypeId,sizeof(long));
492 measInfo->list.array[measInfoIdx]->measName.size= strlen(measInfoForAction->measurementTypeName);
493 DU_ALLOC(measInfo->list.array[measInfoIdx]->measName.buf, measInfo->list.array[measInfoIdx]->measName.size);
494 if(!measInfo->list.array[measInfoIdx]->measName.size)
496 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
500 memcpy(measInfo->list.array[measInfoIdx]->measName.buf, \
501 measInfoForAction->measurementTypeName,\
502 measInfo->list.array[measInfoIdx]->measName.size);
509 /*******************************************************************
511 * @brief fill the ric event trigger style
515 * Function : fillRicEventTriggerStyle
517 * Functionality: fill the ric event trigger style
520 * @return ROK - success
523 ******************************************************************/
524 uint8_t fillRicEventTriggerStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *ricEventTriggerStyle)
528 ricEventTriggerStyle->list.count = ranFuncDb->numOfEventTriggerStyleSupported;
529 ricEventTriggerStyle->list.size = ricEventTriggerStyle->list.count* sizeof(RIC_EventTriggerStyle_Item_t *);
530 DU_ALLOC(ricEventTriggerStyle->list.array, ricEventTriggerStyle->list.size);
531 if(!ricEventTriggerStyle->list.array)
533 DU_LOG("\nERROR --> E2AP: Memory allocation failed for ric_EventTriggerStyle_List %d",__LINE__);
537 for(styleIdx =0;styleIdx<ricEventTriggerStyle->list.count; styleIdx++)
539 DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
540 if(!ricEventTriggerStyle->list.array[styleIdx])
542 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
545 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Type = ranFuncDb->eventTriggerStyleList[styleIdx].styleType;
547 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerFormat_Type = ranFuncDb->eventTriggerStyleList[styleIdx].formatType;
549 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size = strlen(ranFuncDb->eventTriggerStyleList[styleIdx].name);
550 DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,\
551 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
552 if(!ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf)
554 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
557 memcpy(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,ranFuncDb->eventTriggerStyleList[styleIdx].name,\
558 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
564 /*******************************************************************
566 * @brief Builds Ran function item
570 * Function : BuildRanFunctionItem
572 * Functionality: Building RAN function item
575 * RAN function item that has to be filled
576 * Stored RAN Function information
577 * @return ROK - success
580 ******************************************************************/
582 uint8_t BuildRanFunctionItem(RANfunction_Item_t *ranFuncItem, RanFunction *ranFuncDb)
584 uint8_t ret =RFAILED;
585 RANfunctionDefinition_t *ranFunctionDefinition;
586 RANfunction_Name_t *ranFuncName;
587 asn_enc_rval_t encRetVal;
588 E2SM_KPM_RANfunction_Description_t *ranFuncDefinition;
593 ranFuncItem->ranFunctionID = ranFuncDb->id;
595 /* RAN Function Revision*/
596 ranFuncItem->ranFunctionRevision = ranFuncDb->revisionCounter;
598 /* RAN function OID*/
599 ranFuncItem->ranFunctionOID.size = strlen(ranFuncDb->name.serviceModelOID);
600 DU_ALLOC(ranFuncItem->ranFunctionOID.buf, ranFuncItem->ranFunctionOID.size);
601 if(!ranFuncItem->ranFunctionOID.buf)
603 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
606 memcpy(ranFuncItem->ranFunctionOID.buf, ranFuncDb->name.serviceModelOID, ranFuncItem->ranFunctionOID.size);
608 /* RAN function Definition */
609 DU_ALLOC(ranFuncDefinition, sizeof(E2SM_KPM_RANfunction_Description_t));
610 if(!ranFuncDefinition)
612 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
616 /* RAN function Name */
617 ranFuncName = &ranFuncDefinition->ranFunction_Name;
619 /* RAN function ShortName */
620 ranFuncName->ranFunction_ShortName.size = strlen(ranFuncDb->name.shortName);
621 DU_ALLOC(ranFuncName->ranFunction_ShortName.buf, ranFuncName->ranFunction_ShortName.size);
622 if(!ranFuncName->ranFunction_ShortName.buf)
624 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
627 memcpy(ranFuncName->ranFunction_ShortName.buf, ranFuncDb->name.shortName, strlen(ranFuncDb->name.shortName));
629 /* RAN function E2SM_OID */
630 ranFuncName->ranFunction_E2SM_OID.size = strlen(ranFuncDb->name.serviceModelOID);
631 DU_ALLOC(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
632 if(!ranFuncName->ranFunction_E2SM_OID.buf)
634 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
637 memcpy(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncDb->name.serviceModelOID, ranFuncName->ranFunction_E2SM_OID.size);
639 /* RAN Function Name Description */
640 ranFuncName->ranFunction_Description.size = strlen(ranFuncDb->name.description);
641 DU_ALLOC(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
642 if(!ranFuncName->ranFunction_Description.buf)
644 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
647 memcpy(ranFuncName->ranFunction_Description.buf, ranFuncDb->name.description, ranFuncName->ranFunction_Description.size);
649 /* RIC Event Trigger Style List */
650 DU_ALLOC(ranFuncDefinition->ric_EventTriggerStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
651 if(!ranFuncDefinition->ric_EventTriggerStyle_List)
653 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
657 if(fillRicEventTriggerStyle(ranFuncDb, ranFuncDefinition->ric_EventTriggerStyle_List)!=ROK)
659 DU_LOG("\nERROR --> E2AP: failed to fill ric event trigger style");
663 /* RIC Report Style List */
664 DU_ALLOC(ranFuncDefinition->ric_ReportStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
665 if(!ranFuncDefinition->ric_ReportStyle_List)
667 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
670 if(fillRicReportStyle(ranFuncDb, ranFuncDefinition->ric_ReportStyle_List) != ROK)
672 DU_LOG("\nERROR --> E2AP: failed to fill ric report style");
676 /* Encode the F1SetupRequest type as APER */
677 xer_fprint(stdout, &asn_DEF_E2SM_KPM_RANfunction_Description, ranFuncDefinition);
679 memset(encBuf, 0, ENC_BUF_MAX_LEN);
681 encRetVal = aper_encode(&asn_DEF_E2SM_KPM_RANfunction_Description, 0, ranFuncDefinition, PrepFinalEncBuf, encBuf);
684 if(encRetVal.encoded == ENCODE_FAIL)
686 DU_LOG("\nERROR --> F1AP : Could not encode RAN function definition (at %s)\n",\
687 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
692 DU_LOG("\nDEBUG --> F1AP : Created APER encoded buffer for RAN function definition \n");
693 for(uint8_t measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
695 printf("%x",encBuf[measIeIdx]);
697 ranFunctionDefinition = &ranFuncItem->ranFunctionDefinition;
698 ranFunctionDefinition->size = encBufSize;
699 DU_ALLOC(ranFunctionDefinition->buf, encBufSize);
700 if(ranFunctionDefinition->buf == NULLP)
702 DU_LOG("\nERROR --> F1AP : Memory allocation failed for RAN function definition buffer");
705 memcpy(ranFunctionDefinition->buf, &encBuf, encBufSize);
710 freeE2smKpmRanFunctionDefinition(ranFuncDefinition);
714 /*******************************************************************
716 * @brief Builds Ran function add list based on the procedure code
720 * Function : BuildRanFunctionAddList
722 * Functionality: Building RAN addition addition list
723 * In case of ProcedureCodeE2_id_E2setup we add all the RAN Function list
724 * which is present in E2 database.
725 * In the case of other procedures, we just fill the RAN functions whose ID
726 * is contained in recvList
731 * Count of ran functions to be added in the list
732 * Received list of RAN functions
734 * @return ROK - success
737 ******************************************************************/
739 uint8_t BuildRanFunctionAddList(RANfunctions_List_t *ranFunctionsList, uint8_t procedureCode, uint8_t count, RanFuncInfo *recvList)
742 RanFunction *ranFuncDb;
744 RANfunction_ItemIEs_t *ranFuncItemIe;
746 /* For ProcedureCodeE2_id_E2setup, the number of RAN function list items is
747 * equal to the number of ran function entries stored in the database.
748 * For any other procedure, the RAN function list count is equal
749 * to the count of ran functions obtained from the function's caller */
751 if(procedureCode == ProcedureCodeE2_id_E2setup)
752 ranFunctionsList->list.count = duCb.e2apDb.numOfRanFunction;
754 ranFunctionsList->list.count = count;
756 ranFunctionsList->list.size = ranFunctionsList->list.count * sizeof(RANfunction_ItemIEs_t*);
757 DU_ALLOC(ranFunctionsList->list.array, ranFunctionsList->list.size);
758 if(ranFunctionsList->list.array == NULLP)
760 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
764 for(ranFuncIdx = 0; ranFuncIdx< ranFunctionsList->list.count; ranFuncIdx++)
766 DU_ALLOC(ranFunctionsList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
767 if(ranFunctionsList->list.array[ranFuncIdx] == NULLP)
769 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
772 if(procedureCode == ProcedureCodeE2_id_E2setup)
774 /* Getting all of the RAN function's information from DuCb one by one*/
775 ranFuncDb = &duCb.e2apDb.ranFunction[ranFuncIdx];
779 /* Getting only the RAN function information from DuCb whose Id is
780 * present in the received array */
781 id =recvList[ranFuncIdx].id;
782 ranFuncDb = &duCb.e2apDb.ranFunction[id-1];
784 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncIdx];
785 ranFuncItemIe->id = ProtocolIE_IDE2_id_RANfunction_Item;
786 ranFuncItemIe->criticality = CriticalityE2_ignore;
787 ranFuncItemIe->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
788 BuildRanFunctionItem(&ranFuncItemIe->value.choice.RANfunction_Item, ranFuncDb);
793 /*******************************************************************
795 * @brief De Allocate E2 Setup Request Message
799 * Function : FreeE2SetupReq
801 * Functionality: De-Allocating E2 Setup request Message
803 * @params[in] E2AP_PDU_t *e2apMsg
807 * ****************************************************************/
809 void FreeE2SetupReq(E2AP_PDU_t *e2apMsg)
812 uint8_t e2NodeAddListIdx =0, ranFuncAddListIdx;
813 E2setupRequest_t *e2SetupReq;
814 E2nodeComponentConfigAddition_List_t *e2NodeAddList;
815 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem;
816 RANfunctions_List_t *ranFunctionsList;
817 RANfunction_ItemIEs_t *ranFuncItemIe;
818 RANfunction_Item_t *ranFunItem;
820 /* De-allocating Memory */
823 if(e2apMsg->choice.initiatingMessage != NULLP)
825 e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
826 if(e2SetupReq->protocolIEs.list.array != NULLP)
828 for(arrIdx = 0; arrIdx < e2SetupReq->protocolIEs.list.count; arrIdx++)
830 if(e2SetupReq->protocolIEs.list.array[arrIdx] != NULLP)
832 switch(e2SetupReq->protocolIEs.list.array[arrIdx]->id)
834 case ProtocolIE_IDE2_id_TransactionID:
836 case ProtocolIE_IDE2_id_GlobalE2node_ID:
838 if(e2SetupReq->protocolIEs.list.array[arrIdx]->\
839 value.choice.GlobalE2node_ID.choice.gNB != NULLP)
841 GlobalE2node_gNB_ID_t *gNbId = NULLP;
842 gNbId = e2SetupReq->protocolIEs.list.array[arrIdx]->\
843 value.choice.GlobalE2node_ID.choice.gNB;
844 if(gNbId->global_gNB_ID.plmn_id.buf != NULLP)
846 DU_FREE(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf,\
847 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
848 DU_FREE(gNbId->global_gNB_ID.plmn_id.buf,\
849 gNbId->global_gNB_ID.plmn_id.size);
852 if(gNbId->gNB_DU_ID != NULLP)
854 DU_FREE( gNbId->gNB_DU_ID->buf, gNbId->gNB_DU_ID->size);
855 DU_FREE(gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
857 DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
858 choice.GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
862 case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
864 e2NodeAddList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List;
865 if(e2NodeAddList->list.array)
867 for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++)
869 e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[e2NodeAddListIdx];
871 /* Free E2 Node Component Request Part */
872 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
873 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
875 /* Free E2 Node Component Response Part */
876 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.\
877 e2nodeComponentResponsePart.buf, \
878 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
880 /* Free E2 Node Component ID */
881 if(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1)
883 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
884 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
885 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
886 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
887 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
888 sizeof(E2nodeComponentInterfaceF1_t));
890 DU_FREE(e2NodeAddList->list.array[e2NodeAddListIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
892 DU_FREE(e2NodeAddList->list.array, e2NodeAddList->list.size);
896 case ProtocolIE_IDE2_id_RANfunctionsAdded:
898 ranFunctionsList = &(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List);
899 if(ranFunctionsList->list.array)
901 for(ranFuncAddListIdx= 0; ranFuncAddListIdx< ranFunctionsList->list.count; ranFuncAddListIdx++)
903 if(ranFunctionsList->list.array[ranFuncAddListIdx])
905 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncAddListIdx];
906 ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
907 DU_FREE(ranFunItem->ranFunctionOID.buf, ranFunItem->ranFunctionOID.size);
908 DU_FREE(ranFunItem->ranFunctionDefinition.buf, ranFunItem->ranFunctionDefinition.size);
909 DU_FREE(ranFunctionsList->list.array[ranFuncAddListIdx], sizeof(RANfunction_ItemIEs_t));
912 DU_FREE(ranFunctionsList->list.array, ranFunctionsList->list.size);
918 DU_LOG("\nERROR --> E2AP: Invalid event at e2SetupRequet %ld ",\
919 (e2SetupReq->protocolIEs.list.array[arrIdx]->id));
922 DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx], sizeof(E2setupRequestIEs_t));
925 DU_FREE(e2SetupReq->protocolIEs.list.array, e2SetupReq->protocolIEs.list.size);
927 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
929 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
933 /*******************************************************************
935 * @brief Builds and Send the E2SetupRequest
939 * Function : BuildAndSendE2SetupReq
941 * Functionality:Fills the E2SetupRequest
943 * @return ROK - success
946 ******************************************************************/
948 uint8_t BuildAndSendE2SetupReq()
950 uint8_t arrIdx = 0, elementCnt=0;
951 uint8_t transId = 0, ret = ROK;
953 E2AP_PDU_t *e2apMsg = NULLP;
954 E2setupRequest_t *e2SetupReq = NULLP;
955 asn_enc_rval_t encRetVal; /* Encoder return value */
957 DU_LOG("\nINFO --> E2AP : Building E2 Setup Request\n");
960 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
963 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
966 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
967 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
968 if(e2apMsg->choice.initiatingMessage == NULLP)
970 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
973 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
974 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2setup;
975 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_E2setupRequest;
976 e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
979 e2SetupReq->protocolIEs.list.count = elementCnt;
980 e2SetupReq->protocolIEs.list.size = elementCnt * sizeof(E2setupRequestIEs_t*);
982 /* Initialize the E2Setup members */
983 DU_ALLOC(e2SetupReq->protocolIEs.list.array, \
984 e2SetupReq->protocolIEs.list.size);
985 if(e2SetupReq->protocolIEs.list.array == NULLP)
987 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements");
990 for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
992 DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx],\
993 sizeof(E2setupRequestIEs_t));
994 if(e2SetupReq->protocolIEs.list.array[arrIdx] == NULLP)
996 memAllocFailed = true;
997 DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayarrIdx [%d]", arrIdx);
1001 if(memAllocFailed == true)
1007 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
1008 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1009 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
1010 transId = assignTransactionId();
1011 e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
1014 /* GlobalE2node_gNB_ID */
1015 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_GlobalE2node_ID;
1016 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1017 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
1018 e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
1020 DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
1021 GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
1022 if(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
1023 GlobalE2node_ID.choice.gNB == NULLP)
1025 DU_LOG("\nERROR --> E2AP : Memory allocation failed for gNbId");
1030 ret = BuildGlobalgNBId(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
1031 choice.GlobalE2node_ID.choice.gNB);
1034 DU_LOG("\nERROR --> E2AP : Failed to build Global Gnb Id");
1039 /* RAN Functions Added List */
1041 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
1042 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1043 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_RANfunctions_List;
1044 if(BuildRanFunctionAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List), ProcedureCodeE2_id_E2setup, 0, NULL)!=ROK)
1046 DU_LOG("\nERROR --> E2AP : Failed to create RAN Function");
1050 /* E2 Node Component Configuration Addition List */
1052 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition;
1053 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1054 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_E2nodeComponentConfigAddition_List;
1055 if(BuildE2NodeConfigAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List))!=ROK)
1057 DU_LOG("\nERROR --> E2AP : Failed to create E2 Node config list");
1063 /* Prints the Msg formed */
1064 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1066 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1068 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
1070 if(encRetVal.encoded == ENCODE_FAIL)
1072 DU_LOG("\nERROR --> E2AP : Could not encode E2SetupRequest structure (at %s)\n",\
1073 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1078 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupRequest\n");
1079 #ifdef DEBUG_ASN_PRINT
1080 for(int i=0; i< encBufSize; i++)
1082 printf("%x",encBuf[i]);
1086 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
1088 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
1093 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
1094 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
1096 FreeE2SetupReq(e2apMsg);
1098 }/* End of BuildAndSendE2SetupReq */
1100 /*******************************************************************
1102 * @brief Builds Ric Request Id
1106 * Function : BuildRicRequestId
1108 * Functionality: Building the Ric Request Id
1110 * @params[in] RICrequestID_t *ricReqId
1111 * @return ROK - success
1114 * ****************************************************************/
1116 uint8_t BuildRicRequestId(RICrequestID_t *ricReqId)
1118 if(ricReqId == NULLP)
1123 ricReqId->ricRequestorID = 1;
1124 ricReqId->ricInstanceID = 1;
1128 /*******************************************************************
1130 * @brief Fills the mandatory RicAdmitted List Items
1134 * Function : fillRicAdmitList
1136 * Functionality: Fills the mandatory Ric Admitted List Items
1138 * @params[in] RICaction_Admitted_ItemIEs_t *ricAdmitItems
1139 * @return ROK - success
1142 * ****************************************************************/
1144 uint8_t fillRicAdmitList(RICaction_Admitted_ItemIEs_t *ricAdmitItems)
1147 if(ricAdmitItems != NULLP)
1149 ricAdmitItems->id = ProtocolIE_IDE2_id_RICaction_Admitted_Item;
1150 ricAdmitItems->criticality = CriticalityE2_reject;
1151 ricAdmitItems->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
1152 ricAdmitItems->value.choice.RICaction_Admitted_Item.ricActionID = 1;
1160 /*******************************************************************
1162 * @brief Builds the mandatory RicAdmitted List Params
1166 * Function : BuildRicAdmitList
1168 * Functionality: Builds the mandatory Ric Admitted List Params
1170 * @params[in] RICaction_Admitted_List_t *admitListPtr
1171 * @return ROK - success
1174 * ****************************************************************/
1176 uint8_t BuildRicAdmitList(RICaction_Admitted_List_t *admitListPtr)
1183 if(admitListPtr == NULLP)
1185 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC Admit List failed");
1190 admitListPtr->list.count = elementCnt;
1191 admitListPtr->list.size = elementCnt * sizeof(RICaction_Admitted_ItemIEs_t);
1192 DU_ALLOC(admitListPtr->list.array, admitListPtr->list.size);
1193 if(admitListPtr->list.array == NULLP)
1195 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC Admit List failed");
1200 for(idx=0 ; idx<elementCnt ; idx++ )
1202 DU_ALLOC(admitListPtr->list.array[idx], sizeof(RICaction_Admitted_ItemIEs_t));
1203 if(admitListPtr->list.array[idx] == NULLP)
1211 fillRicAdmitList((RICaction_Admitted_ItemIEs_t *)admitListPtr->list.array[idx]);
1217 /*******************************************************************
1219 * @breif Deallocation of BuildAndSendRicSubscriptionRsp memory
1223 * Function : FreeRicSubscriptionRsp
1225 * Functionality:Free the RicSubscriptionRsp
1227 * @param[in] E2AP_PDU_t *e2apRicMsg
1232 ******************************************************************/
1233 void FreeRicSubscriptionRsp(E2AP_PDU_t *e2apRicMsg)
1235 RICsubscriptionResponse_t *ricSubscriptionRsp= NULLP;
1238 RICaction_Admitted_List_t *admitListPtr;
1240 if(e2apRicMsg != NULLP)
1242 if(e2apRicMsg->choice.successfulOutcome != NULLP)
1244 ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
1245 if(ricSubscriptionRsp)
1247 if(ricSubscriptionRsp->protocolIEs.list.array != NULLP)
1249 for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
1251 if(ricSubscriptionRsp->protocolIEs.list.array[idx] != NULLP)
1253 switch(ricSubscriptionRsp->protocolIEs.list.array[idx]->id)
1255 case ProtocolIE_IDE2_id_RICrequestID:
1258 case ProtocolIE_IDE2_id_RANfunctionID:
1261 case ProtocolIE_IDE2_id_RICactions_Admitted:
1263 admitListPtr = &ricSubscriptionRsp->protocolIEs.list.\
1264 array[idx]->value.choice.RICaction_Admitted_List;
1265 if(admitListPtr->list.array != NULLP)
1267 for(idx1=0 ; idx1<admitListPtr->list.count; idx1++ )
1269 if(admitListPtr->list.array[idx1] != NULLP)
1271 DU_FREE(admitListPtr->list.array[idx1],
1272 sizeof(RICaction_Admitted_ItemIEs_t));
1275 DU_FREE(admitListPtr->list.array, admitListPtr->list.size);
1282 DU_FREE(ricSubscriptionRsp->protocolIEs.list.array[idx], \
1283 sizeof(RICsubscriptionResponse_IEs_t));
1286 DU_FREE(ricSubscriptionRsp->protocolIEs.list.array, \
1287 ricSubscriptionRsp->protocolIEs.list.size);
1290 DU_FREE(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
1292 DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
1295 /*******************************************************************
1297 * @brief Builds and Send the RicSubscriptionRsp
1301 * Function : BuildAndSendRicSubscriptionRsp
1303 * functionality:Fills the RicSubscriptionRsp
1305 * @return ROK - success
1308 ******************************************************************/
1309 uint8_t FillRicSubscriptionRsp(RICsubscriptionResponse_t *ricSubscriptionRsp )
1313 uint8_t elementCnt = 0;
1314 uint8_t BuildRicRequestIdret=ROK;
1315 uint8_t BuildRicAdmitListret=ROK;
1318 ricSubscriptionRsp->protocolIEs.list.count = elementCnt;
1319 ricSubscriptionRsp->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionResponse_IEs_t);
1320 DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array, \
1321 ricSubscriptionRsp->protocolIEs.list.size);
1322 if(ricSubscriptionRsp->protocolIEs.list.array == NULLP)
1324 DU_LOG("\nERROR --> E2AP : Memory allocation for FillRicSubscriptionRsp failed");
1329 for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
1331 DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array[idx], \
1332 sizeof(RICsubscriptionResponse_IEs_t));
1333 if(ricSubscriptionRsp->protocolIEs.list.array[idx] == NULLP)
1342 ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
1343 ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1344 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
1345 RICsubscriptionRequest_IEs__value_PR_RICrequestID;
1346 BuildRicRequestIdret =
1347 BuildRicRequestId(&ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RICrequestID);
1348 if(BuildRicRequestIdret != ROK)
1355 ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
1356 ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1357 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
1358 RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
1359 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RANfunctionID = 1;
1362 ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactions_Admitted;
1363 ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1364 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
1365 RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
1366 BuildRicAdmitListret =
1367 BuildRicAdmitList(&ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RICaction_Admitted_List);
1368 if(BuildRicAdmitListret != ROK)
1377 /*******************************************************************
1379 * @brief Builds and Send the RicSubscriptionRsp
1383 * Function : BuildAndSendRicSubscriptionRsp
1385 * Functionality:Fills the RicSubscriptionRsp
1387 * @return ROK - success
1390 ******************************************************************/
1392 uint8_t BuildAndSendRicSubscriptionRsp()
1395 E2AP_PDU_t *e2apRicMsg = NULLP;
1396 RICsubscriptionResponse_t *ricSubscriptionRsp=NULLP;
1397 asn_enc_rval_t encRetVal;
1398 uint8_t ret = RFAILED;
1399 uint8_t FillRicricSubscriptionRspret;
1403 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Response\n");
1405 DU_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t));
1406 if(e2apRicMsg == NULLP)
1408 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1411 e2apRicMsg->present = E2AP_PDU_PR_successfulOutcome;
1412 DU_ALLOC(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
1413 if(e2apRicMsg->choice.successfulOutcome == NULLP)
1415 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC subscription Response failed");
1419 e2apRicMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
1420 e2apRicMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
1421 e2apRicMsg->choice.successfulOutcome->value.present = \
1422 SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse;
1423 ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
1425 FillRicricSubscriptionRspret = FillRicSubscriptionRsp(ricSubscriptionRsp);
1426 if(FillRicricSubscriptionRspret != ROK)
1428 DU_LOG("\nERROR --> E2AP : Memory allocation for RICsubscriptionResponseIE failed");
1432 /* Prints the Msg formed */
1433 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg);
1435 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1437 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apRicMsg, PrepFinalEncBuf,\
1439 if(encRetVal.encoded == ENCODE_FAIL)
1441 DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Response structure (at %s)\n",\
1442 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1447 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC subscription response \n");
1448 #ifdef DEBUG_ASN_PRINT
1449 for(int i=0; i< encBufSize; i++)
1451 printf("%x",encBuf[i]);
1456 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
1458 DU_LOG("\nERROR --> E2AP : Sending RIC Subscription Response failed");
1466 FreeRicSubscriptionRsp(e2apRicMsg);
1471 /******************************************************************
1473 * @brief Deallocation of memory allocated bu aper decoder for e2 setup response
1477 * Function : freeAperDecodingOfE2SetupRsp
1479 * Functionality: Deallocation of memory allocated bu aper decoder for e2
1482 * @params[in] E2setupResponse_t *e2SetRspMsg;
1485 * ****************************************************************/
1486 void freeAperDecodingOfE2SetupRsp(E2setupResponse_t *e2SetRspMsg)
1488 uint8_t arrIdx, e2NodeConfigAddAckListIdx;
1489 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem;
1490 E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAddAckList;
1494 if(e2SetRspMsg->protocolIEs.list.array)
1496 for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
1498 if(e2SetRspMsg->protocolIEs.list.array[arrIdx])
1500 switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
1502 case ProtocolIE_IDE2_id_TransactionID:
1505 case ProtocolIE_IDE2_id_GlobalRIC_ID:
1507 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.pLMN_Identity.buf);
1508 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID.buf);
1512 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
1514 e2NodeConfigAddAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
1515 if(e2NodeConfigAddAckList->list.array )
1517 for(e2NodeConfigAddAckListIdx = 0; e2NodeConfigAddAckListIdx< e2NodeConfigAddAckList->list.count; e2NodeConfigAddAckListIdx++)
1519 if(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx])
1521 e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx];
1522 free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
1523 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf);
1524 free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
1525 e2nodeComponentInterfaceTypeF1);
1526 free(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx]);
1529 free(e2NodeConfigAddAckList->list.array);
1534 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]);
1537 free(e2SetRspMsg->protocolIEs.list.array);
1541 /******************************************************************
1543 * @brief Processes E2 Setup Response sent by RIC
1547 * Function : procE2SetupRsp
1549 * Functionality: Processes E2 Setup Response sent by RIC
1551 * @params[in] E2AP_PDU_t ASN decoded E2AP message
1552 * @return ROK - success
1555 * ****************************************************************/
1556 uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
1558 uint8_t arrIdx =0, transId=0;
1559 uint32_t recvBufLen;
1560 E2setupResponse_t *e2SetRspMsg;
1562 E2NodeComponent *e2NodeComponentInfo;
1564 DU_LOG("\nINFO --> E2AP : E2 Setup Response received");
1565 duCb.e2Status = TRUE; //Set E2 status as true
1566 e2SetRspMsg = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
1568 for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
1570 switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
1572 case ProtocolIE_IDE2_id_TransactionID:
1574 transId = e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
1575 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
1576 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
1578 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
1582 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
1588 case ProtocolIE_IDE2_id_GlobalRIC_ID:
1590 /* To store the Ric Id Params */
1591 recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value\
1592 .choice.GlobalRIC_ID.pLMN_Identity.size);
1593 memcpy(&duCb.e2apDb.ricId.plmnId, e2SetRspMsg->protocolIEs.list.array[arrIdx]\
1594 ->value.choice.GlobalRIC_ID.pLMN_Identity.buf, recvBufLen);
1595 bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID, &duCb.e2apDb.ricId);
1596 /*TODO : duCb.e2apDb.ricId.plmnId memory to be deallocated after the usage */
1600 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
1604 DU_LOG("\nERROR --> E2AP : Invalid IE received in E2SetupRsp:%ld",
1605 e2SetRspMsg->protocolIEs.list.array[arrIdx]->id);
1609 freeAperDecodingOfE2SetupRsp(e2SetRspMsg);
1611 node = searchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD);
1614 DU_LOG("\nERROR --> E2AP : Received e2NodeComponentInfo is null");
1619 e2NodeComponentInfo = (E2NodeComponent*)node->node;
1620 cmLListDelFrm(&duCb.e2apDb.e2NodeComponentList, node);
1621 DU_FREE(e2NodeComponentInfo->componentRequestPart, e2NodeComponentInfo->reqBufSize);
1622 DU_FREE(e2NodeComponentInfo->componentResponsePart, e2NodeComponentInfo->rspBufSize);
1623 DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
1624 DU_FREE(node, sizeof(CmLList));
1627 BuildAndSendE2NodeConfigUpdate();
1631 /*******************************************************************
1633 * @brief Free RIC Subscription Request
1637 * Function : freeAperDecodingOfRicSubsReq
1639 * Functionality : Free RIC Subscription Request
1643 ******************************************************************/
1644 void freeAperDecodingOfRicSubsReq(RICsubscriptionRequest_t *ricSubscriptionReq)
1647 uint8_t elementIdx = 0;
1648 RICsubscriptionDetails_t *subsDetails = NULLP;
1649 RICaction_ToBeSetup_ItemIEs_t *actionItem = NULLP;
1651 if(ricSubscriptionReq->protocolIEs.list.array)
1653 for(idx=0; idx < ricSubscriptionReq->protocolIEs.list.count; idx++)
1655 switch(ricSubscriptionReq->protocolIEs.list.array[idx]->id)
1657 case ProtocolIE_IDE2_id_RICsubscriptionDetails:
1659 subsDetails = &(ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails);
1660 free(subsDetails->ricEventTriggerDefinition.buf);
1662 if(subsDetails->ricAction_ToBeSetup_List.list.array)
1664 for(elementIdx = 0; elementIdx < subsDetails->ricAction_ToBeSetup_List.list.count; elementIdx++)
1666 if(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx])
1668 actionItem = (RICaction_ToBeSetup_ItemIEs_t *)subsDetails->ricAction_ToBeSetup_List.\
1669 list.array[elementIdx];
1670 if(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition)
1672 free(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->buf);
1673 free(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition);
1675 free(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx]);
1678 free(subsDetails->ricAction_ToBeSetup_List.list.array);
1683 free(ricSubscriptionReq->protocolIEs.list.array[idx]);
1685 free(ricSubscriptionReq->protocolIEs.list.array);
1689 /*******************************************************************
1691 * @brief Free Event Trigger Definition
1695 * Function : freeAperDecodingOfEventTriggerDef
1697 * Functionality: Free Event Trigger Definition
1699 * @params[in] E2SM-KPM Event Trigger Definition
1702 * ****************************************************************/
1703 void freeAperDecodingOfEventTriggerDef(E2SM_KPM_EventTriggerDefinition_t *eventTiggerDef)
1707 switch(eventTiggerDef->eventDefinition_formats.present)
1709 case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING:
1712 case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_eventDefinition_Format1:
1713 free(eventTiggerDef->eventDefinition_formats.choice.eventDefinition_Format1);
1719 /*******************************************************************
1721 * @brief Extract E2SM-KPM Event trigger definition
1725 * Function : extractEventTriggerDef
1727 * Functionality : This function :
1728 * - Decodes E2SM-KPM Event Trigger Definition
1729 * - Validates that even trigger style is supported by E2 node
1730 * - Stores event trigger details in local DB
1732 * @params[in] RAN Function Database structure
1733 * RIC Subscription Info to be added to RAN function
1734 * RIC Event Trigger Definition buffer received from RIC
1735 * @return ROK - success
1738 ******************************************************************/
1739 uint8_t extractEventTriggerDef(RanFunction *ranFuncDb, RicSubscription *ricSubscriptionInfo, RICeventTriggerDefinition_t *ricEventTriggerDef)
1741 uint8_t ret = RFAILED;
1742 uint8_t eventIdx = 0;
1743 asn_dec_rval_t rval ={0};
1744 E2SM_KPM_EventTriggerDefinition_t eventTiggerDef, *eventTiggerDefPtr = NULLP;
1746 /* Decoding E2SM-KPM Even Trigger Definition */
1747 eventTiggerDefPtr = &eventTiggerDef;
1748 memset(eventTiggerDefPtr, 0, sizeof(E2SM_KPM_EventTriggerDefinition_t));
1750 rval = aper_decode(0, &asn_DEF_E2SM_KPM_EventTriggerDefinition, (void **)&eventTiggerDefPtr, ricEventTriggerDef->buf,\
1751 ricEventTriggerDef->size, 0, 0);
1752 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
1754 DU_LOG("\nERROR --> E2AP : ASN decode failed for E2SM-KPM Event Trigger Definition");
1758 xer_fprint(stdout, &asn_DEF_E2SM_KPM_EventTriggerDefinition, eventTiggerDefPtr);
1760 /* Validating the received event trigger definition format */
1761 for(eventIdx = 0; eventIdx < ranFuncDb->numOfEventTriggerStyleSupported; eventIdx++)
1763 if((eventTiggerDefPtr->eventDefinition_formats.present != \
1764 E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING) && \
1765 (eventTiggerDefPtr->eventDefinition_formats.present == ranFuncDb->eventTriggerStyleList[eventIdx].formatType))
1767 ricSubscriptionInfo->eventTriggerDefinition.formatType = ranFuncDb->eventTriggerStyleList[eventIdx].formatType;
1768 ricSubscriptionInfo->eventTriggerDefinition.choice.format1.reportingPeriod = \
1769 eventTiggerDefPtr->eventDefinition_formats.choice.eventDefinition_Format1->reportingPeriod;
1776 /* Free E2SM_KPM_EventTriggerDefinition_t */
1777 freeAperDecodingOfEventTriggerDef(eventTiggerDefPtr);
1781 /*******************************************************************
1783 * @brief Free RIC Action Definition
1787 * Function : freeAperDecodingOfRicActionDefinition
1789 * Functionality: Free RIC Action Definition
1791 * @params[in] E2SM-KPM Action definition
1794 * ****************************************************************/
1795 void freeAperDecodingOfRicActionDefinition(E2SM_KPM_ActionDefinition_t *actionDef)
1797 uint8_t elementIdx = 0;
1798 E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
1799 MeasurementInfoItem_t *measItem = NULLP;
1801 switch(actionDef->actionDefinition_formats.present)
1803 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1:
1805 if(actionDef->actionDefinition_formats.choice.actionDefinition_Format1)
1807 actionFormat1 = actionDef->actionDefinition_formats.choice.actionDefinition_Format1;
1808 if(actionFormat1->measInfoList.list.array)
1810 for(elementIdx = 0; elementIdx < actionFormat1->measInfoList.list.count; elementIdx++)
1812 if(actionFormat1->measInfoList.list.array[elementIdx])
1814 measItem = actionFormat1->measInfoList.list.array[elementIdx];
1815 switch(measItem->measType.present)
1817 case MeasurementType_PR_NOTHING:
1820 case MeasurementType_PR_measName:
1822 free(measItem->measType.choice.measName.buf);
1826 case MeasurementType_PR_measID:
1832 free(actionFormat1->measInfoList.list.array);
1834 free(actionFormat1);
1838 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format2:
1839 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format3:
1840 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format4:
1841 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format5:
1847 /*******************************************************************
1849 * @brief Extract Measurement Info list from action definition
1853 * Function : extractMeasInfoList
1855 * Functionality : This function :
1856 * - Traverses Measurement-to-be-subscribed list
1857 * - Validates that each measurement in Measurement-to-be-subscribed
1858 * list is supported in RAN-Function->Measurement-supported list.
1859 * - If all measurements in an action is supported by RAN function,
1860 * it is added to measurement-subscribed list in local DB
1862 * @params[in] Measurement Info supported list by RAN function
1863 * Measurement Info to be subscribed as requested by RIC
1864 * Measurement Info finally subscribed
1865 * Memory failure indicator
1866 * @return ROK - success
1869 ******************************************************************/
1870 uint8_t extractMeasInfoList(CmLListCp *measInfoSupportedList, MeasurementInfoList_t *measInfoToBeSubscribedList, \
1871 CmLListCp *measInfoSubscribedList, bool *memFailure)
1873 uint8_t elementIdx = 0;
1874 MeasurementInfoForAction *measInfoSupportedDb = NULLP;
1875 MeasurementInfo *measInfoSubscribedDb = NULLP, *measInfoToDel = NULLP;
1876 CmLList *supportedMeasNode = NULLP, *measToAddNode = NULLP, *measToDelNode = NULLP;;
1877 MeasurementInfoItem_t *measItem = NULLP;
1879 /* Validate Measurement list is supported by E2 node.
1881 * Traverse and compare the Measurement-Supported List in E2
1882 * node with Measurement-to-be-subscribed list received from RIC.
1883 * If a match is found, add it to measurement-subscription list.
1885 for(elementIdx = 0; elementIdx < measInfoToBeSubscribedList->list.count; elementIdx++)
1887 measInfoSubscribedDb = NULLP;
1888 measToAddNode = NULLP;
1889 measItem = measInfoToBeSubscribedList->list.array[elementIdx];
1891 CM_LLIST_FIRST_NODE(measInfoSupportedList, supportedMeasNode);
1892 while(supportedMeasNode)
1894 measInfoSupportedDb = (MeasurementInfoForAction*)supportedMeasNode->node;
1895 switch(measItem->measType.present)
1897 case MeasurementType_PR_measName:
1899 if(!strcmp(measInfoSupportedDb->measurementTypeName, (char *)measItem->measType.choice.measName.buf))
1901 DU_ALLOC(measInfoSubscribedDb, sizeof(MeasurementInfo));
1906 case MeasurementType_PR_measID:
1908 if(measInfoSupportedDb->measurementTypeId == measItem->measType.choice.measID)
1910 DU_ALLOC(measInfoSubscribedDb, sizeof(MeasurementInfo));
1917 DU_LOG("\nERROR -> DUAPP: Invalid Measurement-type identifier in \
1918 E2SM-KPM Action Definition Format");
1921 } /* End of switch, for measurement type identifier */
1923 /* If measurement type is supported, add to measurement-subscription list */
1924 if(measInfoSubscribedDb)
1926 measInfoSubscribedDb->measurementTypeId = measInfoSupportedDb->measurementTypeId;
1927 memcpy(measInfoSubscribedDb->measurementTypeName, measInfoSupportedDb->measurementTypeName, \
1928 strlen(measInfoSupportedDb->measurementTypeName));
1930 DU_ALLOC(measToAddNode, sizeof(CmLList));
1933 measToAddNode->node = (PTR) measInfoSubscribedDb;
1934 cmLListAdd2Tail(measInfoSubscribedList, measToAddNode);
1936 /* Break out of while loop if measurement info is found in measurement-supported list */
1941 DU_FREE(measInfoSubscribedDb, sizeof(MeasurementInfo));
1942 measInfoSubscribedDb = NULLP;
1948 supportedMeasNode = supportedMeasNode->next;
1950 } /* End of while for traversing measurement-supported list in a report style */
1952 /* If a measurement-to-be-subscribed is not found in measurement-supported list in this report style
1954 * Delete all entries from measurement-subscription list and
1955 * Break out of for loop to search in next report style */
1956 if(!measInfoSubscribedDb)
1958 while(measInfoSubscribedList->count)
1960 measToDelNode = cmLListDelFrm(measInfoSubscribedList, measInfoSubscribedList->first);
1961 measInfoToDel = (MeasurementInfo*)measToDelNode->node;
1962 DU_FREE(measInfoToDel, sizeof(MeasurementInfo));
1963 DU_FREE(measToDelNode, sizeof(CmLList));
1968 } /* End of for loop , traversing measurement-to-be-subscribed list */
1970 /* If all measurement-to-be-subscribed was found in measurement-supported list and
1971 * was added to measurement-subscription list successfully, return from here */
1972 if(measInfoToBeSubscribedList->list.count == measInfoSubscribedList->count)
1978 /*******************************************************************
1980 * @brief Extract E2SM-KPM Action definition
1984 * Function : extractRicActionDef
1986 * Functionality : This function :
1987 * - Decodes E2SM-KPM Action Definition
1988 * - Validates that action is supported by E2 node
1989 * - Stores action details in local DB
1991 * @params[in] RAN Function Database structure
1992 * RIC subscription's Action definition to be added to
1994 * RIC Action Definition buffer received from RIC
1995 * @return ROK - success
1998 ******************************************************************/
1999 uint8_t extractRicActionDef(RanFunction *ranFuncDb, ActionDefinition *actionDefDb, RICactionDefinition_t *ricActionDef)
2001 bool memFailure = false;
2002 uint8_t styleIdx = 0;
2003 asn_dec_rval_t rval ={0};
2005 E2SM_KPM_ActionDefinition_t actionDef, *actionDefPtr = NULLP;
2006 E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
2007 CmLListCp *measInfoSupportedList = NULLP;
2008 CmLListCp *measInfoSubscribedList = NULLP;
2010 /* Decoding E2SM-KPM Action Definition */
2011 actionDefPtr = &actionDef;
2012 memset(actionDefPtr, 0, sizeof(E2SM_KPM_EventTriggerDefinition_t));
2014 rval = aper_decode(0, &asn_DEF_E2SM_KPM_ActionDefinition, (void **)&actionDefPtr, ricActionDef->buf,\
2015 ricActionDef->size, 0, 0);
2016 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
2018 DU_LOG("\nERROR --> E2AP : ASN decode failed for E2SM-KPM Action Definition");
2022 xer_fprint(stdout, &asn_DEF_E2SM_KPM_ActionDefinition, actionDefPtr);
2025 /* Validate if Report style to subscribe is supported by E2 Node */
2026 for(styleIdx= 0; styleIdx < ranFuncDb->numOfReportStyleSupported; styleIdx++)
2028 /* Validate Report style type and report style format type is supported by E2 Node */
2029 if((ranFuncDb->reportStyleList[styleIdx].reportStyle.styleType == actionDefPtr->ric_Style_Type) &&
2030 (ranFuncDb->reportStyleList[styleIdx].reportStyle.formatType == actionDefPtr->actionDefinition_formats.present))
2032 /* Fetch Report stype type and format type */
2033 actionDefDb->styleType = actionDefPtr->ric_Style_Type;
2034 actionDefDb->formatType = actionDefPtr->actionDefinition_formats.present;
2036 switch(actionDefPtr->actionDefinition_formats.present)
2038 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1:
2040 actionFormat1 = actionDefPtr->actionDefinition_formats.choice.actionDefinition_Format1;
2042 /* Fetch granularity period */
2043 actionDefDb->choice.format1.granularityPeriod = actionFormat1->granulPeriod;
2045 /* Validate and add the Measurement to subscription list */
2046 measInfoSupportedList = &ranFuncDb->reportStyleList[styleIdx].measurementInfoList;
2047 measInfoSubscribedList = &actionDefDb->choice.format1.measurementInfoList;
2048 if(extractMeasInfoList(measInfoSupportedList, &actionFormat1->measInfoList, \
2049 measInfoSubscribedList, &memFailure) == ROK)
2053 /* Free E2SM_KPM_ActionDefinition_t */
2054 freeAperDecodingOfRicActionDefinition(actionDefPtr);
2059 break; /* End of E2SM-KPM Action definition format 1 case */
2064 DU_LOG("\nERROR -> DUAPP: Only E2SM-KPM Action Definition Format 1 is supported");
2067 } /* End of switch for E2SM-KPM Action definition formats */
2072 } /* End of for loop, traversing Report-styles-supported list in E2 node */
2074 /* Memset action Db and Free E2SM_KPM_ActionDefinition_t */
2075 memset(actionDefDb, 0, sizeof(ActionDefinition));
2076 freeAperDecodingOfRicActionDefinition(actionDefPtr);
2080 /*******************************************************************
2082 * @brief Extract RIC Action to be setup
2086 * Function : extractRicActionToBeSetup
2088 * Functionality : This function :
2089 * - Validates that each action-to-be-setup is supported by E2 node
2090 * - Stores event trigger details in local DB
2092 * @params[in] RAN Function Database structure
2093 * RIC Subscription Info to be added to RAN function
2094 * RIC Action To Be Setup List received from RIC
2095 * @return ROK - success
2098 ******************************************************************/
2099 uint8_t extractRicActionToBeSetup(RanFunction *ranFuncDb, RicSubscription *ricSubscriptionInfo, RICactions_ToBeSetup_List_t *actionList)
2101 uint8_t actionIdx = 0;
2102 uint8_t ricActionId = 0;
2103 RICaction_ToBeSetup_ItemIEs_t *actionItem = NULLP;
2105 if(actionList->list.array)
2107 for(actionIdx = 0; actionIdx < actionList->list.count; actionIdx++)
2109 actionItem =(RICaction_ToBeSetup_ItemIEs_t *)actionList->list.array[actionIdx];
2110 switch(actionItem->id)
2112 case ProtocolIE_IDE2_id_RICaction_ToBeSetup_Item:
2114 /* If Action type is REPORT and
2115 * If RIC action definition's extraction and validation passes,
2117 * This action is added to action sequence list of subscription info */
2118 if(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionType == RICactionType_report)
2120 ricActionId = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID;
2121 ricSubscriptionInfo->actionSequence[ricActionId-1].id = ricActionId;
2122 ricSubscriptionInfo->actionSequence[ricActionId-1].type = REPORT;
2124 if(extractRicActionDef(ranFuncDb, &ricSubscriptionInfo->actionSequence[ricActionId-1].definition, \
2125 actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition) == ROK)
2127 ricSubscriptionInfo->actionSequence[ricActionId-1].action = CONFIG_ADD;
2128 ricSubscriptionInfo->numOfActions++;
2132 memset(&ricSubscriptionInfo->actionSequence[ricActionId-1], 0, sizeof(ActionInfo));
2133 /* TODO : Since this action addition failed, add to
2134 * reject-action-list in subscription response */
2140 DU_LOG("\nERROR --> E2AP : Invalid IE received in RicSetupLst:%ld",actionItem->id);
2146 /* If there is even 1 action that can be added, return ROK */
2147 if(ricSubscriptionInfo->numOfActions)
2153 /******************************************************************
2155 * @brief Processes RIC Subscription Req sent by RIC
2159 * Function : procRicSubsReq
2161 * Functionality: Processes E2 Setup Response sent by CU
2163 * @params[in] E2AP_PDU_t ASN decoded E2AP message
2164 * @return ROK - success
2167 * ****************************************************************/
2169 uint8_t procRicSubsReq(E2AP_PDU_t *e2apMsg)
2173 uint16_t ranFuncId = 0;
2174 CmLList *ricSubscriptionNode = NULLP;
2175 RanFunction *ranFuncDb = NULLP;
2176 RICsubscriptionRequest_t *ricSubsReq = NULLP;
2177 RICsubscriptionDetails_t *subsDetails = NULLP;
2178 RicSubscription *ricSubscriptionInfo = NULLP;
2180 DU_LOG("\nINFO --> E2AP : RIC Subscription request received");
2181 ricSubsReq = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
2183 for(idx=0; idx<ricSubsReq->protocolIEs.list.count; idx++)
2185 if(ricSubsReq->protocolIEs.list.array[idx])
2187 switch(ricSubsReq->protocolIEs.list.array[idx]->id)
2189 case ProtocolIE_IDE2_id_RICrequestID:
2191 DU_ALLOC(ricSubscriptionInfo, sizeof(RicSubscription));
2192 if(!ricSubscriptionInfo)
2194 DU_LOG("\nERROR --> E2AP : Memory allocation failed for ricSubscriptionInfo");
2198 ricSubscriptionInfo->requestId.requestorId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID;
2199 ricSubscriptionInfo->requestId.instanceId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID;
2204 case ProtocolIE_IDE2_id_RANfunctionID:
2206 ranFuncId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RANfunctionID;
2208 /* Validating RAN Function id */
2209 if(duCb.e2apDb.ranFunction[ranFuncId-1].id == ranFuncId)
2211 ranFuncDb = &duCb.e2apDb.ranFunction[ranFuncId-1];
2215 /* TODO : Send RAN Subcription Failure */
2221 case ProtocolIE_IDE2_id_RICsubscriptionDetails:
2223 subsDetails = &ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails;
2225 /* Decode, Validate and record Event Trigger Definition */
2226 if(extractEventTriggerDef(ranFuncDb, ricSubscriptionInfo, &subsDetails->ricEventTriggerDefinition) != ROK)
2228 /* TODO : Send RAN Subcription Failure */
2233 /* Decode, Validate and record RIC actions */
2234 if(extractRicActionToBeSetup(ranFuncDb, ricSubscriptionInfo, &subsDetails->ricAction_ToBeSetup_List) != ROK)
2236 /* TODO : Send RAN Subcription Failure */
2244 DU_LOG("\nERROR --> E2AP : Invalid IE received in RIC SubsReq:%ld",
2245 ricSubsReq->protocolIEs.list.array[idx]->id);
2254 freeAperDecodingOfRicSubsReq(ricSubsReq);
2258 /* Add RAN subcription detail to RAN function */
2259 DU_ALLOC(ricSubscriptionNode, sizeof(CmLList));
2260 if(ricSubscriptionNode)
2262 ricSubscriptionNode->node = (PTR) ricSubscriptionInfo;
2263 cmLListAdd2Tail(&ranFuncDb->subscriptionList, ricSubscriptionNode);
2266 #ifdef KPI_CALCULATION
2267 /* Send statistics request to other DU entities */
2268 BuildAndSendStatsReq(ranFuncId, ricSubscriptionInfo);
2271 /* TODO : Trigger RIC subscription response once statistics response is
2272 * received from MAC .
2273 * TBD in next gerrit */
2274 ret = BuildAndSendRicSubscriptionRsp();
2276 BuildAndSendRicIndication(ricSubscriptionInfo);
2283 /*******************************************************************
2285 * @brief Free the RicIndication Message
2289 * Function : FreeRicIndication
2291 * Functionality: Free the RicIndication Message
2296 ******************************************************************/
2297 void FreeRicIndication(E2AP_PDU_t *e2apMsg)
2300 RICindication_t *ricIndicationMsg= NULLP;
2302 if(e2apMsg != NULLP)
2304 if(e2apMsg->choice.initiatingMessage != NULLP)
2306 ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
2307 if(ricIndicationMsg!= NULLP)
2309 if(ricIndicationMsg->protocolIEs.list.array != NULLP)
2311 for(idx=0; idx<ricIndicationMsg->protocolIEs.list.count; idx++)
2313 if(ricIndicationMsg->protocolIEs.list.array[idx] != NULLP)
2315 switch(ricIndicationMsg->protocolIEs.list.array[idx]->id)
2317 case ProtocolIE_IDE2_id_RICrequestID:
2320 case ProtocolIE_IDE2_id_RANfunctionID:
2323 case ProtocolIE_IDE2_id_RICactionID:
2326 case ProtocolIE_IDE2_id_RICindicationType:
2329 case ProtocolIE_IDE2_id_RICindicationHeader:
2331 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf,\
2332 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
2335 case ProtocolIE_IDE2_id_RICindicationMessage:
2337 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf,\
2338 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
2344 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx],sizeof(RICindication_IEs_t));
2347 DU_FREE(ricIndicationMsg->protocolIEs.list.array,ricIndicationMsg->protocolIEs.list.size);
2350 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2352 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2356 /*******************************************************************
2358 * brief Fill the RicIndication Message
2362 * Function : FillRicIndication
2364 * Functionality:Fills the RicIndication Message
2366 * @return ROK - success
2369 ******************************************************************/
2370 uint8_t FillRicIndication(RICindication_t *ricIndicationMsg, RicSubscription *ricSubscriptionInfo)
2372 uint8_t elementCnt=0;
2377 ricIndicationMsg->protocolIEs.list.count = elementCnt;
2378 ricIndicationMsg->protocolIEs.list.size = elementCnt * sizeof(RICindication_t);
2379 /* Initialize the Ric Indication members */
2380 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array, \
2381 ricIndicationMsg->protocolIEs.list.size);
2382 if(ricIndicationMsg->protocolIEs.list.array == NULLP)
2384 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
2389 for(idx=0; idx<elementCnt; idx++)
2391 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx],\
2392 sizeof(RICindication_IEs_t));
2393 if(ricIndicationMsg->protocolIEs.list.array[idx] == NULLP)
2395 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
2403 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
2404 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2405 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2406 RICindication_IEs__value_PR_RICrequestID;
2407 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID =ricSubscriptionInfo->requestId.requestorId;
2408 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID = ricSubscriptionInfo->requestId.instanceId;
2411 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
2412 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2413 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2414 RICindication_IEs__value_PR_RANfunctionID;
2415 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RANfunctionID = duCb.e2apDb.ranFunction[0].id;
2418 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactionID;
2419 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2420 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2421 RICindication_IEs__value_PR_RICactionID;
2422 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICactionID = ricSubscriptionInfo->actionSequence[0].id;
2425 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationType;
2426 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2427 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2428 RICindication_IEs__value_PR_RICindicationType;
2429 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationType = ricSubscriptionInfo->actionSequence[0].type;
2432 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationHeader;
2433 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2434 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2435 RICindication_IEs__value_PR_RICindicationHeader;
2436 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size = 3 *
2438 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf ,\
2439 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
2440 if(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf == NULLP)
2442 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
2447 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
2448 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf);
2450 /* TO BE CHANGED: RIC INDICATION DATA */
2451 /* For now filling a dummy octect data, need to tested with PRBs*/
2452 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationMessage;
2453 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
2454 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
2455 RICindication_IEs__value_PR_RICindicationMessage;
2456 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size = 3 *
2458 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf ,\
2459 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
2460 if(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf == NULLP)
2462 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
2467 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
2468 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf);
2476 /*******************************************************************
2478 * @brief Builds and Send the RicIndication Message
2482 * Function : BuildAndSendRicIndication
2484 * Functionality:Fills the RicIndication Message
2486 * @return ROK - success
2489 ******************************************************************/
2491 uint8_t BuildAndSendRicIndication(RicSubscription *ricSubscriptionInfo)
2493 E2AP_PDU_t *e2apMsg = NULLP;
2494 RICindication_t *ricIndicationMsg=NULLP;
2495 asn_enc_rval_t encRetVal; /* Encoder return value */
2496 uint8_t ret = RFAILED;
2497 uint8_t FillRicIndicationret = ROK;
2501 DU_LOG("\nINFO --> E2AP : Building RIC Indication Message\n");
2503 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2504 if(e2apMsg == NULLP)
2506 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2510 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2511 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2512 if(e2apMsg->choice.initiatingMessage == NULLP)
2514 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2517 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICindication;
2518 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2519 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICindication;
2521 ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
2523 FillRicIndicationret = FillRicIndication(ricIndicationMsg, ricSubscriptionInfo);
2524 if(FillRicIndicationret != ROK)
2528 /* Prints the Msg formed */
2529 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2530 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2532 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
2534 if(encRetVal.encoded == ENCODE_FAIL)
2536 DU_LOG("\nERROR --> E2AP : Could not encode RIC Indication Message (at %s)\n",\
2537 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2542 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Indication Message \n");
2543 #ifdef DEBUG_ASN_PRINT
2544 for(int i=0; i< encBufSize; i++)
2546 printf("%x",encBuf[i]);
2551 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
2553 DU_LOG("\nINFO --> E2AP : Sending RIC Indication Message");
2559 FreeRicIndication(e2apMsg);
2563 /*******************************************************************
2565 * @brief Deallocate the memory allocated for E2nodeConfigurationUpdate msg
2569 * Function : FreeE2NodeConfigUpdate
2572 * - freeing the memory allocated for E2nodeConfigurationUpdate
2574 * @params[in] E2AP_PDU_t *e2apMsg
2575 * @return ROK - success
2578 * ****************************************************************/
2579 void FreeE2NodeConfigUpdate(E2AP_PDU_t *e2apMsg)
2582 E2nodeConfigurationUpdate_t *e2NodeConfigUpdate;
2584 if(e2apMsg != NULLP)
2586 if(e2apMsg->choice.initiatingMessage != NULLP)
2588 e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
2589 if(e2NodeConfigUpdate->protocolIEs.list.array != NULLP)
2591 for(arrIdx = 0; arrIdx < e2NodeConfigUpdate->protocolIEs.list.count; arrIdx++)
2593 DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
2595 DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size);
2597 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2599 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2603 /*******************************************************************
2605 * @brief Buld and send the E2 node config update msg
2609 * Function : BuildAndSendE2NodeConfigUpdate
2612 * - Buld and send the E2 node config update msg
2615 * @return ROK - success
2618 * ****************************************************************/
2620 uint8_t BuildAndSendE2NodeConfigUpdate()
2622 uint8_t arrIdx = 0,elementCnt = 1;
2624 E2AP_PDU_t *e2apMsg = NULLP;
2625 E2nodeConfigurationUpdate_t *e2NodeConfigUpdate = NULLP;
2626 asn_enc_rval_t encRetVal; /* Encoder return value */
2628 DU_LOG("\nINFO --> E2AP : Building E2 Node config update\n");
2631 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2632 if(e2apMsg == NULLP)
2634 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2637 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2638 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2639 if(e2apMsg->choice.initiatingMessage == NULLP)
2641 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2642 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2645 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2646 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
2647 e2apMsg->choice.initiatingMessage->value.present = \
2648 InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate;
2649 e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
2651 e2NodeConfigUpdate->protocolIEs.list.count = elementCnt;
2652 e2NodeConfigUpdate->protocolIEs.list.size = elementCnt * sizeof(E2nodeConfigurationUpdate_IEs_t*);
2653 /* Initialize the Ric Indication members */
2654 DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array, \
2655 e2NodeConfigUpdate->protocolIEs.list.size);
2656 if(e2NodeConfigUpdate->protocolIEs.list.array == NULLP)
2658 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
2662 for(arrIdx =0; arrIdx<elementCnt; arrIdx++)
2664 DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
2665 if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx] == NULLP)
2668 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
2675 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2676 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2677 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_TransactionID;
2678 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = TRANS_ID;
2681 /* Prints the Msg formed */
2682 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2684 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2686 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
2688 if(encRetVal.encoded == ENCODE_FAIL)
2690 DU_LOG("\nERROR --> E2AP : Could not encode E2nodeConfigurationUpdate structure (at %s)\n",\
2691 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2696 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2nodeConfigurationUpdate\n");
2697 #ifdef DEBUG_ASN_PRINT
2698 for(int i=0; i< encBufSize; i++)
2700 printf("%x",encBuf[i]);
2704 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize))
2706 DU_LOG("\nERROR --> E2AP : Sending E2 node config update failed");
2713 FreeE2NodeConfigUpdate(e2apMsg);
2717 /*******************************************************************
2719 * @brief Deallocate the memory allocated for E2ResetRequest msg
2723 * Function : FreeE2ResetRequest
2726 * - freeing the memory allocated for E2ResetRequest
2728 * @params[in] E2AP_PDU_t *e2apMsg
2729 * @return ROK - success
2732 * ****************************************************************/
2733 void FreeE2ResetRequest(E2AP_PDU_t *e2apMsg)
2736 ResetRequestE2_t *resetReq = NULLP;
2738 if(e2apMsg != NULLP)
2740 if(e2apMsg->choice.initiatingMessage != NULLP)
2742 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
2743 if(resetReq->protocolIEs.list.array)
2745 for(ieIdx = 0; ieIdx < resetReq->protocolIEs.list.count; ieIdx++)
2747 DU_FREE(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
2749 DU_FREE(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
2751 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2753 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2757 /*******************************************************************
2759 * @brief Build and send the E2 reset request msg
2763 * Function : BuildAndSendE2ResetRequest
2766 * - Buld and send the E2 reset request msg to RIC
2769 * @return ROK - success
2772 * ****************************************************************/
2773 uint8_t BuildAndSendE2ResetRequest(E2CauseType failureType, E2Cause failureCause)
2775 uint8_t ieIdx = 0, elementCnt = 0, transId = 0;
2776 uint8_t ret = RFAILED;
2777 E2AP_PDU_t *e2apMsg = NULLP;
2778 ResetRequestE2_t *resetReq = NULLP;
2779 asn_enc_rval_t encRetVal; /* Encoder return value */
2781 DU_LOG("\nINFO --> E2AP : Building E2 Reset Request\n");
2785 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2786 if(e2apMsg == NULLP)
2788 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation for E2AP-PDU failed");
2792 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2793 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2794 if(e2apMsg->choice.initiatingMessage == NULLP)
2796 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation for initiatingMessage");
2800 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_Reset;
2801 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2802 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ResetRequestE2;
2803 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
2806 resetReq->protocolIEs.list.count = elementCnt;
2807 resetReq->protocolIEs.list.size = elementCnt * sizeof(ResetRequestIEs_t *);
2809 DU_ALLOC(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
2810 if(!resetReq->protocolIEs.list.array)
2812 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
2813 Reset Request IE array");
2817 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
2819 DU_ALLOC(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
2820 if(!resetReq->protocolIEs.list.array[ieIdx])
2822 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
2823 Reset Request IE array element");
2828 /* In case of failure */
2829 if(ieIdx < elementCnt)
2833 resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2834 resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
2835 resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_TransactionID;
2836 transId = assignTransactionId();
2837 resetReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
2840 resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_CauseE2;
2841 resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_ignore;
2842 resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_CauseE2;
2843 resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.present = failureType;
2844 switch(resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.present)
2846 case CauseE2_PR_NOTHING:
2848 case CauseE2_PR_ricRequest:
2849 resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.ricRequest = failureCause;
2851 case CauseE2_PR_ricService:
2852 resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.ricService = failureCause;
2854 case CauseE2_PR_e2Node:
2855 resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.e2Node = failureCause;
2857 case CauseE2_PR_transport:
2858 resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.transport = failureCause;
2860 case CauseE2_PR_protocol:
2861 resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.protocol = failureCause;
2863 case CauseE2_PR_misc:
2864 resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.misc = failureCause;
2868 /* Prints the Msg formed */
2869 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2871 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2873 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
2875 if(encRetVal.encoded == ENCODE_FAIL)
2877 DU_LOG("\nERROR --> E2AP : Could not encode E2SetupRequest structure (at %s)\n",\
2878 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2883 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupRequest\n");
2884 #ifdef DEBUG_ASN_PRINT
2885 for(int i=0; i< encBufSize; i++)
2887 printf("%x",encBuf[i]);
2891 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
2893 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
2897 /* In case the message is sent successfully, store the transaction info to
2898 * be used when response is received */
2899 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
2900 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
2906 /* Free all memory */
2907 FreeE2ResetRequest(e2apMsg);
2911 /*******************************************************************
2913 * @brief Deallocate the memory allocated for Reset Response msg
2917 * Function : freeAperDecodingOfE2ResetRsp
2920 * - freeing the memory allocated for Reset response
2922 * @params[in] ResetResponseE2_t *resetResponse
2925 * ****************************************************************/
2926 void freeAperDecodingOfE2ResetRsp(ResetResponseE2_t *resetResponse)
2932 if(resetResponse->protocolIEs.list.array)
2934 for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
2936 if(resetResponse->protocolIEs.list.array[ieIdx])
2938 switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
2940 case ProtocolIE_IDE2_id_TransactionID:
2943 case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
2946 free(resetResponse->protocolIEs.list.array[ieIdx]);
2949 free(resetResponse->protocolIEs.list.array);
2954 /******************************************************************
2956 * @brief Processes E2 Reset Response sent by RIC
2960 * Function : procResetResponse
2962 * Functionality: Processes E2 Reset Response sent by RIC
2964 * @params[in] E2AP_PDU_t ASN decoded E2AP message
2965 * @return ROK - success
2968 * ****************************************************************/
2969 uint8_t procResetResponse(E2AP_PDU_t *e2apMsg)
2971 uint8_t ieIdx =0, transId;
2972 ResetResponseE2_t *resetResponse;
2974 DU_LOG("\nINFO --> E2AP : E2 Reset Response received");
2975 resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;;
2977 for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
2979 switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
2981 case ProtocolIE_IDE2_id_TransactionID:
2982 transId = resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
2983 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) && \
2984 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
2986 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
2990 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
2994 case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
2995 /* As per ORAN WG3 E2AP spec v3.0, section 9.2.2
2996 Criticality Diagnostics IE is sent by Near-RT RIC when parts of a received message i.e.
2997 Reset Request in this case, have not been comprehended or were missing, or if the message
2998 contained logical errors.
3000 Processing of this ID should be implemented when negative call flows are to be supported.
3004 DU_LOG("\nERROR --> E2AP : Invalid IE received in E2 Reset Response : %ld",
3005 resetResponse->protocolIEs.list.array[ieIdx]->id);
3010 freeAperDecodingOfE2ResetRsp(resetResponse);
3014 /******************************************************************
3016 * @brief Deallocation of memory allocated bu aper decoder for e2 setup Failure
3020 * Function : freeAperDecodingOfE2SetupFailure
3022 * Functionality: Deallocation of memory allocated bu aper decoder for e2
3025 * @params[in] E2setupFailure_t *e2SetupFailure;
3028 * ****************************************************************/
3029 void freeAperDecodingOfE2SetupFailure(E2setupFailure_t *e2SetupFailure)
3035 if(e2SetupFailure->protocolIEs.list.array)
3037 for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
3039 if(e2SetupFailure->protocolIEs.list.array[arrIdx])
3041 free(e2SetupFailure->protocolIEs.list.array[arrIdx]);
3044 free(e2SetupFailure->protocolIEs.list.array);
3048 /******************************************************************
3050 * @brief Processes E2 Setup Failure sent by RIC
3054 * Function : procE2SetupFailure
3056 * Functionality: Processes E2 Setup failure sent by RIC
3058 * @params[in] E2AP_PDU_t ASN decoded E2AP message
3059 * @return ROK - success
3062 * ****************************************************************/
3063 void procE2SetupFailure(E2AP_PDU_t *e2apMsg)
3065 uint8_t arrIdx =0, transId =0, timerValue=0;
3066 E2setupFailure_t *e2SetupFailure;
3068 DU_LOG("\nINFO --> E2AP : E2 Setup failure received");
3069 e2SetupFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure;
3071 for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
3073 switch(e2SetupFailure->protocolIEs.list.array[arrIdx]->id)
3075 case ProtocolIE_IDE2_id_TransactionID:
3077 transId = e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
3078 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
3079 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
3081 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
3085 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
3090 case ProtocolIE_IDE2_id_TimeToWaitE2:
3092 timerValue = covertE2WaitTimerEnumToValue(e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
3093 if((duChkTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.e2SetupTimer), EVENT_E2_SETUP_TMR)) == FALSE)
3095 duStartTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.e2SetupTimer), EVENT_E2_SETUP_TMR, timerValue);
3099 DU_LOG("\nERROR --> E2AP : EVENT_E2_SETUP_TMR timer is already running");
3107 freeAperDecodingOfE2SetupFailure(e2SetupFailure);
3109 /******************************************************************
3111 * @brief Deallocation of memory allocated bu aper decoder for RIC service Query
3115 * Function : freeAperDecodingOfRicServiceQuery
3117 * Functionality: Deallocation of memory allocated bu aper decoder for RIC
3120 * @params[in] RICserviceQuery_t *ricServiceQuery;
3123 * ****************************************************************/
3125 void freeAperDecodingOfRicServiceQuery(RICserviceQuery_t *ricServiceQuery)
3127 uint8_t arrIdx,ranFuncIdx;
3128 RANfunctionsID_List_t *ranFuncAddedList;
3132 if(ricServiceQuery->protocolIEs.list.array)
3134 for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
3136 if(ricServiceQuery->protocolIEs.list.array[arrIdx])
3138 switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
3140 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
3142 ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
3143 if(ranFuncAddedList->list.array)
3145 for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
3147 free(ranFuncAddedList->list.array[ranFuncIdx]);
3149 free(ranFuncAddedList->list.array);;
3156 free(ricServiceQuery->protocolIEs.list.array[arrIdx]);
3159 free(ricServiceQuery->protocolIEs.list.array);
3163 /*******************************************************************
3165 * @brief Build RanFunction Delete List
3169 * Function : BuildRanFunctionDeleteList
3171 * Functionality: Build RanFunction Delete List
3174 * RANfunctionsID List
3175 * Count of the RAN function
3176 * Received RAN function list
3178 * @return ROK - success
3181 ******************************************************************/
3183 uint8_t BuildRanFunctionDeleteList(RANfunctionsID_List_t *deleteList, uint8_t count, RanFuncInfo *recvdRanFunc)
3185 uint8_t ranFuncIdx=0;
3186 RANfunctionID_ItemIEs_t *delRanFuncItem;
3190 deleteList->list.count = count;
3191 deleteList->list.size = deleteList->list.count * sizeof(RANfunctionID_ItemIEs_t*);
3192 DU_ALLOC(deleteList->list.array, deleteList->list.size);
3193 if(deleteList->list.array == NULLP)
3195 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
3198 for(ranFuncIdx = 0; ranFuncIdx< deleteList->list.count; ranFuncIdx++)
3200 DU_ALLOC(deleteList->list.array[ranFuncIdx], sizeof(RANfunctionID_ItemIEs_t));
3201 if(deleteList->list.array[ranFuncIdx] == NULLP)
3203 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
3206 delRanFuncItem= (RANfunctionID_ItemIEs_t *) deleteList->list.array[ranFuncIdx];
3207 delRanFuncItem->id = ProtocolIE_IDE2_id_RANfunctionID_Item;
3208 delRanFuncItem->criticality = CriticalityE2_ignore;
3209 delRanFuncItem->value.choice.RANfunctionID_Item.ranFunctionID = recvdRanFunc[ranFuncIdx].id;
3210 delRanFuncItem->value.choice.RANfunctionID_Item.ranFunctionRevision = recvdRanFunc[ranFuncIdx].revisionCounter;
3216 /*******************************************************************
3218 * @brief De Allocate Ric Service Update message
3222 * Function : FreeRicServiceUpdate
3224 * Functionality: De-Allocating Ric Service Update message
3226 * @params[in] E2AP_PDU_t *e2apMsg
3230 * ****************************************************************/
3232 void FreeRicServiceUpdate(E2AP_PDU_t *e2apMsg)
3235 uint8_t ranFuncAddListIdx=0, ranFuncDelIdx=0;
3236 RICserviceUpdate_t *ricServiceUpdate;
3237 RANfunctions_List_t *ranFunctionsList;
3238 RANfunction_ItemIEs_t *ranFuncItemIe;
3239 RANfunction_Item_t *ranFunItem;
3240 RANfunctionsID_List_t *deleteList;
3242 /* De-allocating Memory */
3243 if(e2apMsg != NULLP)
3245 if(e2apMsg->choice.initiatingMessage != NULLP)
3247 ricServiceUpdate = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate;
3248 if(ricServiceUpdate->protocolIEs.list.array != NULLP)
3250 for(arrIdx = 0; arrIdx < ricServiceUpdate->protocolIEs.list.count; arrIdx++)
3252 if(ricServiceUpdate->protocolIEs.list.array[arrIdx] != NULLP)
3254 switch(ricServiceUpdate->protocolIEs.list.array[arrIdx]->id)
3256 case ProtocolIE_IDE2_id_TransactionID:
3259 case ProtocolIE_IDE2_id_RANfunctionsAdded:
3260 case ProtocolIE_IDE2_id_RANfunctionsModified:
3262 ranFunctionsList = &(ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List);
3263 if(ranFunctionsList->list.array)
3265 for(ranFuncAddListIdx= 0; ranFuncAddListIdx< ranFunctionsList->list.count; ranFuncAddListIdx++)
3267 if(ranFunctionsList->list.array[ranFuncAddListIdx])
3269 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncAddListIdx];
3270 ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
3271 DU_FREE(ranFunItem->ranFunctionOID.buf, ranFunItem->ranFunctionOID.size);
3272 DU_FREE(ranFunItem->ranFunctionDefinition.buf, ranFunItem->ranFunctionDefinition.size);
3273 DU_FREE(ranFunctionsList->list.array[ranFuncAddListIdx], sizeof(RANfunction_ItemIEs_t));
3276 DU_FREE(ranFunctionsList->list.array, ranFunctionsList->list.size);
3280 case ProtocolIE_IDE2_id_RANfunctionsDeleted:
3282 deleteList= &ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
3283 if(deleteList->list.array)
3285 for(ranFuncDelIdx = 0; ranFuncDelIdx< deleteList->list.count; ranFuncDelIdx++)
3287 DU_FREE(deleteList->list.array[ranFuncDelIdx], sizeof(RANfunctionID_ItemIEs_t));
3289 DU_FREE(deleteList->list.array, deleteList->list.size);
3295 DU_LOG("\nERROR --> E2AP: Invalid event at ricServiceUpdate %ld ",\
3296 (ricServiceUpdate->protocolIEs.list.array[arrIdx]->id));
3299 DU_FREE(ricServiceUpdate->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdate_IEs_t));
3302 DU_FREE(ricServiceUpdate->protocolIEs.list.array, ricServiceUpdate->protocolIEs.list.size);
3304 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
3306 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
3310 /*******************************************************************
3312 * @brief Builds and Send the RicServiceUpdateuest
3316 * Function : BuildAndSendRicServiceUpdate
3318 * Functionality:Fills the RicServiceUpdateuest
3320 * @return ROK - success
3323 ******************************************************************/
3325 uint8_t BuildAndSendRicServiceUpdate(RicServiceUpdate serviceUpdate)
3327 uint8_t arrIdx = 0, elementCnt=0;
3328 uint8_t transId = 0, ret = RFAILED;
3329 bool memAllocFailed =false;
3330 E2AP_PDU_t *e2apMsg = NULLP;
3331 RICserviceUpdate_t *ricServiceUpdate = NULLP;
3332 asn_enc_rval_t encRetVal; /* Encoder return value */
3334 DU_LOG("\nINFO --> E2AP : Building Ric Service Update\n");
3337 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
3338 if(e2apMsg == NULLP)
3340 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
3343 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
3344 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
3345 if(e2apMsg->choice.initiatingMessage == NULLP)
3347 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
3350 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
3351 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICserviceUpdate;
3352 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICserviceUpdate;
3353 ricServiceUpdate = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate;
3355 /* For TransId IE, set elementCnt to 1.
3356 If there is any item in the RAN function add list, RAN function modification list, or RAN function delete list, increment the elementCnt.*/
3359 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
3361 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeModified)
3363 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted)
3366 ricServiceUpdate->protocolIEs.list.count = elementCnt;
3367 ricServiceUpdate->protocolIEs.list.size = elementCnt * sizeof(RICserviceUpdate_IEs_t*);
3369 /* Initialize the E2Setup members */
3370 DU_ALLOC(ricServiceUpdate->protocolIEs.list.array, ricServiceUpdate->protocolIEs.list.size);
3371 if(ricServiceUpdate->protocolIEs.list.array == NULLP)
3373 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements");
3377 for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
3379 DU_ALLOC(ricServiceUpdate->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdate_IEs_t));
3380 if(ricServiceUpdate->protocolIEs.list.array[arrIdx] == NULLP)
3382 memAllocFailed = true;
3383 DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayIdx [%d]", arrIdx);
3387 if(memAllocFailed == true)
3393 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
3394 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3395 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
3396 if(serviceUpdate.dir == E2_NODE_INITIATED)
3397 transId = assignTransactionId();
3399 transId = serviceUpdate.transId;
3400 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
3402 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
3405 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
3406 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3407 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
3408 if(BuildRanFunctionAddList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List,\
3409 e2apMsg->choice.initiatingMessage->procedureCode, serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded, serviceUpdate.recvRanFuncList.ranFunToBeAdded) !=ROK)
3415 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeModified)
3418 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsModified;
3419 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3420 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
3421 if(BuildRanFunctionAddList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List,
3422 e2apMsg->choice.initiatingMessage->procedureCode, serviceUpdate.recvRanFuncList.numOfRanFunToBeModified, serviceUpdate.recvRanFuncList.ranFunToBeModified) !=ROK)
3428 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted)
3431 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsDeleted;
3432 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3433 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctionsID_List;
3434 if(BuildRanFunctionDeleteList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List,\
3435 serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted, serviceUpdate.recvRanFuncList.ranFunToBeDeleted) != ROK)
3440 /* Prints the Msg formed */
3441 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3443 memset(encBuf, 0, ENC_BUF_MAX_LEN);
3445 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
3446 if(encRetVal.encoded == ENCODE_FAIL)
3448 DU_LOG("\nERROR --> E2AP : Could not encode RicServiceUpdateuest structure (at %s)\n",\
3449 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3454 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RicServiceUpdateuest\n");
3455 #ifdef DEBUG_ASN_PRINT
3456 for(int i=0; i< encBufSize; i++)
3458 printf("%x",encBuf[i]);
3462 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
3464 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
3473 if(serviceUpdate.dir == E2_NODE_INITIATED)
3475 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
3476 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
3480 duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].transactionId = transId;
3481 duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
3483 duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.dir = serviceUpdate.dir;
3484 duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.transId =transId;
3486 FreeRicServiceUpdate(e2apMsg);
3489 /******************************************************************
3491 * @brief Processes RIC service Query sent by RIC
3495 * Function : procRicServiceQuery
3497 * Functionality: Processes RIC service Query sent by RIC
3499 * @params[in] E2AP_PDU_t ASN decoded E2AP message
3500 * @return ROK - success
3503 * ****************************************************************/
3505 void procRicServiceQuery(E2AP_PDU_t *e2apMsg)
3508 uint16_t arrIdx =0, ranFuncIdx=0,tmpIdx=0;
3509 uint16_t id,revisionCcounter;
3510 bool tmpArray[MAX_RAN_FUNCTION] = {false};
3511 RICserviceQuery_t *ricServiceQuery=NULL;
3512 RicServiceUpdate ricUpdate;
3513 RANfunctionID_ItemIEs_t *ranFuncAddedItemIe;
3514 RANfunctionsID_List_t *ranFuncAddedList;
3516 DU_LOG("\nINFO --> E2AP : RIC Service Query received");
3517 memset(&ricUpdate, 0, sizeof(RicServiceUpdate));
3518 ricUpdate.dir = RIC_INITIATED;
3519 ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
3521 for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
3523 switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
3525 /* TODO completing in next patch/gerrit */
3526 case ProtocolIE_IDE2_id_TransactionID:
3528 ricUpdate.transId = ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
3532 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
3534 ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
3535 if(ranFuncAddedList->list.array)
3537 for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
3539 if(ranFuncAddedList->list.array[ranFuncIdx])
3541 /* Using the RAN function Id, identify the RAN function to be modified or deleted. */
3543 ranFuncAddedItemIe = (RANfunctionID_ItemIEs_t*)ranFuncAddedList->list.array[ranFuncIdx];
3544 id = ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionID;
3545 revisionCcounter = ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionRevision;
3547 if((id != duCb.e2apDb.ranFunction[id-1].id))
3549 action = CONFIG_DEL;
3551 else if((id == duCb.e2apDb.ranFunction[id-1].id)&&(revisionCcounter!=duCb.e2apDb.ranFunction[id-1].revisionCounter))
3553 action = CONFIG_MOD;
3556 if(action == CONFIG_DEL)
3558 ricUpdate.recvRanFuncList.ranFunToBeDeleted[ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted].id = id;
3559 ricUpdate.recvRanFuncList.ranFunToBeDeleted[ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted].revisionCounter = revisionCcounter;
3560 ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted++;
3562 else if(action == CONFIG_MOD)
3564 ricUpdate.recvRanFuncList.ranFunToBeModified[ricUpdate.recvRanFuncList.numOfRanFunToBeModified].id = id;
3565 ricUpdate.recvRanFuncList.ranFunToBeModified[ricUpdate.recvRanFuncList.numOfRanFunToBeModified].revisionCounter = revisionCcounter;
3566 ricUpdate.recvRanFuncList.numOfRanFunToBeModified++;
3569 /* If any ID is set to true, it means that the ID has been used in either modification or deletion list.
3570 * Else we will add the IDs into the added list */
3571 tmpArray[id-1] = true;
3580 /* Traversing the whole RAN function list in ducb to check if any new Ran function ids have been added. */
3581 for(arrIdx =0; arrIdx<MAX_RAN_FUNCTION; arrIdx++)
3583 tmpIdx= ricUpdate.recvRanFuncList.numOfRanFunToBeAdded;
3584 if((duCb.e2apDb.ranFunction[arrIdx].id >0)&&(!tmpArray[arrIdx]))
3586 ricUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].id = duCb.e2apDb.ranFunction[arrIdx].id;
3587 ricUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].revisionCounter = duCb.e2apDb.ranFunction[arrIdx].revisionCounter;
3588 ricUpdate.recvRanFuncList.numOfRanFunToBeAdded++;
3592 if(BuildAndSendRicServiceUpdate(ricUpdate)!= ROK)
3594 DU_LOG("\nERROR --> E2AP : Failed to build and send ric service update message");
3597 freeAperDecodingOfRicServiceQuery(ricServiceQuery);
3601 /*******************************************************************
3603 * @brief Handles received E2AP message and sends back response
3607 * Function : E2APMsgHdlr
3610 * - Decodes received E2AP control message
3611 * - Prepares response message, encodes and sends to SCTP
3614 * @return ROK - success
3617 * ****************************************************************/
3618 void E2APMsgHdlr(Buffer *mBuf)
3621 char *recvBuf = NULLP;
3623 MsgLen recvBufLen =0;
3624 E2AP_PDU_t *e2apMsg = NULLP;
3625 asn_dec_rval_t rval ={0}; /* Decoder return value */
3626 E2AP_PDU_t e2apasnmsg={0} ;
3628 DU_LOG("\nDEBUG --> E2AP : Received E2AP message buffer");
3629 ODU_PRINT_MSG(mBuf, 0,0);
3631 /* Copy mBuf into char array to decode it */
3632 ODU_GET_MSG_LEN(mBuf, &recvBufLen);
3633 DU_ALLOC(recvBuf, (Size)recvBufLen);
3635 if(recvBuf == NULLP)
3637 DU_LOG("\nERROR --> E2AP : Memory allocation failed");
3640 if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
3642 DU_LOG("\nERROR --> E2AP : Failed while copying %d", copyCnt);
3646 #ifdef DEBUG_ASN_PRINT
3647 printf("\nDEBUG --> E2AP : Received flat buffer to be decoded : ");
3648 for(i=0; i< recvBufLen; i++)
3650 printf("%x",recvBuf[i]);
3654 /* Decoding flat buffer into E2AP messsage */
3655 e2apMsg = &e2apasnmsg;
3656 memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
3658 rval = aper_decode(0, &asn_DEF_E2AP_PDU, (void **)&e2apMsg, recvBuf, recvBufLen, 0, 0);
3659 DU_FREE(recvBuf, (Size)recvBufLen);
3661 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
3663 DU_LOG("\nERROR --> E2AP : ASN decode failed");
3667 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3669 switch(e2apMsg->present)
3671 case E2AP_PDU_PR_unsuccessfulOutcome:
3673 switch(e2apMsg->choice.unsuccessfulOutcome->value.present)
3675 case UnsuccessfulOutcomeE2__value_PR_E2setupFailure:
3677 procE2SetupFailure(e2apMsg);
3682 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_unsuccessfulOutcome [%d]",\
3683 e2apMsg->choice.unsuccessfulOutcome->value.present);
3689 case E2AP_PDU_PR_successfulOutcome:
3691 switch(e2apMsg->choice.successfulOutcome->value.present)
3693 case SuccessfulOutcomeE2__value_PR_E2setupResponse:
3697 procE2SetupRsp(e2apMsg);
3701 case SuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateAcknowledge:
3703 DU_LOG("\nDEBUG --> E2AP : E2 node Config update ack message recevied");
3706 case SuccessfulOutcomeE2__value_PR_ResetResponseE2:
3708 procResetResponse(e2apMsg);
3713 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_successfulOutcome [%d]",\
3714 e2apMsg->choice.successfulOutcome->value.present);
3717 }/* End of switch(successfulOutcome) */
3718 free(e2apMsg->choice.successfulOutcome);
3722 case E2AP_PDU_PR_initiatingMessage:
3724 switch(e2apMsg->choice.initiatingMessage->value.present)
3726 case InitiatingMessageE2__value_PR_RICsubscriptionRequest:
3728 procRicSubsReq(e2apMsg);
3731 case InitiatingMessageE2__value_PR_RICserviceQuery:
3733 procRicServiceQuery(e2apMsg);
3738 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\
3739 e2apMsg->choice.initiatingMessage->value.present);
3742 }/* End of switch(initiatingMessage) */
3743 free(e2apMsg->choice.initiatingMessage);
3748 DU_LOG("\nERROR --> E2AP : Invalid type of e2apMsg->present [%d]",e2apMsg->present);
3753 }/* End of switch(e2apMsg->present) */
3755 } /* End of E2APMsgHdlr */
3757 /**********************************************************************
3759 **********************************************************************/