Fixed header packing for SN length 18 for PDCP NR. First TX test is passing.

This commit is contained in:
Pedro Alvarez 2019-07-19 14:36:29 +01:00 committed by Andre Puschmann
parent d399c65082
commit 39e3800781
2 changed files with 42 additions and 32 deletions

View File

@ -215,14 +215,14 @@ void pdcp_entity_nr::write_data_header(const srslte::unique_byte_buffer_t& sdu,
// Add SN
switch (cfg.sn_len) {
case PDCP_SN_LEN_12:
srslte::uint16_to_uint8(0x0FFF & count, sdu->msg);
srslte::uint16_to_uint8(SN(count), sdu->msg);
if (is_drb()) {
sdu->msg[0] |= 0x80; // On DRB Data PDUs we must set the D flag.
sdu->msg[0] |= 0x80; // On Data PDUs for DRBs we must set the D flag.
}
break;
case PDCP_SN_LEN_18:
sdu->msg[0] = 0x80; // Data PDU and SN 18 implies DRB, D flag must be present
*sdu->msg = count & 0x0FFF;
srslte::uint24_to_uint8(SN(count), sdu->msg);
sdu->msg[0] = 0x80; // Data PDU and SN LEN 18 implies DRB, D flag must be present
break;
default:
log->error("Invalid SN length configuration: %d bits\n", cfg.sn_len);

View File

@ -52,6 +52,16 @@ uint32_t PDU2_LEN = 8;
uint8_t pdu3[] = {0x80, 0x00, 0x97, 0xbe, 0xa3, 0x32, 0xfa, 0x61};
uint32_t PDU3_LEN = 8;
uint8_t pdu4[] = {0x80, 0x00, 0x00, 0x8f, 0xe3, 0xe0, 0xdf, 0x82, 0x92};
uint32_t PDU4_LEN = 9;
uint8_t pdu5[] = {0x80, 0x08, 0x00, 0x8d, 0x2c, 0x47, 0x5e, 0xb1, 0x5b};
uint32_t PDU5_LEN = 9;
uint8_t pdu6[] = {0x80, 0x00, 0x00, 0x97, 0xbe, 0xa3, 0x32, 0xfa, 0x61};
uint32_t PDU6_LEN = 9;
// dummy classes
class rlc_dummy : public srsue::rlc_interface_pdcp
{
@ -173,10 +183,10 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log)
* Input: {0x18, 0xE2}
* Output: PDCP Header {0x80, 0x00}, Ciphered Text {0x8f, 0xe3}, MAC-I {0xe0, 0xdf, 0x82, 0x92}
*/
srslte::unique_byte_buffer_t pdu_exp_sn0 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn0->msg, pdu1, PDU1_LEN);
pdu_exp_sn0->N_bytes = PDU1_LEN;
TESTASSERT(test_tx(1, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn0), pool, log) == 0);
srslte::unique_byte_buffer_t pdu_exp_sn0_len12 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn0_len12->msg, pdu1, PDU1_LEN);
pdu_exp_sn0_len12->N_bytes = PDU1_LEN;
TESTASSERT(test_tx(1, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn0_len12), pool, log) == 0);
/*
* TX Test 2: PDCP Entity with SN LEN = 12
@ -185,10 +195,10 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log)
* Input: {0x18, 0xE2}
* Output: PDCP Header {0x88, 0x00}, Ciphered Text {0x8d, 0x2c}, MAC-I {0x47, 0x5e, 0xb1, 0x5b}
*/
srslte::unique_byte_buffer_t pdu_exp_sn2048 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn2048->msg, pdu2, PDU2_LEN);
pdu_exp_sn2048->N_bytes = PDU2_LEN;
TESTASSERT(test_tx(2049, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn2048), pool, log) == 0);
srslte::unique_byte_buffer_t pdu_exp_sn2048_len12 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn2048_len12->msg, pdu2, PDU2_LEN);
pdu_exp_sn2048_len12->N_bytes = PDU2_LEN;
TESTASSERT(test_tx(2049, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn2048_len12), pool, log) == 0);
/*
* TX Test 3: PDCP Entity with SN LEN = 12
@ -197,46 +207,46 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log)
* Input: {0x18, 0xE2}
* Output: PDCP Header {0x80,0x00}, Ciphered Text {0x97, 0xbe}, MAC-I {0xa3, 0x32, 0xfa, 0x61}
*/
srslte::unique_byte_buffer_t pdu_exp_sn4096 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn4096->msg, pdu3, PDU3_LEN);
pdu_exp_sn4096->N_bytes = PDU3_LEN;
TESTASSERT(test_tx(4097, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn4096), pool, log) == 0);
srslte::unique_byte_buffer_t pdu_exp_sn4096_len12 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn4096_len12->msg, pdu3, PDU3_LEN);
pdu_exp_sn4096_len12->N_bytes = PDU3_LEN;
TESTASSERT(test_tx(4097, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn4096_len12), pool, log) == 0);
/*
* TX Test 1: PDCP Entity with SN LEN = 12
* TX Test 4: PDCP Entity with SN LEN = 18
* PDCP entity configured with EIA2 and EEA2
* TX_NEXT = 0.
* Input: {0x18, 0xE2}
* Output: PDCP Header {0x80, 0x00}, Ciphered Text {0x8f, 0xe3}, MAC-I {0xe0, 0xdf, 0x82, 0x92}
* Output: PDCP Header {0x80, 0x80, 0x00}, Ciphered Text {0x8f, 0xe3}, MAC-I {0xe0, 0xdf, 0x82, 0x92}
*/
srslte::unique_byte_buffer_t pdu_exp_sn0 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn0->msg, pdu1, PDU1_LEN);
pdu_exp_sn0->N_bytes = PDU1_LEN;
TESTASSERT(test_tx(1, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn0), pool, log) == 0);
srslte::unique_byte_buffer_t pdu_exp_sn0_len18 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn0_len18->msg, pdu4, PDU4_LEN);
pdu_exp_sn0_len18->N_bytes = PDU4_LEN;
TESTASSERT(test_tx(1, srslte::PDCP_SN_LEN_18, std::move(pdu_exp_sn0_len18), pool, log) == 0);
/*
* TX Test 2: PDCP Entity with SN LEN = 12
* TX Test 5: PDCP Entity with SN LEN = 18
* PDCP entity configured with EIA2 and EEA2
* TX_NEXT = 2048.
* Input: {0x18, 0xE2}
* Output: PDCP Header {0x88, 0x00}, Ciphered Text {0x8d, 0x2c}, MAC-I {0x47, 0x5e, 0xb1, 0x5b}
*/
srslte::unique_byte_buffer_t pdu_exp_sn2048 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn2048->msg, pdu2, PDU2_LEN);
pdu_exp_sn2048->N_bytes = PDU2_LEN;
TESTASSERT(test_tx(2049, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn2048), pool, log) == 0);
srslte::unique_byte_buffer_t pdu_exp_sn2048_len18 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn2048_len18->msg, pdu5, PDU5_LEN);
pdu_exp_sn2048_len18->N_bytes = PDU5_LEN;
TESTASSERT(test_tx(2049, srslte::PDCP_SN_LEN_18, std::move(pdu_exp_sn2048_len18), pool, log) == 0);
/*
* TX Test 3: PDCP Entity with SN LEN = 12
* TX Test 6: PDCP Entity with SN LEN = 18
* PDCP entity configured with EIA2 and EEA2
* TX_NEXT = 4096.
* Input: {0x18, 0xE2}
* Output: PDCP Header {0x80,0x00}, Ciphered Text {0x97, 0xbe}, MAC-I {0xa3, 0x32, 0xfa, 0x61}
*/
srslte::unique_byte_buffer_t pdu_exp_sn4096 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn4096->msg, pdu3, PDU3_LEN);
pdu_exp_sn4096->N_bytes = PDU3_LEN;
TESTASSERT(test_tx(4097, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn4096), pool, log) == 0);
srslte::unique_byte_buffer_t pdu_exp_sn4096_len18 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn4096_len18->msg, pdu6, PDU6_LEN);
pdu_exp_sn4096_len18->N_bytes = PDU6_LEN;
TESTASSERT(test_tx(4097, srslte::PDCP_SN_LEN_18, std::move(pdu_exp_sn4096_len18), pool, log) == 0);
return 0;
}