aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2016-02-03 15:25:04 +0100
committerJacob Erlbeck <jerlbeck@sysmocom.de>2016-02-03 16:59:38 +0100
commitfba39469aa4611b37394ddf9857402cd528e41fc (patch)
tree3e52abbfc0cb5162b8d5bb859ef5815825693f41
parent03defcf3dc8ae0d6ada8b3fd3edd025cbe9ef1d6 (diff)
cs: Add family related methods
Add family handling and the related methods family, isFamilyCompatible, isCombinable, decToSingleBlock to GprsCodingScheme. Sponsored-by: On-Waves ehf
-rw-r--r--src/gprs_coding_scheme.cpp78
-rw-r--r--src/gprs_coding_scheme.h11
-rw-r--r--tests/edge/EdgeTest.cpp13
3 files changed, 86 insertions, 16 deletions
diff --git a/src/gprs_coding_scheme.cpp b/src/gprs_coding_scheme.cpp
index aaa8b20..4f1db1d 100644
--- a/src/gprs_coding_scheme.cpp
+++ b/src/gprs_coding_scheme.cpp
@@ -30,23 +30,38 @@ static struct {
unsigned int data_bytes;
const char *name;
GprsCodingScheme::HeaderType data_hdr;
+ GprsCodingScheme::Family family;
} mcs_info[GprsCodingScheme::NUM_SCHEMES] = {
- {{0, 0}, {0, 0}, 0, "UNKNOWN", GprsCodingScheme::HEADER_INVALID},
- {{23, 0}, {23, 0}, 20, "CS-1", GprsCodingScheme::HEADER_GPRS_DATA},
- {{33, 7}, {33, 7}, 30, "CS-2", GprsCodingScheme::HEADER_GPRS_DATA},
- {{39, 3}, {39, 3}, 36, "CS-3", GprsCodingScheme::HEADER_GPRS_DATA},
- {{53, 7}, {53, 7}, 50, "CS-4", GprsCodingScheme::HEADER_GPRS_DATA},
-
- {{26, 1}, {26, 1}, 22, "MCS-1", GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_3},
- {{32, 1}, {32, 1}, 28, "MCS-2", GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_3},
- {{41, 1}, {41, 1}, 37, "MCS-3", GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_3},
- {{48, 1}, {48, 1}, 44, "MCS-4", GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_3},
-
- {{60, 7}, {59, 6}, 56, "MCS-5", GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_2},
- {{78, 7}, {77, 6}, 74, "MCS-6", GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_2},
- {{118, 2}, {117, 4}, 56, "MCS-7", GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_1},
- {{142, 2}, {141, 4}, 68, "MCS-8", GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_1},
- {{154, 2}, {153, 4}, 74, "MCS-9", GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_1},
+ {{0, 0}, {0, 0}, 0, "UNKNOWN",
+ GprsCodingScheme::HEADER_INVALID, GprsCodingScheme::FAMILY_INVALID},
+ {{23, 0}, {23, 0}, 20, "CS-1",
+ GprsCodingScheme::HEADER_GPRS_DATA, GprsCodingScheme::FAMILY_INVALID},
+ {{33, 7}, {33, 7}, 30, "CS-2",
+ GprsCodingScheme::HEADER_GPRS_DATA, GprsCodingScheme::FAMILY_INVALID},
+ {{39, 3}, {39, 3}, 36, "CS-3",
+ GprsCodingScheme::HEADER_GPRS_DATA, GprsCodingScheme::FAMILY_INVALID},
+ {{53, 7}, {53, 7}, 50, "CS-4",
+ GprsCodingScheme::HEADER_GPRS_DATA, GprsCodingScheme::FAMILY_INVALID},
+
+ {{26, 1}, {26, 1}, 22, "MCS-1",
+ GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_3, GprsCodingScheme::FAMILY_C},
+ {{32, 1}, {32, 1}, 28, "MCS-2",
+ GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_3, GprsCodingScheme::FAMILY_B},
+ {{41, 1}, {41, 1}, 37, "MCS-3",
+ GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_3, GprsCodingScheme::FAMILY_A},
+ {{48, 1}, {48, 1}, 44, "MCS-4",
+ GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_3, GprsCodingScheme::FAMILY_C},
+
+ {{60, 7}, {59, 6}, 56, "MCS-5",
+ GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_2, GprsCodingScheme::FAMILY_B},
+ {{78, 7}, {77, 6}, 74, "MCS-6",
+ GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_2, GprsCodingScheme::FAMILY_A},
+ {{118, 2}, {117, 4}, 56, "MCS-7",
+ GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_1, GprsCodingScheme::FAMILY_B},
+ {{142, 2}, {141, 4}, 68, "MCS-8",
+ GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_1, GprsCodingScheme::FAMILY_A},
+ {{154, 2}, {153, 4}, 74, "MCS-9",
+ GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_1, GprsCodingScheme::FAMILY_A},
};
static struct {
@@ -167,6 +182,11 @@ GprsCodingScheme::HeaderType GprsCodingScheme::headerTypeData() const
return mcs_info[m_scheme].data_hdr;
}
+GprsCodingScheme::Family GprsCodingScheme::family() const
+{
+ return mcs_info[m_scheme].family;
+}
+
void GprsCodingScheme::inc(Mode mode)
{
if (!isCompatible(mode))
@@ -232,3 +252,29 @@ const char *GprsCodingScheme::modeName(Mode mode)
default: return "???";
}
}
+
+bool GprsCodingScheme::isFamilyCompatible(GprsCodingScheme o) const
+{
+ if (*this == o)
+ return true;
+
+ if (family() == FAMILY_INVALID)
+ return false;
+
+ return family() == o.family();
+}
+
+bool GprsCodingScheme::isCombinable(GprsCodingScheme o) const
+{
+ return numDataBlocks() == o.numDataBlocks();
+}
+
+void GprsCodingScheme::decToSingleBlock(bool *needStuffing)
+{
+ switch (m_scheme) {
+ case MCS7: *needStuffing = false; m_scheme = MCS5; break;
+ case MCS8: *needStuffing = true; m_scheme = MCS6; break;
+ case MCS9: *needStuffing = false; m_scheme = MCS6; break;
+ default: *needStuffing = false; break;
+ }
+}
diff --git a/src/gprs_coding_scheme.h b/src/gprs_coding_scheme.h
index 348aefb..e9a06a5 100644
--- a/src/gprs_coding_scheme.h
+++ b/src/gprs_coding_scheme.h
@@ -50,6 +50,13 @@ public:
NUM_HEADER_TYPES
};
+ enum Family {
+ FAMILY_INVALID,
+ FAMILY_A,
+ FAMILY_B,
+ FAMILY_C,
+ };
+
GprsCodingScheme(Scheme s = UNKNOWN);
operator bool() const {return m_scheme != UNKNOWN;}
@@ -65,11 +72,14 @@ public:
bool isEgprsGmsk() const {return isEgprs() && m_scheme <= MCS4;}
bool isCompatible(Mode mode) const;
bool isCompatible(GprsCodingScheme o) const;
+ bool isFamilyCompatible(GprsCodingScheme o) const;
+ bool isCombinable(GprsCodingScheme o) const;
void inc(Mode mode);
void dec(Mode mode);
void inc();
void dec();
+ void decToSingleBlock(bool *needStuffing);
unsigned int sizeUL() const;
unsigned int sizeDL() const;
@@ -87,6 +97,7 @@ public:
const char *name() const;
HeaderType headerTypeData() const;
HeaderType headerTypeControl() const;
+ Family family() const;
static GprsCodingScheme getBySizeUL(unsigned size);
static GprsCodingScheme getGprsByNum(unsigned num);
diff --git a/tests/edge/EdgeTest.cpp b/tests/edge/EdgeTest.cpp
index 5b64701..341567e 100644
--- a/tests/edge/EdgeTest.cpp
+++ b/tests/edge/EdgeTest.cpp
@@ -46,6 +46,7 @@ int16_t spoof_mnc = 0, spoof_mcc = 0;
static void check_coding_scheme(GprsCodingScheme& cs, GprsCodingScheme::Mode mode)
{
volatile unsigned expected_size;
+ bool need_padding;
GprsCodingScheme new_cs;
OSMO_ASSERT(cs.isValid());
@@ -84,6 +85,18 @@ static void check_coding_scheme(GprsCodingScheme& cs, GprsCodingScheme::Mode mod
OSMO_ASSERT(new_cs.isCompatible(mode));
OSMO_ASSERT(new_cs == cs);
}
+
+ new_cs = cs;
+ new_cs.decToSingleBlock(&need_padding);
+ OSMO_ASSERT(new_cs.isFamilyCompatible(cs));
+ OSMO_ASSERT(cs.isFamilyCompatible(new_cs));
+ OSMO_ASSERT(cs.isCompatible(new_cs));
+ if (need_padding) {
+ OSMO_ASSERT(new_cs.maxDataBlockBytes() > cs.maxDataBlockBytes());
+ } else {
+ OSMO_ASSERT(new_cs.maxDataBlockBytes() == cs.maxDataBlockBytes());
+ }
+
}
static void test_coding_scheme()