From 6dd8c21073f65f25a4fb10bd7774afac6ecf336e Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 8 Apr 2021 17:13:56 +0200 Subject: [PATCH] mac_sch_pdu_nr: add unpacking of TA CE in DL-SCH also add basic test to verify correct unpacking --- lib/include/srsran/mac/mac_sch_pdu_nr.h | 7 +++++++ lib/src/mac/mac_sch_pdu_nr.cc | 10 ++++++++++ lib/test/mac/mac_pdu_nr_test.cc | 25 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/lib/include/srsran/mac/mac_sch_pdu_nr.h b/lib/include/srsran/mac/mac_sch_pdu_nr.h index dd196ff6b..c7884b6cc 100644 --- a/lib/include/srsran/mac/mac_sch_pdu_nr.h +++ b/lib/include/srsran/mac/mac_sch_pdu_nr.h @@ -79,6 +79,13 @@ public: static const uint8_t max_num_lcg_lbsr = 8; std::array get_lbsr(); + // TA + struct ta_t { + uint8_t tag_id; + uint8_t ta_command; + }; + ta_t get_ta(); + // setters void set_sdu(const uint32_t lcid_, const uint8_t* payload_, const uint32_t len_); void set_padding(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 6abefe968..65db755d2 100644 --- a/lib/src/mac/mac_sch_pdu_nr.cc +++ b/lib/src/mac/mac_sch_pdu_nr.cc @@ -218,6 +218,16 @@ uint8_t mac_sch_subpdu_nr::get_pcmax() return 0; } +mac_sch_subpdu_nr::ta_t mac_sch_subpdu_nr::get_ta() +{ + ta_t ta = {}; + if (lcid == TA_CMD) { + ta.tag_id = (sdu[0] & 0xc0) >> 6; + ta.ta_command = sdu[0] & 0x3f; + } + return ta; +} + mac_sch_subpdu_nr::lcg_bsr_t mac_sch_subpdu_nr::get_sbsr() { lcg_bsr_t sbsr = {}; diff --git a/lib/test/mac/mac_pdu_nr_test.cc b/lib/test/mac/mac_pdu_nr_test.cc index 40557fb38..bec8a34c1 100644 --- a/lib/test/mac/mac_pdu_nr_test.cc +++ b/lib/test/mac/mac_pdu_nr_test.cc @@ -326,6 +326,26 @@ int mac_rar_pdu_unpack_test8() return SRSRAN_SUCCESS; } +int mac_dl_sch_pdu_unpack_test9() +{ + // MAC PDU with Timing Advance CE and padding + uint8_t tv[] = {0x3d, 0x1f, 0x3f, 0x00, 0x00, 0x00}; + + if (pcap_handle) { + pcap_handle->write_dl_crnti_nr(tv, sizeof(tv), PCAP_CRNTI, true, PCAP_TTI); + } + + srsran::mac_sch_pdu_nr pdu; + pdu.unpack(tv, sizeof(tv)); + TESTASSERT(pdu.get_num_subpdus() == 2); + mac_sch_subpdu_nr subpdu = pdu.get_subpdu(0); + + TESTASSERT(subpdu.get_ta().tag_id == 0); + TESTASSERT(subpdu.get_ta().ta_command == 31); + + return SRSRAN_SUCCESS; +} + int mac_ul_sch_pdu_unpack_test1() { // UL-SCH MAC PDU with fixed-size CE and DL-SCH subheader with 16-bit length field @@ -657,6 +677,11 @@ int main(int argc, char** argv) return SRSRAN_ERROR; } + if (mac_dl_sch_pdu_unpack_test9()) { + fprintf(stderr, "mac_dl_sch_pdu_unpack_test9() failed.\n"); + return SRSRAN_ERROR; + } + if (mac_ul_sch_pdu_unpack_test1()) { fprintf(stderr, "mac_ul_sch_pdu_unpack_test1() failed.\n"); return SRSRAN_ERROR;