Commit c1bb3b04 authored by Raphael Defosseux's avatar Raphael Defosseux

Merge remote-tracking branch 'origin/nr_ue_mac_pdu_fixes' into integration_2021_w33

parents 4a8823d4 91c0fe24
...@@ -234,8 +234,6 @@ typedef struct { ...@@ -234,8 +234,6 @@ typedef struct {
int RA_PCMAX; int RA_PCMAX;
/// Corresponding RA-RNTI for UL-grant /// Corresponding RA-RNTI for UL-grant
uint16_t ra_RNTI; uint16_t ra_RNTI;
/// Pointer to Msg3 payload for UL-grant
uint8_t *Msg3;
/// Frame of last completed synch /// Frame of last completed synch
uint16_t sync_frame; uint16_t sync_frame;
/// Flag to indicate that prach is ready to start: it is enabled with an initial delay after the sync /// Flag to indicate that prach is ready to start: it is enabled with an initial delay after the sync
......
...@@ -2132,7 +2132,8 @@ void nr_ue_prach_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, uint8_t ...@@ -2132,7 +2132,8 @@ void nr_ue_prach_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, uint8_t
int16_t ra_preamble_rx_power = (int16_t)(prach_resources->ra_PREAMBLE_RECEIVED_TARGET_POWER - pathloss + 30); int16_t ra_preamble_rx_power = (int16_t)(prach_resources->ra_PREAMBLE_RECEIVED_TARGET_POWER - pathloss + 30);
ue->tx_power_dBm[nr_slot_tx] = min(nr_get_Pcmax(mod_id), ra_preamble_rx_power); ue->tx_power_dBm[nr_slot_tx] = min(nr_get_Pcmax(mod_id), ra_preamble_rx_power);
LOG_D(PHY,"DEBUG [UE %d][RAPROC][%d.%d]: Generating PRACH Msg1 (preamble %d, PL %d dB, P0_PRACH %d, TARGET_RECEIVED_POWER %d dBm, RA-RNTI %x)\n", LOG_D(PHY, "In %s: [UE %d][RAPROC][%d.%d]: Generating PRACH Msg1 (preamble %d, PL %d dB, P0_PRACH %d, TARGET_RECEIVED_POWER %d dBm, RA-RNTI %x)\n",
__FUNCTION__,
mod_id, mod_id,
frame_tx, frame_tx,
nr_slot_tx, nr_slot_tx,
......
...@@ -325,6 +325,15 @@ typedef struct { ...@@ -325,6 +325,15 @@ typedef struct {
} RAR_grant_t; } RAR_grant_t;
typedef struct {
uint8_t phr_reporting;
uint16_t truncated_bsr;
uint16_t short_bsr;
uint16_t long_bsr;
} NR_UE_MAC_CE_t;
typedef struct { typedef struct {
int n_HARQ_ACK; int n_HARQ_ACK;
uint32_t ack_payload; uint32_t ack_payload;
...@@ -340,7 +349,6 @@ typedef struct { ...@@ -340,7 +349,6 @@ typedef struct {
int8_t delta_pucch; int8_t delta_pucch;
} PUCCH_sched_t; } PUCCH_sched_t;
/*!\brief Top level UE MAC structure */ /*!\brief Top level UE MAC structure */
typedef struct { typedef struct {
...@@ -407,12 +415,8 @@ typedef struct { ...@@ -407,12 +415,8 @@ typedef struct {
nr_ue_if_module_t *if_module; nr_ue_if_module_t *if_module;
nr_phy_config_t phy_config; nr_phy_config_t phy_config;
/// BSR report flag management
uint8_t BSR_reporting_active;
NR_UE_SCHEDULING_INFO scheduling_info; NR_UE_SCHEDULING_INFO scheduling_info;
NR_UE_MAC_CE_t nr_ue_mac_ce;
/// PHR
uint8_t PHR_reporting_active;
NR_Type0_PDCCH_CSS_config_t type0_PDCCH_CSS_config; NR_Type0_PDCCH_CSS_config_t type0_PDCCH_CSS_config;
NR_SearchSpace_t *search_space_zero; NR_SearchSpace_t *search_space_zero;
......
...@@ -169,18 +169,8 @@ void nr_ue_process_mac_pdu(nr_downlink_indication_t *dl_info, ...@@ -169,18 +169,8 @@ void nr_ue_process_mac_pdu(nr_downlink_indication_t *dl_info,
NR_UL_TIME_ALIGNMENT_t *ul_time_alignment, NR_UL_TIME_ALIGNMENT_t *ul_time_alignment,
int pdu_id); int pdu_id);
uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload, int nr_write_ce_ulsch_pdu(uint8_t *mac_ce,
uint8_t *pdu, NR_UE_MAC_INST_t *mac);
uint8_t num_sdus,
uint16_t *sdu_lengths,
uint8_t *sdu_lcids,
uint8_t power_headroom,
uint16_t crnti,
uint16_t truncated_bsr,
uint16_t short_bsr,
uint16_t long_bsr,
unsigned short post_padding,
uint16_t buflen);
void fill_dci_search_candidates(NR_SearchSpace_t *ss,fapi_nr_dl_config_dci_dl_pdu_rel15_t *rel15); void fill_dci_search_candidates(NR_SearchSpace_t *ss,fapi_nr_dl_config_dci_dl_pdu_rel15_t *rel15);
...@@ -201,10 +191,12 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment(NR_UE_MAC_INST_t *mac, ...@@ -201,10 +191,12 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment(NR_UE_MAC_INST_t *mac,
uint8_t time_domain_ind, uint8_t time_domain_ind,
bool use_default); bool use_default);
uint8_t uint8_t nr_ue_get_sdu(module_id_t module_idP,
nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, frame_t frameP,
sub_frame_t subframe, uint8_t eNB_index, sub_frame_t subframe,
uint8_t *ulsch_buffer, uint16_t buflen, uint8_t *access_mode) ; uint8_t gNB_index,
uint8_t *ulsch_buffer,
uint16_t buflen);
int set_tdd_config_nr_ue(fapi_nr_config_request_t *cfg, int mu, int set_tdd_config_nr_ue(fapi_nr_config_request_t *cfg, int mu,
int nrofDownlinkSlots, int nrofDownlinkSymbols, int nrofDownlinkSlots, int nrofDownlinkSymbols,
......
...@@ -474,23 +474,19 @@ void nr_Msg3_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, uint ...@@ -474,23 +474,19 @@ void nr_Msg3_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, uint
} }
///////////////////////////////////////////////////////////////////////// /**
// This function handles: * Function: handles Random Access Preamble Initialization (5.1.1 TS 38.321)
// - Random Access Preamble Initialization (5.1.1 TS 38.321) * handles Random Access Response reception (5.1.4 TS 38.321)
// - Random Access Response reception (5.1.4 TS 38.321) * Note: In SA mode the Msg3 contains a CCCH SDU, therefore no C-RNTI MAC CE is transmitted.
/// In the current implementation, RA is 4-step contention free only *
///////////////////////////////////////////////////////////////////////// * @prach_resources pointer to PRACH resources
// todo TS 38.321: * @prach_pdu pointer to FAPI UL PRACH PDU
// - BWP operation (subclause 5.15 TS 38.321) * @mod_id module ID
// - beam failure recovery * @CC_id CC ID
// - handle initialization by handover * @frame current UL TX frame
// - handle DL assignment on PDCCH for RA-RNTI * @gNB_id gNB ID
// - transmission on DCCH using PRACH (during handover, or sending SR for example) * @nr_slot_tx current UL TX slot
// - take into account MAC CEs in size_sdu (currently hardcoded size to 1 MAC subPDU and 1 padding subheader) */
// - fix rrc data req logic
// - retrieve TBS
// - add mac_rrc_nr_data_req_ue, etc ...
// - Msg3 Retransmissions to be scheduled by DCI 0_0
uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
fapi_nr_ul_config_prach_pdu *prach_pdu, fapi_nr_ul_config_prach_pdu *prach_pdu,
module_id_t mod_id, module_id_t mod_id,
...@@ -501,11 +497,6 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, ...@@ -501,11 +497,6 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id);
RA_config_t *ra = &mac->ra; RA_config_t *ra = &mac->ra;
uint8_t mac_sdus[MAX_NR_ULSCH_PAYLOAD_BYTES];
uint8_t lcid = UL_SCH_LCID_CCCH;
uint8_t *payload;
uint16_t size_sdu = 0;
unsigned short post_padding;
NR_RACH_ConfigCommon_t *setup; NR_RACH_ConfigCommon_t *setup;
if (mac->scc) setup = mac->scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup; if (mac->scc) setup = mac->scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup;
else setup = mac->scc_SIB->uplinkConfigCommon->initialUplinkBWP.rach_ConfigCommon->choice.setup; else setup = mac->scc_SIB->uplinkConfigCommon->initialUplinkBWP.rach_ConfigCommon->choice.setup;
...@@ -513,11 +504,6 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, ...@@ -513,11 +504,6 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
NR_RACH_ConfigGeneric_t *rach_ConfigGeneric = &setup->rach_ConfigGeneric; NR_RACH_ConfigGeneric_t *rach_ConfigGeneric = &setup->rach_ConfigGeneric;
NR_RACH_ConfigDedicated_t *rach_ConfigDedicated = ra->rach_ConfigDedicated; NR_RACH_ConfigDedicated_t *rach_ConfigDedicated = ra->rach_ConfigDedicated;
uint8_t sdu_lcids[NB_RB_MAX] = {0};
uint16_t sdu_lengths[NB_RB_MAX] = {0};
int num_sdus = 0;
int offset = 0;
// Delay init RA procedure to allow the convergence of the IIR filter on PRACH noise measurements at gNB side // Delay init RA procedure to allow the convergence of the IIR filter on PRACH noise measurements at gNB side
if (!prach_resources->init_msg1) { if (!prach_resources->init_msg1) {
if ( (mac->common_configuration_complete>0 || get_softmodem_params()->do_ra==1) && ((MAX_FRAME_NUMBER+frame-prach_resources->sync_frame)%MAX_FRAME_NUMBER)>150 ){ if ( (mac->common_configuration_complete>0 || get_softmodem_params()->do_ra==1) && ((MAX_FRAME_NUMBER+frame-prach_resources->sync_frame)%MAX_FRAME_NUMBER)>150 ){
...@@ -528,90 +514,107 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, ...@@ -528,90 +514,107 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
} }
} }
LOG_D(NR_MAC,"frame %d prach_resources->init_msg1 %d, ra->ra_state %d, ra->RA_active %d\n", LOG_D(NR_MAC, "In %s: [UE %d][%d.%d]: init_msg1 %d, ra_state %d, RA_active %d\n",
frame,prach_resources->init_msg1,ra->ra_state,ra->RA_active); __FUNCTION__,
mod_id,
frame,
nr_slot_tx,
prach_resources->init_msg1,
ra->ra_state,
ra->RA_active);
if (prach_resources->init_msg1 && ra->ra_state != RA_SUCCEEDED) { if (prach_resources->init_msg1 && ra->ra_state != RA_SUCCEEDED) {
if (ra->RA_active == 0) { if (ra->RA_active == 0) {
/* RA not active - checking if RRC is ready to initiate the RA procedure */ /* RA not active - checking if RRC is ready to initiate the RA procedure */
LOG_D(NR_MAC, "RA not active. Checking for data to transmit from upper layers...\n"); LOG_D(NR_MAC, "In %s: RA not active. Checking for data to transmit from upper layers...\n", __FUNCTION__);
uint8_t TBS_max = 8 + sizeof(NR_MAC_SUBHEADER_SHORT) + sizeof(NR_MAC_SUBHEADER_SHORT); const uint8_t lcid = UL_SCH_LCID_CCCH;
payload = (uint8_t*) mac->CCCH_pdu.payload; const uint8_t sh_size = sizeof(NR_MAC_SUBHEADER_FIXED);
const uint8_t TBS_max = 8 + sizeof(NR_MAC_SUBHEADER_SHORT) + sizeof(NR_MAC_SUBHEADER_SHORT); // Note: unclear the reason behind the selection of such TBS_max
int8_t size_sdu = 0;
uint8_t mac_ce[16] = {0};
uint8_t *pdu = get_softmodem_params()->sa ? mac->CCCH_pdu.payload : mac_ce;
uint8_t *payload = pdu;
num_sdus = 1; // Concerning the C-RNTI MAC CE, it has to be included if the UL transmission (Msg3) is not being made for the CCCH logical channel.
post_padding = 1; // Therefore it has been assumed that this event only occurs only when RA is done and it is not SA mode.
sdu_lcids[0] = lcid; if (get_softmodem_params()->sa) {
// initialisation by RRC NR_MAC_SUBHEADER_FIXED *header = (NR_MAC_SUBHEADER_FIXED *) pdu;
pdu += sh_size;
// TODO: To be removed after RA procedures fully implemented // initialisation by RRC
if(get_softmodem_params()->do_ra) {
nr_rrc_ue_generate_RRCSetupRequest(mod_id,gNB_id); nr_rrc_ue_generate_RRCSetupRequest(mod_id,gNB_id);
}
// CCCH PDU // CCCH PDU
size_sdu = (uint16_t) nr_mac_rrc_data_req_ue(mod_id, CC_id, gNB_id, frame, CCCH, mac_sdus); size_sdu = nr_mac_rrc_data_req_ue(mod_id, CC_id, gNB_id, frame, CCCH, pdu);
LOG_D(NR_MAC, "In %s: [UE %d][%d.%d]: Requested RRCConnectionRequest, got %d bytes for LCID 0x%02x \n", __FUNCTION__, mod_id, frame, nr_slot_tx, size_sdu, lcid);
if (size_sdu > 0) {
sdu_lengths[0] = size_sdu; // UE Contention Resolution Identity
// Store the first 48 bits belonging to the uplink CCCH SDU within Msg3 to determine whether or not the
// Random Access Procedure has been successful after reception of Msg4
memcpy(ra->cont_res_id, pdu, sizeof(uint8_t) * 6);
LOG_D(NR_MAC,"[UE %d] Frame %d: Requested RRCConnectionRequest, got %d bytes\n", mod_id, frame, size_sdu); pdu += size_sdu;
ra->Msg3_size = size_sdu + sh_size;
if (size_sdu > 0) { // Build header
header->R = 0;
header->LCID = lcid;
// UE Contention Resolution Identity } else {
// Store the first 48 bits belonging to the uplink CCCH SDU within Msg3 to determine whether or not the pdu -= sh_size;
// Random Access Procedure has been successful after reception of Msg4 }
memcpy(ra->cont_res_id, mac_sdus, sizeof(uint8_t) * 6);
} else {
size_sdu = nr_write_ce_ulsch_pdu(pdu, mac);
pdu += size_sdu;
ra->Msg3_size = size_sdu;
LOG_D(NR_MAC, "[UE %d][%d.%d]: starting initialisation Random Access Procedure...\n", mod_id, frame, nr_slot_tx); }
ra->Msg3_size = size_sdu + sizeof(NR_MAC_SUBHEADER_SHORT) + sizeof(NR_MAC_SUBHEADER_SHORT); if (size_sdu > 0 && ra->generate_nr_prach == GENERATE_PREAMBLE) {
LOG_D(NR_MAC, "In %s: [UE %d][%d.%d]: starting initialisation Random Access Procedure...\n", __FUNCTION__, mod_id, frame, nr_slot_tx);
AssertFatal(TBS_max > ra->Msg3_size, "In %s: allocated resources are not enough for Msg3!\n", __FUNCTION__);
// Init RA procedure
init_RA(mod_id, prach_resources, setup, rach_ConfigGeneric, rach_ConfigDedicated); init_RA(mod_id, prach_resources, setup, rach_ConfigGeneric, rach_ConfigDedicated);
prach_resources->Msg3 = payload;
nr_get_RA_window(mac); nr_get_RA_window(mac);
// Fill in preamble and PRACH resources // Fill in preamble and PRACH resources
if (ra->generate_nr_prach == GENERATE_PREAMBLE) { nr_get_prach_resources(mod_id, CC_id, gNB_id, prach_resources, prach_pdu, rach_ConfigDedicated);
nr_get_prach_resources(mod_id, CC_id, gNB_id, prach_resources, prach_pdu, rach_ConfigDedicated);
}
offset = nr_generate_ulsch_pdu((uint8_t *) mac_sdus, // sdus buffer
(uint8_t *) payload, // UL MAC pdu pointer
num_sdus, // num sdus
sdu_lengths, // sdu length
sdu_lcids, // sdu lcid
0, // power headroom
0, // crnti
0, // truncated bsr
0, // short bsr
0, // long_bsr
post_padding,
0);
AssertFatal(TBS_max > offset, "Frequency resources are not enough for Msg3!\n");
// Padding: fill remainder with 0 // Padding: fill remainder with 0
if (post_padding > 0){ if (TBS_max - ra->Msg3_size > 0) {
for (int j = 0; j < (TBS_max - offset); j++) LOG_D(NR_MAC, "In %s: remaining %d bytes, filling with padding\n", __FUNCTION__, TBS_max - ra->Msg3_size);
payload[offset + j] = 0; ((NR_MAC_SUBHEADER_FIXED *) pdu)->R = 0;
((NR_MAC_SUBHEADER_FIXED *) pdu)->LCID = UL_SCH_LCID_PADDING;
pdu += sizeof(NR_MAC_SUBHEADER_FIXED);
for (int j = 0; j < TBS_max - ra->Msg3_size - sizeof(NR_MAC_SUBHEADER_FIXED); j++) {
pdu[j] = 0;
}
} }
}
LOG_D(MAC,"size_sdu = %i\n", size_sdu); // Dumping ULSCH payload
LOG_D(MAC,"offset = %i\n", offset); LOG_D(NR_MAC, "In %s: dumping UL Msg3 MAC PDU with length %d: \n", __FUNCTION__, TBS_max);
for(int k = 0; k < TBS_max; k++) { for(int k = 0; k < TBS_max; k++) {
LOG_D(MAC,"(%i): %i\n", k, prach_resources->Msg3[k]); LOG_D(NR_MAC,"(%i): %i\n", k, payload[k]);
} }
// Msg3 was initialized with TBS_max bytes because the RA_Msg3_size will only be known after // Msg3 was initialized with TBS_max bytes because the RA_Msg3_size will only be known after
// receiving Msg2 (which contains the Msg3 resource reserve). // receiving Msg2 (which contains the Msg3 resource reserve).
// Msg3 will be transmitted with RA_Msg3_size bytes, removing unnecessary 0s. // Msg3 will be transmitted with RA_Msg3_size bytes, removing unnecessary 0s.
mac->ulsch_pdu.Pdu_size = TBS_max; mac->ulsch_pdu.Pdu_size = TBS_max;
memcpy(mac->ulsch_pdu.payload, prach_resources->Msg3, TBS_max); memcpy(mac->ulsch_pdu.payload, payload, TBS_max);
} else {
return 0;
}
} else if (ra->RA_window_cnt != -1) { // RACH is active } else if (ra->RA_window_cnt != -1) { // RACH is active
LOG_D(MAC, "In %s [%d.%d] RA is active: RA window count %d, RA backoff count %d\n", __FUNCTION__, frame, nr_slot_tx, ra->RA_window_cnt, ra->RA_backoff_cnt); LOG_D(MAC, "In %s [%d.%d] RA is active: RA window count %d, RA backoff count %d\n", __FUNCTION__, frame, nr_slot_tx, ra->RA_window_cnt, ra->RA_backoff_cnt);
...@@ -767,7 +770,6 @@ void nr_ra_succeeded(module_id_t mod_id, frame_t frame, int slot){ ...@@ -767,7 +770,6 @@ void nr_ra_succeeded(module_id_t mod_id, frame_t frame, int slot){
LOG_I(MAC, "[UE %d][%d.%d][RAPROC] RA procedure succeeded. CF-RA: RAR successfully received.\n", mod_id, frame, slot); LOG_I(MAC, "[UE %d][%d.%d][RAPROC] RA procedure succeeded. CF-RA: RAR successfully received.\n", mod_id, frame, slot);
ra->RA_window_cnt = -1; ra->RA_window_cnt = -1;
mac->crnti = ra->t_crnti;
} else { } else {
......
...@@ -2371,14 +2371,6 @@ void nr_ue_send_sdu(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t *u ...@@ -2371,14 +2371,6 @@ void nr_ue_send_sdu(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t *u
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SEND_SDU, VCD_FUNCTION_IN); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SEND_SDU, VCD_FUNCTION_IN);
#if defined(ENABLE_MAC_PAYLOAD_DEBUG)
LOG_T(MAC, "[UE %d] First 32 bytes of DLSCH : \n", module_idP);
for (i = 0; i < 32; i++) {
LOG_T(MAC, "%x.", sdu[i]);
}
LOG_T(MAC, "\n");
#endif
LOG_D(MAC, "In %s [%d.%d] Handling DLSCH PDU...\n", __FUNCTION__, dl_info->frame, dl_info->slot); LOG_D(MAC, "In %s [%d.%d] Handling DLSCH PDU...\n", __FUNCTION__, dl_info->frame, dl_info->slot);
// Processing MAC PDU // Processing MAC PDU
...@@ -3383,145 +3375,116 @@ void nr_ue_process_mac_pdu(nr_downlink_indication_t *dl_info, ...@@ -3383,145 +3375,116 @@ void nr_ue_process_mac_pdu(nr_downlink_indication_t *dl_info,
} }
} }
//////////////////////////////////////////////////////// /**
/////* ULSCH MAC PDU generation (6.1.2 TS 38.321) *///// * Function: generating MAC CEs (MAC CE and subheader) for the ULSCH PDU
//////////////////////////////////////////////////////// * Notes: TODO: PHR and BSR reporting
* Parameters:
* @mac_ce pointer to the MAC sub-PDUs including the MAC CEs
* @mac pointer to the MAC instance
* Return: number of written bytes
*/
int nr_write_ce_ulsch_pdu(uint8_t *mac_ce,
NR_UE_MAC_INST_t *mac) {
uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload, int mac_ce_len = 0;
uint8_t *pdu, uint8_t mac_ce_size = 0;
uint8_t num_sdus, NR_UE_MAC_CE_t *nr_ue_mac_ce = &mac->nr_ue_mac_ce;
uint16_t *sdu_lengths,
uint8_t *sdu_lcids,
uint8_t power_headroom,
uint16_t crnti,
uint16_t truncated_bsr,
uint16_t short_bsr,
uint16_t long_bsr,
unsigned short post_padding,
uint16_t buflen) {
NR_MAC_SUBHEADER_FIXED *mac_pdu_ptr = (NR_MAC_SUBHEADER_FIXED *) pdu; if (nr_ue_mac_ce->phr_reporting && mac->phr_Config != NULL) {
LOG_D(MAC, "[UE] Generating ULSCH PDU : num_sdus %d\n", num_sdus); // MAC CE fixed subheader
((NR_MAC_SUBHEADER_FIXED *) mac_ce)->R = 0;
((NR_MAC_SUBHEADER_FIXED *) mac_ce)->LCID = UL_SCH_LCID_SINGLE_ENTRY_PHR;
mac_ce++;
#ifdef DEBUG_HEADER_PARSING // PHR MAC CE (1 octet)
((NR_SINGLE_ENTRY_PHR_MAC_CE *) mac_ce)->PH = 0;
((NR_SINGLE_ENTRY_PHR_MAC_CE *) mac_ce)->R1 = 0;
((NR_SINGLE_ENTRY_PHR_MAC_CE *) mac_ce)->PCMAX = 0;
((NR_SINGLE_ENTRY_PHR_MAC_CE *) mac_ce)->R2 = 0;
for (int i = 0; i < num_sdus; i++) // update pointer and length
LOG_D(MAC, "[UE] MAC subPDU %d (lcid %d length %d bytes \n", i, sdu_lcids[i], sdu_lengths[i]); mac_ce_size = sizeof(NR_SINGLE_ENTRY_PHR_MAC_CE);
mac_ce += mac_ce_size;
mac_ce_len += mac_ce_size + sizeof(NR_MAC_SUBHEADER_FIXED);
#endif }
// Generating UL MAC subPDUs including MAC SDU and subheader if (!get_softmodem_params()->sa && get_softmodem_params()->do_ra && mac->ra.ra_state != RA_SUCCEEDED) {
for (int i = 0; i < num_sdus; i++) { LOG_D(NR_MAC, "In %s: generating C-RNTI MAC CE with C-RNTI %x\n", __FUNCTION__, mac->crnti);
LOG_D(MAC, "[UE] Generating UL MAC subPDUs for SDU with lenght %d ( num_sdus %d )\n", sdu_lengths[i], num_sdus);
if (sdu_lcids[i] != UL_SCH_LCID_CCCH){ // MAC CE fixed subheader
if (sdu_lengths[i] < 128) { ((NR_MAC_SUBHEADER_FIXED *) mac_ce)->R = 0;
((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->R = 0; ((NR_MAC_SUBHEADER_FIXED *) mac_ce)->LCID = UL_SCH_LCID_C_RNTI;
((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->F = 0; mac_ce++;
((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->LCID = sdu_lcids[i];
((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->L = (unsigned char) sdu_lengths[i];
mac_pdu_ptr += sizeof(NR_MAC_SUBHEADER_SHORT);
} else {
((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->R = 0;
((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->F = 1;
((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->LCID = sdu_lcids[i];
((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->L1 = ((unsigned short) sdu_lengths[i] >> 8) & 0x7f;
((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->L2 = (unsigned short) sdu_lengths[i] & 0xff;
mac_pdu_ptr += sizeof(NR_MAC_SUBHEADER_LONG);
}
} else { // UL CCCH SDU
mac_pdu_ptr->R = 0;
mac_pdu_ptr->LCID = sdu_lcids[i];
mac_pdu_ptr ++;
}
// cycle through SDUs, compute each relevant and place ulsch_buffer in
memcpy((void *) mac_pdu_ptr, (void *) sdus_payload, sdu_lengths[i]);
sdus_payload += sdu_lengths[i];
mac_pdu_ptr += sdu_lengths[i];
}
// Generating UL MAC subPDUs including MAC CEs (MAC CE and subheader) // C-RNTI MAC CE (2 octets)
*(uint16_t *) mac_ce = mac->crnti;
if (power_headroom) { // update pointer and length
// MAC CE fixed subheader mac_ce_size = sizeof(uint16_t);
mac_pdu_ptr->R = 0; mac_ce += mac_ce_size;
mac_pdu_ptr->LCID = UL_SCH_LCID_SINGLE_ENTRY_PHR; mac_ce_len += mac_ce_size + sizeof(NR_MAC_SUBHEADER_FIXED);
mac_pdu_ptr++;
// PHR MAC CE (1 octet)
((NR_SINGLE_ENTRY_PHR_MAC_CE *) mac_pdu_ptr)->PH = power_headroom;
((NR_SINGLE_ENTRY_PHR_MAC_CE *) mac_pdu_ptr)->R1 = 0;
((NR_SINGLE_ENTRY_PHR_MAC_CE *) mac_pdu_ptr)->PCMAX = 0; // todo
((NR_SINGLE_ENTRY_PHR_MAC_CE *) mac_pdu_ptr)->R2 = 0;
mac_pdu_ptr += sizeof(NR_SINGLE_ENTRY_PHR_MAC_CE);
} }
if (crnti) { if (nr_ue_mac_ce->truncated_bsr) {
// MAC CE fixed subheader
mac_pdu_ptr->R = 0;
mac_pdu_ptr->LCID = UL_SCH_LCID_C_RNTI;
mac_pdu_ptr++;
// C-RNTI MAC CE (2 octets) LOG_D(NR_MAC, "In %s: generating short truncated BSR MAC CE with command %x\n", __FUNCTION__, nr_ue_mac_ce->truncated_bsr);
* (uint16_t *) mac_pdu_ptr = crnti;
mac_pdu_ptr += sizeof(uint16_t);
}
if (truncated_bsr) {
// MAC CE fixed subheader // MAC CE fixed subheader
mac_pdu_ptr->R = 0; ((NR_MAC_SUBHEADER_FIXED *) mac_ce)->R = 0;
mac_pdu_ptr->LCID = UL_SCH_LCID_S_TRUNCATED_BSR; ((NR_MAC_SUBHEADER_FIXED *) mac_ce)->LCID = UL_SCH_LCID_S_TRUNCATED_BSR;
mac_pdu_ptr++; mac_ce++;
// Short truncated BSR MAC CE (1 octet) // Short truncated BSR MAC CE (1 octet)
((NR_BSR_SHORT_TRUNCATED *) mac_pdu_ptr)-> Buffer_size = truncated_bsr; ((NR_BSR_SHORT_TRUNCATED *) mac_ce)-> Buffer_size = 0;
((NR_BSR_SHORT_TRUNCATED *) mac_pdu_ptr)-> LcgID = 0; // todo ((NR_BSR_SHORT_TRUNCATED *) mac_ce)-> LcgID = 0;
mac_pdu_ptr+= sizeof(NR_BSR_SHORT_TRUNCATED);
} else if (short_bsr) { // update pointer and length
mac_ce_size = sizeof(NR_BSR_SHORT_TRUNCATED);
mac_ce += mac_ce_size;
mac_ce_len += mac_ce_size + sizeof(NR_MAC_SUBHEADER_FIXED);
} else if (nr_ue_mac_ce->short_bsr) {
LOG_D(NR_MAC, "In %s: generating short BSR MAC CE with command %x\n", __FUNCTION__, nr_ue_mac_ce->short_bsr);
// MAC CE fixed subheader // MAC CE fixed subheader
mac_pdu_ptr->R = 0; ((NR_MAC_SUBHEADER_FIXED *) mac_ce)->R = 0;
mac_pdu_ptr->LCID = UL_SCH_LCID_S_BSR; ((NR_MAC_SUBHEADER_FIXED *) mac_ce)->LCID = UL_SCH_LCID_S_BSR;
mac_pdu_ptr++; mac_ce++;
// Short truncated BSR MAC CE (1 octet) // Short truncated BSR MAC CE (1 octet)
((NR_BSR_SHORT *) mac_pdu_ptr)->Buffer_size = short_bsr; ((NR_BSR_SHORT *) mac_ce)->Buffer_size = nr_ue_mac_ce->short_bsr;
((NR_BSR_SHORT *) mac_pdu_ptr)->LcgID = 0; // todo ((NR_BSR_SHORT *) mac_ce)->LcgID = 0;
mac_pdu_ptr+= sizeof(NR_BSR_SHORT);
} else if (long_bsr) { // update pointer and length
mac_ce_size = sizeof(NR_BSR_SHORT);
mac_ce += mac_ce_size;
mac_ce_len += mac_ce_size + sizeof(NR_MAC_SUBHEADER_FIXED);
} else if (nr_ue_mac_ce->long_bsr) {
// MAC CE variable subheader // MAC CE variable subheader
// todo ch 6.1.3.1. TS 38.321 // todo ch 6.1.3.1. TS 38.321
// ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->R = 0; // ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->R = 0;
// ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->F = 0; // ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->F = 0;
// ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->LCID = UL_SCH_LCID_L_BSR; // ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->LCID = UL_SCH_LCID_L_BSR;
// ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->L = 0; // ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->L = 0;
// last_size = 2; // sh_size = 2;
// mac_pdu_ptr += last_size;
// Short truncated BSR MAC CE (1 octet) // Short truncated BSR MAC CE (1 octet)
// ((NR_BSR_LONG *) ce_ptr)->Buffer_size0 = short_bsr; // ((NR_BSR_LONG *) mac_ce)->Buffer_size0 = short_bsr;
// ((NR_BSR_LONG *) ce_ptr)->LCGID0 = 0; // ((NR_BSR_LONG *) mac_ce)->LCGID0 = 0;
// mac_ce_size = sizeof(NR_BSR_LONG); // size is variable // mac_ce_size = sizeof(NR_BSR_LONG); // size is variable
} }
// compute offset before adding padding (if necessary)
int padding_bytes = 0;
if(buflen > 0) // If the buflen is provided
padding_bytes = buflen + pdu - (unsigned char *) mac_pdu_ptr;
AssertFatal(padding_bytes>=0,""); return mac_ce_len;
// Compute final offset for padding
if (post_padding || padding_bytes>0) {
((NR_MAC_SUBHEADER_FIXED *) mac_pdu_ptr)->R = 0;
((NR_MAC_SUBHEADER_FIXED *) mac_pdu_ptr)->LCID = UL_SCH_LCID_PADDING;
mac_pdu_ptr++;
}
return (uint8_t *)mac_pdu_ptr-pdu;
} }
///////////////////////////////////// /////////////////////////////////////
// Random Access Response PDU // // Random Access Response PDU //
// TS 38.213 ch 8.2 // // TS 38.213 ch 8.2 //
...@@ -3570,7 +3533,6 @@ int nr_ue_process_rar(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t ...@@ -3570,7 +3533,6 @@ int nr_ue_process_rar(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t
uint8_t is_Msg3 = 1; uint8_t is_Msg3 = 1;
frame_t frame_tx = 0; frame_t frame_tx = 0;
int slot_tx = 0; int slot_tx = 0;
uint16_t rnti = 0;
int ret = 0; int ret = 0;
NR_RA_HEADER_RAPID *rarh = (NR_RA_HEADER_RAPID *) dlsch_buffer; // RAR subheader pointer NR_RA_HEADER_RAPID *rarh = (NR_RA_HEADER_RAPID *) dlsch_buffer; // RAR subheader pointer
NR_MAC_RAR *rar = (NR_MAC_RAR *) (dlsch_buffer + 1); // RAR subPDU pointer NR_MAC_RAR *rar = (NR_MAC_RAR *) (dlsch_buffer + 1); // RAR subPDU pointer
...@@ -3622,9 +3584,6 @@ int nr_ue_process_rar(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t ...@@ -3622,9 +3584,6 @@ int nr_ue_process_rar(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t
unsigned char csi_req; unsigned char csi_req;
#endif #endif
// TC-RNTI
ra->t_crnti = rar->TCRNTI_2 + (rar->TCRNTI_1 << 8);
// TA command // TA command
ul_time_alignment->apply_ta = 1; ul_time_alignment->apply_ta = 1;
ul_time_alignment->ta_command = 31 + rar->TA2 + (rar->TA1 << 5); ul_time_alignment->ta_command = 31 + rar->TA2 + (rar->TA1 << 5);
...@@ -3670,12 +3629,6 @@ int nr_ue_process_rar(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t ...@@ -3670,12 +3629,6 @@ int nr_ue_process_rar(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t
rar_grant.Msg3_f_alloc = (uint16_t) ((rar->UL_GRANT_3 >> 4) | (rar->UL_GRANT_2 << 4) | ((rar->UL_GRANT_1 & 0x03) << 12)); rar_grant.Msg3_f_alloc = (uint16_t) ((rar->UL_GRANT_3 >> 4) | (rar->UL_GRANT_2 << 4) | ((rar->UL_GRANT_1 & 0x03) << 12));
// frequency hopping // frequency hopping
rar_grant.freq_hopping = (unsigned char) (rar->UL_GRANT_1 >> 2); rar_grant.freq_hopping = (unsigned char) (rar->UL_GRANT_1 >> 2);
// TC-RNTI
if (ra->t_crnti) {
rnti = ra->t_crnti;
} else {
rnti = mac->crnti;
}
#ifdef DEBUG_RAR #ifdef DEBUG_RAR
LOG_I(NR_MAC, "rarh->E = 0x%x\n", rarh->E); LOG_I(NR_MAC, "rarh->E = 0x%x\n", rarh->E);
...@@ -3715,12 +3668,19 @@ int nr_ue_process_rar(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t ...@@ -3715,12 +3668,19 @@ int nr_ue_process_rar(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t
if (ret != -1){ if (ret != -1){
fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, slot_tx); fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, slot_tx);
uint16_t rnti = mac->crnti;
if (!ul_config) { if (!ul_config) {
LOG_W(MAC, "In %s: ul_config request is NULL. Probably due to unexpected UL DCI in frame.slot %d.%d. Ignoring DCI!\n", __FUNCTION__, frame, slot); LOG_W(MAC, "In %s: ul_config request is NULL. Probably due to unexpected UL DCI in frame.slot %d.%d. Ignoring DCI!\n", __FUNCTION__, frame, slot);
return -1; return -1;
} }
// Upon successful reception, set the T-CRNTI to the RAR value if the RA preamble is selected among the contention-based RA Preambles
if (!ra->cfra) {
ra->t_crnti = rar->TCRNTI_2 + (rar->TCRNTI_1 << 8);
rnti = ra->t_crnti;
}
nfapi_nr_ue_pusch_pdu_t *pusch_config_pdu = &ul_config->ul_config_list[ul_config->number_pdus].pusch_config_pdu; nfapi_nr_ue_pusch_pdu_t *pusch_config_pdu = &ul_config->ul_config_list[ul_config->number_pdus].pusch_config_pdu;
fill_ul_config(ul_config, frame_tx, slot_tx, FAPI_NR_UL_CONFIG_TYPE_PUSCH); fill_ul_config(ul_config, frame_tx, slot_tx, FAPI_NR_UL_CONFIG_TYPE_PUSCH);
......
...@@ -992,7 +992,7 @@ NR_UE_L2_STATE_t nr_ue_scheduler(nr_downlink_indication_t *dl_info, nr_uplink_in ...@@ -992,7 +992,7 @@ NR_UE_L2_STATE_t nr_ue_scheduler(nr_downlink_indication_t *dl_info, nr_uplink_in
frame_t frame_tx = ul_info->frame_tx; frame_t frame_tx = ul_info->frame_tx;
slot_t slot_tx = ul_info->slot_tx; slot_t slot_tx = ul_info->slot_tx;
module_id_t mod_id = ul_info->module_id; module_id_t mod_id = ul_info->module_id;
uint8_t access_mode = SCHEDULED_ACCESS; uint32_t gNB_index = ul_info->gNB_index;
NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id);
RA_config_t *ra = &mac->ra; RA_config_t *ra = &mac->ra;
...@@ -1006,7 +1006,6 @@ NR_UE_L2_STATE_t nr_ue_scheduler(nr_downlink_indication_t *dl_info, nr_uplink_in ...@@ -1006,7 +1006,6 @@ NR_UE_L2_STATE_t nr_ue_scheduler(nr_downlink_indication_t *dl_info, nr_uplink_in
LOG_D(NR_MAC, "In %s:[%d.%d]: number of UL PDUs: %d with UL transmission in [%d.%d]\n", __FUNCTION__, frame_tx, slot_tx, ul_config->number_pdus, ul_config->sfn, ul_config->slot); LOG_D(NR_MAC, "In %s:[%d.%d]: number of UL PDUs: %d with UL transmission in [%d.%d]\n", __FUNCTION__, frame_tx, slot_tx, ul_config->number_pdus, ul_config->sfn, ul_config->slot);
uint8_t ulsch_input_buffer[MAX_ULSCH_PAYLOAD_BYTES]; uint8_t ulsch_input_buffer[MAX_ULSCH_PAYLOAD_BYTES];
uint8_t data_existing = 0;
nr_scheduled_response_t scheduled_response; nr_scheduled_response_t scheduled_response;
fapi_nr_tx_request_t tx_req; fapi_nr_tx_request_t tx_req;
...@@ -1038,45 +1037,14 @@ NR_UE_L2_STATE_t nr_ue_scheduler(nr_downlink_indication_t *dl_info, nr_uplink_in ...@@ -1038,45 +1037,14 @@ NR_UE_L2_STATE_t nr_ue_scheduler(nr_downlink_indication_t *dl_info, nr_uplink_in
mac->first_ul_tx[ulcfg_pdu->pusch_config_pdu.pusch_data.harq_process_id]==1)){ mac->first_ul_tx[ulcfg_pdu->pusch_config_pdu.pusch_data.harq_process_id]==1)){
// Getting IP traffic to be transmitted // Getting IP traffic to be transmitted
data_existing = nr_ue_get_sdu(mod_id, nr_ue_get_sdu(mod_id, frame_tx, slot_tx, gNB_index, ulsch_input_buffer, TBS_bytes);
cc_id,
frame_tx,
slot_tx,
0,
ulsch_input_buffer,
TBS_bytes,
&access_mode);
} }
LOG_D(NR_MAC,"Flipping NDI for harq_id %d\n",ulcfg_pdu->pusch_config_pdu.pusch_data.new_data_indicator); LOG_D(NR_MAC,"Flipping NDI for harq_id %d\n",ulcfg_pdu->pusch_config_pdu.pusch_data.new_data_indicator);
mac->UL_ndi[ulcfg_pdu->pusch_config_pdu.pusch_data.harq_process_id] = ulcfg_pdu->pusch_config_pdu.pusch_data.new_data_indicator; mac->UL_ndi[ulcfg_pdu->pusch_config_pdu.pusch_data.harq_process_id] = ulcfg_pdu->pusch_config_pdu.pusch_data.new_data_indicator;
mac->first_ul_tx[ulcfg_pdu->pusch_config_pdu.pusch_data.harq_process_id] = 0; mac->first_ul_tx[ulcfg_pdu->pusch_config_pdu.pusch_data.harq_process_id] = 0;
//Random traffic to be transmitted if there is no IP traffic available for this Tx opportunity
if (!data_existing) {
//Use zeros for the header bytes in noS1 mode, in order to make sure that the LCID is not valid
//and block this traffic from being forwarded to the upper layers at the gNB
LOG_D(PHY, "In %s: Random data to be transmitted: TBS_bytes %d \n", __FUNCTION__, TBS_bytes);
//Give the first byte a dummy value (a value not corresponding to any valid LCID based on 38.321, Table 6.2.1-2)
//in order to distinguish the PHY random packets at the MAC layer of the gNB receiver from the normal packets that should
//have a valid LCID (nr_process_mac_pdu function)
ulsch_input_buffer[0] = UL_SCH_LCID_PADDING;
for (int i = 1; i < TBS_bytes; i++) {
ulsch_input_buffer[i] = (unsigned char) rand();
}
}
}
#ifdef DEBUG_MAC_PDU
LOG_D(PHY, "Is data existing ?: %d \n", data_existing);
LOG_I(PHY, "Printing MAC PDU to be encoded, TBS is: %d \n", TBS_bytes);
for (i = 0; i < TBS_bytes; i++) {
printf("%02x", ulsch_input_buffer[i]);
} }
printf("\n");
#endif
// Config UL TX PDU // Config UL TX PDU
tx_req.slot = slot_tx; tx_req.slot = slot_tx;
...@@ -2058,90 +2026,174 @@ void nr_ue_prach_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t s ...@@ -2058,90 +2026,174 @@ void nr_ue_prach_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t s
} // if is_nr_UL_slot } // if is_nr_UL_slot
} }
#define MAX_LCID 8 //Fixme: also defined in LCID table #define MAX_LCID 8 // NR_MAX_NUM_LCID shall be used but the mac_rlc_data_req function can fetch data for max 8 LCID
uint8_t
nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, /**
sub_frame_t subframe, uint8_t eNB_index, * Function: to fetch data to be transmitted from RLC, place it in the ULSCH PDU buffer
uint8_t *ulsch_buffer, uint16_t buflen, uint8_t *access_mode) { to generate the complete MAC PDU with sub-headers and MAC CEs according to ULSCH MAC PDU generation (6.1.2 TS 38.321)
the selected sub-header for the payload sub-PDUs is NR_MAC_SUBHEADER_LONG
* @module_idP Module ID
* @frameP current UL frame
* @subframe current UL slot
* @gNB_index gNB index
* @ulsch_buffer Pointer to ULSCH PDU
* @buflen TBS
*/
uint8_t nr_ue_get_sdu(module_id_t module_idP,
frame_t frameP,
sub_frame_t subframe,
uint8_t gNB_index,
uint8_t *ulsch_buffer,
uint16_t buflen) {
int16_t buflen_remain = 0;
uint8_t lcid = 0; uint8_t lcid = 0;
uint16_t sdu_lengths[MAX_LCID] = { 0 }; uint16_t sdu_length = 0;
uint8_t sdu_lcids[MAX_LCID] = { 0 }; uint16_t num_sdus = 0;
uint16_t payload_offset = 0, num_sdus = 0; uint16_t sdu_length_total = 0;
uint8_t ulsch_sdus[MAX_ULSCH_PAYLOAD_BYTES];
//unsigned short post_padding = 0;
NR_UE_MAC_INST_t *mac = get_mac_inst(module_idP); NR_UE_MAC_INST_t *mac = get_mac_inst(module_idP);
const uint8_t sh_size = sizeof(NR_MAC_SUBHEADER_LONG);
// Pointer used to build the MAC PDU by placing the RLC SDUs in the ULSCH buffer
uint8_t *pdu = ulsch_buffer;
// Preparing the MAC CEs sub-PDUs and get the total size
unsigned char mac_header_control_elements[16] = {0};
int tot_mac_ce_len = nr_write_ce_ulsch_pdu(&mac_header_control_elements[0], mac);
uint8_t total_mac_pdu_header_len = tot_mac_ce_len;
LOG_D(NR_MAC, "In %s: [UE %d] [%d.%d] process UL transport block at with size TBS = %d bytes \n", __FUNCTION__, module_idP, frameP, subframe, buflen);
LOG_D(NR_MAC,
"[UE %d] MAC PROCESS UL TRANSPORT BLOCK at frame%d subframe %d TBS=%d\n",
module_idP, frameP, subframe, buflen);
AssertFatal(CC_id == 0,
"Transmission on secondary CCs is not supported yet\n");
// Check for DCCH first // Check for DCCH first
// TO DO: Multiplex in the order defined by the logical channel prioritization // TO DO: Multiplex in the order defined by the logical channel prioritization
int buflen_remain = buflen;
char * current_ulsch_ptr = (char*)ulsch_sdus;
for (lcid = UL_SCH_LCID_SRB1; for (lcid = UL_SCH_LCID_SRB1;
lcid < MAX_LCID; lcid++) { lcid < MAX_LCID; lcid++) {
while ( (sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP,
mac->crnti, buflen_remain = buflen - (total_mac_pdu_header_len + sdu_length_total + sh_size);
eNB_index,
frameP, LOG_D(NR_MAC, "In %s: [UE %d] [%d.%d] UL-DXCH -> ULSCH, RLC with LCID 0x%02x (TBS %d bytes, sdu_length_total %d bytes, MAC header len %d bytes, buflen_remain %d bytes)\n",
ENB_FLAG_NO, __FUNCTION__,
MBMS_FLAG_NO, module_idP,
lcid, frameP,
buflen_remain-MAX_RLC_SDU_SUBHEADER_SIZE*2, subframe,
//Fixme: Laurent I removed MAX_RLC_SDU_SUBHEADER_SIZE*2 because else we get out the buffer silently lcid,
// the interface with nr_generate_ulsch_pdu() looks over complex and not CPU optimized buflen,
current_ulsch_ptr , 0, sdu_length_total,
0)) > 0 ) { tot_mac_ce_len,
buflen_remain);
AssertFatal(buflen_remain >= sdu_lengths[num_sdus],
"LCID=%d RLC has segmented %d bytes but MAC has max=%d\n", while (buflen_remain > 0){
lcid, sdu_lengths[num_sdus], buflen_remain);
AssertFatal(current_ulsch_ptr < (char*)ulsch_sdus+MAX_ULSCH_PAYLOAD_BYTES, ""); // Pointer used to build the MAC sub-PDU headers in the ULSCH buffer for each SDU
NR_MAC_SUBHEADER_LONG *header = (NR_MAC_SUBHEADER_LONG *) pdu;
current_ulsch_ptr += sdu_lengths[num_sdus];
buflen_remain -= sdu_lengths[num_sdus]; pdu += sh_size;
buflen_remain -= MAX_RLC_SDU_SUBHEADER_SIZE;
sdu_lcids[num_sdus] = lcid; sdu_length = mac_rlc_data_req(module_idP,
num_sdus++; mac->crnti,
gNB_index,
frameP,
ENB_FLAG_NO,
MBMS_FLAG_NO,
lcid,
buflen_remain,
(char *)pdu,
0,
0);
AssertFatal(buflen_remain >= sdu_length, "In %s: LCID = 0x%02x RLC has segmented %d bytes but MAC has max %d remaining bytes\n",
__FUNCTION__,
lcid,
sdu_length,
buflen_remain);
if (sdu_length > 0) {
LOG_D(MAC, "In %s: Generating UL MAC sub-PDU for SDU %d, length %d bytes, RB with LCID 0x%02x (buflen (TBS) %d bytes)\n", __FUNCTION__,
num_sdus + 1,
sdu_length,
lcid,
buflen);
header->R = 0;
header->F = 1;
header->LCID = lcid;
header->L1 = ((unsigned short) sdu_length >> 8) & 0x7f;
header->L2 = (unsigned short) sdu_length & 0xff;
#ifdef ENABLE_MAC_PAYLOAD_DEBUG
LOG_I(NR_MAC, "In %s: dumping MAC sub-header with length %d: \n", __FUNCTION__, sh_size);
log_dump(NR_MAC, header, sh_size, LOG_DUMP_CHAR, "\n");
LOG_I(NR_MAC, "In %s: dumping MAC SDU with length %d \n", __FUNCTION__, sdu_length);
log_dump(NR_MAC, pdu, sdu_length, LOG_DUMP_CHAR, "\n");
#endif
pdu += sdu_length;
sdu_length_total += sdu_length;
total_mac_pdu_header_len += sh_size;
num_sdus++;
} else {
pdu -= sh_size;
LOG_D(MAC, "In %s: no data to transmit for RB with LCID 0x%02x\n", __FUNCTION__, lcid);
break;
}
buflen_remain = buflen - (total_mac_pdu_header_len + sdu_length_total + sh_size);
} }
} }
// Generate ULSCH PDU
if (num_sdus>0) {
payload_offset = nr_generate_ulsch_pdu(ulsch_sdus,
ulsch_buffer, // mac header
num_sdus, // num sdus
sdu_lengths, // sdu length
sdu_lcids, // sdu lcid
0, // power_headroom
mac->crnti, // crnti
0, // truncated_bsr
0, // short_bsr
0, // long_bsr
0, // post_padding
buflen); // TBS in bytes
} else {
return 0;
}
// Padding: fill remainder of ULSCH with 0 if (tot_mac_ce_len > 0) {
if (buflen - payload_offset > 0){
for (int j = payload_offset; j < buflen; j++) LOG_D(NR_MAC, "In %s copying %d bytes of MAC CEs to the UL PDU \n", __FUNCTION__, tot_mac_ce_len);
ulsch_buffer[j] = 0; memcpy((void *) pdu, (void *) mac_header_control_elements, tot_mac_ce_len);
pdu += (unsigned char) tot_mac_ce_len;
#ifdef ENABLE_MAC_PAYLOAD_DEBUG
LOG_I(NR_MAC, "In %s: dumping MAC CE with length tot_mac_ce_len %d: \n", __FUNCTION__, tot_mac_ce_len);
log_dump(NR_MAC, mac_header_control_elements, tot_mac_ce_len, LOG_DUMP_CHAR, "\n");
#endif
} }
#if defined(ENABLE_MAC_PAYLOAD_DEBUG) buflen_remain = buflen - (total_mac_pdu_header_len + sdu_length_total);
LOG_I(NR_MAC, "Printing UL MAC payload UE side, payload_offset: %d \n", payload_offset);
for (int i = 0; i < buflen ; i++) { // Compute final offset for padding and fill remainder of ULSCH with 0
//harq_process_ul_ue->a[i] = (unsigned char) rand(); if (buflen_remain > 0) {
//printf("a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]);
printf("%02x ",(unsigned char)ulsch_buffer[i]); ((NR_MAC_SUBHEADER_FIXED *) pdu)->R = 0;
((NR_MAC_SUBHEADER_FIXED *) pdu)->LCID = UL_SCH_LCID_PADDING;
#ifdef ENABLE_MAC_PAYLOAD_DEBUG
LOG_I(NR_MAC, "In %s: padding MAC sub-header with length %ld bytes \n", __FUNCTION__, sizeof(NR_MAC_SUBHEADER_FIXED));
log_dump(NR_MAC, pdu, sizeof(NR_MAC_SUBHEADER_FIXED), LOG_DUMP_CHAR, "\n");
#endif
pdu++;
buflen_remain--;
if (IS_SOFTMODEM_RFSIM) {
for (int j = 0; j < buflen_remain; j++) {
pdu[j] = (unsigned char) rand();
}
} else {
memset(pdu, 0, buflen_remain);
}
#ifdef ENABLE_MAC_PAYLOAD_DEBUG
LOG_I(NR_MAC, "In %s: MAC padding sub-PDU with length %d bytes \n", __FUNCTION__, buflen_remain);
log_dump(NR_MAC, pdu, buflen_remain, LOG_DUMP_CHAR, "\n");
#endif
} }
printf("\n");
#endif
return 1; #ifdef ENABLE_MAC_PAYLOAD_DEBUG
LOG_I(NR_MAC, "In %s: dumping MAC PDU with length %d: \n", __FUNCTION__, buflen);
log_dump(NR_MAC, ulsch_buffer, buflen, LOG_DUMP_CHAR, "\n");
#endif
return num_sdus > 0 ? 1 : 0;
} }
...@@ -174,60 +174,63 @@ void calculate_preferred_ul_tda(module_id_t module_id, const NR_BWP_Uplink_t *ub ...@@ -174,60 +174,63 @@ void calculate_preferred_ul_tda(module_id_t module_id, const NR_BWP_Uplink_t *ub
tdd->nrofUplinkSlots); tdd->nrofUplinkSlots);
} }
// For both UL-SCH except:
// - UL-SCH: fixed-size MAC CE(known by LCID)
// - UL-SCH: padding
// - UL-SCH: MSG3 48-bits
// |0|1|2|3|4|5|6|7| bit-wise
// |R|F| LCID |
// | L |
// |0|1|2|3|4|5|6|7| bit-wise
// |R|F| LCID |
// | L |
// | L |
//
// For:
// - UL-SCH: fixed-size MAC CE(known by LCID)
// - UL-SCH: padding, for single/multiple 1-oct padding CE(s)
// - UL-SCH: MSG3 48-bits
// |0|1|2|3|4|5|6|7| bit-wise
// |R|R| LCID |
//
// LCID: The Logical Channel ID field identifies the logical channel instance of the corresponding MAC SDU or the type of the corresponding MAC CE or padding as described in Tables 6.2.1-1 and 6.2.1-2 for the DL-SCH and UL-SCH respectively. There is one LCID field per MAC subheader. The LCID field size is 6 bits;
// L: The Length field indicates the length of the corresponding MAC SDU or variable-sized MAC CE in bytes. There is one L field per MAC subheader except for subheaders corresponding to fixed-sized MAC CEs and padding. The size of the L field is indicated by the F field;
// F: length of L is 0:8 or 1:16 bits wide
// R: Reserved bit, set to zero.
void nr_process_mac_pdu(module_id_t module_idP, void nr_process_mac_pdu(module_id_t module_idP,
int UE_id, int UE_id,
uint8_t CC_id, uint8_t CC_id,
frame_t frameP, frame_t frameP,
sub_frame_t slot, sub_frame_t slot,
uint8_t *pduP, uint8_t *pduP,
uint16_t mac_pdu_len) int pdu_len)
{ {
// This function is adapting code from the old uint8_t rx_lcid;
// parse_header(...) and ue_send_sdu(...) functions of OAI LTE uint8_t done = 0;
uint16_t mac_ce_len;
uint8_t *pdu_ptr = pduP, rx_lcid, done = 0; uint16_t mac_subheader_len;
int pdu_len = mac_pdu_len; uint16_t mac_sdu_len;
uint16_t mac_ce_len, mac_subheader_len, mac_sdu_len;
NR_UE_info_t *UE_info = &RC.nrmac[module_idP]->UE_info; NR_UE_info_t *UE_info = &RC.nrmac[module_idP]->UE_info;
NR_UE_sched_ctrl_t *sched_ctrl = &UE_info->UE_sched_ctrl[UE_id]; NR_UE_sched_ctrl_t *sched_ctrl = &UE_info->UE_sched_ctrl[UE_id];
if ( pduP[0] != UL_SCH_LCID_PADDING ) if ( pduP[0] != UL_SCH_LCID_PADDING )
trace_NRpdu(DIRECTION_UPLINK, pduP, mac_pdu_len ,UE_id, WS_C_RNTI, UE_info->rnti[UE_id], frameP, 0, 0, 0); trace_NRpdu(DIRECTION_UPLINK, pduP, pdu_len, UE_id, WS_C_RNTI, UE_info->rnti[UE_id], frameP, 0, 0, 0);
// For both DL/UL-SCH #ifdef ENABLE_MAC_PAYLOAD_DEBUG
// Except: LOG_I(NR_MAC, "In %s: dumping MAC PDU in %d.%d:\n", __func__, frameP, slot);
// - UL/DL-SCH: fixed-size MAC CE(known by LCID) log_dump(NR_MAC, pduP, pdu_len, LOG_DUMP_CHAR, "\n");
// - UL/DL-SCH: padding #endif
// - UL-SCH: MSG3 48-bits
// |0|1|2|3|4|5|6|7| bit-wise
// |R|F| LCID |
// | L |
// |0|1|2|3|4|5|6|7| bit-wise
// |R|F| LCID |
// | L |
// | L |
// For both DL/UL-SCH
// For:
// - UL/DL-SCH: fixed-size MAC CE(known by LCID)
// - UL/DL-SCH: padding, for single/multiple 1-oct padding CE(s)
// - UL-SCH: MSG3 48-bits
// |0|1|2|3|4|5|6|7| bit-wise
// |R|R| LCID |
// LCID: The Logical Channel ID field identifies the logical channel instance of the corresponding MAC SDU or the type of the corresponding MAC CE or padding as described in Tables 6.2.1-1 and 6.2.1-2 for the DL-SCH and UL-SCH respectively. There is one LCID field per MAC subheader. The LCID field size is 6 bits;
// L: The Length field indicates the length of the corresponding MAC SDU or variable-sized MAC CE in bytes. There is one L field per MAC subheader except for subheaders corresponding to fixed-sized MAC CEs and padding. The size of the L field is indicated by the F field;
// F: lenght of L is 0:8 or 1:16 bits wide
// R: Reserved bit, set to zero.
while (!done && pdu_len > 0){ while (!done && pdu_len > 0){
mac_ce_len = 0; mac_ce_len = 0;
mac_subheader_len = 1; // default to fixed-length subheader = 1-oct mac_subheader_len = sizeof(NR_MAC_SUBHEADER_FIXED);
mac_sdu_len = 0; mac_sdu_len = 0;
rx_lcid = ((NR_MAC_SUBHEADER_FIXED *)pdu_ptr)->LCID; rx_lcid = ((NR_MAC_SUBHEADER_FIXED *)pduP)->LCID;
LOG_D(NR_MAC, "LCID received at gNB side: %d \n", rx_lcid); LOG_D(NR_MAC, "In %s: received UL-SCH sub-PDU with LCID 0x%x in %d.%d (remaining PDU length %d)\n", __func__, rx_lcid, frameP, slot, pdu_len);
unsigned char *ce_ptr; unsigned char *ce_ptr;
int n_Lcg = 0; int n_Lcg = 0;
...@@ -236,7 +239,7 @@ void nr_process_mac_pdu(module_id_t module_idP, ...@@ -236,7 +239,7 @@ void nr_process_mac_pdu(module_id_t module_idP,
// MAC CE // MAC CE
/*#ifdef DEBUG_HEADER_PARSING /*#ifdef DEBUG_HEADER_PARSING
LOG_D(NR_MAC, "[UE] LCID %d, PDU length %d\n", ((NR_MAC_SUBHEADER_FIXED *)pdu_ptr)->LCID, pdu_len); LOG_D(NR_MAC, "[UE] LCID %d, PDU length %d\n", ((NR_MAC_SUBHEADER_FIXED *)pduP)->LCID, pdu_len);
#endif*/ #endif*/
case UL_SCH_LCID_RECOMMENDED_BITRATE_QUERY: case UL_SCH_LCID_RECOMMENDED_BITRATE_QUERY:
// 38.321 Ch6.1.3.20 // 38.321 Ch6.1.3.20
...@@ -252,7 +255,7 @@ void nr_process_mac_pdu(module_id_t module_idP, ...@@ -252,7 +255,7 @@ void nr_process_mac_pdu(module_id_t module_idP,
//fixed length //fixed length
mac_ce_len =1; mac_ce_len =1;
/* Extract short BSR value */ /* Extract short BSR value */
ce_ptr = &pdu_ptr[mac_subheader_len]; ce_ptr = &pduP[mac_subheader_len];
NR_BSR_SHORT *bsr_s = (NR_BSR_SHORT *) ce_ptr; NR_BSR_SHORT *bsr_s = (NR_BSR_SHORT *) ce_ptr;
sched_ctrl->estimated_ul_buffer = 0; sched_ctrl->estimated_ul_buffer = 0;
sched_ctrl->estimated_ul_buffer = NR_SHORT_BSR_TABLE[bsr_s->Buffer_size]; sched_ctrl->estimated_ul_buffer = NR_SHORT_BSR_TABLE[bsr_s->Buffer_size];
...@@ -270,14 +273,14 @@ void nr_process_mac_pdu(module_id_t module_idP, ...@@ -270,14 +273,14 @@ void nr_process_mac_pdu(module_id_t module_idP,
case UL_SCH_LCID_L_TRUNCATED_BSR: case UL_SCH_LCID_L_TRUNCATED_BSR:
//38.321 section 6.1.3.1 //38.321 section 6.1.3.1
//variable length //variable length
mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pduP)->L;
mac_subheader_len = 2; mac_subheader_len = 2;
if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ if(((NR_MAC_SUBHEADER_SHORT *)pduP)->F){
mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pduP)->L2)<<8;
mac_subheader_len = 3; mac_subheader_len = 3;
} }
/* Extract long BSR value */ /* Extract long BSR value */
ce_ptr = &pdu_ptr[mac_subheader_len]; ce_ptr = &pduP[mac_subheader_len];
NR_BSR_LONG *bsr_l = (NR_BSR_LONG *) ce_ptr; NR_BSR_LONG *bsr_l = (NR_BSR_LONG *) ce_ptr;
sched_ctrl->estimated_ul_buffer = 0; sched_ctrl->estimated_ul_buffer = 0;
...@@ -290,18 +293,18 @@ void nr_process_mac_pdu(module_id_t module_idP, ...@@ -290,18 +293,18 @@ void nr_process_mac_pdu(module_id_t module_idP,
for (int n = 0; n < n_Lcg; n++){ for (int n = 0; n < n_Lcg; n++){
LOG_D(NR_MAC, "LONG BSR, %d/%d (n/n_Lcg), BS Index %d, BS value < %d", LOG_D(NR_MAC, "LONG BSR, %d/%d (n/n_Lcg), BS Index %d, BS value < %d",
n, n_Lcg, pdu_ptr[mac_subheader_len + 1 + n], n, n_Lcg, pduP[mac_subheader_len + 1 + n],
NR_LONG_BSR_TABLE[pdu_ptr[mac_subheader_len + 1 + n]]); NR_LONG_BSR_TABLE[pduP[mac_subheader_len + 1 + n]]);
sched_ctrl->estimated_ul_buffer += sched_ctrl->estimated_ul_buffer +=
NR_LONG_BSR_TABLE[pdu_ptr[mac_subheader_len + 1 + n]]; NR_LONG_BSR_TABLE[pduP[mac_subheader_len + 1 + n]];
LOG_D(NR_MAC, LOG_D(NR_MAC,
"LONG BSR at %4d.%2d, %d/%d (n/n_Lcg), BS Index %d, BS value < %d, total %d\n", "LONG BSR at %4d.%2d, %d/%d (n/n_Lcg), BS Index %d, BS value < %d, total %d\n",
frameP, frameP,
slot, slot,
n, n,
n_Lcg, n_Lcg,
pdu_ptr[mac_subheader_len + 1 + n], pduP[mac_subheader_len + 1 + n],
NR_LONG_BSR_TABLE[pdu_ptr[mac_subheader_len + 1 + n]], NR_LONG_BSR_TABLE[pduP[mac_subheader_len + 1 + n]],
sched_ctrl->estimated_ul_buffer); sched_ctrl->estimated_ul_buffer);
} }
...@@ -319,7 +322,7 @@ void nr_process_mac_pdu(module_id_t module_idP, ...@@ -319,7 +322,7 @@ void nr_process_mac_pdu(module_id_t module_idP,
//fixed length //fixed length
mac_ce_len = 2; mac_ce_len = 2;
/* Extract SINGLE ENTRY PHR elements for PHR calculation */ /* Extract SINGLE ENTRY PHR elements for PHR calculation */
ce_ptr = &pdu_ptr[mac_subheader_len]; ce_ptr = &pduP[mac_subheader_len];
NR_SINGLE_ENTRY_PHR_MAC_CE *phr = (NR_SINGLE_ENTRY_PHR_MAC_CE *) ce_ptr; NR_SINGLE_ENTRY_PHR_MAC_CE *phr = (NR_SINGLE_ENTRY_PHR_MAC_CE *) ce_ptr;
/* Save the phr info */ /* Save the phr info */
const int PH = phr->PH; const int PH = phr->PH;
...@@ -338,10 +341,10 @@ void nr_process_mac_pdu(module_id_t module_idP, ...@@ -338,10 +341,10 @@ void nr_process_mac_pdu(module_id_t module_idP,
case UL_SCH_LCID_MULTI_ENTRY_PHR_1_OCT: case UL_SCH_LCID_MULTI_ENTRY_PHR_1_OCT:
//38.321 section 6.1.3.9 //38.321 section 6.1.3.9
// varialbe length // varialbe length
mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pduP)->L;
mac_subheader_len = 2; mac_subheader_len = 2;
if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ if(((NR_MAC_SUBHEADER_SHORT *)pduP)->F){
mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pduP)->L2)<<8;
mac_subheader_len = 3; mac_subheader_len = 3;
} }
/* Extract MULTI ENTRY PHR elements from single octet bitmap for PHR calculation */ /* Extract MULTI ENTRY PHR elements from single octet bitmap for PHR calculation */
...@@ -350,10 +353,10 @@ void nr_process_mac_pdu(module_id_t module_idP, ...@@ -350,10 +353,10 @@ void nr_process_mac_pdu(module_id_t module_idP,
case UL_SCH_LCID_MULTI_ENTRY_PHR_4_OCT: case UL_SCH_LCID_MULTI_ENTRY_PHR_4_OCT:
//38.321 section 6.1.3.9 //38.321 section 6.1.3.9
// varialbe length // varialbe length
mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pduP)->L;
mac_subheader_len = 2; mac_subheader_len = 2;
if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ if(((NR_MAC_SUBHEADER_SHORT *)pduP)->F){
mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pduP)->L2)<<8;
mac_subheader_len = 3; mac_subheader_len = 3;
} }
/* Extract MULTI ENTRY PHR elements from four octets bitmap for PHR calculation */ /* Extract MULTI ENTRY PHR elements from four octets bitmap for PHR calculation */
...@@ -366,13 +369,13 @@ void nr_process_mac_pdu(module_id_t module_idP, ...@@ -366,13 +369,13 @@ void nr_process_mac_pdu(module_id_t module_idP,
case UL_SCH_LCID_SRB1: case UL_SCH_LCID_SRB1:
case UL_SCH_LCID_SRB2: case UL_SCH_LCID_SRB2:
if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ if(((NR_MAC_SUBHEADER_SHORT *)pduP)->F){
//mac_sdu_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; //mac_sdu_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pduP)->L2)<<8;
mac_subheader_len = 3; mac_subheader_len = 3;
mac_sdu_len = ((uint16_t)(((NR_MAC_SUBHEADER_LONG *) pdu_ptr)->L1 & 0x7f) << 8) mac_sdu_len = ((uint16_t)(((NR_MAC_SUBHEADER_LONG *) pduP)->L1 & 0x7f) << 8)
| ((uint16_t)((NR_MAC_SUBHEADER_LONG *) pdu_ptr)->L2 & 0xff); | ((uint16_t)((NR_MAC_SUBHEADER_LONG *) pduP)->L2 & 0xff);
} else { } else {
mac_sdu_len = (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; mac_sdu_len = (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pduP)->L;
mac_subheader_len = 2; mac_subheader_len = 2;
} }
LOG_D(NR_MAC, "[UE %d] Frame %d : ULSCH -> UL-DCCH %d (gNB %d, %d bytes), rnti: %d \n", module_idP, frameP, rx_lcid, module_idP, mac_sdu_len, UE_info->rnti[UE_id]); LOG_D(NR_MAC, "[UE %d] Frame %d : ULSCH -> UL-DCCH %d (gNB %d, %d bytes), rnti: %d \n", module_idP, frameP, rx_lcid, module_idP, mac_sdu_len, UE_info->rnti[UE_id]);
...@@ -383,7 +386,7 @@ void nr_process_mac_pdu(module_id_t module_idP, ...@@ -383,7 +386,7 @@ void nr_process_mac_pdu(module_id_t module_idP,
ENB_FLAG_YES, ENB_FLAG_YES,
MBMS_FLAG_NO, MBMS_FLAG_NO,
rx_lcid, rx_lcid,
(char *) (pdu_ptr + mac_subheader_len), (char *) (pduP + mac_subheader_len),
mac_sdu_len, mac_sdu_len,
1, 1,
NULL); NULL);
...@@ -404,7 +407,7 @@ void nr_process_mac_pdu(module_id_t module_idP, ...@@ -404,7 +407,7 @@ void nr_process_mac_pdu(module_id_t module_idP,
// Check if it is a valid CCCH1 message, we get all 00's messages very often // Check if it is a valid CCCH1 message, we get all 00's messages very often
int i = 0; int i = 0;
for(i=0; i<(mac_subheader_len+mac_sdu_len); i++) { for(i=0; i<(mac_subheader_len+mac_sdu_len); i++) {
if(pdu_ptr[i] != 0) { if(pduP[i] != 0) {
break; break;
} }
} }
...@@ -425,35 +428,34 @@ void nr_process_mac_pdu(module_id_t module_idP, ...@@ -425,35 +428,34 @@ void nr_process_mac_pdu(module_id_t module_idP,
0, 0,
UE_info->rnti[UE_id], UE_info->rnti[UE_id],
CCCH, CCCH,
pdu_ptr+mac_subheader_len, pduP + mac_subheader_len,
mac_sdu_len, mac_sdu_len,
0); 0);
break; break;
case UL_SCH_LCID_DTCH: case UL_SCH_LCID_DTCH:
// check if LCID is valid at current time. // check if LCID is valid at current time.
if (((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F) { if (((NR_MAC_SUBHEADER_SHORT *)pduP)->F) {
// mac_sdu_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; // mac_sdu_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pduP)->L2)<<8;
mac_subheader_len = 3; mac_subheader_len = 3;
mac_sdu_len = ((uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L1 & 0x7f) << 8) mac_sdu_len = ((uint16_t)(((NR_MAC_SUBHEADER_LONG *)pduP)->L1 & 0x7f) << 8)
| ((uint16_t)((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2 & 0xff); | ((uint16_t)((NR_MAC_SUBHEADER_LONG *)pduP)->L2 & 0xff);
} else { } else {
mac_sdu_len = (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; mac_sdu_len = (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pduP)->L;
mac_subheader_len = 2; mac_subheader_len = 2;
} }
LOG_D(NR_MAC, "[UE %d] Frame %d : ULSCH -> UL-%s %d (gNB %d, %d bytes)\n", LOG_D(NR_MAC, "In %s: [UE %d] %d.%d : ULSCH -> UL-%s %d (gNB %d, %d bytes)\n",
__func__,
module_idP, module_idP,
frameP, frameP,
slot,
rx_lcid<4?"DCCH":"DTCH", rx_lcid<4?"DCCH":"DTCH",
rx_lcid, rx_lcid,
module_idP, module_idP,
mac_sdu_len); mac_sdu_len);
UE_info->mac_stats[UE_id].lc_bytes_rx[rx_lcid] += mac_sdu_len; UE_info->mac_stats[UE_id].lc_bytes_rx[rx_lcid] += mac_sdu_len;
#if defined(ENABLE_MAC_PAYLOAD_DEBUG)
log_dump(NR_MAC, pdu_ptr + mac_subheader_len, 32, LOG_DUMP_CHAR, "\n");
#endif
mac_rlc_data_ind(module_idP, mac_rlc_data_ind(module_idP,
UE_info->rnti[UE_id], UE_info->rnti[UE_id],
...@@ -462,7 +464,7 @@ void nr_process_mac_pdu(module_id_t module_idP, ...@@ -462,7 +464,7 @@ void nr_process_mac_pdu(module_id_t module_idP,
ENB_FLAG_YES, ENB_FLAG_YES,
MBMS_FLAG_NO, MBMS_FLAG_NO,
rx_lcid, rx_lcid,
(char *)(pdu_ptr + mac_subheader_len), (char *)(pduP + mac_subheader_len),
mac_sdu_len, mac_sdu_len,
1, 1,
NULL); NULL);
...@@ -479,14 +481,27 @@ void nr_process_mac_pdu(module_id_t module_idP, ...@@ -479,14 +481,27 @@ void nr_process_mac_pdu(module_id_t module_idP,
return; return;
break; break;
} }
pdu_ptr += ( mac_subheader_len + mac_ce_len + mac_sdu_len );
#ifdef ENABLE_MAC_PAYLOAD_DEBUG
if (rx_lcid < 45 || rx_lcid == 52 || rx_lcid == 63) {
LOG_I(NR_MAC, "In %s: dumping UL MAC SDU sub-header with length %d (LCID = 0x%02x):\n", __func__, mac_subheader_len, rx_lcid);
log_dump(NR_MAC, pduP, mac_subheader_len, LOG_DUMP_CHAR, "\n");
LOG_I(NR_MAC, "In %s: dumping UL MAC SDU with length %d (LCID = 0x%02x):\n", __func__, mac_sdu_len, rx_lcid);
log_dump(NR_MAC, pduP + mac_subheader_len, mac_sdu_len, LOG_DUMP_CHAR, "\n");
} else {
LOG_I(NR_MAC, "In %s: dumping UL MAC CE with length %d (LCID = 0x%02x):\n", __func__, mac_ce_len, rx_lcid);
log_dump(NR_MAC, pduP + mac_subheader_len + mac_sdu_len, mac_ce_len, LOG_DUMP_CHAR, "\n");
}
#endif
pduP += ( mac_subheader_len + mac_ce_len + mac_sdu_len );
pdu_len -= ( mac_subheader_len + mac_ce_len + mac_sdu_len ); pdu_len -= ( mac_subheader_len + mac_ce_len + mac_sdu_len );
if (pdu_len < 0) { if (pdu_len < 0) {
LOG_E(NR_MAC, "%s() residual mac pdu length < 0!, pdu_len: %d\n", __func__, pdu_len); LOG_E(NR_MAC, "In %s: residual UL MAC PDU in %d.%d with length < 0!, pdu_len %d \n", __func__, frameP, slot, pdu_len);
LOG_E(NR_MAC, "MAC PDU "); LOG_E(NR_MAC, "MAC PDU ");
for (int i = 0; i < 20; i++) // Only printf 1st - 20nd bytes for (int i = 0; i < 20; i++) // Only printf 1st - 20nd bytes
printf("%02x ", pdu_ptr[i]); printf("%02x ", pduP[i]);
printf("\n"); printf("\n");
return; return;
} }
......
...@@ -208,7 +208,10 @@ tbs_size_t mac_rlc_data_req( ...@@ -208,7 +208,10 @@ tbs_size_t mac_rlc_data_req(
switch (channel_idP) { switch (channel_idP) {
case 1 ... 3: rb = ue->srb[channel_idP - 1]; break; case 1 ... 3: rb = ue->srb[channel_idP - 1]; break;
case 4 ... 8: rb = ue->drb[channel_idP - 4]; break; case 4 ... 8: rb = ue->drb[channel_idP - 4]; break;
default: rb = NULL; break; default:
rb = NULL;
LOG_E(RLC, "In %s:%d:%s: data request for unknown RB with LCID 0x%02x !\n", __FILE__, __LINE__, __FUNCTION__, channel_idP);
break;
} }
if (rb != NULL) { if (rb != NULL) {
...@@ -216,10 +219,6 @@ tbs_size_t mac_rlc_data_req( ...@@ -216,10 +219,6 @@ tbs_size_t mac_rlc_data_req(
maxsize = tb_sizeP; maxsize = tb_sizeP;
ret = rb->generate_pdu(rb, buffer_pP, maxsize); ret = rb->generate_pdu(rb, buffer_pP, maxsize);
} else { } else {
// Laurent: the query loop was checking all possible RB, but by mac_rlc_get_buffer_occupancy_ind
// so it is more straitforward to try to get data
//LOG_E(RLC, "%s:%d:%s: fatal: data req for unknown RB, channel_idP: %d\n", __FILE__, __LINE__, __FUNCTION__, channel_idP);
//exit(1);
ret = 0; ret = 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment