aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding_scheme.c
blob: 93278e7efd5c34554abe230c37fb651e6e8357f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* coding_scheme.c
 *
 * Copyright (C) 2019 by sysmocom s.f.m.c. GmbH
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#include <stdint.h>
#include <stdbool.h>

#include <osmocom/core/utils.h>

#include "coding_scheme.h"

const struct value_string mcs_names[] = {
	{ UNKNOWN, "UNKNOWN" },
	{ CS1, "CS-1" },
	{ CS2, "CS-2" },
	{ CS3, "CS-3" },
	{ CS4, "CS-4" },
	{ MCS1, "MCS-1" },
	{ MCS2, "MCS-2" },
	{ MCS3, "MCS-3" },
	{ MCS4, "MCS-4" },
	{ MCS5, "MCS-5" },
	{ MCS6, "MCS-6" },
	{ MCS7, "MCS-7" },
	{ MCS8, "MCS-8" },
	{ MCS9, "MCS-9" },
	{ 0, NULL }
};

const char *mcs_name(enum CodingScheme val) {
	return get_value_string(mcs_names, val);
}

static struct {
	struct {
		uint8_t data_header_bits;
	} uplink, downlink;
	uint8_t data_block_header_bits;
	uint8_t num_blocks;
	const char *name;
} hdr_type_info[NUM_HEADER_TYPES] = {
	{ { 0 },         { 0 },         0, 0, "INVALID" },
	{ { 1 * 8 + 0 }, { 1 * 8 + 0 }, 0, 0, "CONTROL" },
	{ { 3 * 8 + 0 }, { 3 * 8 + 0 }, 0, 1, "GPRS_DATA" },
	{ { 5 * 8 + 6 }, { 5 * 8 + 0 }, 2, 2, "EGPRS_DATA_TYPE1" },
	{ { 4 * 8 + 5 }, { 3 * 8 + 4 }, 2, 1, "EGPRS_DATA_TYPE2" },
	{ { 3 * 8 + 7 }, { 3 * 8 + 7 }, 2, 1, "EGPRS_DATA_TYPE3" },
};

uint8_t num_data_blocks(enum HeaderType ht)
{
	OSMO_ASSERT(ht < NUM_HEADER_TYPES);
	return hdr_type_info[ht].num_blocks;
}

uint8_t num_data_header_bits_UL(enum HeaderType ht)
{
	OSMO_ASSERT(ht < NUM_HEADER_TYPES);
	return hdr_type_info[ht].uplink.data_header_bits;
}

uint8_t num_data_header_bits_DL(enum HeaderType ht)
{
	OSMO_ASSERT(ht < NUM_HEADER_TYPES);
	return hdr_type_info[ht].downlink.data_header_bits;
}

uint8_t num_data_block_header_bits(enum HeaderType ht)
{
	OSMO_ASSERT(ht < NUM_HEADER_TYPES);
	return hdr_type_info[ht].data_block_header_bits;
}