MCS: use value_string for conversion
Change-Id: I212ebb892ab162821633974d5a6c7e315d308370
diff --git a/src/coding_scheme.c b/src/coding_scheme.c
index a6f2905..93278e7 100644
--- a/src/coding_scheme.c
+++ b/src/coding_scheme.c
@@ -24,6 +24,28 @@
#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;
diff --git a/src/coding_scheme.h b/src/coding_scheme.h
index b0b85e3..1e8ca78 100644
--- a/src/coding_scheme.h
+++ b/src/coding_scheme.h
@@ -19,6 +19,8 @@
#pragma once
+#include <osmocom/core/utils.h>
+
enum CodingScheme {
UNKNOWN,
/* GPRS Coding Schemes: */
@@ -28,6 +30,9 @@
NUM_SCHEMES
};
+extern const struct value_string mcs_names[];
+const char *mcs_name(enum CodingScheme val);
+
enum HeaderType {
HEADER_INVALID,
HEADER_GPRS_CONTROL,
diff --git a/src/decoding.cpp b/src/decoding.cpp
index 3410291..1473ff7 100644
--- a/src/decoding.cpp
+++ b/src/decoding.cpp
@@ -370,7 +370,7 @@
default:
LOGP(DRLCMACDL, LOGL_ERROR,
"Decoding of uplink %s data blocks not yet supported.\n",
- cs.name());
+ mcs_name(cs));
return -ENOTSUP;
};
diff --git a/src/encoding.cpp b/src/encoding.cpp
index 58df95f..ad53b0b 100644
--- a/src/encoding.cpp
+++ b/src/encoding.cpp
@@ -1227,7 +1227,7 @@
default:
LOGP(DRLCMACDL, LOGL_ERROR,
"Encoding of uplink %s data blocks not yet supported.\n",
- cs.name());
+ mcs_name(cs));
return -ENOTSUP;
};
@@ -1616,7 +1616,7 @@
count_payload);
LOGP(DRLCMACDL, LOGL_ERROR, "%s data block encoding not implemented\n",
- cs.name());
+ mcs_name(cs));
return AR_NEED_MORE_BLOCKS;
}
diff --git a/src/gprs_bssgp_pcu.cpp b/src/gprs_bssgp_pcu.cpp
index 7ac5ab1..9d02df6 100644
--- a/src/gprs_bssgp_pcu.cpp
+++ b/src/gprs_bssgp_pcu.cpp
@@ -26,7 +26,11 @@
#include <tbf.h>
#include <gprs_coding_scheme.h>
#include <pdch.h>
-#include "coding_scheme.h"
+
+extern "C" {
+ #include <osmocom/core/utils.h>
+ #include "coding_scheme.h"
+}
#define BSSGP_TIMER_T1 30 /* Guards the (un)blocking procedures */
#define BSSGP_TIMER_T2 30 /* Guards the reset procedure */
@@ -775,7 +779,7 @@
LOGP(DBSSGP, LOGL_DEBUG,
"Computed BVC leak rate = %d, num_pdch = %d, cs = %s\n",
- leak_rate, num_pdch, max_cs_dl.name());
+ leak_rate, num_pdch, mcs_name(max_cs_dl));
};
if (ms_leak_rate == 0) {
@@ -799,7 +803,7 @@
LOGP(DBSSGP, LOGL_DEBUG,
"Computed MS default leak rate = %d, ms_num_pdch = %d, "
"cs = %s\n",
- ms_leak_rate, ms_num_pdch, max_cs_dl.name());
+ ms_leak_rate, ms_num_pdch, mcs_name(max_cs_dl));
};
/* TODO: Force leak_rate to 0 on buffer bloat */
diff --git a/src/gprs_coding_scheme.cpp b/src/gprs_coding_scheme.cpp
index 0616a49..53b3b07 100644
--- a/src/gprs_coding_scheme.cpp
+++ b/src/gprs_coding_scheme.cpp
@@ -81,39 +81,38 @@
} uplink, downlink;
uint8_t data_bytes;
uint8_t optional_padding_bits;
- const char *name;
enum HeaderType data_hdr;
enum Family family;
} mcs_info[NUM_SCHEMES] = {
- {{0, 0}, {0, 0}, 0, 0, "UNKNOWN",
+ {{0, 0}, {0, 0}, 0, 0,
HEADER_INVALID, FAMILY_INVALID},
- {{23, 0}, {23, 0}, 20, 0, "CS-1",
+ {{23, 0}, {23, 0}, 20, 0,
HEADER_GPRS_DATA, FAMILY_INVALID},
- {{33, 7}, {33, 7}, 30, 0, "CS-2",
+ {{33, 7}, {33, 7}, 30, 0,
HEADER_GPRS_DATA, FAMILY_INVALID},
- {{39, 3}, {39, 3}, 36, 0, "CS-3",
+ {{39, 3}, {39, 3}, 36, 0,
HEADER_GPRS_DATA, FAMILY_INVALID},
- {{53, 7}, {53, 7}, 50, 0, "CS-4",
+ {{53, 7}, {53, 7}, 50, 0,
HEADER_GPRS_DATA, FAMILY_INVALID},
- {{26, 1}, {26, 1}, 22, 0, "MCS-1",
+ {{26, 1}, {26, 1}, 22, 0,
HEADER_EGPRS_DATA_TYPE_3, FAMILY_C},
- {{32, 1}, {32, 1}, 28, 0, "MCS-2",
+ {{32, 1}, {32, 1}, 28, 0,
HEADER_EGPRS_DATA_TYPE_3, FAMILY_B},
- {{41, 1}, {41, 1}, 37, 48, "MCS-3",
+ {{41, 1}, {41, 1}, 37, 48,
HEADER_EGPRS_DATA_TYPE_3, FAMILY_A},
- {{48, 1}, {48, 1}, 44, 0, "MCS-4",
+ {{48, 1}, {48, 1}, 44, 0,
HEADER_EGPRS_DATA_TYPE_3, FAMILY_C},
- {{60, 7}, {59, 6}, 56, 0, "MCS-5",
+ {{60, 7}, {59, 6}, 56, 0,
HEADER_EGPRS_DATA_TYPE_2, FAMILY_B},
- {{78, 7}, {77, 6}, 74, 48, "MCS-6",
+ {{78, 7}, {77, 6}, 74, 48,
HEADER_EGPRS_DATA_TYPE_2, FAMILY_A},
- {{118, 2}, {117, 4}, 56, 0, "MCS-7",
+ {{118, 2}, {117, 4}, 56, 0,
HEADER_EGPRS_DATA_TYPE_1, FAMILY_B},
- {{142, 2}, {141, 4}, 68, 0, "MCS-8",
+ {{142, 2}, {141, 4}, 68, 0,
HEADER_EGPRS_DATA_TYPE_1, FAMILY_A},
- {{154, 2}, {153, 4}, 74, 0, "MCS-9",
+ {{154, 2}, {153, 4}, 74, 0,
HEADER_EGPRS_DATA_TYPE_1, FAMILY_A},
};
@@ -194,11 +193,6 @@
return mcs_info[m_scheme].optional_padding_bits;
}
-const char *GprsCodingScheme::name() const
-{
- return mcs_info[m_scheme].name;
-}
-
enum HeaderType GprsCodingScheme::headerTypeData() const
{
return mcs_info[m_scheme].data_hdr;
diff --git a/src/gprs_coding_scheme.h b/src/gprs_coding_scheme.h
index 56ee002..055c166 100644
--- a/src/gprs_coding_scheme.h
+++ b/src/gprs_coding_scheme.h
@@ -74,7 +74,7 @@
uint8_t spareBitsDL() const;
uint8_t maxDataBlockBytes() const;
uint8_t optionalPaddingBits() const;
- const char *name() const;
+
enum HeaderType headerTypeData() const;
static GprsCodingScheme getBySizeUL(unsigned size);
diff --git a/src/gprs_ms.cpp b/src/gprs_ms.cpp
index 77a8f2e..3c28319 100644
--- a/src/gprs_ms.cpp
+++ b/src/gprs_ms.cpp
@@ -34,6 +34,7 @@
#include <osmocom/core/utils.h>
#include <osmocom/gsm/protocol/gsm_04_08.h>
#include <osmocom/core/logging.h>
+ #include "coding_scheme.h"
}
#define GPRS_CODEL_SLOW_INTERVAL_MS 4000
@@ -527,7 +528,7 @@
LOGP(DRLCMACDL, LOGL_INFO,
"MS (IMSI %s): High error rate %d%%, "
"reducing CS level to %s\n",
- imsi(), error_rate, m_current_cs_dl.name());
+ imsi(), error_rate, mcs_name(m_current_cs_dl));
m_last_cs_not_low = now;
}
} else if (error_rate < bts_data->cs_adj_lower_limit) {
@@ -539,7 +540,7 @@
"MS (IMSI %s): Low error rate %d%%, "
"increasing DL CS level to %s\n",
imsi(), error_rate,
- m_current_cs_dl.name());
+ mcs_name(m_current_cs_dl));
m_last_cs_not_low = now;
} else {
LOGP(DRLCMACDL, LOGL_DEBUG,
@@ -627,7 +628,7 @@
if (!max_cs_ul) {
LOGP(DRLCMACMEAS, LOGL_ERROR,
"max_cs_ul cannot be derived (current UL CS: %s)\n",
- m_current_cs_ul.name());
+ mcs_name(m_current_cs_ul));
return;
}
@@ -636,14 +637,14 @@
if (!m_current_cs_ul) {
LOGP(DRLCMACMEAS, LOGL_ERROR,
"Unable to update UL (M)CS because it's not set: %s\n",
- m_current_cs_ul.name());
+ mcs_name(m_current_cs_ul));
return;
}
if (!meas->have_link_qual) {
LOGP(DRLCMACMEAS, LOGL_ERROR,
"Unable to update UL (M)CS %s because we don't have link quality measurements.\n",
- m_current_cs_ul.name());
+ mcs_name(m_current_cs_ul));
return;
}
@@ -662,7 +663,7 @@
} else {
LOGP(DRLCMACMEAS, LOGL_ERROR,
"Unable to update UL (M)CS because it's neither GPRS nor EDGE: %s\n",
- m_current_cs_ul.name());
+ mcs_name(m_current_cs_ul));
return;
}
@@ -682,7 +683,7 @@
"modifying uplink CS level: %s -> %s\n",
imsi(), meas->link_qual, old_link_qual,
low, high,
- m_current_cs_ul.name(), new_cs_ul.name());
+ mcs_name(m_current_cs_ul), mcs_name(new_cs_ul));
m_current_cs_ul = new_cs_ul;
}
diff --git a/src/pcu_vty_functions.cpp b/src/pcu_vty_functions.cpp
index c71959d..47a0559 100644
--- a/src/pcu_vty_functions.cpp
+++ b/src/pcu_vty_functions.cpp
@@ -41,6 +41,7 @@
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/utils.h>
#include <osmocom/vty/vty.h>
+ #include "coding_scheme.h"
}
static void tbf_print_vty_info(struct vty *vty, gprs_rlcmac_tbf *tbf)
@@ -70,7 +71,7 @@
}
if (tbf->trx != NULL)
vty_out(vty, " TRX_ID=%d", tbf->trx->trx_no);
- vty_out(vty, " CS=%s", tbf->current_cs().name());
+ vty_out(vty, " CS=%s", mcs_name(tbf->current_cs()));
if (ul_tbf) {
gprs_rlc_ul_window *win = ul_tbf->window();
@@ -127,8 +128,8 @@
vty_out(vty, "MS TLLI=%08x, TA=%d, CS-UL=%s, CS-DL=%s, LLC=%zd, Cl=%d, E-Cl=%d,"
" TBF-UL=%s, TBF-DL=%s, IMSI=%s%s",
ms->tlli(),
- ms->ta(), ms->current_cs_ul().name(),
- ms->current_cs_dl().name(),
+ ms->ta(), mcs_name(ms->current_cs_ul()),
+ mcs_name(ms->current_cs_dl()),
ms->llc_queue()->size(),
ms->ms_class(),
ms->egprs_ms_class(),
@@ -148,9 +149,9 @@
vty_out(vty, "MS TLLI=%08x, IMSI=%s%s", ms->tlli(), ms->imsi(), VTY_NEWLINE);
vty_out(vty, " Timing advance (TA): %d%s", ms->ta(), VTY_NEWLINE);
- vty_out(vty, " Coding scheme uplink: %s%s", ms->current_cs_ul().name(),
+ vty_out(vty, " Coding scheme uplink: %s%s", mcs_name(ms->current_cs_ul()),
VTY_NEWLINE);
- vty_out(vty, " Coding scheme downlink: %s%s", ms->current_cs_dl().name(),
+ vty_out(vty, " Coding scheme downlink: %s%s", mcs_name(ms->current_cs_dl()),
VTY_NEWLINE);
vty_out(vty, " Mode: %s%s",
GprsCodingScheme::modeName(ms->mode()), VTY_NEWLINE);
diff --git a/src/pdch.cpp b/src/pdch.cpp
index 22a1605..c6c677c 100644
--- a/src/pdch.cpp
+++ b/src/pdch.cpp
@@ -43,6 +43,7 @@
#include <osmocom/core/gsmtap.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/utils.h>
+ #include "coding_scheme.h"
}
#include <errno.h>
@@ -738,7 +739,7 @@
bts()->rlc_ul_bytes(len);
LOGP(DRLCMACUL, LOGL_DEBUG, "Got RLC block, coding scheme: %s, "
- "length: %d (%d))\n", cs.name(), len, cs.usedSizeUL());
+ "length: %d (%d))\n", mcs_name(cs), len, cs.usedSizeUL());
if (cs.isGprs())
return rcv_block_gprs(data, len, fn, meas, cs);
@@ -748,7 +749,7 @@
bts()->decode_error();
LOGP(DRLCMACUL, LOGL_ERROR, "Unsupported coding scheme %s\n",
- cs.name());
+ mcs_name(cs));
return -EINVAL;
}
@@ -768,7 +769,7 @@
if (!bts()->bts_data()->egprs_enabled) {
LOGP(DRLCMACUL, LOGL_ERROR,
"Got %s RLC block but EGPRS is not enabled\n",
- cs.name());
+ mcs_name(cs));
return -EINVAL;
}
bts()->send_gsmtap(PCU_GSMTAP_C_UL_DATA_EGPRS, true, trx_no(), ts_no, GSMTAP_CHANNEL_PDTCH, fn,
@@ -784,7 +785,7 @@
if (rc < 0) {
LOGP(DRLCMACUL, LOGL_ERROR,
"Got %s RLC block but header parsing has failed\n",
- cs.name());
+ mcs_name(cs));
bts()->decode_error();
return rc;
}
@@ -793,7 +794,7 @@
"Got %s RLC block: "
"R=%d, SI=%d, TFI=%d, CPS=%d, RSB=%d, "
"rc=%d\n",
- cs.name(),
+ mcs_name(cs),
rlc_dec.r, rlc_dec.si, rlc_dec.tfi, rlc_dec.cps, rlc_dec.rsb,
rc);
diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index 2f4781c..38dab37 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -46,6 +46,7 @@
#include <osmocom/core/utils.h>
#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/gsm/protocol/gsm_04_08.h>
+ #include "coding_scheme.h"
}
#include <errno.h>
@@ -429,7 +430,7 @@
new_cs = force_cs ? force_cs : current_cs();
LOGPTBFDL(this, LOGL_DEBUG,
"Sending new block at BSN %d, CS=%s\n",
- m_window.v_s(), new_cs.name());
+ m_window.v_s(), mcs_name(new_cs));
bsn = create_new_bsn(fn, new_cs);
} else if (!m_window.window_empty()) {
@@ -443,7 +444,7 @@
/* Nothing left to send, create dummy LLC commands */
LOGPTBFDL(this, LOGL_DEBUG,
"Sending new dummy block at BSN %d, CS=%s\n",
- m_window.v_s(), current_cs().name());
+ m_window.v_s(), mcs_name(current_cs()));
bsn = create_new_bsn(fn, current_cs());
/* Don't send a second block, so don't set cs_current_trans */
}
@@ -624,7 +625,7 @@
} while (ar == Encoding::AR_COMPLETED_SPACE_LEFT);
LOGPTBFDL(this, LOGL_DEBUG, "data block (BSN %d, %s): %s\n",
- bsn, rlc_data->cs_last.name(),
+ bsn, mcs_name(rlc_data->cs_last),
osmo_hexdump(rlc_data->block, block_data_len));
/* raise send state and set ack state array */
m_window.m_v_b.mark_unacked(bsn);
@@ -867,7 +868,7 @@
Encoding::rlc_write_dl_data_header(&rlc, msg_data);
LOGPTBFDL(this, LOGL_DEBUG, "msg block (BSN %d, %s%s): %s\n",
- index, cs.name(),
+ index, mcs_name(cs),
need_padding ? ", padded" : "",
msgb_hexdump(dl_msg));
@@ -1281,7 +1282,7 @@
"FIXME: Software error: hit invalid condition. "
"headerType(%d) blockstatus(%d) cs(%s) PLEASE FIX!\n",
cs_current_trans.headerTypeData(),
- *block_status_dl, cs_init.name());
+ *block_status_dl, mcs_name(cs_init));
break;
}
diff --git a/src/tbf_ul.cpp b/src/tbf_ul.cpp
index bc36733..0bf5765 100644
--- a/src/tbf_ul.cpp
+++ b/src/tbf_ul.cpp
@@ -43,6 +43,7 @@
#include <osmocom/gprs/gprs_bssgp_bss.h>
#include <osmocom/gprs/protocol/gsm_08_18.h>
#include <osmocom/gsm/tlv.h>
+ #include "coding_scheme.h"
}
#include <errno.h>
@@ -212,7 +213,7 @@
LOGPTBFUL(this, LOGL_DEBUG,
"Got %s RLC data block: CV=%d, BSN=%d, SPB=%d, PI=%d, E=%d, TI=%d, bitoffs=%d\n",
- rlc->cs.name(),
+ mcs_name(rlc->cs),
rdbi->cv, rdbi->bsn, rdbi->spb,
rdbi->pi, rdbi->e, rdbi->ti,
rlc->data_offs_bits[block_idx]);
@@ -278,7 +279,7 @@
bts->decode_error();
LOGPTBFUL(this, LOGL_NOTICE,
"Failed to decode TLLI of %s UL DATA TFI=%d.\n",
- rlc->cs.name(), rlc->tfi);
+ mcs_name(rlc->cs), rlc->tfi);
m_window.invalidate_bsn(rdbi->bsn);
continue;
}
@@ -479,7 +480,7 @@
LOGPTBFUL(this, LOGL_DEBUG,
"Got SPB(%d) cs(%s) data block with BSN (%d), TFI(%d).\n",
- rdbi->spb, rlc->cs.name(), rdbi->bsn, rlc->tfi);
+ rdbi->spb, mcs_name(rlc->cs), rdbi->bsn, rlc->tfi);
egprs_rlc_ul_reseg_bsn_state assemble_status = EGPRS_RESEG_INVALID;
@@ -517,7 +518,7 @@
default:
LOGPTBFUL(this, LOGL_ERROR,
"cs(%s) Error in Upgrading to higher MCS\n",
- rlc->cs.name());
+ mcs_name(rlc->cs));
break;
}
}
diff --git a/tests/edge/EdgeTest.cpp b/tests/edge/EdgeTest.cpp
index 23abada..41a1115 100644
--- a/tests/edge/EdgeTest.cpp
+++ b/tests/edge/EdgeTest.cpp
@@ -1118,7 +1118,7 @@
fprintf(stderr,
"Encoded message block, %s, idx %d, "
"pattern %02x: %s\n",
- rlc.cs.name(), block_idx, pattern,
+ mcs_name(rlc.cs), block_idx, pattern,
osmo_hexdump(bits, cs.sizeDL()));
Decoding::rlc_copy_to_aligned_buffer(