Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1 | #include <stdint.h> |
| 2 | #include <endian.h> |
| 3 | |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 4 | #include "RLCMAC_Types.hh" |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 5 | #include "RLCMAC_Templates.hh" |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 6 | #include "GSM_Types.hh" |
| 7 | /* Decoding of TS 44.060 GPRS RLC/MAC blocks, portions requiring manual functions |
| 8 | * beyond what TITAN RAW coder can handle internally. |
| 9 | * |
| 10 | * (C) 2017 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 11 | * All rights reserved. |
| 12 | * |
| 13 | * Released under the terms of GNU General Public License, Version 2 or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * SPDX-License-Identifier: GPL-2.0-or-later |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | namespace RLCMAC__Types { |
| 20 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 21 | ///////////////////// |
| 22 | // INTENRAL HELPERS |
| 23 | ///////////////////// |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 24 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 25 | /* TS 04.60 10.3a.4.1.1 */ |
| 26 | struct gprs_rlc_ul_header_egprs_1 { |
| 27 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 28 | uint8_t r:1, |
| 29 | si:1, |
| 30 | cv:4, |
| 31 | tfi_hi:2; |
| 32 | uint8_t tfi_lo:3, |
| 33 | bsn1_hi:5; |
| 34 | uint8_t bsn1_lo:6, |
| 35 | bsn2_hi:2; |
| 36 | uint8_t bsn2_lo:8; |
| 37 | uint8_t cps:5, |
| 38 | rsb:1, |
| 39 | pi:1, |
| 40 | spare_hi:1; |
| 41 | uint8_t spare_lo:6, |
| 42 | dummy:2; |
| 43 | #else |
| 44 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */ |
| 45 | uint8_t tfi_hi:2, cv:4, si:1, r:1; |
| 46 | uint8_t bsn1_hi:5, tfi_lo:3; |
| 47 | uint8_t bsn2_hi:2, bsn1_lo:6; |
| 48 | uint8_t bsn2_lo:8; |
| 49 | uint8_t spare_hi:1, pi:1, rsb:1, cps:5; |
| 50 | uint8_t dummy:2, spare_lo:6; |
| 51 | #endif |
| 52 | } __attribute__ ((packed)); |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 53 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 54 | /* TS 04.60 10.3a.4.2.1 */ |
| 55 | struct gprs_rlc_ul_header_egprs_2 { |
| 56 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 57 | uint8_t r:1, |
| 58 | si:1, |
| 59 | cv:4, |
| 60 | tfi_hi:2; |
| 61 | uint8_t tfi_lo:3, |
| 62 | bsn1_hi:5; |
| 63 | uint8_t bsn1_lo:6, |
| 64 | cps_hi:2; |
| 65 | uint8_t cps_lo:1, |
| 66 | rsb:1, |
| 67 | pi:1, |
| 68 | spare_hi:5; |
| 69 | uint8_t spare_lo:5, |
| 70 | dummy:3; |
| 71 | #else |
| 72 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */ |
| 73 | uint8_t tfi_hi:2, cv:4, si:1, r:1; |
| 74 | uint8_t bsn1_hi:5, tfi_lo:3; |
| 75 | uint8_t cps_hi:2, bsn1_lo:6; |
| 76 | uint8_t spare_hi:5, pi:1, rsb:1, cps_lo:1; |
| 77 | uint8_t dummy:3, spare_lo:5; |
| 78 | #endif |
| 79 | } __attribute__ ((packed)); |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 80 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 81 | /* TS 04.60 10.3a.4.3.1 */ |
| 82 | struct gprs_rlc_ul_header_egprs_3 { |
| 83 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 84 | uint8_t r:1, |
| 85 | si:1, |
| 86 | cv:4, |
| 87 | tfi_hi:2; |
| 88 | uint8_t tfi_lo:3, |
| 89 | bsn1_hi:5; |
| 90 | uint8_t bsn1_lo:6, |
| 91 | cps_hi:2; |
| 92 | uint8_t cps_lo:2, |
| 93 | spb:2, |
| 94 | rsb:1, |
| 95 | pi:1, |
| 96 | spare:1, |
| 97 | dummy:1; |
| 98 | #else |
| 99 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */ |
| 100 | uint8_t tfi_hi:2, cv:4, si:1, r:1; |
| 101 | uint8_t bsn1_hi:5, tfi_lo:3; |
| 102 | uint8_t cps_hi:2, bsn1_lo:6; |
| 103 | uint8_t dummy:1, spare:1, pi:1, rsb:1, spb:2, cps_lo:2; |
| 104 | #endif |
| 105 | } __attribute__ ((packed)); |
| 106 | |
| 107 | struct gprs_rlc_dl_header_egprs_1 { |
| 108 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 109 | uint8_t usf:3, |
| 110 | es_p:2, |
| 111 | rrbp:2, |
| 112 | tfi_hi:1; |
| 113 | uint8_t tfi_lo:4, |
| 114 | pr:2, |
| 115 | bsn1_hi:2; |
| 116 | uint8_t bsn1_mid:8; |
| 117 | uint8_t bsn1_lo:1, |
| 118 | bsn2_hi:7; |
| 119 | uint8_t bsn2_lo:3, |
| 120 | cps:5; |
| 121 | #else |
| 122 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */ |
| 123 | uint8_t tfi_hi:1, rrbp:2, es_p:2, usf:3; |
| 124 | uint8_t bsn1_hi:2, pr:2, tfi_lo:4; |
| 125 | uint8_t bsn1_mid:8; |
| 126 | uint8_t bsn2_hi:7, bsn1_lo:1; |
| 127 | uint8_t cps:5, bsn2_lo:3; |
| 128 | #endif |
| 129 | } __attribute__ ((packed)); |
| 130 | |
| 131 | struct gprs_rlc_dl_header_egprs_2 { |
| 132 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 133 | uint8_t usf:3, |
| 134 | es_p:2, |
| 135 | rrbp:2, |
| 136 | tfi_hi:1; |
| 137 | uint8_t tfi_lo:4, |
| 138 | pr:2, |
| 139 | bsn1_hi:2; |
| 140 | uint8_t bsn1_mid:8; |
| 141 | uint8_t bsn1_lo:1, |
| 142 | cps:3, |
| 143 | dummy:4; |
| 144 | #else |
| 145 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */ |
| 146 | uint8_t tfi_hi:1, rrbp:2, es_p:2, usf:3; |
| 147 | uint8_t bsn1_hi:2, pr:2, tfi_lo:4; |
| 148 | uint8_t bsn1_mid:8; |
| 149 | uint8_t dummy:4, cps:3, bsn1_lo:1; |
| 150 | #endif |
| 151 | } __attribute__ ((packed)); |
| 152 | |
| 153 | struct gprs_rlc_dl_header_egprs_3 { |
| 154 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 155 | uint8_t usf:3, |
| 156 | es_p:2, |
| 157 | rrbp:2, |
| 158 | tfi_hi:1; |
| 159 | uint8_t tfi_lo:4, |
| 160 | pr:2, |
| 161 | bsn1_hi:2; |
| 162 | uint8_t bsn1_mid:8; |
| 163 | uint8_t bsn1_lo:1, |
| 164 | cps:4, |
| 165 | spb:2, |
| 166 | dummy:1; |
| 167 | #else |
| 168 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */ |
| 169 | uint8_t tfi_hi:1, rrbp:2, es_p:2, usf:3; |
| 170 | uint8_t bsn1_hi:2, pr:2, tfi_lo:4; |
| 171 | uint8_t bsn1_mid:8; |
| 172 | uint8_t dummy:1, spb:2, cps:4, bsn1_lo:1; |
| 173 | #endif |
| 174 | } __attribute__ ((packed)); |
| 175 | |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 176 | /* |
| 177 | static const char hex_chars[] = "0123456789abcdef"; |
| 178 | void printbuffer(const char* ptr, TTCN_Buffer& buf) { |
| 179 | int len = buf.get_len(); |
| 180 | const unsigned char* cbuf = buf.get_data(); |
| 181 | |
| 182 | fprintf(stderr, "printbuffer %s (len=%d): [", ptr, len); |
| 183 | |
| 184 | for (int i = 0; i < len; i++) { |
| 185 | fprintf(stderr, " %c%c", hex_chars[cbuf[i] >> 4], hex_chars[cbuf[i] & 0xf]); |
| 186 | } |
| 187 | |
| 188 | fprintf(stderr, " ]\n"); |
| 189 | } |
| 190 | */ |
| 191 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 192 | static CodingScheme::enum_type payload_len_2_coding_scheme(size_t payload_len) { |
| 193 | switch (payload_len) { |
| 194 | case 23: |
| 195 | return CodingScheme::CS__1; |
| 196 | case 34: |
| 197 | return CodingScheme::CS__2; |
| 198 | case 40: |
| 199 | return CodingScheme::CS__3; |
| 200 | case 54: |
| 201 | return CodingScheme::CS__4; |
| 202 | case 27: |
| 203 | return CodingScheme::MCS__1; |
| 204 | case 33: |
| 205 | return CodingScheme::MCS__2; |
| 206 | case 42: |
| 207 | return CodingScheme::MCS__3; |
| 208 | case 49: |
| 209 | return CodingScheme::MCS__4; |
| 210 | case 61: |
| 211 | return CodingScheme::MCS__5; |
| 212 | case 79: |
| 213 | return CodingScheme::MCS__6; |
| 214 | case 119: |
| 215 | return CodingScheme::MCS__7; |
| 216 | case 142: |
| 217 | return CodingScheme::MCS__8; |
| 218 | case 155: |
| 219 | return CodingScheme::MCS__9; |
| 220 | default: |
| 221 | return CodingScheme::CS__1; |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 222 | } |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 223 | } |
| 224 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 225 | static unsigned int coding_scheme_2_data_block_len(CodingScheme::enum_type mcs) { |
| 226 | switch (mcs) { |
| 227 | case CodingScheme::MCS__0: |
| 228 | return 0; |
| 229 | case CodingScheme::MCS__1: |
| 230 | return 22; |
| 231 | case CodingScheme::MCS__2: |
| 232 | return 28; |
| 233 | case CodingScheme::MCS__3: |
| 234 | return 37; |
| 235 | case CodingScheme::MCS__4: |
| 236 | return 44; |
| 237 | case CodingScheme::MCS__5: |
| 238 | return 56; |
| 239 | case CodingScheme::MCS__6: |
| 240 | return 74; |
| 241 | case CodingScheme::MCS__7: |
| 242 | return 56; |
| 243 | case CodingScheme::MCS__8: |
| 244 | return 68; |
| 245 | case CodingScheme::MCS__9: |
| 246 | return 74; |
| 247 | default: |
| 248 | return 22; /* MCS1*/ |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | static uint8_t bs2uint8(const BITSTRING& bs) |
| 253 | { |
| 254 | int len = bs.lengthof(); |
| 255 | int i; |
| 256 | uint8_t res = 0; |
| 257 | for (i = 0; i < len; i++) { |
| 258 | res = res << 1; |
| 259 | res |= (bs[i].get_bit() ? 1 : 0); |
| 260 | } |
| 261 | return res; |
| 262 | } |
| 263 | |
| 264 | /* determine the number of rlc data blocks and their size / offsets */ |
| 265 | static void |
| 266 | setup_rlc_mac_priv(CodingScheme::enum_type mcs, EgprsHeaderType::enum_type hdrtype, boolean is_uplink, |
| 267 | unsigned int *n_calls, unsigned int *data_block_bits, unsigned int *data_block_offsets) |
| 268 | { |
| 269 | unsigned int nc, dbl = 0, dbo[2] = {0,0}; |
| 270 | |
| 271 | dbl = coding_scheme_2_data_block_len(mcs); |
| 272 | |
| 273 | switch (hdrtype) { |
| 274 | case EgprsHeaderType::RLCMAC__HDR__TYPE__1: |
| 275 | nc = 3; |
| 276 | dbo[0] = is_uplink ? 5*8 + 6 : 5*8 + 0; |
| 277 | dbo[1] = dbo[0] + dbl * 8 + 2; |
| 278 | break; |
| 279 | case EgprsHeaderType::RLCMAC__HDR__TYPE__2: |
| 280 | nc = 2; |
| 281 | dbo[0] = is_uplink ? 4*8 + 5 : 3*8 + 4; |
| 282 | break; |
| 283 | case EgprsHeaderType::RLCMAC__HDR__TYPE__3: |
| 284 | nc = 2; |
| 285 | dbo[0] = 3*8 + 7; |
| 286 | break; |
| 287 | default: |
| 288 | nc = 1; |
| 289 | break; |
| 290 | } |
| 291 | |
| 292 | *n_calls = nc; |
| 293 | *data_block_bits = dbl * 8 + 2; |
| 294 | data_block_offsets[0] = dbo[0]; |
| 295 | data_block_offsets[1] = dbo[1]; |
| 296 | } |
| 297 | |
| 298 | /* bit-shift the entire 'src' of length 'length_bytes' by 'offset_bits' |
Pau Espin Pedrol | ecaeb89 | 2020-04-30 19:58:15 +0200 | [diff] [blame] | 299 | * and store the result to caller-allocated 'buffer'. The shifting is |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 300 | * done lsb-first. */ |
| 301 | static void clone_aligned_buffer_lsbf(unsigned int offset_bits, unsigned int length_bytes, |
| 302 | const uint8_t *src, uint8_t *buffer) |
| 303 | { |
| 304 | unsigned int hdr_bytes; |
| 305 | unsigned int extra_bits; |
| 306 | unsigned int i; |
| 307 | |
| 308 | uint8_t c, last_c; |
| 309 | uint8_t *dst; |
| 310 | |
| 311 | hdr_bytes = offset_bits / 8; |
| 312 | extra_bits = offset_bits % 8; |
| 313 | |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 314 | //fprintf(stderr, "RLMAC: clone: hdr_bytes=%u extra_bits=%u (length_bytes=%u)\n", hdr_bytes, extra_bits, length_bytes); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 315 | |
| 316 | if (extra_bits == 0) { |
| 317 | /* It is aligned already */ |
| 318 | memcpy(buffer, src + hdr_bytes, length_bytes); |
| 319 | return; |
| 320 | } |
| 321 | |
| 322 | dst = buffer; |
| 323 | src = src + hdr_bytes; |
| 324 | last_c = *(src++); |
| 325 | |
| 326 | for (i = 0; i < length_bytes; i++) { |
| 327 | c = src[i]; |
| 328 | *(dst++) = (last_c >> extra_bits) | (c << (8 - extra_bits)); |
| 329 | last_c = c; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | /* obtain an (aligned) EGPRS data block with given bit-offset and |
| 334 | * bit-length from the parent buffer */ |
| 335 | static void get_egprs_data_block(const TTCN_Buffer& orig_ttcn_buffer, unsigned int offset_bits, |
| 336 | unsigned int length_bits, TTCN_Buffer& dst_ttcn_buffer) |
| 337 | { |
| 338 | const unsigned int initial_spare_bits = 6; |
| 339 | unsigned char *aligned_buf = NULL; |
| 340 | size_t min_src_length_bytes = (offset_bits + length_bits + 7) / 8; |
| 341 | size_t length_bytes = (initial_spare_bits + length_bits + 7) / 8; |
| 342 | size_t accepted_len = length_bytes; |
| 343 | |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 344 | //fprintf(stderr, "RLMAC: trying to allocate %u bytes (orig is %zu bytes long with read pos %zu)\n", length_bytes, orig_ttcn_buffer.get_len(), orig_ttcn_buffer.get_pos()); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 345 | dst_ttcn_buffer.get_end(aligned_buf, accepted_len); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 346 | if (accepted_len < length_bytes) { |
| 347 | fprintf(stderr, "RLMAC: ERROR! asked for %zu bytes but got %zu\n", length_bytes, accepted_len); |
| 348 | } |
| 349 | |
| 350 | /* Copy the data out of the tvb to an aligned buffer */ |
| 351 | clone_aligned_buffer_lsbf( |
| 352 | offset_bits - initial_spare_bits, length_bytes, |
| 353 | orig_ttcn_buffer.get_data(), |
| 354 | aligned_buf); |
| 355 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 356 | /* clear spare bits and move block header bits to the right */ |
| 357 | aligned_buf[0] = aligned_buf[0] >> initial_spare_bits; |
| 358 | |
| 359 | dst_ttcn_buffer.increase_length(length_bytes); |
| 360 | } |
| 361 | |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 362 | /* bit-shift the entire 'src' of length 'length_bytes' |
| 363 | * and store the result to caller-allocated 'buffer' by 'offset_bits'. The shifting is |
| 364 | * done lsb-first. */ |
| 365 | static void clone_unaligned_buffer_lsbf(unsigned int offset_bits, unsigned int length_bytes, |
| 366 | const uint8_t *src, uint8_t *buffer) |
| 367 | { |
| 368 | unsigned int hdr_bytes; |
| 369 | unsigned int extra_bits; |
| 370 | unsigned int i; |
| 371 | |
| 372 | uint8_t c, last_hdr_c, last_c; |
| 373 | uint8_t *dst; |
| 374 | |
| 375 | hdr_bytes = offset_bits / 8; |
| 376 | extra_bits = offset_bits % 8; |
| 377 | |
| 378 | //fprintf(stderr, "RLMAC: clone: hdr_bytes=%u extra_bits=%u (length_bytes=%u)\n", hdr_bytes, extra_bits, length_bytes); |
| 379 | |
| 380 | if (extra_bits == 0) { |
| 381 | /* It is aligned already */ |
| 382 | memcpy(buffer, src + hdr_bytes, length_bytes); |
| 383 | return; |
| 384 | } |
| 385 | |
| 386 | /* Copy first header+data byte, it's not handled correctly by loop */ |
| 387 | dst = buffer + hdr_bytes; |
| 388 | last_hdr_c = *dst; |
| 389 | last_c = *dst << (8 - extra_bits); |
| 390 | |
| 391 | for (i = 0; i < length_bytes; i++) { |
| 392 | c = src[i]; |
| 393 | *(dst++) = (last_c >> (8 - extra_bits)) | (c << extra_bits); |
| 394 | last_c = c; |
| 395 | } |
| 396 | /* overwrite the lower extra_bits */ |
| 397 | *dst = (*dst & (0xff << extra_bits)) | (last_c >> (8 - extra_bits)); |
| 398 | |
| 399 | /* Copy back first header+data byte */ |
| 400 | dst = buffer + hdr_bytes; |
| 401 | *(dst++) = last_hdr_c | (src[0] << (8 - extra_bits)); |
| 402 | *dst |= (src[0] >> (extra_bits)) & (0xff >> (8 - extra_bits)); |
| 403 | } |
| 404 | |
| 405 | /* put an (aligned) EGPRS data block with given bit-offset and |
| 406 | * bit-length into parent buffer */ |
| 407 | static void put_egprs_data_block(const TTCN_Buffer& aligned_data_block_buffer, unsigned int offset_bits, |
| 408 | unsigned int length_bits, TTCN_Buffer& dst_ttcn_buffer) |
| 409 | { |
| 410 | const unsigned int initial_spare_bits = 6; |
| 411 | unsigned char *unaligned_buf = NULL; |
| 412 | char tmpbuf[120]; |
| 413 | int tmplen = dst_ttcn_buffer.get_len(); |
| 414 | //size_t max_length_bytes = (initial_spare_bits + length_bits + 7) / 8; |
| 415 | size_t length_bytes = tmplen + aligned_data_block_buffer.get_len(); |
| 416 | size_t accepted_len = length_bytes; |
| 417 | |
| 418 | //fprintf(stderr, "RLMAC: trying to allocate %u bytes\n", length_bytes); |
| 419 | |
| 420 | /* API .get_end() is the only one I could find to access writeable |
| 421 | memory in the buffer. It points to the end. Hence, we first copy |
| 422 | (readonly) data to tmpbuf and later clear() so that .get_end() |
| 423 | provides us with a pointer to the start of the buffer. */ |
| 424 | memcpy(tmpbuf, dst_ttcn_buffer.get_data(), tmplen); |
| 425 | dst_ttcn_buffer.clear(); |
| 426 | dst_ttcn_buffer.get_end(unaligned_buf, accepted_len); |
| 427 | if (accepted_len < tmplen) { |
| 428 | fprintf(stderr, "RLMAC: ERROR! asked for %zu bytes but got %zu\n", length_bytes, accepted_len); |
| 429 | } |
| 430 | memcpy(unaligned_buf, tmpbuf, tmplen); |
| 431 | |
| 432 | /* Copy the data out of the tvb to an aligned buffer */ |
| 433 | clone_unaligned_buffer_lsbf( |
| 434 | offset_bits - initial_spare_bits, length_bytes, |
| 435 | aligned_data_block_buffer.get_data(), |
| 436 | unaligned_buf); |
| 437 | |
| 438 | dst_ttcn_buffer.increase_length(length_bytes); |
| 439 | } |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 440 | |
| 441 | ///////////////////// |
| 442 | // DECODE |
| 443 | ///////////////////// |
| 444 | |
| 445 | /* DECODE DOWNLINK */ |
| 446 | |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 447 | RlcmacDlDataBlock dec__RlcmacDlDataBlock(const OCTETSTRING& stream) |
| 448 | { |
| 449 | RlcmacDlDataBlock ret_val; |
| 450 | TTCN_Buffer ttcn_buffer(stream); |
| 451 | int num_llc_blocks = 0; |
| 452 | |
| 453 | /* use automatic/generated decoder for header */ |
| 454 | ret_val.mac__hdr().decode(DlMacDataHeader_descr_, ttcn_buffer, TTCN_EncDec::CT_RAW); |
| 455 | |
| 456 | /* optional extension octets, containing LI+M+E of Llc blocks */ |
| 457 | if (ret_val.mac__hdr().hdr__ext().e() == false) { |
| 458 | /* extension octet follows, i.e. optional Llc length octets */ |
| 459 | while (1) { |
| 460 | /* decode one more extension octet with LlcBlocHdr inside */ |
| 461 | LlcBlock lb; |
Harald Welte | 439e546 | 2018-03-08 23:21:17 +0100 | [diff] [blame] | 462 | lb.hdr()().decode(LlcBlockHdr_descr_, ttcn_buffer, TTCN_EncDec::CT_RAW); |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 463 | ret_val.blocks()[num_llc_blocks++] = lb; |
| 464 | |
| 465 | /* if E == '1'B, we can proceed further */ |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 466 | if (lb.hdr()().e() == true) |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 467 | break; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | /* RLC blocks at end */ |
| 472 | if (ret_val.mac__hdr().hdr__ext().e() == true) { |
| 473 | LlcBlock lb; |
| 474 | unsigned int length = ttcn_buffer.get_read_len(); |
| 475 | /* LI not present: The Upper Layer PDU that starts with the current RLC data block either |
| 476 | * fills the current RLC data block precisely or continues in the following in-sequence RLC |
| 477 | * data block */ |
| 478 | lb.payload() = OCTETSTRING(length, ttcn_buffer.get_read_data()); |
| 479 | ttcn_buffer.increase_pos(length); |
| 480 | ret_val.blocks()[0] = lb; |
| 481 | } else { |
| 482 | if (ret_val.blocks().is_bound()) { |
| 483 | for (int i = 0; i < ret_val.blocks().size_of(); i++) { |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 484 | unsigned int length = ret_val.blocks()[i].hdr()().length__ind(); |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 485 | if (length > ttcn_buffer.get_read_len()) |
| 486 | length = ttcn_buffer.get_read_len(); |
| 487 | ret_val.blocks()[i].payload() = OCTETSTRING(length, ttcn_buffer.get_read_data()); |
| 488 | ttcn_buffer.increase_pos(length); |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | return ret_val; |
| 494 | } |
| 495 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 496 | static |
| 497 | EgprsDlMacDataHeader dec__EgprsDlMacDataHeader_type1(const OCTETSTRING& stream) |
| 498 | { |
| 499 | EgprsDlMacDataHeader ret_val; |
| 500 | |
| 501 | fprintf(stderr, "FIXME: Not implemented! %s (%s:%u)\n", __func__, __FILE__, __LINE__); |
| 502 | |
| 503 | return ret_val; |
| 504 | } |
| 505 | |
| 506 | static |
| 507 | EgprsDlMacDataHeader dec__EgprsDlMacDataHeader_type2(const OCTETSTRING& stream) |
| 508 | { |
| 509 | EgprsDlMacDataHeader ret_val; |
| 510 | |
| 511 | fprintf(stderr, "FIXME: Not implemented! %s (%s:%u)\n", __func__, __FILE__, __LINE__); |
| 512 | |
| 513 | return ret_val; |
| 514 | } |
| 515 | |
| 516 | static |
| 517 | EgprsDlMacDataHeader dec__EgprsDlMacDataHeader_type3(const OCTETSTRING& stream) |
| 518 | { |
| 519 | TTCN_Buffer ttcn_buffer(stream); |
| 520 | EgprsDlMacDataHeader ret_val; |
| 521 | const struct gprs_rlc_dl_header_egprs_3 *egprs3; |
| 522 | uint8_t tmp; |
| 523 | |
| 524 | egprs3 = static_cast<const struct gprs_rlc_dl_header_egprs_3 *> |
| 525 | ((const void *)ttcn_buffer.get_data()); |
| 526 | |
| 527 | ret_val.header__type() = EgprsHeaderType::RLCMAC__HDR__TYPE__3; |
| 528 | ret_val.tfi() = egprs3->tfi_lo << 1 | egprs3->tfi_hi << 0; |
| 529 | ret_val.rrbp() = egprs3->rrbp; |
| 530 | tmp = egprs3->es_p; |
| 531 | ret_val.esp() = BITSTRING(2, &tmp); |
| 532 | ret_val.usf() = egprs3->usf; |
| 533 | ret_val.bsn1() = egprs3->bsn1_lo << 10 | egprs3->bsn1_mid << 2 | egprs3->bsn1_hi; |
| 534 | ret_val.bsn2__offset() = 0; /*TODO: mark optional and not set ? */ |
| 535 | ret_val.pr() = egprs3->pr; |
| 536 | ret_val.spb() = egprs3->spb; |
| 537 | ret_val.cps() = egprs3->cps; |
| 538 | |
| 539 | ttcn_buffer.increase_pos(sizeof(*egprs3)); |
| 540 | return ret_val; |
| 541 | } |
| 542 | |
| 543 | static |
| 544 | RlcmacDlEgprsDataBlock dec__RlcmacDlEgprsDataBlock(const OCTETSTRING& stream, CodingScheme::enum_type mcs) |
| 545 | { |
| 546 | RlcmacDlEgprsDataBlock ret_val; |
| 547 | TTCN_Buffer ttcn_buffer(stream); |
| 548 | TTCN_Buffer aligned_buffer; |
| 549 | int num_llc_blocks = 0; |
| 550 | unsigned int data_block_bits, data_block_offsets[2]; |
| 551 | unsigned int num_calls; |
| 552 | const uint8_t *ti_e; |
| 553 | |
| 554 | switch (mcs) { |
| 555 | case CodingScheme::MCS__0: |
| 556 | case CodingScheme::MCS__1: |
| 557 | case CodingScheme::MCS__2: |
| 558 | case CodingScheme::MCS__3: |
| 559 | case CodingScheme::MCS__4: |
| 560 | ret_val.mac__hdr() = dec__EgprsDlMacDataHeader_type3(stream); |
| 561 | break; |
| 562 | case CodingScheme::MCS__5: |
| 563 | case CodingScheme::MCS__6: |
| 564 | ret_val.mac__hdr() = dec__EgprsDlMacDataHeader_type2(stream); |
| 565 | break; |
| 566 | case CodingScheme::MCS__7: |
| 567 | case CodingScheme::MCS__8: |
| 568 | case CodingScheme::MCS__9: |
| 569 | ret_val.mac__hdr() = dec__EgprsDlMacDataHeader_type1(stream); |
| 570 | break; |
| 571 | } |
| 572 | setup_rlc_mac_priv(mcs, ret_val.mac__hdr().header__type(), false, |
| 573 | &num_calls, &data_block_bits, data_block_offsets); |
| 574 | get_egprs_data_block(ttcn_buffer, data_block_offsets[0], data_block_bits, aligned_buffer); |
| 575 | |
| 576 | ti_e = aligned_buffer.get_read_data(); |
| 577 | ret_val.fbi() = *ti_e & 0x02 ? true : false; |
| 578 | ret_val.e() = *ti_e & 0x01 ? true : false; |
| 579 | aligned_buffer.increase_pos(1); |
| 580 | |
| 581 | /* optional extension octets, containing LI+E of Llc blocks */ |
| 582 | if (ret_val.e() == false) { |
| 583 | /* extension octet follows, i.e. optional Llc length octets */ |
| 584 | while (1) { |
| 585 | /* decode one more extension octet with LlcBlocHdr inside */ |
| 586 | EgprsLlcBlock lb; |
| 587 | lb.hdr()().decode(EgprsLlcBlockHdr_descr_, aligned_buffer, TTCN_EncDec::CT_RAW); |
| 588 | ret_val.blocks()[num_llc_blocks++] = lb; |
| 589 | |
| 590 | /* if E == '1'B, we can proceed further */ |
| 591 | if (lb.hdr()().e() == true) |
| 592 | break; |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | /* RLC blocks at end */ |
| 597 | if (ret_val.blocks().is_bound()) { |
| 598 | for (int i = 0; i < ret_val.blocks().size_of(); i++) { |
| 599 | unsigned int length = ret_val.blocks()[i].hdr()().length__ind(); |
| 600 | if (length > aligned_buffer.get_read_len()) |
| 601 | length = aligned_buffer.get_read_len(); |
| 602 | ret_val.blocks()[i].payload() = OCTETSTRING(length, aligned_buffer.get_read_data()); |
| 603 | aligned_buffer.increase_pos(length); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | return ret_val; |
| 608 | } |
| 609 | |
| 610 | RlcmacDlBlock dec__RlcmacDlBlock(const OCTETSTRING& stream) |
| 611 | { |
| 612 | RlcmacDlBlock ret_val; |
| 613 | size_t stream_len = stream.lengthof(); |
| 614 | CodingScheme::enum_type mcs = payload_len_2_coding_scheme(stream_len); |
| 615 | unsigned char pt; |
| 616 | |
| 617 | switch (mcs) { |
| 618 | case CodingScheme::CS__1: |
| 619 | case CodingScheme::CS__2: |
| 620 | case CodingScheme::CS__3: |
| 621 | case CodingScheme::CS__4: |
| 622 | pt = stream[0].get_octet() >> 6; |
| 623 | if (pt == MacPayloadType::MAC__PT__RLC__DATA) |
| 624 | ret_val.data() = dec__RlcmacDlDataBlock(stream); |
| 625 | else |
| 626 | ret_val.ctrl() = dec__RlcmacDlCtrlBlock(stream); |
| 627 | break; |
| 628 | case CodingScheme::MCS__0: |
| 629 | case CodingScheme::MCS__1: |
| 630 | case CodingScheme::MCS__2: |
| 631 | case CodingScheme::MCS__3: |
| 632 | case CodingScheme::MCS__4: |
| 633 | case CodingScheme::MCS__5: |
| 634 | case CodingScheme::MCS__6: |
| 635 | case CodingScheme::MCS__7: |
| 636 | case CodingScheme::MCS__8: |
| 637 | case CodingScheme::MCS__9: |
| 638 | ret_val.data__egprs() = dec__RlcmacDlEgprsDataBlock(stream, mcs); |
| 639 | break; |
| 640 | } |
| 641 | return ret_val; |
| 642 | } |
| 643 | |
| 644 | /* DECODE UPLINK */ |
| 645 | |
| 646 | RlcmacUlDataBlock dec__RlcmacUlDataBlock(const OCTETSTRING& stream) |
| 647 | { |
| 648 | RlcmacUlDataBlock ret_val; |
| 649 | TTCN_Buffer ttcn_buffer(stream); |
| 650 | int num_llc_blocks = 0; |
| 651 | |
| 652 | TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC); |
| 653 | TTCN_Logger::log_event_str("==================================\n" |
| 654 | "dec_RlcmacUlDataBlock(): Stream before decoding: "); |
| 655 | stream.log(); |
| 656 | TTCN_Logger::end_event(); |
| 657 | |
| 658 | /* use automatic/generated decoder for header */ |
| 659 | ret_val.mac__hdr().decode(UlMacDataHeader_descr_, ttcn_buffer, TTCN_EncDec::CT_RAW); |
| 660 | |
| 661 | TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC); |
| 662 | TTCN_Logger::log_event_str("dec_RlcmacUlDataBlock(): Stream after decoding hdr: "); |
| 663 | ttcn_buffer.log(); |
| 664 | TTCN_Logger::end_event(); |
| 665 | TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC); |
| 666 | TTCN_Logger::log_event_str("dec_RlcmacUlDataBlock(): ret_val after decoding hdr: "); |
| 667 | ret_val.log(); |
| 668 | TTCN_Logger::end_event(); |
| 669 | |
| 670 | /* Manually decoder remainder of ttcn_buffer, containing optional header octets, |
| 671 | * optional tlli, optional pfi and LLC Blocks */ |
| 672 | |
| 673 | /* optional extension octets, containing LI+M+E of Llc blocks */ |
| 674 | if (ret_val.mac__hdr().e() == false) { |
| 675 | /* extension octet follows, i.e. optional Llc length octets */ |
| 676 | while (1) { |
| 677 | /* decode one more extension octet with LlcBlocHdr inside */ |
| 678 | LlcBlock lb; |
| 679 | lb.hdr()().decode(LlcBlockHdr_descr_, ttcn_buffer, TTCN_EncDec::CT_RAW); |
| 680 | ret_val.blocks()[num_llc_blocks++] = lb; |
| 681 | |
| 682 | TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC); |
| 683 | TTCN_Logger::log_event_str("dec_RlcmacUlDataBlock(): Stream after decoding ExtOct: "); |
| 684 | ttcn_buffer.log(); |
| 685 | TTCN_Logger::end_event(); |
| 686 | TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC); |
| 687 | TTCN_Logger::log_event_str("dec_RlcmacUlDataBlock(): ret_val after decoding ExtOct: "); |
| 688 | ret_val.log(); |
| 689 | TTCN_Logger::end_event(); |
| 690 | |
| 691 | /* if E == '1'B, we can proceed further */ |
| 692 | if (lb.hdr()().e() == true) |
| 693 | break; |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | /* parse optional TLLI */ |
| 698 | if (ret_val.mac__hdr().tlli__ind()) { |
| 699 | ret_val.tlli() = OCTETSTRING(4, ttcn_buffer.get_read_data()); |
| 700 | ttcn_buffer.increase_pos(4); |
Pau Espin Pedrol | a2c5b6e | 2020-04-30 19:59:13 +0200 | [diff] [blame] | 701 | } else { |
| 702 | ret_val.tlli() = OMIT_VALUE; |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 703 | } |
| 704 | /* parse optional PFI */ |
| 705 | if (ret_val.mac__hdr().pfi__ind()) { |
| 706 | ret_val.pfi().decode(RlcmacUlDataBlock_pfi_descr_, ttcn_buffer, TTCN_EncDec::CT_RAW); |
Pau Espin Pedrol | a2c5b6e | 2020-04-30 19:59:13 +0200 | [diff] [blame] | 707 | } else { |
| 708 | ret_val.pfi() = OMIT_VALUE; |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | /* RLC blocks at end */ |
| 712 | if (ret_val.mac__hdr().e() == true) { |
| 713 | LlcBlock lb; |
| 714 | unsigned int length = ttcn_buffer.get_read_len(); |
| 715 | /* LI not present: The Upper Layer PDU that starts with the current RLC data block either |
| 716 | * fills the current RLC data block precisely or continues in the following in-sequence RLC |
| 717 | * data block */ |
| 718 | lb.payload() = OCTETSTRING(length, ttcn_buffer.get_read_data()); |
| 719 | ttcn_buffer.increase_pos(length); |
| 720 | ret_val.blocks()[0] = lb; |
| 721 | } else { |
| 722 | if (ret_val.blocks().is_bound()) { |
| 723 | for (int i = 0; i < ret_val.blocks().size_of(); i++) { |
| 724 | unsigned int length = ret_val.blocks()[i].hdr()().length__ind(); |
| 725 | if (length > ttcn_buffer.get_read_len()) |
| 726 | length = ttcn_buffer.get_read_len(); |
| 727 | ret_val.blocks()[i].payload() = OCTETSTRING(length, ttcn_buffer.get_read_data()); |
| 728 | ttcn_buffer.increase_pos(length); |
| 729 | } |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC); |
| 734 | TTCN_Logger::log_event_str("dec_RlcmacUlDataBlock(): Stream before return: "); |
| 735 | ttcn_buffer.log(); |
| 736 | TTCN_Logger::end_event(); |
| 737 | TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC); |
| 738 | TTCN_Logger::log_event_str("dec_RlcmacUlDataBlock(): ret_val before return: "); |
| 739 | ret_val.log(); |
| 740 | TTCN_Logger::end_event(); |
| 741 | |
| 742 | return ret_val; |
| 743 | } |
| 744 | |
| 745 | static |
| 746 | EgprsUlMacDataHeader dec__EgprsUlMacDataHeader_type1(const OCTETSTRING& stream) |
| 747 | { |
| 748 | EgprsUlMacDataHeader ret_val; |
| 749 | |
| 750 | fprintf(stderr, "FIXME: Not implemented! %s (%s:%u)\n", __func__, __FILE__, __LINE__); |
| 751 | |
| 752 | return ret_val; |
| 753 | } |
| 754 | |
| 755 | static |
| 756 | EgprsUlMacDataHeader dec__EgprsUlMacDataHeader_type2(const OCTETSTRING& stream) |
| 757 | { |
| 758 | EgprsUlMacDataHeader ret_val; |
| 759 | |
| 760 | fprintf(stderr, "FIXME: Not implemented! %s (%s:%u)\n", __func__, __FILE__, __LINE__); |
| 761 | |
| 762 | return ret_val; |
| 763 | } |
| 764 | |
| 765 | static |
| 766 | EgprsUlMacDataHeader dec__EgprsUlMacDataHeader_type3(const OCTETSTRING& stream) |
| 767 | { |
Pau Espin Pedrol | 0b8e22b | 2020-04-30 20:10:17 +0200 | [diff] [blame] | 768 | TTCN_Buffer ttcn_buffer(stream); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 769 | EgprsUlMacDataHeader ret_val; |
Pau Espin Pedrol | 0b8e22b | 2020-04-30 20:10:17 +0200 | [diff] [blame] | 770 | const struct gprs_rlc_ul_header_egprs_3 *egprs3; |
| 771 | uint8_t tmp; |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 772 | |
Pau Espin Pedrol | 0b8e22b | 2020-04-30 20:10:17 +0200 | [diff] [blame] | 773 | egprs3 = static_cast<const struct gprs_rlc_ul_header_egprs_3 *> |
| 774 | ((const void *)ttcn_buffer.get_data()); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 775 | |
Pau Espin Pedrol | 0b8e22b | 2020-04-30 20:10:17 +0200 | [diff] [blame] | 776 | ret_val.header__type() = EgprsHeaderType::RLCMAC__HDR__TYPE__3; |
| 777 | ret_val.tfi() = egprs3->tfi_lo << 2 | egprs3->tfi_hi << 0; |
| 778 | ret_val.countdown() = egprs3->cv; |
| 779 | tmp = egprs3->si; |
| 780 | ret_val.foi__si() = BITSTRING(1, &tmp); |
| 781 | tmp = egprs3->r; |
| 782 | ret_val.r__ri() = BITSTRING(1, &tmp); |
| 783 | ret_val.bsn1() = egprs3->bsn1_lo << 5 | egprs3->bsn1_hi << 0; |
| 784 | ret_val.cps() = egprs3->cps_lo << 2 | egprs3->cps_hi << 0; |
| 785 | ret_val.pfi__ind() = egprs3->pi; |
| 786 | tmp = egprs3->rsb; |
| 787 | ret_val.rsb() = BITSTRING(1, &tmp); |
| 788 | tmp = egprs3->spb; |
| 789 | ret_val.spb() = BITSTRING(2, &tmp); |
| 790 | |
| 791 | ttcn_buffer.increase_pos(sizeof(*egprs3)); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 792 | return ret_val; |
| 793 | } |
| 794 | |
| 795 | RlcmacUlEgprsDataBlock dec__RlcmacUlEgprsDataBlock(const OCTETSTRING& stream, CodingScheme::enum_type mcs) |
| 796 | { |
| 797 | RlcmacUlEgprsDataBlock ret_val; |
| 798 | TTCN_Buffer ttcn_buffer(stream); |
| 799 | TTCN_Buffer aligned_buffer; |
| 800 | int num_llc_blocks = 0; |
| 801 | unsigned int data_block_bits, data_block_offsets[2]; |
| 802 | unsigned int num_calls; |
| 803 | const uint8_t *ti_e; |
| 804 | |
| 805 | switch (mcs) { |
| 806 | case CodingScheme::MCS__1: |
| 807 | case CodingScheme::MCS__2: |
| 808 | case CodingScheme::MCS__3: |
| 809 | case CodingScheme::MCS__4: |
| 810 | ret_val.mac__hdr() = dec__EgprsUlMacDataHeader_type3(stream); |
| 811 | break; |
| 812 | case CodingScheme::MCS__5: |
| 813 | case CodingScheme::MCS__6: |
| 814 | ret_val.mac__hdr() = dec__EgprsUlMacDataHeader_type2(stream); |
| 815 | break; |
| 816 | case CodingScheme::MCS__7: |
| 817 | case CodingScheme::MCS__8: |
| 818 | case CodingScheme::MCS__9: |
| 819 | ret_val.mac__hdr() = dec__EgprsUlMacDataHeader_type1(stream); |
| 820 | break; |
| 821 | } |
| 822 | setup_rlc_mac_priv(mcs, ret_val.mac__hdr().header__type(), true, |
| 823 | &num_calls, &data_block_bits, data_block_offsets); |
| 824 | get_egprs_data_block(ttcn_buffer, data_block_offsets[0], data_block_bits, aligned_buffer); |
| 825 | |
| 826 | ti_e = aligned_buffer.get_read_data(); |
| 827 | ret_val.tlli__ind() = *ti_e & 0x02 ? true : false; |
| 828 | ret_val.e() = *ti_e & 0x01 ? true : false; |
| 829 | aligned_buffer.increase_pos(1); |
| 830 | |
| 831 | /* Manually decoder remainder of aligned_buffer, containing optional header octets, |
| 832 | * optional tlli, optional pfi and LLC Blocks */ |
| 833 | |
| 834 | /* optional extension octets, containing LI+M+E of Llc blocks */ |
| 835 | if (ret_val.e() == false) { |
| 836 | /* extension octet follows, i.e. optional Llc length octets */ |
| 837 | while (1) { |
| 838 | /* decode one more extension octet with LlcBlocHdr inside */ |
| 839 | EgprsLlcBlock lb; |
| 840 | lb.hdr()().decode(EgprsLlcBlockHdr_descr_, aligned_buffer, TTCN_EncDec::CT_RAW); |
| 841 | ret_val.blocks()[num_llc_blocks++] = lb; |
| 842 | |
| 843 | /* if E == '1'B, we can proceed further */ |
| 844 | if (lb.hdr()().e() == true) |
| 845 | break; |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | /* parse optional TLLI */ |
| 850 | if (ret_val.tlli__ind()) { |
| 851 | ret_val.tlli() = OCTETSTRING(4, aligned_buffer.get_read_data()); |
| 852 | aligned_buffer.increase_pos(4); |
Pau Espin Pedrol | a2c5b6e | 2020-04-30 19:59:13 +0200 | [diff] [blame] | 853 | } else { |
| 854 | ret_val.tlli() = OMIT_VALUE; |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 855 | } |
| 856 | /* parse optional PFI */ |
| 857 | if (ret_val.mac__hdr().pfi__ind()) { |
Pau Espin Pedrol | 331f525 | 2020-04-30 20:05:29 +0200 | [diff] [blame] | 858 | ret_val.pfi().decode(RlcmacUlEgprsDataBlock_pfi_descr_, aligned_buffer, TTCN_EncDec::CT_RAW); |
Pau Espin Pedrol | a2c5b6e | 2020-04-30 19:59:13 +0200 | [diff] [blame] | 859 | } else { |
| 860 | ret_val.pfi() = OMIT_VALUE; |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | /* RLC blocks at end */ |
| 864 | if (ret_val.e() == true) { |
| 865 | EgprsLlcBlock lb; |
| 866 | unsigned int length = aligned_buffer.get_read_len(); |
| 867 | /* LI not present: The Upper Layer PDU that starts with the current RLC data block either |
| 868 | * fills the current RLC data block precisely or continues in the following in-sequence RLC |
| 869 | * data block */ |
| 870 | lb.payload() = OCTETSTRING(length, aligned_buffer.get_read_data()); |
| 871 | aligned_buffer.increase_pos(length); |
| 872 | ret_val.blocks()[0] = lb; |
| 873 | } else { |
| 874 | if (ret_val.blocks().is_bound()) { |
| 875 | for (int i = 0; i < ret_val.blocks().size_of(); i++) { |
| 876 | unsigned int length = ret_val.blocks()[i].hdr()().length__ind(); |
| 877 | if (length > aligned_buffer.get_read_len()) |
| 878 | length = aligned_buffer.get_read_len(); |
| 879 | ret_val.blocks()[i].payload() = OCTETSTRING(length, aligned_buffer.get_read_data()); |
| 880 | aligned_buffer.increase_pos(length); |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | return ret_val; |
| 886 | } |
| 887 | |
| 888 | RlcmacUlBlock dec__RlcmacUlBlock(const OCTETSTRING& stream) |
| 889 | { |
| 890 | RlcmacUlBlock ret_val; |
| 891 | size_t stream_len = stream.lengthof(); |
| 892 | CodingScheme::enum_type mcs = payload_len_2_coding_scheme(stream_len); |
| 893 | unsigned char pt; |
| 894 | |
| 895 | switch (mcs) { |
| 896 | case CodingScheme::CS__1: |
| 897 | case CodingScheme::CS__2: |
| 898 | case CodingScheme::CS__3: |
| 899 | case CodingScheme::CS__4: |
| 900 | pt = stream[0].get_octet() >> 6; |
| 901 | if (pt == MacPayloadType::MAC__PT__RLC__DATA) |
| 902 | ret_val.data() = dec__RlcmacUlDataBlock(stream); |
| 903 | else |
| 904 | ret_val.ctrl() = dec__RlcmacUlCtrlBlock(stream); |
| 905 | break; |
| 906 | case CodingScheme::MCS__1: |
| 907 | case CodingScheme::MCS__2: |
| 908 | case CodingScheme::MCS__3: |
| 909 | case CodingScheme::MCS__4: |
| 910 | case CodingScheme::MCS__5: |
| 911 | case CodingScheme::MCS__6: |
| 912 | case CodingScheme::MCS__7: |
| 913 | case CodingScheme::MCS__8: |
| 914 | case CodingScheme::MCS__9: |
| 915 | ret_val.data__egprs() = dec__RlcmacUlEgprsDataBlock(stream, mcs); |
| 916 | break; |
| 917 | } |
| 918 | |
| 919 | return ret_val; |
| 920 | } |
| 921 | |
| 922 | |
| 923 | ///////////////////// |
| 924 | // ENCODE |
| 925 | ///////////////////// |
| 926 | |
| 927 | /* ENCODE DOWNLINK */ |
| 928 | |
| 929 | OCTETSTRING enc__RlcmacDlDataBlock(const RlcmacDlDataBlock& si) |
| 930 | { |
| 931 | RlcmacDlDataBlock in = si; |
| 932 | OCTETSTRING ret_val; |
| 933 | TTCN_Buffer ttcn_buffer; |
| 934 | int i; |
| 935 | |
| 936 | /* Fix 'e' bit of initial header based on following blocks */ |
| 937 | if (!in.blocks().is_bound() || |
| 938 | (in.blocks().size_of() == 1 && !in.blocks()[0].hdr().is_bound())) |
| 939 | in.mac__hdr().hdr__ext().e() = true; |
| 940 | else |
| 941 | in.mac__hdr().hdr__ext().e() = false; |
| 942 | |
| 943 | /* use automatic/generated decoder for header */ |
| 944 | in.mac__hdr().encode(DlMacDataHeader_descr_, ttcn_buffer, TTCN_EncDec::CT_RAW); |
| 945 | |
| 946 | /* Add LI octets, if any */ |
| 947 | if (in.blocks().is_bound() && |
| 948 | (in.blocks().size_of() != 1 || in.blocks()[0].hdr().is_bound())) { |
| 949 | /* first write LI octets */ |
| 950 | for (i = 0; i < in.blocks().size_of(); i++) { |
| 951 | /* fix the 'E' bit in case it is not clear */ |
| 952 | if (i < in.blocks().size_of()-1) |
| 953 | in.blocks()[i].hdr()().e() = false; |
| 954 | else |
| 955 | in.blocks()[i].hdr()().e() = true; |
| 956 | in.blocks()[i].hdr()().encode(LlcBlockHdr_descr_, ttcn_buffer, TTCN_EncDec::CT_RAW); |
| 957 | } |
| 958 | } |
| 959 | if (in.blocks().is_bound()) { |
| 960 | for (i = 0; i < in.blocks().size_of(); i++) { |
| 961 | if (!in.blocks()[i].is_bound()) |
| 962 | continue; |
| 963 | ttcn_buffer.put_string(in.blocks()[i].payload()); |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | ttcn_buffer.get_string(ret_val); |
| 968 | return ret_val; |
| 969 | } |
| 970 | |
| 971 | static |
| 972 | void enc__RlcmacDlEgprsDataHeader_type1(const EgprsDlMacDataHeader& si, TTCN_Buffer& ttcn_buffer) |
| 973 | { |
| 974 | fprintf(stderr, "FIXME: Not implemented! %s (%s:%u)\n", __func__, __FILE__, __LINE__); |
| 975 | } |
| 976 | |
| 977 | static |
| 978 | void enc__RlcmacDlEgprsDataHeader_type2(const EgprsDlMacDataHeader& si, TTCN_Buffer& ttcn_buffer) |
| 979 | { |
| 980 | fprintf(stderr, "FIXME: Not implemented! %s (%s:%u)\n", __func__, __FILE__, __LINE__); |
| 981 | } |
| 982 | |
| 983 | static |
| 984 | void enc__RlcmacDlEgprsDataHeader_type3(const EgprsDlMacDataHeader& si, TTCN_Buffer& ttcn_buffer) |
| 985 | { |
| 986 | fprintf(stderr, "FIXME: Not implemented! %s (%s:%u)\n", __func__, __FILE__, __LINE__); |
| 987 | } |
| 988 | |
| 989 | OCTETSTRING enc__RlcmacDlEgprsDataBlock(const RlcmacDlEgprsDataBlock& si) |
| 990 | { |
| 991 | RlcmacDlEgprsDataBlock in = si; |
| 992 | OCTETSTRING ret_val; |
| 993 | TTCN_Buffer ttcn_buffer; |
| 994 | int i; |
| 995 | |
| 996 | /* Fix 'e' bit of initial header based on following blocks */ |
| 997 | if (!in.blocks().is_bound() || |
| 998 | (in.blocks().size_of() == 1 && !in.blocks()[0].hdr().is_bound())) |
| 999 | in.e() = true; |
| 1000 | else |
| 1001 | in.e() = false; |
| 1002 | |
| 1003 | switch (in.mac__hdr().header__type()) { |
| 1004 | case EgprsHeaderType::RLCMAC__HDR__TYPE__1: |
| 1005 | enc__RlcmacDlEgprsDataHeader_type1(si.mac__hdr(), ttcn_buffer); |
| 1006 | break; |
| 1007 | case EgprsHeaderType::RLCMAC__HDR__TYPE__2: |
| 1008 | enc__RlcmacDlEgprsDataHeader_type2(si.mac__hdr(), ttcn_buffer); |
| 1009 | break; |
| 1010 | case EgprsHeaderType::RLCMAC__HDR__TYPE__3: |
| 1011 | enc__RlcmacDlEgprsDataHeader_type3(si.mac__hdr(), ttcn_buffer); |
| 1012 | default: |
| 1013 | break; /* TODO: error */ |
| 1014 | } |
| 1015 | |
| 1016 | /* Add LI octets, if any */ |
| 1017 | if (in.blocks().is_bound() && |
| 1018 | (in.blocks().size_of() != 1 || in.blocks()[0].hdr().is_bound())) { |
| 1019 | /* first write LI octets */ |
| 1020 | for (i = 0; i < in.blocks().size_of(); i++) { |
| 1021 | /* fix the 'E' bit in case it is not clear */ |
| 1022 | if (i < in.blocks().size_of()-1) |
| 1023 | in.blocks()[i].hdr()().e() = false; |
| 1024 | else |
| 1025 | in.blocks()[i].hdr()().e() = true; |
| 1026 | in.blocks()[i].hdr()().encode(EgprsLlcBlockHdr_descr_, ttcn_buffer, TTCN_EncDec::CT_RAW); |
| 1027 | } |
| 1028 | } |
| 1029 | if (in.blocks().is_bound()) { |
| 1030 | for (i = 0; i < in.blocks().size_of(); i++) { |
| 1031 | if (!in.blocks()[i].is_bound()) |
| 1032 | continue; |
| 1033 | ttcn_buffer.put_string(in.blocks()[i].payload()); |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | ttcn_buffer.get_string(ret_val); |
| 1038 | return ret_val; |
| 1039 | } |
| 1040 | |
| 1041 | OCTETSTRING enc__RlcmacDlBlock(const RlcmacDlBlock& si) |
| 1042 | { |
| 1043 | if (si.ischosen(RlcmacDlBlock::ALT_data__egprs)) |
| 1044 | return enc__RlcmacDlEgprsDataBlock(si.data__egprs()); |
| 1045 | else if (si.ischosen(RlcmacDlBlock::ALT_data)) |
| 1046 | return enc__RlcmacDlDataBlock(si.data()); |
| 1047 | else |
| 1048 | return enc__RlcmacDlCtrlBlock(si.ctrl()); |
| 1049 | } |
| 1050 | |
| 1051 | /* ENCODE UPLINK */ |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1052 | |
| 1053 | OCTETSTRING enc__RlcmacUlDataBlock(const RlcmacUlDataBlock& si) |
| 1054 | { |
| 1055 | RlcmacUlDataBlock in = si; |
| 1056 | OCTETSTRING ret_val; |
| 1057 | TTCN_Buffer ttcn_buffer; |
| 1058 | int i; |
| 1059 | |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 1060 | if (!in.blocks().is_bound()) { |
Pau Espin Pedrol | ecaeb89 | 2020-04-30 19:58:15 +0200 | [diff] [blame] | 1061 | /* we don't have any blocks: Add length value (zero) */ |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 1062 | in.mac__hdr().e() = false; /* E=0: extension octet follows */ |
| 1063 | } else if (in.blocks().size_of() == 1 && in.blocks()[0].hdr() == OMIT_VALUE) { |
| 1064 | /* If there's only a single block, and that block has no HDR value defined, */ |
| 1065 | in.mac__hdr().e() = true; /* E=0: extension octet follows */ |
| 1066 | } else { |
| 1067 | /* Length value */ |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1068 | in.mac__hdr().e() = false; |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 1069 | } |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1070 | |
| 1071 | /* Fix other presence indications */ |
Harald Welte | 2072ab6 | 2017-07-31 18:33:35 +0200 | [diff] [blame] | 1072 | in.mac__hdr().tlli__ind() = in.tlli().is_bound() && in.tlli() != OMIT_VALUE; |
| 1073 | in.mac__hdr().pfi__ind() = in.pfi().is_bound() && in.pfi() != OMIT_VALUE; |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1074 | |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 1075 | /* use automatic/generated encoder for header */ |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1076 | in.mac__hdr().encode(UlMacDataHeader_descr_, ttcn_buffer, TTCN_EncDec::CT_RAW); |
| 1077 | |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 1078 | if (in.mac__hdr().e() == false) { |
| 1079 | /* Add LI octets, if any */ |
| 1080 | if (!in.blocks().is_bound()) { |
| 1081 | ttcn_buffer.put_c(0x01); /* M=0, E=1 LEN=0 */ |
| 1082 | } else { |
| 1083 | for (i = 0; i < in.blocks().size_of(); i++) { |
| 1084 | #if 0 |
| 1085 | /* check for penultimate block */ |
| 1086 | if (i == in.blocks().size_of()-2) { |
| 1087 | /* if last block has no header, no more LI */ |
| 1088 | if (in.blocks()[i+1].hdr() == OMIT_VALUE) { |
| 1089 | in.blocks()[i].hdr()().more() = true; |
| 1090 | } else { |
| 1091 | /* header present, we have to encode LI */ |
| 1092 | in.blocks()[i].hdr()().more() = false; |
| 1093 | in.blocks()[i].hdr()().length__ind() = |
| 1094 | in.blocks()[i+1].payload().lengthof(); |
| 1095 | } |
| 1096 | } else if (i < in.blocks().size_of()-2) { |
| 1097 | /* one of the first blocks, before the penultimate or last */ |
| 1098 | in.blocks()[i].hdr()().e() = false; /* LI present */ |
| 1099 | /* re-compute length */ |
| 1100 | in.blocks()[i].hdr()().length__ind() = |
| 1101 | in.blocks()[i+1].payload().lengthof(); |
| 1102 | } |
| 1103 | /* Encode LI octet if E=0 */ |
| 1104 | } |
| 1105 | #endif |
| 1106 | if (in.blocks()[i].hdr() != OMIT_VALUE) { |
| 1107 | in.blocks()[i].hdr()().encode(LlcBlockHdr_descr_, ttcn_buffer, |
| 1108 | TTCN_EncDec::CT_RAW); |
| 1109 | } |
| 1110 | } |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | if (in.mac__hdr().tlli__ind()) { |
Harald Welte | acc93ab | 2018-03-02 21:39:09 +0100 | [diff] [blame] | 1115 | ttcn_buffer.put_string(in.tlli()); |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | if (in.mac__hdr().pfi__ind()) { |
| 1119 | in.pfi().encode(RlcmacUlDataBlock_pfi_descr_, ttcn_buffer, TTCN_EncDec::CT_RAW); |
| 1120 | } |
| 1121 | |
| 1122 | if (in.blocks().is_bound()) { |
| 1123 | for (i = 0; i < in.blocks().size_of(); i++) { |
| 1124 | if (!in.blocks()[i].is_bound()) |
| 1125 | continue; |
| 1126 | ttcn_buffer.put_string(in.blocks()[i].payload()); |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | ttcn_buffer.get_string(ret_val); |
| 1131 | return ret_val; |
| 1132 | } |
| 1133 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1134 | static |
| 1135 | void enc__RlcmacUlEgprsDataHeader_type1(const EgprsUlMacDataHeader& si, TTCN_Buffer& ttcn_buffer) |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1136 | { |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1137 | fprintf(stderr, "FIXME: Not implemented! %s (%s:%u)\n", __func__, __FILE__, __LINE__); |
| 1138 | } |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1139 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1140 | static |
| 1141 | void enc__RlcmacUlEgprsDataHeader_type2(const EgprsUlMacDataHeader& si, TTCN_Buffer& ttcn_buffer) |
| 1142 | { |
| 1143 | fprintf(stderr, "FIXME: Not implemented! %s (%s:%u)\n", __func__, __FILE__, __LINE__); |
| 1144 | } |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1145 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1146 | static |
| 1147 | void enc__RlcmacUlEgprsDataHeader_type3(const EgprsUlMacDataHeader& si, TTCN_Buffer& ttcn_buffer) |
| 1148 | { |
| 1149 | struct gprs_rlc_ul_header_egprs_3 egprs3; |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1150 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1151 | egprs3.r = bs2uint8(si.r__ri()); |
| 1152 | egprs3.si = bs2uint8(si.foi__si()); |
| 1153 | egprs3.cv = si.countdown(); |
| 1154 | egprs3.tfi_hi = si.tfi() >> 0; |
Pau Espin Pedrol | d3da797 | 2020-04-30 20:06:52 +0200 | [diff] [blame] | 1155 | egprs3.tfi_lo = si.tfi() >> 2; |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1156 | egprs3.bsn1_hi = si.bsn1() >> 0; |
| 1157 | egprs3.bsn1_lo = si.bsn1() >> 5; |
| 1158 | egprs3.cps_hi = si.cps() >> 0; |
| 1159 | egprs3.cps_lo = si.cps() >> 2; |
| 1160 | egprs3.spb = bs2uint8(si.spb()); |
Pau Espin Pedrol | d3da797 | 2020-04-30 20:06:52 +0200 | [diff] [blame] | 1161 | egprs3.rsb = bs2uint8(si.rsb()); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1162 | egprs3.pi = si.pfi__ind(); |
| 1163 | egprs3.spare = 0; |
| 1164 | egprs3.dummy = 0; |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1165 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1166 | ttcn_buffer.put_s(sizeof(egprs3), (const unsigned char *)&egprs3); |
| 1167 | } |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1168 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1169 | OCTETSTRING enc__RlcmacUlEgprsDataBlock(const RlcmacUlEgprsDataBlock& si) |
| 1170 | { |
| 1171 | RlcmacUlEgprsDataBlock in = si; |
| 1172 | OCTETSTRING ret_val; |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 1173 | TTCN_Buffer ttcn_buffer, aligned_buffer; |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1174 | int i; |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 1175 | unsigned int data_block_bits, data_block_offsets[2]; |
| 1176 | unsigned int num_calls; |
| 1177 | CodingScheme mcs; |
| 1178 | boolean tlli_ind, e; |
| 1179 | |
| 1180 | mcs = RLCMAC__Templates::f__rlcmac__cps__htype__to__mcs(in.mac__hdr().cps(), in.mac__hdr().header__type()); |
| 1181 | //fprintf(stderr, "RLCMAC: infered MCS %s (%d)\n", mcs.enum_to_str(static_cast<CodingScheme::enum_type>(mcs.as_int())), mcs.as_int()); |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1182 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1183 | if (!in.blocks().is_bound()) { |
| 1184 | /* we don't have nay blocks: Add length value (zero) */ |
| 1185 | in.e() = false; /* E=0: extension octet follows */ |
| 1186 | } else if (in.blocks().size_of() == 1 && in.blocks()[0].hdr() == OMIT_VALUE) { |
| 1187 | /* If there's only a single block, and that block has no HDR value defined, */ |
| 1188 | in.e() = true; /* E=0: extension octet follows */ |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1189 | } else { |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1190 | /* Length value */ |
| 1191 | in.e() = false; |
| 1192 | } |
| 1193 | |
| 1194 | /* Fix other presence indications */ |
| 1195 | in.tlli__ind() = in.tlli().is_bound() && in.tlli() != OMIT_VALUE; |
| 1196 | in.mac__hdr().pfi__ind() = in.pfi().is_bound() && in.pfi() != OMIT_VALUE; |
| 1197 | |
| 1198 | switch (in.mac__hdr().header__type()) { |
| 1199 | case EgprsHeaderType::RLCMAC__HDR__TYPE__1: |
Pau Espin Pedrol | 82d22bc | 2020-04-30 20:09:12 +0200 | [diff] [blame] | 1200 | enc__RlcmacUlEgprsDataHeader_type1(in.mac__hdr(), ttcn_buffer); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1201 | break; |
| 1202 | case EgprsHeaderType::RLCMAC__HDR__TYPE__2: |
Pau Espin Pedrol | 82d22bc | 2020-04-30 20:09:12 +0200 | [diff] [blame] | 1203 | enc__RlcmacUlEgprsDataHeader_type2(in.mac__hdr(), ttcn_buffer); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1204 | break; |
| 1205 | case EgprsHeaderType::RLCMAC__HDR__TYPE__3: |
Pau Espin Pedrol | 82d22bc | 2020-04-30 20:09:12 +0200 | [diff] [blame] | 1206 | enc__RlcmacUlEgprsDataHeader_type3(in.mac__hdr(), ttcn_buffer); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1207 | default: |
| 1208 | break; /* TODO: error */ |
| 1209 | } |
| 1210 | |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 1211 | /* Put first TI + E byte */ |
| 1212 | aligned_buffer.put_c(tlli_ind << 1 | e << 0); /* M=0, E=1 LEN=0 */ |
| 1213 | //printbuffer("After encoding first byte", aligned_buffer); |
| 1214 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1215 | if (in.e() == false) { |
| 1216 | /* Add LI octets, if any */ |
| 1217 | if (!in.blocks().is_bound()) { |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 1218 | aligned_buffer.put_c(0x01); /* M=0, E=1 LEN=0 */ |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1219 | } else { |
| 1220 | for (i = 0; i < in.blocks().size_of(); i++) { |
| 1221 | #if 0 |
| 1222 | /* check for penultimate block */ |
| 1223 | if (i == in.blocks().size_of()-2) { |
| 1224 | /* if last block has no header, no more LI */ |
| 1225 | if (in.blocks()[i+1].hdr() == OMIT_VALUE) { |
| 1226 | in.blocks()[i].hdr()().more() = true; |
| 1227 | } else { |
| 1228 | /* header present, we have to encode LI */ |
| 1229 | in.blocks()[i].hdr()().more() = false; |
| 1230 | in.blocks()[i].hdr()().length__ind() = |
| 1231 | in.blocks()[i+1].payload().lengthof(); |
| 1232 | } |
| 1233 | } else if (i < in.blocks().size_of()-2) { |
| 1234 | /* one of the first blocks, before the penultimate or last */ |
| 1235 | in.blocks()[i].hdr()().e() = false; /* LI present */ |
| 1236 | /* re-compute length */ |
| 1237 | in.blocks()[i].hdr()().length__ind() = |
| 1238 | in.blocks()[i+1].payload().lengthof(); |
| 1239 | } |
| 1240 | /* Encode LI octet if E=0 */ |
| 1241 | } |
| 1242 | #endif |
| 1243 | if (in.blocks()[i].hdr() != OMIT_VALUE) { |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 1244 | in.blocks()[i].hdr()().encode(EgprsLlcBlockHdr_descr_, aligned_buffer, |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1245 | TTCN_EncDec::CT_RAW); |
| 1246 | } |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1247 | } |
| 1248 | } |
| 1249 | } |
| 1250 | |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 1251 | |
| 1252 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1253 | if (in.tlli__ind()) { |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 1254 | aligned_buffer.put_string(in.tlli()); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1255 | } |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1256 | |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1257 | if (in.mac__hdr().pfi__ind()) { |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 1258 | in.pfi().encode(RlcmacUlEgprsDataBlock_pfi_descr_, aligned_buffer, TTCN_EncDec::CT_RAW); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1259 | } |
| 1260 | |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 1261 | //printbuffer("Before encoding EgprsLlc payload", aligned_buffer); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1262 | if (in.blocks().is_bound()) { |
| 1263 | for (i = 0; i < in.blocks().size_of(); i++) { |
| 1264 | if (!in.blocks()[i].is_bound()) |
| 1265 | continue; |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 1266 | aligned_buffer.put_string(in.blocks()[i].payload()); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1267 | } |
| 1268 | } |
Pau Espin Pedrol | 2456dad | 2020-04-30 20:22:38 +0200 | [diff] [blame] | 1269 | //printbuffer("After encoding EgprsLlc payload", aligned_buffer); |
| 1270 | |
| 1271 | setup_rlc_mac_priv(mcs, in.mac__hdr().header__type(), true, |
| 1272 | &num_calls, &data_block_bits, data_block_offsets); |
| 1273 | //printbuffer("before merging data block", ttcn_buffer); |
| 1274 | put_egprs_data_block(aligned_buffer, data_block_offsets[0], data_block_bits, ttcn_buffer); |
| 1275 | //printbuffer("after merging data block", ttcn_buffer); |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1276 | |
| 1277 | ttcn_buffer.get_string(ret_val); |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1278 | return ret_val; |
| 1279 | } |
| 1280 | |
Harald Welte | 78a1af6 | 2017-07-31 17:33:56 +0200 | [diff] [blame] | 1281 | OCTETSTRING enc__RlcmacUlBlock(const RlcmacUlBlock& si) |
| 1282 | { |
Pau Espin Pedrol | 372af7a | 2020-04-27 17:32:01 +0200 | [diff] [blame] | 1283 | if (si.ischosen(RlcmacUlBlock::ALT_data__egprs)) |
| 1284 | return enc__RlcmacUlEgprsDataBlock(si.data__egprs()); |
| 1285 | else if (si.ischosen(RlcmacUlBlock::ALT_data)) |
Harald Welte | 78a1af6 | 2017-07-31 17:33:56 +0200 | [diff] [blame] | 1286 | return enc__RlcmacUlDataBlock(si.data()); |
| 1287 | else |
| 1288 | return enc__RlcmacUlCtrlBlock(si.ctrl()); |
| 1289 | } |
| 1290 | |
Harald Welte | 43e060a | 2017-07-30 22:38:03 +0200 | [diff] [blame] | 1291 | } // namespace |