blob: ab298c96aad0c4d11ad0e9e762217edab09d786c [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
160#ifdef ROLE_BSC
161 struct osmo_timer_list T3101;
162 struct osmo_timer_list T3111;
163 struct osmo_timer_list error_timer;
164
165 /* table of neighbor cell measurements */
166 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
167
168 /* cache of last measurement reports on this lchan */
169 struct gsm_meas_rep meas_rep[6];
170 int meas_rep_idx;
171
172 /* GSM Random Access data */
173 struct gsm48_req_ref *rqd_ref;
174 uint8_t rqd_ta;
175
176 struct gsm_subscriber_connection *conn;
177#endif
178};
179
180struct gsm_e1_subslot {
181 /* Number of E1 link */
182 uint8_t e1_nr;
183 /* Number of E1 TS inside E1 link */
184 uint8_t e1_ts;
185 /* Sub-slot within the E1 TS, 0xff if full TS */
186 uint8_t e1_ts_ss;
187};
188
189#define TS_F_PDCH_MODE 0x1000
190/* One Timeslot in a TRX */
191struct gsm_bts_trx_ts {
192 struct gsm_bts_trx *trx;
193 /* number of this timeslot at the TRX */
194 uint8_t nr;
195
196 enum gsm_phys_chan_config pchan;
197
198 unsigned int flags;
Harald Welted64c0bc2011-05-30 12:07:53 +0200199 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200200 struct tlv_parsed nm_attr;
201 uint8_t nm_chan_comb;
Harald Welte135a6482011-05-30 12:09:13 +0200202 int tsc; /* -1 == use BTS TSC */
Harald Welte6be350c2011-05-25 13:10:08 +0200203
204 struct {
205 /* Parameters below are configured by VTY */
206 int enabled;
207 uint8_t maio;
208 uint8_t hsn;
209 struct bitvec arfcns;
210 uint8_t arfcns_data[1024/8];
211 /* This is the pre-computed MA for channel assignments */
212 struct bitvec ma;
213 uint8_t ma_len; /* part of ma_data that is used */
214 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
215 } hopping;
216
217 /* To which E1 subslot are we connected */
218 struct gsm_e1_subslot e1_link;
219
220 struct gsm_lchan lchan[TS_MAX_LCHAN];
221};
222
223/* One TRX in a BTS */
224struct gsm_bts_trx {
225 /* list header in bts->trx_list */
226 struct llist_head list;
227
228 struct gsm_bts *bts;
229 /* number of this TRX in the BTS */
230 uint8_t nr;
231 /* human readable name / description */
232 char *description;
233 /* how do we talk RSL with this TRX? */
234 struct gsm_e1_subslot rsl_e1_link;
235 uint8_t rsl_tei;
236 struct e1inp_sign_link *rsl_link;
237 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
238 struct e1inp_sign_link *oml_link;
239
Harald Welted64c0bc2011-05-30 12:07:53 +0200240 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200241 struct tlv_parsed nm_attr;
242 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200243 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200244 } bb_transc;
245
246 uint16_t arfcn;
247 int nominal_power; /* in dBm */
248 unsigned int max_power_red; /* in actual dB */
249
250 union {
251 struct {
252 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200253 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200254 } bbsig;
255 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200256 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200257 } pa;
258 } bs11;
259 struct {
260 unsigned int test_state;
261 uint8_t test_nr;
262 struct rxlev_stats rxlev_stat;
263 } ipaccess;
264 };
265 struct gsm_bts_trx_ts ts[TRX_NR_TS];
266};
267
268#define GSM_BTS_SI(bts, i) (void *)(bts->si_buf[i])
269
270enum gsm_bts_type {
271 GSM_BTS_TYPE_UNKNOWN,
272 GSM_BTS_TYPE_BS11,
273 GSM_BTS_TYPE_NANOBTS,
274 GSM_BTS_TYPE_RBS2000,
275 GSM_BTS_TYPE_HSL_FEMTO,
276};
277
278struct vty;
279
280struct gsm_bts_model {
281 struct llist_head list;
282
283 enum gsm_bts_type type;
284 const char *name;
285
286 bool started;
287 int (*start)(struct gsm_network *net);
288 int (*oml_rcvmsg)(struct msgb *msg);
289
290 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
291 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
292 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
293
294 struct tlv_definition nm_att_tlvdef;
295
296 struct bitvec features;
297 uint8_t _features_data[128/8];
298};
299
300enum gsm_bts_features {
301 BTS_FEAT_HSCSD,
302 BTS_FEAT_GPRS,
303 BTS_FEAT_EGPRS,
304 BTS_FEAT_ECSD,
305 BTS_FEAT_HOPPING,
306};
307
308/*
309 * This keeps track of the paging status of one BTS. It
310 * includes a number of pending requests, a back pointer
311 * to the gsm_bts, a timer and some more state.
312 */
313struct gsm_bts_paging_state {
314 /* pending requests */
315 struct llist_head pending_requests;
316 struct gsm_bts *bts;
317
318 struct osmo_timer_list work_timer;
319 struct osmo_timer_list credit_timer;
320
321 /* free chans needed */
322 int free_chans_need;
323
324 /* load */
325 uint16_t available_slots;
326};
327
328struct gsm_envabtse {
Harald Welted64c0bc2011-05-30 12:07:53 +0200329 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200330};
331
332struct gsm_bts_gprs_nsvc {
333 struct gsm_bts *bts;
334 /* data read via VTY config file, to configure the BTS
335 * via OML from BSC */
336 int id;
337 uint16_t nsvci;
338 uint16_t local_port; /* on the BTS */
339 uint16_t remote_port; /* on the SGSN */
340 uint32_t remote_ip; /* on the SGSN */
341
Harald Welted64c0bc2011-05-30 12:07:53 +0200342 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200343};
344
345enum neigh_list_manual_mode {
346 NL_MODE_AUTOMATIC = 0,
347 NL_MODE_MANUAL = 1,
348 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
349};
350
351/* One BTS */
352struct gsm_bts {
353 /* list header in net->bts_list */
354 struct llist_head list;
355
356 /* number of ths BTS in network */
357 uint8_t nr;
358 /* human readable name / description */
359 char *description;
360 /* Cell Identity */
361 uint16_t cell_identity;
362 /* location area code of this BTS */
363 uint16_t location_area_code;
364 /* Training Sequence Code */
365 uint8_t tsc;
366 /* Base Station Identification Code (BSIC) */
367 uint8_t bsic;
368 /* type of BTS */
369 enum gsm_bts_type type;
370 struct gsm_bts_model *model;
371 enum gsm_band band;
372 /* maximum Tx power that the MS is permitted to use in this cell */
373 int ms_max_power;
374
375 /* how do we talk OML with this TRX? */
376 struct gsm_e1_subslot oml_e1_link;
377 uint8_t oml_tei;
378 struct e1inp_sign_link *oml_link;
379
380 /* Abis network management O&M handle */
381 struct abis_nm_h *nmh;
Harald Welted64c0bc2011-05-30 12:07:53 +0200382
383 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200384
385 /* number of this BTS on given E1 link */
386 uint8_t bts_nr;
387
388 /* paging state and control */
389 struct gsm_bts_paging_state paging;
390
391 /* CCCH is on C0 */
392 struct gsm_bts_trx *c0;
393
394 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200395 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200396 } site_mgr;
397
398 /* bitmask of all SI that are present/valid in si_buf */
399 uint32_t si_valid;
400 /* buffers where we put the pre-computed SI */
401 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE];
402
403 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
404 union {
405 struct {
406 uint16_t site_id;
407 uint16_t bts_id;
408 uint32_t flags;
409 } ip_access;
410 struct {
411 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200412 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200413 } cclk;
414 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200415 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200416 } rack;
417 struct gsm_envabtse envabtse[4];
418 } bs11;
419 struct {
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 } is;
424 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200425 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200426 struct llist_head conn_groups;
427 } con;
428 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200429 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200430 } dp;
431 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200432 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200433 } tf;
434 } rbs2000;
435 struct {
436 unsigned long serno;
437 } hsl;
438 };
439
440 /* Not entirely sure how ip.access specific this is */
441 struct {
442 enum bts_gprs_mode mode;
443 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200444 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200445 uint16_t nsei;
446 uint8_t timer[7];
447 } nse;
448 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200449 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200450 uint16_t bvci;
451 uint8_t timer[11];
452 } cell;
453 struct gsm_bts_gprs_nsvc nsvc[2];
454 uint8_t rac;
455 } gprs;
456
457 /* RACH NM values */
458 int rach_b_thresh;
459 int rach_ldavg_slots;
460
461 /* transceivers */
462 int num_trx;
463 struct llist_head trx_list;
464
465#ifdef ROLE_BSC
466 /* Abis NM queue */
467 struct llist_head abis_queue;
468 int abis_nm_pend;
469
470 struct gsm_network *network;
471
472 /* should the channel allocator allocate channels from high TRX to TRX0,
473 * rather than starting from TRX0 and go upwards? */
474 int chan_alloc_reverse;
475
476 enum neigh_list_manual_mode neigh_list_manual_mode;
477 /* parameters from which we build SYSTEM INFORMATION */
478 struct {
479 struct gsm48_rach_control rach_control;
480 uint8_t ncc_permitted;
481 struct gsm48_cell_sel_par cell_sel_par;
482 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
483 struct gsm48_cell_options cell_options;
484 struct gsm48_control_channel_descr chan_desc;
485 struct bitvec neigh_list;
486 struct bitvec cell_alloc;
487 struct bitvec si5_neigh_list;
488 struct {
489 /* bitmask large enough for all possible ARFCN's */
490 uint8_t neigh_list[1024/8];
491 uint8_t cell_alloc[1024/8];
492 /* If the user wants a different neighbor list in SI5 than in SI2 */
493 uint8_t si5_neigh_list[1024/8];
494 } data;
495 } si_common;
496
497 /* do we use static (user-defined) system information messages? (bitmask) */
498 uint32_t si_mode_static;
499#endif /* ROLE_BSC */
Harald Welte978714d2011-06-06 18:31:20 +0200500 void *role;
Harald Welte6be350c2011-05-25 13:10:08 +0200501};
502
503
Harald Welte3300c012011-06-05 13:31:33 +0200504struct gsm_bts *gsm_bts_alloc(void *talloc_ctx);
Harald Welte6be350c2011-05-25 13:10:08 +0200505struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
506
507struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
Harald Welte6be350c2011-05-25 13:10:08 +0200508
509const char *gsm_pchan_name(enum gsm_phys_chan_config c);
510enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
511const char *gsm_lchant_name(enum gsm_chan_t c);
512const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
513char *gsm_trx_name(struct gsm_bts_trx *trx);
514char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
515char *gsm_lchan_name(struct gsm_lchan *lchan);
516const char *gsm_lchans_name(enum gsm_lchan_state s);
517
Harald Welte6be350c2011-05-25 13:10:08 +0200518
Harald Welte978714d2011-06-06 18:31:20 +0200519struct gsm_abis_mo *
520gsm_objclass2mo(struct gsm_bts *bts, uint8_t obj_class,
521 struct abis_om_obj_inst *obj_inst);
522
523struct gsm_nm_state *
524gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
525 struct abis_om_obj_inst *obj_inst);
526void *
527gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
528 struct abis_om_obj_inst *obj_inst);
529
Harald Welte6be350c2011-05-25 13:10:08 +0200530#endif