aboutsummaryrefslogtreecommitdiffstats
path: root/src/gsm_utils.c
diff options
context:
space:
mode:
authorHolger Freyther <zecke@selfish.org>2009-02-17 20:31:30 +0000
committerHolger Freyther <zecke@selfish.org>2009-02-17 20:31:30 +0000
commit76c95690215d3f577fb9dac6d85c64df4071f977 (patch)
treec87af3f80b89fb1583238efc284e2faac8921f0a /src/gsm_utils.c
parent9e783318b0da05295665b8a449a80e7a44df882c (diff)
[utils] Create gsm_utils for 7bit encoding and decoding...
Diffstat (limited to 'src/gsm_utils.c')
-rw-r--r--src/gsm_utils.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/gsm_utils.c b/src/gsm_utils.c
new file mode 100644
index 000000000..288d5208c
--- /dev/null
+++ b/src/gsm_utils.c
@@ -0,0 +1,42 @@
+/*
+ * (C) 2008 by Daniel Willmann <daniel@totalueberwachung.de>
+ * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <openbsc/gsm_utils.h>
+#include <malloc.h>
+
+char *gsm_7bit_decode(u_int8_t *user_data, u_int8_t length)
+{
+ u_int8_t d_off = 0, b_off = 0;
+ u_int8_t i;
+ char *text = malloc(length+1);
+
+ for (i=0;i<length;i++) {
+ text[i] = ((user_data[d_off] + (user_data[d_off+1]<<8)) & (0x7f<<b_off))>>b_off;
+ b_off += 7;
+ if (b_off >= 8) {
+ d_off += 1;
+ b_off -= 8;
+ }
+ }
+ text[i] = 0;
+ return text;
+}