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