blob: 3488b320c81ed86900f9aa85c15ebbb46cfa58ae [file] [log] [blame]
Jacob Erlbeck409f9802015-11-30 18:06:50 +01001/* gprs_coding_scheme.cpp
2 *
3 * Copyright (C) 2015 by Sysmocom s.f.m.c. GmbH
4 * Author: Jacob Erlbeck <jerlbeck@sysmocom.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21
22#include "gprs_coding_scheme.h"
23
24static struct {
25 struct {
26 unsigned bytes;
27 unsigned ext_bits;
28 } uplink, downlink;
29 const char *name;
30} mcs_info[GprsCodingScheme::NUM_SCHEMES] = {
31 {{0, 0}, {0, 0}, "UNKNOWN"},
32 {{23, 0}, {23, 0}, "CS-1"},
33 {{33, 7}, {33, 7}, "CS-2"},
34 {{39, 3}, {39, 3}, "CS-3"},
35 {{53, 7}, {53, 7}, "CS-4"},
36
37 {{26, 1}, {26, 1}, "MCS-1"},
38 {{32, 1}, {32, 1}, "MCS-2"},
39 {{41, 1}, {41, 1}, "MCS-3"},
40 {{48, 1}, {48, 1}, "MCS-4"},
41
42 {{60, 7}, {59, 6}, "MCS-5"},
43 {{78, 7}, {77, 6}, "MCS-6"},
44 {{118, 2}, {117, 4}, "MCS-7"},
45 {{142, 2}, {141, 4}, "MCS-8"},
46 {{154, 2}, {153, 4}, "MCS-9"},
47};
48
49
50GprsCodingScheme GprsCodingScheme::getBySizeUL(unsigned size)
51{
52 switch (size) {
53 case 23: return GprsCodingScheme(CS1);
54 case 27: return GprsCodingScheme(MCS1);
55 case 33: return GprsCodingScheme(MCS2);
56 case 34: return GprsCodingScheme(CS2);
57 case 40: return GprsCodingScheme(CS3);
58 case 42: return GprsCodingScheme(MCS3);
59 case 49: return GprsCodingScheme(MCS4);
60 case 54: return GprsCodingScheme(CS4);
61 case 61: return GprsCodingScheme(MCS5);
62 case 79: return GprsCodingScheme(MCS6);
63 case 119: return GprsCodingScheme(MCS7);
64 case 143: return GprsCodingScheme(MCS8);
65 case 155: return GprsCodingScheme(MCS9);
66 }
67
68 return GprsCodingScheme(UNKNOWN);
69}
70
71unsigned int GprsCodingScheme::sizeUL() const
72{
73 return maxBytesUL() + (spareBitsUL() ? 1 : 0);
74}
75
76unsigned int GprsCodingScheme::maxBytesUL() const
77{
78 return mcs_info[m_scheme].uplink.bytes;
79}
80
81unsigned int GprsCodingScheme::spareBitsUL() const
82{
83 return mcs_info[m_scheme].uplink.ext_bits;
84}
85
86unsigned int GprsCodingScheme::sizeDL() const
87{
88 return maxBytesDL() + (spareBitsDL() ? 1 : 0);
89}
90
91unsigned int GprsCodingScheme::maxBytesDL() const
92{
93 return mcs_info[m_scheme].downlink.bytes;
94}
95
96unsigned int GprsCodingScheme::spareBitsDL() const
97{
98 return mcs_info[m_scheme].downlink.ext_bits;
99}
100
101const char *GprsCodingScheme::name() const
102{
103 return mcs_info[m_scheme].name;
104}