Skip to content

Commit 9b024ee

Browse files
committed
ue,mac,ra: fix contention resolution procedure
1 parent 376e835 commit 9b024ee

File tree

8 files changed

+73
-52
lines changed

8 files changed

+73
-52
lines changed

srsue/hdr/stack/mac_nr/demux_nr.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020

2121
namespace srsue {
2222

23+
class mac_nr_interface_demux
24+
{
25+
public:
26+
virtual bool received_contention_id(uint64_t id) = 0;
27+
};
28+
2329
/**
2430
* @brief Logical Channel Demultiplexing and MAC CE dissassemble according to TS 38.321
2531
*
@@ -36,25 +42,26 @@ class demux_nr : public demux_interface_harq_nr
3642
demux_nr(srslog::basic_logger& logger_);
3743
~demux_nr();
3844

39-
int32_t init(rlc_interface_mac* rlc_, phy_interface_mac_nr* phy_);
45+
int32_t init(rlc_interface_mac* rlc_, phy_interface_mac_nr* phy_, mac_nr_interface_demux* mac_);
4046

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

4349
// HARQ interface
44-
void push_bcch(srsran::unique_byte_buffer_t pdu);
45-
void push_pdu(srsran::unique_byte_buffer_t pdu, uint32_t tti);
46-
void push_pdu_temp_crnti(srsran::unique_byte_buffer_t pdu, uint32_t tti);
47-
uint64_t get_received_crueid();
50+
void push_bcch(srsran::unique_byte_buffer_t pdu);
51+
void push_pdu(srsran::unique_byte_buffer_t pdu, uint32_t tti);
52+
void push_pdu_temp_crnti(srsran::unique_byte_buffer_t pdu, uint32_t tti);
53+
bool get_uecrid_successful();
4854

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

53-
srslog::basic_logger& logger;
54-
rlc_interface_mac* rlc = nullptr;
55-
phy_interface_mac_nr* phy = nullptr;
59+
srslog::basic_logger& logger;
60+
rlc_interface_mac* rlc = nullptr;
61+
phy_interface_mac_nr* phy = nullptr;
62+
mac_nr_interface_demux* mac = nullptr;
5663

57-
uint64_t received_crueid = 0;
64+
bool is_uecrid_successful = false;
5865

5966
///< currently only DCH & BCH PDUs supported (add PCH, etc)
6067
srsran::block_queue<srsran::unique_byte_buffer_t> pdu_queue;

srsue/hdr/stack/mac_nr/mac_nr.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class mac_nr final : public mac_interface_phy_nr,
3939
public mac_interface_proc_ra_nr,
4040
public mac_interface_sr_nr,
4141
public mac_interface_mux_nr,
42-
public mac_interface_harq_nr
42+
public mac_interface_harq_nr,
43+
public mac_nr_interface_demux
4344
{
4445
public:
4546
mac_nr(srsran::ext_task_sched_handle task_sched_);
@@ -88,7 +89,6 @@ class mac_nr final : public mac_interface_phy_nr,
8889
void start_ra_procedure();
8990

9091
/// Interface for internal procedures (RA, MUX, HARQ)
91-
bool received_contention_id(uint64_t rx_contention_id);
9292
uint16_t get_crnti();
9393
uint16_t get_temp_crnti();
9494
uint16_t get_csrnti() { return SRSRAN_INVALID_RNTI; }; // SPS not supported
@@ -102,6 +102,9 @@ class mac_nr final : public mac_interface_phy_nr,
102102
srsran::mac_sch_subpdu_nr::lcg_bsr_t generate_sbsr();
103103
void set_padding_bytes(uint32_t nof_bytes);
104104

105+
/// Interface for DEMUX
106+
bool received_contention_id(uint64_t rx_contention_id);
107+
105108
void msg3_flush() { mux.msg3_flush(); }
106109
bool msg3_is_transmitted() { return mux.msg3_is_transmitted(); }
107110
void msg3_prepare() { mux.msg3_prepare(); }

srsue/hdr/stack/mac_nr/mac_nr_interfaces.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class mac_interface_proc_ra_nr
2424
{
2525
public:
2626
// Functions for identity handling, e.g., contention id and c-rnti
27-
virtual uint16_t get_crnti() = 0;
28-
virtual bool set_crnti(uint16_t c_rnti) = 0;
27+
virtual uint16_t get_crnti() = 0;
28+
virtual bool set_crnti(uint16_t c_rnti) = 0;
2929
virtual void set_temp_crnti(uint16_t c_rnti) = 0;
3030
virtual void set_crnti_to_temp() = 0;
3131

@@ -81,9 +81,6 @@ class mac_interface_harq_nr
8181
// MAC also provides Temp C-RNTI (through RA proc)
8282
virtual uint16_t get_temp_crnti() = 0;
8383

84-
// HARQ can query MAC for current C-RNTI
85-
virtual bool received_contention_id(uint64_t rx_contention_id) = 0;
86-
8784
// MAC provides the Currently Scheduled RNTI (for SPS)
8885
virtual uint16_t get_csrnti() = 0;
8986
};
@@ -95,10 +92,10 @@ class demux_interface_harq_nr
9592
{
9693
public:
9794
/// Inform demux unit about a newly decoded TB.
98-
virtual void push_bcch(srsran::unique_byte_buffer_t pdu) = 0;
99-
virtual void push_pdu(srsran::unique_byte_buffer_t pdu, uint32_t tti) = 0;
100-
virtual void push_pdu_temp_crnti(srsran::unique_byte_buffer_t pdu, uint32_t tti) = 0;
101-
virtual uint64_t get_received_crueid() = 0;
95+
virtual void push_bcch(srsran::unique_byte_buffer_t pdu) = 0;
96+
virtual void push_pdu(srsran::unique_byte_buffer_t pdu, uint32_t tti) = 0;
97+
virtual void push_pdu_temp_crnti(srsran::unique_byte_buffer_t pdu, uint32_t tti) = 0;
98+
virtual bool get_uecrid_successful() = 0;
10299
};
103100

104101
} // namespace srsue

srsue/hdr/stack/mac_nr/proc_ra_nr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class proc_ra_nr
113113
void ra_resource_selection();
114114
void ra_preamble_transmission();
115115
void ra_response_reception(const mac_interface_phy_nr::tb_action_dl_result_t& tb);
116-
void ra_contention_resolution(bool received_con_res_matches_ue_id);
116+
void ra_contention_resolution(bool is_successful, bool is_ul_grant);
117117
void ra_completion();
118118
void ra_error();
119119
};

srsue/src/stack/mac_nr/demux_nr.cc

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ demux_nr::demux_nr(srslog::basic_logger& logger_) : logger(logger_) {}
2121

2222
demux_nr::~demux_nr() {}
2323

24-
int32_t demux_nr::init(rlc_interface_mac* rlc_, phy_interface_mac_nr* phy_)
24+
int32_t demux_nr::init(rlc_interface_mac* rlc_, phy_interface_mac_nr* phy_, mac_nr_interface_demux* mac_)
2525
{
2626
rlc = rlc_;
2727
phy = phy_;
28+
mac = mac_;
2829
return SRSRAN_SUCCESS;
2930
}
3031

31-
uint64_t demux_nr::get_received_crueid()
32+
bool demux_nr::get_uecrid_successful()
3233
{
33-
return received_crueid;
34+
return is_uecrid_successful;
3435
}
3536

3637
// Enqueues PDU and returns quickly
@@ -55,7 +56,7 @@ void demux_nr::push_bcch(srsran::unique_byte_buffer_t pdu)
5556
*/
5657
void demux_nr::push_pdu_temp_crnti(srsran::unique_byte_buffer_t pdu, uint32_t tti)
5758
{
58-
received_crueid = 0;
59+
is_uecrid_successful = false;
5960
handle_pdu(rx_pdu_tcrnti, std::move(pdu));
6061
}
6162

@@ -90,6 +91,7 @@ void demux_nr::handle_pdu(srsran::mac_sch_pdu_nr& pdu_buffer, srsran::unique_byt
9091
logger.info("%s", srsran::to_c_str(str_buffer));
9192
}
9293

94+
bool con_res_rxed = false;
9395
for (uint32_t i = 0; i < pdu_buffer.get_num_subpdus(); ++i) {
9496
srsran::mac_sch_subpdu_nr subpdu = pdu_buffer.get_subpdu(i);
9597
logger.debug("Handling subPDU %d/%d: rnti=0x%x lcid=%d, sdu_len=%d",
@@ -99,7 +101,7 @@ void demux_nr::handle_pdu(srsran::mac_sch_pdu_nr& pdu_buffer, srsran::unique_byt
99101
subpdu.get_lcid(),
100102
subpdu.get_sdu_length());
101103

102-
// Handle Timing Advance CE
104+
// Handle Contention Resolution UE ID and Timing Advance CE
103105
switch (subpdu.get_lcid()) {
104106
case srsran::mac_sch_subpdu_nr::nr_lcid_sch_t::DRX_CMD:
105107
logger.info("DRX CE not implemented.");
@@ -109,12 +111,17 @@ void demux_nr::handle_pdu(srsran::mac_sch_pdu_nr& pdu_buffer, srsran::unique_byt
109111
phy->set_timeadv(0, subpdu.get_ta().ta_command);
110112
break;
111113
case srsran::mac_sch_subpdu_nr::nr_lcid_sch_t::CON_RES_ID:
112-
received_crueid = subpdu.get_ue_con_res_id_ce_packed();
114+
con_res_rxed = true;
113115
logger.info("Received Contention Resolution ID 0x%lx", subpdu.get_ue_con_res_id_ce_packed());
116+
if (!is_uecrid_successful) {
117+
is_uecrid_successful = mac->received_contention_id(subpdu.get_ue_con_res_id_ce_packed());
118+
}
114119
break;
115120
default:
116-
if (subpdu.is_sdu()) {
117-
rlc->write_pdu(subpdu.get_lcid(), subpdu.get_sdu(), subpdu.get_sdu_length());
121+
if (!con_res_rxed or (con_res_rxed and is_uecrid_successful)) {
122+
if (subpdu.is_sdu()) {
123+
rlc->write_pdu(subpdu.get_lcid(), subpdu.get_sdu(), subpdu.get_sdu_length());
124+
}
118125
}
119126
}
120127
}

srsue/src/stack/mac_nr/dl_harq_nr.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ void dl_harq_entity_nr::dl_harq_process_nr::tb_decoded(const mac_nr_grant_dl_t&
235235
logger.debug("Delivering PDU=%d bytes to Dissassemble and Demux unit (Temporal C-RNTI) not implemented",
236236
grant.tbs);
237237
harq_entity->demux_unit->push_pdu_temp_crnti(std::move(result.payload), grant.tti);
238-
result.ack = harq_entity->mac->received_contention_id(harq_entity->demux_unit->get_received_crueid());
238+
result.ack = harq_entity->demux_unit->get_uecrid_successful();
239+
if (not result.ack) {
240+
reset();
241+
}
239242
} else {
240243
logger.debug("Delivering PDU=%d bytes to Dissassemble and Demux unit", grant.tbs);
241244
harq_entity->demux_unit->push_pdu(std::move(result.payload), grant.tti);

srsue/src/stack/mac_nr/mac_nr.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int mac_nr::init(const mac_nr_args_t& args_,
6565
return SRSRAN_ERROR;
6666
}
6767

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

350350
dl_harq.at(cc_idx)->tb_decoded(grant, std::move(result));
351351
}
352-
353-
// If proc ra is in contention resolution (RA connection request procedure)
354-
if (proc_ra.is_contention_resolution() && grant.rnti == rntis.get_temp_rnti()) {
355-
proc_ra.received_contention_resolution(contention_res_successful);
356-
}
357352
}
358353

359354
void mac_nr::new_grant_ul(const uint32_t cc_idx, const mac_nr_grant_ul_t& grant, tb_action_ul_t* action)
@@ -566,6 +561,7 @@ void mac_nr::process_pdus()
566561
bool mac_nr::received_contention_id(uint64_t rx_contention_id)
567562
{
568563
contention_res_successful = rntis.get_contention_id() == rx_contention_id;
564+
proc_ra.received_contention_resolution(contention_res_successful);
569565
return contention_res_successful;
570566
}
571567

srsue/src/stack/mac_nr/proc_ra_nr.cc

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ bool proc_ra_nr::has_rar_rnti()
122122
void proc_ra_nr::received_contention_resolution(bool is_successful)
123123
{
124124
std::lock_guard<std::mutex> lock(mutex);
125-
ra_contention_resolution(is_successful);
125+
ra_contention_resolution(is_successful, false);
126126
}
127127

128128
void proc_ra_nr::timer_expired(uint32_t timer_id)
@@ -196,8 +196,6 @@ void proc_ra_nr::ra_response_reception(const mac_interface_phy_nr::tb_action_dl_
196196
return;
197197
}
198198

199-
// Stop rar timer
200-
rar_timeout_timer.stop();
201199
if (tb.ack && tb.payload != nullptr) {
202200
srsran::mac_rar_pdu_nr pdu;
203201
if (!pdu.unpack(tb.payload->msg, tb.payload->N_bytes)) {
@@ -211,6 +209,9 @@ void proc_ra_nr::ra_response_reception(const mac_interface_phy_nr::tb_action_dl_
211209

212210
for (auto& subpdu : pdu.get_subpdus()) {
213211
if (subpdu.has_rapid() && subpdu.get_rapid() == preamble_index) {
212+
// Stop rar timer
213+
rar_timeout_timer.stop();
214+
214215
logger.debug("PROC RA NR: Setting UL grant and prepare Msg3");
215216
mac.set_temp_crnti(subpdu.get_temp_crnti());
216217

@@ -231,18 +232,20 @@ void proc_ra_nr::ra_response_reception(const mac_interface_phy_nr::tb_action_dl_
231232
} else {
232233
preamble_backoff = 0;
233234
}
235+
236+
contention_resolution_timer.set(rach_cfg.ra_ContentionResolutionTimer,
237+
[this](uint32_t tid) { timer_expired(tid); });
238+
contention_resolution_timer.run();
239+
logger.debug("Waiting for Contention Resolution");
240+
state = WAITING_FOR_CONTENTION_RESOLUTION;
234241
}
235242
}
236243
}
237-
contention_resolution_timer.set(rach_cfg.ra_ContentionResolutionTimer, [this](uint32_t tid) { timer_expired(tid); });
238-
contention_resolution_timer.run();
239-
logger.debug("Waiting for Contention Resolution");
240-
state = WAITING_FOR_CONTENTION_RESOLUTION;
241244
}
242245

243246
// TS 38.321 Section 5.1.5 2 ways to resolve contention resolution
244247
// if the C-RNTI MAC CE was included in Msg3: (only this one is implemented)
245-
void proc_ra_nr::ra_contention_resolution(bool received_con_res_matches_ue_id)
248+
void proc_ra_nr::ra_contention_resolution(bool is_successful, bool is_ul_grant)
246249
{
247250
if (state != WAITING_FOR_CONTENTION_RESOLUTION) {
248251
logger.warning(
@@ -251,15 +254,20 @@ void proc_ra_nr::ra_contention_resolution(bool received_con_res_matches_ue_id)
251254
srsran::enum_to_text(state_str_nr, (uint32_t)ra_state_t::MAX_RA_STATES, WAITING_FOR_CONTENTION_RESOLUTION));
252255
return;
253256
}
254-
if (started_by == initiators_t::RRC || started_by == initiators_t::MAC || received_con_res_matches_ue_id) {
255-
if (received_con_res_matches_ue_id) {
256-
logger.info("Received CONRES ID matches transmitted UE ID");
257+
if (started_by == initiators_t::RRC || started_by == initiators_t::MAC || is_successful) {
258+
if (is_successful) {
259+
if (is_ul_grant) {
260+
logger.info("PDCCH to C-RNTI received with a new UL grant of transmission");
261+
} else {
262+
logger.info("Received CONRES ID matches transmitted UE ID");
263+
}
264+
contention_resolution_timer.stop();
265+
state = WAITING_FOR_COMPLETION;
266+
ra_completion();
257267
} else {
258-
logger.info("PDCCH to C-RNTI received with a new UL grant of transmission");
268+
logger.info("Received CONRES ID DOES NOT match transmitted UE ID");
269+
mac.set_temp_crnti(SRSRAN_INVALID_RNTI);
259270
}
260-
contention_resolution_timer.stop();
261-
state = WAITING_FOR_COMPLETION;
262-
ra_completion();
263271
} else {
264272
logger.error("Not started by the correct initiator MAC or RRC");
265273
}
@@ -375,7 +383,7 @@ void proc_ra_nr::handle_rar_pdu(mac_interface_phy_nr::tb_action_dl_result_t& res
375383
// Called from PHY thread, defer actions therefore.
376384
void proc_ra_nr::pdcch_to_crnti()
377385
{
378-
task_queue.push([this]() { ra_contention_resolution(false); });
386+
task_queue.push([this]() { ra_contention_resolution(true, true); });
379387
}
380388

381389
bool proc_ra_nr::is_contention_resolution()

0 commit comments

Comments
 (0)