From 15822a0a5d95963f74f11e9fc1a46debc59fa01e Mon Sep 17 00:00:00 2001 From: francescomani Date: Thu, 20 Apr 2023 11:15:21 +0200 Subject: [PATCH 1/3] rework nr_rrc_mac_config_req --- openair1/SIMULATION/NR_PHY/dlsim.c | 3 +- openair1/SIMULATION/NR_PHY/ulsim.c | 3 - openair2/LAYER2/NR_MAC_UE/config_ue.c | 278 ++++++++++--------- openair2/LAYER2/NR_MAC_UE/mac_defs.h | 2 +- openair2/LAYER2/NR_MAC_UE/mac_proto.h | 36 +-- openair2/LAYER2/NR_MAC_UE/main_ue_nr.c | 3 +- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 11 +- openair2/RRC/NR_UE/rrc_UE.c | 38 ++- 8 files changed, 192 insertions(+), 182 deletions(-) diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index a7465ad99b..04d3962352 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -888,7 +888,8 @@ int main(int argc, char **argv) //Configure UE NR_BCCH_BCH_Message_t *mib = get_new_MIB_NR(scc); - nr_rrc_mac_config_req_ue(0, 0, 0, mib->message.choice.mib, NULL, NULL, secondaryCellGroup); + nr_rrc_mac_config_req_mib(0, 0, 0, mib, false); + nr_rrc_mac_config_req_scg(0, 0, 0, secondaryCellGroup); nr_dcireq_t dcireq; nr_scheduled_response_t scheduled_response; diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c index 6aaa79bb76..4ee528a6fc 100644 --- a/openair1/SIMULATION/NR_PHY/ulsim.c +++ b/openair1/SIMULATION/NR_PHY/ulsim.c @@ -744,11 +744,8 @@ int main(int argc, char **argv) UE_mac->if_module = nr_ue_if_module_init(0); -// nr_rrc_mac_config_req_ue(0,0,0,rrc.carrier.mib.message.choice.mib, NULL, NULL, secondaryCellGroup); - nr_ue_phy_config_request(&UE_mac->phy_config); - unsigned char harq_pid = 0; NR_gNB_ULSCH_t *ulsch_gNB = &gNB->ulsch[UE_id]; diff --git a/openair2/LAYER2/NR_MAC_UE/config_ue.c b/openair2/LAYER2/NR_MAC_UE/config_ue.c index c82e363074..47158f1965 100644 --- a/openair2/LAYER2/NR_MAC_UE/config_ue.c +++ b/openair2/LAYER2/NR_MAC_UE/config_ue.c @@ -693,145 +693,157 @@ void configure_current_BWP(NR_UE_MAC_INST_t *mac, } +void nr_rrc_mac_config_req_mib(module_id_t module_id, + uint8_t gNB_index, + int cc_idP, + NR_MIB_t *mib, + bool sched_sib1) +{ + NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); + AssertFatal(mib, "MIB should not be NULL\n"); + if (mac->dl_config_request == NULL) // for SIB1 reception + mac->dl_config_request = calloc(NR_MAX_SLOTS_PER_FRAME, sizeof(*mac->dl_config_request)); + mac->mib = mib; // update by every reception + mac->phy_config.Mod_id = module_id; + mac->phy_config.CC_id = cc_idP; + mac->get_sib1 = sched_sib1; +} -int nr_rrc_mac_config_req_ue(module_id_t module_id, - int cc_idP, - uint8_t gNB_index, - NR_MIB_t *mibP, - NR_ServingCellConfigCommonSIB_t *sccP, - NR_CellGroupConfig_t *cell_group_config, - NR_CellGroupConfig_t *scell_group_config) +void nr_rrc_mac_config_req_sib1(module_id_t module_id, + int cc_idP, + uint8_t gNB_index, + NR_ServingCellConfigCommonSIB_t *scc) +{ + NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); + AssertFatal(scc, "SIB1 SCC should not be NULL\n"); + mac->scc_SIB = scc; + mac->nr_band = *scc->downlinkConfigCommon.frequencyInfoDL.frequencyBandList.list.array[0]->freqBandIndicatorNR; + config_common_ue_sa(mac, module_id, cc_idP); + configure_current_BWP(mac, scc, NULL); + + fapi_nr_config_request_t *cfg = &mac->phy_config.config_req; + int num_slots_ul = nr_slots_per_frame[mac->mib->subCarrierSpacingCommon]; + if(cfg->cell_config.frame_duplex_type == TDD){ + num_slots_ul = scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSlots; + if (scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSymbols > 0) { + num_slots_ul++; + } + } + LOG_I(NR_MAC, "Initializing ul_config_request. num_slots_ul = %d\n", num_slots_ul); + mac->ul_config_request = calloc(num_slots_ul, sizeof(*mac->ul_config_request)); + for (int i=0; iul_config_request[i].mutex_ul_config), NULL); + + int num_slots_dl = nr_slots_per_frame[mac->mib->subCarrierSpacingCommon]; + if (cfg->cell_config.frame_duplex_type == TDD) { + num_slots_dl = scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofDownlinkSlots; + if (scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofDownlinkSymbols > 0) { + num_slots_dl++; + } + } + LOG_I(NR_MAC, "Initializing dl_config_request. num_slots_dl = %d\n", num_slots_dl); + mac->dl_config_request = realloc(mac->dl_config_request, num_slots_dl*sizeof(*mac->dl_config_request)); + memset(mac->dl_config_request, 0, num_slots_dl*sizeof(fapi_nr_dl_config_request_t)); + + // Setup the SSB to Rach Occasionsif (cell_group_config->spCellConfig) { mapping according to the config + build_ssb_to_ro_map(mac); + if (!get_softmodem_params()->emulate_l1) + mac->if_module->phy_config_request(&mac->phy_config); + mac->phy_config_request_sent = true; +} + +void nr_rrc_mac_config_req_mcg(module_id_t module_id, + int cc_idP, + uint8_t gNB_index, + NR_CellGroupConfig_t *cell_group_config) +{ + LOG_I(MAC,"Applying CellGroupConfig from gNodeB\n"); + AssertFatal(cell_group_config, "CellGroupConfig should not be NULL\n"); + NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); + mac->cg = cell_group_config; + if (cell_group_config->spCellConfig) + mac->servCellIndex = cell_group_config->spCellConfig->servCellIndex ? *cell_group_config->spCellConfig->servCellIndex : 0; + else + mac->servCellIndex = 0; + + mac->scheduling_info.periodicBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING; + mac->scheduling_info.retxBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING; + mac->BSR_reporting_active = NR_BSR_TRIGGER_NONE; + LOG_D(MAC, "[UE %d]: periodic BSR %d (SF), retx BSR %d (SF)\n", + module_id, + mac->scheduling_info.periodicBSR_SF, + mac->scheduling_info.retxBSR_SF); + + configure_current_BWP(mac, NULL, cell_group_config); + config_control_ue(mac); + + RA_config_t *ra = &mac->ra; + if (cell_group_config->spCellConfig && cell_group_config->spCellConfig->reconfigurationWithSync) { + LOG_A(NR_MAC, "Received the reconfigurationWithSync in %s\n", __FUNCTION__); + if (cell_group_config->spCellConfig->reconfigurationWithSync->rach_ConfigDedicated) { + ra->rach_ConfigDedicated = cell_group_config->spCellConfig->reconfigurationWithSync->rach_ConfigDedicated->choice.uplink; + } + mac->scc = cell_group_config->spCellConfig->reconfigurationWithSync->spCellConfigCommon; + mac->nr_band = *mac->scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0]; + if (mac->scc_SIB) { + free(mac->scc_SIB); + mac->scc_SIB = NULL; + } + int num_slots = mac->scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSlots; + if (mac->scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSymbols > 0) { + num_slots++; + } + mac->state = UE_NOT_SYNC; + mac->ra.ra_state = RA_UE_IDLE; + mac->physCellId = *mac->scc->physCellId; + if (!get_softmodem_params()->emulate_l1) { + mac->synch_request.Mod_id = module_id; + mac->synch_request.CC_id = cc_idP; + mac->synch_request.synch_req.target_Nid_cell = mac->physCellId; + mac->if_module->synch_request(&mac->synch_request); + } + mac->ul_config_request = calloc(num_slots, sizeof(*mac->ul_config_request)); + config_common_ue(mac, module_id, cc_idP); + mac->crnti = cell_group_config->spCellConfig->reconfigurationWithSync->newUE_Identity; + LOG_I(MAC, "Configuring CRNTI %x\n", mac->crnti); + + nr_ue_init_mac(module_id); + if (!get_softmodem_params()->emulate_l1) { + mac->if_module->phy_config_request(&mac->phy_config); + mac->phy_config_request_sent = true; + } + + // Setup the SSB to Rach Occasions mapping according to the config + build_ssb_to_ro_map(mac); + } +} + +void nr_rrc_mac_config_req_scg(module_id_t module_id, + int cc_idP, + uint8_t gNB_index, + NR_CellGroupConfig_t *scell_group_config) { NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); RA_config_t *ra = &mac->ra; - fapi_nr_config_request_t *cfg = &mac->phy_config.config_req; - if (mac->dl_config_request == NULL) // for SIB1 reception - mac->dl_config_request = calloc(NR_MAX_SLOTS_PER_FRAME, sizeof(*mac->dl_config_request)); + AssertFatal(scell_group_config == NULL, "scell_group_config cannot be NULL\n"); - // TODO do something FAPI-like P5 L1/L2 config interface in config_si, config_mib, etc. - - if(mibP != NULL){ - mac->mib = mibP; // update by every reception - mac->phy_config.Mod_id = module_id; - mac->phy_config.CC_id = cc_idP; + mac->cg = scell_group_config; + mac->servCellIndex = *scell_group_config->spCellConfig->servCellIndex; + if (scell_group_config->spCellConfig->reconfigurationWithSync) { + if (scell_group_config->spCellConfig->reconfigurationWithSync->rach_ConfigDedicated) { + ra->rach_ConfigDedicated = scell_group_config->spCellConfig->reconfigurationWithSync->rach_ConfigDedicated->choice.uplink; + } + mac->scc = scell_group_config->spCellConfig->reconfigurationWithSync->spCellConfigCommon; + mac->nr_band = *mac->scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0]; + mac->physCellId = *mac->scc->physCellId; + config_common_ue(mac,module_id,cc_idP); + mac->crnti = scell_group_config->spCellConfig->reconfigurationWithSync->newUE_Identity; + LOG_I(MAC,"Configuring CRNTI %x\n",mac->crnti); } - AssertFatal(scell_group_config == NULL || cell_group_config == NULL, - "both scell_group_config and cell_group_config cannot be non-NULL\n"); - - if (sccP != NULL) { - - mac->scc_SIB = sccP; - mac->nr_band = *sccP->downlinkConfigCommon.frequencyInfoDL.frequencyBandList.list.array[0]->freqBandIndicatorNR; - config_common_ue_sa(mac, module_id, cc_idP); - configure_current_BWP(mac, sccP, NULL); - - int num_slots_ul = nr_slots_per_frame[mac->mib->subCarrierSpacingCommon]; - if(cfg->cell_config.frame_duplex_type == TDD){ - num_slots_ul = mac->scc_SIB->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSlots; - if (mac->scc_SIB->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSymbols > 0) { - num_slots_ul++; - } - } - LOG_I(NR_MAC, "Initializing ul_config_request. num_slots_ul = %d\n", num_slots_ul); - mac->ul_config_request = calloc(num_slots_ul, sizeof(*mac->ul_config_request)); - for (int i=0; iul_config_request[i].mutex_ul_config), NULL); - - int num_slots_dl = nr_slots_per_frame[mac->mib->subCarrierSpacingCommon]; - if (cfg->cell_config.frame_duplex_type == TDD) { - num_slots_dl = mac->scc_SIB->tdd_UL_DL_ConfigurationCommon->pattern1.nrofDownlinkSlots; - if (mac->scc_SIB->tdd_UL_DL_ConfigurationCommon->pattern1.nrofDownlinkSymbols > 0) { - num_slots_dl++; - } - } - LOG_I(NR_MAC, "Initializing dl_config_request. num_slots_dl = %d\n", num_slots_dl); - mac->dl_config_request = realloc(mac->dl_config_request, num_slots_dl*sizeof(*mac->dl_config_request)); - memset(mac->dl_config_request, 0, num_slots_dl*sizeof(fapi_nr_dl_config_request_t)); - - // Setup the SSB to Rach Occasionsif (cell_group_config->spCellConfig) { mapping according to the config - 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; - mac->servCellIndex = *scell_group_config->spCellConfig->servCellIndex; - if (scell_group_config->spCellConfig->reconfigurationWithSync) { - if (scell_group_config->spCellConfig->reconfigurationWithSync->rach_ConfigDedicated) { - ra->rach_ConfigDedicated = scell_group_config->spCellConfig->reconfigurationWithSync->rach_ConfigDedicated->choice.uplink; - } - mac->scc = scell_group_config->spCellConfig->reconfigurationWithSync->spCellConfigCommon; - mac->nr_band = *mac->scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0]; - mac->physCellId = *mac->scc->physCellId; - config_common_ue(mac,module_id,cc_idP); - mac->crnti = scell_group_config->spCellConfig->reconfigurationWithSync->newUE_Identity; - LOG_I(MAC,"Configuring CRNTI %x\n",mac->crnti); - } - configure_current_BWP(mac, NULL, scell_group_config); - config_control_ue(mac); - // Setup the SSB to Rach Occasions mapping according to the config - build_ssb_to_ro_map(mac); - - } else if (cell_group_config != NULL) { - LOG_I(MAC,"Applying CellGroupConfig from gNodeB\n"); - mac->cg = cell_group_config; - if (cell_group_config->spCellConfig) - mac->servCellIndex = cell_group_config->spCellConfig->servCellIndex ? *cell_group_config->spCellConfig->servCellIndex : 0; - else - mac->servCellIndex = 0; - - mac->scheduling_info.periodicBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING; - mac->scheduling_info.retxBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING; - mac->BSR_reporting_active = NR_BSR_TRIGGER_NONE; - LOG_D(MAC, "[UE %d]: periodic BSR %d (SF), retx BSR %d (SF)\n", - module_id, - mac->scheduling_info.periodicBSR_SF, - mac->scheduling_info.retxBSR_SF); - - configure_current_BWP(mac, NULL, cell_group_config); - config_control_ue(mac); - - if (cell_group_config->spCellConfig && cell_group_config->spCellConfig->reconfigurationWithSync) { - LOG_A(NR_MAC, "Received the reconfigurationWithSync in %s\n", __FUNCTION__); - if (cell_group_config->spCellConfig->reconfigurationWithSync->rach_ConfigDedicated) { - ra->rach_ConfigDedicated = cell_group_config->spCellConfig->reconfigurationWithSync->rach_ConfigDedicated->choice.uplink; - } - mac->scc = cell_group_config->spCellConfig->reconfigurationWithSync->spCellConfigCommon; - mac->nr_band = *mac->scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0]; - if (mac->scc_SIB) { - free(mac->scc_SIB); - mac->scc_SIB = NULL; - } - int num_slots = mac->scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSlots; - if (mac->scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSymbols > 0) { - num_slots++; - } - mac->state = UE_NOT_SYNC; - mac->ra.ra_state = RA_UE_IDLE; - mac->physCellId = *mac->scc->physCellId; - if (!get_softmodem_params()->emulate_l1) { - mac->synch_request.Mod_id = module_id; - mac->synch_request.CC_id = cc_idP; - mac->synch_request.synch_req.target_Nid_cell = mac->physCellId; - mac->if_module->synch_request(&mac->synch_request); - } - mac->ul_config_request = calloc(num_slots, sizeof(*mac->ul_config_request)); - config_common_ue(mac, module_id, cc_idP); - mac->crnti = cell_group_config->spCellConfig->reconfigurationWithSync->newUE_Identity; - LOG_I(MAC, "Configuring CRNTI %x\n", mac->crnti); - - nr_ue_init_mac(module_id); - if (!get_softmodem_params()->emulate_l1) { - mac->if_module->phy_config_request(&mac->phy_config); - mac->phy_config_request_sent = true; - } - - // Setup the SSB to Rach Occasions mapping according to the config - build_ssb_to_ro_map(mac); - } - } - return 0; + configure_current_BWP(mac, NULL, scell_group_config); + config_control_ue(mac); + // Setup the SSB to Rach Occasions mapping according to the config + build_ssb_to_ro_map(mac); } diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index e5ffe9c356..cc2f90280e 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -399,7 +399,7 @@ typedef struct { long physCellId; //// MAC config int first_sync_frame; - bool sib1_decoded; + bool get_sib1; NR_DRX_Config_t *drx_Config; NR_SchedulingRequestConfig_t *schedulingRequestConfig; NR_BSR_Config_t *bsr_Config; diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index 0c69ee7d5f..b826ace760 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -91,22 +91,26 @@ int nr_rrc_mac_config_req_ue_logicalChannelBearer(module_id_t module_id, long logicalChannelIdentity, bool status); -/**\brief primitive from RRC layer to MAC layer for configuration L1/L2, now supported 4 rrc messages: MIB, cell_group_config for MAC/PHY, spcell_config(serving cell config) - \param module_id module id - \param cc_id component carrier id - \param gNB_index gNB index - \param mibP pointer to RRC message MIB - \param sccP pointer to ServingCellConfigCommon structure, - \param spcell_configP pointer to RRC message serving cell config*/ -int nr_rrc_mac_config_req_ue( - module_id_t module_id, - int cc_idP, - uint8_t gNB_index, - NR_MIB_t *mibP, - NR_ServingCellConfigCommonSIB_t *sccP, - NR_CellGroupConfig_t *cell_group_config, - NR_CellGroupConfig_t *scell_group_config -); +void nr_rrc_mac_config_req_scg(module_id_t module_id, + int cc_idP, + uint8_t gNB_index, + NR_CellGroupConfig_t *scell_group_config); + +void nr_rrc_mac_config_req_mcg(module_id_t module_id, + int cc_idP, + uint8_t gNB_index, + NR_CellGroupConfig_t *scell_group_config); + +void nr_rrc_mac_config_req_mib(module_id_t module_id, + uint8_t gNB_index, + int cc_idP, + NR_MIB_t *mibP, + bool sched_sib1); + +void nr_rrc_mac_config_req_sib1(module_id_t module_id, + int cc_idP, + uint8_t gNB_index, + NR_ServingCellConfigCommonSIB_t *scc); /**\brief initialization NR UE MAC instance(s), total number of MAC instance based on NB_NR_UE_MAC_INST*/ NR_UE_MAC_INST_t * nr_l2_init_ue(NR_UE_RRC_INST_t* rrc_inst); diff --git a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c index 96a9a3e072..b802cb9528 100644 --- a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c +++ b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c @@ -58,7 +58,7 @@ NR_UE_MAC_INST_t * nr_l2_init_ue(NR_UE_RRC_INST_t* rrc_inst) { if (rrc_inst && rrc_inst->scell_group_config) { - nr_rrc_mac_config_req_ue(0,0,0,NULL,NULL,NULL,rrc_inst->scell_group_config); + nr_rrc_mac_config_req_scg(0, 0, 0, rrc_inst->scell_group_config); AssertFatal(rlc_module_init(0) == 0, "%s: Could not initialize RLC layer\n", __FUNCTION__); if (IS_SOFTMODEM_NOS1){ // get default noS1 configuration @@ -95,7 +95,6 @@ NR_UE_MAC_INST_t * nr_l2_init_ue(NR_UE_RRC_INST_t* rrc_inst) { } else { LOG_I(MAC,"Running without CellGroupConfig\n"); - nr_rrc_mac_config_req_ue(0,0,0,NULL,NULL,NULL,NULL); if(get_softmodem_params()->sa == 1) { AssertFatal(rlc_module_init(0) == 0, "%s: Could not initialize RLC layer\n", __FUNCTION__); } diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 2cde4d3c07..19f84c28a1 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -200,7 +200,7 @@ void nr_ue_init_mac(module_id_t module_idP) } mac->first_sync_frame = -1; - mac->sib1_decoded = false; + mac->get_sib1 = false; mac->phy_config_request_sent = false; mac->state = UE_NOT_SYNC; memset(&mac->ssb_measurements, 0, sizeof(mac->ssb_measurements)); @@ -323,7 +323,7 @@ int8_t nr_ue_decode_mib(module_id_t module_id, else ssb_sc_offset_norm = ssb_subcarrier_offset; - if (!mac->sib1_decoded) { + if (mac->get_sib1) { nr_ue_sib1_scheduler(module_id, cc_id, ssb_start_symbol, @@ -361,8 +361,6 @@ int8_t nr_ue_decode_BCCH_DL_SCH(module_id_t module_id, uint32_t pdu_len) { if(ack_nack) { LOG_D(NR_MAC, "Decoding NR-BCCH-DL-SCH-Message (SIB1 or SI)\n"); - NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); - mac->sib1_decoded = true; nr_mac_rrc_data_ind_ue(module_id, cc_id, gNB_index, 0, 0, 0, NR_BCCH_DL_SCH, (uint8_t *) pduP, pdu_len); } else @@ -672,7 +670,10 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fr NR_Type0_PDCCH_CSS_config_t type0_PDCCH_CSS_config = mac->type0_PDCCH_CSS_config; mux_pattern = type0_PDCCH_CSS_config.type0_pdcch_ss_mux_pattern; dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_SI_DLSCH; - dlsch_config_pdu_1_0->SubcarrierSpacing = mac->mib->subCarrierSpacingCommon; + if(mac->frequency_range == FR1) + dlsch_config_pdu_1_0->SubcarrierSpacing = mac->mib->subCarrierSpacingCommon; + else + dlsch_config_pdu_1_0->SubcarrierSpacing = mac->mib->subCarrierSpacingCommon + 2; if (pdsch_config) pdsch_config->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition = NULL; // For PDSCH with mapping type A, the UE shall assume dmrs-AdditionalPosition='pos2' } else { dlsch_config_pdu_1_0->SubcarrierSpacing = current_DL_BWP->scs; diff --git a/openair2/RRC/NR_UE/rrc_UE.c b/openair2/RRC/NR_UE/rrc_UE.c index 7ddc2da5d7..468440a98c 100644 --- a/openair2/RRC/NR_UE/rrc_UE.c +++ b/openair2/RRC/NR_UE/rrc_UE.c @@ -285,6 +285,10 @@ int8_t nr_rrc_ue_process_rrcReconfiguration(const module_id_t module_id, NR_RRCR NR_UE_rrc_inst[module_id].cell_group_config = cellGroupConfig; nr_rrc_ue_process_scg_config(module_id,cellGroupConfig); } + if (get_softmodem_params()->nsa) { + nr_rrc_mac_config_req_scg(0, 0, 0, cellGroupConfig); + LOG_D(NR_RRC, "Filled scc now \n"); + } } else nr_rrc_ue_decode_secondary_cellgroup_config(module_id, @@ -312,7 +316,6 @@ int8_t nr_rrc_ue_process_rrcReconfiguration(const module_id_t module_id, NR_RRCR default: break; } - //nr_rrc_mac_config_req_ue(); return 0; } @@ -340,10 +343,6 @@ int8_t nr_rrc_ue_process_scg_config(const module_id_t module_id, NR_CellGroupCon }else{ // maintain list if(cell_group_config->spCellConfig != NULL){ - if (get_softmodem_params()->nsa) { - nr_rrc_mac_config_req_ue(0, 0, 0, NULL, NULL, cell_group_config, NULL); - LOG_D(NR_RRC, "Filled scc now \n"); - } if(cell_group_config->spCellConfig->spCellConfigDedicated != NULL){ // process element of list to be add by RRC message if(cell_group_config->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList != NULL){ @@ -600,7 +599,10 @@ int8_t nr_rrc_ue_decode_NR_BCCH_BCH_Message(const module_id_t module_id, const u NR_UE_rrc_inst[module_id].mib = bcch_message->message.choice.mib; bcch_message->message.choice.mib = NULL; - nr_rrc_mac_config_req_ue(0, 0, 0, NR_UE_rrc_inst[module_id].mib, NULL, NULL, NULL); + NR_SIB1_t *sib1 = NR_UE_rrc_inst[module_id].sib1[gNB_index]; + // if no sib1 because not acquired yet or expired, get a new one + bool get_sib1 = sib1 ? false : true; + nr_rrc_mac_config_req_mib(module_id, gNB_index, 0, NR_UE_rrc_inst[module_id].mib, get_sib1); ret = 0; } ASN_STRUCT_FREE(asn_DEF_NR_BCCH_BCH_Message, bcch_message); @@ -1210,8 +1212,8 @@ int8_t nr_rrc_ue_decode_NR_BCCH_DL_SCH_Message(module_id_t module_id, } // take ServingCellConfigCommon and configure L1/L2 NR_UE_rrc_inst[module_id].servingCellConfigCommonSIB = sib1->servingCellConfigCommon; - nr_rrc_mac_config_req_ue(module_id,0,0,NULL,sib1->servingCellConfigCommon,NULL,NULL); - nr_rrc_ue_generate_ra_msg(module_id,gNB_index); + nr_rrc_mac_config_req_sib1(module_id, 0, gNB_index, sib1->servingCellConfigCommon); + nr_rrc_ue_generate_ra_msg(module_id, gNB_index); } else { LOG_E(NR_RRC, "SIB1 not decoded\n"); } @@ -1256,12 +1258,9 @@ int8_t nr_rrc_ue_decode_NR_BCCH_DL_SCH_Message(module_id_t module_id, } //----------------------------------------------------------------------------- -void -nr_rrc_ue_process_masterCellGroup( - const protocol_ctxt_t *const ctxt_pP, - uint8_t gNB_index, - OCTET_STRING_t *masterCellGroup -) +void nr_rrc_ue_process_masterCellGroup(const protocol_ctxt_t *const ctxt_pP, + uint8_t gNB_index, + OCTET_STRING_t *masterCellGroup) //----------------------------------------------------------------------------- { NR_CellGroupConfig_t *cellGroupConfig=NULL; @@ -1358,7 +1357,7 @@ nr_rrc_ue_process_masterCellGroup( NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config = cellGroupConfig; } LOG_D(RRC,"Sending CellGroupConfig to MAC\n"); - nr_rrc_mac_config_req_ue(ctxt_pP->module_id,0,0,NULL,NULL,cellGroupConfig,NULL); + nr_rrc_mac_config_req_mcg(ctxt_pP->module_id, 0, 0, cellGroupConfig); //TODO (configure the SpCell as specified in 5.3.5.5.7) } @@ -2136,12 +2135,9 @@ nr_rrc_ue_establish_srb2( } //----------------------------------------------------------------------------- - static void - rrc_ue_process_rrcReconfiguration( - const protocol_ctxt_t *const ctxt_pP, - NR_RRCReconfiguration_t *rrcReconfiguration, - uint8_t gNB_index - ) + static void rrc_ue_process_rrcReconfiguration(const protocol_ctxt_t *const ctxt_pP, + NR_RRCReconfiguration_t *rrcReconfiguration, + uint8_t gNB_index) //----------------------------------------------------------------------------- { LOG_I(NR_RRC, "[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing RRCReconfiguration (gNB %d)\n", From c0f7e458bb09983645e6b67d68e55e83b2a5c616 Mon Sep 17 00:00:00 2001 From: francescomani Date: Thu, 20 Apr 2023 14:15:14 +0200 Subject: [PATCH 2/3] rework and adjust size of config_request mac vectors --- openair1/SIMULATION/NR_PHY/dlsim.c | 2 +- openair2/LAYER2/NR_MAC_UE/config_ue.c | 50 ++++++---------- openair2/LAYER2/NR_MAC_UE/mac_proto.h | 2 +- openair2/LAYER2/NR_MAC_UE/main_ue_nr.c | 14 ----- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 12 +++- openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c | 61 ++++---------------- 6 files changed, 41 insertions(+), 100 deletions(-) diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index 04d3962352..032983644d 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -888,7 +888,7 @@ int main(int argc, char **argv) //Configure UE NR_BCCH_BCH_Message_t *mib = get_new_MIB_NR(scc); - nr_rrc_mac_config_req_mib(0, 0, 0, mib, false); + nr_rrc_mac_config_req_mib(0, 0, 0, mib->message.choice.mib, false); nr_rrc_mac_config_req_scg(0, 0, 0, secondaryCellGroup); nr_dcireq_t dcireq; diff --git a/openair2/LAYER2/NR_MAC_UE/config_ue.c b/openair2/LAYER2/NR_MAC_UE/config_ue.c index 47158f1965..ebcad5d0de 100644 --- a/openair2/LAYER2/NR_MAC_UE/config_ue.c +++ b/openair2/LAYER2/NR_MAC_UE/config_ue.c @@ -693,6 +693,21 @@ void configure_current_BWP(NR_UE_MAC_INST_t *mac, } +void init_config_request(NR_UE_MAC_INST_t *mac) +{ + if(mac->dl_config_request == NULL && mac->ul_config_request == NULL) { + int scs = mac->mib->subCarrierSpacingCommon; + if(mac->frequency_range == FR2) + scs += 2; + int slots_per_frame = nr_slots_per_frame[scs]; + LOG_I(NR_MAC, "Initializing dl and ul config_request. num_slots = %d\n", slots_per_frame); + mac->dl_config_request = calloc(slots_per_frame, sizeof(*mac->dl_config_request)); + mac->ul_config_request = calloc(slots_per_frame, sizeof(*mac->ul_config_request)); + for (int i = 0; i < slots_per_frame; i++) + pthread_mutex_init(&(mac->ul_config_request[i].mutex_ul_config), NULL); + } +} + void nr_rrc_mac_config_req_mib(module_id_t module_id, uint8_t gNB_index, int cc_idP, @@ -701,9 +716,9 @@ void nr_rrc_mac_config_req_mib(module_id_t module_id, { NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); AssertFatal(mib, "MIB should not be NULL\n"); - if (mac->dl_config_request == NULL) // for SIB1 reception - mac->dl_config_request = calloc(NR_MAX_SLOTS_PER_FRAME, sizeof(*mac->dl_config_request)); + // initialize dl and ul config_request upon first reception of MIB mac->mib = mib; // update by every reception + init_config_request(mac); mac->phy_config.Mod_id = module_id; mac->phy_config.CC_id = cc_idP; mac->get_sib1 = sched_sib1; @@ -721,30 +736,6 @@ void nr_rrc_mac_config_req_sib1(module_id_t module_id, config_common_ue_sa(mac, module_id, cc_idP); configure_current_BWP(mac, scc, NULL); - fapi_nr_config_request_t *cfg = &mac->phy_config.config_req; - int num_slots_ul = nr_slots_per_frame[mac->mib->subCarrierSpacingCommon]; - if(cfg->cell_config.frame_duplex_type == TDD){ - num_slots_ul = scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSlots; - if (scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSymbols > 0) { - num_slots_ul++; - } - } - LOG_I(NR_MAC, "Initializing ul_config_request. num_slots_ul = %d\n", num_slots_ul); - mac->ul_config_request = calloc(num_slots_ul, sizeof(*mac->ul_config_request)); - for (int i=0; iul_config_request[i].mutex_ul_config), NULL); - - int num_slots_dl = nr_slots_per_frame[mac->mib->subCarrierSpacingCommon]; - if (cfg->cell_config.frame_duplex_type == TDD) { - num_slots_dl = scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofDownlinkSlots; - if (scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofDownlinkSymbols > 0) { - num_slots_dl++; - } - } - LOG_I(NR_MAC, "Initializing dl_config_request. num_slots_dl = %d\n", num_slots_dl); - mac->dl_config_request = realloc(mac->dl_config_request, num_slots_dl*sizeof(*mac->dl_config_request)); - memset(mac->dl_config_request, 0, num_slots_dl*sizeof(fapi_nr_dl_config_request_t)); - // Setup the SSB to Rach Occasionsif (cell_group_config->spCellConfig) { mapping according to the config build_ssb_to_ro_map(mac); if (!get_softmodem_params()->emulate_l1) @@ -789,10 +780,6 @@ void nr_rrc_mac_config_req_mcg(module_id_t module_id, free(mac->scc_SIB); mac->scc_SIB = NULL; } - int num_slots = mac->scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSlots; - if (mac->scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSymbols > 0) { - num_slots++; - } mac->state = UE_NOT_SYNC; mac->ra.ra_state = RA_UE_IDLE; mac->physCellId = *mac->scc->physCellId; @@ -802,7 +789,6 @@ void nr_rrc_mac_config_req_mcg(module_id_t module_id, mac->synch_request.synch_req.target_Nid_cell = mac->physCellId; mac->if_module->synch_request(&mac->synch_request); } - mac->ul_config_request = calloc(num_slots, sizeof(*mac->ul_config_request)); config_common_ue(mac, module_id, cc_idP); mac->crnti = cell_group_config->spCellConfig->reconfigurationWithSync->newUE_Identity; LOG_I(MAC, "Configuring CRNTI %x\n", mac->crnti); @@ -827,7 +813,7 @@ void nr_rrc_mac_config_req_scg(module_id_t module_id, NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); RA_config_t *ra = &mac->ra; - AssertFatal(scell_group_config == NULL, "scell_group_config cannot be NULL\n"); + AssertFatal(scell_group_config, "scell_group_config cannot be NULL\n"); mac->cg = scell_group_config; mac->servCellIndex = *scell_group_config->spCellConfig->servCellIndex; diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index b826ace760..3be9eb934d 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -438,7 +438,7 @@ static uint8_t nr_extract_dci_info(NR_UE_MAC_INST_t *mac, dci_pdu_rel15_t *dci_pdu_rel15, int slot); -fapi_nr_ul_config_request_t *get_ul_config_request(NR_UE_MAC_INST_t *mac, int slot); +fapi_nr_ul_config_request_t *get_ul_config_request(NR_UE_MAC_INST_t *mac, int slot, int fb_time); fapi_nr_dl_config_request_t *get_dl_config_request(NR_UE_MAC_INST_t *mac, int slot); void fill_ul_config(fapi_nr_ul_config_request_t *ul_config, frame_t frame_tx, int slot_tx, uint8_t pdu_type); diff --git a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c index b802cb9528..78d1b4b0f1 100644 --- a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c +++ b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c @@ -78,20 +78,6 @@ NR_UE_MAC_INST_t * nr_l2_init_ue(NR_UE_RRC_INST_t* rrc_inst) { // free memory free_nr_noS1_bearer_config(&rbconfig, &rlc_rbconfig); } - // Allocate memory for ul_config_request in the mac instance. This is now a pointer and will - // point to a list of structures (one for each UL slot) to store PUSCH scheduling parameters - // received from UL DCI. - if (nr_ue_mac_inst->scc) { - NR_TDD_UL_DL_ConfigCommon_t *tdd = nr_ue_mac_inst->scc->tdd_UL_DL_ConfigurationCommon; - int num_slots_ul = tdd ? tdd->pattern1.nrofUplinkSlots : nr_slots_per_frame[*nr_ue_mac_inst->scc->ssbSubcarrierSpacing]; - if (tdd && nr_ue_mac_inst->scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSymbols > 0) { - num_slots_ul++; - } - LOG_D(NR_MAC, "In %s: Initializing ul_config_request. num_slots_ul = %d\n", __FUNCTION__, num_slots_ul); - nr_ue_mac_inst->ul_config_request = (fapi_nr_ul_config_request_t *)calloc(num_slots_ul, sizeof(fapi_nr_ul_config_request_t)); - for (int i=0; iul_config_request[i].mutex_ul_config), NULL); - } } else { LOG_I(MAC,"Running without CellGroupConfig\n"); diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 19f84c28a1..8b1582a984 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -181,6 +181,12 @@ void nr_ue_init_mac(module_id_t module_idP) // mac->scheduling_info.PathlossChange_db = nr_get_db_dl_PathlossChange(mac->scheduling_info.PathlossChange); // mac->PHR_reporting_active = 0; + mac->first_sync_frame = -1; + mac->get_sib1 = false; + mac->phy_config_request_sent = false; + mac->state = UE_NOT_SYNC; + memset(&mac->ssb_measurements, 0, sizeof(mac->ssb_measurements)); + for (int i = 0; i < NR_MAX_NUM_LCID; i++) { LOG_D(NR_MAC, "[UE%d] Applying default logical channel config for LCGID %d\n", module_idP, i); @@ -511,7 +517,7 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fr if (ret != -1){ // Get UL config request corresponding slot_tx - 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, tda_info.k2); 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); @@ -580,7 +586,7 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fr if (ret != -1){ // Get UL config request corresponding slot_tx - 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, tda_info.k2); 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); @@ -4132,7 +4138,7 @@ int nr_ue_process_rar(nr_downlink_indication_t *dl_info, int pdu_id) 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, tda_info.k2); uint16_t rnti = mac->crnti; if (!ul_config) { diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c index 94067924d1..32914b37f9 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c @@ -107,31 +107,19 @@ void fill_scheduled_response(nr_scheduled_response_t *scheduled_response, * This function returns the UL config corresponding to a given UL slot * from MAC instance . */ -fapi_nr_ul_config_request_t *get_ul_config_request(NR_UE_MAC_INST_t *mac, int slot) +fapi_nr_ul_config_request_t *get_ul_config_request(NR_UE_MAC_INST_t *mac, int slot, int fb_time) { NR_TDD_UL_DL_ConfigCommon_t *tdd_config = mac->scc==NULL ? mac->scc_SIB->tdd_UL_DL_ConfigurationCommon : mac->scc->tdd_UL_DL_ConfigurationCommon; //Check if requested on the right slot - AssertFatal(is_nr_UL_slot(tdd_config, slot, mac->frame_type) != 0, "%s called at wrong slot %d\n", __func__, slot); + AssertFatal(is_nr_UL_slot(tdd_config, slot, mac->frame_type) != 0, "UL config_request called at wrong slot %d\n", slot); - // Calculate the index of the UL slot in mac->ul_config_request list. This is - // based on the TDD pattern (slot configuration period) and number of UL+mixed - // slots in the period. TS 38.213 Sec 11.1 int mu = mac->current_UL_BWP.scs; const int n = nr_slots_per_frame[mu]; - const int num_slots_per_tdd = tdd_config ? (n >> (7 - tdd_config->pattern1.dl_UL_TransmissionPeriodicity)) : n; - const int num_slots_ul = tdd_config ? (tdd_config->pattern1.nrofUplinkSlots + (tdd_config->pattern1.nrofUplinkSymbols != 0)) : n; - int index = slot % num_slots_ul; - - LOG_D(NR_MAC, "In %s slots per %s: %d, num_slots %d, index %d\n", - __FUNCTION__, - tdd_config ? "TDD" : "FDD", - num_slots_per_tdd, - num_slots_ul, - index); - - if (mac->ul_config_request) return &mac->ul_config_request[index]; + AssertFatal(fb_time < n, "Cannot schedule to a slot more than 1 frame away, ul_config_request is not big enough\n"); + if (mac->ul_config_request) + return &mac->ul_config_request[slot]; else { LOG_E(NR_MAC, "mac->ul_config_request not set\n"); return NULL; @@ -144,33 +132,8 @@ fapi_nr_ul_config_request_t *get_ul_config_request(NR_UE_MAC_INST_t *mac, int sl */ fapi_nr_dl_config_request_t *get_dl_config_request(NR_UE_MAC_INST_t *mac, int slot) { - int index; - if (!mac->scc && !mac->scc_SIB) - index = 0; - else { - NR_TDD_UL_DL_ConfigCommon_t *tdd_config = mac->scc==NULL ? mac->scc_SIB->tdd_UL_DL_ConfigurationCommon : mac->scc->tdd_UL_DL_ConfigurationCommon; - - //Check if requested on the right slot - AssertFatal(is_nr_DL_slot(tdd_config, slot) != 0, "%s called at wrong slot %d\n", __func__, slot); - - // Calculate the index of the DL slot in mac->ul_config_request list. This is - // based on the TDD pattern (slot configuration period) and number of DL+mixed - // slots in the period. TS 38.213 Sec 11.1 - int mu = mac->current_UL_BWP.scs; - const int n = nr_slots_per_frame[mu]; - const int num_slots_per_tdd = tdd_config ? (n >> (7 - tdd_config->pattern1.dl_UL_TransmissionPeriodicity)) : n; - const int num_slots_dl = tdd_config ? (tdd_config->pattern1.nrofDownlinkSlots + (tdd_config->pattern1.nrofDownlinkSymbols != 0)) : n; - - index = slot % num_slots_dl; - LOG_D(NR_MAC, "In %s slots per %s: %d, num_slots %d, index %d\n", - __FUNCTION__, - tdd_config ? "TDD" : "FDD", - num_slots_per_tdd, - num_slots_dl, - index); - } - - if (mac->dl_config_request) return &mac->dl_config_request[index]; + if (mac->dl_config_request) + return &mac->dl_config_request[slot]; else { LOG_E(NR_MAC, "mac->dl_config_request not set\n"); return NULL; @@ -928,7 +891,7 @@ void nr_ue_aperiodic_srs_scheduling(NR_UE_MAC_INST_t *mac, long resource_trigger } int sched_frame = frame + (slot + slot_offset >= n_slots_frame) % 1024; - fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, sched_slot); + fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, sched_slot, slot_offset); fapi_nr_ul_config_srs_pdu *srs_config_pdu = &ul_config->ul_config_list[ul_config->number_pdus].srs_config_pdu; configure_srs_pdu(mac, srs_resource, srs_config_pdu, 0, 0); fill_ul_config(ul_config, sched_frame, sched_slot, FAPI_NR_UL_CONFIG_TYPE_SRS); @@ -981,7 +944,7 @@ bool nr_ue_periodic_srs_scheduling(module_id_t mod_id, frame_t frame, slot_t slo // Check if UE should transmit the SRS if((frame*n_slots_frame+slot-offset)%period == 0) { - fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, slot); + fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, slot, 0); fapi_nr_ul_config_srs_pdu *srs_config_pdu = &ul_config->ul_config_list[ul_config->number_pdus].srs_config_pdu; configure_srs_pdu(mac, srs_resource, srs_config_pdu, period, offset); @@ -1070,7 +1033,7 @@ void nr_ue_ul_scheduler(nr_uplink_indication_t *ul_info) 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); + fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, slot_tx, 0); if (!ul_config) LOG_E(NR_MAC, "mac->ul_config is null!\n"); @@ -2239,7 +2202,7 @@ void nr_ue_pucch_scheduler(module_id_t module_idP, frame_t frameP, int slotP, vo if (num_res > 1) multiplex_pucch_resource(mac, pucch, num_res); - fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, slotP); + fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, slotP, 0); pthread_mutex_lock(&ul_config->mutex_ul_config); for (int j = 0; j < num_res; j++) { if (pucch[j].n_harq + pucch[j].n_sr + pucch[j].n_csi != 0) { @@ -2504,7 +2467,7 @@ void nr_ue_prach_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t s if(ra->ra_state != GENERATE_PREAMBLE) return; - fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, slotP); + fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, slotP, 0); if (!ul_config) { LOG_E(NR_MAC, "mac->ul_config is null! \n"); return; From 9421fcc8b9c75050be273c9b2321a501d4360a6d Mon Sep 17 00:00:00 2001 From: francescomani Date: Tue, 25 Apr 2023 17:05:05 +0200 Subject: [PATCH 3/3] addressing review --- openair1/SIMULATION/NR_PHY/dlsim.c | 5 ++-- openair2/LAYER2/NR_MAC_UE/config_ue.c | 26 ++++++------------- openair2/LAYER2/NR_MAC_UE/mac_proto.h | 6 ++--- openair2/LAYER2/NR_MAC_UE/main_ue_nr.c | 10 ++++++- .../NR_MAC_UE/nr_ue_dci_configuration.c | 5 ++-- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 6 ++--- openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c | 16 +++--------- openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c | 2 +- openair2/RRC/NR_UE/rrc_UE.c | 21 +++++++-------- 9 files changed, 42 insertions(+), 55 deletions(-) diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index 032983644d..76373a2113 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -861,6 +861,7 @@ int main(int argc, char **argv) nr_l2_init_ue(NULL); UE_mac = get_mac_inst(0); + ue_init_config_request(UE_mac, mu); UE->if_inst = nr_ue_if_module_init(0); UE->if_inst->scheduled_response = nr_ue_scheduled_response; @@ -888,8 +889,8 @@ int main(int argc, char **argv) //Configure UE NR_BCCH_BCH_Message_t *mib = get_new_MIB_NR(scc); - nr_rrc_mac_config_req_mib(0, 0, 0, mib->message.choice.mib, false); - nr_rrc_mac_config_req_scg(0, 0, 0, secondaryCellGroup); + nr_rrc_mac_config_req_mib(0, 0, mib->message.choice.mib, false); + nr_rrc_mac_config_req_scg(0, 0, secondaryCellGroup); nr_dcireq_t dcireq; nr_scheduled_response_t scheduled_response; diff --git a/openair2/LAYER2/NR_MAC_UE/config_ue.c b/openair2/LAYER2/NR_MAC_UE/config_ue.c index ebcad5d0de..8bca8819c2 100644 --- a/openair2/LAYER2/NR_MAC_UE/config_ue.c +++ b/openair2/LAYER2/NR_MAC_UE/config_ue.c @@ -693,23 +693,17 @@ void configure_current_BWP(NR_UE_MAC_INST_t *mac, } -void init_config_request(NR_UE_MAC_INST_t *mac) +void ue_init_config_request(NR_UE_MAC_INST_t *mac, int scs) { - if(mac->dl_config_request == NULL && mac->ul_config_request == NULL) { - int scs = mac->mib->subCarrierSpacingCommon; - if(mac->frequency_range == FR2) - scs += 2; - int slots_per_frame = nr_slots_per_frame[scs]; - LOG_I(NR_MAC, "Initializing dl and ul config_request. num_slots = %d\n", slots_per_frame); - mac->dl_config_request = calloc(slots_per_frame, sizeof(*mac->dl_config_request)); - mac->ul_config_request = calloc(slots_per_frame, sizeof(*mac->ul_config_request)); - for (int i = 0; i < slots_per_frame; i++) - pthread_mutex_init(&(mac->ul_config_request[i].mutex_ul_config), NULL); - } + int slots_per_frame = nr_slots_per_frame[scs]; + LOG_I(NR_MAC, "Initializing dl and ul config_request. num_slots = %d\n", slots_per_frame); + mac->dl_config_request = calloc(slots_per_frame, sizeof(*mac->dl_config_request)); + mac->ul_config_request = calloc(slots_per_frame, sizeof(*mac->ul_config_request)); + for (int i = 0; i < slots_per_frame; i++) + pthread_mutex_init(&(mac->ul_config_request[i].mutex_ul_config), NULL); } void nr_rrc_mac_config_req_mib(module_id_t module_id, - uint8_t gNB_index, int cc_idP, NR_MIB_t *mib, bool sched_sib1) @@ -718,7 +712,6 @@ void nr_rrc_mac_config_req_mib(module_id_t module_id, AssertFatal(mib, "MIB should not be NULL\n"); // initialize dl and ul config_request upon first reception of MIB mac->mib = mib; // update by every reception - init_config_request(mac); mac->phy_config.Mod_id = module_id; mac->phy_config.CC_id = cc_idP; mac->get_sib1 = sched_sib1; @@ -726,7 +719,6 @@ void nr_rrc_mac_config_req_mib(module_id_t module_id, void nr_rrc_mac_config_req_sib1(module_id_t module_id, int cc_idP, - uint8_t gNB_index, NR_ServingCellConfigCommonSIB_t *scc) { NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); @@ -745,7 +737,6 @@ void nr_rrc_mac_config_req_sib1(module_id_t module_id, void nr_rrc_mac_config_req_mcg(module_id_t module_id, int cc_idP, - uint8_t gNB_index, NR_CellGroupConfig_t *cell_group_config) { LOG_I(MAC,"Applying CellGroupConfig from gNodeB\n"); @@ -777,7 +768,7 @@ void nr_rrc_mac_config_req_mcg(module_id_t module_id, mac->scc = cell_group_config->spCellConfig->reconfigurationWithSync->spCellConfigCommon; mac->nr_band = *mac->scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0]; if (mac->scc_SIB) { - free(mac->scc_SIB); + ASN_STRUCT_FREE(asn_DEF_NR_ServingCellConfigCommonSIB, mac->scc_SIB); mac->scc_SIB = NULL; } mac->state = UE_NOT_SYNC; @@ -806,7 +797,6 @@ void nr_rrc_mac_config_req_mcg(module_id_t module_id, void nr_rrc_mac_config_req_scg(module_id_t module_id, int cc_idP, - uint8_t gNB_index, NR_CellGroupConfig_t *scell_group_config) { diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index 3be9eb934d..3c4d552827 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -93,23 +93,19 @@ int nr_rrc_mac_config_req_ue_logicalChannelBearer(module_id_t module_id, void nr_rrc_mac_config_req_scg(module_id_t module_id, int cc_idP, - uint8_t gNB_index, NR_CellGroupConfig_t *scell_group_config); void nr_rrc_mac_config_req_mcg(module_id_t module_id, int cc_idP, - uint8_t gNB_index, NR_CellGroupConfig_t *scell_group_config); void nr_rrc_mac_config_req_mib(module_id_t module_id, - uint8_t gNB_index, int cc_idP, NR_MIB_t *mibP, bool sched_sib1); void nr_rrc_mac_config_req_sib1(module_id_t module_id, int cc_idP, - uint8_t gNB_index, NR_ServingCellConfigCommonSIB_t *scc); /**\brief initialization NR UE MAC instance(s), total number of MAC instance based on NB_NR_UE_MAC_INST*/ @@ -425,6 +421,8 @@ void fill_dci_search_candidates(NR_SearchSpace_t *ss,fapi_nr_dl_config_dci_dl_pd void build_ssb_to_ro_map(NR_UE_MAC_INST_t *mac); +void ue_init_config_request(NR_UE_MAC_INST_t *mac, int scs); + void configure_ss_coreset(NR_UE_MAC_INST_t *mac, NR_ServingCellConfig_t *scd, NR_BWP_Id_t dl_bwp_id); diff --git a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c index 78d1b4b0f1..8899be18e6 100644 --- a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c +++ b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c @@ -56,9 +56,17 @@ NR_UE_MAC_INST_t * nr_l2_init_ue(NR_UE_RRC_INST_t* rrc_inst) { for (int j = 0; j < NB_NR_UE_MAC_INST; j++) nr_ue_init_mac(j); + int scs = get_softmodem_params()->sa ? + get_softmodem_params()->numerology : + rrc_inst ? + *rrc_inst->scell_group_config->spCellConfig->reconfigurationWithSync->spCellConfigCommon->ssbSubcarrierSpacing : + - 1; + if (scs > -1) + ue_init_config_request(nr_ue_mac_inst, scs); + if (rrc_inst && rrc_inst->scell_group_config) { - nr_rrc_mac_config_req_scg(0, 0, 0, rrc_inst->scell_group_config); + nr_rrc_mac_config_req_scg(0, 0, rrc_inst->scell_group_config); AssertFatal(rlc_module_init(0) == 0, "%s: Could not initialize RLC layer\n", __FUNCTION__); if (IS_SOFTMODEM_NOS1){ // get default noS1 configuration 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 5aa4438af0..6adaecef41 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c @@ -220,9 +220,8 @@ void config_dci_pdu(NR_UE_MAC_INST_t *mac, fapi_nr_dl_config_dci_dl_pdu_rel15_t rel15->rnti = SI_RNTI; // SI-RNTI - 3GPP TS 38.321 Table 7.1-1: RNTI values - if(mac->frequency_range == FR1) - rel15->SubcarrierSpacing = mac->mib->subCarrierSpacingCommon; - else + rel15->SubcarrierSpacing = mac->mib->subCarrierSpacingCommon; + if(mac->frequency_range == FR2) rel15->SubcarrierSpacing = mac->mib->subCarrierSpacingCommon + 2; break; case NR_RNTI_SFI: diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 8b1582a984..9d32171eb0 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -676,9 +676,9 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fr NR_Type0_PDCCH_CSS_config_t type0_PDCCH_CSS_config = mac->type0_PDCCH_CSS_config; mux_pattern = type0_PDCCH_CSS_config.type0_pdcch_ss_mux_pattern; dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_SI_DLSCH; - if(mac->frequency_range == FR1) - dlsch_config_pdu_1_0->SubcarrierSpacing = mac->mib->subCarrierSpacingCommon; - else + // in MIB SCS is signaled as 15or60 and 30or120 + dlsch_config_pdu_1_0->SubcarrierSpacing = mac->mib->subCarrierSpacingCommon; + if(mac->frequency_range == FR2) dlsch_config_pdu_1_0->SubcarrierSpacing = mac->mib->subCarrierSpacingCommon + 2; if (pdsch_config) pdsch_config->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition = NULL; // For PDSCH with mapping type A, the UE shall assume dmrs-AdditionalPosition='pos2' } else { diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c index 32914b37f9..6545fc945a 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c @@ -118,12 +118,8 @@ fapi_nr_ul_config_request_t *get_ul_config_request(NR_UE_MAC_INST_t *mac, int sl int mu = mac->current_UL_BWP.scs; const int n = nr_slots_per_frame[mu]; AssertFatal(fb_time < n, "Cannot schedule to a slot more than 1 frame away, ul_config_request is not big enough\n"); - if (mac->ul_config_request) - return &mac->ul_config_request[slot]; - else { - LOG_E(NR_MAC, "mac->ul_config_request not set\n"); - return NULL; - } + AssertFatal(mac->ul_config_request != NULL, "mac->ul_config_request not initialized, logic bug\n"); + return &mac->ul_config_request[slot]; } /* @@ -132,12 +128,8 @@ fapi_nr_ul_config_request_t *get_ul_config_request(NR_UE_MAC_INST_t *mac, int sl */ fapi_nr_dl_config_request_t *get_dl_config_request(NR_UE_MAC_INST_t *mac, int slot) { - if (mac->dl_config_request) - return &mac->dl_config_request[slot]; - else { - LOG_E(NR_MAC, "mac->dl_config_request not set\n"); - return NULL; - } + AssertFatal(mac->dl_config_request != NULL, "mac->dl_config_request not initialized, logic bug\n"); + return &mac->dl_config_request[slot]; } void ul_layers_config(NR_UE_MAC_INST_t *mac, nfapi_nr_ue_pusch_pdu_t *pusch_config_pdu, dci_pdu_rel15_t *dci, nr_dci_format_t dci_format) diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c index 187976753d..b9876b6773 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c @@ -1144,7 +1144,6 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info) uint32_t ret_mask = 0x0; module_id_t module_id = dl_info->module_id; NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); - fapi_nr_dl_config_request_t *dl_config = get_dl_config_request(mac, dl_info->slot); if ((!dl_info->dci_ind && !dl_info->rx_ind)) { // UL indication to schedule DCI reception @@ -1179,6 +1178,7 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info) if (ret >= 0) { AssertFatal( nr_ue_if_module_inst[module_id] != NULL, "IF module is NULL!\n" ); AssertFatal( nr_ue_if_module_inst[module_id]->scheduled_response != NULL, "scheduled_response is NULL!\n" ); + fapi_nr_dl_config_request_t *dl_config = get_dl_config_request(mac, dl_info->slot); fill_scheduled_response(&scheduled_response, dl_config, NULL, NULL, dl_info->module_id, dl_info->cc_id, dl_info->frame, dl_info->slot, dl_info->phy_data); nr_ue_if_module_inst[module_id]->scheduled_response(&scheduled_response); } diff --git a/openair2/RRC/NR_UE/rrc_UE.c b/openair2/RRC/NR_UE/rrc_UE.c index 468440a98c..0bffcfdc26 100644 --- a/openair2/RRC/NR_UE/rrc_UE.c +++ b/openair2/RRC/NR_UE/rrc_UE.c @@ -286,8 +286,7 @@ int8_t nr_rrc_ue_process_rrcReconfiguration(const module_id_t module_id, NR_RRCR nr_rrc_ue_process_scg_config(module_id,cellGroupConfig); } if (get_softmodem_params()->nsa) { - nr_rrc_mac_config_req_scg(0, 0, 0, cellGroupConfig); - LOG_D(NR_RRC, "Filled scc now \n"); + nr_rrc_mac_config_req_scg(0, 0, cellGroupConfig); } } else @@ -601,8 +600,8 @@ int8_t nr_rrc_ue_decode_NR_BCCH_BCH_Message(const module_id_t module_id, const u NR_SIB1_t *sib1 = NR_UE_rrc_inst[module_id].sib1[gNB_index]; // if no sib1 because not acquired yet or expired, get a new one - bool get_sib1 = sib1 ? false : true; - nr_rrc_mac_config_req_mib(module_id, gNB_index, 0, NR_UE_rrc_inst[module_id].mib, get_sib1); + bool get_sib1 = sib1 == NULL; + nr_rrc_mac_config_req_mib(module_id, 0, NR_UE_rrc_inst[module_id].mib, get_sib1); ret = 0; } ASN_STRUCT_FREE(asn_DEF_NR_BCCH_BCH_Message, bcch_message); @@ -1212,7 +1211,7 @@ int8_t nr_rrc_ue_decode_NR_BCCH_DL_SCH_Message(module_id_t module_id, } // take ServingCellConfigCommon and configure L1/L2 NR_UE_rrc_inst[module_id].servingCellConfigCommonSIB = sib1->servingCellConfigCommon; - nr_rrc_mac_config_req_sib1(module_id, 0, gNB_index, sib1->servingCellConfigCommon); + nr_rrc_mac_config_req_sib1(module_id, 0, sib1->servingCellConfigCommon); nr_rrc_ue_generate_ra_msg(module_id, gNB_index); } else { LOG_E(NR_RRC, "SIB1 not decoded\n"); @@ -1341,23 +1340,23 @@ void nr_rrc_ue_process_masterCellGroup(const protocol_ctxt_t *const ctxt_pP, sizeof(struct NR_MAC_CellGroupConfig)); } - if( cellGroupConfig->sCellToReleaseList != NULL){ + if(cellGroupConfig->sCellToReleaseList != NULL) { //TODO (perform SCell release as specified in 5.3.5.5.8) } - if( cellGroupConfig->spCellConfig != NULL){ + if(cellGroupConfig->spCellConfig != NULL) { if (NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config && - NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->spCellConfig) { + NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->spCellConfig) { memcpy(NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->spCellConfig,cellGroupConfig->spCellConfig, sizeof(struct NR_SpCellConfig)); } else { if (NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config) - NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->spCellConfig = cellGroupConfig->spCellConfig; + NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->spCellConfig = cellGroupConfig->spCellConfig; else - NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config = cellGroupConfig; + NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config = cellGroupConfig; } LOG_D(RRC,"Sending CellGroupConfig to MAC\n"); - nr_rrc_mac_config_req_mcg(ctxt_pP->module_id, 0, 0, cellGroupConfig); + nr_rrc_mac_config_req_mcg(ctxt_pP->module_id, 0, cellGroupConfig); //TODO (configure the SpCell as specified in 5.3.5.5.7) }