blob: de69ee36a80da120810ce691feff71aa69f63025 [file] [log] [blame]
Harald Welte59b04682009-06-10 05:40:52 +08001#ifndef _GSM_DATA_H
2#define _GSM_DATA_H
3
4#include <sys/types.h>
5
Harald Welte03740842009-06-10 23:11:52 +08006enum gsm_phys_chan_config {
7 GSM_PCHAN_NONE,
8 GSM_PCHAN_CCCH,
9 GSM_PCHAN_CCCH_SDCCH4,
10 GSM_PCHAN_TCH_F,
11 GSM_PCHAN_TCH_H,
12 GSM_PCHAN_SDCCH8_SACCH8C,
Harald Welte37884ed2009-10-24 10:25:50 +020013 GSM_PCHAN_PDCH, /* GPRS PDCH */
14 GSM_PCHAN_TCH_F_PDCH, /* TCH/F if used, PDCH otherwise */
Harald Welte03740842009-06-10 23:11:52 +080015 GSM_PCHAN_UNKNOWN,
16};
17
18enum gsm_chan_t {
19 GSM_LCHAN_NONE,
20 GSM_LCHAN_SDCCH,
21 GSM_LCHAN_TCH_F,
22 GSM_LCHAN_TCH_H,
23 GSM_LCHAN_UNKNOWN,
24};
25
Harald Welte52af1952009-12-13 10:53:12 +010026/* RRLP mode of operation */
27enum rrlp_mode {
28 RRLP_MODE_NONE,
29 RRLP_MODE_MS_BASED,
30 RRLP_MODE_MS_PREF,
31 RRLP_MODE_ASS_PREF,
32};
Harald Welte03740842009-06-10 23:11:52 +080033
34/* Channel Request reason */
35enum gsm_chreq_reason_t {
36 GSM_CHREQ_REASON_EMERG,
37 GSM_CHREQ_REASON_PAG,
38 GSM_CHREQ_REASON_CALL,
39 GSM_CHREQ_REASON_LOCATION_UPD,
40 GSM_CHREQ_REASON_OTHER,
41};
42
Harald Weltef4625b12010-02-20 16:24:02 +010043#include <osmocore/timer.h>
Harald Welte59b04682009-06-10 05:40:52 +080044#include <openbsc/gsm_04_08.h>
Harald Welte39274f42009-07-29 15:41:29 +020045#include <openbsc/abis_rsl.h>
Harald Welte03740842009-06-10 23:11:52 +080046#include <openbsc/mncc.h>
Harald Weltef4625b12010-02-20 16:24:02 +010047#include <osmocore/tlv.h>
48#include <osmocore/bitvec.h>
49#include <osmocore/statistics.h>
50#include <osmocore/gsm_utils.h>
51#include <osmocore/utils.h>
Harald Welte59b04682009-06-10 05:40:52 +080052
Harald Welte59b04682009-06-10 05:40:52 +080053#define TRX_NR_TS 8
54#define TS_MAX_LCHAN 8
55
56#define HARDCODED_ARFCN 123
57#define HARDCODED_TSC 7
58#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
59
Harald Welte2d73d4e2009-08-06 17:38:10 +020060/* for multi-drop config */
61#define HARDCODED_BTS0_TS 1
62#define HARDCODED_BTS1_TS 6
63#define HARDCODED_BTS2_TS 11
64
Harald Welte59b04682009-06-10 05:40:52 +080065enum gsm_hooks {
66 GSM_HOOK_NM_SWLOAD,
67 GSM_HOOK_RR_PAGING,
68};
69
70enum gsm_paging_event {
71 GSM_PAGING_SUCCEEDED,
72 GSM_PAGING_EXPIRED,
Holger Freyther8bdf7622009-04-18 13:48:55 +020073 GSM_PAGING_OOM,
Harald Welte59b04682009-06-10 05:40:52 +080074};
75
76struct msgb;
77typedef int gsm_cbfn(unsigned int hooknum,
78 unsigned int event,
79 struct msgb *msg,
80 void *data, void *param);
81
82/*
83 * Use the channel. As side effect the lchannel recycle timer
84 * will be started.
85 */
Harald Welte156c5e62009-07-05 14:02:46 +020086#define LCHAN_RELEASE_TIMEOUT 20, 0
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +010087#define use_subscr_con(con) \
88 do { (con)->use_count++; \
Harald Welte57fde552009-12-24 11:46:44 +010089 DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +010090 (con)->lchan->ts->trx->bts->nr, (con)->lchan->ts->trx->nr, (con)->lchan->ts->nr, \
91 (con)->lchan->nr, (con)->use_count); \
92 bsc_schedule_timer(&(con)->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
Harald Welte59b04682009-06-10 05:40:52 +080093
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +010094#define put_subscr_con(con) \
95 do { (con)->use_count--; \
Harald Welte57fde552009-12-24 11:46:44 +010096 DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +010097 (con)->lchan->ts->trx->bts->nr, (con)->lchan->ts->trx->nr, (con)->lchan->ts->nr, \
98 (con)->lchan->nr, (con)->use_count); \
Harald Welte59b04682009-06-10 05:40:52 +080099 } while(0);
100
101
102/* communications link with a BTS */
103struct gsm_bts_link {
104 struct gsm_bts *bts;
105};
106
Sylvain Munautf3bd3542009-12-27 21:56:14 +0100107/* Real authentication information containing Ki */
108enum gsm_auth_algo {
109 AUTH_ALGO_NONE,
110 AUTH_ALGO_XOR,
111 AUTH_ALGO_COMP128v1,
112};
113
114struct gsm_auth_info {
115 enum gsm_auth_algo auth_algo;
116 unsigned int a3a8_ki_len;
117 u_int8_t a3a8_ki[16];
118};
119
120struct gsm_auth_tuple {
121 int use_count;
122 int key_seq;
123 u_int8_t rand[16];
124 u_int8_t sres[4];
125 u_int8_t kc[8];
126};
127
128
Harald Welte59b04682009-06-10 05:40:52 +0800129struct gsm_lchan;
130struct gsm_subscriber;
Harald Welte03740842009-06-10 23:11:52 +0800131struct gsm_mncc;
Harald Welte3c062072009-07-28 18:25:29 +0200132struct rtp_socket;
Harald Welte59b04682009-06-10 05:40:52 +0800133
Harald Welte59b04682009-06-10 05:40:52 +0800134/* Network Management State */
135struct gsm_nm_state {
136 u_int8_t operational;
137 u_int8_t administrative;
138 u_int8_t availability;
139};
Harald Welte59b04682009-06-10 05:40:52 +0800140
141/*
142 * LOCATION UPDATING REQUEST state
143 *
144 * Our current operation is:
145 * - Get imei/tmsi
146 * - Accept/Reject according to global policy
147 */
148struct gsm_loc_updating_operation {
149 struct timer_list updating_timer;
Holger Hans Peter Freythercde52552009-10-27 10:42:28 +0100150 unsigned int waiting_for_imsi : 1;
151 unsigned int waiting_for_imei : 1;
Harald Welte59b04682009-06-10 05:40:52 +0800152};
153
Harald Welte92d88912009-12-21 13:30:17 +0100154/* Maximum number of neighbor cells whose average we track */
155#define MAX_NEIGH_MEAS 10
156/* Maximum size of the averaging window for neighbor cells */
157#define MAX_WIN_NEIGH_AVG 10
158
159/* processed neighbor measurements for one cell */
160struct neigh_meas_proc {
161 u_int16_t arfcn;
162 u_int8_t bsic;
163 u_int8_t rxlev[MAX_WIN_NEIGH_AVG];
164 unsigned int rxlev_cnt;
165 u_int8_t last_seen_nr;
166};
167
Harald Welted2dd9de2009-08-30 15:37:11 +0900168#define MAX_A5_KEY_LEN (128/8)
169#define RSL_ENC_ALG_A5(x) (x+1)
170
Holger Hans Peter Freytherd8318052009-10-28 14:23:39 +0100171/* is the data link established? who established it? */
172#define LCHAN_SAPI_UNUSED 0
173#define LCHAN_SAPI_MS 1
174#define LCHAN_SAPI_NET 2
175
Harald Welte4baa9c52009-12-21 13:27:11 +0100176/* state of a logical channel */
177enum gsm_lchan_state {
178 LCHAN_S_NONE, /* channel is not active */
Harald Welte (local)c3be50c2009-12-27 18:12:29 +0100179 LCHAN_S_ACT_REQ, /* channel activatin requested */
Harald Welte4baa9c52009-12-21 13:27:11 +0100180 LCHAN_S_ACTIVE, /* channel is active and operational */
Harald Weltec88a4432009-12-29 10:44:17 +0100181 LCHAN_S_REL_REQ, /* channel release has been requested */
Harald Welte4baa9c52009-12-21 13:27:11 +0100182 LCHAN_S_INACTIVE, /* channel is set inactive */
183};
184
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100185/* the per subscriber data for lchan */
186struct gsm_subscriber_connection {
187 /* To whom we are allocated at the moment */
188 struct gsm_subscriber *subscr;
189
190 /* Timer started to release the channel */
191 struct timer_list release_timer;
192
193 /*
194 * Operations that have a state and might be pending
195 */
196 struct gsm_loc_updating_operation *loc_operation;
197
198 /* use count. how many users use this channel */
199 unsigned int use_count;
200
201 /* Are we part of a special "silent" call */
202 int silent_call;
203
204 /* back pointer to the gsm_lchan */
205 struct gsm_lchan *lchan;
206};
207
Harald Welte59b04682009-06-10 05:40:52 +0800208struct gsm_lchan {
209 /* The TS that we're part of */
210 struct gsm_bts_trx_ts *ts;
211 /* The logical subslot number in the TS */
212 u_int8_t nr;
213 /* The logical channel type */
214 enum gsm_chan_t type;
Harald Welte39274f42009-07-29 15:41:29 +0200215 /* RSL channel mode */
216 enum rsl_cmod_spd rsl_cmode;
Harald Welte59b04682009-06-10 05:40:52 +0800217 /* If TCH, traffic channel mode */
Harald Welte39274f42009-07-29 15:41:29 +0200218 enum gsm48_chan_mode tch_mode;
Harald Welte4baa9c52009-12-21 13:27:11 +0100219 /* State */
220 enum gsm_lchan_state state;
Harald Welte59b04682009-06-10 05:40:52 +0800221 /* Power levels for MS and BTS */
222 u_int8_t bs_power;
223 u_int8_t ms_power;
Harald Welted2dd9de2009-08-30 15:37:11 +0900224 /* Encryption information */
225 struct {
226 u_int8_t alg_id;
227 u_int8_t key_len;
228 u_int8_t key[MAX_A5_KEY_LEN];
229 } encr;
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100230
231 struct timer_list T3101;
Holger Hans Peter Freyther3cce58f2009-11-18 22:57:02 +0100232
233 /* AMR bits */
234 struct gsm48_multi_rate_conf mr_conf;
Harald Welte59b04682009-06-10 05:40:52 +0800235
Holger Hans Peter Freytherd8318052009-10-28 14:23:39 +0100236 /* Established data link layer services */
237 u_int8_t sapis[8];
238
Harald Weltef9476812009-12-15 21:36:05 +0100239 /* cache of last measurement reports on this lchan */
240 struct gsm_meas_rep meas_rep[6];
241 int meas_rep_idx;
242
Harald Welte92d88912009-12-21 13:30:17 +0100243 /* table of neighbor cell measurements */
244 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
245
Harald Welte87504212009-12-02 01:56:49 +0530246 struct {
247 u_int32_t bound_ip;
Harald Weltebffa4992009-12-19 16:42:06 +0100248 u_int32_t connect_ip;
Harald Welte87504212009-12-02 01:56:49 +0530249 u_int16_t bound_port;
Harald Weltebffa4992009-12-19 16:42:06 +0100250 u_int16_t connect_port;
Harald Welte87504212009-12-02 01:56:49 +0530251 u_int16_t conn_id;
Harald Weltebffa4992009-12-19 16:42:06 +0100252 u_int8_t rtp_payload2;
253 u_int8_t speech_mode;
Harald Welte87504212009-12-02 01:56:49 +0530254 struct rtp_socket *rtp_socket;
255 } abis_ip;
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100256
257 struct gsm_subscriber_connection conn;
Harald Welte59b04682009-06-10 05:40:52 +0800258};
259
260struct gsm_e1_subslot {
261 /* Number of E1 link */
262 u_int8_t e1_nr;
263 /* Number of E1 TS inside E1 link */
264 u_int8_t e1_ts;
265 /* Sub-slot within the E1 TS, 0xff if full TS */
266 u_int8_t e1_ts_ss;
267};
268
269#define BTS_TRX_F_ACTIVATED 0x0001
270/* One Timeslot in a TRX */
271struct gsm_bts_trx_ts {
272 struct gsm_bts_trx *trx;
273 /* number of this timeslot at the TRX */
274 u_int8_t nr;
275
276 enum gsm_phys_chan_config pchan;
277
278 unsigned int flags;
279 struct gsm_nm_state nm_state;
Harald Welte3ae3cec2009-06-20 19:04:31 +0200280 struct tlv_parsed nm_attr;
Harald Weltef2eb2782009-08-09 21:49:48 +0200281 u_int8_t nm_chan_comb;
Harald Welte59b04682009-06-10 05:40:52 +0800282
283 /* To which E1 subslot are we connected */
284 struct gsm_e1_subslot e1_link;
Harald Welte59b04682009-06-10 05:40:52 +0800285
286 struct gsm_lchan lchan[TS_MAX_LCHAN];
287};
288
289/* One TRX in a BTS */
290struct gsm_bts_trx {
Harald Weltee712a5f2009-06-21 16:17:15 +0200291 /* list header in bts->trx_list */
292 struct llist_head list;
293
Harald Welte59b04682009-06-10 05:40:52 +0800294 struct gsm_bts *bts;
295 /* number of this TRX in the BTS */
296 u_int8_t nr;
297 /* how do we talk RSL with this TRX? */
Harald Welte62868882009-08-08 16:12:58 +0200298 struct gsm_e1_subslot rsl_e1_link;
299 u_int8_t rsl_tei;
Harald Welte59b04682009-06-10 05:40:52 +0800300 struct e1inp_sign_link *rsl_link;
Harald Welte62868882009-08-08 16:12:58 +0200301
Harald Welte59b04682009-06-10 05:40:52 +0800302 struct gsm_nm_state nm_state;
Harald Welte3ae3cec2009-06-20 19:04:31 +0200303 struct tlv_parsed nm_attr;
Harald Welte59b04682009-06-10 05:40:52 +0800304 struct {
305 struct gsm_nm_state nm_state;
306 } bb_transc;
307
308 u_int16_t arfcn;
Harald Welte91afe4c2009-06-20 18:15:19 +0200309 int nominal_power; /* in dBm */
310 unsigned int max_power_red; /* in actual dB */
Harald Welte59b04682009-06-10 05:40:52 +0800311
312 union {
313 struct {
314 struct {
315 struct gsm_nm_state nm_state;
316 } bbsig;
317 struct {
318 struct gsm_nm_state nm_state;
319 } pa;
320 } bs11;
321 };
322 struct gsm_bts_trx_ts ts[TRX_NR_TS];
323};
324
325enum gsm_bts_type {
326 GSM_BTS_TYPE_UNKNOWN,
327 GSM_BTS_TYPE_BS11,
Mike Haben66e0ba02009-10-02 12:19:34 +0100328 GSM_BTS_TYPE_NANOBTS,
Harald Welte59b04682009-06-10 05:40:52 +0800329};
330
Harald Welte59698fb2010-01-10 18:01:52 +0100331struct gsm_bts_model {
332 struct llist_head list;
333
334 enum gsm_bts_type type;
335 const char *name;
336
337 struct tlv_definition nm_att_tlvdef;
338};
339
Harald Welte59b04682009-06-10 05:40:52 +0800340/**
341 * A pending paging request
342 */
343struct gsm_paging_request {
344 /* list_head for list of all paging requests */
345 struct llist_head entry;
346 /* the subscriber which we're paging. Later gsm_paging_request
347 * should probably become a part of the gsm_subscriber struct? */
348 struct gsm_subscriber *subscr;
349 /* back-pointer to the BTS on which we are paging */
350 struct gsm_bts *bts;
351 /* what kind of channel type do we ask the MS to establish */
352 int chan_type;
353
354 /* Timer 3113: how long do we try to page? */
355 struct timer_list T3113;
356
357 /* callback to be called in case paging completes */
358 gsm_cbfn *cbfn;
359 void *cbfn_param;
360};
Harald Welte59b04682009-06-10 05:40:52 +0800361
362/*
363 * This keeps track of the paging status of one BTS. It
364 * includes a number of pending requests, a back pointer
365 * to the gsm_bts, a timer and some more state.
366 */
367struct gsm_bts_paging_state {
368 /* pending requests */
369 struct llist_head pending_requests;
370 struct gsm_paging_request *last_request;
371 struct gsm_bts *bts;
372
373 struct timer_list work_timer;
374
375 /* load */
376 u_int16_t available_slots;
377};
378
379struct gsm_envabtse {
380 struct gsm_nm_state nm_state;
381};
382
Harald Welte439e1282009-10-24 10:19:14 +0200383struct gsm_bts_gprs_nsvc {
384 struct gsm_bts *bts;
385 int id;
Harald Welte3055e332010-03-14 15:37:43 +0800386 u_int16_t nsvci;
Harald Welte410575a2010-03-14 23:30:30 +0800387 u_int16_t local_port;
388 u_int16_t remote_port;
389 u_int32_t remote_ip;
Harald Welte439e1282009-10-24 10:19:14 +0200390 struct gsm_nm_state nm_state;
391};
392
Harald Welte59b04682009-06-10 05:40:52 +0800393/* One BTS */
394struct gsm_bts {
Harald Weltee712a5f2009-06-21 16:17:15 +0200395 /* list header in net->bts_list */
396 struct llist_head list;
397
Harald Welte59b04682009-06-10 05:40:52 +0800398 struct gsm_network *network;
399 /* number of ths BTS in network */
400 u_int8_t nr;
Holger Hans Peter Freythera098dfb2009-08-21 14:44:12 +0200401 /* Cell Identity */
402 u_int16_t cell_identity;
Harald Welte59b04682009-06-10 05:40:52 +0800403 /* location area code of this BTS */
Holger Hans Peter Freyther54a22832009-09-29 14:02:33 +0200404 u_int16_t location_area_code;
Harald Welte59b04682009-06-10 05:40:52 +0800405 /* Training Sequence Code */
406 u_int8_t tsc;
407 /* Base Station Identification Code (BSIC) */
408 u_int8_t bsic;
409 /* type of BTS */
410 enum gsm_bts_type type;
Harald Welte59698fb2010-01-10 18:01:52 +0100411 struct gsm_bts_model *model;
Harald Welte91afe4c2009-06-20 18:15:19 +0200412 enum gsm_band band;
Harald Welteceb3c042009-08-10 13:46:55 +0200413 /* should the channel allocator allocate channels from high TRX to TRX0,
414 * rather than starting from TRX0 and go upwards? */
415 int chan_alloc_reverse;
Harald Welte (local)cbd46102009-08-13 10:14:26 +0200416 /* maximum Tx power that the MS is permitted to use in this cell */
417 int ms_max_power;
Harald Welteceb3c042009-08-10 13:46:55 +0200418
Harald Welte59b04682009-06-10 05:40:52 +0800419 /* how do we talk OML with this TRX? */
Harald Welte62868882009-08-08 16:12:58 +0200420 struct gsm_e1_subslot oml_e1_link;
421 u_int8_t oml_tei;
Harald Welte59b04682009-06-10 05:40:52 +0800422 struct e1inp_sign_link *oml_link;
423
424 /* Abis network management O&M handle */
425 struct abis_nm_h *nmh;
426 struct gsm_nm_state nm_state;
Harald Welte3ae3cec2009-06-20 19:04:31 +0200427 struct tlv_parsed nm_attr;
Harald Welte59b04682009-06-10 05:40:52 +0800428
429 /* number of this BTS on given E1 link */
430 u_int8_t bts_nr;
431
Harald Welte59b04682009-06-10 05:40:52 +0800432 /* paging state and control */
433 struct gsm_bts_paging_state paging;
434
435 /* CCCH is on C0 */
436 struct gsm_bts_trx *c0;
437
438 struct {
439 struct gsm_nm_state nm_state;
440 } site_mgr;
441
Harald Weltea54a2bb2009-12-01 18:04:30 +0530442 /* parameters from which we build SYSTEM INFORMATION */
443 struct {
444 struct gsm48_rach_control rach_control;
445 u_int8_t ncc_permitted;
446 struct gsm48_cell_sel_par cell_sel_par;
447 struct gsm48_cell_options cell_options;
448 struct gsm48_control_channel_descr chan_desc;
Harald Welte6ae64672009-12-14 22:07:14 +0100449 struct bitvec neigh_list;
450 struct bitvec cell_alloc;
451 struct {
452 /* bitmask large enough for all possible ARFCN's */
453 u_int8_t neigh_list[1024/8];
454 u_int8_t cell_alloc[1024/8];
455 } data;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530456 } si_common;
457
Harald Welte59b04682009-06-10 05:40:52 +0800458 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
459 union {
460 struct {
461 u_int16_t site_id;
462 u_int16_t bts_id;
Harald Welte5a989a92009-12-16 17:32:37 +0100463 u_int32_t flags;
Harald Welte59b04682009-06-10 05:40:52 +0800464 } ip_access;
465 struct {
466 struct {
467 struct gsm_nm_state nm_state;
468 } cclk;
469 struct {
470 struct gsm_nm_state nm_state;
471 } rack;
472 struct gsm_envabtse envabtse[4];
473 } bs11;
474 };
Harald Welte439e1282009-10-24 10:19:14 +0200475
476 /* Not entirely sure how ip.access specific this is */
477 struct {
Harald Welte410575a2010-03-14 23:30:30 +0800478 int enabled;
Harald Welte439e1282009-10-24 10:19:14 +0200479 struct {
480 struct gsm_nm_state nm_state;
Harald Welte4a048c52010-03-22 11:48:36 +0800481 u_int16_t nsei;
Harald Welte439e1282009-10-24 10:19:14 +0200482 } nse;
483 struct {
484 struct gsm_nm_state nm_state;
Harald Welte3055e332010-03-14 15:37:43 +0800485 u_int16_t bvci;
Harald Welte439e1282009-10-24 10:19:14 +0200486 } cell;
487 struct gsm_bts_gprs_nsvc nsvc[2];
Harald Welte3055e332010-03-14 15:37:43 +0800488 u_int8_t rac;
Harald Welte439e1282009-10-24 10:19:14 +0200489 } gprs;
Harald Welte59b04682009-06-10 05:40:52 +0800490
491 /* transceivers */
492 int num_trx;
Harald Weltee712a5f2009-06-21 16:17:15 +0200493 struct llist_head trx_list;
Harald Welte59b04682009-06-10 05:40:52 +0800494};
495
Harald Welte3edc5a92009-12-22 00:41:05 +0100496/* Some statistics of our network */
497struct gsmnet_stats {
498 struct {
Harald Weltebdbb7442009-12-22 19:07:32 +0100499 struct counter *total;
500 struct counter *no_channel;
Harald Welte3edc5a92009-12-22 00:41:05 +0100501 } chreq;
502 struct {
Harald Weltebdbb7442009-12-22 19:07:32 +0100503 struct counter *attempted;
504 struct counter *no_channel; /* no channel available */
505 struct counter *timeout; /* T3103 timeout */
506 struct counter *completed; /* HO COMPL received */
507 struct counter *failed; /* HO FAIL received */
Harald Welte3edc5a92009-12-22 00:41:05 +0100508 } handover;
509 struct {
Harald Weltebdbb7442009-12-22 19:07:32 +0100510 struct counter *attach;
511 struct counter *normal;
512 struct counter *periodic;
513 struct counter *detach;
Harald Welte3edc5a92009-12-22 00:41:05 +0100514 } loc_upd_type;
515 struct {
Harald Weltebdbb7442009-12-22 19:07:32 +0100516 struct counter *reject;
517 struct counter *accept;
Harald Welte3edc5a92009-12-22 00:41:05 +0100518 } loc_upd_resp;
519 struct {
Harald Weltebdbb7442009-12-22 19:07:32 +0100520 struct counter *attempted;
521 struct counter *detached;
522 struct counter *completed;
523 struct counter *expired;
Harald Welte3edc5a92009-12-22 00:41:05 +0100524 } paging;
525 struct {
Harald Weltebdbb7442009-12-22 19:07:32 +0100526 struct counter *submitted; /* MO SMS submissions */
527 struct counter *no_receiver;
528 struct counter *delivered; /* MT SMS deliveries */
529 struct counter *rp_err_mem;
530 struct counter *rp_err_other;
Harald Welte3edc5a92009-12-22 00:41:05 +0100531 } sms;
532 struct {
Harald Weltebdbb7442009-12-22 19:07:32 +0100533 struct counter *dialled; /* total number of dialled calls */
534 struct counter *alerted; /* we alerted the other end */
535 struct counter *connected;/* how many calls were accepted */
Harald Welte3edc5a92009-12-22 00:41:05 +0100536 } call;
537};
538
Harald Welte (local)a59a27e2009-08-12 14:42:23 +0200539enum gsm_auth_policy {
540 GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
541 GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
542 GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
543};
544
Harald Weltea9639802009-12-01 17:36:54 +0530545#define GSM_T3101_DEFAULT 10
546#define GSM_T3113_DEFAULT 60
547
Harald Welte59b04682009-06-10 05:40:52 +0800548struct gsm_network {
549 /* global parameters */
550 u_int16_t country_code;
551 u_int16_t network_code;
552 char *name_long;
553 char *name_short;
Harald Welte (local)a59a27e2009-08-12 14:42:23 +0200554 enum gsm_auth_policy auth_policy;
Harald Welte59936d72009-11-18 20:33:19 +0100555 enum gsm48_reject_value reject_cause;
Harald Weltecca253a2009-08-30 15:47:06 +0900556 int a5_encryption;
Holger Hans Peter Freyther96c89822009-11-16 17:12:38 +0100557 int neci;
Harald Weltea310f3e2009-12-14 09:00:24 +0100558 int send_mm_info;
Harald Welte0af9c9f2009-12-19 21:41:52 +0100559 struct {
560 int active;
Harald Welte92d88912009-12-21 13:30:17 +0100561 /* Window RXLEV averaging */
562 unsigned int win_rxlev_avg; /* number of SACCH frames */
563 /* Window RXQUAL averaging */
564 unsigned int win_rxqual_avg; /* number of SACCH frames */
565 /* Window RXLEV neighbouring cells averaging */
566 unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
567
568 /* how often should we check for power budget HO */
569 unsigned int pwr_interval; /* SACCH frames */
570 /* how much better does a neighbor cell have to be ? */
571 unsigned int pwr_hysteresis; /* dBm */
572 /* maximum distacne before we try a handover */
573 unsigned int max_distance; /* TA values */
Harald Welte0af9c9f2009-12-19 21:41:52 +0100574 } handover;
Harald Welte59b04682009-06-10 05:40:52 +0800575
Harald Welte3edc5a92009-12-22 00:41:05 +0100576 struct gsmnet_stats stats;
577
Harald Welte03740842009-06-10 23:11:52 +0800578 /* layer 4 */
579 int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
580 struct llist_head upqueue;
581 struct llist_head trans_list;
582
Harald Welte59b04682009-06-10 05:40:52 +0800583 unsigned int num_bts;
Harald Weltee712a5f2009-06-21 16:17:15 +0200584 struct llist_head bts_list;
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +0100585
586 /* timer values */
587 int T3101;
Holger Hans Peter Freyther89733862009-11-21 21:42:26 +0100588 int T3103;
589 int T3105;
590 int T3107;
591 int T3109;
592 int T3111;
593 int T3113;
594 int T3115;
595 int T3117;
596 int T3119;
597 int T3141;
Harald Welte52af1952009-12-13 10:53:12 +0100598
599 /* Radio Resource Location Protocol (TS 04.31) */
600 struct {
601 enum rrlp_mode mode;
602 } rrlp;
Harald Welte59b04682009-06-10 05:40:52 +0800603};
604
605#define SMS_HDR_SIZE 128
606#define SMS_TEXT_SIZE 256
607struct gsm_sms {
Harald Welte26abffa2009-11-07 00:06:19 +0900608 unsigned long long id;
Harald Welte59b04682009-06-10 05:40:52 +0800609 struct gsm_subscriber *sender;
610 struct gsm_subscriber *receiver;
611
Harald Welte156c5e62009-07-05 14:02:46 +0200612 unsigned long validity_minutes;
Harald Welte68b7df22009-08-08 16:03:15 +0200613 u_int8_t reply_path_req;
614 u_int8_t status_rep_req;
615 u_int8_t ud_hdr_ind;
616 u_int8_t protocol_id;
617 u_int8_t data_coding_scheme;
618 u_int8_t msg_ref;
619 char dest_addr[20+1]; /* DA LV is 12 bytes max, i.e. 10 bytes
620 * BCD == 20 bytes string */
621 u_int8_t user_data_len;
622 u_int8_t user_data[SMS_TEXT_SIZE];
Harald Welteb78996d2009-07-27 20:11:35 +0200623
Harald Welte59b04682009-06-10 05:40:52 +0800624 char text[SMS_TEXT_SIZE];
625};
626
Harald Welte28f7c572009-12-05 15:13:22 +0530627
Harald Weltee712a5f2009-06-21 16:17:15 +0200628struct gsm_network *gsm_network_init(u_int16_t country_code, u_int16_t network_code,
Harald Welte03740842009-06-10 23:11:52 +0800629 int (*mncc_recv)(struct gsm_network *, int, void *));
Harald Weltee712a5f2009-06-21 16:17:15 +0200630struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type,
631 u_int8_t tsc, u_int8_t bsic);
632struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
Harald Welte59698fb2010-01-10 18:01:52 +0100633int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee712a5f2009-06-21 16:17:15 +0200634
635struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Harald Welte2a470862009-12-14 22:33:02 +0100636
637/* Get reference to a neighbor cell on a given BCCH ARFCN */
Harald Welte792a1d42009-12-15 00:21:31 +0100638struct gsm_bts *gsm_bts_neighbor(const struct gsm_bts *bts,
639 u_int16_t arfcn, u_int8_t bsic);
Harald Welte2a470862009-12-14 22:33:02 +0100640
Harald Weltee712a5f2009-06-21 16:17:15 +0200641struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
Harald Welte59b04682009-06-10 05:40:52 +0800642
643const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Harald Welte2ef33202009-08-07 00:32:22 +0200644enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
Harald Welte (local)02204d02009-12-27 18:05:25 +0100645const char *gsm_lchant_name(enum gsm_chan_t c);
Harald Welte59b04682009-06-10 05:40:52 +0800646const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte (local)ab788cf2009-12-28 23:14:22 +0100647char *gsm_trx_name(struct gsm_bts_trx *trx);
Harald Welte59b04682009-06-10 05:40:52 +0800648char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +0100649char *gsm_lchan_name(struct gsm_lchan *lchan);
Harald Welteab2534c2009-12-29 10:52:38 +0100650const char *gsm_lchans_name(enum gsm_lchan_state s);
Harald Welte59b04682009-06-10 05:40:52 +0800651
652enum gsm_e1_event {
653 EVT_E1_NONE,
654 EVT_E1_TEI_UP,
655 EVT_E1_TEI_DN,
656};
657
658void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
659 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte498feae2009-08-08 15:38:29 +0200660enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther56f59bb2009-06-12 17:39:38 +0200661const char *btstype2str(enum gsm_bts_type type);
Harald Weltec985a142010-01-07 20:44:32 +0100662struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Harald Welte59b04682009-06-10 05:40:52 +0800663struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
664 struct gsm_bts *start_bts);
665
Andreas Eversberge4d51462009-06-29 15:19:38 +0200666extern void *tall_bsc_ctx;
Harald Welte8096a512009-12-20 13:48:15 +0100667extern int ipacc_rtp_direct;
Harald Weltea8379772009-06-20 22:36:41 +0200668
Harald Welte59b04682009-06-10 05:40:52 +0800669static inline int is_ipaccess_bts(struct gsm_bts *bts)
670{
671 switch (bts->type) {
Mike Haben66e0ba02009-10-02 12:19:34 +0100672 case GSM_BTS_TYPE_NANOBTS:
Harald Welte59b04682009-06-10 05:40:52 +0800673 return 1;
674 default:
675 break;
676 }
677 return 0;
678}
679
Harald Welteb7744392009-08-10 10:08:01 +0200680static inline int is_siemens_bts(struct gsm_bts *bts)
681{
682 switch (bts->type) {
683 case GSM_BTS_TYPE_BS11:
684 return 1;
685 default:
686 break;
687 }
688
689 return 0;
690}
691
Harald Welte (local)a59a27e2009-08-12 14:42:23 +0200692
693enum gsm_auth_policy gsm_auth_policy_parse(const char *arg);
694const char *gsm_auth_policy_name(enum gsm_auth_policy policy);
695
Harald Welte52af1952009-12-13 10:53:12 +0100696enum rrlp_mode rrlp_mode_parse(const char *arg);
697const char *rrlp_mode_name(enum rrlp_mode mode);
698
Holger Hans Peter Freyther1c8b4802009-11-11 11:54:24 +0100699void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked);
700
Harald Welte3055e332010-03-14 15:37:43 +0800701/* A parsed GPRS routing area */
702struct gprs_ra_id {
703 u_int16_t mnc;
704 u_int16_t mcc;
705 u_int16_t lac;
706 u_int8_t rac;
707};
708
709int gsm48_ra_id_by_bts(u_int8_t *buf, struct gsm_bts *bts);
710void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Weltef9476812009-12-15 21:36:05 +0100711struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan);
712
Harald Weltea24581f2010-03-04 11:04:52 +0100713int gsm_bts_model_register(struct gsm_bts_model *model);
714
Harald Welte59b04682009-06-10 05:40:52 +0800715#endif