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