aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2015-11-30 18:06:50 +0100
committerJacob Erlbeck <jerlbeck@sysmocom.de>2015-12-15 15:19:42 +0100
commit409f980a180ad8977717cbb5ec412990a0ecbfb0 (patch)
tree2643bda3ef63f9e7787a0845f75a80ac4b292c55
parent14e00f8f66faf0c1f551d1d5e4527c51177d6dc8 (diff)
edge: Add GprsCodingScheme class
Currently the coding scheme is checked and compared at different places which makes in cumbersome to extend it for EGPRS. This class encapsules the coding scheme and provides required meta information like sizes as well as helper methods. Sponsored-by: On-Waves ehf
-rw-r--r--src/Makefile.am6
-rw-r--r--src/gprs_coding_scheme.cpp104
-rw-r--r--src/gprs_coding_scheme.h129
3 files changed, 237 insertions, 2 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 1217075..6428bef 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -56,7 +56,8 @@ libgprs_la_SOURCES = \
llc.cpp \
rlc.cpp \
osmobts_sock.cpp \
- gprs_codel.c
+ gprs_codel.c \
+ gprs_coding_scheme.cpp
bin_PROGRAMS = \
osmo-pcu
@@ -94,7 +95,8 @@ noinst_HEADERS = \
llc.h \
pcu_utils.h \
cxx_linuxlist.h \
- gprs_codel.h
+ gprs_codel.h \
+ gprs_coding_scheme.h
osmo_pcu_SOURCES = pcu_main.cpp
diff --git a/src/gprs_coding_scheme.cpp b/src/gprs_coding_scheme.cpp
new file mode 100644
index 0000000..3488b32
--- /dev/null
+++ b/src/gprs_coding_scheme.cpp
@@ -0,0 +1,104 @@
+/* gprs_coding_scheme.cpp
+ *
+ * Copyright (C) 2015 by Sysmocom s.f.m.c. GmbH
+ * Author: Jacob Erlbeck <jerlbeck@sysmocom.de>
+ *
+ * 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 "gprs_coding_scheme.h"
+
+static struct {
+ struct {
+ unsigned bytes;
+ unsigned ext_bits;
+ } uplink, downlink;
+ const char *name;
+} mcs_info[GprsCodingScheme::NUM_SCHEMES] = {
+ {{0, 0}, {0, 0}, "UNKNOWN"},
+ {{23, 0}, {23, 0}, "CS-1"},
+ {{33, 7}, {33, 7}, "CS-2"},
+ {{39, 3}, {39, 3}, "CS-3"},
+ {{53, 7}, {53, 7}, "CS-4"},
+
+ {{26, 1}, {26, 1}, "MCS-1"},
+ {{32, 1}, {32, 1}, "MCS-2"},
+ {{41, 1}, {41, 1}, "MCS-3"},
+ {{48, 1}, {48, 1}, "MCS-4"},
+
+ {{60, 7}, {59, 6}, "MCS-5"},
+ {{78, 7}, {77, 6}, "MCS-6"},
+ {{118, 2}, {117, 4}, "MCS-7"},
+ {{142, 2}, {141, 4}, "MCS-8"},
+ {{154, 2}, {153, 4}, "MCS-9"},
+};
+
+
+GprsCodingScheme GprsCodingScheme::getBySizeUL(unsigned size)
+{
+ switch (size) {
+ case 23: return GprsCodingScheme(CS1);
+ case 27: return GprsCodingScheme(MCS1);
+ case 33: return GprsCodingScheme(MCS2);
+ case 34: return GprsCodingScheme(CS2);
+ case 40: return GprsCodingScheme(CS3);
+ case 42: return GprsCodingScheme(MCS3);
+ case 49: return GprsCodingScheme(MCS4);
+ case 54: return GprsCodingScheme(CS4);
+ case 61: return GprsCodingScheme(MCS5);
+ case 79: return GprsCodingScheme(MCS6);
+ case 119: return GprsCodingScheme(MCS7);
+ case 143: return GprsCodingScheme(MCS8);
+ case 155: return GprsCodingScheme(MCS9);
+ }
+
+ return GprsCodingScheme(UNKNOWN);
+}
+
+unsigned int GprsCodingScheme::sizeUL() const
+{
+ return maxBytesUL() + (spareBitsUL() ? 1 : 0);
+}
+
+unsigned int GprsCodingScheme::maxBytesUL() const
+{
+ return mcs_info[m_scheme].uplink.bytes;
+}
+
+unsigned int GprsCodingScheme::spareBitsUL() const
+{
+ return mcs_info[m_scheme].uplink.ext_bits;
+}
+
+unsigned int GprsCodingScheme::sizeDL() const
+{
+ return maxBytesDL() + (spareBitsDL() ? 1 : 0);
+}
+
+unsigned int GprsCodingScheme::maxBytesDL() const
+{
+ return mcs_info[m_scheme].downlink.bytes;
+}
+
+unsigned int GprsCodingScheme::spareBitsDL() const
+{
+ return mcs_info[m_scheme].downlink.ext_bits;
+}
+
+const char *GprsCodingScheme::name() const
+{
+ return mcs_info[m_scheme].name;
+}
diff --git a/src/gprs_coding_scheme.h b/src/gprs_coding_scheme.h
new file mode 100644
index 0000000..71b64cf
--- /dev/null
+++ b/src/gprs_coding_scheme.h
@@ -0,0 +1,129 @@
+/* gprs_coding_scheme.h
+ *
+ * Copyright (C) 2015 by Sysmocom s.f.m.c. GmbH
+ * Author: Jacob Erlbeck <jerlbeck@sysmocom.de>
+ *
+ * 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.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <stddef.h>
+
+
+class GprsCodingScheme {
+public:
+ enum Scheme {
+ UNKNOWN,
+ CS1, CS2, CS3, CS4,
+ MCS1, MCS2, MCS3, MCS4,
+ MCS5, MCS6, MCS7, MCS8, MCS9,
+ NUM_SCHEMES
+ };
+
+ enum Mode {
+ GPRS,
+ EGPRS_GMSK,
+ EGPRS,
+ };
+
+ GprsCodingScheme(Scheme s = UNKNOWN);
+
+ operator bool() const {return m_scheme != UNKNOWN;}
+ operator int() const {return (int)m_scheme;}
+ void operator =(Scheme s);
+ void operator =(GprsCodingScheme o);
+ bool isValid() const {return UNKNOWN <= m_scheme && m_scheme <= MCS9;}
+ bool isGprs() const {return CS1 <= m_scheme && m_scheme <= CS4;}
+ bool isEgprs() const {return m_scheme >= MCS1;}
+ bool isEgprsGmsk() const {return isEgprs() && m_scheme <= MCS4;}
+ bool isCompatible(Mode mode) const;
+
+ void inc(Mode mode);
+ void dec(Mode mode);
+
+ unsigned int sizeUL() const;
+ unsigned int sizeDL() const;
+ unsigned int maxBytesUL() const;
+ unsigned int maxBytesDL() const;
+ unsigned int spareBitsUL() const;
+ unsigned int spareBitsDL() const;
+ const char *name() const;
+
+ static GprsCodingScheme getBySizeUL(unsigned size);
+
+private:
+ enum Scheme m_scheme;
+};
+
+inline bool GprsCodingScheme::isCompatible(Mode mode) const
+{
+ switch (mode) {
+ case GPRS: return isGprs();
+ case EGPRS_GMSK: return isEgprsGmsk();
+ case EGPRS: return isEgprs();
+ }
+
+ return false;
+}
+
+inline void GprsCodingScheme::inc(Mode mode)
+{
+ if (!isCompatible(mode))
+ /* This should not happen. TODO: Use assert? */
+ return;
+
+ Scheme new_cs(Scheme(m_scheme + 1));
+ if (!GprsCodingScheme(new_cs).isCompatible(mode))
+ /* Clipping, do not change the value */
+ return;
+
+ m_scheme = new_cs;
+}
+
+inline void GprsCodingScheme::dec(Mode mode)
+{
+ if (!isCompatible(mode))
+ /* This should not happen. TODO: Use assert? */
+ return;
+
+ Scheme new_cs(Scheme(m_scheme - 1));
+ if (!GprsCodingScheme(new_cs).isCompatible(mode))
+ /* Clipping, do not change the value */
+ return;
+
+ m_scheme = new_cs;
+}
+
+inline GprsCodingScheme::GprsCodingScheme(Scheme s)
+ : m_scheme(s)
+{
+ if (!isValid())
+ m_scheme = UNKNOWN;
+}
+
+inline void GprsCodingScheme::operator =(Scheme s)
+{
+ m_scheme = s;
+
+ if (!isValid())
+ m_scheme = UNKNOWN;
+}
+
+inline void GprsCodingScheme::operator =(GprsCodingScheme o)
+{
+ m_scheme = o.m_scheme;
+}