blob: 011e0aa96c0e1c99da1deb32964783b4ce97fa45 [file] [log] [blame]
Jonathan Santos5a45b152011-08-17 15:33:57 -04001#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#include <osmocom/gsm/protocol/gsm_12_21.h>
18
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
87struct gsm_abis_mo {
88 uint8_t obj_class;
89 struct abis_om_obj_inst obj_inst;
90 const char *name;
91 struct gsm_nm_state nm_state;
92 struct tlv_parsed *nm_attr;
93 struct gsm_bts *bts;
94};
95
96#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
117/* BTS ONLY */
118#define MAX_NUM_UL_MEAS 104
119#define LC_UL_M_F_L1_VALID (1 << 0)
120#define LC_UL_M_F_RES_VALID (1 << 1)
121
122struct bts_ul_meas {
123 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
124 uint16_t ber10k;
125 /* timing advance offset (in quarter bits) */
126 int16_t ta_offs_qbits;
127 /* C/I ratio in dB */
128 float c_i;
129 /* flags */
130 uint8_t is_sub:1;
131 /* RSSI in dBm * -1 */
132 uint8_t inv_rssi;
133};
134/* /BTS ONLY */
135
136struct gsm_lchan {
137 /* The TS that we're part of */
138 struct gsm_bts_trx_ts *ts;
139 /* The logical subslot number in the TS */
140 uint8_t nr;
141 /* The logical channel type */
142 enum gsm_chan_t type;
143 /* RSL channel mode */
144 enum rsl_cmod_spd rsl_cmode;
145 /* If TCH, traffic channel mode */
146 enum gsm48_chan_mode tch_mode;
147 /* State */
148 enum gsm_lchan_state state;
149 /* Power levels for MS and BTS */
150 uint8_t bs_power;
151 uint8_t ms_power;
152 /* Encryption information */
153 struct {
154 uint8_t alg_id;
155 uint8_t key_len;
156 uint8_t key[MAX_A5_KEY_LEN];
157 } encr;
158
159 /* AMR bits */
160 struct gsm48_multi_rate_conf mr_conf;
161
162 /* Established data link layer services */
163 uint8_t sapis[8];
164 int sach_deact;
165 int release_reason;
166
167 struct {
168 uint32_t bound_ip;
169 uint32_t connect_ip;
170 uint16_t bound_port;
171 uint16_t connect_port;
172 uint16_t conn_id;
173 uint8_t rtp_payload;
174 uint8_t rtp_payload2;
175 uint8_t speech_mode;
176 struct rtp_socket *rtp_socket;
177 } abis_ip;
178
179 uint8_t rqd_ta;
180
181#ifdef ROLE_BSC
182 struct osmo_timer_list T3101;
183 struct osmo_timer_list T3111;
184 struct osmo_timer_list error_timer;
185
186 /* table of neighbor cell measurements */
187 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
188
189 /* cache of last measurement reports on this lchan */
190 struct gsm_meas_rep meas_rep[6];
191 int meas_rep_idx;
192
193 /* GSM Random Access data */
194 struct gsm48_req_ref *rqd_ref;
195
196 struct gsm_subscriber_connection *conn;
197#else
198 struct lapdm_channel lapdm_ch;
199 struct {
200 /* bitmask of all SI that are present/valid in si_buf */
201 uint32_t valid;
202 uint32_t last;
203 /* buffers where we put the pre-computed SI */
204 sysinfo_buf_t buf[_MAX_SYSINFO_TYPE];
205 } si;
206 struct {
207 uint8_t flags;
208 /* RSL measurment result number, 0 at lchan_act */
209 uint8_t res_nr;
210 /* current Tx power level of the BTS */
211 uint8_t bts_tx_pwr;
212 /* number of measurements stored in array below */
213 uint8_t num_ul_meas;
214 struct bts_ul_meas uplink[MAX_NUM_UL_MEAS];
215 /* last L1 header from the MS */
216 uint8_t l1_info[2];
217 struct {
218 uint8_t rxlev_full;
219 uint8_t rxlev_sub;
220 uint8_t rxqual_full;
221 uint8_t rxqual_sub;
222 } res;
223 } meas;
224#endif
225};
226
227
228struct gsm_e1_subslot {
229 /* Number of E1 link */
230 uint8_t e1_nr;
231 /* Number of E1 TS inside E1 link */
232 uint8_t e1_ts;
233 /* Sub-slot within the E1 TS, 0xff if full TS */
234 uint8_t e1_ts_ss;
235};
236
237#define TS_F_PDCH_MODE 0x1000
238/* One Timeslot in a TRX */
239struct gsm_bts_trx_ts {
240 struct gsm_bts_trx *trx;
241 /* number of this timeslot at the TRX */
242 uint8_t nr;
243
244 enum gsm_phys_chan_config pchan;
245
246 unsigned int flags;
247 struct gsm_abis_mo mo;
248 struct tlv_parsed nm_attr;
249 uint8_t nm_chan_comb;
250 int tsc; /* -1 == use BTS TSC */
251
252 struct {
253 /* Parameters below are configured by VTY */
254 int enabled;
255 uint8_t maio;
256 uint8_t hsn;
257 struct bitvec arfcns;
258 uint8_t arfcns_data[1024/8];
259 /* This is the pre-computed MA for channel assignments */
260 struct bitvec ma;
261 uint8_t ma_len; /* part of ma_data that is used */
262 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
263 } hopping;
264
265 /* To which E1 subslot are we connected */
266 struct gsm_e1_subslot e1_link;
267
268 struct gsm_lchan lchan[TS_MAX_LCHAN];
269};
270
271/* One TRX in a BTS */
272struct gsm_bts_trx {
273 /* list header in bts->trx_list */
274 struct llist_head list;
275
276 struct gsm_bts *bts;
277 /* number of this TRX in the BTS */
278 uint8_t nr;
279 /* human readable name / description */
280 char *description;
281 /* how do we talk RSL with this TRX? */
282 struct gsm_e1_subslot rsl_e1_link;
283 uint8_t rsl_tei;
284 struct e1inp_sign_link *rsl_link;
285 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
286 struct e1inp_sign_link *oml_link;
287
288 struct gsm_abis_mo mo;
289 struct tlv_parsed nm_attr;
290 struct {
291 struct gsm_abis_mo mo;
292 } bb_transc;
293
294 uint16_t arfcn;
295 int nominal_power; /* in dBm */
296 unsigned int max_power_red; /* in actual dB */
297
298 struct {
299 void *l1h;
300 } role_bts;
301
302 union {
303 struct {
304 struct {
305 struct gsm_abis_mo mo;
306 } bbsig;
307 struct {
308 struct gsm_abis_mo mo;
309 } pa;
310 } bs11;
311 struct {
312 unsigned int test_state;
313 uint8_t test_nr;
314 struct rxlev_stats rxlev_stat;
315 } ipaccess;
316 };
317 struct gsm_bts_trx_ts ts[TRX_NR_TS];
318};
319
320#define GSM_BTS_SI(bts, i) (void *)(bts->si_buf[i])
321
322enum gsm_bts_type {
323 GSM_BTS_TYPE_UNKNOWN,
324 GSM_BTS_TYPE_BS11,
325 GSM_BTS_TYPE_NANOBTS,
326 GSM_BTS_TYPE_RBS2000,
327 GSM_BTS_TYPE_HSL_FEMTO,
328};
329
330struct vty;
331
332struct gsm_bts_model {
333 struct llist_head list;
334
335 enum gsm_bts_type type;
336 const char *name;
337
338 bool started;
339 int (*start)(struct gsm_network *net);
340 int (*oml_rcvmsg)(struct msgb *msg);
341
342 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
343 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
344 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
345
346 struct tlv_definition nm_att_tlvdef;
347
348 struct bitvec features;
349 uint8_t _features_data[128/8];
350};
351
352enum gsm_bts_features {
353 BTS_FEAT_HSCSD,
354 BTS_FEAT_GPRS,
355 BTS_FEAT_EGPRS,
356 BTS_FEAT_ECSD,
357 BTS_FEAT_HOPPING,
358};
359
360/*
361 * This keeps track of the paging status of one BTS. It
362 * includes a number of pending requests, a back pointer
363 * to the gsm_bts, a timer and some more state.
364 */
365struct gsm_bts_paging_state {
366 /* pending requests */
367 struct llist_head pending_requests;
368 struct gsm_bts *bts;
369
370 struct osmo_timer_list work_timer;
371 struct osmo_timer_list credit_timer;
372
373 /* free chans needed */
374 int free_chans_need;
375
376 /* load */
377 uint16_t available_slots;
378};
379
380struct gsm_envabtse {
381 struct gsm_abis_mo mo;
382};
383
384struct gsm_bts_gprs_nsvc {
385 struct gsm_bts *bts;
386 /* data read via VTY config file, to configure the BTS
387 * via OML from BSC */
388 int id;
389 uint16_t nsvci;
390 uint16_t local_port; /* on the BTS */
391 uint16_t remote_port; /* on the SGSN */
392 uint32_t remote_ip; /* on the SGSN */
393
394 struct gsm_abis_mo mo;
395};
396
397enum neigh_list_manual_mode {
398 NL_MODE_AUTOMATIC = 0,
399 NL_MODE_MANUAL = 1,
400 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
401};
402
403/* One BTS */
404struct gsm_bts {
405 /* list header in net->bts_list */
406 struct llist_head list;
407
408 /* number of ths BTS in network */
409 uint8_t nr;
410 /* human readable name / description */
411 char *description;
412 /* Cell Identity */
413 uint16_t cell_identity;
414 /* location area code of this BTS */
415 uint16_t location_area_code;
416 /* Training Sequence Code */
417 uint8_t tsc;
418 /* Base Station Identification Code (BSIC) */
419 uint8_t bsic;
420 /* type of BTS */
421 enum gsm_bts_type type;
422 struct gsm_bts_model *model;
423 enum gsm_band band;
424 /* maximum Tx power that the MS is permitted to use in this cell */
425 int ms_max_power;
426
427 /* how do we talk OML with this TRX? */
428 struct gsm_e1_subslot oml_e1_link;
429 uint8_t oml_tei;
430 struct e1inp_sign_link *oml_link;
431
432 /* Abis network management O&M handle */
433 struct abis_nm_h *nmh;
434
435 struct gsm_abis_mo mo;
436
437 /* number of this BTS on given E1 link */
438 uint8_t bts_nr;
439
440 /* paging state and control */
441 struct gsm_bts_paging_state paging;
442
443 /* CCCH is on C0 */
444 struct gsm_bts_trx *c0;
445
446 struct {
447 struct gsm_abis_mo mo;
448 } site_mgr;
449
450 /* bitmask of all SI that are present/valid in si_buf */
451 uint32_t si_valid;
452 /* buffers where we put the pre-computed SI */
453 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE];
454
455 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
456 union {
457 struct {
458 uint16_t site_id;
459 uint16_t bts_id;
460 uint32_t flags;
461 } ip_access;
462 struct {
463 struct {
464 struct gsm_abis_mo mo;
465 } cclk;
466 struct {
467 struct gsm_abis_mo mo;
468 } rack;
469 struct gsm_envabtse envabtse[4];
470 } bs11;
471 struct {
472 struct {
473 struct gsm_abis_mo mo;
474 struct llist_head conn_groups;
475 } is;
476 struct {
477 struct gsm_abis_mo mo;
478 struct llist_head conn_groups;
479 } con;
480 struct {
481 struct gsm_abis_mo mo;
482 } dp;
483 struct {
484 struct gsm_abis_mo mo;
485 } tf;
486 } rbs2000;
487 struct {
488 unsigned long serno;
489 } hsl;
490 };
491
492 /* Not entirely sure how ip.access specific this is */
493 struct {
494 enum bts_gprs_mode mode;
495 struct {
496 struct gsm_abis_mo mo;
497 uint16_t nsei;
498 uint8_t timer[7];
499 } nse;
500 struct {
501 struct gsm_abis_mo mo;
502 uint16_t bvci;
503 uint8_t timer[11];
504 } cell;
505 struct gsm_bts_gprs_nsvc nsvc[2];
506 uint8_t rac;
507 } gprs;
508
509 /* RACH NM values */
510 int rach_b_thresh;
511 int rach_ldavg_slots;
512
513 /* transceivers */
514 int num_trx;
515 struct llist_head trx_list;
516
517#ifdef ROLE_BSC
518 /* Abis NM queue */
519 struct llist_head abis_queue;
520 int abis_nm_pend;
521
522 struct gsm_network *network;
523
524 /* should the channel allocator allocate channels from high TRX to TRX0,
525 * rather than starting from TRX0 and go upwards? */
526 int chan_alloc_reverse;
527
528 enum neigh_list_manual_mode neigh_list_manual_mode;
529 /* parameters from which we build SYSTEM INFORMATION */
530 struct {
531 struct gsm48_rach_control rach_control;
532 uint8_t ncc_permitted;
533 struct gsm48_cell_sel_par cell_sel_par;
534 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
535 struct gsm48_cell_options cell_options;
536 struct gsm48_control_channel_descr chan_desc;
537 struct bitvec neigh_list;
538 struct bitvec cell_alloc;
539 struct bitvec si5_neigh_list;
540 struct {
541 /* bitmask large enough for all possible ARFCN's */
542 uint8_t neigh_list[1024/8];
543 uint8_t cell_alloc[1024/8];
544 /* If the user wants a different neighbor list in SI5 than in SI2 */
545 uint8_t si5_neigh_list[1024/8];
546 } data;
547 } si_common;
548
549 /* do we use static (user-defined) system information messages? (bitmask) */
550 uint32_t si_mode_static;
551#endif /* ROLE_BSC */
552 void *role;
553};
554
555
556struct gsm_bts *gsm_bts_alloc(void *talloc_ctx);
557struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
558
559struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
560
561const char *gsm_pchan_name(enum gsm_phys_chan_config c);
562enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
563const char *gsm_lchant_name(enum gsm_chan_t c);
564const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
565char *gsm_trx_name(struct gsm_bts_trx *trx);
566char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
567char *gsm_lchan_name(struct gsm_lchan *lchan);
568const char *gsm_lchans_name(enum gsm_lchan_state s);
569
570
571void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
572
573struct gsm_abis_mo *
574gsm_objclass2mo(struct gsm_bts *bts, uint8_t obj_class,
575 struct abis_om_obj_inst *obj_inst);
576
577struct gsm_nm_state *
578gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
579 struct abis_om_obj_inst *obj_inst);
580void *
581gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
582 struct abis_om_obj_inst *obj_inst);
583
584/* reset the state of all MO in the BTS */
585void gsm_bts_mo_reset(struct gsm_bts *bts);
586
587uint8_t gsm_ts2chan_nr(const struct gsm_bts_trx_ts *ts, uint8_t lchan_nr);
588uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
589
590#endif