blob: 37c9ff2e55c51fb54d3934fc8af9346044688a64 [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
Harald Welte49f48b82009-02-17 15:29:33 +0000123struct gsm_lchan;
124struct gsm_subscriber;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800125struct gsm_mncc;
Harald Welte805f6442009-07-28 18:25:29 +0200126struct rtp_socket;
Harald Welte49f48b82009-02-17 15:29:33 +0000127
Harald Weltebbcc7a52009-02-14 19:45:44 +0000128/* Network Management State */
129struct gsm_nm_state {
130 u_int8_t operational;
131 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000132 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000133};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000134
Holger Freyther73487a22008-12-31 18:53:57 +0000135/*
136 * LOCATION UPDATING REQUEST state
137 *
138 * Our current operation is:
139 * - Get imei/tmsi
140 * - Accept/Reject according to global policy
141 */
142struct gsm_loc_updating_operation {
143 struct timer_list updating_timer;
Holger Hans Peter Freyther251aa912009-10-27 10:42:28 +0100144 unsigned int waiting_for_imsi : 1;
145 unsigned int waiting_for_imei : 1;
Holger Freyther73487a22008-12-31 18:53:57 +0000146};
147
Harald Weltef7c28b02009-12-21 13:30:17 +0100148/* Maximum number of neighbor cells whose average we track */
149#define MAX_NEIGH_MEAS 10
150/* Maximum size of the averaging window for neighbor cells */
151#define MAX_WIN_NEIGH_AVG 10
152
153/* processed neighbor measurements for one cell */
154struct neigh_meas_proc {
155 u_int16_t arfcn;
156 u_int8_t bsic;
157 u_int8_t rxlev[MAX_WIN_NEIGH_AVG];
158 unsigned int rxlev_cnt;
159 u_int8_t last_seen_nr;
160};
161
Harald Welte08d91a52009-08-30 15:37:11 +0900162#define MAX_A5_KEY_LEN (128/8)
163#define RSL_ENC_ALG_A5(x) (x+1)
164
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100165/* is the data link established? who established it? */
166#define LCHAN_SAPI_UNUSED 0
167#define LCHAN_SAPI_MS 1
168#define LCHAN_SAPI_NET 2
169
Harald Welteb8bfc562009-12-21 13:27:11 +0100170/* state of a logical channel */
171enum gsm_lchan_state {
172 LCHAN_S_NONE, /* channel is not active */
Harald Welte (local)3e460312009-12-27 18:12:29 +0100173 LCHAN_S_ACT_REQ, /* channel activatin requested */
Harald Welteb8bfc562009-12-21 13:27:11 +0100174 LCHAN_S_ACTIVE, /* channel is active and operational */
175 LCHAN_S_INACTIVE, /* channel is set inactive */
176};
177
Harald Welte8470bf22008-12-25 23:28:35 +0000178struct gsm_lchan {
179 /* The TS that we're part of */
180 struct gsm_bts_trx_ts *ts;
181 /* The logical subslot number in the TS */
182 u_int8_t nr;
Harald Welte45b407a2009-05-23 15:51:12 +0000183 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000184 enum gsm_chan_t type;
Harald Welte9943c5b2009-07-29 15:41:29 +0200185 /* RSL channel mode */
186 enum rsl_cmod_spd rsl_cmode;
Harald Welte45b407a2009-05-23 15:51:12 +0000187 /* If TCH, traffic channel mode */
Harald Welte9943c5b2009-07-29 15:41:29 +0200188 enum gsm48_chan_mode tch_mode;
Harald Welteb8bfc562009-12-21 13:27:11 +0100189 /* State */
190 enum gsm_lchan_state state;
Harald Welted4c9bf32009-02-15 16:56:18 +0000191 /* Power levels for MS and BTS */
192 u_int8_t bs_power;
193 u_int8_t ms_power;
Harald Welte08d91a52009-08-30 15:37:11 +0900194 /* Encryption information */
195 struct {
196 u_int8_t alg_id;
197 u_int8_t key_len;
198 u_int8_t key[MAX_A5_KEY_LEN];
199 } encr;
Holger Hans Peter Freytherea528022009-11-18 22:57:02 +0100200
201 /* AMR bits */
202 struct gsm48_multi_rate_conf mr_conf;
Harald Welted4c9bf32009-02-15 16:56:18 +0000203
Harald Welte8470bf22008-12-25 23:28:35 +0000204 /* To whom we are allocated at the moment */
205 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000206
207 /* Timer started to release the channel */
208 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000209
Harald Welteb7e81162009-08-10 00:26:10 +0200210 struct timer_list T3101;
211
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100212 /* Established data link layer services */
213 u_int8_t sapis[8];
214
Holger Freyther73487a22008-12-31 18:53:57 +0000215 /*
216 * Operations that have a state and might be pending
217 */
218 struct gsm_loc_updating_operation *loc_operation;
219
Holger Freytherb7193e42008-12-29 17:44:08 +0000220 /* use count. how many users use this channel */
221 unsigned int use_count;
Harald Welte2c828992009-12-02 01:56:49 +0530222
Harald Welted12b0fd2009-12-15 21:36:05 +0100223 /* cache of last measurement reports on this lchan */
224 struct gsm_meas_rep meas_rep[6];
225 int meas_rep_idx;
226
Harald Weltef7c28b02009-12-21 13:30:17 +0100227 /* table of neighbor cell measurements */
228 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
229
Harald Welte2c828992009-12-02 01:56:49 +0530230 struct {
231 u_int32_t bound_ip;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100232 u_int32_t connect_ip;
Harald Welte2c828992009-12-02 01:56:49 +0530233 u_int16_t bound_port;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100234 u_int16_t connect_port;
Harald Welte2c828992009-12-02 01:56:49 +0530235 u_int16_t conn_id;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100236 u_int8_t rtp_payload2;
237 u_int8_t speech_mode;
Harald Welte2c828992009-12-02 01:56:49 +0530238 struct rtp_socket *rtp_socket;
239 } abis_ip;
Harald Welte8470bf22008-12-25 23:28:35 +0000240};
241
Harald Welte85770c72009-01-18 17:47:32 +0000242struct gsm_e1_subslot {
243 /* Number of E1 link */
244 u_int8_t e1_nr;
245 /* Number of E1 TS inside E1 link */
246 u_int8_t e1_ts;
247 /* Sub-slot within the E1 TS, 0xff if full TS */
248 u_int8_t e1_ts_ss;
249};
250
Harald Welte52b1f982008-12-23 20:25:15 +0000251#define BTS_TRX_F_ACTIVATED 0x0001
252/* One Timeslot in a TRX */
253struct gsm_bts_trx_ts {
254 struct gsm_bts_trx *trx;
255 /* number of this timeslot at the TRX */
256 u_int8_t nr;
257
Harald Welte8470bf22008-12-25 23:28:35 +0000258 enum gsm_phys_chan_config pchan;
259
Harald Welte52b1f982008-12-23 20:25:15 +0000260 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000261 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200262 struct tlv_parsed nm_attr;
Harald Welte39c7deb2009-08-09 21:49:48 +0200263 u_int8_t nm_chan_comb;
Harald Welte8470bf22008-12-25 23:28:35 +0000264
Harald Welte85770c72009-01-18 17:47:32 +0000265 /* To which E1 subslot are we connected */
266 struct gsm_e1_subslot e1_link;
267
Harald Welte8470bf22008-12-25 23:28:35 +0000268 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000269};
270
271/* One TRX in a BTS */
272struct gsm_bts_trx {
Harald Weltee441d9c2009-06-21 16:17:15 +0200273 /* list header in bts->trx_list */
274 struct llist_head list;
275
Harald Welte52b1f982008-12-23 20:25:15 +0000276 struct gsm_bts *bts;
277 /* number of this TRX in the BTS */
278 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000279 /* how do we talk RSL with this TRX? */
Harald Welte42581822009-08-08 16:12:58 +0200280 struct gsm_e1_subslot rsl_e1_link;
281 u_int8_t rsl_tei;
Harald Welte1fa60c82009-02-09 18:13:26 +0000282 struct e1inp_sign_link *rsl_link;
Harald Welte42581822009-08-08 16:12:58 +0200283
Harald Weltebbcc7a52009-02-14 19:45:44 +0000284 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200285 struct tlv_parsed nm_attr;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000286 struct {
287 struct gsm_nm_state nm_state;
288 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000289
290 u_int16_t arfcn;
Harald Weltefcd24452009-06-20 18:15:19 +0200291 int nominal_power; /* in dBm */
292 unsigned int max_power_red; /* in actual dB */
Harald Welte8b697c72009-06-05 19:18:45 +0000293
294 union {
295 struct {
296 struct {
297 struct gsm_nm_state nm_state;
298 } bbsig;
299 struct {
300 struct gsm_nm_state nm_state;
301 } pa;
302 } bs11;
303 };
Harald Welte85770c72009-01-18 17:47:32 +0000304 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Holger Hans Peter Freyther2d501ea2009-11-11 11:54:24 +0100305
306 /* NM state */
307 int rf_locked;
Harald Welte52b1f982008-12-23 20:25:15 +0000308};
309
Harald Welte978cb422009-01-18 17:57:27 +0000310enum gsm_bts_type {
311 GSM_BTS_TYPE_UNKNOWN,
312 GSM_BTS_TYPE_BS11,
Mike Habene2d82272009-10-02 12:19:34 +0100313 GSM_BTS_TYPE_NANOBTS,
Harald Welte978cb422009-01-18 17:57:27 +0000314};
315
Holger Freytherceb59b72009-02-06 18:54:00 +0000316/**
317 * A pending paging request
318 */
319struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000320 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000321 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000322 /* the subscriber which we're paging. Later gsm_paging_request
323 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000324 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000325 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000326 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000327 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000328 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000329
330 /* Timer 3113: how long do we try to page? */
331 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000332
333 /* callback to be called in case paging completes */
334 gsm_cbfn *cbfn;
335 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000336};
337
338/*
339 * This keeps track of the paging status of one BTS. It
340 * includes a number of pending requests, a back pointer
341 * to the gsm_bts, a timer and some more state.
342 */
343struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000344 /* pending requests */
345 struct llist_head pending_requests;
346 struct gsm_paging_request *last_request;
347 struct gsm_bts *bts;
348
Harald Welte75a1fa82009-02-17 01:39:41 +0000349 struct timer_list work_timer;
350
Holger Freyther392209c2009-02-10 00:06:19 +0000351 /* load */
352 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000353};
354
Harald Welte8b697c72009-06-05 19:18:45 +0000355struct gsm_envabtse {
356 struct gsm_nm_state nm_state;
357};
358
Harald Welte55dd4432009-10-24 10:19:14 +0200359struct gsm_bts_gprs_nsvc {
360 struct gsm_bts *bts;
361 int id;
362 struct gsm_nm_state nm_state;
363};
364
Harald Welte52b1f982008-12-23 20:25:15 +0000365/* One BTS */
366struct gsm_bts {
Harald Weltee441d9c2009-06-21 16:17:15 +0200367 /* list header in net->bts_list */
368 struct llist_head list;
369
Harald Welte52b1f982008-12-23 20:25:15 +0000370 struct gsm_network *network;
371 /* number of ths BTS in network */
372 u_int8_t nr;
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200373 /* Cell Identity */
374 u_int16_t cell_identity;
Harald Welte52b1f982008-12-23 20:25:15 +0000375 /* location area code of this BTS */
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200376 u_int16_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000377 /* Training Sequence Code */
378 u_int8_t tsc;
Harald Welte78f2f502009-05-23 16:56:52 +0000379 /* Base Station Identification Code (BSIC) */
380 u_int8_t bsic;
Harald Welte978cb422009-01-18 17:57:27 +0000381 /* type of BTS */
382 enum gsm_bts_type type;
Harald Weltefcd24452009-06-20 18:15:19 +0200383 enum gsm_band band;
Harald Weltefc0d9522009-08-10 13:46:55 +0200384 /* should the channel allocator allocate channels from high TRX to TRX0,
385 * rather than starting from TRX0 and go upwards? */
386 int chan_alloc_reverse;
Harald Welte (local)0e451d02009-08-13 10:14:26 +0200387 /* maximum Tx power that the MS is permitted to use in this cell */
388 int ms_max_power;
Harald Weltefc0d9522009-08-10 13:46:55 +0200389
Harald Welte1fa60c82009-02-09 18:13:26 +0000390 /* how do we talk OML with this TRX? */
Harald Welte42581822009-08-08 16:12:58 +0200391 struct gsm_e1_subslot oml_e1_link;
392 u_int8_t oml_tei;
Harald Welte1fa60c82009-02-09 18:13:26 +0000393 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000394
395 /* Abis network management O&M handle */
396 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000397 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200398 struct tlv_parsed nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000399
Harald Welte52b1f982008-12-23 20:25:15 +0000400 /* number of this BTS on given E1 link */
401 u_int8_t bts_nr;
402
Holger Freytherceb59b72009-02-06 18:54:00 +0000403 /* paging state and control */
404 struct gsm_bts_paging_state paging;
405
Harald Welte52b1f982008-12-23 20:25:15 +0000406 /* CCCH is on C0 */
407 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000408
409 struct {
410 struct gsm_nm_state nm_state;
411 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000412
Harald Weltea43f7892009-12-01 18:04:30 +0530413 /* parameters from which we build SYSTEM INFORMATION */
414 struct {
415 struct gsm48_rach_control rach_control;
416 u_int8_t ncc_permitted;
417 struct gsm48_cell_sel_par cell_sel_par;
418 struct gsm48_cell_options cell_options;
419 struct gsm48_control_channel_descr chan_desc;
Harald Welte6c40def2009-12-14 22:07:14 +0100420 struct bitvec neigh_list;
421 struct bitvec cell_alloc;
422 struct {
423 /* bitmask large enough for all possible ARFCN's */
424 u_int8_t neigh_list[1024/8];
425 u_int8_t cell_alloc[1024/8];
426 } data;
Harald Weltea43f7892009-12-01 18:04:30 +0530427 } si_common;
428
Harald Welteedb37782009-05-01 14:59:07 +0000429 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
Harald Welte7b26bcb2009-05-28 11:39:21 +0000430 union {
431 struct {
432 u_int16_t site_id;
433 u_int16_t bts_id;
Harald Welte88a412a2009-12-16 17:32:37 +0100434 u_int32_t flags;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000435 } ip_access;
436 struct {
437 struct {
438 struct gsm_nm_state nm_state;
439 } cclk;
440 struct {
441 struct gsm_nm_state nm_state;
442 } rack;
Harald Welte8b697c72009-06-05 19:18:45 +0000443 struct gsm_envabtse envabtse[4];
Harald Welte7b26bcb2009-05-28 11:39:21 +0000444 } bs11;
445 };
Harald Welte55dd4432009-10-24 10:19:14 +0200446
447 /* Not entirely sure how ip.access specific this is */
448 struct {
449 struct {
450 struct gsm_nm_state nm_state;
451 } nse;
452 struct {
453 struct gsm_nm_state nm_state;
454 } cell;
455 struct gsm_bts_gprs_nsvc nsvc[2];
456 } gprs;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000457
Harald Welte52b1f982008-12-23 20:25:15 +0000458 /* transceivers */
459 int num_trx;
Harald Weltee441d9c2009-06-21 16:17:15 +0200460 struct llist_head trx_list;
Harald Welte52b1f982008-12-23 20:25:15 +0000461};
462
Harald Welte24ff6ee2009-12-22 00:41:05 +0100463/* Some statistics of our network */
464struct gsmnet_stats {
465 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100466 struct counter *total;
467 struct counter *no_channel;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100468 } chreq;
469 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100470 struct counter *attempted;
471 struct counter *no_channel; /* no channel available */
472 struct counter *timeout; /* T3103 timeout */
473 struct counter *completed; /* HO COMPL received */
474 struct counter *failed; /* HO FAIL received */
Harald Welte24ff6ee2009-12-22 00:41:05 +0100475 } handover;
476 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100477 struct counter *attach;
478 struct counter *normal;
479 struct counter *periodic;
480 struct counter *detach;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100481 } loc_upd_type;
482 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100483 struct counter *reject;
484 struct counter *accept;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100485 } loc_upd_resp;
486 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100487 struct counter *attempted;
488 struct counter *detached;
489 struct counter *completed;
490 struct counter *expired;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100491 } paging;
492 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100493 struct counter *submitted; /* MO SMS submissions */
494 struct counter *no_receiver;
495 struct counter *delivered; /* MT SMS deliveries */
496 struct counter *rp_err_mem;
497 struct counter *rp_err_other;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100498 } sms;
499 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100500 struct counter *dialled; /* total number of dialled calls */
501 struct counter *alerted; /* we alerted the other end */
502 struct counter *connected;/* how many calls were accepted */
Harald Welte24ff6ee2009-12-22 00:41:05 +0100503 } call;
504};
505
Harald Welte (local)69de3972009-08-12 14:42:23 +0200506enum gsm_auth_policy {
507 GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
508 GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
509 GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
510};
511
Harald Welteb84ddfc2009-12-01 17:36:54 +0530512#define GSM_T3101_DEFAULT 10
513#define GSM_T3113_DEFAULT 60
514
Harald Welte52b1f982008-12-23 20:25:15 +0000515struct gsm_network {
516 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000517 u_int16_t country_code;
518 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000519 char *name_long;
520 char *name_short;
Harald Welte (local)69de3972009-08-12 14:42:23 +0200521 enum gsm_auth_policy auth_policy;
Harald Welte1085c092009-11-18 20:33:19 +0100522 enum gsm48_reject_value reject_cause;
Harald Welte4381cfe2009-08-30 15:47:06 +0900523 int a5_encryption;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100524 int neci;
Harald Welte648b6ce2009-12-14 09:00:24 +0100525 int send_mm_info;
Harald Weltebc814502009-12-19 21:41:52 +0100526 struct {
527 int active;
Harald Weltef7c28b02009-12-21 13:30:17 +0100528 /* Window RXLEV averaging */
529 unsigned int win_rxlev_avg; /* number of SACCH frames */
530 /* Window RXQUAL averaging */
531 unsigned int win_rxqual_avg; /* number of SACCH frames */
532 /* Window RXLEV neighbouring cells averaging */
533 unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
534
535 /* how often should we check for power budget HO */
536 unsigned int pwr_interval; /* SACCH frames */
537 /* how much better does a neighbor cell have to be ? */
538 unsigned int pwr_hysteresis; /* dBm */
539 /* maximum distacne before we try a handover */
540 unsigned int max_distance; /* TA values */
Harald Weltebc814502009-12-19 21:41:52 +0100541 } handover;
Harald Welte52b1f982008-12-23 20:25:15 +0000542
Harald Welte24ff6ee2009-12-22 00:41:05 +0100543 struct gsmnet_stats stats;
544
Harald Welte4bfdfe72009-06-10 23:11:52 +0800545 /* layer 4 */
546 int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
547 struct llist_head upqueue;
548 struct llist_head trans_list;
549
Harald Welte52b1f982008-12-23 20:25:15 +0000550 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200551 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100552
553 /* timer values */
554 int T3101;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100555 int T3103;
556 int T3105;
557 int T3107;
558 int T3109;
559 int T3111;
560 int T3113;
561 int T3115;
562 int T3117;
563 int T3119;
564 int T3141;
Harald Welteeab84a12009-12-13 10:53:12 +0100565
566 /* Radio Resource Location Protocol (TS 04.31) */
567 struct {
568 enum rrlp_mode mode;
569 } rrlp;
Harald Welte52b1f982008-12-23 20:25:15 +0000570};
571
Harald Welte7e310b12009-03-30 20:56:32 +0000572#define SMS_HDR_SIZE 128
573#define SMS_TEXT_SIZE 256
574struct gsm_sms {
Harald Welted409be72009-11-07 00:06:19 +0900575 unsigned long long id;
Harald Welte7e310b12009-03-30 20:56:32 +0000576 struct gsm_subscriber *sender;
577 struct gsm_subscriber *receiver;
578
Harald Welteb9c758b2009-07-05 14:02:46 +0200579 unsigned long validity_minutes;
Harald Welte76042182009-08-08 16:03:15 +0200580 u_int8_t reply_path_req;
581 u_int8_t status_rep_req;
582 u_int8_t ud_hdr_ind;
583 u_int8_t protocol_id;
584 u_int8_t data_coding_scheme;
585 u_int8_t msg_ref;
586 char dest_addr[20+1]; /* DA LV is 12 bytes max, i.e. 10 bytes
587 * BCD == 20 bytes string */
588 u_int8_t user_data_len;
589 u_int8_t user_data[SMS_TEXT_SIZE];
Harald Weltef3efc592009-07-27 20:11:35 +0200590
Harald Welte7e310b12009-03-30 20:56:32 +0000591 char text[SMS_TEXT_SIZE];
592};
593
Harald Welte3606cc52009-12-05 15:13:22 +0530594enum gsm_auth_algo {
595 AUTH_ALGO_NONE,
596 AUTH_ALGO_XOR,
597 AUTH_ALGO_COMP128v1,
598};
599
600/* Real authentication information containing Ki */
601struct gsm_auth_info {
602 enum gsm_auth_algo auth_algo;
603 unsigned int a3a8_ki_len;
604 u_int8_t a3a8_ki[16];
605};
606
607struct gsm_auth_tuple {
608 u_int8_t rand[16];
609 u_int8_t sres[8];
610 u_int8_t kc[8];
611};
612
Harald Weltee441d9c2009-06-21 16:17:15 +0200613struct gsm_network *gsm_network_init(u_int16_t country_code, u_int16_t network_code,
Harald Welte4bfdfe72009-06-10 23:11:52 +0800614 int (*mncc_recv)(struct gsm_network *, int, void *));
Harald Weltee441d9c2009-06-21 16:17:15 +0200615struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type,
616 u_int8_t tsc, u_int8_t bsic);
617struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
618
619struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Harald Welte84874c92009-12-14 22:33:02 +0100620
621/* Get reference to a neighbor cell on a given BCCH ARFCN */
Harald Welte0b121032009-12-15 00:21:31 +0100622struct gsm_bts *gsm_bts_neighbor(const struct gsm_bts *bts,
623 u_int16_t arfcn, u_int8_t bsic);
Harald Welte84874c92009-12-14 22:33:02 +0100624
Harald Weltee441d9c2009-06-21 16:17:15 +0200625struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
Harald Welte8470bf22008-12-25 23:28:35 +0000626
Harald Weltea72c98e2009-01-04 16:10:38 +0000627const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Harald Welte65da9122009-08-07 00:32:22 +0200628enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
Harald Welte (local)ccd88452009-12-27 18:05:25 +0100629const char *gsm_lchant_name(enum gsm_chan_t c);
Harald Weltea72c98e2009-01-04 16:10:38 +0000630const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte23a68632009-02-19 17:06:42 +0000631char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Weltea72c98e2009-01-04 16:10:38 +0000632
Harald Weltead384642008-12-26 10:20:07 +0000633enum gsm_e1_event {
634 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000635 EVT_E1_TEI_UP,
636 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000637};
638
Harald Weltecd06bfb2009-02-10 17:33:56 +0000639void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
640 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte1d014a52009-08-08 15:38:29 +0200641enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200642const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000643struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
644 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000645
Harald Weltefcd24452009-06-20 18:15:19 +0200646char *gsm_band_name(enum gsm_band band);
Harald Welte42581822009-08-08 16:12:58 +0200647enum gsm_band gsm_band_parse(const char *mhz);
Harald Weltefcd24452009-06-20 18:15:19 +0200648
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 Welte52b1f982008-12-23 20:25:15 +0000686#endif