aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-03-04 10:39:17 +0100
committerHarald Welte <laforge@gnumonks.org>2010-03-04 10:39:17 +0100
commitaebe08c71f4704914c2af40620d0675cf29d2639 (patch)
treeda24ef3b2468305a8a35a40b3047c56d103606f4
parenteb8bf3915cb4733e4e4357252893686f0d9d9d72 (diff)
import gsm_band_name() and gsm_band_parse() from OpenBSC
-rw-r--r--include/osmocore/gsm_utils.h5
-rw-r--r--src/gsm_utils.c55
2 files changed, 59 insertions, 1 deletions
diff --git a/include/osmocore/gsm_utils.h b/include/osmocore/gsm_utils.h
index 57521ac7..b611050d 100644
--- a/include/osmocore/gsm_utils.h
+++ b/include/osmocore/gsm_utils.h
@@ -2,7 +2,7 @@
/*
* (C) 2008 by Daniel Willmann <daniel@totalueberwachung.de>
* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
- * (C) 2009 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
*
* All Rights Reserved
*
@@ -38,6 +38,9 @@ enum gsm_band {
GSM_BAND_810 = 0x80,
};
+char *gsm_band_name(enum gsm_band band);
+enum gsm_band gsm_band_parse(const char *mhz);
+
int gsm_7bit_decode(char *decoded, const uint8_t *user_data, uint8_t length);
int gsm_7bit_encode(uint8_t *result, const char *data);
diff --git a/src/gsm_utils.c b/src/gsm_utils.c
index b0a66a68..174b2d49 100644
--- a/src/gsm_utils.c
+++ b/src/gsm_utils.c
@@ -30,6 +30,7 @@
#include <string.h>
#include <stdio.h>
#include <errno.h>
+#include <ctype.h>
#include "../config.h"
@@ -192,6 +193,60 @@ uint8_t dbm2rxlev(int dbm)
return rxlev;
}
+char *gsm_band_name(enum gsm_band band)
+{
+ switch (band) {
+ case GSM_BAND_450:
+ return "GSM450";
+ case GSM_BAND_480:
+ return "GSM450";
+ case GSM_BAND_750:
+ return "GSM750";
+ case GSM_BAND_810:
+ return "GSM810";
+ case GSM_BAND_850:
+ return "GSM850";
+ case GSM_BAND_900:
+ return "GSM900";
+ case GSM_BAND_1800:
+ return "DCS1800";
+ case GSM_BAND_1900:
+ return "PCS1900";
+ }
+ return "invalid";
+}
+
+enum gsm_band gsm_band_parse(const char* mhz)
+{
+ while (*mhz && !isdigit(*mhz))
+ mhz++;
+
+ if (*mhz == '\0')
+ return -EINVAL;
+
+ switch (atoi(mhz)) {
+ case 450:
+ return GSM_BAND_450;
+ case 480:
+ return GSM_BAND_480;
+ case 750:
+ return GSM_BAND_750;
+ case 810:
+ return GSM_BAND_810;
+ case 850:
+ return GSM_BAND_850;
+ case 900:
+ return GSM_BAND_900;
+ case 1800:
+ return GSM_BAND_1800;
+ case 1900:
+ return GSM_BAND_1900;
+ default:
+ return -EINVAL;
+ }
+}
+
+
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
void generate_backtrace()