blob: d1a901e8ffbcc3932c1d7e21fb18dce280d7501c [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001#ifndef _GSM_DATA_H
2#define _GSM_DATA_H
3
Harald Weltef142c972011-05-24 13:25:38 +02004#include <stdint.h>
Maxddee01f2016-05-24 14:23:27 +02005#include <regex.h>
6#include <sys/types.h>
Maxe6052c42016-06-30 10:25:49 +02007#include <stdbool.h>
Neels Hofmeyr10485162018-02-13 23:22:03 +01008#include <stdint.h>
Harald Weltef142c972011-05-24 13:25:38 +02009
10#include <osmocom/core/timer.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020011#include <osmocom/core/rate_ctr.h>
Harald Welte6be350c2011-05-25 13:10:08 +020012#include <osmocom/core/select.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020013#include <osmocom/core/stats.h>
Stefan Sperling81dc9e72018-02-05 17:34:36 +010014#include <osmocom/core/stat_item.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020015
Harald Welte121e9a42016-04-20 13:13:19 +020016#include <osmocom/crypt/auth.h>
Harald Weltef142c972011-05-24 13:25:38 +020017
Neels Hofmeyrc0164792017-09-04 15:15:32 +020018#include <osmocom/bsc/common.h>
19#include <osmocom/bsc/rest_octets.h>
Harald Welteb96be392011-05-25 12:33:33 +020020
Neels Hofmeyr10485162018-02-13 23:22:03 +010021#include <osmocom/core/bitvec.h>
22#include <osmocom/gsm/gsm_utils.h>
23#include <osmocom/gsm/rxlev_stat.h>
24#include <osmocom/gsm/protocol/gsm_08_58.h>
25#include <osmocom/gsm/protocol/gsm_12_21.h>
26#include <osmocom/abis/e1_input.h>
27#include <osmocom/bsc/meas_rep.h>
28
Harald Welte74b8cdb2018-01-15 19:26:06 +010029struct mgcp_client_conf;
30struct mgcp_client;
31struct mgcp_ctx;
Philipp Maier39f62bb2017-04-09 12:32:51 +020032
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020033/** annotations for msgb ownership */
34#define __uses
35
Holger Hans Peter Freyther6f615552010-11-15 20:50:42 +010036#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
37
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010038struct bsc_subscr;
Neels Hofmeyr7b656882017-07-09 22:09:18 +020039struct gprs_ra_id;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020040
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080041#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
42
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010043#define tmsi_from_string(str) strtoul(str, NULL, 10)
44
Max70fdd242017-06-15 15:10:53 +020045/* 3-bit long values */
46#define EARFCN_PRIO_INVALID 8
47#define EARFCN_MEAS_BW_INVALID 8
48/* 5-bit long values */
49#define EARFCN_QRXLV_INVALID 32
50#define EARFCN_THRESH_LOW_INVALID 32
51
Harald Welte8e1e3ee2009-02-01 13:32:45 +000052struct msgb;
53typedef int gsm_cbfn(unsigned int hooknum,
54 unsigned int event,
55 struct msgb *msg,
56 void *data, void *param);
57
Harald Weltef7c28b02009-12-21 13:30:17 +010058/* Maximum number of neighbor cells whose average we track */
59#define MAX_NEIGH_MEAS 10
60/* Maximum size of the averaging window for neighbor cells */
61#define MAX_WIN_NEIGH_AVG 10
Andreas Eversberg98692032013-06-23 10:44:34 +020062/* Maximum number of report history we store */
63#define MAX_MEAS_REP 10
Harald Weltef7c28b02009-12-21 13:30:17 +010064
65/* processed neighbor measurements for one cell */
66struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020067 uint16_t arfcn;
68 uint8_t bsic;
69 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +010070 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020071 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +010072};
73
Harald Weltea43e0b42016-06-19 18:06:02 +020074struct gsm_classmark {
75 bool classmark1_set;
76 struct gsm48_classmark1 classmark1;
77 uint8_t classmark2_len;
78 uint8_t classmark2[3];
79 uint8_t classmark3_len;
80 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
81};
82
Andreas Eversberg084b4212013-05-30 14:12:48 +020083/* penalty timers for handover */
84struct ho_penalty_timer {
85 struct llist_head entry;
86 uint8_t bts;
87 time_t timeout;
88};
89
Neels Hofmeyr378a4922016-05-09 21:07:43 +020090/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010091struct gsm_subscriber_connection {
Harald Weltea43e0b42016-06-19 18:06:02 +020092 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +080093 struct llist_head entry;
94
Harald Weltea43e0b42016-06-19 18:06:02 +020095 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010096 struct bsc_subscr *bsub;
97
Harald Welte4a8ebc82017-12-18 18:34:41 +010098 /* SCCP connection associatd with this subscriber_connection */
99 struct osmo_bsc_sccp_con *sccp_con;
Holger Hans Peter Freyther2f9d1ef2010-09-16 20:14:01 +0800100
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100101 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200102 struct gsm_network *network;
103
Harald Welte4a8ebc82017-12-18 18:34:41 +0100104 /* the primary / currently active lchan to the BTS/subscriber */
105 struct gsm_lchan *lchan;
106 /* the future/allocated but not yet used lchan during HANDOVER */
107 struct gsm_lchan *ho_lchan;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100108
Harald Welte4a8ebc82017-12-18 18:34:41 +0100109 /* timer for assignment handling */
110 struct osmo_timer_list T10;
111 /* the future allocated but not yet used lchan during ASSIGNMENT */
112 struct gsm_lchan *secondary_lchan;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100113
Harald Welte4a8ebc82017-12-18 18:34:41 +0100114 /* buffer/cache for classmark of the ME of the subscriber */
Harald Weltea43e0b42016-06-19 18:06:02 +0200115 struct gsm_classmark classmark;
Andreas Eversberg935e5d72013-06-17 11:58:30 +0200116
117 /* Cache DTAP messages during handover/assignment (msgb_enqueue()/msgb_dequeue())*/
118 struct llist_head ho_dtap_cache;
119 unsigned int ho_dtap_cache_len;
Andreas Eversberg084b4212013-05-30 14:12:48 +0200120
121 /* penalty timers for handover */
122 struct llist_head ho_penalty_timers;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100123};
124
Harald Weltef142c972011-05-24 13:25:38 +0200125
Neels Hofmeyr10485162018-02-13 23:22:03 +0100126/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 Table 10.5.2.33b.1:
127 4-bit index is used (2#1111 = 10#15) */
128#define SI2Q_MAX_NUM 16
129/* length in bits (for single SI2quater message) */
130#define SI2Q_MAX_LEN 160
131#define SI2Q_MIN_LEN 18
132
133struct osmo_bsc_data;
134
135struct osmo_bsc_sccp_con;
136
137/* Channel Request reason */
138enum gsm_chreq_reason_t {
139 GSM_CHREQ_REASON_EMERG,
140 GSM_CHREQ_REASON_PAG,
141 GSM_CHREQ_REASON_CALL,
142 GSM_CHREQ_REASON_LOCATION_UPD,
143 GSM_CHREQ_REASON_OTHER,
144 GSM_CHREQ_REASON_PDCH,
145};
146
147/* lchans 0..3 are SDCCH in combined channel configuration,
148 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
149#define CCCH_LCHAN 4
150
151#define TRX_NR_TS 8
152#define TS_MAX_LCHAN 8
153
154#define HARDCODED_ARFCN 123
155#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
156
157/* for multi-drop config */
158#define HARDCODED_BTS0_TS 1
159#define HARDCODED_BTS1_TS 6
160#define HARDCODED_BTS2_TS 11
161
162#define MAX_VERSION_LENGTH 64
163
164#define MAX_BTS_FEATURES 128
165
166enum gsm_hooks {
167 GSM_HOOK_NM_SWLOAD,
168 GSM_HOOK_RR_PAGING,
169 GSM_HOOK_RR_SECURITY,
170};
171
172enum gsm_paging_event {
173 GSM_PAGING_SUCCEEDED,
174 GSM_PAGING_EXPIRED,
175 GSM_PAGING_OOM,
176 GSM_PAGING_BUSY,
177};
178
179enum bts_gprs_mode {
180 BTS_GPRS_NONE = 0,
181 BTS_GPRS_GPRS = 1,
182 BTS_GPRS_EGPRS = 2,
183};
184
185struct gsm_lchan;
186struct osmo_rtp_socket;
187struct rtp_socket;
188struct bsc_api;
189
190/* Network Management State */
191struct gsm_nm_state {
192 uint8_t operational;
193 uint8_t administrative;
194 uint8_t availability;
195};
196
197struct gsm_abis_mo {
198 uint8_t obj_class;
199 uint8_t procedure_pending;
200 struct abis_om_obj_inst obj_inst;
201 const char *name;
202 struct gsm_nm_state nm_state;
203 struct tlv_parsed *nm_attr;
204 struct gsm_bts *bts;
205};
206
207/* Ericsson OM2000 Managed Object */
208struct abis_om2k_mo {
209 uint8_t class;
210 uint8_t bts;
211 uint8_t assoc_so;
212 uint8_t inst;
213} __attribute__ ((packed));
214
215struct om2k_mo {
216 struct abis_om2k_mo addr;
217 struct osmo_fsm_inst *fsm;
218};
219
220#define A38_XOR_MIN_KEY_LEN 12
221#define A38_XOR_MAX_KEY_LEN 16
222#define A38_COMP128_KEY_LEN 16
223#define RSL_ENC_ALG_A5(x) (x+1)
224#define MAX_EARFCN_LIST 32
225
226/* is the data link established? who established it? */
227#define LCHAN_SAPI_UNUSED 0
228#define LCHAN_SAPI_MS 1
229#define LCHAN_SAPI_NET 2
230#define LCHAN_SAPI_REL 3
231
232/* state of a logical channel */
233enum gsm_lchan_state {
234 LCHAN_S_NONE, /* channel is not active */
235 LCHAN_S_ACT_REQ, /* channel activation requested */
236 LCHAN_S_ACTIVE, /* channel is active and operational */
237 LCHAN_S_REL_REQ, /* channel release has been requested */
238 LCHAN_S_REL_ERR, /* channel is in an error state */
239 LCHAN_S_BROKEN, /* channel is somehow unusable */
240 LCHAN_S_INACTIVE, /* channel is set inactive */
241};
242
243/* BTS ONLY */
244#define MAX_NUM_UL_MEAS 104
245#define LC_UL_M_F_L1_VALID (1 << 0)
246#define LC_UL_M_F_RES_VALID (1 << 1)
247
248struct bts_ul_meas {
249 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
250 uint16_t ber10k;
251 /* timing advance offset (in quarter bits) */
252 int16_t ta_offs_qbits;
253 /* C/I ratio in dB */
254 float c_i;
255 /* flags */
256 uint8_t is_sub:1;
257 /* RSSI in dBm * -1 */
258 uint8_t inv_rssi;
259};
260
261struct bts_codec_conf {
262 uint8_t hr;
263 uint8_t efr;
264 uint8_t amr;
265};
266
267struct amr_mode {
268 uint8_t mode;
269 uint8_t threshold;
270 uint8_t hysteresis;
271};
272
273struct amr_multirate_conf {
274 uint8_t gsm48_ie[2];
275 struct amr_mode ms_mode[4];
276 struct amr_mode bts_mode[4];
277 uint8_t num_modes;
278};
279/* /BTS ONLY */
280
281enum lchan_csd_mode {
282 LCHAN_CSD_M_NT,
283 LCHAN_CSD_M_T_1200_75,
284 LCHAN_CSD_M_T_600,
285 LCHAN_CSD_M_T_1200,
286 LCHAN_CSD_M_T_2400,
287 LCHAN_CSD_M_T_9600,
288 LCHAN_CSD_M_T_14400,
289 LCHAN_CSD_M_T_29000,
290 LCHAN_CSD_M_T_32000,
291};
292
293/* State of the SAPIs in the lchan */
294enum lchan_sapi_state {
295 LCHAN_SAPI_S_NONE,
296 LCHAN_SAPI_S_REQ,
297 LCHAN_SAPI_S_ASSIGNED,
298 LCHAN_SAPI_S_REL,
299 LCHAN_SAPI_S_ERROR,
300};
301
Neels Hofmeyr92b9f2e2018-02-14 00:19:11 +0100302#define MAX_A5_KEY_LEN (128/8)
303
304struct gsm_encr {
305 uint8_t alg_id;
306 uint8_t key_len;
307 uint8_t key[MAX_A5_KEY_LEN];
308};
309
Neels Hofmeyr10485162018-02-13 23:22:03 +0100310struct gsm_lchan {
311 /* The TS that we're part of */
312 struct gsm_bts_trx_ts *ts;
313 /* The logical subslot number in the TS */
314 uint8_t nr;
315 /* The logical channel type */
316 enum gsm_chan_t type;
317 /* RSL channel mode */
318 enum rsl_cmod_spd rsl_cmode;
319 /* If TCH, traffic channel mode */
320 enum gsm48_chan_mode tch_mode;
321 enum lchan_csd_mode csd_mode;
322 /* State */
323 enum gsm_lchan_state state;
324 const char *broken_reason;
325 /* Power levels for MS and BTS */
326 uint8_t bs_power;
327 uint8_t ms_power;
328 /* Encryption information */
329 struct gsm_encr encr;
330
331 /* AMR bits */
332 uint8_t mr_ms_lv[7];
333 uint8_t mr_bts_lv[7];
334
335 /* Established data link layer services */
336 uint8_t sapis[8];
337
338 struct {
339 uint32_t bound_ip;
340 uint32_t connect_ip;
341 uint16_t bound_port;
342 uint16_t connect_port;
343 uint16_t conn_id;
344 uint8_t rtp_payload;
345 uint8_t rtp_payload2;
346 uint8_t speech_mode;
347 struct rtp_socket *rtp_socket;
348
349 /* info we need to postpone the AoIP
350 * assignment completed message */
351 struct {
352 uint8_t rr_cause;
353 uint8_t chosen_channel;
354 uint8_t encr_alg_id;
355 uint8_t speech_mode;
356 bool valid;
357 } ass_compl;
358 } abis_ip;
359
360 uint8_t rqd_ta;
361
362 char *name;
363
364 struct osmo_timer_list T3101;
365 struct osmo_timer_list T3109;
366 struct osmo_timer_list T3111;
367 struct osmo_timer_list error_timer;
368 struct osmo_timer_list act_timer;
369 struct osmo_timer_list rel_work;
370 uint8_t error_cause;
371
372 /* table of neighbor cell measurements */
373 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
374
375 /* cache of last measurement reports on this lchan */
376 struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
377 int meas_rep_idx;
378 int meas_rep_count;
379
380 /* GSM Random Access data */
381 struct gsm48_req_ref *rqd_ref;
382
383 struct gsm_subscriber_connection *conn;
384
385 struct {
386 /* channel activation type and handover ref */
387 uint8_t act_type;
388 uint8_t ho_ref;
389 struct gsm48_req_ref *rqd_ref;
390 uint8_t rqd_ta;
391 } dyn;
392};
393
394enum {
395 TS_F_PDCH_ACTIVE = 0x1000,
396 TS_F_PDCH_ACT_PENDING = 0x2000,
397 TS_F_PDCH_DEACT_PENDING = 0x4000,
398 TS_F_PDCH_PENDING_MASK = 0x6000 /*<
399 TS_F_PDCH_ACT_PENDING | TS_F_PDCH_DEACT_PENDING */
400} gsm_bts_trx_ts_flags;
401
402/* One Timeslot in a TRX */
403struct gsm_bts_trx_ts {
404 struct gsm_bts_trx *trx;
405 /* number of this timeslot at the TRX */
406 uint8_t nr;
407
408 enum gsm_phys_chan_config pchan;
409
410 struct {
411 enum gsm_phys_chan_config pchan_is;
412 enum gsm_phys_chan_config pchan_want;
413 struct msgb *pending_chan_activ;
414 } dyn;
415
416 unsigned int flags;
417 struct gsm_abis_mo mo;
418 struct tlv_parsed nm_attr;
419 uint8_t nm_chan_comb;
420 int tsc; /* -1 == use BTS TSC */
421
422 struct {
423 /* Parameters below are configured by VTY */
424 int enabled;
425 uint8_t maio;
426 uint8_t hsn;
427 struct bitvec arfcns;
428 uint8_t arfcns_data[1024/8];
429 /* This is the pre-computed MA for channel assignments */
430 struct bitvec ma;
431 uint8_t ma_len; /* part of ma_data that is used */
432 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
433 } hopping;
434
435 /* To which E1 subslot are we connected */
436 struct gsm_e1_subslot e1_link;
437
438 union {
439 struct {
440 struct om2k_mo om2k_mo;
441 } rbs2000;
442 };
443
444 struct gsm_lchan lchan[TS_MAX_LCHAN];
445};
446
447/* One TRX in a BTS */
448struct gsm_bts_trx {
449 /* list header in bts->trx_list */
450 struct llist_head list;
451
452 struct gsm_bts *bts;
453 /* number of this TRX in the BTS */
454 uint8_t nr;
455 /* human readable name / description */
456 char *description;
457 /* how do we talk RSL with this TRX? */
458 struct gsm_e1_subslot rsl_e1_link;
459 uint8_t rsl_tei;
460 struct e1inp_sign_link *rsl_link;
461
462 /* Timeout for initiating the RSL connection. */
463 struct osmo_timer_list rsl_connect_timeout;
464
465 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
466 struct e1inp_sign_link *oml_link;
467
468 struct gsm_abis_mo mo;
469 struct tlv_parsed nm_attr;
470 struct {
471 struct gsm_abis_mo mo;
472 } bb_transc;
473
474 uint16_t arfcn;
475 int nominal_power; /* in dBm */
476 unsigned int max_power_red; /* in actual dB */
477
478 union {
479 struct {
480 struct {
481 struct gsm_abis_mo mo;
482 } bbsig;
483 struct {
484 struct gsm_abis_mo mo;
485 } pa;
486 } bs11;
487 struct {
488 unsigned int test_state;
489 uint8_t test_nr;
490 struct rxlev_stats rxlev_stat;
491 } ipaccess;
492 struct {
493 struct {
494 struct om2k_mo om2k_mo;
495 } trxc;
496 struct {
497 struct om2k_mo om2k_mo;
498 } rx;
499 struct {
500 struct om2k_mo om2k_mo;
501 } tx;
502 } rbs2000;
503 };
504 struct gsm_bts_trx_ts ts[TRX_NR_TS];
505};
506
507#define GSM_BTS_SI2Q(bts, i) (struct gsm48_system_information_type_2quater *)((bts)->si_buf[SYSINFO_TYPE_2quater][i])
508#define GSM_BTS_HAS_SI(bts, i) ((bts)->si_valid & (1 << i))
509#define GSM_BTS_SI(bts, i) (void *)((bts)->si_buf[i][0])
510#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
511
512enum gsm_bts_type {
513 GSM_BTS_TYPE_UNKNOWN,
514 GSM_BTS_TYPE_BS11,
515 GSM_BTS_TYPE_NANOBTS,
516 GSM_BTS_TYPE_RBS2000,
517 GSM_BTS_TYPE_NOKIA_SITE,
518 GSM_BTS_TYPE_OSMOBTS,
519 _NUM_GSM_BTS_TYPE
520};
521
522enum gsm_bts_type_variant {
523 BTS_UNKNOWN,
524 BTS_OSMO_LITECELL15,
525 BTS_OSMO_OCTPHY,
526 BTS_OSMO_SYSMO,
527 BTS_OSMO_TRX,
528 _NUM_BTS_VARIANT
529};
530
531/* Used by OML layer for BTS Attribute reporting */
532enum bts_attribute {
533 BTS_TYPE_VARIANT,
534 BTS_SUB_MODEL,
535 TRX_PHY_VERSION,
536};
537
538struct vty;
539
540struct gsm_bts_model {
541 struct llist_head list;
542
543 enum gsm_bts_type type;
544 enum gsm_bts_type_variant variant;
545 const char *name;
546
547 bool started;
548 int (*start)(struct gsm_network *net);
549 int (*oml_rcvmsg)(struct msgb *msg);
550 char * (*oml_status)(const struct gsm_bts *bts);
551
552 void (*e1line_bind_ops)(struct e1inp_line *line);
553
554 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
555 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
556 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
557
558 struct tlv_definition nm_att_tlvdef;
559
560 /* features of a given BTS model set via gsm_bts_model_register() locally */
561 struct bitvec features;
562 uint8_t _features_data[MAX_BTS_FEATURES/8];
563};
564
565/* N. B: always add new features to the end of the list (right before _NUM_BTS_FEAT) to avoid breaking compatibility
566 with BTS compiled against earlier version of this header */
567enum gsm_bts_features {
568 BTS_FEAT_HSCSD,
569 BTS_FEAT_GPRS,
570 BTS_FEAT_EGPRS,
571 BTS_FEAT_ECSD,
572 BTS_FEAT_HOPPING,
573 BTS_FEAT_MULTI_TSC,
574 BTS_FEAT_OML_ALERTS,
575 BTS_FEAT_AGCH_PCH_PROP,
576 BTS_FEAT_CBCH,
577 _NUM_BTS_FEAT
578};
579
580extern const struct value_string gsm_bts_features_descs[];
581
582/*
583 * This keeps track of the paging status of one BTS. It
584 * includes a number of pending requests, a back pointer
585 * to the gsm_bts, a timer and some more state.
586 */
587struct gsm_bts_paging_state {
588 /* pending requests */
589 struct llist_head pending_requests;
590 struct gsm_bts *bts;
591
592 struct osmo_timer_list work_timer;
593 struct osmo_timer_list credit_timer;
594
595 /* free chans needed */
596 int free_chans_need;
597
598 /* load */
599 uint16_t available_slots;
600};
601
602struct gsm_envabtse {
603 struct gsm_abis_mo mo;
604};
605
606struct gsm_bts_gprs_nsvc {
607 struct gsm_bts *bts;
608 /* data read via VTY config file, to configure the BTS
609 * via OML from BSC */
610 int id;
611 uint16_t nsvci;
612 uint16_t local_port; /* on the BTS */
613 uint16_t remote_port; /* on the SGSN */
614 uint32_t remote_ip; /* on the SGSN */
615
616 struct gsm_abis_mo mo;
617};
618
619enum gprs_rlc_par {
620 RLC_T3142,
621 RLC_T3169,
622 RLC_T3191,
623 RLC_T3193,
624 RLC_T3195,
625 RLC_N3101,
626 RLC_N3103,
627 RLC_N3105,
628 CV_COUNTDOWN,
629 T_DL_TBF_EXT, /* ms */
630 T_UL_TBF_EXT, /* ms */
631 _NUM_RLC_PAR
632};
633
634enum gprs_cs {
635 GPRS_CS1,
636 GPRS_CS2,
637 GPRS_CS3,
638 GPRS_CS4,
639 GPRS_MCS1,
640 GPRS_MCS2,
641 GPRS_MCS3,
642 GPRS_MCS4,
643 GPRS_MCS5,
644 GPRS_MCS6,
645 GPRS_MCS7,
646 GPRS_MCS8,
647 GPRS_MCS9,
648 _NUM_GRPS_CS
649};
650
651struct gprs_rlc_cfg {
652 uint16_t parameter[_NUM_RLC_PAR];
653 struct {
654 uint16_t repeat_time; /* ms */
655 uint8_t repeat_count;
656 } paging;
657 uint32_t cs_mask; /* bitmask of gprs_cs */
658 uint8_t initial_cs;
659 uint8_t initial_mcs;
660};
661
662
663enum neigh_list_manual_mode {
664 NL_MODE_AUTOMATIC = 0,
665 NL_MODE_MANUAL = 1,
666 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
667};
668
669enum bts_loc_fix {
670 BTS_LOC_FIX_INVALID = 0,
671 BTS_LOC_FIX_2D = 1,
672 BTS_LOC_FIX_3D = 2,
673};
674
675extern const struct value_string bts_loc_fix_names[];
676
677struct bts_location {
678 struct llist_head list;
679 time_t tstamp;
680 enum bts_loc_fix valid;
681 double lat;
682 double lon;
683 double height;
684};
685
686/* Channel load counter */
687struct load_counter {
688 unsigned int total;
689 unsigned int used;
690};
691
692/* One BTS */
693struct gsm_bts {
694 /* list header in net->bts_list */
695 struct llist_head list;
696
697 /* Geographical location of the BTS */
698 struct llist_head loc_list;
699
700 /* number of ths BTS in network */
701 uint8_t nr;
702 /* human readable name / description */
703 char *description;
704 /* Cell Identity */
705 uint16_t cell_identity;
706 /* location area code of this BTS */
707 uint16_t location_area_code;
708 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
709 * which is used as TSC for the CCCH */
710 uint8_t bsic;
711 /* type of BTS */
712 enum gsm_bts_type type;
713 enum gsm_bts_type_variant variant;
714 struct gsm_bts_model *model;
715 enum gsm_band band;
716 char version[MAX_VERSION_LENGTH];
717 char sub_model[MAX_VERSION_LENGTH];
718
719 /* features of a given BTS set/reported via OML */
720 struct bitvec features;
721 uint8_t _features_data[MAX_BTS_FEATURES/8];
722
723 /* Connected PCU version (if any) */
724 char pcu_version[MAX_VERSION_LENGTH];
725
726 /* maximum Tx power that the MS is permitted to use in this cell */
727 int ms_max_power;
728
729 /* how do we talk OML with this TRX? */
730 struct gsm_e1_subslot oml_e1_link;
731 uint8_t oml_tei;
732 struct e1inp_sign_link *oml_link;
733 /* when OML link was established */
734 time_t uptime;
735
736 /* Abis network management O&M handle */
737 struct abis_nm_h *nmh;
738
739 struct gsm_abis_mo mo;
740
741 /* number of this BTS on given E1 link */
742 uint8_t bts_nr;
743
744 /* DTX features of this BTS */
745 enum gsm48_dtx_mode dtxu;
746 bool dtxd;
747
748 /* paging state and control */
749 struct gsm_bts_paging_state paging;
750
751 /* CCCH is on C0 */
752 struct gsm_bts_trx *c0;
753
754 struct {
755 struct gsm_abis_mo mo;
756 } site_mgr;
757
758 /* bitmask of all SI that are present/valid in si_buf */
759 uint32_t si_valid;
760 /* 3GPP TS 44.018 Table 10.5.2.33b.1 INDEX and COUNT for SI2quater */
761 uint8_t si2q_index; /* distinguish individual SI2quater messages */
762 uint8_t si2q_count; /* si2q_index for the last (highest indexed) individual SI2quater message */
763 /* buffers where we put the pre-computed SI */
764 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
765 /* offsets used while generating SI2quater */
766 size_t e_offset;
767 size_t u_offset;
768
769 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
770 union {
771 struct {
772 uint16_t site_id;
773 uint16_t bts_id;
774 uint32_t flags;
775 uint32_t rsl_ip;
776 } ip_access;
777 struct {
778 struct {
779 struct gsm_abis_mo mo;
780 } cclk;
781 struct {
782 struct gsm_abis_mo mo;
783 } rack;
784 struct gsm_envabtse envabtse[4];
785 } bs11;
786 struct {
787 struct {
788 struct om2k_mo om2k_mo;
789 struct gsm_abis_mo mo;
790 struct llist_head conn_groups;
791 } cf;
792 struct {
793 struct om2k_mo om2k_mo;
794 struct gsm_abis_mo mo;
795 struct llist_head conn_groups;
796 } is;
797 struct {
798 struct om2k_mo om2k_mo;
799 struct gsm_abis_mo mo;
800 struct llist_head conn_groups;
801 } con;
802 struct {
803 struct om2k_mo om2k_mo;
804 struct gsm_abis_mo mo;
805 } dp;
806 struct {
807 struct om2k_mo om2k_mo;
808 struct gsm_abis_mo mo;
809 } tf;
810 uint32_t use_superchannel:1;
811 } rbs2000;
812 struct {
813 uint8_t bts_type;
814 unsigned int configured:1,
815 skip_reset:1,
816 no_loc_rel_cnf:1,
817 bts_reset_timer_cnf,
818 did_reset:1,
819 wait_reset:1;
820 struct osmo_timer_list reset_timer;
821 } nokia;
822 };
823
824 /* Not entirely sure how ip.access specific this is */
825 struct {
826 uint8_t supports_egprs_11bit_rach;
827 enum bts_gprs_mode mode;
828 struct {
829 struct gsm_abis_mo mo;
830 uint16_t nsei;
831 uint8_t timer[7];
832 } nse;
833 struct {
834 struct gsm_abis_mo mo;
835 uint16_t bvci;
836 uint8_t timer[11];
837 struct gprs_rlc_cfg rlc_cfg;
838 } cell;
839 struct gsm_bts_gprs_nsvc nsvc[2];
840 uint8_t rac;
841 uint8_t net_ctrl_ord;
842 bool ctrl_ack_type_use_block;
843 } gprs;
844
845 /* RACH NM values */
846 int rach_b_thresh;
847 int rach_ldavg_slots;
848
849 /* transceivers */
850 int num_trx;
851 struct llist_head trx_list;
852
853 /* SI related items */
854 int force_combined_si;
855 int bcch_change_mark;
856
857 /* Abis NM queue */
858 struct llist_head abis_queue;
859 int abis_nm_pend;
860
861 struct gsm_network *network;
862
863 /* should the channel allocator allocate channels from high TRX to TRX0,
864 * rather than starting from TRX0 and go upwards? */
865 int chan_alloc_reverse;
866
867 enum neigh_list_manual_mode neigh_list_manual_mode;
868 /* parameters from which we build SYSTEM INFORMATION */
869 struct {
870 struct gsm48_rach_control rach_control;
871 uint8_t ncc_permitted;
872 struct gsm48_cell_sel_par cell_sel_par;
873 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
874 struct gsm48_cell_options cell_options;
875 struct gsm48_control_channel_descr chan_desc;
876 struct bitvec neigh_list;
877 struct bitvec cell_alloc;
878 struct bitvec si5_neigh_list;
879 struct osmo_earfcn_si2q si2quater_neigh_list;
880 size_t uarfcn_length; /* index for uarfcn and scramble lists */
881 struct {
882 /* bitmask large enough for all possible ARFCN's */
883 uint8_t neigh_list[1024/8];
884 uint8_t cell_alloc[1024/8];
885 /* If the user wants a different neighbor list in SI5 than in SI2 */
886 uint8_t si5_neigh_list[1024/8];
887 uint8_t meas_bw_list[MAX_EARFCN_LIST];
888 uint16_t earfcn_list[MAX_EARFCN_LIST];
889 uint16_t uarfcn_list[MAX_EARFCN_LIST];
890 uint16_t scramble_list[MAX_EARFCN_LIST];
891 } data;
892 } si_common;
893 bool early_classmark_allowed;
894 bool early_classmark_allowed_3g;
895 /* for testing only: Have an infinitely long radio link timeout */
896 bool infinite_radio_link_timeout;
897
898 /* do we use static (user-defined) system information messages? (bitmask) */
899 uint32_t si_mode_static;
900
901 /* exclude the BTS from the global RF Lock handling */
902 int excl_from_rf_lock;
903
904 /* supported codecs beside FR */
905 struct bts_codec_conf codec;
906
907 /* BTS dependencies bit field */
908 uint32_t depends_on[256/(8*4)];
909
910 /* full and half rate multirate config */
911 struct amr_multirate_conf mr_full;
912 struct amr_multirate_conf mr_half;
913
914 /* PCU socket state */
915 char *pcu_sock_path;
916 struct pcu_sock_state *pcu_state;
917
918 struct rate_ctr_group *bts_ctrs;
919 struct osmo_stat_item_group *bts_statg;
920
921 struct handover_cfg *ho;
922
923 /* BTS-specific overrides for timer values from struct gsm_network. */
924 uint8_t T3122; /* ASSIGMENT REJECT wait indication */
925
926 /* Periodic channel load measurements are used to maintain T3122. */
927 struct load_counter chan_load_samples[7];
928 int chan_load_samples_idx;
929};
930
931
932struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, uint8_t bts_num);
933struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
934
935struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
936struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
937
938enum gsm_bts_type str2btstype(const char *arg);
939const char *btstype2str(enum gsm_bts_type type);
940
941enum bts_attribute str2btsattr(const char *s);
942const char *btsatttr2str(enum bts_attribute v);
943
944enum gsm_bts_type_variant str2btsvariant(const char *arg);
945const char *btsvariant2str(enum gsm_bts_type_variant v);
946
947extern const struct value_string gsm_chreq_descs[];
948const struct value_string gsm_pchant_names[13];
949const struct value_string gsm_pchant_descs[13];
950const char *gsm_pchan_name(enum gsm_phys_chan_config c);
951enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
952const char *gsm_lchant_name(enum gsm_chan_t c);
953const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
954char *gsm_trx_name(const struct gsm_bts_trx *trx);
955char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
956char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
957char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
958const char *gsm_lchans_name(enum gsm_lchan_state s);
959
960static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
961{
962 return lchan->name;
963}
964
965static inline int gsm_bts_set_feature(struct gsm_bts *bts, enum gsm_bts_features feat)
966{
967 OSMO_ASSERT(_NUM_BTS_FEAT < MAX_BTS_FEATURES);
968 return bitvec_set_bit_pos(&bts->features, feat, 1);
969}
970
971static inline bool gsm_bts_has_feature(const struct gsm_bts *bts, enum gsm_bts_features feat)
972{
973 OSMO_ASSERT(_NUM_BTS_FEAT < MAX_BTS_FEATURES);
974 return bitvec_get_bit_pos(&bts->features, feat);
975}
976
977void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
978
979struct gsm_nm_state *
980gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
981 const struct abis_om_obj_inst *obj_inst);
982void *
983gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
984 const struct abis_om_obj_inst *obj_inst);
985
986/* reset the state of all MO in the BTS */
987void gsm_bts_mo_reset(struct gsm_bts *bts);
988
989uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
990 uint8_t ts_nr, uint8_t lchan_nr);
991uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
992uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
993 enum gsm_phys_chan_config as_pchan);
994
995/* return the gsm_lchan for the CBCH (if it exists at all) */
996struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
997
998/*
999 * help with parsing regexps
1000 */
1001int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
1002 int argc, const char **argv) __attribute__ ((warn_unused_result));
1003
1004static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
1005{
1006 if (ts->tsc != -1)
1007 return ts->tsc;
1008 else
1009 return ts->trx->bts->bsic & 7;
1010}
1011
1012struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
1013 int *rc);
1014
1015enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
1016uint8_t ts_subslots(struct gsm_bts_trx_ts *ts);
1017bool ts_is_tch(struct gsm_bts_trx_ts *ts);
1018
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01001019
Harald Welteb7948872017-12-18 18:48:21 +01001020static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection *conn) {
1021 OSMO_ASSERT(conn->lchan);
1022 return conn->lchan->ts->trx->bts;
1023}
1024
Harald Welted82101e2017-12-09 23:07:38 +01001025enum {
1026 BTS_CTR_CHREQ_TOTAL,
1027 BTS_CTR_CHREQ_NO_CHANNEL,
1028 BTS_CTR_CHAN_RF_FAIL,
1029 BTS_CTR_CHAN_RLL_ERR,
1030 BTS_CTR_BTS_OML_FAIL,
1031 BTS_CTR_BTS_RSL_FAIL,
1032 BTS_CTR_CODEC_AMR_F,
1033 BTS_CTR_CODEC_AMR_H,
1034 BTS_CTR_CODEC_EFR,
1035 BTS_CTR_CODEC_V1_FR,
1036 BTS_CTR_CODEC_V1_HR,
Harald Weltecf9d4312017-12-13 23:17:16 +01001037 BTS_CTR_PAGING_ATTEMPTED,
1038 BTS_CTR_PAGING_ALREADY,
1039 BTS_CTR_PAGING_RESPONDED,
1040 BTS_CTR_PAGING_EXPIRED,
Harald Welte4f598922017-12-14 13:47:02 +01001041 BTS_CTR_CHAN_ACT_TOTAL,
1042 BTS_CTR_CHAN_ACT_NACK,
Harald Welte62d9cb02017-12-14 14:00:26 +01001043 BTS_CTR_RSL_UNKNOWN,
Harald Welte581398a2017-12-14 14:29:44 +01001044 BTS_CTR_RSL_IPA_NACK,
Harald Welte00d64fd2017-12-14 14:34:16 +01001045 BTS_CTR_MODE_MODIFY_NACK,
Harald Welted82101e2017-12-09 23:07:38 +01001046};
1047
1048static const struct rate_ctr_desc bts_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001049 [BTS_CTR_CHREQ_TOTAL] = {"chreq:total", "Received channel requests."},
1050 [BTS_CTR_CHREQ_NO_CHANNEL] = {"chreq:no_channel", "Sent to MS no channel available."},
1051 [BTS_CTR_CHAN_RF_FAIL] = {"chan:rf_fail", "Received a RF failure indication from BTS."},
1052 [BTS_CTR_CHAN_RLL_ERR] = {"chan:rll_err", "Received a RLL failure with T200 cause from BTS."},
Harald Welted82101e2017-12-09 23:07:38 +01001053 [BTS_CTR_BTS_OML_FAIL] = {"oml_fail", "Received a TEI down on a OML link."},
1054 [BTS_CTR_BTS_RSL_FAIL] = {"rsl_fail", "Received a TEI down on a OML link."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001055 [BTS_CTR_CODEC_AMR_F] = {"codec:amr_f", "Count the usage of AMR/F codec by channel mode requested."},
1056 [BTS_CTR_CODEC_AMR_H] = {"codec:amr_h", "Count the usage of AMR/H codec by channel mode requested."},
1057 [BTS_CTR_CODEC_EFR] = {"codec:efr", "Count the usage of EFR codec by channel mode requested."},
1058 [BTS_CTR_CODEC_V1_FR] = {"codec:fr", "Count the usage of FR codec by channel mode requested."},
1059 [BTS_CTR_CODEC_V1_HR] = {"codec:hr", "Count the usage of HR codec by channel mode requested."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001060
1061 [BTS_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
1062 [BTS_CTR_PAGING_ALREADY] = {"paging:already", "Paging attempts ignored as subsciber was already being paged."},
1063 [BTS_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful paging response."},
1064 [BTS_CTR_PAGING_EXPIRED] = {"paging:expired", "Paging Request expired because of timeout T3113."},
Harald Welte4f598922017-12-14 13:47:02 +01001065 [BTS_CTR_CHAN_ACT_TOTAL] = {"chan_act:total", "Total number of Channel Activations."},
1066 [BTS_CTR_CHAN_ACT_NACK] = {"chan_act:nack", "Number of Channel Activations that the BTS NACKed"},
Harald Welte62d9cb02017-12-14 14:00:26 +01001067 [BTS_CTR_RSL_UNKNOWN] = {"rsl:unknown", "Number of unknown/unsupported RSL messages received from BTS"},
Harald Welte581398a2017-12-14 14:29:44 +01001068 [BTS_CTR_RSL_IPA_NACK] = {"rsl:ipa_nack", "Number of IPA (RTP/dyn-PDCH) related NACKs received from BTS"},
Harald Welte00d64fd2017-12-14 14:34:16 +01001069 [BTS_CTR_MODE_MODIFY_NACK] = {"chan:mode_modify_nack", "Number of Channel Mode Modify NACKs received from BTS"},
Harald Welted82101e2017-12-09 23:07:38 +01001070};
1071
1072static const struct rate_ctr_group_desc bts_ctrg_desc = {
1073 "bts",
1074 "base transceiver station",
1075 OSMO_STATS_CLASS_GLOBAL,
1076 ARRAY_SIZE(bts_ctr_description),
1077 bts_ctr_description,
1078};
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001079
Alexander Couzens20423ea2016-07-12 15:42:02 +02001080enum {
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001081 BTS_STAT_CHAN_LOAD_AVERAGE,
1082 BTS_STAT_T3122,
1083};
1084
1085enum {
Alexander Couzensb847a212016-08-02 11:34:11 +02001086 BSC_CTR_HANDOVER_ATTEMPTED,
1087 BSC_CTR_HANDOVER_NO_CHANNEL,
1088 BSC_CTR_HANDOVER_TIMEOUT,
1089 BSC_CTR_HANDOVER_COMPLETED,
1090 BSC_CTR_HANDOVER_FAILED,
1091 BSC_CTR_PAGING_ATTEMPTED,
1092 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +01001093 BSC_CTR_PAGING_RESPONDED,
Alexander Couzensb847a212016-08-02 11:34:11 +02001094};
1095
1096static const struct rate_ctr_desc bsc_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001097 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Received handover attempts."},
1098 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Sent no channel available responses."},
1099 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Count the amount of timeouts of timer T3103."},
1100 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Received handover completed."},
1101 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Receive HO FAIL messages."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001102
1103 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001104 [BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Counts the amount of paging attempts which couldn't sent out any paging request because no responsible bts found."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001105 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response."},
Alexander Couzensb847a212016-08-02 11:34:11 +02001106};
1107
Alexander Couzensb847a212016-08-02 11:34:11 +02001108
1109
1110static const struct rate_ctr_group_desc bsc_ctrg_desc = {
1111 "bsc",
1112 "base station controller",
1113 OSMO_STATS_CLASS_GLOBAL,
1114 ARRAY_SIZE(bsc_ctr_description),
1115 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +02001116};
1117
Harald Weltedea252d2017-12-10 19:55:18 +01001118#define GSM_T3101_DEFAULT 3 /* s */
Harald Weltea0d324b2017-07-20 01:47:39 +02001119#define GSM_T3103_DEFAULT 5 /* s */
1120#define GSM_T3105_DEFAULT 100 /* ms */
1121#define GSM_T3107_DEFAULT 5 /* s */
Harald Welteed23c1d2017-12-10 19:58:16 +01001122#define GSM_T3109_DEFAULT 5 /* s, must be 2s + radio_link_timeout*0.48 */
Harald Weltea0d324b2017-07-20 01:47:39 +02001123#define GSM_T3111_DEFAULT 2 /* s */
Harald Welte6e59ced2017-12-14 12:49:43 +01001124#define GSM_T3113_DEFAULT 10 /* s */
Harald Weltea0d324b2017-07-20 01:47:39 +02001125#define GSM_T3115_DEFAULT 10
1126#define GSM_T3117_DEFAULT 10
1127#define GSM_T3119_DEFAULT 10
Andreas Eversberg75e13a42013-02-07 11:51:16 +01001128#define GSM_T3122_DEFAULT 10
Harald Weltea0d324b2017-07-20 01:47:39 +02001129#define GSM_T3141_DEFAULT 10
Harald Welteb84ddfc2009-12-01 17:36:54 +05301130
Neels Hofmeyr73983952016-05-10 13:29:33 +02001131struct gsm_tz {
1132 int override; /* if 0, use system's time zone instead. */
1133 int hr; /* hour */
1134 int mn; /* minute */
1135 int dst; /* daylight savings */
1136};
1137
Harald Welte52b1f982008-12-23 20:25:15 +00001138struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001139 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
1140 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
1141 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
1142 * these have in common, like country and network code, put in yet
1143 * separate structs and placed as members in osmo_bsc and osmo_msc. */
1144
Harald Welte52b1f982008-12-23 20:25:15 +00001145 /* global parameters */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +02001146 uint16_t country_code;
1147 uint16_t network_code;
Harald Welte4381cfe2009-08-30 15:47:06 +09001148 int a5_encryption;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001149 int neci;
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001150 struct handover_cfg *ho;
Harald Welte52b1f982008-12-23 20:25:15 +00001151
Alexander Couzensb847a212016-08-02 11:34:11 +02001152 struct rate_ctr_group *bsc_ctrs;
Harald Welte24ff6ee2009-12-22 00:41:05 +01001153
Holger Hans Peter Freytherabcddf12010-06-14 18:20:15 +08001154 struct bsc_api *bsc_api;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001155
Harald Welte52b1f982008-12-23 20:25:15 +00001156 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +02001157 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001158
1159 /* timer values */
1160 int T3101;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +01001161 int T3103;
1162 int T3105;
1163 int T3107;
1164 int T3109;
1165 int T3111;
1166 int T3113;
1167 int T3115;
1168 int T3117;
1169 int T3119;
Harald Welte2862dca2010-12-23 14:39:29 +01001170 int T3122;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +01001171 int T3141;
Harald Welteeab84a12009-12-13 10:53:12 +01001172
Jan Luebbebfbdeec2012-12-27 00:27:16 +01001173 /* timer to expire old location updates */
1174 struct osmo_timer_list subscr_expire_timer;
1175
Alexander Couzens547c2072017-11-21 12:03:04 +01001176 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +08001177
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +08001178 /* Use a TCH for handling requests of type paging any */
1179 int pag_any_tch;
1180
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08001181 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +02001182 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +01001183
Daniel Willmann6fc4a982011-07-22 17:55:42 +02001184 /* control interface */
1185 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +02001186
1187 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
1188 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +02001189
1190 /* all active subscriber connections. */
1191 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +02001192
1193 /* if override is nonzero, this timezone data is used for all MM
1194 * contexts. */
1195 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
1196 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +01001197 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +02001198 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +01001199
1200 /* List of all struct bsc_subscr used in libbsc. This llist_head is
1201 * allocated so that the llist_head pointer itself can serve as a
1202 * talloc context (useful to not have to pass the entire gsm_network
1203 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
1204 * not require gsm_data.h). In an MSC-without-BSC environment, this
1205 * pointer is NULL to indicate absence of a bsc_subscribers list. */
1206 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +02001207
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001208 /* Periodic location update default value */
1209 uint8_t t3212;
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001210
Stefan Sperling6cee8932018-01-30 18:14:22 +01001211 /* Timer for periodic channel load measurements to maintain each BTS's T3122. */
1212 struct osmo_timer_list t3122_chan_load_timer;
1213
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001214 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +02001215 struct mgcp_client_conf *conf;
1216 struct mgcp_client *client;
1217 } mgw;
Harald Welte7e310b12009-03-30 20:56:32 +00001218};
1219
Neels Hofmeyrc13e6872016-05-11 13:53:47 +02001220extern void talloc_ctx_init(void *ctx_root);
1221
Harald Welte39315c42010-01-10 18:01:52 +01001222int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +02001223
Harald Welte1d014a52009-08-08 15:38:29 +02001224enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +02001225const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +00001226struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
1227 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +00001228
Andreas Eversberg8226fa72009-06-29 15:19:38 +02001229extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +01001230extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +02001231
Harald Weltef383aa12012-07-02 19:51:55 +02001232/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +00001233static inline int is_ipaccess_bts(struct gsm_bts *bts)
1234{
1235 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001236 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001237 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +00001238 return 1;
1239 default:
1240 break;
1241 }
1242 return 0;
1243}
1244
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001245static inline int is_sysmobts_v2(struct gsm_bts *bts)
1246{
1247 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +01001248 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001249 return 1;
1250 default:
1251 break;
1252 }
1253 return 0;
1254}
1255
Harald Welte5b570672009-08-10 10:08:01 +02001256static inline int is_siemens_bts(struct gsm_bts *bts)
1257{
1258 switch (bts->type) {
1259 case GSM_BTS_TYPE_BS11:
1260 return 1;
1261 default:
1262 break;
1263 }
1264
1265 return 0;
1266}
1267
Andreas Eversberg7d8fa342013-12-05 13:25:06 +01001268static inline int is_nokia_bts(struct gsm_bts *bts)
1269{
1270 switch (bts->type) {
1271 case GSM_BTS_TYPE_NOKIA_SITE:
1272 return 1;
1273 default:
1274 break;
1275 }
1276
1277 return 0;
1278}
1279
Andreas Eversbergdcf38e12013-12-05 14:37:11 +01001280static inline int is_e1_bts(struct gsm_bts *bts)
1281{
1282 switch (bts->type) {
1283 case GSM_BTS_TYPE_BS11:
1284 case GSM_BTS_TYPE_RBS2000:
1285 case GSM_BTS_TYPE_NOKIA_SITE:
1286 return 1;
1287 default:
1288 break;
1289 }
1290
1291 return 0;
1292}
1293
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001294enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +02001295const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001296int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +02001297
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +02001298int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +08001299void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +01001300
Harald Weltef3d8e922010-06-14 22:44:42 +02001301int gsm_btsmodel_set_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
Harald Weltefbda4e12010-03-04 11:04:52 +01001302int gsm_bts_model_register(struct gsm_bts_model *model);
1303
Neels Hofmeyr42eb0142016-05-20 17:15:44 +02001304struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_lchan *lchan);
1305void bsc_subscr_con_free(struct gsm_subscriber_connection *conn);
1306
1307struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
1308void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +08001309
Harald Welte3300c012011-06-05 13:31:33 +02001310struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net,
1311 enum gsm_bts_type type,
Harald Weltea2bbc5e2015-11-20 10:43:31 +01001312 uint8_t bsic);
Harald Welte142d12d2014-12-29 17:47:08 +01001313
Harald Welte3300c012011-06-05 13:31:33 +02001314void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
1315 uint8_t e1_ts, uint8_t e1_ts_ss);
1316
Maxbe356ed2017-09-07 19:10:09 +02001317void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Max71d082b2017-05-30 15:03:38 +02001318bool gsm_btsmodel_has_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
Harald Welte3300c012011-06-05 13:31:33 +02001319struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +01001320int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -04001321int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +02001322
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +02001323/* generic E1 line operations for all ISDN-based BTS. */
1324extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
1325
Harald Weltee555c2b2012-08-17 13:02:12 +02001326extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
1327extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
1328
Max3d049d22017-10-09 17:12:53 +02001329char *get_model_oml_status(const struct gsm_bts *bts);
1330
Max25cc4072017-10-10 14:50:35 +02001331unsigned long long bts_uptime(const struct gsm_bts *bts);
1332
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +01001333/* control interface handling */
1334int bsc_base_ctrl_cmds_install(void);
1335
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001336/* dependency handling */
1337void bts_depend_mark(struct gsm_bts *bts, int dep);
1338void bts_depend_clear(struct gsm_bts *bts, int dep);
1339int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +01001340int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001341
Harald Welte2f8b9d22017-06-18 11:12:13 +03001342int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
1343void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
1344
Harald Weltea43e0b42016-06-19 18:06:02 +02001345bool classmark_is_r99(struct gsm_classmark *cm);
1346
Harald Welte6be350c2011-05-25 13:10:08 +02001347#endif /* _GSM_DATA_H */