Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 1 | /* |
| 2 | * EdgeTest.cpp |
| 3 | * |
| 4 | * Copyright (C) 2015 by Sysmocom s.f.m.c. GmbH |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include "gprs_debug.h" |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 24 | #include "decoding.h" |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 25 | #include "encoding.h" |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 26 | #include "rlc.h" |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 27 | #include "llc.h" |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 28 | #include "bts.h" |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 29 | #include <gprs_rlcmac.h> |
| 30 | |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 31 | extern "C" { |
| 32 | #include "pcu_vty.h" |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 33 | #include "coding_scheme.h" |
Pau Espin Pedrol | ff7c581 | 2022-12-14 18:49:06 +0100 | [diff] [blame] | 34 | #include "alloc_algo.h" |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 35 | |
| 36 | #include <osmocom/core/application.h> |
| 37 | #include <osmocom/core/msgb.h> |
| 38 | #include <osmocom/core/talloc.h> |
| 39 | #include <osmocom/core/utils.h> |
| 40 | #include <osmocom/vty/vty.h> |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 41 | #include <osmocom/gprs/protocol/gsm_04_60.h> |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | #include <errno.h> |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 45 | #include <string.h> |
Neels Hofmeyr | d34646a | 2017-02-08 17:07:40 +0100 | [diff] [blame] | 46 | #include <limits.h> |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 47 | |
| 48 | void *tall_pcu_ctx; |
| 49 | int16_t spoof_mnc = 0, spoof_mcc = 0; |
Neels Hofmeyr | bdc55fa | 2018-02-21 00:39:07 +0100 | [diff] [blame] | 50 | bool spoof_mnc_3_digits = false; |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 51 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 52 | static void check_coding_scheme(enum CodingScheme& cs, enum mcs_kind mode) |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 53 | { |
| 54 | volatile unsigned expected_size; |
Jacob Erlbeck | 2305afd | 2016-02-03 15:25:04 +0100 | [diff] [blame] | 55 | bool need_padding; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 56 | enum CodingScheme new_cs; |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 57 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 58 | OSMO_ASSERT(mcs_is_valid(cs)); |
| 59 | OSMO_ASSERT(mcs_is_compat_kind(cs, mode)); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 60 | |
| 61 | /* Check static getBySizeUL() */ |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 62 | expected_size = mcs_used_size_ul(cs); |
| 63 | if (mcs_spare_bits_ul(cs) > 0 && mcs_is_gprs(cs)) |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 64 | expected_size += 1; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 65 | OSMO_ASSERT(expected_size == mcs_size_ul(cs)); |
| 66 | OSMO_ASSERT(cs == mcs_get_by_size_ul(expected_size)); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 67 | |
| 68 | /* Check static sizeUL() */ |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 69 | expected_size = mcs_used_size_dl(cs); |
| 70 | if (mcs_spare_bits_dl(cs) > 0 && mcs_is_gprs(cs)) |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 71 | expected_size += 1; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 72 | OSMO_ASSERT(expected_size == mcs_size_dl(cs)); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 73 | |
Jacob Erlbeck | 392a545 | 2015-12-14 10:38:29 +0100 | [diff] [blame] | 74 | /* Check data block sizes */ |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 75 | OSMO_ASSERT(mcs_max_data_block_bytes(cs) * num_data_blocks(mcs_header_type(cs)) < mcs_max_bytes_dl(cs)); |
| 76 | OSMO_ASSERT(mcs_max_data_block_bytes(cs) * num_data_blocks(mcs_header_type(cs)) < mcs_max_bytes_ul(cs)); |
Jacob Erlbeck | 392a545 | 2015-12-14 10:38:29 +0100 | [diff] [blame] | 77 | |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 78 | /* Check inc/dec */ |
| 79 | new_cs = cs; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 80 | mcs_inc_kind(&new_cs, mode); |
| 81 | OSMO_ASSERT(mcs_is_compat_kind(new_cs, mode)); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 82 | if (new_cs != cs) { |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 83 | mcs_dec_kind(&new_cs, mode); |
| 84 | OSMO_ASSERT(mcs_is_compat_kind(new_cs, mode)); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 85 | OSMO_ASSERT(new_cs == cs); |
| 86 | } |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 87 | mcs_dec_kind(&new_cs, mode); |
| 88 | OSMO_ASSERT(mcs_is_compat_kind(new_cs, mode)); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 89 | if (new_cs != cs) { |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 90 | mcs_inc_kind(&new_cs, mode); |
| 91 | OSMO_ASSERT(mcs_is_compat_kind(new_cs, mode)); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 92 | OSMO_ASSERT(new_cs == cs); |
| 93 | } |
Jacob Erlbeck | 2305afd | 2016-02-03 15:25:04 +0100 | [diff] [blame] | 94 | |
| 95 | new_cs = cs; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 96 | mcs_dec_to_single_block(&new_cs, &need_padding); |
| 97 | OSMO_ASSERT(mcs_is_family_compat(new_cs, cs)); |
| 98 | OSMO_ASSERT(mcs_is_family_compat(cs, new_cs)); |
| 99 | OSMO_ASSERT(mcs_is_compat(cs, new_cs)); |
Jacob Erlbeck | 2305afd | 2016-02-03 15:25:04 +0100 | [diff] [blame] | 100 | if (need_padding) { |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 101 | OSMO_ASSERT(mcs_max_data_block_bytes(new_cs) == |
| 102 | mcs_opt_padding_bits(new_cs)/8 + mcs_max_data_block_bytes(cs)); |
Jacob Erlbeck | 2305afd | 2016-02-03 15:25:04 +0100 | [diff] [blame] | 103 | } else { |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 104 | OSMO_ASSERT(mcs_max_data_block_bytes(new_cs) == mcs_max_data_block_bytes(cs)); |
Jacob Erlbeck | 2305afd | 2016-02-03 15:25:04 +0100 | [diff] [blame] | 105 | } |
| 106 | |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 107 | } |
| 108 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 109 | static bool check_strong_monotonicity(const enum CodingScheme cs, uint8_t last_UL, uint8_t last_DL) |
Max | 360e021 | 2019-02-26 17:20:41 +0100 | [diff] [blame] | 110 | { |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 111 | if (mcs_max_bytes_ul(cs) <= last_UL) |
Max | 360e021 | 2019-02-26 17:20:41 +0100 | [diff] [blame] | 112 | return false; |
| 113 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 114 | if (mcs_max_bytes_dl(cs) <= last_DL) |
Max | 360e021 | 2019-02-26 17:20:41 +0100 | [diff] [blame] | 115 | return false; |
| 116 | |
| 117 | return true; |
| 118 | } |
| 119 | |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 120 | static void test_coding_scheme() |
| 121 | { |
| 122 | unsigned i; |
Max | 360e021 | 2019-02-26 17:20:41 +0100 | [diff] [blame] | 123 | uint8_t last_size_UL; |
| 124 | uint8_t last_size_DL; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 125 | enum CodingScheme gprs_schemes[] = { |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 126 | CS1, |
| 127 | CS2, |
| 128 | CS3, |
| 129 | CS4 |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 130 | }; |
| 131 | struct { |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 132 | enum CodingScheme s; |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 133 | bool is_gmsk; |
| 134 | } egprs_schemes[] = { |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 135 | { MCS1, true}, |
| 136 | { MCS2, true}, |
| 137 | { MCS3, true}, |
| 138 | { MCS4, true}, |
| 139 | { MCS5, false}, |
| 140 | { MCS6, false}, |
| 141 | { MCS7, false}, |
| 142 | { MCS8, false}, |
| 143 | { MCS9, false}, |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | printf("=== start %s ===\n", __func__); |
| 147 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 148 | enum CodingScheme cs = UNKNOWN; |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 149 | OSMO_ASSERT(!cs); |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 150 | OSMO_ASSERT(!mcs_is_compat_kind(cs, GPRS)); |
| 151 | OSMO_ASSERT(!mcs_is_compat_kind(cs, EGPRS_GMSK)); |
| 152 | OSMO_ASSERT(!mcs_is_compat_kind(cs, EGPRS)); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 153 | |
| 154 | last_size_UL = 0; |
| 155 | last_size_DL = 0; |
| 156 | |
| 157 | for (i = 0; i < ARRAY_SIZE(gprs_schemes); i++) { |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 158 | enum CodingScheme current_cs = gprs_schemes[i]; |
Max | 8a8e0fb | 2019-03-25 16:32:50 +0100 | [diff] [blame] | 159 | OSMO_ASSERT(mcs_is_gprs(current_cs)); |
| 160 | OSMO_ASSERT(!mcs_is_edge(current_cs)); |
| 161 | OSMO_ASSERT(!mcs_is_edge_gmsk(current_cs)); |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 162 | OSMO_ASSERT(current_cs == gprs_schemes[i]); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 163 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 164 | OSMO_ASSERT(check_strong_monotonicity(current_cs, last_size_UL, last_size_DL)); |
| 165 | last_size_UL = mcs_max_bytes_ul(current_cs); |
| 166 | last_size_DL = mcs_max_bytes_dl(current_cs); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 167 | |
Jacob Erlbeck | 6c3dc61 | 2015-12-14 10:21:26 +0100 | [diff] [blame] | 168 | /* Check header types */ |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 169 | OSMO_ASSERT(mcs_header_type(current_cs) == HEADER_GPRS_DATA); |
Jacob Erlbeck | 6c3dc61 | 2015-12-14 10:21:26 +0100 | [diff] [blame] | 170 | |
Max | a4de02d | 2019-03-13 16:35:09 +0100 | [diff] [blame] | 171 | check_coding_scheme(current_cs, GPRS); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 172 | } |
| 173 | OSMO_ASSERT(i == 4); |
| 174 | |
| 175 | last_size_UL = 0; |
| 176 | last_size_DL = 0; |
| 177 | |
| 178 | for (i = 0; i < ARRAY_SIZE(egprs_schemes); i++) { |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 179 | enum CodingScheme current_cs = egprs_schemes[i].s; |
Max | 8a8e0fb | 2019-03-25 16:32:50 +0100 | [diff] [blame] | 180 | OSMO_ASSERT(!mcs_is_gprs(current_cs)); |
| 181 | OSMO_ASSERT(mcs_is_edge(current_cs)); |
| 182 | OSMO_ASSERT(mcs_is_edge_gmsk(current_cs) == !!egprs_schemes[i].is_gmsk); |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 183 | OSMO_ASSERT(current_cs == egprs_schemes[i].s); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 184 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 185 | OSMO_ASSERT(check_strong_monotonicity(current_cs, last_size_UL, last_size_DL)); |
| 186 | last_size_UL = mcs_max_bytes_ul(current_cs); |
| 187 | last_size_DL = mcs_max_bytes_dl(current_cs); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 188 | |
| 189 | if (egprs_schemes[i].is_gmsk) |
Max | a4de02d | 2019-03-13 16:35:09 +0100 | [diff] [blame] | 190 | check_coding_scheme(current_cs, EGPRS_GMSK); |
| 191 | check_coding_scheme(current_cs, EGPRS); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 192 | } |
| 193 | OSMO_ASSERT(i == 9); |
| 194 | |
| 195 | printf("=== end %s ===\n", __func__); |
| 196 | } |
| 197 | |
Jacob Erlbeck | 38f1869 | 2016-02-01 10:08:00 +0100 | [diff] [blame] | 198 | static void test_rlc_unit_decoder() |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 199 | { |
Jacob Erlbeck | f2ba4cb | 2016-01-07 18:59:28 +0100 | [diff] [blame] | 200 | struct gprs_rlc_data_block_info rdbi = {0}; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 201 | enum CodingScheme cs; |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 202 | uint8_t data[74]; |
| 203 | Decoding::RlcData chunks[16]; |
| 204 | volatile int num_chunks = 0; |
| 205 | uint32_t tlli, tlli2; |
| 206 | unsigned int offs; |
| 207 | |
| 208 | |
| 209 | printf("=== start %s ===\n", __func__); |
| 210 | |
| 211 | /* TS 44.060, B.1 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 212 | cs = CS4; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 213 | rdbi.data_len = mcs_max_data_block_bytes(cs); |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 214 | rdbi.e = 0; |
| 215 | rdbi.ti = 0; |
| 216 | rdbi.cv = 15; |
| 217 | tlli = 0; |
| 218 | offs = 0; |
| 219 | data[offs++] = (11 << 2) | (1 << 1) | (0 << 0); |
| 220 | data[offs++] = (26 << 2) | (1 << 1) | (1 << 0); |
| 221 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 222 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 223 | OSMO_ASSERT(num_chunks == 3); |
| 224 | OSMO_ASSERT(tlli == 0); |
| 225 | OSMO_ASSERT(chunks[0].offset == 2); |
| 226 | OSMO_ASSERT(chunks[0].length == 11); |
| 227 | OSMO_ASSERT(chunks[0].is_complete); |
| 228 | OSMO_ASSERT(chunks[1].offset == 13); |
| 229 | OSMO_ASSERT(chunks[1].length == 26); |
| 230 | OSMO_ASSERT(chunks[1].is_complete); |
| 231 | OSMO_ASSERT(chunks[2].offset == 39); |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 232 | OSMO_ASSERT(chunks[2].length == mcs_max_data_block_bytes(cs) - 39); |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 233 | OSMO_ASSERT(!chunks[2].is_complete); |
| 234 | |
| 235 | /* TS 44.060, B.2 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 236 | cs = CS1; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 237 | rdbi.data_len = mcs_max_data_block_bytes(cs); |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 238 | rdbi.e = 0; |
| 239 | rdbi.ti = 0; |
| 240 | rdbi.cv = 15; |
| 241 | tlli = 0; |
| 242 | offs = 0; |
| 243 | data[offs++] = (0 << 2) | (0 << 1) | (1 << 0); |
| 244 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 245 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 246 | OSMO_ASSERT(num_chunks == 1); |
| 247 | OSMO_ASSERT(tlli == 0); |
| 248 | OSMO_ASSERT(chunks[0].offset == 1); |
| 249 | OSMO_ASSERT(chunks[0].length == 19); |
| 250 | OSMO_ASSERT(!chunks[0].is_complete); |
| 251 | |
| 252 | rdbi.e = 0; |
| 253 | rdbi.ti = 0; |
| 254 | rdbi.cv = 15; |
| 255 | tlli = 0; |
| 256 | offs = 0; |
| 257 | data[offs++] = (1 << 2) | (1 << 1) | (1 << 0); |
| 258 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 259 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 260 | OSMO_ASSERT(num_chunks == 2); |
| 261 | OSMO_ASSERT(tlli == 0); |
| 262 | OSMO_ASSERT(chunks[0].offset == 1); |
| 263 | OSMO_ASSERT(chunks[0].length == 1); |
| 264 | OSMO_ASSERT(chunks[0].is_complete); |
| 265 | OSMO_ASSERT(chunks[1].offset == 2); |
| 266 | OSMO_ASSERT(chunks[1].length == 18); |
| 267 | OSMO_ASSERT(!chunks[1].is_complete); |
| 268 | |
| 269 | /* TS 44.060, B.3 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 270 | cs = CS1; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 271 | rdbi.data_len = mcs_max_data_block_bytes(cs); |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 272 | rdbi.e = 0; |
| 273 | rdbi.ti = 0; |
| 274 | rdbi.cv = 15; |
| 275 | tlli = 0; |
| 276 | offs = 0; |
| 277 | data[offs++] = (7 << 2) | (1 << 1) | (0 << 0); |
| 278 | data[offs++] = (11 << 2) | (0 << 1) | (1 << 0); |
| 279 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 280 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 281 | OSMO_ASSERT(num_chunks == 2); |
| 282 | OSMO_ASSERT(tlli == 0); |
| 283 | OSMO_ASSERT(chunks[0].offset == 2); |
| 284 | OSMO_ASSERT(chunks[0].length == 7); |
| 285 | OSMO_ASSERT(chunks[0].is_complete); |
| 286 | OSMO_ASSERT(chunks[1].offset == 9); |
| 287 | OSMO_ASSERT(chunks[1].length == 11); |
| 288 | OSMO_ASSERT(chunks[1].is_complete); |
| 289 | |
| 290 | /* TS 44.060, B.4 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 291 | cs = CS1; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 292 | rdbi.data_len = mcs_max_data_block_bytes(cs); |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 293 | rdbi.e = 1; |
| 294 | rdbi.ti = 0; |
| 295 | rdbi.cv = 15; |
| 296 | tlli = 0; |
| 297 | offs = 0; |
| 298 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 299 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 300 | OSMO_ASSERT(num_chunks == 1); |
| 301 | OSMO_ASSERT(tlli == 0); |
| 302 | OSMO_ASSERT(chunks[0].offset == 0); |
| 303 | OSMO_ASSERT(chunks[0].length == 20); |
| 304 | OSMO_ASSERT(!chunks[0].is_complete); |
| 305 | |
| 306 | /* TS 44.060, B.6 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 307 | cs = CS1; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 308 | rdbi.data_len = mcs_max_data_block_bytes(cs); |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 309 | rdbi.e = 1; |
| 310 | rdbi.ti = 0; |
| 311 | rdbi.cv = 0; |
| 312 | tlli = 0; |
| 313 | offs = 0; |
| 314 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 315 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 316 | OSMO_ASSERT(num_chunks == 1); |
| 317 | OSMO_ASSERT(tlli == 0); |
| 318 | OSMO_ASSERT(chunks[0].offset == 0); |
| 319 | OSMO_ASSERT(chunks[0].length == 20); |
| 320 | OSMO_ASSERT(chunks[0].is_complete); |
| 321 | |
| 322 | /* TS 44.060, B.8.1 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 323 | cs = MCS4; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 324 | rdbi.data_len = mcs_max_data_block_bytes(cs); |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 325 | rdbi.e = 0; |
| 326 | rdbi.ti = 0; |
| 327 | rdbi.cv = 15; |
| 328 | tlli = 0; |
| 329 | offs = 0; |
| 330 | data[offs++] = (11 << 1) | (0 << 0); |
| 331 | data[offs++] = (26 << 1) | (1 << 0); |
| 332 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 333 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 334 | OSMO_ASSERT(num_chunks == 3); |
| 335 | OSMO_ASSERT(tlli == 0); |
| 336 | OSMO_ASSERT(chunks[0].offset == 2); |
| 337 | OSMO_ASSERT(chunks[0].length == 11); |
| 338 | OSMO_ASSERT(chunks[0].is_complete); |
| 339 | OSMO_ASSERT(chunks[1].offset == 13); |
| 340 | OSMO_ASSERT(chunks[1].length == 26); |
| 341 | OSMO_ASSERT(chunks[1].is_complete); |
| 342 | OSMO_ASSERT(chunks[2].offset == 39); |
| 343 | OSMO_ASSERT(chunks[2].length == 5); |
| 344 | OSMO_ASSERT(!chunks[2].is_complete); |
| 345 | |
| 346 | /* TS 44.060, B.8.2 */ |
| 347 | |
| 348 | /* Note that the spec confuses the byte numbering here, since it |
| 349 | * includes the FBI/E header bits into the N2 octet count which |
| 350 | * is not consistent with Section 10.3a.1 & 10.3a.2. */ |
| 351 | |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 352 | cs = MCS2; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 353 | rdbi.data_len = mcs_max_data_block_bytes(cs); |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 354 | rdbi.e = 0; |
| 355 | rdbi.ti = 0; |
| 356 | rdbi.cv = 15; |
| 357 | tlli = 0; |
| 358 | offs = 0; |
| 359 | data[offs++] = (15 << 1) | (1 << 0); |
| 360 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 361 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 362 | OSMO_ASSERT(num_chunks == 2); |
| 363 | OSMO_ASSERT(tlli == 0); |
| 364 | OSMO_ASSERT(chunks[0].offset == 1); |
| 365 | OSMO_ASSERT(chunks[0].length == 15); |
| 366 | OSMO_ASSERT(chunks[0].is_complete); |
| 367 | OSMO_ASSERT(chunks[1].offset == 16); |
| 368 | OSMO_ASSERT(chunks[1].length == 12); |
| 369 | OSMO_ASSERT(!chunks[1].is_complete); |
| 370 | |
| 371 | rdbi.e = 0; |
| 372 | rdbi.ti = 0; |
| 373 | rdbi.cv = 15; |
| 374 | tlli = 0; |
| 375 | offs = 0; |
| 376 | data[offs++] = ( 0 << 1) | (0 << 0); |
| 377 | data[offs++] = ( 7 << 1) | (0 << 0); |
| 378 | data[offs++] = (18 << 1) | (1 << 0); /* Differs from spec's N2-11 = 17 */ |
| 379 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 380 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 381 | OSMO_ASSERT(num_chunks == 3); |
| 382 | OSMO_ASSERT(tlli == 0); |
| 383 | OSMO_ASSERT(chunks[0].offset == 3); |
| 384 | OSMO_ASSERT(chunks[0].length == 0); |
| 385 | OSMO_ASSERT(chunks[0].is_complete); |
| 386 | OSMO_ASSERT(chunks[1].offset == 3); |
| 387 | OSMO_ASSERT(chunks[1].length == 7); |
| 388 | OSMO_ASSERT(chunks[1].is_complete); |
| 389 | OSMO_ASSERT(chunks[2].offset == 10); |
| 390 | OSMO_ASSERT(chunks[2].length == 18); |
| 391 | OSMO_ASSERT(chunks[2].is_complete); |
| 392 | |
| 393 | rdbi.e = 0; |
| 394 | rdbi.ti = 0; |
| 395 | rdbi.cv = 0; |
| 396 | tlli = 0; |
| 397 | offs = 0; |
| 398 | data[offs++] = ( 6 << 1) | (0 << 0); |
| 399 | data[offs++] = (12 << 1) | (0 << 0); |
| 400 | data[offs++] = (127 << 1) | (1 << 0); |
| 401 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 402 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 403 | OSMO_ASSERT(num_chunks == 2); |
| 404 | OSMO_ASSERT(tlli == 0); |
| 405 | OSMO_ASSERT(chunks[0].offset == 3); |
| 406 | OSMO_ASSERT(chunks[0].length == 6); |
| 407 | OSMO_ASSERT(chunks[0].is_complete); |
| 408 | OSMO_ASSERT(chunks[1].offset == 9); |
| 409 | OSMO_ASSERT(chunks[1].length == 12); |
| 410 | OSMO_ASSERT(chunks[1].is_complete); |
| 411 | |
| 412 | /* TS 44.060, B.8.3 */ |
| 413 | |
| 414 | /* Note that the spec confuses the byte numbering here, too (see above) */ |
| 415 | |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 416 | cs = MCS2; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 417 | rdbi.data_len = mcs_max_data_block_bytes(cs); |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 418 | rdbi.e = 1; |
| 419 | rdbi.ti = 0; |
| 420 | rdbi.cv = 0; |
| 421 | tlli = 0; |
| 422 | offs = 0; |
| 423 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 424 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 425 | OSMO_ASSERT(num_chunks == 1); |
| 426 | OSMO_ASSERT(tlli == 0); |
| 427 | OSMO_ASSERT(chunks[0].offset == 0); |
| 428 | OSMO_ASSERT(chunks[0].length == 28); |
| 429 | OSMO_ASSERT(chunks[0].is_complete); |
| 430 | |
| 431 | /* CS-1, TLLI, last block, single chunk until the end of the block */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 432 | cs = CS1; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 433 | rdbi.data_len = mcs_max_data_block_bytes(cs); |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 434 | rdbi.e = 1; |
| 435 | rdbi.ti = 1; |
| 436 | rdbi.cv = 0; |
| 437 | tlli = 0; |
| 438 | tlli2 = 0xffeeddcc; |
| 439 | offs = 0; |
| 440 | data[offs++] = tlli2 >> 24; |
| 441 | data[offs++] = tlli2 >> 16; |
| 442 | data[offs++] = tlli2 >> 8; |
| 443 | data[offs++] = tlli2 >> 0; |
| 444 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 445 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 446 | OSMO_ASSERT(num_chunks == 1); |
| 447 | OSMO_ASSERT(tlli == tlli2); |
| 448 | OSMO_ASSERT(chunks[0].offset == 4); |
| 449 | OSMO_ASSERT(chunks[0].length == 16); |
| 450 | OSMO_ASSERT(chunks[0].is_complete); |
| 451 | |
| 452 | /* Like TS 44.060, B.2, first RLC block but with TLLI */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 453 | cs = CS1; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 454 | rdbi.data_len = mcs_max_data_block_bytes(cs); |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 455 | rdbi.e = 0; |
| 456 | rdbi.ti = 1; |
| 457 | rdbi.cv = 15; |
| 458 | tlli = 0; |
| 459 | tlli2 = 0xffeeddbb; |
| 460 | offs = 0; |
| 461 | data[offs++] = (0 << 2) | (0 << 1) | (1 << 0); |
| 462 | data[offs++] = tlli2 >> 24; |
| 463 | data[offs++] = tlli2 >> 16; |
| 464 | data[offs++] = tlli2 >> 8; |
| 465 | data[offs++] = tlli2 >> 0; |
| 466 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 467 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 468 | OSMO_ASSERT(num_chunks == 1); |
| 469 | OSMO_ASSERT(tlli == tlli2); |
| 470 | OSMO_ASSERT(chunks[0].offset == 5); |
| 471 | OSMO_ASSERT(chunks[0].length == 15); |
| 472 | OSMO_ASSERT(!chunks[0].is_complete); |
| 473 | |
| 474 | /* Like TS 44.060, B.8.1 but with TLLI */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 475 | cs = MCS4; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 476 | rdbi.data_len = mcs_max_data_block_bytes(cs); |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 477 | rdbi.e = 0; |
| 478 | rdbi.ti = 1; |
| 479 | rdbi.cv = 15; |
| 480 | tlli = 0; |
| 481 | tlli2 = 0xffeeddaa; |
| 482 | offs = 0; |
| 483 | data[offs++] = (11 << 1) | (0 << 0); |
| 484 | data[offs++] = (26 << 1) | (1 << 0); |
| 485 | /* Little endian */ |
| 486 | data[offs++] = tlli2 >> 0; |
| 487 | data[offs++] = tlli2 >> 8; |
| 488 | data[offs++] = tlli2 >> 16; |
| 489 | data[offs++] = tlli2 >> 24; |
| 490 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 491 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 492 | OSMO_ASSERT(num_chunks == 3); |
| 493 | OSMO_ASSERT(tlli == tlli2); |
| 494 | OSMO_ASSERT(chunks[0].offset == 6); |
| 495 | OSMO_ASSERT(chunks[0].length == 11); |
| 496 | OSMO_ASSERT(chunks[0].is_complete); |
| 497 | OSMO_ASSERT(chunks[1].offset == 17); |
| 498 | OSMO_ASSERT(chunks[1].length == 26); |
| 499 | OSMO_ASSERT(chunks[1].is_complete); |
| 500 | OSMO_ASSERT(chunks[2].offset == 43); |
| 501 | OSMO_ASSERT(chunks[2].length == 1); |
| 502 | OSMO_ASSERT(!chunks[2].is_complete); |
| 503 | |
Aravind Sirsikar | 3463bd4 | 2016-09-15 17:19:54 +0530 | [diff] [blame] | 504 | rdbi.e = 0; |
| 505 | rdbi.ti = 0; |
| 506 | rdbi.cv = 1; |
| 507 | tlli = 0; |
| 508 | offs = 0; |
| 509 | data[offs++] = 1; |
| 510 | num_chunks = Decoding::rlc_data_from_ul_data(&rdbi, cs, data, |
| 511 | chunks, ARRAY_SIZE(chunks), &tlli); |
| 512 | |
Aravind Sirsikar | 22a9019 | 2016-09-15 17:24:49 +0530 | [diff] [blame] | 513 | OSMO_ASSERT(num_chunks == 2); |
Aravind Sirsikar | 3463bd4 | 2016-09-15 17:19:54 +0530 | [diff] [blame] | 514 | OSMO_ASSERT(chunks[0].offset == 1); |
Aravind Sirsikar | 22a9019 | 2016-09-15 17:24:49 +0530 | [diff] [blame] | 515 | OSMO_ASSERT(chunks[0].length == 0); |
| 516 | OSMO_ASSERT(chunks[0].is_complete); |
| 517 | |
| 518 | OSMO_ASSERT(chunks[1].offset == 1); |
| 519 | OSMO_ASSERT(chunks[1].length == 43); |
| 520 | OSMO_ASSERT(!chunks[1].is_complete); |
Aravind Sirsikar | 3463bd4 | 2016-09-15 17:19:54 +0530 | [diff] [blame] | 521 | |
Jacob Erlbeck | 6167925 | 2015-12-11 18:25:21 +0100 | [diff] [blame] | 522 | printf("=== end %s ===\n", __func__); |
| 523 | } |
| 524 | |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 525 | static void test_rlc_unit_encoder() |
| 526 | { |
| 527 | struct gprs_rlc_data_block_info rdbi = {0}; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 528 | enum CodingScheme cs; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 529 | uint8_t data[74]; |
| 530 | uint8_t llc_data[1500] = {0,}; |
| 531 | int num_chunks = 0; |
| 532 | int write_offset; |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 533 | int count_payload; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 534 | struct gprs_llc llc; |
| 535 | Encoding::AppendResult ar; |
| 536 | |
| 537 | printf("=== start %s ===\n", __func__); |
| 538 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 539 | llc_init(&llc); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 540 | |
| 541 | /* TS 44.060, B.1 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 542 | cs = CS4; |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 543 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 544 | num_chunks = 0; |
| 545 | write_offset = 0; |
| 546 | memset(data, 0, sizeof(data)); |
| 547 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 548 | llc_reset(&llc); |
| 549 | llc_put_frame(&llc, llc_data, 11); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 550 | count_payload = -1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 551 | |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 552 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 553 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 554 | |
| 555 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_SPACE_LEFT); |
| 556 | OSMO_ASSERT(rdbi.e == 0); |
| 557 | OSMO_ASSERT(write_offset == 1 + 11); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 558 | OSMO_ASSERT(count_payload == 11); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 559 | OSMO_ASSERT(num_chunks == 1); |
| 560 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 561 | llc_reset(&llc); |
| 562 | llc_put_frame(&llc, llc_data, 26); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 563 | count_payload = -1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 564 | |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 565 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 566 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 567 | |
| 568 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_SPACE_LEFT); |
| 569 | OSMO_ASSERT(rdbi.e == 0); |
| 570 | OSMO_ASSERT(write_offset == 2 + 11 + 26); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 571 | OSMO_ASSERT(count_payload == 26); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 572 | OSMO_ASSERT(num_chunks == 2); |
| 573 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 574 | llc_reset(&llc); |
| 575 | llc_put_frame(&llc, llc_data, 99); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 576 | count_payload = -1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 577 | |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 578 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 579 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 580 | |
| 581 | OSMO_ASSERT(ar == Encoding::AR_NEED_MORE_BLOCKS); |
| 582 | OSMO_ASSERT(rdbi.e == 0); |
| 583 | OSMO_ASSERT(rdbi.cv != 0); |
| 584 | OSMO_ASSERT(write_offset == (int)rdbi.data_len); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 585 | OSMO_ASSERT(count_payload == 11); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 586 | OSMO_ASSERT(num_chunks == 3); |
| 587 | |
| 588 | OSMO_ASSERT(data[0] == ((11 << 2) | (1 << 1) | (0 << 0))); |
| 589 | OSMO_ASSERT(data[1] == ((26 << 2) | (1 << 1) | (1 << 0))); |
| 590 | OSMO_ASSERT(data[2] == 0); |
| 591 | |
| 592 | /* TS 44.060, B.2 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 593 | cs = CS1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 594 | |
| 595 | /* Block 1 */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 596 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 597 | num_chunks = 0; |
| 598 | write_offset = 0; |
| 599 | memset(data, 0, sizeof(data)); |
| 600 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 601 | llc_reset(&llc); |
| 602 | llc_put_frame(&llc, llc_data, 20); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 603 | count_payload = -1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 604 | |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 605 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 606 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 607 | |
| 608 | OSMO_ASSERT(ar == Encoding::AR_NEED_MORE_BLOCKS); |
| 609 | OSMO_ASSERT(rdbi.e == 0); |
| 610 | OSMO_ASSERT(write_offset == 1 + 19); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 611 | OSMO_ASSERT(count_payload == 19); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 612 | OSMO_ASSERT(num_chunks == 1); |
| 613 | |
| 614 | OSMO_ASSERT(data[0] == ((0 << 2) | (0 << 1) | (1 << 0))); |
| 615 | OSMO_ASSERT(data[1] == 0); |
| 616 | |
| 617 | /* Block 2 */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 618 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 619 | num_chunks = 0; |
| 620 | write_offset = 0; |
| 621 | memset(data, 0, sizeof(data)); |
| 622 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 623 | OSMO_ASSERT(llc_chunk_size(&llc) == 1); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 624 | |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 625 | count_payload = -1; |
| 626 | |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 627 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 628 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 629 | |
| 630 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_SPACE_LEFT); |
| 631 | OSMO_ASSERT(rdbi.e == 0); |
| 632 | OSMO_ASSERT(write_offset == 1 + 1); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 633 | OSMO_ASSERT(count_payload == 1); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 634 | OSMO_ASSERT(num_chunks == 1); |
| 635 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 636 | llc_reset(&llc); |
| 637 | llc_put_frame(&llc, llc_data, 99); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 638 | count_payload = -1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 639 | |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 640 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 641 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 642 | |
| 643 | OSMO_ASSERT(ar == Encoding::AR_NEED_MORE_BLOCKS); |
| 644 | OSMO_ASSERT(rdbi.e == 0); |
| 645 | OSMO_ASSERT(write_offset == 1 + 1 + 18); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 646 | OSMO_ASSERT(count_payload == 18); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 647 | OSMO_ASSERT(num_chunks == 2); |
| 648 | |
| 649 | OSMO_ASSERT(data[0] == ((1 << 2) | (1 << 1) | (1 << 0))); |
| 650 | OSMO_ASSERT(data[1] == 0); |
| 651 | |
| 652 | /* TS 44.060, B.3 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 653 | cs = CS1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 654 | |
| 655 | /* Block 1 */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 656 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 657 | num_chunks = 0; |
| 658 | write_offset = 0; |
| 659 | memset(data, 0, sizeof(data)); |
| 660 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 661 | llc_reset(&llc); |
| 662 | llc_put_frame(&llc, llc_data, 7); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 663 | count_payload = -1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 664 | |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 665 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 666 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 667 | |
| 668 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_SPACE_LEFT); |
| 669 | OSMO_ASSERT(rdbi.e == 0); |
| 670 | OSMO_ASSERT(write_offset == 1 + 7); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 671 | OSMO_ASSERT(count_payload == 7); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 672 | OSMO_ASSERT(num_chunks == 1); |
| 673 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 674 | llc_reset(&llc); |
| 675 | llc_put_frame(&llc, llc_data, 11); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 676 | count_payload = -1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 677 | |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 678 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 679 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 680 | |
| 681 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_BLOCK_FILLED); |
| 682 | OSMO_ASSERT(rdbi.e == 0); |
| 683 | OSMO_ASSERT(write_offset == 2 + 7 + 11); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 684 | OSMO_ASSERT(count_payload == 11); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 685 | OSMO_ASSERT(num_chunks == 2); |
| 686 | |
| 687 | OSMO_ASSERT(data[0] == ((7 << 2) | (1 << 1) | (0 << 0))); |
| 688 | OSMO_ASSERT(data[1] == ((11 << 2) | (0 << 1) | (1 << 0))); |
| 689 | OSMO_ASSERT(data[2] == 0); |
| 690 | |
| 691 | /* TS 44.060, B.4 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 692 | cs = CS1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 693 | |
| 694 | /* Block 1 */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 695 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 696 | num_chunks = 0; |
| 697 | write_offset = 0; |
| 698 | memset(data, 0, sizeof(data)); |
| 699 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 700 | llc_reset(&llc); |
| 701 | llc_put_frame(&llc, llc_data, 99); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 702 | count_payload = -1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 703 | |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 704 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 705 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 706 | |
| 707 | OSMO_ASSERT(ar == Encoding::AR_NEED_MORE_BLOCKS); |
| 708 | OSMO_ASSERT(rdbi.e == 1); |
| 709 | OSMO_ASSERT(write_offset == 20); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 710 | OSMO_ASSERT(count_payload == 20); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 711 | OSMO_ASSERT(num_chunks == 1); |
| 712 | OSMO_ASSERT(rdbi.cv != 0); |
| 713 | |
| 714 | OSMO_ASSERT(data[0] == 0); |
| 715 | |
| 716 | /* TS 44.060, B.5 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 717 | cs = CS1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 718 | |
| 719 | /* Block 1 */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 720 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 721 | num_chunks = 0; |
| 722 | write_offset = 0; |
| 723 | memset(data, 0, sizeof(data)); |
| 724 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 725 | llc_reset(&llc); |
| 726 | llc_put_frame(&llc, llc_data, 20); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 727 | count_payload = -1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 728 | |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 729 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 730 | &llc, &write_offset, &num_chunks, data, true, &count_payload); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 731 | |
| 732 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_BLOCK_FILLED); |
| 733 | OSMO_ASSERT(rdbi.e == 1); |
| 734 | OSMO_ASSERT(write_offset == 20); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 735 | OSMO_ASSERT(count_payload == 20); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 736 | OSMO_ASSERT(num_chunks == 1); |
| 737 | OSMO_ASSERT(rdbi.cv == 0); |
| 738 | |
| 739 | OSMO_ASSERT(data[0] == 0); |
| 740 | |
| 741 | /* TS 44.060, B.7 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 742 | cs = CS1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 743 | |
| 744 | /* Block 1 */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 745 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 746 | num_chunks = 0; |
| 747 | write_offset = 0; |
| 748 | memset(data, 0, sizeof(data)); |
| 749 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 750 | llc_reset(&llc); |
| 751 | llc_put_frame(&llc, llc_data, 30); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 752 | count_payload = -1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 753 | |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 754 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 755 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 756 | |
| 757 | OSMO_ASSERT(ar == Encoding::AR_NEED_MORE_BLOCKS); |
| 758 | OSMO_ASSERT(rdbi.e == 1); |
| 759 | OSMO_ASSERT(write_offset == 20); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 760 | OSMO_ASSERT(count_payload == 20); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 761 | OSMO_ASSERT(num_chunks == 1); |
| 762 | |
| 763 | OSMO_ASSERT(data[0] == 0); |
| 764 | |
| 765 | /* Block 2 */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 766 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 767 | num_chunks = 0; |
| 768 | write_offset = 0; |
| 769 | memset(data, 0, sizeof(data)); |
| 770 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 771 | OSMO_ASSERT(llc_chunk_size(&llc) == 10); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 772 | count_payload = -1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 773 | |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 774 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 775 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 776 | |
| 777 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_SPACE_LEFT); |
| 778 | OSMO_ASSERT(rdbi.e == 0); |
| 779 | OSMO_ASSERT(write_offset == 1 + 10); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 780 | OSMO_ASSERT(count_payload == 10); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 781 | OSMO_ASSERT(num_chunks == 1); |
| 782 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 783 | llc_reset(&llc); |
| 784 | llc_put_frame(&llc, llc_data, 99); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 785 | count_payload = -1; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 786 | |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 787 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 788 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 789 | |
| 790 | OSMO_ASSERT(ar == Encoding::AR_NEED_MORE_BLOCKS); |
| 791 | OSMO_ASSERT(rdbi.e == 0); |
| 792 | OSMO_ASSERT(write_offset == 1 + 10 + 9); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 793 | OSMO_ASSERT(count_payload == 9); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 794 | OSMO_ASSERT(num_chunks == 2); |
| 795 | |
| 796 | OSMO_ASSERT(data[0] == ((10 << 2) | (1 << 1) | (1 << 0))); |
| 797 | OSMO_ASSERT(data[1] == 0); |
| 798 | |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 799 | /* TS 44.060, B.8.1 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 800 | cs = MCS4; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 801 | |
| 802 | /* Block 1 */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 803 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 804 | num_chunks = 0; |
| 805 | write_offset = 0; |
| 806 | memset(data, 0, sizeof(data)); |
| 807 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 808 | llc_reset(&llc); |
| 809 | llc_put_frame(&llc, llc_data, 11); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 810 | count_payload = -1; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 811 | |
| 812 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 813 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 814 | |
| 815 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_SPACE_LEFT); |
| 816 | OSMO_ASSERT(rdbi.e == 0); |
| 817 | OSMO_ASSERT(write_offset == 1 + 11); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 818 | OSMO_ASSERT(count_payload == 11); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 819 | OSMO_ASSERT(num_chunks == 1); |
| 820 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 821 | llc_reset(&llc); |
| 822 | llc_put_frame(&llc, llc_data, 26); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 823 | count_payload = -1; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 824 | |
| 825 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 826 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 827 | |
| 828 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_SPACE_LEFT); |
| 829 | OSMO_ASSERT(rdbi.e == 0); |
| 830 | OSMO_ASSERT(write_offset == 2 + 11 + 26); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 831 | OSMO_ASSERT(count_payload == 26); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 832 | OSMO_ASSERT(num_chunks == 2); |
| 833 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 834 | llc_reset(&llc); |
| 835 | llc_put_frame(&llc, llc_data, 99); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 836 | count_payload = -1; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 837 | |
| 838 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 839 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 840 | |
| 841 | OSMO_ASSERT(ar == Encoding::AR_NEED_MORE_BLOCKS); |
| 842 | OSMO_ASSERT(rdbi.e == 0); |
| 843 | OSMO_ASSERT(rdbi.cv != 0); |
| 844 | OSMO_ASSERT(write_offset == (int)rdbi.data_len); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 845 | OSMO_ASSERT(count_payload == 5); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 846 | OSMO_ASSERT(num_chunks == 3); |
| 847 | |
| 848 | OSMO_ASSERT(data[0] == ((11 << 1) | (0 << 0))); |
| 849 | OSMO_ASSERT(data[1] == ((26 << 1) | (1 << 0))); |
| 850 | OSMO_ASSERT(data[2] == 0); |
| 851 | |
| 852 | /* TS 44.060, B.8.2 */ |
| 853 | |
| 854 | /* Note that the spec confuses the byte numbering here, since it |
| 855 | * includes the FBI/E header bits into the N2 octet count which |
| 856 | * is not consistent with Section 10.3a.1 & 10.3a.2. */ |
| 857 | |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 858 | cs = MCS2; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 859 | |
| 860 | /* Block 1 */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 861 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 862 | num_chunks = 0; |
| 863 | write_offset = 0; |
| 864 | memset(data, 0, sizeof(data)); |
| 865 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 866 | llc_reset(&llc); |
| 867 | llc_put_frame(&llc, llc_data, 15); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 868 | count_payload = -1; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 869 | |
| 870 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 871 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 872 | |
| 873 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_SPACE_LEFT); |
| 874 | OSMO_ASSERT(rdbi.e == 0); |
| 875 | OSMO_ASSERT(write_offset == 1 + 15); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 876 | OSMO_ASSERT(count_payload == 15); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 877 | OSMO_ASSERT(num_chunks == 1); |
| 878 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 879 | llc_reset(&llc); |
| 880 | llc_put_frame(&llc, llc_data, 12); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 881 | count_payload = -1; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 882 | |
| 883 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 884 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 885 | |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 886 | /* no LI here, becaues there are exact 12 bytes left. Put LI into next frame */ |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 887 | OSMO_ASSERT(ar == Encoding::AR_NEED_MORE_BLOCKS); |
| 888 | OSMO_ASSERT(rdbi.e == 0); |
| 889 | OSMO_ASSERT(rdbi.cv != 0); |
| 890 | OSMO_ASSERT(write_offset == (int)rdbi.data_len); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 891 | OSMO_ASSERT(count_payload == 12); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 892 | OSMO_ASSERT(num_chunks == 2); |
| 893 | |
| 894 | OSMO_ASSERT(data[0] == ((15 << 1) | (1 << 0))); |
| 895 | OSMO_ASSERT(data[1] == 0); |
| 896 | |
| 897 | /* Block 2 */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 898 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 899 | num_chunks = 0; |
| 900 | write_offset = 0; |
| 901 | memset(data, 0, sizeof(data)); |
| 902 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 903 | OSMO_ASSERT(llc_chunk_size(&llc) == 0); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 904 | count_payload = -1; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 905 | |
| 906 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 907 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 908 | |
| 909 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_SPACE_LEFT); |
| 910 | OSMO_ASSERT(rdbi.e == 0); |
| 911 | OSMO_ASSERT(write_offset == 1 + 0); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 912 | OSMO_ASSERT(count_payload == 0); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 913 | OSMO_ASSERT(num_chunks == 1); |
| 914 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 915 | llc_reset(&llc); |
| 916 | llc_put_frame(&llc, llc_data, 7); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 917 | count_payload = -1; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 918 | |
| 919 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 920 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 921 | |
| 922 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_SPACE_LEFT); |
| 923 | OSMO_ASSERT(rdbi.e == 0); |
| 924 | OSMO_ASSERT(rdbi.cv != 0); |
| 925 | OSMO_ASSERT(write_offset == 2 + 0 + 7); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 926 | OSMO_ASSERT(count_payload == 7); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 927 | OSMO_ASSERT(num_chunks == 2); |
| 928 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 929 | llc_reset(&llc); |
| 930 | llc_put_frame(&llc, llc_data, 18); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 931 | count_payload = -1; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 932 | |
| 933 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 934 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 935 | |
| 936 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_BLOCK_FILLED); |
| 937 | OSMO_ASSERT(rdbi.e == 0); |
| 938 | OSMO_ASSERT(rdbi.cv != 0); |
| 939 | OSMO_ASSERT(write_offset == (int)rdbi.data_len); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 940 | OSMO_ASSERT(count_payload == 18); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 941 | OSMO_ASSERT(num_chunks == 3); |
| 942 | |
| 943 | OSMO_ASSERT(data[0] == ((0 << 1) | (0 << 0))); |
| 944 | OSMO_ASSERT(data[1] == ((7 << 1) | (0 << 0))); |
| 945 | OSMO_ASSERT(data[2] == ((18 << 1) | (1 << 0))); |
| 946 | OSMO_ASSERT(data[3] == 0); |
| 947 | |
| 948 | /* Block 3 */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 949 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 950 | num_chunks = 0; |
| 951 | write_offset = 0; |
| 952 | memset(data, 0, sizeof(data)); |
| 953 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 954 | llc_reset(&llc); |
| 955 | llc_put_frame(&llc, llc_data, 6); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 956 | count_payload = -1; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 957 | |
| 958 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 959 | &llc, &write_offset, &num_chunks, data, false, &count_payload); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 960 | |
| 961 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_SPACE_LEFT); |
| 962 | OSMO_ASSERT(rdbi.e == 0); |
| 963 | OSMO_ASSERT(write_offset == 1 + 6); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 964 | OSMO_ASSERT(count_payload == 6); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 965 | OSMO_ASSERT(num_chunks == 1); |
| 966 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 967 | llc_reset(&llc); |
| 968 | llc_put_frame(&llc, llc_data, 12); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 969 | count_payload = -1; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 970 | |
| 971 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 972 | &llc, &write_offset, &num_chunks, data, true, &count_payload); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 973 | |
| 974 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_BLOCK_FILLED); |
| 975 | OSMO_ASSERT(rdbi.e == 0); |
| 976 | OSMO_ASSERT(rdbi.cv == 0); |
| 977 | OSMO_ASSERT(write_offset == (int)rdbi.data_len); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 978 | OSMO_ASSERT(count_payload == 12); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 979 | OSMO_ASSERT(num_chunks == 3); |
| 980 | |
| 981 | OSMO_ASSERT(data[0] == ((6 << 1) | (0 << 0))); |
| 982 | OSMO_ASSERT(data[1] == ((12 << 1) | (0 << 0))); |
| 983 | OSMO_ASSERT(data[2] == ((127 << 1) | (1 << 0))); |
| 984 | OSMO_ASSERT(data[3] == 0); |
| 985 | |
| 986 | /* TS 44.060, B.8.3 */ |
| 987 | |
| 988 | /* Note that the spec confuses the byte numbering here, too (see above) */ |
| 989 | |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 990 | cs = MCS2; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 991 | |
| 992 | /* Block 1 */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 993 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 994 | num_chunks = 0; |
| 995 | write_offset = 0; |
| 996 | memset(data, 0, sizeof(data)); |
| 997 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 998 | llc_reset(&llc); |
| 999 | llc_put_frame(&llc, llc_data, rdbi.data_len); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1000 | count_payload = -1; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1001 | |
| 1002 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1003 | &llc, &write_offset, &num_chunks, data, true, &count_payload); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1004 | |
| 1005 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_BLOCK_FILLED); |
| 1006 | OSMO_ASSERT(rdbi.e == 1); |
| 1007 | OSMO_ASSERT(rdbi.cv == 0); |
| 1008 | OSMO_ASSERT(write_offset == (int)rdbi.data_len); |
Neels Hofmeyr | d34646a | 2017-02-08 17:07:40 +0100 | [diff] [blame] | 1009 | OSMO_ASSERT(rdbi.data_len <= INT_MAX && count_payload == (int)rdbi.data_len); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1010 | OSMO_ASSERT(num_chunks == 1); |
| 1011 | |
| 1012 | OSMO_ASSERT(data[0] == 0); |
| 1013 | |
| 1014 | /* Final block with an LLC of size data_len-1 */ |
| 1015 | |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 1016 | cs = MCS2; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1017 | |
| 1018 | /* Block 1 */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 1019 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1020 | num_chunks = 0; |
| 1021 | write_offset = 0; |
| 1022 | memset(data, 0, sizeof(data)); |
| 1023 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 1024 | llc_reset(&llc); |
| 1025 | llc_put_frame(&llc, llc_data, rdbi.data_len - 1); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1026 | count_payload = -1; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1027 | |
| 1028 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1029 | &llc, &write_offset, &num_chunks, data, true, &count_payload); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1030 | |
| 1031 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_BLOCK_FILLED); |
| 1032 | OSMO_ASSERT(rdbi.e == 0); |
| 1033 | OSMO_ASSERT(rdbi.cv == 0); |
| 1034 | OSMO_ASSERT(write_offset == (int)rdbi.data_len); |
Neels Hofmeyr | d34646a | 2017-02-08 17:07:40 +0100 | [diff] [blame] | 1035 | OSMO_ASSERT((rdbi.data_len - 1) <= INT_MAX |
| 1036 | && count_payload == (int)(rdbi.data_len - 1)); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1037 | OSMO_ASSERT(num_chunks == 1); |
| 1038 | |
| 1039 | OSMO_ASSERT(data[0] == (((rdbi.data_len-1) << 1) | (1 << 0))); |
| 1040 | OSMO_ASSERT(data[1] == 0); |
| 1041 | |
| 1042 | /* Final block with an LLC of size data_len-2 */ |
| 1043 | |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 1044 | cs = MCS2; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1045 | |
| 1046 | /* Block 1 */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 1047 | gprs_rlc_data_block_info_init(&rdbi, cs, false, 0); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1048 | num_chunks = 0; |
| 1049 | write_offset = 0; |
| 1050 | memset(data, 0, sizeof(data)); |
| 1051 | |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 1052 | llc_reset(&llc); |
| 1053 | llc_put_frame(&llc, llc_data, rdbi.data_len - 2); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1054 | count_payload = -1; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1055 | |
| 1056 | ar = Encoding::rlc_data_to_dl_append(&rdbi, cs, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1057 | &llc, &write_offset, &num_chunks, data, true, &count_payload); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1058 | |
| 1059 | OSMO_ASSERT(ar == Encoding::AR_COMPLETED_BLOCK_FILLED); |
| 1060 | OSMO_ASSERT(rdbi.e == 0); |
| 1061 | OSMO_ASSERT(rdbi.cv == 0); |
| 1062 | OSMO_ASSERT(write_offset == (int)rdbi.data_len); |
Neels Hofmeyr | d34646a | 2017-02-08 17:07:40 +0100 | [diff] [blame] | 1063 | OSMO_ASSERT((rdbi.data_len - 2) <= INT_MAX |
| 1064 | && count_payload == (int)(rdbi.data_len - 2)); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1065 | OSMO_ASSERT(num_chunks == 2); |
| 1066 | |
| 1067 | OSMO_ASSERT(data[0] == (((rdbi.data_len-2) << 1) | (0 << 0))); |
| 1068 | OSMO_ASSERT(data[1] == ((127 << 1) | (1 << 0))); |
| 1069 | OSMO_ASSERT(data[2] == 0); |
| 1070 | |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1071 | printf("=== end %s ===\n", __func__); |
| 1072 | } |
| 1073 | |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1074 | static void test_rlc_unaligned_copy() |
| 1075 | { |
| 1076 | uint8_t bits[256]; |
| 1077 | uint8_t saved_block[256]; |
| 1078 | uint8_t test_block[256]; |
| 1079 | uint8_t out_block[256]; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 1080 | enum CodingScheme cs; |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1081 | int pattern; |
| 1082 | volatile unsigned int block_idx, i; |
| 1083 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 1084 | for (cs = CS1; cs < NUM_SCHEMES; cs = static_cast<enum CodingScheme>(cs + 1)) |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1085 | { |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1086 | for (pattern = 0; pattern <= 0xff; pattern += 0xff) { |
| 1087 | /* prepare test block */ |
| 1088 | test_block[0] = pattern ^ 0xff; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 1089 | for (i = 1; i + 1 < mcs_max_data_block_bytes(cs); i++) |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1090 | test_block[i] = i; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 1091 | test_block[mcs_max_data_block_bytes(cs)-1] = pattern ^ 0xff; |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1092 | |
| 1093 | for (block_idx = 0; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 1094 | block_idx < num_data_blocks(mcs_header_type(cs)); |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1095 | block_idx++) |
| 1096 | { |
| 1097 | struct gprs_rlc_data_info rlc; |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 1098 | gprs_rlc_data_info_init_dl(&rlc, cs, false, 0); |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1099 | |
| 1100 | memset(bits, pattern, sizeof(bits)); |
| 1101 | Decoding::rlc_copy_to_aligned_buffer( |
| 1102 | &rlc, block_idx, bits, saved_block); |
| 1103 | |
| 1104 | fprintf(stderr, |
| 1105 | "Test data block: %s\n", |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 1106 | osmo_hexdump(test_block, mcs_max_data_block_bytes(cs))); |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1107 | |
| 1108 | Encoding::rlc_copy_from_aligned_buffer( |
| 1109 | &rlc, block_idx, bits, test_block); |
| 1110 | |
| 1111 | fprintf(stderr, |
| 1112 | "Encoded message block, %s, idx %d, " |
| 1113 | "pattern %02x: %s\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 1114 | mcs_name(rlc.cs), block_idx, pattern, |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 1115 | osmo_hexdump(bits, mcs_size_dl(cs))); |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1116 | |
| 1117 | Decoding::rlc_copy_to_aligned_buffer( |
| 1118 | &rlc, block_idx, bits, out_block); |
| 1119 | |
| 1120 | fprintf(stderr, |
| 1121 | "Out data block: %s\n", |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 1122 | osmo_hexdump(out_block, mcs_max_data_block_bytes(cs))); |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1123 | /* restore original bits */ |
| 1124 | Encoding::rlc_copy_from_aligned_buffer( |
| 1125 | &rlc, block_idx, bits, saved_block); |
| 1126 | |
| 1127 | OSMO_ASSERT(memcmp(test_block, out_block, |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 1128 | mcs_max_data_block_bytes(rlc.cs)) == 0); |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1129 | |
| 1130 | for (i = 0; i < sizeof(bits); i++) |
| 1131 | OSMO_ASSERT(bits[i] == pattern); |
| 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | } |
| 1136 | |
Jacob Erlbeck | 6e9f9c2 | 2016-01-11 11:15:45 +0100 | [diff] [blame] | 1137 | static void test_rlc_info_init() |
| 1138 | { |
| 1139 | struct gprs_rlc_data_info rlc; |
| 1140 | |
| 1141 | printf("=== start %s ===\n", __func__); |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 1142 | gprs_rlc_data_info_init_dl(&rlc, CS1, false, 0); |
Jacob Erlbeck | 6e9f9c2 | 2016-01-11 11:15:45 +0100 | [diff] [blame] | 1143 | OSMO_ASSERT(rlc.num_data_blocks == 1); |
| 1144 | OSMO_ASSERT(rlc.data_offs_bits[0] == 24); |
| 1145 | OSMO_ASSERT(rlc.block_info[0].data_len == 20); |
| 1146 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 1147 | gprs_rlc_data_info_init_dl(&rlc, MCS1, false, 0); |
Jacob Erlbeck | 6e9f9c2 | 2016-01-11 11:15:45 +0100 | [diff] [blame] | 1148 | OSMO_ASSERT(rlc.num_data_blocks == 1); |
| 1149 | OSMO_ASSERT(rlc.data_offs_bits[0] == 33); |
| 1150 | OSMO_ASSERT(rlc.block_info[0].data_len == 22); |
| 1151 | |
| 1152 | printf("=== end %s ===\n", __func__); |
| 1153 | } |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 1154 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1155 | static void setup_bts(struct gprs_rlcmac_bts *bts, uint8_t ts_no, uint8_t cs = 1) |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1156 | { |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1157 | gprs_rlcmac_trx *trx; |
| 1158 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1159 | the_pcu->alloc_algorithm = alloc_algorithm_a; |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1160 | bts->initial_cs_dl = cs; |
| 1161 | bts->initial_cs_ul = cs; |
| 1162 | trx = &bts->trx[0]; |
| 1163 | trx->pdch[ts_no].enable(); |
| 1164 | } |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1165 | static void uplink_header_type_2_parsing_test(struct gprs_rlcmac_bts *bts, |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1166 | uint8_t ts_no, uint32_t tlli, uint32_t *fn, uint16_t qta, |
| 1167 | uint8_t ms_class) |
| 1168 | { |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1169 | int tfi = 0; |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1170 | uint8_t data[79] = {0}; |
| 1171 | struct gprs_rlc_ul_header_egprs_2 *egprs2 = NULL; |
| 1172 | |
| 1173 | egprs2 = (struct gprs_rlc_ul_header_egprs_2 *) data; |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1174 | |
| 1175 | tfi = 1; |
| 1176 | |
| 1177 | struct gprs_rlc_data_info rlc; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 1178 | enum CodingScheme cs; |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1179 | int rc, offs; |
| 1180 | |
| 1181 | /*without padding*/ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 1182 | cs = MCS5; |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1183 | egprs2 = (struct gprs_rlc_ul_header_egprs_2 *) data; |
| 1184 | egprs2->r = 1; |
| 1185 | egprs2->si = 1; |
| 1186 | egprs2->cv = 7; |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 1187 | egprs2->tfi_hi = tfi & 0x03; |
| 1188 | egprs2->tfi_lo = (tfi & 0x1c) >> 2; |
| 1189 | egprs2->bsn1_hi = 0; |
| 1190 | egprs2->bsn1_lo = 0; |
| 1191 | egprs2->cps_hi = 3; |
| 1192 | egprs2->cps_lo = 0; |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1193 | egprs2->rsb = 0; |
| 1194 | egprs2->pi = 0; |
| 1195 | data[4] = 0x20; /* Setting E field */ |
| 1196 | rc = Decoding::rlc_parse_ul_data_header(&rlc, data, cs); |
Neels Hofmeyr | de9da39 | 2017-02-08 17:34:56 +0100 | [diff] [blame] | 1197 | OSMO_ASSERT(rc == 487); |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1198 | offs = rlc.data_offs_bits[0] / 8; |
| 1199 | OSMO_ASSERT(offs == 4); |
| 1200 | OSMO_ASSERT(rlc.tfi == 1); |
| 1201 | OSMO_ASSERT(rlc.num_data_blocks == 1); |
| 1202 | OSMO_ASSERT(rlc.block_info[0].e == 1); |
| 1203 | OSMO_ASSERT(rlc.block_info[0].ti == 0); |
| 1204 | OSMO_ASSERT(rlc.block_info[0].bsn == 0); |
| 1205 | |
| 1206 | /* with padding case */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 1207 | cs = MCS6; |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1208 | egprs2 = (struct gprs_rlc_ul_header_egprs_2 *) data; |
| 1209 | egprs2->r = 1; |
| 1210 | egprs2->si = 1; |
| 1211 | egprs2->cv = 7; |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 1212 | egprs2->tfi_hi = tfi & 0x03; |
| 1213 | egprs2->tfi_lo = (tfi & 0x1c) >> 2; |
| 1214 | egprs2->bsn1_hi = 0; |
| 1215 | egprs2->bsn1_lo = 0; |
| 1216 | egprs2->cps_hi = 3; |
| 1217 | egprs2->cps_lo = 0; |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1218 | egprs2->rsb = 0; |
| 1219 | egprs2->pi = 0; |
| 1220 | data[10] = 0x20; /* Setting E field */ |
| 1221 | rc = Decoding::rlc_parse_ul_data_header(&rlc, data, cs); |
Neels Hofmeyr | de9da39 | 2017-02-08 17:34:56 +0100 | [diff] [blame] | 1222 | OSMO_ASSERT(rc == 679); |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1223 | offs = rlc.data_offs_bits[0] / 8; |
| 1224 | OSMO_ASSERT(offs == 10); |
| 1225 | OSMO_ASSERT(rlc.num_data_blocks == 1); |
| 1226 | OSMO_ASSERT(rlc.tfi == 1); |
| 1227 | OSMO_ASSERT(rlc.block_info[0].e == 1); |
| 1228 | OSMO_ASSERT(rlc.block_info[0].ti == 0); |
| 1229 | OSMO_ASSERT(rlc.block_info[0].bsn == 0); |
| 1230 | |
| 1231 | egprs2->r = 1; |
| 1232 | egprs2->si = 1; |
| 1233 | egprs2->cv = 7; |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 1234 | egprs2->tfi_hi = tfi & 0x03; |
| 1235 | egprs2->tfi_lo = (tfi & 0x1c) >> 2; |
| 1236 | egprs2->bsn1_hi = 1; |
| 1237 | egprs2->bsn1_lo = 0; |
| 1238 | egprs2->cps_hi = 2; |
| 1239 | egprs2->cps_lo = 0; |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1240 | egprs2->rsb = 0; |
| 1241 | egprs2->pi = 0; |
| 1242 | data[10] = 0x20; /* Setting E field */ |
| 1243 | rc = Decoding::rlc_parse_ul_data_header(&rlc, data, cs); |
Neels Hofmeyr | de9da39 | 2017-02-08 17:34:56 +0100 | [diff] [blame] | 1244 | OSMO_ASSERT(rc == 679); |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1245 | offs = rlc.data_offs_bits[0] / 8; |
| 1246 | OSMO_ASSERT(offs == 10); |
| 1247 | OSMO_ASSERT(rlc.tfi == 1); |
| 1248 | OSMO_ASSERT(rlc.num_data_blocks == 1); |
| 1249 | OSMO_ASSERT(rlc.block_info[0].e == 1); |
| 1250 | OSMO_ASSERT(rlc.block_info[0].ti == 0); |
| 1251 | OSMO_ASSERT(rlc.block_info[0].bsn == 1); |
| 1252 | } |
| 1253 | |
| 1254 | static void uplink_header_type2_test(void) |
| 1255 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1256 | struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0); |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1257 | int ts_no = 7; |
| 1258 | uint32_t fn = 2654218; |
| 1259 | uint16_t qta = 31; |
| 1260 | uint32_t tlli = 0xf1223344; |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1261 | uint8_t ms_class = 1; |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1262 | |
| 1263 | printf("=== start %s ===\n", __func__); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1264 | setup_bts(bts, ts_no, 10); |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1265 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1266 | uplink_header_type_2_parsing_test(bts, ts_no, |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1267 | tlli, &fn, qta, ms_class); |
| 1268 | printf("=== end %s ===\n", __func__); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1269 | talloc_free(bts); |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1270 | } |
| 1271 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1272 | static void uplink_header_type_1_parsing_test(struct gprs_rlcmac_bts *bts, |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1273 | uint8_t ts_no, uint32_t tlli, uint32_t *fn, uint16_t qta, |
| 1274 | uint8_t ms_class) |
| 1275 | { |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1276 | int tfi = 0; |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1277 | uint8_t data[155] = {0}; |
| 1278 | struct gprs_rlc_ul_header_egprs_1 *egprs1 = NULL; |
| 1279 | struct gprs_rlc_data_info rlc; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 1280 | enum CodingScheme cs; |
Neels Hofmeyr | d34646a | 2017-02-08 17:07:40 +0100 | [diff] [blame] | 1281 | int rc; |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1282 | |
| 1283 | egprs1 = (struct gprs_rlc_ul_header_egprs_1 *) data; |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1284 | |
| 1285 | tfi = 1; |
| 1286 | |
| 1287 | /* MCS 7 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 1288 | cs = MCS7; |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1289 | egprs1 = (struct gprs_rlc_ul_header_egprs_1 *) data; |
| 1290 | egprs1->si = 1; |
| 1291 | egprs1->r = 1; |
| 1292 | egprs1->cv = 7; |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 1293 | egprs1->tfi_hi = tfi & 0x03; |
| 1294 | egprs1->tfi_lo = (tfi & 0x1c) >> 2; |
| 1295 | egprs1->bsn1_hi = 0; |
| 1296 | egprs1->bsn1_lo = 0; |
| 1297 | egprs1->bsn2_hi = 1; |
| 1298 | egprs1->bsn2_lo = 0; |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1299 | egprs1->cps = 15; |
| 1300 | egprs1->rsb = 0; |
| 1301 | egprs1->pi = 0; |
| 1302 | data[5] = 0xc0; |
| 1303 | data[5 + 57] = 1; |
| 1304 | rc = Decoding::rlc_parse_ul_data_header(&rlc, data, cs); |
Neels Hofmeyr | de9da39 | 2017-02-08 17:34:56 +0100 | [diff] [blame] | 1305 | OSMO_ASSERT(rc == 946); |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1306 | OSMO_ASSERT(rlc.num_data_blocks == 2); |
| 1307 | OSMO_ASSERT(rlc.block_info[0].e == 1); |
| 1308 | OSMO_ASSERT(rlc.block_info[0].ti == 1); |
| 1309 | OSMO_ASSERT(rlc.block_info[1].e == 1); |
| 1310 | OSMO_ASSERT(rlc.block_info[1].ti == 0); |
| 1311 | OSMO_ASSERT(rlc.block_info[0].bsn == 0); |
| 1312 | OSMO_ASSERT(rlc.block_info[1].bsn == 1); |
| 1313 | OSMO_ASSERT(rlc.tfi == 1); |
| 1314 | |
| 1315 | /* MCS 8 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 1316 | cs = MCS8; |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1317 | egprs1 = (struct gprs_rlc_ul_header_egprs_1 *) data; |
| 1318 | egprs1->si = 1; |
| 1319 | egprs1->r = 1; |
| 1320 | egprs1->cv = 7; |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 1321 | egprs1->tfi_hi = tfi & 0x03; |
| 1322 | egprs1->tfi_lo = (tfi & 0x1c) >> 2; |
| 1323 | egprs1->bsn1_hi = 0; |
| 1324 | egprs1->bsn1_lo = 0; |
| 1325 | egprs1->bsn2_hi = 1; |
| 1326 | egprs1->bsn2_lo = 0; |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1327 | egprs1->cps = 15; |
| 1328 | egprs1->rsb = 0; |
| 1329 | egprs1->pi = 0; |
| 1330 | data[5] = 0xc0; |
| 1331 | data[5 + 69] = 1; |
| 1332 | rc = Decoding::rlc_parse_ul_data_header(&rlc, data, cs); |
Neels Hofmeyr | de9da39 | 2017-02-08 17:34:56 +0100 | [diff] [blame] | 1333 | OSMO_ASSERT(rc == 1138); |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1334 | OSMO_ASSERT(rlc.num_data_blocks == 2); |
| 1335 | OSMO_ASSERT(rlc.block_info[0].e == 1); |
| 1336 | OSMO_ASSERT(rlc.block_info[0].ti == 1); |
| 1337 | OSMO_ASSERT(rlc.block_info[1].e == 1); |
| 1338 | OSMO_ASSERT(rlc.block_info[1].ti == 0); |
| 1339 | OSMO_ASSERT(rlc.block_info[0].bsn == 0); |
| 1340 | OSMO_ASSERT(rlc.block_info[1].bsn == 1); |
| 1341 | OSMO_ASSERT(rlc.tfi == 1); |
| 1342 | |
| 1343 | /* MCS 9 */ |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 1344 | cs = MCS9; |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1345 | egprs1 = (struct gprs_rlc_ul_header_egprs_1 *) data; |
| 1346 | egprs1->si = 1; |
| 1347 | egprs1->r = 1; |
| 1348 | egprs1->cv = 7; |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 1349 | egprs1->tfi_hi = tfi & 0x03; |
| 1350 | egprs1->tfi_lo = (tfi & 0x1c) >> 2; |
| 1351 | egprs1->bsn1_hi = 0; |
| 1352 | egprs1->bsn1_lo = 0; |
| 1353 | egprs1->bsn2_hi = 1; |
| 1354 | egprs1->bsn2_lo = 0; |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1355 | egprs1->cps = 15; |
| 1356 | egprs1->rsb = 0; |
| 1357 | egprs1->pi = 0; |
| 1358 | data[5] = 0xc0; |
| 1359 | data[5 + 75] = 1; |
| 1360 | rc = Decoding::rlc_parse_ul_data_header(&rlc, data, cs); |
Neels Hofmeyr | de9da39 | 2017-02-08 17:34:56 +0100 | [diff] [blame] | 1361 | OSMO_ASSERT(rc == 1234); |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1362 | OSMO_ASSERT(rlc.num_data_blocks == 2); |
| 1363 | OSMO_ASSERT(rlc.block_info[0].e == 1); |
| 1364 | OSMO_ASSERT(rlc.block_info[0].ti == 1); |
| 1365 | OSMO_ASSERT(rlc.block_info[1].e == 1); |
| 1366 | OSMO_ASSERT(rlc.block_info[1].ti == 0); |
| 1367 | OSMO_ASSERT(rlc.block_info[0].bsn == 0); |
| 1368 | OSMO_ASSERT(rlc.block_info[1].bsn == 1); |
| 1369 | OSMO_ASSERT(rlc.tfi == 1); |
| 1370 | } |
| 1371 | |
| 1372 | void uplink_header_type1_test(void) |
| 1373 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1374 | struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0); |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1375 | int ts_no = 7; |
| 1376 | uint32_t fn = 2654218; |
| 1377 | uint16_t qta = 31; |
| 1378 | uint32_t tlli = 0xf1223344; |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1379 | uint8_t ms_class = 1; |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1380 | |
| 1381 | printf("=== start %s ===\n", __func__); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1382 | setup_bts(bts, ts_no, 12); |
| 1383 | uplink_header_type_1_parsing_test(bts, ts_no, tlli, &fn, |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1384 | qta, ms_class); |
| 1385 | printf("=== end %s ===\n", __func__); |
| 1386 | } |
| 1387 | |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 1388 | int main(int argc, char **argv) |
| 1389 | { |
| 1390 | struct vty_app_info pcu_vty_info = {0}; |
| 1391 | |
| 1392 | tall_pcu_ctx = talloc_named_const(NULL, 1, "EdgeTest context"); |
| 1393 | if (!tall_pcu_ctx) |
| 1394 | abort(); |
| 1395 | |
Neels Hofmeyr | 78ce591 | 2017-02-08 17:07:31 +0100 | [diff] [blame] | 1396 | msgb_talloc_ctx_init(tall_pcu_ctx, 0); |
Neels Hofmeyr | 42f2d61 | 2018-04-01 16:54:40 +0200 | [diff] [blame] | 1397 | osmo_init_logging2(tall_pcu_ctx, &gprs_log_info); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 1398 | log_set_use_color(osmo_stderr_target, 0); |
Pau Espin Pedrol | 00f52cc | 2021-02-19 14:01:52 +0100 | [diff] [blame] | 1399 | log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE); |
Pau Espin Pedrol | b18d2a5 | 2021-02-19 14:00:48 +0100 | [diff] [blame] | 1400 | log_set_print_category(osmo_stderr_target, 0); |
| 1401 | log_set_print_category_hex(osmo_stderr_target, 0); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 1402 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1403 | the_pcu = gprs_pcu_alloc(tall_pcu_ctx); |
| 1404 | |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 1405 | vty_init(&pcu_vty_info); |
Pau Espin Pedrol | cd2ac56 | 2019-08-05 14:30:44 +0200 | [diff] [blame] | 1406 | pcu_vty_init(); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 1407 | |
| 1408 | test_coding_scheme(); |
Jacob Erlbeck | 6e9f9c2 | 2016-01-11 11:15:45 +0100 | [diff] [blame] | 1409 | test_rlc_info_init(); |
Jacob Erlbeck | 38f1869 | 2016-02-01 10:08:00 +0100 | [diff] [blame] | 1410 | test_rlc_unit_decoder(); |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1411 | test_rlc_unaligned_copy(); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1412 | test_rlc_unit_encoder(); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 1413 | |
Aravind Sirsikar | 189742b | 2016-06-14 19:01:14 +0530 | [diff] [blame] | 1414 | uplink_header_type2_test(); |
Aravind Sirsikar | 2c9f980 | 2016-06-14 19:01:56 +0530 | [diff] [blame] | 1415 | uplink_header_type1_test(); |
| 1416 | |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 1417 | if (getenv("TALLOC_REPORT_FULL")) |
| 1418 | talloc_report_full(tall_pcu_ctx, stderr); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1419 | |
| 1420 | talloc_free(the_pcu); |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 1421 | return EXIT_SUCCESS; |
| 1422 | } |
| 1423 | |
| 1424 | /* |
| 1425 | * stubs that should not be reached |
| 1426 | */ |
| 1427 | extern "C" { |
| 1428 | void l1if_pdch_req() { abort(); } |
| 1429 | void l1if_connect_pdch() { abort(); } |
Philipp Maier | 72ed333 | 2023-02-27 15:32:00 +0100 | [diff] [blame^] | 1430 | void l1if_disconnect_pdch() { abort(); } |
Jacob Erlbeck | d0222cf | 2015-12-07 12:23:35 +0100 | [diff] [blame] | 1431 | void l1if_close_pdch() { abort(); } |
| 1432 | void l1if_open_pdch() { abort(); } |
| 1433 | } |