blob: 27aa2619e30c627dd5a7b72b59abb7fd318c0e9d [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>
Neels Hofmeyra60f3442018-02-12 16:44:32 +010015#include <osmocom/gsm/protocol/gsm_08_08.h>
Neels Hofmeyrf93970b2018-03-05 02:09:40 +010016#include <osmocom/gsm/gsm48.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020017
Harald Welte121e9a42016-04-20 13:13:19 +020018#include <osmocom/crypt/auth.h>
Harald Weltef142c972011-05-24 13:25:38 +020019
Neels Hofmeyrc0164792017-09-04 15:15:32 +020020#include <osmocom/bsc/rest_octets.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>
Harald Welte519c7e12018-01-28 02:45:46 +010029#include <osmocom/bsc/bsc_msg_filter.h>
Stefan Sperling6442e432018-02-06 14:44:54 +010030#include <osmocom/bsc/acc_ramp.h>
Neels Hofmeyr10485162018-02-13 23:22:03 +010031
Harald Welte74b8cdb2018-01-15 19:26:06 +010032struct mgcp_client_conf;
33struct mgcp_client;
34struct mgcp_ctx;
Philipp Maier39f62bb2017-04-09 12:32:51 +020035
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020036/** annotations for msgb ownership */
37#define __uses
38
Holger Hans Peter Freyther6f615552010-11-15 20:50:42 +010039#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
40
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010041struct bsc_subscr;
Neels Hofmeyr7b656882017-07-09 22:09:18 +020042struct gprs_ra_id;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020043
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080044#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
45
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010046#define tmsi_from_string(str) strtoul(str, NULL, 10)
47
Max70fdd242017-06-15 15:10:53 +020048/* 3-bit long values */
49#define EARFCN_PRIO_INVALID 8
50#define EARFCN_MEAS_BW_INVALID 8
51/* 5-bit long values */
52#define EARFCN_QRXLV_INVALID 32
53#define EARFCN_THRESH_LOW_INVALID 32
54
Harald Welte8e1e3ee2009-02-01 13:32:45 +000055struct msgb;
56typedef int gsm_cbfn(unsigned int hooknum,
57 unsigned int event,
58 struct msgb *msg,
59 void *data, void *param);
60
Harald Weltef7c28b02009-12-21 13:30:17 +010061/* Maximum number of neighbor cells whose average we track */
62#define MAX_NEIGH_MEAS 10
63/* Maximum size of the averaging window for neighbor cells */
64#define MAX_WIN_NEIGH_AVG 10
Andreas Eversberg98692032013-06-23 10:44:34 +020065/* Maximum number of report history we store */
66#define MAX_MEAS_REP 10
Harald Weltef7c28b02009-12-21 13:30:17 +010067
68/* processed neighbor measurements for one cell */
69struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020070 uint16_t arfcn;
71 uint8_t bsic;
72 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +010073 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020074 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +010075};
76
Harald Weltea43e0b42016-06-19 18:06:02 +020077struct gsm_classmark {
78 bool classmark1_set;
79 struct gsm48_classmark1 classmark1;
80 uint8_t classmark2_len;
81 uint8_t classmark2[3];
82 uint8_t classmark3_len;
83 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
84};
85
Harald Welte519c7e12018-01-28 02:45:46 +010086enum subscr_sccp_state {
87 SUBSCR_SCCP_ST_NONE,
88 SUBSCR_SCCP_ST_WAIT_CONN_CONF,
89 SUBSCR_SCCP_ST_CONNECTED
90};
91
Neels Hofmeyr378a4922016-05-09 21:07:43 +020092/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010093struct gsm_subscriber_connection {
Harald Weltea43e0b42016-06-19 18:06:02 +020094 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +080095 struct llist_head entry;
96
Harald Weltea43e0b42016-06-19 18:06:02 +020097 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010098 struct bsc_subscr *bsub;
99
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100100 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200101 struct gsm_network *network;
102
Harald Welte4a8ebc82017-12-18 18:34:41 +0100103 /* the primary / currently active lchan to the BTS/subscriber */
104 struct gsm_lchan *lchan;
105 /* the future/allocated but not yet used lchan during HANDOVER */
106 struct gsm_lchan *ho_lchan;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100107
Harald Welte4a8ebc82017-12-18 18:34:41 +0100108 /* timer for assignment handling */
109 struct osmo_timer_list T10;
110 /* the future allocated but not yet used lchan during ASSIGNMENT */
111 struct gsm_lchan *secondary_lchan;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100112
Harald Welte4a8ebc82017-12-18 18:34:41 +0100113 /* buffer/cache for classmark of the ME of the subscriber */
Harald Weltea43e0b42016-06-19 18:06:02 +0200114 struct gsm_classmark classmark;
Andreas Eversberg935e5d72013-06-17 11:58:30 +0200115
116 /* Cache DTAP messages during handover/assignment (msgb_enqueue()/msgb_dequeue())*/
117 struct llist_head ho_dtap_cache;
118 unsigned int ho_dtap_cache_len;
Andreas Eversberg084b4212013-05-30 14:12:48 +0200119
Neels Hofmeyrec422642018-02-15 14:07:40 +0100120 struct {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100121 int failures;
Neels Hofmeyrec422642018-02-15 14:07:40 +0100122 struct penalty_timers *penalty_timers;
123 } hodec2;
Neels Hofmeyra60f3442018-02-12 16:44:32 +0100124
125 /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment Request. 3GPP 48.008
126 * 3.2.2.103 says:
127 * The "Codec List (MSC Preferred)" shall not include codecs
128 * that are not supported by the MS.
129 * i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed the MS bearer
130 * capabilities, which the MSC is required to translate into the codec list. */
131 struct gsm0808_speech_codec_list codec_list;
132 bool codec_list_present;
Harald Welte519c7e12018-01-28 02:45:46 +0100133
134 /* flag to prevent multiple simultaneous ciphering commands */
135 int ciphering_handled;
136
137 /* state related to welcome USSD */
138 uint8_t new_subscriber;
139
140 /* state related to osmo_bsc_filter.c */
141 struct bsc_filter_state filter_state;
142
143 /* SCCP connection associatd with this subscriber_connection */
144 struct {
145 /* for advanced ping/pong */
146 int send_ping;
147
148 /* SCCP connection realted */
149 struct bsc_msc_data *msc;
150
151 /* Sigtran connection ID */
152 int conn_id;
153 enum subscr_sccp_state state;
154 } sccp;
155
156 /* for audio handling */
157 struct {
158 uint16_t cic;
159 uint32_t rtp_ip;
160 int rtp_port;
161 /* RTP address of the remote end (assigned by MSC through assignment request) */
162 struct sockaddr_storage aoip_rtp_addr_remote;
163
164 /* Local RTP address (reported back to the MSC by us with the
165 * assignment complete message) */
166 struct sockaddr_storage aoip_rtp_addr_local;
167
168 /* storage to keep states of the MGCP connection handler, the
169 * handler is created when an assignment request is received
170 * and is terminated when the assignment complete message is
171 * sent */
172 struct mgcp_ctx *mgcp_ctx;
173 } user_plane;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100174};
175
Harald Weltef142c972011-05-24 13:25:38 +0200176
Neels Hofmeyr10485162018-02-13 23:22:03 +0100177/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 Table 10.5.2.33b.1:
178 4-bit index is used (2#1111 = 10#15) */
179#define SI2Q_MAX_NUM 16
180/* length in bits (for single SI2quater message) */
181#define SI2Q_MAX_LEN 160
182#define SI2Q_MIN_LEN 18
183
184struct osmo_bsc_data;
185
186struct osmo_bsc_sccp_con;
187
188/* Channel Request reason */
189enum gsm_chreq_reason_t {
190 GSM_CHREQ_REASON_EMERG,
191 GSM_CHREQ_REASON_PAG,
192 GSM_CHREQ_REASON_CALL,
193 GSM_CHREQ_REASON_LOCATION_UPD,
194 GSM_CHREQ_REASON_OTHER,
195 GSM_CHREQ_REASON_PDCH,
196};
197
198/* lchans 0..3 are SDCCH in combined channel configuration,
199 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
200#define CCCH_LCHAN 4
201
202#define TRX_NR_TS 8
203#define TS_MAX_LCHAN 8
204
205#define HARDCODED_ARFCN 123
206#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
207
208/* for multi-drop config */
209#define HARDCODED_BTS0_TS 1
210#define HARDCODED_BTS1_TS 6
211#define HARDCODED_BTS2_TS 11
212
213#define MAX_VERSION_LENGTH 64
214
215#define MAX_BTS_FEATURES 128
216
217enum gsm_hooks {
218 GSM_HOOK_NM_SWLOAD,
219 GSM_HOOK_RR_PAGING,
220 GSM_HOOK_RR_SECURITY,
221};
222
223enum gsm_paging_event {
224 GSM_PAGING_SUCCEEDED,
225 GSM_PAGING_EXPIRED,
226 GSM_PAGING_OOM,
227 GSM_PAGING_BUSY,
228};
229
230enum bts_gprs_mode {
231 BTS_GPRS_NONE = 0,
232 BTS_GPRS_GPRS = 1,
233 BTS_GPRS_EGPRS = 2,
234};
235
236struct gsm_lchan;
237struct osmo_rtp_socket;
238struct rtp_socket;
239struct bsc_api;
240
241/* Network Management State */
242struct gsm_nm_state {
243 uint8_t operational;
244 uint8_t administrative;
245 uint8_t availability;
246};
247
248struct gsm_abis_mo {
249 uint8_t obj_class;
250 uint8_t procedure_pending;
251 struct abis_om_obj_inst obj_inst;
252 const char *name;
253 struct gsm_nm_state nm_state;
254 struct tlv_parsed *nm_attr;
255 struct gsm_bts *bts;
256};
257
258/* Ericsson OM2000 Managed Object */
259struct abis_om2k_mo {
260 uint8_t class;
261 uint8_t bts;
262 uint8_t assoc_so;
263 uint8_t inst;
264} __attribute__ ((packed));
265
266struct om2k_mo {
267 struct abis_om2k_mo addr;
268 struct osmo_fsm_inst *fsm;
269};
270
271#define A38_XOR_MIN_KEY_LEN 12
272#define A38_XOR_MAX_KEY_LEN 16
273#define A38_COMP128_KEY_LEN 16
274#define RSL_ENC_ALG_A5(x) (x+1)
275#define MAX_EARFCN_LIST 32
276
277/* is the data link established? who established it? */
278#define LCHAN_SAPI_UNUSED 0
279#define LCHAN_SAPI_MS 1
280#define LCHAN_SAPI_NET 2
281#define LCHAN_SAPI_REL 3
282
283/* state of a logical channel */
284enum gsm_lchan_state {
285 LCHAN_S_NONE, /* channel is not active */
286 LCHAN_S_ACT_REQ, /* channel activation requested */
287 LCHAN_S_ACTIVE, /* channel is active and operational */
288 LCHAN_S_REL_REQ, /* channel release has been requested */
289 LCHAN_S_REL_ERR, /* channel is in an error state */
290 LCHAN_S_BROKEN, /* channel is somehow unusable */
291 LCHAN_S_INACTIVE, /* channel is set inactive */
292};
293
294/* BTS ONLY */
295#define MAX_NUM_UL_MEAS 104
296#define LC_UL_M_F_L1_VALID (1 << 0)
297#define LC_UL_M_F_RES_VALID (1 << 1)
298
299struct bts_ul_meas {
300 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
301 uint16_t ber10k;
302 /* timing advance offset (in quarter bits) */
303 int16_t ta_offs_qbits;
304 /* C/I ratio in dB */
305 float c_i;
306 /* flags */
307 uint8_t is_sub:1;
308 /* RSSI in dBm * -1 */
309 uint8_t inv_rssi;
310};
311
312struct bts_codec_conf {
313 uint8_t hr;
314 uint8_t efr;
315 uint8_t amr;
316};
317
318struct amr_mode {
319 uint8_t mode;
320 uint8_t threshold;
321 uint8_t hysteresis;
322};
323
324struct amr_multirate_conf {
325 uint8_t gsm48_ie[2];
326 struct amr_mode ms_mode[4];
327 struct amr_mode bts_mode[4];
328 uint8_t num_modes;
329};
330/* /BTS ONLY */
331
332enum lchan_csd_mode {
333 LCHAN_CSD_M_NT,
334 LCHAN_CSD_M_T_1200_75,
335 LCHAN_CSD_M_T_600,
336 LCHAN_CSD_M_T_1200,
337 LCHAN_CSD_M_T_2400,
338 LCHAN_CSD_M_T_9600,
339 LCHAN_CSD_M_T_14400,
340 LCHAN_CSD_M_T_29000,
341 LCHAN_CSD_M_T_32000,
342};
343
344/* State of the SAPIs in the lchan */
345enum lchan_sapi_state {
346 LCHAN_SAPI_S_NONE,
347 LCHAN_SAPI_S_REQ,
348 LCHAN_SAPI_S_ASSIGNED,
349 LCHAN_SAPI_S_REL,
350 LCHAN_SAPI_S_ERROR,
351};
352
Neels Hofmeyr92b9f2e2018-02-14 00:19:11 +0100353#define MAX_A5_KEY_LEN (128/8)
354
355struct gsm_encr {
356 uint8_t alg_id;
357 uint8_t key_len;
358 uint8_t key[MAX_A5_KEY_LEN];
359};
360
Neels Hofmeyr10485162018-02-13 23:22:03 +0100361struct gsm_lchan {
362 /* The TS that we're part of */
363 struct gsm_bts_trx_ts *ts;
364 /* The logical subslot number in the TS */
365 uint8_t nr;
366 /* The logical channel type */
367 enum gsm_chan_t type;
368 /* RSL channel mode */
369 enum rsl_cmod_spd rsl_cmode;
370 /* If TCH, traffic channel mode */
371 enum gsm48_chan_mode tch_mode;
372 enum lchan_csd_mode csd_mode;
373 /* State */
374 enum gsm_lchan_state state;
375 const char *broken_reason;
376 /* Power levels for MS and BTS */
377 uint8_t bs_power;
378 uint8_t ms_power;
379 /* Encryption information */
380 struct gsm_encr encr;
381
382 /* AMR bits */
383 uint8_t mr_ms_lv[7];
384 uint8_t mr_bts_lv[7];
385
386 /* Established data link layer services */
387 uint8_t sapis[8];
388
389 struct {
390 uint32_t bound_ip;
391 uint32_t connect_ip;
392 uint16_t bound_port;
393 uint16_t connect_port;
394 uint16_t conn_id;
395 uint8_t rtp_payload;
396 uint8_t rtp_payload2;
397 uint8_t speech_mode;
398 struct rtp_socket *rtp_socket;
399
400 /* info we need to postpone the AoIP
401 * assignment completed message */
402 struct {
403 uint8_t rr_cause;
404 uint8_t chosen_channel;
405 uint8_t encr_alg_id;
406 uint8_t speech_mode;
407 bool valid;
408 } ass_compl;
409 } abis_ip;
410
411 uint8_t rqd_ta;
412
413 char *name;
414
415 struct osmo_timer_list T3101;
416 struct osmo_timer_list T3109;
417 struct osmo_timer_list T3111;
418 struct osmo_timer_list error_timer;
419 struct osmo_timer_list act_timer;
420 struct osmo_timer_list rel_work;
421 uint8_t error_cause;
422
423 /* table of neighbor cell measurements */
424 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
425
426 /* cache of last measurement reports on this lchan */
427 struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
428 int meas_rep_idx;
429 int meas_rep_count;
Neels Hofmeyr35ba85c2018-02-12 16:47:40 +0100430 uint8_t meas_rep_last_seen_nr;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100431
432 /* GSM Random Access data */
433 struct gsm48_req_ref *rqd_ref;
434
435 struct gsm_subscriber_connection *conn;
436
437 struct {
438 /* channel activation type and handover ref */
439 uint8_t act_type;
440 uint8_t ho_ref;
441 struct gsm48_req_ref *rqd_ref;
442 uint8_t rqd_ta;
443 } dyn;
444};
445
446enum {
447 TS_F_PDCH_ACTIVE = 0x1000,
448 TS_F_PDCH_ACT_PENDING = 0x2000,
449 TS_F_PDCH_DEACT_PENDING = 0x4000,
450 TS_F_PDCH_PENDING_MASK = 0x6000 /*<
451 TS_F_PDCH_ACT_PENDING | TS_F_PDCH_DEACT_PENDING */
452} gsm_bts_trx_ts_flags;
453
454/* One Timeslot in a TRX */
455struct gsm_bts_trx_ts {
456 struct gsm_bts_trx *trx;
457 /* number of this timeslot at the TRX */
458 uint8_t nr;
459
460 enum gsm_phys_chan_config pchan;
461
462 struct {
463 enum gsm_phys_chan_config pchan_is;
464 enum gsm_phys_chan_config pchan_want;
465 struct msgb *pending_chan_activ;
466 } dyn;
467
468 unsigned int flags;
469 struct gsm_abis_mo mo;
470 struct tlv_parsed nm_attr;
471 uint8_t nm_chan_comb;
472 int tsc; /* -1 == use BTS TSC */
473
474 struct {
475 /* Parameters below are configured by VTY */
476 int enabled;
477 uint8_t maio;
478 uint8_t hsn;
479 struct bitvec arfcns;
480 uint8_t arfcns_data[1024/8];
481 /* This is the pre-computed MA for channel assignments */
482 struct bitvec ma;
483 uint8_t ma_len; /* part of ma_data that is used */
484 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
485 } hopping;
486
487 /* To which E1 subslot are we connected */
488 struct gsm_e1_subslot e1_link;
489
490 union {
491 struct {
492 struct om2k_mo om2k_mo;
493 } rbs2000;
494 };
495
496 struct gsm_lchan lchan[TS_MAX_LCHAN];
497};
498
499/* One TRX in a BTS */
500struct gsm_bts_trx {
501 /* list header in bts->trx_list */
502 struct llist_head list;
503
504 struct gsm_bts *bts;
505 /* number of this TRX in the BTS */
506 uint8_t nr;
507 /* human readable name / description */
508 char *description;
509 /* how do we talk RSL with this TRX? */
510 struct gsm_e1_subslot rsl_e1_link;
511 uint8_t rsl_tei;
512 struct e1inp_sign_link *rsl_link;
513
514 /* Timeout for initiating the RSL connection. */
515 struct osmo_timer_list rsl_connect_timeout;
516
517 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
518 struct e1inp_sign_link *oml_link;
519
520 struct gsm_abis_mo mo;
521 struct tlv_parsed nm_attr;
522 struct {
523 struct gsm_abis_mo mo;
524 } bb_transc;
525
526 uint16_t arfcn;
527 int nominal_power; /* in dBm */
528 unsigned int max_power_red; /* in actual dB */
529
530 union {
531 struct {
532 struct {
533 struct gsm_abis_mo mo;
534 } bbsig;
535 struct {
536 struct gsm_abis_mo mo;
537 } pa;
538 } bs11;
539 struct {
540 unsigned int test_state;
541 uint8_t test_nr;
542 struct rxlev_stats rxlev_stat;
543 } ipaccess;
544 struct {
545 struct {
546 struct om2k_mo om2k_mo;
547 } trxc;
548 struct {
549 struct om2k_mo om2k_mo;
550 } rx;
551 struct {
552 struct om2k_mo om2k_mo;
553 } tx;
554 } rbs2000;
555 };
556 struct gsm_bts_trx_ts ts[TRX_NR_TS];
557};
558
559#define GSM_BTS_SI2Q(bts, i) (struct gsm48_system_information_type_2quater *)((bts)->si_buf[SYSINFO_TYPE_2quater][i])
560#define GSM_BTS_HAS_SI(bts, i) ((bts)->si_valid & (1 << i))
561#define GSM_BTS_SI(bts, i) (void *)((bts)->si_buf[i][0])
562#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
563
564enum gsm_bts_type {
565 GSM_BTS_TYPE_UNKNOWN,
566 GSM_BTS_TYPE_BS11,
567 GSM_BTS_TYPE_NANOBTS,
568 GSM_BTS_TYPE_RBS2000,
569 GSM_BTS_TYPE_NOKIA_SITE,
570 GSM_BTS_TYPE_OSMOBTS,
571 _NUM_GSM_BTS_TYPE
572};
573
574enum gsm_bts_type_variant {
575 BTS_UNKNOWN,
576 BTS_OSMO_LITECELL15,
577 BTS_OSMO_OCTPHY,
578 BTS_OSMO_SYSMO,
579 BTS_OSMO_TRX,
580 _NUM_BTS_VARIANT
581};
582
583/* Used by OML layer for BTS Attribute reporting */
584enum bts_attribute {
585 BTS_TYPE_VARIANT,
586 BTS_SUB_MODEL,
587 TRX_PHY_VERSION,
588};
589
590struct vty;
591
592struct gsm_bts_model {
593 struct llist_head list;
594
595 enum gsm_bts_type type;
596 enum gsm_bts_type_variant variant;
597 const char *name;
598
599 bool started;
600 int (*start)(struct gsm_network *net);
601 int (*oml_rcvmsg)(struct msgb *msg);
602 char * (*oml_status)(const struct gsm_bts *bts);
603
604 void (*e1line_bind_ops)(struct e1inp_line *line);
605
606 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
607 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
608 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
609
610 struct tlv_definition nm_att_tlvdef;
611
612 /* features of a given BTS model set via gsm_bts_model_register() locally */
613 struct bitvec features;
614 uint8_t _features_data[MAX_BTS_FEATURES/8];
615};
616
617/* N. B: always add new features to the end of the list (right before _NUM_BTS_FEAT) to avoid breaking compatibility
618 with BTS compiled against earlier version of this header */
619enum gsm_bts_features {
620 BTS_FEAT_HSCSD,
621 BTS_FEAT_GPRS,
622 BTS_FEAT_EGPRS,
623 BTS_FEAT_ECSD,
624 BTS_FEAT_HOPPING,
625 BTS_FEAT_MULTI_TSC,
626 BTS_FEAT_OML_ALERTS,
627 BTS_FEAT_AGCH_PCH_PROP,
628 BTS_FEAT_CBCH,
629 _NUM_BTS_FEAT
630};
631
632extern const struct value_string gsm_bts_features_descs[];
633
634/*
635 * This keeps track of the paging status of one BTS. It
636 * includes a number of pending requests, a back pointer
637 * to the gsm_bts, a timer and some more state.
638 */
639struct gsm_bts_paging_state {
640 /* pending requests */
641 struct llist_head pending_requests;
642 struct gsm_bts *bts;
643
644 struct osmo_timer_list work_timer;
645 struct osmo_timer_list credit_timer;
646
647 /* free chans needed */
648 int free_chans_need;
649
650 /* load */
651 uint16_t available_slots;
652};
653
654struct gsm_envabtse {
655 struct gsm_abis_mo mo;
656};
657
658struct gsm_bts_gprs_nsvc {
659 struct gsm_bts *bts;
660 /* data read via VTY config file, to configure the BTS
661 * via OML from BSC */
662 int id;
663 uint16_t nsvci;
664 uint16_t local_port; /* on the BTS */
665 uint16_t remote_port; /* on the SGSN */
666 uint32_t remote_ip; /* on the SGSN */
667
668 struct gsm_abis_mo mo;
669};
670
671enum gprs_rlc_par {
672 RLC_T3142,
673 RLC_T3169,
674 RLC_T3191,
675 RLC_T3193,
676 RLC_T3195,
677 RLC_N3101,
678 RLC_N3103,
679 RLC_N3105,
680 CV_COUNTDOWN,
681 T_DL_TBF_EXT, /* ms */
682 T_UL_TBF_EXT, /* ms */
683 _NUM_RLC_PAR
684};
685
686enum gprs_cs {
687 GPRS_CS1,
688 GPRS_CS2,
689 GPRS_CS3,
690 GPRS_CS4,
691 GPRS_MCS1,
692 GPRS_MCS2,
693 GPRS_MCS3,
694 GPRS_MCS4,
695 GPRS_MCS5,
696 GPRS_MCS6,
697 GPRS_MCS7,
698 GPRS_MCS8,
699 GPRS_MCS9,
700 _NUM_GRPS_CS
701};
702
703struct gprs_rlc_cfg {
704 uint16_t parameter[_NUM_RLC_PAR];
705 struct {
706 uint16_t repeat_time; /* ms */
707 uint8_t repeat_count;
708 } paging;
709 uint32_t cs_mask; /* bitmask of gprs_cs */
710 uint8_t initial_cs;
711 uint8_t initial_mcs;
712};
713
714
715enum neigh_list_manual_mode {
716 NL_MODE_AUTOMATIC = 0,
717 NL_MODE_MANUAL = 1,
718 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
719};
720
721enum bts_loc_fix {
722 BTS_LOC_FIX_INVALID = 0,
723 BTS_LOC_FIX_2D = 1,
724 BTS_LOC_FIX_3D = 2,
725};
726
727extern const struct value_string bts_loc_fix_names[];
728
729struct bts_location {
730 struct llist_head list;
731 time_t tstamp;
732 enum bts_loc_fix valid;
733 double lat;
734 double lon;
735 double height;
736};
737
738/* Channel load counter */
739struct load_counter {
740 unsigned int total;
741 unsigned int used;
742};
743
744/* One BTS */
745struct gsm_bts {
746 /* list header in net->bts_list */
747 struct llist_head list;
748
749 /* Geographical location of the BTS */
750 struct llist_head loc_list;
751
752 /* number of ths BTS in network */
753 uint8_t nr;
754 /* human readable name / description */
755 char *description;
756 /* Cell Identity */
757 uint16_t cell_identity;
758 /* location area code of this BTS */
759 uint16_t location_area_code;
760 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
761 * which is used as TSC for the CCCH */
762 uint8_t bsic;
763 /* type of BTS */
764 enum gsm_bts_type type;
765 enum gsm_bts_type_variant variant;
766 struct gsm_bts_model *model;
767 enum gsm_band band;
768 char version[MAX_VERSION_LENGTH];
769 char sub_model[MAX_VERSION_LENGTH];
770
771 /* features of a given BTS set/reported via OML */
772 struct bitvec features;
773 uint8_t _features_data[MAX_BTS_FEATURES/8];
774
775 /* Connected PCU version (if any) */
776 char pcu_version[MAX_VERSION_LENGTH];
777
778 /* maximum Tx power that the MS is permitted to use in this cell */
779 int ms_max_power;
780
781 /* how do we talk OML with this TRX? */
782 struct gsm_e1_subslot oml_e1_link;
783 uint8_t oml_tei;
784 struct e1inp_sign_link *oml_link;
785 /* when OML link was established */
786 time_t uptime;
787
788 /* Abis network management O&M handle */
789 struct abis_nm_h *nmh;
790
791 struct gsm_abis_mo mo;
792
793 /* number of this BTS on given E1 link */
794 uint8_t bts_nr;
795
796 /* DTX features of this BTS */
797 enum gsm48_dtx_mode dtxu;
798 bool dtxd;
799
800 /* paging state and control */
801 struct gsm_bts_paging_state paging;
802
803 /* CCCH is on C0 */
804 struct gsm_bts_trx *c0;
805
806 struct {
807 struct gsm_abis_mo mo;
808 } site_mgr;
809
810 /* bitmask of all SI that are present/valid in si_buf */
811 uint32_t si_valid;
812 /* 3GPP TS 44.018 Table 10.5.2.33b.1 INDEX and COUNT for SI2quater */
813 uint8_t si2q_index; /* distinguish individual SI2quater messages */
814 uint8_t si2q_count; /* si2q_index for the last (highest indexed) individual SI2quater message */
815 /* buffers where we put the pre-computed SI */
816 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
817 /* offsets used while generating SI2quater */
818 size_t e_offset;
819 size_t u_offset;
820
821 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
822 union {
823 struct {
824 uint16_t site_id;
825 uint16_t bts_id;
826 uint32_t flags;
827 uint32_t rsl_ip;
828 } ip_access;
829 struct {
830 struct {
831 struct gsm_abis_mo mo;
832 } cclk;
833 struct {
834 struct gsm_abis_mo mo;
835 } rack;
836 struct gsm_envabtse envabtse[4];
837 } bs11;
838 struct {
839 struct {
840 struct om2k_mo om2k_mo;
841 struct gsm_abis_mo mo;
842 struct llist_head conn_groups;
843 } cf;
844 struct {
845 struct om2k_mo om2k_mo;
846 struct gsm_abis_mo mo;
847 struct llist_head conn_groups;
848 } is;
849 struct {
850 struct om2k_mo om2k_mo;
851 struct gsm_abis_mo mo;
852 struct llist_head conn_groups;
853 } con;
854 struct {
855 struct om2k_mo om2k_mo;
856 struct gsm_abis_mo mo;
857 } dp;
858 struct {
859 struct om2k_mo om2k_mo;
860 struct gsm_abis_mo mo;
861 } tf;
862 uint32_t use_superchannel:1;
863 } rbs2000;
864 struct {
865 uint8_t bts_type;
866 unsigned int configured:1,
867 skip_reset:1,
868 no_loc_rel_cnf:1,
869 bts_reset_timer_cnf,
870 did_reset:1,
871 wait_reset:1;
872 struct osmo_timer_list reset_timer;
873 } nokia;
874 };
875
876 /* Not entirely sure how ip.access specific this is */
877 struct {
878 uint8_t supports_egprs_11bit_rach;
879 enum bts_gprs_mode mode;
880 struct {
881 struct gsm_abis_mo mo;
882 uint16_t nsei;
883 uint8_t timer[7];
884 } nse;
885 struct {
886 struct gsm_abis_mo mo;
887 uint16_t bvci;
888 uint8_t timer[11];
889 struct gprs_rlc_cfg rlc_cfg;
890 } cell;
891 struct gsm_bts_gprs_nsvc nsvc[2];
892 uint8_t rac;
893 uint8_t net_ctrl_ord;
894 bool ctrl_ack_type_use_block;
895 } gprs;
896
897 /* RACH NM values */
898 int rach_b_thresh;
899 int rach_ldavg_slots;
900
901 /* transceivers */
902 int num_trx;
903 struct llist_head trx_list;
904
905 /* SI related items */
906 int force_combined_si;
907 int bcch_change_mark;
908
909 /* Abis NM queue */
910 struct llist_head abis_queue;
911 int abis_nm_pend;
912
913 struct gsm_network *network;
914
915 /* should the channel allocator allocate channels from high TRX to TRX0,
916 * rather than starting from TRX0 and go upwards? */
917 int chan_alloc_reverse;
918
919 enum neigh_list_manual_mode neigh_list_manual_mode;
920 /* parameters from which we build SYSTEM INFORMATION */
921 struct {
922 struct gsm48_rach_control rach_control;
923 uint8_t ncc_permitted;
924 struct gsm48_cell_sel_par cell_sel_par;
925 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
926 struct gsm48_cell_options cell_options;
927 struct gsm48_control_channel_descr chan_desc;
928 struct bitvec neigh_list;
929 struct bitvec cell_alloc;
930 struct bitvec si5_neigh_list;
931 struct osmo_earfcn_si2q si2quater_neigh_list;
932 size_t uarfcn_length; /* index for uarfcn and scramble lists */
933 struct {
934 /* bitmask large enough for all possible ARFCN's */
935 uint8_t neigh_list[1024/8];
936 uint8_t cell_alloc[1024/8];
937 /* If the user wants a different neighbor list in SI5 than in SI2 */
938 uint8_t si5_neigh_list[1024/8];
939 uint8_t meas_bw_list[MAX_EARFCN_LIST];
940 uint16_t earfcn_list[MAX_EARFCN_LIST];
941 uint16_t uarfcn_list[MAX_EARFCN_LIST];
942 uint16_t scramble_list[MAX_EARFCN_LIST];
943 } data;
944 } si_common;
945 bool early_classmark_allowed;
946 bool early_classmark_allowed_3g;
947 /* for testing only: Have an infinitely long radio link timeout */
948 bool infinite_radio_link_timeout;
949
950 /* do we use static (user-defined) system information messages? (bitmask) */
951 uint32_t si_mode_static;
952
Stefan Sperling6442e432018-02-06 14:44:54 +0100953 /* access control class ramping */
954 struct acc_ramp acc_ramp;
955
Neels Hofmeyr10485162018-02-13 23:22:03 +0100956 /* exclude the BTS from the global RF Lock handling */
957 int excl_from_rf_lock;
958
959 /* supported codecs beside FR */
960 struct bts_codec_conf codec;
961
962 /* BTS dependencies bit field */
963 uint32_t depends_on[256/(8*4)];
964
965 /* full and half rate multirate config */
966 struct amr_multirate_conf mr_full;
967 struct amr_multirate_conf mr_half;
968
969 /* PCU socket state */
970 char *pcu_sock_path;
971 struct pcu_sock_state *pcu_state;
972
973 struct rate_ctr_group *bts_ctrs;
974 struct osmo_stat_item_group *bts_statg;
975
976 struct handover_cfg *ho;
977
978 /* BTS-specific overrides for timer values from struct gsm_network. */
979 uint8_t T3122; /* ASSIGMENT REJECT wait indication */
980
981 /* Periodic channel load measurements are used to maintain T3122. */
982 struct load_counter chan_load_samples[7];
983 int chan_load_samples_idx;
Stefan Sperling6442e432018-02-06 14:44:54 +0100984 uint8_t chan_load_avg; /* current channel load average in percent (0 - 100). */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100985};
986
987
988struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, uint8_t bts_num);
989struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
990
991struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
992struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
993
994enum gsm_bts_type str2btstype(const char *arg);
995const char *btstype2str(enum gsm_bts_type type);
996
997enum bts_attribute str2btsattr(const char *s);
998const char *btsatttr2str(enum bts_attribute v);
999
1000enum gsm_bts_type_variant str2btsvariant(const char *arg);
1001const char *btsvariant2str(enum gsm_bts_type_variant v);
1002
1003extern const struct value_string gsm_chreq_descs[];
1004const struct value_string gsm_pchant_names[13];
1005const struct value_string gsm_pchant_descs[13];
1006const char *gsm_pchan_name(enum gsm_phys_chan_config c);
1007enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
1008const char *gsm_lchant_name(enum gsm_chan_t c);
1009const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
1010char *gsm_trx_name(const struct gsm_bts_trx *trx);
1011char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
1012char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
1013char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
1014const char *gsm_lchans_name(enum gsm_lchan_state s);
1015
1016static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
1017{
1018 return lchan->name;
1019}
1020
1021static inline int gsm_bts_set_feature(struct gsm_bts *bts, enum gsm_bts_features feat)
1022{
1023 OSMO_ASSERT(_NUM_BTS_FEAT < MAX_BTS_FEATURES);
1024 return bitvec_set_bit_pos(&bts->features, feat, 1);
1025}
1026
1027static inline bool gsm_bts_has_feature(const struct gsm_bts *bts, enum gsm_bts_features feat)
1028{
1029 OSMO_ASSERT(_NUM_BTS_FEAT < MAX_BTS_FEATURES);
1030 return bitvec_get_bit_pos(&bts->features, feat);
1031}
1032
1033void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
1034
1035struct gsm_nm_state *
1036gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
1037 const struct abis_om_obj_inst *obj_inst);
1038void *
1039gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
1040 const struct abis_om_obj_inst *obj_inst);
1041
1042/* reset the state of all MO in the BTS */
1043void gsm_bts_mo_reset(struct gsm_bts *bts);
1044
1045uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
1046 uint8_t ts_nr, uint8_t lchan_nr);
1047uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
1048uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
1049 enum gsm_phys_chan_config as_pchan);
1050
1051/* return the gsm_lchan for the CBCH (if it exists at all) */
1052struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
1053
1054/*
1055 * help with parsing regexps
1056 */
1057int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
1058 int argc, const char **argv) __attribute__ ((warn_unused_result));
1059
1060static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
1061{
1062 if (ts->tsc != -1)
1063 return ts->tsc;
1064 else
1065 return ts->trx->bts->bsic & 7;
1066}
1067
1068struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
1069 int *rc);
1070
1071enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
1072uint8_t ts_subslots(struct gsm_bts_trx_ts *ts);
1073bool ts_is_tch(struct gsm_bts_trx_ts *ts);
1074
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01001075
Harald Welteb7948872017-12-18 18:48:21 +01001076static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection *conn) {
1077 OSMO_ASSERT(conn->lchan);
1078 return conn->lchan->ts->trx->bts;
1079}
1080
Harald Welted82101e2017-12-09 23:07:38 +01001081enum {
1082 BTS_CTR_CHREQ_TOTAL,
1083 BTS_CTR_CHREQ_NO_CHANNEL,
1084 BTS_CTR_CHAN_RF_FAIL,
1085 BTS_CTR_CHAN_RLL_ERR,
1086 BTS_CTR_BTS_OML_FAIL,
1087 BTS_CTR_BTS_RSL_FAIL,
1088 BTS_CTR_CODEC_AMR_F,
1089 BTS_CTR_CODEC_AMR_H,
1090 BTS_CTR_CODEC_EFR,
1091 BTS_CTR_CODEC_V1_FR,
1092 BTS_CTR_CODEC_V1_HR,
Harald Weltecf9d4312017-12-13 23:17:16 +01001093 BTS_CTR_PAGING_ATTEMPTED,
1094 BTS_CTR_PAGING_ALREADY,
1095 BTS_CTR_PAGING_RESPONDED,
1096 BTS_CTR_PAGING_EXPIRED,
Harald Welte4f598922017-12-14 13:47:02 +01001097 BTS_CTR_CHAN_ACT_TOTAL,
1098 BTS_CTR_CHAN_ACT_NACK,
Harald Welte62d9cb02017-12-14 14:00:26 +01001099 BTS_CTR_RSL_UNKNOWN,
Harald Welte581398a2017-12-14 14:29:44 +01001100 BTS_CTR_RSL_IPA_NACK,
Harald Welte00d64fd2017-12-14 14:34:16 +01001101 BTS_CTR_MODE_MODIFY_NACK,
Harald Welted82101e2017-12-09 23:07:38 +01001102};
1103
1104static const struct rate_ctr_desc bts_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001105 [BTS_CTR_CHREQ_TOTAL] = {"chreq:total", "Received channel requests."},
1106 [BTS_CTR_CHREQ_NO_CHANNEL] = {"chreq:no_channel", "Sent to MS no channel available."},
1107 [BTS_CTR_CHAN_RF_FAIL] = {"chan:rf_fail", "Received a RF failure indication from BTS."},
1108 [BTS_CTR_CHAN_RLL_ERR] = {"chan:rll_err", "Received a RLL failure with T200 cause from BTS."},
Harald Welted82101e2017-12-09 23:07:38 +01001109 [BTS_CTR_BTS_OML_FAIL] = {"oml_fail", "Received a TEI down on a OML link."},
1110 [BTS_CTR_BTS_RSL_FAIL] = {"rsl_fail", "Received a TEI down on a OML link."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001111 [BTS_CTR_CODEC_AMR_F] = {"codec:amr_f", "Count the usage of AMR/F codec by channel mode requested."},
1112 [BTS_CTR_CODEC_AMR_H] = {"codec:amr_h", "Count the usage of AMR/H codec by channel mode requested."},
1113 [BTS_CTR_CODEC_EFR] = {"codec:efr", "Count the usage of EFR codec by channel mode requested."},
1114 [BTS_CTR_CODEC_V1_FR] = {"codec:fr", "Count the usage of FR codec by channel mode requested."},
1115 [BTS_CTR_CODEC_V1_HR] = {"codec:hr", "Count the usage of HR codec by channel mode requested."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001116
1117 [BTS_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
1118 [BTS_CTR_PAGING_ALREADY] = {"paging:already", "Paging attempts ignored as subsciber was already being paged."},
1119 [BTS_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful paging response."},
1120 [BTS_CTR_PAGING_EXPIRED] = {"paging:expired", "Paging Request expired because of timeout T3113."},
Harald Welte4f598922017-12-14 13:47:02 +01001121 [BTS_CTR_CHAN_ACT_TOTAL] = {"chan_act:total", "Total number of Channel Activations."},
1122 [BTS_CTR_CHAN_ACT_NACK] = {"chan_act:nack", "Number of Channel Activations that the BTS NACKed"},
Harald Welte62d9cb02017-12-14 14:00:26 +01001123 [BTS_CTR_RSL_UNKNOWN] = {"rsl:unknown", "Number of unknown/unsupported RSL messages received from BTS"},
Harald Welte581398a2017-12-14 14:29:44 +01001124 [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 +01001125 [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 +01001126};
1127
1128static const struct rate_ctr_group_desc bts_ctrg_desc = {
1129 "bts",
1130 "base transceiver station",
1131 OSMO_STATS_CLASS_GLOBAL,
1132 ARRAY_SIZE(bts_ctr_description),
1133 bts_ctr_description,
1134};
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001135
Alexander Couzens20423ea2016-07-12 15:42:02 +02001136enum {
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001137 BTS_STAT_CHAN_LOAD_AVERAGE,
1138 BTS_STAT_T3122,
1139};
1140
1141enum {
Alexander Couzensb847a212016-08-02 11:34:11 +02001142 BSC_CTR_HANDOVER_ATTEMPTED,
1143 BSC_CTR_HANDOVER_NO_CHANNEL,
1144 BSC_CTR_HANDOVER_TIMEOUT,
1145 BSC_CTR_HANDOVER_COMPLETED,
1146 BSC_CTR_HANDOVER_FAILED,
1147 BSC_CTR_PAGING_ATTEMPTED,
1148 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +01001149 BSC_CTR_PAGING_RESPONDED,
Alexander Couzensb847a212016-08-02 11:34:11 +02001150};
1151
1152static const struct rate_ctr_desc bsc_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001153 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Received handover attempts."},
1154 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Sent no channel available responses."},
1155 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Count the amount of timeouts of timer T3103."},
1156 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Received handover completed."},
1157 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Receive HO FAIL messages."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001158
1159 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001160 [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 +01001161 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response."},
Alexander Couzensb847a212016-08-02 11:34:11 +02001162};
1163
Alexander Couzensb847a212016-08-02 11:34:11 +02001164
1165
1166static const struct rate_ctr_group_desc bsc_ctrg_desc = {
1167 "bsc",
1168 "base station controller",
1169 OSMO_STATS_CLASS_GLOBAL,
1170 ARRAY_SIZE(bsc_ctr_description),
1171 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +02001172};
1173
Harald Weltedea252d2017-12-10 19:55:18 +01001174#define GSM_T3101_DEFAULT 3 /* s */
Harald Weltea0d324b2017-07-20 01:47:39 +02001175#define GSM_T3103_DEFAULT 5 /* s */
1176#define GSM_T3105_DEFAULT 100 /* ms */
1177#define GSM_T3107_DEFAULT 5 /* s */
Harald Welteed23c1d2017-12-10 19:58:16 +01001178#define GSM_T3109_DEFAULT 5 /* s, must be 2s + radio_link_timeout*0.48 */
Harald Weltea0d324b2017-07-20 01:47:39 +02001179#define GSM_T3111_DEFAULT 2 /* s */
Harald Welte6e59ced2017-12-14 12:49:43 +01001180#define GSM_T3113_DEFAULT 10 /* s */
Harald Weltea0d324b2017-07-20 01:47:39 +02001181#define GSM_T3115_DEFAULT 10
1182#define GSM_T3117_DEFAULT 10
1183#define GSM_T3119_DEFAULT 10
Andreas Eversberg75e13a42013-02-07 11:51:16 +01001184#define GSM_T3122_DEFAULT 10
Harald Weltea0d324b2017-07-20 01:47:39 +02001185#define GSM_T3141_DEFAULT 10
Harald Welteb84ddfc2009-12-01 17:36:54 +05301186
Neels Hofmeyr73983952016-05-10 13:29:33 +02001187struct gsm_tz {
1188 int override; /* if 0, use system's time zone instead. */
1189 int hr; /* hour */
1190 int mn; /* minute */
1191 int dst; /* daylight savings */
1192};
1193
Harald Welte52b1f982008-12-23 20:25:15 +00001194struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001195 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
1196 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
1197 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
1198 * these have in common, like country and network code, put in yet
1199 * separate structs and placed as members in osmo_bsc and osmo_msc. */
1200
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001201 struct osmo_plmn_id plmn;
1202
Harald Welte51e4bf32017-12-23 17:30:18 +01001203 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
1204 uint8_t a5_encryption_mask;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001205 int neci;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001206
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001207 struct handover_cfg *ho;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001208 struct {
1209 unsigned int congestion_check_interval_s;
1210 struct osmo_timer_list congestion_check_timer;
1211 } hodec2;
Harald Welte52b1f982008-12-23 20:25:15 +00001212
Alexander Couzensb847a212016-08-02 11:34:11 +02001213 struct rate_ctr_group *bsc_ctrs;
Harald Welte24ff6ee2009-12-22 00:41:05 +01001214
Holger Hans Peter Freytherabcddf12010-06-14 18:20:15 +08001215 struct bsc_api *bsc_api;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001216
Harald Welte52b1f982008-12-23 20:25:15 +00001217 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +02001218 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001219
1220 /* timer values */
1221 int T3101;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +01001222 int T3103;
1223 int T3105;
1224 int T3107;
1225 int T3109;
1226 int T3111;
1227 int T3113;
1228 int T3115;
1229 int T3117;
1230 int T3119;
Harald Welte2862dca2010-12-23 14:39:29 +01001231 int T3122;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +01001232 int T3141;
Harald Welteeab84a12009-12-13 10:53:12 +01001233
Alexander Couzens547c2072017-11-21 12:03:04 +01001234 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +08001235
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +08001236 /* Use a TCH for handling requests of type paging any */
1237 int pag_any_tch;
1238
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08001239 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +02001240 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +01001241
Daniel Willmann6fc4a982011-07-22 17:55:42 +02001242 /* control interface */
1243 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +02001244
1245 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
1246 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +02001247
1248 /* all active subscriber connections. */
1249 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +02001250
1251 /* if override is nonzero, this timezone data is used for all MM
1252 * contexts. */
1253 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
1254 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +01001255 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +02001256 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +01001257
1258 /* List of all struct bsc_subscr used in libbsc. This llist_head is
1259 * allocated so that the llist_head pointer itself can serve as a
1260 * talloc context (useful to not have to pass the entire gsm_network
1261 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
1262 * not require gsm_data.h). In an MSC-without-BSC environment, this
1263 * pointer is NULL to indicate absence of a bsc_subscribers list. */
1264 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +02001265
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001266 /* Periodic location update default value */
1267 uint8_t t3212;
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001268
Stefan Sperling6cee8932018-01-30 18:14:22 +01001269 /* Timer for periodic channel load measurements to maintain each BTS's T3122. */
1270 struct osmo_timer_list t3122_chan_load_timer;
1271
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001272 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +02001273 struct mgcp_client_conf *conf;
1274 struct mgcp_client *client;
1275 } mgw;
Harald Welte7e310b12009-03-30 20:56:32 +00001276};
1277
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001278static inline const struct osmo_location_area_id *bts_lai(struct gsm_bts *bts)
1279{
1280 static struct osmo_location_area_id lai;
1281 lai = (struct osmo_location_area_id){
1282 .plmn = bts->network->plmn,
1283 .lac = bts->location_area_code,
1284 };
1285 return &lai;
1286}
1287
Neels Hofmeyrc13e6872016-05-11 13:53:47 +02001288extern void talloc_ctx_init(void *ctx_root);
1289
Harald Welte39315c42010-01-10 18:01:52 +01001290int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +02001291
Harald Welte1d014a52009-08-08 15:38:29 +02001292enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +02001293const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +00001294struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
1295 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +00001296
Andreas Eversberg8226fa72009-06-29 15:19:38 +02001297extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +01001298extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +02001299
Harald Weltef383aa12012-07-02 19:51:55 +02001300/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +00001301static inline int is_ipaccess_bts(struct gsm_bts *bts)
1302{
1303 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001304 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001305 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +00001306 return 1;
1307 default:
1308 break;
1309 }
1310 return 0;
1311}
1312
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001313static inline int is_sysmobts_v2(struct gsm_bts *bts)
1314{
1315 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +01001316 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001317 return 1;
1318 default:
1319 break;
1320 }
1321 return 0;
1322}
1323
Harald Welte5b570672009-08-10 10:08:01 +02001324static inline int is_siemens_bts(struct gsm_bts *bts)
1325{
1326 switch (bts->type) {
1327 case GSM_BTS_TYPE_BS11:
1328 return 1;
1329 default:
1330 break;
1331 }
1332
1333 return 0;
1334}
1335
Andreas Eversberg7d8fa342013-12-05 13:25:06 +01001336static inline int is_nokia_bts(struct gsm_bts *bts)
1337{
1338 switch (bts->type) {
1339 case GSM_BTS_TYPE_NOKIA_SITE:
1340 return 1;
1341 default:
1342 break;
1343 }
1344
1345 return 0;
1346}
1347
Andreas Eversbergdcf38e12013-12-05 14:37:11 +01001348static inline int is_e1_bts(struct gsm_bts *bts)
1349{
1350 switch (bts->type) {
1351 case GSM_BTS_TYPE_BS11:
1352 case GSM_BTS_TYPE_RBS2000:
1353 case GSM_BTS_TYPE_NOKIA_SITE:
1354 return 1;
1355 default:
1356 break;
1357 }
1358
1359 return 0;
1360}
1361
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001362enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +02001363const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001364int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +02001365
Neels Hofmeyr4d358c02018-02-22 03:19:05 +01001366void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +08001367void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +01001368
Harald Weltef3d8e922010-06-14 22:44:42 +02001369int gsm_btsmodel_set_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
Harald Weltefbda4e12010-03-04 11:04:52 +01001370int gsm_bts_model_register(struct gsm_bts_model *model);
1371
Neels Hofmeyr42eb0142016-05-20 17:15:44 +02001372struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_lchan *lchan);
1373void bsc_subscr_con_free(struct gsm_subscriber_connection *conn);
1374
1375struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
1376void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +08001377
Harald Welte3300c012011-06-05 13:31:33 +02001378struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net,
1379 enum gsm_bts_type type,
Harald Weltea2bbc5e2015-11-20 10:43:31 +01001380 uint8_t bsic);
Harald Welte142d12d2014-12-29 17:47:08 +01001381
Harald Welte3300c012011-06-05 13:31:33 +02001382void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
1383 uint8_t e1_ts, uint8_t e1_ts_ss);
1384
Maxbe356ed2017-09-07 19:10:09 +02001385void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Max71d082b2017-05-30 15:03:38 +02001386bool gsm_btsmodel_has_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
Harald Welte3300c012011-06-05 13:31:33 +02001387struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +01001388int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -04001389int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +02001390
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +02001391/* generic E1 line operations for all ISDN-based BTS. */
1392extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
1393
Harald Weltee555c2b2012-08-17 13:02:12 +02001394extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
1395extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
1396
Max3d049d22017-10-09 17:12:53 +02001397char *get_model_oml_status(const struct gsm_bts *bts);
1398
Max25cc4072017-10-10 14:50:35 +02001399unsigned long long bts_uptime(const struct gsm_bts *bts);
1400
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +01001401/* control interface handling */
1402int bsc_base_ctrl_cmds_install(void);
1403
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001404/* dependency handling */
1405void bts_depend_mark(struct gsm_bts *bts, int dep);
1406void bts_depend_clear(struct gsm_bts *bts, int dep);
1407int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +01001408int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001409
Harald Welte2f8b9d22017-06-18 11:12:13 +03001410int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
1411void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
1412
Harald Weltea43e0b42016-06-19 18:06:02 +02001413bool classmark_is_r99(struct gsm_classmark *cm);
1414
Harald Welte6be350c2011-05-25 13:10:08 +02001415#endif /* _GSM_DATA_H */