[Epic-ID: ODUHIGH-516][Task-ID: ODUHIGH-523] Statistics Request API and Timer Based...
[o-du/l2.git] / src / du_app / du_e2ap_msg_hdl.c
index e048d6d..d528b51 100644 (file)
@@ -16,6 +16,7 @@
 ################################################################################
 *******************************************************************************/
 #include "common_def.h"
+#include "du_tmr.h"
 #include "lrg.h"
 #include "lkw.x"
 #include "lrg.x"
 #include "E2setupRequest.h"
 #include "InitiatingMessageE2.h"
 #include "SuccessfulOutcomeE2.h"
+#include "UnsuccessfulOutcomeE2.h"
 #include "E2AP-PDU.h"
 #include "odu_common_codec.h"
 #include "E2nodeComponentInterfaceF1.h"
 #include "E2setupRequest.h"
+#include "du_e2_conversions.h"
+#include "E2SM-KPM-RANfunction-Description.h"
+#include "RANfunction-Name.h"
+#include "RIC-EventTriggerStyle-Item.h"
+#include "RIC-ReportStyle-Item.h"
+#include "MeasurementInfo-Action-Item.h"
 
 /*******************************************************************
  *
@@ -58,10 +66,10 @@ uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
 {
    uint8_t unused = 0;
    uint8_t byteSize = 4;
-   uint8_t gnbId = 1;
+   uint8_t gnbId = duCb.gnbId;
    uint8_t ret = ROK;
 
-   /* Allocate Buffer size */
+   /* fill Global gNB ID Id */
    gNbId->global_gNB_ID.plmn_id.size = 3 * sizeof(uint8_t);
    gNbId->global_gNB_ID.plmn_id.buf = NULLP;
    DU_ALLOC(gNbId->global_gNB_ID.plmn_id.buf , gNbId->global_gNB_ID.plmn_id.size);
@@ -74,7 +82,6 @@ uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
    {
       buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
             gNbId->global_gNB_ID.plmn_id.buf);
-      /* fill gND Id */
       gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
       /* Allocate Buffer size */
       gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = byteSize * sizeof(uint8_t);
@@ -91,9 +98,67 @@ uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
          fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, gnbId);
       }
    }
+
+   /* fill gNB-DU ID */ 
+   DU_ALLOC( gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
+   if(gNbId->gNB_DU_ID == NULLP)
+   {
+      DU_LOG("\nERROR  -->  E2AP: Memory allocation failed for gNB_DU_ID ");
+      ret = RFAILED;
+   }
+   else
+   {
+      gNbId->gNB_DU_ID->size = sizeof(uint8_t);
+      DU_ALLOC( gNbId->gNB_DU_ID->buf, sizeof(uint8_t));
+      if(gNbId->gNB_DU_ID->buf)
+      {
+         gNbId->gNB_DU_ID->buf[0] =duCb.e2apDb.e2NodeId;
+      }
+      else
+      {
+         DU_LOG("\nERROR  -->  E2AP: Memory allocation failed for gNB_DU_ID buffer");
+         ret = RFAILED;
+      }
+   }
+
    return ret;
 }
 
+/******************************************************************
+ *
+ * @brief Search E2 node component with the help of action type
+ *
+ * @details
+ *
+ *    Function : searchE2NodeComponentInfo 
+ *
+ *    Functionality: Search E2 node component with the help of action type 
+ *
+ * @params[in] uint8_t componentActionType
+ * @return CmLList
+ *
+ * ****************************************************************/
+
+CmLList *searchE2NodeComponentInfo(InterfaceType interfaceType, uint8_t componentActionType)
+{
+   E2NodeComponent *e2NodeComponentInfo;
+   CmLList         *node;
+
+   if(duCb.e2apDb.e2NodeComponentList.count)
+   {
+      CM_LLIST_FIRST_NODE(&duCb.e2apDb.e2NodeComponentList, node);
+      while(node)
+      {
+         e2NodeComponentInfo = (E2NodeComponent*)node->node;
+         if((e2NodeComponentInfo->interfaceType == interfaceType) && (e2NodeComponentInfo->componentActionType == componentActionType))
+            break;
+         else
+            node = node->next;
+      }
+   }
+   return node; 
+}
+
 /*******************************************************************
  *
  * @brief Builds E2 node config addition list 
@@ -113,6 +178,8 @@ uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
 uint8_t BuildE2NodeConfigAddList(E2nodeComponentConfigAddition_List_t *e2NodeAddList)
 {
    uint8_t arrIdx = 0;
+   CmLList         *node;
+   E2NodeComponent *e2NodeComponentInfo;
    E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItemIe;
    E2nodeComponentConfigAddition_Item_t *e2NodeAddItem;
 
@@ -134,7 +201,15 @@ uint8_t BuildE2NodeConfigAddList(E2nodeComponentConfigAddition_List_t *e2NodeAdd
          return RFAILED;
       }
    }
-
+   
+   node = searchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD);
+   if(!node)
+   {
+      DU_LOG("\nERROR  --> E2AP : Received e2NodeComponentInfo is null");
+      return RFAILED;
+   }
+   e2NodeComponentInfo = (E2NodeComponent*)node->node;
+   
    arrIdx = 0;
    e2NodeAddItemIe = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[arrIdx];
    e2NodeAddItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition_Item;
@@ -146,34 +221,49 @@ uint8_t BuildE2NodeConfigAddList(E2nodeComponentConfigAddition_List_t *e2NodeAdd
    e2NodeAddItem->e2nodeComponentInterfaceType = E2nodeComponentInterfaceType_f1;
 
    /* E2 Node Component Request Part */
-   e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size = duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize;
-   DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
-   e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
-   if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf == NULLP)
+   if(e2NodeComponentInfo->componentRequestPart)
+   {
+      e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size = e2NodeComponentInfo->reqBufSize ;
+      DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
+            e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
+      if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf == NULLP)
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
+         return RFAILED;
+      }
+
+      memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
+            e2NodeComponentInfo->componentRequestPart, e2NodeAddItem->e2nodeComponentConfiguration.\
+            e2nodeComponentRequestPart.size);
+   }
+   else
    {
-      DU_LOG("\nERROR  --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
+      DU_LOG("\nERROR  --> E2AP: componentRequestPart is null ");
       return RFAILED;
    }
 
-   memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
-   duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, e2NodeAddItem->e2nodeComponentConfiguration.\
-   e2nodeComponentRequestPart.size);
-   DU_FREE(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf,duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize);
-  
+
    /* E2 Node Component Response Part */
-   e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size = duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize; 
-   DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \
-   e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
-   if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf == NULLP)
+   if(e2NodeComponentInfo->componentResponsePart)
    {
-      DU_LOG("\nERROR  --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
+      e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size = e2NodeComponentInfo->rspBufSize; 
+      DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \
+            e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
+      if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf == NULLP)
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
+         return RFAILED;
+      }
+      memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \
+            e2NodeComponentInfo->componentResponsePart, e2NodeAddItem->e2nodeComponentConfiguration.\
+            e2nodeComponentResponsePart.size);
+   }
+   else
+   {
+      DU_LOG("\nERROR  --> E2AP: componentResponsePart is null");
       return RFAILED;
    }
-   memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \
-   duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, e2NodeAddItem->e2nodeComponentConfiguration.\
-   e2nodeComponentResponsePart.size);
-   DU_FREE(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize);
-
+   
    /* E2 Node Component ID */
    e2NodeAddItem->e2nodeComponentID.present = E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1;
    DU_ALLOC(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
@@ -192,114 +282,450 @@ uint8_t BuildE2NodeConfigAddList(E2nodeComponentConfigAddition_List_t *e2NodeAdd
       DU_LOG("\nERROR  -->list.  E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
       return RFAILED;
    }
-   e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[arrIdx]  = duCfgParam.duId;
+   e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[arrIdx]  = e2NodeComponentInfo->componentId;
    return ROK;
 
 }
 
 /*******************************************************************
  *
- * @brief Fills the initiating IE for E2 Setup Request
+ * @brief deallocation of E2SM_KPM_RANfunction_Description_t
+ *
+ * @details
+ *
+ *    Function : freeE2smKpmRanFunctionDefinition
+ *
+ *    Functionality: deallocation of E2SM_KPM_RANfunction_Description_t
+ *
+ * @params[in]  E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition
+ * @return void
+ *
+ ******************************************************************/
+
+void freeE2smKpmRanFunctionDefinition(E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition)
+{
+   MeasurementInfo_Action_Item_t *measInfoList;
+   uint8_t eventTriggerIdx, reportStyleIdx, measInfoIdx;
+   RANfunction_Name_t *ranFuncName;
+   struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle;
+   struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *eventTriggerStyle;
+   if(ranFunctionDefinition)
+   {
+      ranFuncName = &ranFunctionDefinition->ranFunction_Name;
+      /* Free RAN function Name */     
+      DU_FREE(ranFuncName->ranFunction_ShortName.buf,  ranFuncName->ranFunction_ShortName.size);
+      DU_FREE(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
+      DU_FREE(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
+
+      /* Sequence of Event Trigger styles */
+      eventTriggerStyle = ranFunctionDefinition->ric_EventTriggerStyle_List;
+      if(eventTriggerStyle)
+      {
+         if(eventTriggerStyle->list.array)
+         {
+            for(eventTriggerIdx =0;eventTriggerIdx<eventTriggerStyle->list.count; eventTriggerIdx++)
+            {
+               if(eventTriggerStyle->list.array[eventTriggerIdx])
+               {
+                  DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.buf,\
+                        eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.size);
+                  DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
+               }
+            }
+            DU_FREE(eventTriggerStyle->list.array, eventTriggerStyle->list.size)
+         }
+         DU_FREE(eventTriggerStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
+      }
+      
+      /* Sequence of Report styles */
+      ricReportStyle = ranFunctionDefinition->ric_ReportStyle_List;
+      if(ricReportStyle)
+      {
+         if(ricReportStyle->list.array)
+         {
+            for(reportStyleIdx =0;reportStyleIdx<ricReportStyle->list.count; reportStyleIdx++)
+            {
+               if(ricReportStyle->list.array[reportStyleIdx])
+               {
+                  if(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf)
+                  {
+                     DU_FREE(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf,\
+                           ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.size);
+                  }
+                  if(ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array)
+                  {
+                     for(measInfoIdx=0; measInfoIdx<ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.count; \
+                           measInfoIdx++)
+                     {
+                        measInfoList = ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array[measInfoIdx];
+                        if(measInfoList)
+                        {
+                           DU_FREE(measInfoList->measID, sizeof(long));
+                           DU_FREE(measInfoList->measName.buf, measInfoList->measName.size);
+                           DU_FREE(measInfoList,sizeof(MeasurementInfo_Action_Item_t)); 
+                        }
+                     }
+                     DU_FREE(measInfoList,ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.size);
+                  }
+                  DU_FREE(ricReportStyle->list.array[reportStyleIdx], sizeof(RIC_ReportStyle_Item_t));
+               }
+            }
+            DU_FREE(ricReportStyle->list.array, ricReportStyle->list.size);
+         }
+         DU_FREE(ricReportStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
+      }
+      DU_FREE(ranFunctionDefinition, sizeof(E2SM_KPM_RANfunction_Description_t)); 
+   }
+}
+
+/*******************************************************************
+ *
+ * @brief fill the e2sm ric report style
  *
  * @details
  *
- *    Function : fillE2SetupReq
+ *    Function : fillRicReportStyle
  *
- * Functionality:Fills the Initiating message for
- *               E2SetupRequest
+ *    Functionality: fill the report style
  *
- * @params[in] E2setupRequest_t *e2SetupReq,
- *             uint8_t *idx
+ * @params[in]   RanFunction *ranFuncDb, struct
+ * E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle
  * @return ROK     - success
  *         RFAILED - failure
  *
  ******************************************************************/
-
-uint8_t fillE2SetupReq(E2setupRequest_t **e2SetupReq, uint8_t *idx)
+uint8_t fillRicReportStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle)
 {
-   uint8_t elementCnt = 0;
-   uint8_t arrIdx = 0;
-   uint8_t ret = ROK;
+   uint8_t styleIdx, measInfoIdx;
+   MeasurementInfo_Action_List_t *measInfo;
+   CmLList  *node;
+   
+   ricReportStyle->list.count = ranFuncDb->numOfReportStyleSupported;
+   ricReportStyle->list.size = ricReportStyle->list.count * sizeof(RIC_ReportStyle_Item_t*);
+   DU_ALLOC(ricReportStyle->list.array, ricReportStyle->list.size);
+   if(!ricReportStyle->list.array)
+   {
+      DU_LOG("\nERROR  --> E2AP: Memory allocation failed for ranFuncDefinition %d",__LINE__);
+      return RFAILED;
+   }
 
-   if(*e2SetupReq != NULLP)
+   for(styleIdx =0;styleIdx<ricReportStyle->list.count; styleIdx++)
    {
-      elementCnt = 3;
-      (*e2SetupReq)->protocolIEs.list.count = elementCnt;
-      (*e2SetupReq)->protocolIEs.list.size = elementCnt * sizeof(E2setupRequestIEs_t*);
+      DU_ALLOC(ricReportStyle->list.array[styleIdx], sizeof(RIC_ReportStyle_Item_t));
+      if(!ricReportStyle->list.array[styleIdx])
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+         return RFAILED;
+      }
+      
+      /* RIC Report Style Type */
+      ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.styleType;
+      
+      /* RIC Report Style Format Type */
+      ricReportStyle->list.array[styleIdx]->ric_ActionFormat_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.formatType;
+      
+      /* RIC Report Style Name */
+      ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size = strlen(ranFuncDb->reportStyleList[styleIdx].reportStyle.name);
+      DU_ALLOC(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf,\
+            ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
+      if(!ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf)
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+         return RFAILED;
+      }
+      memcpy(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf, ranFuncDb->reportStyleList[styleIdx].reportStyle.name,\
+            ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
 
-      /* Initialize the E2Setup members */
-      DU_ALLOC((*e2SetupReq)->protocolIEs.list.array, \
-            (*e2SetupReq)->protocolIEs.list.size);
-      if((*e2SetupReq)->protocolIEs.list.array == NULLP)
+      /* RIC Indication Header Format Type*/
+      ricReportStyle->list.array[styleIdx]->ric_IndicationHeaderFormat_Type = ranFuncDb->ricIndicationHeaderFormat;
+
+      /* RIC Indication Message Format Type*/
+      ricReportStyle->list.array[styleIdx]->ric_IndicationMessageFormat_Type = ranFuncDb->ricIndicationMessageFormat;
+      
+      /* Measurement Info Action List */
+      CmLListCp measInfoList =ranFuncDb->reportStyleList[styleIdx].measurementInfoList;
+      if(!measInfoList.count)
       {
-         DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for array elements");
+         continue;      
+      }
+
+      CM_LLIST_FIRST_NODE(&ranFuncDb->reportStyleList[styleIdx].measurementInfoList, node);
+      measInfo = &ricReportStyle->list.array[styleIdx]->measInfo_Action_List;
+
+      measInfo->list.count = measInfoList.count; 
+      measInfo->list.size =  measInfoList.count*sizeof(MeasurementInfo_Action_Item_t*);
+      DU_ALLOC(measInfo->list.array, measInfo->list.size);
+      if(!measInfo->list.array)
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
          return RFAILED;
       }
-      for(*idx = 0; *idx < elementCnt; (*idx)++)
+
+      for(measInfoIdx=0; measInfoIdx<measInfo->list.count; measInfoIdx++)
       {
-         DU_ALLOC((*e2SetupReq)->protocolIEs.list.array[*idx],\
-               sizeof(E2setupRequestIEs_t));
-         if((*e2SetupReq)->protocolIEs.list.array[*idx] == NULLP)
+         if(!node)
+         {
+            DU_LOG("\nERROR  --> E2AP: Measurement info node is null");
+            return RFAILED;
+         }
+
+         DU_ALLOC(measInfo->list.array[measInfoIdx],sizeof(MeasurementInfo_Action_Item_t));  
+         if(!measInfo->list.array[measInfoIdx])
+         {
+            DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+            return RFAILED;
+         }
+         MeasurementInfoForAction *measInfoForAction= (MeasurementInfoForAction*)node->node;
+         DU_ALLOC(measInfo->list.array[measInfoIdx]->measID, sizeof(long));
+         if(!measInfo->list.array[measInfoIdx]->measID)
+         {
+            DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+            return RFAILED;
+         }
+         
+         memcpy(measInfo->list.array[measInfoIdx]->measID, &measInfoForAction->measurementTypeId,sizeof(long));
+         measInfo->list.array[measInfoIdx]->measName.size= strlen(measInfoForAction->measurementTypeName);
+         DU_ALLOC(measInfo->list.array[measInfoIdx]->measName.buf, measInfo->list.array[measInfoIdx]->measName.size);
+         if(!measInfo->list.array[measInfoIdx]->measName.size)
          {
-            DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for arrayidx [%d]", *idx);
+            DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
             return RFAILED;
          }
+
+         memcpy(measInfo->list.array[measInfoIdx]->measName.buf, \
+               measInfoForAction->measurementTypeName,\
+               measInfo->list.array[measInfoIdx]->measName.size);
+         node = node->next;
       }
-      arrIdx = 0;
 
-      /* TransactionID */
-      (*e2SetupReq)->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
-      (*e2SetupReq)->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
-      (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
-      (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = TRANS_ID;
+   }
+   return ROK;
+}
+/*******************************************************************
+ *
+ * @brief fill the ric event trigger style
+ *
+ * @details
+ *
+ *    Function : fillRicEventTriggerStyle
+ *
+ *    Functionality: fill the ric event trigger style
+ *
+ * @params[in]   
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ ******************************************************************/
+uint8_t fillRicEventTriggerStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *ricEventTriggerStyle)
+{
+   uint8_t styleIdx;
 
-      arrIdx++;
-      /* GlobalE2node_gNB_ID */
-      (*e2SetupReq)->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_GlobalE2node_ID;
-      (*e2SetupReq)->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
-      (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
-      (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
+   ricEventTriggerStyle->list.count = ranFuncDb->numOfEventTriggerStyleSupported;
+   ricEventTriggerStyle->list.size = ricEventTriggerStyle->list.count*  sizeof(RIC_EventTriggerStyle_Item_t *);
+   DU_ALLOC(ricEventTriggerStyle->list.array, ricEventTriggerStyle->list.size);
+   if(!ricEventTriggerStyle->list.array)
+   {
+      DU_LOG("\nERROR  --> E2AP: Memory allocation failed for ric_EventTriggerStyle_List %d",__LINE__);
+      return RFAILED;
+   }
 
-      DU_ALLOC((*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.\
-            GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
-      if((*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.\
-            GlobalE2node_ID.choice.gNB == NULLP)
+   for(styleIdx =0;styleIdx<ricEventTriggerStyle->list.count; styleIdx++)
+   {
+      DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
+      if(!ricEventTriggerStyle->list.array[styleIdx])
       {
-         DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for gNbId");
-         return  RFAILED;
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+         return RFAILED;
+      }
+      ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Type = ranFuncDb->eventTriggerStyleList[styleIdx].styleType;
+
+      ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerFormat_Type = ranFuncDb->eventTriggerStyleList[styleIdx].formatType;
+
+      ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size = strlen(ranFuncDb->eventTriggerStyleList[styleIdx].name);
+      DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,\
+            ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
+      if(!ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf)
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+         return RFAILED;
+      }
+      memcpy(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,ranFuncDb->eventTriggerStyleList[styleIdx].name,\
+            ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
+   
+   }
+   return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Builds Ran function add list
+ *
+ * @details
+ *
+ *    Function : BuildRanFunctionAddList 
+ *
+ *    Functionality: Building RAN addition addition list
+ *
+ * @params[in]  RANfunctions_List_t *RANfunctions_List 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildRanFunctionAddList(RANfunctions_List_t *ranFunctionsList)
+{
+   asn_enc_rval_t encRetVal;
+   RanFunction *ranFuncDb;
+   RANfunction_Name_t *ranFuncName;
+   uint8_t ranFuncIdx;
+   RANfunction_ItemIEs_t *ranFuncItemIe;
+   RANfunction_Item_t  *ranFuncItem;
+   E2SM_KPM_RANfunction_Description_t *ranFuncDefinition;
+
+   ranFunctionsList->list.count = duCb.e2apDb.numOfRanFunction;
+   ranFunctionsList->list.size = ranFunctionsList->list.count * sizeof(RANfunction_ItemIEs_t*);
+   DU_ALLOC(ranFunctionsList->list.array, ranFunctionsList->list.size);
+   if(ranFunctionsList->list.array == NULLP)
+   {
+      DU_LOG("\nERROR  --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
+      return RFAILED;
+   }
+
+   for(ranFuncIdx = 0; ranFuncIdx< ranFunctionsList->list.count; ranFuncIdx++)
+   {
+      DU_ALLOC(ranFunctionsList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
+      if(ranFunctionsList->list.array[ranFuncIdx] == NULLP)
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
+         return RFAILED;
+      }
+
+      ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncIdx];
+      ranFuncItemIe->id = ProtocolIE_IDE2_id_RANfunction_Item;
+      ranFuncItemIe->criticality = CriticalityE2_ignore;
+      ranFuncItemIe->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
+      ranFuncItem = &ranFuncItemIe->value.choice.RANfunction_Item;
+      ranFuncDb = &duCb.e2apDb.ranFunction[ranFuncIdx];   
+      /* RAN function Id*/
+      ranFuncItem->ranFunctionID = ranFuncDb->id;
+      
+      /* RAN Function Revision*/
+      ranFuncItem->ranFunctionRevision = ranFuncDb->revisionCounter;
+      
+      /* RAN function OID*/
+      ranFuncItem->ranFunctionOID.size = strlen(ranFuncDb->name.serviceModelOID);
+      DU_ALLOC(ranFuncItem->ranFunctionOID.buf, ranFuncItem->ranFunctionOID.size);
+      if(!ranFuncItem->ranFunctionOID.buf)
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+         return RFAILED;
+      }
+      memcpy(ranFuncItem->ranFunctionOID.buf, ranFuncDb->name.serviceModelOID, ranFuncItem->ranFunctionOID.size);
+
+      /* RAN function Definition */
+      DU_ALLOC(ranFuncDefinition, sizeof(E2SM_KPM_RANfunction_Description_t));
+      if(!ranFuncDefinition)
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+         return RFAILED;
+      }
+      
+      /* RAN function Name */
+      ranFuncName = &ranFuncDefinition->ranFunction_Name;
+      
+      /* RAN function ShortName */
+      ranFuncName->ranFunction_ShortName.size = strlen(ranFuncDb->name.shortName); 
+      DU_ALLOC(ranFuncName->ranFunction_ShortName.buf,  ranFuncName->ranFunction_ShortName.size);
+      if(!ranFuncName->ranFunction_ShortName.buf)
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+         return RFAILED;
+      }
+      memcpy(ranFuncName->ranFunction_ShortName.buf, ranFuncDb->name.shortName, strlen(ranFuncDb->name.shortName));
+      
+      /* RAN function E2SM_OID */
+      ranFuncName->ranFunction_E2SM_OID.size = strlen(ranFuncDb->name.serviceModelOID);
+      DU_ALLOC(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
+      if(!ranFuncName->ranFunction_E2SM_OID.buf)
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+         return RFAILED;
+      }
+      memcpy(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncDb->name.serviceModelOID, ranFuncName->ranFunction_E2SM_OID.size);
+
+      /* RAN function Description */
+      ranFuncName->ranFunction_Description.size = strlen(ranFuncDb->name.description);
+      DU_ALLOC(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
+      if(!ranFuncName->ranFunction_Description.buf)
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+         return RFAILED;
+      }
+      memcpy(ranFuncName->ranFunction_Description.buf, ranFuncDb->name.description, ranFuncName->ranFunction_Description.size);
+      
+      /* RIC Event Trigger Style List */
+      DU_ALLOC(ranFuncDefinition->ric_EventTriggerStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
+      if(!ranFuncDefinition->ric_EventTriggerStyle_List)
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+         return RFAILED;
+      }
+      
+      if(fillRicEventTriggerStyle(ranFuncDb, ranFuncDefinition->ric_EventTriggerStyle_List)!=ROK)
+      {
+         DU_LOG("\nERROR  --> E2AP: failed to fill ric event trigger style");
+         return RFAILED;
+      }
+
+      /* RIC Report Style List */
+      DU_ALLOC(ranFuncDefinition->ric_ReportStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
+      if(!ranFuncDefinition->ric_ReportStyle_List)
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
+         return RFAILED;
+      }
+      if(fillRicReportStyle(ranFuncDb, ranFuncDefinition->ric_ReportStyle_List) != ROK)
+      {
+         DU_LOG("\nERROR  --> E2AP: failed to fill ric report style");
+         return RFAILED;
+      }
+
+      /* Encode the F1SetupRequest type as APER */
+      xer_fprint(stdout, &asn_DEF_E2SM_KPM_RANfunction_Description, ranFuncDefinition);
+
+      memset(encBuf, 0, ENC_BUF_MAX_LEN);
+      encBufSize = 0;
+      encRetVal = aper_encode(&asn_DEF_E2SM_KPM_RANfunction_Description, 0, ranFuncDefinition, PrepFinalEncBuf, encBuf);
+
+      /* Encode results */
+      if(encRetVal.encoded == ENCODE_FAIL)
+      {
+         DU_LOG("\nERROR  -->  F1AP : Could not encode RAN function definition  (at %s)\n",\
+               encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+         break;
       }
       else
       {
-         ret = BuildGlobalgNBId((*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.\
-               choice.GlobalE2node_ID.choice.gNB);
-         if(ret != ROK)
+         DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RAN function definition \n");
+         for(uint8_t measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
          {
-             DU_LOG("\nERROR  -->  E2AP : Failed to build Global Gnb Id");
-             return RFAILED;
+            printf("%x",encBuf[measIeIdx]);
          }
+
       }
-      
-      arrIdx++;
-      /* E2 Node Component Configuration Addition List */
-      (*e2SetupReq)->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition;
-      (*e2SetupReq)->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
-      (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_E2nodeComponentConfigAddition_List;
-      if(BuildE2NodeConfigAddList(&((*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List))!=ROK)
+      ranFuncItem->ranFunctionDefinition.size = encBufSize;
+      DU_ALLOC(ranFuncItem->ranFunctionDefinition.buf, encBufSize);
+      if(ranFuncItem->ranFunctionDefinition.buf == NULLP)
       {
-         DU_LOG("\nERROR  -->  E2AP : Failed to E2 Node config addition list");
+         DU_LOG("\nERROR  -->  F1AP : Memory allocation failed for RAN function definition buffer");
          return RFAILED;
       }
-
-   }
-   else
-   {
-      DU_LOG("\nERROR  -->  E2AP : received e2SetupReq is NULL");
-      return RFAILED;
+      memcpy(ranFuncItem->ranFunctionDefinition.buf, &encBuf, encBufSize);
    }
+   freeE2smKpmRanFunctionDefinition(ranFuncDefinition);
    return ROK;
 }
 
-
 /*******************************************************************
  *
  * @brief De Allocate E2 Setup Request Message
@@ -319,10 +745,13 @@ uint8_t fillE2SetupReq(E2setupRequest_t **e2SetupReq, uint8_t *idx)
 void FreeE2SetupReq(E2AP_PDU_t *e2apMsg)
 {
    uint8_t arrIdx = 0;
-   uint8_t e2NodeAddListIdx =0;
+   uint8_t e2NodeAddListIdx =0, ranFuncAddListIdx;
    E2setupRequest_t *e2SetupReq;
    E2nodeComponentConfigAddition_List_t *e2NodeAddList;
    E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem;
+   RANfunctions_List_t *ranFunctionsList;
+   RANfunction_ItemIEs_t *ranFuncItemIe;
+   RANfunction_Item_t  *ranFunItem;
 
    /* De-allocating Memory */
    if(e2apMsg != NULLP)
@@ -351,10 +780,16 @@ void FreeE2SetupReq(E2AP_PDU_t *e2apMsg)
                               if(gNbId->global_gNB_ID.plmn_id.buf != NULLP)
                               {
                                  DU_FREE(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf,\
-                                          gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
+                                       gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
                                  DU_FREE(gNbId->global_gNB_ID.plmn_id.buf,\
                                        gNbId->global_gNB_ID.plmn_id.size);
                               }
+
+                              if(gNbId->gNB_DU_ID != NULLP)
+                              {
+                                 DU_FREE( gNbId->gNB_DU_ID->buf, gNbId->gNB_DU_ID->size);
+                                 DU_FREE(gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
+                              }
                               DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
                                     choice.GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
                            }
@@ -394,6 +829,27 @@ void FreeE2SetupReq(E2AP_PDU_t *e2apMsg)
                          }
                          break;
                      }
+                     case ProtocolIE_IDE2_id_RANfunctionsAdded:
+                     {
+                        ranFunctionsList = &(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List);  
+                        if(ranFunctionsList->list.array)
+                        {  
+                           for(ranFuncAddListIdx= 0; ranFuncAddListIdx< ranFunctionsList->list.count; ranFuncAddListIdx++)
+                           {
+                              if(ranFunctionsList->list.array[ranFuncAddListIdx])
+                              {
+                                 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncAddListIdx];
+                                 ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
+                                 DU_FREE(ranFunItem->ranFunctionOID.buf, ranFunItem->ranFunctionOID.size);
+                                 DU_FREE(ranFunItem->ranFunctionDefinition.buf, ranFunItem->ranFunctionDefinition.size);
+                                 DU_FREE(ranFunctionsList->list.array[ranFuncAddListIdx], sizeof(RANfunction_ItemIEs_t));
+                              }
+                           }
+                           DU_FREE(ranFunctionsList->list.array, ranFunctionsList->list.size);
+                        }
+                        break;
+                     }
+
                      default:
                         DU_LOG("\nERROR  --> E2AP: Invalid event at e2SetupRequet %ld ",\
                               (e2SetupReq->protocolIEs.list.array[arrIdx]->id));
@@ -427,8 +883,9 @@ void FreeE2SetupReq(E2AP_PDU_t *e2apMsg)
 
 uint8_t BuildAndSendE2SetupReq()
 {
-   uint8_t idx = 0;
-   uint8_t ret = ROK;
+   uint8_t arrIdx = 0, elementCnt=0;
+   uint8_t transId = 0, ret = ROK;
+   bool memAllocFailed;
    E2AP_PDU_t        *e2apMsg = NULLP;
    E2setupRequest_t  *e2SetupReq = NULLP;
    asn_enc_rval_t     encRetVal;       /* Encoder return value */
@@ -447,20 +904,98 @@ uint8_t BuildAndSendE2SetupReq()
       if(e2apMsg->choice.initiatingMessage == NULLP)
       {
          DU_LOG("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
-         DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
-         return RFAILED;
+         break;
       }
       e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
       e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2setup;
       e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_E2setupRequest;
       e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
 
-      ret = fillE2SetupReq(&e2SetupReq, &idx);
-      if(ret != ROK)
+      elementCnt = 4;
+      e2SetupReq->protocolIEs.list.count = elementCnt;
+      e2SetupReq->protocolIEs.list.size = elementCnt * sizeof(E2setupRequestIEs_t*);
+
+      /* Initialize the E2Setup members */
+      DU_ALLOC(e2SetupReq->protocolIEs.list.array, \
+            e2SetupReq->protocolIEs.list.size);
+      if(e2SetupReq->protocolIEs.list.array == NULLP)
+      {
+         DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for array elements");
+         break;
+      }
+      for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
+      {
+         DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx],\
+               sizeof(E2setupRequestIEs_t));
+         if(e2SetupReq->protocolIEs.list.array[arrIdx] == NULLP)
+         {
+            memAllocFailed = true;
+            DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for arrayarrIdx [%d]", arrIdx);
+            break;
+         }
+      }
+      if(memAllocFailed == true)
+         break;
+
+      arrIdx = 0;
+
+      /* TransactionID */
+      e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
+      e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+      e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
+      transId = assignTransactionId();
+      e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
+
+      arrIdx++;
+      /* GlobalE2node_gNB_ID */
+      e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_GlobalE2node_ID;
+      e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+      e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
+      e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
+
+      DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
+            GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
+      if(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
+            GlobalE2node_ID.choice.gNB == NULLP)
+      {
+         DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for gNbId");
+         break;
+      }
+      else
+      {
+         ret = BuildGlobalgNBId(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
+               choice.GlobalE2node_ID.choice.gNB);
+         if(ret != ROK)
+         {
+             DU_LOG("\nERROR  -->  E2AP : Failed to build Global Gnb Id");
+             break;
+         }
+      }
+      
+      /* RAN Functions Added List */
+      arrIdx++;
+      e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
+      e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+      e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_RANfunctions_List;
+      if(BuildRanFunctionAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List))!=ROK)
+      {
+         DU_LOG("\nERROR  -->  E2AP : Failed to create RAN Function");
+         break;
+      }
+
+      /* E2 Node Component Configuration Addition List */
+      arrIdx++;
+      e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition;
+      e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+      e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_E2nodeComponentConfigAddition_List;
+      if(BuildE2NodeConfigAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List))!=ROK)
       {
-         DU_LOG("\nERROR  -->  E2AP : fillE2SetupReq() failed");
+         DU_LOG("\nERROR  -->  E2AP : Failed to create E2 Node config list");
          break;
       }
+
+
+
       /* Prints the Msg formed */
       xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
 
@@ -488,10 +1023,12 @@ uint8_t BuildAndSendE2SetupReq()
       {
          DU_LOG("\nERROR  -->  E2AP : Sending E2 Setup request failed");
       }
-
       break;
    }while(true);
 
+   duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].transactionId = transId;
+   duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
+   
    FreeE2SetupReq(e2apMsg);
    return ret;
 }/* End of BuildAndSendE2SetupReq */
@@ -954,9 +1491,11 @@ void freeAperDecodingOfE2SetupRsp(E2setupResponse_t *e2SetRspMsg)
  * ****************************************************************/
 uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
 {
-   uint8_t arrIdx =0; 
+   uint8_t arrIdx =0, transId=0
    uint32_t recvBufLen;             
    E2setupResponse_t *e2SetRspMsg;
+   CmLList         *node;
+   E2NodeComponent *e2NodeComponentInfo;
 
    DU_LOG("\nINFO   -->  E2AP : E2 Setup Response received"); 
    duCb.e2Status = TRUE; //Set E2 status as true
@@ -967,22 +1506,28 @@ uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
       switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
       {
          case ProtocolIE_IDE2_id_TransactionID:
-            break;
+            {
+               transId = e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
+               if((duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].transactionId == transId) &&\
+                     (duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
+                  memset(&duCb.e2apDb.e2TransInfo.onGoingTransaction[transId], 0, sizeof(E2TransInfo));
+               else
+               {
+                  DU_LOG("\nERROR  -->  E2AP : Invalid transaction id [%d]", transId);
+                  return RFAILED;
+               }
+               break;
+            }
 
          case ProtocolIE_IDE2_id_GlobalRIC_ID:
             {
                /* To store the Ric Id Params */
                recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value\
                      .choice.GlobalRIC_ID.pLMN_Identity.size);
-               duCb.e2apDb.plmn = NULLP;
-               DU_ALLOC(duCb.e2apDb.plmn, recvBufLen);
-               if(duCb.e2apDb.plmn)
-               {
-                  memcpy(duCb.e2apDb.plmn, e2SetRspMsg->protocolIEs.list.array[arrIdx]\
+                  memcpy(&duCb.e2apDb.ricId.plmnId, e2SetRspMsg->protocolIEs.list.array[arrIdx]\
                         ->value.choice.GlobalRIC_ID.pLMN_Identity.buf, recvBufLen);
-               }
                bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID, &duCb.e2apDb.ricId);
-               /*TODO : duCb.e2apDb.plmn memory to be deallocated after the usage */
+               /*TODO : duCb.e2apDb.ricId.plmnId memory to be deallocated after the usage */
                break;
             }
 
@@ -996,6 +1541,23 @@ uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
       }
    }
    freeAperDecodingOfE2SetupRsp(e2SetRspMsg);
+   
+   node = searchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD);
+   if(!node)
+   {
+      DU_LOG("\nERROR  --> E2AP : Received e2NodeComponentInfo is null");
+      return RFAILED;
+   }
+   else
+   {
+      e2NodeComponentInfo = (E2NodeComponent*)node->node;
+      cmLListDelFrm(&duCb.e2apDb.e2NodeComponentList, node);
+      DU_FREE(e2NodeComponentInfo->componentRequestPart, e2NodeComponentInfo->reqBufSize);
+      DU_FREE(e2NodeComponentInfo->componentResponsePart, e2NodeComponentInfo->rspBufSize);
+      DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
+      DU_FREE(node, sizeof(CmLList));
+   }
+
    BuildAndSendE2NodeConfigUpdate();
    return ROK;
 }
@@ -1021,8 +1583,9 @@ uint8_t procRicSubsReq(E2AP_PDU_t *e2apMsg)
    uint8_t idx; 
    uint8_t ied; 
    uint8_t ret = ROK;
-   uint32_t recvBufLen;             
+   CmLList  *ricSubscriptionNode = NULLP;
    RICsubscriptionRequest_t *ricSubsReq;
+   RicSubscription *ricSubscriptionInfo;
    RICaction_ToBeSetup_ItemIEs_t *actionItem;
 
    DU_LOG("\nINFO   -->  E2AP : RIC Subscription request received"); 
@@ -1036,33 +1599,33 @@ uint8_t procRicSubsReq(E2AP_PDU_t *e2apMsg)
          {
             case ProtocolIE_IDE2_id_RICrequestID:
                {
-                  duCb.e2apDb.ricReqId = ricSubsReq->protocolIEs.list.array[idx]->\
-                                         value.choice.RICrequestID.ricRequestorID;
-                  duCb.e2apDb.ricInstanceId = ricSubsReq->protocolIEs.list.array[idx]-> \
-                                              value.choice.RICrequestID.ricInstanceID;
+                  /* TODO :- ricSubscriptionInfo details will be stored based on
+                   * RAN function id, so first we need to search RAN function and then add
+                   * subscription details to that ran function */
+                  DU_ALLOC(ricSubscriptionInfo, sizeof(RicSubscription));
+                  if(!ricSubscriptionInfo)
+                  {
+                     DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for ricSubscriptionInfo");
+                     return RFAILED;
+                  }
+                  ricSubscriptionInfo->requestId.requestorId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID;
+                  ricSubscriptionInfo->requestId.instanceId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID;
+                  DU_ALLOC(ricSubscriptionNode, sizeof(CmLList));
+                  if(ricSubscriptionNode)
+                  {
+                     ricSubscriptionNode->node = (PTR) ricSubscriptionInfo;
+                     cmLListAdd2Tail(&duCb.e2apDb.ranFunction[0].subscriptionList,ricSubscriptionNode);
+                  }
                   break;
                }
             case ProtocolIE_IDE2_id_RANfunctionID:
                {
-                  duCb.e2apDb.ranFuncId = ricSubsReq->protocolIEs.list.array[idx]-> \
+                  duCb.e2apDb.ranFunction[0].id = ricSubsReq->protocolIEs.list.array[idx]-> \
                                           value.choice.RANfunctionID; 
                   break;
                }
             case ProtocolIE_IDE2_id_RICsubscriptionDetails:
                {
-                  recvBufLen = sizeof(ricSubsReq->protocolIEs.list.array[idx]->value\
-                        .choice.RICsubscriptionDetails.ricEventTriggerDefinition.size);
-                  duCb.e2apDb.ricEventTrigger = NULLP;
-                  DU_ALLOC(duCb.e2apDb.ricEventTrigger, recvBufLen);
-                  /*TODO : duCb.e2apDb.ricEventTrigger memory to be deallocated after the usage */
-                  if(duCb.e2apDb.ricEventTrigger)
-                  {
-                     memcpy(duCb.e2apDb.ricEventTrigger, ricSubsReq->protocolIEs.list.array[idx]\
-                           ->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition.buf, \
-                           recvBufLen);
-                     free(ricSubsReq->protocolIEs.list.array[idx]->value.choice.\
-                           RICsubscriptionDetails.ricEventTriggerDefinition.buf);
-                  }
                   if(ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.\
                         list.array)
                   {
@@ -1077,8 +1640,8 @@ uint8_t procRicSubsReq(E2AP_PDU_t *e2apMsg)
                         {
                            case ProtocolIE_IDE2_id_RICaction_ToBeSetup_Item:
                               {
-                                 duCb.e2apDb.ricActionId = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID;
-                                 duCb.e2apDb.ricActionType = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionType;
+                                 ricSubscriptionInfo->actionSequence[0].id  = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID;
+                                 ricSubscriptionInfo->actionSequence[0].type = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionType;
                                  break;
                               }
                            default:
@@ -1089,6 +1652,13 @@ uint8_t procRicSubsReq(E2AP_PDU_t *e2apMsg)
                      }
                      free(ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.\
                            list.array);
+
+                     /* This is a dummy trigger for statistics request. It will
+                      * be removed in next gerrit and actual statistics request
+                      * will be sent when RIC subscription request is received
+                      * from RIC */
+                     ricSubscriptionInfo->actionSequence[0].definition.styleType = 1;
+                     BuildAndSendStatsReq(ricSubscriptionInfo->actionSequence[0].definition);
                   }
                   break;
                }
@@ -1103,6 +1673,9 @@ uint8_t procRicSubsReq(E2AP_PDU_t *e2apMsg)
    }
    free(ricSubsReq->protocolIEs.list.array);
    ret = BuildAndSendRicSubscriptionRsp();
+   {
+      BuildAndSendRicIndication(ricSubscriptionInfo);
+   }
 
    return ret;
 }
@@ -1194,7 +1767,7 @@ void FreeRicIndication(E2AP_PDU_t  *e2apMsg)
  *         RFAILED - failure
  *
  ******************************************************************/
-uint8_t FillRicIndication(RICindication_t *ricIndicationMsg)
+uint8_t FillRicIndication(RICindication_t *ricIndicationMsg, RicSubscription *ricSubscriptionInfo)
 {
    uint8_t elementCnt=0;
    uint8_t idx=0;
@@ -1231,34 +1804,29 @@ uint8_t FillRicIndication(RICindication_t *ricIndicationMsg)
         ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
         ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
                                                                        RICindication_IEs__value_PR_RICrequestID;
-        ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID =\
-                                                                                                 duCb.e2apDb.ricReqId;
-        ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID =\
-                                                                                                duCb.e2apDb.ricInstanceId;
+        ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID =ricSubscriptionInfo->requestId.requestorId;
+        ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID = ricSubscriptionInfo->requestId.instanceId;
 
         idx++;
         ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
         ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
         ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
                                                                        RICindication_IEs__value_PR_RANfunctionID;
-        ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RANfunctionID =
-           duCb.e2apDb.ranFuncId;
+        ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RANfunctionID = duCb.e2apDb.ranFunction[0].id;
 
         idx++;
         ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactionID;
         ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
         ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
                                                                        RICindication_IEs__value_PR_RICactionID;
-        ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICactionID =
-           duCb.e2apDb.ricActionId;
+        ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICactionID = ricSubscriptionInfo->actionSequence[0].id;
 
         idx++;
         ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationType;
         ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
         ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
                                                                        RICindication_IEs__value_PR_RICindicationType;
-        ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationType =
-           duCb.e2apDb.ricActionType;
+        ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationType = ricSubscriptionInfo->actionSequence[0].type;
 
         idx++;
         ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationHeader;
@@ -1320,7 +1888,7 @@ uint8_t FillRicIndication(RICindication_t *ricIndicationMsg)
  *
  ******************************************************************/
 
-uint8_t BuildAndSendRicIndication()
+uint8_t BuildAndSendRicIndication(RicSubscription *ricSubscriptionInfo)
 {
    E2AP_PDU_t                 *e2apMsg = NULLP;
    RICindication_t            *ricIndicationMsg=NULLP;
@@ -1352,7 +1920,7 @@ uint8_t BuildAndSendRicIndication()
 
       ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
 
-      FillRicIndicationret = FillRicIndication(ricIndicationMsg);
+      FillRicIndicationret = FillRicIndication(ricIndicationMsg, ricSubscriptionInfo);
       if(FillRicIndicationret != ROK)
       {
         break;
@@ -1728,8 +2296,8 @@ uint8_t BuildAndSendE2ResetRequest(E2CauseType failureType, E2Cause failureCause
 
       /* In case the message is sent successfully, store the transaction info to
        * be used when response is received */
-      duCb.e2apDb.onGoingTransaction[transId].transactionId = transId;
-      duCb.e2apDb.onGoingTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
+      duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].transactionId = transId;
+      duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
 
       ret = ROK;
       break;
@@ -1812,8 +2380,9 @@ uint8_t procResetResponse(E2AP_PDU_t *e2apMsg)
       {
          case ProtocolIE_IDE2_id_TransactionID:
             transId = resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
-            if(duCb.e2apDb.onGoingTransaction[transId].transactionId == transId)
-              memset(&duCb.e2apDb.onGoingTransaction[transId], 0, sizeof(E2TransInfo));
+            if((duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].transactionId == transId) && \
+                  (duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
+              memset(&duCb.e2apDb.e2TransInfo.onGoingTransaction[transId], 0, sizeof(E2TransInfo));
             else
             {
                DU_LOG("\nERROR  -->  E2AP : Invalid transaction id [%d]", transId);
@@ -1840,6 +2409,99 @@ uint8_t procResetResponse(E2AP_PDU_t *e2apMsg)
    return ROK;
 }
 
+/******************************************************************
+ *
+ * @brief Deallocation of memory allocated bu aper decoder for e2 setup Failure
+ *
+ * @details
+ *
+ *    Function : freeAperDecodingOfE2SetupFailure
+ *
+ *    Functionality: Deallocation of memory allocated bu aper decoder for e2
+ *    setup Failure
+ *
+ * @params[in] E2setupFailure_t *e2SetupFailure;
+ * @return void
+ *
+ * ****************************************************************/
+void freeAperDecodingOfE2SetupFailure(E2setupFailure_t *e2SetupFailure)
+{
+   uint8_t arrIdx;
+
+   if(e2SetupFailure)
+   {
+      if(e2SetupFailure->protocolIEs.list.array)
+      {
+         for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
+         {
+            if(e2SetupFailure->protocolIEs.list.array[arrIdx])
+            {
+               free(e2SetupFailure->protocolIEs.list.array[arrIdx]);  
+            }
+         }
+         free(e2SetupFailure->protocolIEs.list.array);
+      }
+   }
+}
+/******************************************************************
+ *
+ * @brief Processes E2 Setup Failure sent by RIC
+ *
+ * @details
+ *
+ *    Function : procE2SetupFailure
+ *
+ *    Functionality: Processes E2 Setup failure sent by RIC
+ *
+ * @params[in] E2AP_PDU_t ASN decoded E2AP message
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+void procE2SetupFailure(E2AP_PDU_t *e2apMsg)
+{
+   uint8_t arrIdx =0, transId =0, timerValue=0; 
+   E2setupFailure_t *e2SetupFailure;
+
+   DU_LOG("\nINFO   -->  E2AP : E2 Setup failure received"); 
+   e2SetupFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure;
+
+   for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
+   {
+      switch(e2SetupFailure->protocolIEs.list.array[arrIdx]->id)
+      {
+         case ProtocolIE_IDE2_id_TransactionID:
+         {
+            transId = e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
+            if((duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].transactionId == transId) &&\
+            (duCb.e2apDb.e2TransInfo.onGoingTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
+              memset(&duCb.e2apDb.e2TransInfo.onGoingTransaction[transId], 0, sizeof(E2TransInfo));
+            else
+            {
+               DU_LOG("\nERROR  -->  E2AP : Invalid transaction id [%d]", transId);
+               return ;
+            }
+            break;
+         }
+         case ProtocolIE_IDE2_id_TimeToWaitE2:
+            {
+               timerValue = covertE2WaitTimerEnumToValue(e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
+               if((duChkTmr((PTR)&(duCb.e2apDb), EVENT_E2_SETUP_TMR)) == FALSE)
+               {
+                  duStartTmr((PTR)&(duCb.e2apDb), EVENT_E2_SETUP_TMR, timerValue);
+               }
+               else
+               {
+                  DU_LOG("\nERROR   -->  E2AP : EVENT_E2_SETUP_TMR timer is already running");
+                  return;
+               }
+               break; 
+            }
+      }
+   }
+
+   freeAperDecodingOfE2SetupFailure(e2SetupFailure);
+}
 /*******************************************************************
  *
  * @brief Handles received E2AP message and sends back response  
@@ -1910,6 +2572,24 @@ void E2APMsgHdlr(Buffer *mBuf)
 
    switch(e2apMsg->present)
    {
+      case E2AP_PDU_PR_unsuccessfulOutcome:
+         {
+            switch(e2apMsg->choice.unsuccessfulOutcome->value.present)
+            {
+               case UnsuccessfulOutcomeE2__value_PR_E2setupFailure:
+                  {
+                     procE2SetupFailure(e2apMsg);
+                     break;
+                  }
+               default:
+                  {
+                     DU_LOG("\nERROR  -->  E2AP : Invalid type of E2AP_PDU_PR_unsuccessfulOutcome  [%d]",\
+                           e2apMsg->choice.unsuccessfulOutcome->value.present);
+                     return;
+                  }
+            }
+            break;
+         }
       case E2AP_PDU_PR_successfulOutcome:
          {
             switch(e2apMsg->choice.successfulOutcome->value.present)
@@ -1949,10 +2629,7 @@ void E2APMsgHdlr(Buffer *mBuf)
             {
                case InitiatingMessageE2__value_PR_RICsubscriptionRequest: 
                   {
-                     if(procRicSubsReq(e2apMsg) == ROK)
-                     {
-                        BuildAndSendRicIndication();
-                     }
+                     procRicSubsReq(e2apMsg);
                      break;
                   }
                default: