From 5d8e79521efacbcaad873ce538ed48c1954a1cf2 Mon Sep 17 00:00:00 2001 From: francescomani Date: Tue, 17 Mar 2026 15:58:34 +0100 Subject: [PATCH 1/3] some cleanup and improvements for default PUCCH on gNB --- .../NR_MAC_gNB/gNB_scheduler_primitives.c | 42 +++++++------------ openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 1 - 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c index 20e92f7130..c8979b338d 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c @@ -1287,13 +1287,6 @@ const int default_pucch_numbsymb[] = {2,2,2,2,4,4,4,4,10,10,10,10,14,14,14,14,1 const int default_pucch_prboffset[] = {0,0,3,0,0,2,4,0,0,2,4,0,0,2,4,-1}; const int default_pucch_csset[] = {2,3,3,2,4,4,4,2,4,4,4,2,4,4,4,4}; -int nr_get_default_pucch_res(int pucch_ResourceCommon) { - - AssertFatal(pucch_ResourceCommon>=0 && pucch_ResourceCommon < 16, "illegal pucch_ResourceCommon %d\n",pucch_ResourceCommon); - - return(default_pucch_csset[pucch_ResourceCommon]); -} - void nr_configure_pdcch(nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu, NR_ControlResourceSet_t *coreset, NR_sched_pdcch_t *pdcch) { pdcch_pdu->BWPSize = pdcch->BWPSize; @@ -1543,13 +1536,17 @@ void nr_configure_pucch(nfapi_nr_pucch_pdu_t *pucch_pdu, pucch_pdu->freq_hop_flag = 1; pucch_pdu->second_hop_prb = second_hop_prb; pucch_pdu->format_type = default_pucch_fmt[rsetindex]; - pucch_pdu->initial_cyclic_shift = r_pucch%default_pucch_csset[rsetindex]; - if (rsetindex==3||rsetindex==7||rsetindex==11) pucch_pdu->initial_cyclic_shift*=6; - else if (rsetindex==1||rsetindex==2) pucch_pdu->initial_cyclic_shift*=4; - else pucch_pdu->initial_cyclic_shift*=3; + int initial_cyclic_shift_idx = (r_pucch % 8) % default_pucch_csset[rsetindex]; + if (rsetindex == 3 || rsetindex == 7 || rsetindex == 11) + pucch_pdu->initial_cyclic_shift = initial_cyclic_shift_idx * 6; + else if (rsetindex == 1 || rsetindex == 2) + pucch_pdu->initial_cyclic_shift = initial_cyclic_shift_idx * 4; + else + pucch_pdu->initial_cyclic_shift = initial_cyclic_shift_idx * 3; pucch_pdu->nr_of_symbols = nr_of_symb; pucch_pdu->start_symbol_index = start_symb; - if (pucch_pdu->format_type == 1) pucch_pdu->time_domain_occ_idx = 0; // check this!! + if (pucch_pdu->format_type == 1) + pucch_pdu->time_domain_occ_idx = 0; // check this!! pucch_pdu->sr_flag = O_sr; pucch_pdu->prb_size=1; } @@ -1567,21 +1564,14 @@ void set_r_pucch_parms(int rsetindex, int *prb_start, int *second_hop_prb, int *nr_of_symbols, - int *start_symbol_index) { - + int *start_symbol_index) +{ // procedure described in 38.213 section 9.2.1 - - int prboffset = r_pucch/default_pucch_csset[rsetindex]; - int prboffsetm8 = (r_pucch-8)/default_pucch_csset[rsetindex]; - - *prb_start = (r_pucch>>3)==0 ? - default_pucch_prboffset[rsetindex] + prboffset: - bwp_size-1-default_pucch_prboffset[rsetindex]-prboffsetm8; - - *second_hop_prb = (r_pucch>>3)==0? - bwp_size-1-default_pucch_prboffset[rsetindex]-prboffset: - default_pucch_prboffset[rsetindex] + prboffsetm8; - + int prboffset = (r_pucch % 8) / default_pucch_csset[rsetindex]; + int offset1 = default_pucch_prboffset[rsetindex] + prboffset; + int offset2 = bwp_size - 1 - default_pucch_prboffset[rsetindex] - prboffset; + *prb_start = (r_pucch >> 3) == 0 ? offset1 : offset2; + *second_hop_prb = (r_pucch >> 3) == 0 ? offset2 : offset1; *nr_of_symbols = default_pucch_numbsymb[rsetindex]; *start_symbol_index = default_pucch_firstsymb[rsetindex]; } diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index 433bb4aa32..69658709a7 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -298,7 +298,6 @@ bool add_connected_nr_ue(gNB_MAC_INST *nr_mac, NR_UE_info_t *UE); bool nr_check_Msg4_MsgB_Ack(module_id_t module_id, frame_t frame, slot_t slot, NR_UE_info_t *UE, bool success); void mac_remove_nr_ue(gNB_MAC_INST *nr_mac, rnti_t rnti); NR_UE_info_t *get_new_nr_ue_inst(uid_allocator_t *uia, rnti_t rnti, NR_CellGroupConfig_t *CellGroup, const nr_mac_config_t *config); -int nr_get_default_pucch_res(int pucch_ResourceCommon); nfapi_nr_pusch_pdu_t *prepare_pusch_pdu(nfapi_nr_ul_tti_request_t *future_ul_tti_req, const NR_UE_info_t *UE, const NR_ServingCellConfigCommon_t *scc, From edd761185433d578de45b5309f0f32eb21d1cf3b Mon Sep 17 00:00:00 2001 From: francescomani Date: Tue, 17 Mar 2026 17:03:37 +0100 Subject: [PATCH 2/3] pre-store pucch_ResourceCommon to avoid segfault in scheduling PUCCH at UE (the field in some scenarios was erased by RRCSetup before being used for ACK of MSG4, storing it in advance prevents the segfault) --- openair2/LAYER2/NR_MAC_UE/mac_defs.h | 1 + openair2/LAYER2/NR_MAC_UE/mac_proto.h | 2 +- openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c | 2 ++ openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 11 ++++++----- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index 224887252d..8029235fac 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -293,6 +293,7 @@ typedef struct { int n_CCE; int N_CCE; int initial_pucch_id; + int pucch_ResourceCommon; } PUCCH_sched_t; typedef struct { diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index f4d6d6bda8..e9d8b1b890 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -237,7 +237,7 @@ void nr_ra_succeeded(NR_UE_MAC_INST_t *mac, const frame_t frame, const int slot) void nr_ra_backoff_setting(RA_config_t *ra); void nr_get_RA_window(NR_UE_MAC_INST_t *mac); void prepare_msg4_msgb_feedback(NR_UE_MAC_INST_t *mac, int pid, int ack_nack); -void configure_initial_pucch(PUCCH_sched_t *pucch, int res_ind); +void configure_initial_pucch(PUCCH_sched_t *pucch, int res_ind, long *pucch_ResourceCommon); void release_PUCCH_SRS(NR_UE_MAC_INST_t *mac); void nr_ue_reset_sync_state(NR_UE_MAC_INST_t *mac, bool reconf); void nr_ue_send_synch_request(NR_UE_MAC_INST_t *mac, module_id_t module_id, int cc_id, const fapi_nr_synch_request_t *sync_req); diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c index 78083f8907..8be86c95ad 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c @@ -1199,6 +1199,8 @@ void prepare_msg4_msgb_feedback(NR_UE_MAC_INST_t *mac, int pid, int ack_nack) .n_harq = 1}; current_harq->active = false; current_harq->ack_received = false; + const NR_UE_UL_BWP_t *current_UL_BWP = mac->current_UL_BWP; + configure_initial_pucch(&pucch, current_harq->pucch_resource_indicator, current_UL_BWP->pucch_ConfigCommon->pucch_ResourceCommon); RA_config_t *ra = &mac->ra; ra->ra_pucch = calloc_or_fail(1, sizeof(*ra->ra_pucch)); diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index d6c49d3797..199d364d80 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -1540,8 +1540,7 @@ int nr_ue_configure_pucch(NR_UE_MAC_INST_t *mac, // configure pucch from Table 9.2.1-1 // only for ack/nack if (pucch->initial_pucch_id > -1 && pucch->pucch_resource == NULL) { - const int idx = *current_UL_BWP->pucch_ConfigCommon->pucch_ResourceCommon; - const initial_pucch_resource_t pucch_resourcecommon = get_initial_pucch_resource(idx); + const initial_pucch_resource_t pucch_resourcecommon = get_initial_pucch_resource(pucch->pucch_ResourceCommon); pucch_pdu->format_type = pucch_resourcecommon.format; pucch_pdu->start_symbol_index = pucch_resourcecommon.startingSymbolIndex; pucch_pdu->nr_of_symbols = pucch_resourcecommon.nrofSymbols; @@ -1551,7 +1550,7 @@ int nr_ue_configure_pucch(NR_UE_MAC_INST_t *mac, pucch_pdu->prb_size = 1; // format 0 or 1 int RB_BWP_offset; - if (pucch->initial_pucch_id == 15) + if (pucch->pucch_ResourceCommon == 15) RB_BWP_offset = pucch_pdu->bwp_size >> 2; else RB_BWP_offset = pucch_resourcecommon.PRB_offset; @@ -2269,7 +2268,7 @@ void multiplex_pucch_resource(NR_UE_MAC_INST_t *mac, PUCCH_sched_t *pucch, int n } } -void configure_initial_pucch(PUCCH_sched_t *pucch, int res_ind) +void configure_initial_pucch(PUCCH_sched_t *pucch, int res_ind, long *pucch_ResourceCommon) { /* see TS 38.213 9.2.1 PUCCH Resource Sets */ int delta_PRI = res_ind; @@ -2280,6 +2279,8 @@ void configure_initial_pucch(PUCCH_sched_t *pucch, int res_ind) int r_PUCCH = ((2 * n_CCE_0) / N_CCE_0) + (2 * delta_PRI); pucch->initial_pucch_id = r_PUCCH; pucch->pucch_resource = NULL; + AssertFatal(pucch_ResourceCommon, "pucch_ResourceCommon NULL\n"); + pucch->pucch_ResourceCommon = *pucch_ResourceCommon; } /******************************************************************* @@ -2468,7 +2469,7 @@ bool get_downlink_ack(NR_UE_MAC_INST_t *mac, frame_t frame, int slot, PUCCH_sche NR_PUCCH_Config_t *pucch_Config = current_UL_BWP ? current_UL_BWP->pucch_Config : NULL; if (!(pucch_Config && pucch_Config->resourceSetToAddModList && pucch_Config->resourceSetToAddModList->list.array[0])) - configure_initial_pucch(pucch, res_ind); + configure_initial_pucch(pucch, res_ind, current_UL_BWP->pucch_ConfigCommon->pucch_ResourceCommon); else { int resource_set_id = find_pucch_resource_set(pucch_Config, O_ACK); int n_list = pucch_Config->resourceSetToAddModList->list.count; From dfed62bd24c8255d22f2061e716fff957fe8a6c5 Mon Sep 17 00:00:00 2001 From: Bartosz Podrygajlo Date: Mon, 30 Mar 2026 10:29:32 +0200 Subject: [PATCH 3/3] Better stubs for test_nr_ue_ra_procedures --- .../LAYER2/NR_MAC_UE/tests/CMakeLists.txt | 2 +- .../tests/test_nr_ue_ra_procedures.cpp | 63 ++++++++++++++----- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_UE/tests/CMakeLists.txt b/openair2/LAYER2/NR_MAC_UE/tests/CMakeLists.txt index 6dcad6fad8..406129c0aa 100644 --- a/openair2/LAYER2/NR_MAC_UE/tests/CMakeLists.txt +++ b/openair2/LAYER2/NR_MAC_UE/tests/CMakeLists.txt @@ -8,7 +8,7 @@ add_test(NAME test_nr_ue_power_procedures COMMAND ./test_nr_ue_power_procedures) add_executable(test_nr_ue_ra_procedures test_nr_ue_ra_procedures.cpp) -target_link_libraries(test_nr_ue_ra_procedures PRIVATE nr_ue_ra_procedures nr_ue_power_procedures GTest::gtest minimal_lib) +target_link_libraries(test_nr_ue_ra_procedures PRIVATE nr_ue_ra_procedures nr_ue_power_procedures GTest::gtest minimal_lib MAC_UE_NR) add_dependencies(tests test_nr_ue_ra_procedures) add_test(NAME test_nr_ue_ra_procedures COMMAND ./test_nr_ue_ra_procedures) diff --git a/openair2/LAYER2/NR_MAC_UE/tests/test_nr_ue_ra_procedures.cpp b/openair2/LAYER2/NR_MAC_UE/tests/test_nr_ue_ra_procedures.cpp index 47c7ad4027..ae79c87aee 100644 --- a/openair2/LAYER2/NR_MAC_UE/tests/test_nr_ue_ra_procedures.cpp +++ b/openair2/LAYER2/NR_MAC_UE/tests/test_nr_ue_ra_procedures.cpp @@ -6,6 +6,8 @@ extern "C" { #include "openair2/LAYER2/NR_MAC_UE/mac_proto.h" #include "executables/softmodem-common.h" +#include "openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h" +#include "common/utils/ocp_itti/intertask_interface.h" static softmodem_params_t softmodem_params; softmodem_params_t *get_softmodem_params(void) @@ -18,7 +20,13 @@ void nr_mac_rrc_ra_ind(const module_id_t mod_id, bool success) void nr_mac_rrc_msg3_ind(const module_id_t mod_id, const int rnti, bool prepare_payload) { } -tbs_size_t nr_mac_rlc_data_req(const module_id_t module_idP, +void nr_mac_rlc_status_ind(uint16_t ue_id, frame_t frame, int n_ch, const logical_chan_id_t *ch, mac_rlc_status_resp_t *ret) +{ +} +void nr_mac_rrc_inactivity_timer_ind(const module_id_t mod_id) +{ +} +tbs_size_t nr_mac_rlc_data_req(const module_id_t module_idP, const uint16_t ue_id, const bool gnb_flagP, const logical_chan_id_t channel_idP, @@ -27,32 +35,55 @@ tbs_size_t nr_mac_rlc_data_req(const module_id_t module_idP, { return 0; } -fapi_nr_ul_config_request_pdu_t *lockGet_ul_config(NR_UE_MAC_INST_t *mac, frame_t frame_tx, int slot_tx, uint8_t pdu_type) -{ - return nullptr; -} -void release_ul_config(fapi_nr_ul_config_request_pdu_t *configPerSlot, bool clearIt) +void nr_mac_rlc_data_ind(const module_id_t module_idP, + const uint16_t ue_id, + const bool gnb_flagP, + const nr_rlc_data_ind_t *data, + int num_data) { } -void remove_ul_config_last_item(fapi_nr_ul_config_request_pdu_t *pdu) + +bool nr_rlc_activate_srb0(int ue_id, + void *data, + void (*send_initial_ul_rrc_message)(int ue_id, const uint8_t *sdu, sdu_size_t sdu_len, void *data)) { + return true; } -int nr_ue_configure_pucch(NR_UE_MAC_INST_t *mac, - int slot, - frame_t frame, - uint16_t rnti, - PUCCH_sched_t *pucch, - fapi_nr_ul_config_pucch_pdu *pucch_pdu) +int nr_rlc_module_init(nr_rlc_op_mode_t mode) { return 0; } -NR_UE_DL_BWP_t *get_dl_bwp_structure(NR_UE_MAC_INST_t *mac, int bwp_id, bool setup) +MessageDef *itti_alloc_new_message(task_id_t origin_task_id, instance_t originInstance, MessagesIds message_id) { return NULL; } -NR_UE_UL_BWP_t *get_ul_bwp_structure(NR_UE_MAC_INST_t *mac, int bwp_id, bool setup) +int itti_send_msg_to_task(task_id_t task_id, instance_t instance, MessageDef *message) +{ + return 0; +} +typedef uint32_t channel_t; +int8_t nr_mac_rrc_data_ind_ue(const module_id_t module_id, + const int CC_id, + const uint8_t gNB_index, + const int hfn, + const frame_t frame, + const int slot, + const rnti_t rnti, + const uint32_t cellid, + const long arfcn, + const channel_t channel, + const uint8_t *pduP, + const sdu_size_t pdu_len) +{ + return 0; +} +void nr_mac_rrc_meas_ind_ue(module_id_t module_id, + uint32_t gNB_index, + uint16_t Nid_cell, + bool csi_meas, + bool is_neighboring_cell, + int rsrp_dBm) { - return NULL; } } #include