Holger Freyther | 76c9569 | 2009-02-17 20:31:30 +0000 | [diff] [blame] | 1 | /* GSM utility functions, e.g. coding and decoding */ |
| 2 | /* |
| 3 | * (C) 2008 by Daniel Willmann <daniel@totalueberwachung.de> |
| 4 | * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 5 | * (C) 2009 by Harald Welte <laforge@gnumonks.org> |
Holger Freyther | 76c9569 | 2009-02-17 20:31:30 +0000 | [diff] [blame] | 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #ifndef GSM_UTILS_H |
| 26 | #define GSM_UTILS_H |
| 27 | |
| 28 | #include <sys/types.h> |
| 29 | |
Harald Welte | dfe6c7d | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 30 | enum gsm_band { |
| 31 | GSM_BAND_850 = 1, |
| 32 | GSM_BAND_900 = 2, |
| 33 | GSM_BAND_1800 = 4, |
| 34 | GSM_BAND_1900 = 8, |
| 35 | GSM_BAND_450 = 0x10, |
| 36 | GSM_BAND_480 = 0x20, |
| 37 | GSM_BAND_750 = 0x40, |
| 38 | GSM_BAND_810 = 0x80, |
| 39 | }; |
| 40 | |
Harald Welte | 7e310b1 | 2009-03-30 20:56:32 +0000 | [diff] [blame] | 41 | int gsm_7bit_decode(char *decoded, const u_int8_t *user_data, u_int8_t length); |
| 42 | int gsm_7bit_encode(u_int8_t *result, const char *data); |
Holger Freyther | 76c9569 | 2009-02-17 20:31:30 +0000 | [diff] [blame] | 43 | |
Harald Welte | 66b6a8d | 2009-08-09 14:45:18 +0200 | [diff] [blame] | 44 | int ms_pwr_ctl_lvl(enum gsm_band band, unsigned int dbm); |
| 45 | int ms_pwr_dbm(enum gsm_band band, u_int8_t lvl); |
Holger Hans Peter Freyther | 25f30ba | 2009-10-28 09:12:43 +0100 | [diff] [blame] | 46 | |
Harald Welte | 4bb4738 | 2009-12-12 15:37:54 +0100 | [diff] [blame] | 47 | /* According to TS 08.05 Chapter 8.1.4 */ |
| 48 | int rxlev2dbm(u_int8_t rxlev); |
| 49 | u_int8_t dbm2rxlev(int dbm); |
| 50 | |
Sylvain Munaut | 4010f1e | 2009-12-22 13:43:26 +0100 | [diff] [blame] | 51 | /* According to GSM 04.08 Chapter 10.5.2.29 */ |
| 52 | static inline int rach_max_trans_val2raw(int val) { return (val >> 1) & 3; } |
| 53 | static inline int rach_max_trans_raw2val(int raw) { |
| 54 | const int tbl[4] = { 1, 2, 4, 7 }; |
| 55 | return tbl[raw & 3]; |
| 56 | } |
| 57 | |
Holger Hans Peter Freyther | 25f30ba | 2009-10-28 09:12:43 +0100 | [diff] [blame] | 58 | void generate_backtrace(); |
Holger Freyther | 76c9569 | 2009-02-17 20:31:30 +0000 | [diff] [blame] | 59 | #endif |