1 /* GSM utility functions, e.g. coding and decoding */
3 * (C) 2008 by Daniel Willmann <daniel@totalueberwachung.de>
4 * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
5 * (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
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.
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.
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.
30 #define ADD_MODULO(sum, delta, modulo) do { \
31 if ((sum += delta) >= modulo) \
35 #define GSM_MAX_FN (26*51*2048)
38 uint32_t fn
; /* FN count */
39 uint16_t t1
; /* FN div (26*51) */
40 uint8_t t2
; /* FN modulo 26 */
41 uint8_t t3
; /* FN modulo 51 */
56 const char *gsm_band_name(enum gsm_band band
);
57 enum gsm_band
gsm_band_parse(const char *mhz
);
59 int gsm_7bit_decode(char *decoded
, const uint8_t *user_data
, uint8_t length
);
60 int gsm_7bit_decode_hdr(char *decoded
, const uint8_t *user_data
, uint8_t length
, uint8_t ud_hdr_ind
);
61 int gsm_7bit_encode(uint8_t *result
, const char *data
);
63 int gsm_septets2octets(uint8_t *result
, uint8_t *rdata
, uint8_t septet_len
, uint8_t padding
);
64 int gsm_septet_encode(uint8_t *result
, const char *data
);
65 uint8_t gsm_get_octet_len(const uint8_t sept_len
);
67 unsigned int ms_class_gmsk_dbm(enum gsm_band band
, int ms_class
);
69 int ms_pwr_ctl_lvl(enum gsm_band band
, unsigned int dbm
);
70 int ms_pwr_dbm(enum gsm_band band
, uint8_t lvl
);
72 /* According to TS 08.05 Chapter 8.1.4 */
73 int rxlev2dbm(uint8_t rxlev
);
74 uint8_t dbm2rxlev(int dbm
);
76 /* According to GSM 04.08 Chapter 10.5.1.6 */
77 static inline int ms_cm2_a5n_support(uint8_t *cm2
, int n
) {
80 case 1: return (cm2
[0] & (1<<3)) ? 0 : 1;
81 case 2: return (cm2
[2] & (1<<0)) ? 1 : 0;
82 case 3: return (cm2
[2] & (1<<1)) ? 1 : 0;
88 /* According to GSM 04.08 Chapter 10.5.2.29 */
89 static inline int rach_max_trans_val2raw(int val
) { return (val
>> 1) & 3; }
90 static inline int rach_max_trans_raw2val(int raw
) {
91 const int tbl
[4] = { 1, 2, 4, 7 };
95 #define ARFCN_PCS 0x8000
96 #define ARFCN_UPLINK 0x4000
97 #define ARFCN_FLAG_MASK 0xf000 /* Reserve the upper 5 bits for flags */
99 enum gsm_band
gsm_arfcn2band(uint16_t arfcn
);
101 /* Convert an ARFCN to the frequency in MHz * 10 */
102 uint16_t gsm_arfcn2freq10(uint16_t arfcn
, int uplink
);
104 /* Convert from frame number to GSM time */
105 void gsm_fn2gsmtime(struct gsm_time
*time
, uint32_t fn
);
107 /* Convert from GSM time to frame number */
108 uint32_t gsm_gsmtime2fn(struct gsm_time
*time
);
110 /* GSM TS 03.03 Chapter 2.6 */
111 enum gprs_tlli_type
{
119 /* TS 03.03 Chapter 2.6 */
120 int gprs_tlli_type(uint32_t tlli
);
122 uint32_t gprs_tmsi2tlli(uint32_t p_tmsi
, enum gprs_tlli_type type
);
124 /* Osmocom internal, not part of any gsm spec */
125 enum gsm_phys_chan_config
{
128 GSM_PCHAN_CCCH_SDCCH4
,
131 GSM_PCHAN_SDCCH8_SACCH8C
,
132 GSM_PCHAN_PDCH
, /* GPRS PDCH */
133 GSM_PCHAN_TCH_F_PDCH
, /* TCH/F if used, PDCH otherwise */
138 /* Osmocom internal, not part of any gsm spec */