From 4ca43c68045edd83d2e3a482b9d06daa130fb303 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Wed, 3 Feb 2021 17:24:47 +0100 Subject: [PATCH] mac_sch_pdu_nr: add unpacking helpers for CRNTI, SBSR and PHR CEs * unpackers for CEs * testcase with TV --- lib/include/srslte/mac/mac_sch_pdu_nr.h | 15 ++++++++ lib/src/mac/mac_sch_pdu_nr.cc | 36 +++++++++++++++++++ lib/test/mac/mac_pdu_nr_test.cc | 47 +++++++++++++++++++++++++ 3 files changed, 98 insertions(+) diff --git a/lib/include/srslte/mac/mac_sch_pdu_nr.h b/lib/include/srslte/mac/mac_sch_pdu_nr.h index 1fdd324f3..488dfc9e0 100644 --- a/lib/include/srslte/mac/mac_sch_pdu_nr.h +++ b/lib/include/srslte/mac/mac_sch_pdu_nr.h @@ -42,6 +42,7 @@ public: LONG_TRUNC_BSR = 0b111100, CCCH_SIZE_48 = 0b110100, CCCH_SIZE_64 = 0b000000, + SE_PHR = 0b111001, // Single Entry PHR SHORT_BSR = 0b111101, LONG_BSR = 0b111110, @@ -63,6 +64,20 @@ public: uint32_t get_sdu_length(); uint32_t get_lcid(); uint8_t* get_sdu(); + uint16_t get_c_rnti(); + + // both return the reported values as per TS 38.321, mapping to dB according to TS 38.133 Sec 10.1.17 not done here + uint8_t get_phr(); + uint8_t get_pcmax(); + + // BSR + struct lcg_bsr_t { + uint8_t lcg_id; + uint8_t buffer_size; + }; + lcg_bsr_t get_sbsr(); + static const uint8_t max_num_lcg_lbsr = 8; + std::array get_lbsr(); void set_sdu(const uint32_t lcid_, const uint8_t* payload_, const uint32_t len_); diff --git a/lib/src/mac/mac_sch_pdu_nr.cc b/lib/src/mac/mac_sch_pdu_nr.cc index c6a8afda0..1404c048d 100644 --- a/lib/src/mac/mac_sch_pdu_nr.cc +++ b/lib/src/mac/mac_sch_pdu_nr.cc @@ -163,6 +163,40 @@ uint8_t* mac_sch_subpdu_nr::get_sdu() return sdu; } +uint16_t mac_sch_subpdu_nr::get_c_rnti() +{ + if (parent->is_ulsch() && lcid == CRNTI) { + return le16toh((uint16_t)sdu[0] << 8 | sdu[1]); + } + return 0; +} + +uint8_t mac_sch_subpdu_nr::get_phr() +{ + if (parent->is_ulsch() && lcid == SE_PHR) { + return sdu[0] & 0x3f; + } + return 0; +} + +uint8_t mac_sch_subpdu_nr::get_pcmax() +{ + if (parent->is_ulsch() && lcid == SE_PHR) { + return sdu[1] & 0x3f; + } + return 0; +} + +mac_sch_subpdu_nr::lcg_bsr_t mac_sch_subpdu_nr::get_sbsr() +{ + lcg_bsr_t sbsr = {}; + if (parent->is_ulsch() && lcid == SHORT_BSR) { + sbsr.lcg_id = (sdu[0] & 0xe0) >> 5; + sbsr.buffer_size = sdu[0] & 0x1f; + } + return sbsr; +} + uint32_t mac_sch_subpdu_nr::sizeof_ce(uint32_t lcid, bool is_ul) { if (is_ul) { @@ -177,6 +211,8 @@ uint32_t mac_sch_subpdu_nr::sizeof_ce(uint32_t lcid, bool is_ul) return 1; case SHORT_BSR: return 1; + case SE_PHR: + return 2; case PADDING: return 0; } diff --git a/lib/test/mac/mac_pdu_nr_test.cc b/lib/test/mac/mac_pdu_nr_test.cc index dea16c575..778a6394e 100644 --- a/lib/test/mac/mac_pdu_nr_test.cc +++ b/lib/test/mac/mac_pdu_nr_test.cc @@ -523,6 +523,48 @@ int mac_ul_sch_pdu_unpack_test5() return SRSLTE_SUCCESS; } +int mac_ul_sch_pdu_unpack_test6() +{ + // MAC PDU with UL-SCH: CRNTI, SE PHR, SBDR and padding + + // CRNTI:4601 SE PHR:ph=63 pc=52 SBSR: lcg=6 bs=0 PAD: len=0 + uint8_t tv[] = {0x3a, 0x46, 0x01, 0x39, 0x3f, 0x34, 0x3d, 0xc0, 0x3f}; + + if (pcap_handle) { + pcap_handle->write_ul_crnti_nr(tv, sizeof(tv), PCAP_CRNTI, true, PCAP_TTI); + } + + srslte::mac_sch_pdu_nr pdu(true); + pdu.unpack(tv, sizeof(tv)); + TESTASSERT(pdu.get_num_subpdus() == 4); + + // 1st C-RNTI + mac_sch_subpdu_nr subpdu = pdu.get_subpdu(0); + TESTASSERT(subpdu.get_total_length() == 3); + TESTASSERT(subpdu.get_sdu_length() == 2); + TESTASSERT(subpdu.get_lcid() == mac_sch_subpdu_nr::CRNTI); + TESTASSERT(subpdu.get_c_rnti() == 0x4601); + + // 2nd subPDU is SE PHR + subpdu = pdu.get_subpdu(1); + TESTASSERT(subpdu.get_lcid() == mac_sch_subpdu_nr::SE_PHR); + TESTASSERT(subpdu.get_phr() == 63); + TESTASSERT(subpdu.get_pcmax() == 52); + + // 3rd subPDU is SBSR + subpdu = pdu.get_subpdu(2); + TESTASSERT(subpdu.get_lcid() == mac_sch_subpdu_nr::SHORT_BSR); + mac_sch_subpdu_nr::lcg_bsr_t sbsr = subpdu.get_sbsr(); + TESTASSERT(sbsr.lcg_id == 6); + TESTASSERT(sbsr.buffer_size == 0); + + // 4th is padding + subpdu = pdu.get_subpdu(3); + TESTASSERT(subpdu.get_lcid() == mac_sch_subpdu_nr::PADDING); + + return SRSLTE_SUCCESS; +} + int main(int argc, char** argv) { #if PCAP @@ -601,6 +643,11 @@ int main(int argc, char** argv) return SRSLTE_ERROR; } + if (mac_ul_sch_pdu_unpack_test6()) { + fprintf(stderr, "mac_ul_sch_pdu_unpack_test6() failed.\n"); + return SRSLTE_ERROR; + } + if (pcap_handle) { pcap_handle->close(); }