blob: dbc85eda322ebc89446f90d847ea194a31afa1b2 [file] [log] [blame]
Harald Welte6be350c2011-05-25 13:10:08 +02001#ifndef _GSM_DATA_SHAREDH
2#define _GSM_DATA_SHAREDH
3
4#include <stdbool.h>
5#include <stdint.h>
6
7#include <osmocom/core/timer.h>
8#include <osmocom/core/bitvec.h>
9#include <osmocom/core/statistics.h>
10#include <osmocom/core/utils.h>
11#include <osmocom/gsm/gsm_utils.h>
12#include <osmocom/gsm/tlv.h>
13#include <osmocom/gsm/rxlev_stat.h>
14#include <osmocom/gsm/sysinfo.h>
15
16#include <osmocom/gsm/protocol/gsm_08_58.h>
Harald Welte3300c012011-06-05 13:31:33 +020017#include <osmocom/gsm/protocol/gsm_12_21.h>
Harald Welte6be350c2011-05-25 13:10:08 +020018
19struct osmo_msc_data;
20struct osmo_bsc_sccp_con;
21struct gsm_sms_queue;
22
23/* RRLP mode of operation */
24enum rrlp_mode {
25 RRLP_MODE_NONE,
26 RRLP_MODE_MS_BASED,
27 RRLP_MODE_MS_PREF,
28 RRLP_MODE_ASS_PREF,
29};
30
31/* Channel Request reason */
32enum gsm_chreq_reason_t {
33 GSM_CHREQ_REASON_EMERG,
34 GSM_CHREQ_REASON_PAG,
35 GSM_CHREQ_REASON_CALL,
36 GSM_CHREQ_REASON_LOCATION_UPD,
37 GSM_CHREQ_REASON_OTHER,
38};
39
40#define TRX_NR_TS 8
41#define TS_MAX_LCHAN 8
42
43#define HARDCODED_ARFCN 123
44#define HARDCODED_TSC 7
45#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
46
47/* for multi-drop config */
48#define HARDCODED_BTS0_TS 1
49#define HARDCODED_BTS1_TS 6
50#define HARDCODED_BTS2_TS 11
51
52/* reserved according to GSM 03.03 ยง 2.4 */
53#define GSM_RESERVED_TMSI 0xFFFFFFFF
54
55enum gsm_hooks {
56 GSM_HOOK_NM_SWLOAD,
57 GSM_HOOK_RR_PAGING,
58 GSM_HOOK_RR_SECURITY,
59};
60
61enum gsm_paging_event {
62 GSM_PAGING_SUCCEEDED,
63 GSM_PAGING_EXPIRED,
64 GSM_PAGING_OOM,
65 GSM_PAGING_BUSY,
66};
67
68enum bts_gprs_mode {
69 BTS_GPRS_NONE = 0,
70 BTS_GPRS_GPRS = 1,
71 BTS_GPRS_EGPRS = 2,
72};
73
74struct gsm_lchan;
75struct gsm_subscriber;
76struct gsm_mncc;
77struct rtp_socket;
78struct bsc_api;
79
80/* Network Management State */
81struct gsm_nm_state {
82 uint8_t operational;
83 uint8_t administrative;
84 uint8_t availability;
85};
86
Harald Welted64c0bc2011-05-30 12:07:53 +020087struct gsm_abis_mo {
Harald Welte3300c012011-06-05 13:31:33 +020088 uint8_t obj_class;
89 struct abis_om_obj_inst obj_inst;
Harald Welted64c0bc2011-05-30 12:07:53 +020090 const char *name;
91 struct gsm_nm_state nm_state;
92 struct tlv_parsed *nm_attr;
Harald Welte32bc1162011-06-06 18:58:48 +020093 struct gsm_bts *bts;
Harald Welted64c0bc2011-05-30 12:07:53 +020094};
95
Harald Welte6be350c2011-05-25 13:10:08 +020096#define MAX_A5_KEY_LEN (128/8)
97#define A38_XOR_MIN_KEY_LEN 12
98#define A38_XOR_MAX_KEY_LEN 16
99#define A38_COMP128_KEY_LEN 16
100#define RSL_ENC_ALG_A5(x) (x+1)
101
102/* is the data link established? who established it? */
103#define LCHAN_SAPI_UNUSED 0
104#define LCHAN_SAPI_MS 1
105#define LCHAN_SAPI_NET 2
106
107/* state of a logical channel */
108enum gsm_lchan_state {
109 LCHAN_S_NONE, /* channel is not active */
110 LCHAN_S_ACT_REQ, /* channel activatin requested */
111 LCHAN_S_ACTIVE, /* channel is active and operational */
112 LCHAN_S_REL_REQ, /* channel release has been requested */
113 LCHAN_S_REL_ERR, /* channel is in an error state */
114 LCHAN_S_INACTIVE, /* channel is set inactive */
115};
116
Harald Welte6be350c2011-05-25 13:10:08 +0200117struct gsm_lchan {
118 /* The TS that we're part of */
119 struct gsm_bts_trx_ts *ts;
120 /* The logical subslot number in the TS */
121 uint8_t nr;
122 /* The logical channel type */
123 enum gsm_chan_t type;
124 /* RSL channel mode */
125 enum rsl_cmod_spd rsl_cmode;
126 /* If TCH, traffic channel mode */
127 enum gsm48_chan_mode tch_mode;
128 /* State */
129 enum gsm_lchan_state state;
130 /* Power levels for MS and BTS */
131 uint8_t bs_power;
132 uint8_t ms_power;
133 /* Encryption information */
134 struct {
135 uint8_t alg_id;
136 uint8_t key_len;
137 uint8_t key[MAX_A5_KEY_LEN];
138 } encr;
139
140 /* AMR bits */
141 struct gsm48_multi_rate_conf mr_conf;
142
143 /* Established data link layer services */
144 uint8_t sapis[8];
145 int sach_deact;
146 int release_reason;
147
148 struct {
149 uint32_t bound_ip;
150 uint32_t connect_ip;
151 uint16_t bound_port;
152 uint16_t connect_port;
153 uint16_t conn_id;
154 uint8_t rtp_payload;
155 uint8_t rtp_payload2;
156 uint8_t speech_mode;
157 struct rtp_socket *rtp_socket;
158 } abis_ip;
159
Harald Welte2c1ae472011-06-26 14:13:37 +0200160 uint8_t rqd_ta;
161
Harald Welte6be350c2011-05-25 13:10:08 +0200162#ifdef ROLE_BSC
163 struct osmo_timer_list T3101;
164 struct osmo_timer_list T3111;
165 struct osmo_timer_list error_timer;
166
167 /* table of neighbor cell measurements */
168 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
169
170 /* cache of last measurement reports on this lchan */
171 struct gsm_meas_rep meas_rep[6];
172 int meas_rep_idx;
173
174 /* GSM Random Access data */
175 struct gsm48_req_ref *rqd_ref;
Harald Welte6be350c2011-05-25 13:10:08 +0200176
177 struct gsm_subscriber_connection *conn;
Harald Weltef6093a42011-06-25 10:02:33 +0200178#else
179 struct lapdm_channel lapdm_ch;
Harald Welte2c1ae472011-06-26 14:13:37 +0200180 struct {
181 /* bitmask of all SI that are present/valid in si_buf */
182 uint32_t valid;
183 uint32_t last;
184 /* buffers where we put the pre-computed SI */
185 sysinfo_buf_t buf[_MAX_SYSINFO_TYPE];
186 } si;
Harald Welte6be350c2011-05-25 13:10:08 +0200187#endif
188};
189
190struct gsm_e1_subslot {
191 /* Number of E1 link */
192 uint8_t e1_nr;
193 /* Number of E1 TS inside E1 link */
194 uint8_t e1_ts;
195 /* Sub-slot within the E1 TS, 0xff if full TS */
196 uint8_t e1_ts_ss;
197};
198
199#define TS_F_PDCH_MODE 0x1000
200/* One Timeslot in a TRX */
201struct gsm_bts_trx_ts {
202 struct gsm_bts_trx *trx;
203 /* number of this timeslot at the TRX */
204 uint8_t nr;
205
206 enum gsm_phys_chan_config pchan;
207
208 unsigned int flags;
Harald Welted64c0bc2011-05-30 12:07:53 +0200209 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200210 struct tlv_parsed nm_attr;
211 uint8_t nm_chan_comb;
Harald Welte135a6482011-05-30 12:09:13 +0200212 int tsc; /* -1 == use BTS TSC */
Harald Welte6be350c2011-05-25 13:10:08 +0200213
214 struct {
215 /* Parameters below are configured by VTY */
216 int enabled;
217 uint8_t maio;
218 uint8_t hsn;
219 struct bitvec arfcns;
220 uint8_t arfcns_data[1024/8];
221 /* This is the pre-computed MA for channel assignments */
222 struct bitvec ma;
223 uint8_t ma_len; /* part of ma_data that is used */
224 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
225 } hopping;
226
227 /* To which E1 subslot are we connected */
228 struct gsm_e1_subslot e1_link;
229
230 struct gsm_lchan lchan[TS_MAX_LCHAN];
231};
232
233/* One TRX in a BTS */
234struct gsm_bts_trx {
235 /* list header in bts->trx_list */
236 struct llist_head list;
237
238 struct gsm_bts *bts;
239 /* number of this TRX in the BTS */
240 uint8_t nr;
241 /* human readable name / description */
242 char *description;
243 /* how do we talk RSL with this TRX? */
244 struct gsm_e1_subslot rsl_e1_link;
245 uint8_t rsl_tei;
246 struct e1inp_sign_link *rsl_link;
247 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
248 struct e1inp_sign_link *oml_link;
249
Harald Welted64c0bc2011-05-30 12:07:53 +0200250 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200251 struct tlv_parsed nm_attr;
252 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200253 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200254 } bb_transc;
255
256 uint16_t arfcn;
257 int nominal_power; /* in dBm */
258 unsigned int max_power_red; /* in actual dB */
259
Harald Welted134cc72011-06-07 00:12:53 +0200260 struct {
261 void *l1h;
262 } role_bts;
263
Harald Welte6be350c2011-05-25 13:10:08 +0200264 union {
265 struct {
266 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200267 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200268 } bbsig;
269 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200270 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200271 } pa;
272 } bs11;
273 struct {
274 unsigned int test_state;
275 uint8_t test_nr;
276 struct rxlev_stats rxlev_stat;
277 } ipaccess;
278 };
279 struct gsm_bts_trx_ts ts[TRX_NR_TS];
280};
281
282#define GSM_BTS_SI(bts, i) (void *)(bts->si_buf[i])
283
284enum gsm_bts_type {
285 GSM_BTS_TYPE_UNKNOWN,
286 GSM_BTS_TYPE_BS11,
287 GSM_BTS_TYPE_NANOBTS,
288 GSM_BTS_TYPE_RBS2000,
289 GSM_BTS_TYPE_HSL_FEMTO,
290};
291
292struct vty;
293
294struct gsm_bts_model {
295 struct llist_head list;
296
297 enum gsm_bts_type type;
298 const char *name;
299
300 bool started;
301 int (*start)(struct gsm_network *net);
302 int (*oml_rcvmsg)(struct msgb *msg);
303
304 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
305 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
306 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
307
308 struct tlv_definition nm_att_tlvdef;
309
310 struct bitvec features;
311 uint8_t _features_data[128/8];
312};
313
314enum gsm_bts_features {
315 BTS_FEAT_HSCSD,
316 BTS_FEAT_GPRS,
317 BTS_FEAT_EGPRS,
318 BTS_FEAT_ECSD,
319 BTS_FEAT_HOPPING,
320};
321
322/*
323 * This keeps track of the paging status of one BTS. It
324 * includes a number of pending requests, a back pointer
325 * to the gsm_bts, a timer and some more state.
326 */
327struct gsm_bts_paging_state {
328 /* pending requests */
329 struct llist_head pending_requests;
330 struct gsm_bts *bts;
331
332 struct osmo_timer_list work_timer;
333 struct osmo_timer_list credit_timer;
334
335 /* free chans needed */
336 int free_chans_need;
337
338 /* load */
339 uint16_t available_slots;
340};
341
342struct gsm_envabtse {
Harald Welted64c0bc2011-05-30 12:07:53 +0200343 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200344};
345
346struct gsm_bts_gprs_nsvc {
347 struct gsm_bts *bts;
348 /* data read via VTY config file, to configure the BTS
349 * via OML from BSC */
350 int id;
351 uint16_t nsvci;
352 uint16_t local_port; /* on the BTS */
353 uint16_t remote_port; /* on the SGSN */
354 uint32_t remote_ip; /* on the SGSN */
355
Harald Welted64c0bc2011-05-30 12:07:53 +0200356 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200357};
358
359enum neigh_list_manual_mode {
360 NL_MODE_AUTOMATIC = 0,
361 NL_MODE_MANUAL = 1,
362 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
363};
364
365/* One BTS */
366struct gsm_bts {
367 /* list header in net->bts_list */
368 struct llist_head list;
369
370 /* number of ths BTS in network */
371 uint8_t nr;
372 /* human readable name / description */
373 char *description;
374 /* Cell Identity */
375 uint16_t cell_identity;
376 /* location area code of this BTS */
377 uint16_t location_area_code;
378 /* Training Sequence Code */
379 uint8_t tsc;
380 /* Base Station Identification Code (BSIC) */
381 uint8_t bsic;
382 /* type of BTS */
383 enum gsm_bts_type type;
384 struct gsm_bts_model *model;
385 enum gsm_band band;
386 /* maximum Tx power that the MS is permitted to use in this cell */
387 int ms_max_power;
388
389 /* how do we talk OML with this TRX? */
390 struct gsm_e1_subslot oml_e1_link;
391 uint8_t oml_tei;
392 struct e1inp_sign_link *oml_link;
393
394 /* Abis network management O&M handle */
395 struct abis_nm_h *nmh;
Harald Welted64c0bc2011-05-30 12:07:53 +0200396
397 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200398
399 /* number of this BTS on given E1 link */
400 uint8_t bts_nr;
401
402 /* paging state and control */
403 struct gsm_bts_paging_state paging;
404
405 /* CCCH is on C0 */
406 struct gsm_bts_trx *c0;
407
408 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200409 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200410 } site_mgr;
411
412 /* bitmask of all SI that are present/valid in si_buf */
413 uint32_t si_valid;
414 /* buffers where we put the pre-computed SI */
415 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE];
416
417 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
418 union {
419 struct {
420 uint16_t site_id;
421 uint16_t bts_id;
422 uint32_t flags;
423 } ip_access;
424 struct {
425 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200426 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200427 } cclk;
428 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200429 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200430 } rack;
431 struct gsm_envabtse envabtse[4];
432 } bs11;
433 struct {
434 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200435 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200436 struct llist_head conn_groups;
437 } is;
438 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200439 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200440 struct llist_head conn_groups;
441 } con;
442 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200443 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200444 } dp;
445 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200446 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200447 } tf;
448 } rbs2000;
449 struct {
450 unsigned long serno;
451 } hsl;
452 };
453
454 /* Not entirely sure how ip.access specific this is */
455 struct {
456 enum bts_gprs_mode mode;
457 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200458 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200459 uint16_t nsei;
460 uint8_t timer[7];
461 } nse;
462 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200463 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200464 uint16_t bvci;
465 uint8_t timer[11];
466 } cell;
467 struct gsm_bts_gprs_nsvc nsvc[2];
468 uint8_t rac;
469 } gprs;
470
471 /* RACH NM values */
472 int rach_b_thresh;
473 int rach_ldavg_slots;
474
475 /* transceivers */
476 int num_trx;
477 struct llist_head trx_list;
478
479#ifdef ROLE_BSC
480 /* Abis NM queue */
481 struct llist_head abis_queue;
482 int abis_nm_pend;
483
484 struct gsm_network *network;
485
486 /* should the channel allocator allocate channels from high TRX to TRX0,
487 * rather than starting from TRX0 and go upwards? */
488 int chan_alloc_reverse;
489
490 enum neigh_list_manual_mode neigh_list_manual_mode;
491 /* parameters from which we build SYSTEM INFORMATION */
492 struct {
493 struct gsm48_rach_control rach_control;
494 uint8_t ncc_permitted;
495 struct gsm48_cell_sel_par cell_sel_par;
496 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
497 struct gsm48_cell_options cell_options;
498 struct gsm48_control_channel_descr chan_desc;
499 struct bitvec neigh_list;
500 struct bitvec cell_alloc;
501 struct bitvec si5_neigh_list;
502 struct {
503 /* bitmask large enough for all possible ARFCN's */
504 uint8_t neigh_list[1024/8];
505 uint8_t cell_alloc[1024/8];
506 /* If the user wants a different neighbor list in SI5 than in SI2 */
507 uint8_t si5_neigh_list[1024/8];
508 } data;
509 } si_common;
510
511 /* do we use static (user-defined) system information messages? (bitmask) */
512 uint32_t si_mode_static;
513#endif /* ROLE_BSC */
Harald Welte978714d2011-06-06 18:31:20 +0200514 void *role;
Harald Welte6be350c2011-05-25 13:10:08 +0200515};
516
517
Harald Welte3300c012011-06-05 13:31:33 +0200518struct gsm_bts *gsm_bts_alloc(void *talloc_ctx);
Harald Welte6be350c2011-05-25 13:10:08 +0200519struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
520
521struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
Harald Welte6be350c2011-05-25 13:10:08 +0200522
523const char *gsm_pchan_name(enum gsm_phys_chan_config c);
524enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
525const char *gsm_lchant_name(enum gsm_chan_t c);
526const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
527char *gsm_trx_name(struct gsm_bts_trx *trx);
528char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
529char *gsm_lchan_name(struct gsm_lchan *lchan);
530const char *gsm_lchans_name(enum gsm_lchan_state s);
531
Harald Welte6be350c2011-05-25 13:10:08 +0200532
Harald Welte978714d2011-06-06 18:31:20 +0200533struct gsm_abis_mo *
534gsm_objclass2mo(struct gsm_bts *bts, uint8_t obj_class,
535 struct abis_om_obj_inst *obj_inst);
536
537struct gsm_nm_state *
538gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
539 struct abis_om_obj_inst *obj_inst);
540void *
541gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
542 struct abis_om_obj_inst *obj_inst);
543
Harald Weltef6093a42011-06-25 10:02:33 +0200544uint8_t gsm_ts2chan_nr(const struct gsm_bts_trx_ts *ts, uint8_t lchan_nr);
545uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
546
Harald Welte6be350c2011-05-25 13:10:08 +0200547#endif