mac_sch_pdu_nr: add unpacking helpers for CRNTI, SBSR and PHR CEs

* unpackers for CEs
* testcase with TV
master
Andre Puschmann 4 years ago
parent a154bef23f
commit 4ca43c6804

@ -42,6 +42,7 @@ public:
LONG_TRUNC_BSR = 0b111100, LONG_TRUNC_BSR = 0b111100,
CCCH_SIZE_48 = 0b110100, CCCH_SIZE_48 = 0b110100,
CCCH_SIZE_64 = 0b000000, CCCH_SIZE_64 = 0b000000,
SE_PHR = 0b111001, // Single Entry PHR
SHORT_BSR = 0b111101, SHORT_BSR = 0b111101,
LONG_BSR = 0b111110, LONG_BSR = 0b111110,
@ -63,6 +64,20 @@ public:
uint32_t get_sdu_length(); uint32_t get_sdu_length();
uint32_t get_lcid(); uint32_t get_lcid();
uint8_t* get_sdu(); 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<lcg_bsr_t, max_num_lcg_lbsr> get_lbsr();
void set_sdu(const uint32_t lcid_, const uint8_t* payload_, const uint32_t len_); void set_sdu(const uint32_t lcid_, const uint8_t* payload_, const uint32_t len_);

@ -163,6 +163,40 @@ uint8_t* mac_sch_subpdu_nr::get_sdu()
return 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) uint32_t mac_sch_subpdu_nr::sizeof_ce(uint32_t lcid, bool is_ul)
{ {
if (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; return 1;
case SHORT_BSR: case SHORT_BSR:
return 1; return 1;
case SE_PHR:
return 2;
case PADDING: case PADDING:
return 0; return 0;
} }

@ -523,6 +523,48 @@ int mac_ul_sch_pdu_unpack_test5()
return SRSLTE_SUCCESS; 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) int main(int argc, char** argv)
{ {
#if PCAP #if PCAP
@ -601,6 +643,11 @@ int main(int argc, char** argv)
return SRSLTE_ERROR; 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) { if (pcap_handle) {
pcap_handle->close(); pcap_handle->close();
} }

Loading…
Cancel
Save