blob: 52b82c062a547b89222b31d7c574525154fc350e [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
Harald Welte4511d892010-04-18 15:51:20 +020076enum bts_gprs_mode {
77 BTS_GPRS_NONE = 0,
78 BTS_GPRS_GPRS = 1,
79 BTS_GPRS_EGPRS = 2,
80};
81
Harald Welte8e1e3ee2009-02-01 13:32:45 +000082struct msgb;
83typedef int gsm_cbfn(unsigned int hooknum,
84 unsigned int event,
85 struct msgb *msg,
86 void *data, void *param);
87
Holger Freytherc6ea9db2008-12-30 19:18:21 +000088/*
89 * Use the channel. As side effect the lchannel recycle timer
90 * will be started.
91 */
Harald Welteb9c758b2009-07-05 14:02:46 +020092#define LCHAN_RELEASE_TIMEOUT 20, 0
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010093#define use_subscr_con(con) \
94 do { (con)->use_count++; \
Harald Welted0c19142009-12-24 11:46:44 +010095 DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010096 (con)->lchan->ts->trx->bts->nr, (con)->lchan->ts->trx->nr, (con)->lchan->ts->nr, \
97 (con)->lchan->nr, (con)->use_count); \
98 bsc_schedule_timer(&(con)->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
Holger Freytherc6ea9db2008-12-30 19:18:21 +000099
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100100#define put_subscr_con(con) \
101 do { (con)->use_count--; \
Harald Welted0c19142009-12-24 11:46:44 +0100102 DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100103 (con)->lchan->ts->trx->bts->nr, (con)->lchan->ts->trx->nr, (con)->lchan->ts->nr, \
104 (con)->lchan->nr, (con)->use_count); \
Holger Freyther4f584c32009-06-02 02:55:07 +0000105 } while(0);
106
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000107
Harald Welte52b1f982008-12-23 20:25:15 +0000108/* communications link with a BTS */
109struct gsm_bts_link {
110 struct gsm_bts *bts;
111};
112
Sylvain Munaut47193072009-12-27 21:56:14 +0100113/* Real authentication information containing Ki */
114enum gsm_auth_algo {
115 AUTH_ALGO_NONE,
116 AUTH_ALGO_XOR,
117 AUTH_ALGO_COMP128v1,
118};
119
120struct gsm_auth_info {
121 enum gsm_auth_algo auth_algo;
122 unsigned int a3a8_ki_len;
123 u_int8_t a3a8_ki[16];
124};
125
126struct gsm_auth_tuple {
127 int use_count;
128 int key_seq;
129 u_int8_t rand[16];
130 u_int8_t sres[4];
131 u_int8_t kc[8];
132};
133
134
Harald Welte49f48b82009-02-17 15:29:33 +0000135struct gsm_lchan;
136struct gsm_subscriber;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800137struct gsm_mncc;
Harald Welte805f6442009-07-28 18:25:29 +0200138struct rtp_socket;
Harald Welte49f48b82009-02-17 15:29:33 +0000139
Harald Weltebbcc7a52009-02-14 19:45:44 +0000140/* Network Management State */
141struct gsm_nm_state {
142 u_int8_t operational;
143 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000144 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000145};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000146
Holger Freyther73487a22008-12-31 18:53:57 +0000147/*
148 * LOCATION UPDATING REQUEST state
149 *
150 * Our current operation is:
151 * - Get imei/tmsi
152 * - Accept/Reject according to global policy
153 */
154struct gsm_loc_updating_operation {
155 struct timer_list updating_timer;
Holger Hans Peter Freyther251aa912009-10-27 10:42:28 +0100156 unsigned int waiting_for_imsi : 1;
157 unsigned int waiting_for_imei : 1;
Holger Freyther73487a22008-12-31 18:53:57 +0000158};
159
Harald Weltef7c28b02009-12-21 13:30:17 +0100160/* Maximum number of neighbor cells whose average we track */
161#define MAX_NEIGH_MEAS 10
162/* Maximum size of the averaging window for neighbor cells */
163#define MAX_WIN_NEIGH_AVG 10
164
165/* processed neighbor measurements for one cell */
166struct neigh_meas_proc {
167 u_int16_t arfcn;
168 u_int8_t bsic;
169 u_int8_t rxlev[MAX_WIN_NEIGH_AVG];
170 unsigned int rxlev_cnt;
171 u_int8_t last_seen_nr;
172};
173
Harald Welte08d91a52009-08-30 15:37:11 +0900174#define MAX_A5_KEY_LEN (128/8)
175#define RSL_ENC_ALG_A5(x) (x+1)
176
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100177/* is the data link established? who established it? */
178#define LCHAN_SAPI_UNUSED 0
179#define LCHAN_SAPI_MS 1
180#define LCHAN_SAPI_NET 2
181
Harald Welteb8bfc562009-12-21 13:27:11 +0100182/* state of a logical channel */
183enum gsm_lchan_state {
184 LCHAN_S_NONE, /* channel is not active */
Harald Welte (local)3e460312009-12-27 18:12:29 +0100185 LCHAN_S_ACT_REQ, /* channel activatin requested */
Harald Welteb8bfc562009-12-21 13:27:11 +0100186 LCHAN_S_ACTIVE, /* channel is active and operational */
Harald Welte8e93b792009-12-29 10:44:17 +0100187 LCHAN_S_REL_REQ, /* channel release has been requested */
Harald Welteb8bfc562009-12-21 13:27:11 +0100188 LCHAN_S_INACTIVE, /* channel is set inactive */
189};
190
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100191/* the per subscriber data for lchan */
192struct gsm_subscriber_connection {
193 /* To whom we are allocated at the moment */
194 struct gsm_subscriber *subscr;
195
196 /* Timer started to release the channel */
197 struct timer_list release_timer;
198
199 /*
200 * Operations that have a state and might be pending
201 */
202 struct gsm_loc_updating_operation *loc_operation;
203
204 /* use count. how many users use this channel */
205 unsigned int use_count;
206
207 /* Are we part of a special "silent" call */
208 int silent_call;
209
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100210 /* back pointers */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100211 struct gsm_lchan *lchan;
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100212 struct gsm_bts *bts;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100213};
214
Harald Welte8470bf22008-12-25 23:28:35 +0000215struct gsm_lchan {
216 /* The TS that we're part of */
217 struct gsm_bts_trx_ts *ts;
218 /* The logical subslot number in the TS */
219 u_int8_t nr;
Harald Welte45b407a2009-05-23 15:51:12 +0000220 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000221 enum gsm_chan_t type;
Harald Welte9943c5b2009-07-29 15:41:29 +0200222 /* RSL channel mode */
223 enum rsl_cmod_spd rsl_cmode;
Harald Welte45b407a2009-05-23 15:51:12 +0000224 /* If TCH, traffic channel mode */
Harald Welte9943c5b2009-07-29 15:41:29 +0200225 enum gsm48_chan_mode tch_mode;
Harald Welteb8bfc562009-12-21 13:27:11 +0100226 /* State */
227 enum gsm_lchan_state state;
Harald Welted4c9bf32009-02-15 16:56:18 +0000228 /* Power levels for MS and BTS */
229 u_int8_t bs_power;
230 u_int8_t ms_power;
Harald Welte08d91a52009-08-30 15:37:11 +0900231 /* Encryption information */
232 struct {
233 u_int8_t alg_id;
234 u_int8_t key_len;
235 u_int8_t key[MAX_A5_KEY_LEN];
236 } encr;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100237
238 struct timer_list T3101;
Holger Hans Peter Freytherea528022009-11-18 22:57:02 +0100239
240 /* AMR bits */
241 struct gsm48_multi_rate_conf mr_conf;
Harald Welted4c9bf32009-02-15 16:56:18 +0000242
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100243 /* Established data link layer services */
244 u_int8_t sapis[8];
245
Harald Welted12b0fd2009-12-15 21:36:05 +0100246 /* cache of last measurement reports on this lchan */
247 struct gsm_meas_rep meas_rep[6];
248 int meas_rep_idx;
249
Harald Weltef7c28b02009-12-21 13:30:17 +0100250 /* table of neighbor cell measurements */
251 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
252
Harald Welte2c828992009-12-02 01:56:49 +0530253 struct {
254 u_int32_t bound_ip;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100255 u_int32_t connect_ip;
Harald Welte2c828992009-12-02 01:56:49 +0530256 u_int16_t bound_port;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100257 u_int16_t connect_port;
Harald Welte2c828992009-12-02 01:56:49 +0530258 u_int16_t conn_id;
Sylvain Munautb54dda42009-12-20 22:06:40 +0100259 u_int8_t rtp_payload;
Harald Welte5e3d91b2009-12-19 16:42:06 +0100260 u_int8_t rtp_payload2;
261 u_int8_t speech_mode;
Harald Welte2c828992009-12-02 01:56:49 +0530262 struct rtp_socket *rtp_socket;
263 } abis_ip;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100264
265 struct gsm_subscriber_connection conn;
Harald Welte8470bf22008-12-25 23:28:35 +0000266};
267
Harald Welte85770c72009-01-18 17:47:32 +0000268struct gsm_e1_subslot {
269 /* Number of E1 link */
270 u_int8_t e1_nr;
271 /* Number of E1 TS inside E1 link */
272 u_int8_t e1_ts;
273 /* Sub-slot within the E1 TS, 0xff if full TS */
274 u_int8_t e1_ts_ss;
275};
276
Harald Welte4563eab2010-03-28 14:42:09 +0800277#define TS_F_PDCH_MODE 0x1000
Harald Welte52b1f982008-12-23 20:25:15 +0000278/* One Timeslot in a TRX */
279struct gsm_bts_trx_ts {
280 struct gsm_bts_trx *trx;
281 /* number of this timeslot at the TRX */
282 u_int8_t nr;
283
Harald Welte8470bf22008-12-25 23:28:35 +0000284 enum gsm_phys_chan_config pchan;
285
Harald Welte52b1f982008-12-23 20:25:15 +0000286 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000287 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200288 struct tlv_parsed nm_attr;
Harald Welte39c7deb2009-08-09 21:49:48 +0200289 u_int8_t nm_chan_comb;
Harald Welte8470bf22008-12-25 23:28:35 +0000290
Harald Welte85770c72009-01-18 17:47:32 +0000291 /* To which E1 subslot are we connected */
292 struct gsm_e1_subslot e1_link;
293
Harald Welte8470bf22008-12-25 23:28:35 +0000294 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000295};
296
297/* One TRX in a BTS */
298struct gsm_bts_trx {
Harald Weltee441d9c2009-06-21 16:17:15 +0200299 /* list header in bts->trx_list */
300 struct llist_head list;
301
Harald Welte52b1f982008-12-23 20:25:15 +0000302 struct gsm_bts *bts;
303 /* number of this TRX in the BTS */
304 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000305 /* how do we talk RSL with this TRX? */
Harald Welte42581822009-08-08 16:12:58 +0200306 struct gsm_e1_subslot rsl_e1_link;
307 u_int8_t rsl_tei;
Harald Welte1fa60c82009-02-09 18:13:26 +0000308 struct e1inp_sign_link *rsl_link;
Harald Welte42581822009-08-08 16:12:58 +0200309
Harald Weltebbcc7a52009-02-14 19:45:44 +0000310 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200311 struct tlv_parsed nm_attr;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000312 struct {
313 struct gsm_nm_state nm_state;
314 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000315
316 u_int16_t arfcn;
Harald Weltefcd24452009-06-20 18:15:19 +0200317 int nominal_power; /* in dBm */
318 unsigned int max_power_red; /* in actual dB */
Harald Welte8b697c72009-06-05 19:18:45 +0000319
320 union {
321 struct {
322 struct {
323 struct gsm_nm_state nm_state;
324 } bbsig;
325 struct {
326 struct gsm_nm_state nm_state;
327 } pa;
328 } bs11;
329 };
Harald Welte85770c72009-01-18 17:47:32 +0000330 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000331};
332
Harald Welte978cb422009-01-18 17:57:27 +0000333enum gsm_bts_type {
334 GSM_BTS_TYPE_UNKNOWN,
335 GSM_BTS_TYPE_BS11,
Mike Habene2d82272009-10-02 12:19:34 +0100336 GSM_BTS_TYPE_NANOBTS,
Harald Welte978cb422009-01-18 17:57:27 +0000337};
338
Harald Welte39315c42010-01-10 18:01:52 +0100339struct gsm_bts_model {
340 struct llist_head list;
341
342 enum gsm_bts_type type;
343 const char *name;
344
345 struct tlv_definition nm_att_tlvdef;
346};
347
Holger Freytherceb59b72009-02-06 18:54:00 +0000348/**
349 * A pending paging request
350 */
351struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000352 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000353 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000354 /* the subscriber which we're paging. Later gsm_paging_request
355 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000356 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000357 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000358 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000359 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000360 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000361
362 /* Timer 3113: how long do we try to page? */
363 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000364
365 /* callback to be called in case paging completes */
366 gsm_cbfn *cbfn;
367 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000368};
369
370/*
371 * This keeps track of the paging status of one BTS. It
372 * includes a number of pending requests, a back pointer
373 * to the gsm_bts, a timer and some more state.
374 */
375struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000376 /* pending requests */
377 struct llist_head pending_requests;
Holger Freytherceb59b72009-02-06 18:54:00 +0000378 struct gsm_bts *bts;
379
Harald Welte75a1fa82009-02-17 01:39:41 +0000380 struct timer_list work_timer;
381
Holger Freyther392209c2009-02-10 00:06:19 +0000382 /* load */
383 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000384};
385
Harald Welte8b697c72009-06-05 19:18:45 +0000386struct gsm_envabtse {
387 struct gsm_nm_state nm_state;
388};
389
Harald Welte55dd4432009-10-24 10:19:14 +0200390struct gsm_bts_gprs_nsvc {
391 struct gsm_bts *bts;
392 int id;
Harald Welte97a282b2010-03-14 15:37:43 +0800393 u_int16_t nsvci;
Harald Welteaf387632010-03-14 23:30:30 +0800394 u_int16_t local_port;
395 u_int16_t remote_port;
396 u_int32_t remote_ip;
Harald Welte55dd4432009-10-24 10:19:14 +0200397 struct gsm_nm_state nm_state;
398};
399
Harald Welte52b1f982008-12-23 20:25:15 +0000400/* One BTS */
401struct gsm_bts {
Harald Weltee441d9c2009-06-21 16:17:15 +0200402 /* list header in net->bts_list */
403 struct llist_head list;
404
Harald Welte52b1f982008-12-23 20:25:15 +0000405 struct gsm_network *network;
406 /* number of ths BTS in network */
407 u_int8_t nr;
Holger Hans Peter Freytherc4a49e32009-08-21 14:44:12 +0200408 /* Cell Identity */
409 u_int16_t cell_identity;
Harald Welte52b1f982008-12-23 20:25:15 +0000410 /* location area code of this BTS */
Holger Hans Peter Freyther0b7f4b32009-09-29 14:02:33 +0200411 u_int16_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000412 /* Training Sequence Code */
413 u_int8_t tsc;
Harald Welte78f2f502009-05-23 16:56:52 +0000414 /* Base Station Identification Code (BSIC) */
415 u_int8_t bsic;
Harald Welte978cb422009-01-18 17:57:27 +0000416 /* type of BTS */
417 enum gsm_bts_type type;
Harald Welte39315c42010-01-10 18:01:52 +0100418 struct gsm_bts_model *model;
Harald Weltefcd24452009-06-20 18:15:19 +0200419 enum gsm_band band;
Harald Weltefc0d9522009-08-10 13:46:55 +0200420 /* should the channel allocator allocate channels from high TRX to TRX0,
421 * rather than starting from TRX0 and go upwards? */
422 int chan_alloc_reverse;
Harald Welte (local)0e451d02009-08-13 10:14:26 +0200423 /* maximum Tx power that the MS is permitted to use in this cell */
424 int ms_max_power;
Harald Weltefc0d9522009-08-10 13:46:55 +0200425
Harald Welte1fa60c82009-02-09 18:13:26 +0000426 /* how do we talk OML with this TRX? */
Harald Welte42581822009-08-08 16:12:58 +0200427 struct gsm_e1_subslot oml_e1_link;
428 u_int8_t oml_tei;
Harald Welte1fa60c82009-02-09 18:13:26 +0000429 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000430
431 /* Abis network management O&M handle */
432 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000433 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200434 struct tlv_parsed nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000435
Harald Welte52b1f982008-12-23 20:25:15 +0000436 /* number of this BTS on given E1 link */
437 u_int8_t bts_nr;
438
Holger Freytherceb59b72009-02-06 18:54:00 +0000439 /* paging state and control */
440 struct gsm_bts_paging_state paging;
441
Harald Welte52b1f982008-12-23 20:25:15 +0000442 /* CCCH is on C0 */
443 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000444
445 struct {
446 struct gsm_nm_state nm_state;
447 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000448
Harald Weltea43f7892009-12-01 18:04:30 +0530449 /* parameters from which we build SYSTEM INFORMATION */
450 struct {
451 struct gsm48_rach_control rach_control;
452 u_int8_t ncc_permitted;
453 struct gsm48_cell_sel_par cell_sel_par;
454 struct gsm48_cell_options cell_options;
455 struct gsm48_control_channel_descr chan_desc;
Harald Welte6c40def2009-12-14 22:07:14 +0100456 struct bitvec neigh_list;
457 struct bitvec cell_alloc;
458 struct {
459 /* bitmask large enough for all possible ARFCN's */
460 u_int8_t neigh_list[1024/8];
461 u_int8_t cell_alloc[1024/8];
462 } data;
Harald Weltea43f7892009-12-01 18:04:30 +0530463 } si_common;
464
Harald Welteedb37782009-05-01 14:59:07 +0000465 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
Harald Welte7b26bcb2009-05-28 11:39:21 +0000466 union {
467 struct {
468 u_int16_t site_id;
469 u_int16_t bts_id;
Harald Welte88a412a2009-12-16 17:32:37 +0100470 u_int32_t flags;
Harald Welte7b26bcb2009-05-28 11:39:21 +0000471 } ip_access;
472 struct {
473 struct {
474 struct gsm_nm_state nm_state;
475 } cclk;
476 struct {
477 struct gsm_nm_state nm_state;
478 } rack;
Harald Welte8b697c72009-06-05 19:18:45 +0000479 struct gsm_envabtse envabtse[4];
Harald Welte7b26bcb2009-05-28 11:39:21 +0000480 } bs11;
481 };
Harald Welte55dd4432009-10-24 10:19:14 +0200482
483 /* Not entirely sure how ip.access specific this is */
484 struct {
Harald Welte4511d892010-04-18 15:51:20 +0200485 enum bts_gprs_mode mode;
Harald Welte55dd4432009-10-24 10:19:14 +0200486 struct {
487 struct gsm_nm_state nm_state;
Harald Weltea5731cf2010-03-22 11:48:36 +0800488 u_int16_t nsei;
Harald Welte55dd4432009-10-24 10:19:14 +0200489 } nse;
490 struct {
491 struct gsm_nm_state nm_state;
Harald Welte97a282b2010-03-14 15:37:43 +0800492 u_int16_t bvci;
Harald Welte55dd4432009-10-24 10:19:14 +0200493 } cell;
494 struct gsm_bts_gprs_nsvc nsvc[2];
Harald Welte97a282b2010-03-14 15:37:43 +0800495 u_int8_t rac;
Harald Welte55dd4432009-10-24 10:19:14 +0200496 } gprs;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000497
Harald Welte52b1f982008-12-23 20:25:15 +0000498 /* transceivers */
499 int num_trx;
Harald Weltee441d9c2009-06-21 16:17:15 +0200500 struct llist_head trx_list;
Harald Welte52b1f982008-12-23 20:25:15 +0000501};
502
Harald Welte24ff6ee2009-12-22 00:41:05 +0100503/* Some statistics of our network */
504struct gsmnet_stats {
505 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100506 struct counter *total;
507 struct counter *no_channel;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100508 } chreq;
509 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100510 struct counter *attempted;
511 struct counter *no_channel; /* no channel available */
512 struct counter *timeout; /* T3103 timeout */
513 struct counter *completed; /* HO COMPL received */
514 struct counter *failed; /* HO FAIL received */
Harald Welte24ff6ee2009-12-22 00:41:05 +0100515 } handover;
516 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100517 struct counter *attach;
518 struct counter *normal;
519 struct counter *periodic;
520 struct counter *detach;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100521 } loc_upd_type;
522 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100523 struct counter *reject;
524 struct counter *accept;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100525 } loc_upd_resp;
526 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100527 struct counter *attempted;
528 struct counter *detached;
529 struct counter *completed;
530 struct counter *expired;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100531 } paging;
532 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100533 struct counter *submitted; /* MO SMS submissions */
534 struct counter *no_receiver;
535 struct counter *delivered; /* MT SMS deliveries */
536 struct counter *rp_err_mem;
537 struct counter *rp_err_other;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100538 } sms;
539 struct {
Harald Welteffa55a42009-12-22 19:07:32 +0100540 struct counter *dialled; /* total number of dialled calls */
541 struct counter *alerted; /* we alerted the other end */
542 struct counter *connected;/* how many calls were accepted */
Harald Welte24ff6ee2009-12-22 00:41:05 +0100543 } call;
Holger Hans Peter Freyther3ba36d52010-04-17 06:48:29 +0200544 struct {
545 struct counter *rf_fail;
546 struct counter *rll_err;
547 } chan;
Holger Hans Peter Freytherbb110f92010-04-12 10:45:52 +0200548 struct {
549 struct counter *oml_fail;
550 struct counter *rsl_fail;
551 } bts;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100552};
553
Harald Welte (local)69de3972009-08-12 14:42:23 +0200554enum gsm_auth_policy {
555 GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
556 GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
557 GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
558};
559
Harald Welteb84ddfc2009-12-01 17:36:54 +0530560#define GSM_T3101_DEFAULT 10
561#define GSM_T3113_DEFAULT 60
562
Harald Welte52b1f982008-12-23 20:25:15 +0000563struct gsm_network {
564 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000565 u_int16_t country_code;
566 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000567 char *name_long;
568 char *name_short;
Harald Welte (local)69de3972009-08-12 14:42:23 +0200569 enum gsm_auth_policy auth_policy;
Harald Welte1085c092009-11-18 20:33:19 +0100570 enum gsm48_reject_value reject_cause;
Harald Welte4381cfe2009-08-30 15:47:06 +0900571 int a5_encryption;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100572 int neci;
Harald Welte648b6ce2009-12-14 09:00:24 +0100573 int send_mm_info;
Harald Weltebc814502009-12-19 21:41:52 +0100574 struct {
575 int active;
Harald Weltef7c28b02009-12-21 13:30:17 +0100576 /* Window RXLEV averaging */
577 unsigned int win_rxlev_avg; /* number of SACCH frames */
578 /* Window RXQUAL averaging */
579 unsigned int win_rxqual_avg; /* number of SACCH frames */
580 /* Window RXLEV neighbouring cells averaging */
581 unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
582
583 /* how often should we check for power budget HO */
584 unsigned int pwr_interval; /* SACCH frames */
585 /* how much better does a neighbor cell have to be ? */
586 unsigned int pwr_hysteresis; /* dBm */
587 /* maximum distacne before we try a handover */
588 unsigned int max_distance; /* TA values */
Harald Weltebc814502009-12-19 21:41:52 +0100589 } handover;
Harald Welte52b1f982008-12-23 20:25:15 +0000590
Harald Welte24ff6ee2009-12-22 00:41:05 +0100591 struct gsmnet_stats stats;
592
Harald Welte4bfdfe72009-06-10 23:11:52 +0800593 /* layer 4 */
594 int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
595 struct llist_head upqueue;
596 struct llist_head trans_list;
597
Harald Welte52b1f982008-12-23 20:25:15 +0000598 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200599 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100600
601 /* timer values */
602 int T3101;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100603 int T3103;
604 int T3105;
605 int T3107;
606 int T3109;
607 int T3111;
608 int T3113;
609 int T3115;
610 int T3117;
611 int T3119;
612 int T3141;
Harald Welteeab84a12009-12-13 10:53:12 +0100613
614 /* Radio Resource Location Protocol (TS 04.31) */
615 struct {
616 enum rrlp_mode mode;
617 } rrlp;
Harald Welte52b1f982008-12-23 20:25:15 +0000618};
619
Harald Welte7e310b12009-03-30 20:56:32 +0000620#define SMS_HDR_SIZE 128
621#define SMS_TEXT_SIZE 256
622struct gsm_sms {
Harald Welted409be72009-11-07 00:06:19 +0900623 unsigned long long id;
Harald Welte7e310b12009-03-30 20:56:32 +0000624 struct gsm_subscriber *sender;
625 struct gsm_subscriber *receiver;
626
Harald Welteb9c758b2009-07-05 14:02:46 +0200627 unsigned long validity_minutes;
Harald Welte76042182009-08-08 16:03:15 +0200628 u_int8_t reply_path_req;
629 u_int8_t status_rep_req;
630 u_int8_t ud_hdr_ind;
631 u_int8_t protocol_id;
632 u_int8_t data_coding_scheme;
633 u_int8_t msg_ref;
634 char dest_addr[20+1]; /* DA LV is 12 bytes max, i.e. 10 bytes
635 * BCD == 20 bytes string */
636 u_int8_t user_data_len;
637 u_int8_t user_data[SMS_TEXT_SIZE];
Harald Weltef3efc592009-07-27 20:11:35 +0200638
Harald Welte7e310b12009-03-30 20:56:32 +0000639 char text[SMS_TEXT_SIZE];
640};
641
Harald Welte3606cc52009-12-05 15:13:22 +0530642
Harald Weltee441d9c2009-06-21 16:17:15 +0200643struct gsm_network *gsm_network_init(u_int16_t country_code, u_int16_t network_code,
Harald Welte4bfdfe72009-06-10 23:11:52 +0800644 int (*mncc_recv)(struct gsm_network *, int, void *));
Harald Weltee441d9c2009-06-21 16:17:15 +0200645struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type,
646 u_int8_t tsc, u_int8_t bsic);
647struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
Harald Welte39315c42010-01-10 18:01:52 +0100648int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +0200649
650struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Harald Welte84874c92009-12-14 22:33:02 +0100651
652/* Get reference to a neighbor cell on a given BCCH ARFCN */
Harald Welte0b121032009-12-15 00:21:31 +0100653struct gsm_bts *gsm_bts_neighbor(const struct gsm_bts *bts,
654 u_int16_t arfcn, u_int8_t bsic);
Harald Welte84874c92009-12-14 22:33:02 +0100655
Harald Weltee441d9c2009-06-21 16:17:15 +0200656struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
Harald Welte8470bf22008-12-25 23:28:35 +0000657
Harald Weltea72c98e2009-01-04 16:10:38 +0000658const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Harald Welte65da9122009-08-07 00:32:22 +0200659enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
Harald Welte (local)ccd88452009-12-27 18:05:25 +0100660const char *gsm_lchant_name(enum gsm_chan_t c);
Harald Weltea72c98e2009-01-04 16:10:38 +0000661const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte (local)d48f4eb2009-12-28 23:14:22 +0100662char *gsm_trx_name(struct gsm_bts_trx *trx);
Harald Welte23a68632009-02-19 17:06:42 +0000663char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Welte (local)19ef62a2009-12-27 18:16:36 +0100664char *gsm_lchan_name(struct gsm_lchan *lchan);
Harald Welte1887f9d2009-12-29 10:52:38 +0100665const char *gsm_lchans_name(enum gsm_lchan_state s);
Harald Weltea72c98e2009-01-04 16:10:38 +0000666
Harald Weltead384642008-12-26 10:20:07 +0000667enum gsm_e1_event {
668 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000669 EVT_E1_TEI_UP,
670 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000671};
672
Harald Weltecd06bfb2009-02-10 17:33:56 +0000673void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
674 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte1d014a52009-08-08 15:38:29 +0200675enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200676const char *btstype2str(enum gsm_bts_type type);
Harald Welte6e670aa2010-01-07 20:44:32 +0100677struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Harald Weltebe991492009-05-23 13:56:40 +0000678struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
679 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000680
Andreas Eversberg8226fa72009-06-29 15:19:38 +0200681extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +0100682extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +0200683
Harald Welte32201c12009-03-10 12:15:10 +0000684static inline int is_ipaccess_bts(struct gsm_bts *bts)
685{
686 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +0100687 case GSM_BTS_TYPE_NANOBTS:
Harald Welte32201c12009-03-10 12:15:10 +0000688 return 1;
689 default:
690 break;
691 }
692 return 0;
693}
694
Harald Welte5b570672009-08-10 10:08:01 +0200695static inline int is_siemens_bts(struct gsm_bts *bts)
696{
697 switch (bts->type) {
698 case GSM_BTS_TYPE_BS11:
699 return 1;
700 default:
701 break;
702 }
703
704 return 0;
705}
706
Harald Welte (local)69de3972009-08-12 14:42:23 +0200707
708enum gsm_auth_policy gsm_auth_policy_parse(const char *arg);
709const char *gsm_auth_policy_name(enum gsm_auth_policy policy);
710
Harald Welteeab84a12009-12-13 10:53:12 +0100711enum rrlp_mode rrlp_mode_parse(const char *arg);
712const char *rrlp_mode_name(enum rrlp_mode mode);
713
Harald Welte4511d892010-04-18 15:51:20 +0200714enum bts_gprs_mode bts_gprs_mode_parse(const char *arg);
715const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
716
Holger Hans Peter Freyther2d501ea2009-11-11 11:54:24 +0100717void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked);
718
Harald Welte97a282b2010-03-14 15:37:43 +0800719/* A parsed GPRS routing area */
720struct gprs_ra_id {
721 u_int16_t mnc;
722 u_int16_t mcc;
723 u_int16_t lac;
724 u_int8_t rac;
725};
726
727int gsm48_ra_id_by_bts(u_int8_t *buf, struct gsm_bts *bts);
728void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +0100729struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan);
730
Harald Weltefbda4e12010-03-04 11:04:52 +0100731int gsm_bts_model_register(struct gsm_bts_model *model);
732
Harald Welte52b1f982008-12-23 20:25:15 +0000733#endif