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