<[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-421]Paging Message: CU_STUB Trigger and...
[o-du/l2.git] / src / 5gnrmac / mac_rach.c
index 2d5d2c8..363f0b9 100644 (file)
 ################################################################################
  *******************************************************************************/
 /* header include files (.h) */
-#include "envopt.h"        /* environment options */
-#include "envdep.h"        /* environment dependent */
-#include "envind.h"        /* environment independent */
-#include "gen.h"           /* general */
-#include "ssi.h"           /* system services */
-#include "cm_tkns.h"       /* Common Token Defines */
-#include "cm_llist.h"      /* Common Link List Defines */
-#include "cm_hash.h"       /* Common Hash List Defines */
-#include "cm_mblk.h"       /* common memory link list library */
-#include "cm_lte.h"        /* Common LTE Defines */
-#include "tfu.h"           /* RGU Interface includes */
+#include "common_def.h"
 #include "lrg.h"
-#include "gen.x"           /* general */
-#include "ssi.x"           /* system services */
-#include "cm5.x"           /* system services */
-#include "cm_tkns.x"       /* Common Token Definitions */
-#include "cm_llist.x"      /* Common Link List Definitions */
-#include "cm_lib.x"        /* Common Library Definitions */
-#include "cm_hash.x"       /* Common Hash List Definitions */
-#include "cm_mblk.x"       /* common memory link list library */
-#include "cm_lte.x"        /* Common LTE Defines */
-#include "tfu.x"           /* RGU Interface includes */
 #include "lrg.x"
 #include "du_app_mac_inf.h"
+#include "mac_sch_interface.h"
+#include "lwr_mac_upr_inf.h"
 #include "mac.h"
-#include "du_log.h"
+#include "mac_utils.h"
 
 /* Function pointer for sending rach ind from MAC to SCH */
 MacSchRachIndFunc macSchRachIndOpts[]=
 {
    packMacSchRachInd,
-   macSchRachInd,
+   MacSchRachInd,
    packMacSchRachInd
 };
 
-/* Function pointer for sending crc ind from MAC to SCH */
-MacSchCrcIndFunc macSchCrcIndOpts[]=
-{
-   packMacSchCrcInd,
-   macSchCrcInd,
-   packMacSchCrcInd
-};
-
 /*******************************************************************
  *
  * @brief Sends RACH indication to SCH
@@ -75,43 +49,14 @@ MacSchCrcIndFunc macSchCrcIndOpts[]=
  *         RFAILED - failure
  *
  * ****************************************************************/
-int sendRachIndMacToSch(RachIndInfo *rachInd)
+uint8_t sendRachIndMacToSch(RachIndInfo *rachInd)
 {
    Pst pst;
-    
-   fillMacToSchPst(&pst);
-   pst.event = EVENT_RACH_IND_TO_SCH;
-    
-   return(*macSchRachIndOpts[pst.selector])(&pst, rachInd); 
-}
 
-/*******************************************************************
- *
- * @brief Sends CRC Indication to SCH
- *
- * @details
- *
- *    Function : sendCrcIndMacToSch 
- *
- *    Functionality:
- *       Sends CRC Indication to SCH
- *
- * @params[in] 
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-int sendCrcIndMacToSch(CrcIndInfo *crcInd)
-{
-   Pst pst;
-  
-   fillMacToSchPst(&pst);
-   pst.event = EVENT_CRC_IND_TO_SCH;
-   return(*macSchCrcIndOpts[pst.selector])(&pst, crcInd);
+   FILL_PST_MAC_TO_SCH(pst, EVENT_RACH_IND_TO_SCH);
+   return(*macSchRachIndOpts[pst.selector])(&pst, rachInd); 
 }
 
 /*******************************************************************
  *
  * @brief Processes RACH indication from PHY
@@ -129,22 +74,26 @@ int sendCrcIndMacToSch(CrcIndInfo *crcInd)
  *         RFAILED - failure
  *
  * ****************************************************************/ 
-uint16_t fapiMacRachInd(Pst *pst, RachInd *rachInd)
+uint8_t fapiMacRachInd(Pst *pst, RachInd *rachInd)
 {
    uint8_t      pduIdx;
    uint8_t      preambleIdx;
    RachIndInfo  *rachIndInfo;
 
-   DU_LOG("\nMAC : Received RACH indication");
+   DU_LOG("\nINFO  -->  MAC : Received RACH indication");
    /* Considering one pdu and one preamble */
    pduIdx = 0;
    preambleIdx = 0;
 
-   rachIndInfo = &macCb.macCell->raCb;
+   MAC_ALLOC(rachIndInfo, sizeof(RachIndInfo));
+   if(!rachIndInfo)
+   {
+      DU_LOG("\nERROR  --> MAC : Memory allocation failure in fapiMacRachInd");
+      MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rachInd, sizeof(RachInd));
+      return RFAILED;
+   }
 
-   rachIndInfo->cellId = rachInd->rachPdu[pduIdx].pci;
-   /* TODO : Allocate unique crnti for each ue */
-   rachIndInfo->crnti = 100;
+   rachIndInfo->cellId = rachInd->cellId;
    rachIndInfo->timingInfo.sfn = rachInd->timingInfo.sfn;
    rachIndInfo->timingInfo.slot = rachInd->timingInfo.slot;
    rachIndInfo->slotIdx = rachInd->rachPdu[pduIdx].slotIdx;
@@ -155,84 +104,54 @@ uint16_t fapiMacRachInd(Pst *pst, RachInd *rachInd)
    rachIndInfo->timingAdv = \
       rachInd->rachPdu[pduIdx].preamInfo[preambleIdx].timingAdv;
 
-   return(sendRachIndMacToSch(rachIndInfo));
-}
+   /* Store the value in macRaCb */
+   createMacRaCb(rachIndInfo);
 
-/*******************************************************************
- *
- * @brief Processes CRC Indication from PHY
- *
- * @details
- *
- *    Function : fapiMacCrcInd
- *
- *    Functionality:
- *       Processes CRC Indication from PHY
- *
- * @params[in] Post Structure Pointer
- *             Crc Indication Pointer
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-uint16_t fapiMacCrcInd(Pst *pst, CrcInd *crcInd)
-{
-   CrcIndInfo   crcIndInfo;
+   /* Free sharable buffer used to send RACH Indication from lower MAC to MAC */
+   MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rachInd, sizeof(RachInd));
 
-   DU_LOG("\nMAC : Received CRC indication");
-   /* Considering one pdu and one preamble */
-   
-   crcIndInfo.cellId = macCb.macCell->cellId;;
-   crcIndInfo.crnti = crcInd->crcInfo[0].rnti;
-   crcIndInfo.timingInfo.sfn = crcInd->timingInfo.sfn;
-   crcIndInfo.timingInfo.slot = crcInd->timingInfo.slot;
-   crcIndInfo.numCrcInd = crcInd->crcInfo[0].numCb;
-   crcIndInfo.crcInd[0] = crcInd->crcInfo[0].cbCrcStatus[0];
-   
-   return(sendCrcIndMacToSch(&crcIndInfo));
+   /* Send RACH Indication to SCH */
+   return(sendRachIndMacToSch(rachIndInfo));
 }
 
 /* spec-38.211 Table 6.3.3.1-7 */
 uint8_t UnrestrictedSetNcsTable[MAX_ZERO_CORR_CFG_IDX] = 
 {0, 2, 4, 6, 8, 10, 12, 13, 15, 17, 19, 23, 27, 34, 46, 69};
 
-int MacProcUlSchInfo(Pst *pst, UlSchInfo *ulSchInfo)
-{
-   if(ulSchInfo != NULLP)
-       {
-      MacUlSlot *currUlSlot = 
-          &macCb.macCell->ulSlot[ulSchInfo->slotIndInfo.slot % MAX_SLOT_SUPPORTED];
-      memcpy(&currUlSlot->ulCellInfo, ulSchInfo, sizeof(UlSchInfo)); 
-   }
-   return ROK;
-}
-
 /*******************************************************************
  *
- * @brief Process Rx Data Ind at MAC
+ * @brief Processes UL scheduling info from SCH
  *
  * @details
  *
- *    Function : fapiMacRxDataInd
+ *    Function : MacProcUlSchInfo
  *
- *    Functionality:
- *       Process Rx Data Ind at MAC
+ *    Functionality: Processes UL scheduling info from SCH
  *
  * @params[in] Post structure
- *             Rx Data Indication
+ *             UL scheduling info
  * @return ROK     - success
  *         RFAILED - failure
  *
  * ****************************************************************/
-uint16_t fapiMacRxDataInd(Pst *pst, RxDataInd *rxDataInd)
+uint8_t MacProcUlSchInfo(Pst *pst, UlSchedInfo *ulSchedInfo)
 {
-   DU_LOG("\nMAC : Received Rx Data indication");
-   /* TODO : Demuxing */
+   uint16_t  cellIdx;
+
+#ifdef CALL_FLOW_DEBUG_LOG
+   DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_UL_SCH_INFO\n");
+#endif
+
+   GET_CELL_IDX(ulSchedInfo->cellId, cellIdx);
+   if(ulSchedInfo != NULLP)
+   {
+      MacUlSlot *currUlSlot = 
+        &macCb.macCell[cellIdx]->ulSlot[ulSchedInfo->slotIndInfo.slot % MAX_SLOTS];
+      memcpy(&currUlSlot->ulInfo, ulSchedInfo, sizeof(UlSchedInfo)); 
+   }
    return ROK;
 }
 
-
 /**********************************************************************
   End of file
  **********************************************************************/