Deleted the rlog folder
[o-du/l2.git] / src / 5gnrmac / mac_mux.c
index e20d8bb..18167d7 100644 (file)
@@ -25,6 +25,7 @@
 #include "mac_sch_interface.h"
 #include "lwr_mac_upr_inf.h"
 #include "mac.h"
+#include "mac_utils.h"
 
 /*******************************************************************
  *
@@ -41,7 +42,7 @@
  * @return void
  *
  * ****************************************************************/
-void packBytes(uint8_t *buf, uint8_t *bytePos, uint8_t *bitPos, uint32_t val, uint8_t valSize)
+void packBytes(uint8_t *buf, uint16_t *bytePos, uint8_t *bitPos, uint32_t val, uint8_t valSize)
 {
    uint32_t  temp;
    uint8_t   bytePart1;
@@ -98,7 +99,7 @@ void fillRarPdu(RarInfo *rarInfo)
    uint8_t   *rarPdu = rarInfo->rarPdu;
    uint16_t  totalBits = 0;
    uint8_t   numBytes = 0;
-   uint8_t   bytePos= 0;
+   uint16_t  bytePos= 0;
    uint8_t   bitPos = 0;
 
    /* RAR subheader fields */
@@ -190,15 +191,27 @@ void fillRarPdu(RarInfo *rarInfo)
  * @return void
  *
  * ****************************************************************/
-void createMacRaCb(uint16_t cellId, uint16_t crnti)
+void createMacRaCb(RachIndInfo *rachIndInfo)
 {
-   uint8_t idx = 0; /* supporting 1 UE */
-   uint16_t cellIdx;
+   uint8_t  ueIdx = 0;
+   uint16_t crnti = 0;
+   uint16_t cellIdx = 0;
 
-   GET_CELL_IDX(cellId, cellIdx);
+   GET_CELL_IDX(rachIndInfo->cellId, cellIdx);
+   
+   crnti = getNewCrnti(&macCb.macCell[cellIdx]->crntiMap);
+   if(crnti == -1)
+      return;
 
-   macCb.macCell[cellIdx]->macRaCb[idx].cellId = cellId;
-   macCb.macCell[cellIdx]->macRaCb[idx].crnti = crnti;
+   GET_UE_IDX(crnti, ueIdx);
+   ueIdx = ueIdx -1;
+
+   /* store in rach ind structure */
+   rachIndInfo->crnti  = crnti;
+
+   /* store in raCb */
+   macCb.macCell[cellIdx]->macRaCb[ueIdx].cellId = rachIndInfo->cellId;
+   macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti  = crnti;
 }
 
 /*************************************************
@@ -214,21 +227,14 @@ void createMacRaCb(uint16_t cellId, uint16_t crnti)
  *             msg4Pdu pointer
  ************************************************/
 
-void fillMsg4DlData(uint16_t cellId, MacDlData *dlData, uint8_t *msg4Pdu)
+void fillMsg4DlData(MacDlData *dlData, uint16_t msg4PduLen, uint8_t *msg4Pdu)
 {
    uint8_t idx = 0;
-   uint16_t idx2;
-   uint16_t cellIdx;
-
-   GET_CELL_IDX(cellId, cellIdx);
 
    dlData->numPdu = 1;
    dlData->pduInfo[idx].lcId = MAC_LCID_CCCH;
-   dlData->pduInfo[idx].pduLen = macCb.macCell[cellIdx]->macRaCb[idx].msg4PduLen;
-   for(idx2 = 0; idx2 <  dlData->pduInfo[idx].pduLen; idx2++)
-   {
-      dlData->pduInfo[idx].dlPdu[idx2] = msg4Pdu[idx2];
-   }
+   dlData->pduInfo[idx].pduLen = msg4PduLen;
+   memcpy(dlData->pduInfo[idx].dlPdu, msg4Pdu, msg4PduLen);
 }
 
 /*************************************************
@@ -266,13 +272,13 @@ void fillMacCe(MacCeInfo *macCeInfo, uint8_t *msg3Pdu)
  *    Functionality:
  *     The MAC PDU will be MUXed and formed
  *
- * @params[in] MacDlData *, MacCeInfo *, msg4TxPdu *, tbSize
+ * @params[in] MacDlData *, MacCeInfo *, txPdu *, tbSize
  * @return void
  * ****************************************************************/
 
-void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *msg4TxPdu, uint16_t tbSize)
+void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *txPdu, uint16_t tbSize)
 {
-   uint8_t bytePos = 0;
+   uint16_t bytePos = 0;
    uint8_t bitPos = 7;
    uint8_t idx = 0;
    uint8_t macPdu[tbSize];
@@ -280,8 +286,8 @@ void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *msg4TxPdu, uint
 
    /* subheader fields */
    uint8_t RBit = 0;              /* Reserved bit */
-   uint8_t FBit;                  /* Format Indicator */
-   uint8_t lcid;                  /* LCID */
+   uint8_t FBit =0;                  /* Format Indicator */
+   uint8_t lcid =0;                  /* LCID */
    uint16_t lenField = 0;         /* Length field */
 
    /* subheader field size (in bits) */
@@ -291,24 +297,27 @@ void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *msg4TxPdu, uint
    uint8_t lenFieldSize = 0;      /* 8-bit or 16-bit L field  */
 
    /* PACK ALL MAC CE */
-   for(idx = 0; idx < macCeData->numCes; idx++)
+   if(macCeData != NULLP)
    {
-      lcid = macCeData->macCe[idx].macCeLcid;
-      switch(lcid)
+      for(idx = 0; idx < macCeData->numCes; idx++)
       {
-        case MAC_LCID_CRI:
-           {
-              /* Packing fields into MAC PDU R/R/LCID */
-              packBytes(macPdu, &bytePos, &bitPos, RBit, (RBitSize * 2));
-              packBytes(macPdu, &bytePos, &bitPos, lcid, lcidSize);
-              memcpy(&macPdu[bytePos], macCeData->macCe[idx].macCeValue,\
-                    MAX_CRI_SIZE);
-              bytePos += MAX_CRI_SIZE;
+        lcid = macCeData->macCe[idx].macCeLcid;
+        switch(lcid)
+        {
+           case MAC_LCID_CRI:
+              {
+                 /* Packing fields into MAC PDU R/R/LCID */
+                 packBytes(macPdu, &bytePos, &bitPos, RBit, (RBitSize * 2));
+                 packBytes(macPdu, &bytePos, &bitPos, lcid, lcidSize);
+                 memcpy(&macPdu[bytePos], macCeData->macCe[idx].macCeValue,\
+                       MAX_CRI_SIZE);
+                 bytePos += MAX_CRI_SIZE;
+                 break;
+              }
+           default:
+              DU_LOG("\nERROR  -->  MAC: Invalid LCID %d in mac pdu",lcid);
               break;
-           }
-        default:
-           DU_LOG("\n MAC: Invalid LCID %d in mac pdu",lcid);
-           break;
+        }
       }
    }
 
@@ -319,6 +328,7 @@ void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *msg4TxPdu, uint
       switch(lcid)
       {
         case MAC_LCID_CCCH:
+        case MAC_LCID_MIN ... MAC_LCID_MAX :
            {
               lenField = dlData->pduInfo[idx].pduLen;
               if(dlData->pduInfo[idx].pduLen > 255)
@@ -343,10 +353,9 @@ void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *msg4TxPdu, uint
            }
 
         default:
-           DU_LOG("\n MAC: Invalid LCID %d in mac pdu",lcid);
+           DU_LOG("\nERROR  -->  MAC: Invalid LCID %d in mac pdu",lcid);
            break;
       }
-
    }
    if(bytePos < tbSize && (tbSize-bytePos >= 1))
    {
@@ -357,10 +366,10 @@ void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *msg4TxPdu, uint
       packBytes(macPdu, &bytePos, &bitPos, lcid, lcidSize);
    }
 
-   /*Storing the muxed pdu in macRaCb */
-   if(msg4TxPdu != NULLP)
+   /*Storing the muxed pdu */
+   if(txPdu != NULLP)
    {
-      memcpy(msg4TxPdu, macPdu, tbSize);
+      memcpy(txPdu, macPdu, tbSize);
    }
 }