[Epic-ID: ODUHIGH-516][Task-ID: 526] Implementation of ric service update 89/11789/5
authorlal.harshita <Harshita.Lal@radisys.com>
Wed, 13 Sep 2023 14:20:10 +0000 (19:50 +0530)
committerpborla <pborla@radisys.com>
Thu, 14 Sep 2023 13:22:42 +0000 (18:52 +0530)
Change-Id: Ibf53e48070ecbe2c70187b06496afcb732480586
Signed-off-by: lal.harshita <Harshita.Lal@radisys.com>
Signed-off-by: pborla <pborla@radisys.com>
src/du_app/du_cfg.c
src/du_app/du_e2ap_mgr.h
src/du_app/du_e2ap_msg_hdl.c
src/ric_stub/ric_e2ap_msg_hdl.c

index 872a426..849f5ec 100644 (file)
@@ -1166,6 +1166,7 @@ uint8_t duReadCfg()
 
    /* Initialize the timer blocks */
    cmInitTimers(&(duCb.e2apDb.e2TimersInfo.e2Timers.e2SetupTimer), 1);
+   cmInitTimers(&(duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.timer), 1);
 
    /* Initialzie the timer queue */   
    memset(&(duCb.duTimersInfo.tmrTq), 0, sizeof(CmTqType) * DU_TQ_SIZE);
index c6a6d67..e59e646 100644 (file)
  *******************************************************************************/
 
 /* This file contains all E2AP message handler related functionality */
-
-#define MAX_NUM_TRANSACTION 256 /* As per, O-RAN WG3 E2AP v3.0, section 9.2.33 */
 #define MAX_E2_SETUP_TMR 1
+#define MAX_RIC_SERVICE_UPDATE_TMR 1
+
 #define EVENT_E2_SETUP_TMR 1
+#define EVENT_RIC_SERVICE_UPDATE_TMR 2
+
+#define MAX_NUM_TRANSACTION 256 /* As per, O-RAN WG3 E2AP v3.0, section 9.2.33 */
 #define MAX_RAN_FUNCTION 256        /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.1.2.2 : maxofRANfunctionID */
 #define MAX_E2_NODE_COMPONENT 1024     /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.1.2.2 : maxofE2nodeComponents */
 #define MAX_TNL_ASSOCIATION 32         /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.1.2.11 : maxofTNLA */
@@ -175,9 +178,39 @@ typedef struct e2Transcation
    E2TransInfo ricInitTransaction[MAX_NUM_TRANSACTION]; /* Storing RIC-initiated transactions information */
 }E2Transaction;
 
+typedef struct
+{
+   uint16_t   id;
+   uint16_t   revisionCounter;
+}RanFuncInfo;
+
+typedef struct
+{
+   uint8_t     numOfRanFunToBeAdded;
+   RanFuncInfo ranFunToBeAdded[MAX_RAN_FUNCTION];
+   uint8_t     numOfRanFunToBeModified;
+   RanFuncInfo ranFunToBeModified[MAX_RAN_FUNCTION];
+   uint8_t     numOfRanFunToBeDeleted;
+   RanFuncInfo ranFunToBeDeleted[MAX_RAN_FUNCTION];
+}E2TmpRanFunList;
+
+typedef struct ricServiceUpdate
+{
+   E2ProcedureDirection dir;
+   uint8_t              transId;
+   E2TmpRanFunList      recvRanFuncList;
+}RicServiceUpdate;
+
+typedef struct 
+{
+   RicServiceUpdate ricService;
+   CmTimer          timer;
+}RicServiceUpdateTimer;
+
 typedef struct e2Timer
 {
    CmTimer e2SetupTimer;
+   RicServiceUpdateTimer ricServiceUpdateTimer;
    /* More timers can be added to this structure in future */
 }E2Timer;
 
@@ -392,21 +425,6 @@ typedef struct
    E2TimersInfo     e2TimersInfo;
 }E2apDb;
 
-typedef struct
-{
-   uint16_t   id;
-   uint16_t   revisionCounter;
-}RanFuncInfo;
-
-typedef struct
-{
-   uint8_t addCount;
-   uint8_t addArr[MAX_RAN_FUNCTION];
-   uint8_t modCount;
-   uint8_t modArr[MAX_RAN_FUNCTION];
-   uint8_t delCount;
-   RanFuncInfo delArr[MAX_RAN_FUNCTION];
-}E2TmpRanFunList;
 
 uint8_t assignTransactionId();
 uint8_t ResetE2Request(E2ProcedureDirection dir, E2CauseType type, E2Cause cause);
index eb72634..49586c5 100644 (file)
@@ -731,7 +731,7 @@ uint8_t BuildRanFunctionItem(RANfunction_Item_t *ranFuncItem, RanFunction *ranFu
  *
  ******************************************************************/
 
-uint8_t BuildRanFunctionAddList(RANfunctions_List_t *ranFunctionsList, uint8_t procedureCode, uint8_t count, uint8_t *recvList)
+uint8_t BuildRanFunctionAddList(RANfunctions_List_t *ranFunctionsList, uint8_t procedureCode, uint8_t count, RanFuncInfo *recvList)
 {
    uint16_t id;
    RanFunction *ranFuncDb;
@@ -773,7 +773,7 @@ uint8_t BuildRanFunctionAddList(RANfunctions_List_t *ranFunctionsList, uint8_t p
       {
          /* Getting only the RAN function information from DuCb whose Id is
           * present in the received array */
-         id =recvList[ranFuncIdx];
+         id =recvList[ranFuncIdx].id;
          ranFuncDb = &duCb.e2apDb.ranFunction[id-1];
       }
       ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncIdx];
@@ -2569,6 +2569,497 @@ void procE2SetupFailure(E2AP_PDU_t *e2apMsg)
 
    freeAperDecodingOfE2SetupFailure(e2SetupFailure);
 }
+/******************************************************************
+ *
+ * @brief Deallocation of memory allocated bu aper decoder for RIC service Query
+ *
+ * @details
+ *
+ *    Function : freeAperDecodingOfRicServiceQuery
+ *
+ *    Functionality: Deallocation of memory allocated bu aper decoder for RIC
+ *    service Query
+ *
+ * @params[in] RICserviceQuery_t *ricServiceQuery;
+ * @return void
+ *
+ * ****************************************************************/
+
+void freeAperDecodingOfRicServiceQuery(RICserviceQuery_t *ricServiceQuery)
+{
+   uint8_t arrIdx,ranFuncIdx;
+    RANfunctionsID_List_t *ranFuncAddedList;
+
+   if(ricServiceQuery)
+   {
+      if(ricServiceQuery->protocolIEs.list.array)
+      {
+         for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
+         {
+            if(ricServiceQuery->protocolIEs.list.array[arrIdx])
+            {
+               switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
+               {
+                  case ProtocolIE_IDE2_id_RANfunctionsAccepted:
+                  {
+                     ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
+                     if(ranFuncAddedList->list.array)
+                     {
+                        for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
+                        {
+                           free(ranFuncAddedList->list.array[ranFuncIdx]);
+                        }
+                        free(ranFuncAddedList->list.array);;
+                     }
+                     break;
+                  }
+                  default:
+                     break;
+               }
+               free(ricServiceQuery->protocolIEs.list.array[arrIdx]);
+            }
+         }
+         free(ricServiceQuery->protocolIEs.list.array);
+      }
+   }
+}
+/*******************************************************************
+ *
+ * @brief Build RanFunction Delete List
+ *
+ * @details
+ *
+ *    Function : BuildRanFunctionDeleteList
+ *
+ * Functionality:  Build RanFunction Delete List
+ *
+ * @params[in]
+ *    RANfunctionsID List
+ *    Count of the RAN function
+ *    Received RAN function list
+ *
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildRanFunctionDeleteList(RANfunctionsID_List_t *deleteList, uint8_t count, RanFuncInfo *recvdRanFunc)
+{
+   uint8_t ranFuncIdx=0;
+   RANfunctionID_ItemIEs_t *delRanFuncItem;
+
+   if(count)
+   {
+      deleteList->list.count = count;
+      deleteList->list.size = deleteList->list.count * sizeof(RANfunctionID_ItemIEs_t*);
+      DU_ALLOC(deleteList->list.array, deleteList->list.size);
+      if(deleteList->list.array == NULLP)
+      {
+         DU_LOG("\nERROR  --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
+         return RFAILED;
+      }
+      for(ranFuncIdx = 0; ranFuncIdx< deleteList->list.count; ranFuncIdx++)
+      {
+         DU_ALLOC(deleteList->list.array[ranFuncIdx], sizeof(RANfunctionID_ItemIEs_t));
+         if(deleteList->list.array[ranFuncIdx] == NULLP)
+         {
+            DU_LOG("\nERROR  --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
+            return RFAILED;
+         }
+         delRanFuncItem= (RANfunctionID_ItemIEs_t *) deleteList->list.array[ranFuncIdx];
+         delRanFuncItem->id = ProtocolIE_IDE2_id_RANfunctionID_Item;
+         delRanFuncItem->criticality = CriticalityE2_ignore;
+         delRanFuncItem->value.choice.RANfunctionID_Item.ranFunctionID = recvdRanFunc[ranFuncIdx].id;
+         delRanFuncItem->value.choice.RANfunctionID_Item.ranFunctionRevision = recvdRanFunc[ranFuncIdx].revisionCounter;
+
+      }
+   }
+   return ROK;
+}
+/*******************************************************************
+ *
+ * @brief De Allocate  Ric Service Update message
+ *
+ * @details
+ *
+ *    Function : FreeRicServiceUpdate
+ *
+ *    Functionality: De-Allocating Ric Service Update message
+ *
+ * @params[in] E2AP_PDU_t *e2apMsg
+
+ * @return void
+ *
+ * ****************************************************************/
+
+void FreeRicServiceUpdate(E2AP_PDU_t *e2apMsg)
+{
+   uint8_t arrIdx = 0;
+   uint8_t ranFuncAddListIdx=0, ranFuncDelIdx=0;
+   RICserviceUpdate_t *ricServiceUpdate;
+   RANfunctions_List_t *ranFunctionsList;
+   RANfunction_ItemIEs_t *ranFuncItemIe;
+   RANfunction_Item_t  *ranFunItem;
+   RANfunctionsID_List_t *deleteList;
+
+   /* De-allocating Memory */
+   if(e2apMsg != NULLP)
+   {
+      if(e2apMsg->choice.initiatingMessage != NULLP)
+      {
+         ricServiceUpdate = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate;
+         if(ricServiceUpdate->protocolIEs.list.array != NULLP)
+         {
+            for(arrIdx = 0; arrIdx < ricServiceUpdate->protocolIEs.list.count; arrIdx++)
+            {
+               if(ricServiceUpdate->protocolIEs.list.array[arrIdx] != NULLP)
+               {
+                  switch(ricServiceUpdate->protocolIEs.list.array[arrIdx]->id)
+                  {
+                     case ProtocolIE_IDE2_id_TransactionID:
+                        break;
+
+                     case ProtocolIE_IDE2_id_RANfunctionsAdded:
+                     case ProtocolIE_IDE2_id_RANfunctionsModified:
+                        {
+                           ranFunctionsList = &(ricServiceUpdate->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;
+                        }
+                     case ProtocolIE_IDE2_id_RANfunctionsDeleted:
+                        {
+                           deleteList= &ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
+                           if(deleteList->list.array)
+                           {
+                              for(ranFuncDelIdx = 0; ranFuncDelIdx< deleteList->list.count; ranFuncDelIdx++)
+                              {
+                                 DU_FREE(deleteList->list.array[ranFuncDelIdx], sizeof(RANfunctionID_ItemIEs_t));
+                              }
+                              DU_FREE(deleteList->list.array, deleteList->list.size);
+  
+                           }
+                           break;
+                        }
+                     default:
+                        DU_LOG("\nERROR  --> E2AP: Invalid event at ricServiceUpdate %ld ",\
+                              (ricServiceUpdate->protocolIEs.list.array[arrIdx]->id));
+                        break;
+                  }
+                  DU_FREE(ricServiceUpdate->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdate_IEs_t));
+               }
+            }
+            DU_FREE(ricServiceUpdate->protocolIEs.list.array, ricServiceUpdate->protocolIEs.list.size);
+         }
+         DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+      }
+      DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
+   }
+}
+
+/*******************************************************************
+ *
+ * @brief Builds and Send the RicServiceUpdateuest
+ *
+ * @details
+ *
+ *    Function : BuildAndSendRicServiceUpdate
+ *
+ * Functionality:Fills the RicServiceUpdateuest
+ *
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildAndSendRicServiceUpdate(RicServiceUpdate serviceUpdate)
+{
+   uint8_t arrIdx = 0, elementCnt=0;
+   uint8_t transId = 0, ret = RFAILED;
+   bool memAllocFailed =false;
+   E2AP_PDU_t        *e2apMsg = NULLP;
+   RICserviceUpdate_t  *ricServiceUpdate = NULLP;
+   asn_enc_rval_t     encRetVal;       /* Encoder return value */
+
+   DU_LOG("\nINFO   -->  E2AP : Building Ric Service Update\n");
+   do
+   {
+      DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
+      if(e2apMsg == NULLP)
+      {
+         DU_LOG("\nERROR  -->  E2AP : 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("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
+         break;
+      }
+      e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
+      e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICserviceUpdate;
+      e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICserviceUpdate;
+      ricServiceUpdate = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate;
+      
+      /* For TransId IE, set elementCnt to 1.
+      If there is any item in the RAN function add list, RAN function modification list, or RAN function delete list, increment the elementCnt.*/
+
+      elementCnt =1;
+      if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
+        elementCnt++;
+      if(serviceUpdate.recvRanFuncList.numOfRanFunToBeModified)
+         elementCnt++;
+      if(serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted)
+         elementCnt++;
+       
+      ricServiceUpdate->protocolIEs.list.count = elementCnt;
+      ricServiceUpdate->protocolIEs.list.size = elementCnt * sizeof(RICserviceUpdate_IEs_t*);
+
+      /* Initialize the E2Setup members */
+      DU_ALLOC(ricServiceUpdate->protocolIEs.list.array, ricServiceUpdate->protocolIEs.list.size);
+      if(ricServiceUpdate->protocolIEs.list.array == NULLP)
+      {
+         DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for array elements");
+         break;
+      }
+      
+      for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
+      {
+         DU_ALLOC(ricServiceUpdate->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdate_IEs_t));
+         if(ricServiceUpdate->protocolIEs.list.array[arrIdx] == NULLP)
+         {
+            memAllocFailed = true;
+            DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for arrayIdx [%d]", arrIdx);
+            break;
+         }
+      }
+      if(memAllocFailed == true)
+         break;
+
+      arrIdx = 0;
+
+      /* TransactionID */
+      ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
+      ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+      ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
+      if(serviceUpdate.dir == E2_NODE_INITIATED)
+         transId = assignTransactionId();
+      else
+        transId = serviceUpdate.transId;
+      ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
+
+      if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
+      {
+         arrIdx++;
+         ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
+         ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+         ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
+         if(BuildRanFunctionAddList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List,\
+         e2apMsg->choice.initiatingMessage->procedureCode, serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded, serviceUpdate.recvRanFuncList.ranFunToBeAdded) !=ROK)
+         {
+            break;
+         }
+      }
+
+      if(serviceUpdate.recvRanFuncList.numOfRanFunToBeModified)
+      {
+         arrIdx++;
+         ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsModified;
+         ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+         ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
+         if(BuildRanFunctionAddList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List,
+         e2apMsg->choice.initiatingMessage->procedureCode, serviceUpdate.recvRanFuncList.numOfRanFunToBeModified, serviceUpdate.recvRanFuncList.ranFunToBeModified) !=ROK)
+         {
+            break;
+         }
+      }
+
+      if(serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted)
+      {
+         arrIdx++;
+         ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsDeleted;
+         ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+         ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctionsID_List;
+         if(BuildRanFunctionDeleteList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List,\
+         serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted, serviceUpdate.recvRanFuncList.ranFunToBeDeleted) != ROK)
+         {
+            break;
+         }
+      }
+      /* Prints the Msg formed */
+      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 RicServiceUpdateuest structure (at %s)\n",\
+               encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+         break;
+      }
+      else
+      {
+         DU_LOG("\nDEBUG   -->  E2AP : Created APER encoded buffer for RicServiceUpdateuest\n");
+#ifdef DEBUG_ASN_PRINT
+         for(int i=0; i< encBufSize; i++)
+         {
+            printf("%x",encBuf[i]);
+         }
+#endif
+      }
+      if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
+      {
+         DU_LOG("\nERROR  -->  E2AP : Sending E2 Setup request failed");
+         break;
+      }
+      ret = ROK;
+      break;
+   }while(true);
+   
+   if(ret == ROK)
+   {
+      if(serviceUpdate.dir == E2_NODE_INITIATED)
+      {
+         duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
+         duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
+      }
+      else
+      {
+         duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].transactionId = transId;
+         duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
+      }
+      duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.dir = serviceUpdate.dir;
+      duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.transId =transId;
+   }
+   FreeRicServiceUpdate(e2apMsg);
+   return ret;
+}
+/******************************************************************
+ *
+ * @brief Processes RIC service Query sent by RIC
+ *
+ * @details
+ *
+ *    Function : procRicServiceQuery
+ *
+ *    Functionality: Processes RIC service Query sent by RIC
+ *
+ * @params[in] E2AP_PDU_t ASN decoded E2AP message
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+
+void procRicServiceQuery(E2AP_PDU_t *e2apMsg)
+{
+   ConfigType action;
+   uint8_t arrIdx =0, ranFuncIdx=0,tmpIdx=0;
+   uint16_t id,revisionCcounter;
+   bool tmpArray[MAX_RAN_FUNCTION] = {false};
+   RICserviceQuery_t *ricServiceQuery=NULL;
+   RicServiceUpdate ricUpdate;
+   RANfunctionID_ItemIEs_t *ranFuncAddedItemIe;
+   RANfunctionsID_List_t *ranFuncAddedList;
+
+   DU_LOG("\nINFO   -->  E2AP : RIC Service Query received");
+   memset(&ricUpdate, 0, sizeof(RicServiceUpdate));
+   ricUpdate.dir = RIC_INITIATED;
+   ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
+
+   for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
+   {
+      switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
+      {
+         /* TODO completing in next patch/gerrit */
+         case ProtocolIE_IDE2_id_TransactionID:
+         {
+            ricUpdate.transId = ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
+            break;
+         }
+
+         case ProtocolIE_IDE2_id_RANfunctionsAccepted:
+         {
+            ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
+            if(ranFuncAddedList->list.array)
+            {
+               for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
+               {
+                  if(ranFuncAddedList->list.array[ranFuncIdx])
+                  {
+                     /* Using the RAN function Id, identify the RAN function to be modified or deleted.  */
+                     
+                     ranFuncAddedItemIe = (RANfunctionID_ItemIEs_t*)ranFuncAddedList->list.array[ranFuncIdx];
+                     id = ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionID;
+                     revisionCcounter = ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionRevision;
+                     
+                     if((id != duCb.e2apDb.ranFunction[id-1].id))
+                     {
+                        action = CONFIG_DEL;
+                     }
+                     else if((id == duCb.e2apDb.ranFunction[id-1].id)&&(revisionCcounter!=duCb.e2apDb.ranFunction[id-1].revisionCounter))
+                     {
+                        action = CONFIG_MOD;
+                     }
+
+                     if(action == CONFIG_DEL)
+                     {
+                        ricUpdate.recvRanFuncList.ranFunToBeDeleted[ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted].id = id;
+                        ricUpdate.recvRanFuncList.ranFunToBeDeleted[ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted].revisionCounter = revisionCcounter;
+                        ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted++;
+                     }
+                     else if(action == CONFIG_MOD)
+                     {
+                        ricUpdate.recvRanFuncList.ranFunToBeModified[ricUpdate.recvRanFuncList.numOfRanFunToBeModified].id = id;
+                        ricUpdate.recvRanFuncList.ranFunToBeModified[ricUpdate.recvRanFuncList.numOfRanFunToBeModified].revisionCounter = revisionCcounter;
+                        ricUpdate.recvRanFuncList.numOfRanFunToBeModified++;
+                     }
+
+                     /* If any ID is set to true, it means that the ID has been used in either modification or deletion list. 
+                      * Else we will add the IDs into the added list */
+                     tmpArray[id-1] = true;
+                  }
+               }
+            }
+            break;
+         }
+      }
+   }
+
+   /*  Traversing the whole RAN function list in ducb to check if any new Ran function ids have been added. */
+   for(arrIdx =0; arrIdx<MAX_RAN_FUNCTION; arrIdx++)
+   {
+      tmpIdx= ricUpdate.recvRanFuncList.numOfRanFunToBeAdded;
+      if((duCb.e2apDb.ranFunction[arrIdx].id >0)&&(!tmpArray[arrIdx]))
+      {
+         ricUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].id = duCb.e2apDb.ranFunction[arrIdx].id;
+         ricUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].revisionCounter = duCb.e2apDb.ranFunction[arrIdx].revisionCounter;
+         ricUpdate.recvRanFuncList.numOfRanFunToBeAdded++;
+      }
+   }
+   if(BuildAndSendRicServiceUpdate(ricUpdate)!= ROK)
+   {
+      DU_LOG("\nERROR  -->  E2AP : Failed to build and send ric service update message");
+   }
+
+   freeAperDecodingOfRicServiceQuery(ricServiceQuery);
+}
+
+
 /*******************************************************************
  *
  * @brief Handles received E2AP message and sends back response  
@@ -2699,6 +3190,11 @@ void E2APMsgHdlr(Buffer *mBuf)
                      procRicSubsReq(e2apMsg);
                      break;
                   }
+               case InitiatingMessageE2__value_PR_RICserviceQuery:
+                  {
+                     procRicServiceQuery(e2apMsg);
+                     break;
+                  }
                default:
                   {
                      DU_LOG("\nERROR  -->  E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\
index 6060f9c..5eebc63 100644 (file)
@@ -1794,6 +1794,12 @@ void E2APMsgHdlr(uint32_t *duId, Buffer *mBuf)
                      DU_LOG("\nINFO  -->  E2AP : RIC Indication Acknowledged");
                      break;
                   }
+               case InitiatingMessageE2__value_PR_RICserviceUpdate:
+                  {
+                     DU_LOG("\nINFO  -->  E2AP : RIC Service update received");
+                     break;
+                  }
+
                default:
                   {
                      DU_LOG("\nERROR  -->  E2AP : Invalid type of intiating message [%d]",e2apMsg->choice.initiatingMessage->value.present);