[Epic-ID: ODUHIGH-406] [Task-ID: ODUHIGH-439] Building Paging RRC PDU
[o-du/l2.git] / src / du_app / du_utils.c
index 95772fe..608efb7 100644 (file)
  *******************************************************************************/
 /* Utility definitions to be used in du app */
 #include "common_def.h"
+#include "lrg.h"
+#include "lrg.x"
+#include "lkw.x"
 #include "du_app_mac_inf.h"
+#include "du_app_rlc_inf.h"
+#include "du_cfg.h"
+#include "du_mgr.h"
 #include "du_utils.h"
 
 /* Spec Ref-38.214-Table 5.1.2.1-1 */
@@ -180,3 +186,366 @@ void fillStartSymbolAndLen(uint8_t numRsrcAlloc, PdschConfig *pdschCfg, PuschCfg
       }
    }
 }
+
+/*******************************************************************
+ * @brief Function to add a node to a linked list
+ *
+ * @details
+ *
+ *     Function: duAddNodeToLList
+ *
+ *     This function adds a new node to the linked list
+ *
+ *  @param[in]  Pointer to the list
+ *              Pointer to node to be added
+ *              Pointer to current node
+ *  @return     ROK
+ *              RFAILED
+*******************************************************************/
+uint8_t duAddNodeToLList(CmLListCp *llist, void *blockToAdd, CmLList *currNode)
+{
+   CmLList  *newNode = NULLP;
+
+   DU_ALLOC(newNode, sizeof(CmLList));
+   if(newNode)
+   {
+      newNode->node = (PTR)blockToAdd;
+      
+      if(currNode == NULLP)
+         cmLListAdd2Tail(llist, newNode);
+      else
+      {
+         llist->crnt = currNode;
+         cmLListInsAfterCrnt(llist, newNode);
+      }
+      return ROK;
+   } 
+   return RFAILED;
+}
+
+/*******************************************************************
+ * @brief Function to delete a node from linked list
+ *
+ * @details
+ *
+ *     Function: duDelNodeFromLList
+ *
+ *     This function deletes a node from the linked list
+ *
+ *  @param[in]  Pointer to the list
+ *              Pointer to node to be deleted
+ *  @return     Pointer to the deleted node
+*******************************************************************/
+
+uint8_t duDelNodeFromLList(CmLListCp *llist, CmLList *node)
+{
+   node = cmLListDelFrm(llist, node);
+   DU_FREE(node, sizeof(CmLList));
+
+   return ROK;
+}
+
+/*******************************************************************
+ * @brief Handle the PageUe List
+ *
+ * @details
+ *
+ *    Function : handlePageUeLL
+ *
+ *    Functionality: Handling the (SEARCH,CREATE,DELETE) PageUeList
+ *
+ * @params[in] DuPagingMsg *pagingParam, CmLListCp *pageUeLL, ActionTypeLL
+ * action
+ *
+ * @return DuPagUeRecord 
+ *
+ * ****************************************************************/
+DuPagUeRecord* handlePageUeLL(uint16_t pagUeId, uint64_t sTmsi, CmLListCp *pageUeLL, ActionTypeLL action)
+{
+   CmLList  *node = NULLP;
+   DuPagUeRecord *ueRecord = NULLP;
+   bool found = FALSE;
+
+   if((pageUeLL == NULLP) ||
+          ((pageUeLL->first == NULLP) && (action != CREATE)))
+   {
+      DU_LOG("\nERROR  -->  DU APP: UE Page Record LL is empty");
+      return NULLP;
+   }
+   node = pageUeLL->first;
+
+   while(node)
+   {
+      ueRecord = (DuPagUeRecord *)node->node;
+      if(action == PRINT)
+      {
+         DU_LOG("\n  INFO   -->  DU APP ueId:%d, sTmsi:%lu",\
+                 ueRecord->pagUeId, ueRecord->sTmsi);
+      }
+      else if(ueRecord && (ueRecord->pagUeId == pagUeId && 
+               ueRecord->sTmsi == sTmsi))
+      {
+         found = TRUE;
+         break;
+      }
+      node = node->next;
+   }
+
+   switch(action)
+   {
+      case SEARCH:
+         {
+            if(!found)
+            {
+               ueRecord = NULLP;
+            }
+            return ueRecord;
+         }
+
+      case CREATE:
+         {
+            if(node != NULLP)
+               return ueRecord;
+
+            /*Need to add a new node for this LC*/
+
+            /*List is empty; Initialize the LL ControlPointer*/
+            if(pageUeLL->count == 0)
+            {
+               cmLListInit(pageUeLL);
+            }
+
+            ueRecord = NULLP;
+            /*Allocate the List*/
+            DU_ALLOC(ueRecord, sizeof(DuPagUeRecord));
+            if(ueRecord)
+            {
+               ueRecord->pagUeId = pagUeId;
+               ueRecord->sTmsi = sTmsi;
+            }
+            else
+            {
+               DU_LOG("\nERROR  -->  DU APP : Allocation of UE Record failed,ueId:%d",pagUeId);
+               return NULLP;
+            }
+
+            if(duAddNodeToLList(pageUeLL, ueRecord, NULLP) == RFAILED)
+            {
+               DU_LOG("\nERROR  -->  DU APP : failed to Add Ue Record Node,ueId:%d",pagUeId);
+               DU_FREE(ueRecord, sizeof(DuPagUeRecord));
+               return NULLP;
+            }
+            return ueRecord;
+         }
+      case DELETE:
+         {
+            if(!found ||  ueRecord == NULLP)
+            {
+               DU_LOG("\nERROR  -->  DU APP: UeId:%d not found; thus Deletion unsuccessful",pagUeId);
+            }
+            else
+            {
+               if(duDelNodeFromLList(pageUeLL, node) == ROK)
+                  DU_FREE(ueRecord, sizeof(DuPagUeRecord));
+
+               DU_LOG("\nDEBUG  -->  DU APP: UeId:%d Deleted successfully",pagUeId);
+            }
+            return NULLP;
+         }
+      case PRINT:
+      case TRAVERSE_ALL:
+         {
+            break;
+         }
+      default:
+         {
+            DU_LOG("\nERROR  -->  DU APP: Incorrect ActionType:%d on UeRecord",action);
+         }
+   }
+   return NULLP;
+}
+
+/*******************************************************************
+ * @brief Handle the PageInfo List
+ *
+ * @details
+ *
+ *    Function : handlePageInfoLL
+ *
+ *    Functionality: Handling the (SEARCH,CREATE,DELETE) PageInfoList
+ *
+ * @params[in] uint8_t i_s, CmLListCp *pagInfoLL, ActionTypeLL action
+ *
+ * @return DuPagUeList 
+ *
+ * ****************************************************************/
+DuPagUeList* handlePageInfoLL(uint16_t pf, uint8_t i_s, CmLListCp *pagInfoLL, ActionTypeLL action)
+{
+   CmLList  *node = NULLP, *next = NULLP;
+   DuPagUeList *pagInfo = NULLP;
+   bool found = FALSE;
+   
+   if((pagInfoLL == NULLP) || 
+         ((pagInfoLL->first == NULLP) && (action != CREATE)))
+   {
+      DU_LOG("\nERROR  -->  DU APP: PagInfo LL is empty");
+      return NULLP;
+   }
+   node = pagInfoLL->first;
+
+   while(node)
+   {
+      next = node->next;
+      pagInfo = (DuPagUeList *)node->node;
+      if(action == PRINT)
+      {
+         DU_LOG("\n INFO   -->  DU APP: Paging Index (i_s):%d",pagInfo->i_s);
+         handlePageUeLL(NULLD, NULLD, &(pagInfo->pagUeList), PRINT);
+      }
+      else if(action == TRAVERSE_ALL)
+      {
+          return pagInfo;
+      }
+      else if(pagInfo->i_s == i_s)
+      {
+         found = TRUE;
+         break;
+      }
+      node = next;
+   }
+
+   switch(action)
+   {
+      case SEARCH:
+         {
+            if(!found)
+            {
+               pagInfo = NULLP;
+            }
+            return pagInfo;
+         }
+
+      case CREATE:
+         {
+            if(node != NULLP)
+               return pagInfo;
+
+            /*Need to add a new node for this LC*/
+
+            /*List is empty; Initialize the LL ControlPointer*/
+            if(pagInfoLL->count == 0)
+            {
+               cmLListInit(pagInfoLL);
+            }
+
+            pagInfo = NULLP;
+            /*Allocate the List*/
+            DU_ALLOC(pagInfo, sizeof(DuPagUeList));
+            if(pagInfo)
+            {
+               pagInfo->i_s = i_s;
+            }
+            else
+            {
+               DU_LOG("\nERROR  -->  DU APP : Allocation of List failed,i_s:%d",i_s);
+               return NULLP;
+            }
+
+            if(duAddNodeToLList(pagInfoLL, pagInfo, NULLP) == RFAILED)
+            {
+               DU_LOG("\nERROR  -->  DU APP : failed to Add Node,i_s:%d",i_s);
+               DU_FREE(pagInfo, sizeof(DuPagUeList));
+               return NULLP;
+            }
+            return pagInfo;
+         }
+      case DELETE:
+         {
+            if(!found ||  pagInfo == NULLP)
+            {
+               DU_LOG("\nERROR  -->  DU APP: i_s:%d not found; thus Deletion unsuccessful",i_s);
+            }
+            else
+            {
+               if(duDelNodeFromLList(pagInfoLL, node) == ROK)
+                  DU_FREE(pagInfo, sizeof(DuPagUeList));
+
+               DU_LOG("\nDEBUG  -->  DU APP: i_s:%d Deleted successfully",i_s);
+            }
+            return NULLP;
+         }
+      case PRINT:
+      case TRAVERSE_ALL:
+         {
+            break;
+         }
+      default:
+         {
+            DU_LOG("\nERROR  -->  DU APP: Incorrect ActionType:%d on PageInfo List",action);
+         }
+   }
+   return NULLP;
+}
+
+/*******************************************************************
+ * @brief Find the PageInfo List from HashMap 
+ *
+ * @details
+ *
+ *    Function : findPagingInfoFromMap
+ *
+ *    Functionality: Search for the PageInfoList for a PF from HashMap
+ *
+ * @params[in] uint16_t pf, CmHashListCp *pagingInfoMap
+ *
+ * @return DuPagInfoList 
+ *
+ * ****************************************************************/
+DuPagInfoList* findPagingInfoFromMap(uint16_t pf, CmHashListCp *pagingInfoMap)
+{
+   DuPagInfoList *pagInfoLL = NULLP;
+
+   cmHashListFind(pagingInfoMap, (uint8_t *)&(pf), sizeof(uint16_t), 0, (PTR *)&pagInfoLL);
+   
+   return pagInfoLL;
+}
+
+/*Below function for printing will be used in future so disabling it for now*/
+#if 0
+/*******************************************************************
+ * @brief Print the Page Info List and UE Records
+ *
+ * @details
+ *
+ *    Function : printPageList
+ *
+ *    Functionality: Print the Page Info List and UE Records
+ *
+ * @params[in] CmHashListCp *pagingInfoMap
+ *
+ * @return void
+ *
+ * ****************************************************************/
+void printPageList(CmHashListCp *pagingInfoMap)
+{
+   uint8_t ret = ROK;
+   DuPagInfoList *pagInfoLLFromPF = NULLP, *prevPageInfoLL = NULLP;
+
+   do
+   {
+      ret = cmHashListGetNext(pagingInfoMap, (PTR)prevPageInfoLL, (PTR *)&pagInfoLLFromPF);
+      if(ret == ROK)
+      {
+         DU_LOG("\nDEBUG  --> DUAPP: Page List for PF:%d",pagInfoLLFromPF->pf);
+         handlePageInfoLL(NULLD, NULLD, &(pagInfoLLFromPF->pagInfoList), PRINT);
+         prevPageInfoLL = pagInfoLLFromPF;
+      }
+   }while(ret == ROK);
+   
+}
+#endif
+
+/**********************************************************************
+End of file
+**********************************************************************/
+