[Epic-ID: ODUHIGH-516][Task-ID: 526] Fixing the memory issue
[o-du/l2.git] / src / du_app / du_e2ap_msg_hdl.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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"
19 #include "du_tmr.h"
20 #include "lrg.h"
21 #include "lkw.x"
22 #include "lrg.x"
23 #include "legtp.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"
28 #include "du_cfg.h"
29 #include "du_mgr.h"
30 #include "du_mgr_main.h"
31 #include "du_utils.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"
38 #include "E2AP-PDU.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
49 /*******************************************************************
50  *
51  * @brief Builds Global gNodeB Params
52  *
53  * @details
54  *
55  *    Function : BuildGlobalgNBId
56  *
57  *    Functionality: Building the Plmn and gNB id
58  *
59  * @params[in] GlobalE2node_gNB_ID_t *gNbId
60  * @return ROK     - success
61  *         RFAILED - failure
62  *
63  ******************************************************************/
64
65 uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
66 {
67    uint8_t unused = 0;
68    uint8_t byteSize = 4;
69    uint8_t gnbId = duCb.gnbId;
70    uint8_t ret = ROK;
71
72    /* fill Global gNB ID Id */
73    gNbId->global_gNB_ID.plmn_id.size = 3 * sizeof(uint8_t);
74    gNbId->global_gNB_ID.plmn_id.buf = NULLP;
75    DU_ALLOC(gNbId->global_gNB_ID.plmn_id.buf , gNbId->global_gNB_ID.plmn_id.size);
76    if(gNbId->global_gNB_ID.plmn_id.buf == NULLP)
77    {
78       DU_LOG("\nERROR  -->  E2AP: Memory allocation failed for Plmn buffer");
79       ret = RFAILED;
80    }
81    else
82    {
83       buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
84             gNbId->global_gNB_ID.plmn_id.buf);
85       gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
86       /* Allocate Buffer size */
87       gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = byteSize * sizeof(uint8_t);
88       gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf = NULLP;
89       DU_ALLOC(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf, \
90             gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
91       if(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf == NULLP)
92       {
93          DU_LOG("\nERROR  -->  E2AP: Memory allocation failed for gnb buffer");
94          ret = RFAILED;
95       }
96       else
97       {
98          fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, gnbId);
99       }
100    }
101
102    /* fill gNB-DU ID */ 
103    DU_ALLOC( gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
104    if(gNbId->gNB_DU_ID == NULLP)
105    {
106       DU_LOG("\nERROR  -->  E2AP: Memory allocation failed for gNB_DU_ID ");
107       ret = RFAILED;
108    }
109    else
110    {
111       gNbId->gNB_DU_ID->size = sizeof(uint8_t);
112       DU_ALLOC( gNbId->gNB_DU_ID->buf, sizeof(uint8_t));
113       if(gNbId->gNB_DU_ID->buf)
114       {
115          gNbId->gNB_DU_ID->buf[0] =duCb.e2apDb.e2NodeId;
116       }
117       else
118       {
119          DU_LOG("\nERROR  -->  E2AP: Memory allocation failed for gNB_DU_ID buffer");
120          ret = RFAILED;
121       }
122    }
123
124    return ret;
125 }
126
127 /******************************************************************
128  *
129  * @brief Search E2 node component with the help of action type
130  *
131  * @details
132  *
133  *    Function : searchE2NodeComponentInfo 
134  *
135  *    Functionality: Search E2 node component with the help of action type 
136  *
137  * @params[in] uint8_t componentActionType
138  * @return CmLList
139  *
140  * ****************************************************************/
141
142 CmLList *searchE2NodeComponentInfo(InterfaceType interfaceType, uint8_t componentActionType)
143 {
144    E2NodeComponent *e2NodeComponentInfo;
145    CmLList         *node;
146
147    if(duCb.e2apDb.e2NodeComponentList.count)
148    {
149       CM_LLIST_FIRST_NODE(&duCb.e2apDb.e2NodeComponentList, node);
150       while(node)
151       {
152          e2NodeComponentInfo = (E2NodeComponent*)node->node;
153          if((e2NodeComponentInfo->interfaceType == interfaceType) && (e2NodeComponentInfo->componentActionType == componentActionType))
154             break;
155          else
156             node = node->next;
157       }
158    }
159    return node; 
160 }
161
162 /*******************************************************************
163  *
164  * @brief Builds E2 node config addition list 
165  *
166  * @details
167  *
168  *    Function : BuildE2NodeConfigAddList
169  *
170  *    Functionality: Building E2 node config addition list
171  *
172  * @params[in] E2nodeComponentConfigAddition_List_t *e2NodeAddList 
173  * @return ROK     - success
174  *         RFAILED - failure
175  *
176  ******************************************************************/
177
178 uint8_t BuildE2NodeConfigAddList(E2nodeComponentConfigAddition_List_t *e2NodeAddList)
179 {
180    uint8_t arrIdx = 0;
181    CmLList         *node;
182    E2NodeComponent *e2NodeComponentInfo;
183    E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItemIe;
184    E2nodeComponentConfigAddition_Item_t *e2NodeAddItem;
185
186    e2NodeAddList->list.count = 1;
187    e2NodeAddList->list.size = e2NodeAddList->list.count * sizeof(E2nodeComponentConfigAddition_ItemIEs_t *);
188    DU_ALLOC(e2NodeAddList->list.array, e2NodeAddList->list.size);
189    if(e2NodeAddList->list.array == NULLP)
190    {
191        DU_LOG("\nERROR  --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
192        return RFAILED;
193    }
194
195    for(arrIdx = 0; arrIdx< e2NodeAddList->list.count; arrIdx++)
196    {
197       DU_ALLOC(e2NodeAddList->list.array[arrIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
198       if(e2NodeAddList->list.array[arrIdx] == NULLP)
199       {
200          DU_LOG("\nERROR  --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
201          return RFAILED;
202       }
203    }
204    
205    node = searchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD);
206    if(!node)
207    {
208       DU_LOG("\nERROR  --> E2AP : Received e2NodeComponentInfo is null");
209       return RFAILED;
210    }
211    e2NodeComponentInfo = (E2NodeComponent*)node->node;
212    
213    arrIdx = 0;
214    e2NodeAddItemIe = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[arrIdx];
215    e2NodeAddItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition_Item;
216    e2NodeAddItemIe->criticality = CriticalityE2_reject;
217    e2NodeAddItemIe->value.present = E2nodeComponentConfigAddition_ItemIEs__value_PR_E2nodeComponentConfigAddition_Item;
218    e2NodeAddItem = &e2NodeAddItemIe->value.choice.E2nodeComponentConfigAddition_Item;
219    
220    /* E2nodeComponentInterfaceType */
221    e2NodeAddItem->e2nodeComponentInterfaceType = E2nodeComponentInterfaceType_f1;
222
223    /* E2 Node Component Request Part */
224    if(e2NodeComponentInfo->componentRequestPart)
225    {
226       e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size = e2NodeComponentInfo->reqBufSize ;
227       DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
228             e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
229       if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf == NULLP)
230       {
231          DU_LOG("\nERROR  --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
232          return RFAILED;
233       }
234
235       memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
236             e2NodeComponentInfo->componentRequestPart, e2NodeAddItem->e2nodeComponentConfiguration.\
237             e2nodeComponentRequestPart.size);
238    }
239    else
240    {
241       DU_LOG("\nERROR  --> E2AP: componentRequestPart is null ");
242       return RFAILED;
243    }
244
245
246    /* E2 Node Component Response Part */
247    if(e2NodeComponentInfo->componentResponsePart)
248    {
249       e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size = e2NodeComponentInfo->rspBufSize; 
250       DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \
251             e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
252       if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf == NULLP)
253       {
254          DU_LOG("\nERROR  --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
255          return RFAILED;
256       }
257       memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \
258             e2NodeComponentInfo->componentResponsePart, e2NodeAddItem->e2nodeComponentConfiguration.\
259             e2nodeComponentResponsePart.size);
260    }
261    else
262    {
263       DU_LOG("\nERROR  --> E2AP: componentResponsePart is null");
264       return RFAILED;
265    }
266    
267    /* E2 Node Component ID */
268    e2NodeAddItem->e2nodeComponentID.present = E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1;
269    DU_ALLOC(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
270    sizeof(E2nodeComponentInterfaceF1_t));
271    if(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1 == NULLP)
272    {
273        DU_LOG("\nERROR  --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
274        return RFAILED;
275    }
276    e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size = sizeof(uint8_t);
277    DU_ALLOC(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
278    e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
279
280    if(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf == NULLP)
281    {
282       DU_LOG("\nERROR  -->list.  E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
283       return RFAILED;
284    }
285    e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[arrIdx]  = e2NodeComponentInfo->componentId;
286    return ROK;
287
288 }
289
290 /*******************************************************************
291  *
292  * @brief deallocation of E2SM_KPM_RANfunction_Description_t
293  *
294  * @details
295  *
296  *    Function : freeE2smKpmRanFunctionDefinition
297  *
298  *    Functionality: deallocation of E2SM_KPM_RANfunction_Description_t
299  *
300  * @params[in]  E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition
301  * @return void
302  *
303  ******************************************************************/
304
305 void freeE2smKpmRanFunctionDefinition(E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition)
306 {
307    MeasurementInfo_Action_Item_t *measInfoList;
308    uint8_t eventTriggerIdx, reportStyleIdx, measInfoIdx;
309    RANfunction_Name_t *ranFuncName;
310    struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle;
311    struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *eventTriggerStyle;
312    if(ranFunctionDefinition)
313    {
314       ranFuncName = &ranFunctionDefinition->ranFunction_Name;
315       /* Free RAN function Name */     
316       DU_FREE(ranFuncName->ranFunction_ShortName.buf,  ranFuncName->ranFunction_ShortName.size);
317       DU_FREE(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
318       DU_FREE(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
319
320       /* Sequence of Event Trigger styles */
321       eventTriggerStyle = ranFunctionDefinition->ric_EventTriggerStyle_List;
322       if(eventTriggerStyle)
323       {
324          if(eventTriggerStyle->list.array)
325          {
326             for(eventTriggerIdx =0;eventTriggerIdx<eventTriggerStyle->list.count; eventTriggerIdx++)
327             {
328                if(eventTriggerStyle->list.array[eventTriggerIdx])
329                {
330                   DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.buf,\
331                         eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.size);
332                   DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
333                }
334             }
335             DU_FREE(eventTriggerStyle->list.array, eventTriggerStyle->list.size)
336          }
337          DU_FREE(eventTriggerStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
338       }
339       
340       /* Sequence of Report styles */
341       ricReportStyle = ranFunctionDefinition->ric_ReportStyle_List;
342       if(ricReportStyle)
343       {
344          if(ricReportStyle->list.array)
345          {
346             for(reportStyleIdx =0;reportStyleIdx<ricReportStyle->list.count; reportStyleIdx++)
347             {
348                if(ricReportStyle->list.array[reportStyleIdx])
349                {
350                   if(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf)
351                   {
352                      DU_FREE(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf,\
353                            ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.size);
354                   }
355                   if(ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array)
356                   {
357                      for(measInfoIdx=0; measInfoIdx<ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.count; \
358                            measInfoIdx++)
359                      {
360                         measInfoList = ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array[measInfoIdx];
361                         if(measInfoList)
362                         {
363                            DU_FREE(measInfoList->measID, sizeof(long));
364                            DU_FREE(measInfoList->measName.buf, measInfoList->measName.size);
365                            DU_FREE(measInfoList,sizeof(MeasurementInfo_Action_Item_t)); 
366                         }
367                      }
368                      DU_FREE(measInfoList,ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.size);
369                   }
370                   DU_FREE(ricReportStyle->list.array[reportStyleIdx], sizeof(RIC_ReportStyle_Item_t));
371                }
372             }
373             DU_FREE(ricReportStyle->list.array, ricReportStyle->list.size);
374          }
375          DU_FREE(ricReportStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
376       }
377       DU_FREE(ranFunctionDefinition, sizeof(E2SM_KPM_RANfunction_Description_t)); 
378    }
379 }
380
381 /*******************************************************************
382  *
383  * @brief fill the e2sm ric report style
384  *
385  * @details
386  *
387  *    Function : fillRicReportStyle
388  *
389  *    Functionality: fill the report style
390  *
391  * @params[in]   RanFunction *ranFuncDb, struct
392  * E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle
393  * @return ROK     - success
394  *         RFAILED - failure
395  *
396  ******************************************************************/
397 uint8_t fillRicReportStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle)
398 {
399    uint8_t styleIdx, measInfoIdx;
400    MeasurementInfo_Action_List_t *measInfo;
401    CmLList  *node;
402    
403    ricReportStyle->list.count = ranFuncDb->numOfReportStyleSupported;
404    ricReportStyle->list.size = ricReportStyle->list.count * sizeof(RIC_ReportStyle_Item_t*);
405    DU_ALLOC(ricReportStyle->list.array, ricReportStyle->list.size);
406    if(!ricReportStyle->list.array)
407    {
408       DU_LOG("\nERROR  --> E2AP: Memory allocation failed for ranFuncDefinition %d",__LINE__);
409       return RFAILED;
410    }
411
412    for(styleIdx =0;styleIdx<ricReportStyle->list.count; styleIdx++)
413    {
414       DU_ALLOC(ricReportStyle->list.array[styleIdx], sizeof(RIC_ReportStyle_Item_t));
415       if(!ricReportStyle->list.array[styleIdx])
416       {
417          DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
418          return RFAILED;
419       }
420       
421       /* RIC Report Style Type */
422       ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.styleType;
423       
424       /* RIC Report Style Format Type */
425       ricReportStyle->list.array[styleIdx]->ric_ActionFormat_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.formatType;
426       
427       /* RIC Report Style Name */
428       ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size = strlen(ranFuncDb->reportStyleList[styleIdx].reportStyle.name);
429       DU_ALLOC(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf,\
430             ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
431       if(!ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf)
432       {
433          DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
434          return RFAILED;
435       }
436       memcpy(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf, ranFuncDb->reportStyleList[styleIdx].reportStyle.name,\
437             ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
438
439       /* RIC Indication Header Format Type*/
440       ricReportStyle->list.array[styleIdx]->ric_IndicationHeaderFormat_Type = ranFuncDb->ricIndicationHeaderFormat;
441
442       /* RIC Indication Message Format Type*/
443       ricReportStyle->list.array[styleIdx]->ric_IndicationMessageFormat_Type = ranFuncDb->ricIndicationMessageFormat;
444       
445       /* Measurement Info Action List */
446       CmLListCp measInfoList =ranFuncDb->reportStyleList[styleIdx].measurementInfoList;
447       if(!measInfoList.count)
448       {
449          continue;      
450       }
451
452       CM_LLIST_FIRST_NODE(&ranFuncDb->reportStyleList[styleIdx].measurementInfoList, node);
453       measInfo = &ricReportStyle->list.array[styleIdx]->measInfo_Action_List;
454
455       measInfo->list.count = measInfoList.count; 
456       measInfo->list.size =  measInfoList.count*sizeof(MeasurementInfo_Action_Item_t*);
457       DU_ALLOC(measInfo->list.array, measInfo->list.size);
458       if(!measInfo->list.array)
459       {
460          DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
461          return RFAILED;
462       }
463
464       for(measInfoIdx=0; measInfoIdx<measInfo->list.count; measInfoIdx++)
465       {
466          if(!node)
467          {
468             DU_LOG("\nERROR  --> E2AP: Measurement info node is null");
469             return RFAILED;
470          }
471
472          DU_ALLOC(measInfo->list.array[measInfoIdx],sizeof(MeasurementInfo_Action_Item_t));  
473          if(!measInfo->list.array[measInfoIdx])
474          {
475             DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
476             return RFAILED;
477          }
478          MeasurementInfoForAction *measInfoForAction= (MeasurementInfoForAction*)node->node;
479          DU_ALLOC(measInfo->list.array[measInfoIdx]->measID, sizeof(long));
480          if(!measInfo->list.array[measInfoIdx]->measID)
481          {
482             DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
483             return RFAILED;
484          }
485          
486          memcpy(measInfo->list.array[measInfoIdx]->measID, &measInfoForAction->measurementTypeId,sizeof(long));
487          measInfo->list.array[measInfoIdx]->measName.size= strlen(measInfoForAction->measurementTypeName);
488          DU_ALLOC(measInfo->list.array[measInfoIdx]->measName.buf, measInfo->list.array[measInfoIdx]->measName.size);
489          if(!measInfo->list.array[measInfoIdx]->measName.size)
490          {
491             DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
492             return RFAILED;
493          }
494
495          memcpy(measInfo->list.array[measInfoIdx]->measName.buf, \
496                measInfoForAction->measurementTypeName,\
497                measInfo->list.array[measInfoIdx]->measName.size);
498          node = node->next;
499       }
500
501    }
502    return ROK;
503 }
504 /*******************************************************************
505  *
506  * @brief fill the ric event trigger style
507  *
508  * @details
509  *
510  *    Function : fillRicEventTriggerStyle
511  *
512  *    Functionality: fill the ric event trigger style
513  *
514  * @params[in]   
515  * @return ROK     - success
516  *         RFAILED - failure
517  *
518  ******************************************************************/
519 uint8_t fillRicEventTriggerStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *ricEventTriggerStyle)
520 {
521    uint8_t styleIdx;
522
523    ricEventTriggerStyle->list.count = ranFuncDb->numOfEventTriggerStyleSupported;
524    ricEventTriggerStyle->list.size = ricEventTriggerStyle->list.count*  sizeof(RIC_EventTriggerStyle_Item_t *);
525    DU_ALLOC(ricEventTriggerStyle->list.array, ricEventTriggerStyle->list.size);
526    if(!ricEventTriggerStyle->list.array)
527    {
528       DU_LOG("\nERROR  --> E2AP: Memory allocation failed for ric_EventTriggerStyle_List %d",__LINE__);
529       return RFAILED;
530    }
531
532    for(styleIdx =0;styleIdx<ricEventTriggerStyle->list.count; styleIdx++)
533    {
534       DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
535       if(!ricEventTriggerStyle->list.array[styleIdx])
536       {
537          DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
538          return RFAILED;
539       }
540       ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Type = ranFuncDb->eventTriggerStyleList[styleIdx].styleType;
541
542       ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerFormat_Type = ranFuncDb->eventTriggerStyleList[styleIdx].formatType;
543
544       ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size = strlen(ranFuncDb->eventTriggerStyleList[styleIdx].name);
545       DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,\
546             ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
547       if(!ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf)
548       {
549          DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
550          return RFAILED;
551       }
552       memcpy(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,ranFuncDb->eventTriggerStyleList[styleIdx].name,\
553             ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
554    
555    }
556    return ROK;
557 }
558
559 /*******************************************************************
560  *
561  * @brief Builds Ran function add list
562  *
563  * @details
564  *
565  *    Function : BuildRanFunctionAddList 
566  *
567  *    Functionality: Building RAN addition addition list
568  *
569  * @params[in]  RANfunctions_List_t *RANfunctions_List 
570  * @return ROK     - success
571  *         RFAILED - failure
572  *
573  ******************************************************************/
574
575 uint8_t BuildRanFunctionAddList(RANfunctions_List_t *ranFunctionsList)
576 {
577    asn_enc_rval_t encRetVal;
578    RanFunction *ranFuncDb;
579    RANfunction_Name_t *ranFuncName;
580    uint8_t ranFuncIdx;
581    RANfunction_ItemIEs_t *ranFuncItemIe;
582    RANfunction_Item_t  *ranFuncItem;
583    E2SM_KPM_RANfunction_Description_t *ranFuncDefinition;
584
585    ranFunctionsList->list.count = duCb.e2apDb.numOfRanFunction;
586    ranFunctionsList->list.size = ranFunctionsList->list.count * sizeof(RANfunction_ItemIEs_t*);
587    DU_ALLOC(ranFunctionsList->list.array, ranFunctionsList->list.size);
588    if(ranFunctionsList->list.array == NULLP)
589    {
590       DU_LOG("\nERROR  --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
591       return RFAILED;
592    }
593
594    for(ranFuncIdx = 0; ranFuncIdx< ranFunctionsList->list.count; ranFuncIdx++)
595    {
596       DU_ALLOC(ranFunctionsList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
597       if(ranFunctionsList->list.array[ranFuncIdx] == NULLP)
598       {
599          DU_LOG("\nERROR  --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
600          return RFAILED;
601       }
602
603       ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncIdx];
604       ranFuncItemIe->id = ProtocolIE_IDE2_id_RANfunction_Item;
605       ranFuncItemIe->criticality = CriticalityE2_ignore;
606       ranFuncItemIe->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
607       ranFuncItem = &ranFuncItemIe->value.choice.RANfunction_Item;
608       ranFuncDb = &duCb.e2apDb.ranFunction[ranFuncIdx];   
609       /* RAN function Id*/
610       ranFuncItem->ranFunctionID = ranFuncDb->id;
611       
612       /* RAN Function Revision*/
613       ranFuncItem->ranFunctionRevision = ranFuncDb->revisionCounter;
614       
615       /* RAN function OID*/
616       ranFuncItem->ranFunctionOID.size = strlen(ranFuncDb->name.serviceModelOID);
617       DU_ALLOC(ranFuncItem->ranFunctionOID.buf, ranFuncItem->ranFunctionOID.size);
618       if(!ranFuncItem->ranFunctionOID.buf)
619       {
620          DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
621          return RFAILED;
622       }
623       memcpy(ranFuncItem->ranFunctionOID.buf, ranFuncDb->name.serviceModelOID, ranFuncItem->ranFunctionOID.size);
624
625       /* RAN function Definition */
626       DU_ALLOC(ranFuncDefinition, sizeof(E2SM_KPM_RANfunction_Description_t));
627       if(!ranFuncDefinition)
628       {
629          DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
630          return RFAILED;
631       }
632       
633       /* RAN function Name */
634       ranFuncName = &ranFuncDefinition->ranFunction_Name;
635       
636       /* RAN function ShortName */
637       ranFuncName->ranFunction_ShortName.size = strlen(ranFuncDb->name.shortName); 
638       DU_ALLOC(ranFuncName->ranFunction_ShortName.buf,  ranFuncName->ranFunction_ShortName.size);
639       if(!ranFuncName->ranFunction_ShortName.buf)
640       {
641          DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
642          return RFAILED;
643       }
644       memcpy(ranFuncName->ranFunction_ShortName.buf, ranFuncDb->name.shortName, strlen(ranFuncDb->name.shortName));
645       
646       /* RAN function E2SM_OID */
647       ranFuncName->ranFunction_E2SM_OID.size = strlen(ranFuncDb->name.serviceModelOID);
648       DU_ALLOC(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
649       if(!ranFuncName->ranFunction_E2SM_OID.buf)
650       {
651          DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
652          return RFAILED;
653       }
654       memcpy(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncDb->name.serviceModelOID, ranFuncName->ranFunction_E2SM_OID.size);
655
656       /* RAN function Description */
657       ranFuncName->ranFunction_Description.size = strlen(ranFuncDb->name.description);
658       DU_ALLOC(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
659       if(!ranFuncName->ranFunction_Description.buf)
660       {
661          DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
662          return RFAILED;
663       }
664       memcpy(ranFuncName->ranFunction_Description.buf, ranFuncDb->name.description, ranFuncName->ranFunction_Description.size);
665       
666       /* RIC Event Trigger Style List */
667       DU_ALLOC(ranFuncDefinition->ric_EventTriggerStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
668       if(!ranFuncDefinition->ric_EventTriggerStyle_List)
669       {
670          DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
671          return RFAILED;
672       }
673       
674       if(fillRicEventTriggerStyle(ranFuncDb, ranFuncDefinition->ric_EventTriggerStyle_List)!=ROK)
675       {
676          DU_LOG("\nERROR  --> E2AP: failed to fill ric event trigger style");
677          return RFAILED;
678       }
679
680       /* RIC Report Style List */
681       DU_ALLOC(ranFuncDefinition->ric_ReportStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
682       if(!ranFuncDefinition->ric_ReportStyle_List)
683       {
684          DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
685          return RFAILED;
686       }
687       if(fillRicReportStyle(ranFuncDb, ranFuncDefinition->ric_ReportStyle_List) != ROK)
688       {
689          DU_LOG("\nERROR  --> E2AP: failed to fill ric report style");
690          return RFAILED;
691       }
692
693       /* Encode the F1SetupRequest type as APER */
694       xer_fprint(stdout, &asn_DEF_E2SM_KPM_RANfunction_Description, ranFuncDefinition);
695
696       memset(encBuf, 0, ENC_BUF_MAX_LEN);
697       encBufSize = 0;
698       encRetVal = aper_encode(&asn_DEF_E2SM_KPM_RANfunction_Description, 0, ranFuncDefinition, PrepFinalEncBuf, encBuf);
699
700       /* Encode results */
701       if(encRetVal.encoded == ENCODE_FAIL)
702       {
703          DU_LOG("\nERROR  -->  F1AP : Could not encode RAN function definition  (at %s)\n",\
704                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
705          break;
706       }
707       else
708       {
709          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RAN function definition \n");
710          for(uint8_t measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
711          {
712             printf("%x",encBuf[measIeIdx]);
713          }
714
715       }
716       ranFuncItem->ranFunctionDefinition.size = encBufSize;
717       DU_ALLOC(ranFuncItem->ranFunctionDefinition.buf, encBufSize);
718       if(ranFuncItem->ranFunctionDefinition.buf == NULLP)
719       {
720          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed for RAN function definition buffer");
721          return RFAILED;
722       }
723       memcpy(ranFuncItem->ranFunctionDefinition.buf, &encBuf, encBufSize);
724    }
725    freeE2smKpmRanFunctionDefinition(ranFuncDefinition);
726    return ROK;
727 }
728
729 /*******************************************************************
730  *
731  * @brief De Allocate E2 Setup Request Message
732  *
733  * @details
734  *
735  *    Function : FreeE2SetupReq
736  *
737  *    Functionality: De-Allocating E2 Setup request Message
738  *
739  * @params[in] E2AP_PDU_t *e2apMsg
740  
741  * @return void
742  *
743  * ****************************************************************/
744
745 void FreeE2SetupReq(E2AP_PDU_t *e2apMsg)
746 {
747    uint8_t arrIdx = 0;
748    uint8_t e2NodeAddListIdx =0, ranFuncAddListIdx;
749    E2setupRequest_t *e2SetupReq;
750    E2nodeComponentConfigAddition_List_t *e2NodeAddList;
751    E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem;
752    RANfunctions_List_t *ranFunctionsList;
753    RANfunction_ItemIEs_t *ranFuncItemIe;
754    RANfunction_Item_t  *ranFunItem;
755
756    /* De-allocating Memory */
757    if(e2apMsg != NULLP)
758    {
759       if(e2apMsg->choice.initiatingMessage != NULLP)
760       {
761          e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest; 
762          if(e2SetupReq->protocolIEs.list.array != NULLP)
763          {
764             for(arrIdx = 0; arrIdx < e2SetupReq->protocolIEs.list.count; arrIdx++)
765             {
766                if(e2SetupReq->protocolIEs.list.array[arrIdx] != NULLP)
767                {
768                   switch(e2SetupReq->protocolIEs.list.array[arrIdx]->id)
769                   {
770                      case ProtocolIE_IDE2_id_TransactionID:
771                           break;
772                      case ProtocolIE_IDE2_id_GlobalE2node_ID:
773                         {
774                            if(e2SetupReq->protocolIEs.list.array[arrIdx]->\
775                                  value.choice.GlobalE2node_ID.choice.gNB != NULLP)
776                            {
777                               GlobalE2node_gNB_ID_t *gNbId = NULLP;
778                               gNbId = e2SetupReq->protocolIEs.list.array[arrIdx]->\
779                                       value.choice.GlobalE2node_ID.choice.gNB;
780                               if(gNbId->global_gNB_ID.plmn_id.buf != NULLP)
781                               {
782                                  DU_FREE(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf,\
783                                        gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
784                                  DU_FREE(gNbId->global_gNB_ID.plmn_id.buf,\
785                                        gNbId->global_gNB_ID.plmn_id.size);
786                               }
787
788                               if(gNbId->gNB_DU_ID != NULLP)
789                               {
790                                  DU_FREE( gNbId->gNB_DU_ID->buf, gNbId->gNB_DU_ID->size);
791                                  DU_FREE(gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
792                               }
793                               DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
794                                     choice.GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
795                            }
796                            break;
797                         }
798                      case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
799                      {
800                          e2NodeAddList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List;
801                          if(e2NodeAddList->list.array)
802                          {
803                              for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++)
804                              {
805                                 e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[e2NodeAddListIdx];
806                                 
807                                 /* Free E2 Node Component Request Part */
808                                 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
809                                       e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
810                                 
811                                 /* Free E2 Node Component Response Part */
812                                 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.\
813                                       e2nodeComponentResponsePart.buf, \
814                                       e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
815                                  
816                                  /* Free E2 Node Component ID */
817                                 if(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1)
818                                 {
819                                     DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
820                                     e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
821                                     e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
822                                     e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
823                                     DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
824                                     sizeof(E2nodeComponentInterfaceF1_t));
825                                 }
826                                 DU_FREE(e2NodeAddList->list.array[e2NodeAddListIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
827                              }
828                              DU_FREE(e2NodeAddList->list.array, e2NodeAddList->list.size);
829                          }
830                          break;
831                      }
832                      case ProtocolIE_IDE2_id_RANfunctionsAdded:
833                      {
834                         ranFunctionsList = &(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List);  
835                         if(ranFunctionsList->list.array)
836                         {  
837                            for(ranFuncAddListIdx= 0; ranFuncAddListIdx< ranFunctionsList->list.count; ranFuncAddListIdx++)
838                            {
839                               if(ranFunctionsList->list.array[ranFuncAddListIdx])
840                               {
841                                  ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncAddListIdx];
842                                  ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
843                                  DU_FREE(ranFunItem->ranFunctionOID.buf, ranFunItem->ranFunctionOID.size);
844                                  DU_FREE(ranFunItem->ranFunctionDefinition.buf, ranFunItem->ranFunctionDefinition.size);
845                                  DU_FREE(ranFunctionsList->list.array[ranFuncAddListIdx], sizeof(RANfunction_ItemIEs_t));
846                               }
847                            }
848                            DU_FREE(ranFunctionsList->list.array, ranFunctionsList->list.size);
849                         }
850                         break;
851                      }
852
853                      default:
854                         DU_LOG("\nERROR  --> E2AP: Invalid event at e2SetupRequet %ld ",\
855                               (e2SetupReq->protocolIEs.list.array[arrIdx]->id));
856                         break;
857                   }
858                   DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx], sizeof(E2setupRequestIEs_t));
859                }
860             }
861             DU_FREE(e2SetupReq->protocolIEs.list.array, e2SetupReq->protocolIEs.list.size);
862          }
863          DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
864       }
865       DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
866    }
867 }
868
869 /*******************************************************************
870  *
871  * @brief Builds and Send the E2SetupRequest
872  *
873  * @details
874  *
875  *    Function : BuildAndSendE2SetupReq
876  *
877  * Functionality:Fills the E2SetupRequest
878  *
879  * @return ROK     - success
880  *         RFAILED - failure
881  *
882  ******************************************************************/
883
884 uint8_t BuildAndSendE2SetupReq()
885 {
886    uint8_t arrIdx = 0, elementCnt=0;
887    uint8_t transId = 0, ret = ROK;
888    bool memAllocFailed;
889    E2AP_PDU_t        *e2apMsg = NULLP;
890    E2setupRequest_t  *e2SetupReq = NULLP;
891    asn_enc_rval_t     encRetVal;       /* Encoder return value */
892
893    DU_LOG("\nINFO   -->  E2AP : Building E2 Setup Request\n");
894    do
895    {
896       DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
897       if(e2apMsg == NULLP)
898       {
899          DU_LOG("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
900          break;
901       }
902       e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
903       DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
904       if(e2apMsg->choice.initiatingMessage == NULLP)
905       {
906          DU_LOG("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
907          break;
908       }
909       e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
910       e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2setup;
911       e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_E2setupRequest;
912       e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
913
914       elementCnt = 4;
915       e2SetupReq->protocolIEs.list.count = elementCnt;
916       e2SetupReq->protocolIEs.list.size = elementCnt * sizeof(E2setupRequestIEs_t*);
917
918       /* Initialize the E2Setup members */
919       DU_ALLOC(e2SetupReq->protocolIEs.list.array, \
920             e2SetupReq->protocolIEs.list.size);
921       if(e2SetupReq->protocolIEs.list.array == NULLP)
922       {
923          DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for array elements");
924          break;
925       }
926       for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
927       {
928          DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx],\
929                sizeof(E2setupRequestIEs_t));
930          if(e2SetupReq->protocolIEs.list.array[arrIdx] == NULLP)
931          {
932             memAllocFailed = true;
933             DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for arrayarrIdx [%d]", arrIdx);
934             break;
935          }
936       }
937       if(memAllocFailed == true)
938          break;
939
940       arrIdx = 0;
941
942       /* TransactionID */
943       e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
944       e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
945       e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
946       transId = assignTransactionId();
947       e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
948
949       arrIdx++;
950       /* GlobalE2node_gNB_ID */
951       e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_GlobalE2node_ID;
952       e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
953       e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
954       e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
955
956       DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
957             GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
958       if(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
959             GlobalE2node_ID.choice.gNB == NULLP)
960       {
961          DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for gNbId");
962          break;
963       }
964       else
965       {
966          ret = BuildGlobalgNBId(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
967                choice.GlobalE2node_ID.choice.gNB);
968          if(ret != ROK)
969          {
970              DU_LOG("\nERROR  -->  E2AP : Failed to build Global Gnb Id");
971              break;
972          }
973       }
974       
975       /* RAN Functions Added List */
976       arrIdx++;
977       e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
978       e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
979       e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_RANfunctions_List;
980       if(BuildRanFunctionAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List))!=ROK)
981       {
982          DU_LOG("\nERROR  -->  E2AP : Failed to create RAN Function");
983          break;
984       }
985
986       /* E2 Node Component Configuration Addition List */
987       arrIdx++;
988       e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition;
989       e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
990       e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_E2nodeComponentConfigAddition_List;
991       if(BuildE2NodeConfigAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List))!=ROK)
992       {
993          DU_LOG("\nERROR  -->  E2AP : Failed to create E2 Node config list");
994          break;
995       }
996
997
998
999       /* Prints the Msg formed */
1000       xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1001
1002       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1003       encBufSize = 0;
1004       encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
1005             encBuf);
1006       if(encRetVal.encoded == ENCODE_FAIL)
1007       {
1008          DU_LOG("\nERROR  -->  E2AP : Could not encode E2SetupRequest structure (at %s)\n",\
1009                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1010          break;
1011       }
1012       else
1013       {
1014          DU_LOG("\nDEBUG   -->  E2AP : Created APER encoded buffer for E2SetupRequest\n");
1015 #ifdef DEBUG_ASN_PRINT
1016          for(int i=0; i< encBufSize; i++)
1017          {
1018             printf("%x",encBuf[i]);
1019          }
1020 #endif
1021       }
1022       if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
1023       {
1024          DU_LOG("\nERROR  -->  E2AP : Sending E2 Setup request failed");
1025       }
1026       break;
1027    }while(true);
1028
1029    duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].transactionId = transId;
1030    duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
1031    
1032    FreeE2SetupReq(e2apMsg);
1033    return ret;
1034 }/* End of BuildAndSendE2SetupReq */
1035
1036 /*******************************************************************
1037  *
1038  * @brief Builds Ric Request Id
1039  *
1040  * @details
1041  *
1042  *    Function : BuildRicRequestId
1043  *
1044  *    Functionality: Building the Ric Request Id
1045  *
1046  * @params[in] RICrequestID_t *ricReqId
1047  * @return ROK     - success
1048  *         RFAILED - failure
1049  *
1050  * ****************************************************************/
1051
1052 uint8_t BuildRicRequestId(RICrequestID_t *ricReqId)
1053 {
1054    if(ricReqId == NULLP)
1055    {
1056       return RFAILED;
1057    }
1058
1059    ricReqId->ricRequestorID = 1;
1060    ricReqId->ricInstanceID  = 1;
1061    return ROK;
1062 }
1063
1064 /*******************************************************************
1065  *
1066  * @brief Fills the mandatory RicAdmitted List Items
1067  *
1068  * @details
1069  *
1070  *    Function : fillRicAdmitList
1071  *
1072  *    Functionality: Fills the mandatory Ric Admitted List Items
1073  *
1074  * @params[in] RICaction_Admitted_ItemIEs_t *ricAdmitItems
1075  * @return ROK     - success
1076  *         RFAILED - failure
1077  *
1078  * ****************************************************************/
1079
1080 uint8_t fillRicAdmitList(RICaction_Admitted_ItemIEs_t *ricAdmitItems)
1081 {
1082
1083    if(ricAdmitItems != NULLP)
1084    {
1085       ricAdmitItems->id = ProtocolIE_IDE2_id_RICaction_Admitted_Item;
1086       ricAdmitItems->criticality = CriticalityE2_reject;
1087       ricAdmitItems->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
1088       ricAdmitItems->value.choice.RICaction_Admitted_Item.ricActionID = 1; 
1089    }
1090    else
1091    {
1092       return RFAILED;
1093    }
1094    return ROK;
1095 }
1096 /*******************************************************************
1097  *
1098  * @brief Builds the mandatory RicAdmitted List Params
1099  *
1100  * @details
1101  *
1102  *    Function : BuildRicAdmitList
1103  *
1104  *    Functionality: Builds the mandatory Ric Admitted List Params
1105  *
1106  * @params[in] RICaction_Admitted_List_t *admitListPtr
1107  * @return ROK     - success
1108  *         RFAILED - failure
1109  *
1110  * ****************************************************************/
1111
1112 uint8_t BuildRicAdmitList(RICaction_Admitted_List_t *admitListPtr)
1113 {
1114    uint8_t idx ;
1115    uint8_t elementCnt;  
1116    uint8_t ret= ROK;
1117    elementCnt = 1;
1118
1119    if(admitListPtr == NULLP)
1120    {
1121       DU_LOG("\nERROR  -->  E2AP : Memory allocation for RIC Admit List failed");
1122       ret = RFAILED;
1123    }
1124    else
1125    {
1126       admitListPtr->list.count = elementCnt;
1127       admitListPtr->list.size  = elementCnt * sizeof(RICaction_Admitted_ItemIEs_t);
1128       DU_ALLOC(admitListPtr->list.array, admitListPtr->list.size);
1129       if(admitListPtr->list.array == NULLP)
1130       {
1131          DU_LOG("\nERROR  -->  E2AP : Memory allocation for RIC Admit List failed");
1132          ret = RFAILED;
1133       }
1134       else
1135       {
1136          for(idx=0 ; idx<elementCnt ; idx++ )
1137          {
1138             DU_ALLOC(admitListPtr->list.array[idx], sizeof(RICaction_Admitted_ItemIEs_t));
1139             if(admitListPtr->list.array[idx] == NULLP)
1140             {
1141                ret = RFAILED;
1142             }
1143          }
1144          if(ret != RFAILED)
1145          {
1146             idx=0;
1147             fillRicAdmitList((RICaction_Admitted_ItemIEs_t *)admitListPtr->list.array[idx]);
1148          }
1149       }
1150    }    
1151    return ret;
1152 }
1153 /*******************************************************************
1154  *
1155  * @breif Deallocation of BuildAndSendRicSubscriptionRsp memory
1156  *
1157  * @details
1158  *
1159  *    Function : FreeRicSubscriptionRsp
1160  *
1161  * Functionality:Free the RicSubscriptionRsp
1162  *
1163  * @param[in] E2AP_PDU_t *e2apRicMsg
1164  *
1165  * @return void
1166  *      
1167  *
1168  ******************************************************************/
1169 void FreeRicSubscriptionRsp(E2AP_PDU_t  *e2apRicMsg)
1170 {
1171    RICsubscriptionResponse_t  *ricSubscriptionRsp= NULLP;
1172    uint8_t idx=0;
1173    uint8_t idx1=0;
1174    RICaction_Admitted_List_t *admitListPtr;
1175
1176    if(e2apRicMsg != NULLP)
1177    {
1178       if(e2apRicMsg->choice.successfulOutcome != NULLP)
1179       {
1180          ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
1181          if(ricSubscriptionRsp)
1182          {
1183             if(ricSubscriptionRsp->protocolIEs.list.array != NULLP)
1184             {
1185                for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
1186                {
1187                   if(ricSubscriptionRsp->protocolIEs.list.array[idx] != NULLP)
1188                   {
1189                      switch(ricSubscriptionRsp->protocolIEs.list.array[idx]->id)
1190                      {
1191                         case ProtocolIE_IDE2_id_RICrequestID:
1192                            break;
1193
1194                         case ProtocolIE_IDE2_id_RANfunctionID:
1195                            break;
1196
1197                         case ProtocolIE_IDE2_id_RICactions_Admitted:
1198                            {
1199                               admitListPtr = &ricSubscriptionRsp->protocolIEs.list.\
1200                                              array[idx]->value.choice.RICaction_Admitted_List;
1201                               if(admitListPtr->list.array != NULLP)
1202                               {
1203                                  for(idx1=0 ; idx1<admitListPtr->list.count; idx1++ )
1204                                  {
1205                                     if(admitListPtr->list.array[idx1] != NULLP)
1206                                     {
1207                                        DU_FREE(admitListPtr->list.array[idx1],
1208                                              sizeof(RICaction_Admitted_ItemIEs_t));
1209                                     }
1210                                  }
1211                                  DU_FREE(admitListPtr->list.array, admitListPtr->list.size);     
1212                               }
1213                               break;
1214                            }
1215                         default:
1216                            break;
1217                      }
1218                      DU_FREE(ricSubscriptionRsp->protocolIEs.list.array[idx], \
1219                            sizeof(RICsubscriptionResponse_IEs_t));
1220                   }
1221                }
1222                DU_FREE(ricSubscriptionRsp->protocolIEs.list.array, \
1223                      ricSubscriptionRsp->protocolIEs.list.size);
1224             }
1225          }   
1226          DU_FREE(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
1227       }         
1228       DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));        
1229    }
1230 }
1231 /*******************************************************************
1232  *
1233  * @brief Builds and Send the RicSubscriptionRsp
1234  *
1235  * @details
1236  *
1237  *    Function : BuildAndSendRicSubscriptionRsp
1238  *
1239  * functionality:Fills the RicSubscriptionRsp
1240  *
1241  * @return ROK     - success
1242  *         RFAILED - failure
1243  *
1244  ******************************************************************/
1245 uint8_t  FillRicSubscriptionRsp(RICsubscriptionResponse_t  *ricSubscriptionRsp )
1246 {
1247    uint8_t idx=0;
1248    uint8_t ret = ROK;
1249    uint8_t elementCnt = 0;
1250    uint8_t BuildRicRequestIdret=ROK;
1251    uint8_t BuildRicAdmitListret=ROK;
1252
1253    elementCnt=3;
1254    ricSubscriptionRsp->protocolIEs.list.count = elementCnt;
1255    ricSubscriptionRsp->protocolIEs.list.size  = elementCnt * sizeof(RICsubscriptionResponse_IEs_t);
1256    DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array, \
1257          ricSubscriptionRsp->protocolIEs.list.size);
1258    if(ricSubscriptionRsp->protocolIEs.list.array == NULLP)
1259    {
1260       DU_LOG("\nERROR  -->  E2AP : Memory allocation for FillRicSubscriptionRsp  failed");
1261       ret = RFAILED;
1262    }
1263    else
1264    {
1265       for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
1266       {
1267          DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array[idx], \
1268                sizeof(RICsubscriptionResponse_IEs_t));
1269          if(ricSubscriptionRsp->protocolIEs.list.array[idx] == NULLP)
1270          {
1271             ret = RFAILED;
1272          }
1273       }
1274       if(ret != RFAILED)
1275       {
1276
1277          idx=0;
1278          ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
1279          ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1280          ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
1281                                                                          RICsubscriptionRequest_IEs__value_PR_RICrequestID;
1282          BuildRicRequestIdret =
1283             BuildRicRequestId(&ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RICrequestID);
1284          if(BuildRicRequestIdret != ROK)
1285          {
1286             ret = RFAILED;
1287          }
1288          else
1289          {
1290             idx++;
1291             ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
1292             ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1293             ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
1294                                                                             RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
1295             ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RANfunctionID = 1;
1296
1297             idx++;
1298             ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactions_Admitted;
1299             ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1300             ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
1301                                                                             RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
1302             BuildRicAdmitListret =
1303                BuildRicAdmitList(&ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RICaction_Admitted_List);
1304             if(BuildRicAdmitListret != ROK)
1305             {
1306                ret = RFAILED;
1307             }
1308          }
1309       }
1310    }    
1311    return ret;
1312 }
1313 /*******************************************************************
1314  *
1315  * @brief Builds and Send the RicSubscriptionRsp
1316  *
1317  * @details
1318  *
1319  *    Function : BuildAndSendRicSubscriptionRsp
1320  *
1321  * Functionality:Fills the RicSubscriptionRsp
1322  *
1323  * @return ROK     - success
1324  *         RFAILED - failure
1325  *
1326  ******************************************************************/
1327
1328 uint8_t BuildAndSendRicSubscriptionRsp()
1329 {
1330
1331    E2AP_PDU_t         *e2apRicMsg = NULLP;
1332    RICsubscriptionResponse_t  *ricSubscriptionRsp=NULLP;
1333    asn_enc_rval_t     encRetVal; 
1334    uint8_t ret = RFAILED;
1335    uint8_t FillRicricSubscriptionRspret;
1336
1337    while(true)
1338    {
1339       DU_LOG("\nINFO   -->  E2AP : Building RIC Subscription Response\n");
1340
1341       DU_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t)); 
1342       if(e2apRicMsg == NULLP)
1343       {
1344          DU_LOG("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
1345          break;
1346       }
1347       e2apRicMsg->present =  E2AP_PDU_PR_successfulOutcome;
1348       DU_ALLOC(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
1349       if(e2apRicMsg->choice.successfulOutcome == NULLP)
1350       {
1351          DU_LOG("\nERROR  -->  E2AP : Memory allocation for RIC subscription Response failed");
1352          break;
1353       }
1354
1355       e2apRicMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
1356       e2apRicMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
1357       e2apRicMsg->choice.successfulOutcome->value.present = \
1358                                                             SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse;
1359       ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
1360
1361       FillRicricSubscriptionRspret = FillRicSubscriptionRsp(ricSubscriptionRsp);
1362       if(FillRicricSubscriptionRspret != ROK)
1363       {
1364          DU_LOG("\nERROR  -->  E2AP : Memory allocation for RICsubscriptionResponseIE failed");
1365          break;
1366       }
1367
1368       /* Prints the Msg formed */
1369       xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg);
1370
1371       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1372       encBufSize = 0;
1373       encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apRicMsg, PrepFinalEncBuf,\
1374             encBuf);
1375       if(encRetVal.encoded == ENCODE_FAIL)
1376       {
1377          DU_LOG("\nERROR  -->  E2AP : Could not encode RIC Subscription Response structure (at %s)\n",\
1378                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1379          break;
1380       }
1381       else
1382       {
1383          DU_LOG("\nDEBUG   -->  E2AP : Created APER encoded buffer for RIC subscription response \n");
1384 #ifdef DEBUG_ASN_PRINT
1385          for(int i=0; i< encBufSize; i++)
1386          {
1387             printf("%x",encBuf[i]);
1388          } 
1389 #endif
1390       } 
1391
1392       if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
1393       {
1394          DU_LOG("\nERROR  -->  E2AP : Sending RIC Subscription Response failed");      
1395          break;
1396       }
1397
1398       ret = ROK;
1399       break;
1400
1401    }
1402    FreeRicSubscriptionRsp(e2apRicMsg);
1403
1404    return ret;
1405 }
1406
1407 /******************************************************************
1408  *
1409  * @brief Deallocation of memory allocated bu aper decoder for e2 setup response
1410  *
1411  * @details
1412  *
1413  *    Function : freeAperDecodingOfE2SetupRsp
1414  *
1415  *    Functionality: Deallocation of memory allocated bu aper decoder for e2
1416  *    setup response
1417  *
1418  * @params[in] E2setupResponse_t *e2SetRspMsg;
1419  * @return void
1420  *
1421  * ****************************************************************/
1422 void freeAperDecodingOfE2SetupRsp(E2setupResponse_t *e2SetRspMsg)
1423 {
1424    uint8_t arrIdx, e2NodeConfigAddAckListIdx;
1425    E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem;
1426    E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAddAckList;
1427
1428    if(e2SetRspMsg)
1429    {
1430       if(e2SetRspMsg->protocolIEs.list.array)
1431       {
1432          for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
1433          {
1434             if(e2SetRspMsg->protocolIEs.list.array[arrIdx])
1435             {
1436                switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
1437                {
1438                   case ProtocolIE_IDE2_id_TransactionID:
1439                      break;
1440
1441                   case ProtocolIE_IDE2_id_GlobalRIC_ID:
1442                      {
1443                         free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.pLMN_Identity.buf);
1444                         free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID.buf);
1445                         break;
1446                      }
1447
1448                   case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
1449                      {
1450                         e2NodeConfigAddAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
1451                         if(e2NodeConfigAddAckList->list.array )
1452                         {
1453                            for(e2NodeConfigAddAckListIdx = 0; e2NodeConfigAddAckListIdx< e2NodeConfigAddAckList->list.count; e2NodeConfigAddAckListIdx++)
1454                            {
1455                               if(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx])
1456                               {
1457                                  e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx];
1458                                  free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
1459                                        e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf);
1460                                  free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
1461                                        e2nodeComponentInterfaceTypeF1);
1462                                  free(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx]);
1463                               }
1464                            }
1465                            free(e2NodeConfigAddAckList->list.array);
1466                         }
1467                         break;
1468                      }
1469                }
1470                free(e2SetRspMsg->protocolIEs.list.array[arrIdx]);  
1471             }
1472          }
1473          free(e2SetRspMsg->protocolIEs.list.array);
1474       }
1475    }
1476 }
1477 /******************************************************************
1478  *
1479  * @brief Processes E2 Setup Response sent by RIC
1480  *
1481  * @details
1482  *
1483  *    Function : procE2SetupRsp
1484  *
1485  *    Functionality: Processes E2 Setup Response sent by RIC
1486  *
1487  * @params[in] E2AP_PDU_t ASN decoded E2AP message
1488  * @return ROK     - success
1489  *         RFAILED - failure
1490  *
1491  * ****************************************************************/
1492 uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
1493 {
1494    uint8_t arrIdx =0, transId=0; 
1495    uint32_t recvBufLen;             
1496    E2setupResponse_t *e2SetRspMsg;
1497    CmLList         *node;
1498    E2NodeComponent *e2NodeComponentInfo;
1499
1500    DU_LOG("\nINFO   -->  E2AP : E2 Setup Response received"); 
1501    duCb.e2Status = TRUE; //Set E2 status as true
1502    e2SetRspMsg = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
1503
1504    for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
1505    {
1506       switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
1507       {
1508          case ProtocolIE_IDE2_id_TransactionID:
1509             {
1510                transId = e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
1511                if((duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].transactionId == transId) &&\
1512                      (duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
1513                   memset(&duCb.e2apDb.e2TransInfo.onGoingTransaction[transId], 0, sizeof(E2TransInfo));
1514                else
1515                {
1516                   DU_LOG("\nERROR  -->  E2AP : Invalid transaction id [%d]", transId);
1517                   return RFAILED;
1518                }
1519                break;
1520             }
1521
1522          case ProtocolIE_IDE2_id_GlobalRIC_ID:
1523             {
1524                /* To store the Ric Id Params */
1525                recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value\
1526                      .choice.GlobalRIC_ID.pLMN_Identity.size);
1527                   memcpy(&duCb.e2apDb.ricId.plmnId, e2SetRspMsg->protocolIEs.list.array[arrIdx]\
1528                         ->value.choice.GlobalRIC_ID.pLMN_Identity.buf, recvBufLen);
1529                bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID, &duCb.e2apDb.ricId);
1530                /*TODO : duCb.e2apDb.ricId.plmnId memory to be deallocated after the usage */
1531                break;
1532             }
1533
1534          case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
1535             break;
1536
1537          default:
1538             DU_LOG("\nERROR  -->  E2AP : Invalid IE received in E2SetupRsp:%ld",
1539                   e2SetRspMsg->protocolIEs.list.array[arrIdx]->id);
1540             break;
1541       }
1542    }
1543    freeAperDecodingOfE2SetupRsp(e2SetRspMsg);
1544    
1545    node = searchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD);
1546    if(!node)
1547    {
1548       DU_LOG("\nERROR  --> E2AP : Received e2NodeComponentInfo is null");
1549       return RFAILED;
1550    }
1551    else
1552    {
1553       e2NodeComponentInfo = (E2NodeComponent*)node->node;
1554       cmLListDelFrm(&duCb.e2apDb.e2NodeComponentList, node);
1555       DU_FREE(e2NodeComponentInfo->componentRequestPart, e2NodeComponentInfo->reqBufSize);
1556       DU_FREE(e2NodeComponentInfo->componentResponsePart, e2NodeComponentInfo->rspBufSize);
1557       DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
1558       DU_FREE(node, sizeof(CmLList));
1559    }
1560
1561    BuildAndSendE2NodeConfigUpdate();
1562    return ROK;
1563 }
1564
1565 /******************************************************************
1566  *
1567  * @brief Processes RIC Subscription Req sent by RIC
1568  *
1569  * @details
1570  *
1571  *    Function : procRicSubsReq
1572  *
1573  *    Functionality: Processes E2 Setup Response sent by CU
1574  *
1575  * @params[in] E2AP_PDU_t ASN decoded E2AP message
1576  * @return ROK     - success
1577  *         RFAILED - failure
1578  *
1579  * ****************************************************************/
1580
1581 uint8_t procRicSubsReq(E2AP_PDU_t *e2apMsg)
1582 {
1583    uint8_t idx; 
1584    uint8_t ied; 
1585    uint8_t ret = ROK;
1586    CmLList  *ricSubscriptionNode = NULLP;
1587    RICsubscriptionRequest_t *ricSubsReq;
1588    RicSubscription *ricSubscriptionInfo;
1589    RICaction_ToBeSetup_ItemIEs_t *actionItem;
1590
1591    DU_LOG("\nINFO   -->  E2AP : RIC Subscription request received"); 
1592    ricSubsReq = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
1593
1594    for(idx=0; idx<ricSubsReq->protocolIEs.list.count; idx++)
1595    {
1596       if(ricSubsReq->protocolIEs.list.array[idx])
1597       {
1598          switch(ricSubsReq->protocolIEs.list.array[idx]->id)
1599          {
1600             case ProtocolIE_IDE2_id_RICrequestID:
1601                {
1602                   /* TODO :- ricSubscriptionInfo details will be stored based on
1603                    * RAN function id, so first we need to search RAN function and then add
1604                    * subscription details to that ran function */
1605                   DU_ALLOC(ricSubscriptionInfo, sizeof(RicSubscription));
1606                   if(!ricSubscriptionInfo)
1607                   {
1608                      DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for ricSubscriptionInfo");
1609                      return RFAILED;
1610                   }
1611                   ricSubscriptionInfo->requestId.requestorId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID;
1612                   ricSubscriptionInfo->requestId.instanceId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID;
1613                   DU_ALLOC(ricSubscriptionNode, sizeof(CmLList));
1614                   if(ricSubscriptionNode)
1615                   {
1616                      ricSubscriptionNode->node = (PTR) ricSubscriptionInfo;
1617                      cmLListAdd2Tail(&duCb.e2apDb.ranFunction[0].subscriptionList,ricSubscriptionNode);
1618                   }
1619                   break;
1620                }
1621             case ProtocolIE_IDE2_id_RANfunctionID:
1622                {
1623                   duCb.e2apDb.ranFunction[0].id = ricSubsReq->protocolIEs.list.array[idx]-> \
1624                                           value.choice.RANfunctionID; 
1625                   break;
1626                }
1627             case ProtocolIE_IDE2_id_RICsubscriptionDetails:
1628                {
1629                   if(ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.\
1630                         list.array)
1631                   {
1632                      actionItem =(RICaction_ToBeSetup_ItemIEs_t *)ricSubsReq->protocolIEs.list\
1633                                  .array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List\
1634                                  .list.array[0];
1635
1636                      for(ied = 0; ied < ricSubsReq->protocolIEs.list.array[idx]->value.choice.\
1637                            RICsubscriptionDetails.ricAction_ToBeSetup_List.list.count; ied++)
1638                      {
1639                         switch(actionItem->id)
1640                         {
1641                            case ProtocolIE_IDE2_id_RICaction_ToBeSetup_Item:
1642                               {
1643                                  ricSubscriptionInfo->actionSequence[0].id  = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID;
1644                                  ricSubscriptionInfo->actionSequence[0].type = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionType;
1645                                  break;
1646                               }
1647                            default:
1648                               DU_LOG("\nERROR  -->  E2AP : Invalid IE received in RicSetupLst:%ld",actionItem->id);
1649                               break;
1650                         }
1651                         free(actionItem);
1652                      }
1653                      free(ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.\
1654                            list.array);
1655
1656 #ifdef KPI_CALCULATION 
1657                      /* This is a dummy trigger for statistics request. It will
1658                       * be removed in next gerrit and actual statistics request
1659                       * will be sent when RIC subscription request is received
1660                       * from RIC */
1661                      ricSubscriptionInfo->actionSequence[0].definition.styleType = 1;
1662                      BuildAndSendStatsReq(ricSubscriptionInfo->actionSequence[0].definition);
1663 #endif
1664                   }
1665                   break;
1666                }
1667
1668             default:
1669                DU_LOG("\nERROR  -->  E2AP : Invalid IE received in RIC SubsReq:%ld",
1670                      ricSubsReq->protocolIEs.list.array[idx]->id);
1671                break;
1672          }
1673          free(ricSubsReq->protocolIEs.list.array[idx]);
1674       }
1675    }
1676    free(ricSubsReq->protocolIEs.list.array);
1677    ret = BuildAndSendRicSubscriptionRsp();
1678    {
1679       BuildAndSendRicIndication(ricSubscriptionInfo);
1680    }
1681
1682    return ret;
1683 }
1684
1685 /*******************************************************************
1686  *
1687  * @brief Free the RicIndication Message
1688  *
1689  * @details
1690  *
1691  *    Function : FreeRicIndication
1692  *
1693  * Functionality: Free the RicIndication Message
1694  *
1695  * @return void
1696  *         
1697  *
1698  ******************************************************************/
1699 void FreeRicIndication(E2AP_PDU_t  *e2apMsg) 
1700 {
1701    uint8_t idx=0;
1702    RICindication_t *ricIndicationMsg= NULLP;
1703
1704
1705    if(e2apMsg != NULLP)
1706    {
1707       if(e2apMsg->choice.initiatingMessage != NULLP)
1708       {
1709          ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
1710          if(ricIndicationMsg!= NULLP)
1711          {
1712             if(ricIndicationMsg->protocolIEs.list.array != NULLP)
1713             {
1714                for(idx=0; idx<ricIndicationMsg->protocolIEs.list.count; idx++)
1715                {
1716                   if(ricIndicationMsg->protocolIEs.list.array[idx] != NULLP)
1717                   {
1718                      switch(ricIndicationMsg->protocolIEs.list.array[idx]->id)
1719                      {
1720                         case ProtocolIE_IDE2_id_RICrequestID:
1721                            break;
1722
1723                         case ProtocolIE_IDE2_id_RANfunctionID:
1724                            break;
1725
1726                         case ProtocolIE_IDE2_id_RICactionID:
1727                            break;
1728
1729                         case ProtocolIE_IDE2_id_RICindicationType:
1730                            break;
1731
1732                         case ProtocolIE_IDE2_id_RICindicationHeader:
1733                            {
1734                               DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf,\
1735                                     ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
1736                               break;
1737                            }
1738                         case ProtocolIE_IDE2_id_RICindicationMessage:
1739                            {
1740                               DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf,\
1741                                     ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
1742                               break;
1743                            }
1744                         default:
1745                            break;
1746                      }
1747                      DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx],sizeof(RICindication_IEs_t));
1748                   }
1749                }
1750                DU_FREE(ricIndicationMsg->protocolIEs.list.array,ricIndicationMsg->protocolIEs.list.size);
1751             }
1752          }
1753          DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1754       }
1755       DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
1756    }
1757 }
1758 /*******************************************************************
1759  *
1760  * brief Fill the RicIndication Message
1761  *
1762  * @details
1763  *
1764  *    Function : FillRicIndication
1765  *
1766  * Functionality:Fills the RicIndication Message
1767  *
1768  * @return ROK     - success
1769  *         RFAILED - failure
1770  *
1771  ******************************************************************/
1772 uint8_t FillRicIndication(RICindication_t *ricIndicationMsg, RicSubscription *ricSubscriptionInfo)
1773 {
1774    uint8_t elementCnt=0;
1775    uint8_t idx=0;
1776    uint8_t ret = ROK;
1777    elementCnt = 6;
1778
1779    ricIndicationMsg->protocolIEs.list.count = elementCnt;
1780    ricIndicationMsg->protocolIEs.list.size  = elementCnt * sizeof(RICindication_t);
1781    /* Initialize the Ric Indication members */
1782    DU_ALLOC(ricIndicationMsg->protocolIEs.list.array, \
1783          ricIndicationMsg->protocolIEs.list.size);
1784    if(ricIndicationMsg->protocolIEs.list.array == NULLP)
1785    {
1786       DU_LOG("\nERROR  -->  E2AP : Memory allocation for RICindicationIEs failed");
1787       ret = RFAILED;
1788    }
1789    else
1790    {
1791       for(idx=0; idx<elementCnt; idx++)
1792       {
1793          DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx],\
1794                sizeof(RICindication_IEs_t));
1795          if(ricIndicationMsg->protocolIEs.list.array[idx] == NULLP)
1796          {
1797             DU_LOG("\nERROR  -->  E2AP : Memory allocation for RICindicationIEs failed");
1798             ret = RFAILED;
1799          }
1800       }
1801       if(ret != RFAILED)
1802       {
1803          idx = 0;
1804
1805          ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
1806          ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1807          ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1808                                                                         RICindication_IEs__value_PR_RICrequestID;
1809          ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID =ricSubscriptionInfo->requestId.requestorId;
1810          ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID = ricSubscriptionInfo->requestId.instanceId;
1811
1812          idx++;
1813          ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
1814          ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1815          ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1816                                                                         RICindication_IEs__value_PR_RANfunctionID;
1817          ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RANfunctionID = duCb.e2apDb.ranFunction[0].id;
1818
1819          idx++;
1820          ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactionID;
1821          ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1822          ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1823                                                                         RICindication_IEs__value_PR_RICactionID;
1824          ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICactionID = ricSubscriptionInfo->actionSequence[0].id;
1825
1826          idx++;
1827          ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationType;
1828          ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1829          ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1830                                                                         RICindication_IEs__value_PR_RICindicationType;
1831          ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationType = ricSubscriptionInfo->actionSequence[0].type;
1832
1833          idx++;
1834          ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationHeader;
1835          ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1836          ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1837                                                                         RICindication_IEs__value_PR_RICindicationHeader;
1838          ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size = 3 *
1839             sizeof(uint8_t);
1840          DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf ,\
1841                ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
1842          if(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf == NULLP)
1843          {
1844             DU_LOG("\nERROR  -->  E2AP : Memory allocation for RICindicationIEs failed");
1845             ret = RFAILED;
1846          }
1847          else
1848          {
1849             buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
1850                   ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf);
1851             idx++;
1852             /* TO BE CHANGED: RIC INDICATION DATA */
1853             /* For now filling a dummy octect data, need to tested with PRBs*/
1854             ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationMessage;
1855             ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1856             ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1857                                                                            RICindication_IEs__value_PR_RICindicationMessage;
1858             ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size = 3 *
1859                sizeof(uint8_t);
1860             DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf ,\
1861                   ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
1862             if(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf == NULLP)
1863             {
1864                DU_LOG("\nERROR  -->  E2AP : Memory allocation for RICindicationIEs failed");
1865                ret = RFAILED;
1866             }
1867             else
1868             {
1869                buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
1870                      ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf);
1871             }
1872          }
1873       }
1874    }
1875    return ret;
1876 }
1877
1878 /*******************************************************************
1879  *
1880  * @brief Builds and Send the RicIndication Message
1881  *
1882  * @details
1883  *
1884  *    Function : BuildAndSendRicIndication
1885  *
1886  * Functionality:Fills the RicIndication Message
1887  *
1888  * @return ROK     - success
1889  *         RFAILED - failure
1890  *
1891  ******************************************************************/
1892
1893 uint8_t BuildAndSendRicIndication(RicSubscription *ricSubscriptionInfo)
1894 {
1895    E2AP_PDU_t                 *e2apMsg = NULLP;
1896    RICindication_t            *ricIndicationMsg=NULLP;
1897    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1898    uint8_t ret = RFAILED; 
1899    uint8_t FillRicIndicationret = ROK;
1900
1901    while(true)
1902    {
1903       DU_LOG("\nINFO   -->  E2AP : Building RIC Indication Message\n");
1904
1905       DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
1906       if(e2apMsg == NULLP)
1907       {
1908          DU_LOG("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
1909          break;
1910       }
1911
1912       e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
1913       DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1914       if(e2apMsg->choice.initiatingMessage == NULLP)
1915       {
1916          DU_LOG("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
1917          break;
1918       }
1919       e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICindication;
1920       e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
1921       e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICindication;
1922
1923       ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
1924
1925       FillRicIndicationret = FillRicIndication(ricIndicationMsg, ricSubscriptionInfo);
1926       if(FillRicIndicationret != ROK)
1927       {
1928          break;
1929       }
1930       /* Prints the Msg formed */
1931       xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1932       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1933       encBufSize = 0;
1934       encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
1935             encBuf);
1936       if(encRetVal.encoded == ENCODE_FAIL)
1937       {
1938          DU_LOG("\nERROR  -->  E2AP : Could not encode RIC Indication Message (at %s)\n",\
1939                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1940          break;
1941       }
1942       else
1943       {
1944          DU_LOG("\nDEBUG  -->  E2AP : Created APER encoded buffer for RIC Indication Message \n");
1945 #ifdef DEBUG_ASN_PRINT
1946          for(int i=0; i< encBufSize; i++)
1947          {
1948             printf("%x",encBuf[i]);
1949          } 
1950 #endif
1951       }
1952
1953       if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
1954       {
1955          DU_LOG("\nINFO   -->  E2AP : Sending RIC Indication Message");      
1956
1957       }
1958       ret = ROK;
1959       break;
1960    }
1961    FreeRicIndication(e2apMsg);  
1962    return ret;
1963 }
1964
1965 /*******************************************************************
1966  *
1967  * @brief Deallocate the memory allocated for E2nodeConfigurationUpdate msg 
1968  *
1969  * @details
1970  *
1971  *    Function : FreeE2NodeConfigUpdate 
1972  *
1973  *    Functionality:
1974  *       - freeing the memory allocated for E2nodeConfigurationUpdate
1975  *
1976  * @params[in] E2AP_PDU_t *e2apMsg 
1977  * @return ROK     - success
1978  *         RFAILED - failure
1979  *
1980  * ****************************************************************/
1981 void FreeE2NodeConfigUpdate(E2AP_PDU_t *e2apMsg)
1982 {
1983    uint8_t arrIdx =0;
1984    E2nodeConfigurationUpdate_t *e2NodeConfigUpdate;
1985
1986    if(e2apMsg != NULLP)
1987    {
1988       if(e2apMsg->choice.initiatingMessage != NULLP)
1989       {
1990          e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
1991          if(e2NodeConfigUpdate->protocolIEs.list.array != NULLP)
1992          {
1993             for(arrIdx = 0; arrIdx < e2NodeConfigUpdate->protocolIEs.list.count; arrIdx++)
1994             {
1995                DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
1996             }
1997             DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size);
1998          }
1999          DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2000       }
2001       DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2002    }
2003 }
2004
2005 /*******************************************************************
2006  *
2007  * @brief Buld and send the E2 node config update msg 
2008  *
2009  * @details
2010  *
2011  *    Function : BuildAndSendE2NodeConfigUpdate
2012  *
2013  *    Functionality:
2014  *         - Buld and send the E2 node config update msg
2015  *
2016  * @params[in] 
2017  * @return ROK     - success
2018  *         RFAILED - failure
2019  *
2020  * ****************************************************************/
2021
2022 uint8_t BuildAndSendE2NodeConfigUpdate()
2023 {
2024    uint8_t arrIdx = 0,elementCnt = 1;
2025    uint8_t ret = ROK;
2026    E2AP_PDU_t        *e2apMsg = NULLP;
2027    E2nodeConfigurationUpdate_t *e2NodeConfigUpdate = NULLP;
2028    asn_enc_rval_t     encRetVal;       /* Encoder return value */
2029
2030    DU_LOG("\nINFO   -->  E2AP : Building E2 Node config update\n");
2031    do
2032    {
2033       DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2034       if(e2apMsg == NULLP)
2035       {
2036          DU_LOG("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
2037          break;
2038       }
2039       e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2040       DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2041       if(e2apMsg->choice.initiatingMessage == NULLP)
2042       {
2043          DU_LOG("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
2044          DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2045          return RFAILED;
2046       }
2047       e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2048       e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
2049       e2apMsg->choice.initiatingMessage->value.present = \
2050       InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate;
2051       e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
2052
2053       e2NodeConfigUpdate->protocolIEs.list.count = elementCnt;
2054       e2NodeConfigUpdate->protocolIEs.list.size  = elementCnt * sizeof(E2nodeConfigurationUpdate_IEs_t*);
2055       /* Initialize the Ric Indication members */
2056       DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array, \
2057             e2NodeConfigUpdate->protocolIEs.list.size);
2058       if(e2NodeConfigUpdate->protocolIEs.list.array == NULLP)
2059       {
2060          DU_LOG("\nERROR  -->  E2AP : Memory allocation for e2NodeConfigUpdate failed");
2061          break;
2062       }
2063       
2064       for(arrIdx =0; arrIdx<elementCnt; arrIdx++)
2065       {
2066          DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
2067          if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx] == NULLP)
2068          {
2069             
2070             DU_LOG("\nERROR  -->  E2AP : Memory allocation for e2NodeConfigUpdate failed");
2071             break;
2072          }
2073       }
2074
2075       arrIdx = 0;
2076       /* TransactionID */
2077       e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2078       e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2079       e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_TransactionID;
2080       e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = TRANS_ID;
2081
2082
2083       /* Prints the Msg formed */
2084       xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2085
2086       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2087       encBufSize = 0;
2088       encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
2089             encBuf);
2090       if(encRetVal.encoded == ENCODE_FAIL)
2091       {
2092          DU_LOG("\nERROR  -->  E2AP : Could not encode E2nodeConfigurationUpdate structure (at %s)\n",\
2093                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2094          break;
2095       }
2096       else
2097       {
2098          DU_LOG("\nDEBUG   -->  E2AP : Created APER encoded buffer for E2nodeConfigurationUpdate\n");
2099 #ifdef DEBUG_ASN_PRINT
2100          for(int i=0; i< encBufSize; i++)
2101          {
2102             printf("%x",encBuf[i]);
2103          }
2104 #endif
2105       }
2106       if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize))
2107       {
2108          DU_LOG("\nERROR  -->  E2AP : Sending E2 node config update failed");
2109          return RFAILED;
2110       }
2111
2112       break;
2113    }while(true);
2114    
2115    FreeE2NodeConfigUpdate(e2apMsg);
2116    return ret;
2117 }
2118
2119 /*******************************************************************
2120  *
2121  * @brief Deallocate the memory allocated for E2ResetRequest msg
2122  *
2123  * @details
2124  *
2125  *    Function : FreeE2ResetRequest
2126  *
2127  *    Functionality:
2128  *       - freeing the memory allocated for E2ResetRequest
2129  *
2130  * @params[in] E2AP_PDU_t *e2apMsg
2131  * @return ROK     - success
2132  *         RFAILED - failure
2133  *
2134  * ****************************************************************/
2135 void FreeE2ResetRequest(E2AP_PDU_t *e2apMsg)
2136 {
2137    uint8_t ieIdx =0;
2138    ResetRequestE2_t  *resetReq = NULLP;
2139
2140    if(e2apMsg != NULLP)
2141    {
2142       if(e2apMsg->choice.initiatingMessage != NULLP)
2143       {
2144          resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
2145          if(resetReq->protocolIEs.list.array)
2146          {
2147             for(ieIdx = 0; ieIdx < resetReq->protocolIEs.list.count; ieIdx++)
2148             {
2149                DU_FREE(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
2150             }
2151             DU_FREE(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
2152          }
2153          DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2154       }
2155       DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2156    }
2157 }
2158
2159 /*******************************************************************
2160  *
2161  * @brief Build and send the E2 reset request msg
2162  *
2163  * @details
2164  *
2165  *    Function : BuildAndSendE2ResetRequest
2166  *
2167  *    Functionality:
2168  *         - Buld and send the E2 reset request msg to RIC
2169  *
2170  * @params[in]
2171  * @return ROK     - success
2172  *         RFAILED - failure
2173  *
2174  * ****************************************************************/
2175 uint8_t BuildAndSendE2ResetRequest(E2CauseType failureType, E2Cause failureCause)
2176 {
2177    uint8_t ieIdx = 0, elementCnt = 0, transId = 0;
2178    uint8_t ret = RFAILED;
2179    E2AP_PDU_t        *e2apMsg = NULLP;
2180    ResetRequestE2_t  *resetReq = NULLP;
2181    asn_enc_rval_t     encRetVal;       /* Encoder return value */
2182
2183    DU_LOG("\nINFO   -->  E2AP : Building E2 Reset Request\n");
2184
2185    do
2186    {
2187       DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2188       if(e2apMsg == NULLP)
2189       {
2190          DU_LOG("\nERROR  -->  E2AP : BuildAndSendE2ResetRequest(): Memory allocation for E2AP-PDU failed");
2191          break;
2192       }
2193
2194       e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2195       DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2196       if(e2apMsg->choice.initiatingMessage == NULLP)
2197       {
2198          DU_LOG("\nERROR  -->  E2AP : BuildAndSendE2ResetRequest(): Memory allocation for initiatingMessage");
2199          break;
2200       }
2201
2202       e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_Reset;
2203       e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2204       e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ResetRequestE2;
2205       resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
2206
2207       elementCnt = 2;
2208       resetReq->protocolIEs.list.count = elementCnt;
2209       resetReq->protocolIEs.list.size = elementCnt * sizeof(ResetRequestIEs_t *);
2210
2211       DU_ALLOC(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
2212       if(!resetReq->protocolIEs.list.array)
2213       {
2214          DU_LOG("\nERROR  -->  E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
2215             Reset Request IE array");
2216          break;
2217       }
2218
2219       for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
2220       {
2221          DU_ALLOC(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
2222          if(!resetReq->protocolIEs.list.array[ieIdx])
2223          {
2224             DU_LOG("\nERROR  -->  E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
2225             Reset Request IE array element");
2226             break;
2227          }
2228       }
2229
2230       /* In case of failure */
2231       if(ieIdx < elementCnt)
2232          break;
2233
2234       ieIdx = 0;
2235       resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2236       resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
2237       resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_TransactionID;
2238       transId = assignTransactionId();
2239       resetReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
2240
2241       ieIdx++;
2242       resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_CauseE2;
2243       resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_ignore;
2244       resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_CauseE2;
2245       resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.present = failureType;
2246       switch(resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.present)
2247       {
2248          case CauseE2_PR_NOTHING:
2249             break;
2250          case CauseE2_PR_ricRequest:
2251             resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.ricRequest = failureCause;
2252             break;
2253          case CauseE2_PR_ricService:
2254             resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.ricService = failureCause;
2255             break;
2256          case CauseE2_PR_e2Node:
2257             resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.e2Node = failureCause;
2258             break;
2259          case CauseE2_PR_transport:
2260             resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.transport = failureCause;
2261             break;
2262          case CauseE2_PR_protocol:
2263             resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.protocol = failureCause;
2264             break;
2265          case CauseE2_PR_misc:
2266             resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.misc = failureCause;
2267             break;
2268       }
2269
2270       /* Prints the Msg formed */
2271       xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2272
2273       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2274       encBufSize = 0;
2275       encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
2276             encBuf);
2277       if(encRetVal.encoded == ENCODE_FAIL)
2278       {
2279          DU_LOG("\nERROR  -->  E2AP : Could not encode E2SetupRequest structure (at %s)\n",\
2280                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2281          break;
2282       }
2283       else
2284       {
2285          DU_LOG("\nDEBUG   -->  E2AP : Created APER encoded buffer for E2SetupRequest\n");
2286 #ifdef DEBUG_ASN_PRINT
2287          for(int i=0; i< encBufSize; i++)
2288          {
2289             printf("%x",encBuf[i]);
2290          }
2291 #endif
2292       }
2293       if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
2294       {
2295          DU_LOG("\nERROR  -->  E2AP : Sending E2 Setup request failed");
2296          break;
2297       }
2298
2299       /* In case the message is sent successfully, store the transaction info to
2300        * be used when response is received */
2301       duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].transactionId = transId;
2302       duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
2303
2304       ret = ROK;
2305       break;
2306    }while(true);
2307
2308    /* Free all memory */
2309    FreeE2ResetRequest(e2apMsg);
2310    return ret;
2311 }
2312
2313 /*******************************************************************
2314  *
2315  * @brief Deallocate the memory allocated for Reset Response msg
2316  *
2317  * @details
2318  *
2319  *    Function : freeAperDecodingOfE2ResetRsp
2320  *
2321  *    Functionality:
2322  *       - freeing the memory allocated for Reset response
2323  *
2324  * @params[in] ResetResponseE2_t *resetResponse
2325  * @return void
2326  *
2327  * ****************************************************************/
2328 void freeAperDecodingOfE2ResetRsp(ResetResponseE2_t *resetResponse)
2329 {
2330    uint8_t ieIdx;
2331
2332    if(resetResponse)
2333    {
2334       if(resetResponse->protocolIEs.list.array)
2335       {
2336          for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
2337          {
2338             if(resetResponse->protocolIEs.list.array[ieIdx])
2339             {
2340                switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
2341                {
2342                   case ProtocolIE_IDE2_id_TransactionID:
2343                      break;
2344
2345                   case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
2346                      break;
2347                }
2348                free(resetResponse->protocolIEs.list.array[ieIdx]);
2349             }
2350          }
2351          free(resetResponse->protocolIEs.list.array);
2352       }
2353    }
2354 }
2355
2356 /******************************************************************
2357  *
2358  * @brief Processes E2 Reset Response sent by RIC
2359  *
2360  * @details
2361  *
2362  *    Function : procResetResponse
2363  *
2364  *    Functionality: Processes E2 Reset Response sent by RIC
2365  *
2366  * @params[in] E2AP_PDU_t ASN decoded E2AP message
2367  * @return ROK     - success
2368  *         RFAILED - failure
2369  *
2370  * ****************************************************************/
2371 uint8_t procResetResponse(E2AP_PDU_t *e2apMsg)
2372 {
2373    uint8_t ieIdx =0, transId;
2374    ResetResponseE2_t *resetResponse;
2375
2376    DU_LOG("\nINFO   -->  E2AP : E2 Reset Response received");
2377    resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;;
2378
2379    for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
2380    {
2381       switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
2382       {
2383          case ProtocolIE_IDE2_id_TransactionID:
2384             transId = resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
2385             if((duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].transactionId == transId) && \
2386                   (duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
2387               memset(&duCb.e2apDb.e2TransInfo.onGoingTransaction[transId], 0, sizeof(E2TransInfo));
2388             else
2389             {
2390                DU_LOG("\nERROR  -->  E2AP : Invalid transaction id [%d]", transId);
2391                return RFAILED;
2392             }
2393             break;
2394          case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
2395             /* As per ORAN WG3 E2AP spec v3.0, section 9.2.2
2396                Criticality Diagnostics IE is sent by Near-RT RIC when parts of a received message i.e. 
2397                Reset Request in this case, have not been comprehended or were missing, or if the message 
2398                contained logical errors.
2399
2400                Processing of this ID should be implemented when negative call flows are to be supported.
2401              */
2402             break;
2403          default:
2404             DU_LOG("\nERROR  -->  E2AP : Invalid IE received in E2 Reset Response : %ld",
2405                   resetResponse->protocolIEs.list.array[ieIdx]->id);
2406             break;
2407       }
2408    }
2409
2410    freeAperDecodingOfE2ResetRsp(resetResponse);
2411    return ROK;
2412 }
2413
2414 /******************************************************************
2415  *
2416  * @brief Deallocation of memory allocated bu aper decoder for e2 setup Failure
2417  *
2418  * @details
2419  *
2420  *    Function : freeAperDecodingOfE2SetupFailure
2421  *
2422  *    Functionality: Deallocation of memory allocated bu aper decoder for e2
2423  *    setup Failure
2424  *
2425  * @params[in] E2setupFailure_t *e2SetupFailure;
2426  * @return void
2427  *
2428  * ****************************************************************/
2429 void freeAperDecodingOfE2SetupFailure(E2setupFailure_t *e2SetupFailure)
2430 {
2431    uint8_t arrIdx;
2432
2433    if(e2SetupFailure)
2434    {
2435       if(e2SetupFailure->protocolIEs.list.array)
2436       {
2437          for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
2438          {
2439             if(e2SetupFailure->protocolIEs.list.array[arrIdx])
2440             {
2441                free(e2SetupFailure->protocolIEs.list.array[arrIdx]);  
2442             }
2443          }
2444          free(e2SetupFailure->protocolIEs.list.array);
2445       }
2446    }
2447 }
2448 /******************************************************************
2449  *
2450  * @brief Processes E2 Setup Failure sent by RIC
2451  *
2452  * @details
2453  *
2454  *    Function : procE2SetupFailure
2455  *
2456  *    Functionality: Processes E2 Setup failure sent by RIC
2457  *
2458  * @params[in] E2AP_PDU_t ASN decoded E2AP message
2459  * @return ROK     - success
2460  *         RFAILED - failure
2461  *
2462  * ****************************************************************/
2463 void procE2SetupFailure(E2AP_PDU_t *e2apMsg)
2464 {
2465    uint8_t arrIdx =0, transId =0, timerValue=0; 
2466    E2setupFailure_t *e2SetupFailure;
2467
2468    DU_LOG("\nINFO   -->  E2AP : E2 Setup failure received"); 
2469    e2SetupFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure;
2470
2471    for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
2472    {
2473       switch(e2SetupFailure->protocolIEs.list.array[arrIdx]->id)
2474       {
2475          case ProtocolIE_IDE2_id_TransactionID:
2476          {
2477             transId = e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
2478             if((duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].transactionId == transId) &&\
2479             (duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
2480               memset(&duCb.e2apDb.e2TransInfo.onGoingTransaction[transId], 0, sizeof(E2TransInfo));
2481             else
2482             {
2483                DU_LOG("\nERROR  -->  E2AP : Invalid transaction id [%d]", transId);
2484                return ;
2485             }
2486             break;
2487          }
2488          case ProtocolIE_IDE2_id_TimeToWaitE2:
2489             {
2490                timerValue = covertE2WaitTimerEnumToValue(e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
2491                if((duChkTmr((PTR)&(duCb.e2apDb), EVENT_E2_SETUP_TMR)) == FALSE)
2492                {
2493                   duStartTmr((PTR)&(duCb.e2apDb), EVENT_E2_SETUP_TMR, timerValue);
2494                }
2495                else
2496                {
2497                   DU_LOG("\nERROR   -->  E2AP : EVENT_E2_SETUP_TMR timer is already running");
2498                   return;
2499                }
2500                break; 
2501             }
2502       }
2503    }
2504
2505    freeAperDecodingOfE2SetupFailure(e2SetupFailure);
2506 }
2507 /*******************************************************************
2508  *
2509  * @brief Handles received E2AP message and sends back response  
2510  *
2511  * @details
2512  *
2513  *    Function : E2APMsgHdlr
2514  *
2515  *    Functionality:
2516  *         - Decodes received E2AP control message
2517  *         - Prepares response message, encodes and sends to SCTP
2518  *
2519  * @params[in] 
2520  * @return ROK     - success
2521  *         RFAILED - failure
2522  *
2523  * ****************************************************************/
2524 void E2APMsgHdlr(Buffer *mBuf)
2525 {
2526    int i =0;
2527    char *recvBuf = NULLP;
2528    MsgLen copyCnt =0;
2529    MsgLen recvBufLen =0;
2530    E2AP_PDU_t *e2apMsg = NULLP;
2531    asn_dec_rval_t rval ={0}; /* Decoder return value */
2532    E2AP_PDU_t e2apasnmsg={0} ;
2533
2534    DU_LOG("\nDEBUG   -->  E2AP : Received E2AP message buffer");
2535    ODU_PRINT_MSG(mBuf, 0,0);
2536
2537    /* Copy mBuf into char array to decode it */
2538    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
2539    DU_ALLOC(recvBuf, (Size)recvBufLen);
2540
2541    if(recvBuf == NULLP)
2542    {
2543       DU_LOG("\nERROR  -->  E2AP : Memory allocation failed");
2544       return;
2545    }
2546    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
2547    {
2548       DU_LOG("\nERROR  -->  E2AP : Failed while copying %d", copyCnt);
2549       return;
2550    }
2551
2552 #ifdef DEBUG_ASN_PRINT
2553    printf("\nDEBUG   -->  E2AP : Received flat buffer to be decoded : ");
2554    for(i=0; i< recvBufLen; i++)
2555    {
2556       printf("%x",recvBuf[i]);
2557    }
2558 #endif
2559
2560    /* Decoding flat buffer into E2AP messsage */
2561    e2apMsg = &e2apasnmsg;
2562    memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
2563
2564    rval = aper_decode(0, &asn_DEF_E2AP_PDU, (void **)&e2apMsg, recvBuf, recvBufLen, 0, 0);
2565    DU_FREE(recvBuf, (Size)recvBufLen);
2566
2567    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
2568    {
2569       DU_LOG("\nERROR  -->  E2AP : ASN decode failed");
2570       return;
2571    }
2572    printf("\n");
2573    xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2574
2575    switch(e2apMsg->present)
2576    {
2577       case E2AP_PDU_PR_unsuccessfulOutcome:
2578          {
2579             switch(e2apMsg->choice.unsuccessfulOutcome->value.present)
2580             {
2581                case UnsuccessfulOutcomeE2__value_PR_E2setupFailure:
2582                   {
2583                      procE2SetupFailure(e2apMsg);
2584                      break;
2585                   }
2586                default:
2587                   {
2588                      DU_LOG("\nERROR  -->  E2AP : Invalid type of E2AP_PDU_PR_unsuccessfulOutcome  [%d]",\
2589                            e2apMsg->choice.unsuccessfulOutcome->value.present);
2590                      return;
2591                   }
2592             }
2593             break;
2594          }
2595       case E2AP_PDU_PR_successfulOutcome:
2596          {
2597             switch(e2apMsg->choice.successfulOutcome->value.present)
2598             {
2599                case SuccessfulOutcomeE2__value_PR_E2setupResponse:
2600                   {
2601                      if(!duCb.e2Status)
2602                      {
2603                         procE2SetupRsp(e2apMsg);
2604                      }
2605                      break;
2606                   }
2607                case SuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateAcknowledge:
2608                   {
2609                      DU_LOG("\nDEBUG   -->  E2AP : E2 node Config update ack message recevied");
2610                      break;
2611                   }
2612                case SuccessfulOutcomeE2__value_PR_ResetResponseE2:
2613                   {
2614                      procResetResponse(e2apMsg);
2615                      break;
2616                   }
2617                default:
2618                   {
2619                      DU_LOG("\nERROR  -->  E2AP : Invalid type of E2AP_PDU_PR_successfulOutcome  [%d]",\
2620                            e2apMsg->choice.successfulOutcome->value.present);
2621                      return;
2622                   }
2623             }/* End of switch(successfulOutcome) */
2624             free(e2apMsg->choice.successfulOutcome);
2625             break;
2626          }
2627
2628       case E2AP_PDU_PR_initiatingMessage:
2629          {
2630             switch(e2apMsg->choice.initiatingMessage->value.present)
2631             {
2632                case InitiatingMessageE2__value_PR_RICsubscriptionRequest: 
2633                   {
2634                      procRicSubsReq(e2apMsg);
2635                      break;
2636                   }
2637                default:
2638                   {
2639                      DU_LOG("\nERROR  -->  E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\
2640                            e2apMsg->choice.initiatingMessage->value.present);
2641                      return;
2642                   }
2643             }/* End of switch(initiatingMessage) */
2644             free(e2apMsg->choice.initiatingMessage);
2645             break;
2646          }
2647       default:
2648          {
2649             DU_LOG("\nERROR  -->  E2AP : Invalid type of e2apMsg->present [%d]",e2apMsg->present);
2650             return;
2651          }
2652          free(e2apMsg);
2653
2654    }/* End of switch(e2apMsg->present) */
2655
2656 } /* End of E2APMsgHdlr */
2657
2658 /**********************************************************************
2659   End of file
2660  **********************************************************************/