[utils] Create gsm_utils for 7bit encoding and decoding...
diff --git a/include/openbsc/Makefile.am b/include/openbsc/Makefile.am
index 062df34..7c848b3 100644
--- a/include/openbsc/Makefile.am
+++ b/include/openbsc/Makefile.am
@@ -1,4 +1,5 @@
 noinst_HEADERS = abis_nm.h abis_rsl.h debug.h db.h gsm_04_08.h gsm_data.h \
 		 gsm_subscriber.h linuxlist.h msgb.h select.h tlv.h gsm_04_11.h \
 		 timer.h misdn.h chan_alloc.h telnet_interface.h paging.h \
-		 subchan_demux.h trau_frame.h e1_input.h trau_mux.h signal.h
+		 subchan_demux.h trau_frame.h e1_input.h trau_mux.h signal.h \
+		 gsm_utils.h
diff --git a/include/openbsc/gsm_utils.h b/include/openbsc/gsm_utils.h
new file mode 100644
index 0000000..8e4162e
--- /dev/null
+++ b/include/openbsc/gsm_utils.h
@@ -0,0 +1,32 @@
+/* GSM utility functions, e.g. coding and decoding */
+/*
+ * (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.
+ *
+ */
+
+#ifndef GSM_UTILS_H
+#define GSM_UTILS_H
+
+#include <sys/types.h>
+
+char *gsm_7bit_decode(u_int8_t *user_data, u_int8_t length);
+u_int8_t *gsm_7bit_encode(char *data);
+
+#endif
diff --git a/src/Makefile.am b/src/Makefile.am
index 714fff5..8edc99b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,7 +7,7 @@
 		gsm_subscriber.c msgb.c select.c chan_alloc.c timer.c debug.c db.c \
 		gsm_04_11.c telnet_interface.c telnet_parser.l subchan_demux.c \
 		trau_frame.c trau_mux.c paging.c e1_config.c e1_input.c tlv_parser.c \
-		input/misdn.c input/ipaccess.c signal.c
+		input/misdn.c input/ipaccess.c signal.c gsm_utils.c
 bsc_hack_LDADD = -ldl -ldbi
 
 bs11_config_SOURCES = bs11_config.c abis_nm.c gsm_data.c msgb.c debug.c select.c timer.c rs232.c
diff --git a/src/gsm_04_11.c b/src/gsm_04_11.c
index a7b603e..e94f9ad 100644
--- a/src/gsm_04_11.c
+++ b/src/gsm_04_11.c
@@ -35,6 +35,7 @@
 #include <openbsc/gsm_subscriber.h>
 #include <openbsc/gsm_04_11.h>
 #include <openbsc/gsm_04_08.h>
+#include <openbsc/gsm_utils.h>
 #include <openbsc/abis_rsl.h>
 #include <openbsc/signal.h>
 
@@ -56,23 +57,6 @@
 	return rsl_data_request(msg, 0);
 }
 
-static char *gsm411_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;
-}
 
 #if 0
 static u_int8_t gsm0411_tpdu_from_sms(u_int8_t *tpdu, struct sms_deliver *sms)
@@ -112,7 +96,7 @@
 	}
 	sms->ud_len = *smsp++;
 
-	sms->user_data = (u_int8_t *)gsm411_7bit_decode(smsp, sms->ud_len);
+	sms->user_data = (u_int8_t *)gsm_7bit_decode(smsp, sms->ud_len);
 
 	DEBUGP(DSMS, "SMS:\nMTI: 0x%02x, VPF: 0x%02x, MR: 0x%02x\n"
 			"PID: 0x%02x, DCS: 0x%02x, UserDataLength: 0x%02x\n"
diff --git a/src/gsm_utils.c b/src/gsm_utils.c
new file mode 100644
index 0000000..288d520
--- /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;
+}