E2setupRequest Clean up changes
[o-du/l2.git] / src / du_app / du_e2ap_msg_hdl.c
index 4ee88c6..cf3a1b1 100644 (file)
 #include "du_mgr_main.h"
 #include "GlobalE2node-gNB-ID.h"
 
-#define ENC_BUF_MAX_LEN 100
-
 /* Global variable */
 DuCfgParams duCfgParam;
-char encBuf[ENC_BUF_MAX_LEN];
-int  encBufSize;
-
-/*******************************************************************
- *
- * @brief Writes the encoded chunks into a buffer
- *
- * @details
- *
- *    Function : PrepFinalEncBuf
- *
- *    Functionality:Fills the encoded buffer
- *
- * @params[in] void *buffer,initial encoded data
- * @params[in] size_t size,size of buffer
- * @params[in] void *encodedBuf,final buffer
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-static int PrepFinalEncBuf(const void *buffer, size_t size, void *encodedBuf)
-{
-   memcpy(encodedBuf + encBufSize, buffer, size);
-   encBufSize += size;
-   return 0;
-} /* PrepFinalEncBuf */
 
 /*******************************************************************
  *
- * @brief Builds PLMN ID 
+ * @brief Builds Global gNodeB Params
  *
  * @details
  *
- *    Function : BuildPlmnId
+ *    Function : BuildGlobalgNB
  *
- *    Functionality: Building the PLMN ID
+ *    Functionality: Building the Plmn and gNB id
  *
- * @params[in] PLMNID plmn
- *             OCTET_STRING_t *plmnid
+ * @params[in] GlobalE2node_gNB_ID_t *gNbId
  * @return ROK     - success
  *         RFAILED - failure
  *
- * ****************************************************************/
+ ******************************************************************/
 
-S16 BuildPlmnId(PlmnId plmn, OCTET_STRING_t *plmnid)
+S16 BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
 {
-   U8 mncCnt;
-   plmnid->size = 3;
-   DU_ALLOC(plmnid->buf,  plmnid->size * sizeof(U8));
-   if(plmnid->buf == NULLP)
-   {
-      RETVALUE(RFAILED);
-   }
-   mncCnt = 2;
-   plmnid->buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
-   if(mncCnt == 2)
+   uint8_t unused = 0;
+   uint8_t byteSize = 4;
+   uint8_t val = 1;
+   uint8_t ret = ROK;
+
+   /* Allocate Buffer size */
+   gNbId->global_gNB_ID.plmn_id.size = 3 * sizeof(U8);
+   gNbId->global_gNB_ID.plmn_id.buf = NULLP;
+   DU_ALLOC(gNbId->global_gNB_ID.plmn_id.buf , gNbId->global_gNB_ID.plmn_id.size);
+   if(gNbId->global_gNB_ID.plmn_id.buf == NULLP)
    {
-      plmnid->buf[1]  = ((0xf0) | (plmn.mcc[2]));
-      plmnid->buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
+      DU_LOG("\nE2AP: Memory allocation failed for Plmn buffer");
+      ret = RFAILED;
    }
    else
    {
-      plmnid->buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
-      plmnid->buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
+      buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
+         &gNbId->global_gNB_ID.plmn_id);
+      /* 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(U8);
+      gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf = NULLP;
+      DU_ALLOC(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf, \
+         gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
+      if(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf == NULLP)
+      {
+         DU_LOG("\nE2AP: Memory allocation failed for gnb buffer");
+         ret = RFAILED;
+      }
+      else
+      {
+         fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, val);
+      }
    }
-  RETVALUE(ROK);
+   return ret;
 }
 
 /*******************************************************************
  *
- * @brief Builds NodeB Id
+ * @brief Fills the initiating IE for E2 Setup Request
  *
  * @details
  *
- *    Function : BuildNodeBId
+ *    Function : fillE2SetupReq
  *
- *    Functionality: Building the NodeBId
- *
- * @params[in] BIT_STRING_t *nbid,
- *             U8 unusedBits
- *             U8 byteSize
- *             U8 val
+ * Functionality:Fills the Initiating message for
+ *               E2SetupRequest
  *
+ * @params[in] E2setupRequest_t *e2SetupReq,
+ *             uint8_t *idx
  * @return ROK     - success
  *         RFAILED - failure
  *
- * ****************************************************************/
+ ******************************************************************/
 
-S16 BuildNodeBId(BIT_STRING_t *nbid, U8 unusedBits, U8 byteSize, U8 val)
+uint16_t fillE2SetupReq(E2setupRequest_t **e2SetupReq, uint8_t *idx)
 {
-   U8 tmp;
-   nbid->size = byteSize;
-   DU_ALLOC(nbid->buf, nbid->size * sizeof(U8));
-   if(nbid->buf == NULLP)
-   {
-      RETVALUE(RFAILED);
-   }
+   uint8_t elementCnt = 0;
+   uint8_t idx2 = 0;
+   uint8_t ret = ROK;
 
-   for (tmp = 0 ; tmp < ((nbid->size)-1); tmp++)
+   if(*e2SetupReq != NULLP)
    {
-      nbid->buf[tmp] = 0;
-   }
-   nbid->buf[byteSize-1] = val; 
-   nbid->bits_unused = unusedBits;
-   RETVALUE(ROK);
+      elementCnt = 1;
+      (*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("\nE2AP : Memory allocation failed for array elements");
+         ret = RFAILED;
+      }
+      else
+      {
+         for(*idx = 0; *idx < elementCnt; (*idx)++)
+         {
+            DU_ALLOC((*e2SetupReq)->protocolIEs.list.array[*idx],\
+               sizeof(E2setupRequestIEs_t));
+            if((*e2SetupReq)->protocolIEs.list.array[*idx] == NULLP)
+            {
+               DU_LOG("\nE2AP : Memory allocation failed for arrayidx [%d]", *idx);
+               ret = RFAILED;
+            }
+            else
+            {
+               /* GlobalE2node_gNB_ID */
+               (*e2SetupReq)->protocolIEs.list.array[idx2]->id = \
+                      ProtocolIE_IDE2_id_GlobalE2node_ID;
+               (*e2SetupReq)->protocolIEs.list.array[idx2]->criticality = \
+                            CriticalityE2_reject;
+               (*e2SetupReq)->protocolIEs.list.array[idx2]->value.present =\
+                             E2setupRequestIEs__value_PR_GlobalE2node_ID;
+               (*e2SetupReq)->protocolIEs.list.array[idx2]->value.choice.\
+                  GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
+      
+               DU_ALLOC((*e2SetupReq)->protocolIEs.list.array[idx2]->value.choice.\
+                  GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
+               if((*e2SetupReq)->protocolIEs.list.array[idx2]->value.choice.\
+                  GlobalE2node_ID.choice.gNB == NULLP)
+               {
+                  DU_LOG("\nE2AP : Memory allocation failed for gNbId");
+                  ret = RFAILED;
+               }
+               else
+               {
+                  ret = BuildGlobalgNBId((*e2SetupReq)->protocolIEs.list.array[idx2]->value.\
+                     choice.GlobalE2node_ID.choice.gNB);
+                  if(ret != ROK)
+                  {
+                     ret = RFAILED;
+                  }
+               }
+
+            }
+         }
+      }
+    }
+    else
+    {
+       ret = RFAILED;
+       DU_LOG("\nE2AP : Passed e2SetupReq is NULL");
+    }
+    return ret;
 }
 
 /*******************************************************************
  *
- * @brief Builds Global gNodeB Params
+ * @brief Builds and Send the E2SetupRequest
  *
  * @details
  *
- *    Function : BuildGlobalgNB
+ *    Function : BuildAndSendE2SetupReq
  *
- *    Functionality: Building the Plmn and gNB id
+ * Functionality:Fills the E2SetupRequest
  *
- * @params[in] GlobalE2node_gNB_ID_t *gNbId
  * @return ROK     - success
  *         RFAILED - failure
  *
- * ****************************************************************/
+ ******************************************************************/
 
-S16 BuildGlobalgNB(GlobalE2node_gNB_ID_t *gNbId)
+S16 BuildAndSendE2SetupReq()
 {
-   U8 unused = 0;
-   U8 byteSize = 4;
-   U8 val = 1;
-   if(gNbId != NULLP)
+   uint8_t idx = 0;
+   uint8_t ret = ROK;
+   E2AP_PDU_t        *e2apMsg = NULLP;
+   E2setupRequest_t  *e2SetupReq = NULLP;
+   asn_enc_rval_t     encRetVal;       /* Encoder return value */
+
+   DU_LOG("\nE2AP : Building E2 Setup Request\n");
+   do
    {
-      BuildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
-       &gNbId->global_gNB_ID.plmn_id); 
-      /* fill gND Id */
-      gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID; 
-      BuildNodeBId(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, val);
-   }
-   RETVALUE(ROK);   
-}
+      DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
+      if(e2apMsg == NULLP)
+      {
+         DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
+         break;
+      }
+      e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
+      DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+      if(e2apMsg->choice.initiatingMessage == NULLP)
+      {
+         DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
+         DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
+         return RFAILED;
+      }
+      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)
+      {
+         DU_LOG("\nE2AP : fillE2SetupReq() failed");
+         break;
+      }
+      /* Prints the Msg formed */
+      xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
+
+      cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN);
+      encBufSize = 0;
+      encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
+                      encBuf);
+      if(encRetVal.encoded == ENCODE_FAIL)
+      {
+         DU_LOG("\nE2AP : Could not encode E2SetupRequest structure (at %s)\n",\
+            encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+         break;
+      }
+      else
+      {
+         DU_LOG("\nE2AP : Created APER encoded buffer for E2SetupRequest\n");
+         for(int i=0; i< encBufSize; i++)
+         {
+            printf("%x",encBuf[i]);
+         }
+      }
+      if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
+      {
+         DU_LOG("\nE2AP : Sending E2 Setup request failed");
+      }
+
+    break;
+   }while(1);
+
+   deAllocateE2SetupReqMsg(e2apMsg, e2SetupReq, idx);
+   return ret;
+}/* End of BuildAndSendE2SetupReq */
 
 /*******************************************************************
  *
- * @brief Builds and Send the E2SetupRequest
+ * @brief De Allocate E2 Setup Request Message
  *
  * @details
  *
- *    Function : BuildAndSendE2SetupReq
+ *    Function : deAllocateE2SetupReqMsg
  *
- * Functionality:Fills the E2SetupRequest
+ *    Functionality: De-Allocating E2 Setup request Message
  *
+ * @params[in] E2AP_PDU_t *e2apMsg
+ *             E2setupRequest_t *e2SetupReq
  * @return ROK     - success
  *         RFAILED - failure
  *
- ******************************************************************/
+ * ****************************************************************/
 
-S16 BuildAndSendE2SetupReq()
+uint16_t deAllocateE2SetupReqMsg(E2AP_PDU_t *e2apMsg, \
+   E2setupRequest_t *e2SetupReq, uint8_t idx)
 {
-   E2AP_PDU_t                 *e2apMsg = NULLP;
-   E2setupRequest_t           *e2SetupReq;
-   U8   elementCnt;
-   U8   idx;
-   U8   ieId;
-   S16  ret; 
-   asn_enc_rval_t             encRetVal;        /* Encoder return value */
-
-   DU_LOG("\nE2AP : Building E2 Setup Request\n");
-
-   DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
-   if(e2apMsg == NULLP)
+   uint8_t idx2;
+   uint8_t ret = ROK;
+   /* De-allocating Memory */
+   if(e2apMsg != NULLP)
    {
-      DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
-      RETVALUE(RFAILED);
-   }
-
-   e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
-   DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
-   if(e2apMsg->choice.initiatingMessage == NULLP)
-   {
-      DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
-      DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
-      RETVALUE(RFAILED);
-   }
-   e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
-   e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2setup;
-   e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_E2setupRequest;
-   
-   DU_ALLOC(e2SetupReq, sizeof(E2setupRequest_t));
-   e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
-   
-   elementCnt = 1;
-   
-   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("\nE2AP : Memory allocation for E2RequestIEs failed");
-      DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
-      DU_FREE(e2apMsg, (Size)sizeof(E2AP_PDU_t));
-      RETVALUE(RFAILED);
-   }
-   
-   for(idx=0; idx<elementCnt; idx++)
-   {
-      DU_ALLOC(e2SetupReq->protocolIEs.list.array[idx],\
-            sizeof(E2setupRequestIEs_t));
-      if(e2SetupReq->protocolIEs.list.array[idx] == NULLP)
+      if(e2apMsg->choice.initiatingMessage != NULLP)
       {
-         for(ieId=0; ieId<idx; ieId++)
+         if(e2SetupReq->protocolIEs.list.array != NULLP)
          {
-            DU_FREE(e2SetupReq->protocolIEs.list.array[ieId],\
-                  sizeof(E2setupRequestIEs_t));
+            for(idx2 = 0; idx2 < idx; idx2++)
+            {
+               if(e2SetupReq->protocolIEs.list.array[idx2] != NULLP)
+               {
+                  switch(e2SetupReq->protocolIEs.list.array[idx2]->id)
+                  {
+                     case ProtocolIE_IDE2_id_GlobalE2node_ID:
+                     {
+                        if(e2SetupReq->protocolIEs.list.array[idx2]->\
+                             value.choice.GlobalE2node_ID.choice.gNB != NULLP)
+                        {
+                              GlobalE2node_gNB_ID_t *gNbId = NULLP;
+                              gNbId = e2SetupReq->protocolIEs.list.array[idx2]->\
+                                         value.choice.GlobalE2node_ID.choice.gNB;
+                              if(gNbId->global_gNB_ID.plmn_id.buf != NULLP)
+                              {
+                                 if(gNbId->global_gNB_ID.gnb_id.choice.gnb_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);
+                                 }
+                                 DU_FREE(gNbId->global_gNB_ID.plmn_id.buf,\
+                                            gNbId->global_gNB_ID.plmn_id.size);
+                              }
+                              DU_FREE(e2SetupReq->protocolIEs.list.array[idx2]->value.\
+                                choice.GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
+                        }
+                        DU_FREE(e2SetupReq->protocolIEs.list.array[idx2],\
+                            sizeof(E2setupRequestIEs_t));
+                        break;
+                     }
+                     default:
+                        DU_LOG("\n E2AP: Invalid event at e2SetupRequet %ld ",\
+                          (e2SetupReq->protocolIEs.list.array[idx2]->id));
+                        break;
+                  }
+               }
+            }
+            DU_FREE(e2SetupReq->protocolIEs.list.array, e2SetupReq->protocolIEs.list.size);
          }
-         DU_FREE(e2SetupReq->protocolIEs.list.array,\
-                 e2SetupReq->protocolIEs.list.size);
-         DU_FREE(e2apMsg->choice.initiatingMessage, \
-               sizeof(InitiatingMessageE2_t));
-         DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
-         RETVALUE(RFAILED);
+         DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
       }
+      DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
    }
-
-   idx = 0;
-   /* GlobalE2node_gNB_ID */
-   e2SetupReq->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_GlobalE2node_ID;
-   e2SetupReq->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
-   e2SetupReq->protocolIEs.list.array[idx]->value.present =\
-                                    E2setupRequestIEs__value_PR_GlobalE2node_ID;
-   e2SetupReq->protocolIEs.list.array[idx]->value.choice.GlobalE2node_ID.present = \
-                                                                   GlobalE2node_ID_PR_gNB;
-   
-   GlobalE2node_gNB_ID_t *gNbId;
-   DU_ALLOC(gNbId, sizeof(GlobalE2node_gNB_ID_t));
-   BuildGlobalgNB(gNbId);
-   e2SetupReq->protocolIEs.list.array[idx]->value.choice.GlobalE2node_ID.choice.gNB = gNbId;
-
-   /* Prints the Msg formed */
-   xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
-
-
-   cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN);
-   encBufSize = 0;
-   encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
-               encBuf);
-   if(encRetVal.encoded == ENCODE_FAIL)
-   {
-          DU_LOG("\nE2AP : Could not encode E2SetupRequest structure (at %s)\n",\
-                          encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
-          RETVALUE(RFAILED);
-   }
-   else
-   {
-           DU_LOG("\nE2AP : Created APER encoded buffer for E2SetupRequest\n");
-          for(int i=0; i< encBufSize; i++)
-          {
-                  printf("%x",encBuf[i]);
-          } 
-   }
-
-   if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
-   {
-          DU_LOG("\nE2AP : Sending E2 Setup request failed");
-          RETVALUE(RFAILED);
-   }
-
-   RETVALUE(ROK);
-}/* End of BuildAndSendE2SetupReq */
-
+   return ret;  
+}
 /*******************************************************************
  *
  * @brief Builds Ric Request Id
@@ -316,7 +352,7 @@ S16 BuildRicRequestId(RICrequestID_t *ricReqId)
       ricReqId->ricRequestorID = 1;
       ricReqId->ricInstanceID  = 1;
    }
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /*******************************************************************
@@ -345,7 +381,7 @@ S16 fillRicAdmitList(RICaction_Admitted_ItemIEs_t *ricAdmitItems)
       ricAdmitItems->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
       ricAdmitItems->value.choice.RICaction_Admitted_Item.ricActionID = 1; 
    }
-   RETVALUE(ROK);
+   return ROK;
 }
 /*******************************************************************
  *
@@ -374,12 +410,12 @@ S16 BuildRicAdmitList(RICaction_Admitted_List_t *admitListPtr)
    if(admitListPtr->list.array == NULLP)
    {
       DU_LOG("\nE2AP : Memory allocation for RIC Admit List failed");
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    DU_ALLOC(admitListPtr->list.array[0], sizeof(RICaction_Admitted_ItemIEs_t));
-   fillRicAdmitList(admitListPtr->list.array[0]);
+   fillRicAdmitList((RICaction_Admitted_ItemIEs_t *)admitListPtr->list.array[0]);
 
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /*******************************************************************
@@ -413,7 +449,7 @@ S16 BuildAndSendRicSubscriptionRsp()
    if(e2apRicMsg == NULLP)
    {
       DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    e2apRicMsg->present =  E2AP_PDU_PR_successfulOutcome;
    DU_ALLOC(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
@@ -421,7 +457,7 @@ S16 BuildAndSendRicSubscriptionRsp()
    {
       DU_LOG("\nE2AP : Memory allocation for Ric subscription Response failed");
       DU_FREE(e2apRicMsg, sizeof(RICsubscriptionResponse_t));
-      RETVALUE(RFAILED);  
+      return RFAILED;  
    }
 
    e2apRicMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
@@ -441,7 +477,7 @@ S16 BuildAndSendRicSubscriptionRsp()
       DU_LOG("\nE2AP : Memory allocation for RICsubscriptionResponseIE failed");
       DU_FREE(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
       DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
 
    for(idx=0; idx<elementCnt; idx++)
@@ -455,7 +491,7 @@ S16 BuildAndSendRicSubscriptionRsp()
          DU_FREE(e2apRicMsg->choice.successfulOutcome, \
                sizeof(SuccessfulOutcomeE2_t));
          DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
-         RETVALUE(RFAILED);
+         return RFAILED;
       }    
    }
    idx = 0;
@@ -491,7 +527,7 @@ S16 BuildAndSendRicSubscriptionRsp()
    {
           DU_LOG("\nE2AP : Could not encode RIC Subscription Response structure (at %s)\n",\
                           encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
-          RETVALUE(RFAILED);
+          return RFAILED;
    }
    else
    {
@@ -505,10 +541,10 @@ S16 BuildAndSendRicSubscriptionRsp()
    if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
    {
       DU_LOG("\nE2AP : Sending RIC Subscription Response failed");      
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    
-   RETVALUE(ROK);
+   return ROK;
 }
 /******************************************************************
 *
@@ -548,10 +584,10 @@ S16 procE2SetupRsp(E2AP_PDU_t *e2apMsg)
             recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID.pLMN_Identity);
 
             bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID.ric_ID, &e2SetupRspDb.ricId);
-            
-            aper_decode(0, &asn_DEF_PLMN_IdentityE2, (void **)&e2SetupRspDb.plmn, &e2SetRspMsg->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID.pLMN_Identity, recvBufLen, 0, 0);
-            //xer_fprint(stdout, &asn_DEF_PLMN_IdentityE2, &e2SetupRspDb.plmn);
+            aper_decode(0, &asn_DEF_PLMN_IdentityE2, (void **)&e2SetupRspDb.plmn, \
+              &e2SetRspMsg->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID.pLMN_Identity, recvBufLen, 0, 0);
 
+            xer_fprint(stdout, &asn_DEF_PLMN_IdentityE2, &e2SetupRspDb.plmn);
             break;
          }
          default:
@@ -560,7 +596,7 @@ S16 procE2SetupRsp(E2AP_PDU_t *e2apMsg)
             break;
       }
    }
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /******************************************************************
@@ -597,13 +633,16 @@ S16 procRicSubsReq(E2AP_PDU_t *e2apMsg)
       {
          case ProtocolIE_IDE2_id_RICrequestID:
          {
-            ricReqDb.ricReqId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID;
-            ricReqDb.ricInstanceId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID;
+            ricReqDb.ricReqId = ricSubsReq->protocolIEs.list.array[idx]->\
+                                   value.choice.RICrequestID.ricRequestorID;
+            ricReqDb.ricInstanceId = ricSubsReq->protocolIEs.list.array[idx]-> \
+                                       value.choice.RICrequestID.ricInstanceID;
             break;
          }
          case ProtocolIE_IDE2_id_RANfunctionID:
          {
-            ricReqDb.ranFuncId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RANfunctionID; 
+            ricReqDb.ranFuncId = ricSubsReq->protocolIEs.list.array[idx]-> \
+                                   value.choice.RANfunctionID; 
             break;
          }
          case ProtocolIE_IDE2_id_RICsubscriptionDetails:
@@ -614,9 +653,9 @@ S16 procRicSubsReq(E2AP_PDU_t *e2apMsg)
             recvBufLen = sizeof(ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition);
 
             aper_decode(0, &asn_DEF_RICeventTriggerDefinition, (void **)&ricReqDb.ricEventTrigger, &(ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition), recvBufLen, 0, 0);
-            //xer_fprint(stdout, &asn_DEF_RICeventTriggerDefinition, &ricReqDb.ricEventTrigger);
+            xer_fprint(stdout, &asn_DEF_RICeventTriggerDefinition, &ricReqDb.ricEventTrigger);
 
-            actionItem = *ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.list.array;
+            actionItem =(RICaction_ToBeSetup_ItemIEs_t *) ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.list.array[0];
             
             for(ied = 0; ied < ricSubsReq->protocolIEs.list.array[idx]->value.choice.\
                                 RICsubscriptionDetails.ricAction_ToBeSetup_List.list.count; ied++)
@@ -673,7 +712,6 @@ S16 BuildAndSendRicIndication()
    U8   elementCnt;
    U8   idx;
    U8   ieId;
-   S16  ret; 
    asn_enc_rval_t             encRetVal;        /* Encoder return value */
 
    DU_LOG("\nE2AP : Building Ric Indication Message\n");
@@ -682,7 +720,7 @@ S16 BuildAndSendRicIndication()
    if(e2apMsg == NULLP)
    {
       DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
 
    e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
@@ -691,7 +729,7 @@ S16 BuildAndSendRicIndication()
    {
       DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
       DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICindication;
    e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
@@ -713,7 +751,7 @@ S16 BuildAndSendRicIndication()
       DU_LOG("\nE2AP : Memory allocation for RICindicationIEs failed");
       DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
       DU_FREE(e2apMsg, (Size)sizeof(E2AP_PDU_t));
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
    
    for(idx=0; idx<elementCnt; idx++)
@@ -732,7 +770,7 @@ S16 BuildAndSendRicIndication()
          DU_FREE(e2apMsg->choice.initiatingMessage, \
                sizeof(InitiatingMessageE2_t));
          DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
-         RETVALUE(RFAILED);
+         return RFAILED;
       }
    }
    idx = 0;
@@ -772,17 +810,23 @@ S16 BuildAndSendRicIndication()
    ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
    ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
                                    RICindication_IEs__value_PR_RICindicationHeader;
-   BuildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
+   ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size = 3 * sizeof(U8);
+   DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf ,\
+     ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
+   buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
                 &ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader);
 
    /* TO BE CHANGED: RIC INDICATION DATA */
-   /* Foe now filling a dummy octect data, need to tested with PRBs*/ 
+   /* For now filling a dummy octect data, need to tested with PRBs*/ 
    idx++;
    ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationMessage;
    ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
    ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
                                   RICindication_IEs__value_PR_RICindicationMessage;
-   BuildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
+   ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size = 3 * sizeof(U8);
+   DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf ,\
+     ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
+   buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
                 &ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage);
   
    /* Prints the Msg formed */
@@ -796,7 +840,7 @@ S16 BuildAndSendRicIndication()
    {
           DU_LOG("\nE2AP : Could not encode RIC Indication Message (at %s)\n",\
                           encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
-          RETVALUE(RFAILED);
+          return RFAILED;
    }
    else
    {
@@ -810,9 +854,9 @@ S16 BuildAndSendRicIndication()
    if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
    {
       DU_LOG("\nE2AP : Sending RIC Indication Message");      
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /*******************************************************************
@@ -846,24 +890,24 @@ S16 SendE2APMsg(Region region, Pool pool)
          {
             DU_LOG("\nE2AP : SCTP Send for E2  failed");
             SPutMsg(mBuf);
-            RETVALUE(RFAILED);
+            return RFAILED;
          }
       }
       else
       {
          DU_LOG("\nE2AP : SAddPstMsgMult failed");
          SPutMsg(mBuf);
-         RETVALUE(RFAILED);
+         return RFAILED;
       }
       SPutMsg(mBuf);
    }
    else
    {
       DU_LOG("\nE2AP : Failed to allocate memory");
-      RETVALUE(RFAILED);
+      return RFAILED;
    }
  
-   RETVALUE(ROK);
+   return ROK;
 } /* SendE2APMsg */
 
 /*******************************************************************