blob: 1b212650c1675e34b2ff7995d774d7e3ffd2fe50 [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
Pau Espin Pedrol97296b22021-01-14 13:08:02 +010041enum egprs_arq_type {
42 EGPRS_ARQ1 = 0,
43 EGPRS_ARQ2 = 1
44};
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020045
Max136ebcc2019-03-05 14:59:03 +010046extern const struct value_string mcs_names[];
47const char *mcs_name(enum CodingScheme val);
Max902e3e52019-03-25 16:38:53 +010048enum CodingScheme get_retx_mcs(enum CodingScheme initial_mcs, enum CodingScheme commanded_mcs, bool resegment_bit);
Max136ebcc2019-03-05 14:59:03 +010049
Max8a8e0fb2019-03-25 16:32:50 +010050bool mcs_is_gprs(enum CodingScheme cs);
51bool mcs_is_edge(enum CodingScheme cs);
52bool mcs_is_edge_gmsk(enum CodingScheme cs);
53
Max898dddb2019-03-12 15:50:57 +010054uint8_t mcs_chan_code(enum CodingScheme cs);
55
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020056enum CodingScheme mcs_get_by_size_ul(unsigned size);
57enum CodingScheme mcs_get_gprs_by_num(unsigned num);
58enum CodingScheme mcs_get_egprs_by_num(unsigned num);
59bool mcs_is_valid(enum CodingScheme cs);
60bool mcs_is_compat(enum CodingScheme cs, enum CodingScheme o);
61bool mcs_is_compat_kind(enum CodingScheme cs, enum mcs_kind mode);
62
63uint8_t mcs_size_ul(enum CodingScheme cs);
64uint8_t mcs_size_dl(enum CodingScheme cs);
65uint8_t mcs_used_size_ul(enum CodingScheme cs);
66uint8_t mcs_used_size_dl(enum CodingScheme cs);
67uint8_t mcs_max_bytes_ul(enum CodingScheme cs);
68uint8_t mcs_max_bytes_dl(enum CodingScheme cs);
69uint8_t mcs_spare_bits_ul(enum CodingScheme cs);
70uint8_t mcs_spare_bits_dl(enum CodingScheme cs);
71uint8_t mcs_max_data_block_bytes(enum CodingScheme cs);
72uint8_t mcs_opt_padding_bits(enum CodingScheme cs);
73
74void mcs_inc_kind(enum CodingScheme *cs, enum mcs_kind mode);
75void mcs_dec_kind(enum CodingScheme *cs, enum mcs_kind mode);
76void mcs_inc(enum CodingScheme *cs);
77void mcs_dec(enum CodingScheme *cs);
78
79bool mcs_is_family_compat(enum CodingScheme cs, enum CodingScheme o);
80void mcs_dec_to_single_block(enum CodingScheme *cs, bool *need_stuffing);
81
Max51754b62019-03-13 17:14:13 +010082enum 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 Pedrol2ae83372020-05-18 11:35:35 +020092enum HeaderType mcs_header_type(enum CodingScheme mcs);
Max51754b62019-03-13 17:14:13 +010093
94uint8_t num_data_blocks(enum HeaderType ht);
95uint8_t num_data_header_bits_UL(enum HeaderType ht);
96uint8_t num_data_header_bits_DL(enum HeaderType ht);
97uint8_t num_data_block_header_bits(enum HeaderType ht);
Maxa4de02d2019-03-13 16:35:09 +010098
Maxa4de02d2019-03-13 16:35:09 +010099const char *mode_name(enum mcs_kind val);