blob: dc686c366983c6e47f23d9151f748f20310d379a [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>
Neels Hofmeyra6078fe2019-01-28 03:52:14 +010020#include <osmocom/core/tdef.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020021
Harald Welte121e9a42016-04-20 13:13:19 +020022#include <osmocom/crypt/auth.h>
Harald Weltef142c972011-05-24 13:25:38 +020023
Neels Hofmeyrc0164792017-09-04 15:15:32 +020024#include <osmocom/bsc/rest_octets.h>
Harald Welteb96be392011-05-25 12:33:33 +020025
Neels Hofmeyr10485162018-02-13 23:22:03 +010026#include <osmocom/core/bitvec.h>
27#include <osmocom/gsm/gsm_utils.h>
28#include <osmocom/gsm/rxlev_stat.h>
29#include <osmocom/gsm/protocol/gsm_08_58.h>
30#include <osmocom/gsm/protocol/gsm_12_21.h>
31#include <osmocom/abis/e1_input.h>
32#include <osmocom/bsc/meas_rep.h>
Harald Welte519c7e12018-01-28 02:45:46 +010033#include <osmocom/bsc/bsc_msg_filter.h>
Stefan Sperling6442e432018-02-06 14:44:54 +010034#include <osmocom/bsc/acc_ramp.h>
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020035#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 Hofmeyrf14aaa42019-04-23 18:37:37 +020042struct osmo_mgcpc_ep;
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
Sylvain Munautaa824922019-03-07 16:32:02 +0100101enum channel_rate {
102 CH_RATE_SDCCH,
103 CH_RATE_HALF,
104 CH_RATE_FULL,
105};
106
Philipp Maierbb66d102019-01-22 11:29:06 +0100107struct channel_mode_and_rate {
108 enum gsm48_chan_mode chan_mode;
Sylvain Munautaa824922019-03-07 16:32:02 +0100109 enum channel_rate chan_rate;
Philipp Maierbb66d102019-01-22 11:29:06 +0100110 uint16_t s15_s0;
111};
112
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100113/* Information retrieved during an Assignment Request from the MSC. This is storage of the Assignment instructions
114 * parsed from the Assignment Request message, to pass on until the gscon and assignment FSMs have decided whether an
115 * Assignment is actually going to be carried out. Should remain unchanged after initial decoding. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200116struct assignment_request {
117 bool aoip;
118
119 uint16_t msc_assigned_cic;
120
121 char msc_rtp_addr[INET_ADDRSTRLEN];
122 uint16_t msc_rtp_port;
123
Sylvain Munautaa824922019-03-07 16:32:02 +0100124 /* Rate/codec setting in preference order (need at least 1 !) */
125 int n_ch_mode_rate;
126 struct channel_mode_and_rate ch_mode_rate[3];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200127};
128
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100129/* State of an ongoing Assignment, while the assignment_fsm is still busy. This serves as state separation to keep the
130 * currently used lchan and gscon unmodified until the outcome of an Assignment is known. If the Assignment fails, this
131 * state is simply discarded, and the gscon carries on with the original lchan remaining unchanged. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200132struct assignment_fsm_data {
133 struct assignment_request req;
134 bool requires_voice_stream;
135
136 struct osmo_fsm_inst *fi;
137 struct gsm_lchan *new_lchan;
138
139 /* Whether this assignment triggered creation of the MGW endpoint: if the assignment
140 * fails, we will release that again as soon as possible. (If false, the endpoint already
141 * existed before or isn't needed at all.)*/
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200142 struct osmo_mgcpc_ep_ci *created_ci_for_msc;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200143
144 enum gsm0808_cause failure_cause;
145 enum gsm48_rr_cause rr_cause;
146
147 bool result_rate_ctr_done;
148};
149
150enum hodec_id {
151 HODEC_NONE,
152 HODEC1 = 1,
153 HODEC2 = 2,
154 HODEC_USER,
155 HODEC_REMOTE,
156};
157
158/* For example, to count specific kinds of ongoing handovers, it is useful to be able to OR-combine
159 * scopes. */
160enum handover_scope {
161 HO_NO_HANDOVER = 0,
162 HO_INTRA_CELL = 0x1,
163 HO_INTRA_BSC = 0x2,
164 HO_INTER_BSC_OUT = 0x4,
165 HO_INTER_BSC_IN = 0x8,
166 HO_SCOPE_ALL = 0xffff,
167};
168
169extern const struct value_string handover_scope_names[];
170inline static const char *handover_scope_name(enum handover_scope val)
171{ return get_value_string(handover_scope_names, val); }
172
173struct handover_out_req {
174 enum hodec_id from_hodec_id;
175 struct gsm_lchan *old_lchan;
176 struct neighbor_ident_key target_nik;
177 enum gsm_chan_t new_lchan_type; /*< leave GSM_LCHAN_NONE to use same as old_lchan */
178};
179
180struct handover_in_req {
181 struct gsm0808_channel_type ct;
182 struct gsm0808_speech_codec_list scl;
183 struct gsm0808_encrypt_info ei;
184 struct gsm_classmark classmark;
Neels Hofmeyrc15f6cd2019-03-15 02:48:39 +0100185 /* chosen_encr_alg reflects the encoded value as in RSL_ENC_ALG_A5(a5_numer):
186 * chosen_encr_alg == 1 means A5/0 i.e. no encryption, chosen_encr_alg == 4 means A5/3.
187 * chosen_encr_alg == 0 means no such IE was present. */
188 uint8_t chosen_encr_alg;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200189 struct gsm0808_cell_id cell_id_serving;
190 char cell_id_serving_name[64];
191 struct gsm0808_cell_id cell_id_target;
192 char cell_id_target_name[64];
193 uint16_t msc_assigned_cic;
194 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
195 uint16_t msc_assigned_rtp_port;
196};
197
198struct handover {
199 struct osmo_fsm_inst *fi;
200
201 enum hodec_id from_hodec_id;
202 enum handover_scope scope;
203 enum gsm_chan_t new_lchan_type;
204 struct neighbor_ident_key target_cell;
205
206 uint8_t ho_ref;
207 struct gsm_bts *new_bts;
208 struct gsm_lchan *new_lchan;
209 bool async;
210 struct handover_in_req inter_bsc_in;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200211 struct osmo_mgcpc_ep_ci *created_ci_for_msc;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200212};
213
Neels Hofmeyr378a4922016-05-09 21:07:43 +0200214/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100215struct gsm_subscriber_connection {
Harald Weltea43e0b42016-06-19 18:06:02 +0200216 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +0800217 struct llist_head entry;
218
Harald Welte3561bd42018-01-28 03:04:16 +0100219 /* FSM instance to control the subscriber connection state (RTP, A) */
220 struct osmo_fsm_inst *fi;
221
Harald Weltea43e0b42016-06-19 18:06:02 +0200222 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100223 struct bsc_subscr *bsub;
224
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100225 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200226 struct gsm_network *network;
227
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100228 /* the primary / currently active lchan to the BTS/subscriber. During Assignment and Handover, separate lchans
229 * are kept in the .assignment or .handover sub-structs, respectively, so that this lchan remains unaffected
230 * until Assignment or Handover have actually succeeded. */
Harald Welte4a8ebc82017-12-18 18:34:41 +0100231 struct gsm_lchan *lchan;
Harald Welte3561bd42018-01-28 03:04:16 +0100232
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100233 /* Only valid during an ongoing Assignment; might be overwritten at any time by a failed Assignment attempt.
234 * Once an Assignment was successful, all relevant state must be copied out of this sub-struct. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200235 struct assignment_fsm_data assignment;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100236
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100237 /* handover information, if a handover is pending for this conn. Valid only during an ongoing Handover
238 * operation. If a Handover was successful, all relevant state must be copied out of this sub-struct. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200239 struct handover ho;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100240
Harald Welte4a8ebc82017-12-18 18:34:41 +0100241 /* buffer/cache for classmark of the ME of the subscriber */
Harald Weltea43e0b42016-06-19 18:06:02 +0200242 struct gsm_classmark classmark;
Andreas Eversberg935e5d72013-06-17 11:58:30 +0200243
Neels Hofmeyr149160f2018-06-16 17:20:13 +0200244 /* Queue DTAP messages during handover/assignment (msgb_enqueue()/msgb_dequeue())*/
245 struct llist_head dtap_queue;
246 unsigned int dtap_queue_len;
Andreas Eversberg084b4212013-05-30 14:12:48 +0200247
Neels Hofmeyrec422642018-02-15 14:07:40 +0100248 struct {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100249 int failures;
Neels Hofmeyrec422642018-02-15 14:07:40 +0100250 struct penalty_timers *penalty_timers;
251 } hodec2;
Neels Hofmeyra60f3442018-02-12 16:44:32 +0100252
253 /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment Request. 3GPP 48.008
254 * 3.2.2.103 says:
255 * The "Codec List (MSC Preferred)" shall not include codecs
256 * that are not supported by the MS.
257 * i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed the MS bearer
258 * capabilities, which the MSC is required to translate into the codec list. */
259 struct gsm0808_speech_codec_list codec_list;
Harald Welte519c7e12018-01-28 02:45:46 +0100260
261 /* flag to prevent multiple simultaneous ciphering commands */
262 int ciphering_handled;
263
264 /* state related to welcome USSD */
265 uint8_t new_subscriber;
266
267 /* state related to osmo_bsc_filter.c */
268 struct bsc_filter_state filter_state;
269
270 /* SCCP connection associatd with this subscriber_connection */
271 struct {
272 /* for advanced ping/pong */
273 int send_ping;
274
275 /* SCCP connection realted */
276 struct bsc_msc_data *msc;
277
278 /* Sigtran connection ID */
279 int conn_id;
280 enum subscr_sccp_state state;
281 } sccp;
282
283 /* for audio handling */
284 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200285 uint16_t msc_assigned_cic;
Harald Welte519c7e12018-01-28 02:45:46 +0100286
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200287 /* RTP address where the MSC expects us to send the RTP stream coming from the BTS. */
288 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
289 uint16_t msc_assigned_rtp_port;
Harald Welte519c7e12018-01-28 02:45:46 +0100290
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200291 /* The endpoint at the MGW used to join both BTS and MSC side connections, e.g.
292 * "rtpbridge/23@mgw". */
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200293 struct osmo_mgcpc_ep *mgw_endpoint;
Harald Welte3561bd42018-01-28 03:04:16 +0100294
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200295 /* The connection identifier of the osmo_mgcpc_ep used to transceive RTP towards the MSC.
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200296 * (The BTS side CI is handled by struct gsm_lchan and the lchan_fsm.) */
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200297 struct osmo_mgcpc_ep_ci *mgw_endpoint_ci_msc;
Harald Welte519c7e12018-01-28 02:45:46 +0100298 } user_plane;
Harald Weltec997ceb2018-05-30 01:39:43 +0200299
300 /* LCLS (local call, local switch) related state */
301 struct {
302 uint8_t global_call_ref[15];
303 uint8_t global_call_ref_len; /* length of global_call_ref */
Maxfe65ece2018-11-09 13:36:11 +0100304 enum gsm0808_lcls_config config; /* TS 48.008 3.2.2.116 */
305 enum gsm0808_lcls_control control; /* TS 48.008 3.2.2.117 */
Harald Weltec997ceb2018-05-30 01:39:43 +0200306 /* LCLS FSM */
307 struct osmo_fsm_inst *fi;
308 /* pointer to "other" connection, if Call Leg Relocation was successful */
309 struct gsm_subscriber_connection *other;
310 } lcls;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100311};
312
Harald Weltef142c972011-05-24 13:25:38 +0200313
Neels Hofmeyr10485162018-02-13 23:22:03 +0100314/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 Table 10.5.2.33b.1:
315 4-bit index is used (2#1111 = 10#15) */
316#define SI2Q_MAX_NUM 16
317/* length in bits (for single SI2quater message) */
318#define SI2Q_MAX_LEN 160
319#define SI2Q_MIN_LEN 18
320
321struct osmo_bsc_data;
322
323struct osmo_bsc_sccp_con;
324
325/* Channel Request reason */
326enum gsm_chreq_reason_t {
327 GSM_CHREQ_REASON_EMERG,
328 GSM_CHREQ_REASON_PAG,
329 GSM_CHREQ_REASON_CALL,
330 GSM_CHREQ_REASON_LOCATION_UPD,
331 GSM_CHREQ_REASON_OTHER,
332 GSM_CHREQ_REASON_PDCH,
333};
334
335/* lchans 0..3 are SDCCH in combined channel configuration,
336 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
337#define CCCH_LCHAN 4
338
339#define TRX_NR_TS 8
340#define TS_MAX_LCHAN 8
341
342#define HARDCODED_ARFCN 123
343#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
344
345/* for multi-drop config */
346#define HARDCODED_BTS0_TS 1
347#define HARDCODED_BTS1_TS 6
348#define HARDCODED_BTS2_TS 11
349
350#define MAX_VERSION_LENGTH 64
351
Neels Hofmeyr10485162018-02-13 23:22:03 +0100352enum gsm_hooks {
353 GSM_HOOK_NM_SWLOAD,
354 GSM_HOOK_RR_PAGING,
355 GSM_HOOK_RR_SECURITY,
356};
357
Neels Hofmeyr10485162018-02-13 23:22:03 +0100358enum bts_gprs_mode {
359 BTS_GPRS_NONE = 0,
360 BTS_GPRS_GPRS = 1,
361 BTS_GPRS_EGPRS = 2,
362};
363
364struct gsm_lchan;
365struct osmo_rtp_socket;
366struct rtp_socket;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100367
368/* Network Management State */
369struct gsm_nm_state {
370 uint8_t operational;
371 uint8_t administrative;
372 uint8_t availability;
373};
374
375struct gsm_abis_mo {
376 uint8_t obj_class;
377 uint8_t procedure_pending;
378 struct abis_om_obj_inst obj_inst;
379 const char *name;
380 struct gsm_nm_state nm_state;
381 struct tlv_parsed *nm_attr;
382 struct gsm_bts *bts;
383};
384
385/* Ericsson OM2000 Managed Object */
386struct abis_om2k_mo {
387 uint8_t class;
388 uint8_t bts;
389 uint8_t assoc_so;
390 uint8_t inst;
391} __attribute__ ((packed));
392
393struct om2k_mo {
394 struct abis_om2k_mo addr;
395 struct osmo_fsm_inst *fsm;
396};
397
398#define A38_XOR_MIN_KEY_LEN 12
399#define A38_XOR_MAX_KEY_LEN 16
400#define A38_COMP128_KEY_LEN 16
401#define RSL_ENC_ALG_A5(x) (x+1)
402#define MAX_EARFCN_LIST 32
403
404/* is the data link established? who established it? */
405#define LCHAN_SAPI_UNUSED 0
406#define LCHAN_SAPI_MS 1
407#define LCHAN_SAPI_NET 2
Neels Hofmeyr10485162018-02-13 23:22:03 +0100408
409/* BTS ONLY */
410#define MAX_NUM_UL_MEAS 104
411#define LC_UL_M_F_L1_VALID (1 << 0)
412#define LC_UL_M_F_RES_VALID (1 << 1)
413
414struct bts_ul_meas {
415 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
416 uint16_t ber10k;
417 /* timing advance offset (in quarter bits) */
418 int16_t ta_offs_qbits;
419 /* C/I ratio in dB */
420 float c_i;
421 /* flags */
422 uint8_t is_sub:1;
423 /* RSSI in dBm * -1 */
424 uint8_t inv_rssi;
425};
426
427struct bts_codec_conf {
428 uint8_t hr;
429 uint8_t efr;
430 uint8_t amr;
431};
432
433struct amr_mode {
434 uint8_t mode;
435 uint8_t threshold;
436 uint8_t hysteresis;
437};
438
439struct amr_multirate_conf {
440 uint8_t gsm48_ie[2];
441 struct amr_mode ms_mode[4];
442 struct amr_mode bts_mode[4];
443 uint8_t num_modes;
444};
445/* /BTS ONLY */
446
447enum lchan_csd_mode {
448 LCHAN_CSD_M_NT,
449 LCHAN_CSD_M_T_1200_75,
450 LCHAN_CSD_M_T_600,
451 LCHAN_CSD_M_T_1200,
452 LCHAN_CSD_M_T_2400,
453 LCHAN_CSD_M_T_9600,
454 LCHAN_CSD_M_T_14400,
455 LCHAN_CSD_M_T_29000,
456 LCHAN_CSD_M_T_32000,
457};
458
459/* State of the SAPIs in the lchan */
460enum lchan_sapi_state {
461 LCHAN_SAPI_S_NONE,
462 LCHAN_SAPI_S_REQ,
463 LCHAN_SAPI_S_ASSIGNED,
464 LCHAN_SAPI_S_REL,
465 LCHAN_SAPI_S_ERROR,
466};
467
Neels Hofmeyr92b9f2e2018-02-14 00:19:11 +0100468#define MAX_A5_KEY_LEN (128/8)
469
470struct gsm_encr {
471 uint8_t alg_id;
472 uint8_t key_len;
473 uint8_t key[MAX_A5_KEY_LEN];
474};
475
Neels Hofmeyr8da22332018-04-11 01:43:41 +0200476#define LOGPLCHAN(lchan, ss, level, fmt, args...) \
477 LOGP(ss, level, "%s (ss=%d,%s) (%s) " fmt, \
478 lchan ? gsm_ts_and_pchan_name(lchan->ts) : "-", \
479 lchan ? lchan->nr : 0, \
480 lchan ? gsm_lchant_name(lchan->type) : "-", \
481 bsc_subscr_name(lchan && lchan->conn ? lchan->conn->bsub : NULL), \
482 ## args)
483
Pau Espin Pedrold3e8e0c2018-11-28 16:35:10 +0100484/* Iterate lchans that have an FSM allocated based based on explicit pchan kind
485 * (GSM_PCHAN_* constant).
486 * Remark: PDCH related lchans are not handled in BSC but in PCU, so trying to
487 * iterate through GSM_PCHAN_PDCH is considered a void loop.
488 */
489#define ts_as_pchan_for_each_lchan(lchan, ts, as_pchan) \
490 for (lchan = (ts)->lchan; \
491 ((lchan - (ts)->lchan) < ARRAY_SIZE((ts)->lchan)) \
492 && lchan->fi \
493 && lchan->nr < pchan_subslots(as_pchan); \
494 lchan++)
495
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100496/* Iterate lchans that have an FSM allocated based on current PCHAN
497 * mode set in \ref ts.
498 * usage:
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200499 * struct gsm_lchan *lchan;
500 * struct gsm_bts_trx_ts *ts = get_some_timeslot();
501 * ts_for_each_lchan(lchan, ts) {
502 * LOGPLCHAN(DMAIN, LOGL_DEBUG, "hello world\n");
503 * }
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100504 */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200505#define ts_for_each_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_is)
506
Pau Espin Pedrol0ba20df2018-11-28 16:39:29 +0100507/* Iterate over all possible lchans available that have an FSM allocated based
508 * on PCHAN \ref ts (dynamic) configuration.
509 * Iterate all lchan instances set up by this \ref ts type, including those
510 * lchans currently disabled or in process of being enabled (e.g. due to dynamic
511 * timeslot in switchover). Compare ts_for_each_lchan(), which iterates only the
512 * enabled lchans.
513 * For example, it is useful in case dynamic timeslot \ref ts is in process of
514 * switching from configuration PDCH (no lchans) to TCH_F (1 lchan), where
515 * pchan_is is still set to PDCH but \ref ts may contain already an \ref lchan
516 * of type TCH_F which initiated the request to switch the \ts configuration.
517 */
518#define ts_for_each_potential_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_on_init)
519
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200520enum lchan_activate_mode {
521 FOR_NONE,
522 FOR_MS_CHANNEL_REQUEST,
523 FOR_ASSIGNMENT,
524 FOR_HANDOVER,
525 FOR_VTY,
526};
527
528extern const struct value_string lchan_activate_mode_names[];
529static inline const char *lchan_activate_mode_name(enum lchan_activate_mode activ_for)
530{ return get_value_string(lchan_activate_mode_names, activ_for); }
531
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100532struct lchan_activate_info {
533 enum lchan_activate_mode activ_for;
534 struct gsm_subscriber_connection *for_conn;
535 /* This always is for a specific lchan, so its lchan->type indicates full or half rate.
536 * When a dyn TS was selected, the lchan->type has been set to the desired rate. */
537 enum gsm48_chan_mode chan_mode;
Neels Hofmeyr58cf1b12019-03-15 02:49:18 +0100538 struct gsm_encr encr;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100539 /* AMR config */
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100540 uint16_t s15_s0;
541 bool requires_voice_stream;
542 bool wait_before_switching_rtp; /*< true = requires LCHAN_EV_READY_TO_SWITCH_RTP */
543 uint16_t msc_assigned_cic;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100544 /* During intra-BSC handover, we keep the MGW endpoint intact and just re-route to the new lchan. This
545 * 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 +0100546 struct gsm_lchan *re_use_mgw_endpoint_from_lchan;
547};
548
Neels Hofmeyr10485162018-02-13 23:22:03 +0100549struct gsm_lchan {
550 /* The TS that we're part of */
551 struct gsm_bts_trx_ts *ts;
552 /* The logical subslot number in the TS */
553 uint8_t nr;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200554 char *name;
555
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100556 char *last_error;
557
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200558 struct osmo_fsm_inst *fi;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200559 struct osmo_fsm_inst *fi_rtp;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200560 struct osmo_mgcpc_ep_ci *mgw_endpoint_ci_bts;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200561
562 struct {
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100563 struct lchan_activate_info info;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200564 bool activ_ack; /*< true as soon as RSL Chan Activ Ack is received */
Neels Hofmeyr369fba22018-11-27 01:30:50 +0100565 bool immediate_assignment_sent;
Neels Hofmeyr193c1e32018-08-27 22:06:24 +0200566 /*! This flag ensures that when an lchan activation has succeeded, and we have already
567 * sent ACKs like Immediate Assignment or BSSMAP Assignment Complete, and if other errors
568 * occur later, e.g. during release, that we don't send a NACK out of context. */
569 bool concluded;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200570 enum gsm0808_cause gsm0808_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200571 } activate;
572
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100573 struct {
574 /* If an event to release the lchan comes in while still waiting for responses, just mark this
575 * flag, so that the lchan will gracefully release at the next sensible junction. */
576 bool requested;
577 bool do_rr_release;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200578
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100579 /* There is an RSL error cause of value 0, so we need a separate flag. */
580 bool in_error;
581 /* RSL error code, RSL_ERR_* */
582 uint8_t rsl_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200583
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100584 /* If a release event is being handled, ignore other ricocheting release events until that
585 * release handling has concluded. */
586 bool in_release_handler;
Harald Welte963763d2019-02-03 12:11:12 +0100587
588 /* is this release at the end of a CSFB call? */
589 bool is_csfb;
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100590 } release;
Neels Hofmeyrd5df9a12018-07-20 05:35:47 +0200591
Neels Hofmeyr10485162018-02-13 23:22:03 +0100592 /* The logical channel type */
593 enum gsm_chan_t type;
594 /* RSL channel mode */
595 enum rsl_cmod_spd rsl_cmode;
596 /* If TCH, traffic channel mode */
597 enum gsm48_chan_mode tch_mode;
598 enum lchan_csd_mode csd_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100599 /* Power levels for MS and BTS */
600 uint8_t bs_power;
601 uint8_t ms_power;
602 /* Encryption information */
603 struct gsm_encr encr;
604
605 /* AMR bits */
606 uint8_t mr_ms_lv[7];
607 uint8_t mr_bts_lv[7];
Neels Hofmeyr4daa2102019-01-30 16:46:58 +0100608 /* AMR bits were based on these rate bits: */
609 uint16_t s15_s0;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100610
611 /* Established data link layer services */
612 uint8_t sapis[8];
613
614 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200615 uint32_t bound_ip; /*< where the BTS receives RTP */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100616 uint16_t bound_port;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200617 uint32_t connect_ip; /*< where the BTS sends RTP to (MGW) */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100618 uint16_t connect_port;
619 uint16_t conn_id;
620 uint8_t rtp_payload;
621 uint8_t rtp_payload2;
622 uint8_t speech_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100623
624 /* info we need to postpone the AoIP
625 * assignment completed message */
626 struct {
627 uint8_t rr_cause;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100628 bool valid;
629 } ass_compl;
630 } abis_ip;
631
632 uint8_t rqd_ta;
633
Neels Hofmeyr10485162018-02-13 23:22:03 +0100634 /* table of neighbor cell measurements */
635 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
636
637 /* cache of last measurement reports on this lchan */
638 struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
639 int meas_rep_idx;
640 int meas_rep_count;
Neels Hofmeyr35ba85c2018-02-12 16:47:40 +0100641 uint8_t meas_rep_last_seen_nr;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100642
643 /* GSM Random Access data */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200644 /* TODO: don't allocate this, rather keep an "is_present" flag */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100645 struct gsm48_req_ref *rqd_ref;
646
647 struct gsm_subscriber_connection *conn;
Philipp Maierbb66d102019-01-22 11:29:06 +0100648
649 /* Depending on the preferences that where submitted together with
650 * the assignment and the current channel load, the BSC has to select
651 * one of the offered codec/rates. The final selection by the BSC is
652 * stored here and is used when sending the assignment complete or
653 * when performing a handover procedure. */
654 struct channel_mode_and_rate ch_mode_rate;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100655};
656
Neels Hofmeyr10485162018-02-13 23:22:03 +0100657/* One Timeslot in a TRX */
658struct gsm_bts_trx_ts {
659 struct gsm_bts_trx *trx;
660 /* number of this timeslot at the TRX */
661 uint8_t nr;
662
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200663 struct osmo_fsm_inst *fi;
664 char *last_errmsg;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100665
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200666 /* vty phys_chan_config setting, not necessarily in effect in case it was changed in the telnet
667 * vty after OML activation. Gets written on vty 'write file'. */
668 enum gsm_phys_chan_config pchan_from_config;
669 /* When the timeslot OML is established, pchan_from_config is copied here. This is the pchan
670 * currently in effect; for dynamic ts, this is the dyn kind (GSM_PCHAN_TCH_F_TCH_H_PDCH or
671 * GSM_PCHAN_TCH_F_PDCH) and does not show the pchan type currently active. */
672 enum gsm_phys_chan_config pchan_on_init;
673 /* This is the *actual* pchan type currently active. For dynamic timeslots, this reflects either
674 * GSM_PCHAN_NONE or one of the standard GSM_PCHAN_TCH_F, GSM_PCHAN_TCH_H, GSM_PCHAN_PDCH.
675 * Callers can use this transparently without being aware of dyn ts. */
676 enum gsm_phys_chan_config pchan_is;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100677
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200678 /* After a PDCH ACT NACK, we shall not infinitely loop to try and ACT again.
679 * Also marks a timeslot where PDCH was deactivated by VTY. This is cleared whenever a timeslot
680 * enters IN_USE state, i.e. after each TCH use we try to PDCH ACT once again. */
681 bool pdch_act_allowed;
682
Neels Hofmeyrbcdbfb72018-07-26 20:33:15 +0200683 /* Whether TS_EV_OML_READY was received */
684 bool is_oml_ready;
685 /* Whether TS_EV_RSL_READY was received */
686 bool is_rsl_ready;
687
Neels Hofmeyr10485162018-02-13 23:22:03 +0100688 struct gsm_abis_mo mo;
689 struct tlv_parsed nm_attr;
690 uint8_t nm_chan_comb;
691 int tsc; /* -1 == use BTS TSC */
692
693 struct {
694 /* Parameters below are configured by VTY */
695 int enabled;
696 uint8_t maio;
697 uint8_t hsn;
698 struct bitvec arfcns;
699 uint8_t arfcns_data[1024/8];
700 /* This is the pre-computed MA for channel assignments */
701 struct bitvec ma;
702 uint8_t ma_len; /* part of ma_data that is used */
703 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
704 } hopping;
705
706 /* To which E1 subslot are we connected */
707 struct gsm_e1_subslot e1_link;
708
709 union {
710 struct {
711 struct om2k_mo om2k_mo;
712 } rbs2000;
713 };
714
715 struct gsm_lchan lchan[TS_MAX_LCHAN];
716};
717
718/* One TRX in a BTS */
719struct gsm_bts_trx {
720 /* list header in bts->trx_list */
721 struct llist_head list;
722
723 struct gsm_bts *bts;
724 /* number of this TRX in the BTS */
725 uint8_t nr;
726 /* human readable name / description */
727 char *description;
728 /* how do we talk RSL with this TRX? */
729 struct gsm_e1_subslot rsl_e1_link;
730 uint8_t rsl_tei;
731 struct e1inp_sign_link *rsl_link;
732
733 /* Timeout for initiating the RSL connection. */
734 struct osmo_timer_list rsl_connect_timeout;
735
736 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
737 struct e1inp_sign_link *oml_link;
738
739 struct gsm_abis_mo mo;
740 struct tlv_parsed nm_attr;
741 struct {
742 struct gsm_abis_mo mo;
743 } bb_transc;
744
745 uint16_t arfcn;
746 int nominal_power; /* in dBm */
747 unsigned int max_power_red; /* in actual dB */
748
749 union {
750 struct {
751 struct {
752 struct gsm_abis_mo mo;
753 } bbsig;
754 struct {
755 struct gsm_abis_mo mo;
756 } pa;
757 } bs11;
758 struct {
759 unsigned int test_state;
760 uint8_t test_nr;
761 struct rxlev_stats rxlev_stat;
762 } ipaccess;
763 struct {
764 struct {
765 struct om2k_mo om2k_mo;
766 } trxc;
767 struct {
768 struct om2k_mo om2k_mo;
769 } rx;
770 struct {
771 struct om2k_mo om2k_mo;
772 } tx;
773 } rbs2000;
774 };
775 struct gsm_bts_trx_ts ts[TRX_NR_TS];
776};
777
778#define GSM_BTS_SI2Q(bts, i) (struct gsm48_system_information_type_2quater *)((bts)->si_buf[SYSINFO_TYPE_2quater][i])
779#define GSM_BTS_HAS_SI(bts, i) ((bts)->si_valid & (1 << i))
780#define GSM_BTS_SI(bts, i) (void *)((bts)->si_buf[i][0])
781#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
782
783enum gsm_bts_type {
784 GSM_BTS_TYPE_UNKNOWN,
785 GSM_BTS_TYPE_BS11,
786 GSM_BTS_TYPE_NANOBTS,
787 GSM_BTS_TYPE_RBS2000,
788 GSM_BTS_TYPE_NOKIA_SITE,
789 GSM_BTS_TYPE_OSMOBTS,
790 _NUM_GSM_BTS_TYPE
791};
792
793enum gsm_bts_type_variant {
794 BTS_UNKNOWN,
795 BTS_OSMO_LITECELL15,
796 BTS_OSMO_OCTPHY,
797 BTS_OSMO_SYSMO,
798 BTS_OSMO_TRX,
799 _NUM_BTS_VARIANT
800};
801
802/* Used by OML layer for BTS Attribute reporting */
803enum bts_attribute {
804 BTS_TYPE_VARIANT,
805 BTS_SUB_MODEL,
806 TRX_PHY_VERSION,
807};
808
809struct vty;
810
811struct gsm_bts_model {
812 struct llist_head list;
813
814 enum gsm_bts_type type;
815 enum gsm_bts_type_variant variant;
816 const char *name;
817
818 bool started;
819 int (*start)(struct gsm_network *net);
820 int (*oml_rcvmsg)(struct msgb *msg);
821 char * (*oml_status)(const struct gsm_bts *bts);
822
823 void (*e1line_bind_ops)(struct e1inp_line *line);
824
825 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
826 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
827 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
828
Pau Espin Pedrol167cb822018-11-19 17:48:17 +0100829 /* Should SI2bis and SI2ter be disabled by default on this BTS model? */
830 bool force_combined_si;
831
Neels Hofmeyr10485162018-02-13 23:22:03 +0100832 struct tlv_definition nm_att_tlvdef;
833
834 /* features of a given BTS model set via gsm_bts_model_register() locally */
835 struct bitvec features;
836 uint8_t _features_data[MAX_BTS_FEATURES/8];
837};
838
Neels Hofmeyr10485162018-02-13 23:22:03 +0100839
Neels Hofmeyr10485162018-02-13 23:22:03 +0100840
841/*
842 * This keeps track of the paging status of one BTS. It
843 * includes a number of pending requests, a back pointer
844 * to the gsm_bts, a timer and some more state.
845 */
846struct gsm_bts_paging_state {
847 /* pending requests */
848 struct llist_head pending_requests;
849 struct gsm_bts *bts;
850
851 struct osmo_timer_list work_timer;
852 struct osmo_timer_list credit_timer;
853
854 /* free chans needed */
855 int free_chans_need;
856
857 /* load */
858 uint16_t available_slots;
859};
860
861struct gsm_envabtse {
862 struct gsm_abis_mo mo;
863};
864
865struct gsm_bts_gprs_nsvc {
866 struct gsm_bts *bts;
867 /* data read via VTY config file, to configure the BTS
868 * via OML from BSC */
869 int id;
870 uint16_t nsvci;
871 uint16_t local_port; /* on the BTS */
872 uint16_t remote_port; /* on the SGSN */
873 uint32_t remote_ip; /* on the SGSN */
874
875 struct gsm_abis_mo mo;
876};
877
878enum gprs_rlc_par {
879 RLC_T3142,
880 RLC_T3169,
881 RLC_T3191,
882 RLC_T3193,
883 RLC_T3195,
884 RLC_N3101,
885 RLC_N3103,
886 RLC_N3105,
887 CV_COUNTDOWN,
888 T_DL_TBF_EXT, /* ms */
889 T_UL_TBF_EXT, /* ms */
890 _NUM_RLC_PAR
891};
892
893enum gprs_cs {
894 GPRS_CS1,
895 GPRS_CS2,
896 GPRS_CS3,
897 GPRS_CS4,
898 GPRS_MCS1,
899 GPRS_MCS2,
900 GPRS_MCS3,
901 GPRS_MCS4,
902 GPRS_MCS5,
903 GPRS_MCS6,
904 GPRS_MCS7,
905 GPRS_MCS8,
906 GPRS_MCS9,
907 _NUM_GRPS_CS
908};
909
910struct gprs_rlc_cfg {
911 uint16_t parameter[_NUM_RLC_PAR];
912 struct {
913 uint16_t repeat_time; /* ms */
914 uint8_t repeat_count;
915 } paging;
916 uint32_t cs_mask; /* bitmask of gprs_cs */
917 uint8_t initial_cs;
918 uint8_t initial_mcs;
919};
920
921
922enum neigh_list_manual_mode {
923 NL_MODE_AUTOMATIC = 0,
924 NL_MODE_MANUAL = 1,
925 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
926};
927
928enum bts_loc_fix {
929 BTS_LOC_FIX_INVALID = 0,
930 BTS_LOC_FIX_2D = 1,
931 BTS_LOC_FIX_3D = 2,
932};
933
934extern const struct value_string bts_loc_fix_names[];
935
936struct bts_location {
937 struct llist_head list;
938 time_t tstamp;
939 enum bts_loc_fix valid;
940 double lat;
941 double lon;
942 double height;
943};
944
945/* Channel load counter */
946struct load_counter {
947 unsigned int total;
948 unsigned int used;
949};
950
Neels Hofmeyr19bed232018-03-22 04:54:57 +0100951/* Useful to track N-N relations between BTS, for example neighbors. */
952struct gsm_bts_ref {
953 struct llist_head entry;
954 struct gsm_bts *bts;
955};
956
Neels Hofmeyr10485162018-02-13 23:22:03 +0100957/* One BTS */
958struct gsm_bts {
959 /* list header in net->bts_list */
960 struct llist_head list;
961
962 /* Geographical location of the BTS */
963 struct llist_head loc_list;
964
965 /* number of ths BTS in network */
966 uint8_t nr;
967 /* human readable name / description */
968 char *description;
969 /* Cell Identity */
970 uint16_t cell_identity;
971 /* location area code of this BTS */
972 uint16_t location_area_code;
973 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
974 * which is used as TSC for the CCCH */
975 uint8_t bsic;
976 /* type of BTS */
977 enum gsm_bts_type type;
978 enum gsm_bts_type_variant variant;
979 struct gsm_bts_model *model;
980 enum gsm_band band;
981 char version[MAX_VERSION_LENGTH];
982 char sub_model[MAX_VERSION_LENGTH];
983
984 /* features of a given BTS set/reported via OML */
985 struct bitvec features;
986 uint8_t _features_data[MAX_BTS_FEATURES/8];
987
988 /* Connected PCU version (if any) */
989 char pcu_version[MAX_VERSION_LENGTH];
990
991 /* maximum Tx power that the MS is permitted to use in this cell */
992 int ms_max_power;
993
994 /* how do we talk OML with this TRX? */
995 struct gsm_e1_subslot oml_e1_link;
996 uint8_t oml_tei;
997 struct e1inp_sign_link *oml_link;
Pau Espin Pedrol9862bcb2018-08-22 21:54:12 +0200998 /* Timer to use for deferred drop of OML link, see \ref ipaccess_drop_oml_deferred */
999 struct osmo_timer_list oml_drop_link_timer;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001000 /* when OML link was established */
1001 time_t uptime;
1002
1003 /* Abis network management O&M handle */
1004 struct abis_nm_h *nmh;
1005
1006 struct gsm_abis_mo mo;
1007
1008 /* number of this BTS on given E1 link */
1009 uint8_t bts_nr;
1010
1011 /* DTX features of this BTS */
1012 enum gsm48_dtx_mode dtxu;
1013 bool dtxd;
1014
1015 /* paging state and control */
1016 struct gsm_bts_paging_state paging;
1017
1018 /* CCCH is on C0 */
1019 struct gsm_bts_trx *c0;
1020
1021 struct {
1022 struct gsm_abis_mo mo;
1023 } site_mgr;
1024
1025 /* bitmask of all SI that are present/valid in si_buf */
1026 uint32_t si_valid;
1027 /* 3GPP TS 44.018 Table 10.5.2.33b.1 INDEX and COUNT for SI2quater */
1028 uint8_t si2q_index; /* distinguish individual SI2quater messages */
1029 uint8_t si2q_count; /* si2q_index for the last (highest indexed) individual SI2quater message */
1030 /* buffers where we put the pre-computed SI */
1031 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
1032 /* offsets used while generating SI2quater */
1033 size_t e_offset;
1034 size_t u_offset;
Pau Espin Pedrol1cf21de2018-12-05 13:38:10 +01001035 /* 3GPP TS 08.58 §8.5.1 BCCH INFORMATION. Some nanoBTS fail upon
1036 * receival of empty SI disabling unsupported SI. see OS#3707. */
1037 bool si_unused_send_empty;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001038
1039 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
1040 union {
1041 struct {
1042 uint16_t site_id;
1043 uint16_t bts_id;
1044 uint32_t flags;
1045 uint32_t rsl_ip;
1046 } ip_access;
1047 struct {
1048 struct {
1049 struct gsm_abis_mo mo;
1050 } cclk;
1051 struct {
1052 struct gsm_abis_mo mo;
1053 } rack;
1054 struct gsm_envabtse envabtse[4];
1055 } bs11;
1056 struct {
1057 struct {
1058 struct om2k_mo om2k_mo;
1059 struct gsm_abis_mo mo;
1060 struct llist_head conn_groups;
1061 } cf;
1062 struct {
1063 struct om2k_mo om2k_mo;
1064 struct gsm_abis_mo mo;
1065 struct llist_head conn_groups;
1066 } is;
1067 struct {
1068 struct om2k_mo om2k_mo;
1069 struct gsm_abis_mo mo;
1070 struct llist_head conn_groups;
1071 } con;
1072 struct {
1073 struct om2k_mo om2k_mo;
1074 struct gsm_abis_mo mo;
1075 } dp;
1076 struct {
1077 struct om2k_mo om2k_mo;
1078 struct gsm_abis_mo mo;
1079 } tf;
1080 uint32_t use_superchannel:1;
1081 } rbs2000;
1082 struct {
1083 uint8_t bts_type;
1084 unsigned int configured:1,
1085 skip_reset:1,
1086 no_loc_rel_cnf:1,
1087 bts_reset_timer_cnf,
1088 did_reset:1,
1089 wait_reset:1;
1090 struct osmo_timer_list reset_timer;
1091 } nokia;
1092 };
1093
1094 /* Not entirely sure how ip.access specific this is */
1095 struct {
1096 uint8_t supports_egprs_11bit_rach;
1097 enum bts_gprs_mode mode;
1098 struct {
1099 struct gsm_abis_mo mo;
1100 uint16_t nsei;
1101 uint8_t timer[7];
1102 } nse;
1103 struct {
1104 struct gsm_abis_mo mo;
1105 uint16_t bvci;
1106 uint8_t timer[11];
1107 struct gprs_rlc_cfg rlc_cfg;
1108 } cell;
1109 struct gsm_bts_gprs_nsvc nsvc[2];
1110 uint8_t rac;
1111 uint8_t net_ctrl_ord;
1112 bool ctrl_ack_type_use_block;
1113 } gprs;
1114
1115 /* RACH NM values */
1116 int rach_b_thresh;
1117 int rach_ldavg_slots;
1118
1119 /* transceivers */
1120 int num_trx;
1121 struct llist_head trx_list;
1122
1123 /* SI related items */
1124 int force_combined_si;
Pau Espin Pedrol167cb822018-11-19 17:48:17 +01001125 bool force_combined_si_set;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001126 int bcch_change_mark;
1127
1128 /* Abis NM queue */
1129 struct llist_head abis_queue;
1130 int abis_nm_pend;
1131
1132 struct gsm_network *network;
1133
1134 /* should the channel allocator allocate channels from high TRX to TRX0,
1135 * rather than starting from TRX0 and go upwards? */
1136 int chan_alloc_reverse;
1137
1138 enum neigh_list_manual_mode neigh_list_manual_mode;
1139 /* parameters from which we build SYSTEM INFORMATION */
1140 struct {
1141 struct gsm48_rach_control rach_control;
1142 uint8_t ncc_permitted;
1143 struct gsm48_cell_sel_par cell_sel_par;
1144 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
1145 struct gsm48_cell_options cell_options;
1146 struct gsm48_control_channel_descr chan_desc;
1147 struct bitvec neigh_list;
1148 struct bitvec cell_alloc;
1149 struct bitvec si5_neigh_list;
1150 struct osmo_earfcn_si2q si2quater_neigh_list;
1151 size_t uarfcn_length; /* index for uarfcn and scramble lists */
1152 struct {
1153 /* bitmask large enough for all possible ARFCN's */
1154 uint8_t neigh_list[1024/8];
1155 uint8_t cell_alloc[1024/8];
1156 /* If the user wants a different neighbor list in SI5 than in SI2 */
1157 uint8_t si5_neigh_list[1024/8];
1158 uint8_t meas_bw_list[MAX_EARFCN_LIST];
1159 uint16_t earfcn_list[MAX_EARFCN_LIST];
1160 uint16_t uarfcn_list[MAX_EARFCN_LIST];
1161 uint16_t scramble_list[MAX_EARFCN_LIST];
1162 } data;
1163 } si_common;
1164 bool early_classmark_allowed;
1165 bool early_classmark_allowed_3g;
1166 /* for testing only: Have an infinitely long radio link timeout */
1167 bool infinite_radio_link_timeout;
1168
1169 /* do we use static (user-defined) system information messages? (bitmask) */
1170 uint32_t si_mode_static;
1171
Stefan Sperling6442e432018-02-06 14:44:54 +01001172 /* access control class ramping */
1173 struct acc_ramp acc_ramp;
1174
Neels Hofmeyr10485162018-02-13 23:22:03 +01001175 /* exclude the BTS from the global RF Lock handling */
1176 int excl_from_rf_lock;
1177
1178 /* supported codecs beside FR */
1179 struct bts_codec_conf codec;
1180
1181 /* BTS dependencies bit field */
1182 uint32_t depends_on[256/(8*4)];
1183
1184 /* full and half rate multirate config */
1185 struct amr_multirate_conf mr_full;
1186 struct amr_multirate_conf mr_half;
1187
1188 /* PCU socket state */
1189 char *pcu_sock_path;
1190 struct pcu_sock_state *pcu_state;
1191
1192 struct rate_ctr_group *bts_ctrs;
1193 struct osmo_stat_item_group *bts_statg;
1194
1195 struct handover_cfg *ho;
1196
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001197 /* A list of struct gsm_bts_ref, indicating neighbors of this BTS.
1198 * When the si_common neigh_list is in automatic mode, it is populated from this list as well as
1199 * gsm_network->neighbor_bss_cells. */
1200 struct llist_head local_neighbors;
1201
Neels Hofmeyr10485162018-02-13 23:22:03 +01001202 /* BTS-specific overrides for timer values from struct gsm_network. */
1203 uint8_t T3122; /* ASSIGMENT REJECT wait indication */
Pau Espin Pedrol1b963342018-11-07 14:19:32 +01001204 bool T3113_dynamic; /* Calculate T3113 timeout dynamically based on BTS channel config and load */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001205
1206 /* Periodic channel load measurements are used to maintain T3122. */
1207 struct load_counter chan_load_samples[7];
1208 int chan_load_samples_idx;
Stefan Sperling6442e432018-02-06 14:44:54 +01001209 uint8_t chan_load_avg; /* current channel load average in percent (0 - 100). */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001210};
1211
Oliver Smith8d8d7102018-10-23 15:35:43 +02001212/* One rejected BTS */
1213struct gsm_bts_rejected {
1214 /* list header in net->bts_rejected */
1215 struct llist_head list;
1216
1217 uint16_t site_id;
1218 uint16_t bts_id;
1219 char ip[INET6_ADDRSTRLEN];
1220 time_t time;
1221};
Neels Hofmeyr10485162018-02-13 23:22:03 +01001222
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001223struct gsm_network *gsm_network_init(void *ctx);
1224
Neels Hofmeyr10485162018-02-13 23:22:03 +01001225struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, uint8_t bts_num);
Neels Hofmeyr6d568ed2018-07-09 16:49:18 +02001226struct gsm_bts *gsm_bts_num(const struct gsm_network *net, int num);
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001227bool gsm_bts_matches_lai(const struct gsm_bts *bts, const struct osmo_location_area_id *lai);
1228bool gsm_bts_matches_cell_id(const struct gsm_bts *bts, const struct gsm0808_cell_id *cell_id);
1229struct gsm_bts *gsm_bts_by_cell_id(const struct gsm_network *net,
1230 const struct gsm0808_cell_id *cell_id,
1231 int match_idx);
1232int gsm_bts_local_neighbor_add(struct gsm_bts *bts, struct gsm_bts *neighbor);
1233int gsm_bts_local_neighbor_del(struct gsm_bts *bts, const struct gsm_bts *neighbor);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001234
1235struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
1236struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
1237
1238enum gsm_bts_type str2btstype(const char *arg);
1239const char *btstype2str(enum gsm_bts_type type);
1240
1241enum bts_attribute str2btsattr(const char *s);
1242const char *btsatttr2str(enum bts_attribute v);
1243
1244enum gsm_bts_type_variant str2btsvariant(const char *arg);
1245const char *btsvariant2str(enum gsm_bts_type_variant v);
1246
1247extern const struct value_string gsm_chreq_descs[];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001248extern const struct value_string gsm_pchant_names[];
1249extern const struct value_string gsm_pchant_descs[];
1250extern const struct value_string gsm_pchan_ids[];
Neels Hofmeyr10485162018-02-13 23:22:03 +01001251const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001252static inline const char *gsm_pchan_id(enum gsm_phys_chan_config c)
1253{ return get_value_string(gsm_pchan_ids, c); }
Neels Hofmeyr10485162018-02-13 23:22:03 +01001254enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
1255const char *gsm_lchant_name(enum gsm_chan_t c);
1256const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte57658ec2019-02-04 12:30:44 +01001257char *gsm_bts_name(const struct gsm_bts *bts);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001258char *gsm_trx_name(const struct gsm_bts_trx *trx);
1259char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
1260char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
1261char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001262
1263static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
1264{
1265 return lchan->name;
1266}
1267
Neels Hofmeyr10485162018-02-13 23:22:03 +01001268void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
1269
1270struct gsm_nm_state *
1271gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
1272 const struct abis_om_obj_inst *obj_inst);
1273void *
1274gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
1275 const struct abis_om_obj_inst *obj_inst);
1276
1277/* reset the state of all MO in the BTS */
1278void gsm_bts_mo_reset(struct gsm_bts *bts);
1279
1280uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
1281 uint8_t ts_nr, uint8_t lchan_nr);
1282uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
1283uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
1284 enum gsm_phys_chan_config as_pchan);
1285
Harald Welte251bec12018-09-09 17:14:09 +02001286void gsm48_lchan2chan_desc(struct gsm48_chan_desc *cd,
1287 const struct gsm_lchan *lchan);
Harald Welte24286f32018-09-09 17:17:44 +02001288void gsm48_lchan2chan_desc_as_configured(struct gsm48_chan_desc *cd, const struct gsm_lchan *lchan);
Harald Welte251bec12018-09-09 17:14:09 +02001289
Neels Hofmeyr10485162018-02-13 23:22:03 +01001290/* return the gsm_lchan for the CBCH (if it exists at all) */
1291struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
1292
1293/*
1294 * help with parsing regexps
1295 */
1296int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
1297 int argc, const char **argv) __attribute__ ((warn_unused_result));
1298
1299static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
1300{
1301 if (ts->tsc != -1)
1302 return ts->tsc;
1303 else
1304 return ts->trx->bts->bsic & 7;
1305}
1306
1307struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
1308 int *rc);
1309
1310enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001311uint8_t pchan_subslots(enum gsm_phys_chan_config pchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001312bool ts_is_tch(struct gsm_bts_trx_ts *ts);
1313
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01001314
Harald Welteb7948872017-12-18 18:48:21 +01001315static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection *conn) {
1316 OSMO_ASSERT(conn->lchan);
1317 return conn->lchan->ts->trx->bts;
1318}
1319
Harald Welted82101e2017-12-09 23:07:38 +01001320enum {
1321 BTS_CTR_CHREQ_TOTAL,
1322 BTS_CTR_CHREQ_NO_CHANNEL,
1323 BTS_CTR_CHAN_RF_FAIL,
1324 BTS_CTR_CHAN_RLL_ERR,
1325 BTS_CTR_BTS_OML_FAIL,
1326 BTS_CTR_BTS_RSL_FAIL,
1327 BTS_CTR_CODEC_AMR_F,
1328 BTS_CTR_CODEC_AMR_H,
1329 BTS_CTR_CODEC_EFR,
1330 BTS_CTR_CODEC_V1_FR,
1331 BTS_CTR_CODEC_V1_HR,
Harald Weltecf9d4312017-12-13 23:17:16 +01001332 BTS_CTR_PAGING_ATTEMPTED,
1333 BTS_CTR_PAGING_ALREADY,
1334 BTS_CTR_PAGING_RESPONDED,
1335 BTS_CTR_PAGING_EXPIRED,
Harald Welte4f598922017-12-14 13:47:02 +01001336 BTS_CTR_CHAN_ACT_TOTAL,
1337 BTS_CTR_CHAN_ACT_NACK,
Harald Welte62d9cb02017-12-14 14:00:26 +01001338 BTS_CTR_RSL_UNKNOWN,
Harald Welte581398a2017-12-14 14:29:44 +01001339 BTS_CTR_RSL_IPA_NACK,
Harald Welte00d64fd2017-12-14 14:34:16 +01001340 BTS_CTR_MODE_MODIFY_NACK,
Harald Welted82101e2017-12-09 23:07:38 +01001341};
1342
1343static const struct rate_ctr_desc bts_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001344 [BTS_CTR_CHREQ_TOTAL] = {"chreq:total", "Received channel requests."},
1345 [BTS_CTR_CHREQ_NO_CHANNEL] = {"chreq:no_channel", "Sent to MS no channel available."},
1346 [BTS_CTR_CHAN_RF_FAIL] = {"chan:rf_fail", "Received a RF failure indication from BTS."},
1347 [BTS_CTR_CHAN_RLL_ERR] = {"chan:rll_err", "Received a RLL failure with T200 cause from BTS."},
Harald Welted82101e2017-12-09 23:07:38 +01001348 [BTS_CTR_BTS_OML_FAIL] = {"oml_fail", "Received a TEI down on a OML link."},
1349 [BTS_CTR_BTS_RSL_FAIL] = {"rsl_fail", "Received a TEI down on a OML link."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001350 [BTS_CTR_CODEC_AMR_F] = {"codec:amr_f", "Count the usage of AMR/F codec by channel mode requested."},
1351 [BTS_CTR_CODEC_AMR_H] = {"codec:amr_h", "Count the usage of AMR/H codec by channel mode requested."},
1352 [BTS_CTR_CODEC_EFR] = {"codec:efr", "Count the usage of EFR codec by channel mode requested."},
1353 [BTS_CTR_CODEC_V1_FR] = {"codec:fr", "Count the usage of FR codec by channel mode requested."},
1354 [BTS_CTR_CODEC_V1_HR] = {"codec:hr", "Count the usage of HR codec by channel mode requested."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001355
1356 [BTS_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
1357 [BTS_CTR_PAGING_ALREADY] = {"paging:already", "Paging attempts ignored as subsciber was already being paged."},
1358 [BTS_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful paging response."},
1359 [BTS_CTR_PAGING_EXPIRED] = {"paging:expired", "Paging Request expired because of timeout T3113."},
Harald Welte4f598922017-12-14 13:47:02 +01001360 [BTS_CTR_CHAN_ACT_TOTAL] = {"chan_act:total", "Total number of Channel Activations."},
1361 [BTS_CTR_CHAN_ACT_NACK] = {"chan_act:nack", "Number of Channel Activations that the BTS NACKed"},
Harald Welte62d9cb02017-12-14 14:00:26 +01001362 [BTS_CTR_RSL_UNKNOWN] = {"rsl:unknown", "Number of unknown/unsupported RSL messages received from BTS"},
Harald Welte581398a2017-12-14 14:29:44 +01001363 [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 +01001364 [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 +01001365};
1366
1367static const struct rate_ctr_group_desc bts_ctrg_desc = {
1368 "bts",
1369 "base transceiver station",
1370 OSMO_STATS_CLASS_GLOBAL,
1371 ARRAY_SIZE(bts_ctr_description),
1372 bts_ctr_description,
1373};
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001374
Alexander Couzens20423ea2016-07-12 15:42:02 +02001375enum {
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001376 BTS_STAT_CHAN_LOAD_AVERAGE,
1377 BTS_STAT_T3122,
1378};
1379
1380enum {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001381 BSC_CTR_ASSIGNMENT_ATTEMPTED,
1382 BSC_CTR_ASSIGNMENT_COMPLETED,
1383 BSC_CTR_ASSIGNMENT_STOPPED,
1384 BSC_CTR_ASSIGNMENT_NO_CHANNEL,
1385 BSC_CTR_ASSIGNMENT_TIMEOUT,
1386 BSC_CTR_ASSIGNMENT_FAILED,
1387 BSC_CTR_ASSIGNMENT_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001388 BSC_CTR_HANDOVER_ATTEMPTED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001389 BSC_CTR_HANDOVER_COMPLETED,
1390 BSC_CTR_HANDOVER_STOPPED,
Alexander Couzensb847a212016-08-02 11:34:11 +02001391 BSC_CTR_HANDOVER_NO_CHANNEL,
1392 BSC_CTR_HANDOVER_TIMEOUT,
Alexander Couzensb847a212016-08-02 11:34:11 +02001393 BSC_CTR_HANDOVER_FAILED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001394 BSC_CTR_HANDOVER_ERROR,
1395 BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED,
1396 BSC_CTR_INTER_BSC_HO_OUT_COMPLETED,
1397 BSC_CTR_INTER_BSC_HO_OUT_STOPPED,
1398 BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT,
1399 BSC_CTR_INTER_BSC_HO_OUT_ERROR,
1400 BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED,
1401 BSC_CTR_INTER_BSC_HO_IN_COMPLETED,
1402 BSC_CTR_INTER_BSC_HO_IN_STOPPED,
1403 BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL,
1404 BSC_CTR_INTER_BSC_HO_IN_FAILED,
1405 BSC_CTR_INTER_BSC_HO_IN_TIMEOUT,
1406 BSC_CTR_INTER_BSC_HO_IN_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001407 BSC_CTR_PAGING_ATTEMPTED,
1408 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +01001409 BSC_CTR_PAGING_RESPONDED,
Stefan Sperling7926d982018-05-17 14:52:02 +02001410 BSC_CTR_UNKNOWN_UNIT_ID,
Alexander Couzensb847a212016-08-02 11:34:11 +02001411};
1412
1413static const struct rate_ctr_desc bsc_ctr_description[] = {
Neels Hofmeyrdbb38d52018-07-11 19:53:56 +02001414 [BSC_CTR_ASSIGNMENT_ATTEMPTED] = {"assignment:attempted", "Assignment attempts."},
1415 [BSC_CTR_ASSIGNMENT_COMPLETED] = {"assignment:completed", "Assignment completed."},
1416 [BSC_CTR_ASSIGNMENT_STOPPED] = {"assignment:stopped", "Connection ended during Assignment."},
1417 [BSC_CTR_ASSIGNMENT_NO_CHANNEL] = {"assignment:no_channel", "Failure to allocate lchan for Assignment."},
1418 [BSC_CTR_ASSIGNMENT_TIMEOUT] = {"assignment:timeout", "Assignment timed out."},
1419 [BSC_CTR_ASSIGNMENT_FAILED] = {"assignment:failed", "Received Assignment Failure message."},
1420 [BSC_CTR_ASSIGNMENT_ERROR] = {"assignment:error", "Assigment failed for other reason."},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001421
1422 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Intra-BSC handover attempts."},
1423 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Intra-BSC handover completed."},
1424 [BSC_CTR_HANDOVER_STOPPED] = {"handover:stopped", "Connection ended during HO."},
1425 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Failure to allocate lchan for HO."},
1426 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Handover timed out."},
1427 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Received Handover Fail messages."},
1428 [BSC_CTR_HANDOVER_ERROR] = {"handover:error", "Re-assigment failed for other reason."},
1429
1430 [BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED] = {"interbsc_ho_out:attempted",
1431 "Attempts to handover to remote BSS."},
1432 [BSC_CTR_INTER_BSC_HO_OUT_COMPLETED] = {"interbsc_ho_out:completed",
1433 "Handover to remote BSS completed."},
1434 [BSC_CTR_INTER_BSC_HO_OUT_STOPPED] = {"interbsc_ho_out:stopped", "Connection ended during HO."},
1435 [BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT] = {"interbsc_ho_out:timeout", "Handover timed out."},
1436 [BSC_CTR_INTER_BSC_HO_OUT_ERROR] = {"interbsc_ho_out:error",
1437 "Handover to remote BSS failed for other reason."},
1438
1439 [BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED] = {"interbsc_ho_in:attempted",
1440 "Attempts to handover from remote BSS."},
1441 [BSC_CTR_INTER_BSC_HO_IN_COMPLETED] = {"interbsc_ho_in:completed",
1442 "Handover from remote BSS completed."},
1443 [BSC_CTR_INTER_BSC_HO_IN_STOPPED] = {"interbsc_ho_in:stopped", "Connection ended during HO."},
1444 [BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL] = {"interbsc_ho_in:no_channel",
1445 "Failure to allocate lchan for HO."},
1446 [BSC_CTR_INTER_BSC_HO_IN_TIMEOUT] = {"interbsc_ho_in:timeout", "Handover from remote BSS timed out."},
1447 [BSC_CTR_INTER_BSC_HO_IN_FAILED] = {"interbsc_ho_in:failed", "Received Handover Fail message."},
1448 [BSC_CTR_INTER_BSC_HO_IN_ERROR] = {"interbsc_ho_in:error",
1449 "Handover from remote BSS failed for other reason."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001450
1451 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001452 [BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Paging request send failures because no responsible BTS was found."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001453 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response."},
Stefan Sperling7926d982018-05-17 14:52:02 +02001454
1455 [BSC_CTR_UNKNOWN_UNIT_ID] = {"abis:unknown_unit_id", "Connection attempts from unknown IPA CCM Unit ID."},
Alexander Couzensb847a212016-08-02 11:34:11 +02001456};
1457
Alexander Couzensb847a212016-08-02 11:34:11 +02001458
1459
1460static const struct rate_ctr_group_desc bsc_ctrg_desc = {
1461 "bsc",
1462 "base station controller",
1463 OSMO_STATS_CLASS_GLOBAL,
1464 ARRAY_SIZE(bsc_ctr_description),
1465 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +02001466};
1467
Neels Hofmeyr73983952016-05-10 13:29:33 +02001468struct gsm_tz {
1469 int override; /* if 0, use system's time zone instead. */
1470 int hr; /* hour */
1471 int mn; /* minute */
1472 int dst; /* daylight savings */
1473};
1474
Harald Welte52b1f982008-12-23 20:25:15 +00001475struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001476 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
1477 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
1478 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
1479 * these have in common, like country and network code, put in yet
1480 * separate structs and placed as members in osmo_bsc and osmo_msc. */
1481
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001482 struct osmo_plmn_id plmn;
1483
Harald Welte51e4bf32017-12-23 17:30:18 +01001484 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
1485 uint8_t a5_encryption_mask;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001486 int neci;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001487
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001488 struct handover_cfg *ho;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001489 struct {
1490 unsigned int congestion_check_interval_s;
1491 struct osmo_timer_list congestion_check_timer;
1492 } hodec2;
Harald Welte52b1f982008-12-23 20:25:15 +00001493
Alexander Couzensb847a212016-08-02 11:34:11 +02001494 struct rate_ctr_group *bsc_ctrs;
Harald Welte24ff6ee2009-12-22 00:41:05 +01001495
Harald Welte52b1f982008-12-23 20:25:15 +00001496 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +02001497 struct llist_head bts_list;
Oliver Smith8d8d7102018-10-23 15:35:43 +02001498 struct llist_head bts_rejected;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001499
Neels Hofmeyr596c4022018-06-16 19:29:50 +02001500 /* shall reference gsm_network_T[] */
Neels Hofmeyra6078fe2019-01-28 03:52:14 +01001501 struct osmo_tdef *T_defs;
Harald Welteeab84a12009-12-13 10:53:12 +01001502
Alexander Couzens547c2072017-11-21 12:03:04 +01001503 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +08001504
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +08001505 /* Use a TCH for handling requests of type paging any */
1506 int pag_any_tch;
1507
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08001508 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +02001509 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +01001510
Daniel Willmann6fc4a982011-07-22 17:55:42 +02001511 /* control interface */
1512 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +02001513
1514 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
1515 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +02001516
1517 /* all active subscriber connections. */
1518 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +02001519
1520 /* if override is nonzero, this timezone data is used for all MM
1521 * contexts. */
1522 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
1523 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +01001524 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +02001525 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +01001526
1527 /* List of all struct bsc_subscr used in libbsc. This llist_head is
1528 * allocated so that the llist_head pointer itself can serve as a
1529 * talloc context (useful to not have to pass the entire gsm_network
1530 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
1531 * not require gsm_data.h). In an MSC-without-BSC environment, this
1532 * pointer is NULL to indicate absence of a bsc_subscribers list. */
1533 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +02001534
Stefan Sperling6cee8932018-01-30 18:14:22 +01001535 /* Timer for periodic channel load measurements to maintain each BTS's T3122. */
1536 struct osmo_timer_list t3122_chan_load_timer;
1537
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001538 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +02001539 struct mgcp_client_conf *conf;
1540 struct mgcp_client *client;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +02001541 struct osmo_tdef *tdefs;
Philipp Maier39c609b2017-09-27 15:51:34 +02001542 } mgw;
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001543
1544 /* Remote BSS Cell Identifier Lists */
1545 struct neighbor_ident_list *neighbor_bss_cells;
Harald Welte7e310b12009-03-30 20:56:32 +00001546};
1547
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001548struct gsm_audio_support {
1549 uint8_t hr : 1,
1550 ver : 7;
1551};
1552
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001553static inline const struct osmo_location_area_id *bts_lai(struct gsm_bts *bts)
1554{
1555 static struct osmo_location_area_id lai;
1556 lai = (struct osmo_location_area_id){
1557 .plmn = bts->network->plmn,
1558 .lac = bts->location_area_code,
1559 };
1560 return &lai;
1561}
1562
Neels Hofmeyrc13e6872016-05-11 13:53:47 +02001563extern void talloc_ctx_init(void *ctx_root);
1564
Harald Welte39315c42010-01-10 18:01:52 +01001565int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +02001566
Harald Welte1d014a52009-08-08 15:38:29 +02001567enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +02001568const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +00001569struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
1570 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +00001571
Andreas Eversberg8226fa72009-06-29 15:19:38 +02001572extern void *tall_bsc_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +02001573
Harald Weltef383aa12012-07-02 19:51:55 +02001574/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +00001575static inline int is_ipaccess_bts(struct gsm_bts *bts)
1576{
1577 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001578 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001579 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +00001580 return 1;
1581 default:
1582 break;
1583 }
1584 return 0;
1585}
1586
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001587static inline int is_sysmobts_v2(struct gsm_bts *bts)
1588{
1589 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +01001590 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001591 return 1;
1592 default:
1593 break;
1594 }
1595 return 0;
1596}
1597
Harald Welte5b570672009-08-10 10:08:01 +02001598static inline int is_siemens_bts(struct gsm_bts *bts)
1599{
1600 switch (bts->type) {
1601 case GSM_BTS_TYPE_BS11:
1602 return 1;
1603 default:
1604 break;
1605 }
1606
1607 return 0;
1608}
1609
Andreas Eversberg7d8fa342013-12-05 13:25:06 +01001610static inline int is_nokia_bts(struct gsm_bts *bts)
1611{
1612 switch (bts->type) {
1613 case GSM_BTS_TYPE_NOKIA_SITE:
1614 return 1;
1615 default:
1616 break;
1617 }
1618
1619 return 0;
1620}
1621
Andreas Eversbergdcf38e12013-12-05 14:37:11 +01001622static inline int is_e1_bts(struct gsm_bts *bts)
1623{
1624 switch (bts->type) {
1625 case GSM_BTS_TYPE_BS11:
1626 case GSM_BTS_TYPE_RBS2000:
1627 case GSM_BTS_TYPE_NOKIA_SITE:
1628 return 1;
1629 default:
1630 break;
1631 }
1632
1633 return 0;
1634}
1635
Harald Welte1876c312018-05-27 11:53:43 +02001636extern struct gsm_network *bsc_gsmnet;
1637
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001638enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +02001639const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001640int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +02001641
Neels Hofmeyr4d358c02018-02-22 03:19:05 +01001642void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +08001643void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +01001644
Harald Weltefbda4e12010-03-04 11:04:52 +01001645int gsm_bts_model_register(struct gsm_bts_model *model);
1646
Harald Welte3561bd42018-01-28 03:04:16 +01001647struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *network);
Neels Hofmeyr42eb0142016-05-20 17:15:44 +02001648
1649struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
1650void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +08001651
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001652struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, uint8_t bsic);
1653struct 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 +01001654
Harald Welte3300c012011-06-05 13:31:33 +02001655void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
1656 uint8_t e1_ts, uint8_t e1_ts_ss);
1657
Maxbe356ed2017-09-07 19:10:09 +02001658void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Harald Welte3300c012011-06-05 13:31:33 +02001659struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +01001660int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -04001661int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +02001662
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +02001663/* generic E1 line operations for all ISDN-based BTS. */
1664extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
1665
Harald Weltee555c2b2012-08-17 13:02:12 +02001666extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
1667extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
1668
Max3d049d22017-10-09 17:12:53 +02001669char *get_model_oml_status(const struct gsm_bts *bts);
1670
Max25cc4072017-10-10 14:50:35 +02001671unsigned long long bts_uptime(const struct gsm_bts *bts);
1672
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +01001673/* control interface handling */
1674int bsc_base_ctrl_cmds_install(void);
1675
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001676/* dependency handling */
1677void bts_depend_mark(struct gsm_bts *bts, int dep);
1678void bts_depend_clear(struct gsm_bts *bts, int dep);
1679int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +01001680int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001681
Harald Welte2f8b9d22017-06-18 11:12:13 +03001682int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
1683void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
1684
Harald Weltea43e0b42016-06-19 18:06:02 +02001685bool classmark_is_r99(struct gsm_classmark *cm);
1686
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001687bool trx_is_usable(const struct gsm_bts_trx *trx);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001688bool ts_is_usable(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001689
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001690int gsm_lchan_type_by_pchan(enum gsm_phys_chan_config pchan);
1691enum gsm_phys_chan_config gsm_pchan_by_lchan_type(enum gsm_chan_t type);
1692
1693void gsm_bts_all_ts_dispatch(struct gsm_bts *bts, uint32_t ts_ev, void *data);
1694void gsm_trx_all_ts_dispatch(struct gsm_bts_trx *trx, uint32_t ts_ev, void *data);
1695
1696int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001697
Harald Welte6be350c2011-05-25 13:10:08 +02001698#endif /* _GSM_DATA_H */