RARandSib1Transmission
[o-du/l2.git] / src / 5gnrmac / lwr_mac_fsm.c
index c0ba316..f32f051 100644 (file)
@@ -79,6 +79,8 @@ extern uint8_t UnrestrictedSetNcsTable[MAX_ZERO_CORR_CFG_IDX];
 SlotIndInfo slotIndInfo;
 uint8_t slotIndIdx;
 
+uint16_t sendTxDataReq(CmLteTimingInfo *currTimingInfo, DlAlloc *dlInfo);
+
 void lwrMacInit()
 {
 #ifdef INTEL_WLS
@@ -111,7 +113,7 @@ void lwrMacInit()
   * ****************************************************************/
 S16 lwr_mac_handleInvalidEvt(void *msg)
 {
-  printf("\nLOWER MAC: Error Indication Event[%d] received in state [%d]", clGlobalCp.event, clGlobalCp.phyState);
+  printf("\nLWR_MAC: Error Indication Event[%d] received in state [%d]", clGlobalCp.event, clGlobalCp.phyState);
   RETVALUE(ROK);
 }
 
@@ -1293,7 +1295,7 @@ uint32_t getParamValue(fapi_uint16_tlv_t *tlv, uint16_t type)
     }
     else
     {
-      DU_LOG("\nLOWER MAC: Value Extraction failed" );
+      DU_LOG("\nLWR_MAC: Value Extraction failed" );
       return RFAILED;
     }
 }
@@ -1322,23 +1324,17 @@ S16 lwr_mac_handleParamReqEvt(void *msg)
    uint32_t msgLen;      //Length of message Body
    msgLen = 0;
    fapi_param_req_t *paramReq;
-#ifdef INTEL_WLS
-   WLS_MEM_ALLOC(paramReq, sizeof(fapi_param_req_t));
-#else
-   MAC_ALLOC(paramReq, sizeof(fapi_param_req_t));
-#endif
+       LWR_MAC_ALLOC(paramReq, sizeof(fapi_param_req_t));
    if(paramReq != NULLP)
    {
       fillMsgHeader(&paramReq->header, FAPI_PARAM_REQUEST, msgLen);
-      DU_LOG("\nLOWER MAC: Sending Param Request to Phy");
+      DU_LOG("\nLWR_MAC: Sending Param Request to Phy");
       LwrMacSendToPhy(paramReq->header.message_type_id, sizeof(fapi_param_req_t), (void *)paramReq);
-      MAC_FREE(paramReq, sizeof(fapi_param_req_t));
       return ROK;
    }
    else
    {
-      DU_LOG("\nLOWER MAC: Failed to allocate memory for Param Request");
+      DU_LOG("\nLWR_MAC: Failed to allocate memory for Param Request");
       return RFAILED;
    }
 #else
@@ -1373,14 +1369,14 @@ S16 lwr_mac_handleParamRspEvt(void *msg)
    ClCellParam *cellParam = NULLP;
 
    paramRsp = (fapi_param_resp_t *)msg;
-   DU_LOG("\nLOWER MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
+   DU_LOG("\nLWR_MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
 
    if(paramRsp != NULLP)
    {
       MAC_ALLOC(cellParam, sizeof(ClCellParam));
       if(cellParam != NULLP)
       {
-         DU_LOG("\n LOWER MAC: Filling TLVS into MAC API");
+         DU_LOG("\n LWR_MAC: Filling TLVS into MAC API");
          if(paramRsp->error_code == MSG_OK)
          {
             for(index = 0; index < paramRsp->number_of_tlvs; index++)
@@ -1857,26 +1853,24 @@ S16 lwr_mac_handleParamRspEvt(void *msg)
               }
            }
            MAC_FREE(cellParam, sizeof(ClCellParam));
-           MAC_FREE(paramRsp, sizeof(fapi_param_resp_t));
-             
            sendToLowerMac(FAPI_CONFIG_REQUEST, 0, (void *)NULL);
            return ROK;
          }
          else
          {
-            DU_LOG("\n LOWER MAC: Invalid error code %d", paramRsp->error_code);
+            DU_LOG("\n LWR_MAC: Invalid error code %d", paramRsp->error_code);
             return RFAILED;
          }
      }
      else
      {
-        DU_LOG("\nLOWER MAC: Failed to allocate memory for cell param");
+        DU_LOG("\nLWR_MAC: Failed to allocate memory for cell param");
         return RFAILED;
      }
    }
    else
    {
-       DU_LOG("\nLOWER MAC:  Param Response received from PHY is NULL");
+       DU_LOG("\nLWR_MAC:  Param Response received from PHY is NULL");
        return RFAILED;
    }
 #else
@@ -1911,18 +1905,13 @@ S16 lwr_mac_handleConfigReqEvt(void *msg)
    MacCellCfg macCfgParams;
    Inst inst = 0;
 
-   DU_LOG("\nLOWER MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
+   DU_LOG("\nLWR_MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
 
    fapi_config_req_t *configReq;
    cellParams = rgCb[inst].cell;
    macCfgParams = cellParams->macCellCfg;
    configReqSize = sizeof(fapi_config_req_t) + (macCfgParams.numTlv * sizeof(fapi_uint16_tlv_t));
-#ifdef INTEL_WLS
-   WLS_MEM_ALLOC(configReq, configReqSize);
-#else
-   MAC_ALLOC(configReq, configReqSize);
-#endif
-
+       LWR_MAC_ALLOC(configReq, configReqSize);
    if(configReq != NULL)
    {
       configReq->number_of_tlvs = macCfgParams.numTlv;
@@ -1965,11 +1954,18 @@ S16 lwr_mac_handleConfigReqEvt(void *msg)
       fillTlvs(&configReq->tlvs[index++], FAPI_K1_TAG,                         sizeof(uint16_t), macCfgParams.prachCfg.fdm[0].k1, &msgLen);
       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_ZERO_CORR_CONF_TAG ,      sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].zeroCorrZoneCfg, &msgLen);
       fillTlvs(&configReq->tlvs[index++], FAPI_NUM_UNUSED_ROOT_SEQUENCES_TAG,  sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].numUnusedRootSeq, &msgLen);
-      //MAC_ALLOC(macCfgParams.prachCfg.fdm[0].unsuedRootSeq, \
-         sizeof(uint8_t)*macCfgParams.prachCfg.fdm[0].numUnusedRootSeq);
-      macCfgParams.prachCfg.fdm[0].unsuedRootSeq = (uint8_t *)malloc(sizeof(uint8_t)*macCfgParams.prachCfg.fdm[0].numUnusedRootSeq);
-      fillTlvs(&configReq->tlvs[index++], FAPI_UNUSED_ROOT_SEQUENCES_TAG,
-                  sizeof(uint8_t), *(macCfgParams.prachCfg.fdm[0].unsuedRootSeq), &msgLen);
+               if(macCfgParams.prachCfg.fdm[0].numUnusedRootSeq)
+               {
+                  LWR_MAC_ALLOC(macCfgParams.prachCfg.fdm[0].unsuedRootSeq ,
+                     sizeof(uint8_t)*macCfgParams.prachCfg.fdm[0].numUnusedRootSeq);
+                  fillTlvs(&configReq->tlvs[index++], FAPI_UNUSED_ROOT_SEQUENCES_TAG,\
+                     sizeof(uint8_t), *(macCfgParams.prachCfg.fdm[0].unsuedRootSeq), &msgLen);
+               }
+               else
+               {
+                  macCfgParams.prachCfg.fdm[0].unsuedRootSeq = NULL;
+               }
+
       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_PER_RACH_TAG,               sizeof(uint8_t), macCfgParams.prachCfg.ssbPerRach, &msgLen);
       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_MULTIPLE_CARRIERS_IN_A_BAND_TAG,  sizeof(uint8_t), macCfgParams.prachCfg.prachMultCarrBand, &msgLen);
 
@@ -1995,7 +1991,6 @@ S16 lwr_mac_handleConfigReqEvt(void *msg)
       DU_LOG("\nLOWER_MAC: Sending Config Request to Phy");
       /* TODO : Recheck the size / msglen to be sent to WLS_Put*/
       LwrMacSendToPhy(configReq->header.message_type_id, msgLen, (void *)configReq);
-      MAC_FREE(configReq, configReqSize);
       return ROK;
    }
    else
@@ -2013,26 +2008,25 @@ S16 lwr_mac_handleConfigRspEvt(void *msg)
 #ifdef FAPI
    fapi_config_resp_t *configRsp;
        configRsp = (fapi_config_resp_t *)msg;
-   DU_LOG("\nLOWER MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
+   DU_LOG("\nLWR_MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
 
    if(configRsp != NULL)
    {
       if(configRsp->error_code == MSG_OK)
       {
-         DU_LOG("\nLOWER MAC: PHY has moved to Conigured state \n");
+         DU_LOG("\nLWR_MAC: PHY has moved to Configured state \n");
          clGlobalCp.phyState = PHY_STATE_CONFIGURED;
          /* TODO : 
           * Store config response into an intermediate struture and send to MAC
           * Support LC and LWLC for sending config rsp to MAC 
           */
          fapiMacConfigRsp();
-         MAC_FREE(configRsp, sizeof(fapi_config_resp_t));
          return ROK;
       }
       else
       {
 
-         DU_LOG("\n LOWER MAC: Invalid error code %d", configRsp->error_code);
+         DU_LOG("\n LWR_MAC: Invalid error code %d", configRsp->error_code);
          return RFAILED;
       }
    }
@@ -2051,23 +2045,18 @@ S16 lwr_mac_handleStartReqEvt(void *msg)
 #ifdef FAPI
    uint32_t msgLen = 0;
    fapi_start_req_t *startReq;
-#ifdef INTEL_WLS
-   WLS_MEM_ALLOC(startReq, sizeof(fapi_start_req_t));
-#else
-   MAC_ALLOC(startReq, sizeof(fapi_start_req_t));
-#endif
 
+       LWR_MAC_ALLOC(startReq, sizeof(fapi_start_req_t));
    if(startReq != NULL)
    {
       fillMsgHeader(&startReq->header, FAPI_START_REQUEST, msgLen);
-      DU_LOG("\nLOWER MAC: Sending Start Request to PHY");
+      DU_LOG("\nLWR_MAC: Sending Start Request to PHY");
       LwrMacSendToPhy(startReq->header.message_type_id, sizeof(fapi_start_req_t), (void *)startReq);
-      MAC_FREE(startReq, sizeof(fapi_start_req_t));
       return ROK;
    }
    else
    {
-      DU_LOG("\nLOWER MAC: Failed to allocate memory for Start Request");
+      DU_LOG("\nLWR_MAC: Failed to allocate memory for Start Request");
       return RFAILED;
    }
 #else
@@ -2104,7 +2093,7 @@ PUBLIC void setMibPdu(uint8_t *mibPdu, uint32_t *val)
 {
    *mibPdu |= (((uint8_t)(slotIndInfo.sfn >> 2)) & MIB_SFN_BITMASK);
    *val = (mibPdu[0] << 24 | mibPdu[1] << 16 | mibPdu[2] << 8);
-    DU_LOG("\nLOWER MAC: value filled %x", *val);
+    DU_LOG("\nLWR_MAC: MIB PDU %x", *val);
 }
 
 #ifdef FAPI
@@ -2271,7 +2260,7 @@ void fillSib1DlDciPdu(fapi_dl_dci_t *dlDciPtr, PdcchCfg *sib1PdcchInfo)
 
      if(numBytes > DCI_PAYLOAD_BYTE_LEN)
      {
-        DU_LOG("\nLOWER MAC : Total bytes for DCI is more than expected");
+        DU_LOG("\nLWR_MAC : Total bytes for DCI is more than expected");
         return;
      }
 
@@ -2405,7 +2394,7 @@ void fillRarDlDciPdu(fapi_dl_dci_t *dlDciPtr, PdcchCfg *rarPdcchInfo)
 
                if(numBytes > DCI_PAYLOAD_BYTE_LEN)
                {
-                       DU_LOG("\nLOWER MAC : Total bytes for DCI is more than expected");
+                       DU_LOG("\nLWR_MAC : Total bytes for DCI is more than expected");
                        return;
                }
 
@@ -2471,11 +2460,7 @@ uint32_t *msgLen)
        dlTtiReqPdu->u.pdcch_pdu.shiftIndex =  pdcchInfo->coreset0Cfg.shiftIndex;
        dlTtiReqPdu->u.pdcch_pdu.precoderGranularity = pdcchInfo->coreset0Cfg.precoderGranularity;
        dlTtiReqPdu->u.pdcch_pdu.numDlDci = pdcchInfo->numDlDci;
-#ifdef INTEL_WLS       
-       WLS_MEM_ALLOC(dlTtiReqPdu->u.pdcch_pdu.dlDci, sizeof(fapi_dl_dci_t));
-#else
-       MAC_ALLOC(dlTtiReqPdu->u.pdcch_pdu.dlDci, sizeof(fapi_dl_dci_t));
-#endif
+                LWR_MAC_ALLOC(dlTtiReqPdu->u.pdcch_pdu.dlDci, sizeof(fapi_dl_dci_t));
        if(pdcchInfo->dci.rnti == SI_RNTI)
                 {
           fillSib1DlDciPdu(dlTtiReqPdu->u.pdcch_pdu.dlDci, pdcchInfo);
@@ -2513,7 +2498,7 @@ uint32_t *msgLen)
  ******************************************************************/
 
 void fillPdschPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, PdschCfg *pdschInfo,
-uint32_t *msgLen)
+uint32_t *msgLen, uint16_t pduIndex)
 {
     uint8_t idx;
 
@@ -2522,7 +2507,7 @@ uint32_t *msgLen)
        dlTtiReqPdu->pduType = PDSCH_PDU_TYPE;
        dlTtiReqPdu->u.pdsch_pdu.pduBitMap = pdschInfo->pduBitmap;
        dlTtiReqPdu->u.pdsch_pdu.rnti = pdschInfo->rnti;         
-       dlTtiReqPdu->u.pdsch_pdu.pduIndex = pdschInfo->pduIndex;
+       dlTtiReqPdu->u.pdsch_pdu.pduIndex = pduIndex;
        dlTtiReqPdu->u.pdsch_pdu.bwpSize = pdschInfo->pdschBwpCfg.BWPSize;       
        dlTtiReqPdu->u.pdsch_pdu.bwpStart = pdschInfo->pdschBwpCfg.BWPStart;
        dlTtiReqPdu->u.pdsch_pdu.subCarrierSpacing = pdschInfo->pdschBwpCfg.subcarrierSpacing;
@@ -2576,7 +2561,7 @@ uint32_t *msgLen)
  *
  * @details
  *
- *    Function : calculatePduCount
+ *    Function : calcDlTtiReqPduCount
  *
  *    Functionality:
  *         -calculates the total pdu count to be allocated for DL TTI Req
@@ -2585,7 +2570,7 @@ uint32_t *msgLen)
  * @return count
  *
  * ********************************************************************/
-uint8_t calculatePduCount(DlAlloc *dlInfo)
+uint8_t calcDlTtiReqPduCount(DlAlloc *dlInfo)
 {
    uint8_t count = 0;
    uint8_t idx = 0;
@@ -2610,6 +2595,34 @@ uint8_t calculatePduCount(DlAlloc *dlInfo)
    return count;
 }
 
+/***********************************************************************
+ *
+ * @brief calculates the total size to be allocated for DL TTI Req
+ *
+ * @details
+ *
+ *    Function : calcTxDataReqPduCount
+ *
+ *    Functionality:
+ *         -calculates the total pdu count to be allocated for DL TTI Req
+ *
+ * @params[in]    DlBrdcstAlloc *cellBroadcastInfo
+ * @return count
+ *
+ * ********************************************************************/
+uint8_t calcTxDataReqPduCount(DlAlloc *dlInfo)
+{
+   uint8_t count = 0;
+       if(dlInfo->isBroadcastPres && dlInfo->brdcstAlloc.sib1Trans)
+       {
+         count++;
+   }
+       if(dlInfo->isRarPres)
+       {
+          count++;
+       }
+   return count;
+}
 /***********************************************************************
  *
  * @brief fills the SIB1 TX-DATA request message
@@ -2622,43 +2635,44 @@ uint8_t calculatePduCount(DlAlloc *dlInfo)
  *         - fills the SIB1 TX-DATA request message
  *
  * @params[in]    fapi_tx_pdu_desc_t *pduDesc
- * @params[in]    MacCellCfg *macCellCfg
- * @params[in]    uint16_t pduIndex
+ * @params[in]    macCellCfg consist of SIB1 pdu
  * @params[in]    uint32_t *msgLen
+ * @params[in]    uint16_t pduIndex
  * @return ROK
  *
  * ********************************************************************/
 uint8_t fillSib1TxDataReq(fapi_tx_pdu_desc_t *pduDesc,MacCellCfg *macCellCfg,
-   uint16_t pduIndex, uint32_t *msgLen)
+   uint32_t *msgLen, uint16_t pduIndex)
 {
    uint32_t pduLen = 0;
        uint32_t *sib1TxdataValue = NULLP;
 
-       pduDesc->pduIndex = pduIndex;
-       pduDesc->numTlvs = 1;
+       pduDesc[pduIndex].pduIndex = pduIndex;
+       pduDesc[pduIndex].numTlvs = 1;
 
        /* fill the TLV */
        /* as of now, memory is allocated from SSI, later WLS memory needs to be taken */
-       pduDesc->tlvs[0].tl.tag = 1; /* pointer to be sent */
-       pduDesc->tlvs[0].tl.length = macCellCfg->sib1Cfg.sib1PduLen;
-   MAC_ALLOC(sib1TxdataValue,macCellCfg->sib1Cfg.sib1PduLen);
+       pduDesc[pduIndex].tlvs[0].tl.tag = 1; /* pointer to be sent */
+       pduDesc[pduIndex].tlvs[0].tl.length = macCellCfg->sib1Cfg.sib1PduLen;
+       LWR_MAC_ALLOC(sib1TxdataValue,macCellCfg->sib1Cfg.sib1PduLen);
        if(sib1TxdataValue == NULLP)
        {
           return RFAILED;
        }
        memcpy(sib1TxdataValue,macCellCfg->sib1Cfg.sib1Pdu,
           macCellCfg->sib1Cfg.sib1PduLen);
-       pduDesc->tlvs[0].value = sib1TxdataValue;
+       pduDesc[pduIndex].tlvs[0].value = sib1TxdataValue;
 
    /* The total length of the PDU description and      PDU data */
        pduLen += 8; /* size of PDU length 2 bytes, PDU index 2 bytes, numTLV 4 bytes */
        pduLen += sizeof(fapi_uint32_tlv_t); /* only 1 TLV is present */
-   pduDesc->pduLength = pduLen; 
+   pduDesc[pduIndex].pduLength = pduLen; 
        msgLen += pduLen;
 
-       /* TODO: The pointer value which was stored, needs to be free-ed at PHY *
-        * But since we did not implement WLS, this has to be done here */
-        MAC_FREE(sib1TxdataValue,macCellCfg->sib1Cfg.sib1PduLen);
+#ifndef INTEL_WLS   
+   MAC_FREE(sib1TxdataValue,macCellCfg->sib1Cfg.sib1PduLen);
+#endif
+
 
        return ROK;
 }
@@ -2676,41 +2690,44 @@ uint8_t fillSib1TxDataReq(fapi_tx_pdu_desc_t *pduDesc,MacCellCfg *macCellCfg,
  *
  * @params[in]    fapi_tx_pdu_desc_t *pduDesc
  * @params[in]    RarInfo *rarInfo
- * @params[in]    uint16_t pduIndex
  * @params[in]    uint32_t *msgLen
+ * @params[in]    uint16_t pduIndex
  * @return ROK
  *
  * ********************************************************************/
 uint8_t fillRarTxDataReq(fapi_tx_pdu_desc_t *pduDesc, RarInfo *rarInfo,
-   uint16_t pduIndex, uint32_t *msgLen)
+   uint32_t *msgLen, uint16_t pduIndex)
 {
    uint32_t pduLen = 0;
        uint32_t *rarTxdataValue = NULLP;
 
-       pduDesc->pduIndex = pduIndex;
-       pduDesc->numTlvs = 1;
+       pduDesc[pduIndex].pduIndex = pduIndex;
+       pduDesc[pduIndex].numTlvs = 1;
 
        /* fill the TLV */
        /* as of now, memory is allocated from SSI, later WLS memory needs to be taken */
-       pduDesc->tlvs[0].tl.tag = 1; /* pointer to be sent */
-       pduDesc->tlvs[0].tl.length = rarInfo->rarPduLen;
-   MAC_ALLOC(rarTxdataValue,rarInfo->rarPduLen);
+       pduDesc[pduIndex].tlvs[0].tl.tag = 1; /* pointer to be sent */
+       pduDesc[pduIndex].tlvs[0].tl.length = rarInfo->rarPduLen;
+       LWR_MAC_ALLOC(rarTxdataValue,rarInfo->rarPduLen);
        if(rarTxdataValue == NULLP)
        {
           return RFAILED;
        }
        memcpy(rarTxdataValue,rarInfo->rarPdu,rarInfo->rarPduLen);
-       pduDesc->tlvs[0].value = (uint32_t)rarTxdataValue;
+       pduDesc[pduIndex].tlvs[0].value = (uint32_t)rarTxdataValue;
 
    /* The total length of the PDU description and      PDU data */
        pduLen += 8; /* size of PDU length 2 bytes, PDU index 2 bytes, numTLV 4 bytes */
        pduLen += sizeof(fapi_uint32_tlv_t); /* only 1 TLV is present */
-   pduDesc->pduLength = pduLen; 
+   pduDesc[pduIndex].pduLength = pduLen; 
        msgLen += pduLen;
 
-       /* TODO: The pointer value which was stored, needs to be free-ed at PHY *
-        * But since we did not implement WLS, this has to be done here */
-        MAC_FREE(rarTxdataValue,rarInfo->rarPduLen);
+/* TODO: The pointer value which was stored, needs to be free-ed at PHY *
+ * But since we did not implement WLS, this has to be done here
+ */
+#ifndef INTEL_WLS   
+   MAC_FREE(rarTxdataValue,rarInfo->rarPduLen);
+#endif
 
        return ROK;
 }
@@ -2726,22 +2743,22 @@ uint8_t fillRarTxDataReq(fapi_tx_pdu_desc_t *pduDesc, RarInfo *rarInfo,
  *    Function : handleDlTtiReq
  *
  *    Functionality:
- *         -Sends FAPI Param req to PHY
+ *         -Sends FAPI DL TTI req to PHY
  *
- * @params[in]    RgDlSf *dlTtiReqSlot
+ * @params[in]    timing info
  * @return ROK     - success
  *         RFAILED - failure
  *
  * ****************************************************************/
-uint16_t handleDlTtiReq(CmLteTimingInfo *dlTtiReqtimingInfo)
+uint16_t handleDlTtiReq(CmLteTimingInfo *currTimingInfo)
 {
 #ifdef FAPI
        uint8_t idx;
        uint8_t nPdu = 0;
        uint8_t numPduEncoded = 0;
+       uint16_t pduIndex = 0;
        uint32_t msgLen = 0;
        fapi_dl_tti_req_t *dlTtiReq = NULLP;
-       fapi_tx_data_req_t *txDataReq = NULLP;
        RgCellCb  *cellCbParams = NULLP;
        MacDlSlot *currDlSlot = NULLP;
        MacCellCfg macCellCfg;
@@ -2753,28 +2770,26 @@ uint16_t handleDlTtiReq(CmLteTimingInfo *dlTtiReqtimingInfo)
                cellCbParams = rgCb[inst].cell;
                macCellCfg = cellCbParams->macCellCfg;
 
-               if(dlTtiReqtimingInfo != NULLP)
+               if(currTimingInfo != NULLP)
                {
-#ifdef INTEL_WLS
-                       WLS_MEM_ALLOC(dlTtiReq, sizeof(fapi_dl_tti_req_t));
-#else
-                       MAC_ALLOC(dlTtiReq, sizeof(fapi_dl_tti_req_t));
-#endif
+                  LWR_MAC_ALLOC(dlTtiReq, sizeof(fapi_dl_tti_req_t));
                        if(dlTtiReq != NULLP)
                        {
-                               dlTtiReq->sfn = dlTtiReqtimingInfo->sfn;
-                               dlTtiReq->slot = dlTtiReqtimingInfo->slot;
+                               dlTtiReq->sfn = currTimingInfo->sfn;
+                               dlTtiReq->slot = currTimingInfo->slot;
                                currDlSlot = &macCb.macCell->dlSlot[dlTtiReq->slot % MAX_SLOT_SUPPORTED];
-                               dlTtiReq->nPdus = calculatePduCount(&currDlSlot->dlInfo);  /* get total Pdus */
+                               dlTtiReq->nPdus = calcDlTtiReqPduCount(&currDlSlot->dlInfo);  /* get total Pdus */
                                nPdu = dlTtiReq->nPdus;
                                dlTtiReq->nGroup = 0;
                                if(dlTtiReq->nPdus > 0)
                                {
-#ifdef INTEL_WLS
-                                       WLS_MEM_ALLOC(dlTtiReq->pdus, (nPdu * sizeof(fapi_dl_tti_req_pdu_t)));
-#else
-                                       MAC_ALLOC(dlTtiReq->pdus, (nPdu * sizeof(fapi_dl_tti_req_pdu_t)));
-#endif
+                                  LWR_MAC_ALLOC(dlTtiReq->pdus, (nPdu * sizeof(fapi_dl_tti_req_pdu_t)));
+               if(!dlTtiReq->pdus)
+               {
+                  DU_LOG("\nLWR_MAC: Memory allocation failed");
+                  return RFAILED;
+               }
+          
                                        if(currDlSlot->dlInfo.isBroadcastPres)
                                        {
                                                if(currDlSlot->dlInfo.brdcstAlloc.ssbTrans)
@@ -2789,7 +2804,9 @@ uint16_t handleDlTtiReq(CmLteTimingInfo *dlTtiReqtimingInfo)
                                                                        numPduEncoded++;
                                                                }
                                                        }
-                                                       DU_LOG("\nLOWER MAC: MIB sent..");
+                                                       printf("\033[1;31m");
+                                                       DU_LOG("\nLWR_MAC: MIB sent..");
+                                                       printf("\033[0m");
                                                }
                                                if(currDlSlot->dlInfo.brdcstAlloc.sib1Trans)
                                                {
@@ -2800,20 +2817,29 @@ uint16_t handleDlTtiReq(CmLteTimingInfo *dlTtiReqtimingInfo)
                                                                                sib1Alloc.sib1PdcchCfg, &msgLen);
                                                                numPduEncoded++;
                                                                fillPdschPdu(&dlTtiReq->pdus[numPduEncoded],&currDlSlot->dlInfo.brdcstAlloc.\
-                                                                               sib1Alloc.sib1PdschCfg, &msgLen);
+                                                                               sib1Alloc.sib1PdschCfg, &msgLen, pduIndex);
+                                                               pduIndex++;
                                                                numPduEncoded++;
                                                        }
-                                                       DU_LOG("\nLOWER MAC: SIB1 sent...");
+                                                       printf("\033[1;34m");
+                                                       DU_LOG("\nLWR_MAC: SIB1 sent...");
+                                                       printf("\033[0m");
                                                }
                                        }
                                        if(currDlSlot->dlInfo.isRarPres)
                                        {
                                                /* Filling RAR param */
+                                fillRarPdu(&currDlSlot->dlInfo.rarAlloc.rarInfo);
                                                fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded], &currDlSlot->dlInfo.rarAlloc.rarPdcchCfg, &msgLen);
                                                numPduEncoded++;
-                                               fillPdschPdu(&dlTtiReq->pdus[numPduEncoded], &currDlSlot->dlInfo.rarAlloc.rarPdschCfg, &msgLen);
+                                               fillPdschPdu(&dlTtiReq->pdus[numPduEncoded], &currDlSlot->dlInfo.rarAlloc.rarPdschCfg,
+                                                  &msgLen, pduIndex);
                                                numPduEncoded++;
-                                               DU_LOG("\nLOWER MAC: RAR sent...");
+                                               pduIndex++;
+
+                                               printf("\033[1;32m");
+                                               DU_LOG("\nLWR_MAC: RAR sent...");
+                                               printf("\033[0m");
                                        }
 
                                        msgLen += sizeof(fapi_dl_tti_req_t) - sizeof(fapi_msg_t);
@@ -2821,73 +2847,8 @@ uint16_t handleDlTtiReq(CmLteTimingInfo *dlTtiReqtimingInfo)
                                        /* TODO : Recheck the size / msglen to be sent to WLS_Put*/
                                        LwrMacSendToPhy(dlTtiReq->header.message_type_id, msgLen, (void *)dlTtiReq);
 
-                                       /* FREE the allocated memories */
-                                       if(currDlSlot->dlInfo.brdcstAlloc.sib1Trans)
-                                       {
-                                               if(currDlSlot->dlInfo.brdcstAlloc.ssbTrans)
-                                               {
-                                                       MAC_FREE(dlTtiReq->pdus[1].u.pdcch_pdu.dlDci, 
-                                                                       sizeof(fapi_dl_dci_t));
-                                               }
-                                               else
-                                               {
-                                                       MAC_FREE(dlTtiReq->pdus[0].u.pdcch_pdu.dlDci, 
-                                                                       sizeof(fapi_dl_dci_t));
-                                               }
-                                       }
-                                       if(currDlSlot->dlInfo.isRarPres)
-                                       {
-                                               if(currDlSlot->dlInfo.brdcstAlloc.ssbTrans)
-                                               {
-                                                       MAC_FREE(dlTtiReq->pdus[1].u.pdcch_pdu.dlDci, 
-                                                                       sizeof(fapi_dl_dci_t));
-                                               }
-                                               else
-                                               {
-                                                       MAC_FREE(dlTtiReq->pdus[0].u.pdcch_pdu.dlDci, 
-                                                                       sizeof(fapi_dl_dci_t));
-                                               }
-                                       }
-
-                                       MAC_FREE(dlTtiReq->pdus, (nPdu * sizeof(fapi_dl_tti_req_pdu_t)));
-
-               /* send TX_Data request message */
-               if(currDlSlot->dlInfo.brdcstAlloc.sib1Trans)
-               {
-                  msgLen = 0;
-                  MAC_ALLOC(txDataReq,sizeof(fapi_tx_data_req_t));
-                  txDataReq->sfn = dlTtiReqtimingInfo->sfn;
-                  txDataReq->slot = dlTtiReqtimingInfo->slot;
-                  txDataReq->numPdus = 1;
-                  fillSib1TxDataReq(
-                        &txDataReq->pduDesc,
-                        &rgCb[inst].cell->macCellCfg,
-                        currDlSlot->dlInfo.brdcstAlloc.sib1Alloc.sib1PdschCfg.pduIndex,
-                        &msgLen);
-                  msgLen += sizeof(fapi_tx_data_req_t) - sizeof(fapi_msg_t);
-                  fillMsgHeader(&txDataReq->header, FAPI_TX_DATA_REQUEST, msgLen);
-                  LwrMacSendToPhy(txDataReq->header.message_type_id, msgLen,(void *)txDataReq);
-                                               MAC_FREE(txDataReq,sizeof(fapi_tx_data_req_t));
-               }
-               if(currDlSlot->dlInfo.isRarPres)
-               {
-                  msgLen = 0;
-                                               /* mux and form RAR pdu */
-                                               fillRarPdu(&currDlSlot->dlInfo.rarAlloc.rarInfo);
-
-                  MAC_ALLOC(txDataReq,sizeof(fapi_tx_data_req_t));
-                  txDataReq->sfn = dlTtiReqtimingInfo->sfn;
-                  txDataReq->slot = dlTtiReqtimingInfo->slot;
-                  txDataReq->numPdus = 1;
-                  fillRarTxDataReq(
-                        &txDataReq->pduDesc,
-                        &currDlSlot->dlInfo.rarAlloc.rarInfo,
-                        currDlSlot->dlInfo.rarAlloc.rarPdschCfg.pduIndex,
-                        &msgLen);
-                  fillMsgHeader(&txDataReq->header, FAPI_TX_DATA_REQUEST, msgLen);
-                  LwrMacSendToPhy(txDataReq->header.message_type_id, msgLen,(void *)txDataReq);
-                                               MAC_FREE(txDataReq,sizeof(fapi_tx_data_req_t));
-               }
+                                       /* send Tx-DATA req message */
+                                       sendTxDataReq(currTimingInfo, &currDlSlot->dlInfo);
                                }
                                else
                                {
@@ -2896,29 +2857,98 @@ uint16_t handleDlTtiReq(CmLteTimingInfo *dlTtiReqtimingInfo)
                                        /* TODO : Recheck the size / msglen to be sent to WLS_Put*/
                                        LwrMacSendToPhy(dlTtiReq->header.message_type_id, msgLen, (void *)dlTtiReq);
                                }
-                               MAC_FREE(dlTtiReq, sizeof(fapi_dl_tti_req_t));
                                return ROK;
                        }
                        else
                        {
-                               DU_LOG("\nLOWER MAC: Failed to allocate memory for DL TTI Request");
+                               DU_LOG("\nLWR_MAC: Failed to allocate memory for DL TTI Request");
                                return RFAILED;
                        }
                }
       else
       {
-         DU_LOG("\nLOWER MAC: Current TTI Info is NULL");
+         DU_LOG("\nLWR_MAC: Current TTI Info is NULL");
          return RFAILED;
       }
    }
    else
    {
-       lwr_mac_handleInvalidEvt(dlTtiReqtimingInfo);
+       lwr_mac_handleInvalidEvt(currTimingInfo);
+                return RFAILED;
    }
 #endif
    return ROK;
 }
 
+/*******************************************************************
+ *
+ * @brief Sends TX data Request to PHY
+ *
+ * @details
+ *
+ *    Function : sendTxDataReq
+ *
+ *    Functionality:
+ *         -Sends FAPI TX data req to PHY
+ *
+ * @params[in]    timing info
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+uint16_t sendTxDataReq(CmLteTimingInfo *currTimingInfo, DlAlloc *dlInfo)
+{
+#ifdef FAPI
+       uint8_t nPdu = 0;
+       uint32_t msgLen = 0;
+   uint16_t pduIndex = 0;
+       fapi_tx_data_req_t *txDataReq = NULLP;
+       Inst inst = 0;
+
+       /* send TX_Data request message */
+       nPdu = calcTxDataReqPduCount(dlInfo);
+       if(nPdu > 0)
+       {
+      LWR_MAC_ALLOC(txDataReq,sizeof(fapi_tx_data_req_t));
+               if(txDataReq == NULLP)
+               {
+                       DU_LOG("\nLWR_MAC: Failed to allocate memory for TX data Request");
+                       return RFAILED;
+               }
+               txDataReq->sfn = currTimingInfo->sfn;
+               txDataReq->slot = currTimingInfo->slot;
+      LWR_MAC_ALLOC(txDataReq->pduDesc,nPdu*sizeof(fapi_tx_pdu_desc_t));
+               if(txDataReq->pduDesc == NULLP)
+               {
+                       DU_LOG("\nLWR_MAC: Failed to allocate memory for pduDesc TX data Request");
+                       return RFAILED;
+               }
+
+               if(dlInfo->brdcstAlloc.sib1Trans)
+               {
+                       fillSib1TxDataReq(txDataReq->pduDesc,
+                                       &rgCb[inst].cell->macCellCfg, &msgLen, pduIndex);
+                       pduIndex++;
+                       txDataReq->numPdus++;
+               }
+               if(dlInfo->isRarPres)
+               {
+                       /* mux and form RAR pdu */
+                       //fillRarPdu(&dlInfo->rarAlloc.rarInfo);
+                       fillRarTxDataReq(txDataReq->pduDesc,
+                                       &dlInfo->rarAlloc.rarInfo, &msgLen, pduIndex);
+                       pduIndex++;
+                       txDataReq->numPdus++;
+               }
+
+               msgLen += sizeof(fapi_tx_data_req_t) - sizeof(fapi_msg_t);
+               fillMsgHeader(&txDataReq->header, FAPI_TX_DATA_REQUEST, msgLen);
+               LwrMacSendToPhy(txDataReq->header.message_type_id, msgLen,(void *)txDataReq);
+       }
+#endif
+       return ROK;
+}
+
 /***********************************************************************
  *
  * @brief calculates the total size to be allocated for UL TTI Req
@@ -3050,7 +3080,7 @@ void fillPrachPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg, Ma
  *         RFAILED - failure
  *
  ******************************************************************/
-S16 handleUlTtiReq(CmLteTimingInfo *currTimingInfo)
+uint16_t handleUlTtiReq(CmLteTimingInfo *currTimingInfo)
 {
 #ifdef FAPI
    uint32_t msgLen = 0;
@@ -3069,11 +3099,7 @@ S16 handleUlTtiReq(CmLteTimingInfo *currTimingInfo)
 
       if(currTimingInfo != NULLP)
       {
-#ifdef INTEL_WLS
-         WLS_MEM_ALLOC(ulTtiReq, sizeof(fapi_ul_tti_req_t));
-#else
-         MAC_ALLOC(ulTtiReq, sizeof(fapi_ul_tti_req_t));
-#endif
+         LWR_MAC_ALLOC(ulTtiReq, sizeof(fapi_ul_tti_req_t));
          if(ulTtiReq != NULLP)
          {
             ulTtiReq->sfn = currTimingInfo->sfn;
@@ -3083,11 +3109,8 @@ S16 handleUlTtiReq(CmLteTimingInfo *currTimingInfo)
             ulTtiReq->nGroup = 0;
             if(ulTtiReq->nPdus > 0)
             {
-#ifdef INTEL_WLS
-               WLS_MEM_ALLOC(ulTtiReqPdu, (ulTtiReq->nPdus * sizeof(fapi_ul_tti_req_pdu_t)));
-#else
-               MAC_ALLOC(ulTtiReqPdu, (ulTtiReq->nPdus * sizeof(fapi_ul_tti_req_pdu_t)));
-#endif
+                                  LWR_MAC_ALLOC(ulTtiReqPdu, (ulTtiReq->nPdus *
+                                       sizeof(fapi_ul_tti_req_pdu_t)));
                /* Fill Prach Pdu */
                if(ulTtiReq->rachPresent)
                {
@@ -3098,30 +3121,28 @@ S16 handleUlTtiReq(CmLteTimingInfo *currTimingInfo)
                  }
                  msgLen = sizeof(fapi_ul_tti_req_t) - sizeof(fapi_msg_t);
                  fillMsgHeader(&ulTtiReq->header, FAPI_UL_TTI_REQUEST, msgLen);
-                 DU_LOG("\nLOWER MAC: Sending UL TTI Request");
+                 DU_LOG("\nLWR_MAC: Sending UL TTI Request");
                  LwrMacSendToPhy(ulTtiReq->header.message_type_id, msgLen, (void *)ulTtiReq);
-                                         MAC_FREE(ulTtiReqPdu, (ulTtiReq->nPdus * sizeof(fapi_ul_tti_req_pdu_t)));
                }
             } 
             else
             {
                 msgLen = sizeof(fapi_ul_tti_req_t) - sizeof(fapi_msg_t);
                 fillMsgHeader(&ulTtiReq->header, FAPI_UL_TTI_REQUEST, msgLen);
-                DU_LOG("\nLOWER MAC: Sending UL TTI Request");
+                DU_LOG("\nLWR_MAC: Sending UL TTI Request");
                 LwrMacSendToPhy(ulTtiReq->header.message_type_id, msgLen, (void *)ulTtiReq);
             }
-                               MAC_FREE(ulTtiReq, sizeof(fapi_ul_tti_req_t));
                                return ROK;
          }
              else
              {
-                DU_LOG("\nLOWER MAC: Failed to allocate memory for UL TTI Request");
+                DU_LOG("\nLWR_MAC: Failed to allocate memory for UL TTI Request");
             return RFAILED;
          }
       }
       else
       {
-         DU_LOG("\nLOWER MAC: Current TTI Info in UL is NULL");
+         DU_LOG("\nLWR_MAC: Current TTI Info in UL is NULL");
          return RFAILED;
       }
    }
@@ -3163,7 +3184,7 @@ lwrMacFsmHdlr fapiEvtHdlr[MAX_STATE][MAX_EVENT] =
 
 /*******************************************************************
  *
- * @brief Sends message to Lower Mac Fsm Event Handler
+ * @brief Sends message to LWR_MAC Fsm Event Handler
  *
  * @details
  *