blob: 579461732f4d9334a0f391380510770d93d022ab [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>
Harald Welte3561bd42018-01-28 03:04:16 +010018#include <osmocom/core/fsm.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020019
Harald Welte121e9a42016-04-20 13:13:19 +020020#include <osmocom/crypt/auth.h>
Harald Weltef142c972011-05-24 13:25:38 +020021
Neels Hofmeyrc0164792017-09-04 15:15:32 +020022#include <osmocom/bsc/rest_octets.h>
Harald Welte3561bd42018-01-28 03:04:16 +010023#include <osmocom/bsc/handover.h>
Harald Welteb96be392011-05-25 12:33:33 +020024
Neels Hofmeyr10485162018-02-13 23:22:03 +010025#include <osmocom/core/bitvec.h>
26#include <osmocom/gsm/gsm_utils.h>
27#include <osmocom/gsm/rxlev_stat.h>
28#include <osmocom/gsm/protocol/gsm_08_58.h>
29#include <osmocom/gsm/protocol/gsm_12_21.h>
30#include <osmocom/abis/e1_input.h>
31#include <osmocom/bsc/meas_rep.h>
Harald Welte519c7e12018-01-28 02:45:46 +010032#include <osmocom/bsc/bsc_msg_filter.h>
Stefan Sperling6442e432018-02-06 14:44:54 +010033#include <osmocom/bsc/acc_ramp.h>
Neels Hofmeyr10485162018-02-13 23:22:03 +010034
Harald Welte74b8cdb2018-01-15 19:26:06 +010035struct mgcp_client_conf;
36struct mgcp_client;
37struct mgcp_ctx;
Philipp Maier39f62bb2017-04-09 12:32:51 +020038
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020039/** annotations for msgb ownership */
40#define __uses
41
Holger Hans Peter Freyther6f615552010-11-15 20:50:42 +010042#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
43
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010044struct bsc_subscr;
Neels Hofmeyr7b656882017-07-09 22:09:18 +020045struct gprs_ra_id;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020046
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080047#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
48
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010049#define tmsi_from_string(str) strtoul(str, NULL, 10)
50
Max70fdd242017-06-15 15:10:53 +020051/* 3-bit long values */
52#define EARFCN_PRIO_INVALID 8
53#define EARFCN_MEAS_BW_INVALID 8
54/* 5-bit long values */
55#define EARFCN_QRXLV_INVALID 32
56#define EARFCN_THRESH_LOW_INVALID 32
57
Harald Welte8e1e3ee2009-02-01 13:32:45 +000058struct msgb;
59typedef int gsm_cbfn(unsigned int hooknum,
60 unsigned int event,
61 struct msgb *msg,
62 void *data, void *param);
63
Harald Weltef7c28b02009-12-21 13:30:17 +010064/* Maximum number of neighbor cells whose average we track */
65#define MAX_NEIGH_MEAS 10
66/* Maximum size of the averaging window for neighbor cells */
67#define MAX_WIN_NEIGH_AVG 10
Andreas Eversberg98692032013-06-23 10:44:34 +020068/* Maximum number of report history we store */
69#define MAX_MEAS_REP 10
Harald Weltef7c28b02009-12-21 13:30:17 +010070
71/* processed neighbor measurements for one cell */
72struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020073 uint16_t arfcn;
74 uint8_t bsic;
75 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +010076 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020077 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +010078};
79
Harald Weltea43e0b42016-06-19 18:06:02 +020080struct gsm_classmark {
81 bool classmark1_set;
82 struct gsm48_classmark1 classmark1;
83 uint8_t classmark2_len;
84 uint8_t classmark2[3];
85 uint8_t classmark3_len;
86 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
87};
88
Harald Welte519c7e12018-01-28 02:45:46 +010089enum subscr_sccp_state {
90 SUBSCR_SCCP_ST_NONE,
91 SUBSCR_SCCP_ST_WAIT_CONN_CONF,
92 SUBSCR_SCCP_ST_CONNECTED
93};
94
Neels Hofmeyr378a4922016-05-09 21:07:43 +020095/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010096struct gsm_subscriber_connection {
Harald Weltea43e0b42016-06-19 18:06:02 +020097 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +080098 struct llist_head entry;
99
Harald Welte3561bd42018-01-28 03:04:16 +0100100 /* FSM instance to control the subscriber connection state (RTP, A) */
101 struct osmo_fsm_inst *fi;
102
Harald Weltea43e0b42016-06-19 18:06:02 +0200103 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100104 struct bsc_subscr *bsub;
105
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100106 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200107 struct gsm_network *network;
108
Harald Welte4a8ebc82017-12-18 18:34:41 +0100109 /* the primary / currently active lchan to the BTS/subscriber */
110 struct gsm_lchan *lchan;
Harald Welte3561bd42018-01-28 03:04:16 +0100111
112 /* handover information, if a handover is pending for this conn. */
113 struct bsc_handover *ho;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100114
Harald Welte4a8ebc82017-12-18 18:34:41 +0100115 /* the future allocated but not yet used lchan during ASSIGNMENT */
116 struct gsm_lchan *secondary_lchan;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100117
Harald Welte4a8ebc82017-12-18 18:34:41 +0100118 /* buffer/cache for classmark of the ME of the subscriber */
Harald Weltea43e0b42016-06-19 18:06:02 +0200119 struct gsm_classmark classmark;
Andreas Eversberg935e5d72013-06-17 11:58:30 +0200120
121 /* Cache DTAP messages during handover/assignment (msgb_enqueue()/msgb_dequeue())*/
122 struct llist_head ho_dtap_cache;
123 unsigned int ho_dtap_cache_len;
Andreas Eversberg084b4212013-05-30 14:12:48 +0200124
Neels Hofmeyrec422642018-02-15 14:07:40 +0100125 struct {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100126 int failures;
Neels Hofmeyrec422642018-02-15 14:07:40 +0100127 struct penalty_timers *penalty_timers;
128 } hodec2;
Neels Hofmeyra60f3442018-02-12 16:44:32 +0100129
130 /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment Request. 3GPP 48.008
131 * 3.2.2.103 says:
132 * The "Codec List (MSC Preferred)" shall not include codecs
133 * that are not supported by the MS.
134 * i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed the MS bearer
135 * capabilities, which the MSC is required to translate into the codec list. */
136 struct gsm0808_speech_codec_list codec_list;
137 bool codec_list_present;
Harald Welte519c7e12018-01-28 02:45:46 +0100138
139 /* flag to prevent multiple simultaneous ciphering commands */
140 int ciphering_handled;
141
142 /* state related to welcome USSD */
143 uint8_t new_subscriber;
144
145 /* state related to osmo_bsc_filter.c */
146 struct bsc_filter_state filter_state;
147
148 /* SCCP connection associatd with this subscriber_connection */
149 struct {
150 /* for advanced ping/pong */
151 int send_ping;
152
153 /* SCCP connection realted */
154 struct bsc_msc_data *msc;
155
156 /* Sigtran connection ID */
157 int conn_id;
158 enum subscr_sccp_state state;
159 } sccp;
160
161 /* for audio handling */
162 struct {
163 uint16_t cic;
164 uint32_t rtp_ip;
165 int rtp_port;
166 /* RTP address of the remote end (assigned by MSC through assignment request) */
167 struct sockaddr_storage aoip_rtp_addr_remote;
168
169 /* Local RTP address (reported back to the MSC by us with the
170 * assignment complete message) */
171 struct sockaddr_storage aoip_rtp_addr_local;
172
Harald Welte3561bd42018-01-28 03:04:16 +0100173 /* FSM instance to control the BTS sided RTP connection */
174 struct osmo_fsm_inst *fi_bts;
175
176 /* FSM instance to control the MSC sided RTP connection */
177 struct osmo_fsm_inst *fi_msc;
178
179 /* Endpoint identifier of the MGCP endpoint the connection uses */
180 char *mgw_endpoint;
181
182 /* Channel rate flag, FR=1, HR=0, Invalid=-1 */
183 int full_rate;
184
Philipp Maier79745fc2018-03-21 10:53:24 +0100185 /* Channel mode flag (signaling or voice channel) */
Harald Welte3561bd42018-01-28 03:04:16 +0100186 enum gsm48_chan_mode chan_mode;
187
Harald Welte519c7e12018-01-28 02:45:46 +0100188 } user_plane;
Harald Weltec997ceb2018-05-30 01:39:43 +0200189
190 /* LCLS (local call, local switch) related state */
191 struct {
192 uint8_t global_call_ref[15];
193 uint8_t global_call_ref_len; /* length of global_call_ref */
194 uint8_t config; /* TS 48.008 3.2.2.116 */
195 uint8_t control;/* TS 48.008 3.2.2.117 */
196 /* LCLS FSM */
197 struct osmo_fsm_inst *fi;
198 /* pointer to "other" connection, if Call Leg Relocation was successful */
199 struct gsm_subscriber_connection *other;
200 } lcls;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100201};
202
Harald Weltef142c972011-05-24 13:25:38 +0200203
Neels Hofmeyr10485162018-02-13 23:22:03 +0100204/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 Table 10.5.2.33b.1:
205 4-bit index is used (2#1111 = 10#15) */
206#define SI2Q_MAX_NUM 16
207/* length in bits (for single SI2quater message) */
208#define SI2Q_MAX_LEN 160
209#define SI2Q_MIN_LEN 18
210
211struct osmo_bsc_data;
212
213struct osmo_bsc_sccp_con;
214
215/* Channel Request reason */
216enum gsm_chreq_reason_t {
217 GSM_CHREQ_REASON_EMERG,
218 GSM_CHREQ_REASON_PAG,
219 GSM_CHREQ_REASON_CALL,
220 GSM_CHREQ_REASON_LOCATION_UPD,
221 GSM_CHREQ_REASON_OTHER,
222 GSM_CHREQ_REASON_PDCH,
223};
224
225/* lchans 0..3 are SDCCH in combined channel configuration,
226 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
227#define CCCH_LCHAN 4
228
229#define TRX_NR_TS 8
230#define TS_MAX_LCHAN 8
231
232#define HARDCODED_ARFCN 123
233#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
234
235/* for multi-drop config */
236#define HARDCODED_BTS0_TS 1
237#define HARDCODED_BTS1_TS 6
238#define HARDCODED_BTS2_TS 11
239
240#define MAX_VERSION_LENGTH 64
241
Neels Hofmeyr10485162018-02-13 23:22:03 +0100242enum gsm_hooks {
243 GSM_HOOK_NM_SWLOAD,
244 GSM_HOOK_RR_PAGING,
245 GSM_HOOK_RR_SECURITY,
246};
247
Neels Hofmeyr10485162018-02-13 23:22:03 +0100248enum bts_gprs_mode {
249 BTS_GPRS_NONE = 0,
250 BTS_GPRS_GPRS = 1,
251 BTS_GPRS_EGPRS = 2,
252};
253
254struct gsm_lchan;
255struct osmo_rtp_socket;
256struct rtp_socket;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100257
258/* Network Management State */
259struct gsm_nm_state {
260 uint8_t operational;
261 uint8_t administrative;
262 uint8_t availability;
263};
264
265struct gsm_abis_mo {
266 uint8_t obj_class;
267 uint8_t procedure_pending;
268 struct abis_om_obj_inst obj_inst;
269 const char *name;
270 struct gsm_nm_state nm_state;
271 struct tlv_parsed *nm_attr;
272 struct gsm_bts *bts;
273};
274
275/* Ericsson OM2000 Managed Object */
276struct abis_om2k_mo {
277 uint8_t class;
278 uint8_t bts;
279 uint8_t assoc_so;
280 uint8_t inst;
281} __attribute__ ((packed));
282
283struct om2k_mo {
284 struct abis_om2k_mo addr;
285 struct osmo_fsm_inst *fsm;
286};
287
288#define A38_XOR_MIN_KEY_LEN 12
289#define A38_XOR_MAX_KEY_LEN 16
290#define A38_COMP128_KEY_LEN 16
291#define RSL_ENC_ALG_A5(x) (x+1)
292#define MAX_EARFCN_LIST 32
293
294/* is the data link established? who established it? */
295#define LCHAN_SAPI_UNUSED 0
296#define LCHAN_SAPI_MS 1
297#define LCHAN_SAPI_NET 2
298#define LCHAN_SAPI_REL 3
299
300/* state of a logical channel */
301enum gsm_lchan_state {
302 LCHAN_S_NONE, /* channel is not active */
303 LCHAN_S_ACT_REQ, /* channel activation requested */
304 LCHAN_S_ACTIVE, /* channel is active and operational */
305 LCHAN_S_REL_REQ, /* channel release has been requested */
306 LCHAN_S_REL_ERR, /* channel is in an error state */
307 LCHAN_S_BROKEN, /* channel is somehow unusable */
308 LCHAN_S_INACTIVE, /* channel is set inactive */
309};
310
311/* BTS ONLY */
312#define MAX_NUM_UL_MEAS 104
313#define LC_UL_M_F_L1_VALID (1 << 0)
314#define LC_UL_M_F_RES_VALID (1 << 1)
315
316struct bts_ul_meas {
317 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
318 uint16_t ber10k;
319 /* timing advance offset (in quarter bits) */
320 int16_t ta_offs_qbits;
321 /* C/I ratio in dB */
322 float c_i;
323 /* flags */
324 uint8_t is_sub:1;
325 /* RSSI in dBm * -1 */
326 uint8_t inv_rssi;
327};
328
329struct bts_codec_conf {
330 uint8_t hr;
331 uint8_t efr;
332 uint8_t amr;
333};
334
335struct amr_mode {
336 uint8_t mode;
337 uint8_t threshold;
338 uint8_t hysteresis;
339};
340
341struct amr_multirate_conf {
342 uint8_t gsm48_ie[2];
343 struct amr_mode ms_mode[4];
344 struct amr_mode bts_mode[4];
345 uint8_t num_modes;
346};
347/* /BTS ONLY */
348
349enum lchan_csd_mode {
350 LCHAN_CSD_M_NT,
351 LCHAN_CSD_M_T_1200_75,
352 LCHAN_CSD_M_T_600,
353 LCHAN_CSD_M_T_1200,
354 LCHAN_CSD_M_T_2400,
355 LCHAN_CSD_M_T_9600,
356 LCHAN_CSD_M_T_14400,
357 LCHAN_CSD_M_T_29000,
358 LCHAN_CSD_M_T_32000,
359};
360
361/* State of the SAPIs in the lchan */
362enum lchan_sapi_state {
363 LCHAN_SAPI_S_NONE,
364 LCHAN_SAPI_S_REQ,
365 LCHAN_SAPI_S_ASSIGNED,
366 LCHAN_SAPI_S_REL,
367 LCHAN_SAPI_S_ERROR,
368};
369
Neels Hofmeyr92b9f2e2018-02-14 00:19:11 +0100370#define MAX_A5_KEY_LEN (128/8)
371
372struct gsm_encr {
373 uint8_t alg_id;
374 uint8_t key_len;
375 uint8_t key[MAX_A5_KEY_LEN];
376};
377
Neels Hofmeyr8da22332018-04-11 01:43:41 +0200378#define LOGPLCHAN(lchan, ss, level, fmt, args...) \
379 LOGP(ss, level, "%s (ss=%d,%s) (%s) " fmt, \
380 lchan ? gsm_ts_and_pchan_name(lchan->ts) : "-", \
381 lchan ? lchan->nr : 0, \
382 lchan ? gsm_lchant_name(lchan->type) : "-", \
383 bsc_subscr_name(lchan && lchan->conn ? lchan->conn->bsub : NULL), \
384 ## args)
385
Neels Hofmeyr10485162018-02-13 23:22:03 +0100386struct gsm_lchan {
387 /* The TS that we're part of */
388 struct gsm_bts_trx_ts *ts;
389 /* The logical subslot number in the TS */
390 uint8_t nr;
391 /* The logical channel type */
392 enum gsm_chan_t type;
393 /* RSL channel mode */
394 enum rsl_cmod_spd rsl_cmode;
395 /* If TCH, traffic channel mode */
396 enum gsm48_chan_mode tch_mode;
397 enum lchan_csd_mode csd_mode;
398 /* State */
399 enum gsm_lchan_state state;
400 const char *broken_reason;
401 /* Power levels for MS and BTS */
402 uint8_t bs_power;
403 uint8_t ms_power;
404 /* Encryption information */
405 struct gsm_encr encr;
406
407 /* AMR bits */
408 uint8_t mr_ms_lv[7];
409 uint8_t mr_bts_lv[7];
410
411 /* Established data link layer services */
412 uint8_t sapis[8];
413
414 struct {
415 uint32_t bound_ip;
416 uint32_t connect_ip;
417 uint16_t bound_port;
418 uint16_t connect_port;
419 uint16_t conn_id;
420 uint8_t rtp_payload;
421 uint8_t rtp_payload2;
422 uint8_t speech_mode;
423 struct rtp_socket *rtp_socket;
424
425 /* info we need to postpone the AoIP
426 * assignment completed message */
427 struct {
428 uint8_t rr_cause;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100429 bool valid;
430 } ass_compl;
431 } abis_ip;
432
433 uint8_t rqd_ta;
434
435 char *name;
436
437 struct osmo_timer_list T3101;
438 struct osmo_timer_list T3109;
439 struct osmo_timer_list T3111;
440 struct osmo_timer_list error_timer;
441 struct osmo_timer_list act_timer;
442 struct osmo_timer_list rel_work;
443 uint8_t error_cause;
444
445 /* table of neighbor cell measurements */
446 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
447
448 /* cache of last measurement reports on this lchan */
449 struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
450 int meas_rep_idx;
451 int meas_rep_count;
Neels Hofmeyr35ba85c2018-02-12 16:47:40 +0100452 uint8_t meas_rep_last_seen_nr;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100453
454 /* GSM Random Access data */
455 struct gsm48_req_ref *rqd_ref;
456
457 struct gsm_subscriber_connection *conn;
458
459 struct {
460 /* channel activation type and handover ref */
461 uint8_t act_type;
462 uint8_t ho_ref;
463 struct gsm48_req_ref *rqd_ref;
464 uint8_t rqd_ta;
465 } dyn;
466};
467
468enum {
469 TS_F_PDCH_ACTIVE = 0x1000,
470 TS_F_PDCH_ACT_PENDING = 0x2000,
471 TS_F_PDCH_DEACT_PENDING = 0x4000,
Neels Hofmeyr163f6312018-05-08 01:11:04 +0200472 TS_F_PDCH_PENDING_MASK = (TS_F_PDCH_ACT_PENDING | TS_F_PDCH_DEACT_PENDING),
Neels Hofmeyr10485162018-02-13 23:22:03 +0100473} gsm_bts_trx_ts_flags;
474
475/* One Timeslot in a TRX */
476struct gsm_bts_trx_ts {
477 struct gsm_bts_trx *trx;
Neels Hofmeyr91aa68f2018-05-09 17:46:22 +0200478 bool initialized;
479
Neels Hofmeyr10485162018-02-13 23:22:03 +0100480 /* number of this timeslot at the TRX */
481 uint8_t nr;
482
483 enum gsm_phys_chan_config pchan;
484
485 struct {
486 enum gsm_phys_chan_config pchan_is;
487 enum gsm_phys_chan_config pchan_want;
488 struct msgb *pending_chan_activ;
489 } dyn;
490
491 unsigned int flags;
492 struct gsm_abis_mo mo;
493 struct tlv_parsed nm_attr;
494 uint8_t nm_chan_comb;
495 int tsc; /* -1 == use BTS TSC */
496
497 struct {
498 /* Parameters below are configured by VTY */
499 int enabled;
500 uint8_t maio;
501 uint8_t hsn;
502 struct bitvec arfcns;
503 uint8_t arfcns_data[1024/8];
504 /* This is the pre-computed MA for channel assignments */
505 struct bitvec ma;
506 uint8_t ma_len; /* part of ma_data that is used */
507 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
508 } hopping;
509
510 /* To which E1 subslot are we connected */
511 struct gsm_e1_subslot e1_link;
512
513 union {
514 struct {
515 struct om2k_mo om2k_mo;
516 } rbs2000;
517 };
518
519 struct gsm_lchan lchan[TS_MAX_LCHAN];
520};
521
522/* One TRX in a BTS */
523struct gsm_bts_trx {
524 /* list header in bts->trx_list */
525 struct llist_head list;
526
527 struct gsm_bts *bts;
528 /* number of this TRX in the BTS */
529 uint8_t nr;
530 /* human readable name / description */
531 char *description;
532 /* how do we talk RSL with this TRX? */
533 struct gsm_e1_subslot rsl_e1_link;
534 uint8_t rsl_tei;
535 struct e1inp_sign_link *rsl_link;
536
537 /* Timeout for initiating the RSL connection. */
538 struct osmo_timer_list rsl_connect_timeout;
539
540 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
541 struct e1inp_sign_link *oml_link;
542
543 struct gsm_abis_mo mo;
544 struct tlv_parsed nm_attr;
545 struct {
546 struct gsm_abis_mo mo;
547 } bb_transc;
548
549 uint16_t arfcn;
550 int nominal_power; /* in dBm */
551 unsigned int max_power_red; /* in actual dB */
552
553 union {
554 struct {
555 struct {
556 struct gsm_abis_mo mo;
557 } bbsig;
558 struct {
559 struct gsm_abis_mo mo;
560 } pa;
561 } bs11;
562 struct {
563 unsigned int test_state;
564 uint8_t test_nr;
565 struct rxlev_stats rxlev_stat;
566 } ipaccess;
567 struct {
568 struct {
569 struct om2k_mo om2k_mo;
570 } trxc;
571 struct {
572 struct om2k_mo om2k_mo;
573 } rx;
574 struct {
575 struct om2k_mo om2k_mo;
576 } tx;
577 } rbs2000;
578 };
579 struct gsm_bts_trx_ts ts[TRX_NR_TS];
580};
581
582#define GSM_BTS_SI2Q(bts, i) (struct gsm48_system_information_type_2quater *)((bts)->si_buf[SYSINFO_TYPE_2quater][i])
583#define GSM_BTS_HAS_SI(bts, i) ((bts)->si_valid & (1 << i))
584#define GSM_BTS_SI(bts, i) (void *)((bts)->si_buf[i][0])
585#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
586
587enum gsm_bts_type {
588 GSM_BTS_TYPE_UNKNOWN,
589 GSM_BTS_TYPE_BS11,
590 GSM_BTS_TYPE_NANOBTS,
591 GSM_BTS_TYPE_RBS2000,
592 GSM_BTS_TYPE_NOKIA_SITE,
593 GSM_BTS_TYPE_OSMOBTS,
594 _NUM_GSM_BTS_TYPE
595};
596
597enum gsm_bts_type_variant {
598 BTS_UNKNOWN,
599 BTS_OSMO_LITECELL15,
600 BTS_OSMO_OCTPHY,
601 BTS_OSMO_SYSMO,
602 BTS_OSMO_TRX,
603 _NUM_BTS_VARIANT
604};
605
606/* Used by OML layer for BTS Attribute reporting */
607enum bts_attribute {
608 BTS_TYPE_VARIANT,
609 BTS_SUB_MODEL,
610 TRX_PHY_VERSION,
611};
612
613struct vty;
614
615struct gsm_bts_model {
616 struct llist_head list;
617
618 enum gsm_bts_type type;
619 enum gsm_bts_type_variant variant;
620 const char *name;
621
622 bool started;
623 int (*start)(struct gsm_network *net);
624 int (*oml_rcvmsg)(struct msgb *msg);
625 char * (*oml_status)(const struct gsm_bts *bts);
Neels Hofmeyr91aa68f2018-05-09 17:46:22 +0200626 bool (*oml_is_ts_ready)(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr10485162018-02-13 23:22:03 +0100627
628 void (*e1line_bind_ops)(struct e1inp_line *line);
629
630 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
631 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
632 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
633
634 struct tlv_definition nm_att_tlvdef;
635
636 /* features of a given BTS model set via gsm_bts_model_register() locally */
637 struct bitvec features;
638 uint8_t _features_data[MAX_BTS_FEATURES/8];
639};
640
Neels Hofmeyr10485162018-02-13 23:22:03 +0100641
Neels Hofmeyr10485162018-02-13 23:22:03 +0100642
643/*
644 * This keeps track of the paging status of one BTS. It
645 * includes a number of pending requests, a back pointer
646 * to the gsm_bts, a timer and some more state.
647 */
648struct gsm_bts_paging_state {
649 /* pending requests */
650 struct llist_head pending_requests;
651 struct gsm_bts *bts;
652
653 struct osmo_timer_list work_timer;
654 struct osmo_timer_list credit_timer;
655
656 /* free chans needed */
657 int free_chans_need;
658
659 /* load */
660 uint16_t available_slots;
661};
662
663struct gsm_envabtse {
664 struct gsm_abis_mo mo;
665};
666
667struct gsm_bts_gprs_nsvc {
668 struct gsm_bts *bts;
669 /* data read via VTY config file, to configure the BTS
670 * via OML from BSC */
671 int id;
672 uint16_t nsvci;
673 uint16_t local_port; /* on the BTS */
674 uint16_t remote_port; /* on the SGSN */
675 uint32_t remote_ip; /* on the SGSN */
676
677 struct gsm_abis_mo mo;
678};
679
680enum gprs_rlc_par {
681 RLC_T3142,
682 RLC_T3169,
683 RLC_T3191,
684 RLC_T3193,
685 RLC_T3195,
686 RLC_N3101,
687 RLC_N3103,
688 RLC_N3105,
689 CV_COUNTDOWN,
690 T_DL_TBF_EXT, /* ms */
691 T_UL_TBF_EXT, /* ms */
692 _NUM_RLC_PAR
693};
694
695enum gprs_cs {
696 GPRS_CS1,
697 GPRS_CS2,
698 GPRS_CS3,
699 GPRS_CS4,
700 GPRS_MCS1,
701 GPRS_MCS2,
702 GPRS_MCS3,
703 GPRS_MCS4,
704 GPRS_MCS5,
705 GPRS_MCS6,
706 GPRS_MCS7,
707 GPRS_MCS8,
708 GPRS_MCS9,
709 _NUM_GRPS_CS
710};
711
712struct gprs_rlc_cfg {
713 uint16_t parameter[_NUM_RLC_PAR];
714 struct {
715 uint16_t repeat_time; /* ms */
716 uint8_t repeat_count;
717 } paging;
718 uint32_t cs_mask; /* bitmask of gprs_cs */
719 uint8_t initial_cs;
720 uint8_t initial_mcs;
721};
722
723
724enum neigh_list_manual_mode {
725 NL_MODE_AUTOMATIC = 0,
726 NL_MODE_MANUAL = 1,
727 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
728};
729
730enum bts_loc_fix {
731 BTS_LOC_FIX_INVALID = 0,
732 BTS_LOC_FIX_2D = 1,
733 BTS_LOC_FIX_3D = 2,
734};
735
736extern const struct value_string bts_loc_fix_names[];
737
738struct bts_location {
739 struct llist_head list;
740 time_t tstamp;
741 enum bts_loc_fix valid;
742 double lat;
743 double lon;
744 double height;
745};
746
747/* Channel load counter */
748struct load_counter {
749 unsigned int total;
750 unsigned int used;
751};
752
753/* One BTS */
754struct gsm_bts {
755 /* list header in net->bts_list */
756 struct llist_head list;
757
758 /* Geographical location of the BTS */
759 struct llist_head loc_list;
760
761 /* number of ths BTS in network */
762 uint8_t nr;
763 /* human readable name / description */
764 char *description;
765 /* Cell Identity */
766 uint16_t cell_identity;
767 /* location area code of this BTS */
768 uint16_t location_area_code;
769 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
770 * which is used as TSC for the CCCH */
771 uint8_t bsic;
772 /* type of BTS */
773 enum gsm_bts_type type;
774 enum gsm_bts_type_variant variant;
775 struct gsm_bts_model *model;
776 enum gsm_band band;
777 char version[MAX_VERSION_LENGTH];
778 char sub_model[MAX_VERSION_LENGTH];
779
780 /* features of a given BTS set/reported via OML */
781 struct bitvec features;
782 uint8_t _features_data[MAX_BTS_FEATURES/8];
783
784 /* Connected PCU version (if any) */
785 char pcu_version[MAX_VERSION_LENGTH];
786
787 /* maximum Tx power that the MS is permitted to use in this cell */
788 int ms_max_power;
789
790 /* how do we talk OML with this TRX? */
791 struct gsm_e1_subslot oml_e1_link;
792 uint8_t oml_tei;
793 struct e1inp_sign_link *oml_link;
794 /* when OML link was established */
795 time_t uptime;
796
797 /* Abis network management O&M handle */
798 struct abis_nm_h *nmh;
799
800 struct gsm_abis_mo mo;
801
802 /* number of this BTS on given E1 link */
803 uint8_t bts_nr;
804
805 /* DTX features of this BTS */
806 enum gsm48_dtx_mode dtxu;
807 bool dtxd;
808
809 /* paging state and control */
810 struct gsm_bts_paging_state paging;
811
812 /* CCCH is on C0 */
813 struct gsm_bts_trx *c0;
814
815 struct {
816 struct gsm_abis_mo mo;
817 } site_mgr;
818
819 /* bitmask of all SI that are present/valid in si_buf */
820 uint32_t si_valid;
821 /* 3GPP TS 44.018 Table 10.5.2.33b.1 INDEX and COUNT for SI2quater */
822 uint8_t si2q_index; /* distinguish individual SI2quater messages */
823 uint8_t si2q_count; /* si2q_index for the last (highest indexed) individual SI2quater message */
824 /* buffers where we put the pre-computed SI */
825 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
826 /* offsets used while generating SI2quater */
827 size_t e_offset;
828 size_t u_offset;
829
830 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
831 union {
832 struct {
833 uint16_t site_id;
834 uint16_t bts_id;
835 uint32_t flags;
836 uint32_t rsl_ip;
837 } ip_access;
838 struct {
839 struct {
840 struct gsm_abis_mo mo;
841 } cclk;
842 struct {
843 struct gsm_abis_mo mo;
844 } rack;
845 struct gsm_envabtse envabtse[4];
846 } bs11;
847 struct {
848 struct {
849 struct om2k_mo om2k_mo;
850 struct gsm_abis_mo mo;
851 struct llist_head conn_groups;
852 } cf;
853 struct {
854 struct om2k_mo om2k_mo;
855 struct gsm_abis_mo mo;
856 struct llist_head conn_groups;
857 } is;
858 struct {
859 struct om2k_mo om2k_mo;
860 struct gsm_abis_mo mo;
861 struct llist_head conn_groups;
862 } con;
863 struct {
864 struct om2k_mo om2k_mo;
865 struct gsm_abis_mo mo;
866 } dp;
867 struct {
868 struct om2k_mo om2k_mo;
869 struct gsm_abis_mo mo;
870 } tf;
871 uint32_t use_superchannel:1;
872 } rbs2000;
873 struct {
874 uint8_t bts_type;
875 unsigned int configured:1,
876 skip_reset:1,
877 no_loc_rel_cnf:1,
878 bts_reset_timer_cnf,
879 did_reset:1,
880 wait_reset:1;
881 struct osmo_timer_list reset_timer;
882 } nokia;
883 };
884
885 /* Not entirely sure how ip.access specific this is */
886 struct {
887 uint8_t supports_egprs_11bit_rach;
888 enum bts_gprs_mode mode;
889 struct {
890 struct gsm_abis_mo mo;
891 uint16_t nsei;
892 uint8_t timer[7];
893 } nse;
894 struct {
895 struct gsm_abis_mo mo;
896 uint16_t bvci;
897 uint8_t timer[11];
898 struct gprs_rlc_cfg rlc_cfg;
899 } cell;
900 struct gsm_bts_gprs_nsvc nsvc[2];
901 uint8_t rac;
902 uint8_t net_ctrl_ord;
903 bool ctrl_ack_type_use_block;
904 } gprs;
905
906 /* RACH NM values */
907 int rach_b_thresh;
908 int rach_ldavg_slots;
909
910 /* transceivers */
911 int num_trx;
912 struct llist_head trx_list;
913
914 /* SI related items */
915 int force_combined_si;
916 int bcch_change_mark;
917
918 /* Abis NM queue */
919 struct llist_head abis_queue;
920 int abis_nm_pend;
921
922 struct gsm_network *network;
923
924 /* should the channel allocator allocate channels from high TRX to TRX0,
925 * rather than starting from TRX0 and go upwards? */
926 int chan_alloc_reverse;
927
928 enum neigh_list_manual_mode neigh_list_manual_mode;
929 /* parameters from which we build SYSTEM INFORMATION */
930 struct {
931 struct gsm48_rach_control rach_control;
932 uint8_t ncc_permitted;
933 struct gsm48_cell_sel_par cell_sel_par;
934 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
935 struct gsm48_cell_options cell_options;
936 struct gsm48_control_channel_descr chan_desc;
937 struct bitvec neigh_list;
938 struct bitvec cell_alloc;
939 struct bitvec si5_neigh_list;
940 struct osmo_earfcn_si2q si2quater_neigh_list;
941 size_t uarfcn_length; /* index for uarfcn and scramble lists */
942 struct {
943 /* bitmask large enough for all possible ARFCN's */
944 uint8_t neigh_list[1024/8];
945 uint8_t cell_alloc[1024/8];
946 /* If the user wants a different neighbor list in SI5 than in SI2 */
947 uint8_t si5_neigh_list[1024/8];
948 uint8_t meas_bw_list[MAX_EARFCN_LIST];
949 uint16_t earfcn_list[MAX_EARFCN_LIST];
950 uint16_t uarfcn_list[MAX_EARFCN_LIST];
951 uint16_t scramble_list[MAX_EARFCN_LIST];
952 } data;
953 } si_common;
954 bool early_classmark_allowed;
955 bool early_classmark_allowed_3g;
956 /* for testing only: Have an infinitely long radio link timeout */
957 bool infinite_radio_link_timeout;
958
959 /* do we use static (user-defined) system information messages? (bitmask) */
960 uint32_t si_mode_static;
961
Stefan Sperling6442e432018-02-06 14:44:54 +0100962 /* access control class ramping */
963 struct acc_ramp acc_ramp;
964
Neels Hofmeyr10485162018-02-13 23:22:03 +0100965 /* exclude the BTS from the global RF Lock handling */
966 int excl_from_rf_lock;
967
968 /* supported codecs beside FR */
969 struct bts_codec_conf codec;
970
971 /* BTS dependencies bit field */
972 uint32_t depends_on[256/(8*4)];
973
974 /* full and half rate multirate config */
975 struct amr_multirate_conf mr_full;
976 struct amr_multirate_conf mr_half;
977
978 /* PCU socket state */
979 char *pcu_sock_path;
980 struct pcu_sock_state *pcu_state;
981
982 struct rate_ctr_group *bts_ctrs;
983 struct osmo_stat_item_group *bts_statg;
984
985 struct handover_cfg *ho;
986
987 /* BTS-specific overrides for timer values from struct gsm_network. */
988 uint8_t T3122; /* ASSIGMENT REJECT wait indication */
989
990 /* Periodic channel load measurements are used to maintain T3122. */
991 struct load_counter chan_load_samples[7];
992 int chan_load_samples_idx;
Stefan Sperling6442e432018-02-06 14:44:54 +0100993 uint8_t chan_load_avg; /* current channel load average in percent (0 - 100). */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100994};
995
996
Neels Hofmeyr958f2592018-05-27 01:26:31 +0200997struct gsm_network *gsm_network_init(void *ctx);
998
Neels Hofmeyr10485162018-02-13 23:22:03 +0100999struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, uint8_t bts_num);
1000struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
1001
1002struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
1003struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
1004
1005enum gsm_bts_type str2btstype(const char *arg);
1006const char *btstype2str(enum gsm_bts_type type);
1007
1008enum bts_attribute str2btsattr(const char *s);
1009const char *btsatttr2str(enum bts_attribute v);
1010
1011enum gsm_bts_type_variant str2btsvariant(const char *arg);
1012const char *btsvariant2str(enum gsm_bts_type_variant v);
1013
1014extern const struct value_string gsm_chreq_descs[];
1015const struct value_string gsm_pchant_names[13];
1016const struct value_string gsm_pchant_descs[13];
1017const char *gsm_pchan_name(enum gsm_phys_chan_config c);
1018enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
1019const char *gsm_lchant_name(enum gsm_chan_t c);
1020const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
1021char *gsm_trx_name(const struct gsm_bts_trx *trx);
1022char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
1023char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
1024char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
1025const char *gsm_lchans_name(enum gsm_lchan_state s);
1026
1027static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
1028{
1029 return lchan->name;
1030}
1031
Neels Hofmeyr10485162018-02-13 23:22:03 +01001032void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
1033
1034struct gsm_nm_state *
1035gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
1036 const struct abis_om_obj_inst *obj_inst);
1037void *
1038gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
1039 const struct abis_om_obj_inst *obj_inst);
1040
1041/* reset the state of all MO in the BTS */
1042void gsm_bts_mo_reset(struct gsm_bts *bts);
1043
1044uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
1045 uint8_t ts_nr, uint8_t lchan_nr);
1046uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
1047uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
1048 enum gsm_phys_chan_config as_pchan);
1049
1050/* return the gsm_lchan for the CBCH (if it exists at all) */
1051struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
1052
1053/*
1054 * help with parsing regexps
1055 */
1056int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
1057 int argc, const char **argv) __attribute__ ((warn_unused_result));
1058
1059static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
1060{
1061 if (ts->tsc != -1)
1062 return ts->tsc;
1063 else
1064 return ts->trx->bts->bsic & 7;
1065}
1066
1067struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
1068 int *rc);
1069
1070enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
1071uint8_t ts_subslots(struct gsm_bts_trx_ts *ts);
1072bool ts_is_tch(struct gsm_bts_trx_ts *ts);
1073
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01001074
Harald Welteb7948872017-12-18 18:48:21 +01001075static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection *conn) {
1076 OSMO_ASSERT(conn->lchan);
1077 return conn->lchan->ts->trx->bts;
1078}
1079
Harald Welted82101e2017-12-09 23:07:38 +01001080enum {
1081 BTS_CTR_CHREQ_TOTAL,
1082 BTS_CTR_CHREQ_NO_CHANNEL,
1083 BTS_CTR_CHAN_RF_FAIL,
1084 BTS_CTR_CHAN_RLL_ERR,
1085 BTS_CTR_BTS_OML_FAIL,
1086 BTS_CTR_BTS_RSL_FAIL,
1087 BTS_CTR_CODEC_AMR_F,
1088 BTS_CTR_CODEC_AMR_H,
1089 BTS_CTR_CODEC_EFR,
1090 BTS_CTR_CODEC_V1_FR,
1091 BTS_CTR_CODEC_V1_HR,
Harald Weltecf9d4312017-12-13 23:17:16 +01001092 BTS_CTR_PAGING_ATTEMPTED,
1093 BTS_CTR_PAGING_ALREADY,
1094 BTS_CTR_PAGING_RESPONDED,
1095 BTS_CTR_PAGING_EXPIRED,
Harald Welte4f598922017-12-14 13:47:02 +01001096 BTS_CTR_CHAN_ACT_TOTAL,
1097 BTS_CTR_CHAN_ACT_NACK,
Harald Welte62d9cb02017-12-14 14:00:26 +01001098 BTS_CTR_RSL_UNKNOWN,
Harald Welte581398a2017-12-14 14:29:44 +01001099 BTS_CTR_RSL_IPA_NACK,
Harald Welte00d64fd2017-12-14 14:34:16 +01001100 BTS_CTR_MODE_MODIFY_NACK,
Harald Welted82101e2017-12-09 23:07:38 +01001101};
1102
1103static const struct rate_ctr_desc bts_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001104 [BTS_CTR_CHREQ_TOTAL] = {"chreq:total", "Received channel requests."},
1105 [BTS_CTR_CHREQ_NO_CHANNEL] = {"chreq:no_channel", "Sent to MS no channel available."},
1106 [BTS_CTR_CHAN_RF_FAIL] = {"chan:rf_fail", "Received a RF failure indication from BTS."},
1107 [BTS_CTR_CHAN_RLL_ERR] = {"chan:rll_err", "Received a RLL failure with T200 cause from BTS."},
Harald Welted82101e2017-12-09 23:07:38 +01001108 [BTS_CTR_BTS_OML_FAIL] = {"oml_fail", "Received a TEI down on a OML link."},
1109 [BTS_CTR_BTS_RSL_FAIL] = {"rsl_fail", "Received a TEI down on a OML link."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001110 [BTS_CTR_CODEC_AMR_F] = {"codec:amr_f", "Count the usage of AMR/F codec by channel mode requested."},
1111 [BTS_CTR_CODEC_AMR_H] = {"codec:amr_h", "Count the usage of AMR/H codec by channel mode requested."},
1112 [BTS_CTR_CODEC_EFR] = {"codec:efr", "Count the usage of EFR codec by channel mode requested."},
1113 [BTS_CTR_CODEC_V1_FR] = {"codec:fr", "Count the usage of FR codec by channel mode requested."},
1114 [BTS_CTR_CODEC_V1_HR] = {"codec:hr", "Count the usage of HR codec by channel mode requested."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001115
1116 [BTS_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
1117 [BTS_CTR_PAGING_ALREADY] = {"paging:already", "Paging attempts ignored as subsciber was already being paged."},
1118 [BTS_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful paging response."},
1119 [BTS_CTR_PAGING_EXPIRED] = {"paging:expired", "Paging Request expired because of timeout T3113."},
Harald Welte4f598922017-12-14 13:47:02 +01001120 [BTS_CTR_CHAN_ACT_TOTAL] = {"chan_act:total", "Total number of Channel Activations."},
1121 [BTS_CTR_CHAN_ACT_NACK] = {"chan_act:nack", "Number of Channel Activations that the BTS NACKed"},
Harald Welte62d9cb02017-12-14 14:00:26 +01001122 [BTS_CTR_RSL_UNKNOWN] = {"rsl:unknown", "Number of unknown/unsupported RSL messages received from BTS"},
Harald Welte581398a2017-12-14 14:29:44 +01001123 [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 +01001124 [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 +01001125};
1126
1127static const struct rate_ctr_group_desc bts_ctrg_desc = {
1128 "bts",
1129 "base transceiver station",
1130 OSMO_STATS_CLASS_GLOBAL,
1131 ARRAY_SIZE(bts_ctr_description),
1132 bts_ctr_description,
1133};
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001134
Alexander Couzens20423ea2016-07-12 15:42:02 +02001135enum {
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001136 BTS_STAT_CHAN_LOAD_AVERAGE,
1137 BTS_STAT_T3122,
1138};
1139
1140enum {
Alexander Couzensb847a212016-08-02 11:34:11 +02001141 BSC_CTR_HANDOVER_ATTEMPTED,
1142 BSC_CTR_HANDOVER_NO_CHANNEL,
1143 BSC_CTR_HANDOVER_TIMEOUT,
1144 BSC_CTR_HANDOVER_COMPLETED,
1145 BSC_CTR_HANDOVER_FAILED,
1146 BSC_CTR_PAGING_ATTEMPTED,
1147 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +01001148 BSC_CTR_PAGING_RESPONDED,
Stefan Sperling7926d982018-05-17 14:52:02 +02001149 BSC_CTR_UNKNOWN_UNIT_ID,
Alexander Couzensb847a212016-08-02 11:34:11 +02001150};
1151
1152static const struct rate_ctr_desc bsc_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001153 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Received handover attempts."},
1154 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Sent no channel available responses."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001155 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Timeouts of timer T3103."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001156 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Received handover completed."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001157 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Received HO FAIL messages."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001158
1159 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001160 [BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Paging request send failures because no responsible BTS was found."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001161 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response."},
Stefan Sperling7926d982018-05-17 14:52:02 +02001162
1163 [BSC_CTR_UNKNOWN_UNIT_ID] = {"abis:unknown_unit_id", "Connection attempts from unknown IPA CCM Unit ID."},
Alexander Couzensb847a212016-08-02 11:34:11 +02001164};
1165
Alexander Couzensb847a212016-08-02 11:34:11 +02001166
1167
1168static const struct rate_ctr_group_desc bsc_ctrg_desc = {
1169 "bsc",
1170 "base station controller",
1171 OSMO_STATS_CLASS_GLOBAL,
1172 ARRAY_SIZE(bsc_ctr_description),
1173 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +02001174};
1175
Harald Weltedea252d2017-12-10 19:55:18 +01001176#define GSM_T3101_DEFAULT 3 /* s */
Harald Weltea0d324b2017-07-20 01:47:39 +02001177#define GSM_T3103_DEFAULT 5 /* s */
1178#define GSM_T3105_DEFAULT 100 /* ms */
1179#define GSM_T3107_DEFAULT 5 /* s */
Harald Welteed23c1d2017-12-10 19:58:16 +01001180#define GSM_T3109_DEFAULT 5 /* s, must be 2s + radio_link_timeout*0.48 */
Harald Weltea0d324b2017-07-20 01:47:39 +02001181#define GSM_T3111_DEFAULT 2 /* s */
Harald Welte6e59ced2017-12-14 12:49:43 +01001182#define GSM_T3113_DEFAULT 10 /* s */
Harald Weltea0d324b2017-07-20 01:47:39 +02001183#define GSM_T3115_DEFAULT 10
1184#define GSM_T3117_DEFAULT 10
1185#define GSM_T3119_DEFAULT 10
Andreas Eversberg75e13a42013-02-07 11:51:16 +01001186#define GSM_T3122_DEFAULT 10
Harald Weltea0d324b2017-07-20 01:47:39 +02001187#define GSM_T3141_DEFAULT 10
Neels Hofmeyr0c1ac9f2018-06-05 15:37:59 +02001188#define GSM_T10_DEFAULT 6 /* RR Assignment timeout, in seconds */
Neels Hofmeyr0abe84e2018-05-14 18:14:29 +02001189#define GSM_T7_DEFAULT 10 /* inter-BSC MO Handover first timeout, in seconds */
1190#define GSM_T8_DEFAULT 10 /* inter-BSC MO Handover second timeout, in seconds */
1191#define GSM_T101_DEFAULT 10 /* inter-BSC MT Handover timeout, in seconds */
Harald Welteb84ddfc2009-12-01 17:36:54 +05301192
Neels Hofmeyr73983952016-05-10 13:29:33 +02001193struct gsm_tz {
1194 int override; /* if 0, use system's time zone instead. */
1195 int hr; /* hour */
1196 int mn; /* minute */
1197 int dst; /* daylight savings */
1198};
1199
Harald Welte52b1f982008-12-23 20:25:15 +00001200struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001201 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
1202 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
1203 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
1204 * these have in common, like country and network code, put in yet
1205 * separate structs and placed as members in osmo_bsc and osmo_msc. */
1206
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001207 struct osmo_plmn_id plmn;
1208
Harald Welte51e4bf32017-12-23 17:30:18 +01001209 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
1210 uint8_t a5_encryption_mask;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001211 int neci;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001212
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001213 struct handover_cfg *ho;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001214 struct {
1215 unsigned int congestion_check_interval_s;
1216 struct osmo_timer_list congestion_check_timer;
1217 } hodec2;
Harald Welte52b1f982008-12-23 20:25:15 +00001218
Alexander Couzensb847a212016-08-02 11:34:11 +02001219 struct rate_ctr_group *bsc_ctrs;
Harald Welte24ff6ee2009-12-22 00:41:05 +01001220
Harald Welte52b1f982008-12-23 20:25:15 +00001221 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +02001222 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001223
1224 /* timer values */
1225 int T3101;
Neels Hofmeyr0abe84e2018-05-14 18:14:29 +02001226 int T3103; /*< Handover timeout */
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +01001227 int T3105;
1228 int T3107;
1229 int T3109;
1230 int T3111;
1231 int T3113;
1232 int T3115;
1233 int T3117;
1234 int T3119;
Harald Welte2862dca2010-12-23 14:39:29 +01001235 int T3122;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +01001236 int T3141;
Neels Hofmeyr0c1ac9f2018-06-05 15:37:59 +02001237 int T10; /*< RR Assignment timeout, in seconds */
Neels Hofmeyr0abe84e2018-05-14 18:14:29 +02001238 int T7; /*< inter-BSC handover MO timeout from Handover Required to Handover Command */
1239 int T8; /*< inter-BSC handover MO timeout from Handover Command to final Clear*/
1240 int T101; /*< inter-BSC handover MT timeout from Handover Request to Handover Accept */
Harald Welteeab84a12009-12-13 10:53:12 +01001241
Alexander Couzens547c2072017-11-21 12:03:04 +01001242 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +08001243
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +08001244 /* Use a TCH for handling requests of type paging any */
1245 int pag_any_tch;
1246
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08001247 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +02001248 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +01001249
Daniel Willmann6fc4a982011-07-22 17:55:42 +02001250 /* control interface */
1251 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +02001252
1253 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
1254 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +02001255
1256 /* all active subscriber connections. */
1257 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +02001258
1259 /* if override is nonzero, this timezone data is used for all MM
1260 * contexts. */
1261 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
1262 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +01001263 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +02001264 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +01001265
1266 /* List of all struct bsc_subscr used in libbsc. This llist_head is
1267 * allocated so that the llist_head pointer itself can serve as a
1268 * talloc context (useful to not have to pass the entire gsm_network
1269 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
1270 * not require gsm_data.h). In an MSC-without-BSC environment, this
1271 * pointer is NULL to indicate absence of a bsc_subscribers list. */
1272 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +02001273
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001274 /* Periodic location update default value */
1275 uint8_t t3212;
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001276
Stefan Sperling6cee8932018-01-30 18:14:22 +01001277 /* Timer for periodic channel load measurements to maintain each BTS's T3122. */
1278 struct osmo_timer_list t3122_chan_load_timer;
1279
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001280 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +02001281 struct mgcp_client_conf *conf;
1282 struct mgcp_client *client;
1283 } mgw;
Harald Welte7e310b12009-03-30 20:56:32 +00001284};
1285
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001286static inline const struct osmo_location_area_id *bts_lai(struct gsm_bts *bts)
1287{
1288 static struct osmo_location_area_id lai;
1289 lai = (struct osmo_location_area_id){
1290 .plmn = bts->network->plmn,
1291 .lac = bts->location_area_code,
1292 };
1293 return &lai;
1294}
1295
Neels Hofmeyrc13e6872016-05-11 13:53:47 +02001296extern void talloc_ctx_init(void *ctx_root);
1297
Harald Welte39315c42010-01-10 18:01:52 +01001298int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +02001299
Harald Welte1d014a52009-08-08 15:38:29 +02001300enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +02001301const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +00001302struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
1303 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +00001304
Andreas Eversberg8226fa72009-06-29 15:19:38 +02001305extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +01001306extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +02001307
Harald Weltef383aa12012-07-02 19:51:55 +02001308/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +00001309static inline int is_ipaccess_bts(struct gsm_bts *bts)
1310{
1311 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001312 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001313 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +00001314 return 1;
1315 default:
1316 break;
1317 }
1318 return 0;
1319}
1320
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001321static inline int is_sysmobts_v2(struct gsm_bts *bts)
1322{
1323 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +01001324 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001325 return 1;
1326 default:
1327 break;
1328 }
1329 return 0;
1330}
1331
Harald Welte5b570672009-08-10 10:08:01 +02001332static inline int is_siemens_bts(struct gsm_bts *bts)
1333{
1334 switch (bts->type) {
1335 case GSM_BTS_TYPE_BS11:
1336 return 1;
1337 default:
1338 break;
1339 }
1340
1341 return 0;
1342}
1343
Andreas Eversberg7d8fa342013-12-05 13:25:06 +01001344static inline int is_nokia_bts(struct gsm_bts *bts)
1345{
1346 switch (bts->type) {
1347 case GSM_BTS_TYPE_NOKIA_SITE:
1348 return 1;
1349 default:
1350 break;
1351 }
1352
1353 return 0;
1354}
1355
Andreas Eversbergdcf38e12013-12-05 14:37:11 +01001356static inline int is_e1_bts(struct gsm_bts *bts)
1357{
1358 switch (bts->type) {
1359 case GSM_BTS_TYPE_BS11:
1360 case GSM_BTS_TYPE_RBS2000:
1361 case GSM_BTS_TYPE_NOKIA_SITE:
1362 return 1;
1363 default:
1364 break;
1365 }
1366
1367 return 0;
1368}
1369
Harald Welte1876c312018-05-27 11:53:43 +02001370extern struct gsm_network *bsc_gsmnet;
1371
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001372enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +02001373const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001374int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +02001375
Neels Hofmeyr4d358c02018-02-22 03:19:05 +01001376void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +08001377void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +01001378
Harald Weltefbda4e12010-03-04 11:04:52 +01001379int gsm_bts_model_register(struct gsm_bts_model *model);
1380
Harald Welte3561bd42018-01-28 03:04:16 +01001381struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *network);
Neels Hofmeyr42eb0142016-05-20 17:15:44 +02001382
1383struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
1384void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +08001385
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001386struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, uint8_t bsic);
1387struct gsm_bts *bsc_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, uint8_t bsic);
Harald Welte142d12d2014-12-29 17:47:08 +01001388
Harald Welte3300c012011-06-05 13:31:33 +02001389void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
1390 uint8_t e1_ts, uint8_t e1_ts_ss);
1391
Maxbe356ed2017-09-07 19:10:09 +02001392void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Harald Welte3300c012011-06-05 13:31:33 +02001393struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +01001394int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -04001395int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +02001396
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +02001397/* generic E1 line operations for all ISDN-based BTS. */
1398extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
1399
Harald Weltee555c2b2012-08-17 13:02:12 +02001400extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
1401extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
1402
Max3d049d22017-10-09 17:12:53 +02001403char *get_model_oml_status(const struct gsm_bts *bts);
1404
Max25cc4072017-10-10 14:50:35 +02001405unsigned long long bts_uptime(const struct gsm_bts *bts);
1406
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +01001407/* control interface handling */
1408int bsc_base_ctrl_cmds_install(void);
1409
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001410/* dependency handling */
1411void bts_depend_mark(struct gsm_bts *bts, int dep);
1412void bts_depend_clear(struct gsm_bts *bts, int dep);
1413int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +01001414int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001415
Harald Welte2f8b9d22017-06-18 11:12:13 +03001416int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
1417void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
1418
Harald Weltea43e0b42016-06-19 18:06:02 +02001419bool classmark_is_r99(struct gsm_classmark *cm);
1420
Neels Hofmeyr91aa68f2018-05-09 17:46:22 +02001421void gsm_ts_check_init(struct gsm_bts_trx_ts *ts);
1422void gsm_trx_mark_all_ts_uninitialized(struct gsm_bts_trx *trx);
1423void gsm_bts_mark_all_ts_uninitialized(struct gsm_bts *bts);
1424
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001425bool trx_is_usable(const struct gsm_bts_trx *trx);
1426
1427bool on_gsm_ts_init(struct gsm_bts_trx_ts *ts);
1428
Harald Welte6be350c2011-05-25 13:10:08 +02001429#endif /* _GSM_DATA_H */