From f0e403911d1f00d83b8080e2d70fd9fe02dd4ad1 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Fri, 8 Jan 2016 10:07:53 +0100 Subject: edge: Add encoder for downlink RLC data blocks Currently the (GPRS) RLC block encoding is done by setting the header fields directly in gprs_rlcmac_dl_tbf::create_new_bsn. This is much more complex with EGPRS, since the data fields are not byte aligned, the header formats depend on the header type, and the mapping of bits to bytes is LSB first. This commit adds Encoding::rlc_write_dl_data_header which writes the header according to the given gprs_rlc_data_header structure. Encoding::rlc_copy_from_aligned_buffer is also added to copy byte sequences into the message. Note that the actual encoding of data units is not yet present. Sponsored-by: On-Waves ehf --- tests/edge/EdgeTest.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'tests') diff --git a/tests/edge/EdgeTest.cpp b/tests/edge/EdgeTest.cpp index 7bb81e47..11459457 100644 --- a/tests/edge/EdgeTest.cpp +++ b/tests/edge/EdgeTest.cpp @@ -23,6 +23,7 @@ #include "gprs_debug.h" #include "gprs_coding_scheme.h" #include "decoding.h" +#include "encoding.h" #include "rlc.h" extern "C" { @@ -36,6 +37,7 @@ extern "C" { } #include +#include void *tall_pcu_ctx; int16_t spoof_mnc = 0, spoof_mcc = 0; @@ -481,6 +483,73 @@ static void test_rlc_unit_decoder() printf("=== end %s ===\n", __func__); } +static void test_rlc_unaligned_copy() +{ + uint8_t bits[256]; + uint8_t saved_block[256]; + uint8_t test_block[256]; + uint8_t out_block[256]; + GprsCodingScheme::Scheme scheme; + int pattern; + volatile unsigned int block_idx, i; + + for (scheme = GprsCodingScheme::CS1; + scheme < GprsCodingScheme::NUM_SCHEMES; + scheme = GprsCodingScheme::Scheme(scheme + 1)) + { + GprsCodingScheme cs(scheme); + + for (pattern = 0; pattern <= 0xff; pattern += 0xff) { + /* prepare test block */ + test_block[0] = pattern ^ 0xff; + for (i = 1; i + 1 < cs.maxDataBlockBytes(); i++) + test_block[i] = i; + test_block[cs.maxDataBlockBytes()-1] = pattern ^ 0xff; + + for (block_idx = 0; + block_idx < cs.numDataBlocks(); + block_idx++) + { + struct gprs_rlc_data_info rlc; + gprs_rlc_data_info_init_dl(&rlc, cs); + + memset(bits, pattern, sizeof(bits)); + Decoding::rlc_copy_to_aligned_buffer( + &rlc, block_idx, bits, saved_block); + + fprintf(stderr, + "Test data block: %s\n", + osmo_hexdump(test_block, cs.maxDataBlockBytes())); + + Encoding::rlc_copy_from_aligned_buffer( + &rlc, block_idx, bits, test_block); + + fprintf(stderr, + "Encoded message block, %s, idx %d, " + "pattern %02x: %s\n", + rlc.cs.name(), block_idx, pattern, + osmo_hexdump(bits, cs.sizeDL())); + + Decoding::rlc_copy_to_aligned_buffer( + &rlc, block_idx, bits, out_block); + + fprintf(stderr, + "Out data block: %s\n", + osmo_hexdump(out_block, cs.maxDataBlockBytes())); + /* restore original bits */ + Encoding::rlc_copy_from_aligned_buffer( + &rlc, block_idx, bits, saved_block); + + OSMO_ASSERT(memcmp(test_block, out_block, + rlc.cs.maxDataBlockBytes()) == 0); + + for (i = 0; i < sizeof(bits); i++) + OSMO_ASSERT(bits[i] == pattern); + } + } + } +} + static void test_rlc_info_init() { struct gprs_rlc_data_info rlc; @@ -544,6 +613,7 @@ int main(int argc, char **argv) test_coding_scheme(); test_rlc_info_init(); test_rlc_unit_decoder(); + test_rlc_unaligned_copy(); if (getenv("TALLOC_REPORT_FULL")) talloc_report_full(tall_pcu_ctx, stderr); -- cgit v1.2.3