blob: ea1ded1b938cfeb0e5d6b10b4208fd8e481aadb5 [file] [log] [blame]
Maxbea2edb2019-03-06 17:04:59 +01001/* 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
Max136ebcc2019-03-05 14:59:03 +010022#include <osmocom/core/utils.h>
23
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020024#include <stdbool.h>
25
Maxbea2edb2019-03-06 17:04:59 +010026enum 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};
Max51754b62019-03-13 17:14:13 +010034
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020035enum mcs_kind {
36 GPRS,
37 EGPRS_GMSK,
38 EGPRS,
39};
40
41#define EGPRS_ARQ1 0x0
42#define EGPRS_ARQ2 0x1
43
Max136ebcc2019-03-05 14:59:03 +010044extern const struct value_string mcs_names[];
45const char *mcs_name(enum CodingScheme val);
Max902e3e52019-03-25 16:38:53 +010046enum CodingScheme get_retx_mcs(enum CodingScheme initial_mcs, enum CodingScheme commanded_mcs, bool resegment_bit);
Max136ebcc2019-03-05 14:59:03 +010047
Max8a8e0fb2019-03-25 16:32:50 +010048bool mcs_is_gprs(enum CodingScheme cs);
49bool mcs_is_edge(enum CodingScheme cs);
50bool mcs_is_edge_gmsk(enum CodingScheme cs);
51
Max898dddb2019-03-12 15:50:57 +010052uint8_t mcs_chan_code(enum CodingScheme cs);
53
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020054enum CodingScheme mcs_get_by_size_ul(unsigned size);
55enum CodingScheme mcs_get_gprs_by_num(unsigned num);
56enum CodingScheme mcs_get_egprs_by_num(unsigned num);
57bool mcs_is_valid(enum CodingScheme cs);
58bool mcs_is_compat(enum CodingScheme cs, enum CodingScheme o);
59bool mcs_is_compat_kind(enum CodingScheme cs, enum mcs_kind mode);
60
61uint8_t mcs_size_ul(enum CodingScheme cs);
62uint8_t mcs_size_dl(enum CodingScheme cs);
63uint8_t mcs_used_size_ul(enum CodingScheme cs);
64uint8_t mcs_used_size_dl(enum CodingScheme cs);
65uint8_t mcs_max_bytes_ul(enum CodingScheme cs);
66uint8_t mcs_max_bytes_dl(enum CodingScheme cs);
67uint8_t mcs_spare_bits_ul(enum CodingScheme cs);
68uint8_t mcs_spare_bits_dl(enum CodingScheme cs);
69uint8_t mcs_max_data_block_bytes(enum CodingScheme cs);
70uint8_t mcs_opt_padding_bits(enum CodingScheme cs);
71
72void mcs_inc_kind(enum CodingScheme *cs, enum mcs_kind mode);
73void mcs_dec_kind(enum CodingScheme *cs, enum mcs_kind mode);
74void mcs_inc(enum CodingScheme *cs);
75void mcs_dec(enum CodingScheme *cs);
76
77bool mcs_is_family_compat(enum CodingScheme cs, enum CodingScheme o);
78void mcs_dec_to_single_block(enum CodingScheme *cs, bool *need_stuffing);
79
Max51754b62019-03-13 17:14:13 +010080enum HeaderType {
81 HEADER_INVALID,
82 HEADER_GPRS_CONTROL,
83 HEADER_GPRS_DATA,
84 HEADER_EGPRS_DATA_TYPE_1,
85 HEADER_EGPRS_DATA_TYPE_2,
86 HEADER_EGPRS_DATA_TYPE_3,
87 NUM_HEADER_TYPES
88};
89
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020090enum HeaderType mcs_header_type(enum CodingScheme mcs);
Max51754b62019-03-13 17:14:13 +010091
92uint8_t num_data_blocks(enum HeaderType ht);
93uint8_t num_data_header_bits_UL(enum HeaderType ht);
94uint8_t num_data_header_bits_DL(enum HeaderType ht);
95uint8_t num_data_block_header_bits(enum HeaderType ht);
Maxa4de02d2019-03-13 16:35:09 +010096
Maxa4de02d2019-03-13 16:35:09 +010097const char *mode_name(enum mcs_kind val);