2 * (C) 2008 by Daniel Willmann <daniel@totalueberwachung.de>
3 * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * (C) 2009 by Harald Welte <laforge@gnumonks.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 //#include <openbsc/gsm_data.h>
25 #include <osmocore/utils.h>
26 #include <osmocore/gsm_utils.h>
34 #include "../config.h"
36 /* GSM 03.38 6.2.1 Charachter packing */
37 int gsm_7bit_decode(char *text, const uint8_t *user_data, uint8_t length)
42 /* FIXME: We need to account for user data headers here */
44 for (; i < length; i ++)
46 ((user_data[(i * 7 + 7) >> 3] <<
47 (7 - ((i * 7 + 7) & 7))) |
48 (user_data[(i * 7) >> 3] >>
49 ((i * 7) & 7))) & 0x7f;
56 /* GSM 03.38 6.2.1 Charachter packing */
57 int gsm_7bit_encode(uint8_t *result, const char *data)
60 unsigned char ch1, ch2;
63 for ( i=0; i<strlen(data); i++ ) {
67 ch2 = data[(i+1)] & 0x7F;
68 ch2 = ch2 << (7-shift);
76 if ((shift == 7) && (i+1<strlen(data))) {
85 /* determine power control level for given dBm value, as indicated
86 * by the tables in chapter 4.1.1 of GSM TS 05.05 */
87 int ms_pwr_ctl_lvl(enum gsm_band band, unsigned int dbm)
101 /* we are guaranteed to have (5 <= dbm < 39) */
102 return 2 + ((39 - dbm) / 2);
115 /* we are guaranteed to have (0 <= dbm < 31) */
116 return (30 - dbm) / 2;
127 /* we are guaranteed to have (0 <= dbm < 31) */
128 return (30 - dbm) / 2;
135 int ms_pwr_dbm(enum gsm_band band, uint8_t lvl)
149 return 39 - ((lvl - 2) * 2) ;
155 return 30 - (lvl * 2);
159 return 36 - ((lvl - 29) * 2);
163 return 30 - (lvl * 2);
167 return 33 - (lvl - 30);
173 /* According to TS 08.05 Chapter 8.1.4 */
174 int rxlev2dbm(uint8_t rxlev)
182 /* According to TS 08.05 Chapter 8.1.4 */
183 uint8_t dbm2rxlev(int dbm)
185 int rxlev = dbm + 110;
195 #ifdef HAVE_EXECINFO_H
196 #include <execinfo.h>
197 void generate_backtrace()
203 nptrs = backtrace(buffer, ARRAY_SIZE(buffer));
204 printf("backtrace() returned %d addresses\n", nptrs);
206 strings = backtrace_symbols(buffer, nptrs);
210 for (i = 1; i < nptrs; i++)
211 printf("%s\n", strings[i]);