X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2F5gnrmac%2Fmac_demux.c;h=1989a3be5c9b8f1c24172ff5107624c864b25afc;hb=e0ab592152182a8a00aa8e7968209d2c4152e1e9;hp=44be3a4513b97a2f1b93d5f330925a535f97de73;hpb=45d134510deb6902b870b4a0fb574b6075fba601;p=o-du%2Fl2.git diff --git a/src/5gnrmac/mac_demux.c b/src/5gnrmac/mac_demux.c index 44be3a451..1989a3be5 100644 --- a/src/5gnrmac/mac_demux.c +++ b/src/5gnrmac/mac_demux.c @@ -26,6 +26,7 @@ #include "mac.h" #include "mac_utils.h" + /******************************************************************* * * @brief De-mux of MAC-Sub PDUs from Rx Data Ind Pdu @@ -43,111 +44,223 @@ * RFAILED * * ****************************************************************/ -uint8_t unpackRxData(uint16_t cellId, RxDataIndPdu *rxDataIndPdu) +uint8_t unpackRxData(uint16_t cellId, SlotTimingInfo slotInfo, RxDataIndPdu *rxDataIndPdu) { - uint8_t lcId; - uint8_t idx = 0; - uint16_t length; - uint8_t *pdu; - uint16_t pduLen; - uint8_t *rxDataPdu; - uint16_t cellIdx; + uint8_t ueId = 0; /* UE Identity */ + uint8_t ueIdx = 0; /* Iterator for UE list */ + uint8_t lcId = 0; /* LC ID of a sub pdu */ + uint8_t fBit = 0; /* Value of F Bit in MAC sub-header */ + uint8_t rxPduIdx = 0; /* Iterator for received PDU */ + uint16_t length = 0; /* Length of payload in a sub-PDU */ + uint8_t *pdu = NULLP; /* Payload in sub-PDU */ + uint16_t pduLen = 0; /* Length of undecoded PDU */ + uint8_t *rxDataPdu = NULLP; /* Received PDU in Rx Data Ind */ + uint16_t cellIdx = 0; /* Cell Index */ + uint8_t ret =ROK; GET_CELL_IDX(cellId, cellIdx); + + if(rxDataIndPdu == NULLP) + { + DU_LOG("\nERROR --> MAC: Rx Data is empty"); + return RFAILED; + } + + if(macCb.macCell[cellIdx] == NULLP) + { + DU_LOG("\nERROR --> CellId :%d is not created, as CellCB is empty", cellId); + return RFAILED; + } pduLen = rxDataIndPdu->pduLength; rxDataPdu = rxDataIndPdu->pduData; + GET_UE_ID(rxDataIndPdu->rnti, ueId); + ueIdx = ueId -1; while(pduLen > 0) { + /* MSB in 1st octet is Reserved bit. Hence not decoding it. + 2nd MSB in 1st octet is R/F bit depending upon type of payload */ + fBit = (1 << 7) & rxDataPdu[rxPduIdx]; + /* LC id is the 6 LSB in 1st octet */ - lcId = (~((~0) << 6)) & rxDataPdu[idx]; + lcId = (~((~0) << 6)) & rxDataPdu[rxPduIdx]; + pdu = NULLP; switch(lcId) { - case MAC_LCID_CCCH : - { - pduLen--; + case MAC_LCID_CCCH : + { + pduLen--; + + /* for UL CCCH,fixed length of MAC SDU */ + length = 6; + + /* Allocating sharable memory to send ul ccch msg to du app*/ + MAC_ALLOC_SHRABL_BUF(pdu, length); + if(!pdu) + { + DU_LOG("\nERROR --> MAC : UL CCCH PDU memory allocation failed"); + return RFAILED; + } + rxPduIdx++; + memcpy(pdu, &rxDataPdu[rxPduIdx], length); + pduLen -= length; + rxPduIdx = rxPduIdx + length; + + /* store msg3 pdu in macRaCb for CRI value */ + memcpy(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg3Pdu, pdu, length); + + /* Send UL-CCCH Indication to DU APP */ + ret = macProcUlCcchInd(macCb.macCell[cellIdx]->cellId, rxDataIndPdu->rnti, length, pdu); + break; + } + + case MAC_LCID_MIN ... MAC_LCID_MAX : + { + DU_LOG("\nINFO --> MAC : PDU received for LC ID %d", lcId); + pduLen--; + rxPduIdx++; - /* for UL CCCH,fixed length of MAC SDU */ - length = 6; + length = rxDataPdu[rxPduIdx]; + if(fBit) + { + pduLen--; + rxPduIdx++; + length = (length << 8) & rxDataPdu[rxPduIdx]; + } - /* Allocating sharable memory to send ul ccch msg to du app*/ - MAC_ALLOC_SHRABL_BUF(pdu, length); - if(!pdu) - { - DU_LOG("\nMAC : UL CCCH PDU memory allocation failed"); - return RFAILED; - } - idx++; - memcpy(pdu, &rxDataPdu[idx], length); - pduLen -= length; - idx = idx + length; + pdu = NULLP; + /* Copying the payload to send to RLC */ + MAC_ALLOC_SHRABL_BUF(pdu, length); + if(!pdu) + { + DU_LOG("\nERROR --> MAC : Memory allocation failed while demuxing Rx Data PDU"); + return RFAILED; + } + pduLen--; + rxPduIdx++; + memcpy(pdu, &rxDataPdu[rxPduIdx], length); + pduLen -= length; + rxPduIdx = rxPduIdx + length; - /* store msg3 pdu in macRaCb for CRI value */ - memcpy(macCb.macCell[cellIdx]->macRaCb[0].msg3Pdu, pdu, length); + /* Send UL Data to RLC */ + ret = macProcUlData(cellId, rxDataIndPdu->rnti, slotInfo, lcId, length, pdu); - /* Send UL-CCCH Indication to DU APP */ - macSendUlCcchInd(pdu, macCb.macCell[cellIdx]->cellId, rxDataIndPdu->rnti); - break; - } + break; + } + case MAC_LCID_RESERVED_MIN ... MAC_LCID_RESERVED_MAX : + break; - case MAC_DEDLC_MIN_LCID ... MAC_DEDLC_MAX_LCID : - break; + case MAC_LCID_CCCH_48BIT : + break; - case MAC_LCID_RESERVED_MIN ... MAC_LCID_RESERVED_MAX : - break; + case MAC_LCID_BIT_RATE_QUERY : + break; - case MAC_LCID_CCCH_48BIT : - break; + case MAC_LCID_MULT_PHR_FOUR_OCT : + break; - case MAC_LCID_BIT_RATE_QUERY : - break; + case MAC_LCID_CFG_GRANT_CFM : + break; - case MAC_LCID_MULT_PHR_FOUR_OCT : - break; + case MAC_LCID_MULT_PHR_ONE_OCT: + break; - case MAC_LCID_CFG_GRANT_CFM : - break; + case MAC_LCID_SINGLE_PHR : + break; - case MAC_LCID_MULT_PHR_ONE_OCT: - break; + case MAC_LCID_CRNTI : + break; - case MAC_LCID_SINGLE_PHR : - break; + case MAC_LCID_SHORT_TRUNC_BSR : + break; - case MAC_LCID_CRNTI : - break; + case MAC_LCID_LONG_TRUNC_BSR : + break; - case MAC_LCID_SHORT_TRUNC_BSR : - break; + case MAC_LCID_SHORT_BSR : + { + uint8_t lcgId = 0; + uint8_t bufferSizeIdx = 0; + uint8_t crnti = 0; + uint32_t bufferSize = 0; - case MAC_LCID_LONG_TRUNC_BSR : - break; + pduLen--; - case MAC_LCID_SHORT_BSR : - break; + rxPduIdx++; + crnti = rxDataIndPdu->rnti; + /* 5 LSB bits in pdu represent buffer size */ + bufferSizeIdx = (~((~0) << 5)) & rxDataPdu[rxPduIdx]; + /* first 3 MSB bits in pdu represent LCGID */ + lcgId = (rxDataPdu[rxPduIdx]) >> 5; + /* determine actual number of bytes requested */ + bufferSize = shortBsrBytesTable[bufferSizeIdx]; + ret = macProcShortBsr(macCb.macCell[cellIdx]->cellId, crnti, lcgId, bufferSize); + pduLen--; + rxPduIdx++; - case MAC_LCID_LONG_BSR : - break; + break; + } - case MAC_LCID_PADDING : - { - break; - } + case MAC_LCID_LONG_BSR : + { + DataVolInfo dataVolInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS]; + memset(dataVolInfo, 0,MAX_NUM_LOGICAL_CHANNEL_GROUPS * sizeof(DataVolInfo)); + uint8_t lcgIdx = 0; + uint8_t crnti = 0; + uint8_t numLcg = 0; + uint8_t lcgIdxPos = 0; + pduLen--; - default: - { - DU_LOG("\nMAC : Invalid LC Id %d", lcId); - return RFAILED; - } + rxPduIdx++;/*To reach the Octet where lcgIdx will be present*/ + crnti = rxDataIndPdu->rnti; + + lcgIdxPos = rxPduIdx; + + pduLen--; + rxPduIdx++;/*To reach the Octet where bsrIdx starts*/ + for(lcgIdx = 0; lcgIdx < MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++) + { + if(rxDataPdu[lcgIdxPos] & (1 << lcgIdx)) + { + if(rxDataPdu[rxPduIdx] > 0 && rxDataPdu[rxPduIdx] < MAX_LONG_BSR_TABLE_ENTRIES) + { + dataVolInfo[numLcg].dataVol = longBsrBytesTable[rxDataPdu[rxPduIdx]]; + dataVolInfo[numLcg].lcgId = lcgIdx; + numLcg++; + } + else + { + DU_LOG("\nERROR --> MAC: Invalid BsrIdx:%d rcvd for lcgIdx:%d",lcgIdx,rxDataPdu[rxPduIdx]); + } + /*next byte in PDU*/ + pduLen--; + rxPduIdx++; + } + } + + ret = macProcLongBsr(macCb.macCell[cellIdx]->cellId, crnti, numLcg, dataVolInfo); + + break; + } + + case MAC_LCID_PADDING : + break; + + default: + { + DU_LOG("\nERROR --> MAC : Invalid LC Id %d", lcId); + return RFAILED; + } } /* End of switch */ if(lcId == MAC_LCID_PADDING) - break; - + { + break; + } } /* End of While */ - return ROK; + return ret; } /* End of unpackRxData */ /**********************************************************************