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>
35 #include "../config.h"
37 /* GSM 03.38 6.2.1 Charachter packing */
38 int gsm_7bit_decode(char *text, const uint8_t *user_data, uint8_t length)
43 /* FIXME: We need to account for user data headers here */
45 for (; i < length; i ++)
47 ((user_data[(i * 7 + 7) >> 3] <<
48 (7 - ((i * 7 + 7) & 7))) |
49 (user_data[(i * 7) >> 3] >>
50 ((i * 7) & 7))) & 0x7f;
57 /* GSM 03.38 6.2.1 Charachter packing */
58 int gsm_7bit_encode(uint8_t *result, const char *data)
61 unsigned char ch1, ch2;
64 for ( i=0; i<strlen(data); i++ ) {
68 ch2 = data[(i+1)] & 0x7F;
69 ch2 = ch2 << (7-shift);
77 if ((shift == 7) && (i+1<strlen(data))) {
86 /* determine power control level for given dBm value, as indicated
87 * by the tables in chapter 4.1.1 of GSM TS 05.05 */
88 int ms_pwr_ctl_lvl(enum gsm_band band, unsigned int dbm)
102 /* we are guaranteed to have (5 <= dbm < 39) */
103 return 2 + ((39 - dbm) / 2);
116 /* we are guaranteed to have (0 <= dbm < 31) */
117 return (30 - dbm) / 2;
128 /* we are guaranteed to have (0 <= dbm < 31) */
129 return (30 - dbm) / 2;
136 int ms_pwr_dbm(enum gsm_band band, uint8_t lvl)
150 return 39 - ((lvl - 2) * 2) ;
156 return 30 - (lvl * 2);
160 return 36 - ((lvl - 29) * 2);
164 return 30 - (lvl * 2);
168 return 33 - (lvl - 30);
174 /* According to TS 08.05 Chapter 8.1.4 */
175 int rxlev2dbm(uint8_t rxlev)
183 /* According to TS 08.05 Chapter 8.1.4 */
184 uint8_t dbm2rxlev(int dbm)
186 int rxlev = dbm + 110;
196 char *gsm_band_name(enum gsm_band band)
219 enum gsm_band gsm_band_parse(const char* mhz)
221 while (*mhz && !isdigit(*mhz))
241 return GSM_BAND_1800;
243 return GSM_BAND_1900;
250 #ifdef HAVE_EXECINFO_H
251 #include <execinfo.h>
252 void generate_backtrace()
258 nptrs = backtrace(buffer, ARRAY_SIZE(buffer));
259 printf("backtrace() returned %d addresses\n", nptrs);
261 strings = backtrace_symbols(buffer, nptrs);
265 for (i = 1; i < nptrs; i++)
266 printf("%s\n", strings[i]);