d528b512129d55f364787b519e1af13ddcc3db8d
[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                      /* This is a dummy trigger for statistics request. It will
1657                       * be removed in next gerrit and actual statistics request
1658                       * will be sent when RIC subscription request is received
1659                       * from RIC */
1660                      ricSubscriptionInfo->actionSequence[0].definition.styleType = 1;
1661                      BuildAndSendStatsReq(ricSubscriptionInfo->actionSequence[0].definition);
1662                   }
1663                   break;
1664                }
1665
1666             default:
1667                DU_LOG("\nERROR  -->  E2AP : Invalid IE received in RIC SubsReq:%ld",
1668                      ricSubsReq->protocolIEs.list.array[idx]->id);
1669                break;
1670          }
1671          free(ricSubsReq->protocolIEs.list.array[idx]);
1672       }
1673    }
1674    free(ricSubsReq->protocolIEs.list.array);
1675    ret = BuildAndSendRicSubscriptionRsp();
1676    {
1677       BuildAndSendRicIndication(ricSubscriptionInfo);
1678    }
1679
1680    return ret;
1681 }
1682
1683 /*******************************************************************
1684  *
1685  * @brief Free the RicIndication Message
1686  *
1687  * @details
1688  *
1689  *    Function : FreeRicIndication
1690  *
1691  * Functionality: Free the RicIndication Message
1692  *
1693  * @return void
1694  *         
1695  *
1696  ******************************************************************/
1697 void FreeRicIndication(E2AP_PDU_t  *e2apMsg) 
1698 {
1699    uint8_t idx=0;
1700    RICindication_t *ricIndicationMsg= NULLP;
1701
1702
1703    if(e2apMsg != NULLP)
1704    {
1705       if(e2apMsg->choice.initiatingMessage != NULLP)
1706       {
1707          ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
1708          if(ricIndicationMsg!= NULLP)
1709          {
1710             if(ricIndicationMsg->protocolIEs.list.array != NULLP)
1711             {
1712                for(idx=0; idx<ricIndicationMsg->protocolIEs.list.count; idx++)
1713                {
1714                   if(ricIndicationMsg->protocolIEs.list.array[idx] != NULLP)
1715                   {
1716                      switch(ricIndicationMsg->protocolIEs.list.array[idx]->id)
1717                      {
1718                         case ProtocolIE_IDE2_id_RICrequestID:
1719                            break;
1720
1721                         case ProtocolIE_IDE2_id_RANfunctionID:
1722                            break;
1723
1724                         case ProtocolIE_IDE2_id_RICactionID:
1725                            break;
1726
1727                         case ProtocolIE_IDE2_id_RICindicationType:
1728                            break;
1729
1730                         case ProtocolIE_IDE2_id_RICindicationHeader:
1731                            {
1732                               DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf,\
1733                                     ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
1734                               break;
1735                            }
1736                         case ProtocolIE_IDE2_id_RICindicationMessage:
1737                            {
1738                               DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf,\
1739                                     ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
1740                               break;
1741                            }
1742                         default:
1743                            break;
1744                      }
1745                      DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx],sizeof(RICindication_IEs_t));
1746                   }
1747                }
1748                DU_FREE(ricIndicationMsg->protocolIEs.list.array,ricIndicationMsg->protocolIEs.list.size);
1749             }
1750          }
1751          DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1752       }
1753       DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
1754    }
1755 }
1756 /*******************************************************************
1757  *
1758  * brief Fill the RicIndication Message
1759  *
1760  * @details
1761  *
1762  *    Function : FillRicIndication
1763  *
1764  * Functionality:Fills the RicIndication Message
1765  *
1766  * @return ROK     - success
1767  *         RFAILED - failure
1768  *
1769  ******************************************************************/
1770 uint8_t FillRicIndication(RICindication_t *ricIndicationMsg, RicSubscription *ricSubscriptionInfo)
1771 {
1772    uint8_t elementCnt=0;
1773    uint8_t idx=0;
1774    uint8_t ret = ROK;
1775    elementCnt = 6;
1776
1777    ricIndicationMsg->protocolIEs.list.count = elementCnt;
1778    ricIndicationMsg->protocolIEs.list.size  = elementCnt * sizeof(RICindication_t);
1779    /* Initialize the Ric Indication members */
1780    DU_ALLOC(ricIndicationMsg->protocolIEs.list.array, \
1781          ricIndicationMsg->protocolIEs.list.size);
1782    if(ricIndicationMsg->protocolIEs.list.array == NULLP)
1783    {
1784       DU_LOG("\nERROR  -->  E2AP : Memory allocation for RICindicationIEs failed");
1785       ret = RFAILED;
1786    }
1787    else
1788    {
1789       for(idx=0; idx<elementCnt; idx++)
1790       {
1791          DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx],\
1792                sizeof(RICindication_IEs_t));
1793          if(ricIndicationMsg->protocolIEs.list.array[idx] == NULLP)
1794          {
1795             DU_LOG("\nERROR  -->  E2AP : Memory allocation for RICindicationIEs failed");
1796             ret = RFAILED;
1797          }
1798       }
1799       if(ret != RFAILED)
1800       {
1801          idx = 0;
1802
1803          ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
1804          ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1805          ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1806                                                                         RICindication_IEs__value_PR_RICrequestID;
1807          ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID =ricSubscriptionInfo->requestId.requestorId;
1808          ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID = ricSubscriptionInfo->requestId.instanceId;
1809
1810          idx++;
1811          ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
1812          ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1813          ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1814                                                                         RICindication_IEs__value_PR_RANfunctionID;
1815          ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RANfunctionID = duCb.e2apDb.ranFunction[0].id;
1816
1817          idx++;
1818          ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactionID;
1819          ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1820          ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1821                                                                         RICindication_IEs__value_PR_RICactionID;
1822          ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICactionID = ricSubscriptionInfo->actionSequence[0].id;
1823
1824          idx++;
1825          ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationType;
1826          ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1827          ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1828                                                                         RICindication_IEs__value_PR_RICindicationType;
1829          ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationType = ricSubscriptionInfo->actionSequence[0].type;
1830
1831          idx++;
1832          ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationHeader;
1833          ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1834          ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1835                                                                         RICindication_IEs__value_PR_RICindicationHeader;
1836          ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size = 3 *
1837             sizeof(uint8_t);
1838          DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf ,\
1839                ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
1840          if(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf == NULLP)
1841          {
1842             DU_LOG("\nERROR  -->  E2AP : Memory allocation for RICindicationIEs failed");
1843             ret = RFAILED;
1844          }
1845          else
1846          {
1847             buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
1848                   ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf);
1849             idx++;
1850             /* TO BE CHANGED: RIC INDICATION DATA */
1851             /* For now filling a dummy octect data, need to tested with PRBs*/
1852             ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationMessage;
1853             ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1854             ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1855                                                                            RICindication_IEs__value_PR_RICindicationMessage;
1856             ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size = 3 *
1857                sizeof(uint8_t);
1858             DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf ,\
1859                   ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
1860             if(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf == NULLP)
1861             {
1862                DU_LOG("\nERROR  -->  E2AP : Memory allocation for RICindicationIEs failed");
1863                ret = RFAILED;
1864             }
1865             else
1866             {
1867                buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
1868                      ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf);
1869             }
1870          }
1871       }
1872    }
1873    return ret;
1874 }
1875
1876 /*******************************************************************
1877  *
1878  * @brief Builds and Send the RicIndication Message
1879  *
1880  * @details
1881  *
1882  *    Function : BuildAndSendRicIndication
1883  *
1884  * Functionality:Fills the RicIndication Message
1885  *
1886  * @return ROK     - success
1887  *         RFAILED - failure
1888  *
1889  ******************************************************************/
1890
1891 uint8_t BuildAndSendRicIndication(RicSubscription *ricSubscriptionInfo)
1892 {
1893    E2AP_PDU_t                 *e2apMsg = NULLP;
1894    RICindication_t            *ricIndicationMsg=NULLP;
1895    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1896    uint8_t ret = RFAILED; 
1897    uint8_t FillRicIndicationret = ROK;
1898
1899    while(true)
1900    {
1901       DU_LOG("\nINFO   -->  E2AP : Building RIC Indication Message\n");
1902
1903       DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
1904       if(e2apMsg == NULLP)
1905       {
1906          DU_LOG("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
1907          break;
1908       }
1909
1910       e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
1911       DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1912       if(e2apMsg->choice.initiatingMessage == NULLP)
1913       {
1914          DU_LOG("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
1915          break;
1916       }
1917       e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICindication;
1918       e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
1919       e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICindication;
1920
1921       ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
1922
1923       FillRicIndicationret = FillRicIndication(ricIndicationMsg, ricSubscriptionInfo);
1924       if(FillRicIndicationret != ROK)
1925       {
1926          break;
1927       }
1928       /* Prints the Msg formed */
1929       xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1930       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1931       encBufSize = 0;
1932       encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
1933             encBuf);
1934       if(encRetVal.encoded == ENCODE_FAIL)
1935       {
1936          DU_LOG("\nERROR  -->  E2AP : Could not encode RIC Indication Message (at %s)\n",\
1937                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1938          break;
1939       }
1940       else
1941       {
1942          DU_LOG("\nDEBUG  -->  E2AP : Created APER encoded buffer for RIC Indication Message \n");
1943 #ifdef DEBUG_ASN_PRINT
1944          for(int i=0; i< encBufSize; i++)
1945          {
1946             printf("%x",encBuf[i]);
1947          } 
1948 #endif
1949       }
1950
1951       if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
1952       {
1953          DU_LOG("\nINFO   -->  E2AP : Sending RIC Indication Message");      
1954
1955       }
1956       ret = ROK;
1957       break;
1958    }
1959    FreeRicIndication(e2apMsg);  
1960    return ret;
1961 }
1962
1963 /*******************************************************************
1964  *
1965  * @brief Deallocate the memory allocated for E2nodeConfigurationUpdate msg 
1966  *
1967  * @details
1968  *
1969  *    Function : FreeE2NodeConfigUpdate 
1970  *
1971  *    Functionality:
1972  *       - freeing the memory allocated for E2nodeConfigurationUpdate
1973  *
1974  * @params[in] E2AP_PDU_t *e2apMsg 
1975  * @return ROK     - success
1976  *         RFAILED - failure
1977  *
1978  * ****************************************************************/
1979 void FreeE2NodeConfigUpdate(E2AP_PDU_t *e2apMsg)
1980 {
1981    uint8_t arrIdx =0;
1982    E2nodeConfigurationUpdate_t *e2NodeConfigUpdate;
1983
1984    if(e2apMsg != NULLP)
1985    {
1986       if(e2apMsg->choice.initiatingMessage != NULLP)
1987       {
1988          e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
1989          if(e2NodeConfigUpdate->protocolIEs.list.array != NULLP)
1990          {
1991             for(arrIdx = 0; arrIdx < e2NodeConfigUpdate->protocolIEs.list.count; arrIdx++)
1992             {
1993                DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
1994             }
1995             DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size);
1996          }
1997          DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1998       }
1999       DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2000    }
2001 }
2002
2003 /*******************************************************************
2004  *
2005  * @brief Buld and send the E2 node config update msg 
2006  *
2007  * @details
2008  *
2009  *    Function : BuildAndSendE2NodeConfigUpdate
2010  *
2011  *    Functionality:
2012  *         - Buld and send the E2 node config update msg
2013  *
2014  * @params[in] 
2015  * @return ROK     - success
2016  *         RFAILED - failure
2017  *
2018  * ****************************************************************/
2019
2020 uint8_t BuildAndSendE2NodeConfigUpdate()
2021 {
2022    uint8_t arrIdx = 0,elementCnt = 1;
2023    uint8_t ret = ROK;
2024    E2AP_PDU_t        *e2apMsg = NULLP;
2025    E2nodeConfigurationUpdate_t *e2NodeConfigUpdate = NULLP;
2026    asn_enc_rval_t     encRetVal;       /* Encoder return value */
2027
2028    DU_LOG("\nINFO   -->  E2AP : Building E2 Node config update\n");
2029    do
2030    {
2031       DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2032       if(e2apMsg == NULLP)
2033       {
2034          DU_LOG("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
2035          break;
2036       }
2037       e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2038       DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2039       if(e2apMsg->choice.initiatingMessage == NULLP)
2040       {
2041          DU_LOG("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
2042          DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2043          return RFAILED;
2044       }
2045       e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2046       e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
2047       e2apMsg->choice.initiatingMessage->value.present = \
2048       InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate;
2049       e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
2050
2051       e2NodeConfigUpdate->protocolIEs.list.count = elementCnt;
2052       e2NodeConfigUpdate->protocolIEs.list.size  = elementCnt * sizeof(E2nodeConfigurationUpdate_IEs_t*);
2053       /* Initialize the Ric Indication members */
2054       DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array, \
2055             e2NodeConfigUpdate->protocolIEs.list.size);
2056       if(e2NodeConfigUpdate->protocolIEs.list.array == NULLP)
2057       {
2058          DU_LOG("\nERROR  -->  E2AP : Memory allocation for e2NodeConfigUpdate failed");
2059          break;
2060       }
2061       
2062       for(arrIdx =0; arrIdx<elementCnt; arrIdx++)
2063       {
2064          DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
2065          if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx] == NULLP)
2066          {
2067             
2068             DU_LOG("\nERROR  -->  E2AP : Memory allocation for e2NodeConfigUpdate failed");
2069             break;
2070          }
2071       }
2072
2073       arrIdx = 0;
2074       /* TransactionID */
2075       e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2076       e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2077       e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_TransactionID;
2078       e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = TRANS_ID;
2079
2080
2081       /* Prints the Msg formed */
2082       xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2083
2084       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2085       encBufSize = 0;
2086       encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
2087             encBuf);
2088       if(encRetVal.encoded == ENCODE_FAIL)
2089       {
2090          DU_LOG("\nERROR  -->  E2AP : Could not encode E2nodeConfigurationUpdate structure (at %s)\n",\
2091                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2092          break;
2093       }
2094       else
2095       {
2096          DU_LOG("\nDEBUG   -->  E2AP : Created APER encoded buffer for E2nodeConfigurationUpdate\n");
2097 #ifdef DEBUG_ASN_PRINT
2098          for(int i=0; i< encBufSize; i++)
2099          {
2100             printf("%x",encBuf[i]);
2101          }
2102 #endif
2103       }
2104       if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize))
2105       {
2106          DU_LOG("\nERROR  -->  E2AP : Sending E2 node config update failed");
2107          return RFAILED;
2108       }
2109
2110       break;
2111    }while(true);
2112    
2113    FreeE2NodeConfigUpdate(e2apMsg);
2114    return ret;
2115 }
2116
2117 /*******************************************************************
2118  *
2119  * @brief Deallocate the memory allocated for E2ResetRequest msg
2120  *
2121  * @details
2122  *
2123  *    Function : FreeE2ResetRequest
2124  *
2125  *    Functionality:
2126  *       - freeing the memory allocated for E2ResetRequest
2127  *
2128  * @params[in] E2AP_PDU_t *e2apMsg
2129  * @return ROK     - success
2130  *         RFAILED - failure
2131  *
2132  * ****************************************************************/
2133 void FreeE2ResetRequest(E2AP_PDU_t *e2apMsg)
2134 {
2135    uint8_t ieIdx =0;
2136    ResetRequestE2_t  *resetReq = NULLP;
2137
2138    if(e2apMsg != NULLP)
2139    {
2140       if(e2apMsg->choice.initiatingMessage != NULLP)
2141       {
2142          resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
2143          if(resetReq->protocolIEs.list.array)
2144          {
2145             for(ieIdx = 0; ieIdx < resetReq->protocolIEs.list.count; ieIdx++)
2146             {
2147                DU_FREE(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
2148             }
2149             DU_FREE(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
2150          }
2151          DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2152       }
2153       DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2154    }
2155 }
2156
2157 /*******************************************************************
2158  *
2159  * @brief Build and send the E2 reset request msg
2160  *
2161  * @details
2162  *
2163  *    Function : BuildAndSendE2ResetRequest
2164  *
2165  *    Functionality:
2166  *         - Buld and send the E2 reset request msg to RIC
2167  *
2168  * @params[in]
2169  * @return ROK     - success
2170  *         RFAILED - failure
2171  *
2172  * ****************************************************************/
2173 uint8_t BuildAndSendE2ResetRequest(E2CauseType failureType, E2Cause failureCause)
2174 {
2175    uint8_t ieIdx = 0, elementCnt = 0, transId = 0;
2176    uint8_t ret = RFAILED;
2177    E2AP_PDU_t        *e2apMsg = NULLP;
2178    ResetRequestE2_t  *resetReq = NULLP;
2179    asn_enc_rval_t     encRetVal;       /* Encoder return value */
2180
2181    DU_LOG("\nINFO   -->  E2AP : Building E2 Reset Request\n");
2182
2183    do
2184    {
2185       DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2186       if(e2apMsg == NULLP)
2187       {
2188          DU_LOG("\nERROR  -->  E2AP : BuildAndSendE2ResetRequest(): Memory allocation for E2AP-PDU failed");
2189          break;
2190       }
2191
2192       e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2193       DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2194       if(e2apMsg->choice.initiatingMessage == NULLP)
2195       {
2196          DU_LOG("\nERROR  -->  E2AP : BuildAndSendE2ResetRequest(): Memory allocation for initiatingMessage");
2197          break;
2198       }
2199
2200       e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_Reset;
2201       e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2202       e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ResetRequestE2;
2203       resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
2204
2205       elementCnt = 2;
2206       resetReq->protocolIEs.list.count = elementCnt;
2207       resetReq->protocolIEs.list.size = elementCnt * sizeof(ResetRequestIEs_t *);
2208
2209       DU_ALLOC(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
2210       if(!resetReq->protocolIEs.list.array)
2211       {
2212          DU_LOG("\nERROR  -->  E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
2213             Reset Request IE array");
2214          break;
2215       }
2216
2217       for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
2218       {
2219          DU_ALLOC(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
2220          if(!resetReq->protocolIEs.list.array[ieIdx])
2221          {
2222             DU_LOG("\nERROR  -->  E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
2223             Reset Request IE array element");
2224             break;
2225          }
2226       }
2227
2228       /* In case of failure */
2229       if(ieIdx < elementCnt)
2230          break;
2231
2232       ieIdx = 0;
2233       resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2234       resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
2235       resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_TransactionID;
2236       transId = assignTransactionId();
2237       resetReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
2238
2239       ieIdx++;
2240       resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_CauseE2;
2241       resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_ignore;
2242       resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_CauseE2;
2243       resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.present = failureType;
2244       switch(resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.present)
2245       {
2246          case CauseE2_PR_NOTHING:
2247             break;
2248          case CauseE2_PR_ricRequest:
2249             resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.ricRequest = failureCause;
2250             break;
2251          case CauseE2_PR_ricService:
2252             resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.ricService = failureCause;
2253             break;
2254          case CauseE2_PR_e2Node:
2255             resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.e2Node = failureCause;
2256             break;
2257          case CauseE2_PR_transport:
2258             resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.transport = failureCause;
2259             break;
2260          case CauseE2_PR_protocol:
2261             resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.protocol = failureCause;
2262             break;
2263          case CauseE2_PR_misc:
2264             resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.misc = failureCause;
2265             break;
2266       }
2267
2268       /* Prints the Msg formed */
2269       xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2270
2271       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2272       encBufSize = 0;
2273       encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
2274             encBuf);
2275       if(encRetVal.encoded == ENCODE_FAIL)
2276       {
2277          DU_LOG("\nERROR  -->  E2AP : Could not encode E2SetupRequest structure (at %s)\n",\
2278                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2279          break;
2280       }
2281       else
2282       {
2283          DU_LOG("\nDEBUG   -->  E2AP : Created APER encoded buffer for E2SetupRequest\n");
2284 #ifdef DEBUG_ASN_PRINT
2285          for(int i=0; i< encBufSize; i++)
2286          {
2287             printf("%x",encBuf[i]);
2288          }
2289 #endif
2290       }
2291       if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
2292       {
2293          DU_LOG("\nERROR  -->  E2AP : Sending E2 Setup request failed");
2294          break;
2295       }
2296
2297       /* In case the message is sent successfully, store the transaction info to
2298        * be used when response is received */
2299       duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].transactionId = transId;
2300       duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
2301
2302       ret = ROK;
2303       break;
2304    }while(true);
2305
2306    /* Free all memory */
2307    FreeE2ResetRequest(e2apMsg);
2308    return ret;
2309 }
2310
2311 /*******************************************************************
2312  *
2313  * @brief Deallocate the memory allocated for Reset Response msg
2314  *
2315  * @details
2316  *
2317  *    Function : freeAperDecodingOfE2ResetRsp
2318  *
2319  *    Functionality:
2320  *       - freeing the memory allocated for Reset response
2321  *
2322  * @params[in] ResetResponseE2_t *resetResponse
2323  * @return void
2324  *
2325  * ****************************************************************/
2326 void freeAperDecodingOfE2ResetRsp(ResetResponseE2_t *resetResponse)
2327 {
2328    uint8_t ieIdx;
2329
2330    if(resetResponse)
2331    {
2332       if(resetResponse->protocolIEs.list.array)
2333       {
2334          for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
2335          {
2336             if(resetResponse->protocolIEs.list.array[ieIdx])
2337             {
2338                switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
2339                {
2340                   case ProtocolIE_IDE2_id_TransactionID:
2341                      break;
2342
2343                   case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
2344                      break;
2345                }
2346                free(resetResponse->protocolIEs.list.array[ieIdx]);
2347             }
2348          }
2349          free(resetResponse->protocolIEs.list.array);
2350       }
2351    }
2352 }
2353
2354 /******************************************************************
2355  *
2356  * @brief Processes E2 Reset Response sent by RIC
2357  *
2358  * @details
2359  *
2360  *    Function : procResetResponse
2361  *
2362  *    Functionality: Processes E2 Reset Response sent by RIC
2363  *
2364  * @params[in] E2AP_PDU_t ASN decoded E2AP message
2365  * @return ROK     - success
2366  *         RFAILED - failure
2367  *
2368  * ****************************************************************/
2369 uint8_t procResetResponse(E2AP_PDU_t *e2apMsg)
2370 {
2371    uint8_t ieIdx =0, transId;
2372    ResetResponseE2_t *resetResponse;
2373
2374    DU_LOG("\nINFO   -->  E2AP : E2 Reset Response received");
2375    resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;;
2376
2377    for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
2378    {
2379       switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
2380       {
2381          case ProtocolIE_IDE2_id_TransactionID:
2382             transId = resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
2383             if((duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].transactionId == transId) && \
2384                   (duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
2385               memset(&duCb.e2apDb.e2TransInfo.onGoingTransaction[transId], 0, sizeof(E2TransInfo));
2386             else
2387             {
2388                DU_LOG("\nERROR  -->  E2AP : Invalid transaction id [%d]", transId);
2389                return RFAILED;
2390             }
2391             break;
2392          case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
2393             /* As per ORAN WG3 E2AP spec v3.0, section 9.2.2
2394                Criticality Diagnostics IE is sent by Near-RT RIC when parts of a received message i.e. 
2395                Reset Request in this case, have not been comprehended or were missing, or if the message 
2396                contained logical errors.
2397
2398                Processing of this ID should be implemented when negative call flows are to be supported.
2399              */
2400             break;
2401          default:
2402             DU_LOG("\nERROR  -->  E2AP : Invalid IE received in E2 Reset Response : %ld",
2403                   resetResponse->protocolIEs.list.array[ieIdx]->id);
2404             break;
2405       }
2406    }
2407
2408    freeAperDecodingOfE2ResetRsp(resetResponse);
2409    return ROK;
2410 }
2411
2412 /******************************************************************
2413  *
2414  * @brief Deallocation of memory allocated bu aper decoder for e2 setup Failure
2415  *
2416  * @details
2417  *
2418  *    Function : freeAperDecodingOfE2SetupFailure
2419  *
2420  *    Functionality: Deallocation of memory allocated bu aper decoder for e2
2421  *    setup Failure
2422  *
2423  * @params[in] E2setupFailure_t *e2SetupFailure;
2424  * @return void
2425  *
2426  * ****************************************************************/
2427 void freeAperDecodingOfE2SetupFailure(E2setupFailure_t *e2SetupFailure)
2428 {
2429    uint8_t arrIdx;
2430
2431    if(e2SetupFailure)
2432    {
2433       if(e2SetupFailure->protocolIEs.list.array)
2434       {
2435          for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
2436          {
2437             if(e2SetupFailure->protocolIEs.list.array[arrIdx])
2438             {
2439                free(e2SetupFailure->protocolIEs.list.array[arrIdx]);  
2440             }
2441          }
2442          free(e2SetupFailure->protocolIEs.list.array);
2443       }
2444    }
2445 }
2446 /******************************************************************
2447  *
2448  * @brief Processes E2 Setup Failure sent by RIC
2449  *
2450  * @details
2451  *
2452  *    Function : procE2SetupFailure
2453  *
2454  *    Functionality: Processes E2 Setup failure sent by RIC
2455  *
2456  * @params[in] E2AP_PDU_t ASN decoded E2AP message
2457  * @return ROK     - success
2458  *         RFAILED - failure
2459  *
2460  * ****************************************************************/
2461 void procE2SetupFailure(E2AP_PDU_t *e2apMsg)
2462 {
2463    uint8_t arrIdx =0, transId =0, timerValue=0; 
2464    E2setupFailure_t *e2SetupFailure;
2465
2466    DU_LOG("\nINFO   -->  E2AP : E2 Setup failure received"); 
2467    e2SetupFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure;
2468
2469    for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
2470    {
2471       switch(e2SetupFailure->protocolIEs.list.array[arrIdx]->id)
2472       {
2473          case ProtocolIE_IDE2_id_TransactionID:
2474          {
2475             transId = e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
2476             if((duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].transactionId == transId) &&\
2477             (duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
2478               memset(&duCb.e2apDb.e2TransInfo.onGoingTransaction[transId], 0, sizeof(E2TransInfo));
2479             else
2480             {
2481                DU_LOG("\nERROR  -->  E2AP : Invalid transaction id [%d]", transId);
2482                return ;
2483             }
2484             break;
2485          }
2486          case ProtocolIE_IDE2_id_TimeToWaitE2:
2487             {
2488                timerValue = covertE2WaitTimerEnumToValue(e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
2489                if((duChkTmr((PTR)&(duCb.e2apDb), EVENT_E2_SETUP_TMR)) == FALSE)
2490                {
2491                   duStartTmr((PTR)&(duCb.e2apDb), EVENT_E2_SETUP_TMR, timerValue);
2492                }
2493                else
2494                {
2495                   DU_LOG("\nERROR   -->  E2AP : EVENT_E2_SETUP_TMR timer is already running");
2496                   return;
2497                }
2498                break; 
2499             }
2500       }
2501    }
2502
2503    freeAperDecodingOfE2SetupFailure(e2SetupFailure);
2504 }
2505 /*******************************************************************
2506  *
2507  * @brief Handles received E2AP message and sends back response  
2508  *
2509  * @details
2510  *
2511  *    Function : E2APMsgHdlr
2512  *
2513  *    Functionality:
2514  *         - Decodes received E2AP control message
2515  *         - Prepares response message, encodes and sends to SCTP
2516  *
2517  * @params[in] 
2518  * @return ROK     - success
2519  *         RFAILED - failure
2520  *
2521  * ****************************************************************/
2522 void E2APMsgHdlr(Buffer *mBuf)
2523 {
2524    int i =0;
2525    char *recvBuf = NULLP;
2526    MsgLen copyCnt =0;
2527    MsgLen recvBufLen =0;
2528    E2AP_PDU_t *e2apMsg = NULLP;
2529    asn_dec_rval_t rval ={0}; /* Decoder return value */
2530    E2AP_PDU_t e2apasnmsg={0} ;
2531
2532    DU_LOG("\nDEBUG   -->  E2AP : Received E2AP message buffer");
2533    ODU_PRINT_MSG(mBuf, 0,0);
2534
2535    /* Copy mBuf into char array to decode it */
2536    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
2537    DU_ALLOC(recvBuf, (Size)recvBufLen);
2538
2539    if(recvBuf == NULLP)
2540    {
2541       DU_LOG("\nERROR  -->  E2AP : Memory allocation failed");
2542       return;
2543    }
2544    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
2545    {
2546       DU_LOG("\nERROR  -->  E2AP : Failed while copying %d", copyCnt);
2547       return;
2548    }
2549
2550 #ifdef DEBUG_ASN_PRINT
2551    printf("\nDEBUG   -->  E2AP : Received flat buffer to be decoded : ");
2552    for(i=0; i< recvBufLen; i++)
2553    {
2554       printf("%x",recvBuf[i]);
2555    }
2556 #endif
2557
2558    /* Decoding flat buffer into E2AP messsage */
2559    e2apMsg = &e2apasnmsg;
2560    memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
2561
2562    rval = aper_decode(0, &asn_DEF_E2AP_PDU, (void **)&e2apMsg, recvBuf, recvBufLen, 0, 0);
2563    DU_FREE(recvBuf, (Size)recvBufLen);
2564
2565    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
2566    {
2567       DU_LOG("\nERROR  -->  E2AP : ASN decode failed");
2568       return;
2569    }
2570    printf("\n");
2571    xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2572
2573    switch(e2apMsg->present)
2574    {
2575       case E2AP_PDU_PR_unsuccessfulOutcome:
2576          {
2577             switch(e2apMsg->choice.unsuccessfulOutcome->value.present)
2578             {
2579                case UnsuccessfulOutcomeE2__value_PR_E2setupFailure:
2580                   {
2581                      procE2SetupFailure(e2apMsg);
2582                      break;
2583                   }
2584                default:
2585                   {
2586                      DU_LOG("\nERROR  -->  E2AP : Invalid type of E2AP_PDU_PR_unsuccessfulOutcome  [%d]",\
2587                            e2apMsg->choice.unsuccessfulOutcome->value.present);
2588                      return;
2589                   }
2590             }
2591             break;
2592          }
2593       case E2AP_PDU_PR_successfulOutcome:
2594          {
2595             switch(e2apMsg->choice.successfulOutcome->value.present)
2596             {
2597                case SuccessfulOutcomeE2__value_PR_E2setupResponse:
2598                   {
2599                      if(!duCb.e2Status)
2600                      {
2601                         procE2SetupRsp(e2apMsg);
2602                      }
2603                      break;
2604                   }
2605                case SuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateAcknowledge:
2606                   {
2607                      DU_LOG("\nDEBUG   -->  E2AP : E2 node Config update ack message recevied");
2608                      break;
2609                   }
2610                case SuccessfulOutcomeE2__value_PR_ResetResponseE2:
2611                   {
2612                      procResetResponse(e2apMsg);
2613                      break;
2614                   }
2615                default:
2616                   {
2617                      DU_LOG("\nERROR  -->  E2AP : Invalid type of E2AP_PDU_PR_successfulOutcome  [%d]",\
2618                            e2apMsg->choice.successfulOutcome->value.present);
2619                      return;
2620                   }
2621             }/* End of switch(successfulOutcome) */
2622             free(e2apMsg->choice.successfulOutcome);
2623             break;
2624          }
2625
2626       case E2AP_PDU_PR_initiatingMessage:
2627          {
2628             switch(e2apMsg->choice.initiatingMessage->value.present)
2629             {
2630                case InitiatingMessageE2__value_PR_RICsubscriptionRequest: 
2631                   {
2632                      procRicSubsReq(e2apMsg);
2633                      break;
2634                   }
2635                default:
2636                   {
2637                      DU_LOG("\nERROR  -->  E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\
2638                            e2apMsg->choice.initiatingMessage->value.present);
2639                      return;
2640                   }
2641             }/* End of switch(initiatingMessage) */
2642             free(e2apMsg->choice.initiatingMessage);
2643             break;
2644          }
2645       default:
2646          {
2647             DU_LOG("\nERROR  -->  E2AP : Invalid type of e2apMsg->present [%d]",e2apMsg->present);
2648             return;
2649          }
2650          free(e2apMsg);
2651
2652    }/* End of switch(e2apMsg->present) */
2653
2654 } /* End of E2APMsgHdlr */
2655
2656 /**********************************************************************
2657   End of file
2658  **********************************************************************/