blob: 573ce5fb747ba6db5c2cb8f02e6ffc38d1d5f0fb [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);
Harald Welte (local)240ce882009-12-26 19:43:11 +010012int get_string_value(const struct value_string *vs, const char *str);
Harald Welteccda9652009-11-12 22:28:18 +090013
Harald Weltefcd24452009-06-20 18:15:19 +020014enum gsm_band {
15 GSM_BAND_400,
16 GSM_BAND_850,
17 GSM_BAND_900,
18 GSM_BAND_1800,
19 GSM_BAND_1900,
20};
21
Harald Welte4bfdfe72009-06-10 23:11:52 +080022enum gsm_phys_chan_config {
23 GSM_PCHAN_NONE,
24 GSM_PCHAN_CCCH,
25 GSM_PCHAN_CCCH_SDCCH4,
26 GSM_PCHAN_TCH_F,
27 GSM_PCHAN_TCH_H,
28 GSM_PCHAN_SDCCH8_SACCH8C,
Harald Weltea1499d02009-10-24 10:25:50 +020029 GSM_PCHAN_PDCH, /* GPRS PDCH */
30 GSM_PCHAN_TCH_F_PDCH, /* TCH/F if used, PDCH otherwise */
Harald Welte4bfdfe72009-06-10 23:11:52 +080031 GSM_PCHAN_UNKNOWN,
32};
33
34enum gsm_chan_t {
35 GSM_LCHAN_NONE,
36 GSM_LCHAN_SDCCH,
37 GSM_LCHAN_TCH_F,
38 GSM_LCHAN_TCH_H,
39 GSM_LCHAN_UNKNOWN,
40};
41
Harald Welteeab84a12009-12-13 10:53:12 +010042/* RRLP mode of operation */
43enum rrlp_mode {
44 RRLP_MODE_NONE,
45 RRLP_MODE_MS_BASED,
46 RRLP_MODE_MS_PREF,
47 RRLP_MODE_ASS_PREF,
48};
Harald Welte4bfdfe72009-06-10 23:11:52 +080049
50/* Channel Request reason */
51enum gsm_chreq_reason_t {
52 GSM_CHREQ_REASON_EMERG,
53 GSM_CHREQ_REASON_PAG,
54 GSM_CHREQ_REASON_CALL,
55 GSM_CHREQ_REASON_LOCATION_UPD,
56 GSM_CHREQ_REASON_OTHER,
57};
58
Harald Welte255539c2008-12-28 02:26:27 +000059#include <openbsc/timer.h>
Holger Freyther1adb4ff2009-02-04 00:04:52 +000060#include <openbsc/gsm_04_08.h>
Harald Welte9943c5b2009-07-29 15:41:29 +020061#include <openbsc/abis_rsl.h>
Harald Welte4bfdfe72009-06-10 23:11:52 +080062#include <openbsc/mncc.h>
Harald Welte93e9d172009-06-20 19:04:31 +020063#include <openbsc/tlv.h>
Harald Welte6c40def2009-12-14 22:07:14 +010064#include <openbsc/bitvec.h>
Harald Welteffa55a42009-12-22 19:07:32 +010065#include <openbsc/statistics.h>
Harald Welte255539c2008-12-28 02:26:27 +000066
Harald Welte8470bf22008-12-25 23:28:35 +000067#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
68
Harald Welte85770c72009-01-18 17:47:32 +000069#define TRX_NR_TS 8
Harald Welte8470bf22008-12-25 23:28:35 +000070#define TS_MAX_LCHAN 8
Harald Welte52b1f982008-12-23 20:25:15 +000071
72#define HARDCODED_ARFCN 123
Harald Welte02b0e092009-02-28 13:11:07 +000073#define HARDCODED_TSC 7
Harald Welte78f2f502009-05-23 16:56:52 +000074#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
Harald Welte52b1f982008-12-23 20:25:15 +000075
Harald Welte63589be2009-08-06 17:38:10 +020076/* for multi-drop config */
77#define HARDCODED_BTS0_TS 1
78#define HARDCODED_BTS1_TS 6
79#define HARDCODED_BTS2_TS 11
80
Harald Welte8e1e3ee2009-02-01 13:32:45 +000081enum gsm_hooks {
82 GSM_HOOK_NM_SWLOAD,
Harald Welte0932d1e2009-02-16 22:53:52 +000083 GSM_HOOK_RR_PAGING,
84};
85
86enum gsm_paging_event {
87 GSM_PAGING_SUCCEEDED,
88 GSM_PAGING_EXPIRED,
Holger Freyther85a7b362009-04-18 13:48:55 +020089 GSM_PAGING_OOM,
Harald Welte8e1e3ee2009-02-01 13:32:45 +000090};
91
92struct msgb;
93typedef int gsm_cbfn(unsigned int hooknum,
94 unsigned int event,
95 struct msgb *msg,
96 void *data, void *param);
97
Holger Freytherc6ea9db2008-12-30 19:18:21 +000098/*
99 * Use the channel. As side effect the lchannel recycle timer
100 * will be started.
101 */
Harald Welteb9c758b2009-07-05 14:02:46 +0200102#define LCHAN_RELEASE_TIMEOUT 20, 0
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000103#define use_lchan(lchan) \
104 do { lchan->use_count++; \
Harald Welted0c19142009-12-24 11:46:44 +0100105 DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
Holger Freyther4f584c32009-06-02 02:55:07 +0000106 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
107 lchan->nr, lchan->use_count); \
Harald Welteff117a82009-05-23 05:22:08 +0000108 bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000109
110#define put_lchan(lchan) \
Holger Freyther4f584c32009-06-02 02:55:07 +0000111 do { lchan->use_count--; \
Harald Welted0c19142009-12-24 11:46:44 +0100112 DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
Holger Freyther4f584c32009-06-02 02:55:07 +0000113 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
114 lchan->nr, lchan->use_count); \
115 } while(0);
116
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000117
Harald Welte52b1f982008-12-23 20:25:15 +0000118/* communications link with a BTS */
119struct gsm_bts_link {
120 struct gsm_bts *bts;
121};
122
Sylvain Munaut47193072009-12-27 21:56:14 +0100123/* Real authentication information containing Ki */
124enum gsm_auth_algo {
125 AUTH_ALGO_NONE,
126 AUTH_ALGO_XOR,
127 AUTH_ALGO_COMP128v1,
128};
129
130struct gsm_auth_info {
131 enum gsm_auth_algo auth_algo;
132 unsigned int a3a8_ki_len;
133 u_int8_t a3a8_ki[16];
134};
135
136struct gsm_auth_tuple {
137 int use_count;
138 int key_seq;
139 u_int8_t rand[16];
140 u_int8_t sres[4];
141 u_int8_t kc[8];
142};
143
144
Harald Welte49f48b82009-02-17 15:29:33 +0000145struct gsm_lchan;
146struct gsm_subscriber;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800147struct gsm_mncc;
Harald Welte805f6442009-07-28 18:25:29 +0200148struct rtp_socket;
Harald Welte49f48b82009-02-17 15:29:33 +0000149
Harald Weltebbcc7a52009-02-14 19:45:44 +0000150/* Network Management State */
151struct gsm_nm_state {
152 u_int8_t operational;
153 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000154 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000155};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000156
Holger Freyther73487a22008-12-31 18:53:57 +0000157/*
158 * LOCATION UPDATING REQUEST state
159 *
160 * Our current operation is:
161 * - Get imei/tmsi
162 * - Accept/Reject according to global policy
163 */
164struct gsm_loc_updating_operation {
165 struct timer_list updating_timer;
Holger Hans Peter Freyther251aa912009-10-27 10:42:28 +0100166 unsigned int waiting_for_imsi : 1;
167 unsigned int waiting_for_imei : 1;
Holger Freyther73487a22008-12-31 18:53:57 +0000168};
169
Harald Weltef7c28b02009-12-21 13:30:17 +0100170/* Maximum number of neighbor cells whose average we track */
171#define MAX_NEIGH_MEAS 10
172/* Maximum size of the averaging window for neighbor cells */
173#define MAX_WIN_NEIGH_AVG 10
174
175/* processed neighbor measurements for one cell */
176struct neigh_meas_proc {
177 u_int16_t arfcn;
178 u_int8_t bsic;
179 u_int8_t rxlev[MAX_WIN_NEIGH_AVG];
180 unsigned int rxlev_cnt;
181 u_int8_t last_seen_nr;
182};
183
Harald Welte08d91a52009-08-30 15:37:11 +0900184#define MAX_A5_KEY_LEN (128/8)
185#define RSL_ENC_ALG_A5(x) (x+1)
186
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100187/* is the data link established? who established it? */
188#define LCHAN_SAPI_UNUSED 0
189#define LCHAN_SAPI_MS 1
190#define LCHAN_SAPI_NET 2
191
Harald Welteb8bfc562009-12-21 13:27:11 +0100192/* state of a logical channel */
193enum gsm_lchan_state {
194 LCHAN_S_NONE, /* channel is not active */
Harald Welte (local)3e460312009-12-27 18:12:29 +0100195 LCHAN_S_ACT_REQ, /* channel activatin requested */
Harald Welteb8bfc562009-12-21 13:27:11 +0100196 LCHAN_S_ACTIVE, /* channel is active and operational */
Harald Welte8e93b792009-12-29 10:44:17 +0100197 LCHAN_S_REL_REQ, /* channel release has been requested */
Harald Welteb8bfc562009-12-21 13:27:11 +0100198 LCHAN_S_INACTIVE, /* channel is set inactive */
199};
200
Harald Welte8470bf22008-12-25 23:28:35 +0000201struct gsm_lchan {
202 /* The TS that we're part of */
203 struct gsm_bts_trx_ts *ts;
204 /* The logical subslot number in the TS */
205 u_int8_t nr;
Harald Welte45b407a2009-05-23 15:51:12 +0000206 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000207 enum gsm_chan_t type;
Harald Welte9943c5b2009-07-29 15:41:29 +0200208 /* RSL channel mode */
209 enum rsl_cmod_spd rsl_cmode;
Harald Welte45b407a2009-05-23 15:51:12 +0000210 /* If TCH, traffic channel mode */
Harald Welte9943c5b2009-07-29 15:41:29 +0200211 enum gsm48_chan_mode tch_mode;
Harald Welteb8bfc562009-12-21 13:27:11 +0100212 /* State */
213 enum gsm_lchan_state state;
Harald Welted4c9bf32009-02-15 16:56:18 +0000214 /* Power levels for MS and BTS */
215 u_int8_t bs_power;
216 u_int8_t ms_power;
Harald Welte08d91a52009-08-30 15:37:11 +0900217 /* Encryption information */
218 struct {
219 u_int8_t alg_id;
220 u_int8_t key_len;
221 u_int8_t key[MAX_A5_KEY_LEN];
222 } encr;
Harald Welte83579ca2009-12-29 11:17:18 +0100223 /* Are we part of a special "silent" call */
224 int silent_call;
Holger Hans Peter Freytherea528022009-11-18 22:57:02 +0100225
226 /* AMR bits */
227 struct gsm48_multi_rate_conf mr_conf;
Harald Welted4c9bf32009-02-15 16:56:18 +0000228
Harald Welte8470bf22008-12-25 23:28:35 +0000229 /* To whom we are allocated at the moment */
230 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000231
232 /* Timer started to release the channel */
233 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000234
Harald Welteb7e81162009-08-10 00:26:10 +0200235 struct timer_list T3101;
236
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100237 /* Established data link layer services */
238 u_int8_t sapis[8];
239
Holger Freyther73487a22008-12-31 18:53:57 +0000240 /*
241 * Operations that have a state and might be pending
242 */
243 struct gsm_loc_updating_operation *loc_operation;
244
Holger Freytherb7193e42008-12-29 17:44:08 +0000245 /* use count. how many users use this channel */
246 unsigned int use_count;
Harald Welte2c828992009-12-02 01:56:49 +0530247
Harald Welted12b0fd2009-12-15 21:36:05 +0100248 /* cache of last measurement reports on this lchan */
249 struct gsm_meas_rep meas_rep[6];
250 int meas_rep_idx;
251
Harald Weltef7c28b02009-12-21 13:30:17 +0100252 /* table of neighbor cell measurements */
253 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
254
Harald Welte2c828992009-12-02 01:56:49 +0530255 struct {
256 u_int32_t bound_ip;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100257 u_int32_t connect_ip;
Harald Welte2c828992009-12-02 01:56:49 +0530258 u_int16_t bound_port;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100259 u_int16_t connect_port;
Harald Welte2c828992009-12-02 01:56:49 +0530260 u_int16_t conn_id;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100261 u_int8_t rtp_payload2;
262 u_int8_t speech_mode;
Harald Welte2c828992009-12-02 01:56:49 +0530263 struct rtp_socket *rtp_socket;
264 } abis_ip;
Harald Welte8470bf22008-12-25 23:28:35 +0000265};
266
Harald Welte85770c72009-01-18 17:47:32 +0000267struct gsm_e1_subslot {
268 /* Number of E1 link */
269 u_int8_t e1_nr;
270 /* Number of E1 TS inside E1 link */
271 u_int8_t e1_ts;
272 /* Sub-slot within the E1 TS, 0xff if full TS */
273 u_int8_t e1_ts_ss;
274};
275
Harald Welte52b1f982008-12-23 20:25:15 +0000276#define BTS_TRX_F_ACTIVATED 0x0001
277/* One Timeslot in a TRX */
278struct gsm_bts_trx_ts {
279 struct gsm_bts_trx *trx;
280 /* number of this timeslot at the TRX */
281 u_int8_t nr;
282
Harald Welte8470bf22008-12-25 23:28:35 +0000283 enum gsm_phys_chan_config pchan;
284
Harald Welte52b1f982008-12-23 20:25:15 +0000285 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000286 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200287 struct tlv_parsed nm_attr;
Harald Welte39c7deb2009-08-09 21:49:48 +0200288 u_int8_t nm_chan_comb;
Harald Welte8470bf22008-12-25 23:28:35 +0000289
Harald Welte85770c72009-01-18 17:47:32 +0000290 /* To which E1 subslot are we connected */
291 struct gsm_e1_subslot e1_link;
292
Harald Welte8470bf22008-12-25 23:28:35 +0000293 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000294};
295
296/* One TRX in a BTS */
297struct gsm_bts_trx {
Harald Weltee441d9c2009-06-21 16:17:15 +0200298 /* list header in bts->trx_list */
299 struct llist_head list;
300
Harald Welte52b1f982008-12-23 20:25:15 +0000301 struct gsm_bts *bts;
302 /* number of this TRX in the BTS */
303 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000304 /* how do we talk RSL with this TRX? */
Harald Welte42581822009-08-08 16:12:58 +0200305 struct gsm_e1_subslot rsl_e1_link;
306 u_int8_t rsl_tei;
Harald Welte1fa60c82009-02-09 18:13:26 +0000307 struct e1inp_sign_link *rsl_link;
Harald Welte42581822009-08-08 16:12:58 +0200308
Harald Weltebbcc7a52009-02-14 19:45:44 +0000309 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200310 struct tlv_parsed nm_attr;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000311 struct {
312 struct gsm_nm_state nm_state;
313 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000314
315 u_int16_t arfcn;
Harald Weltefcd24452009-06-20 18:15:19 +0200316 int nominal_power; /* in dBm */
317 unsigned int max_power_red; /* in actual dB */
Harald Welte8b697c72009-06-05 19:18:45 +0000318
319 union {
320 struct {
321 struct {
322 struct gsm_nm_state nm_state;
323 } bbsig;
324 struct {
325 struct gsm_nm_state nm_state;
326 } pa;
327 } bs11;
328 };
Harald Welte85770c72009-01-18 17:47:32 +0000329 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000330};
331
Harald Welte978cb422009-01-18 17:57:27 +0000332enum gsm_bts_type {
333 GSM_BTS_TYPE_UNKNOWN,
334 GSM_BTS_TYPE_BS11,
Mike Habene2d82272009-10-02 12:19:34 +0100335 GSM_BTS_TYPE_NANOBTS,
Harald Welte978cb422009-01-18 17:57:27 +0000336};
337
Holger Freytherceb59b72009-02-06 18:54:00 +0000338/**
339 * A pending paging request
340 */
341struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000342 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000343 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000344 /* the subscriber which we're paging. Later gsm_paging_request
345 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000346 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000347 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000348 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000349 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000350 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000351
352 /* Timer 3113: how long do we try to page? */
353 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000354
355 /* callback to be called in case paging completes */
356 gsm_cbfn *cbfn;
357 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000358};
359
360/*
361 * This keeps track of the paging status of one BTS. It
362 * includes a number of pending requests, a back pointer
363 * to the gsm_bts, a timer and some more state.
364 */
365struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000366 /* pending requests */
367 struct llist_head pending_requests;
368 struct gsm_paging_request *last_request;
369 struct gsm_bts *bts;
370
Harald Welte75a1fa82009-02-17 01:39:41 +0000371 struct timer_list work_timer;
372
Holger Freyther392209c2009-02-10 00:06:19 +0000373 /* load */
374 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000375};
376
Harald Welte8b697c72009-06-05 19:18:45 +0000377struct gsm_envabtse {
378 struct gsm_nm_state nm_state;
379};
380
Harald Welte55dd4432009-10-24 10:19:14 +0200381struct gsm_bts_gprs_nsvc {
382 struct gsm_bts *bts;
383 int id;
384 struct gsm_nm_state nm_state;
385};
386
Harald Welte52b1f982008-12-23 20:25:15 +0000387/* One BTS */
388struct gsm_bts {
Harald Weltee441d9c2009-06-21 16:17:15 +0200389 /* list header in net->bts_list */
390 struct llist_head list;
391
Harald Welte52b1f982008-12-23 20:25:15 +0000392 struct gsm_network *network;
393 /* number of ths BTS in network */
394 u_int8_t nr;
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200395 /* Cell Identity */
396 u_int16_t cell_identity;
Harald Welte52b1f982008-12-23 20:25:15 +0000397 /* location area code of this BTS */
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200398 u_int16_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000399 /* Training Sequence Code */
400 u_int8_t tsc;
Harald Welte78f2f502009-05-23 16:56:52 +0000401 /* Base Station Identification Code (BSIC) */
402 u_int8_t bsic;
Harald Welte978cb422009-01-18 17:57:27 +0000403 /* type of BTS */
404 enum gsm_bts_type type;
Harald Weltefcd24452009-06-20 18:15:19 +0200405 enum gsm_band band;
Harald Weltefc0d9522009-08-10 13:46:55 +0200406 /* should the channel allocator allocate channels from high TRX to TRX0,
407 * rather than starting from TRX0 and go upwards? */
408 int chan_alloc_reverse;
Harald Welte (local)0e451d02009-08-13 10:14:26 +0200409 /* maximum Tx power that the MS is permitted to use in this cell */
410 int ms_max_power;
Harald Weltefc0d9522009-08-10 13:46:55 +0200411
Harald Welte1fa60c82009-02-09 18:13:26 +0000412 /* how do we talk OML with this TRX? */
Harald Welte42581822009-08-08 16:12:58 +0200413 struct gsm_e1_subslot oml_e1_link;
414 u_int8_t oml_tei;
Harald Welte1fa60c82009-02-09 18:13:26 +0000415 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000416
417 /* Abis network management O&M handle */
418 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000419 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200420 struct tlv_parsed nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000421
Harald Welte52b1f982008-12-23 20:25:15 +0000422 /* number of this BTS on given E1 link */
423 u_int8_t bts_nr;
424
Holger Freytherceb59b72009-02-06 18:54:00 +0000425 /* paging state and control */
426 struct gsm_bts_paging_state paging;
427
Harald Welte52b1f982008-12-23 20:25:15 +0000428 /* CCCH is on C0 */
429 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000430
431 struct {
432 struct gsm_nm_state nm_state;
433 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000434
Harald Weltea43f7892009-12-01 18:04:30 +0530435 /* parameters from which we build SYSTEM INFORMATION */
436 struct {
437 struct gsm48_rach_control rach_control;
438 u_int8_t ncc_permitted;
439 struct gsm48_cell_sel_par cell_sel_par;
440 struct gsm48_cell_options cell_options;
441 struct gsm48_control_channel_descr chan_desc;
Harald Welte6c40def2009-12-14 22:07:14 +0100442 struct bitvec neigh_list;
443 struct bitvec cell_alloc;
444 struct {
445 /* bitmask large enough for all possible ARFCN's */
446 u_int8_t neigh_list[1024/8];
447 u_int8_t cell_alloc[1024/8];
448 } data;
Harald Weltea43f7892009-12-01 18:04:30 +0530449 } si_common;
450
Harald Welteedb37782009-05-01 14:59:07 +0000451 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
Harald Welte7b26bcb2009-05-28 11:39:21 +0000452 union {
453 struct {
454 u_int16_t site_id;
455 u_int16_t bts_id;
Harald Welte88a412a2009-12-16 17:32:37 +0100456 u_int32_t flags;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000457 } ip_access;
458 struct {
459 struct {
460 struct gsm_nm_state nm_state;
461 } cclk;
462 struct {
463 struct gsm_nm_state nm_state;
464 } rack;
Harald Welte8b697c72009-06-05 19:18:45 +0000465 struct gsm_envabtse envabtse[4];
Harald Welte7b26bcb2009-05-28 11:39:21 +0000466 } bs11;
467 };
Harald Welte55dd4432009-10-24 10:19:14 +0200468
469 /* Not entirely sure how ip.access specific this is */
470 struct {
471 struct {
472 struct gsm_nm_state nm_state;
473 } nse;
474 struct {
475 struct gsm_nm_state nm_state;
476 } cell;
477 struct gsm_bts_gprs_nsvc nsvc[2];
478 } gprs;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000479
Harald Welte52b1f982008-12-23 20:25:15 +0000480 /* transceivers */
481 int num_trx;
Harald Weltee441d9c2009-06-21 16:17:15 +0200482 struct llist_head trx_list;
Harald Welte52b1f982008-12-23 20:25:15 +0000483};
484
Harald Welte24ff6ee2009-12-22 00:41:05 +0100485/* Some statistics of our network */
486struct gsmnet_stats {
487 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100488 struct counter *total;
489 struct counter *no_channel;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100490 } chreq;
491 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100492 struct counter *attempted;
493 struct counter *no_channel; /* no channel available */
494 struct counter *timeout; /* T3103 timeout */
495 struct counter *completed; /* HO COMPL received */
496 struct counter *failed; /* HO FAIL received */
Harald Welte24ff6ee2009-12-22 00:41:05 +0100497 } handover;
498 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100499 struct counter *attach;
500 struct counter *normal;
501 struct counter *periodic;
502 struct counter *detach;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100503 } loc_upd_type;
504 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100505 struct counter *reject;
506 struct counter *accept;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100507 } loc_upd_resp;
508 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100509 struct counter *attempted;
510 struct counter *detached;
511 struct counter *completed;
512 struct counter *expired;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100513 } paging;
514 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100515 struct counter *submitted; /* MO SMS submissions */
516 struct counter *no_receiver;
517 struct counter *delivered; /* MT SMS deliveries */
518 struct counter *rp_err_mem;
519 struct counter *rp_err_other;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100520 } sms;
521 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100522 struct counter *dialled; /* total number of dialled calls */
523 struct counter *alerted; /* we alerted the other end */
524 struct counter *connected;/* how many calls were accepted */
Harald Welte24ff6ee2009-12-22 00:41:05 +0100525 } call;
526};
527
Harald Welte (local)69de3972009-08-12 14:42:23 +0200528enum gsm_auth_policy {
529 GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
530 GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
531 GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
532};
533
Harald Welteb84ddfc2009-12-01 17:36:54 +0530534#define GSM_T3101_DEFAULT 10
535#define GSM_T3113_DEFAULT 60
536
Harald Welte52b1f982008-12-23 20:25:15 +0000537struct gsm_network {
538 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000539 u_int16_t country_code;
540 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000541 char *name_long;
542 char *name_short;
Harald Welte (local)69de3972009-08-12 14:42:23 +0200543 enum gsm_auth_policy auth_policy;
Harald Welte1085c092009-11-18 20:33:19 +0100544 enum gsm48_reject_value reject_cause;
Harald Welte4381cfe2009-08-30 15:47:06 +0900545 int a5_encryption;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100546 int neci;
Harald Welte648b6ce2009-12-14 09:00:24 +0100547 int send_mm_info;
Harald Weltebc814502009-12-19 21:41:52 +0100548 struct {
549 int active;
Harald Weltef7c28b02009-12-21 13:30:17 +0100550 /* Window RXLEV averaging */
551 unsigned int win_rxlev_avg; /* number of SACCH frames */
552 /* Window RXQUAL averaging */
553 unsigned int win_rxqual_avg; /* number of SACCH frames */
554 /* Window RXLEV neighbouring cells averaging */
555 unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
556
557 /* how often should we check for power budget HO */
558 unsigned int pwr_interval; /* SACCH frames */
559 /* how much better does a neighbor cell have to be ? */
560 unsigned int pwr_hysteresis; /* dBm */
561 /* maximum distacne before we try a handover */
562 unsigned int max_distance; /* TA values */
Harald Weltebc814502009-12-19 21:41:52 +0100563 } handover;
Harald Welte52b1f982008-12-23 20:25:15 +0000564
Harald Welte24ff6ee2009-12-22 00:41:05 +0100565 struct gsmnet_stats stats;
566
Harald Welte4bfdfe72009-06-10 23:11:52 +0800567 /* layer 4 */
568 int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
569 struct llist_head upqueue;
570 struct llist_head trans_list;
571
Harald Welte52b1f982008-12-23 20:25:15 +0000572 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200573 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100574
575 /* timer values */
576 int T3101;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100577 int T3103;
578 int T3105;
579 int T3107;
580 int T3109;
581 int T3111;
582 int T3113;
583 int T3115;
584 int T3117;
585 int T3119;
586 int T3141;
Harald Welteeab84a12009-12-13 10:53:12 +0100587
588 /* Radio Resource Location Protocol (TS 04.31) */
589 struct {
590 enum rrlp_mode mode;
591 } rrlp;
Harald Welte52b1f982008-12-23 20:25:15 +0000592};
593
Harald Welte7e310b12009-03-30 20:56:32 +0000594#define SMS_HDR_SIZE 128
595#define SMS_TEXT_SIZE 256
596struct gsm_sms {
Harald Welted409be72009-11-07 00:06:19 +0900597 unsigned long long id;
Harald Welte7e310b12009-03-30 20:56:32 +0000598 struct gsm_subscriber *sender;
599 struct gsm_subscriber *receiver;
600
Harald Welteb9c758b2009-07-05 14:02:46 +0200601 unsigned long validity_minutes;
Harald Welte76042182009-08-08 16:03:15 +0200602 u_int8_t reply_path_req;
603 u_int8_t status_rep_req;
604 u_int8_t ud_hdr_ind;
605 u_int8_t protocol_id;
606 u_int8_t data_coding_scheme;
607 u_int8_t msg_ref;
608 char dest_addr[20+1]; /* DA LV is 12 bytes max, i.e. 10 bytes
609 * BCD == 20 bytes string */
610 u_int8_t user_data_len;
611 u_int8_t user_data[SMS_TEXT_SIZE];
Harald Weltef3efc592009-07-27 20:11:35 +0200612
Harald Welte7e310b12009-03-30 20:56:32 +0000613 char text[SMS_TEXT_SIZE];
614};
615
Harald Welte3606cc52009-12-05 15:13:22 +0530616
Harald Weltee441d9c2009-06-21 16:17:15 +0200617struct gsm_network *gsm_network_init(u_int16_t country_code, u_int16_t network_code,
Harald Welte4bfdfe72009-06-10 23:11:52 +0800618 int (*mncc_recv)(struct gsm_network *, int, void *));
Harald Weltee441d9c2009-06-21 16:17:15 +0200619struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type,
620 u_int8_t tsc, u_int8_t bsic);
621struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
Harald Welte (local)7b37d972009-12-27 20:56:38 +0100622void gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +0200623
624struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Harald Welte84874c92009-12-14 22:33:02 +0100625
626/* Get reference to a neighbor cell on a given BCCH ARFCN */
Harald Welte0b121032009-12-15 00:21:31 +0100627struct gsm_bts *gsm_bts_neighbor(const struct gsm_bts *bts,
628 u_int16_t arfcn, u_int8_t bsic);
Harald Welte84874c92009-12-14 22:33:02 +0100629
Harald Weltee441d9c2009-06-21 16:17:15 +0200630struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
Harald Welte8470bf22008-12-25 23:28:35 +0000631
Harald Weltea72c98e2009-01-04 16:10:38 +0000632const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Harald Welte65da9122009-08-07 00:32:22 +0200633enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
Harald Welte (local)ccd88452009-12-27 18:05:25 +0100634const char *gsm_lchant_name(enum gsm_chan_t c);
Harald Weltea72c98e2009-01-04 16:10:38 +0000635const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte (local)d48f4eb2009-12-28 23:14:22 +0100636char *gsm_trx_name(struct gsm_bts_trx *trx);
Harald Welte23a68632009-02-19 17:06:42 +0000637char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Welte (local)19ef62a2009-12-27 18:16:36 +0100638char *gsm_lchan_name(struct gsm_lchan *lchan);
Harald Welte1887f9d2009-12-29 10:52:38 +0100639const char *gsm_lchans_name(enum gsm_lchan_state s);
Harald Weltea72c98e2009-01-04 16:10:38 +0000640
Harald Weltead384642008-12-26 10:20:07 +0000641enum gsm_e1_event {
642 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000643 EVT_E1_TEI_UP,
644 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000645};
646
Harald Weltecd06bfb2009-02-10 17:33:56 +0000647void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
648 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte1d014a52009-08-08 15:38:29 +0200649enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200650const char *btstype2str(enum gsm_bts_type type);
Harald Welte6e670aa2010-01-07 20:44:32 +0100651struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Harald Weltebe991492009-05-23 13:56:40 +0000652struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
653 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000654
Harald Weltefcd24452009-06-20 18:15:19 +0200655char *gsm_band_name(enum gsm_band band);
Harald Welte42581822009-08-08 16:12:58 +0200656enum gsm_band gsm_band_parse(const char *mhz);
Harald Weltefcd24452009-06-20 18:15:19 +0200657
Andreas Eversberg8226fa72009-06-29 15:19:38 +0200658extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +0100659extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +0200660
Harald Welte32201c12009-03-10 12:15:10 +0000661static inline int is_ipaccess_bts(struct gsm_bts *bts)
662{
663 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +0100664 case GSM_BTS_TYPE_NANOBTS:
Harald Welte32201c12009-03-10 12:15:10 +0000665 return 1;
666 default:
667 break;
668 }
669 return 0;
670}
671
Harald Welte5b570672009-08-10 10:08:01 +0200672static inline int is_siemens_bts(struct gsm_bts *bts)
673{
674 switch (bts->type) {
675 case GSM_BTS_TYPE_BS11:
676 return 1;
677 default:
678 break;
679 }
680
681 return 0;
682}
683
Harald Welte (local)69de3972009-08-12 14:42:23 +0200684
685enum gsm_auth_policy gsm_auth_policy_parse(const char *arg);
686const char *gsm_auth_policy_name(enum gsm_auth_policy policy);
687
Harald Welteeab84a12009-12-13 10:53:12 +0100688enum rrlp_mode rrlp_mode_parse(const char *arg);
689const char *rrlp_mode_name(enum rrlp_mode mode);
690
Holger Hans Peter Freyther2d501ea2009-11-11 11:54:24 +0100691void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked);
692
Harald Welted12b0fd2009-12-15 21:36:05 +0100693struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan);
694
Harald Welte52b1f982008-12-23 20:25:15 +0000695#endif