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