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