blob: eebe6abb9ab28711a2c792f50783aba1305a0f01 [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 Welte4bfdfe72009-06-10 23:11:52 +080014enum gsm_phys_chan_config {
15 GSM_PCHAN_NONE,
16 GSM_PCHAN_CCCH,
17 GSM_PCHAN_CCCH_SDCCH4,
18 GSM_PCHAN_TCH_F,
19 GSM_PCHAN_TCH_H,
20 GSM_PCHAN_SDCCH8_SACCH8C,
Harald Weltea1499d02009-10-24 10:25:50 +020021 GSM_PCHAN_PDCH, /* GPRS PDCH */
22 GSM_PCHAN_TCH_F_PDCH, /* TCH/F if used, PDCH otherwise */
Harald Welte4bfdfe72009-06-10 23:11:52 +080023 GSM_PCHAN_UNKNOWN,
24};
25
26enum gsm_chan_t {
27 GSM_LCHAN_NONE,
28 GSM_LCHAN_SDCCH,
29 GSM_LCHAN_TCH_F,
30 GSM_LCHAN_TCH_H,
31 GSM_LCHAN_UNKNOWN,
32};
33
Harald Welteeab84a12009-12-13 10:53:12 +010034/* RRLP mode of operation */
35enum rrlp_mode {
36 RRLP_MODE_NONE,
37 RRLP_MODE_MS_BASED,
38 RRLP_MODE_MS_PREF,
39 RRLP_MODE_ASS_PREF,
40};
Harald Welte4bfdfe72009-06-10 23:11:52 +080041
42/* Channel Request reason */
43enum gsm_chreq_reason_t {
44 GSM_CHREQ_REASON_EMERG,
45 GSM_CHREQ_REASON_PAG,
46 GSM_CHREQ_REASON_CALL,
47 GSM_CHREQ_REASON_LOCATION_UPD,
48 GSM_CHREQ_REASON_OTHER,
49};
50
Harald Weltedfe6c7d2010-02-20 16:24:02 +010051#include <osmocore/timer.h>
Holger Freyther1adb4ff2009-02-04 00:04:52 +000052#include <openbsc/gsm_04_08.h>
Harald Welte9943c5b2009-07-29 15:41:29 +020053#include <openbsc/abis_rsl.h>
Harald Welte4bfdfe72009-06-10 23:11:52 +080054#include <openbsc/mncc.h>
Harald Weltedfe6c7d2010-02-20 16:24:02 +010055#include <osmocore/tlv.h>
56#include <osmocore/bitvec.h>
57#include <osmocore/statistics.h>
58#include <osmocore/gsm_utils.h>
59#include <osmocore/utils.h>
Harald Welte8470bf22008-12-25 23:28:35 +000060
Harald Welte85770c72009-01-18 17:47:32 +000061#define TRX_NR_TS 8
Harald Welte8470bf22008-12-25 23:28:35 +000062#define TS_MAX_LCHAN 8
Harald Welte52b1f982008-12-23 20:25:15 +000063
64#define HARDCODED_ARFCN 123
Harald Welte02b0e092009-02-28 13:11:07 +000065#define HARDCODED_TSC 7
Harald Welte78f2f502009-05-23 16:56:52 +000066#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
Harald Welte52b1f982008-12-23 20:25:15 +000067
Harald Welte63589be2009-08-06 17:38:10 +020068/* for multi-drop config */
69#define HARDCODED_BTS0_TS 1
70#define HARDCODED_BTS1_TS 6
71#define HARDCODED_BTS2_TS 11
72
Harald Welte8e1e3ee2009-02-01 13:32:45 +000073enum gsm_hooks {
74 GSM_HOOK_NM_SWLOAD,
Harald Welte0932d1e2009-02-16 22:53:52 +000075 GSM_HOOK_RR_PAGING,
76};
77
78enum gsm_paging_event {
79 GSM_PAGING_SUCCEEDED,
80 GSM_PAGING_EXPIRED,
Holger Freyther85a7b362009-04-18 13:48:55 +020081 GSM_PAGING_OOM,
Harald Welte8e1e3ee2009-02-01 13:32:45 +000082};
83
84struct msgb;
85typedef int gsm_cbfn(unsigned int hooknum,
86 unsigned int event,
87 struct msgb *msg,
88 void *data, void *param);
89
Holger Freytherc6ea9db2008-12-30 19:18:21 +000090/*
91 * Use the channel. As side effect the lchannel recycle timer
92 * will be started.
93 */
Harald Welteb9c758b2009-07-05 14:02:46 +020094#define LCHAN_RELEASE_TIMEOUT 20, 0
Holger Freytherc6ea9db2008-12-30 19:18:21 +000095#define use_lchan(lchan) \
96 do { lchan->use_count++; \
Harald Welted0c19142009-12-24 11:46:44 +010097 DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
Holger Freyther4f584c32009-06-02 02:55:07 +000098 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
99 lchan->nr, lchan->use_count); \
Harald Welteff117a82009-05-23 05:22:08 +0000100 bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000101
102#define put_lchan(lchan) \
Holger Freyther4f584c32009-06-02 02:55:07 +0000103 do { lchan->use_count--; \
Harald Welted0c19142009-12-24 11:46:44 +0100104 DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
Holger Freyther4f584c32009-06-02 02:55:07 +0000105 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
106 lchan->nr, lchan->use_count); \
107 } while(0);
108
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000109
Harald Welte52b1f982008-12-23 20:25:15 +0000110/* communications link with a BTS */
111struct gsm_bts_link {
112 struct gsm_bts *bts;
113};
114
Sylvain Munaut47193072009-12-27 21:56:14 +0100115/* Real authentication information containing Ki */
116enum gsm_auth_algo {
117 AUTH_ALGO_NONE,
118 AUTH_ALGO_XOR,
119 AUTH_ALGO_COMP128v1,
120};
121
122struct gsm_auth_info {
123 enum gsm_auth_algo auth_algo;
124 unsigned int a3a8_ki_len;
125 u_int8_t a3a8_ki[16];
126};
127
128struct gsm_auth_tuple {
129 int use_count;
130 int key_seq;
131 u_int8_t rand[16];
132 u_int8_t sres[4];
133 u_int8_t kc[8];
134};
135
136
Harald Welte49f48b82009-02-17 15:29:33 +0000137struct gsm_lchan;
138struct gsm_subscriber;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800139struct gsm_mncc;
Harald Welte805f6442009-07-28 18:25:29 +0200140struct rtp_socket;
Harald Welte49f48b82009-02-17 15:29:33 +0000141
Harald Weltebbcc7a52009-02-14 19:45:44 +0000142/* Network Management State */
143struct gsm_nm_state {
144 u_int8_t operational;
145 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000146 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000147};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000148
Holger Freyther73487a22008-12-31 18:53:57 +0000149/*
150 * LOCATION UPDATING REQUEST state
151 *
152 * Our current operation is:
153 * - Get imei/tmsi
154 * - Accept/Reject according to global policy
155 */
156struct gsm_loc_updating_operation {
157 struct timer_list updating_timer;
Holger Hans Peter Freyther251aa912009-10-27 10:42:28 +0100158 unsigned int waiting_for_imsi : 1;
159 unsigned int waiting_for_imei : 1;
Holger Freyther73487a22008-12-31 18:53:57 +0000160};
161
Harald Weltef7c28b02009-12-21 13:30:17 +0100162/* Maximum number of neighbor cells whose average we track */
163#define MAX_NEIGH_MEAS 10
164/* Maximum size of the averaging window for neighbor cells */
165#define MAX_WIN_NEIGH_AVG 10
166
167/* processed neighbor measurements for one cell */
168struct neigh_meas_proc {
169 u_int16_t arfcn;
170 u_int8_t bsic;
171 u_int8_t rxlev[MAX_WIN_NEIGH_AVG];
172 unsigned int rxlev_cnt;
173 u_int8_t last_seen_nr;
174};
175
Harald Welte08d91a52009-08-30 15:37:11 +0900176#define MAX_A5_KEY_LEN (128/8)
177#define RSL_ENC_ALG_A5(x) (x+1)
178
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100179/* is the data link established? who established it? */
180#define LCHAN_SAPI_UNUSED 0
181#define LCHAN_SAPI_MS 1
182#define LCHAN_SAPI_NET 2
183
Harald Welteb8bfc562009-12-21 13:27:11 +0100184/* state of a logical channel */
185enum gsm_lchan_state {
186 LCHAN_S_NONE, /* channel is not active */
Harald Welte (local)3e460312009-12-27 18:12:29 +0100187 LCHAN_S_ACT_REQ, /* channel activatin requested */
Harald Welteb8bfc562009-12-21 13:27:11 +0100188 LCHAN_S_ACTIVE, /* channel is active and operational */
Harald Welte8e93b792009-12-29 10:44:17 +0100189 LCHAN_S_REL_REQ, /* channel release has been requested */
Harald Welteb8bfc562009-12-21 13:27:11 +0100190 LCHAN_S_INACTIVE, /* channel is set inactive */
191};
192
Harald Welte8470bf22008-12-25 23:28:35 +0000193struct gsm_lchan {
194 /* The TS that we're part of */
195 struct gsm_bts_trx_ts *ts;
196 /* The logical subslot number in the TS */
197 u_int8_t nr;
Harald Welte45b407a2009-05-23 15:51:12 +0000198 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000199 enum gsm_chan_t type;
Harald Welte9943c5b2009-07-29 15:41:29 +0200200 /* RSL channel mode */
201 enum rsl_cmod_spd rsl_cmode;
Harald Welte45b407a2009-05-23 15:51:12 +0000202 /* If TCH, traffic channel mode */
Harald Welte9943c5b2009-07-29 15:41:29 +0200203 enum gsm48_chan_mode tch_mode;
Harald Welteb8bfc562009-12-21 13:27:11 +0100204 /* State */
205 enum gsm_lchan_state state;
Harald Welted4c9bf32009-02-15 16:56:18 +0000206 /* Power levels for MS and BTS */
207 u_int8_t bs_power;
208 u_int8_t ms_power;
Harald Welte08d91a52009-08-30 15:37:11 +0900209 /* Encryption information */
210 struct {
211 u_int8_t alg_id;
212 u_int8_t key_len;
213 u_int8_t key[MAX_A5_KEY_LEN];
214 } encr;
Harald Welte83579ca2009-12-29 11:17:18 +0100215 /* Are we part of a special "silent" call */
216 int silent_call;
Holger Hans Peter Freytherea528022009-11-18 22:57:02 +0100217
218 /* AMR bits */
219 struct gsm48_multi_rate_conf mr_conf;
Harald Welted4c9bf32009-02-15 16:56:18 +0000220
Harald Welte8470bf22008-12-25 23:28:35 +0000221 /* To whom we are allocated at the moment */
222 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000223
224 /* Timer started to release the channel */
225 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000226
Harald Welteb7e81162009-08-10 00:26:10 +0200227 struct timer_list T3101;
228
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100229 /* Established data link layer services */
230 u_int8_t sapis[8];
231
Holger Freyther73487a22008-12-31 18:53:57 +0000232 /*
233 * Operations that have a state and might be pending
234 */
235 struct gsm_loc_updating_operation *loc_operation;
236
Holger Freytherb7193e42008-12-29 17:44:08 +0000237 /* use count. how many users use this channel */
238 unsigned int use_count;
Harald Welte2c828992009-12-02 01:56:49 +0530239
Harald Welted12b0fd2009-12-15 21:36:05 +0100240 /* cache of last measurement reports on this lchan */
241 struct gsm_meas_rep meas_rep[6];
242 int meas_rep_idx;
243
Harald Weltef7c28b02009-12-21 13:30:17 +0100244 /* table of neighbor cell measurements */
245 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
246
Harald Welte2c828992009-12-02 01:56:49 +0530247 struct {
248 u_int32_t bound_ip;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100249 u_int32_t connect_ip;
Harald Welte2c828992009-12-02 01:56:49 +0530250 u_int16_t bound_port;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100251 u_int16_t connect_port;
Harald Welte2c828992009-12-02 01:56:49 +0530252 u_int16_t conn_id;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100253 u_int8_t rtp_payload2;
254 u_int8_t speech_mode;
Harald Welte2c828992009-12-02 01:56:49 +0530255 struct rtp_socket *rtp_socket;
256 } abis_ip;
Harald Welte8470bf22008-12-25 23:28:35 +0000257};
258
Harald Welte85770c72009-01-18 17:47:32 +0000259struct gsm_e1_subslot {
260 /* Number of E1 link */
261 u_int8_t e1_nr;
262 /* Number of E1 TS inside E1 link */
263 u_int8_t e1_ts;
264 /* Sub-slot within the E1 TS, 0xff if full TS */
265 u_int8_t e1_ts_ss;
266};
267
Harald Welte52b1f982008-12-23 20:25:15 +0000268#define BTS_TRX_F_ACTIVATED 0x0001
269/* One Timeslot in a TRX */
270struct gsm_bts_trx_ts {
271 struct gsm_bts_trx *trx;
272 /* number of this timeslot at the TRX */
273 u_int8_t nr;
274
Harald Welte8470bf22008-12-25 23:28:35 +0000275 enum gsm_phys_chan_config pchan;
276
Harald Welte52b1f982008-12-23 20:25:15 +0000277 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000278 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200279 struct tlv_parsed nm_attr;
Harald Welte39c7deb2009-08-09 21:49:48 +0200280 u_int8_t nm_chan_comb;
Harald Welte8470bf22008-12-25 23:28:35 +0000281
Harald Welte85770c72009-01-18 17:47:32 +0000282 /* To which E1 subslot are we connected */
283 struct gsm_e1_subslot e1_link;
284
Harald Welte8470bf22008-12-25 23:28:35 +0000285 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000286};
287
288/* One TRX in a BTS */
289struct gsm_bts_trx {
Harald Weltee441d9c2009-06-21 16:17:15 +0200290 /* list header in bts->trx_list */
291 struct llist_head list;
292
Harald Welte52b1f982008-12-23 20:25:15 +0000293 struct gsm_bts *bts;
294 /* number of this TRX in the BTS */
295 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000296 /* how do we talk RSL with this TRX? */
Harald Welte42581822009-08-08 16:12:58 +0200297 struct gsm_e1_subslot rsl_e1_link;
298 u_int8_t rsl_tei;
Harald Welte1fa60c82009-02-09 18:13:26 +0000299 struct e1inp_sign_link *rsl_link;
Harald Welte42581822009-08-08 16:12:58 +0200300
Harald Weltebbcc7a52009-02-14 19:45:44 +0000301 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200302 struct tlv_parsed nm_attr;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000303 struct {
304 struct gsm_nm_state nm_state;
305 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000306
307 u_int16_t arfcn;
Harald Weltefcd24452009-06-20 18:15:19 +0200308 int nominal_power; /* in dBm */
309 unsigned int max_power_red; /* in actual dB */
Harald Welte8b697c72009-06-05 19:18:45 +0000310
311 union {
312 struct {
313 struct {
314 struct gsm_nm_state nm_state;
315 } bbsig;
316 struct {
317 struct gsm_nm_state nm_state;
318 } pa;
319 } bs11;
320 };
Harald Welte85770c72009-01-18 17:47:32 +0000321 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000322};
323
Harald Welte978cb422009-01-18 17:57:27 +0000324enum gsm_bts_type {
325 GSM_BTS_TYPE_UNKNOWN,
326 GSM_BTS_TYPE_BS11,
Mike Habene2d82272009-10-02 12:19:34 +0100327 GSM_BTS_TYPE_NANOBTS,
Harald Welte978cb422009-01-18 17:57:27 +0000328};
329
Harald Welte39315c42010-01-10 18:01:52 +0100330struct gsm_bts_model {
331 struct llist_head list;
332
333 enum gsm_bts_type type;
334 const char *name;
335
336 struct tlv_definition nm_att_tlvdef;
337};
338
Holger Freytherceb59b72009-02-06 18:54:00 +0000339/**
340 * A pending paging request
341 */
342struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000343 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000344 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000345 /* the subscriber which we're paging. Later gsm_paging_request
346 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000347 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000348 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000349 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000350 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000351 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000352
353 /* Timer 3113: how long do we try to page? */
354 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000355
356 /* callback to be called in case paging completes */
357 gsm_cbfn *cbfn;
358 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000359};
360
361/*
362 * This keeps track of the paging status of one BTS. It
363 * includes a number of pending requests, a back pointer
364 * to the gsm_bts, a timer and some more state.
365 */
366struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000367 /* pending requests */
368 struct llist_head pending_requests;
369 struct gsm_paging_request *last_request;
370 struct gsm_bts *bts;
371
Harald Welte75a1fa82009-02-17 01:39:41 +0000372 struct timer_list work_timer;
373
Holger Freyther392209c2009-02-10 00:06:19 +0000374 /* load */
375 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000376};
377
Harald Welte8b697c72009-06-05 19:18:45 +0000378struct gsm_envabtse {
379 struct gsm_nm_state nm_state;
380};
381
Harald Welte55dd4432009-10-24 10:19:14 +0200382struct gsm_bts_gprs_nsvc {
383 struct gsm_bts *bts;
384 int id;
385 struct gsm_nm_state nm_state;
386};
387
Harald Welte52b1f982008-12-23 20:25:15 +0000388/* One BTS */
389struct gsm_bts {
Harald Weltee441d9c2009-06-21 16:17:15 +0200390 /* list header in net->bts_list */
391 struct llist_head list;
392
Harald Welte52b1f982008-12-23 20:25:15 +0000393 struct gsm_network *network;
394 /* number of ths BTS in network */
395 u_int8_t nr;
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200396 /* Cell Identity */
397 u_int16_t cell_identity;
Harald Welte52b1f982008-12-23 20:25:15 +0000398 /* location area code of this BTS */
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200399 u_int16_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000400 /* Training Sequence Code */
401 u_int8_t tsc;
Harald Welte78f2f502009-05-23 16:56:52 +0000402 /* Base Station Identification Code (BSIC) */
403 u_int8_t bsic;
Harald Welte978cb422009-01-18 17:57:27 +0000404 /* type of BTS */
405 enum gsm_bts_type type;
Harald Welte39315c42010-01-10 18:01:52 +0100406 struct gsm_bts_model *model;
Harald Weltefcd24452009-06-20 18:15:19 +0200407 enum gsm_band band;
Harald Weltefc0d9522009-08-10 13:46:55 +0200408 /* should the channel allocator allocate channels from high TRX to TRX0,
409 * rather than starting from TRX0 and go upwards? */
410 int chan_alloc_reverse;
Harald Welte (local)0e451d02009-08-13 10:14:26 +0200411 /* maximum Tx power that the MS is permitted to use in this cell */
412 int ms_max_power;
Harald Weltefc0d9522009-08-10 13:46:55 +0200413
Harald Welte1fa60c82009-02-09 18:13:26 +0000414 /* how do we talk OML with this TRX? */
Harald Welte42581822009-08-08 16:12:58 +0200415 struct gsm_e1_subslot oml_e1_link;
416 u_int8_t oml_tei;
Harald Welte1fa60c82009-02-09 18:13:26 +0000417 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000418
419 /* Abis network management O&M handle */
420 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000421 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200422 struct tlv_parsed nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000423
Harald Welte52b1f982008-12-23 20:25:15 +0000424 /* number of this BTS on given E1 link */
425 u_int8_t bts_nr;
426
Holger Freytherceb59b72009-02-06 18:54:00 +0000427 /* paging state and control */
428 struct gsm_bts_paging_state paging;
429
Harald Welte52b1f982008-12-23 20:25:15 +0000430 /* CCCH is on C0 */
431 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000432
433 struct {
434 struct gsm_nm_state nm_state;
435 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000436
Harald Weltea43f7892009-12-01 18:04:30 +0530437 /* parameters from which we build SYSTEM INFORMATION */
438 struct {
439 struct gsm48_rach_control rach_control;
440 u_int8_t ncc_permitted;
441 struct gsm48_cell_sel_par cell_sel_par;
442 struct gsm48_cell_options cell_options;
443 struct gsm48_control_channel_descr chan_desc;
Harald Welte6c40def2009-12-14 22:07:14 +0100444 struct bitvec neigh_list;
445 struct bitvec cell_alloc;
446 struct {
447 /* bitmask large enough for all possible ARFCN's */
448 u_int8_t neigh_list[1024/8];
449 u_int8_t cell_alloc[1024/8];
450 } data;
Harald Weltea43f7892009-12-01 18:04:30 +0530451 } si_common;
452
Harald Welteedb37782009-05-01 14:59:07 +0000453 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
Harald Welte7b26bcb2009-05-28 11:39:21 +0000454 union {
455 struct {
456 u_int16_t site_id;
457 u_int16_t bts_id;
Harald Welte88a412a2009-12-16 17:32:37 +0100458 u_int32_t flags;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000459 } ip_access;
460 struct {
461 struct {
462 struct gsm_nm_state nm_state;
463 } cclk;
464 struct {
465 struct gsm_nm_state nm_state;
466 } rack;
Harald Welte8b697c72009-06-05 19:18:45 +0000467 struct gsm_envabtse envabtse[4];
Harald Welte7b26bcb2009-05-28 11:39:21 +0000468 } bs11;
469 };
Harald Welte55dd4432009-10-24 10:19:14 +0200470
471 /* Not entirely sure how ip.access specific this is */
472 struct {
473 struct {
474 struct gsm_nm_state nm_state;
475 } nse;
476 struct {
477 struct gsm_nm_state nm_state;
478 } cell;
479 struct gsm_bts_gprs_nsvc nsvc[2];
480 } gprs;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000481
Harald Welte52b1f982008-12-23 20:25:15 +0000482 /* transceivers */
483 int num_trx;
Harald Weltee441d9c2009-06-21 16:17:15 +0200484 struct llist_head trx_list;
Harald Welte52b1f982008-12-23 20:25:15 +0000485};
486
Harald Welte24ff6ee2009-12-22 00:41:05 +0100487/* Some statistics of our network */
488struct gsmnet_stats {
489 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100490 struct counter *total;
491 struct counter *no_channel;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100492 } chreq;
493 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100494 struct counter *attempted;
495 struct counter *no_channel; /* no channel available */
496 struct counter *timeout; /* T3103 timeout */
497 struct counter *completed; /* HO COMPL received */
498 struct counter *failed; /* HO FAIL received */
Harald Welte24ff6ee2009-12-22 00:41:05 +0100499 } handover;
500 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100501 struct counter *attach;
502 struct counter *normal;
503 struct counter *periodic;
504 struct counter *detach;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100505 } loc_upd_type;
506 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100507 struct counter *reject;
508 struct counter *accept;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100509 } loc_upd_resp;
510 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100511 struct counter *attempted;
512 struct counter *detached;
513 struct counter *completed;
514 struct counter *expired;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100515 } paging;
516 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100517 struct counter *submitted; /* MO SMS submissions */
518 struct counter *no_receiver;
519 struct counter *delivered; /* MT SMS deliveries */
520 struct counter *rp_err_mem;
521 struct counter *rp_err_other;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100522 } sms;
523 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100524 struct counter *dialled; /* total number of dialled calls */
525 struct counter *alerted; /* we alerted the other end */
526 struct counter *connected;/* how many calls were accepted */
Harald Welte24ff6ee2009-12-22 00:41:05 +0100527 } call;
528};
529
Harald Welte (local)69de3972009-08-12 14:42:23 +0200530enum gsm_auth_policy {
531 GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
532 GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
533 GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
534};
535
Harald Welteb84ddfc2009-12-01 17:36:54 +0530536#define GSM_T3101_DEFAULT 10
537#define GSM_T3113_DEFAULT 60
538
Harald Welte52b1f982008-12-23 20:25:15 +0000539struct gsm_network {
540 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000541 u_int16_t country_code;
542 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000543 char *name_long;
544 char *name_short;
Harald Welte (local)69de3972009-08-12 14:42:23 +0200545 enum gsm_auth_policy auth_policy;
Harald Welte1085c092009-11-18 20:33:19 +0100546 enum gsm48_reject_value reject_cause;
Harald Welte4381cfe2009-08-30 15:47:06 +0900547 int a5_encryption;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100548 int neci;
Harald Welte648b6ce2009-12-14 09:00:24 +0100549 int send_mm_info;
Harald Weltebc814502009-12-19 21:41:52 +0100550 struct {
551 int active;
Harald Weltef7c28b02009-12-21 13:30:17 +0100552 /* Window RXLEV averaging */
553 unsigned int win_rxlev_avg; /* number of SACCH frames */
554 /* Window RXQUAL averaging */
555 unsigned int win_rxqual_avg; /* number of SACCH frames */
556 /* Window RXLEV neighbouring cells averaging */
557 unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
558
559 /* how often should we check for power budget HO */
560 unsigned int pwr_interval; /* SACCH frames */
561 /* how much better does a neighbor cell have to be ? */
562 unsigned int pwr_hysteresis; /* dBm */
563 /* maximum distacne before we try a handover */
564 unsigned int max_distance; /* TA values */
Harald Weltebc814502009-12-19 21:41:52 +0100565 } handover;
Harald Welte52b1f982008-12-23 20:25:15 +0000566
Harald Welte24ff6ee2009-12-22 00:41:05 +0100567 struct gsmnet_stats stats;
568
Harald Welte4bfdfe72009-06-10 23:11:52 +0800569 /* layer 4 */
570 int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
571 struct llist_head upqueue;
572 struct llist_head trans_list;
573
Harald Welte52b1f982008-12-23 20:25:15 +0000574 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200575 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100576
577 /* timer values */
578 int T3101;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100579 int T3103;
580 int T3105;
581 int T3107;
582 int T3109;
583 int T3111;
584 int T3113;
585 int T3115;
586 int T3117;
587 int T3119;
588 int T3141;
Harald Welteeab84a12009-12-13 10:53:12 +0100589
590 /* Radio Resource Location Protocol (TS 04.31) */
591 struct {
592 enum rrlp_mode mode;
593 } rrlp;
Harald Welte52b1f982008-12-23 20:25:15 +0000594};
595
Harald Welte7e310b12009-03-30 20:56:32 +0000596#define SMS_HDR_SIZE 128
597#define SMS_TEXT_SIZE 256
598struct gsm_sms {
Harald Welted409be72009-11-07 00:06:19 +0900599 unsigned long long id;
Harald Welte7e310b12009-03-30 20:56:32 +0000600 struct gsm_subscriber *sender;
601 struct gsm_subscriber *receiver;
602
Harald Welteb9c758b2009-07-05 14:02:46 +0200603 unsigned long validity_minutes;
Harald Welte76042182009-08-08 16:03:15 +0200604 u_int8_t reply_path_req;
605 u_int8_t status_rep_req;
606 u_int8_t ud_hdr_ind;
607 u_int8_t protocol_id;
608 u_int8_t data_coding_scheme;
609 u_int8_t msg_ref;
610 char dest_addr[20+1]; /* DA LV is 12 bytes max, i.e. 10 bytes
611 * BCD == 20 bytes string */
612 u_int8_t user_data_len;
613 u_int8_t user_data[SMS_TEXT_SIZE];
Harald Weltef3efc592009-07-27 20:11:35 +0200614
Harald Welte7e310b12009-03-30 20:56:32 +0000615 char text[SMS_TEXT_SIZE];
616};
617
Harald Welte3606cc52009-12-05 15:13:22 +0530618
Harald Weltee441d9c2009-06-21 16:17:15 +0200619struct gsm_network *gsm_network_init(u_int16_t country_code, u_int16_t network_code,
Harald Welte4bfdfe72009-06-10 23:11:52 +0800620 int (*mncc_recv)(struct gsm_network *, int, void *));
Harald Weltee441d9c2009-06-21 16:17:15 +0200621struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type,
622 u_int8_t tsc, u_int8_t bsic);
623struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
Harald Welte39315c42010-01-10 18:01:52 +0100624int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +0200625
626struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Harald Welte84874c92009-12-14 22:33:02 +0100627
628/* Get reference to a neighbor cell on a given BCCH ARFCN */
Harald Welte0b121032009-12-15 00:21:31 +0100629struct gsm_bts *gsm_bts_neighbor(const struct gsm_bts *bts,
630 u_int16_t arfcn, u_int8_t bsic);
Harald Welte84874c92009-12-14 22:33:02 +0100631
Harald Weltee441d9c2009-06-21 16:17:15 +0200632struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
Harald Welte8470bf22008-12-25 23:28:35 +0000633
Harald Weltea72c98e2009-01-04 16:10:38 +0000634const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Harald Welte65da9122009-08-07 00:32:22 +0200635enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
Harald Welte (local)ccd88452009-12-27 18:05:25 +0100636const char *gsm_lchant_name(enum gsm_chan_t c);
Harald Weltea72c98e2009-01-04 16:10:38 +0000637const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte (local)d48f4eb2009-12-28 23:14:22 +0100638char *gsm_trx_name(struct gsm_bts_trx *trx);
Harald Welte23a68632009-02-19 17:06:42 +0000639char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Welte (local)19ef62a2009-12-27 18:16:36 +0100640char *gsm_lchan_name(struct gsm_lchan *lchan);
Harald Welte1887f9d2009-12-29 10:52:38 +0100641const char *gsm_lchans_name(enum gsm_lchan_state s);
Harald Weltea72c98e2009-01-04 16:10:38 +0000642
Harald Weltead384642008-12-26 10:20:07 +0000643enum gsm_e1_event {
644 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000645 EVT_E1_TEI_UP,
646 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000647};
648
Harald Weltecd06bfb2009-02-10 17:33:56 +0000649void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
650 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte1d014a52009-08-08 15:38:29 +0200651enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200652const char *btstype2str(enum gsm_bts_type type);
Harald Welte6e670aa2010-01-07 20:44:32 +0100653struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Harald Weltebe991492009-05-23 13:56:40 +0000654struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
655 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000656
Harald Weltefcd24452009-06-20 18:15:19 +0200657char *gsm_band_name(enum gsm_band band);
Harald Welte42581822009-08-08 16:12:58 +0200658enum gsm_band gsm_band_parse(const char *mhz);
Harald Weltefcd24452009-06-20 18:15:19 +0200659
Andreas Eversberg8226fa72009-06-29 15:19:38 +0200660extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +0100661extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +0200662
Harald Welte32201c12009-03-10 12:15:10 +0000663static inline int is_ipaccess_bts(struct gsm_bts *bts)
664{
665 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +0100666 case GSM_BTS_TYPE_NANOBTS:
Harald Welte32201c12009-03-10 12:15:10 +0000667 return 1;
668 default:
669 break;
670 }
671 return 0;
672}
673
Harald Welte5b570672009-08-10 10:08:01 +0200674static inline int is_siemens_bts(struct gsm_bts *bts)
675{
676 switch (bts->type) {
677 case GSM_BTS_TYPE_BS11:
678 return 1;
679 default:
680 break;
681 }
682
683 return 0;
684}
685
Harald Welte (local)69de3972009-08-12 14:42:23 +0200686
687enum gsm_auth_policy gsm_auth_policy_parse(const char *arg);
688const char *gsm_auth_policy_name(enum gsm_auth_policy policy);
689
Harald Welteeab84a12009-12-13 10:53:12 +0100690enum rrlp_mode rrlp_mode_parse(const char *arg);
691const char *rrlp_mode_name(enum rrlp_mode mode);
692
Holger Hans Peter Freyther2d501ea2009-11-11 11:54:24 +0100693void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked);
694
Harald Welted12b0fd2009-12-15 21:36:05 +0100695struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan);
696
Harald Welte52b1f982008-12-23 20:25:15 +0000697#endif