From 035c369a43a5555aea365ca6f7a473266d398556 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 7 Jul 2020 17:22:05 +0200 Subject: [PATCH] mac_pdu: fix check of remaining length when adding new subheader to MAC PDU when adding a new subheader to a MAC PDU we should only add the subheader if at least 2 bytes are left in the PDU. Even a 1 Byte MAC Control Element requires another byte to pack the subheader. This fixes #1424 in which a 3 B MAC opportunity is provided in the UL. After adding the Short BSR, we tried to add another MAC subheader. Adding the subheader succeeded even though no space is left to add a single byte. With this patch, adding the subheader fails and the generates MAC PDU is correct. --- lib/include/srslte/mac/pdu.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/include/srslte/mac/pdu.h b/lib/include/srslte/mac/pdu.h index ee24b99ed..2f8f1d882 100644 --- a/lib/include/srslte/mac/pdu.h +++ b/lib/include/srslte/mac/pdu.h @@ -165,7 +165,9 @@ public: bool new_subh() { - if (nof_subheaders < (int)max_subheaders - 1 && rem_len > 0 && buffer_tx->get_headroom() > 1) { + if (nof_subheaders < (int)max_subheaders - 1 && + rem_len >= 2 /* Even a MAC CE with one byte (e.g. PHR) needs a 1 Byte subheader */ + && buffer_tx->get_headroom() > 1) { nof_subheaders++; return next(); } else {