X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2F5gnrmac%2Fmac_mux.c;h=a72639579991e4f9ba6e1438dcf6430c91937759;hb=ba2574ac618b40905509604da8d3a2b1b9e39664;hp=688afd6979809277d85c8d768a033ffe293b27be;hpb=746426865b5742eb3d79ae2457081c47c1c2c4c1;p=o-du%2Fl2.git diff --git a/src/5gnrmac/mac_mux.c b/src/5gnrmac/mac_mux.c index 688afd697..a72639579 100644 --- a/src/5gnrmac/mac_mux.c +++ b/src/5gnrmac/mac_mux.c @@ -16,51 +16,16 @@ ################################################################################ *******************************************************************************/ -#include -#include -#include /* header include files -- defines (.h) */ -#include "envopt.h" /* environment options */ -#include "envdep.h" /* environment dependent */ -#include "envind.h" /* environment independent */ -#include "gen.h" /* general layer */ -#include "ssi.h" /* system service interface */ -#include "cm_hash.h" /* common hash list */ -#include "cm_mblk.h" /* common memory link list library */ -#include "cm_llist.h" /* common linked list library */ -#include "cm_err.h" /* common error */ -#include "cm_lte.h" /* common LTE */ +#include "common_def.h" #include "lrg.h" /* Layer manager interface includes*/ -#include "crg.h" /* CRG interface includes*/ -#include "rgu.h" /* RGU interface includes*/ -#include "tfu.h" /* TFU interface includes */ -#include "rg_sch_inf.h" /* SCH interface includes */ -#include "rg_prg.h" /* PRG (MAC-MAC) interface includes*/ -#include "rg_env.h" /* MAC environmental includes*/ -#include "rg.h" /* MAC includes*/ -#include "rg_err.h" /* MAC error includes*/ -#include "du_log.h" - -/* header/extern include files (.x) */ -#include "gen.x" /* general layer typedefs */ -#include "ssi.x" /* system services typedefs */ -#include "cm5.x" /* common timers */ -#include "cm_hash.x" /* common hash list */ -#include "cm_lib.x" /* common library */ -#include "cm_llist.x" /* common linked list */ -#include "cm_mblk.x" /* memory management */ -#include "cm_tkns.x" /* common tokens */ -#include "cm_lte.x" /* common tokens */ -#include "rgu.x" /* RGU types */ -#include "tfu.x" /* RGU types */ #include "lrg.x" /* layer management typedefs for MAC */ -#include "crg.x" /* CRG interface includes */ -#include "rg_sch_inf.x" /* SCH interface typedefs */ -#include "rg_prg.x" /* PRG (MAC-MAC) Interface typedefs */ #include "du_app_mac_inf.h" +#include "mac_sch_interface.h" +#include "lwr_mac_upr_inf.h" #include "mac.h" -#include "rg.x" /* typedefs for MAC */ +#include "mac_utils.h" /******************************************************************* * @@ -84,7 +49,7 @@ void packBytes(uint8_t *buf, uint8_t *bytePos, uint8_t *bitPos, uint32_t val, ui uint32_t bytePart2; uint8_t bytePart1Size; uint32_t bytePart2Size; - + if(*bitPos - valSize + 1 >= 0) { bytePart1 = (uint8_t)val; @@ -92,11 +57,11 @@ void packBytes(uint8_t *buf, uint8_t *bytePos, uint8_t *bitPos, uint32_t val, ui buf[*bytePos] |= bytePart1; if(*bitPos - valSize < 0) { - *bitPos = 7; - (*bytePos)++; + *bitPos = 7; + (*bytePos)++; } else - *bitPos -= valSize; + *bitPos -= valSize; } else { @@ -106,7 +71,7 @@ void packBytes(uint8_t *buf, uint8_t *bytePos, uint8_t *bitPos, uint32_t val, ui bytePart1 = (val >> bytePart2Size) << (*bitPos -bytePart1Size +1); bytePart2 = (~((~temp) << bytePart2Size)) & val; - + buf[*bytePos] |= bytePart1; (*bytePos)++; *bitPos = 7; @@ -147,14 +112,14 @@ void fillRarPdu(RarInfo *rarInfo) uint16_t timeAdv = 0; uint32_t ulGrant = 0; uint16_t tmpCrnti = 0; - uint8_t paddingLcid = 63; + uint8_t paddingLcid = 63; /* Size(in bits) of RAR subheader files */ uint8_t EBitSize = 1; uint8_t TBitSize = 1; uint8_t rapidSize = 6; - uint8_t paddingLcidSize = 6; - uint8_t paddingSize = 8; + uint8_t paddingLcidSize = 6; + uint8_t paddingSize = 8; /* Size(in bits) of RAR payload fields */ @@ -167,7 +132,7 @@ void fillRarPdu(RarInfo *rarInfo) EBit = 0; TBit = 1; rapId = rarInfo->RAPID; - + RBit = 0; timeAdv = rarInfo->ta; ulGrant = 0; /* this will be done when implementing msg3 */ @@ -175,22 +140,22 @@ void fillRarPdu(RarInfo *rarInfo) /* Calulating total number of bytes in buffer */ totalBits = EBitSize + TBitSize + rapidSize + RBitSize + timeAdvSize \ - + ulGrantSize + tmpCrntiSize; + + ulGrantSize + tmpCrntiSize; /* add padding size */ - totalBits += RBitSize*2 + paddingLcidSize + paddingSize; - + totalBits += RBitSize*2 + paddingLcidSize + paddingSize; + /* Calulating total number of bytes in buffer */ numBytes = totalBits/8; if(totalBits % 8) numBytes += 1; - - rarInfo->rarPduLen = numBytes; + + rarInfo->rarPduLen = numBytes; /* Initialize buffer */ for(bytePos = 0; bytePos < numBytes; bytePos++) rarPdu[bytePos] = 0; - + bytePos = 0; bitPos = 7; @@ -203,11 +168,11 @@ void fillRarPdu(RarInfo *rarInfo) packBytes(rarPdu, &bytePos, &bitPos, ulGrant, ulGrantSize); packBytes(rarPdu, &bytePos, &bitPos, tmpCrnti, tmpCrntiSize); - /* padding of 2 bytes */ + /* padding of 2 bytes */ packBytes(rarPdu, &bytePos, &bitPos, RBit, RBitSize*2); packBytes(rarPdu, &bytePos, &bitPos, paddingLcid, paddingLcidSize); packBytes(rarPdu, &bytePos, &bitPos, 0, paddingSize); - + } /******************************************************************* @@ -226,11 +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 */ - macCb.macCell->macRaCb[idx].cellId = cellId; - macCb.macCell->macRaCb[idx].crnti = crnti; + uint8_t ueIdx = 0; + uint16_t crnti = 0; + uint16_t cellIdx = 0; + + GET_CELL_IDX(rachIndInfo->cellId, cellIdx); + + crnti = getNewCrnti(&macCb.macCell[cellIdx]->crntiMap); + if(crnti == -1) + return; + + 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; } /************************************************* @@ -239,24 +220,21 @@ void createMacRaCb(uint16_t cellId, uint16_t crnti) * @details * * Function : fillMsg4DlData - * This function is a stub which sends Dl Data + * This function sends Dl Data * to form MAC SDUs * * @param[in] MacDlData *dlData + * msg4Pdu pointer ************************************************/ -void fillMsg4DlData(MacDlData *dlData) +void fillMsg4DlData(MacDlData *dlData, uint16_t msg4PduLen, uint8_t *msg4Pdu) { uint8_t idx = 0; - uint16_t idx2; + dlData->numPdu = 1; dlData->pduInfo[idx].lcId = MAC_LCID_CCCH; - dlData->pduInfo[idx].pduLen = macCb.macCell->macRaCb[idx].msg4PduLen; - for(idx2 = 0; idx2 < dlData->pduInfo[idx].pduLen; idx2++) - { - dlData->pduInfo[idx].dlPdu[idx2] = \ - macCb.macCell->macRaCb[idx].msg4Pdu[idx2]; - } + dlData->pduInfo[idx].pduLen = msg4PduLen; + memcpy(dlData->pduInfo[idx].dlPdu, msg4Pdu, msg4PduLen); } /************************************************* @@ -268,9 +246,10 @@ void fillMsg4DlData(MacDlData *dlData) * This function fills Mac ce identities * * @param[in] RlcMacData *dlData + * Msg3Pdu Data ************************************************/ -void fillMacCe(MacCeInfo *macCeInfo) +void fillMacCe(MacCeInfo *macCeInfo, uint8_t *msg3Pdu) { uint8_t idx; macCeInfo->numCes = 1; @@ -278,7 +257,7 @@ void fillMacCe(MacCeInfo *macCeInfo) { macCeInfo->macCe[idx].macCeLcid = MAC_LCID_CRI; memcpy(macCeInfo->macCe[idx].macCeValue, \ - macCb.macCell->macRaCb[idx].msg3Pdu, MAX_CRI_SIZE); + msg3Pdu, MAX_CRI_SIZE); } } @@ -293,12 +272,11 @@ void fillMacCe(MacCeInfo *macCeInfo) * Functionality: * The MAC PDU will be MUXed and formed * - * @params[in] MacDlData *, MacCeInfo *, tbSize + * @params[in] MacDlData *, MacCeInfo *, txPdu *, tbSize * @return void - * * ****************************************************************/ -void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint16_t tbSize) +void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *txPdu, uint16_t tbSize) { uint8_t bytePos = 0; uint8_t bitPos = 7; @@ -308,8 +286,8 @@ void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint16_t tbSize) /* 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) */ @@ -319,24 +297,27 @@ void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint16_t tbSize) 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: + lcid = macCeData->macCe[idx].macCeLcid; + switch(lcid) { - /* 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("\n MAC: Invalid LCID %d in mac pdu",lcid); - break; + 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("\n MAC: Invalid LCID %d in mac pdu",lcid); + break; + } } } @@ -346,33 +327,34 @@ void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint16_t tbSize) lcid = dlData->pduInfo[idx].lcId; switch(lcid) { - case MAC_LCID_CCCH: - { - lenField = dlData->pduInfo[idx].pduLen; - if(dlData->pduInfo[idx].pduLen > 255) - { - FBit = 1; - lenFieldSize = 16; - - } - else - { - FBit = 0; - lenFieldSize = 8; - } - /* Packing fields into MAC PDU R/F/LCID/L */ - packBytes(macPdu, &bytePos, &bitPos, RBit, RBitSize); - packBytes(macPdu, &bytePos, &bitPos, FBit, FBitSize); - packBytes(macPdu, &bytePos, &bitPos, lcid, lcidSize); - packBytes(macPdu, &bytePos, &bitPos, lenField, lenFieldSize); - memcpy(&macPdu[bytePos], dlData->pduInfo[idx].dlPdu, lenField); - bytePos += lenField; - break; - } - - default: - DU_LOG("\n MAC: Invalid LCID %d in mac pdu",lcid); - break; + case MAC_LCID_CCCH: + case MAC_LCID_MIN ... MAC_LCID_MAX : + { + lenField = dlData->pduInfo[idx].pduLen; + if(dlData->pduInfo[idx].pduLen > 255) + { + FBit = 1; + lenFieldSize = 16; + + } + else + { + FBit = 0; + lenFieldSize = 8; + } + /* Packing fields into MAC PDU R/F/LCID/L */ + packBytes(macPdu, &bytePos, &bitPos, RBit, RBitSize); + packBytes(macPdu, &bytePos, &bitPos, FBit, FBitSize); + packBytes(macPdu, &bytePos, &bitPos, lcid, lcidSize); + packBytes(macPdu, &bytePos, &bitPos, lenField, lenFieldSize); + memcpy(&macPdu[bytePos], dlData->pduInfo[idx].dlPdu, lenField); + bytePos += lenField; + break; + } + + default: + DU_LOG("\n MAC: Invalid LCID %d in mac pdu",lcid); + break; } } @@ -385,13 +367,10 @@ void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint16_t tbSize) packBytes(macPdu, &bytePos, &bitPos, lcid, lcidSize); } - /*Storing the muxed pdu in macRaCb */ - macCb.macCell->macRaCb[0].msg4TxPdu = NULLP; - MAC_ALLOC(macCb.macCell->macRaCb[0].msg4TxPdu, macCb.macCell->macRaCb[0].msg4TbSize); - if(macCb.macCell->macRaCb[0].msg4TxPdu != NULLP) + /*Storing the muxed pdu */ + if(txPdu != NULLP) { - memcpy(macCb.macCell->macRaCb[0].msg4TxPdu, macPdu,\ - macCb.macCell->macRaCb[0].msg4TbSize); + memcpy(txPdu, macPdu, tbSize); } }