aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2019-03-25 16:32:50 +0100
committerMax <msuraev@sysmocom.de>2019-03-26 11:19:30 +0100
commit8a8e0fb2675878c045d9770da0940c7c895b89ec (patch)
treef24bf858ddbc36b3f51ca0270a56b5a4e606e5f0
parentfb3fd093536af6c4f40709b8170bf32cf435fc94 (diff)
MCS: add mcs_is_*() helpers
In preparation for Channel Coding Command encoder in follow-up patches let's add necessary helpers. Those are similar to previously used helpers from GprsCodingScheme class but without CamelCase and with less typo chances between Gprs and Egprs cases. Change-Id: I6699cbc8d7ae766fa4d2b3d37e5f9ff1cf158b7e
-rw-r--r--src/coding_scheme.c18
-rw-r--r--src/coding_scheme.h4
-rw-r--r--src/decoding.cpp4
-rw-r--r--src/encoding.cpp4
-rw-r--r--src/gprs_coding_scheme.cpp8
-rw-r--r--src/gprs_coding_scheme.h16
-rw-r--r--src/gprs_ms.cpp20
-rw-r--r--src/pdch.cpp6
-rw-r--r--src/tbf.cpp4
-rw-r--r--src/tbf_dl.cpp8
-rw-r--r--src/tbf_ul.cpp2
-rw-r--r--tests/edge/EdgeTest.cpp16
12 files changed, 65 insertions, 45 deletions
diff --git a/src/coding_scheme.c b/src/coding_scheme.c
index 135ddd2..4a5d0d4 100644
--- a/src/coding_scheme.c
+++ b/src/coding_scheme.c
@@ -46,6 +46,24 @@ const char *mcs_name(enum CodingScheme val) {
return get_value_string(mcs_names, val);
}
+bool mcs_is_gprs(enum CodingScheme cs)
+{
+ return CS1 <= cs && cs <= CS4;
+}
+
+bool mcs_is_edge(enum CodingScheme cs)
+{
+ return MCS1 <= cs && cs <= MCS9;
+}
+
+bool mcs_is_edge_gmsk(enum CodingScheme cs)
+{
+ if (mcs_is_edge(cs))
+ return cs <= MCS4;
+
+ return false;
+}
+
static struct {
struct {
uint8_t data_header_bits;
diff --git a/src/coding_scheme.h b/src/coding_scheme.h
index f69a76e..3a9ef25 100644
--- a/src/coding_scheme.h
+++ b/src/coding_scheme.h
@@ -33,6 +33,10 @@ enum CodingScheme {
extern const struct value_string mcs_names[];
const char *mcs_name(enum CodingScheme val);
+bool mcs_is_gprs(enum CodingScheme cs);
+bool mcs_is_edge(enum CodingScheme cs);
+bool mcs_is_edge_gmsk(enum CodingScheme cs);
+
enum HeaderType {
HEADER_INVALID,
HEADER_GPRS_CONTROL,
diff --git a/src/decoding.cpp b/src/decoding.cpp
index 1473ff7..d439e30 100644
--- a/src/decoding.cpp
+++ b/src/decoding.cpp
@@ -215,7 +215,7 @@ int Decoding::rlc_data_from_ul_data(
"but no more chunks possible\n");
return -ENOSPC;
}
- } else if (cs.isEgprs()) {
+ } else if (mcs_is_edge(cs)) {
/* if E is not set (LI follows), EGPRS */
num_chunks = parse_extensions_egprs(data, data_len, &offs,
is_last_block,
@@ -240,7 +240,7 @@ int Decoding::rlc_data_from_ul_data(
}
memcpy(&tlli_enc, data + offs, sizeof(tlli_enc));
- if (cs.isGprs())
+ if (mcs_is_gprs(cs))
/* The TLLI is encoded in big endian for GPRS (see
* TS 44.060, figure 10.2.2.1, note) */
*tlli = be32toh(tlli_enc);
diff --git a/src/encoding.cpp b/src/encoding.cpp
index e21a7fc..9920b46 100644
--- a/src/encoding.cpp
+++ b/src/encoding.cpp
@@ -1605,12 +1605,12 @@ Encoding::AppendResult Encoding::rlc_data_to_dl_append(
gprs_llc *llc, int *offset, int *num_chunks,
uint8_t *data_block, bool is_final, int *count_payload)
{
- if (cs.isGprs())
+ if (mcs_is_gprs(cs))
return rlc_data_to_dl_append_gprs(rdbi,
llc, offset, num_chunks, data_block, is_final,
count_payload);
- if (cs.isEgprs())
+ if (mcs_is_edge(cs))
return rlc_data_to_dl_append_egprs(rdbi,
llc, offset, num_chunks, data_block, is_final,
count_payload);
diff --git a/src/gprs_coding_scheme.cpp b/src/gprs_coding_scheme.cpp
index 1a89b77..8e6593b 100644
--- a/src/gprs_coding_scheme.cpp
+++ b/src/gprs_coding_scheme.cpp
@@ -228,10 +228,10 @@ void GprsCodingScheme::dec(enum mcs_kind mode)
void GprsCodingScheme::inc()
{
- if (isGprs() && m_scheme == CS4)
+ if (mcs_is_gprs(m_scheme) && m_scheme == CS4)
return;
- if (isEgprs() && m_scheme == MCS9)
+ if (mcs_is_edge(m_scheme) && m_scheme == MCS9)
return;
if (!isValid())
@@ -242,10 +242,10 @@ void GprsCodingScheme::inc()
void GprsCodingScheme::dec()
{
- if (isGprs() && m_scheme == CS1)
+ if (mcs_is_gprs(m_scheme) && m_scheme == CS1)
return;
- if (isEgprs() && m_scheme == MCS1)
+ if (mcs_is_edge(m_scheme) && m_scheme == MCS1)
return;
if (!isValid())
diff --git a/src/gprs_coding_scheme.h b/src/gprs_coding_scheme.h
index 6f965d6..728ffd6 100644
--- a/src/gprs_coding_scheme.h
+++ b/src/gprs_coding_scheme.h
@@ -45,9 +45,7 @@ public:
GprsCodingScheme& 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(enum mcs_kind mode) const;
bool isCompatible(GprsCodingScheme o) const;
bool isFamilyCompatible(GprsCodingScheme o) const;
@@ -86,10 +84,10 @@ private:
inline uint8_t GprsCodingScheme::to_num() const
{
- if (isGprs())
+ if (mcs_is_gprs(m_scheme))
return (m_scheme - CS1) + 1;
- if (isEgprs())
+ if (mcs_is_edge(m_scheme))
return (m_scheme - MCS1) + 1;
return 0;
@@ -98,9 +96,9 @@ inline uint8_t GprsCodingScheme::to_num() const
inline bool GprsCodingScheme::isCompatible(enum mcs_kind mode) const
{
switch (mode) {
- case GPRS: return isGprs();
- case EGPRS_GMSK: return isEgprsGmsk();
- case EGPRS: return isEgprs();
+ case GPRS: return mcs_is_gprs(m_scheme);
+ case EGPRS_GMSK: return mcs_is_edge_gmsk(m_scheme);
+ case EGPRS: return mcs_is_edge(m_scheme);
}
return false;
@@ -108,7 +106,7 @@ inline bool GprsCodingScheme::isCompatible(enum mcs_kind mode) const
inline bool GprsCodingScheme::isCompatible(GprsCodingScheme o) const
{
- return (isGprs() && o.isGprs()) || (isEgprs() && o.isEgprs());
+ return (mcs_is_gprs(m_scheme) && mcs_is_gprs(o)) || (mcs_is_edge(m_scheme) && mcs_is_edge(o));
}
inline GprsCodingScheme::GprsCodingScheme(CodingScheme s)
diff --git a/src/gprs_ms.cpp b/src/gprs_ms.cpp
index e64bee4..f8f6227 100644
--- a/src/gprs_ms.cpp
+++ b/src/gprs_ms.cpp
@@ -222,13 +222,13 @@ void GprsMs::set_mode(enum mcs_kind mode)
switch (m_mode) {
case GPRS:
- if (!m_current_cs_ul.isGprs()) {
+ if (!mcs_is_gprs(m_current_cs_ul)) {
m_current_cs_ul = GprsCodingScheme::getGprsByNum(
m_bts->bts_data()->initial_cs_ul);
if (!m_current_cs_ul.isValid())
m_current_cs_ul = CS1;
}
- if (!m_current_cs_dl.isGprs()) {
+ if (!mcs_is_gprs(m_current_cs_dl)) {
m_current_cs_dl = GprsCodingScheme::getGprsByNum(
m_bts->bts_data()->initial_cs_dl);
if (!m_current_cs_dl.isValid())
@@ -238,13 +238,13 @@ void GprsMs::set_mode(enum mcs_kind mode)
case EGPRS_GMSK:
case EGPRS:
- if (!m_current_cs_ul.isEgprs()) {
+ if (!mcs_is_edge(m_current_cs_ul)) {
m_current_cs_ul = GprsCodingScheme::getEgprsByNum(
m_bts->bts_data()->initial_mcs_ul);
if (!m_current_cs_ul.isValid())
m_current_cs_ul = MCS1;
}
- if (!m_current_cs_dl.isEgprs()) {
+ if (!mcs_is_edge(m_current_cs_dl)) {
m_current_cs_dl = GprsCodingScheme::getEgprsByNum(
m_bts->bts_data()->initial_mcs_dl);
if (!m_current_cs_dl.isValid())
@@ -564,14 +564,14 @@ GprsCodingScheme GprsMs::max_cs_ul() const
OSMO_ASSERT(m_bts != NULL);
bts_data = m_bts->bts_data();
- if (m_current_cs_ul.isGprs()) {
+ if (mcs_is_gprs(m_current_cs_ul)) {
if (!bts_data->max_cs_ul)
return GprsCodingScheme(CS4);
return GprsCodingScheme::getGprsByNum(bts_data->max_cs_ul);
}
- if (!m_current_cs_ul.isEgprs())
+ if (!mcs_is_edge(m_current_cs_ul))
return GprsCodingScheme(); /* UNKNOWN */
if (bts_data->max_mcs_ul)
@@ -594,14 +594,14 @@ GprsCodingScheme GprsMs::max_cs_dl() const
OSMO_ASSERT(m_bts != NULL);
bts_data = m_bts->bts_data();
- if (m_current_cs_dl.isGprs()) {
+ if (mcs_is_gprs(m_current_cs_dl)) {
if (!bts_data->max_cs_dl)
return GprsCodingScheme(CS4);
return GprsCodingScheme::getGprsByNum(bts_data->max_cs_dl);
}
- if (!m_current_cs_dl.isEgprs())
+ if (!mcs_is_edge(m_current_cs_dl))
return GprsCodingScheme(); /* UNKNOWN */
if (bts_data->max_mcs_dl)
@@ -650,12 +650,12 @@ void GprsMs::update_cs_ul(const pcu_l1_meas *meas)
old_link_qual = meas->link_qual;
- if (m_current_cs_ul.isGprs()) {
+ if (mcs_is_gprs(m_current_cs_ul)) {
if (current_cs_num > MAX_GPRS_CS)
current_cs_num = MAX_GPRS_CS;
low = bts_data->cs_lqual_ranges[current_cs_num-1].low;
high = bts_data->cs_lqual_ranges[current_cs_num-1].high;
- } else if (m_current_cs_ul.isEgprs()) {
+ } else if (mcs_is_edge(m_current_cs_ul)) {
if (current_cs_num > MAX_EDGE_MCS)
current_cs_num = MAX_EDGE_MCS;
low = bts_data->mcs_lqual_ranges[current_cs_num-1].low;
diff --git a/src/pdch.cpp b/src/pdch.cpp
index c6c677c..8003105 100644
--- a/src/pdch.cpp
+++ b/src/pdch.cpp
@@ -741,10 +741,10 @@ int gprs_rlcmac_pdch::rcv_block(uint8_t *data, uint8_t len, uint32_t fn,
LOGP(DRLCMACUL, LOGL_DEBUG, "Got RLC block, coding scheme: %s, "
"length: %d (%d))\n", mcs_name(cs), len, cs.usedSizeUL());
- if (cs.isGprs())
+ if (mcs_is_gprs(cs))
return rcv_block_gprs(data, len, fn, meas, cs);
- if (cs.isEgprs())
+ if (mcs_is_edge(cs))
return rcv_data_block(data, len, fn, meas, cs);
bts()->decode_error();
@@ -765,7 +765,7 @@ int gprs_rlcmac_pdch::rcv_data_block(uint8_t *data, uint8_t data_len, uint32_t f
/* These are always data blocks, since EGPRS still uses CS-1 for
* control blocks (see 44.060, section 10.3, 1st par.)
*/
- if (cs.isEgprs()) {
+ if (mcs_is_edge(cs)) {
if (!bts()->bts_data()->egprs_enabled) {
LOGP(DRLCMACUL, LOGL_ERROR,
"Got %s RLC block but EGPRS is not enabled\n",
diff --git a/src/tbf.cpp b/src/tbf.cpp
index 3d9b5c4..dc90dbb 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -952,8 +952,8 @@ static int ul_tbf_dtor(struct gprs_rlcmac_ul_tbf *tbf)
static void setup_egprs_mode(gprs_rlcmac_bts *bts, GprsMs *ms)
{
- if (GprsCodingScheme::getEgprsByNum(bts->max_mcs_ul).isEgprsGmsk() &&
- GprsCodingScheme::getEgprsByNum(bts->max_mcs_dl).isEgprsGmsk() &&
+ if (mcs_is_edge_gmsk(GprsCodingScheme::getEgprsByNum(bts->max_mcs_ul)) &&
+ mcs_is_edge_gmsk(GprsCodingScheme::getEgprsByNum(bts->max_mcs_dl)) &&
ms->mode() != EGPRS)
{
ms->set_mode(EGPRS_GMSK);
diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index c276b3a..13ef143 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -363,7 +363,7 @@ int gprs_rlcmac_dl_tbf::take_next_bsn(uint32_t fn,
if (previous_bsn >= 0) {
force_cs = m_rlc.block(previous_bsn)->cs_current_trans;
- if (!force_cs.isEgprs())
+ if (!mcs_is_edge(force_cs))
return -1;
force_data_len = m_rlc.block(previous_bsn)->len;
}
@@ -765,7 +765,7 @@ struct msgb *gprs_rlcmac_dl_tbf::create_dl_acked_block(
m_rlc.block(bsn)->next_ps,
m_rlc.block(bsn)->cs_last, cs, spb);
- if (cs.isEgprs()) {
+ if (mcs_is_edge(cs)) {
OSMO_ASSERT(m_rlc.block(bsn)->next_ps >= EGPRS_PS_1);
OSMO_ASSERT(m_rlc.block(bsn)->next_ps <= EGPRS_PS_3);
}
@@ -812,7 +812,7 @@ struct msgb *gprs_rlcmac_dl_tbf::create_dl_acked_block(
}
/* Calculate CPS only for EGPRS case */
- if (cs.isEgprs())
+ if (mcs_is_edge(cs))
rlc.cps = gprs_rlc_mcs_cps(cs, punct[0], punct[1], need_padding);
/* If the TBF has just started, relate frames_since_last_poll to the
@@ -1369,7 +1369,7 @@ void gprs_rlcmac_dl_tbf::update_coding_scheme_counter_dl(const GprsCodingScheme
uint8_t coding_scheme = 0;
coding_scheme = CodingScheme(cs);
- if (cs.isGprs()) {
+ if (mcs_is_gprs(cs)) {
switch (coding_scheme) {
case CS1 :
bts->gprs_dl_cs1();
diff --git a/src/tbf_ul.cpp b/src/tbf_ul.cpp
index 0bf5765..f40ec3d 100644
--- a/src/tbf_ul.cpp
+++ b/src/tbf_ul.cpp
@@ -530,7 +530,7 @@ void gprs_rlcmac_ul_tbf::update_coding_scheme_counter_ul(const GprsCodingScheme
uint8_t coding_scheme = 0;
coding_scheme = CodingScheme(cs);
- if (cs.isGprs()) {
+ if (mcs_is_gprs(cs)) {
switch (coding_scheme) {
case CS1 :
bts->gprs_ul_cs1();
diff --git a/tests/edge/EdgeTest.cpp b/tests/edge/EdgeTest.cpp
index b902806..f124b76 100644
--- a/tests/edge/EdgeTest.cpp
+++ b/tests/edge/EdgeTest.cpp
@@ -59,14 +59,14 @@ static void check_coding_scheme(GprsCodingScheme& cs, enum mcs_kind mode)
/* Check static getBySizeUL() */
expected_size = cs.usedSizeUL();
- if (cs.spareBitsUL() > 0 && cs.isGprs())
+ if (cs.spareBitsUL() > 0 && mcs_is_gprs(cs))
expected_size += 1;
OSMO_ASSERT(expected_size == cs.sizeUL());
OSMO_ASSERT(cs == GprsCodingScheme::getBySizeUL(expected_size));
/* Check static sizeUL() */
expected_size = cs.usedSizeDL();
- if (cs.spareBitsDL() > 0 && cs.isGprs())
+ if (cs.spareBitsDL() > 0 && mcs_is_gprs(cs))
expected_size += 1;
OSMO_ASSERT(expected_size == cs.sizeDL());
@@ -157,9 +157,9 @@ static void test_coding_scheme()
for (i = 0; i < ARRAY_SIZE(gprs_schemes); i++) {
GprsCodingScheme current_cs(gprs_schemes[i]);
- OSMO_ASSERT(current_cs.isGprs());
- OSMO_ASSERT(!current_cs.isEgprs());
- OSMO_ASSERT(!current_cs.isEgprsGmsk());
+ OSMO_ASSERT(mcs_is_gprs(current_cs));
+ OSMO_ASSERT(!mcs_is_edge(current_cs));
+ OSMO_ASSERT(!mcs_is_edge_gmsk(current_cs));
OSMO_ASSERT(CodingScheme(current_cs) == gprs_schemes[i]);
OSMO_ASSERT(current_cs == GprsCodingScheme(gprs_schemes[i]));
@@ -179,9 +179,9 @@ static void test_coding_scheme()
for (i = 0; i < ARRAY_SIZE(egprs_schemes); i++) {
GprsCodingScheme current_cs(egprs_schemes[i].s);
- OSMO_ASSERT(!current_cs.isGprs());
- OSMO_ASSERT(current_cs.isEgprs());
- OSMO_ASSERT(!!current_cs.isEgprsGmsk() == !!egprs_schemes[i].is_gmsk);
+ OSMO_ASSERT(!mcs_is_gprs(current_cs));
+ OSMO_ASSERT(mcs_is_edge(current_cs));
+ OSMO_ASSERT(mcs_is_edge_gmsk(current_cs) == !!egprs_schemes[i].is_gmsk);
OSMO_ASSERT(CodingScheme(current_cs) == egprs_schemes[i].s);
OSMO_ASSERT(current_cs == GprsCodingScheme(egprs_schemes[i].s));