From 548c45a8fc2006b116f315c42a423e6d66282975 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 3 Sep 2021 10:20:24 +0200 Subject: [PATCH] enb,mac_nr: add RAR packing --- srsenb/hdr/stack/mac/mac_nr.h | 3 +- srsenb/hdr/stack/mac/nr/sched_nr_interface.h | 2 +- srsenb/src/stack/mac/nr/mac_nr.cc | 32 ++++++++++++++++++-- srsue/src/stack/mac_nr/mux_nr.cc | 1 + 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/srsenb/hdr/stack/mac/mac_nr.h b/srsenb/hdr/stack/mac/mac_nr.h index 76b0d591e..6b3814ec5 100644 --- a/srsenb/hdr/stack/mac/mac_nr.h +++ b/srsenb/hdr/stack/mac/mac_nr.h @@ -86,6 +86,7 @@ private: // Encoding srsran::byte_buffer_t* assemble_rar(srsran::const_span grants); + srsran::unique_byte_buffer_t rar_pdu_buffer = nullptr; // Interaction with other components phy_interface_stack_nr* phy = nullptr; @@ -124,7 +125,7 @@ private: std::vector bcch_dlsch_payload; srsran::unique_byte_buffer_t bcch_bch_payload = nullptr; - // Number of rach preambles detected for a cc. + // Number of rach preambles detected for a CC std::vector detected_rachs; }; diff --git a/srsenb/hdr/stack/mac/nr/sched_nr_interface.h b/srsenb/hdr/stack/mac/nr/sched_nr_interface.h index b0e7ec713..5669fa815 100644 --- a/srsenb/hdr/stack/mac/nr/sched_nr_interface.h +++ b/srsenb/hdr/stack/mac/nr/sched_nr_interface.h @@ -88,7 +88,7 @@ public: ////// RACH ////// struct dl_sched_rar_info_t { - uint32_t preamble_idx; + uint32_t preamble_idx; // is this the RAPID? uint32_t ofdm_symbol_idx; uint32_t freq_idx; uint32_t ta_cmd; diff --git a/srsenb/src/stack/mac/nr/mac_nr.cc b/srsenb/src/stack/mac/nr/mac_nr.cc index 5320bf9da..081f59569 100644 --- a/srsenb/src/stack/mac/nr/mac_nr.cc +++ b/srsenb/src/stack/mac/nr/mac_nr.cc @@ -16,7 +16,9 @@ #include "srsran/common/log_helper.h" #include "srsran/common/rwlock_guard.h" #include "srsran/common/standard_streams.h" +#include "srsran/common/string_helpers.h" #include "srsran/common/time_prof.h" +#include "srsran/mac/mac_rar_pdu_nr.h" #include #include #include @@ -28,7 +30,8 @@ mac_nr::mac_nr(srsran::task_sched_handle task_sched_, const sched_nr_interface:: logger(srslog::fetch_basic_logger("MAC-NR")), task_sched(task_sched_), sched(sched_cfg), - bcch_bch_payload(srsran::make_byte_buffer()) + bcch_bch_payload(srsran::make_byte_buffer()), + rar_pdu_buffer(srsran::make_byte_buffer()) { stack_task_queue = task_sched.make_task_queue(); } @@ -289,6 +292,7 @@ int mac_nr::get_dl_sched(const srsran_slot_cfg_t& slot_cfg, dl_sched_t& dl_sched } } else if (pdsch.sch.grant.rnti_type == srsran_rnti_type_ra) { sched_nr_interface::sched_rar_t& rar = dl_res.rar[rar_count++]; + // for RARs we could actually move the byte_buffer to the PHY, as there are no retx pdsch.data[0] = assemble_rar(rar.grants); } } @@ -361,7 +365,31 @@ int mac_nr::pusch_info(const srsran_slot_cfg_t& slot_cfg, mac_interface_phy_nr:: srsran::byte_buffer_t* mac_nr::assemble_rar(srsran::const_span grants) { - return nullptr; + srsran::mac_rar_pdu_nr rar_pdu; + + uint32_t pdsch_tbs = 10; // FIXME: how big is the PDSCH? + rar_pdu.init_tx(rar_pdu_buffer.get(), pdsch_tbs); + + for (auto& rar_grant : grants) { + srsran::mac_rar_subpdu_nr& rar_subpdu = rar_pdu.add_subpdu(); + + rar_subpdu.set_ta(rar_grant.data.ta_cmd); + rar_subpdu.set_rapid(rar_grant.data.preamble_idx); + rar_subpdu.set_temp_crnti(rar_grant.data.temp_crnti); + // TODO: where do we get full Msg3 grant data from? + // rar_subpdu.set_ul_grant(msg3_grant); + } + + if (rar_pdu.pack() != SRSRAN_SUCCESS) { + logger.error("Couldn't assemble RAR PDU"); + return nullptr; + } + + fmt::memory_buffer buff; + rar_pdu.to_string(buff); + logger.info("DL %s", srsran::to_c_str(buff)); + + return rar_pdu_buffer.get(); } } // namespace srsenb diff --git a/srsue/src/stack/mac_nr/mux_nr.cc b/srsue/src/stack/mac_nr/mux_nr.cc index d8542f688..dfe3ca7d8 100644 --- a/srsue/src/stack/mac_nr/mux_nr.cc +++ b/srsue/src/stack/mac_nr/mux_nr.cc @@ -13,6 +13,7 @@ #include "srsue/hdr/stack/mac_nr/mux_nr.h" #include "srsran/common/buffer_pool.h" #include "srsran/interfaces/ue_rlc_interfaces.h" + namespace srsue { mux_nr::mux_nr(mac_interface_mux_nr& mac_, srslog::basic_logger& logger_) : mac(mac_), logger(logger_) {}