blob: 47ca5e8391b5ccf13a82dac5883a75ba10fa787f [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;
Neels Hofmeyr19bed232018-03-22 04:54:57 +010041struct gsm0808_cell_id;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020042struct mgw_endpoint;
Philipp Maier39f62bb2017-04-09 12:32:51 +020043
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020044/** annotations for msgb ownership */
45#define __uses
46
Holger Hans Peter Freyther6f615552010-11-15 20:50:42 +010047#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
48
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010049struct bsc_subscr;
Neels Hofmeyr7b656882017-07-09 22:09:18 +020050struct gprs_ra_id;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020051struct handover;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020052
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080053#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
54
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010055#define tmsi_from_string(str) strtoul(str, NULL, 10)
56
Max70fdd242017-06-15 15:10:53 +020057/* 3-bit long values */
58#define EARFCN_PRIO_INVALID 8
59#define EARFCN_MEAS_BW_INVALID 8
60/* 5-bit long values */
61#define EARFCN_QRXLV_INVALID 32
62#define EARFCN_THRESH_LOW_INVALID 32
63
Harald Welte8e1e3ee2009-02-01 13:32:45 +000064struct msgb;
65typedef int gsm_cbfn(unsigned int hooknum,
66 unsigned int event,
67 struct msgb *msg,
68 void *data, void *param);
69
Harald Weltef7c28b02009-12-21 13:30:17 +010070/* Maximum number of neighbor cells whose average we track */
71#define MAX_NEIGH_MEAS 10
72/* Maximum size of the averaging window for neighbor cells */
73#define MAX_WIN_NEIGH_AVG 10
Andreas Eversberg98692032013-06-23 10:44:34 +020074/* Maximum number of report history we store */
75#define MAX_MEAS_REP 10
Harald Weltef7c28b02009-12-21 13:30:17 +010076
77/* processed neighbor measurements for one cell */
78struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020079 uint16_t arfcn;
80 uint8_t bsic;
81 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +010082 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020083 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +010084};
85
Harald Weltea43e0b42016-06-19 18:06:02 +020086struct gsm_classmark {
87 bool classmark1_set;
88 struct gsm48_classmark1 classmark1;
89 uint8_t classmark2_len;
90 uint8_t classmark2[3];
91 uint8_t classmark3_len;
92 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
93};
94
Harald Welte519c7e12018-01-28 02:45:46 +010095enum subscr_sccp_state {
96 SUBSCR_SCCP_ST_NONE,
97 SUBSCR_SCCP_ST_WAIT_CONN_CONF,
98 SUBSCR_SCCP_ST_CONNECTED
99};
100
Philipp Maierbb66d102019-01-22 11:29:06 +0100101struct channel_mode_and_rate {
102 enum gsm48_chan_mode chan_mode;
Neels Hofmeyr0848ff82019-03-14 22:11:45 +0000103 bool full_rate;
Philipp Maierbb66d102019-01-22 11:29:06 +0100104 uint16_t s15_s0;
105};
106
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100107/* Information retrieved during an Assignment Request from the MSC. This is storage of the Assignment instructions
108 * parsed from the Assignment Request message, to pass on until the gscon and assignment FSMs have decided whether an
109 * Assignment is actually going to be carried out. Should remain unchanged after initial decoding. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200110struct assignment_request {
111 bool aoip;
112
113 uint16_t msc_assigned_cic;
114
115 char msc_rtp_addr[INET_ADDRSTRLEN];
116 uint16_t msc_rtp_port;
117
Neels Hofmeyr0848ff82019-03-14 22:11:45 +0000118 /* Prefered rate/codec setting (mandatory) */
119 struct channel_mode_and_rate ch_mode_rate_pref;
120
121 /* Alternate rate/codec setting (optional) */
122 bool ch_mode_rate_alt_present;
123 struct channel_mode_and_rate ch_mode_rate_alt;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200124};
125
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100126/* State of an ongoing Assignment, while the assignment_fsm is still busy. This serves as state separation to keep the
127 * currently used lchan and gscon unmodified until the outcome of an Assignment is known. If the Assignment fails, this
128 * state is simply discarded, and the gscon carries on with the original lchan remaining unchanged. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200129struct assignment_fsm_data {
130 struct assignment_request req;
131 bool requires_voice_stream;
132
133 struct osmo_fsm_inst *fi;
134 struct gsm_lchan *new_lchan;
135
136 /* Whether this assignment triggered creation of the MGW endpoint: if the assignment
137 * fails, we will release that again as soon as possible. (If false, the endpoint already
138 * existed before or isn't needed at all.)*/
139 struct mgwep_ci *created_ci_for_msc;
140
141 enum gsm0808_cause failure_cause;
142 enum gsm48_rr_cause rr_cause;
143
144 bool result_rate_ctr_done;
145};
146
147enum hodec_id {
148 HODEC_NONE,
149 HODEC1 = 1,
150 HODEC2 = 2,
151 HODEC_USER,
152 HODEC_REMOTE,
153};
154
155/* For example, to count specific kinds of ongoing handovers, it is useful to be able to OR-combine
156 * scopes. */
157enum handover_scope {
158 HO_NO_HANDOVER = 0,
159 HO_INTRA_CELL = 0x1,
160 HO_INTRA_BSC = 0x2,
161 HO_INTER_BSC_OUT = 0x4,
162 HO_INTER_BSC_IN = 0x8,
163 HO_SCOPE_ALL = 0xffff,
164};
165
166extern const struct value_string handover_scope_names[];
167inline static const char *handover_scope_name(enum handover_scope val)
168{ return get_value_string(handover_scope_names, val); }
169
170struct handover_out_req {
171 enum hodec_id from_hodec_id;
172 struct gsm_lchan *old_lchan;
173 struct neighbor_ident_key target_nik;
174 enum gsm_chan_t new_lchan_type; /*< leave GSM_LCHAN_NONE to use same as old_lchan */
175};
176
177struct handover_in_req {
178 struct gsm0808_channel_type ct;
179 struct gsm0808_speech_codec_list scl;
180 struct gsm0808_encrypt_info ei;
181 struct gsm_classmark classmark;
182 struct gsm0808_cell_id cell_id_serving;
183 char cell_id_serving_name[64];
184 struct gsm0808_cell_id cell_id_target;
185 char cell_id_target_name[64];
186 uint16_t msc_assigned_cic;
187 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
188 uint16_t msc_assigned_rtp_port;
189};
190
191struct handover {
192 struct osmo_fsm_inst *fi;
193
194 enum hodec_id from_hodec_id;
195 enum handover_scope scope;
196 enum gsm_chan_t new_lchan_type;
197 struct neighbor_ident_key target_cell;
198
199 uint8_t ho_ref;
200 struct gsm_bts *new_bts;
201 struct gsm_lchan *new_lchan;
202 bool async;
203 struct handover_in_req inter_bsc_in;
204 struct mgwep_ci *created_ci_for_msc;
205};
206
Neels Hofmeyr378a4922016-05-09 21:07:43 +0200207/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100208struct gsm_subscriber_connection {
Harald Weltea43e0b42016-06-19 18:06:02 +0200209 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +0800210 struct llist_head entry;
211
Harald Welte3561bd42018-01-28 03:04:16 +0100212 /* FSM instance to control the subscriber connection state (RTP, A) */
213 struct osmo_fsm_inst *fi;
214
Harald Weltea43e0b42016-06-19 18:06:02 +0200215 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100216 struct bsc_subscr *bsub;
217
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100218 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200219 struct gsm_network *network;
220
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100221 /* the primary / currently active lchan to the BTS/subscriber. During Assignment and Handover, separate lchans
222 * are kept in the .assignment or .handover sub-structs, respectively, so that this lchan remains unaffected
223 * until Assignment or Handover have actually succeeded. */
Harald Welte4a8ebc82017-12-18 18:34:41 +0100224 struct gsm_lchan *lchan;
Harald Welte3561bd42018-01-28 03:04:16 +0100225
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100226 /* Only valid during an ongoing Assignment; might be overwritten at any time by a failed Assignment attempt.
227 * Once an Assignment was successful, all relevant state must be copied out of this sub-struct. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200228 struct assignment_fsm_data assignment;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100229
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100230 /* handover information, if a handover is pending for this conn. Valid only during an ongoing Handover
231 * operation. If a Handover was successful, all relevant state must be copied out of this sub-struct. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200232 struct handover ho;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100233
Harald Welte4a8ebc82017-12-18 18:34:41 +0100234 /* buffer/cache for classmark of the ME of the subscriber */
Harald Weltea43e0b42016-06-19 18:06:02 +0200235 struct gsm_classmark classmark;
Andreas Eversberg935e5d72013-06-17 11:58:30 +0200236
Neels Hofmeyr149160f2018-06-16 17:20:13 +0200237 /* Queue DTAP messages during handover/assignment (msgb_enqueue()/msgb_dequeue())*/
238 struct llist_head dtap_queue;
239 unsigned int dtap_queue_len;
Andreas Eversberg084b4212013-05-30 14:12:48 +0200240
Neels Hofmeyrec422642018-02-15 14:07:40 +0100241 struct {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100242 int failures;
Neels Hofmeyrec422642018-02-15 14:07:40 +0100243 struct penalty_timers *penalty_timers;
244 } hodec2;
Neels Hofmeyra60f3442018-02-12 16:44:32 +0100245
246 /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment Request. 3GPP 48.008
247 * 3.2.2.103 says:
248 * The "Codec List (MSC Preferred)" shall not include codecs
249 * that are not supported by the MS.
250 * i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed the MS bearer
251 * capabilities, which the MSC is required to translate into the codec list. */
252 struct gsm0808_speech_codec_list codec_list;
Harald Welte519c7e12018-01-28 02:45:46 +0100253
254 /* flag to prevent multiple simultaneous ciphering commands */
255 int ciphering_handled;
256
257 /* state related to welcome USSD */
258 uint8_t new_subscriber;
259
260 /* state related to osmo_bsc_filter.c */
261 struct bsc_filter_state filter_state;
262
263 /* SCCP connection associatd with this subscriber_connection */
264 struct {
265 /* for advanced ping/pong */
266 int send_ping;
267
268 /* SCCP connection realted */
269 struct bsc_msc_data *msc;
270
271 /* Sigtran connection ID */
272 int conn_id;
273 enum subscr_sccp_state state;
274 } sccp;
275
276 /* for audio handling */
277 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200278 uint16_t msc_assigned_cic;
Harald Welte519c7e12018-01-28 02:45:46 +0100279
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200280 /* RTP address where the MSC expects us to send the RTP stream coming from the BTS. */
281 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
282 uint16_t msc_assigned_rtp_port;
Harald Welte519c7e12018-01-28 02:45:46 +0100283
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200284 /* The endpoint at the MGW used to join both BTS and MSC side connections, e.g.
285 * "rtpbridge/23@mgw". */
286 struct mgw_endpoint *mgw_endpoint;
Harald Welte3561bd42018-01-28 03:04:16 +0100287
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200288 /* The connection identifier of the mgw_endpoint used to transceive RTP towards the MSC.
289 * (The BTS side CI is handled by struct gsm_lchan and the lchan_fsm.) */
290 struct mgwep_ci *mgw_endpoint_ci_msc;
Harald Welte519c7e12018-01-28 02:45:46 +0100291 } user_plane;
Harald Weltec997ceb2018-05-30 01:39:43 +0200292
293 /* LCLS (local call, local switch) related state */
294 struct {
295 uint8_t global_call_ref[15];
296 uint8_t global_call_ref_len; /* length of global_call_ref */
Maxfe65ece2018-11-09 13:36:11 +0100297 enum gsm0808_lcls_config config; /* TS 48.008 3.2.2.116 */
298 enum gsm0808_lcls_control control; /* TS 48.008 3.2.2.117 */
Harald Weltec997ceb2018-05-30 01:39:43 +0200299 /* LCLS FSM */
300 struct osmo_fsm_inst *fi;
301 /* pointer to "other" connection, if Call Leg Relocation was successful */
302 struct gsm_subscriber_connection *other;
303 } lcls;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100304};
305
Harald Weltef142c972011-05-24 13:25:38 +0200306
Neels Hofmeyr10485162018-02-13 23:22:03 +0100307/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 Table 10.5.2.33b.1:
308 4-bit index is used (2#1111 = 10#15) */
309#define SI2Q_MAX_NUM 16
310/* length in bits (for single SI2quater message) */
311#define SI2Q_MAX_LEN 160
312#define SI2Q_MIN_LEN 18
313
314struct osmo_bsc_data;
315
316struct osmo_bsc_sccp_con;
317
318/* Channel Request reason */
319enum gsm_chreq_reason_t {
320 GSM_CHREQ_REASON_EMERG,
321 GSM_CHREQ_REASON_PAG,
322 GSM_CHREQ_REASON_CALL,
323 GSM_CHREQ_REASON_LOCATION_UPD,
324 GSM_CHREQ_REASON_OTHER,
325 GSM_CHREQ_REASON_PDCH,
326};
327
328/* lchans 0..3 are SDCCH in combined channel configuration,
329 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
330#define CCCH_LCHAN 4
331
332#define TRX_NR_TS 8
333#define TS_MAX_LCHAN 8
334
335#define HARDCODED_ARFCN 123
336#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
337
338/* for multi-drop config */
339#define HARDCODED_BTS0_TS 1
340#define HARDCODED_BTS1_TS 6
341#define HARDCODED_BTS2_TS 11
342
343#define MAX_VERSION_LENGTH 64
344
Neels Hofmeyr10485162018-02-13 23:22:03 +0100345enum gsm_hooks {
346 GSM_HOOK_NM_SWLOAD,
347 GSM_HOOK_RR_PAGING,
348 GSM_HOOK_RR_SECURITY,
349};
350
Neels Hofmeyr10485162018-02-13 23:22:03 +0100351enum bts_gprs_mode {
352 BTS_GPRS_NONE = 0,
353 BTS_GPRS_GPRS = 1,
354 BTS_GPRS_EGPRS = 2,
355};
356
357struct gsm_lchan;
358struct osmo_rtp_socket;
359struct rtp_socket;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100360
361/* Network Management State */
362struct gsm_nm_state {
363 uint8_t operational;
364 uint8_t administrative;
365 uint8_t availability;
366};
367
368struct gsm_abis_mo {
369 uint8_t obj_class;
370 uint8_t procedure_pending;
371 struct abis_om_obj_inst obj_inst;
372 const char *name;
373 struct gsm_nm_state nm_state;
374 struct tlv_parsed *nm_attr;
375 struct gsm_bts *bts;
376};
377
378/* Ericsson OM2000 Managed Object */
379struct abis_om2k_mo {
380 uint8_t class;
381 uint8_t bts;
382 uint8_t assoc_so;
383 uint8_t inst;
384} __attribute__ ((packed));
385
386struct om2k_mo {
387 struct abis_om2k_mo addr;
388 struct osmo_fsm_inst *fsm;
389};
390
391#define A38_XOR_MIN_KEY_LEN 12
392#define A38_XOR_MAX_KEY_LEN 16
393#define A38_COMP128_KEY_LEN 16
394#define RSL_ENC_ALG_A5(x) (x+1)
395#define MAX_EARFCN_LIST 32
396
397/* is the data link established? who established it? */
398#define LCHAN_SAPI_UNUSED 0
399#define LCHAN_SAPI_MS 1
400#define LCHAN_SAPI_NET 2
Neels Hofmeyr10485162018-02-13 23:22:03 +0100401
402/* BTS ONLY */
403#define MAX_NUM_UL_MEAS 104
404#define LC_UL_M_F_L1_VALID (1 << 0)
405#define LC_UL_M_F_RES_VALID (1 << 1)
406
407struct bts_ul_meas {
408 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
409 uint16_t ber10k;
410 /* timing advance offset (in quarter bits) */
411 int16_t ta_offs_qbits;
412 /* C/I ratio in dB */
413 float c_i;
414 /* flags */
415 uint8_t is_sub:1;
416 /* RSSI in dBm * -1 */
417 uint8_t inv_rssi;
418};
419
420struct bts_codec_conf {
421 uint8_t hr;
422 uint8_t efr;
423 uint8_t amr;
424};
425
426struct amr_mode {
427 uint8_t mode;
428 uint8_t threshold;
429 uint8_t hysteresis;
430};
431
432struct amr_multirate_conf {
433 uint8_t gsm48_ie[2];
434 struct amr_mode ms_mode[4];
435 struct amr_mode bts_mode[4];
436 uint8_t num_modes;
437};
438/* /BTS ONLY */
439
440enum lchan_csd_mode {
441 LCHAN_CSD_M_NT,
442 LCHAN_CSD_M_T_1200_75,
443 LCHAN_CSD_M_T_600,
444 LCHAN_CSD_M_T_1200,
445 LCHAN_CSD_M_T_2400,
446 LCHAN_CSD_M_T_9600,
447 LCHAN_CSD_M_T_14400,
448 LCHAN_CSD_M_T_29000,
449 LCHAN_CSD_M_T_32000,
450};
451
452/* State of the SAPIs in the lchan */
453enum lchan_sapi_state {
454 LCHAN_SAPI_S_NONE,
455 LCHAN_SAPI_S_REQ,
456 LCHAN_SAPI_S_ASSIGNED,
457 LCHAN_SAPI_S_REL,
458 LCHAN_SAPI_S_ERROR,
459};
460
Neels Hofmeyr92b9f2e2018-02-14 00:19:11 +0100461#define MAX_A5_KEY_LEN (128/8)
462
463struct gsm_encr {
464 uint8_t alg_id;
465 uint8_t key_len;
466 uint8_t key[MAX_A5_KEY_LEN];
467};
468
Neels Hofmeyr8da22332018-04-11 01:43:41 +0200469#define LOGPLCHAN(lchan, ss, level, fmt, args...) \
470 LOGP(ss, level, "%s (ss=%d,%s) (%s) " fmt, \
471 lchan ? gsm_ts_and_pchan_name(lchan->ts) : "-", \
472 lchan ? lchan->nr : 0, \
473 lchan ? gsm_lchant_name(lchan->type) : "-", \
474 bsc_subscr_name(lchan && lchan->conn ? lchan->conn->bsub : NULL), \
475 ## args)
476
Pau Espin Pedrold3e8e0c2018-11-28 16:35:10 +0100477/* Iterate lchans that have an FSM allocated based based on explicit pchan kind
478 * (GSM_PCHAN_* constant).
479 * Remark: PDCH related lchans are not handled in BSC but in PCU, so trying to
480 * iterate through GSM_PCHAN_PDCH is considered a void loop.
481 */
482#define ts_as_pchan_for_each_lchan(lchan, ts, as_pchan) \
483 for (lchan = (ts)->lchan; \
484 ((lchan - (ts)->lchan) < ARRAY_SIZE((ts)->lchan)) \
485 && lchan->fi \
486 && lchan->nr < pchan_subslots(as_pchan); \
487 lchan++)
488
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100489/* Iterate lchans that have an FSM allocated based on current PCHAN
490 * mode set in \ref ts.
491 * usage:
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200492 * struct gsm_lchan *lchan;
493 * struct gsm_bts_trx_ts *ts = get_some_timeslot();
494 * ts_for_each_lchan(lchan, ts) {
495 * LOGPLCHAN(DMAIN, LOGL_DEBUG, "hello world\n");
496 * }
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100497 */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200498#define ts_for_each_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_is)
499
Pau Espin Pedrol0ba20df2018-11-28 16:39:29 +0100500/* Iterate over all possible lchans available that have an FSM allocated based
501 * on PCHAN \ref ts (dynamic) configuration.
502 * Iterate all lchan instances set up by this \ref ts type, including those
503 * lchans currently disabled or in process of being enabled (e.g. due to dynamic
504 * timeslot in switchover). Compare ts_for_each_lchan(), which iterates only the
505 * enabled lchans.
506 * For example, it is useful in case dynamic timeslot \ref ts is in process of
507 * switching from configuration PDCH (no lchans) to TCH_F (1 lchan), where
508 * pchan_is is still set to PDCH but \ref ts may contain already an \ref lchan
509 * of type TCH_F which initiated the request to switch the \ts configuration.
510 */
511#define ts_for_each_potential_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_on_init)
512
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200513enum lchan_activate_mode {
514 FOR_NONE,
515 FOR_MS_CHANNEL_REQUEST,
516 FOR_ASSIGNMENT,
517 FOR_HANDOVER,
518 FOR_VTY,
519};
520
521extern const struct value_string lchan_activate_mode_names[];
522static inline const char *lchan_activate_mode_name(enum lchan_activate_mode activ_for)
523{ return get_value_string(lchan_activate_mode_names, activ_for); }
524
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100525struct lchan_activate_info {
526 enum lchan_activate_mode activ_for;
527 struct gsm_subscriber_connection *for_conn;
528 /* This always is for a specific lchan, so its lchan->type indicates full or half rate.
529 * When a dyn TS was selected, the lchan->type has been set to the desired rate. */
530 enum gsm48_chan_mode chan_mode;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100531 /* AMR config */
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100532 uint16_t s15_s0;
533 bool requires_voice_stream;
534 bool wait_before_switching_rtp; /*< true = requires LCHAN_EV_READY_TO_SWITCH_RTP */
535 uint16_t msc_assigned_cic;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100536 /* During intra-BSC handover, we keep the MGW endpoint intact and just re-route to the new lchan. This
537 * 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 +0100538 struct gsm_lchan *re_use_mgw_endpoint_from_lchan;
539};
540
Neels Hofmeyr10485162018-02-13 23:22:03 +0100541struct gsm_lchan {
542 /* The TS that we're part of */
543 struct gsm_bts_trx_ts *ts;
544 /* The logical subslot number in the TS */
545 uint8_t nr;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200546 char *name;
547
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100548 char *last_error;
549
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200550 struct osmo_fsm_inst *fi;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200551 struct osmo_fsm_inst *fi_rtp;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200552 struct mgwep_ci *mgw_endpoint_ci_bts;
553
554 struct {
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100555 struct lchan_activate_info info;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200556 bool activ_ack; /*< true as soon as RSL Chan Activ Ack is received */
Neels Hofmeyr369fba22018-11-27 01:30:50 +0100557 bool immediate_assignment_sent;
Neels Hofmeyr193c1e32018-08-27 22:06:24 +0200558 /*! This flag ensures that when an lchan activation has succeeded, and we have already
559 * sent ACKs like Immediate Assignment or BSSMAP Assignment Complete, and if other errors
560 * occur later, e.g. during release, that we don't send a NACK out of context. */
561 bool concluded;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200562 enum gsm0808_cause gsm0808_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200563 } activate;
564
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100565 struct {
566 /* If an event to release the lchan comes in while still waiting for responses, just mark this
567 * flag, so that the lchan will gracefully release at the next sensible junction. */
568 bool requested;
569 bool do_rr_release;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200570
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100571 /* There is an RSL error cause of value 0, so we need a separate flag. */
572 bool in_error;
573 /* RSL error code, RSL_ERR_* */
574 uint8_t rsl_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200575
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100576 /* If a release event is being handled, ignore other ricocheting release events until that
577 * release handling has concluded. */
578 bool in_release_handler;
Harald Welte963763d2019-02-03 12:11:12 +0100579
580 /* is this release at the end of a CSFB call? */
581 bool is_csfb;
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100582 } release;
Neels Hofmeyrd5df9a12018-07-20 05:35:47 +0200583
Neels Hofmeyr10485162018-02-13 23:22:03 +0100584 /* The logical channel type */
585 enum gsm_chan_t type;
586 /* RSL channel mode */
587 enum rsl_cmod_spd rsl_cmode;
588 /* If TCH, traffic channel mode */
589 enum gsm48_chan_mode tch_mode;
590 enum lchan_csd_mode csd_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100591 /* Power levels for MS and BTS */
592 uint8_t bs_power;
593 uint8_t ms_power;
594 /* Encryption information */
595 struct gsm_encr encr;
596
597 /* AMR bits */
598 uint8_t mr_ms_lv[7];
599 uint8_t mr_bts_lv[7];
Neels Hofmeyr4daa2102019-01-30 16:46:58 +0100600 /* AMR bits were based on these rate bits: */
601 uint16_t s15_s0;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100602
603 /* Established data link layer services */
604 uint8_t sapis[8];
605
606 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200607 uint32_t bound_ip; /*< where the BTS receives RTP */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100608 uint16_t bound_port;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200609 uint32_t connect_ip; /*< where the BTS sends RTP to (MGW) */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100610 uint16_t connect_port;
611 uint16_t conn_id;
612 uint8_t rtp_payload;
613 uint8_t rtp_payload2;
614 uint8_t speech_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100615
616 /* info we need to postpone the AoIP
617 * assignment completed message */
618 struct {
619 uint8_t rr_cause;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100620 bool valid;
621 } ass_compl;
622 } abis_ip;
623
624 uint8_t rqd_ta;
625
Neels Hofmeyr10485162018-02-13 23:22:03 +0100626 /* table of neighbor cell measurements */
627 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
628
629 /* cache of last measurement reports on this lchan */
630 struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
631 int meas_rep_idx;
632 int meas_rep_count;
Neels Hofmeyr35ba85c2018-02-12 16:47:40 +0100633 uint8_t meas_rep_last_seen_nr;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100634
635 /* GSM Random Access data */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200636 /* TODO: don't allocate this, rather keep an "is_present" flag */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100637 struct gsm48_req_ref *rqd_ref;
638
639 struct gsm_subscriber_connection *conn;
Philipp Maierbb66d102019-01-22 11:29:06 +0100640
641 /* Depending on the preferences that where submitted together with
642 * the assignment and the current channel load, the BSC has to select
643 * one of the offered codec/rates. The final selection by the BSC is
644 * stored here and is used when sending the assignment complete or
645 * when performing a handover procedure. */
646 struct channel_mode_and_rate ch_mode_rate;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100647};
648
Neels Hofmeyr10485162018-02-13 23:22:03 +0100649/* One Timeslot in a TRX */
650struct gsm_bts_trx_ts {
651 struct gsm_bts_trx *trx;
652 /* number of this timeslot at the TRX */
653 uint8_t nr;
654
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200655 struct osmo_fsm_inst *fi;
656 char *last_errmsg;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100657
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200658 /* vty phys_chan_config setting, not necessarily in effect in case it was changed in the telnet
659 * vty after OML activation. Gets written on vty 'write file'. */
660 enum gsm_phys_chan_config pchan_from_config;
661 /* When the timeslot OML is established, pchan_from_config is copied here. This is the pchan
662 * currently in effect; for dynamic ts, this is the dyn kind (GSM_PCHAN_TCH_F_TCH_H_PDCH or
663 * GSM_PCHAN_TCH_F_PDCH) and does not show the pchan type currently active. */
664 enum gsm_phys_chan_config pchan_on_init;
665 /* This is the *actual* pchan type currently active. For dynamic timeslots, this reflects either
666 * GSM_PCHAN_NONE or one of the standard GSM_PCHAN_TCH_F, GSM_PCHAN_TCH_H, GSM_PCHAN_PDCH.
667 * Callers can use this transparently without being aware of dyn ts. */
668 enum gsm_phys_chan_config pchan_is;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100669
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200670 /* After a PDCH ACT NACK, we shall not infinitely loop to try and ACT again.
671 * Also marks a timeslot where PDCH was deactivated by VTY. This is cleared whenever a timeslot
672 * enters IN_USE state, i.e. after each TCH use we try to PDCH ACT once again. */
673 bool pdch_act_allowed;
674
Neels Hofmeyrbcdbfb72018-07-26 20:33:15 +0200675 /* Whether TS_EV_OML_READY was received */
676 bool is_oml_ready;
677 /* Whether TS_EV_RSL_READY was received */
678 bool is_rsl_ready;
679
Neels Hofmeyr10485162018-02-13 23:22:03 +0100680 struct gsm_abis_mo mo;
681 struct tlv_parsed nm_attr;
682 uint8_t nm_chan_comb;
683 int tsc; /* -1 == use BTS TSC */
684
685 struct {
686 /* Parameters below are configured by VTY */
687 int enabled;
688 uint8_t maio;
689 uint8_t hsn;
690 struct bitvec arfcns;
691 uint8_t arfcns_data[1024/8];
692 /* This is the pre-computed MA for channel assignments */
693 struct bitvec ma;
694 uint8_t ma_len; /* part of ma_data that is used */
695 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
696 } hopping;
697
698 /* To which E1 subslot are we connected */
699 struct gsm_e1_subslot e1_link;
700
701 union {
702 struct {
703 struct om2k_mo om2k_mo;
704 } rbs2000;
705 };
706
707 struct gsm_lchan lchan[TS_MAX_LCHAN];
708};
709
710/* One TRX in a BTS */
711struct gsm_bts_trx {
712 /* list header in bts->trx_list */
713 struct llist_head list;
714
715 struct gsm_bts *bts;
716 /* number of this TRX in the BTS */
717 uint8_t nr;
718 /* human readable name / description */
719 char *description;
720 /* how do we talk RSL with this TRX? */
721 struct gsm_e1_subslot rsl_e1_link;
722 uint8_t rsl_tei;
723 struct e1inp_sign_link *rsl_link;
724
725 /* Timeout for initiating the RSL connection. */
726 struct osmo_timer_list rsl_connect_timeout;
727
728 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
729 struct e1inp_sign_link *oml_link;
730
731 struct gsm_abis_mo mo;
732 struct tlv_parsed nm_attr;
733 struct {
734 struct gsm_abis_mo mo;
735 } bb_transc;
736
737 uint16_t arfcn;
738 int nominal_power; /* in dBm */
739 unsigned int max_power_red; /* in actual dB */
740
741 union {
742 struct {
743 struct {
744 struct gsm_abis_mo mo;
745 } bbsig;
746 struct {
747 struct gsm_abis_mo mo;
748 } pa;
749 } bs11;
750 struct {
751 unsigned int test_state;
752 uint8_t test_nr;
753 struct rxlev_stats rxlev_stat;
754 } ipaccess;
755 struct {
756 struct {
757 struct om2k_mo om2k_mo;
758 } trxc;
759 struct {
760 struct om2k_mo om2k_mo;
761 } rx;
762 struct {
763 struct om2k_mo om2k_mo;
764 } tx;
765 } rbs2000;
766 };
767 struct gsm_bts_trx_ts ts[TRX_NR_TS];
768};
769
770#define GSM_BTS_SI2Q(bts, i) (struct gsm48_system_information_type_2quater *)((bts)->si_buf[SYSINFO_TYPE_2quater][i])
771#define GSM_BTS_HAS_SI(bts, i) ((bts)->si_valid & (1 << i))
772#define GSM_BTS_SI(bts, i) (void *)((bts)->si_buf[i][0])
773#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
774
775enum gsm_bts_type {
776 GSM_BTS_TYPE_UNKNOWN,
777 GSM_BTS_TYPE_BS11,
778 GSM_BTS_TYPE_NANOBTS,
779 GSM_BTS_TYPE_RBS2000,
780 GSM_BTS_TYPE_NOKIA_SITE,
781 GSM_BTS_TYPE_OSMOBTS,
782 _NUM_GSM_BTS_TYPE
783};
784
785enum gsm_bts_type_variant {
786 BTS_UNKNOWN,
787 BTS_OSMO_LITECELL15,
788 BTS_OSMO_OCTPHY,
789 BTS_OSMO_SYSMO,
790 BTS_OSMO_TRX,
791 _NUM_BTS_VARIANT
792};
793
794/* Used by OML layer for BTS Attribute reporting */
795enum bts_attribute {
796 BTS_TYPE_VARIANT,
797 BTS_SUB_MODEL,
798 TRX_PHY_VERSION,
799};
800
801struct vty;
802
803struct gsm_bts_model {
804 struct llist_head list;
805
806 enum gsm_bts_type type;
807 enum gsm_bts_type_variant variant;
808 const char *name;
809
810 bool started;
811 int (*start)(struct gsm_network *net);
812 int (*oml_rcvmsg)(struct msgb *msg);
813 char * (*oml_status)(const struct gsm_bts *bts);
814
815 void (*e1line_bind_ops)(struct e1inp_line *line);
816
817 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
818 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
819 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
820
Pau Espin Pedrol167cb822018-11-19 17:48:17 +0100821 /* Should SI2bis and SI2ter be disabled by default on this BTS model? */
822 bool force_combined_si;
823
Neels Hofmeyr10485162018-02-13 23:22:03 +0100824 struct tlv_definition nm_att_tlvdef;
825
826 /* features of a given BTS model set via gsm_bts_model_register() locally */
827 struct bitvec features;
828 uint8_t _features_data[MAX_BTS_FEATURES/8];
829};
830
Neels Hofmeyr10485162018-02-13 23:22:03 +0100831
Neels Hofmeyr10485162018-02-13 23:22:03 +0100832
833/*
834 * This keeps track of the paging status of one BTS. It
835 * includes a number of pending requests, a back pointer
836 * to the gsm_bts, a timer and some more state.
837 */
838struct gsm_bts_paging_state {
839 /* pending requests */
840 struct llist_head pending_requests;
841 struct gsm_bts *bts;
842
843 struct osmo_timer_list work_timer;
844 struct osmo_timer_list credit_timer;
845
846 /* free chans needed */
847 int free_chans_need;
848
849 /* load */
850 uint16_t available_slots;
851};
852
853struct gsm_envabtse {
854 struct gsm_abis_mo mo;
855};
856
857struct gsm_bts_gprs_nsvc {
858 struct gsm_bts *bts;
859 /* data read via VTY config file, to configure the BTS
860 * via OML from BSC */
861 int id;
862 uint16_t nsvci;
863 uint16_t local_port; /* on the BTS */
864 uint16_t remote_port; /* on the SGSN */
865 uint32_t remote_ip; /* on the SGSN */
866
867 struct gsm_abis_mo mo;
868};
869
870enum gprs_rlc_par {
871 RLC_T3142,
872 RLC_T3169,
873 RLC_T3191,
874 RLC_T3193,
875 RLC_T3195,
876 RLC_N3101,
877 RLC_N3103,
878 RLC_N3105,
879 CV_COUNTDOWN,
880 T_DL_TBF_EXT, /* ms */
881 T_UL_TBF_EXT, /* ms */
882 _NUM_RLC_PAR
883};
884
885enum gprs_cs {
886 GPRS_CS1,
887 GPRS_CS2,
888 GPRS_CS3,
889 GPRS_CS4,
890 GPRS_MCS1,
891 GPRS_MCS2,
892 GPRS_MCS3,
893 GPRS_MCS4,
894 GPRS_MCS5,
895 GPRS_MCS6,
896 GPRS_MCS7,
897 GPRS_MCS8,
898 GPRS_MCS9,
899 _NUM_GRPS_CS
900};
901
902struct gprs_rlc_cfg {
903 uint16_t parameter[_NUM_RLC_PAR];
904 struct {
905 uint16_t repeat_time; /* ms */
906 uint8_t repeat_count;
907 } paging;
908 uint32_t cs_mask; /* bitmask of gprs_cs */
909 uint8_t initial_cs;
910 uint8_t initial_mcs;
911};
912
913
914enum neigh_list_manual_mode {
915 NL_MODE_AUTOMATIC = 0,
916 NL_MODE_MANUAL = 1,
917 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
918};
919
920enum bts_loc_fix {
921 BTS_LOC_FIX_INVALID = 0,
922 BTS_LOC_FIX_2D = 1,
923 BTS_LOC_FIX_3D = 2,
924};
925
926extern const struct value_string bts_loc_fix_names[];
927
928struct bts_location {
929 struct llist_head list;
930 time_t tstamp;
931 enum bts_loc_fix valid;
932 double lat;
933 double lon;
934 double height;
935};
936
937/* Channel load counter */
938struct load_counter {
939 unsigned int total;
940 unsigned int used;
941};
942
Neels Hofmeyr19bed232018-03-22 04:54:57 +0100943/* Useful to track N-N relations between BTS, for example neighbors. */
944struct gsm_bts_ref {
945 struct llist_head entry;
946 struct gsm_bts *bts;
947};
948
Neels Hofmeyr10485162018-02-13 23:22:03 +0100949/* One BTS */
950struct gsm_bts {
951 /* list header in net->bts_list */
952 struct llist_head list;
953
954 /* Geographical location of the BTS */
955 struct llist_head loc_list;
956
957 /* number of ths BTS in network */
958 uint8_t nr;
959 /* human readable name / description */
960 char *description;
961 /* Cell Identity */
962 uint16_t cell_identity;
963 /* location area code of this BTS */
964 uint16_t location_area_code;
965 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
966 * which is used as TSC for the CCCH */
967 uint8_t bsic;
968 /* type of BTS */
969 enum gsm_bts_type type;
970 enum gsm_bts_type_variant variant;
971 struct gsm_bts_model *model;
972 enum gsm_band band;
973 char version[MAX_VERSION_LENGTH];
974 char sub_model[MAX_VERSION_LENGTH];
975
976 /* features of a given BTS set/reported via OML */
977 struct bitvec features;
978 uint8_t _features_data[MAX_BTS_FEATURES/8];
979
980 /* Connected PCU version (if any) */
981 char pcu_version[MAX_VERSION_LENGTH];
982
983 /* maximum Tx power that the MS is permitted to use in this cell */
984 int ms_max_power;
985
986 /* how do we talk OML with this TRX? */
987 struct gsm_e1_subslot oml_e1_link;
988 uint8_t oml_tei;
989 struct e1inp_sign_link *oml_link;
Pau Espin Pedrol9862bcb2018-08-22 21:54:12 +0200990 /* Timer to use for deferred drop of OML link, see \ref ipaccess_drop_oml_deferred */
991 struct osmo_timer_list oml_drop_link_timer;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100992 /* when OML link was established */
993 time_t uptime;
994
995 /* Abis network management O&M handle */
996 struct abis_nm_h *nmh;
997
998 struct gsm_abis_mo mo;
999
1000 /* number of this BTS on given E1 link */
1001 uint8_t bts_nr;
1002
1003 /* DTX features of this BTS */
1004 enum gsm48_dtx_mode dtxu;
1005 bool dtxd;
1006
1007 /* paging state and control */
1008 struct gsm_bts_paging_state paging;
1009
1010 /* CCCH is on C0 */
1011 struct gsm_bts_trx *c0;
1012
1013 struct {
1014 struct gsm_abis_mo mo;
1015 } site_mgr;
1016
1017 /* bitmask of all SI that are present/valid in si_buf */
1018 uint32_t si_valid;
1019 /* 3GPP TS 44.018 Table 10.5.2.33b.1 INDEX and COUNT for SI2quater */
1020 uint8_t si2q_index; /* distinguish individual SI2quater messages */
1021 uint8_t si2q_count; /* si2q_index for the last (highest indexed) individual SI2quater message */
1022 /* buffers where we put the pre-computed SI */
1023 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
1024 /* offsets used while generating SI2quater */
1025 size_t e_offset;
1026 size_t u_offset;
Pau Espin Pedrol1cf21de2018-12-05 13:38:10 +01001027 /* 3GPP TS 08.58 §8.5.1 BCCH INFORMATION. Some nanoBTS fail upon
1028 * receival of empty SI disabling unsupported SI. see OS#3707. */
1029 bool si_unused_send_empty;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001030
1031 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
1032 union {
1033 struct {
1034 uint16_t site_id;
1035 uint16_t bts_id;
1036 uint32_t flags;
1037 uint32_t rsl_ip;
1038 } ip_access;
1039 struct {
1040 struct {
1041 struct gsm_abis_mo mo;
1042 } cclk;
1043 struct {
1044 struct gsm_abis_mo mo;
1045 } rack;
1046 struct gsm_envabtse envabtse[4];
1047 } bs11;
1048 struct {
1049 struct {
1050 struct om2k_mo om2k_mo;
1051 struct gsm_abis_mo mo;
1052 struct llist_head conn_groups;
1053 } cf;
1054 struct {
1055 struct om2k_mo om2k_mo;
1056 struct gsm_abis_mo mo;
1057 struct llist_head conn_groups;
1058 } is;
1059 struct {
1060 struct om2k_mo om2k_mo;
1061 struct gsm_abis_mo mo;
1062 struct llist_head conn_groups;
1063 } con;
1064 struct {
1065 struct om2k_mo om2k_mo;
1066 struct gsm_abis_mo mo;
1067 } dp;
1068 struct {
1069 struct om2k_mo om2k_mo;
1070 struct gsm_abis_mo mo;
1071 } tf;
1072 uint32_t use_superchannel:1;
1073 } rbs2000;
1074 struct {
1075 uint8_t bts_type;
1076 unsigned int configured:1,
1077 skip_reset:1,
1078 no_loc_rel_cnf:1,
1079 bts_reset_timer_cnf,
1080 did_reset:1,
1081 wait_reset:1;
1082 struct osmo_timer_list reset_timer;
1083 } nokia;
1084 };
1085
1086 /* Not entirely sure how ip.access specific this is */
1087 struct {
1088 uint8_t supports_egprs_11bit_rach;
1089 enum bts_gprs_mode mode;
1090 struct {
1091 struct gsm_abis_mo mo;
1092 uint16_t nsei;
1093 uint8_t timer[7];
1094 } nse;
1095 struct {
1096 struct gsm_abis_mo mo;
1097 uint16_t bvci;
1098 uint8_t timer[11];
1099 struct gprs_rlc_cfg rlc_cfg;
1100 } cell;
1101 struct gsm_bts_gprs_nsvc nsvc[2];
1102 uint8_t rac;
1103 uint8_t net_ctrl_ord;
1104 bool ctrl_ack_type_use_block;
1105 } gprs;
1106
1107 /* RACH NM values */
1108 int rach_b_thresh;
1109 int rach_ldavg_slots;
1110
1111 /* transceivers */
1112 int num_trx;
1113 struct llist_head trx_list;
1114
1115 /* SI related items */
1116 int force_combined_si;
Pau Espin Pedrol167cb822018-11-19 17:48:17 +01001117 bool force_combined_si_set;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001118 int bcch_change_mark;
1119
1120 /* Abis NM queue */
1121 struct llist_head abis_queue;
1122 int abis_nm_pend;
1123
1124 struct gsm_network *network;
1125
1126 /* should the channel allocator allocate channels from high TRX to TRX0,
1127 * rather than starting from TRX0 and go upwards? */
1128 int chan_alloc_reverse;
1129
1130 enum neigh_list_manual_mode neigh_list_manual_mode;
1131 /* parameters from which we build SYSTEM INFORMATION */
1132 struct {
1133 struct gsm48_rach_control rach_control;
1134 uint8_t ncc_permitted;
1135 struct gsm48_cell_sel_par cell_sel_par;
1136 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
1137 struct gsm48_cell_options cell_options;
1138 struct gsm48_control_channel_descr chan_desc;
1139 struct bitvec neigh_list;
1140 struct bitvec cell_alloc;
1141 struct bitvec si5_neigh_list;
1142 struct osmo_earfcn_si2q si2quater_neigh_list;
1143 size_t uarfcn_length; /* index for uarfcn and scramble lists */
1144 struct {
1145 /* bitmask large enough for all possible ARFCN's */
1146 uint8_t neigh_list[1024/8];
1147 uint8_t cell_alloc[1024/8];
1148 /* If the user wants a different neighbor list in SI5 than in SI2 */
1149 uint8_t si5_neigh_list[1024/8];
1150 uint8_t meas_bw_list[MAX_EARFCN_LIST];
1151 uint16_t earfcn_list[MAX_EARFCN_LIST];
1152 uint16_t uarfcn_list[MAX_EARFCN_LIST];
1153 uint16_t scramble_list[MAX_EARFCN_LIST];
1154 } data;
1155 } si_common;
1156 bool early_classmark_allowed;
1157 bool early_classmark_allowed_3g;
1158 /* for testing only: Have an infinitely long radio link timeout */
1159 bool infinite_radio_link_timeout;
1160
1161 /* do we use static (user-defined) system information messages? (bitmask) */
1162 uint32_t si_mode_static;
1163
Stefan Sperling6442e432018-02-06 14:44:54 +01001164 /* access control class ramping */
1165 struct acc_ramp acc_ramp;
1166
Neels Hofmeyr10485162018-02-13 23:22:03 +01001167 /* exclude the BTS from the global RF Lock handling */
1168 int excl_from_rf_lock;
1169
1170 /* supported codecs beside FR */
1171 struct bts_codec_conf codec;
1172
1173 /* BTS dependencies bit field */
1174 uint32_t depends_on[256/(8*4)];
1175
1176 /* full and half rate multirate config */
1177 struct amr_multirate_conf mr_full;
1178 struct amr_multirate_conf mr_half;
1179
1180 /* PCU socket state */
1181 char *pcu_sock_path;
1182 struct pcu_sock_state *pcu_state;
1183
1184 struct rate_ctr_group *bts_ctrs;
1185 struct osmo_stat_item_group *bts_statg;
1186
1187 struct handover_cfg *ho;
1188
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001189 /* A list of struct gsm_bts_ref, indicating neighbors of this BTS.
1190 * When the si_common neigh_list is in automatic mode, it is populated from this list as well as
1191 * gsm_network->neighbor_bss_cells. */
1192 struct llist_head local_neighbors;
1193
Neels Hofmeyr10485162018-02-13 23:22:03 +01001194 /* BTS-specific overrides for timer values from struct gsm_network. */
1195 uint8_t T3122; /* ASSIGMENT REJECT wait indication */
Pau Espin Pedrol1b963342018-11-07 14:19:32 +01001196 bool T3113_dynamic; /* Calculate T3113 timeout dynamically based on BTS channel config and load */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001197
1198 /* Periodic channel load measurements are used to maintain T3122. */
1199 struct load_counter chan_load_samples[7];
1200 int chan_load_samples_idx;
Stefan Sperling6442e432018-02-06 14:44:54 +01001201 uint8_t chan_load_avg; /* current channel load average in percent (0 - 100). */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001202};
1203
Oliver Smith8d8d7102018-10-23 15:35:43 +02001204/* One rejected BTS */
1205struct gsm_bts_rejected {
1206 /* list header in net->bts_rejected */
1207 struct llist_head list;
1208
1209 uint16_t site_id;
1210 uint16_t bts_id;
1211 char ip[INET6_ADDRSTRLEN];
1212 time_t time;
1213};
Neels Hofmeyr10485162018-02-13 23:22:03 +01001214
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001215struct gsm_network *gsm_network_init(void *ctx);
1216
Neels Hofmeyr10485162018-02-13 23:22:03 +01001217struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, uint8_t bts_num);
Neels Hofmeyr6d568ed2018-07-09 16:49:18 +02001218struct gsm_bts *gsm_bts_num(const struct gsm_network *net, int num);
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001219bool gsm_bts_matches_lai(const struct gsm_bts *bts, const struct osmo_location_area_id *lai);
1220bool gsm_bts_matches_cell_id(const struct gsm_bts *bts, const struct gsm0808_cell_id *cell_id);
1221struct gsm_bts *gsm_bts_by_cell_id(const struct gsm_network *net,
1222 const struct gsm0808_cell_id *cell_id,
1223 int match_idx);
1224int gsm_bts_local_neighbor_add(struct gsm_bts *bts, struct gsm_bts *neighbor);
1225int gsm_bts_local_neighbor_del(struct gsm_bts *bts, const struct gsm_bts *neighbor);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001226
1227struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
1228struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
1229
1230enum gsm_bts_type str2btstype(const char *arg);
1231const char *btstype2str(enum gsm_bts_type type);
1232
1233enum bts_attribute str2btsattr(const char *s);
1234const char *btsatttr2str(enum bts_attribute v);
1235
1236enum gsm_bts_type_variant str2btsvariant(const char *arg);
1237const char *btsvariant2str(enum gsm_bts_type_variant v);
1238
1239extern const struct value_string gsm_chreq_descs[];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001240extern const struct value_string gsm_pchant_names[];
1241extern const struct value_string gsm_pchant_descs[];
1242extern const struct value_string gsm_pchan_ids[];
Neels Hofmeyr10485162018-02-13 23:22:03 +01001243const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001244static inline const char *gsm_pchan_id(enum gsm_phys_chan_config c)
1245{ return get_value_string(gsm_pchan_ids, c); }
Neels Hofmeyr10485162018-02-13 23:22:03 +01001246enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
1247const char *gsm_lchant_name(enum gsm_chan_t c);
1248const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte57658ec2019-02-04 12:30:44 +01001249char *gsm_bts_name(const struct gsm_bts *bts);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001250char *gsm_trx_name(const struct gsm_bts_trx *trx);
1251char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
1252char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
1253char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001254
1255static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
1256{
1257 return lchan->name;
1258}
1259
Neels Hofmeyr10485162018-02-13 23:22:03 +01001260void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
1261
1262struct gsm_nm_state *
1263gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
1264 const struct abis_om_obj_inst *obj_inst);
1265void *
1266gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
1267 const struct abis_om_obj_inst *obj_inst);
1268
1269/* reset the state of all MO in the BTS */
1270void gsm_bts_mo_reset(struct gsm_bts *bts);
1271
1272uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
1273 uint8_t ts_nr, uint8_t lchan_nr);
1274uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
1275uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
1276 enum gsm_phys_chan_config as_pchan);
1277
Harald Welte251bec12018-09-09 17:14:09 +02001278void gsm48_lchan2chan_desc(struct gsm48_chan_desc *cd,
1279 const struct gsm_lchan *lchan);
Harald Welte24286f32018-09-09 17:17:44 +02001280void gsm48_lchan2chan_desc_as_configured(struct gsm48_chan_desc *cd, const struct gsm_lchan *lchan);
Harald Welte251bec12018-09-09 17:14:09 +02001281
Neels Hofmeyr10485162018-02-13 23:22:03 +01001282/* return the gsm_lchan for the CBCH (if it exists at all) */
1283struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
1284
1285/*
1286 * help with parsing regexps
1287 */
1288int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
1289 int argc, const char **argv) __attribute__ ((warn_unused_result));
1290
1291static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
1292{
1293 if (ts->tsc != -1)
1294 return ts->tsc;
1295 else
1296 return ts->trx->bts->bsic & 7;
1297}
1298
1299struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
1300 int *rc);
1301
1302enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001303uint8_t pchan_subslots(enum gsm_phys_chan_config pchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001304bool ts_is_tch(struct gsm_bts_trx_ts *ts);
1305
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01001306
Harald Welteb7948872017-12-18 18:48:21 +01001307static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection *conn) {
1308 OSMO_ASSERT(conn->lchan);
1309 return conn->lchan->ts->trx->bts;
1310}
1311
Harald Welted82101e2017-12-09 23:07:38 +01001312enum {
1313 BTS_CTR_CHREQ_TOTAL,
1314 BTS_CTR_CHREQ_NO_CHANNEL,
1315 BTS_CTR_CHAN_RF_FAIL,
1316 BTS_CTR_CHAN_RLL_ERR,
1317 BTS_CTR_BTS_OML_FAIL,
1318 BTS_CTR_BTS_RSL_FAIL,
1319 BTS_CTR_CODEC_AMR_F,
1320 BTS_CTR_CODEC_AMR_H,
1321 BTS_CTR_CODEC_EFR,
1322 BTS_CTR_CODEC_V1_FR,
1323 BTS_CTR_CODEC_V1_HR,
Harald Weltecf9d4312017-12-13 23:17:16 +01001324 BTS_CTR_PAGING_ATTEMPTED,
1325 BTS_CTR_PAGING_ALREADY,
1326 BTS_CTR_PAGING_RESPONDED,
1327 BTS_CTR_PAGING_EXPIRED,
Harald Welte4f598922017-12-14 13:47:02 +01001328 BTS_CTR_CHAN_ACT_TOTAL,
1329 BTS_CTR_CHAN_ACT_NACK,
Harald Welte62d9cb02017-12-14 14:00:26 +01001330 BTS_CTR_RSL_UNKNOWN,
Harald Welte581398a2017-12-14 14:29:44 +01001331 BTS_CTR_RSL_IPA_NACK,
Harald Welte00d64fd2017-12-14 14:34:16 +01001332 BTS_CTR_MODE_MODIFY_NACK,
Harald Welted82101e2017-12-09 23:07:38 +01001333};
1334
1335static const struct rate_ctr_desc bts_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001336 [BTS_CTR_CHREQ_TOTAL] = {"chreq:total", "Received channel requests."},
1337 [BTS_CTR_CHREQ_NO_CHANNEL] = {"chreq:no_channel", "Sent to MS no channel available."},
1338 [BTS_CTR_CHAN_RF_FAIL] = {"chan:rf_fail", "Received a RF failure indication from BTS."},
1339 [BTS_CTR_CHAN_RLL_ERR] = {"chan:rll_err", "Received a RLL failure with T200 cause from BTS."},
Harald Welted82101e2017-12-09 23:07:38 +01001340 [BTS_CTR_BTS_OML_FAIL] = {"oml_fail", "Received a TEI down on a OML link."},
1341 [BTS_CTR_BTS_RSL_FAIL] = {"rsl_fail", "Received a TEI down on a OML link."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001342 [BTS_CTR_CODEC_AMR_F] = {"codec:amr_f", "Count the usage of AMR/F codec by channel mode requested."},
1343 [BTS_CTR_CODEC_AMR_H] = {"codec:amr_h", "Count the usage of AMR/H codec by channel mode requested."},
1344 [BTS_CTR_CODEC_EFR] = {"codec:efr", "Count the usage of EFR codec by channel mode requested."},
1345 [BTS_CTR_CODEC_V1_FR] = {"codec:fr", "Count the usage of FR codec by channel mode requested."},
1346 [BTS_CTR_CODEC_V1_HR] = {"codec:hr", "Count the usage of HR codec by channel mode requested."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001347
1348 [BTS_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
1349 [BTS_CTR_PAGING_ALREADY] = {"paging:already", "Paging attempts ignored as subsciber was already being paged."},
1350 [BTS_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful paging response."},
1351 [BTS_CTR_PAGING_EXPIRED] = {"paging:expired", "Paging Request expired because of timeout T3113."},
Harald Welte4f598922017-12-14 13:47:02 +01001352 [BTS_CTR_CHAN_ACT_TOTAL] = {"chan_act:total", "Total number of Channel Activations."},
1353 [BTS_CTR_CHAN_ACT_NACK] = {"chan_act:nack", "Number of Channel Activations that the BTS NACKed"},
Harald Welte62d9cb02017-12-14 14:00:26 +01001354 [BTS_CTR_RSL_UNKNOWN] = {"rsl:unknown", "Number of unknown/unsupported RSL messages received from BTS"},
Harald Welte581398a2017-12-14 14:29:44 +01001355 [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 +01001356 [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 +01001357};
1358
1359static const struct rate_ctr_group_desc bts_ctrg_desc = {
1360 "bts",
1361 "base transceiver station",
1362 OSMO_STATS_CLASS_GLOBAL,
1363 ARRAY_SIZE(bts_ctr_description),
1364 bts_ctr_description,
1365};
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001366
Alexander Couzens20423ea2016-07-12 15:42:02 +02001367enum {
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001368 BTS_STAT_CHAN_LOAD_AVERAGE,
1369 BTS_STAT_T3122,
1370};
1371
1372enum {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001373 BSC_CTR_ASSIGNMENT_ATTEMPTED,
1374 BSC_CTR_ASSIGNMENT_COMPLETED,
1375 BSC_CTR_ASSIGNMENT_STOPPED,
1376 BSC_CTR_ASSIGNMENT_NO_CHANNEL,
1377 BSC_CTR_ASSIGNMENT_TIMEOUT,
1378 BSC_CTR_ASSIGNMENT_FAILED,
1379 BSC_CTR_ASSIGNMENT_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001380 BSC_CTR_HANDOVER_ATTEMPTED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001381 BSC_CTR_HANDOVER_COMPLETED,
1382 BSC_CTR_HANDOVER_STOPPED,
Alexander Couzensb847a212016-08-02 11:34:11 +02001383 BSC_CTR_HANDOVER_NO_CHANNEL,
1384 BSC_CTR_HANDOVER_TIMEOUT,
Alexander Couzensb847a212016-08-02 11:34:11 +02001385 BSC_CTR_HANDOVER_FAILED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001386 BSC_CTR_HANDOVER_ERROR,
1387 BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED,
1388 BSC_CTR_INTER_BSC_HO_OUT_COMPLETED,
1389 BSC_CTR_INTER_BSC_HO_OUT_STOPPED,
1390 BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT,
1391 BSC_CTR_INTER_BSC_HO_OUT_ERROR,
1392 BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED,
1393 BSC_CTR_INTER_BSC_HO_IN_COMPLETED,
1394 BSC_CTR_INTER_BSC_HO_IN_STOPPED,
1395 BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL,
1396 BSC_CTR_INTER_BSC_HO_IN_FAILED,
1397 BSC_CTR_INTER_BSC_HO_IN_TIMEOUT,
1398 BSC_CTR_INTER_BSC_HO_IN_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001399 BSC_CTR_PAGING_ATTEMPTED,
1400 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +01001401 BSC_CTR_PAGING_RESPONDED,
Stefan Sperling7926d982018-05-17 14:52:02 +02001402 BSC_CTR_UNKNOWN_UNIT_ID,
Alexander Couzensb847a212016-08-02 11:34:11 +02001403};
1404
1405static const struct rate_ctr_desc bsc_ctr_description[] = {
Neels Hofmeyrdbb38d52018-07-11 19:53:56 +02001406 [BSC_CTR_ASSIGNMENT_ATTEMPTED] = {"assignment:attempted", "Assignment attempts."},
1407 [BSC_CTR_ASSIGNMENT_COMPLETED] = {"assignment:completed", "Assignment completed."},
1408 [BSC_CTR_ASSIGNMENT_STOPPED] = {"assignment:stopped", "Connection ended during Assignment."},
1409 [BSC_CTR_ASSIGNMENT_NO_CHANNEL] = {"assignment:no_channel", "Failure to allocate lchan for Assignment."},
1410 [BSC_CTR_ASSIGNMENT_TIMEOUT] = {"assignment:timeout", "Assignment timed out."},
1411 [BSC_CTR_ASSIGNMENT_FAILED] = {"assignment:failed", "Received Assignment Failure message."},
1412 [BSC_CTR_ASSIGNMENT_ERROR] = {"assignment:error", "Assigment failed for other reason."},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001413
1414 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Intra-BSC handover attempts."},
1415 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Intra-BSC handover completed."},
1416 [BSC_CTR_HANDOVER_STOPPED] = {"handover:stopped", "Connection ended during HO."},
1417 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Failure to allocate lchan for HO."},
1418 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Handover timed out."},
1419 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Received Handover Fail messages."},
1420 [BSC_CTR_HANDOVER_ERROR] = {"handover:error", "Re-assigment failed for other reason."},
1421
1422 [BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED] = {"interbsc_ho_out:attempted",
1423 "Attempts to handover to remote BSS."},
1424 [BSC_CTR_INTER_BSC_HO_OUT_COMPLETED] = {"interbsc_ho_out:completed",
1425 "Handover to remote BSS completed."},
1426 [BSC_CTR_INTER_BSC_HO_OUT_STOPPED] = {"interbsc_ho_out:stopped", "Connection ended during HO."},
1427 [BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT] = {"interbsc_ho_out:timeout", "Handover timed out."},
1428 [BSC_CTR_INTER_BSC_HO_OUT_ERROR] = {"interbsc_ho_out:error",
1429 "Handover to remote BSS failed for other reason."},
1430
1431 [BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED] = {"interbsc_ho_in:attempted",
1432 "Attempts to handover from remote BSS."},
1433 [BSC_CTR_INTER_BSC_HO_IN_COMPLETED] = {"interbsc_ho_in:completed",
1434 "Handover from remote BSS completed."},
1435 [BSC_CTR_INTER_BSC_HO_IN_STOPPED] = {"interbsc_ho_in:stopped", "Connection ended during HO."},
1436 [BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL] = {"interbsc_ho_in:no_channel",
1437 "Failure to allocate lchan for HO."},
1438 [BSC_CTR_INTER_BSC_HO_IN_TIMEOUT] = {"interbsc_ho_in:timeout", "Handover from remote BSS timed out."},
1439 [BSC_CTR_INTER_BSC_HO_IN_FAILED] = {"interbsc_ho_in:failed", "Received Handover Fail message."},
1440 [BSC_CTR_INTER_BSC_HO_IN_ERROR] = {"interbsc_ho_in:error",
1441 "Handover from remote BSS failed for other reason."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001442
1443 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001444 [BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Paging request send failures because no responsible BTS was found."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001445 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response."},
Stefan Sperling7926d982018-05-17 14:52:02 +02001446
1447 [BSC_CTR_UNKNOWN_UNIT_ID] = {"abis:unknown_unit_id", "Connection attempts from unknown IPA CCM Unit ID."},
Alexander Couzensb847a212016-08-02 11:34:11 +02001448};
1449
Alexander Couzensb847a212016-08-02 11:34:11 +02001450
1451
1452static const struct rate_ctr_group_desc bsc_ctrg_desc = {
1453 "bsc",
1454 "base station controller",
1455 OSMO_STATS_CLASS_GLOBAL,
1456 ARRAY_SIZE(bsc_ctr_description),
1457 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +02001458};
1459
Neels Hofmeyr73983952016-05-10 13:29:33 +02001460struct gsm_tz {
1461 int override; /* if 0, use system's time zone instead. */
1462 int hr; /* hour */
1463 int mn; /* minute */
1464 int dst; /* daylight savings */
1465};
1466
Harald Welte52b1f982008-12-23 20:25:15 +00001467struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001468 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
1469 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
1470 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
1471 * these have in common, like country and network code, put in yet
1472 * separate structs and placed as members in osmo_bsc and osmo_msc. */
1473
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001474 struct osmo_plmn_id plmn;
1475
Harald Welte51e4bf32017-12-23 17:30:18 +01001476 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
1477 uint8_t a5_encryption_mask;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001478 int neci;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001479
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001480 struct handover_cfg *ho;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001481 struct {
1482 unsigned int congestion_check_interval_s;
1483 struct osmo_timer_list congestion_check_timer;
1484 } hodec2;
Harald Welte52b1f982008-12-23 20:25:15 +00001485
Alexander Couzensb847a212016-08-02 11:34:11 +02001486 struct rate_ctr_group *bsc_ctrs;
Harald Welte24ff6ee2009-12-22 00:41:05 +01001487
Harald Welte52b1f982008-12-23 20:25:15 +00001488 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +02001489 struct llist_head bts_list;
Oliver Smith8d8d7102018-10-23 15:35:43 +02001490 struct llist_head bts_rejected;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001491
Neels Hofmeyr596c4022018-06-16 19:29:50 +02001492 /* shall reference gsm_network_T[] */
1493 struct T_def *T_defs;
Harald Welteeab84a12009-12-13 10:53:12 +01001494
Alexander Couzens547c2072017-11-21 12:03:04 +01001495 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +08001496
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +08001497 /* Use a TCH for handling requests of type paging any */
1498 int pag_any_tch;
1499
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08001500 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +02001501 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +01001502
Daniel Willmann6fc4a982011-07-22 17:55:42 +02001503 /* control interface */
1504 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +02001505
1506 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
1507 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +02001508
1509 /* all active subscriber connections. */
1510 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +02001511
1512 /* if override is nonzero, this timezone data is used for all MM
1513 * contexts. */
1514 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
1515 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +01001516 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +02001517 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +01001518
1519 /* List of all struct bsc_subscr used in libbsc. This llist_head is
1520 * allocated so that the llist_head pointer itself can serve as a
1521 * talloc context (useful to not have to pass the entire gsm_network
1522 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
1523 * not require gsm_data.h). In an MSC-without-BSC environment, this
1524 * pointer is NULL to indicate absence of a bsc_subscribers list. */
1525 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +02001526
Stefan Sperling6cee8932018-01-30 18:14:22 +01001527 /* Timer for periodic channel load measurements to maintain each BTS's T3122. */
1528 struct osmo_timer_list t3122_chan_load_timer;
1529
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001530 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +02001531 struct mgcp_client_conf *conf;
1532 struct mgcp_client *client;
1533 } mgw;
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001534
1535 /* Remote BSS Cell Identifier Lists */
1536 struct neighbor_ident_list *neighbor_bss_cells;
Harald Welte7e310b12009-03-30 20:56:32 +00001537};
1538
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001539struct gsm_audio_support {
1540 uint8_t hr : 1,
1541 ver : 7;
1542};
1543
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001544static inline const struct osmo_location_area_id *bts_lai(struct gsm_bts *bts)
1545{
1546 static struct osmo_location_area_id lai;
1547 lai = (struct osmo_location_area_id){
1548 .plmn = bts->network->plmn,
1549 .lac = bts->location_area_code,
1550 };
1551 return &lai;
1552}
1553
Neels Hofmeyrc13e6872016-05-11 13:53:47 +02001554extern void talloc_ctx_init(void *ctx_root);
1555
Harald Welte39315c42010-01-10 18:01:52 +01001556int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +02001557
Harald Welte1d014a52009-08-08 15:38:29 +02001558enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +02001559const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +00001560struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
1561 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +00001562
Andreas Eversberg8226fa72009-06-29 15:19:38 +02001563extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +01001564extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +02001565
Harald Weltef383aa12012-07-02 19:51:55 +02001566/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +00001567static inline int is_ipaccess_bts(struct gsm_bts *bts)
1568{
1569 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001570 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001571 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +00001572 return 1;
1573 default:
1574 break;
1575 }
1576 return 0;
1577}
1578
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001579static inline int is_sysmobts_v2(struct gsm_bts *bts)
1580{
1581 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +01001582 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001583 return 1;
1584 default:
1585 break;
1586 }
1587 return 0;
1588}
1589
Harald Welte5b570672009-08-10 10:08:01 +02001590static inline int is_siemens_bts(struct gsm_bts *bts)
1591{
1592 switch (bts->type) {
1593 case GSM_BTS_TYPE_BS11:
1594 return 1;
1595 default:
1596 break;
1597 }
1598
1599 return 0;
1600}
1601
Andreas Eversberg7d8fa342013-12-05 13:25:06 +01001602static inline int is_nokia_bts(struct gsm_bts *bts)
1603{
1604 switch (bts->type) {
1605 case GSM_BTS_TYPE_NOKIA_SITE:
1606 return 1;
1607 default:
1608 break;
1609 }
1610
1611 return 0;
1612}
1613
Andreas Eversbergdcf38e12013-12-05 14:37:11 +01001614static inline int is_e1_bts(struct gsm_bts *bts)
1615{
1616 switch (bts->type) {
1617 case GSM_BTS_TYPE_BS11:
1618 case GSM_BTS_TYPE_RBS2000:
1619 case GSM_BTS_TYPE_NOKIA_SITE:
1620 return 1;
1621 default:
1622 break;
1623 }
1624
1625 return 0;
1626}
1627
Harald Welte1876c312018-05-27 11:53:43 +02001628extern struct gsm_network *bsc_gsmnet;
1629
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001630enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +02001631const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001632int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +02001633
Neels Hofmeyr4d358c02018-02-22 03:19:05 +01001634void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +08001635void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +01001636
Harald Weltefbda4e12010-03-04 11:04:52 +01001637int gsm_bts_model_register(struct gsm_bts_model *model);
1638
Harald Welte3561bd42018-01-28 03:04:16 +01001639struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *network);
Neels Hofmeyr42eb0142016-05-20 17:15:44 +02001640
1641struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
1642void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +08001643
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001644struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, uint8_t bsic);
1645struct 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 +01001646
Harald Welte3300c012011-06-05 13:31:33 +02001647void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
1648 uint8_t e1_ts, uint8_t e1_ts_ss);
1649
Maxbe356ed2017-09-07 19:10:09 +02001650void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Harald Welte3300c012011-06-05 13:31:33 +02001651struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +01001652int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -04001653int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +02001654
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +02001655/* generic E1 line operations for all ISDN-based BTS. */
1656extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
1657
Harald Weltee555c2b2012-08-17 13:02:12 +02001658extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
1659extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
1660
Max3d049d22017-10-09 17:12:53 +02001661char *get_model_oml_status(const struct gsm_bts *bts);
1662
Max25cc4072017-10-10 14:50:35 +02001663unsigned long long bts_uptime(const struct gsm_bts *bts);
1664
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +01001665/* control interface handling */
1666int bsc_base_ctrl_cmds_install(void);
1667
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001668/* dependency handling */
1669void bts_depend_mark(struct gsm_bts *bts, int dep);
1670void bts_depend_clear(struct gsm_bts *bts, int dep);
1671int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +01001672int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001673
Harald Welte2f8b9d22017-06-18 11:12:13 +03001674int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
1675void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
1676
Harald Weltea43e0b42016-06-19 18:06:02 +02001677bool classmark_is_r99(struct gsm_classmark *cm);
1678
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001679bool trx_is_usable(const struct gsm_bts_trx *trx);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001680bool ts_is_usable(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001681
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001682int gsm_lchan_type_by_pchan(enum gsm_phys_chan_config pchan);
1683enum gsm_phys_chan_config gsm_pchan_by_lchan_type(enum gsm_chan_t type);
1684
1685void gsm_bts_all_ts_dispatch(struct gsm_bts *bts, uint32_t ts_ev, void *data);
1686void gsm_trx_all_ts_dispatch(struct gsm_bts_trx *trx, uint32_t ts_ev, void *data);
1687
1688int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001689
Harald Welte6be350c2011-05-25 13:10:08 +02001690#endif /* _GSM_DATA_H */