Add helper function to convert enums to string
diff mbox

Message ID 1458745349-4848-1-git-send-email-msuraev@sysmocom.de
State Superseded
Headers show

Commit Message

Max March 23, 2016, 3:02 p.m. UTC
From: Max <msuraev@sysmocom.de>

Add convertors for gsm48_chan_mode and gsm_chan_t types which are useful
for debugging.
---
 include/osmocom/gsm/gsm_utils.h          |  2 ++
 include/osmocom/gsm/protocol/gsm_04_08.h |  2 ++
 src/gsm/gsm48.c                          | 17 +++++++++++++++++
 src/gsm/gsm_utils.c                      | 17 +++++++++++++++++
 src/gsm/libosmogsm.map                   |  2 ++
 5 files changed, 40 insertions(+)

Patch
diff mbox

diff --git a/include/osmocom/gsm/gsm_utils.h b/include/osmocom/gsm/gsm_utils.h
index 6458447..c9c565e 100644
--- a/include/osmocom/gsm/gsm_utils.h
+++ b/include/osmocom/gsm/gsm_utils.h
@@ -199,6 +199,8 @@  enum gsm_chan_t {
 	_GSM_LCHAN_MAX
 };
 
+const char * osmo_gsm48_chan_type2str(enum gsm_chan_t type);
+
 /* Deprectated functions */
 /* Limit encoding and decoding to use no more than this amount of buffer bytes */
 #define GSM_7BIT_LEGACY_MAX_BUFFER_SIZE  0x10000
diff --git a/include/osmocom/gsm/protocol/gsm_04_08.h b/include/osmocom/gsm/protocol/gsm_04_08.h
index d49b77f..78aaef2 100644
--- a/include/osmocom/gsm/protocol/gsm_04_08.h
+++ b/include/osmocom/gsm/protocol/gsm_04_08.h
@@ -347,6 +347,8 @@  enum gsm48_chan_mode {
 	GSM48_CMODE_DATA_3k6	= 0x13,
 };
 
+const char * osmo_gsm48_chan_mode2str(enum gsm48_chan_mode);
+
 /* Chapter 9.1.2 */
 struct gsm48_ass_cmd {
 	/* Semantic is from 10.5.2.5a */
diff --git a/src/gsm/gsm48.c b/src/gsm/gsm48.c
index d0a2286..494c013 100644
--- a/src/gsm/gsm48.c
+++ b/src/gsm/gsm48.c
@@ -197,6 +197,23 @@  static const char *cc_state_names[32] = {
 	"illegal state 31",
 };
 
+static const struct value_string gsm48_chan_modes[] = {
+	{GSM48_CMODE_SIGN,		"SIGNALLING"},
+	{GSM48_CMODE_SPEECH_V1,		"SPEECH_V1"},
+	{GSM48_CMODE_SPEECH_EFR,	"SPEECH_EFR"},
+	{GSM48_CMODE_SPEECH_AMR,	"SPEECH_AMR"},
+	{GSM48_CMODE_DATA_14k5,		"DATA_14k5"},
+	{GSM48_CMODE_DATA_12k0,		"DATA_12k0"},
+	{GSM48_CMODE_DATA_6k0,		"DATA_6k0"},
+	{GSM48_CMODE_DATA_3k6,		"DATA_3k6"},
+	{ 0,				NULL },
+};
+
+const char * osmo_gsm48_chan_mode2str(enum gsm48_chan_mode mode)
+{
+	return get_value_string(gsm48_chan_modes, mode);
+}
+
 const char *gsm48_cc_state_name(uint8_t state)
 {
 	if (state < ARRAY_SIZE(cc_state_names))
diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c
index e8e452f..16a4117 100644
--- a/src/gsm/gsm_utils.c
+++ b/src/gsm/gsm_utils.c
@@ -691,6 +691,23 @@  uint32_t gprs_tmsi2tlli(uint32_t p_tmsi, enum gprs_tlli_type type)
 	return tlli;
 }
 
+static const struct value_string gsm48_chan_types[] = {
+	{ GSM_LCHAN_NONE,	"NONE"},
+	{ GSM_LCHAN_SDCCH,	"SDCCH"},
+	{ GSM_LCHAN_TCH_F,	"TCH_F"},
+	{ GSM_LCHAN_TCH_H,	"TCH_H"},
+	{ GSM_LCHAN_UNKNOWN,	"UNKNOWN"},
+	{ GSM_LCHAN_CCCH,	"CCCH"},
+	{ GSM_LCHAN_PDTCH,	"PDTCH"},
+	{ GSM_LCHAN_CBCH,	"CBCH"},
+	{ 0,			NULL },
+};
+
+const char * osmo_gsm48_chan_type2str(enum gsm_chan_t type)
+{
+	return get_value_string(gsm48_chan_types, type);
+}
+
 /* Wrappers for deprecated functions: */
 
 int gsm_7bit_decode(char *text, const uint8_t *user_data, uint8_t septet_l)
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index a6908a2..411daf2 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -25,6 +25,8 @@  abis_nm_osmo_magic;
 abis_nm_ipa_magic;
 
 osmo_sitype_strs;
+osmo_gsm48_chan_type2str;
+osmo_gsm48_chan_mode2str;
 
 comp128;
 dbm2rxlev;