[utils] Create gsm_utils for 7bit encoding and decoding...

This commit is contained in:
Holger Freyther 2009-02-17 20:31:30 +00:00
parent 9e783318b0
commit 76c9569021
5 changed files with 79 additions and 20 deletions

View File

@ -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

View File

@ -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

View File

@ -7,7 +7,7 @@ bsc_hack_SOURCES = bsc_hack.c abis_rsl.c abis_nm.c gsm_04_08.c gsm_data.c \
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

View File

@ -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 @@ int gsm0411_sendmsg(struct msgb *msg)
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 @@ static int gsm411_sms_submit_from_msgb(struct msgb *msg)
}
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"

42
src/gsm_utils.c Normal file
View File

@ -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;
}