From bc73e73c261bb21bfa7523e8effe66e4e3196234 Mon Sep 17 00:00:00 2001 From: francescomani Date: Fri, 10 Mar 2023 16:53:13 +0100 Subject: [PATCH] improve UE state machine --- executables/nr-ue.c | 3 +- executables/nr-uesoftmodem.c | 8 +- openair1/SCHED_NR_UE/fapi_nr_ue_l1.c | 15 +- openair1/SIMULATION/NR_PHY/dlsim.c | 1 + openair2/LAYER2/NR_MAC_UE/config_ue.c | 2 + openair2/LAYER2/NR_MAC_UE/mac_defs.h | 12 +- openair2/LAYER2/NR_MAC_UE/mac_proto.h | 3 +- openair2/LAYER2/NR_MAC_UE/main_ue_nr.c | 2 + openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c | 16 +- .../NR_MAC_UE/nr_ue_dci_configuration.c | 6 +- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 5 + openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c | 313 +++++++++--------- openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c | 38 +-- 13 files changed, 193 insertions(+), 231 deletions(-) diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 26ccec80b4..075789e12b 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -352,8 +352,7 @@ static void *NRUE_phy_stub_standalone_pnf_task(void *arg) mac->scc_SIB->tdd_UL_DL_ConfigurationCommon, ul_info.slot_tx, mac->frame_type)) { LOG_D(NR_MAC, "Slot %d. calling nr_ue_ul_ind() and nr_ue_pucch_scheduler() from %s\n", ul_info.slot_tx, __FUNCTION__); - nr_ue_scheduler(NULL, &ul_info); - nr_ue_prach_scheduler(mod_id, ul_info.frame_tx, ul_info.slot_tx); + nr_ue_ul_scheduler(&ul_info); nr_ue_pucch_scheduler(mod_id, ul_info.frame_tx, ul_info.slot_tx, NULL); } if (!IS_SOFTMODEM_NOS1 && get_softmodem_params()->sa) { diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index d3d8090be5..eb6e160ec3 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -510,13 +510,13 @@ int main( int argc, char **argv ) { nr_band); } else{ - if(mac->if_module != NULL && mac->if_module->phy_config_request != NULL) - mac->if_module->phy_config_request(&mac->phy_config); - + DevAssert(mac->if_module != NULL && mac->if_module->phy_config_request != NULL); + mac->if_module->phy_config_request(&mac->phy_config); + mac->phy_config_request_sent = true; fapi_nr_config_request_t *nrUE_config = &UE[CC_id]->nrUE_config; nr_init_frame_parms_ue(&UE[CC_id]->frame_parms, nrUE_config, - *mac->scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0]); + *mac->scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0]); } init_nr_ue_vars(UE[CC_id], 0, abstraction_flag); diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c index e3134c24f6..b64be34f6e 100644 --- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c +++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c @@ -421,7 +421,8 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ for (int i = 0; i < ul_config->number_pdus; ++i){ AssertFatal(ul_config->ul_config_list[i].pdu_type <= FAPI_NR_UL_CONFIG_TYPES,"pdu_type %d out of bounds\n",ul_config->ul_config_list[i].pdu_type); - LOG_D(PHY, "In %s i %d: processing %s PDU of %d total UL PDUs (ul_config %p) \n", __FUNCTION__, i, ul_pdu_type[ul_config->ul_config_list[i].pdu_type - 1], ul_config->number_pdus, ul_config); + LOG_D(PHY, "[%d.%d] i %d: processing %s PDU of %d total UL PDUs (ul_config %p) \n", + scheduled_response->frame, slot, i, ul_pdu_type[ul_config->ul_config_list[i].pdu_type - 1], ul_config->number_pdus, ul_config); uint8_t pdu_type = ul_config->ul_config_list[i].pdu_type, current_harq_pid, gNB_id = 0; /* PRACH */ @@ -447,7 +448,6 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ LOG_D(PHY, "In %s i %d: copy pusch_config_pdu nrOfLayers:%d, num_dmrs_cdm_grps_no_data:%d \n", __FUNCTION__, i, pusch_config_pdu->nrOfLayers,pusch_config_pdu->num_dmrs_cdm_grps_no_data); memcpy(pusch_pdu, pusch_config_pdu, sizeof(nfapi_nr_ue_pusch_pdu_t)); - if (scheduled_response->tx_request) { for (int j=0; jtx_request->number_of_pdus; j++) { fapi_nr_tx_request_body_t *tx_req_body = &scheduled_response->tx_request->tx_request_body[j]; @@ -541,17 +541,10 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ return 0; } - - - -int8_t nr_ue_phy_config_request(nr_phy_config_t *phy_config){ - +int8_t nr_ue_phy_config_request(nr_phy_config_t *phy_config) +{ fapi_nr_config_request_t *nrUE_config = &PHY_vars_UE_g[phy_config->Mod_id][phy_config->CC_id]->nrUE_config; - if(phy_config != NULL) memcpy(nrUE_config,&phy_config->config_req,sizeof(fapi_nr_config_request_t)); - return 0; } - - diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index e939a27d1b..8fa8e1f008 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -852,6 +852,7 @@ int main(int argc, char **argv) UE->chest_time = chest_type[1]; UE_mac->if_module = nr_ue_if_module_init(0); + UE_mac->state = UE_CONNECTED; unsigned int available_bits=0; unsigned char *estimated_output_bit; diff --git a/openair2/LAYER2/NR_MAC_UE/config_ue.c b/openair2/LAYER2/NR_MAC_UE/config_ue.c index 89346dfeda..8ab321b9e1 100644 --- a/openair2/LAYER2/NR_MAC_UE/config_ue.c +++ b/openair2/LAYER2/NR_MAC_UE/config_ue.c @@ -684,6 +684,7 @@ void configure_current_BWP(NR_UE_MAC_INST_t *mac, NRRIV2PRBOFFSET(mac->scc_SIB->downlinkConfigCommon.initialDownlinkBWP.genericParameters.locationAndBandwidth, MAX_BWP_SIZE); UL_BWP->initial_BWPStart = mac->scc ? NRRIV2PRBOFFSET(mac->scc->uplinkConfigCommon->initialUplinkBWP->genericParameters.locationAndBandwidth, MAX_BWP_SIZE) : NRRIV2PRBOFFSET(mac->scc_SIB->uplinkConfigCommon->initialUplinkBWP.genericParameters.locationAndBandwidth, MAX_BWP_SIZE); + } @@ -732,6 +733,7 @@ int nr_rrc_mac_config_req_ue(module_id_t module_id, build_ssb_to_ro_map(mac);//->scc, mac->phy_config.config_req.cell_config.frame_duplex_type); if (!get_softmodem_params()->emulate_l1) mac->if_module->phy_config_request(&mac->phy_config); + mac->phy_config_request_sent = true; } if(scell_group_config != NULL ){ mac->cg = scell_group_config; diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index fe458ba644..e5401515c4 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -159,10 +159,11 @@ /*!\brief UE layer 2 status */ typedef enum { - UE_CONNECTION_OK = 0, - UE_CONNECTION_LOST, - UE_PHY_RESYNCH, - UE_PHY_HO_PRACH + UE_NOT_SYNC = 0, + UE_SYNC, + UE_PERFORMING_RA, + UE_WAIT_TX_ACK_MSG4, + UE_CONNECTED } NR_UE_L2_STATE_t; typedef enum { @@ -380,7 +381,7 @@ typedef struct { /*!\brief Top level UE MAC structure */ typedef struct { - + NR_UE_L2_STATE_t state; NR_ServingCellConfigCommon_t *scc; NR_ServingCellConfigCommonSIB_t *scc_SIB; NR_CellGroupConfig_t *cg; @@ -406,6 +407,7 @@ typedef struct { NR_ControlResourceSet_t *coreset[MAX_NUM_BWP_UE][FAPI_NR_MAX_CORESET_PER_BWP]; NR_SearchSpace_t *SSpace[MAX_NUM_BWP_UE][FAPI_NR_MAX_SS]; + bool phy_config_request_sent; frame_type_t frame_type; /// Type0-PDCCH seach space diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index eb773672d4..80b5c9082a 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -120,7 +120,8 @@ NR_UE_MAC_INST_t *get_mac_inst( performs BSR/SR/PHR procedures, random access procedure handler and DLSCH/ULSCH procedures. \param dl_info DL indication \param ul_info UL indication*/ -NR_UE_L2_STATE_t nr_ue_scheduler(nr_downlink_indication_t *dl_info, nr_uplink_indication_t *ul_info); +void nr_ue_ul_scheduler(nr_uplink_indication_t *ul_info); +void nr_ue_dl_scheduler(nr_downlink_indication_t *dl_info); /**\brief fill nr_scheduled_response struct instance @param nr_scheduled_response_t * pointer to scheduled_response instance to fill diff --git a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c index 662548231b..7fb2295f2d 100644 --- a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c +++ b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c @@ -53,6 +53,8 @@ NR_UE_MAC_INST_t * nr_l2_init_ue(NR_UE_RRC_INST_t* rrc_inst) { nr_ue_mac_inst = (NR_UE_MAC_INST_t *)calloc(sizeof(NR_UE_MAC_INST_t),NB_NR_UE_MAC_INST); nr_ue_mac_inst->first_sync_frame = -1; nr_ue_mac_inst->sib1_decoded = false; + nr_ue_mac_inst->phy_config_request_sent = false; + nr_ue_mac_inst->state = UE_NOT_SYNC; for (int j=0;jstate = UE_PERFORMING_RA; RA_config_t *ra = &mac->ra; ra->RA_active = 1; ra->ra_PreambleIndex = -1; @@ -734,8 +734,8 @@ uint8_t nr_ue_get_rach(module_id_t mod_id, int CC_id, frame_t frame, uint8_t gNB_id, - int nr_slot_tx){ - + int nr_slot_tx) +{ NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); RA_config_t *ra = &mac->ra; NR_RACH_ConfigDedicated_t *rach_ConfigDedicated = ra->rach_ConfigDedicated; @@ -1007,27 +1007,21 @@ void nr_ra_succeeded(module_id_t mod_id, frame_t frame, int slot){ RA_config_t *ra = &mac->ra; if (ra->cfra) { - LOG_I(MAC, "[UE %d][%d.%d][RAPROC] RA procedure succeeded. CF-RA: RAR successfully received.\n", mod_id, frame, slot); - + mac->state = UE_CONNECTED; ra->RA_window_cnt = -1; - } else { - LOG_A(MAC, "[UE %d][%d.%d][RAPROC] RA procedure succeeded. CB-RA: Contention Resolution is successful.\n", mod_id, frame, slot); - ra->RA_contention_resolution_timer_active = 0; mac->crnti = ra->t_crnti; ra->t_crnti = 0; - LOG_D(MAC, "In %s: [UE %d][%d.%d] CB-RA: cleared contention resolution timer...\n", __FUNCTION__, mod_id, frame, slot); - + mac->state = UE_WAIT_TX_ACK_MSG4; } LOG_D(MAC, "In %s: [UE %d] clearing RA_active flag...\n", __FUNCTION__, mod_id); ra->RA_active = 0; ra->ra_state = RA_SUCCEEDED; - } // Handling failure of RA procedure @ MAC layer diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c index 9d691514ed..e5b246f5c1 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c @@ -268,7 +268,7 @@ void ue_dci_configuration(NR_UE_MAC_INST_t *mac, fapi_nr_dl_config_request_t *dl uint8_t bwp_id = mac->current_DL_BWP.bwp_id; //NR_ServingCellConfig_t *scd = mac->scg->spCellConfig->spCellConfigDedicated; - NR_BWP_DownlinkDedicated_t *bwpd = (bwp_id>0) ? mac->DLbwp[bwp_id-1]->bwp_Dedicated : mac->cg->spCellConfig->spCellConfigDedicated->initialDownlinkBWP; + NR_BWP_DownlinkDedicated_t *bwpd = (bwp_id>0) ? mac->DLbwp[bwp_id-1]->bwp_Dedicated : (mac->cg ? mac->cg->spCellConfig->spCellConfigDedicated->initialDownlinkBWP : NULL); NR_BWP_DownlinkCommon_t *bwp_Common = (bwp_id>0) ? mac->DLbwp[bwp_id-1]->bwp_Common : &mac->scc_SIB->downlinkConfigCommon.initialDownlinkBWP; LOG_D(NR_MAC, "[DCI_CONFIG] ra_rnti %p (%x) crnti %p (%x) t_crnti %p (%x)\n", &ra->ra_rnti, ra->ra_rnti, &mac->crnti, mac->crnti, &ra->t_crnti, ra->t_crnti); @@ -376,7 +376,7 @@ void ue_dci_configuration(NR_UE_MAC_INST_t *mac, fapi_nr_dl_config_request_t *dl // this is an USS if (ss->searchSpaceType->choice.ue_Specific && ss->searchSpaceType->choice.ue_Specific->dci_Formats == NR_SearchSpace__searchSpaceType__ue_Specific__dci_Formats_formats0_1_And_1_1 && - (ra->ra_state == RA_SUCCEEDED || get_softmodem_params()->phy_test) && + mac->state == UE_CONNECTED && mac->crnti > 0) { // Monitors DCI 01 and 11 scrambled with C-RNTI, or CS-RNTI(s), or SP-CSI-RNTI LOG_D(NR_MAC, "[DCI_CONFIG] Configure monitoring of PDCCH candidates in the user specific search space\n"); @@ -417,6 +417,6 @@ void ue_dci_configuration(NR_UE_MAC_INST_t *mac, fapi_nr_dl_config_request_t *dl } // for ss_id } else { - AssertFatal(1==0,"Handle DCI searching when CellGroup without dedicated BWP\n"); + LOG_E(MAC,"Cannot handle DCI without dedicated BWP\n"); } } diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index f9bc506102..0e0eed0c1c 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -319,6 +319,11 @@ int8_t nr_ue_decode_mib(module_id_t module_id, mac->dl_config_request.sfn = frame; mac->dl_config_request.slot = ssb_start_symbol/14; + if(get_softmodem_params()->phy_test) + mac->state = UE_CONNECTED; + else if(mac->state == UE_NOT_SYNC) + mac->state = UE_SYNC; + return 0; } diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c index ae068fb333..a7d3db3d34 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c @@ -791,8 +791,8 @@ int nr_config_pusch_pdu(NR_UE_MAC_INST_t *mac, NR_tda_info_t *tda_info, nfapi_nr } // Periodic SRS scheduling -bool nr_ue_periodic_srs_scheduling(module_id_t mod_id, frame_t frame, slot_t slot) { - +bool nr_ue_periodic_srs_scheduling(module_id_t mod_id, frame_t frame, slot_t slot) +{ bool srs_scheduled = false; NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); @@ -913,185 +913,171 @@ bool nr_ue_periodic_srs_scheduling(module_id_t mod_id, frame_t frame, slot_t slo // 1. TODO: Call RRC for link status return to PHY // 2. TODO: Perform SR/BSR procedures for scheduling feedback // 3. TODO: Perform PHR procedures -NR_UE_L2_STATE_t nr_ue_scheduler(nr_downlink_indication_t *dl_info, nr_uplink_indication_t *ul_info){ +void nr_ue_dl_scheduler(nr_downlink_indication_t *dl_info) +{ + module_id_t mod_id = dl_info->module_id; + uint32_t gNB_index = dl_info->gNB_index; + int cc_id = dl_info->cc_id; + frame_t rx_frame = dl_info->frame; + slot_t rx_slot = dl_info->slot; + NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); - if (dl_info){ + fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request; - module_id_t mod_id = dl_info->module_id; - uint32_t gNB_index = dl_info->gNB_index; - int cc_id = dl_info->cc_id; - frame_t rx_frame = dl_info->frame; - slot_t rx_slot = dl_info->slot; - NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); + nr_scheduled_response_t scheduled_response; + nr_dcireq_t dcireq; - fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request; + if(mac->state == UE_CONNECTED) { - nr_scheduled_response_t scheduled_response; - nr_dcireq_t dcireq; + dcireq.module_id = mod_id; + dcireq.gNB_index = gNB_index; + dcireq.cc_id = cc_id; + dcireq.frame = rx_frame; + dcireq.slot = rx_slot; + dcireq.dl_config_req.number_pdus = 0; + nr_ue_dcireq(&dcireq); //to be replaced with function pointer later + mac->dl_config_request = dcireq.dl_config_req; - if(mac->cg != NULL){ // we have a cg + nr_schedule_csirs_reception(mac, rx_frame, rx_slot); + nr_schedule_csi_for_im(mac, rx_frame, rx_slot); + dcireq.dl_config_req = mac->dl_config_request; - dcireq.module_id = mod_id; - dcireq.gNB_index = gNB_index; - dcireq.cc_id = cc_id; - dcireq.frame = rx_frame; - dcireq.slot = rx_slot; - dcireq.dl_config_req.number_pdus = 0; - nr_ue_dcireq(&dcireq); //to be replaced with function pointer later - mac->dl_config_request = dcireq.dl_config_req; - - nr_schedule_csirs_reception(mac, rx_frame, rx_slot); - nr_schedule_csi_for_im(mac, rx_frame, rx_slot); - dcireq.dl_config_req = mac->dl_config_request; - - fill_scheduled_response(&scheduled_response, &dcireq.dl_config_req, NULL, NULL, mod_id, cc_id, rx_frame, rx_slot, dl_info->phy_data); - if(mac->if_module != NULL && mac->if_module->scheduled_response != NULL) { - LOG_D(NR_MAC,"1# scheduled_response transmitted, %d, %d\n", rx_frame, rx_slot); + fill_scheduled_response(&scheduled_response, &dcireq.dl_config_req, NULL, NULL, mod_id, cc_id, rx_frame, rx_slot, dl_info->phy_data); + if(mac->if_module != NULL && mac->if_module->scheduled_response != NULL) { + LOG_D(NR_MAC,"1# scheduled_response transmitted, %d, %d\n", rx_frame, rx_slot); + mac->if_module->scheduled_response(&scheduled_response); + } + } + else if (mac->state == UE_PERFORMING_RA) { + // this is for Msg2/Msg4 + if (mac->ra.ra_state >= WAIT_RAR) { + fapi_nr_dl_config_dci_dl_pdu_rel15_t *rel15 = &dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15; + rel15->num_dci_options = mac->ra.ra_state == WAIT_RAR ? 1 : 2; + rel15->dci_format_options[0] = NR_DL_DCI_FORMAT_1_0; + if (mac->ra.ra_state == WAIT_CONTENTION_RESOLUTION) + rel15->dci_format_options[1] = NR_UL_DCI_FORMAT_0_0; // msg3 retransmission + config_dci_pdu(mac, rel15, dl_config, mac->ra.ra_state == WAIT_RAR ? NR_RNTI_RA : NR_RNTI_TC , mac->ra.ss->searchSpaceId); + fill_dci_search_candidates(mac->ra.ss, rel15, -1 , -1); + dl_config->number_pdus = 1; + LOG_D(MAC,"mac->cg %p: Calling fill_scheduled_response rnti %x, type0_pdcch, num_pdus %d\n",mac->cg,rel15->rnti,dl_config->number_pdus); + fill_scheduled_response(&scheduled_response, dl_config, NULL, NULL, mod_id, cc_id, rx_frame, rx_slot, dl_info->phy_data); + if(mac->if_module != NULL && mac->if_module->scheduled_response != NULL) mac->if_module->scheduled_response(&scheduled_response); - } } - else { - // this is for Msg2/Msg4 - if (mac->ra.ra_state >= WAIT_RAR) { - fapi_nr_dl_config_dci_dl_pdu_rel15_t *rel15 = &dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15; - rel15->num_dci_options = mac->ra.ra_state == WAIT_RAR ? 1 : 2; - rel15->dci_format_options[0] = NR_DL_DCI_FORMAT_1_0; - if (mac->ra.ra_state == WAIT_CONTENTION_RESOLUTION) - rel15->dci_format_options[1] = NR_UL_DCI_FORMAT_0_0; // msg3 retransmission - config_dci_pdu(mac, rel15, dl_config, mac->ra.ra_state == WAIT_RAR ? NR_RNTI_RA : NR_RNTI_TC , mac->ra.ss->searchSpaceId); - fill_dci_search_candidates(mac->ra.ss, rel15, -1 , -1); - dl_config->number_pdus = 1; - LOG_D(MAC,"mac->cg %p: Calling fill_scheduled_response rnti %x, type0_pdcch, num_pdus %d\n",mac->cg,rel15->rnti,dl_config->number_pdus); - fill_scheduled_response(&scheduled_response, dl_config, NULL, NULL, mod_id, cc_id, rx_frame, rx_slot, dl_info->phy_data); - if(mac->if_module != NULL && mac->if_module->scheduled_response != NULL) - mac->if_module->scheduled_response(&scheduled_response); - } - else - { - dl_config->number_pdus = 0; - } - } - } else if (ul_info) { + } + else + dl_config->number_pdus = 0; +} - int cc_id = ul_info->cc_id; - frame_t frame_tx = ul_info->frame_tx; - slot_t slot_tx = ul_info->slot_tx; - module_id_t mod_id = ul_info->module_id; - uint32_t gNB_index = ul_info->gNB_index; +void nr_ue_ul_scheduler(nr_uplink_indication_t *ul_info) +{ + int cc_id = ul_info->cc_id; + frame_t frame_tx = ul_info->frame_tx; + slot_t slot_tx = ul_info->slot_tx; + module_id_t mod_id = ul_info->module_id; + uint32_t gNB_index = ul_info->gNB_index; - NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); - RA_config_t *ra = &mac->ra; + NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); + RA_config_t *ra = &mac->ra; - fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, slot_tx); - if (!ul_config) { - LOG_E(NR_MAC, "mac->ul_config is null!\n"); - } + fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, slot_tx); + if (!ul_config) + LOG_E(NR_MAC, "mac->ul_config is null!\n"); + if(mac->state < UE_CONNECTED) { nr_ue_get_rach(mod_id, cc_id, frame_tx, gNB_index, slot_tx); - // Periodic SRS scheduling + nr_ue_prach_scheduler(mod_id, frame_tx, slot_tx); + } + + // Periodic SRS scheduling + if(mac->state == UE_CONNECTED) nr_ue_periodic_srs_scheduling(mod_id, frame_tx, slot_tx); - // Schedule ULSCH only if the current frame and slot match those in ul_config_req - // AND if a UL grant (UL DCI or Msg3) has been received (as indicated by num_pdus) - if (ul_config){ - pthread_mutex_lock(&ul_config->mutex_ul_config); - if ((ul_info->slot_tx == ul_config->slot && ul_info->frame_tx == ul_config->sfn) && ul_config->number_pdus > 0){ + // Schedule ULSCH only if the current frame and slot match those in ul_config_req + // AND if a UL grant (UL DCI or Msg3) has been received (as indicated by num_pdus) + if (ul_config) { + pthread_mutex_lock(&ul_config->mutex_ul_config); + if ((ul_info->slot_tx == ul_config->slot && ul_info->frame_tx == ul_config->sfn) && ul_config->number_pdus > 0){ - 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, "[%d.%d]: number of UL PDUs: %d with UL transmission in [%d.%d]\n", frame_tx, slot_tx, ul_config->number_pdus, ul_config->sfn, ul_config->slot); - uint8_t ulsch_input_buffer_array[NFAPI_MAX_NUM_UL_PDU][MAX_ULSCH_PAYLOAD_BYTES]; - nr_scheduled_response_t scheduled_response; - fapi_nr_tx_request_t tx_req; - //tx_req.slot = slot_tx; - //tx_req.sfn = frame_tx; - tx_req.slot = slot_tx; - tx_req.sfn = frame_tx; - tx_req.number_of_pdus = 0; + uint8_t ulsch_input_buffer_array[NFAPI_MAX_NUM_UL_PDU][MAX_ULSCH_PAYLOAD_BYTES]; + nr_scheduled_response_t scheduled_response; + fapi_nr_tx_request_t tx_req; + tx_req.slot = slot_tx; + tx_req.sfn = frame_tx; + tx_req.number_of_pdus = 0; - for (int j = 0; j < ul_config->number_pdus; j++) { - uint8_t *ulsch_input_buffer = ulsch_input_buffer_array[tx_req.number_of_pdus]; + for (int j = 0; j < ul_config->number_pdus; j++) { + uint8_t *ulsch_input_buffer = ulsch_input_buffer_array[tx_req.number_of_pdus]; - fapi_nr_ul_config_request_pdu_t *ulcfg_pdu = &ul_config->ul_config_list[j]; + fapi_nr_ul_config_request_pdu_t *ulcfg_pdu = &ul_config->ul_config_list[j]; - if (ulcfg_pdu->pdu_type == FAPI_NR_UL_CONFIG_TYPE_PUSCH) { - int mac_pdu_exist = 0; - uint16_t TBS_bytes = ulcfg_pdu->pusch_config_pdu.pusch_data.tb_size; - LOG_D(NR_MAC,"harq_id %d, NDI %d NDI_DCI %d, TBS_bytes %d (ra_state %d)\n", - ulcfg_pdu->pusch_config_pdu.pusch_data.harq_process_id, - mac->UL_ndi[ulcfg_pdu->pusch_config_pdu.pusch_data.harq_process_id], - ulcfg_pdu->pusch_config_pdu.pusch_data.new_data_indicator, - TBS_bytes,ra->ra_state); - if (ra->ra_state == WAIT_RAR && !ra->cfra){ - memcpy(ulsch_input_buffer, mac->ulsch_pdu.payload, TBS_bytes); - LOG_D(NR_MAC,"[RAPROC] Msg3 to be transmitted:\n"); - for (int k = 0; k < TBS_bytes; k++) { - LOG_D(NR_MAC,"(%i): 0x%x\n",k,mac->ulsch_pdu.payload[k]); - } - LOG_D(NR_MAC,"Flipping NDI for harq_id %d (Msg3)\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->first_ul_tx[ulcfg_pdu->pusch_config_pdu.pusch_data.harq_process_id] = 0; + if (ulcfg_pdu->pdu_type == FAPI_NR_UL_CONFIG_TYPE_PUSCH) { + int mac_pdu_exist = 0; + uint16_t TBS_bytes = ulcfg_pdu->pusch_config_pdu.pusch_data.tb_size; + LOG_D(NR_MAC,"harq_id %d, NDI %d NDI_DCI %d, TBS_bytes %d (ra_state %d)\n", + ulcfg_pdu->pusch_config_pdu.pusch_data.harq_process_id, + mac->UL_ndi[ulcfg_pdu->pusch_config_pdu.pusch_data.harq_process_id], + ulcfg_pdu->pusch_config_pdu.pusch_data.new_data_indicator, + TBS_bytes,ra->ra_state); + if (ra->ra_state == WAIT_RAR && !ra->cfra){ + memcpy(ulsch_input_buffer, mac->ulsch_pdu.payload, TBS_bytes); + LOG_D(NR_MAC,"[RAPROC] Msg3 to be transmitted:\n"); + for (int k = 0; k < TBS_bytes; k++) { + LOG_D(NR_MAC,"(%i): 0x%x\n",k,mac->ulsch_pdu.payload[k]); + } + LOG_D(NR_MAC,"Flipping NDI for harq_id %d (Msg3)\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->first_ul_tx[ulcfg_pdu->pusch_config_pdu.pusch_data.harq_process_id] = 0; + mac_pdu_exist = 1; + } else { + + if ((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] == 1) && + (mac->state == UE_CONNECTED || + (ra->ra_state == WAIT_RAR && ra->cfra))){ + + // Getting IP traffic to be transmitted + nr_ue_get_sdu(mod_id, cc_id,frame_tx, slot_tx, gNB_index, ulsch_input_buffer, TBS_bytes); mac_pdu_exist = 1; - } else { - - if ((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]==1) && - ((get_softmodem_params()->phy_test == 1) || - (ra->ra_state == RA_SUCCEEDED) || - (ra->ra_state == WAIT_RAR && ra->cfra))){ - - // Getting IP traffic to be transmitted - nr_ue_get_sdu(mod_id, cc_id,frame_tx, slot_tx, gNB_index, ulsch_input_buffer, TBS_bytes); - mac_pdu_exist = 1; - } - - 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->first_ul_tx[ulcfg_pdu->pusch_config_pdu.pusch_data.harq_process_id] = 0; - } - // Config UL TX PDU - if (mac_pdu_exist) { - tx_req.tx_request_body[tx_req.number_of_pdus].pdu_length = TBS_bytes; - tx_req.tx_request_body[tx_req.number_of_pdus].pdu_index = j; - tx_req.tx_request_body[tx_req.number_of_pdus].pdu = ulsch_input_buffer; - tx_req.number_of_pdus++; - } - if (ra->ra_state == WAIT_CONTENTION_RESOLUTION && !ra->cfra){ - LOG_I(NR_MAC,"[RAPROC][%d.%d] RA-Msg3 retransmitted\n", frame_tx, slot_tx); - // 38.321 restart the ra-ContentionResolutionTimer at each HARQ retransmission in the first symbol after the end of the Msg3 transmission - nr_Msg3_transmitted(ul_info->module_id, ul_info->cc_id, ul_info->frame_tx, ul_info->slot_tx, ul_info->gNB_index); - } - if (ra->ra_state == WAIT_RAR && !ra->cfra){ - LOG_A(NR_MAC, "[RAPROC][%d.%d] RA-Msg3 transmitted\n", frame_tx, slot_tx); - nr_Msg3_transmitted(ul_info->module_id, ul_info->cc_id, ul_info->frame_tx, ul_info->slot_tx, ul_info->gNB_index); - } + 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->first_ul_tx[ulcfg_pdu->pusch_config_pdu.pusch_data.harq_process_id] = 0; + + } + + // Config UL TX PDU + if (mac_pdu_exist) { + tx_req.tx_request_body[tx_req.number_of_pdus].pdu_length = TBS_bytes; + tx_req.tx_request_body[tx_req.number_of_pdus].pdu_index = j; + tx_req.tx_request_body[tx_req.number_of_pdus].pdu = ulsch_input_buffer; + tx_req.number_of_pdus++; + } + if (ra->ra_state == WAIT_CONTENTION_RESOLUTION && !ra->cfra){ + LOG_I(NR_MAC,"[RAPROC][%d.%d] RA-Msg3 retransmitted\n", frame_tx, slot_tx); + // 38.321 restart the ra-ContentionResolutionTimer at each HARQ retransmission in the first symbol after the end of the Msg3 transmission + nr_Msg3_transmitted(ul_info->module_id, ul_info->cc_id, ul_info->frame_tx, ul_info->slot_tx, ul_info->gNB_index); + } + if (ra->ra_state == WAIT_RAR && !ra->cfra){ + LOG_A(NR_MAC, "[RAPROC][%d.%d] RA-Msg3 transmitted\n", frame_tx, slot_tx); + nr_Msg3_transmitted(ul_info->module_id, ul_info->cc_id, ul_info->frame_tx, ul_info->slot_tx, ul_info->gNB_index); } } - pthread_mutex_unlock(&ul_config->mutex_ul_config); // avoid double lock - - fill_scheduled_response(&scheduled_response, NULL, ul_config, &tx_req, mod_id, cc_id, frame_tx, slot_tx, ul_info->phy_data); - if(mac->if_module != NULL && mac->if_module->scheduled_response != NULL){ - LOG_D(NR_MAC,"3# scheduled_response transmitted,%d, %d\n", frame_tx, slot_tx); - mac->if_module->scheduled_response(&scheduled_response); - } - pthread_mutex_lock(&ul_config->mutex_ul_config); } - pthread_mutex_unlock(&ul_config->mutex_ul_config); + pthread_mutex_unlock(&ul_config->mutex_ul_config); // avoid double lock + fill_scheduled_response(&scheduled_response, NULL, ul_config, &tx_req, mod_id, cc_id, frame_tx, slot_tx, ul_info->phy_data); + if(mac->if_module != NULL && mac->if_module->scheduled_response != NULL){ + LOG_D(NR_MAC,"3# scheduled_response transmitted,%d, %d\n", frame_tx, slot_tx); + mac->if_module->scheduled_response(&scheduled_response); + } + pthread_mutex_lock(&ul_config->mutex_ul_config); } + pthread_mutex_unlock(&ul_config->mutex_ul_config); } - if (dl_info) { - return (UE_CONNECTION_OK); - } - module_id_t mod_id = ul_info->module_id; - frame_t txFrameP = ul_info->frame_tx; - slot_t txSlotP = ul_info->slot_tx; - - // Handle the SR/BSR procedures per subframe - NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); - uint8_t gNB_indexP=0; - // Call BSR procedure as described in Section 5.4.5 in 38.321 // First check ReTxBSR Timer because it is always configured @@ -1106,21 +1092,22 @@ NR_UE_L2_STATE_t nr_ue_scheduler(nr_downlink_indication_t *dl_info, nr_uplink_in } //Check whether Regular BSR is triggered - if (nr_update_bsr(mod_id, txFrameP, txSlotP, gNB_indexP) == true) { + if (nr_update_bsr(mod_id, frame_tx, slot_tx, gNB_index) == true) { // call SR procedure to generate pending SR and BSR for next PUCCH/PUSCH TxOp. This should implement the procedures // outlined in Sections 5.4.4 an 5.4.5 of 38.321 mac->scheduling_info.SR_pending = 1; // Regular BSR trigger mac->BSR_reporting_active |= NR_BSR_TRIGGER_REGULAR; LOG_D(NR_MAC, "[UE %d][BSR] Regular BSR Triggered Frame %d slot %d SR for PUSCH is pending\n", - mod_id, txFrameP, txSlotP); + mod_id, frame_tx, slot_tx); } - return UE_CONNECTION_OK; + if(mac->state >= UE_PERFORMING_RA) + nr_ue_pucch_scheduler(mod_id,frame_tx, slot_tx, ul_info->phy_data); } -bool -nr_update_bsr(module_id_t module_idP, frame_t frameP, slot_t slotP, uint8_t gNB_index) { +bool nr_update_bsr(module_id_t module_idP, frame_t frameP, slot_t slotP, uint8_t gNB_index) +{ mac_rlc_status_resp_t rlc_status; bool bsr_regular_triggered = false; uint8_t lcid; @@ -2138,7 +2125,7 @@ void nr_ue_pucch_scheduler(module_id_t module_idP, frame_t frameP, int slotP, vo uint16_t rnti = mac->crnti; //FIXME not sure this is valid for all pucch instances // SR - if (trigger_periodic_scheduling_request(mac, &pucch, frameP, slotP)) { + if (mac->state == UE_CONNECTED && trigger_periodic_scheduling_request(mac, &pucch, frameP, slotP)) { O_SR = 1; /* sr_payload = 1 means that this is a positive SR, sr_payload = 0 means that it is a negative SR */ pucch.sr_payload = nr_ue_get_SR(module_idP, @@ -2147,7 +2134,7 @@ void nr_ue_pucch_scheduler(module_id_t module_idP, frame_t frameP, int slotP, vo } // CSI - if (mac->ra.ra_state == RA_SUCCEEDED || get_softmodem_params()->phy_test == 1) + if (mac->state == UE_CONNECTED) O_CSI = nr_get_csi_measurements(mac, frameP, slotP, &pucch); // ACKNACK @@ -2197,15 +2184,14 @@ void nr_ue_pucch_scheduler(module_id_t module_idP, frame_t frameP, int slotP, vo fill_scheduled_response(&scheduled_response, NULL, ul_config, NULL, module_idP, 0 /*TBR fix*/, frameP, slotP, phy_data); if(mac->if_module != NULL && mac->if_module->scheduled_response != NULL) mac->if_module->scheduled_response(&scheduled_response); + if(mac->state == UE_WAIT_TX_ACK_MSG4) + mac->state = UE_CONNECTED; } } void nr_schedule_csi_for_im(NR_UE_MAC_INST_t *mac, int frame, int slot) { - if (mac->ra.ra_state != RA_SUCCEEDED && get_softmodem_params()->phy_test == 0) - return; - NR_UE_UL_BWP_t *current_UL_BWP = &mac->current_UL_BWP; if (!current_UL_BWP->csi_MeasConfig) @@ -2260,9 +2246,6 @@ void nr_schedule_csi_for_im(NR_UE_MAC_INST_t *mac, int frame, int slot) { void nr_schedule_csirs_reception(NR_UE_MAC_INST_t *mac, int frame, int slot) { - if (mac->ra.ra_state != RA_SUCCEEDED && get_softmodem_params()->phy_test == 0) - return; - NR_UE_UL_BWP_t *current_UL_BWP = &mac->current_UL_BWP; if (!current_UL_BWP->csi_MeasConfig) diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c index 27adaa39bc..87d8527eb9 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c @@ -736,7 +736,7 @@ void check_and_process_dci(nfapi_nr_dl_tti_request_t *dl_tti_request, NR_UL_TIME_ALIGNMENT_t ul_time_alignment; memset(&ul_time_alignment, 0, sizeof(ul_time_alignment)); fill_dci_from_dl_config(&mac->dl_info, &mac->dl_config_request); - nr_ue_scheduler(&mac->dl_info, NULL); + nr_ue_dl_scheduler(&mac->dl_info); nr_ue_dl_indication(&mac->dl_info, &ul_time_alignment); if (pthread_mutex_unlock(&mac->mutex_dl_info)) abort(); @@ -756,8 +756,7 @@ void check_and_process_dci(nfapi_nr_dl_tti_request_t *dl_tti_request, mac->scc_SIB->tdd_UL_DL_ConfigurationCommon, ul_info.slot_tx, mac->frame_type) && mac->ra.ra_state != RA_SUCCEEDED) { - nr_ue_scheduler(NULL, &ul_info); - nr_ue_prach_scheduler(ul_info.module_id, ul_info.frame_tx, ul_info.slot_tx); + nr_ue_ul_scheduler(&ul_info); } } } @@ -1115,36 +1114,17 @@ void update_harq_status(module_id_t module_id, uint8_t harq_pid, uint8_t ack_nac } } -int nr_ue_ul_indication(nr_uplink_indication_t *ul_info){ - - NR_UE_L2_STATE_t ret=0; +int nr_ue_ul_indication(nr_uplink_indication_t *ul_info) +{ module_id_t module_id = ul_info->module_id; NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); - NR_TDD_UL_DL_ConfigCommon_t *tdd_UL_DL_ConfigurationCommon = mac->scc != NULL ? mac->scc->tdd_UL_DL_ConfigurationCommon : mac->scc_SIB->tdd_UL_DL_ConfigurationCommon; LOG_T(NR_MAC, "In %s():%d not calling scheduler mac->ra.ra_state = %d\n", __FUNCTION__, __LINE__, mac->ra.ra_state); - ret = nr_ue_scheduler(NULL, ul_info); - if (is_nr_UL_slot(tdd_UL_DL_ConfigurationCommon, ul_info->slot_tx, mac->frame_type)) { - nr_ue_pucch_scheduler(module_id, ul_info->frame_tx, ul_info->slot_tx, ul_info->phy_data); - if (!get_softmodem_params()->phy_test) - nr_ue_prach_scheduler(module_id, ul_info->frame_tx, ul_info->slot_tx); - } - - switch(ret){ - case UE_CONNECTION_OK: - break; - case UE_CONNECTION_LOST: - break; - case UE_PHY_RESYNCH: - break; - case UE_PHY_HO_PRACH: - break; - default: - break; - } - + NR_TDD_UL_DL_ConfigCommon_t *tdd_UL_DL_ConfigurationCommon = mac->scc != NULL ? mac->scc->tdd_UL_DL_ConfigurationCommon : mac->scc_SIB->tdd_UL_DL_ConfigurationCommon; + if (mac->phy_config_request_sent && is_nr_UL_slot(tdd_UL_DL_ConfigurationCommon, ul_info->slot_tx, mac->frame_type)) + nr_ue_ul_scheduler(ul_info); return 0; } @@ -1157,11 +1137,11 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_ if ((!dl_info->dci_ind && !dl_info->rx_ind)) { // UL indication to schedule DCI reception - nr_ue_scheduler(dl_info, NULL); + if (mac->phy_config_request_sent) + nr_ue_dl_scheduler(dl_info); } else { // UL indication after reception of DCI or DL PDU if (dl_info && dl_info->dci_ind && dl_info->dci_ind->number_of_dcis) { - LOG_T(MAC,"[L2][IF MODULE][DL INDICATION][DCI_IND]\n"); for (int i = 0; i < dl_info->dci_ind->number_of_dcis; i++) { LOG_T(MAC,">>>NR_IF_Module i=%d, dl_info->dci_ind->number_of_dcis=%d\n",i,dl_info->dci_ind->number_of_dcis);