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