Skip to content

Commit

Permalink
Merge branch 'next' into agpl_next
Browse files Browse the repository at this point in the history
  • Loading branch information
srs-codebot committed Jan 31, 2024
2 parents eea87b1 + f8978a6 commit ec29b0c
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 68 deletions.
2 changes: 2 additions & 0 deletions lib/include/srsran/interfaces/mac_interface_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ struct rach_cfg_nr_t {
uint32_t powerRampingStep;
uint32_t ra_responseWindow;
uint32_t ra_ContentionResolutionTimer;
uint32_t nof_preambles;

rach_cfg_nr_t() { reset(); }
void reset()
Expand All @@ -149,6 +150,7 @@ struct rach_cfg_nr_t {
powerRampingStep = 0;
preambleTransMax = 0;
ra_responseWindow = 0;
nof_preambles = 0;
}
};

Expand Down
4 changes: 4 additions & 0 deletions lib/src/asn1/rrc_nr_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ void make_mac_rach_cfg(const rach_cfg_common_s& asn1_type, rach_cfg_nr_t* rach_c
rach_cfg_nr->PreambleReceivedTargetPower = asn1_type.rach_cfg_generic.preamb_rx_target_pwr;
rach_cfg_nr->preambleTransMax = asn1_type.rach_cfg_generic.preamb_trans_max.to_number();
rach_cfg_nr->ra_ContentionResolutionTimer = asn1_type.ra_contention_resolution_timer.to_number();

if (asn1_type.total_nof_ra_preambs_present) {
rach_cfg_nr->nof_preambles = asn1_type.total_nof_ra_preambs;
}
};

int make_rlc_config_t(const rlc_cfg_c& asn1_type, uint8_t bearer_id, rlc_config_t* cfg_out)
Expand Down
8 changes: 5 additions & 3 deletions lib/src/mac/mac_rar_pdu_nr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,22 +290,24 @@ bool mac_rar_pdu_nr::unpack(const uint8_t* payload, const uint32_t& len)
bool ret = false;
bool have_more_subpdus = false;
uint32_t offset = 0;
bool success = false;

remaining_len = len;

do {
mac_rar_subpdu_nr rar_subpdu(this);
ret = rar_subpdu.read_subpdu(payload + offset);
success = rar_subpdu.read_subpdu(payload + offset);
have_more_subpdus = rar_subpdu.has_more_subpdus();
offset += rar_subpdu.get_total_length();
remaining_len -= rar_subpdu.get_total_length();

// only append if subPDU could be read successfully
if (ret == true) {
if (success == true) {
subpdus.push_back(rar_subpdu);
}
ret |= success;
// continue reading as long as subPDUs can be extracted ok and we are not overrunning the PDU length
} while (ret && have_more_subpdus && offset <= len);
} while (success && have_more_subpdus && offset <= len);

return ret;
}
Expand Down
25 changes: 16 additions & 9 deletions srsue/hdr/stack/mac_nr/demux_nr.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@

namespace srsue {

class mac_nr_interface_demux
{
public:
virtual bool received_contention_id(uint64_t id) = 0;
};

/**
* @brief Logical Channel Demultiplexing and MAC CE dissassemble according to TS 38.321
*
Expand All @@ -45,25 +51,26 @@ class demux_nr : public demux_interface_harq_nr
demux_nr(srslog::basic_logger& logger_);
~demux_nr();

int32_t init(rlc_interface_mac* rlc_, phy_interface_mac_nr* phy_);
int32_t init(rlc_interface_mac* rlc_, phy_interface_mac_nr* phy_, mac_nr_interface_demux* mac_);

void process_pdus(); /// Called by MAC to process received PDUs

// HARQ interface
void push_bcch(srsran::unique_byte_buffer_t pdu);
void push_pdu(srsran::unique_byte_buffer_t pdu, uint32_t tti);
void push_pdu_temp_crnti(srsran::unique_byte_buffer_t pdu, uint32_t tti);
uint64_t get_received_crueid();
void push_bcch(srsran::unique_byte_buffer_t pdu);
void push_pdu(srsran::unique_byte_buffer_t pdu, uint32_t tti);
void push_pdu_temp_crnti(srsran::unique_byte_buffer_t pdu, uint32_t tti);
bool get_uecrid_successful();

private:
// internal helpers
void handle_pdu(srsran::mac_sch_pdu_nr& pdu_buffer, srsran::unique_byte_buffer_t pdu);

srslog::basic_logger& logger;
rlc_interface_mac* rlc = nullptr;
phy_interface_mac_nr* phy = nullptr;
srslog::basic_logger& logger;
rlc_interface_mac* rlc = nullptr;
phy_interface_mac_nr* phy = nullptr;
mac_nr_interface_demux* mac = nullptr;

uint64_t received_crueid = 0;
bool is_uecrid_successful = false;

///< currently only DCH & BCH PDUs supported (add PCH, etc)
srsran::block_queue<srsran::unique_byte_buffer_t> pdu_queue;
Expand Down
7 changes: 5 additions & 2 deletions srsue/hdr/stack/mac_nr/mac_nr.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class mac_nr final : public mac_interface_phy_nr,
public mac_interface_proc_ra_nr,
public mac_interface_sr_nr,
public mac_interface_mux_nr,
public mac_interface_harq_nr
public mac_interface_harq_nr,
public mac_nr_interface_demux
{
public:
mac_nr(srsran::ext_task_sched_handle task_sched_);
Expand Down Expand Up @@ -97,7 +98,6 @@ class mac_nr final : public mac_interface_phy_nr,
void start_ra_procedure();

/// Interface for internal procedures (RA, MUX, HARQ)
bool received_contention_id(uint64_t rx_contention_id);
uint16_t get_crnti();
uint16_t get_temp_crnti();
uint16_t get_csrnti() { return SRSRAN_INVALID_RNTI; }; // SPS not supported
Expand All @@ -111,6 +111,9 @@ class mac_nr final : public mac_interface_phy_nr,
srsran::mac_sch_subpdu_nr::lcg_bsr_t generate_sbsr();
void set_padding_bytes(uint32_t nof_bytes);

/// Interface for DEMUX
bool received_contention_id(uint64_t rx_contention_id);

void msg3_flush() { mux.msg3_flush(); }
bool msg3_is_transmitted() { return mux.msg3_is_transmitted(); }
void msg3_prepare() { mux.msg3_prepare(); }
Expand Down
15 changes: 6 additions & 9 deletions srsue/hdr/stack/mac_nr/mac_nr_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class mac_interface_proc_ra_nr
{
public:
// Functions for identity handling, e.g., contention id and c-rnti
virtual uint16_t get_crnti() = 0;
virtual bool set_crnti(uint16_t c_rnti) = 0;
virtual uint16_t get_crnti() = 0;
virtual bool set_crnti(uint16_t c_rnti) = 0;
virtual void set_temp_crnti(uint16_t c_rnti) = 0;
virtual void set_crnti_to_temp() = 0;

Expand Down Expand Up @@ -90,9 +90,6 @@ class mac_interface_harq_nr
// MAC also provides Temp C-RNTI (through RA proc)
virtual uint16_t get_temp_crnti() = 0;

// HARQ can query MAC for current C-RNTI
virtual bool received_contention_id(uint64_t rx_contention_id) = 0;

// MAC provides the Currently Scheduled RNTI (for SPS)
virtual uint16_t get_csrnti() = 0;
};
Expand All @@ -104,10 +101,10 @@ class demux_interface_harq_nr
{
public:
/// Inform demux unit about a newly decoded TB.
virtual void push_bcch(srsran::unique_byte_buffer_t pdu) = 0;
virtual void push_pdu(srsran::unique_byte_buffer_t pdu, uint32_t tti) = 0;
virtual void push_pdu_temp_crnti(srsran::unique_byte_buffer_t pdu, uint32_t tti) = 0;
virtual uint64_t get_received_crueid() = 0;
virtual void push_bcch(srsran::unique_byte_buffer_t pdu) = 0;
virtual void push_pdu(srsran::unique_byte_buffer_t pdu, uint32_t tti) = 0;
virtual void push_pdu_temp_crnti(srsran::unique_byte_buffer_t pdu, uint32_t tti) = 0;
virtual bool get_uecrid_successful() = 0;
};

} // namespace srsue
Expand Down
2 changes: 2 additions & 0 deletions srsue/hdr/stack/mac_nr/mux_nr.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class mux_nr final : mux_base, public mux_interface_bsr_nr
bool msg3_is_transmitted();
bool msg3_is_pending();
bool msg3_is_empty();
srsran::unique_byte_buffer_t get_msg3(uint32_t max_pdu_len);

// MAC interface
int setup_lcid(const srsran::logical_channel_config_t& config);
Expand All @@ -60,6 +61,7 @@ class mux_nr final : mux_base, public mux_interface_bsr_nr

private:
// internal helper methods
srsran::unique_byte_buffer_t pdu_get_nolock(uint32_t max_pdu_len);

// ctor configured members
mac_interface_mux_nr& mac;
Expand Down
10 changes: 6 additions & 4 deletions srsue/hdr/stack/mac_nr/proc_ra_nr.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class proc_ra_nr
{
public:
proc_ra_nr(mac_interface_proc_ra_nr& mac_, srslog::basic_logger& logger_);
~proc_ra_nr(){};
~proc_ra_nr() { srsran_random_free(random_gen); };

void init(phy_interface_mac_nr* phy_h_, srsran::ext_task_sched_handle* task_sched_);
void set_config(const srsran::rach_cfg_nr_t& rach_cfg_nr);
Expand Down Expand Up @@ -66,8 +66,10 @@ class proc_ra_nr
16 * 10; ///< Limited from frame system number opportunity period in TS 38.211 tables 6.3.3.2-2, 6.3.3.2-3
///< and 6.3.3.2-4

mac_interface_proc_ra_nr& mac;
srslog::basic_logger& logger;
mac_interface_proc_ra_nr& mac;
srslog::basic_logger& logger;
srsran_random_t random_gen;

phy_interface_mac_nr* phy = nullptr;
srsran::ext_task_sched_handle* task_sched = nullptr;
srsran::task_multiqueue::queue_handle task_queue;
Expand Down Expand Up @@ -120,7 +122,7 @@ class proc_ra_nr
void ra_resource_selection();
void ra_preamble_transmission();
void ra_response_reception(const mac_interface_phy_nr::tb_action_dl_result_t& tb);
void ra_contention_resolution(bool received_con_res_matches_ue_id);
void ra_contention_resolution(bool is_successful, bool is_ul_grant);
void ra_completion();
void ra_error();
};
Expand Down
2 changes: 2 additions & 0 deletions srsue/hdr/stack/rrc_nr/rrc_nr.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ class rrc_nr final : public rrc_interface_phy_nr,
bool running = false;
srsran::block_queue<cmd_msg_t> cmd_q;

srsran_random_t random_gen;

// PHY config
srsran::phy_cfg_nr_t phy_cfg = {};

Expand Down
5 changes: 5 additions & 0 deletions srsue/src/phy/nr/cc_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ bool cc_worker::decode_pdsch_dl()
mac_dl_grant.tti = dl_slot_cfg.idx;
phy.stack->new_grant_dl(0, mac_dl_grant, &dl_action);

// check if RA-RNTI, if true reset HARQ buffers
if (pdsch_cfg.grant.rnti_type == srsran_rnti_type_ra && dl_action.tb.softbuffer != nullptr) {
srsran_softbuffer_rx_reset(dl_action.tb.softbuffer);
}

// Abort if MAC says it doesn't need the TB
if (not dl_action.tb.enabled) {
// Force positive ACK
Expand Down
23 changes: 15 additions & 8 deletions srsue/src/stack/mac_nr/demux_nr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ demux_nr::demux_nr(srslog::basic_logger& logger_) : logger(logger_) {}

demux_nr::~demux_nr() {}

int32_t demux_nr::init(rlc_interface_mac* rlc_, phy_interface_mac_nr* phy_)
int32_t demux_nr::init(rlc_interface_mac* rlc_, phy_interface_mac_nr* phy_, mac_nr_interface_demux* mac_)
{
rlc = rlc_;
phy = phy_;
mac = mac_;
return SRSRAN_SUCCESS;
}

uint64_t demux_nr::get_received_crueid()
bool demux_nr::get_uecrid_successful()
{
return received_crueid;
return is_uecrid_successful;
}

// Enqueues PDU and returns quickly
Expand All @@ -64,7 +65,7 @@ void demux_nr::push_bcch(srsran::unique_byte_buffer_t pdu)
*/
void demux_nr::push_pdu_temp_crnti(srsran::unique_byte_buffer_t pdu, uint32_t tti)
{
received_crueid = 0;
is_uecrid_successful = false;
handle_pdu(rx_pdu_tcrnti, std::move(pdu));
}

Expand Down Expand Up @@ -99,6 +100,7 @@ void demux_nr::handle_pdu(srsran::mac_sch_pdu_nr& pdu_buffer, srsran::unique_byt
logger.info("%s", srsran::to_c_str(str_buffer));
}

bool con_res_rxed = false;
for (uint32_t i = 0; i < pdu_buffer.get_num_subpdus(); ++i) {
srsran::mac_sch_subpdu_nr subpdu = pdu_buffer.get_subpdu(i);
logger.debug("Handling subPDU %d/%d: rnti=0x%x lcid=%d, sdu_len=%d",
Expand All @@ -108,7 +110,7 @@ void demux_nr::handle_pdu(srsran::mac_sch_pdu_nr& pdu_buffer, srsran::unique_byt
subpdu.get_lcid(),
subpdu.get_sdu_length());

// Handle Timing Advance CE
// Handle Contention Resolution UE ID and Timing Advance CE
switch (subpdu.get_lcid()) {
case srsran::mac_sch_subpdu_nr::nr_lcid_sch_t::DRX_CMD:
logger.info("DRX CE not implemented.");
Expand All @@ -118,12 +120,17 @@ void demux_nr::handle_pdu(srsran::mac_sch_pdu_nr& pdu_buffer, srsran::unique_byt
phy->set_timeadv(0, subpdu.get_ta().ta_command);
break;
case srsran::mac_sch_subpdu_nr::nr_lcid_sch_t::CON_RES_ID:
received_crueid = subpdu.get_ue_con_res_id_ce_packed();
con_res_rxed = true;
logger.info("Received Contention Resolution ID 0x%lx", subpdu.get_ue_con_res_id_ce_packed());
if (!is_uecrid_successful) {
is_uecrid_successful = mac->received_contention_id(subpdu.get_ue_con_res_id_ce_packed());
}
break;
default:
if (subpdu.is_sdu()) {
rlc->write_pdu(subpdu.get_lcid(), subpdu.get_sdu(), subpdu.get_sdu_length());
if (!con_res_rxed or (con_res_rxed and is_uecrid_successful)) {
if (subpdu.is_sdu()) {
rlc->write_pdu(subpdu.get_lcid(), subpdu.get_sdu(), subpdu.get_sdu_length());
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion srsue/src/stack/mac_nr/dl_harq_nr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ void dl_harq_entity_nr::dl_harq_process_nr::tb_decoded(const mac_nr_grant_dl_t&
logger.debug("Delivering PDU=%d bytes to Dissassemble and Demux unit (Temporal C-RNTI) not implemented",
grant.tbs);
harq_entity->demux_unit->push_pdu_temp_crnti(std::move(result.payload), grant.tti);
result.ack = harq_entity->mac->received_contention_id(harq_entity->demux_unit->get_received_crueid());
result.ack = harq_entity->demux_unit->get_uecrid_successful();
if (not result.ack) {
reset();
}
} else {
logger.debug("Delivering PDU=%d bytes to Dissassemble and Demux unit", grant.tbs);
harq_entity->demux_unit->push_pdu(std::move(result.payload), grant.tti);
Expand Down
8 changes: 2 additions & 6 deletions srsue/src/stack/mac_nr/mac_nr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int mac_nr::init(const mac_nr_args_t& args_,
return SRSRAN_ERROR;
}

if (demux.init(rlc, phy) != SRSRAN_SUCCESS) {
if (demux.init(rlc, phy, this) != SRSRAN_SUCCESS) {
logger.error("Couldn't initialize demux unit.");
return SRSRAN_ERROR;
}
Expand Down Expand Up @@ -358,11 +358,6 @@ void mac_nr::tb_decoded(const uint32_t cc_idx, const mac_nr_grant_dl_t& grant, t

dl_harq.at(cc_idx)->tb_decoded(grant, std::move(result));
}

// If proc ra is in contention resolution (RA connection request procedure)
if (proc_ra.is_contention_resolution() && grant.rnti == rntis.get_temp_rnti()) {
proc_ra.received_contention_resolution(contention_res_successful);
}
}

void mac_nr::new_grant_ul(const uint32_t cc_idx, const mac_nr_grant_ul_t& grant, tb_action_ul_t* action)
Expand Down Expand Up @@ -575,6 +570,7 @@ void mac_nr::process_pdus()
bool mac_nr::received_contention_id(uint64_t rx_contention_id)
{
contention_res_successful = rntis.get_contention_id() == rx_contention_id;
proc_ra.received_contention_resolution(contention_res_successful);
return contention_res_successful;
}

Expand Down
34 changes: 30 additions & 4 deletions srsue/src/stack/mac_nr/mux_nr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ int mux_nr::setup_lcid(const srsran::logical_channel_config_t& config)
return mux_base::setup_lcid(config);
}

srsran::unique_byte_buffer_t mux_nr::get_pdu(uint32_t max_pdu_len)
srsran::unique_byte_buffer_t mux_nr::pdu_get_nolock(uint32_t max_pdu_len)
{
// Lock MAC PDU from current access from PHY workers (will be moved to UL HARQ)
std::lock_guard<std::mutex> lock(mutex);

// initialize MAC PDU
srsran::unique_byte_buffer_t phy_tx_pdu = srsran::make_byte_buffer();
if (phy_tx_pdu == nullptr) {
Expand Down Expand Up @@ -199,6 +196,35 @@ bool mux_nr::msg3_is_empty()
return msg3_buff->N_bytes == 0;
}

srsran::unique_byte_buffer_t mux_nr::get_pdu(uint32_t max_pdu_len)
{
// Lock MAC PDU from current access from PHY workers (will be moved to UL HARQ)
std::lock_guard<std::mutex> lock(mutex);
return pdu_get_nolock(max_pdu_len);
}

srsran::unique_byte_buffer_t mux_nr::get_msg3(uint32_t max_pdu_len)
{
// Lock MAC PDU from current access from PHY workers (will be moved to UL HARQ)
std::lock_guard<std::mutex> lock(mutex);
srsran::unique_byte_buffer_t phy_tx_pdu = srsran::make_byte_buffer();

if (max_pdu_len < msg3_buff->get_tailroom()) {
if (msg3_is_empty()) {
msg3_buff = pdu_get_nolock(max_pdu_len);
if (msg3_buff == nullptr) {
logger.error("Moving PDU from Mux unit to Msg3 buffer");
return NULL;
}
}
*phy_tx_pdu = *msg3_buff;
return phy_tx_pdu;
} else {
logger.error("Msg3 size exceeds buffer");
return nullptr;
}
}

void mux_nr::generate_bsr_mac_ce(const srsran::bsr_format_nr_t& format)
{
switch (format) {
Expand Down
Loading

0 comments on commit ec29b0c

Please sign in to comment.