blob: ea4240d67eda03b9c016bda626ac0f0c58572fed [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>
17
18struct osmo_msc_data;
19struct osmo_bsc_sccp_con;
20struct gsm_sms_queue;
21
22/* RRLP mode of operation */
23enum rrlp_mode {
24 RRLP_MODE_NONE,
25 RRLP_MODE_MS_BASED,
26 RRLP_MODE_MS_PREF,
27 RRLP_MODE_ASS_PREF,
28};
29
30/* Channel Request reason */
31enum gsm_chreq_reason_t {
32 GSM_CHREQ_REASON_EMERG,
33 GSM_CHREQ_REASON_PAG,
34 GSM_CHREQ_REASON_CALL,
35 GSM_CHREQ_REASON_LOCATION_UPD,
36 GSM_CHREQ_REASON_OTHER,
37};
38
39#define TRX_NR_TS 8
40#define TS_MAX_LCHAN 8
41
42#define HARDCODED_ARFCN 123
43#define HARDCODED_TSC 7
44#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
45
46/* for multi-drop config */
47#define HARDCODED_BTS0_TS 1
48#define HARDCODED_BTS1_TS 6
49#define HARDCODED_BTS2_TS 11
50
51/* reserved according to GSM 03.03 ยง 2.4 */
52#define GSM_RESERVED_TMSI 0xFFFFFFFF
53
54enum gsm_hooks {
55 GSM_HOOK_NM_SWLOAD,
56 GSM_HOOK_RR_PAGING,
57 GSM_HOOK_RR_SECURITY,
58};
59
60enum gsm_paging_event {
61 GSM_PAGING_SUCCEEDED,
62 GSM_PAGING_EXPIRED,
63 GSM_PAGING_OOM,
64 GSM_PAGING_BUSY,
65};
66
67enum bts_gprs_mode {
68 BTS_GPRS_NONE = 0,
69 BTS_GPRS_GPRS = 1,
70 BTS_GPRS_EGPRS = 2,
71};
72
73struct gsm_lchan;
74struct gsm_subscriber;
75struct gsm_mncc;
76struct rtp_socket;
77struct bsc_api;
78
79/* Network Management State */
80struct gsm_nm_state {
81 uint8_t operational;
82 uint8_t administrative;
83 uint8_t availability;
84};
85
Harald Welted64c0bc2011-05-30 12:07:53 +020086struct gsm_abis_mo {
87 const char *name;
88 struct gsm_nm_state nm_state;
89 struct tlv_parsed *nm_attr;
90};
91
Harald Welte6be350c2011-05-25 13:10:08 +020092#define MAX_A5_KEY_LEN (128/8)
93#define A38_XOR_MIN_KEY_LEN 12
94#define A38_XOR_MAX_KEY_LEN 16
95#define A38_COMP128_KEY_LEN 16
96#define RSL_ENC_ALG_A5(x) (x+1)
97
98/* is the data link established? who established it? */
99#define LCHAN_SAPI_UNUSED 0
100#define LCHAN_SAPI_MS 1
101#define LCHAN_SAPI_NET 2
102
103/* state of a logical channel */
104enum gsm_lchan_state {
105 LCHAN_S_NONE, /* channel is not active */
106 LCHAN_S_ACT_REQ, /* channel activatin requested */
107 LCHAN_S_ACTIVE, /* channel is active and operational */
108 LCHAN_S_REL_REQ, /* channel release has been requested */
109 LCHAN_S_REL_ERR, /* channel is in an error state */
110 LCHAN_S_INACTIVE, /* channel is set inactive */
111};
112
Harald Welte6be350c2011-05-25 13:10:08 +0200113struct gsm_lchan {
114 /* The TS that we're part of */
115 struct gsm_bts_trx_ts *ts;
116 /* The logical subslot number in the TS */
117 uint8_t nr;
118 /* The logical channel type */
119 enum gsm_chan_t type;
120 /* RSL channel mode */
121 enum rsl_cmod_spd rsl_cmode;
122 /* If TCH, traffic channel mode */
123 enum gsm48_chan_mode tch_mode;
124 /* State */
125 enum gsm_lchan_state state;
126 /* Power levels for MS and BTS */
127 uint8_t bs_power;
128 uint8_t ms_power;
129 /* Encryption information */
130 struct {
131 uint8_t alg_id;
132 uint8_t key_len;
133 uint8_t key[MAX_A5_KEY_LEN];
134 } encr;
135
136 /* AMR bits */
137 struct gsm48_multi_rate_conf mr_conf;
138
139 /* Established data link layer services */
140 uint8_t sapis[8];
141 int sach_deact;
142 int release_reason;
143
144 struct {
145 uint32_t bound_ip;
146 uint32_t connect_ip;
147 uint16_t bound_port;
148 uint16_t connect_port;
149 uint16_t conn_id;
150 uint8_t rtp_payload;
151 uint8_t rtp_payload2;
152 uint8_t speech_mode;
153 struct rtp_socket *rtp_socket;
154 } abis_ip;
155
156#ifdef ROLE_BSC
157 struct osmo_timer_list T3101;
158 struct osmo_timer_list T3111;
159 struct osmo_timer_list error_timer;
160
161 /* table of neighbor cell measurements */
162 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
163
164 /* cache of last measurement reports on this lchan */
165 struct gsm_meas_rep meas_rep[6];
166 int meas_rep_idx;
167
168 /* GSM Random Access data */
169 struct gsm48_req_ref *rqd_ref;
170 uint8_t rqd_ta;
171
172 struct gsm_subscriber_connection *conn;
173#endif
174};
175
176struct gsm_e1_subslot {
177 /* Number of E1 link */
178 uint8_t e1_nr;
179 /* Number of E1 TS inside E1 link */
180 uint8_t e1_ts;
181 /* Sub-slot within the E1 TS, 0xff if full TS */
182 uint8_t e1_ts_ss;
183};
184
185#define TS_F_PDCH_MODE 0x1000
186/* One Timeslot in a TRX */
187struct gsm_bts_trx_ts {
188 struct gsm_bts_trx *trx;
189 /* number of this timeslot at the TRX */
190 uint8_t nr;
191
192 enum gsm_phys_chan_config pchan;
193
194 unsigned int flags;
Harald Welted64c0bc2011-05-30 12:07:53 +0200195 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200196 struct tlv_parsed nm_attr;
197 uint8_t nm_chan_comb;
Harald Welte135a6482011-05-30 12:09:13 +0200198 int tsc; /* -1 == use BTS TSC */
Harald Welte6be350c2011-05-25 13:10:08 +0200199
200 struct {
201 /* Parameters below are configured by VTY */
202 int enabled;
203 uint8_t maio;
204 uint8_t hsn;
205 struct bitvec arfcns;
206 uint8_t arfcns_data[1024/8];
207 /* This is the pre-computed MA for channel assignments */
208 struct bitvec ma;
209 uint8_t ma_len; /* part of ma_data that is used */
210 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
211 } hopping;
212
213 /* To which E1 subslot are we connected */
214 struct gsm_e1_subslot e1_link;
215
216 struct gsm_lchan lchan[TS_MAX_LCHAN];
217};
218
219/* One TRX in a BTS */
220struct gsm_bts_trx {
221 /* list header in bts->trx_list */
222 struct llist_head list;
223
224 struct gsm_bts *bts;
225 /* number of this TRX in the BTS */
226 uint8_t nr;
227 /* human readable name / description */
228 char *description;
229 /* how do we talk RSL with this TRX? */
230 struct gsm_e1_subslot rsl_e1_link;
231 uint8_t rsl_tei;
232 struct e1inp_sign_link *rsl_link;
233 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
234 struct e1inp_sign_link *oml_link;
235
Harald Welted64c0bc2011-05-30 12:07:53 +0200236 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200237 struct tlv_parsed nm_attr;
238 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200239 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200240 } bb_transc;
241
242 uint16_t arfcn;
243 int nominal_power; /* in dBm */
244 unsigned int max_power_red; /* in actual dB */
245
246 union {
247 struct {
248 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200249 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200250 } bbsig;
251 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200252 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200253 } pa;
254 } bs11;
255 struct {
256 unsigned int test_state;
257 uint8_t test_nr;
258 struct rxlev_stats rxlev_stat;
259 } ipaccess;
260 };
261 struct gsm_bts_trx_ts ts[TRX_NR_TS];
262};
263
264#define GSM_BTS_SI(bts, i) (void *)(bts->si_buf[i])
265
266enum gsm_bts_type {
267 GSM_BTS_TYPE_UNKNOWN,
268 GSM_BTS_TYPE_BS11,
269 GSM_BTS_TYPE_NANOBTS,
270 GSM_BTS_TYPE_RBS2000,
271 GSM_BTS_TYPE_HSL_FEMTO,
272};
273
274struct vty;
275
276struct gsm_bts_model {
277 struct llist_head list;
278
279 enum gsm_bts_type type;
280 const char *name;
281
282 bool started;
283 int (*start)(struct gsm_network *net);
284 int (*oml_rcvmsg)(struct msgb *msg);
285
286 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
287 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
288 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
289
290 struct tlv_definition nm_att_tlvdef;
291
292 struct bitvec features;
293 uint8_t _features_data[128/8];
294};
295
296enum gsm_bts_features {
297 BTS_FEAT_HSCSD,
298 BTS_FEAT_GPRS,
299 BTS_FEAT_EGPRS,
300 BTS_FEAT_ECSD,
301 BTS_FEAT_HOPPING,
302};
303
304/*
305 * This keeps track of the paging status of one BTS. It
306 * includes a number of pending requests, a back pointer
307 * to the gsm_bts, a timer and some more state.
308 */
309struct gsm_bts_paging_state {
310 /* pending requests */
311 struct llist_head pending_requests;
312 struct gsm_bts *bts;
313
314 struct osmo_timer_list work_timer;
315 struct osmo_timer_list credit_timer;
316
317 /* free chans needed */
318 int free_chans_need;
319
320 /* load */
321 uint16_t available_slots;
322};
323
324struct gsm_envabtse {
Harald Welted64c0bc2011-05-30 12:07:53 +0200325 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200326};
327
328struct gsm_bts_gprs_nsvc {
329 struct gsm_bts *bts;
330 /* data read via VTY config file, to configure the BTS
331 * via OML from BSC */
332 int id;
333 uint16_t nsvci;
334 uint16_t local_port; /* on the BTS */
335 uint16_t remote_port; /* on the SGSN */
336 uint32_t remote_ip; /* on the SGSN */
337
Harald Welted64c0bc2011-05-30 12:07:53 +0200338 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200339};
340
341enum neigh_list_manual_mode {
342 NL_MODE_AUTOMATIC = 0,
343 NL_MODE_MANUAL = 1,
344 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
345};
346
347/* One BTS */
348struct gsm_bts {
349 /* list header in net->bts_list */
350 struct llist_head list;
351
352 /* number of ths BTS in network */
353 uint8_t nr;
354 /* human readable name / description */
355 char *description;
356 /* Cell Identity */
357 uint16_t cell_identity;
358 /* location area code of this BTS */
359 uint16_t location_area_code;
360 /* Training Sequence Code */
361 uint8_t tsc;
362 /* Base Station Identification Code (BSIC) */
363 uint8_t bsic;
364 /* type of BTS */
365 enum gsm_bts_type type;
366 struct gsm_bts_model *model;
367 enum gsm_band band;
368 /* maximum Tx power that the MS is permitted to use in this cell */
369 int ms_max_power;
370
371 /* how do we talk OML with this TRX? */
372 struct gsm_e1_subslot oml_e1_link;
373 uint8_t oml_tei;
374 struct e1inp_sign_link *oml_link;
375
376 /* Abis network management O&M handle */
377 struct abis_nm_h *nmh;
Harald Welted64c0bc2011-05-30 12:07:53 +0200378
379 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200380
381 /* number of this BTS on given E1 link */
382 uint8_t bts_nr;
383
384 /* paging state and control */
385 struct gsm_bts_paging_state paging;
386
387 /* CCCH is on C0 */
388 struct gsm_bts_trx *c0;
389
390 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200391 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200392 } site_mgr;
393
394 /* bitmask of all SI that are present/valid in si_buf */
395 uint32_t si_valid;
396 /* buffers where we put the pre-computed SI */
397 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE];
398
399 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
400 union {
401 struct {
402 uint16_t site_id;
403 uint16_t bts_id;
404 uint32_t flags;
405 } ip_access;
406 struct {
407 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200408 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200409 } cclk;
410 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200411 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200412 } rack;
413 struct gsm_envabtse envabtse[4];
414 } bs11;
415 struct {
416 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200417 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200418 struct llist_head conn_groups;
419 } is;
420 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200421 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200422 struct llist_head conn_groups;
423 } con;
424 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200425 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200426 } dp;
427 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200428 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200429 } tf;
430 } rbs2000;
431 struct {
432 unsigned long serno;
433 } hsl;
434 };
435
436 /* Not entirely sure how ip.access specific this is */
437 struct {
438 enum bts_gprs_mode mode;
439 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200440 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200441 uint16_t nsei;
442 uint8_t timer[7];
443 } nse;
444 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200445 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200446 uint16_t bvci;
447 uint8_t timer[11];
448 } cell;
449 struct gsm_bts_gprs_nsvc nsvc[2];
450 uint8_t rac;
451 } gprs;
452
453 /* RACH NM values */
454 int rach_b_thresh;
455 int rach_ldavg_slots;
456
457 /* transceivers */
458 int num_trx;
459 struct llist_head trx_list;
460
461#ifdef ROLE_BSC
462 /* Abis NM queue */
463 struct llist_head abis_queue;
464 int abis_nm_pend;
465
466 struct gsm_network *network;
467
468 /* should the channel allocator allocate channels from high TRX to TRX0,
469 * rather than starting from TRX0 and go upwards? */
470 int chan_alloc_reverse;
471
472 enum neigh_list_manual_mode neigh_list_manual_mode;
473 /* parameters from which we build SYSTEM INFORMATION */
474 struct {
475 struct gsm48_rach_control rach_control;
476 uint8_t ncc_permitted;
477 struct gsm48_cell_sel_par cell_sel_par;
478 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
479 struct gsm48_cell_options cell_options;
480 struct gsm48_control_channel_descr chan_desc;
481 struct bitvec neigh_list;
482 struct bitvec cell_alloc;
483 struct bitvec si5_neigh_list;
484 struct {
485 /* bitmask large enough for all possible ARFCN's */
486 uint8_t neigh_list[1024/8];
487 uint8_t cell_alloc[1024/8];
488 /* If the user wants a different neighbor list in SI5 than in SI2 */
489 uint8_t si5_neigh_list[1024/8];
490 } data;
491 } si_common;
492
493 /* do we use static (user-defined) system information messages? (bitmask) */
494 uint32_t si_mode_static;
495#endif /* ROLE_BSC */
496};
497
498
499
500struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type,
501 uint8_t tsc, uint8_t bsic);
502struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
503
504struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
505struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
506
507const char *gsm_pchan_name(enum gsm_phys_chan_config c);
508enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
509const char *gsm_lchant_name(enum gsm_chan_t c);
510const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
511char *gsm_trx_name(struct gsm_bts_trx *trx);
512char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
513char *gsm_lchan_name(struct gsm_lchan *lchan);
514const char *gsm_lchans_name(enum gsm_lchan_state s);
515
516void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
517 uint8_t e1_ts, uint8_t e1_ts_ss);
518
519void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked);
520int gsm_bts_has_feature(struct gsm_bts *bts, enum gsm_bts_features feat);
521
522
523#endif