[Epic-ID: ODUHIGH-516][Task-ID: ODUHIGH-534] Handling of reset rsp
[o-du/l2.git] / src / du_app / du_e2ap_msg_hdl.c
index 2041f9b..6f366b6 100644 (file)
@@ -117,6 +117,62 @@ void fillE2Cause(CauseE2_t *e2Cause, E2FailureCause failureCause)
    }
 }
 
+/*******************************************************************
+ *
+ * @brief Printing Type and Cause of failure
+ *
+ * @details
+ *
+ *    Function : printE2ErrorCause
+ *
+ *    Functionality: Printing Type and Cause of failure
+ *
+ * @params[in] E2 Cause
+ * @return void
+ *
+ ******************************************************************/
+void printE2ErrorCause(CauseE2_t *cause)
+{
+   switch(cause->present)
+   {
+      case CauseE2_PR_ricRequest:
+         {
+            DU_LOG("Failure_Type [%s] Cause [%ld]", "RIC_Request", cause->choice.ricRequest);
+            break;
+         }
+      case CauseE2_PR_ricService:
+         {
+            DU_LOG("Failure_Type [%s] Cause [%ld]", "RIC_Service", cause->choice.ricService);
+            break;
+         }
+      case CauseE2_PR_e2Node:
+         {
+            DU_LOG("Failure_Type [%s] Cause [%ld]", "E2_Node", cause->choice.e2Node);
+            break;
+         }
+      case CauseE2_PR_transport:
+         {
+            DU_LOG("Failure_Type [%s] Cause [%ld]", "Transport", cause->choice.transport);
+            break;
+         }
+      case CauseE2_PR_protocol:
+         {
+            DU_LOG("Failure_Type [%s] Cause [%ld]", "Protocol", cause->choice.protocol);
+            break;
+         }
+      case CauseE2_PR_misc:
+         {
+            DU_LOG("Failure_Type [%s] Cause [%ld]", "Miscellaneous", cause->choice.misc);
+            break;
+         }
+      default:
+         {
+            DU_LOG("Failure_Type and Cause unknown");
+            break;
+         }
+   }
+}
+
 /*******************************************************************
  *
  * @brief Free the ErrorIndication Message
@@ -2126,13 +2182,13 @@ void freeAperDecodingOfE2SetupRsp(E2setupResponse_t *e2SetRspMsg)
  *    Functionality: Processes E2 Setup Response sent by RIC
  *
  * @params[in] E2AP_PDU_t ASN decoded E2AP message
- * @return ROK     - success
- *         RFAILED - failure
+ * @return void
  *
  * ****************************************************************/
 
-uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
+void procE2SetupRsp(E2AP_PDU_t *e2apMsg)
 {
+   bool invalidTransId = false;
    uint8_t arrIdx =0, transId=0, idx=0; 
    uint32_t recvBufLen;             
    E2setupResponse_t *e2SetRspMsg=NULL;
@@ -2160,7 +2216,7 @@ uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
                else
                {
                   DU_LOG("\nERROR  -->  E2AP : Invalid transaction id [%d]", transId);
-                  return RFAILED;
+                  invalidTransId = true;
                }
                break;
             }
@@ -2170,60 +2226,67 @@ uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
                /* To store the Ric Id Params */
                recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value\
                      .choice.GlobalRIC_ID.pLMN_Identity.size);
-                  memcpy(&duCb.e2apDb.ricId.plmnId, e2SetRspMsg->protocolIEs.list.array[arrIdx]\
-                        ->value.choice.GlobalRIC_ID.pLMN_Identity.buf, recvBufLen);
+               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.ricId.plmnId memory to be deallocated after the usage */
                break;
             }
 
          case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
-         {
-            e2NodeCfgAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
-            for(idx =0; idx <e2NodeCfgAckList->list.count; idx++)
             {
-               e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeCfgAckList->list.array[idx];
-               switch(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.present)
+               e2NodeCfgAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
+               for(idx =0; idx <e2NodeCfgAckList->list.count; idx++)
                {
-                  case E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1:
-                     {
-                        e2NodeComponentInfo = fetchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD, &node);
-                        if(!e2NodeComponentInfo)
-                        {
-                           DU_LOG("\nERROR  --> E2AP : Received null e2NodeComponentInfo at line number %d",__LINE__);
-                           return RFAILED;
-                        }
-                        else
+                  e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeCfgAckList->list.array[idx];
+                  switch(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.present)
+                  {
+                     case E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1:
                         {
-                           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));
+                           e2NodeComponentInfo = fetchE2NodeComponentInfo(F1, E2_NODE_COMPONENT_ADD, &node);
+                           if(!e2NodeComponentInfo)
+                           {
+                              DU_LOG("\nERROR  --> E2AP : Received null e2NodeComponentInfo at line number %d",__LINE__);
+                           }
+                           else
+                           {
+                              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));
+                           }
+                           break;
                         }
+                     default:
                         break;
-                     }
-                  default:
-                     break;
+                  }
                }
+               break;
             }
-            break;
-         }
 
          default:
-            DU_LOG("\nERROR  -->  E2AP : Invalid IE received in E2SetupRsp:%ld",
-                  e2SetRspMsg->protocolIEs.list.array[arrIdx]->id);
-            break;
+            {
+               DU_LOG("\nERROR  -->  E2AP : Invalid IE received in E2SetupRsp:%ld",
+                     e2SetRspMsg->protocolIEs.list.array[arrIdx]->id);
+               break;
+            }
+      }
+
+      if(invalidTransId == true)
+      {
+         break;
       }
    }
    freeAperDecodingOfE2SetupRsp(e2SetRspMsg);
 
-   if(duSendE2NodeConfigurationUpdate() != ROK)
+   if(invalidTransId == false)
    {
-      DU_LOG("\nERROR  -->  E2AP : Failed to send E2 node config update");
-      return RFAILED;
+      if(duSendE2NodeConfigurationUpdate() != ROK)
+      {
+         DU_LOG("\nERROR  -->  E2AP : Failed to send E2 node config update");
+      }
    }
-   return ROK;
 }
 
 /*******************************************************************
@@ -2560,13 +2623,7 @@ uint8_t extractMeasInfoList(CmLListCp *measInfoSupportedList, MeasurementInfoLis
        * Break out of for loop to search in next report style */
       if(!measInfoSubscribedDb)
       {
-         while(measInfoSubscribedList->count)
-         {
-            measToDelNode = cmLListDelFrm(measInfoSubscribedList, measInfoSubscribedList->first);
-            measInfoToDel = (MeasurementInfo*)measToDelNode->node;
-            DU_FREE(measInfoToDel, sizeof(MeasurementInfo));
-            DU_FREE(measToDelNode, sizeof(CmLList));
-         }
+         deleteMeasurementInfoList(measInfoSubscribedList);
          break;
       }
 
@@ -2752,8 +2809,7 @@ uint8_t extractRicActionToBeSetup(RanFunction *ranFuncDb, RicSubscription *ricSu
 
                   /* In case of any failure, action is rejected
                    * Added to rejected-action-list in subscription response */
-                  memset(&ricSubscriptionInfo->actionSequence[ricActionId], 0, sizeof(ActionInfo));
-                  ricSubscriptionInfo->actionSequence[ricActionId].actionId = -1;
+                  deleteActionSequence(&ricSubscriptionInfo->actionSequence[ricActionId]);
 
                   subsRsp->rejectedActionList[subsRsp->numOfRejectedActions].id = ricActionId;
                   if(failureCause->causeType == E2_NOTHING)
@@ -3374,16 +3430,11 @@ uint8_t fillMeasRecord(MeasurementRecord_t *measRecord, MeasurementInfo *measInf
          measRecord->list.array[measRecIdx]->choice.real = measVal;
      }
      measRecIdx++;
-
+     measValNode= measValNode->next;  
      /* Once the measurement record is added to the message, delete it from DB */
-     cmLListDelFrm(&measInfoDb->measuredValue, measValNode);
-     DU_FREE(measValNode->node, sizeof(double));
-     DU_FREE(measValNode, sizeof(CmLList));
-
-     CM_LLIST_FIRST_NODE(&measInfoDb->measuredValue, measValNode);
      measVal = 0;
    }
-
+   deleteMeasuredValueList(&measInfoDb->measuredValue);
    return ROK;
 }
 
@@ -4444,6 +4495,7 @@ void FreeE2ResetRequest(E2AP_PDU_t *e2apMsg)
  *         - Buld and send the E2 reset request msg to RIC
  *
  * @params[in]
+ *    Reset cause
  * @return ROK     - success
  *         RFAILED - failure
  *
@@ -4529,13 +4581,13 @@ uint8_t BuildAndSendE2ResetRequest(E2FailureCause resetCause)
             encBuf);
       if(encRetVal.encoded == ENCODE_FAIL)
       {
-         DU_LOG("\nERROR  -->  E2AP : Could not encode E2SetupRequest structure (at %s)\n",\
+         DU_LOG("\nERROR  -->  E2AP : Could not encode reset request structure (at %s)\n",\
                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
          break;
       }
       else
       {
-         DU_LOG("\nDEBUG   -->  E2AP : Created APER encoded buffer for E2SetupRequest\n");
+         DU_LOG("\nDEBUG   -->  E2AP : Created APER encoded buffer for reset request\n");
 #ifdef DEBUG_ASN_PRINT
          for(int i=0; i< encBufSize; i++)
          {
@@ -4617,14 +4669,15 @@ void freeAperDecodingOfE2ResetRsp(ResetResponseE2_t *resetResponse)
  *    Functionality: Processes E2 Reset Response sent by RIC
  *
  * @params[in] E2AP_PDU_t ASN decoded E2AP message
- * @return ROK     - success
- *         RFAILED - failure
+ * @return void
  *
  * ****************************************************************/
-uint8_t procResetResponse(E2AP_PDU_t *e2apMsg)
+void procResetResponse(E2AP_PDU_t *e2apMsg)
 {
-   uint8_t ieIdx =0, transId;
-   ResetResponseE2_t *resetResponse;
+   bool invalidTransId=false;
+   uint8_t ieIdx =0, transId =0;
+   uint16_t ranFuncIdx=0;
+   ResetResponseE2_t *resetResponse =NULLP;
 
    DU_LOG("\nINFO   -->  E2AP : E2 Reset Response received");
    resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;;
@@ -4634,36 +4687,47 @@ uint8_t procResetResponse(E2AP_PDU_t *e2apMsg)
       switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
       {
          case ProtocolIE_IDE2_id_TransactionID:
-            transId = resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
-            if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) && \
-                  (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
             {
-               memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
+               transId = resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
+               if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) && \
+                     (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
+               {
+                  memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
+               }
+               else
+               {
+                  DU_LOG("\nERROR  -->  E2AP : Invalid transaction id [%d]", transId);
+                  invalidTransId = true;
+               }
+               break;
             }
-            else
+         case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
             {
-               DU_LOG("\nERROR  -->  E2AP : Invalid transaction id [%d]", transId);
-               return RFAILED;
+               for(ranFuncIdx=0; ranFuncIdx<MAX_RAN_FUNCTION; ranFuncIdx++)
+               {
+                  if(duCb.e2apDb.ranFunction[ranFuncIdx].id >0)
+                  {
+                     deleteRicSubscriptionList(&(duCb.e2apDb.ranFunction[ranFuncIdx].subscriptionList));
+                     memset(&(duCb.e2apDb.ranFunction[ranFuncIdx].pendingSubsRspInfo), 0, MAX_PENDING_SUBSCRIPTION_RSP*sizeof(PendingSubsRspInfo));
+                  }
+               }
+               break;
             }
-            break;
-         case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
-            /* As per ORAN WG3 E2AP spec v3.0, section 9.2.2
-               Criticality Diagnostics IE is sent by Near-RT RIC when parts of a received message i.e. 
-               Reset Request in this case, have not been comprehended or were missing, or if the message 
-               contained logical errors.
-
-               Processing of this ID should be implemented when negative call flows are to be supported.
-             */
-            break;
          default:
-            DU_LOG("\nERROR  -->  E2AP : Invalid IE received in E2 Reset Response : %ld",
-                  resetResponse->protocolIEs.list.array[ieIdx]->id);
-            break;
+            {
+               DU_LOG("\nERROR  -->  E2AP : Invalid IE received in E2 Reset Response : %ld",
+                     resetResponse->protocolIEs.list.array[ieIdx]->id);
+               break;
+            }
+      }
+
+      if(invalidTransId == true)
+      {
+         break;
       }
    }
 
    freeAperDecodingOfE2ResetRsp(resetResponse);
-   return ROK;
 }
 
 /******************************************************************
@@ -5784,9 +5848,13 @@ uint8_t FillRicSubsModRequired(RICsubscriptionModificationRequired_t *ricSubsMod
    uint8_t ieIdx = 0, elementCnt=0, actionIdx = 0;
    uint8_t numActionsMod = 0, numActionsRmv = 0;
    RICsubscriptionModificationRequired_IEs_t *ricSubsModReqdIe = NULLP;
-   RICactions_RequiredToBeModified_List_t *actionToBeModList = NULLP;
    RICactions_RequiredToBeRemoved_List_t  *actionToBeRmvList = NULLP;
 
+/* Unused in case of E2SM-KPM */
+#if 0
+   RICactions_RequiredToBeModified_List_t *actionToBeModList = NULLP;
+#endif
+
    /* Count number of Actions to be modified or deleted */
    for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
    {
@@ -6112,11 +6180,14 @@ void procRicSubscriptionModificationConfirm(E2AP_PDU_t *e2apMsg)
    RICsubscriptionModificationConfirm_t *ricSubsModCfm = NULLP;
    RICsubscriptionModificationConfirm_IEs_t *ricSubsModCfmIe = NULLP;
 
+/* Not used in case of E2SM-KPM */
+#if 0
    RICactions_ConfirmedForModification_List_t *modCfmList = NULLP;
    RICaction_ConfirmedForModification_ItemIEs_t *modCfmListItem = NULLP;
 
    RICactions_RefusedToBeModified_List_t *modRefusedList = NULLP;
    RICaction_RefusedToBeModified_ItemIEs_t *modRefusedListItem = NULLP;
+#endif
 
    RICactions_ConfirmedForRemoval_List_t *rmvCfmList = NULLP;
    RICaction_ConfirmedForRemoval_ItemIEs_t *rmvCfmListItem = NULLP;
@@ -6257,8 +6328,8 @@ void procRicSubscriptionModificationConfirm(E2AP_PDU_t *e2apMsg)
                      }
                      else
                      {
-                        memset(actionDb, 0, sizeof(ActionInfo));
-                        actionDb->actionId = -1;
+                        deleteActionSequence(actionDb);
+                        actionDb =NULLP;
                         ricSubsDb->numOfActions--;
                         /* Further handling can include :
                          * Deletion of this action from all DU layers 
@@ -6305,6 +6376,377 @@ void procRicSubscriptionModificationConfirm(E2AP_PDU_t *e2apMsg)
    return;
 }
 
+/******************************************************************
+* @brief Deallocate the memory allocated for E2 Reset Response
+*
+* @details
+*
+*    Function : FreeE2ResetResponse
+*
+*    Functionality:
+*       - freeing the memory allocated for E2ResetResponse
+*
+* @params[in] E2AP_PDU_t *e2apMsg
+* @return ROK     - success
+*         RFAILED - failure
+*
+* ****************************************************************/
+void FreeE2ResetResponse(E2AP_PDU_t *e2apMsg)
+{
+   uint8_t ieIdx =0;
+   ResetResponseE2_t *resetResponse;
+
+   if(e2apMsg != NULLP)
+   {
+      if(e2apMsg->choice.successfulOutcome != NULLP)
+      {
+         resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;
+         if(resetResponse->protocolIEs.list.array)
+         {
+            for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
+            {
+               if(resetResponse->protocolIEs.list.array[ieIdx])
+               {
+                  DU_FREE(resetResponse->protocolIEs.list.array[ieIdx], sizeof(ResetResponseIEs_t));
+               }
+            }
+            DU_FREE(resetResponse->protocolIEs.list.array, resetResponse->protocolIEs.list.size);
+         }
+
+         DU_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
+      }
+      DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
+   }
+}
+
+/*******************************************************************
+ *
+ * @brief Buld and send the E2 Reset Response msg
+ *
+ * @details
+ *
+ *    Function : BuildAndSendE2ResetResponse
+ *
+ *    Functionality:
+ *         - Buld and send the E2 Reset Response Message
+ *
+ * @params[in] Trans Id
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t BuildAndSendResetResponse(uint8_t transId)
+{
+   uint8_t           ieIdx = 0, elementCnt = 0;
+   uint8_t           ret = RFAILED;
+   E2AP_PDU_t        *e2apMsg = NULLP;
+   ResetResponseE2_t *resetResponse;
+   asn_enc_rval_t    encRetVal;       /* Encoder return value */
+
+   DU_LOG("\nINFO   -->  E2AP : Building E2 Reset Response Message\n");
+   do
+   {
+      DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
+      if(e2apMsg == NULLP)
+      {
+         DU_LOG("\nERROR  -->  E2AP : BuildAndSendResetResponse(): Memory allocation for E2AP-PDU failed");
+         break;
+      }
+      e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
+
+      DU_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
+      if(e2apMsg->choice.successfulOutcome == NULLP)
+      {
+         DU_LOG("\nERROR  -->  E2AP : BuildAndSendResetResponse: Memory allocation failed for successfulOutcome");
+         break;
+      }
+
+      e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_Reset;
+      e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
+      e2apMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_ResetResponseE2;
+      resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;
+
+      elementCnt = 1;
+      resetResponse->protocolIEs.list.count = elementCnt;
+      resetResponse->protocolIEs.list.size = elementCnt * sizeof(ResetResponseIEs_t *);
+      DU_ALLOC(resetResponse->protocolIEs.list.array, resetResponse->protocolIEs.list.size);
+      if(!resetResponse->protocolIEs.list.array)
+      {
+         DU_LOG("\nERROR  -->  E2AP : BuildAndSendResetResponse: Memory allocation failed for protocol IE array");
+         break;
+      }
+
+      for(ieIdx=0; ieIdx < elementCnt; ieIdx++)
+      {
+         DU_ALLOC(resetResponse->protocolIEs.list.array[ieIdx], sizeof(ResetResponseIEs_t));
+         if(!resetResponse->protocolIEs.list.array[ieIdx])
+         {
+            DU_LOG("\nERROR  -->  E2AP : BuildAndSendResetResponse: Memory allocation failed for protocol IE array element");
+            break;
+         }
+      }
+      if(ieIdx < elementCnt)
+         break;
+
+      ieIdx = 0;
+      resetResponse->protocolIEs.list.array[ieIdx]->id =  ProtocolIE_IDE2_id_TransactionID;
+      resetResponse->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
+      resetResponse->protocolIEs.list.array[ieIdx]->value.present = ResetResponseIEs__value_PR_TransactionID;
+      resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
+
+      xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
+
+      memset(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("\nERROR  -->  E2AP : Could not encode E2 reset response structure (at %s)\n",\
+               encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+         break;
+      }
+      else
+      {
+         DU_LOG("\nDEBUG  -->  E2AP : Created APER encoded buffer for E2 Reset Response \n");
+         for(int i=0; i< encBufSize; i++)
+         {
+            DU_LOG("%x",encBuf[i]);
+         }
+      }
+
+      /* Sending msg */
+      if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
+      {
+         DU_LOG("\nERROR  -->  E2AP : Failed to send E2 Reset Response");
+         break;
+      }
+
+      ret = ROK;
+      break;
+   }while(true);
+
+   FreeE2ResetResponse(e2apMsg);
+   return ret;
+}
+
+/******************************************************************
+ *
+ * @brief Deallocation of memory allocated by aper decoder for reset req
+ *
+ * @details
+ *
+ *    Function : freeAperDecodingOfE2ResetReq
+ *
+ *    Functionality: Deallocation of memory allocated by aper decoder for
+ *    reset req
+ *
+ * @params[in] Pointer to resetReq
+ * @return void
+ *
+ * ****************************************************************/
+void freeAperDecodingOfE2ResetReq(ResetRequestE2_t *resetReq)
+{
+   uint8_t arrIdx=0;
+
+   if(resetReq)
+   {
+      if(resetReq->protocolIEs.list.array)
+      {
+         for(arrIdx=0; arrIdx<resetReq->protocolIEs.list.count; arrIdx++)
+         {
+            if(resetReq->protocolIEs.list.array[arrIdx])
+            {
+               free(resetReq->protocolIEs.list.array[arrIdx]);
+            }
+         }
+         free(resetReq->protocolIEs.list.array);
+      }
+   }
+}
+
+/*******************************************************************
+ *
+ * @brief Process reset req received from RIC
+ *
+ * @details
+ *
+ *    Function : procE2ResetRequest
+ *
+ * Functionality: Process reset req received from RIC
+ *
+ * @param  E2AP_PDU_t  *e2apMsg
+ * @return void
+ *
+ ******************************************************************/
+
+void procE2ResetRequest(E2AP_PDU_t  *e2apMsg)
+{
+   uint16_t ranFuncIdx=0;
+   uint8_t arrIdx =0, transId =0;
+   ResetRequestE2_t *resetReq;
+
+   DU_LOG("\nINFO   -->  E2AP : E2 Reset request received");
+   resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
+
+   for(arrIdx=0; arrIdx<resetReq->protocolIEs.list.count; arrIdx++)
+   {
+      switch(resetReq->protocolIEs.list.array[arrIdx]->id)
+      {
+         case ProtocolIE_IDE2_id_TransactionID:
+            {
+               transId = resetReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
+               break;
+            }
+
+         case ProtocolIE_IDE2_id_CauseE2:
+            {
+               for(ranFuncIdx=0; ranFuncIdx<MAX_RAN_FUNCTION; ranFuncIdx++)
+               {
+                  if(duCb.e2apDb.ranFunction[ranFuncIdx].id >0)
+                  {
+                     deleteRicSubscriptionList(&(duCb.e2apDb.ranFunction[ranFuncIdx].subscriptionList));
+                     memset(&(duCb.e2apDb.ranFunction[ranFuncIdx].pendingSubsRspInfo), 0, MAX_PENDING_SUBSCRIPTION_RSP*sizeof(PendingSubsRspInfo));
+                  }
+               }
+               break;
+            }
+      }
+   }
+   if(BuildAndSendResetResponse(transId) != ROK)
+   {
+      DU_LOG("\nERROR  -->  E2AP : Failed to build and send reset response");
+   }
+   freeAperDecodingOfE2ResetReq(resetReq);
+}
+
+/*******************************************************************
+ *
+ * @brief Free APER decoding of RIC Subscription Modification Refuse
+ *
+ * @details
+ *
+ *    Function : freeAperDecodingOfRicSubsModRefuse
+ *
+ * Functionality:  Free APER decoding of RIC Subscription 
+ *   Modification Refuse
+ *
+ * @param  E2AP Message PDU
+ * @return void
+ *
+ ******************************************************************/
+void freeAperDecodingOfRicSubsModRefuse(E2AP_PDU_t *e2apMsg)
+{
+   uint8_t ieIdx =0;
+   RICsubscriptionModificationRefuse_t *ricSubsModRefuse = NULLP;
+
+   if(e2apMsg && e2apMsg->choice.unsuccessfulOutcome)
+   {
+      ricSubsModRefuse = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionModificationRefuse;
+      if(ricSubsModRefuse->protocolIEs.list.array)
+      {
+         for(ieIdx = 0; ieIdx < ricSubsModRefuse->protocolIEs.list.count; ieIdx++)
+         {
+            if(ricSubsModRefuse->protocolIEs.list.array[ieIdx])
+               free(ricSubsModRefuse->protocolIEs.list.array[ieIdx]);
+         }
+         free(ricSubsModRefuse->protocolIEs.list.array);
+      }
+   }
+}
+
+/*******************************************************************
+ *
+ * @brief Process RIC Subscription Modification Refuse Message
+ *
+ * @details
+ *
+ *    Function : procRicSubscriptionModificationRefuse
+ *
+ * Functionality:  Process RIC Subscription Modification Refuse
+ *    Message received from RIC. 
+ *
+ * @param  E2AP Message PDU
+ * @return void
+ *
+ ******************************************************************/
+void procRicSubscriptionModificationRefuse(E2AP_PDU_t *e2apMsg)
+{
+   uint8_t ieIdx = 0;
+   uint16_t ranFuncId = 0;
+   RicRequestId ricReqId;
+   RICsubscriptionModificationRefuse_t *ricSubsModRefuse = NULLP;
+   RICsubscriptionModificationRefuse_IEs_t *ricSubsModRefuseIe = NULLP;
+   CauseE2_t *cause = NULLP;
+
+   DU_LOG("\nINFO   -->  E2AP : %s: Received RIC Subscription Modification Refuse", __func__);
+
+   do{
+      if(!e2apMsg)
+      {
+         DU_LOG("\nERROR  -->  E2AP : %s: E2AP Message is NULL", __func__);
+         break;
+      }
+
+      if(!e2apMsg->choice.unsuccessfulOutcome)
+      {
+         DU_LOG("\nERROR  -->  E2AP : %s: Unsuccessful Outcome in E2AP message is NULL", __func__);
+         break;
+      }
+
+      ricSubsModRefuse = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionModificationRefuse;
+      if(!ricSubsModRefuse->protocolIEs.list.array)
+      {
+         DU_LOG("\nERROR  -->  E2AP : %s: Array conatining E2AP message IEs is null", __func__);
+         break;
+      }
+
+      for(ieIdx = 0; ieIdx < ricSubsModRefuse->protocolIEs.list.count; ieIdx++)
+      {
+         if(!ricSubsModRefuse->protocolIEs.list.array[ieIdx])
+         {
+            DU_LOG("\nERROR  -->  E2AP : %s: IE at index [%d] in E2AP message IEs list is null", __func__, ieIdx);
+            break;
+         }
+
+         ricSubsModRefuseIe = ricSubsModRefuse->protocolIEs.list.array[ieIdx];
+         switch(ricSubsModRefuseIe->id)
+         {
+            case ProtocolIE_IDE2_id_RICrequestID:
+               {
+                  memset(&ricReqId, 0, sizeof(RicRequestId));
+                  ricReqId.requestorId = ricSubsModRefuseIe->value.choice.RICrequestID.ricRequestorID;
+                  ricReqId.instanceId = ricSubsModRefuseIe->value.choice.RICrequestID.ricInstanceID;
+                  break;
+               }
+
+            case ProtocolIE_IDE2_id_RANfunctionID:
+               {
+                  ranFuncId = ricSubsModRefuseIe->value.choice.RANfunctionID;
+                  break;
+               }
+
+            case ProtocolIE_IDE2_id_CauseE2:
+               {
+                  DU_LOG("\nDEBUG  -->  E2AP : %s: RIC subscriptiom modification refused for RIC_Requestor_ID [%d] \
+                        RIC_Instance_ID [%d] RAN_Function_ID [%d] ", __func__, ricReqId.requestorId, \
+                        ricReqId.instanceId, ranFuncId);
+
+                  cause = &ricSubsModRefuseIe->value.choice.CauseE2;
+                  printE2ErrorCause(cause);
+               }
+
+            default:
+               break;
+         } /* End of switch for Protocol IE Id */
+      } /* End of for loop for Protocol IE list */
+
+      break;
+   }while(true);
+
+   freeAperDecodingOfRicSubsModRefuse(e2apMsg);
+   return;
+}
+
 /*******************************************************************
  *
  * @brief Handles received E2AP message and sends back response  
@@ -6394,6 +6836,11 @@ void E2APMsgHdlr(Buffer *mBuf)
                      procRicServiceUpdateFailure(e2apMsg);
                      break;
                   }
+               case UnsuccessfulOutcomeE2__value_PR_RICsubscriptionModificationRefuse:
+                  {
+                     procRicSubscriptionModificationRefuse(e2apMsg);
+                     break;
+                  }
                default:
                   {
                      DU_LOG("\nERROR  -->  E2AP : Invalid type of E2AP_PDU_PR_unsuccessfulOutcome  [%d]",\
@@ -6467,6 +6914,12 @@ void E2APMsgHdlr(Buffer *mBuf)
                      DU_LOG("\nINFO  -->  E2AP : Error indication received");
                      break;
                   }
+               case InitiatingMessageE2__value_PR_ResetRequestE2:
+                  {
+                     DU_LOG("\nINFO  -->  E2AP : Error indication received");
+                     procE2ResetRequest(e2apMsg);
+                     break;
+                  }
                default:
                   {
                      DU_LOG("\nERROR  -->  E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\