[Epic-ID: ODUHIGH-516][Task-ID: ODUHIGH-523] Statistics Request API and Timer Based...
[o-du/l2.git] / src / 5gnrmac / mac_cfg_hdl.c
index fee5f4f..fa17ba0 100644 (file)
@@ -1014,6 +1014,105 @@ uint8_t MacProcDlBroadcastReq(Pst *pst, MacDlBroadcastReq *dlBroadcastReq)
    }
    return ret;
 }
+
+/**
+ * @brief Mac process the statistics Req received from DUAPP
+ *
+ * @details
+ *
+ *     Function : MacProcStatsReq
+ *
+ *     This function process the statistics request from duapp
+ *
+ *  @param[in]  Pst      *pst
+ *  @param[in]  StatsReq *statsReq
+ *  @return  int
+ *      -# ROK
+ **/
+uint8_t MacProcStatsReq(Pst *pst, MacStatsReq *macStatsReq)
+{
+   uint8_t   macStatsIdx = 0, schStatsIdx = 0;
+   uint8_t   ret = RFAILED;
+   bool      measTypeInvalid = false;
+   Pst       schPst;
+   SchStatsReq  *schStatsReq = NULLP;
+   CauseOfResult cause;
+
+   if(macStatsReq)
+   {
+      DU_LOG("\nINFO   -->  MAC : Received Statistics Request from DU_APP");
+
+      MAC_ALLOC(schStatsReq, sizeof(SchStatsReq));
+      if(schStatsReq == NULLP)
+      {
+         DU_LOG("\nERROR  -->  MAC : MacProcStatsReq: Failed to allocate memory");
+         cause = RESOURCE_UNAVAILABLE;
+      }
+      else
+      {
+         schStatsReq->numStats = 0;
+         for(macStatsIdx=0; macStatsIdx < macStatsReq->numStats; macStatsIdx++)
+         {
+            /* Checking each measurement type to send only SCH related
+             * measurement config to SCH
+             * This will be useful in future when some measurement type will
+             * be configured for SCH and rest for only MAC */
+            switch(macStatsReq->statsList[macStatsIdx].type)
+            {
+               case MAC_DL_TOTAL_PRB_USAGE:
+                  {
+                     schStatsReq->statsList[schStatsIdx].type = SCH_DL_TOTAL_PRB_USAGE;
+                     break;
+                  }
+               case MAC_UL_TOTAL_PRB_USAGE:
+                  {
+                     schStatsReq->statsList[schStatsIdx].type = SCH_UL_TOTAL_PRB_USAGE;
+                     break;
+                  }
+               default:
+                  {
+                     DU_LOG("\nERROR  -->  MAC : MacProcStatsReq: Invalid measurement type [%d]", \
+                        macStatsReq->statsList[macStatsIdx].type);
+                     measTypeInvalid = true;
+                  }
+            }
+
+            if(!measTypeInvalid)
+            {
+               schStatsReq->statsList[schStatsIdx].periodicity = macStatsReq->statsList[macStatsIdx].periodicity;
+               schStatsIdx++;
+               measTypeInvalid = false;
+            }
+         }
+         schStatsReq->numStats = schStatsIdx;
+
+         /* If no measurement types are valid, it is failure scenario.
+          * Even if one measurement type is valid, send to SCH */
+         if(schStatsReq->numStats)
+         {
+            FILL_PST_MAC_TO_SCH(schPst, EVENT_STATISTICS_REQ_TO_SCH);
+            ret = SchMessageRouter(&schPst, (void *)schStatsReq);
+         }
+         else
+         {
+            cause = PARAM_INVALID;
+         }
+      }
+      MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macStatsReq, sizeof(MacStatsReq));
+   }
+   else
+   {
+      DU_LOG("\nERROR  -->  MAC : MacProcStatsReq(): Received Null pointer");
+      cause = PARAM_INVALID;
+   }
+
+   if(ret == RFAILED)
+   {
+      /* Send negative acknowledgment to DU APP. TBD in next gerrit */
+   }
+   return ret;
+}
+
 /**********************************************************************
   End of file
  **********************************************************************/