blob: 867a46c9af59410730c2ff50617b5e45538e525a [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 Hofmeyr31f525e2018-05-14 18:14:15 +020017#include <osmocom/gsm/gsm0808.h>
Neels Hofmeyrf93970b2018-03-05 02:09:40 +010018#include <osmocom/gsm/gsm48.h>
Harald Welte3561bd42018-01-28 03:04:16 +010019#include <osmocom/core/fsm.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020020
Harald Welte121e9a42016-04-20 13:13:19 +020021#include <osmocom/crypt/auth.h>
Harald Weltef142c972011-05-24 13:25:38 +020022
Neels Hofmeyrc0164792017-09-04 15:15:32 +020023#include <osmocom/bsc/rest_octets.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 Hofmeyr31f525e2018-05-14 18:14:15 +020034#include <osmocom/bsc/gsm_timers.h>
35#include <osmocom/bsc/neighbor_ident.h>
Neels Hofmeyr10485162018-02-13 23:22:03 +010036
Neels Hofmeyr596c4022018-06-16 19:29:50 +020037#define GSM_T3122_DEFAULT 10
38
Harald Welte74b8cdb2018-01-15 19:26:06 +010039struct mgcp_client_conf;
40struct mgcp_client;
41struct mgcp_ctx;
Neels Hofmeyr19bed232018-03-22 04:54:57 +010042struct gsm0808_cell_id;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020043struct mgw_endpoint;
Philipp Maier39f62bb2017-04-09 12:32:51 +020044
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020045/** annotations for msgb ownership */
46#define __uses
47
Holger Hans Peter Freyther6f615552010-11-15 20:50:42 +010048#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
49
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010050struct bsc_subscr;
Neels Hofmeyr7b656882017-07-09 22:09:18 +020051struct gprs_ra_id;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020052struct handover;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020053
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080054#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
55
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010056#define tmsi_from_string(str) strtoul(str, NULL, 10)
57
Max70fdd242017-06-15 15:10:53 +020058/* 3-bit long values */
59#define EARFCN_PRIO_INVALID 8
60#define EARFCN_MEAS_BW_INVALID 8
61/* 5-bit long values */
62#define EARFCN_QRXLV_INVALID 32
63#define EARFCN_THRESH_LOW_INVALID 32
64
Harald Welte8e1e3ee2009-02-01 13:32:45 +000065struct msgb;
66typedef int gsm_cbfn(unsigned int hooknum,
67 unsigned int event,
68 struct msgb *msg,
69 void *data, void *param);
70
Harald Weltef7c28b02009-12-21 13:30:17 +010071/* Maximum number of neighbor cells whose average we track */
72#define MAX_NEIGH_MEAS 10
73/* Maximum size of the averaging window for neighbor cells */
74#define MAX_WIN_NEIGH_AVG 10
Andreas Eversberg98692032013-06-23 10:44:34 +020075/* Maximum number of report history we store */
76#define MAX_MEAS_REP 10
Harald Weltef7c28b02009-12-21 13:30:17 +010077
78/* processed neighbor measurements for one cell */
79struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020080 uint16_t arfcn;
81 uint8_t bsic;
82 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +010083 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020084 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +010085};
86
Harald Weltea43e0b42016-06-19 18:06:02 +020087struct gsm_classmark {
88 bool classmark1_set;
89 struct gsm48_classmark1 classmark1;
90 uint8_t classmark2_len;
91 uint8_t classmark2[3];
92 uint8_t classmark3_len;
93 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
94};
95
Harald Welte519c7e12018-01-28 02:45:46 +010096enum subscr_sccp_state {
97 SUBSCR_SCCP_ST_NONE,
98 SUBSCR_SCCP_ST_WAIT_CONN_CONF,
99 SUBSCR_SCCP_ST_CONNECTED
100};
101
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200102struct assignment_request {
103 bool aoip;
104
105 uint16_t msc_assigned_cic;
106
107 char msc_rtp_addr[INET_ADDRSTRLEN];
108 uint16_t msc_rtp_port;
109
110 enum gsm48_chan_mode chan_mode;
111 bool full_rate;
Philipp Maierc9a4f692018-09-21 14:21:50 +0200112 uint16_t s15_s0;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200113};
114
115struct assignment_fsm_data {
116 struct assignment_request req;
117 bool requires_voice_stream;
118
119 struct osmo_fsm_inst *fi;
120 struct gsm_lchan *new_lchan;
121
122 /* Whether this assignment triggered creation of the MGW endpoint: if the assignment
123 * fails, we will release that again as soon as possible. (If false, the endpoint already
124 * existed before or isn't needed at all.)*/
125 struct mgwep_ci *created_ci_for_msc;
126
127 enum gsm0808_cause failure_cause;
128 enum gsm48_rr_cause rr_cause;
129
130 bool result_rate_ctr_done;
131};
132
133enum hodec_id {
134 HODEC_NONE,
135 HODEC1 = 1,
136 HODEC2 = 2,
137 HODEC_USER,
138 HODEC_REMOTE,
139};
140
141/* For example, to count specific kinds of ongoing handovers, it is useful to be able to OR-combine
142 * scopes. */
143enum handover_scope {
144 HO_NO_HANDOVER = 0,
145 HO_INTRA_CELL = 0x1,
146 HO_INTRA_BSC = 0x2,
147 HO_INTER_BSC_OUT = 0x4,
148 HO_INTER_BSC_IN = 0x8,
149 HO_SCOPE_ALL = 0xffff,
150};
151
152extern const struct value_string handover_scope_names[];
153inline static const char *handover_scope_name(enum handover_scope val)
154{ return get_value_string(handover_scope_names, val); }
155
156struct handover_out_req {
157 enum hodec_id from_hodec_id;
158 struct gsm_lchan *old_lchan;
159 struct neighbor_ident_key target_nik;
160 enum gsm_chan_t new_lchan_type; /*< leave GSM_LCHAN_NONE to use same as old_lchan */
161};
162
163struct handover_in_req {
164 struct gsm0808_channel_type ct;
165 struct gsm0808_speech_codec_list scl;
166 struct gsm0808_encrypt_info ei;
167 struct gsm_classmark classmark;
168 struct gsm0808_cell_id cell_id_serving;
169 char cell_id_serving_name[64];
170 struct gsm0808_cell_id cell_id_target;
171 char cell_id_target_name[64];
172 uint16_t msc_assigned_cic;
173 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
174 uint16_t msc_assigned_rtp_port;
175};
176
177struct handover {
178 struct osmo_fsm_inst *fi;
179
180 enum hodec_id from_hodec_id;
181 enum handover_scope scope;
182 enum gsm_chan_t new_lchan_type;
183 struct neighbor_ident_key target_cell;
184
185 uint8_t ho_ref;
186 struct gsm_bts *new_bts;
187 struct gsm_lchan *new_lchan;
188 bool async;
189 struct handover_in_req inter_bsc_in;
190 struct mgwep_ci *created_ci_for_msc;
191};
192
Neels Hofmeyr378a4922016-05-09 21:07:43 +0200193/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100194struct gsm_subscriber_connection {
Harald Weltea43e0b42016-06-19 18:06:02 +0200195 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +0800196 struct llist_head entry;
197
Harald Welte3561bd42018-01-28 03:04:16 +0100198 /* FSM instance to control the subscriber connection state (RTP, A) */
199 struct osmo_fsm_inst *fi;
200
Harald Weltea43e0b42016-06-19 18:06:02 +0200201 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100202 struct bsc_subscr *bsub;
203
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100204 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200205 struct gsm_network *network;
206
Harald Welte4a8ebc82017-12-18 18:34:41 +0100207 /* the primary / currently active lchan to the BTS/subscriber */
208 struct gsm_lchan *lchan;
Harald Welte3561bd42018-01-28 03:04:16 +0100209
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200210 struct assignment_fsm_data assignment;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100211
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200212 /* handover information, if a handover is pending for this conn. */
213 struct handover ho;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100214
Harald Welte4a8ebc82017-12-18 18:34:41 +0100215 /* buffer/cache for classmark of the ME of the subscriber */
Harald Weltea43e0b42016-06-19 18:06:02 +0200216 struct gsm_classmark classmark;
Andreas Eversberg935e5d72013-06-17 11:58:30 +0200217
Neels Hofmeyr149160f2018-06-16 17:20:13 +0200218 /* Queue DTAP messages during handover/assignment (msgb_enqueue()/msgb_dequeue())*/
219 struct llist_head dtap_queue;
220 unsigned int dtap_queue_len;
Andreas Eversberg084b4212013-05-30 14:12:48 +0200221
Neels Hofmeyrec422642018-02-15 14:07:40 +0100222 struct {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100223 int failures;
Neels Hofmeyrec422642018-02-15 14:07:40 +0100224 struct penalty_timers *penalty_timers;
225 } hodec2;
Neels Hofmeyra60f3442018-02-12 16:44:32 +0100226
227 /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment Request. 3GPP 48.008
228 * 3.2.2.103 says:
229 * The "Codec List (MSC Preferred)" shall not include codecs
230 * that are not supported by the MS.
231 * i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed the MS bearer
232 * capabilities, which the MSC is required to translate into the codec list. */
233 struct gsm0808_speech_codec_list codec_list;
Harald Welte519c7e12018-01-28 02:45:46 +0100234
235 /* flag to prevent multiple simultaneous ciphering commands */
236 int ciphering_handled;
237
238 /* state related to welcome USSD */
239 uint8_t new_subscriber;
240
241 /* state related to osmo_bsc_filter.c */
242 struct bsc_filter_state filter_state;
243
244 /* SCCP connection associatd with this subscriber_connection */
245 struct {
246 /* for advanced ping/pong */
247 int send_ping;
248
249 /* SCCP connection realted */
250 struct bsc_msc_data *msc;
251
252 /* Sigtran connection ID */
253 int conn_id;
254 enum subscr_sccp_state state;
255 } sccp;
256
257 /* for audio handling */
258 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200259 uint16_t msc_assigned_cic;
Harald Welte519c7e12018-01-28 02:45:46 +0100260
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200261 /* RTP address where the MSC expects us to send the RTP stream coming from the BTS. */
262 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
263 uint16_t msc_assigned_rtp_port;
Harald Welte519c7e12018-01-28 02:45:46 +0100264
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200265 /* The endpoint at the MGW used to join both BTS and MSC side connections, e.g.
266 * "rtpbridge/23@mgw". */
267 struct mgw_endpoint *mgw_endpoint;
Harald Welte3561bd42018-01-28 03:04:16 +0100268
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200269 /* The connection identifier of the mgw_endpoint used to transceive RTP towards the MSC.
270 * (The BTS side CI is handled by struct gsm_lchan and the lchan_fsm.) */
271 struct mgwep_ci *mgw_endpoint_ci_msc;
Harald Welte519c7e12018-01-28 02:45:46 +0100272 } user_plane;
Harald Weltec997ceb2018-05-30 01:39:43 +0200273
274 /* LCLS (local call, local switch) related state */
275 struct {
276 uint8_t global_call_ref[15];
277 uint8_t global_call_ref_len; /* length of global_call_ref */
Maxfe65ece2018-11-09 13:36:11 +0100278 enum gsm0808_lcls_config config; /* TS 48.008 3.2.2.116 */
279 enum gsm0808_lcls_control control; /* TS 48.008 3.2.2.117 */
Harald Weltec997ceb2018-05-30 01:39:43 +0200280 /* LCLS FSM */
281 struct osmo_fsm_inst *fi;
282 /* pointer to "other" connection, if Call Leg Relocation was successful */
283 struct gsm_subscriber_connection *other;
284 } lcls;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100285};
286
Harald Weltef142c972011-05-24 13:25:38 +0200287
Neels Hofmeyr10485162018-02-13 23:22:03 +0100288/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 Table 10.5.2.33b.1:
289 4-bit index is used (2#1111 = 10#15) */
290#define SI2Q_MAX_NUM 16
291/* length in bits (for single SI2quater message) */
292#define SI2Q_MAX_LEN 160
293#define SI2Q_MIN_LEN 18
294
295struct osmo_bsc_data;
296
297struct osmo_bsc_sccp_con;
298
299/* Channel Request reason */
300enum gsm_chreq_reason_t {
301 GSM_CHREQ_REASON_EMERG,
302 GSM_CHREQ_REASON_PAG,
303 GSM_CHREQ_REASON_CALL,
304 GSM_CHREQ_REASON_LOCATION_UPD,
305 GSM_CHREQ_REASON_OTHER,
306 GSM_CHREQ_REASON_PDCH,
307};
308
309/* lchans 0..3 are SDCCH in combined channel configuration,
310 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
311#define CCCH_LCHAN 4
312
313#define TRX_NR_TS 8
314#define TS_MAX_LCHAN 8
315
316#define HARDCODED_ARFCN 123
317#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
318
319/* for multi-drop config */
320#define HARDCODED_BTS0_TS 1
321#define HARDCODED_BTS1_TS 6
322#define HARDCODED_BTS2_TS 11
323
324#define MAX_VERSION_LENGTH 64
325
Neels Hofmeyr10485162018-02-13 23:22:03 +0100326enum gsm_hooks {
327 GSM_HOOK_NM_SWLOAD,
328 GSM_HOOK_RR_PAGING,
329 GSM_HOOK_RR_SECURITY,
330};
331
Neels Hofmeyr10485162018-02-13 23:22:03 +0100332enum bts_gprs_mode {
333 BTS_GPRS_NONE = 0,
334 BTS_GPRS_GPRS = 1,
335 BTS_GPRS_EGPRS = 2,
336};
337
338struct gsm_lchan;
339struct osmo_rtp_socket;
340struct rtp_socket;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100341
342/* Network Management State */
343struct gsm_nm_state {
344 uint8_t operational;
345 uint8_t administrative;
346 uint8_t availability;
347};
348
349struct gsm_abis_mo {
350 uint8_t obj_class;
351 uint8_t procedure_pending;
352 struct abis_om_obj_inst obj_inst;
353 const char *name;
354 struct gsm_nm_state nm_state;
355 struct tlv_parsed *nm_attr;
356 struct gsm_bts *bts;
357};
358
359/* Ericsson OM2000 Managed Object */
360struct abis_om2k_mo {
361 uint8_t class;
362 uint8_t bts;
363 uint8_t assoc_so;
364 uint8_t inst;
365} __attribute__ ((packed));
366
367struct om2k_mo {
368 struct abis_om2k_mo addr;
369 struct osmo_fsm_inst *fsm;
370};
371
372#define A38_XOR_MIN_KEY_LEN 12
373#define A38_XOR_MAX_KEY_LEN 16
374#define A38_COMP128_KEY_LEN 16
375#define RSL_ENC_ALG_A5(x) (x+1)
376#define MAX_EARFCN_LIST 32
377
378/* is the data link established? who established it? */
379#define LCHAN_SAPI_UNUSED 0
380#define LCHAN_SAPI_MS 1
381#define LCHAN_SAPI_NET 2
Neels Hofmeyr10485162018-02-13 23:22:03 +0100382
383/* BTS ONLY */
384#define MAX_NUM_UL_MEAS 104
385#define LC_UL_M_F_L1_VALID (1 << 0)
386#define LC_UL_M_F_RES_VALID (1 << 1)
387
388struct bts_ul_meas {
389 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
390 uint16_t ber10k;
391 /* timing advance offset (in quarter bits) */
392 int16_t ta_offs_qbits;
393 /* C/I ratio in dB */
394 float c_i;
395 /* flags */
396 uint8_t is_sub:1;
397 /* RSSI in dBm * -1 */
398 uint8_t inv_rssi;
399};
400
401struct bts_codec_conf {
402 uint8_t hr;
403 uint8_t efr;
404 uint8_t amr;
405};
406
407struct amr_mode {
408 uint8_t mode;
409 uint8_t threshold;
410 uint8_t hysteresis;
411};
412
413struct amr_multirate_conf {
414 uint8_t gsm48_ie[2];
415 struct amr_mode ms_mode[4];
416 struct amr_mode bts_mode[4];
417 uint8_t num_modes;
418};
419/* /BTS ONLY */
420
421enum lchan_csd_mode {
422 LCHAN_CSD_M_NT,
423 LCHAN_CSD_M_T_1200_75,
424 LCHAN_CSD_M_T_600,
425 LCHAN_CSD_M_T_1200,
426 LCHAN_CSD_M_T_2400,
427 LCHAN_CSD_M_T_9600,
428 LCHAN_CSD_M_T_14400,
429 LCHAN_CSD_M_T_29000,
430 LCHAN_CSD_M_T_32000,
431};
432
433/* State of the SAPIs in the lchan */
434enum lchan_sapi_state {
435 LCHAN_SAPI_S_NONE,
436 LCHAN_SAPI_S_REQ,
437 LCHAN_SAPI_S_ASSIGNED,
438 LCHAN_SAPI_S_REL,
439 LCHAN_SAPI_S_ERROR,
440};
441
Neels Hofmeyr92b9f2e2018-02-14 00:19:11 +0100442#define MAX_A5_KEY_LEN (128/8)
443
444struct gsm_encr {
445 uint8_t alg_id;
446 uint8_t key_len;
447 uint8_t key[MAX_A5_KEY_LEN];
448};
449
Neels Hofmeyr8da22332018-04-11 01:43:41 +0200450#define LOGPLCHAN(lchan, ss, level, fmt, args...) \
451 LOGP(ss, level, "%s (ss=%d,%s) (%s) " fmt, \
452 lchan ? gsm_ts_and_pchan_name(lchan->ts) : "-", \
453 lchan ? lchan->nr : 0, \
454 lchan ? gsm_lchant_name(lchan->type) : "-", \
455 bsc_subscr_name(lchan && lchan->conn ? lchan->conn->bsub : NULL), \
456 ## args)
457
Pau Espin Pedrold3e8e0c2018-11-28 16:35:10 +0100458/* Iterate lchans that have an FSM allocated based based on explicit pchan kind
459 * (GSM_PCHAN_* constant).
460 * Remark: PDCH related lchans are not handled in BSC but in PCU, so trying to
461 * iterate through GSM_PCHAN_PDCH is considered a void loop.
462 */
463#define ts_as_pchan_for_each_lchan(lchan, ts, as_pchan) \
464 for (lchan = (ts)->lchan; \
465 ((lchan - (ts)->lchan) < ARRAY_SIZE((ts)->lchan)) \
466 && lchan->fi \
467 && lchan->nr < pchan_subslots(as_pchan); \
468 lchan++)
469
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100470/* Iterate lchans that have an FSM allocated based on current PCHAN
471 * mode set in \ref ts.
472 * usage:
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200473 * struct gsm_lchan *lchan;
474 * struct gsm_bts_trx_ts *ts = get_some_timeslot();
475 * ts_for_each_lchan(lchan, ts) {
476 * LOGPLCHAN(DMAIN, LOGL_DEBUG, "hello world\n");
477 * }
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100478 */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200479#define ts_for_each_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_is)
480
Pau Espin Pedrol0ba20df2018-11-28 16:39:29 +0100481/* Iterate over all possible lchans available that have an FSM allocated based
482 * on PCHAN \ref ts (dynamic) configuration.
483 * Iterate all lchan instances set up by this \ref ts type, including those
484 * lchans currently disabled or in process of being enabled (e.g. due to dynamic
485 * timeslot in switchover). Compare ts_for_each_lchan(), which iterates only the
486 * enabled lchans.
487 * For example, it is useful in case dynamic timeslot \ref ts is in process of
488 * switching from configuration PDCH (no lchans) to TCH_F (1 lchan), where
489 * pchan_is is still set to PDCH but \ref ts may contain already an \ref lchan
490 * of type TCH_F which initiated the request to switch the \ts configuration.
491 */
492#define ts_for_each_potential_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_on_init)
493
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200494enum lchan_activate_mode {
495 FOR_NONE,
496 FOR_MS_CHANNEL_REQUEST,
497 FOR_ASSIGNMENT,
498 FOR_HANDOVER,
499 FOR_VTY,
500};
501
502extern const struct value_string lchan_activate_mode_names[];
503static inline const char *lchan_activate_mode_name(enum lchan_activate_mode activ_for)
504{ return get_value_string(lchan_activate_mode_names, activ_for); }
505
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100506struct lchan_activate_info {
507 enum lchan_activate_mode activ_for;
508 struct gsm_subscriber_connection *for_conn;
509 /* This always is for a specific lchan, so its lchan->type indicates full or half rate.
510 * When a dyn TS was selected, the lchan->type has been set to the desired rate. */
511 enum gsm48_chan_mode chan_mode;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100512 /* AMR config */
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100513 uint16_t s15_s0;
514 bool requires_voice_stream;
515 bool wait_before_switching_rtp; /*< true = requires LCHAN_EV_READY_TO_SWITCH_RTP */
516 uint16_t msc_assigned_cic;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100517 /* During intra-BSC handover, we keep the MGW endpoint intact and just re-route to the new lchan. This
518 * activate_info is for the new lchan, the re_use_mgw_endpoint_from_lchan points at the old lchan. */
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100519 struct gsm_lchan *re_use_mgw_endpoint_from_lchan;
520};
521
Neels Hofmeyr10485162018-02-13 23:22:03 +0100522struct gsm_lchan {
523 /* The TS that we're part of */
524 struct gsm_bts_trx_ts *ts;
525 /* The logical subslot number in the TS */
526 uint8_t nr;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200527 char *name;
528
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100529 char *last_error;
530
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200531 struct osmo_fsm_inst *fi;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200532 struct osmo_fsm_inst *fi_rtp;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200533 struct mgwep_ci *mgw_endpoint_ci_bts;
534
535 struct {
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100536 struct lchan_activate_info info;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200537 bool activ_ack; /*< true as soon as RSL Chan Activ Ack is received */
Neels Hofmeyr369fba22018-11-27 01:30:50 +0100538 bool immediate_assignment_sent;
Neels Hofmeyr193c1e32018-08-27 22:06:24 +0200539 /*! This flag ensures that when an lchan activation has succeeded, and we have already
540 * sent ACKs like Immediate Assignment or BSSMAP Assignment Complete, and if other errors
541 * occur later, e.g. during release, that we don't send a NACK out of context. */
542 bool concluded;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200543 enum gsm0808_cause gsm0808_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200544 } activate;
545
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100546 struct {
547 /* If an event to release the lchan comes in while still waiting for responses, just mark this
548 * flag, so that the lchan will gracefully release at the next sensible junction. */
549 bool requested;
550 bool do_rr_release;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200551
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100552 /* There is an RSL error cause of value 0, so we need a separate flag. */
553 bool in_error;
554 /* RSL error code, RSL_ERR_* */
555 uint8_t rsl_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200556
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100557 /* If a release event is being handled, ignore other ricocheting release events until that
558 * release handling has concluded. */
559 bool in_release_handler;
Harald Welte963763d2019-02-03 12:11:12 +0100560
561 /* is this release at the end of a CSFB call? */
562 bool is_csfb;
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100563 } release;
Neels Hofmeyrd5df9a12018-07-20 05:35:47 +0200564
Neels Hofmeyr10485162018-02-13 23:22:03 +0100565 /* The logical channel type */
566 enum gsm_chan_t type;
567 /* RSL channel mode */
568 enum rsl_cmod_spd rsl_cmode;
569 /* If TCH, traffic channel mode */
570 enum gsm48_chan_mode tch_mode;
571 enum lchan_csd_mode csd_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100572 /* Power levels for MS and BTS */
573 uint8_t bs_power;
574 uint8_t ms_power;
575 /* Encryption information */
576 struct gsm_encr encr;
577
578 /* AMR bits */
579 uint8_t mr_ms_lv[7];
580 uint8_t mr_bts_lv[7];
Neels Hofmeyr4daa2102019-01-30 16:46:58 +0100581 /* AMR bits were based on these rate bits: */
582 uint16_t s15_s0;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100583
584 /* Established data link layer services */
585 uint8_t sapis[8];
586
587 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200588 uint32_t bound_ip; /*< where the BTS receives RTP */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100589 uint16_t bound_port;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200590 uint32_t connect_ip; /*< where the BTS sends RTP to (MGW) */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100591 uint16_t connect_port;
592 uint16_t conn_id;
593 uint8_t rtp_payload;
594 uint8_t rtp_payload2;
595 uint8_t speech_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100596
597 /* info we need to postpone the AoIP
598 * assignment completed message */
599 struct {
600 uint8_t rr_cause;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100601 bool valid;
602 } ass_compl;
603 } abis_ip;
604
605 uint8_t rqd_ta;
606
Neels Hofmeyr10485162018-02-13 23:22:03 +0100607 /* table of neighbor cell measurements */
608 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
609
610 /* cache of last measurement reports on this lchan */
611 struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
612 int meas_rep_idx;
613 int meas_rep_count;
Neels Hofmeyr35ba85c2018-02-12 16:47:40 +0100614 uint8_t meas_rep_last_seen_nr;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100615
616 /* GSM Random Access data */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200617 /* TODO: don't allocate this, rather keep an "is_present" flag */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100618 struct gsm48_req_ref *rqd_ref;
619
620 struct gsm_subscriber_connection *conn;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100621};
622
Neels Hofmeyr10485162018-02-13 23:22:03 +0100623/* One Timeslot in a TRX */
624struct gsm_bts_trx_ts {
625 struct gsm_bts_trx *trx;
626 /* number of this timeslot at the TRX */
627 uint8_t nr;
628
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200629 struct osmo_fsm_inst *fi;
630 char *last_errmsg;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100631
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200632 /* vty phys_chan_config setting, not necessarily in effect in case it was changed in the telnet
633 * vty after OML activation. Gets written on vty 'write file'. */
634 enum gsm_phys_chan_config pchan_from_config;
635 /* When the timeslot OML is established, pchan_from_config is copied here. This is the pchan
636 * currently in effect; for dynamic ts, this is the dyn kind (GSM_PCHAN_TCH_F_TCH_H_PDCH or
637 * GSM_PCHAN_TCH_F_PDCH) and does not show the pchan type currently active. */
638 enum gsm_phys_chan_config pchan_on_init;
639 /* This is the *actual* pchan type currently active. For dynamic timeslots, this reflects either
640 * GSM_PCHAN_NONE or one of the standard GSM_PCHAN_TCH_F, GSM_PCHAN_TCH_H, GSM_PCHAN_PDCH.
641 * Callers can use this transparently without being aware of dyn ts. */
642 enum gsm_phys_chan_config pchan_is;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100643
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200644 /* After a PDCH ACT NACK, we shall not infinitely loop to try and ACT again.
645 * Also marks a timeslot where PDCH was deactivated by VTY. This is cleared whenever a timeslot
646 * enters IN_USE state, i.e. after each TCH use we try to PDCH ACT once again. */
647 bool pdch_act_allowed;
648
Neels Hofmeyrbcdbfb72018-07-26 20:33:15 +0200649 /* Whether TS_EV_OML_READY was received */
650 bool is_oml_ready;
651 /* Whether TS_EV_RSL_READY was received */
652 bool is_rsl_ready;
653
Neels Hofmeyr10485162018-02-13 23:22:03 +0100654 struct gsm_abis_mo mo;
655 struct tlv_parsed nm_attr;
656 uint8_t nm_chan_comb;
657 int tsc; /* -1 == use BTS TSC */
658
659 struct {
660 /* Parameters below are configured by VTY */
661 int enabled;
662 uint8_t maio;
663 uint8_t hsn;
664 struct bitvec arfcns;
665 uint8_t arfcns_data[1024/8];
666 /* This is the pre-computed MA for channel assignments */
667 struct bitvec ma;
668 uint8_t ma_len; /* part of ma_data that is used */
669 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
670 } hopping;
671
672 /* To which E1 subslot are we connected */
673 struct gsm_e1_subslot e1_link;
674
675 union {
676 struct {
677 struct om2k_mo om2k_mo;
678 } rbs2000;
679 };
680
681 struct gsm_lchan lchan[TS_MAX_LCHAN];
682};
683
684/* One TRX in a BTS */
685struct gsm_bts_trx {
686 /* list header in bts->trx_list */
687 struct llist_head list;
688
689 struct gsm_bts *bts;
690 /* number of this TRX in the BTS */
691 uint8_t nr;
692 /* human readable name / description */
693 char *description;
694 /* how do we talk RSL with this TRX? */
695 struct gsm_e1_subslot rsl_e1_link;
696 uint8_t rsl_tei;
697 struct e1inp_sign_link *rsl_link;
698
699 /* Timeout for initiating the RSL connection. */
700 struct osmo_timer_list rsl_connect_timeout;
701
702 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
703 struct e1inp_sign_link *oml_link;
704
705 struct gsm_abis_mo mo;
706 struct tlv_parsed nm_attr;
707 struct {
708 struct gsm_abis_mo mo;
709 } bb_transc;
710
711 uint16_t arfcn;
712 int nominal_power; /* in dBm */
713 unsigned int max_power_red; /* in actual dB */
714
715 union {
716 struct {
717 struct {
718 struct gsm_abis_mo mo;
719 } bbsig;
720 struct {
721 struct gsm_abis_mo mo;
722 } pa;
723 } bs11;
724 struct {
725 unsigned int test_state;
726 uint8_t test_nr;
727 struct rxlev_stats rxlev_stat;
728 } ipaccess;
729 struct {
730 struct {
731 struct om2k_mo om2k_mo;
732 } trxc;
733 struct {
734 struct om2k_mo om2k_mo;
735 } rx;
736 struct {
737 struct om2k_mo om2k_mo;
738 } tx;
739 } rbs2000;
740 };
741 struct gsm_bts_trx_ts ts[TRX_NR_TS];
742};
743
744#define GSM_BTS_SI2Q(bts, i) (struct gsm48_system_information_type_2quater *)((bts)->si_buf[SYSINFO_TYPE_2quater][i])
745#define GSM_BTS_HAS_SI(bts, i) ((bts)->si_valid & (1 << i))
746#define GSM_BTS_SI(bts, i) (void *)((bts)->si_buf[i][0])
747#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
748
749enum gsm_bts_type {
750 GSM_BTS_TYPE_UNKNOWN,
751 GSM_BTS_TYPE_BS11,
752 GSM_BTS_TYPE_NANOBTS,
753 GSM_BTS_TYPE_RBS2000,
754 GSM_BTS_TYPE_NOKIA_SITE,
755 GSM_BTS_TYPE_OSMOBTS,
756 _NUM_GSM_BTS_TYPE
757};
758
759enum gsm_bts_type_variant {
760 BTS_UNKNOWN,
761 BTS_OSMO_LITECELL15,
762 BTS_OSMO_OCTPHY,
763 BTS_OSMO_SYSMO,
764 BTS_OSMO_TRX,
765 _NUM_BTS_VARIANT
766};
767
768/* Used by OML layer for BTS Attribute reporting */
769enum bts_attribute {
770 BTS_TYPE_VARIANT,
771 BTS_SUB_MODEL,
772 TRX_PHY_VERSION,
773};
774
775struct vty;
776
777struct gsm_bts_model {
778 struct llist_head list;
779
780 enum gsm_bts_type type;
781 enum gsm_bts_type_variant variant;
782 const char *name;
783
784 bool started;
785 int (*start)(struct gsm_network *net);
786 int (*oml_rcvmsg)(struct msgb *msg);
787 char * (*oml_status)(const struct gsm_bts *bts);
788
789 void (*e1line_bind_ops)(struct e1inp_line *line);
790
791 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
792 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
793 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
794
Pau Espin Pedrol167cb822018-11-19 17:48:17 +0100795 /* Should SI2bis and SI2ter be disabled by default on this BTS model? */
796 bool force_combined_si;
797
Neels Hofmeyr10485162018-02-13 23:22:03 +0100798 struct tlv_definition nm_att_tlvdef;
799
800 /* features of a given BTS model set via gsm_bts_model_register() locally */
801 struct bitvec features;
802 uint8_t _features_data[MAX_BTS_FEATURES/8];
803};
804
Neels Hofmeyr10485162018-02-13 23:22:03 +0100805
Neels Hofmeyr10485162018-02-13 23:22:03 +0100806
807/*
808 * This keeps track of the paging status of one BTS. It
809 * includes a number of pending requests, a back pointer
810 * to the gsm_bts, a timer and some more state.
811 */
812struct gsm_bts_paging_state {
813 /* pending requests */
814 struct llist_head pending_requests;
815 struct gsm_bts *bts;
816
817 struct osmo_timer_list work_timer;
818 struct osmo_timer_list credit_timer;
819
820 /* free chans needed */
821 int free_chans_need;
822
823 /* load */
824 uint16_t available_slots;
825};
826
827struct gsm_envabtse {
828 struct gsm_abis_mo mo;
829};
830
831struct gsm_bts_gprs_nsvc {
832 struct gsm_bts *bts;
833 /* data read via VTY config file, to configure the BTS
834 * via OML from BSC */
835 int id;
836 uint16_t nsvci;
837 uint16_t local_port; /* on the BTS */
838 uint16_t remote_port; /* on the SGSN */
839 uint32_t remote_ip; /* on the SGSN */
840
841 struct gsm_abis_mo mo;
842};
843
844enum gprs_rlc_par {
845 RLC_T3142,
846 RLC_T3169,
847 RLC_T3191,
848 RLC_T3193,
849 RLC_T3195,
850 RLC_N3101,
851 RLC_N3103,
852 RLC_N3105,
853 CV_COUNTDOWN,
854 T_DL_TBF_EXT, /* ms */
855 T_UL_TBF_EXT, /* ms */
856 _NUM_RLC_PAR
857};
858
859enum gprs_cs {
860 GPRS_CS1,
861 GPRS_CS2,
862 GPRS_CS3,
863 GPRS_CS4,
864 GPRS_MCS1,
865 GPRS_MCS2,
866 GPRS_MCS3,
867 GPRS_MCS4,
868 GPRS_MCS5,
869 GPRS_MCS6,
870 GPRS_MCS7,
871 GPRS_MCS8,
872 GPRS_MCS9,
873 _NUM_GRPS_CS
874};
875
876struct gprs_rlc_cfg {
877 uint16_t parameter[_NUM_RLC_PAR];
878 struct {
879 uint16_t repeat_time; /* ms */
880 uint8_t repeat_count;
881 } paging;
882 uint32_t cs_mask; /* bitmask of gprs_cs */
883 uint8_t initial_cs;
884 uint8_t initial_mcs;
885};
886
887
888enum neigh_list_manual_mode {
889 NL_MODE_AUTOMATIC = 0,
890 NL_MODE_MANUAL = 1,
891 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
892};
893
894enum bts_loc_fix {
895 BTS_LOC_FIX_INVALID = 0,
896 BTS_LOC_FIX_2D = 1,
897 BTS_LOC_FIX_3D = 2,
898};
899
900extern const struct value_string bts_loc_fix_names[];
901
902struct bts_location {
903 struct llist_head list;
904 time_t tstamp;
905 enum bts_loc_fix valid;
906 double lat;
907 double lon;
908 double height;
909};
910
911/* Channel load counter */
912struct load_counter {
913 unsigned int total;
914 unsigned int used;
915};
916
Neels Hofmeyr19bed232018-03-22 04:54:57 +0100917/* Useful to track N-N relations between BTS, for example neighbors. */
918struct gsm_bts_ref {
919 struct llist_head entry;
920 struct gsm_bts *bts;
921};
922
Neels Hofmeyr10485162018-02-13 23:22:03 +0100923/* One BTS */
924struct gsm_bts {
925 /* list header in net->bts_list */
926 struct llist_head list;
927
928 /* Geographical location of the BTS */
929 struct llist_head loc_list;
930
931 /* number of ths BTS in network */
932 uint8_t nr;
933 /* human readable name / description */
934 char *description;
935 /* Cell Identity */
936 uint16_t cell_identity;
937 /* location area code of this BTS */
938 uint16_t location_area_code;
939 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
940 * which is used as TSC for the CCCH */
941 uint8_t bsic;
942 /* type of BTS */
943 enum gsm_bts_type type;
944 enum gsm_bts_type_variant variant;
945 struct gsm_bts_model *model;
946 enum gsm_band band;
947 char version[MAX_VERSION_LENGTH];
948 char sub_model[MAX_VERSION_LENGTH];
949
950 /* features of a given BTS set/reported via OML */
951 struct bitvec features;
952 uint8_t _features_data[MAX_BTS_FEATURES/8];
953
954 /* Connected PCU version (if any) */
955 char pcu_version[MAX_VERSION_LENGTH];
956
957 /* maximum Tx power that the MS is permitted to use in this cell */
958 int ms_max_power;
959
960 /* how do we talk OML with this TRX? */
961 struct gsm_e1_subslot oml_e1_link;
962 uint8_t oml_tei;
963 struct e1inp_sign_link *oml_link;
Pau Espin Pedrol9862bcb2018-08-22 21:54:12 +0200964 /* Timer to use for deferred drop of OML link, see \ref ipaccess_drop_oml_deferred */
965 struct osmo_timer_list oml_drop_link_timer;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100966 /* when OML link was established */
967 time_t uptime;
968
969 /* Abis network management O&M handle */
970 struct abis_nm_h *nmh;
971
972 struct gsm_abis_mo mo;
973
974 /* number of this BTS on given E1 link */
975 uint8_t bts_nr;
976
977 /* DTX features of this BTS */
978 enum gsm48_dtx_mode dtxu;
979 bool dtxd;
980
981 /* paging state and control */
982 struct gsm_bts_paging_state paging;
983
984 /* CCCH is on C0 */
985 struct gsm_bts_trx *c0;
986
987 struct {
988 struct gsm_abis_mo mo;
989 } site_mgr;
990
991 /* bitmask of all SI that are present/valid in si_buf */
992 uint32_t si_valid;
993 /* 3GPP TS 44.018 Table 10.5.2.33b.1 INDEX and COUNT for SI2quater */
994 uint8_t si2q_index; /* distinguish individual SI2quater messages */
995 uint8_t si2q_count; /* si2q_index for the last (highest indexed) individual SI2quater message */
996 /* buffers where we put the pre-computed SI */
997 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
998 /* offsets used while generating SI2quater */
999 size_t e_offset;
1000 size_t u_offset;
Pau Espin Pedrol1cf21de2018-12-05 13:38:10 +01001001 /* 3GPP TS 08.58 §8.5.1 BCCH INFORMATION. Some nanoBTS fail upon
1002 * receival of empty SI disabling unsupported SI. see OS#3707. */
1003 bool si_unused_send_empty;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001004
1005 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
1006 union {
1007 struct {
1008 uint16_t site_id;
1009 uint16_t bts_id;
1010 uint32_t flags;
1011 uint32_t rsl_ip;
1012 } ip_access;
1013 struct {
1014 struct {
1015 struct gsm_abis_mo mo;
1016 } cclk;
1017 struct {
1018 struct gsm_abis_mo mo;
1019 } rack;
1020 struct gsm_envabtse envabtse[4];
1021 } bs11;
1022 struct {
1023 struct {
1024 struct om2k_mo om2k_mo;
1025 struct gsm_abis_mo mo;
1026 struct llist_head conn_groups;
1027 } cf;
1028 struct {
1029 struct om2k_mo om2k_mo;
1030 struct gsm_abis_mo mo;
1031 struct llist_head conn_groups;
1032 } is;
1033 struct {
1034 struct om2k_mo om2k_mo;
1035 struct gsm_abis_mo mo;
1036 struct llist_head conn_groups;
1037 } con;
1038 struct {
1039 struct om2k_mo om2k_mo;
1040 struct gsm_abis_mo mo;
1041 } dp;
1042 struct {
1043 struct om2k_mo om2k_mo;
1044 struct gsm_abis_mo mo;
1045 } tf;
1046 uint32_t use_superchannel:1;
1047 } rbs2000;
1048 struct {
1049 uint8_t bts_type;
1050 unsigned int configured:1,
1051 skip_reset:1,
1052 no_loc_rel_cnf:1,
1053 bts_reset_timer_cnf,
1054 did_reset:1,
1055 wait_reset:1;
1056 struct osmo_timer_list reset_timer;
1057 } nokia;
1058 };
1059
1060 /* Not entirely sure how ip.access specific this is */
1061 struct {
1062 uint8_t supports_egprs_11bit_rach;
1063 enum bts_gprs_mode mode;
1064 struct {
1065 struct gsm_abis_mo mo;
1066 uint16_t nsei;
1067 uint8_t timer[7];
1068 } nse;
1069 struct {
1070 struct gsm_abis_mo mo;
1071 uint16_t bvci;
1072 uint8_t timer[11];
1073 struct gprs_rlc_cfg rlc_cfg;
1074 } cell;
1075 struct gsm_bts_gprs_nsvc nsvc[2];
1076 uint8_t rac;
1077 uint8_t net_ctrl_ord;
1078 bool ctrl_ack_type_use_block;
1079 } gprs;
1080
1081 /* RACH NM values */
1082 int rach_b_thresh;
1083 int rach_ldavg_slots;
1084
1085 /* transceivers */
1086 int num_trx;
1087 struct llist_head trx_list;
1088
1089 /* SI related items */
1090 int force_combined_si;
Pau Espin Pedrol167cb822018-11-19 17:48:17 +01001091 bool force_combined_si_set;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001092 int bcch_change_mark;
1093
1094 /* Abis NM queue */
1095 struct llist_head abis_queue;
1096 int abis_nm_pend;
1097
1098 struct gsm_network *network;
1099
1100 /* should the channel allocator allocate channels from high TRX to TRX0,
1101 * rather than starting from TRX0 and go upwards? */
1102 int chan_alloc_reverse;
1103
1104 enum neigh_list_manual_mode neigh_list_manual_mode;
1105 /* parameters from which we build SYSTEM INFORMATION */
1106 struct {
1107 struct gsm48_rach_control rach_control;
1108 uint8_t ncc_permitted;
1109 struct gsm48_cell_sel_par cell_sel_par;
1110 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
1111 struct gsm48_cell_options cell_options;
1112 struct gsm48_control_channel_descr chan_desc;
1113 struct bitvec neigh_list;
1114 struct bitvec cell_alloc;
1115 struct bitvec si5_neigh_list;
1116 struct osmo_earfcn_si2q si2quater_neigh_list;
1117 size_t uarfcn_length; /* index for uarfcn and scramble lists */
1118 struct {
1119 /* bitmask large enough for all possible ARFCN's */
1120 uint8_t neigh_list[1024/8];
1121 uint8_t cell_alloc[1024/8];
1122 /* If the user wants a different neighbor list in SI5 than in SI2 */
1123 uint8_t si5_neigh_list[1024/8];
1124 uint8_t meas_bw_list[MAX_EARFCN_LIST];
1125 uint16_t earfcn_list[MAX_EARFCN_LIST];
1126 uint16_t uarfcn_list[MAX_EARFCN_LIST];
1127 uint16_t scramble_list[MAX_EARFCN_LIST];
1128 } data;
1129 } si_common;
1130 bool early_classmark_allowed;
1131 bool early_classmark_allowed_3g;
1132 /* for testing only: Have an infinitely long radio link timeout */
1133 bool infinite_radio_link_timeout;
1134
1135 /* do we use static (user-defined) system information messages? (bitmask) */
1136 uint32_t si_mode_static;
1137
Stefan Sperling6442e432018-02-06 14:44:54 +01001138 /* access control class ramping */
1139 struct acc_ramp acc_ramp;
1140
Neels Hofmeyr10485162018-02-13 23:22:03 +01001141 /* exclude the BTS from the global RF Lock handling */
1142 int excl_from_rf_lock;
1143
1144 /* supported codecs beside FR */
1145 struct bts_codec_conf codec;
1146
1147 /* BTS dependencies bit field */
1148 uint32_t depends_on[256/(8*4)];
1149
1150 /* full and half rate multirate config */
1151 struct amr_multirate_conf mr_full;
1152 struct amr_multirate_conf mr_half;
1153
1154 /* PCU socket state */
1155 char *pcu_sock_path;
1156 struct pcu_sock_state *pcu_state;
1157
1158 struct rate_ctr_group *bts_ctrs;
1159 struct osmo_stat_item_group *bts_statg;
1160
1161 struct handover_cfg *ho;
1162
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001163 /* A list of struct gsm_bts_ref, indicating neighbors of this BTS.
1164 * When the si_common neigh_list is in automatic mode, it is populated from this list as well as
1165 * gsm_network->neighbor_bss_cells. */
1166 struct llist_head local_neighbors;
1167
Neels Hofmeyr10485162018-02-13 23:22:03 +01001168 /* BTS-specific overrides for timer values from struct gsm_network. */
1169 uint8_t T3122; /* ASSIGMENT REJECT wait indication */
Pau Espin Pedrol1b963342018-11-07 14:19:32 +01001170 bool T3113_dynamic; /* Calculate T3113 timeout dynamically based on BTS channel config and load */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001171
1172 /* Periodic channel load measurements are used to maintain T3122. */
1173 struct load_counter chan_load_samples[7];
1174 int chan_load_samples_idx;
Stefan Sperling6442e432018-02-06 14:44:54 +01001175 uint8_t chan_load_avg; /* current channel load average in percent (0 - 100). */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001176};
1177
Oliver Smith8d8d7102018-10-23 15:35:43 +02001178/* One rejected BTS */
1179struct gsm_bts_rejected {
1180 /* list header in net->bts_rejected */
1181 struct llist_head list;
1182
1183 uint16_t site_id;
1184 uint16_t bts_id;
1185 char ip[INET6_ADDRSTRLEN];
1186 time_t time;
1187};
Neels Hofmeyr10485162018-02-13 23:22:03 +01001188
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001189struct gsm_network *gsm_network_init(void *ctx);
1190
Neels Hofmeyr10485162018-02-13 23:22:03 +01001191struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, uint8_t bts_num);
Neels Hofmeyr6d568ed2018-07-09 16:49:18 +02001192struct gsm_bts *gsm_bts_num(const struct gsm_network *net, int num);
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001193bool gsm_bts_matches_lai(const struct gsm_bts *bts, const struct osmo_location_area_id *lai);
1194bool gsm_bts_matches_cell_id(const struct gsm_bts *bts, const struct gsm0808_cell_id *cell_id);
1195struct gsm_bts *gsm_bts_by_cell_id(const struct gsm_network *net,
1196 const struct gsm0808_cell_id *cell_id,
1197 int match_idx);
1198int gsm_bts_local_neighbor_add(struct gsm_bts *bts, struct gsm_bts *neighbor);
1199int gsm_bts_local_neighbor_del(struct gsm_bts *bts, const struct gsm_bts *neighbor);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001200
1201struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
1202struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
1203
1204enum gsm_bts_type str2btstype(const char *arg);
1205const char *btstype2str(enum gsm_bts_type type);
1206
1207enum bts_attribute str2btsattr(const char *s);
1208const char *btsatttr2str(enum bts_attribute v);
1209
1210enum gsm_bts_type_variant str2btsvariant(const char *arg);
1211const char *btsvariant2str(enum gsm_bts_type_variant v);
1212
1213extern const struct value_string gsm_chreq_descs[];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001214extern const struct value_string gsm_pchant_names[];
1215extern const struct value_string gsm_pchant_descs[];
1216extern const struct value_string gsm_pchan_ids[];
Neels Hofmeyr10485162018-02-13 23:22:03 +01001217const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001218static inline const char *gsm_pchan_id(enum gsm_phys_chan_config c)
1219{ return get_value_string(gsm_pchan_ids, c); }
Neels Hofmeyr10485162018-02-13 23:22:03 +01001220enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
1221const char *gsm_lchant_name(enum gsm_chan_t c);
1222const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte57658ec2019-02-04 12:30:44 +01001223char *gsm_bts_name(const struct gsm_bts *bts);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001224char *gsm_trx_name(const struct gsm_bts_trx *trx);
1225char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
1226char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
1227char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001228
1229static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
1230{
1231 return lchan->name;
1232}
1233
Neels Hofmeyr10485162018-02-13 23:22:03 +01001234void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
1235
1236struct gsm_nm_state *
1237gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
1238 const struct abis_om_obj_inst *obj_inst);
1239void *
1240gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
1241 const struct abis_om_obj_inst *obj_inst);
1242
1243/* reset the state of all MO in the BTS */
1244void gsm_bts_mo_reset(struct gsm_bts *bts);
1245
1246uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
1247 uint8_t ts_nr, uint8_t lchan_nr);
1248uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
1249uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
1250 enum gsm_phys_chan_config as_pchan);
1251
Harald Welte251bec12018-09-09 17:14:09 +02001252void gsm48_lchan2chan_desc(struct gsm48_chan_desc *cd,
1253 const struct gsm_lchan *lchan);
Harald Welte24286f32018-09-09 17:17:44 +02001254void gsm48_lchan2chan_desc_as_configured(struct gsm48_chan_desc *cd, const struct gsm_lchan *lchan);
Harald Welte251bec12018-09-09 17:14:09 +02001255
Neels Hofmeyr10485162018-02-13 23:22:03 +01001256/* return the gsm_lchan for the CBCH (if it exists at all) */
1257struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
1258
1259/*
1260 * help with parsing regexps
1261 */
1262int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
1263 int argc, const char **argv) __attribute__ ((warn_unused_result));
1264
1265static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
1266{
1267 if (ts->tsc != -1)
1268 return ts->tsc;
1269 else
1270 return ts->trx->bts->bsic & 7;
1271}
1272
1273struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
1274 int *rc);
1275
1276enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001277uint8_t pchan_subslots(enum gsm_phys_chan_config pchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001278bool ts_is_tch(struct gsm_bts_trx_ts *ts);
1279
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01001280
Harald Welteb7948872017-12-18 18:48:21 +01001281static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection *conn) {
1282 OSMO_ASSERT(conn->lchan);
1283 return conn->lchan->ts->trx->bts;
1284}
1285
Harald Welted82101e2017-12-09 23:07:38 +01001286enum {
1287 BTS_CTR_CHREQ_TOTAL,
1288 BTS_CTR_CHREQ_NO_CHANNEL,
1289 BTS_CTR_CHAN_RF_FAIL,
1290 BTS_CTR_CHAN_RLL_ERR,
1291 BTS_CTR_BTS_OML_FAIL,
1292 BTS_CTR_BTS_RSL_FAIL,
1293 BTS_CTR_CODEC_AMR_F,
1294 BTS_CTR_CODEC_AMR_H,
1295 BTS_CTR_CODEC_EFR,
1296 BTS_CTR_CODEC_V1_FR,
1297 BTS_CTR_CODEC_V1_HR,
Harald Weltecf9d4312017-12-13 23:17:16 +01001298 BTS_CTR_PAGING_ATTEMPTED,
1299 BTS_CTR_PAGING_ALREADY,
1300 BTS_CTR_PAGING_RESPONDED,
1301 BTS_CTR_PAGING_EXPIRED,
Harald Welte4f598922017-12-14 13:47:02 +01001302 BTS_CTR_CHAN_ACT_TOTAL,
1303 BTS_CTR_CHAN_ACT_NACK,
Harald Welte62d9cb02017-12-14 14:00:26 +01001304 BTS_CTR_RSL_UNKNOWN,
Harald Welte581398a2017-12-14 14:29:44 +01001305 BTS_CTR_RSL_IPA_NACK,
Harald Welte00d64fd2017-12-14 14:34:16 +01001306 BTS_CTR_MODE_MODIFY_NACK,
Harald Welted82101e2017-12-09 23:07:38 +01001307};
1308
1309static const struct rate_ctr_desc bts_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001310 [BTS_CTR_CHREQ_TOTAL] = {"chreq:total", "Received channel requests."},
1311 [BTS_CTR_CHREQ_NO_CHANNEL] = {"chreq:no_channel", "Sent to MS no channel available."},
1312 [BTS_CTR_CHAN_RF_FAIL] = {"chan:rf_fail", "Received a RF failure indication from BTS."},
1313 [BTS_CTR_CHAN_RLL_ERR] = {"chan:rll_err", "Received a RLL failure with T200 cause from BTS."},
Harald Welted82101e2017-12-09 23:07:38 +01001314 [BTS_CTR_BTS_OML_FAIL] = {"oml_fail", "Received a TEI down on a OML link."},
1315 [BTS_CTR_BTS_RSL_FAIL] = {"rsl_fail", "Received a TEI down on a OML link."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001316 [BTS_CTR_CODEC_AMR_F] = {"codec:amr_f", "Count the usage of AMR/F codec by channel mode requested."},
1317 [BTS_CTR_CODEC_AMR_H] = {"codec:amr_h", "Count the usage of AMR/H codec by channel mode requested."},
1318 [BTS_CTR_CODEC_EFR] = {"codec:efr", "Count the usage of EFR codec by channel mode requested."},
1319 [BTS_CTR_CODEC_V1_FR] = {"codec:fr", "Count the usage of FR codec by channel mode requested."},
1320 [BTS_CTR_CODEC_V1_HR] = {"codec:hr", "Count the usage of HR codec by channel mode requested."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001321
1322 [BTS_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
1323 [BTS_CTR_PAGING_ALREADY] = {"paging:already", "Paging attempts ignored as subsciber was already being paged."},
1324 [BTS_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful paging response."},
1325 [BTS_CTR_PAGING_EXPIRED] = {"paging:expired", "Paging Request expired because of timeout T3113."},
Harald Welte4f598922017-12-14 13:47:02 +01001326 [BTS_CTR_CHAN_ACT_TOTAL] = {"chan_act:total", "Total number of Channel Activations."},
1327 [BTS_CTR_CHAN_ACT_NACK] = {"chan_act:nack", "Number of Channel Activations that the BTS NACKed"},
Harald Welte62d9cb02017-12-14 14:00:26 +01001328 [BTS_CTR_RSL_UNKNOWN] = {"rsl:unknown", "Number of unknown/unsupported RSL messages received from BTS"},
Harald Welte581398a2017-12-14 14:29:44 +01001329 [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 +01001330 [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 +01001331};
1332
1333static const struct rate_ctr_group_desc bts_ctrg_desc = {
1334 "bts",
1335 "base transceiver station",
1336 OSMO_STATS_CLASS_GLOBAL,
1337 ARRAY_SIZE(bts_ctr_description),
1338 bts_ctr_description,
1339};
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001340
Alexander Couzens20423ea2016-07-12 15:42:02 +02001341enum {
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001342 BTS_STAT_CHAN_LOAD_AVERAGE,
1343 BTS_STAT_T3122,
1344};
1345
1346enum {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001347 BSC_CTR_ASSIGNMENT_ATTEMPTED,
1348 BSC_CTR_ASSIGNMENT_COMPLETED,
1349 BSC_CTR_ASSIGNMENT_STOPPED,
1350 BSC_CTR_ASSIGNMENT_NO_CHANNEL,
1351 BSC_CTR_ASSIGNMENT_TIMEOUT,
1352 BSC_CTR_ASSIGNMENT_FAILED,
1353 BSC_CTR_ASSIGNMENT_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001354 BSC_CTR_HANDOVER_ATTEMPTED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001355 BSC_CTR_HANDOVER_COMPLETED,
1356 BSC_CTR_HANDOVER_STOPPED,
Alexander Couzensb847a212016-08-02 11:34:11 +02001357 BSC_CTR_HANDOVER_NO_CHANNEL,
1358 BSC_CTR_HANDOVER_TIMEOUT,
Alexander Couzensb847a212016-08-02 11:34:11 +02001359 BSC_CTR_HANDOVER_FAILED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001360 BSC_CTR_HANDOVER_ERROR,
1361 BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED,
1362 BSC_CTR_INTER_BSC_HO_OUT_COMPLETED,
1363 BSC_CTR_INTER_BSC_HO_OUT_STOPPED,
1364 BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT,
1365 BSC_CTR_INTER_BSC_HO_OUT_ERROR,
1366 BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED,
1367 BSC_CTR_INTER_BSC_HO_IN_COMPLETED,
1368 BSC_CTR_INTER_BSC_HO_IN_STOPPED,
1369 BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL,
1370 BSC_CTR_INTER_BSC_HO_IN_FAILED,
1371 BSC_CTR_INTER_BSC_HO_IN_TIMEOUT,
1372 BSC_CTR_INTER_BSC_HO_IN_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001373 BSC_CTR_PAGING_ATTEMPTED,
1374 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +01001375 BSC_CTR_PAGING_RESPONDED,
Stefan Sperling7926d982018-05-17 14:52:02 +02001376 BSC_CTR_UNKNOWN_UNIT_ID,
Alexander Couzensb847a212016-08-02 11:34:11 +02001377};
1378
1379static const struct rate_ctr_desc bsc_ctr_description[] = {
Neels Hofmeyrdbb38d52018-07-11 19:53:56 +02001380 [BSC_CTR_ASSIGNMENT_ATTEMPTED] = {"assignment:attempted", "Assignment attempts."},
1381 [BSC_CTR_ASSIGNMENT_COMPLETED] = {"assignment:completed", "Assignment completed."},
1382 [BSC_CTR_ASSIGNMENT_STOPPED] = {"assignment:stopped", "Connection ended during Assignment."},
1383 [BSC_CTR_ASSIGNMENT_NO_CHANNEL] = {"assignment:no_channel", "Failure to allocate lchan for Assignment."},
1384 [BSC_CTR_ASSIGNMENT_TIMEOUT] = {"assignment:timeout", "Assignment timed out."},
1385 [BSC_CTR_ASSIGNMENT_FAILED] = {"assignment:failed", "Received Assignment Failure message."},
1386 [BSC_CTR_ASSIGNMENT_ERROR] = {"assignment:error", "Assigment failed for other reason."},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001387
1388 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Intra-BSC handover attempts."},
1389 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Intra-BSC handover completed."},
1390 [BSC_CTR_HANDOVER_STOPPED] = {"handover:stopped", "Connection ended during HO."},
1391 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Failure to allocate lchan for HO."},
1392 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Handover timed out."},
1393 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Received Handover Fail messages."},
1394 [BSC_CTR_HANDOVER_ERROR] = {"handover:error", "Re-assigment failed for other reason."},
1395
1396 [BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED] = {"interbsc_ho_out:attempted",
1397 "Attempts to handover to remote BSS."},
1398 [BSC_CTR_INTER_BSC_HO_OUT_COMPLETED] = {"interbsc_ho_out:completed",
1399 "Handover to remote BSS completed."},
1400 [BSC_CTR_INTER_BSC_HO_OUT_STOPPED] = {"interbsc_ho_out:stopped", "Connection ended during HO."},
1401 [BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT] = {"interbsc_ho_out:timeout", "Handover timed out."},
1402 [BSC_CTR_INTER_BSC_HO_OUT_ERROR] = {"interbsc_ho_out:error",
1403 "Handover to remote BSS failed for other reason."},
1404
1405 [BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED] = {"interbsc_ho_in:attempted",
1406 "Attempts to handover from remote BSS."},
1407 [BSC_CTR_INTER_BSC_HO_IN_COMPLETED] = {"interbsc_ho_in:completed",
1408 "Handover from remote BSS completed."},
1409 [BSC_CTR_INTER_BSC_HO_IN_STOPPED] = {"interbsc_ho_in:stopped", "Connection ended during HO."},
1410 [BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL] = {"interbsc_ho_in:no_channel",
1411 "Failure to allocate lchan for HO."},
1412 [BSC_CTR_INTER_BSC_HO_IN_TIMEOUT] = {"interbsc_ho_in:timeout", "Handover from remote BSS timed out."},
1413 [BSC_CTR_INTER_BSC_HO_IN_FAILED] = {"interbsc_ho_in:failed", "Received Handover Fail message."},
1414 [BSC_CTR_INTER_BSC_HO_IN_ERROR] = {"interbsc_ho_in:error",
1415 "Handover from remote BSS failed for other reason."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001416
1417 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001418 [BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Paging request send failures because no responsible BTS was found."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001419 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response."},
Stefan Sperling7926d982018-05-17 14:52:02 +02001420
1421 [BSC_CTR_UNKNOWN_UNIT_ID] = {"abis:unknown_unit_id", "Connection attempts from unknown IPA CCM Unit ID."},
Alexander Couzensb847a212016-08-02 11:34:11 +02001422};
1423
Alexander Couzensb847a212016-08-02 11:34:11 +02001424
1425
1426static const struct rate_ctr_group_desc bsc_ctrg_desc = {
1427 "bsc",
1428 "base station controller",
1429 OSMO_STATS_CLASS_GLOBAL,
1430 ARRAY_SIZE(bsc_ctr_description),
1431 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +02001432};
1433
Neels Hofmeyr73983952016-05-10 13:29:33 +02001434struct gsm_tz {
1435 int override; /* if 0, use system's time zone instead. */
1436 int hr; /* hour */
1437 int mn; /* minute */
1438 int dst; /* daylight savings */
1439};
1440
Harald Welte52b1f982008-12-23 20:25:15 +00001441struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001442 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
1443 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
1444 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
1445 * these have in common, like country and network code, put in yet
1446 * separate structs and placed as members in osmo_bsc and osmo_msc. */
1447
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001448 struct osmo_plmn_id plmn;
1449
Harald Welte51e4bf32017-12-23 17:30:18 +01001450 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
1451 uint8_t a5_encryption_mask;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001452 int neci;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001453
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001454 struct handover_cfg *ho;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001455 struct {
1456 unsigned int congestion_check_interval_s;
1457 struct osmo_timer_list congestion_check_timer;
1458 } hodec2;
Harald Welte52b1f982008-12-23 20:25:15 +00001459
Alexander Couzensb847a212016-08-02 11:34:11 +02001460 struct rate_ctr_group *bsc_ctrs;
Harald Welte24ff6ee2009-12-22 00:41:05 +01001461
Harald Welte52b1f982008-12-23 20:25:15 +00001462 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +02001463 struct llist_head bts_list;
Oliver Smith8d8d7102018-10-23 15:35:43 +02001464 struct llist_head bts_rejected;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001465
Neels Hofmeyr596c4022018-06-16 19:29:50 +02001466 /* shall reference gsm_network_T[] */
1467 struct T_def *T_defs;
Harald Welteeab84a12009-12-13 10:53:12 +01001468
Alexander Couzens547c2072017-11-21 12:03:04 +01001469 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +08001470
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +08001471 /* Use a TCH for handling requests of type paging any */
1472 int pag_any_tch;
1473
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08001474 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +02001475 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +01001476
Daniel Willmann6fc4a982011-07-22 17:55:42 +02001477 /* control interface */
1478 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +02001479
1480 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
1481 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +02001482
1483 /* all active subscriber connections. */
1484 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +02001485
1486 /* if override is nonzero, this timezone data is used for all MM
1487 * contexts. */
1488 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
1489 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +01001490 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +02001491 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +01001492
1493 /* List of all struct bsc_subscr used in libbsc. This llist_head is
1494 * allocated so that the llist_head pointer itself can serve as a
1495 * talloc context (useful to not have to pass the entire gsm_network
1496 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
1497 * not require gsm_data.h). In an MSC-without-BSC environment, this
1498 * pointer is NULL to indicate absence of a bsc_subscribers list. */
1499 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +02001500
Stefan Sperling6cee8932018-01-30 18:14:22 +01001501 /* Timer for periodic channel load measurements to maintain each BTS's T3122. */
1502 struct osmo_timer_list t3122_chan_load_timer;
1503
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001504 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +02001505 struct mgcp_client_conf *conf;
1506 struct mgcp_client *client;
1507 } mgw;
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001508
1509 /* Remote BSS Cell Identifier Lists */
1510 struct neighbor_ident_list *neighbor_bss_cells;
Harald Welte7e310b12009-03-30 20:56:32 +00001511};
1512
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001513struct gsm_audio_support {
1514 uint8_t hr : 1,
1515 ver : 7;
1516};
1517
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001518static inline const struct osmo_location_area_id *bts_lai(struct gsm_bts *bts)
1519{
1520 static struct osmo_location_area_id lai;
1521 lai = (struct osmo_location_area_id){
1522 .plmn = bts->network->plmn,
1523 .lac = bts->location_area_code,
1524 };
1525 return &lai;
1526}
1527
Neels Hofmeyrc13e6872016-05-11 13:53:47 +02001528extern void talloc_ctx_init(void *ctx_root);
1529
Harald Welte39315c42010-01-10 18:01:52 +01001530int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +02001531
Harald Welte1d014a52009-08-08 15:38:29 +02001532enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +02001533const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +00001534struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
1535 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +00001536
Andreas Eversberg8226fa72009-06-29 15:19:38 +02001537extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +01001538extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +02001539
Harald Weltef383aa12012-07-02 19:51:55 +02001540/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +00001541static inline int is_ipaccess_bts(struct gsm_bts *bts)
1542{
1543 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001544 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001545 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +00001546 return 1;
1547 default:
1548 break;
1549 }
1550 return 0;
1551}
1552
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001553static inline int is_sysmobts_v2(struct gsm_bts *bts)
1554{
1555 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +01001556 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001557 return 1;
1558 default:
1559 break;
1560 }
1561 return 0;
1562}
1563
Harald Welte5b570672009-08-10 10:08:01 +02001564static inline int is_siemens_bts(struct gsm_bts *bts)
1565{
1566 switch (bts->type) {
1567 case GSM_BTS_TYPE_BS11:
1568 return 1;
1569 default:
1570 break;
1571 }
1572
1573 return 0;
1574}
1575
Andreas Eversberg7d8fa342013-12-05 13:25:06 +01001576static inline int is_nokia_bts(struct gsm_bts *bts)
1577{
1578 switch (bts->type) {
1579 case GSM_BTS_TYPE_NOKIA_SITE:
1580 return 1;
1581 default:
1582 break;
1583 }
1584
1585 return 0;
1586}
1587
Andreas Eversbergdcf38e12013-12-05 14:37:11 +01001588static inline int is_e1_bts(struct gsm_bts *bts)
1589{
1590 switch (bts->type) {
1591 case GSM_BTS_TYPE_BS11:
1592 case GSM_BTS_TYPE_RBS2000:
1593 case GSM_BTS_TYPE_NOKIA_SITE:
1594 return 1;
1595 default:
1596 break;
1597 }
1598
1599 return 0;
1600}
1601
Harald Welte1876c312018-05-27 11:53:43 +02001602extern struct gsm_network *bsc_gsmnet;
1603
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001604enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +02001605const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001606int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +02001607
Neels Hofmeyr4d358c02018-02-22 03:19:05 +01001608void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +08001609void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +01001610
Harald Weltefbda4e12010-03-04 11:04:52 +01001611int gsm_bts_model_register(struct gsm_bts_model *model);
1612
Harald Welte3561bd42018-01-28 03:04:16 +01001613struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *network);
Neels Hofmeyr42eb0142016-05-20 17:15:44 +02001614
1615struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
1616void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +08001617
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001618struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, uint8_t bsic);
1619struct 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 +01001620
Harald Welte3300c012011-06-05 13:31:33 +02001621void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
1622 uint8_t e1_ts, uint8_t e1_ts_ss);
1623
Maxbe356ed2017-09-07 19:10:09 +02001624void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Harald Welte3300c012011-06-05 13:31:33 +02001625struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +01001626int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -04001627int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +02001628
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +02001629/* generic E1 line operations for all ISDN-based BTS. */
1630extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
1631
Harald Weltee555c2b2012-08-17 13:02:12 +02001632extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
1633extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
1634
Max3d049d22017-10-09 17:12:53 +02001635char *get_model_oml_status(const struct gsm_bts *bts);
1636
Max25cc4072017-10-10 14:50:35 +02001637unsigned long long bts_uptime(const struct gsm_bts *bts);
1638
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +01001639/* control interface handling */
1640int bsc_base_ctrl_cmds_install(void);
1641
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001642/* dependency handling */
1643void bts_depend_mark(struct gsm_bts *bts, int dep);
1644void bts_depend_clear(struct gsm_bts *bts, int dep);
1645int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +01001646int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001647
Harald Welte2f8b9d22017-06-18 11:12:13 +03001648int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
1649void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
1650
Harald Weltea43e0b42016-06-19 18:06:02 +02001651bool classmark_is_r99(struct gsm_classmark *cm);
1652
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001653bool trx_is_usable(const struct gsm_bts_trx *trx);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001654bool ts_is_usable(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001655
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001656int gsm_lchan_type_by_pchan(enum gsm_phys_chan_config pchan);
1657enum gsm_phys_chan_config gsm_pchan_by_lchan_type(enum gsm_chan_t type);
1658
1659void gsm_bts_all_ts_dispatch(struct gsm_bts *bts, uint32_t ts_ev, void *data);
1660void gsm_trx_all_ts_dispatch(struct gsm_bts_trx *trx, uint32_t ts_ev, void *data);
1661
1662int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001663
Philipp Maier89d72d82018-11-05 15:28:38 +01001664struct osmo_cell_global_id *cgi_for_msc(struct bsc_msc_data *msc, struct gsm_bts *bts);
1665
Harald Welte6be350c2011-05-25 13:10:08 +02001666#endif /* _GSM_DATA_H */