blob: ff01d7287c01acccebf832a757ad40e29c65069b [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001#ifndef _GSM_DATA_H
2#define _GSM_DATA_H
3
4#include <sys/types.h>
5
Harald Welteccda9652009-11-12 22:28:18 +09006struct value_string {
7 unsigned int value;
8 const char *str;
9};
10
11const char *get_value_string(const struct value_string *vs, u_int32_t val);
12
Harald Weltefcd24452009-06-20 18:15:19 +020013enum gsm_band {
14 GSM_BAND_400,
15 GSM_BAND_850,
16 GSM_BAND_900,
17 GSM_BAND_1800,
18 GSM_BAND_1900,
19};
20
Harald Welte4bfdfe72009-06-10 23:11:52 +080021enum gsm_phys_chan_config {
22 GSM_PCHAN_NONE,
23 GSM_PCHAN_CCCH,
24 GSM_PCHAN_CCCH_SDCCH4,
25 GSM_PCHAN_TCH_F,
26 GSM_PCHAN_TCH_H,
27 GSM_PCHAN_SDCCH8_SACCH8C,
Harald Weltea1499d02009-10-24 10:25:50 +020028 GSM_PCHAN_PDCH, /* GPRS PDCH */
29 GSM_PCHAN_TCH_F_PDCH, /* TCH/F if used, PDCH otherwise */
Harald Welte4bfdfe72009-06-10 23:11:52 +080030 GSM_PCHAN_UNKNOWN,
31};
32
33enum gsm_chan_t {
34 GSM_LCHAN_NONE,
35 GSM_LCHAN_SDCCH,
36 GSM_LCHAN_TCH_F,
37 GSM_LCHAN_TCH_H,
38 GSM_LCHAN_UNKNOWN,
39};
40
Harald Welteeab84a12009-12-13 10:53:12 +010041/* RRLP mode of operation */
42enum rrlp_mode {
43 RRLP_MODE_NONE,
44 RRLP_MODE_MS_BASED,
45 RRLP_MODE_MS_PREF,
46 RRLP_MODE_ASS_PREF,
47};
Harald Welte4bfdfe72009-06-10 23:11:52 +080048
49/* Channel Request reason */
50enum gsm_chreq_reason_t {
51 GSM_CHREQ_REASON_EMERG,
52 GSM_CHREQ_REASON_PAG,
53 GSM_CHREQ_REASON_CALL,
54 GSM_CHREQ_REASON_LOCATION_UPD,
55 GSM_CHREQ_REASON_OTHER,
56};
57
Harald Welte255539c2008-12-28 02:26:27 +000058#include <openbsc/timer.h>
Holger Freyther1adb4ff2009-02-04 00:04:52 +000059#include <openbsc/gsm_04_08.h>
Harald Welte9943c5b2009-07-29 15:41:29 +020060#include <openbsc/abis_rsl.h>
Harald Welte4bfdfe72009-06-10 23:11:52 +080061#include <openbsc/mncc.h>
Harald Welte93e9d172009-06-20 19:04:31 +020062#include <openbsc/tlv.h>
Harald Welte6c40def2009-12-14 22:07:14 +010063#include <openbsc/bitvec.h>
Harald Welteffa55a42009-12-22 19:07:32 +010064#include <openbsc/statistics.h>
Harald Welte255539c2008-12-28 02:26:27 +000065
Harald Welte8470bf22008-12-25 23:28:35 +000066#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
67
Harald Welte85770c72009-01-18 17:47:32 +000068#define TRX_NR_TS 8
Harald Welte8470bf22008-12-25 23:28:35 +000069#define TS_MAX_LCHAN 8
Harald Welte52b1f982008-12-23 20:25:15 +000070
71#define HARDCODED_ARFCN 123
Harald Welte02b0e092009-02-28 13:11:07 +000072#define HARDCODED_TSC 7
Harald Welte78f2f502009-05-23 16:56:52 +000073#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
Harald Welte52b1f982008-12-23 20:25:15 +000074
Harald Welte63589be2009-08-06 17:38:10 +020075/* for multi-drop config */
76#define HARDCODED_BTS0_TS 1
77#define HARDCODED_BTS1_TS 6
78#define HARDCODED_BTS2_TS 11
79
Harald Welte8e1e3ee2009-02-01 13:32:45 +000080enum gsm_hooks {
81 GSM_HOOK_NM_SWLOAD,
Harald Welte0932d1e2009-02-16 22:53:52 +000082 GSM_HOOK_RR_PAGING,
83};
84
85enum gsm_paging_event {
86 GSM_PAGING_SUCCEEDED,
87 GSM_PAGING_EXPIRED,
Holger Freyther85a7b362009-04-18 13:48:55 +020088 GSM_PAGING_OOM,
Harald Welte8e1e3ee2009-02-01 13:32:45 +000089};
90
91struct msgb;
92typedef int gsm_cbfn(unsigned int hooknum,
93 unsigned int event,
94 struct msgb *msg,
95 void *data, void *param);
96
Holger Freytherc6ea9db2008-12-30 19:18:21 +000097/*
98 * Use the channel. As side effect the lchannel recycle timer
99 * will be started.
100 */
Harald Welteb9c758b2009-07-05 14:02:46 +0200101#define LCHAN_RELEASE_TIMEOUT 20, 0
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000102#define use_lchan(lchan) \
103 do { lchan->use_count++; \
Holger Freyther4f584c32009-06-02 02:55:07 +0000104 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
105 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
106 lchan->nr, lchan->use_count); \
Harald Welteff117a82009-05-23 05:22:08 +0000107 bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000108
109#define put_lchan(lchan) \
Holger Freyther4f584c32009-06-02 02:55:07 +0000110 do { lchan->use_count--; \
111 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
112 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
113 lchan->nr, lchan->use_count); \
114 } while(0);
115
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000116
Harald Welte52b1f982008-12-23 20:25:15 +0000117/* communications link with a BTS */
118struct gsm_bts_link {
119 struct gsm_bts *bts;
120};
121
Harald Welte49f48b82009-02-17 15:29:33 +0000122struct gsm_lchan;
123struct gsm_subscriber;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800124struct gsm_mncc;
Harald Welte805f6442009-07-28 18:25:29 +0200125struct rtp_socket;
Harald Welte49f48b82009-02-17 15:29:33 +0000126
Harald Weltebbcc7a52009-02-14 19:45:44 +0000127/* Network Management State */
128struct gsm_nm_state {
129 u_int8_t operational;
130 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000131 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000132};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000133
Holger Freyther73487a22008-12-31 18:53:57 +0000134/*
135 * LOCATION UPDATING REQUEST state
136 *
137 * Our current operation is:
138 * - Get imei/tmsi
139 * - Accept/Reject according to global policy
140 */
141struct gsm_loc_updating_operation {
142 struct timer_list updating_timer;
Holger Hans Peter Freyther251aa912009-10-27 10:42:28 +0100143 unsigned int waiting_for_imsi : 1;
144 unsigned int waiting_for_imei : 1;
Holger Freyther73487a22008-12-31 18:53:57 +0000145};
146
Harald Weltef7c28b02009-12-21 13:30:17 +0100147/* Maximum number of neighbor cells whose average we track */
148#define MAX_NEIGH_MEAS 10
149/* Maximum size of the averaging window for neighbor cells */
150#define MAX_WIN_NEIGH_AVG 10
151
152/* processed neighbor measurements for one cell */
153struct neigh_meas_proc {
154 u_int16_t arfcn;
155 u_int8_t bsic;
156 u_int8_t rxlev[MAX_WIN_NEIGH_AVG];
157 unsigned int rxlev_cnt;
158 u_int8_t last_seen_nr;
159};
160
Harald Welte08d91a52009-08-30 15:37:11 +0900161#define MAX_A5_KEY_LEN (128/8)
162#define RSL_ENC_ALG_A5(x) (x+1)
163
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100164/* is the data link established? who established it? */
165#define LCHAN_SAPI_UNUSED 0
166#define LCHAN_SAPI_MS 1
167#define LCHAN_SAPI_NET 2
168
Harald Welteb8bfc562009-12-21 13:27:11 +0100169/* state of a logical channel */
170enum gsm_lchan_state {
171 LCHAN_S_NONE, /* channel is not active */
172 LCHAN_S_ACTIVE, /* channel is active and operational */
173 LCHAN_S_INACTIVE, /* channel is set inactive */
174};
175
Harald Welte8470bf22008-12-25 23:28:35 +0000176struct gsm_lchan {
177 /* The TS that we're part of */
178 struct gsm_bts_trx_ts *ts;
179 /* The logical subslot number in the TS */
180 u_int8_t nr;
Harald Welte45b407a2009-05-23 15:51:12 +0000181 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000182 enum gsm_chan_t type;
Harald Welte9943c5b2009-07-29 15:41:29 +0200183 /* RSL channel mode */
184 enum rsl_cmod_spd rsl_cmode;
Harald Welte45b407a2009-05-23 15:51:12 +0000185 /* If TCH, traffic channel mode */
Harald Welte9943c5b2009-07-29 15:41:29 +0200186 enum gsm48_chan_mode tch_mode;
Harald Welteb8bfc562009-12-21 13:27:11 +0100187 /* State */
188 enum gsm_lchan_state state;
Harald Welted4c9bf32009-02-15 16:56:18 +0000189 /* Power levels for MS and BTS */
190 u_int8_t bs_power;
191 u_int8_t ms_power;
Harald Welte08d91a52009-08-30 15:37:11 +0900192 /* Encryption information */
193 struct {
194 u_int8_t alg_id;
195 u_int8_t key_len;
196 u_int8_t key[MAX_A5_KEY_LEN];
197 } encr;
Holger Hans Peter Freytherea528022009-11-18 22:57:02 +0100198
199 /* AMR bits */
200 struct gsm48_multi_rate_conf mr_conf;
Harald Welted4c9bf32009-02-15 16:56:18 +0000201
Harald Welte8470bf22008-12-25 23:28:35 +0000202 /* To whom we are allocated at the moment */
203 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000204
205 /* Timer started to release the channel */
206 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000207
Harald Welteb7e81162009-08-10 00:26:10 +0200208 struct timer_list T3101;
209
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100210 /* Established data link layer services */
211 u_int8_t sapis[8];
212
Holger Freyther73487a22008-12-31 18:53:57 +0000213 /*
214 * Operations that have a state and might be pending
215 */
216 struct gsm_loc_updating_operation *loc_operation;
217
Holger Freytherb7193e42008-12-29 17:44:08 +0000218 /* use count. how many users use this channel */
219 unsigned int use_count;
Harald Welte2c828992009-12-02 01:56:49 +0530220
Harald Welted12b0fd2009-12-15 21:36:05 +0100221 /* cache of last measurement reports on this lchan */
222 struct gsm_meas_rep meas_rep[6];
223 int meas_rep_idx;
224
Harald Weltef7c28b02009-12-21 13:30:17 +0100225 /* table of neighbor cell measurements */
226 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
227
Harald Welte2c828992009-12-02 01:56:49 +0530228 struct {
229 u_int32_t bound_ip;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100230 u_int32_t connect_ip;
Harald Welte2c828992009-12-02 01:56:49 +0530231 u_int16_t bound_port;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100232 u_int16_t connect_port;
Harald Welte2c828992009-12-02 01:56:49 +0530233 u_int16_t conn_id;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100234 u_int8_t rtp_payload2;
235 u_int8_t speech_mode;
Harald Welte2c828992009-12-02 01:56:49 +0530236 struct rtp_socket *rtp_socket;
237 } abis_ip;
Harald Welte8470bf22008-12-25 23:28:35 +0000238};
239
Harald Welte85770c72009-01-18 17:47:32 +0000240struct gsm_e1_subslot {
241 /* Number of E1 link */
242 u_int8_t e1_nr;
243 /* Number of E1 TS inside E1 link */
244 u_int8_t e1_ts;
245 /* Sub-slot within the E1 TS, 0xff if full TS */
246 u_int8_t e1_ts_ss;
247};
248
Harald Welte52b1f982008-12-23 20:25:15 +0000249#define BTS_TRX_F_ACTIVATED 0x0001
250/* One Timeslot in a TRX */
251struct gsm_bts_trx_ts {
252 struct gsm_bts_trx *trx;
253 /* number of this timeslot at the TRX */
254 u_int8_t nr;
255
Harald Welte8470bf22008-12-25 23:28:35 +0000256 enum gsm_phys_chan_config pchan;
257
Harald Welte52b1f982008-12-23 20:25:15 +0000258 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000259 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200260 struct tlv_parsed nm_attr;
Harald Welte39c7deb2009-08-09 21:49:48 +0200261 u_int8_t nm_chan_comb;
Harald Welte8470bf22008-12-25 23:28:35 +0000262
Harald Welte85770c72009-01-18 17:47:32 +0000263 /* To which E1 subslot are we connected */
264 struct gsm_e1_subslot e1_link;
265
Harald Welte8470bf22008-12-25 23:28:35 +0000266 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000267};
268
269/* One TRX in a BTS */
270struct gsm_bts_trx {
Harald Weltee441d9c2009-06-21 16:17:15 +0200271 /* list header in bts->trx_list */
272 struct llist_head list;
273
Harald Welte52b1f982008-12-23 20:25:15 +0000274 struct gsm_bts *bts;
275 /* number of this TRX in the BTS */
276 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000277 /* how do we talk RSL with this TRX? */
Harald Welte42581822009-08-08 16:12:58 +0200278 struct gsm_e1_subslot rsl_e1_link;
279 u_int8_t rsl_tei;
Harald Welte1fa60c82009-02-09 18:13:26 +0000280 struct e1inp_sign_link *rsl_link;
Harald Welte42581822009-08-08 16:12:58 +0200281
Harald Weltebbcc7a52009-02-14 19:45:44 +0000282 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200283 struct tlv_parsed nm_attr;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000284 struct {
285 struct gsm_nm_state nm_state;
286 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000287
288 u_int16_t arfcn;
Harald Weltefcd24452009-06-20 18:15:19 +0200289 int nominal_power; /* in dBm */
290 unsigned int max_power_red; /* in actual dB */
Harald Welte8b697c72009-06-05 19:18:45 +0000291
292 union {
293 struct {
294 struct {
295 struct gsm_nm_state nm_state;
296 } bbsig;
297 struct {
298 struct gsm_nm_state nm_state;
299 } pa;
300 } bs11;
301 };
Harald Welte85770c72009-01-18 17:47:32 +0000302 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Holger Hans Peter Freyther2d501ea2009-11-11 11:54:24 +0100303
304 /* NM state */
305 int rf_locked;
Harald Welte52b1f982008-12-23 20:25:15 +0000306};
307
Harald Welte978cb422009-01-18 17:57:27 +0000308enum gsm_bts_type {
309 GSM_BTS_TYPE_UNKNOWN,
310 GSM_BTS_TYPE_BS11,
Mike Habene2d82272009-10-02 12:19:34 +0100311 GSM_BTS_TYPE_NANOBTS,
Harald Welte978cb422009-01-18 17:57:27 +0000312};
313
Holger Freytherceb59b72009-02-06 18:54:00 +0000314/**
315 * A pending paging request
316 */
317struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000318 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000319 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000320 /* the subscriber which we're paging. Later gsm_paging_request
321 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000322 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000323 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000324 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000325 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000326 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000327
328 /* Timer 3113: how long do we try to page? */
329 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000330
331 /* callback to be called in case paging completes */
332 gsm_cbfn *cbfn;
333 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000334};
335
336/*
337 * This keeps track of the paging status of one BTS. It
338 * includes a number of pending requests, a back pointer
339 * to the gsm_bts, a timer and some more state.
340 */
341struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000342 /* pending requests */
343 struct llist_head pending_requests;
344 struct gsm_paging_request *last_request;
345 struct gsm_bts *bts;
346
Harald Welte75a1fa82009-02-17 01:39:41 +0000347 struct timer_list work_timer;
348
Holger Freyther392209c2009-02-10 00:06:19 +0000349 /* load */
350 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000351};
352
Harald Welte8b697c72009-06-05 19:18:45 +0000353struct gsm_envabtse {
354 struct gsm_nm_state nm_state;
355};
356
Harald Welte55dd4432009-10-24 10:19:14 +0200357struct gsm_bts_gprs_nsvc {
358 struct gsm_bts *bts;
359 int id;
360 struct gsm_nm_state nm_state;
361};
362
Harald Welte52b1f982008-12-23 20:25:15 +0000363/* One BTS */
364struct gsm_bts {
Harald Weltee441d9c2009-06-21 16:17:15 +0200365 /* list header in net->bts_list */
366 struct llist_head list;
367
Harald Welte52b1f982008-12-23 20:25:15 +0000368 struct gsm_network *network;
369 /* number of ths BTS in network */
370 u_int8_t nr;
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200371 /* Cell Identity */
372 u_int16_t cell_identity;
Harald Welte52b1f982008-12-23 20:25:15 +0000373 /* location area code of this BTS */
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200374 u_int16_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000375 /* Training Sequence Code */
376 u_int8_t tsc;
Harald Welte78f2f502009-05-23 16:56:52 +0000377 /* Base Station Identification Code (BSIC) */
378 u_int8_t bsic;
Harald Welte978cb422009-01-18 17:57:27 +0000379 /* type of BTS */
380 enum gsm_bts_type type;
Harald Weltefcd24452009-06-20 18:15:19 +0200381 enum gsm_band band;
Harald Weltefc0d9522009-08-10 13:46:55 +0200382 /* should the channel allocator allocate channels from high TRX to TRX0,
383 * rather than starting from TRX0 and go upwards? */
384 int chan_alloc_reverse;
Harald Welte (local)0e451d02009-08-13 10:14:26 +0200385 /* maximum Tx power that the MS is permitted to use in this cell */
386 int ms_max_power;
Harald Weltefc0d9522009-08-10 13:46:55 +0200387
Harald Welte1fa60c82009-02-09 18:13:26 +0000388 /* how do we talk OML with this TRX? */
Harald Welte42581822009-08-08 16:12:58 +0200389 struct gsm_e1_subslot oml_e1_link;
390 u_int8_t oml_tei;
Harald Welte1fa60c82009-02-09 18:13:26 +0000391 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000392
393 /* Abis network management O&M handle */
394 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000395 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200396 struct tlv_parsed nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000397
Harald Welte52b1f982008-12-23 20:25:15 +0000398 /* number of this BTS on given E1 link */
399 u_int8_t bts_nr;
400
Holger Freytherceb59b72009-02-06 18:54:00 +0000401 /* paging state and control */
402 struct gsm_bts_paging_state paging;
403
Harald Welte52b1f982008-12-23 20:25:15 +0000404 /* CCCH is on C0 */
405 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000406
407 struct {
408 struct gsm_nm_state nm_state;
409 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000410
Harald Weltea43f7892009-12-01 18:04:30 +0530411 /* parameters from which we build SYSTEM INFORMATION */
412 struct {
413 struct gsm48_rach_control rach_control;
414 u_int8_t ncc_permitted;
415 struct gsm48_cell_sel_par cell_sel_par;
416 struct gsm48_cell_options cell_options;
417 struct gsm48_control_channel_descr chan_desc;
Harald Welte6c40def2009-12-14 22:07:14 +0100418 struct bitvec neigh_list;
419 struct bitvec cell_alloc;
420 struct {
421 /* bitmask large enough for all possible ARFCN's */
422 u_int8_t neigh_list[1024/8];
423 u_int8_t cell_alloc[1024/8];
424 } data;
Harald Weltea43f7892009-12-01 18:04:30 +0530425 } si_common;
426
Harald Welteedb37782009-05-01 14:59:07 +0000427 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
Harald Welte7b26bcb2009-05-28 11:39:21 +0000428 union {
429 struct {
430 u_int16_t site_id;
431 u_int16_t bts_id;
Harald Welte88a412a2009-12-16 17:32:37 +0100432 u_int32_t flags;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000433 } ip_access;
434 struct {
435 struct {
436 struct gsm_nm_state nm_state;
437 } cclk;
438 struct {
439 struct gsm_nm_state nm_state;
440 } rack;
Harald Welte8b697c72009-06-05 19:18:45 +0000441 struct gsm_envabtse envabtse[4];
Harald Welte7b26bcb2009-05-28 11:39:21 +0000442 } bs11;
443 };
Harald Welte55dd4432009-10-24 10:19:14 +0200444
445 /* Not entirely sure how ip.access specific this is */
446 struct {
447 struct {
448 struct gsm_nm_state nm_state;
449 } nse;
450 struct {
451 struct gsm_nm_state nm_state;
452 } cell;
453 struct gsm_bts_gprs_nsvc nsvc[2];
454 } gprs;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000455
Harald Welte52b1f982008-12-23 20:25:15 +0000456 /* transceivers */
457 int num_trx;
Harald Weltee441d9c2009-06-21 16:17:15 +0200458 struct llist_head trx_list;
Harald Welte52b1f982008-12-23 20:25:15 +0000459};
460
Harald Welte24ff6ee2009-12-22 00:41:05 +0100461/* Some statistics of our network */
462struct gsmnet_stats {
463 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100464 struct counter *total;
465 struct counter *no_channel;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100466 } chreq;
467 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100468 struct counter *attempted;
469 struct counter *no_channel; /* no channel available */
470 struct counter *timeout; /* T3103 timeout */
471 struct counter *completed; /* HO COMPL received */
472 struct counter *failed; /* HO FAIL received */
Harald Welte24ff6ee2009-12-22 00:41:05 +0100473 } handover;
474 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100475 struct counter *attach;
476 struct counter *normal;
477 struct counter *periodic;
478 struct counter *detach;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100479 } loc_upd_type;
480 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100481 struct counter *reject;
482 struct counter *accept;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100483 } loc_upd_resp;
484 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100485 struct counter *attempted;
486 struct counter *detached;
487 struct counter *completed;
488 struct counter *expired;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100489 } paging;
490 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100491 struct counter *submitted; /* MO SMS submissions */
492 struct counter *no_receiver;
493 struct counter *delivered; /* MT SMS deliveries */
494 struct counter *rp_err_mem;
495 struct counter *rp_err_other;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100496 } sms;
497 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100498 struct counter *dialled; /* total number of dialled calls */
499 struct counter *alerted; /* we alerted the other end */
500 struct counter *connected;/* how many calls were accepted */
Harald Welte24ff6ee2009-12-22 00:41:05 +0100501 } call;
502};
503
Harald Welte (local)69de3972009-08-12 14:42:23 +0200504enum gsm_auth_policy {
505 GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
506 GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
507 GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
508};
509
Harald Welteb84ddfc2009-12-01 17:36:54 +0530510#define GSM_T3101_DEFAULT 10
511#define GSM_T3113_DEFAULT 60
512
Harald Welte52b1f982008-12-23 20:25:15 +0000513struct gsm_network {
514 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000515 u_int16_t country_code;
516 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000517 char *name_long;
518 char *name_short;
Harald Welte (local)69de3972009-08-12 14:42:23 +0200519 enum gsm_auth_policy auth_policy;
Harald Welte1085c092009-11-18 20:33:19 +0100520 enum gsm48_reject_value reject_cause;
Harald Welte4381cfe2009-08-30 15:47:06 +0900521 int a5_encryption;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100522 int neci;
Harald Welte648b6ce2009-12-14 09:00:24 +0100523 int send_mm_info;
Harald Weltebc814502009-12-19 21:41:52 +0100524 struct {
525 int active;
Harald Weltef7c28b02009-12-21 13:30:17 +0100526 /* Window RXLEV averaging */
527 unsigned int win_rxlev_avg; /* number of SACCH frames */
528 /* Window RXQUAL averaging */
529 unsigned int win_rxqual_avg; /* number of SACCH frames */
530 /* Window RXLEV neighbouring cells averaging */
531 unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
532
533 /* how often should we check for power budget HO */
534 unsigned int pwr_interval; /* SACCH frames */
535 /* how much better does a neighbor cell have to be ? */
536 unsigned int pwr_hysteresis; /* dBm */
537 /* maximum distacne before we try a handover */
538 unsigned int max_distance; /* TA values */
Harald Weltebc814502009-12-19 21:41:52 +0100539 } handover;
Harald Welte52b1f982008-12-23 20:25:15 +0000540
Harald Welte24ff6ee2009-12-22 00:41:05 +0100541 struct gsmnet_stats stats;
542
Harald Welte4bfdfe72009-06-10 23:11:52 +0800543 /* layer 4 */
544 int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
545 struct llist_head upqueue;
546 struct llist_head trans_list;
547
Harald Welte52b1f982008-12-23 20:25:15 +0000548 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200549 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100550
551 /* timer values */
552 int T3101;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100553 int T3103;
554 int T3105;
555 int T3107;
556 int T3109;
557 int T3111;
558 int T3113;
559 int T3115;
560 int T3117;
561 int T3119;
562 int T3141;
Harald Welteeab84a12009-12-13 10:53:12 +0100563
564 /* Radio Resource Location Protocol (TS 04.31) */
565 struct {
566 enum rrlp_mode mode;
567 } rrlp;
Harald Welte52b1f982008-12-23 20:25:15 +0000568};
569
Harald Welte7e310b12009-03-30 20:56:32 +0000570#define SMS_HDR_SIZE 128
571#define SMS_TEXT_SIZE 256
572struct gsm_sms {
Harald Welted409be72009-11-07 00:06:19 +0900573 unsigned long long id;
Harald Welte7e310b12009-03-30 20:56:32 +0000574 struct gsm_subscriber *sender;
575 struct gsm_subscriber *receiver;
576
Harald Welteb9c758b2009-07-05 14:02:46 +0200577 unsigned long validity_minutes;
Harald Welte76042182009-08-08 16:03:15 +0200578 u_int8_t reply_path_req;
579 u_int8_t status_rep_req;
580 u_int8_t ud_hdr_ind;
581 u_int8_t protocol_id;
582 u_int8_t data_coding_scheme;
583 u_int8_t msg_ref;
584 char dest_addr[20+1]; /* DA LV is 12 bytes max, i.e. 10 bytes
585 * BCD == 20 bytes string */
586 u_int8_t user_data_len;
587 u_int8_t user_data[SMS_TEXT_SIZE];
Harald Weltef3efc592009-07-27 20:11:35 +0200588
Harald Welte7e310b12009-03-30 20:56:32 +0000589 char text[SMS_TEXT_SIZE];
590};
591
Harald Welte3606cc52009-12-05 15:13:22 +0530592enum gsm_auth_algo {
593 AUTH_ALGO_NONE,
594 AUTH_ALGO_XOR,
595 AUTH_ALGO_COMP128v1,
596};
597
598/* Real authentication information containing Ki */
599struct gsm_auth_info {
600 enum gsm_auth_algo auth_algo;
601 unsigned int a3a8_ki_len;
602 u_int8_t a3a8_ki[16];
603};
604
605struct gsm_auth_tuple {
606 u_int8_t rand[16];
607 u_int8_t sres[8];
608 u_int8_t kc[8];
609};
610
Harald Weltee441d9c2009-06-21 16:17:15 +0200611struct gsm_network *gsm_network_init(u_int16_t country_code, u_int16_t network_code,
Harald Welte4bfdfe72009-06-10 23:11:52 +0800612 int (*mncc_recv)(struct gsm_network *, int, void *));
Harald Weltee441d9c2009-06-21 16:17:15 +0200613struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type,
614 u_int8_t tsc, u_int8_t bsic);
615struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
616
617struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Harald Welte84874c92009-12-14 22:33:02 +0100618
619/* Get reference to a neighbor cell on a given BCCH ARFCN */
Harald Welte0b121032009-12-15 00:21:31 +0100620struct gsm_bts *gsm_bts_neighbor(const struct gsm_bts *bts,
621 u_int16_t arfcn, u_int8_t bsic);
Harald Welte84874c92009-12-14 22:33:02 +0100622
Harald Weltee441d9c2009-06-21 16:17:15 +0200623struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
Harald Welte8470bf22008-12-25 23:28:35 +0000624
Harald Weltea72c98e2009-01-04 16:10:38 +0000625const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Harald Welte65da9122009-08-07 00:32:22 +0200626enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
Harald Weltea72c98e2009-01-04 16:10:38 +0000627const char *gsm_lchan_name(enum gsm_chan_t c);
628const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte23a68632009-02-19 17:06:42 +0000629char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Weltea72c98e2009-01-04 16:10:38 +0000630
Harald Weltead384642008-12-26 10:20:07 +0000631enum gsm_e1_event {
632 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000633 EVT_E1_TEI_UP,
634 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000635};
636
Harald Weltecd06bfb2009-02-10 17:33:56 +0000637void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
638 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte1d014a52009-08-08 15:38:29 +0200639enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200640const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000641struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
642 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000643
Harald Weltefcd24452009-06-20 18:15:19 +0200644char *gsm_band_name(enum gsm_band band);
Harald Welte42581822009-08-08 16:12:58 +0200645enum gsm_band gsm_band_parse(const char *mhz);
Harald Weltefcd24452009-06-20 18:15:19 +0200646
Andreas Eversberg8226fa72009-06-29 15:19:38 +0200647extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +0100648extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +0200649
Harald Welte32201c12009-03-10 12:15:10 +0000650static inline int is_ipaccess_bts(struct gsm_bts *bts)
651{
652 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +0100653 case GSM_BTS_TYPE_NANOBTS:
Harald Welte32201c12009-03-10 12:15:10 +0000654 return 1;
655 default:
656 break;
657 }
658 return 0;
659}
660
Harald Welte5b570672009-08-10 10:08:01 +0200661static inline int is_siemens_bts(struct gsm_bts *bts)
662{
663 switch (bts->type) {
664 case GSM_BTS_TYPE_BS11:
665 return 1;
666 default:
667 break;
668 }
669
670 return 0;
671}
672
Harald Welte (local)69de3972009-08-12 14:42:23 +0200673
674enum gsm_auth_policy gsm_auth_policy_parse(const char *arg);
675const char *gsm_auth_policy_name(enum gsm_auth_policy policy);
676
Harald Welteeab84a12009-12-13 10:53:12 +0100677enum rrlp_mode rrlp_mode_parse(const char *arg);
678const char *rrlp_mode_name(enum rrlp_mode mode);
679
Holger Hans Peter Freyther2d501ea2009-11-11 11:54:24 +0100680void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked);
681
Harald Welted12b0fd2009-12-15 21:36:05 +0100682struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan);
683
Harald Welte52b1f982008-12-23 20:25:15 +0000684#endif