blob: db3eaff59329bd508f7b22ab32ff7ea9a44efe5f [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 Welte4bfdfe72009-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 Weltea1499d02009-10-24 10:25:50 +020013 GSM_PCHAN_PDCH, /* GPRS PDCH */
14 GSM_PCHAN_TCH_F_PDCH, /* TCH/F if used, PDCH otherwise */
Harald Welte4bfdfe72009-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 Welteeab84a12009-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 Welte4bfdfe72009-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 Weltedfe6c7d2010-02-20 16:24:02 +010043#include <osmocore/timer.h>
Holger Freyther1adb4ff2009-02-04 00:04:52 +000044#include <openbsc/gsm_04_08.h>
Harald Welte9943c5b2009-07-29 15:41:29 +020045#include <openbsc/abis_rsl.h>
Harald Welte4bfdfe72009-06-10 23:11:52 +080046#include <openbsc/mncc.h>
Harald Weltedfe6c7d2010-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 Welte8470bf22008-12-25 23:28:35 +000052
Harald Welte85770c72009-01-18 17:47:32 +000053#define TRX_NR_TS 8
Harald Welte8470bf22008-12-25 23:28:35 +000054#define TS_MAX_LCHAN 8
Harald Welte52b1f982008-12-23 20:25:15 +000055
56#define HARDCODED_ARFCN 123
Harald Welte02b0e092009-02-28 13:11:07 +000057#define HARDCODED_TSC 7
Harald Welte78f2f502009-05-23 16:56:52 +000058#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
Harald Welte52b1f982008-12-23 20:25:15 +000059
Harald Welte63589be2009-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 Welte8e1e3ee2009-02-01 13:32:45 +000065enum gsm_hooks {
66 GSM_HOOK_NM_SWLOAD,
Harald Welte0932d1e2009-02-16 22:53:52 +000067 GSM_HOOK_RR_PAGING,
68};
69
70enum gsm_paging_event {
71 GSM_PAGING_SUCCEEDED,
72 GSM_PAGING_EXPIRED,
Holger Freyther85a7b362009-04-18 13:48:55 +020073 GSM_PAGING_OOM,
Harald Welte8e1e3ee2009-02-01 13:32:45 +000074};
75
76struct msgb;
77typedef int gsm_cbfn(unsigned int hooknum,
78 unsigned int event,
79 struct msgb *msg,
80 void *data, void *param);
81
Holger Freytherc6ea9db2008-12-30 19:18:21 +000082/*
83 * Use the channel. As side effect the lchannel recycle timer
84 * will be started.
85 */
Harald Welteb9c758b2009-07-05 14:02:46 +020086#define LCHAN_RELEASE_TIMEOUT 20, 0
Holger Freytherc6ea9db2008-12-30 19:18:21 +000087#define use_lchan(lchan) \
88 do { lchan->use_count++; \
Harald Welted0c19142009-12-24 11:46:44 +010089 DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
Holger Freyther4f584c32009-06-02 02:55:07 +000090 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
91 lchan->nr, lchan->use_count); \
Harald Welteff117a82009-05-23 05:22:08 +000092 bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
Holger Freytherc6ea9db2008-12-30 19:18:21 +000093
94#define put_lchan(lchan) \
Holger Freyther4f584c32009-06-02 02:55:07 +000095 do { lchan->use_count--; \
Harald Welted0c19142009-12-24 11:46:44 +010096 DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
Holger Freyther4f584c32009-06-02 02:55:07 +000097 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
98 lchan->nr, lchan->use_count); \
99 } while(0);
100
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000101
Harald Welte52b1f982008-12-23 20:25:15 +0000102/* communications link with a BTS */
103struct gsm_bts_link {
104 struct gsm_bts *bts;
105};
106
Sylvain Munaut47193072009-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 Welte49f48b82009-02-17 15:29:33 +0000129struct gsm_lchan;
130struct gsm_subscriber;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800131struct gsm_mncc;
Harald Welte805f6442009-07-28 18:25:29 +0200132struct rtp_socket;
Harald Welte49f48b82009-02-17 15:29:33 +0000133
Harald Weltebbcc7a52009-02-14 19:45:44 +0000134/* Network Management State */
135struct gsm_nm_state {
136 u_int8_t operational;
137 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000138 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000139};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000140
Holger Freyther73487a22008-12-31 18:53:57 +0000141/*
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 Freyther251aa912009-10-27 10:42:28 +0100150 unsigned int waiting_for_imsi : 1;
151 unsigned int waiting_for_imei : 1;
Holger Freyther73487a22008-12-31 18:53:57 +0000152};
153
Harald Weltef7c28b02009-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 Welte08d91a52009-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 Freyther5ba6f482009-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 Welteb8bfc562009-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)3e460312009-12-27 18:12:29 +0100179 LCHAN_S_ACT_REQ, /* channel activatin requested */
Harald Welteb8bfc562009-12-21 13:27:11 +0100180 LCHAN_S_ACTIVE, /* channel is active and operational */
Harald Welte8e93b792009-12-29 10:44:17 +0100181 LCHAN_S_REL_REQ, /* channel release has been requested */
Harald Welteb8bfc562009-12-21 13:27:11 +0100182 LCHAN_S_INACTIVE, /* channel is set inactive */
183};
184
Harald Welte8470bf22008-12-25 23:28:35 +0000185struct gsm_lchan {
186 /* The TS that we're part of */
187 struct gsm_bts_trx_ts *ts;
188 /* The logical subslot number in the TS */
189 u_int8_t nr;
Harald Welte45b407a2009-05-23 15:51:12 +0000190 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000191 enum gsm_chan_t type;
Harald Welte9943c5b2009-07-29 15:41:29 +0200192 /* RSL channel mode */
193 enum rsl_cmod_spd rsl_cmode;
Harald Welte45b407a2009-05-23 15:51:12 +0000194 /* If TCH, traffic channel mode */
Harald Welte9943c5b2009-07-29 15:41:29 +0200195 enum gsm48_chan_mode tch_mode;
Harald Welteb8bfc562009-12-21 13:27:11 +0100196 /* State */
197 enum gsm_lchan_state state;
Harald Welted4c9bf32009-02-15 16:56:18 +0000198 /* Power levels for MS and BTS */
199 u_int8_t bs_power;
200 u_int8_t ms_power;
Harald Welte08d91a52009-08-30 15:37:11 +0900201 /* Encryption information */
202 struct {
203 u_int8_t alg_id;
204 u_int8_t key_len;
205 u_int8_t key[MAX_A5_KEY_LEN];
206 } encr;
Harald Welte83579ca2009-12-29 11:17:18 +0100207 /* Are we part of a special "silent" call */
208 int silent_call;
Holger Hans Peter Freytherea528022009-11-18 22:57:02 +0100209
210 /* AMR bits */
211 struct gsm48_multi_rate_conf mr_conf;
Harald Welted4c9bf32009-02-15 16:56:18 +0000212
Harald Welte8470bf22008-12-25 23:28:35 +0000213 /* To whom we are allocated at the moment */
214 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000215
216 /* Timer started to release the channel */
217 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000218
Harald Welteb7e81162009-08-10 00:26:10 +0200219 struct timer_list T3101;
220
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100221 /* Established data link layer services */
222 u_int8_t sapis[8];
223
Holger Freyther73487a22008-12-31 18:53:57 +0000224 /*
225 * Operations that have a state and might be pending
226 */
227 struct gsm_loc_updating_operation *loc_operation;
228
Holger Freytherb7193e42008-12-29 17:44:08 +0000229 /* use count. how many users use this channel */
230 unsigned int use_count;
Harald Welte2c828992009-12-02 01:56:49 +0530231
Harald Welted12b0fd2009-12-15 21:36:05 +0100232 /* cache of last measurement reports on this lchan */
233 struct gsm_meas_rep meas_rep[6];
234 int meas_rep_idx;
235
Harald Weltef7c28b02009-12-21 13:30:17 +0100236 /* table of neighbor cell measurements */
237 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
238
Harald Welte2c828992009-12-02 01:56:49 +0530239 struct {
240 u_int32_t bound_ip;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100241 u_int32_t connect_ip;
Harald Welte2c828992009-12-02 01:56:49 +0530242 u_int16_t bound_port;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100243 u_int16_t connect_port;
Harald Welte2c828992009-12-02 01:56:49 +0530244 u_int16_t conn_id;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100245 u_int8_t rtp_payload2;
246 u_int8_t speech_mode;
Harald Welte2c828992009-12-02 01:56:49 +0530247 struct rtp_socket *rtp_socket;
248 } abis_ip;
Harald Welte8470bf22008-12-25 23:28:35 +0000249};
250
Harald Welte85770c72009-01-18 17:47:32 +0000251struct gsm_e1_subslot {
252 /* Number of E1 link */
253 u_int8_t e1_nr;
254 /* Number of E1 TS inside E1 link */
255 u_int8_t e1_ts;
256 /* Sub-slot within the E1 TS, 0xff if full TS */
257 u_int8_t e1_ts_ss;
258};
259
Harald Welte52b1f982008-12-23 20:25:15 +0000260#define BTS_TRX_F_ACTIVATED 0x0001
261/* One Timeslot in a TRX */
262struct gsm_bts_trx_ts {
263 struct gsm_bts_trx *trx;
264 /* number of this timeslot at the TRX */
265 u_int8_t nr;
266
Harald Welte8470bf22008-12-25 23:28:35 +0000267 enum gsm_phys_chan_config pchan;
268
Harald Welte52b1f982008-12-23 20:25:15 +0000269 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000270 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200271 struct tlv_parsed nm_attr;
Harald Welte39c7deb2009-08-09 21:49:48 +0200272 u_int8_t nm_chan_comb;
Harald Welte8470bf22008-12-25 23:28:35 +0000273
Harald Welte85770c72009-01-18 17:47:32 +0000274 /* To which E1 subslot are we connected */
275 struct gsm_e1_subslot e1_link;
276
Harald Welte8470bf22008-12-25 23:28:35 +0000277 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000278};
279
280/* One TRX in a BTS */
281struct gsm_bts_trx {
Harald Weltee441d9c2009-06-21 16:17:15 +0200282 /* list header in bts->trx_list */
283 struct llist_head list;
284
Harald Welte52b1f982008-12-23 20:25:15 +0000285 struct gsm_bts *bts;
286 /* number of this TRX in the BTS */
287 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000288 /* how do we talk RSL with this TRX? */
Harald Welte42581822009-08-08 16:12:58 +0200289 struct gsm_e1_subslot rsl_e1_link;
290 u_int8_t rsl_tei;
Harald Welte1fa60c82009-02-09 18:13:26 +0000291 struct e1inp_sign_link *rsl_link;
Harald Welte42581822009-08-08 16:12:58 +0200292
Harald Weltebbcc7a52009-02-14 19:45:44 +0000293 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200294 struct tlv_parsed nm_attr;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000295 struct {
296 struct gsm_nm_state nm_state;
297 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000298
299 u_int16_t arfcn;
Harald Weltefcd24452009-06-20 18:15:19 +0200300 int nominal_power; /* in dBm */
301 unsigned int max_power_red; /* in actual dB */
Harald Welte8b697c72009-06-05 19:18:45 +0000302
303 union {
304 struct {
305 struct {
306 struct gsm_nm_state nm_state;
307 } bbsig;
308 struct {
309 struct gsm_nm_state nm_state;
310 } pa;
311 } bs11;
312 };
Harald Welte85770c72009-01-18 17:47:32 +0000313 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000314};
315
Harald Welte978cb422009-01-18 17:57:27 +0000316enum gsm_bts_type {
317 GSM_BTS_TYPE_UNKNOWN,
318 GSM_BTS_TYPE_BS11,
Mike Habene2d82272009-10-02 12:19:34 +0100319 GSM_BTS_TYPE_NANOBTS,
Harald Welte978cb422009-01-18 17:57:27 +0000320};
321
Harald Welte39315c42010-01-10 18:01:52 +0100322struct gsm_bts_model {
323 struct llist_head list;
324
325 enum gsm_bts_type type;
326 const char *name;
327
328 struct tlv_definition nm_att_tlvdef;
329};
330
Holger Freytherceb59b72009-02-06 18:54:00 +0000331/**
332 * A pending paging request
333 */
334struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000335 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000336 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000337 /* the subscriber which we're paging. Later gsm_paging_request
338 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000339 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000340 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000341 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000342 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000343 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000344
345 /* Timer 3113: how long do we try to page? */
346 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000347
348 /* callback to be called in case paging completes */
349 gsm_cbfn *cbfn;
350 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000351};
352
353/*
354 * This keeps track of the paging status of one BTS. It
355 * includes a number of pending requests, a back pointer
356 * to the gsm_bts, a timer and some more state.
357 */
358struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000359 /* pending requests */
360 struct llist_head pending_requests;
361 struct gsm_paging_request *last_request;
362 struct gsm_bts *bts;
363
Harald Welte75a1fa82009-02-17 01:39:41 +0000364 struct timer_list work_timer;
365
Holger Freyther392209c2009-02-10 00:06:19 +0000366 /* load */
367 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000368};
369
Harald Welte8b697c72009-06-05 19:18:45 +0000370struct gsm_envabtse {
371 struct gsm_nm_state nm_state;
372};
373
Harald Welte55dd4432009-10-24 10:19:14 +0200374struct gsm_bts_gprs_nsvc {
375 struct gsm_bts *bts;
376 int id;
377 struct gsm_nm_state nm_state;
378};
379
Harald Welte52b1f982008-12-23 20:25:15 +0000380/* One BTS */
381struct gsm_bts {
Harald Weltee441d9c2009-06-21 16:17:15 +0200382 /* list header in net->bts_list */
383 struct llist_head list;
384
Harald Welte52b1f982008-12-23 20:25:15 +0000385 struct gsm_network *network;
386 /* number of ths BTS in network */
387 u_int8_t nr;
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200388 /* Cell Identity */
389 u_int16_t cell_identity;
Harald Welte52b1f982008-12-23 20:25:15 +0000390 /* location area code of this BTS */
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200391 u_int16_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000392 /* Training Sequence Code */
393 u_int8_t tsc;
Harald Welte78f2f502009-05-23 16:56:52 +0000394 /* Base Station Identification Code (BSIC) */
395 u_int8_t bsic;
Harald Welte978cb422009-01-18 17:57:27 +0000396 /* type of BTS */
397 enum gsm_bts_type type;
Harald Welte39315c42010-01-10 18:01:52 +0100398 struct gsm_bts_model *model;
Harald Weltefcd24452009-06-20 18:15:19 +0200399 enum gsm_band band;
Harald Weltefc0d9522009-08-10 13:46:55 +0200400 /* should the channel allocator allocate channels from high TRX to TRX0,
401 * rather than starting from TRX0 and go upwards? */
402 int chan_alloc_reverse;
Harald Welte (local)0e451d02009-08-13 10:14:26 +0200403 /* maximum Tx power that the MS is permitted to use in this cell */
404 int ms_max_power;
Harald Weltefc0d9522009-08-10 13:46:55 +0200405
Harald Welte1fa60c82009-02-09 18:13:26 +0000406 /* how do we talk OML with this TRX? */
Harald Welte42581822009-08-08 16:12:58 +0200407 struct gsm_e1_subslot oml_e1_link;
408 u_int8_t oml_tei;
Harald Welte1fa60c82009-02-09 18:13:26 +0000409 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000410
411 /* Abis network management O&M handle */
412 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000413 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200414 struct tlv_parsed nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000415
Harald Welte52b1f982008-12-23 20:25:15 +0000416 /* number of this BTS on given E1 link */
417 u_int8_t bts_nr;
418
Holger Freytherceb59b72009-02-06 18:54:00 +0000419 /* paging state and control */
420 struct gsm_bts_paging_state paging;
421
Harald Welte52b1f982008-12-23 20:25:15 +0000422 /* CCCH is on C0 */
423 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000424
425 struct {
426 struct gsm_nm_state nm_state;
427 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000428
Harald Weltea43f7892009-12-01 18:04:30 +0530429 /* parameters from which we build SYSTEM INFORMATION */
430 struct {
431 struct gsm48_rach_control rach_control;
432 u_int8_t ncc_permitted;
433 struct gsm48_cell_sel_par cell_sel_par;
434 struct gsm48_cell_options cell_options;
435 struct gsm48_control_channel_descr chan_desc;
Harald Welte6c40def2009-12-14 22:07:14 +0100436 struct bitvec neigh_list;
437 struct bitvec cell_alloc;
438 struct {
439 /* bitmask large enough for all possible ARFCN's */
440 u_int8_t neigh_list[1024/8];
441 u_int8_t cell_alloc[1024/8];
442 } data;
Harald Weltea43f7892009-12-01 18:04:30 +0530443 } si_common;
444
Harald Welteedb37782009-05-01 14:59:07 +0000445 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
Harald Welte7b26bcb2009-05-28 11:39:21 +0000446 union {
447 struct {
448 u_int16_t site_id;
449 u_int16_t bts_id;
Harald Welte88a412a2009-12-16 17:32:37 +0100450 u_int32_t flags;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000451 } ip_access;
452 struct {
453 struct {
454 struct gsm_nm_state nm_state;
455 } cclk;
456 struct {
457 struct gsm_nm_state nm_state;
458 } rack;
Harald Welte8b697c72009-06-05 19:18:45 +0000459 struct gsm_envabtse envabtse[4];
Harald Welte7b26bcb2009-05-28 11:39:21 +0000460 } bs11;
461 };
Harald Welte55dd4432009-10-24 10:19:14 +0200462
463 /* Not entirely sure how ip.access specific this is */
464 struct {
465 struct {
466 struct gsm_nm_state nm_state;
467 } nse;
468 struct {
469 struct gsm_nm_state nm_state;
470 } cell;
471 struct gsm_bts_gprs_nsvc nsvc[2];
472 } gprs;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000473
Harald Welte52b1f982008-12-23 20:25:15 +0000474 /* transceivers */
475 int num_trx;
Harald Weltee441d9c2009-06-21 16:17:15 +0200476 struct llist_head trx_list;
Harald Welte52b1f982008-12-23 20:25:15 +0000477};
478
Harald Welte24ff6ee2009-12-22 00:41:05 +0100479/* Some statistics of our network */
480struct gsmnet_stats {
481 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100482 struct counter *total;
483 struct counter *no_channel;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100484 } chreq;
485 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100486 struct counter *attempted;
487 struct counter *no_channel; /* no channel available */
488 struct counter *timeout; /* T3103 timeout */
489 struct counter *completed; /* HO COMPL received */
490 struct counter *failed; /* HO FAIL received */
Harald Welte24ff6ee2009-12-22 00:41:05 +0100491 } handover;
492 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100493 struct counter *attach;
494 struct counter *normal;
495 struct counter *periodic;
496 struct counter *detach;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100497 } loc_upd_type;
498 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100499 struct counter *reject;
500 struct counter *accept;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100501 } loc_upd_resp;
502 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100503 struct counter *attempted;
504 struct counter *detached;
505 struct counter *completed;
506 struct counter *expired;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100507 } paging;
508 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100509 struct counter *submitted; /* MO SMS submissions */
510 struct counter *no_receiver;
511 struct counter *delivered; /* MT SMS deliveries */
512 struct counter *rp_err_mem;
513 struct counter *rp_err_other;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100514 } sms;
515 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100516 struct counter *dialled; /* total number of dialled calls */
517 struct counter *alerted; /* we alerted the other end */
518 struct counter *connected;/* how many calls were accepted */
Harald Welte24ff6ee2009-12-22 00:41:05 +0100519 } call;
520};
521
Harald Welte (local)69de3972009-08-12 14:42:23 +0200522enum gsm_auth_policy {
523 GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
524 GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
525 GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
526};
527
Harald Welteb84ddfc2009-12-01 17:36:54 +0530528#define GSM_T3101_DEFAULT 10
529#define GSM_T3113_DEFAULT 60
530
Harald Welte52b1f982008-12-23 20:25:15 +0000531struct gsm_network {
532 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000533 u_int16_t country_code;
534 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000535 char *name_long;
536 char *name_short;
Harald Welte (local)69de3972009-08-12 14:42:23 +0200537 enum gsm_auth_policy auth_policy;
Harald Welte1085c092009-11-18 20:33:19 +0100538 enum gsm48_reject_value reject_cause;
Harald Welte4381cfe2009-08-30 15:47:06 +0900539 int a5_encryption;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100540 int neci;
Harald Welte648b6ce2009-12-14 09:00:24 +0100541 int send_mm_info;
Harald Weltebc814502009-12-19 21:41:52 +0100542 struct {
543 int active;
Harald Weltef7c28b02009-12-21 13:30:17 +0100544 /* Window RXLEV averaging */
545 unsigned int win_rxlev_avg; /* number of SACCH frames */
546 /* Window RXQUAL averaging */
547 unsigned int win_rxqual_avg; /* number of SACCH frames */
548 /* Window RXLEV neighbouring cells averaging */
549 unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
550
551 /* how often should we check for power budget HO */
552 unsigned int pwr_interval; /* SACCH frames */
553 /* how much better does a neighbor cell have to be ? */
554 unsigned int pwr_hysteresis; /* dBm */
555 /* maximum distacne before we try a handover */
556 unsigned int max_distance; /* TA values */
Harald Weltebc814502009-12-19 21:41:52 +0100557 } handover;
Harald Welte52b1f982008-12-23 20:25:15 +0000558
Harald Welte24ff6ee2009-12-22 00:41:05 +0100559 struct gsmnet_stats stats;
560
Harald Welte4bfdfe72009-06-10 23:11:52 +0800561 /* layer 4 */
562 int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
563 struct llist_head upqueue;
564 struct llist_head trans_list;
565
Harald Welte52b1f982008-12-23 20:25:15 +0000566 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200567 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100568
569 /* timer values */
570 int T3101;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100571 int T3103;
572 int T3105;
573 int T3107;
574 int T3109;
575 int T3111;
576 int T3113;
577 int T3115;
578 int T3117;
579 int T3119;
580 int T3141;
Harald Welteeab84a12009-12-13 10:53:12 +0100581
582 /* Radio Resource Location Protocol (TS 04.31) */
583 struct {
584 enum rrlp_mode mode;
585 } rrlp;
Harald Welte52b1f982008-12-23 20:25:15 +0000586};
587
Harald Welte7e310b12009-03-30 20:56:32 +0000588#define SMS_HDR_SIZE 128
589#define SMS_TEXT_SIZE 256
590struct gsm_sms {
Harald Welted409be72009-11-07 00:06:19 +0900591 unsigned long long id;
Harald Welte7e310b12009-03-30 20:56:32 +0000592 struct gsm_subscriber *sender;
593 struct gsm_subscriber *receiver;
594
Harald Welteb9c758b2009-07-05 14:02:46 +0200595 unsigned long validity_minutes;
Harald Welte76042182009-08-08 16:03:15 +0200596 u_int8_t reply_path_req;
597 u_int8_t status_rep_req;
598 u_int8_t ud_hdr_ind;
599 u_int8_t protocol_id;
600 u_int8_t data_coding_scheme;
601 u_int8_t msg_ref;
602 char dest_addr[20+1]; /* DA LV is 12 bytes max, i.e. 10 bytes
603 * BCD == 20 bytes string */
604 u_int8_t user_data_len;
605 u_int8_t user_data[SMS_TEXT_SIZE];
Harald Weltef3efc592009-07-27 20:11:35 +0200606
Harald Welte7e310b12009-03-30 20:56:32 +0000607 char text[SMS_TEXT_SIZE];
608};
609
Harald Welte3606cc52009-12-05 15:13:22 +0530610
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);
Harald Welte39315c42010-01-10 18:01:52 +0100616int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +0200617
618struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Harald Welte84874c92009-12-14 22:33:02 +0100619
620/* Get reference to a neighbor cell on a given BCCH ARFCN */
Harald Welte0b121032009-12-15 00:21:31 +0100621struct gsm_bts *gsm_bts_neighbor(const struct gsm_bts *bts,
622 u_int16_t arfcn, u_int8_t bsic);
Harald Welte84874c92009-12-14 22:33:02 +0100623
Harald Weltee441d9c2009-06-21 16:17:15 +0200624struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
Harald Welte8470bf22008-12-25 23:28:35 +0000625
Harald Weltea72c98e2009-01-04 16:10:38 +0000626const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Harald Welte65da9122009-08-07 00:32:22 +0200627enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
Harald Welte (local)ccd88452009-12-27 18:05:25 +0100628const char *gsm_lchant_name(enum gsm_chan_t c);
Harald Weltea72c98e2009-01-04 16:10:38 +0000629const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte (local)d48f4eb2009-12-28 23:14:22 +0100630char *gsm_trx_name(struct gsm_bts_trx *trx);
Harald Welte23a68632009-02-19 17:06:42 +0000631char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Welte (local)19ef62a2009-12-27 18:16:36 +0100632char *gsm_lchan_name(struct gsm_lchan *lchan);
Harald Welte1887f9d2009-12-29 10:52:38 +0100633const char *gsm_lchans_name(enum gsm_lchan_state s);
Harald Weltea72c98e2009-01-04 16:10:38 +0000634
Harald Weltead384642008-12-26 10:20:07 +0000635enum gsm_e1_event {
636 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000637 EVT_E1_TEI_UP,
638 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000639};
640
Harald Weltecd06bfb2009-02-10 17:33:56 +0000641void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
642 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte1d014a52009-08-08 15:38:29 +0200643enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200644const char *btstype2str(enum gsm_bts_type type);
Harald Welte6e670aa2010-01-07 20:44:32 +0100645struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Harald Weltebe991492009-05-23 13:56:40 +0000646struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
647 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000648
Andreas Eversberg8226fa72009-06-29 15:19:38 +0200649extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +0100650extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +0200651
Harald Welte32201c12009-03-10 12:15:10 +0000652static inline int is_ipaccess_bts(struct gsm_bts *bts)
653{
654 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +0100655 case GSM_BTS_TYPE_NANOBTS:
Harald Welte32201c12009-03-10 12:15:10 +0000656 return 1;
657 default:
658 break;
659 }
660 return 0;
661}
662
Harald Welte5b570672009-08-10 10:08:01 +0200663static inline int is_siemens_bts(struct gsm_bts *bts)
664{
665 switch (bts->type) {
666 case GSM_BTS_TYPE_BS11:
667 return 1;
668 default:
669 break;
670 }
671
672 return 0;
673}
674
Harald Welte (local)69de3972009-08-12 14:42:23 +0200675
676enum gsm_auth_policy gsm_auth_policy_parse(const char *arg);
677const char *gsm_auth_policy_name(enum gsm_auth_policy policy);
678
Harald Welteeab84a12009-12-13 10:53:12 +0100679enum rrlp_mode rrlp_mode_parse(const char *arg);
680const char *rrlp_mode_name(enum rrlp_mode mode);
681
Holger Hans Peter Freyther2d501ea2009-11-11 11:54:24 +0100682void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked);
683
Harald Welted12b0fd2009-12-15 21:36:05 +0100684struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan);
685
Harald Weltefbda4e12010-03-04 11:04:52 +0100686int gsm_bts_model_register(struct gsm_bts_model *model);
687
Harald Welte52b1f982008-12-23 20:25:15 +0000688#endif