Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 1 | /* coding_scheme.h |
| 2 | * |
| 3 | * Copyright (C) 2015-2019 by sysmocom s.f.m.c. GmbH |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | |
| 20 | #pragma once |
| 21 | |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 22 | #include <osmocom/core/utils.h> |
| 23 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 24 | #include <stdbool.h> |
| 25 | |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 26 | enum CodingScheme { |
| 27 | UNKNOWN, |
| 28 | /* GPRS Coding Schemes: */ |
| 29 | CS1, CS2, CS3, CS4, |
| 30 | /* EDGE/EGPRS Modulation and Coding Schemes: */ |
| 31 | MCS1, MCS2, MCS3, MCS4, MCS5, MCS6, MCS7, MCS8, MCS9, |
| 32 | NUM_SCHEMES |
| 33 | }; |
Max | 51754b6 | 2019-03-13 17:14:13 +0100 | [diff] [blame] | 34 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 35 | enum mcs_kind { |
| 36 | GPRS, |
| 37 | EGPRS_GMSK, |
| 38 | EGPRS, |
| 39 | }; |
| 40 | |
Pau Espin Pedrol | 97296b2 | 2021-01-14 13:08:02 +0100 | [diff] [blame] | 41 | enum egprs_arq_type { |
| 42 | EGPRS_ARQ1 = 0, |
| 43 | EGPRS_ARQ2 = 1 |
| 44 | }; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 45 | |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 46 | extern const struct value_string mcs_names[]; |
| 47 | const char *mcs_name(enum CodingScheme val); |
Max | 902e3e5 | 2019-03-25 16:38:53 +0100 | [diff] [blame] | 48 | enum CodingScheme get_retx_mcs(enum CodingScheme initial_mcs, enum CodingScheme commanded_mcs, bool resegment_bit); |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 49 | |
Max | 8a8e0fb | 2019-03-25 16:32:50 +0100 | [diff] [blame] | 50 | bool mcs_is_gprs(enum CodingScheme cs); |
| 51 | bool mcs_is_edge(enum CodingScheme cs); |
| 52 | bool mcs_is_edge_gmsk(enum CodingScheme cs); |
| 53 | |
Max | 898dddb | 2019-03-12 15:50:57 +0100 | [diff] [blame] | 54 | uint8_t mcs_chan_code(enum CodingScheme cs); |
| 55 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 56 | enum CodingScheme mcs_get_by_size_ul(unsigned size); |
| 57 | enum CodingScheme mcs_get_gprs_by_num(unsigned num); |
| 58 | enum CodingScheme mcs_get_egprs_by_num(unsigned num); |
| 59 | bool mcs_is_valid(enum CodingScheme cs); |
| 60 | bool mcs_is_compat(enum CodingScheme cs, enum CodingScheme o); |
| 61 | bool mcs_is_compat_kind(enum CodingScheme cs, enum mcs_kind mode); |
| 62 | |
| 63 | uint8_t mcs_size_ul(enum CodingScheme cs); |
| 64 | uint8_t mcs_size_dl(enum CodingScheme cs); |
| 65 | uint8_t mcs_used_size_ul(enum CodingScheme cs); |
| 66 | uint8_t mcs_used_size_dl(enum CodingScheme cs); |
| 67 | uint8_t mcs_max_bytes_ul(enum CodingScheme cs); |
| 68 | uint8_t mcs_max_bytes_dl(enum CodingScheme cs); |
| 69 | uint8_t mcs_spare_bits_ul(enum CodingScheme cs); |
| 70 | uint8_t mcs_spare_bits_dl(enum CodingScheme cs); |
| 71 | uint8_t mcs_max_data_block_bytes(enum CodingScheme cs); |
| 72 | uint8_t mcs_opt_padding_bits(enum CodingScheme cs); |
| 73 | |
| 74 | void mcs_inc_kind(enum CodingScheme *cs, enum mcs_kind mode); |
| 75 | void mcs_dec_kind(enum CodingScheme *cs, enum mcs_kind mode); |
| 76 | void mcs_inc(enum CodingScheme *cs); |
| 77 | void mcs_dec(enum CodingScheme *cs); |
| 78 | |
| 79 | bool mcs_is_family_compat(enum CodingScheme cs, enum CodingScheme o); |
| 80 | void mcs_dec_to_single_block(enum CodingScheme *cs, bool *need_stuffing); |
| 81 | |
Max | 51754b6 | 2019-03-13 17:14:13 +0100 | [diff] [blame] | 82 | enum HeaderType { |
| 83 | HEADER_INVALID, |
| 84 | HEADER_GPRS_CONTROL, |
| 85 | HEADER_GPRS_DATA, |
| 86 | HEADER_EGPRS_DATA_TYPE_1, |
| 87 | HEADER_EGPRS_DATA_TYPE_2, |
| 88 | HEADER_EGPRS_DATA_TYPE_3, |
| 89 | NUM_HEADER_TYPES |
| 90 | }; |
| 91 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 92 | enum HeaderType mcs_header_type(enum CodingScheme mcs); |
Max | 51754b6 | 2019-03-13 17:14:13 +0100 | [diff] [blame] | 93 | |
| 94 | uint8_t num_data_blocks(enum HeaderType ht); |
| 95 | uint8_t num_data_header_bits_UL(enum HeaderType ht); |
| 96 | uint8_t num_data_header_bits_DL(enum HeaderType ht); |
| 97 | uint8_t num_data_block_header_bits(enum HeaderType ht); |
Max | a4de02d | 2019-03-13 16:35:09 +0100 | [diff] [blame] | 98 | |
Max | a4de02d | 2019-03-13 16:35:09 +0100 | [diff] [blame] | 99 | const char *mode_name(enum mcs_kind val); |