blob: eaa4953494dc8b33d72b58f59bb9d9c17f61f41f [file] [log] [blame]
Max51754b62019-03-13 17:14:13 +01001/* coding_scheme.c
2 *
3 * Copyright (C) 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#include <stdint.h>
21#include <stdbool.h>
22
23#include <osmocom/core/utils.h>
24
25#include "coding_scheme.h"
26
Max136ebcc2019-03-05 14:59:03 +010027const struct value_string mcs_names[] = {
28 { UNKNOWN, "UNKNOWN" },
29 { CS1, "CS-1" },
30 { CS2, "CS-2" },
31 { CS3, "CS-3" },
32 { CS4, "CS-4" },
33 { MCS1, "MCS-1" },
34 { MCS2, "MCS-2" },
35 { MCS3, "MCS-3" },
36 { MCS4, "MCS-4" },
37 { MCS5, "MCS-5" },
38 { MCS6, "MCS-6" },
39 { MCS7, "MCS-7" },
40 { MCS8, "MCS-8" },
41 { MCS9, "MCS-9" },
42 { 0, NULL }
43};
44
45const char *mcs_name(enum CodingScheme val) {
46 return get_value_string(mcs_names, val);
47}
48
Max8a8e0fb2019-03-25 16:32:50 +010049bool mcs_is_gprs(enum CodingScheme cs)
50{
51 return CS1 <= cs && cs <= CS4;
52}
53
54bool mcs_is_edge(enum CodingScheme cs)
55{
56 return MCS1 <= cs && cs <= MCS9;
57}
58
59bool mcs_is_edge_gmsk(enum CodingScheme cs)
60{
61 if (mcs_is_edge(cs))
62 return cs <= MCS4;
63
64 return false;
65}
66
Max898dddb2019-03-12 15:50:57 +010067/* Return 3GPP TS 44.060 ยง12.10d (EDGE) or Table 11.2.28.2 (GPRS) Channel Coding Command value */
68uint8_t mcs_chan_code(enum CodingScheme cs)
69{
70 if (mcs_is_gprs(cs))
71 return cs - CS1;
72
73 if (mcs_is_edge(cs))
74 return cs - MCS1;
75
76 /* Defaults to (M)CS1 */
77 return 0;
78}
79
Max51754b62019-03-13 17:14:13 +010080static struct {
81 struct {
82 uint8_t data_header_bits;
83 } uplink, downlink;
84 uint8_t data_block_header_bits;
85 uint8_t num_blocks;
86 const char *name;
87} hdr_type_info[NUM_HEADER_TYPES] = {
88 { { 0 }, { 0 }, 0, 0, "INVALID" },
89 { { 1 * 8 + 0 }, { 1 * 8 + 0 }, 0, 0, "CONTROL" },
90 { { 3 * 8 + 0 }, { 3 * 8 + 0 }, 0, 1, "GPRS_DATA" },
91 { { 5 * 8 + 6 }, { 5 * 8 + 0 }, 2, 2, "EGPRS_DATA_TYPE1" },
92 { { 4 * 8 + 5 }, { 3 * 8 + 4 }, 2, 1, "EGPRS_DATA_TYPE2" },
93 { { 3 * 8 + 7 }, { 3 * 8 + 7 }, 2, 1, "EGPRS_DATA_TYPE3" },
94};
95
96uint8_t num_data_blocks(enum HeaderType ht)
97{
98 OSMO_ASSERT(ht < NUM_HEADER_TYPES);
99 return hdr_type_info[ht].num_blocks;
100}
101
102uint8_t num_data_header_bits_UL(enum HeaderType ht)
103{
104 OSMO_ASSERT(ht < NUM_HEADER_TYPES);
105 return hdr_type_info[ht].uplink.data_header_bits;
106}
107
108uint8_t num_data_header_bits_DL(enum HeaderType ht)
109{
110 OSMO_ASSERT(ht < NUM_HEADER_TYPES);
111 return hdr_type_info[ht].downlink.data_header_bits;
112}
113
114uint8_t num_data_block_header_bits(enum HeaderType ht)
115{
116 OSMO_ASSERT(ht < NUM_HEADER_TYPES);
117 return hdr_type_info[ht].data_block_header_bits;
118}
Maxa4de02d2019-03-13 16:35:09 +0100119
120const struct value_string mode_names[] = {
121 { GPRS, "GPRS" },
122 { EGPRS_GMSK, "EGPRS_GMSK-only"},
123 { EGPRS, "EGPRS"},
124 { 0, NULL }
125};
126
127const char *mode_name(enum mcs_kind val) {
128 return get_value_string(mode_names, val);
129}
Max902e3e52019-03-25 16:38:53 +0100130
131/* FIXME: take into account padding and special cases of commanded MCS (MCS-6-9 and MCS-5-7) */
132enum CodingScheme get_retx_mcs(enum CodingScheme initial_mcs, enum CodingScheme commanded_mcs, bool resegment_bit)
133{
134 OSMO_ASSERT(mcs_is_edge(initial_mcs));
135 OSMO_ASSERT(mcs_is_edge(commanded_mcs));
136 OSMO_ASSERT(NUM_SCHEMES - MCS1 == 9);
137
138 if (resegment_bit) { /* 3GPP TS 44.060 Table 8.1.1.1, reflected over antidiagonal */
139 enum CodingScheme egprs_reseg[NUM_SCHEMES - MCS1][NUM_SCHEMES - MCS1] = {
140 { MCS1, MCS1, MCS1, MCS1, MCS1, MCS1, MCS1, MCS1, MCS1 },
141 { MCS2, MCS2, MCS2, MCS2, MCS2, MCS2, MCS2, MCS2, MCS2 },
142 { MCS3, MCS3, MCS3, MCS3, MCS3, MCS3, MCS3, MCS3, MCS3 },
143 { MCS1, MCS1, MCS1, MCS4, MCS4, MCS4, MCS4, MCS4, MCS4 },
144 { MCS2, MCS2, MCS2, MCS2, MCS5, MCS5, MCS7, MCS7, MCS7 },
145 { MCS3, MCS3, MCS3, MCS3, MCS3, MCS6, MCS6, MCS6, MCS9 },
146 { MCS2, MCS2, MCS2, MCS2, MCS5, MCS5, MCS7, MCS7, MCS7 },
147 { MCS3, MCS3, MCS3, MCS3, MCS3, MCS6, MCS6, MCS8, MCS8 },
148 { MCS3, MCS3, MCS3, MCS3, MCS3, MCS6, MCS6, MCS6, MCS9 },
149 };
150 return egprs_reseg[mcs_chan_code(initial_mcs)][mcs_chan_code(commanded_mcs)];
151 } else { /* 3GPP TS 44.060 Table 8.1.1.2, reflected over antidiagonal */
152 enum CodingScheme egprs_no_reseg[NUM_SCHEMES - MCS1][NUM_SCHEMES - MCS1] = {
153 { MCS1, MCS1, MCS1, MCS1, MCS1, MCS1, MCS1, MCS1, MCS1 },
154 { MCS2, MCS2, MCS2, MCS2, MCS2, MCS2, MCS2, MCS2, MCS2 },
155 { MCS3, MCS3, MCS3, MCS3, MCS3, MCS3, MCS3, MCS3, MCS3 },
156 { MCS4, MCS4, MCS4, MCS4, MCS4, MCS4, MCS4, MCS4, MCS4 },
157 { MCS5, MCS5, MCS5, MCS5, MCS5, MCS5, MCS7, MCS7, MCS7 },
158 { MCS6, MCS6, MCS6, MCS6, MCS6, MCS6, MCS6, MCS6, MCS9 },
159 { MCS5, MCS5, MCS5, MCS5, MCS5, MCS5, MCS7, MCS7, MCS7 },
160 { MCS6, MCS6, MCS6, MCS6, MCS6, MCS6, MCS6, MCS8, MCS8 },
161 { MCS6, MCS6, MCS6, MCS6, MCS6, MCS6, MCS6, MCS6, MCS9 },
162 };
163 return egprs_no_reseg[mcs_chan_code(initial_mcs)][mcs_chan_code(commanded_mcs)];
164 }
165}