blob: 4a5d0d4d86f9e95ac48d8dad1290c590b0517a45 [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
Max51754b62019-03-13 17:14:13 +010067static struct {
68 struct {
69 uint8_t data_header_bits;
70 } uplink, downlink;
71 uint8_t data_block_header_bits;
72 uint8_t num_blocks;
73 const char *name;
74} hdr_type_info[NUM_HEADER_TYPES] = {
75 { { 0 }, { 0 }, 0, 0, "INVALID" },
76 { { 1 * 8 + 0 }, { 1 * 8 + 0 }, 0, 0, "CONTROL" },
77 { { 3 * 8 + 0 }, { 3 * 8 + 0 }, 0, 1, "GPRS_DATA" },
78 { { 5 * 8 + 6 }, { 5 * 8 + 0 }, 2, 2, "EGPRS_DATA_TYPE1" },
79 { { 4 * 8 + 5 }, { 3 * 8 + 4 }, 2, 1, "EGPRS_DATA_TYPE2" },
80 { { 3 * 8 + 7 }, { 3 * 8 + 7 }, 2, 1, "EGPRS_DATA_TYPE3" },
81};
82
83uint8_t num_data_blocks(enum HeaderType ht)
84{
85 OSMO_ASSERT(ht < NUM_HEADER_TYPES);
86 return hdr_type_info[ht].num_blocks;
87}
88
89uint8_t num_data_header_bits_UL(enum HeaderType ht)
90{
91 OSMO_ASSERT(ht < NUM_HEADER_TYPES);
92 return hdr_type_info[ht].uplink.data_header_bits;
93}
94
95uint8_t num_data_header_bits_DL(enum HeaderType ht)
96{
97 OSMO_ASSERT(ht < NUM_HEADER_TYPES);
98 return hdr_type_info[ht].downlink.data_header_bits;
99}
100
101uint8_t num_data_block_header_bits(enum HeaderType ht)
102{
103 OSMO_ASSERT(ht < NUM_HEADER_TYPES);
104 return hdr_type_info[ht].data_block_header_bits;
105}
Maxa4de02d2019-03-13 16:35:09 +0100106
107const struct value_string mode_names[] = {
108 { GPRS, "GPRS" },
109 { EGPRS_GMSK, "EGPRS_GMSK-only"},
110 { EGPRS, "EGPRS"},
111 { 0, NULL }
112};
113
114const char *mode_name(enum mcs_kind val) {
115 return get_value_string(mode_names, val);
116}