blob: 47849357f7dad8a219b10aa441ee644fb7a569a2 [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 <sys/types.h>
Maxe6052c42016-06-30 10:25:49 +02006#include <stdbool.h>
Neels Hofmeyr10485162018-02-13 23:22:03 +01007#include <stdint.h>
Harald Weltef142c972011-05-24 13:25:38 +02008
9#include <osmocom/core/timer.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020010#include <osmocom/core/rate_ctr.h>
Harald Welte6be350c2011-05-25 13:10:08 +020011#include <osmocom/core/select.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020012#include <osmocom/core/stats.h>
Stefan Sperling81dc9e72018-02-05 17:34:36 +010013#include <osmocom/core/stat_item.h>
Philipp Maier8c498fc2018-02-21 13:24:36 +010014#include <osmocom/gsm/bts_features.h>
Neels Hofmeyra60f3442018-02-12 16:44:32 +010015#include <osmocom/gsm/protocol/gsm_08_08.h>
Harald Welted41b7c72019-06-13 09:41:58 +020016#include <osmocom/gsm/protocol/gsm_48_049.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>
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/neighbor_ident.h>
Pau Espin Pedrol83c0f762019-04-16 20:05:32 +020035#include <osmocom/bsc/osmux.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;
Pau Espin Pedrol83c0f762019-04-16 20:05:32 +0200123 bool use_osmux;
124 uint8_t osmux_cid;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200125
Sylvain Munautaa824922019-03-07 16:32:02 +0100126 /* Rate/codec setting in preference order (need at least 1 !) */
127 int n_ch_mode_rate;
128 struct channel_mode_and_rate ch_mode_rate[3];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200129};
130
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100131/* State of an ongoing Assignment, while the assignment_fsm is still busy. This serves as state separation to keep the
132 * currently used lchan and gscon unmodified until the outcome of an Assignment is known. If the Assignment fails, this
133 * state is simply discarded, and the gscon carries on with the original lchan remaining unchanged. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200134struct assignment_fsm_data {
135 struct assignment_request req;
136 bool requires_voice_stream;
137
138 struct osmo_fsm_inst *fi;
139 struct gsm_lchan *new_lchan;
140
141 /* Whether this assignment triggered creation of the MGW endpoint: if the assignment
142 * fails, we will release that again as soon as possible. (If false, the endpoint already
143 * existed before or isn't needed at all.)*/
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200144 struct osmo_mgcpc_ep_ci *created_ci_for_msc;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200145
146 enum gsm0808_cause failure_cause;
147 enum gsm48_rr_cause rr_cause;
148
149 bool result_rate_ctr_done;
150};
151
152enum hodec_id {
153 HODEC_NONE,
154 HODEC1 = 1,
155 HODEC2 = 2,
156 HODEC_USER,
157 HODEC_REMOTE,
158};
159
160/* For example, to count specific kinds of ongoing handovers, it is useful to be able to OR-combine
161 * scopes. */
162enum handover_scope {
163 HO_NO_HANDOVER = 0,
164 HO_INTRA_CELL = 0x1,
165 HO_INTRA_BSC = 0x2,
166 HO_INTER_BSC_OUT = 0x4,
167 HO_INTER_BSC_IN = 0x8,
168 HO_SCOPE_ALL = 0xffff,
169};
170
171extern const struct value_string handover_scope_names[];
172inline static const char *handover_scope_name(enum handover_scope val)
173{ return get_value_string(handover_scope_names, val); }
174
175struct handover_out_req {
176 enum hodec_id from_hodec_id;
177 struct gsm_lchan *old_lchan;
178 struct neighbor_ident_key target_nik;
179 enum gsm_chan_t new_lchan_type; /*< leave GSM_LCHAN_NONE to use same as old_lchan */
180};
181
182struct handover_in_req {
183 struct gsm0808_channel_type ct;
184 struct gsm0808_speech_codec_list scl;
185 struct gsm0808_encrypt_info ei;
186 struct gsm_classmark classmark;
Neels Hofmeyrc15f6cd2019-03-15 02:48:39 +0100187 /* chosen_encr_alg reflects the encoded value as in RSL_ENC_ALG_A5(a5_numer):
188 * chosen_encr_alg == 1 means A5/0 i.e. no encryption, chosen_encr_alg == 4 means A5/3.
189 * chosen_encr_alg == 0 means no such IE was present. */
190 uint8_t chosen_encr_alg;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200191 struct gsm0808_cell_id cell_id_serving;
192 char cell_id_serving_name[64];
193 struct gsm0808_cell_id cell_id_target;
194 char cell_id_target_name[64];
195 uint16_t msc_assigned_cic;
196 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
197 uint16_t msc_assigned_rtp_port;
198};
199
200struct handover {
201 struct osmo_fsm_inst *fi;
202
203 enum hodec_id from_hodec_id;
204 enum handover_scope scope;
205 enum gsm_chan_t new_lchan_type;
206 struct neighbor_ident_key target_cell;
207
208 uint8_t ho_ref;
209 struct gsm_bts *new_bts;
210 struct gsm_lchan *new_lchan;
211 bool async;
212 struct handover_in_req inter_bsc_in;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200213 struct osmo_mgcpc_ep_ci *created_ci_for_msc;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200214};
215
Neels Hofmeyr378a4922016-05-09 21:07:43 +0200216/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100217struct gsm_subscriber_connection {
Harald Weltea43e0b42016-06-19 18:06:02 +0200218 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +0800219 struct llist_head entry;
220
Harald Welte3561bd42018-01-28 03:04:16 +0100221 /* FSM instance to control the subscriber connection state (RTP, A) */
222 struct osmo_fsm_inst *fi;
223
Harald Weltea43e0b42016-06-19 18:06:02 +0200224 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100225 struct bsc_subscr *bsub;
226
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100227 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200228 struct gsm_network *network;
229
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100230 /* the primary / currently active lchan to the BTS/subscriber. During Assignment and Handover, separate lchans
231 * are kept in the .assignment or .handover sub-structs, respectively, so that this lchan remains unaffected
232 * until Assignment or Handover have actually succeeded. */
Harald Welte4a8ebc82017-12-18 18:34:41 +0100233 struct gsm_lchan *lchan;
Harald Welte3561bd42018-01-28 03:04:16 +0100234
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100235 /* Only valid during an ongoing Assignment; might be overwritten at any time by a failed Assignment attempt.
236 * Once an Assignment was successful, all relevant state must be copied out of this sub-struct. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200237 struct assignment_fsm_data assignment;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100238
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100239 /* handover information, if a handover is pending for this conn. Valid only during an ongoing Handover
240 * operation. If a Handover was successful, all relevant state must be copied out of this sub-struct. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200241 struct handover ho;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100242
Neels Hofmeyr149160f2018-06-16 17:20:13 +0200243 /* Queue DTAP messages during handover/assignment (msgb_enqueue()/msgb_dequeue())*/
244 struct llist_head dtap_queue;
245 unsigned int dtap_queue_len;
Andreas Eversberg084b4212013-05-30 14:12:48 +0200246
Neels Hofmeyrec422642018-02-15 14:07:40 +0100247 struct {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100248 int failures;
Neels Hofmeyrec422642018-02-15 14:07:40 +0100249 struct penalty_timers *penalty_timers;
250 } hodec2;
Neels Hofmeyra60f3442018-02-12 16:44:32 +0100251
252 /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment Request. 3GPP 48.008
253 * 3.2.2.103 says:
254 * The "Codec List (MSC Preferred)" shall not include codecs
255 * that are not supported by the MS.
256 * i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed the MS bearer
257 * capabilities, which the MSC is required to translate into the codec list. */
258 struct gsm0808_speech_codec_list codec_list;
Harald Welte519c7e12018-01-28 02:45:46 +0100259
260 /* flag to prevent multiple simultaneous ciphering commands */
261 int ciphering_handled;
262
263 /* state related to welcome USSD */
264 uint8_t new_subscriber;
265
Harald Welte519c7e12018-01-28 02:45:46 +0100266 /* SCCP connection associatd with this subscriber_connection */
267 struct {
268 /* for advanced ping/pong */
269 int send_ping;
270
Martin Haukea29affd2019-11-13 22:10:41 +0100271 /* SCCP connection related */
Harald Welte519c7e12018-01-28 02:45:46 +0100272 struct bsc_msc_data *msc;
273
274 /* Sigtran connection ID */
275 int conn_id;
276 enum subscr_sccp_state state;
277 } sccp;
278
279 /* for audio handling */
280 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200281 uint16_t msc_assigned_cic;
Harald Welte519c7e12018-01-28 02:45:46 +0100282
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200283 /* RTP address where the MSC expects us to send the RTP stream coming from the BTS. */
284 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
285 uint16_t msc_assigned_rtp_port;
Harald Welte519c7e12018-01-28 02:45:46 +0100286
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200287 /* The endpoint at the MGW used to join both BTS and MSC side connections, e.g.
288 * "rtpbridge/23@mgw". */
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200289 struct osmo_mgcpc_ep *mgw_endpoint;
Harald Welte3561bd42018-01-28 03:04:16 +0100290
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200291 /* The connection identifier of the osmo_mgcpc_ep used to transceive RTP towards the MSC.
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200292 * (The BTS side CI is handled by struct gsm_lchan and the lchan_fsm.) */
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200293 struct osmo_mgcpc_ep_ci *mgw_endpoint_ci_msc;
Harald Welte519c7e12018-01-28 02:45:46 +0100294 } user_plane;
Harald Weltec997ceb2018-05-30 01:39:43 +0200295
296 /* LCLS (local call, local switch) related state */
297 struct {
298 uint8_t global_call_ref[15];
299 uint8_t global_call_ref_len; /* length of global_call_ref */
Maxfe65ece2018-11-09 13:36:11 +0100300 enum gsm0808_lcls_config config; /* TS 48.008 3.2.2.116 */
301 enum gsm0808_lcls_control control; /* TS 48.008 3.2.2.117 */
Harald Weltec997ceb2018-05-30 01:39:43 +0200302 /* LCLS FSM */
303 struct osmo_fsm_inst *fi;
304 /* pointer to "other" connection, if Call Leg Relocation was successful */
305 struct gsm_subscriber_connection *other;
306 } lcls;
Pau Espin Pedrol7950e5d2019-10-31 15:59:49 +0100307
308 /* MS Power Class, TS 05.05 sec 4.1.1 "Mobile station". 0 means unset. */
309 uint8_t ms_power_class:3;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100310};
311
Harald Weltef142c972011-05-24 13:25:38 +0200312
Neels Hofmeyr10485162018-02-13 23:22:03 +0100313/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 Table 10.5.2.33b.1:
314 4-bit index is used (2#1111 = 10#15) */
315#define SI2Q_MAX_NUM 16
316/* length in bits (for single SI2quater message) */
317#define SI2Q_MAX_LEN 160
318#define SI2Q_MIN_LEN 18
319
320struct osmo_bsc_data;
321
322struct osmo_bsc_sccp_con;
323
324/* Channel Request reason */
325enum gsm_chreq_reason_t {
326 GSM_CHREQ_REASON_EMERG,
327 GSM_CHREQ_REASON_PAG,
328 GSM_CHREQ_REASON_CALL,
329 GSM_CHREQ_REASON_LOCATION_UPD,
330 GSM_CHREQ_REASON_OTHER,
331 GSM_CHREQ_REASON_PDCH,
332};
333
334/* lchans 0..3 are SDCCH in combined channel configuration,
335 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
336#define CCCH_LCHAN 4
337
338#define TRX_NR_TS 8
339#define TS_MAX_LCHAN 8
340
341#define HARDCODED_ARFCN 123
342#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
343
344/* for multi-drop config */
345#define HARDCODED_BTS0_TS 1
346#define HARDCODED_BTS1_TS 6
347#define HARDCODED_BTS2_TS 11
348
349#define MAX_VERSION_LENGTH 64
350
Neels Hofmeyr10485162018-02-13 23:22:03 +0100351enum gsm_hooks {
352 GSM_HOOK_NM_SWLOAD,
353 GSM_HOOK_RR_PAGING,
354 GSM_HOOK_RR_SECURITY,
355};
356
Neels Hofmeyr10485162018-02-13 23:22:03 +0100357enum bts_gprs_mode {
358 BTS_GPRS_NONE = 0,
359 BTS_GPRS_GPRS = 1,
360 BTS_GPRS_EGPRS = 2,
361};
362
363struct gsm_lchan;
364struct osmo_rtp_socket;
365struct rtp_socket;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100366
367/* Network Management State */
368struct gsm_nm_state {
369 uint8_t operational;
370 uint8_t administrative;
371 uint8_t availability;
372};
373
374struct gsm_abis_mo {
375 uint8_t obj_class;
376 uint8_t procedure_pending;
377 struct abis_om_obj_inst obj_inst;
378 const char *name;
379 struct gsm_nm_state nm_state;
380 struct tlv_parsed *nm_attr;
381 struct gsm_bts *bts;
382};
383
384/* Ericsson OM2000 Managed Object */
385struct abis_om2k_mo {
386 uint8_t class;
387 uint8_t bts;
388 uint8_t assoc_so;
389 uint8_t inst;
390} __attribute__ ((packed));
391
392struct om2k_mo {
393 struct abis_om2k_mo addr;
394 struct osmo_fsm_inst *fsm;
395};
396
397#define A38_XOR_MIN_KEY_LEN 12
398#define A38_XOR_MAX_KEY_LEN 16
399#define A38_COMP128_KEY_LEN 16
400#define RSL_ENC_ALG_A5(x) (x+1)
401#define MAX_EARFCN_LIST 32
402
403/* is the data link established? who established it? */
404#define LCHAN_SAPI_UNUSED 0
405#define LCHAN_SAPI_MS 1
406#define LCHAN_SAPI_NET 2
Neels Hofmeyr10485162018-02-13 23:22:03 +0100407
408/* BTS ONLY */
409#define MAX_NUM_UL_MEAS 104
410#define LC_UL_M_F_L1_VALID (1 << 0)
411#define LC_UL_M_F_RES_VALID (1 << 1)
412
413struct bts_ul_meas {
414 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
415 uint16_t ber10k;
416 /* timing advance offset (in quarter bits) */
417 int16_t ta_offs_qbits;
418 /* C/I ratio in dB */
419 float c_i;
420 /* flags */
421 uint8_t is_sub:1;
422 /* RSSI in dBm * -1 */
423 uint8_t inv_rssi;
424};
425
426struct bts_codec_conf {
427 uint8_t hr;
428 uint8_t efr;
429 uint8_t amr;
430};
431
432struct amr_mode {
433 uint8_t mode;
434 uint8_t threshold;
435 uint8_t hysteresis;
436};
437
438struct amr_multirate_conf {
439 uint8_t gsm48_ie[2];
440 struct amr_mode ms_mode[4];
441 struct amr_mode bts_mode[4];
442 uint8_t num_modes;
443};
444/* /BTS ONLY */
445
446enum lchan_csd_mode {
447 LCHAN_CSD_M_NT,
448 LCHAN_CSD_M_T_1200_75,
449 LCHAN_CSD_M_T_600,
450 LCHAN_CSD_M_T_1200,
451 LCHAN_CSD_M_T_2400,
452 LCHAN_CSD_M_T_9600,
453 LCHAN_CSD_M_T_14400,
454 LCHAN_CSD_M_T_29000,
455 LCHAN_CSD_M_T_32000,
456};
457
458/* State of the SAPIs in the lchan */
459enum lchan_sapi_state {
460 LCHAN_SAPI_S_NONE,
461 LCHAN_SAPI_S_REQ,
462 LCHAN_SAPI_S_ASSIGNED,
463 LCHAN_SAPI_S_REL,
464 LCHAN_SAPI_S_ERROR,
465};
466
Neels Hofmeyr92b9f2e2018-02-14 00:19:11 +0100467#define MAX_A5_KEY_LEN (128/8)
468
469struct gsm_encr {
470 uint8_t alg_id;
471 uint8_t key_len;
472 uint8_t key[MAX_A5_KEY_LEN];
473};
474
Neels Hofmeyr8da22332018-04-11 01:43:41 +0200475#define LOGPLCHAN(lchan, ss, level, fmt, args...) \
476 LOGP(ss, level, "%s (ss=%d,%s) (%s) " fmt, \
477 lchan ? gsm_ts_and_pchan_name(lchan->ts) : "-", \
478 lchan ? lchan->nr : 0, \
479 lchan ? gsm_lchant_name(lchan->type) : "-", \
480 bsc_subscr_name(lchan && lchan->conn ? lchan->conn->bsub : NULL), \
481 ## args)
482
Pau Espin Pedrold3e8e0c2018-11-28 16:35:10 +0100483/* Iterate lchans that have an FSM allocated based based on explicit pchan kind
484 * (GSM_PCHAN_* constant).
485 * Remark: PDCH related lchans are not handled in BSC but in PCU, so trying to
486 * iterate through GSM_PCHAN_PDCH is considered a void loop.
487 */
488#define ts_as_pchan_for_each_lchan(lchan, ts, as_pchan) \
489 for (lchan = (ts)->lchan; \
490 ((lchan - (ts)->lchan) < ARRAY_SIZE((ts)->lchan)) \
491 && lchan->fi \
492 && lchan->nr < pchan_subslots(as_pchan); \
493 lchan++)
494
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100495/* Iterate lchans that have an FSM allocated based on current PCHAN
496 * mode set in \ref ts.
497 * usage:
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200498 * struct gsm_lchan *lchan;
499 * struct gsm_bts_trx_ts *ts = get_some_timeslot();
500 * ts_for_each_lchan(lchan, ts) {
501 * LOGPLCHAN(DMAIN, LOGL_DEBUG, "hello world\n");
502 * }
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100503 */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200504#define ts_for_each_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_is)
505
Pau Espin Pedrol0ba20df2018-11-28 16:39:29 +0100506/* Iterate over all possible lchans available that have an FSM allocated based
507 * on PCHAN \ref ts (dynamic) configuration.
508 * Iterate all lchan instances set up by this \ref ts type, including those
509 * lchans currently disabled or in process of being enabled (e.g. due to dynamic
510 * timeslot in switchover). Compare ts_for_each_lchan(), which iterates only the
511 * enabled lchans.
512 * For example, it is useful in case dynamic timeslot \ref ts is in process of
513 * switching from configuration PDCH (no lchans) to TCH_F (1 lchan), where
514 * pchan_is is still set to PDCH but \ref ts may contain already an \ref lchan
515 * of type TCH_F which initiated the request to switch the \ts configuration.
516 */
517#define ts_for_each_potential_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_on_init)
518
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200519enum lchan_activate_mode {
520 FOR_NONE,
521 FOR_MS_CHANNEL_REQUEST,
522 FOR_ASSIGNMENT,
523 FOR_HANDOVER,
524 FOR_VTY,
525};
526
527extern const struct value_string lchan_activate_mode_names[];
528static inline const char *lchan_activate_mode_name(enum lchan_activate_mode activ_for)
529{ return get_value_string(lchan_activate_mode_names, activ_for); }
530
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100531struct lchan_activate_info {
532 enum lchan_activate_mode activ_for;
533 struct gsm_subscriber_connection *for_conn;
534 /* This always is for a specific lchan, so its lchan->type indicates full or half rate.
535 * When a dyn TS was selected, the lchan->type has been set to the desired rate. */
536 enum gsm48_chan_mode chan_mode;
Neels Hofmeyr58cf1b12019-03-15 02:49:18 +0100537 struct gsm_encr encr;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100538 /* AMR config */
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100539 uint16_t s15_s0;
540 bool requires_voice_stream;
541 bool wait_before_switching_rtp; /*< true = requires LCHAN_EV_READY_TO_SWITCH_RTP */
542 uint16_t msc_assigned_cic;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100543 /* During intra-BSC handover, we keep the MGW endpoint intact and just re-route to the new lchan. This
544 * 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 +0100545 struct gsm_lchan *re_use_mgw_endpoint_from_lchan;
546};
547
Neels Hofmeyr10485162018-02-13 23:22:03 +0100548struct gsm_lchan {
549 /* The TS that we're part of */
550 struct gsm_bts_trx_ts *ts;
551 /* The logical subslot number in the TS */
552 uint8_t nr;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200553 char *name;
554
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100555 char *last_error;
556
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200557 struct osmo_fsm_inst *fi;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200558 struct osmo_fsm_inst *fi_rtp;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200559 struct osmo_mgcpc_ep_ci *mgw_endpoint_ci_bts;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200560
561 struct {
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100562 struct lchan_activate_info info;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200563 bool activ_ack; /*< true as soon as RSL Chan Activ Ack is received */
Neels Hofmeyr369fba22018-11-27 01:30:50 +0100564 bool immediate_assignment_sent;
Neels Hofmeyr193c1e32018-08-27 22:06:24 +0200565 /*! This flag ensures that when an lchan activation has succeeded, and we have already
566 * sent ACKs like Immediate Assignment or BSSMAP Assignment Complete, and if other errors
567 * occur later, e.g. during release, that we don't send a NACK out of context. */
568 bool concluded;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200569 enum gsm0808_cause gsm0808_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200570 } activate;
571
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100572 struct {
573 /* If an event to release the lchan comes in while still waiting for responses, just mark this
574 * flag, so that the lchan will gracefully release at the next sensible junction. */
575 bool requested;
576 bool do_rr_release;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200577
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100578 /* There is an RSL error cause of value 0, so we need a separate flag. */
579 bool in_error;
580 /* RSL error code, RSL_ERR_* */
581 uint8_t rsl_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200582
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100583 /* If a release event is being handled, ignore other ricocheting release events until that
584 * release handling has concluded. */
585 bool in_release_handler;
Harald Welte963763d2019-02-03 12:11:12 +0100586
587 /* is this release at the end of a CSFB call? */
588 bool is_csfb;
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100589 } release;
Neels Hofmeyrd5df9a12018-07-20 05:35:47 +0200590
Neels Hofmeyr10485162018-02-13 23:22:03 +0100591 /* The logical channel type */
592 enum gsm_chan_t type;
593 /* RSL channel mode */
594 enum rsl_cmod_spd rsl_cmode;
595 /* If TCH, traffic channel mode */
596 enum gsm48_chan_mode tch_mode;
597 enum lchan_csd_mode csd_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100598 /* Power levels for MS and BTS */
599 uint8_t bs_power;
600 uint8_t ms_power;
601 /* Encryption information */
602 struct gsm_encr encr;
603
604 /* AMR bits */
605 uint8_t mr_ms_lv[7];
606 uint8_t mr_bts_lv[7];
Neels Hofmeyr4daa2102019-01-30 16:46:58 +0100607 /* AMR bits were based on these rate bits: */
608 uint16_t s15_s0;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100609
610 /* Established data link layer services */
611 uint8_t sapis[8];
612
613 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200614 uint32_t bound_ip; /*< where the BTS receives RTP */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100615 uint16_t bound_port;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200616 uint32_t connect_ip; /*< where the BTS sends RTP to (MGW) */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100617 uint16_t connect_port;
618 uint16_t conn_id;
619 uint8_t rtp_payload;
620 uint8_t rtp_payload2;
621 uint8_t speech_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100622
623 /* info we need to postpone the AoIP
624 * assignment completed message */
625 struct {
626 uint8_t rr_cause;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100627 bool valid;
628 } ass_compl;
629 } abis_ip;
630
631 uint8_t rqd_ta;
632
Neels Hofmeyr10485162018-02-13 23:22:03 +0100633 /* table of neighbor cell measurements */
634 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
635
636 /* cache of last measurement reports on this lchan */
637 struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
638 int meas_rep_idx;
639 int meas_rep_count;
Neels Hofmeyr35ba85c2018-02-12 16:47:40 +0100640 uint8_t meas_rep_last_seen_nr;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100641
642 /* GSM Random Access data */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200643 /* TODO: don't allocate this, rather keep an "is_present" flag */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100644 struct gsm48_req_ref *rqd_ref;
645
646 struct gsm_subscriber_connection *conn;
Philipp Maierbb66d102019-01-22 11:29:06 +0100647
648 /* Depending on the preferences that where submitted together with
649 * the assignment and the current channel load, the BSC has to select
650 * one of the offered codec/rates. The final selection by the BSC is
651 * stored here and is used when sending the assignment complete or
652 * when performing a handover procedure. */
653 struct channel_mode_and_rate ch_mode_rate;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100654};
655
Neels Hofmeyr10485162018-02-13 23:22:03 +0100656/* One Timeslot in a TRX */
657struct gsm_bts_trx_ts {
658 struct gsm_bts_trx *trx;
659 /* number of this timeslot at the TRX */
660 uint8_t nr;
661
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200662 struct osmo_fsm_inst *fi;
663 char *last_errmsg;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100664
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200665 /* vty phys_chan_config setting, not necessarily in effect in case it was changed in the telnet
666 * vty after OML activation. Gets written on vty 'write file'. */
667 enum gsm_phys_chan_config pchan_from_config;
668 /* When the timeslot OML is established, pchan_from_config is copied here. This is the pchan
669 * currently in effect; for dynamic ts, this is the dyn kind (GSM_PCHAN_TCH_F_TCH_H_PDCH or
670 * GSM_PCHAN_TCH_F_PDCH) and does not show the pchan type currently active. */
671 enum gsm_phys_chan_config pchan_on_init;
672 /* This is the *actual* pchan type currently active. For dynamic timeslots, this reflects either
673 * GSM_PCHAN_NONE or one of the standard GSM_PCHAN_TCH_F, GSM_PCHAN_TCH_H, GSM_PCHAN_PDCH.
674 * Callers can use this transparently without being aware of dyn ts. */
675 enum gsm_phys_chan_config pchan_is;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100676
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200677 /* After a PDCH ACT NACK, we shall not infinitely loop to try and ACT again.
678 * Also marks a timeslot where PDCH was deactivated by VTY. This is cleared whenever a timeslot
679 * enters IN_USE state, i.e. after each TCH use we try to PDCH ACT once again. */
680 bool pdch_act_allowed;
681
Neels Hofmeyrbcdbfb72018-07-26 20:33:15 +0200682 /* Whether TS_EV_OML_READY was received */
683 bool is_oml_ready;
684 /* Whether TS_EV_RSL_READY was received */
685 bool is_rsl_ready;
686
Neels Hofmeyr10485162018-02-13 23:22:03 +0100687 struct gsm_abis_mo mo;
688 struct tlv_parsed nm_attr;
689 uint8_t nm_chan_comb;
690 int tsc; /* -1 == use BTS TSC */
691
692 struct {
693 /* Parameters below are configured by VTY */
694 int enabled;
695 uint8_t maio;
696 uint8_t hsn;
697 struct bitvec arfcns;
698 uint8_t arfcns_data[1024/8];
699 /* This is the pre-computed MA for channel assignments */
700 struct bitvec ma;
701 uint8_t ma_len; /* part of ma_data that is used */
702 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
703 } hopping;
704
705 /* To which E1 subslot are we connected */
706 struct gsm_e1_subslot e1_link;
707
708 union {
709 struct {
710 struct om2k_mo om2k_mo;
711 } rbs2000;
712 };
713
714 struct gsm_lchan lchan[TS_MAX_LCHAN];
715};
716
717/* One TRX in a BTS */
718struct gsm_bts_trx {
719 /* list header in bts->trx_list */
720 struct llist_head list;
721
722 struct gsm_bts *bts;
723 /* number of this TRX in the BTS */
724 uint8_t nr;
725 /* human readable name / description */
726 char *description;
727 /* how do we talk RSL with this TRX? */
728 struct gsm_e1_subslot rsl_e1_link;
729 uint8_t rsl_tei;
730 struct e1inp_sign_link *rsl_link;
731
732 /* Timeout for initiating the RSL connection. */
733 struct osmo_timer_list rsl_connect_timeout;
734
735 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
736 struct e1inp_sign_link *oml_link;
737
738 struct gsm_abis_mo mo;
739 struct tlv_parsed nm_attr;
740 struct {
741 struct gsm_abis_mo mo;
742 } bb_transc;
743
744 uint16_t arfcn;
745 int nominal_power; /* in dBm */
746 unsigned int max_power_red; /* in actual dB */
747
748 union {
749 struct {
750 struct {
751 struct gsm_abis_mo mo;
752 } bbsig;
753 struct {
754 struct gsm_abis_mo mo;
755 } pa;
756 } bs11;
757 struct {
758 unsigned int test_state;
759 uint8_t test_nr;
760 struct rxlev_stats rxlev_stat;
761 } ipaccess;
762 struct {
763 struct {
764 struct om2k_mo om2k_mo;
765 } trxc;
766 struct {
767 struct om2k_mo om2k_mo;
768 } rx;
769 struct {
770 struct om2k_mo om2k_mo;
771 } tx;
772 } rbs2000;
773 };
774 struct gsm_bts_trx_ts ts[TRX_NR_TS];
775};
776
777#define GSM_BTS_SI2Q(bts, i) (struct gsm48_system_information_type_2quater *)((bts)->si_buf[SYSINFO_TYPE_2quater][i])
778#define GSM_BTS_HAS_SI(bts, i) ((bts)->si_valid & (1 << i))
779#define GSM_BTS_SI(bts, i) (void *)((bts)->si_buf[i][0])
780#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
781
782enum gsm_bts_type {
783 GSM_BTS_TYPE_UNKNOWN,
784 GSM_BTS_TYPE_BS11,
785 GSM_BTS_TYPE_NANOBTS,
786 GSM_BTS_TYPE_RBS2000,
787 GSM_BTS_TYPE_NOKIA_SITE,
788 GSM_BTS_TYPE_OSMOBTS,
789 _NUM_GSM_BTS_TYPE
790};
791
792enum gsm_bts_type_variant {
793 BTS_UNKNOWN,
794 BTS_OSMO_LITECELL15,
795 BTS_OSMO_OCTPHY,
796 BTS_OSMO_SYSMO,
797 BTS_OSMO_TRX,
798 _NUM_BTS_VARIANT
799};
800
801/* Used by OML layer for BTS Attribute reporting */
802enum bts_attribute {
803 BTS_TYPE_VARIANT,
804 BTS_SUB_MODEL,
805 TRX_PHY_VERSION,
806};
807
808struct vty;
809
810struct gsm_bts_model {
811 struct llist_head list;
812
813 enum gsm_bts_type type;
814 enum gsm_bts_type_variant variant;
815 const char *name;
816
817 bool started;
818 int (*start)(struct gsm_network *net);
819 int (*oml_rcvmsg)(struct msgb *msg);
820 char * (*oml_status)(const struct gsm_bts *bts);
821
822 void (*e1line_bind_ops)(struct e1inp_line *line);
823
824 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
825 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
826 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
827
Pau Espin Pedrol167cb822018-11-19 17:48:17 +0100828 /* Should SI2bis and SI2ter be disabled by default on this BTS model? */
829 bool force_combined_si;
830
Neels Hofmeyr10485162018-02-13 23:22:03 +0100831 struct tlv_definition nm_att_tlvdef;
832
833 /* features of a given BTS model set via gsm_bts_model_register() locally */
834 struct bitvec features;
835 uint8_t _features_data[MAX_BTS_FEATURES/8];
836};
837
Neels Hofmeyr10485162018-02-13 23:22:03 +0100838
Neels Hofmeyr10485162018-02-13 23:22:03 +0100839
840/*
841 * This keeps track of the paging status of one BTS. It
842 * includes a number of pending requests, a back pointer
843 * to the gsm_bts, a timer and some more state.
844 */
845struct gsm_bts_paging_state {
846 /* pending requests */
847 struct llist_head pending_requests;
848 struct gsm_bts *bts;
849
850 struct osmo_timer_list work_timer;
851 struct osmo_timer_list credit_timer;
852
853 /* free chans needed */
854 int free_chans_need;
855
856 /* load */
857 uint16_t available_slots;
858};
859
860struct gsm_envabtse {
861 struct gsm_abis_mo mo;
862};
863
864struct gsm_bts_gprs_nsvc {
865 struct gsm_bts *bts;
866 /* data read via VTY config file, to configure the BTS
867 * via OML from BSC */
868 int id;
869 uint16_t nsvci;
870 uint16_t local_port; /* on the BTS */
871 uint16_t remote_port; /* on the SGSN */
872 uint32_t remote_ip; /* on the SGSN */
873
874 struct gsm_abis_mo mo;
875};
876
877enum gprs_rlc_par {
878 RLC_T3142,
879 RLC_T3169,
880 RLC_T3191,
881 RLC_T3193,
882 RLC_T3195,
883 RLC_N3101,
884 RLC_N3103,
885 RLC_N3105,
886 CV_COUNTDOWN,
887 T_DL_TBF_EXT, /* ms */
888 T_UL_TBF_EXT, /* ms */
889 _NUM_RLC_PAR
890};
891
892enum gprs_cs {
893 GPRS_CS1,
894 GPRS_CS2,
895 GPRS_CS3,
896 GPRS_CS4,
897 GPRS_MCS1,
898 GPRS_MCS2,
899 GPRS_MCS3,
900 GPRS_MCS4,
901 GPRS_MCS5,
902 GPRS_MCS6,
903 GPRS_MCS7,
904 GPRS_MCS8,
905 GPRS_MCS9,
906 _NUM_GRPS_CS
907};
908
909struct gprs_rlc_cfg {
910 uint16_t parameter[_NUM_RLC_PAR];
911 struct {
912 uint16_t repeat_time; /* ms */
913 uint8_t repeat_count;
914 } paging;
915 uint32_t cs_mask; /* bitmask of gprs_cs */
916 uint8_t initial_cs;
917 uint8_t initial_mcs;
918};
919
920
921enum neigh_list_manual_mode {
922 NL_MODE_AUTOMATIC = 0,
923 NL_MODE_MANUAL = 1,
924 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
925};
926
927enum bts_loc_fix {
928 BTS_LOC_FIX_INVALID = 0,
929 BTS_LOC_FIX_2D = 1,
930 BTS_LOC_FIX_3D = 2,
931};
932
933extern const struct value_string bts_loc_fix_names[];
934
935struct bts_location {
936 struct llist_head list;
937 time_t tstamp;
938 enum bts_loc_fix valid;
939 double lat;
940 double lon;
941 double height;
942};
943
944/* Channel load counter */
945struct load_counter {
946 unsigned int total;
947 unsigned int used;
948};
949
Neels Hofmeyr19bed232018-03-22 04:54:57 +0100950/* Useful to track N-N relations between BTS, for example neighbors. */
951struct gsm_bts_ref {
952 struct llist_head entry;
953 struct gsm_bts *bts;
954};
955
Harald Welted41b7c72019-06-13 09:41:58 +0200956/* A single Page of a SMSCB message */
957struct bts_smscb_page {
958 /* SMSCB message we're part of */
959 struct bts_smscb_message *msg;
960 /* Page Number within message (1 to 15) */
961 uint8_t nr;
962 /* number of valid blocks in data (up to 4) */
963 uint8_t num_blocks;
964 /* up to four blocks of 22 bytes each */
965 uint8_t data[88];
966};
967
968/* A SMSCB message (received from CBSP) */
969struct bts_smscb_message {
970 /* entry in bts_smscb_chan_state.messages */
971 struct llist_head list;
972 struct {
973 /* input data from CBSP (CBC) side */
974 uint16_t msg_id;
975 uint16_t serial_nr;
976 enum cbsp_category category;
977 uint16_t rep_period;
978 uint16_t num_bcast_req;
979 uint8_t dcs;
980 } input;
981 /* how often have all pages of this message been broadcast? */
982 uint32_t bcast_count;
983 /* actual page data of this message */
984 uint8_t num_pages; /* up to 15 */
985 struct bts_smscb_page page[15];
986};
987
988/* per-channel (basic/extended) CBCH state for a single BTS */
989struct bts_smscb_chan_state {
990 /* back-pointer to BTS */
991 struct gsm_bts *bts;
992 /* list of bts_smscb_message */
993 struct llist_head messages;
994 /* scheduling array; pointer of SMSCB pages */
995 struct bts_smscb_page **sched_arr;
996 size_t sched_arr_size;
997 /* index of the next to be transmitted page into the scheduler array */
998 size_t next_idx;
999 /* number of messages we have to pause due to overflow */
1000 uint8_t overflow;
1001};
1002
Oliver Smithba0a1222020-03-18 12:39:30 +01001003struct bts_oml_fail_rep {
1004 struct llist_head list;
1005 time_t time;
1006 struct msgb *mb;
1007};
1008
Neels Hofmeyr10485162018-02-13 23:22:03 +01001009/* One BTS */
1010struct gsm_bts {
1011 /* list header in net->bts_list */
1012 struct llist_head list;
1013
1014 /* Geographical location of the BTS */
1015 struct llist_head loc_list;
1016
Martin Haukea29affd2019-11-13 22:10:41 +01001017 /* number of this BTS in network */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001018 uint8_t nr;
1019 /* human readable name / description */
1020 char *description;
1021 /* Cell Identity */
1022 uint16_t cell_identity;
1023 /* location area code of this BTS */
1024 uint16_t location_area_code;
1025 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
1026 * which is used as TSC for the CCCH */
1027 uint8_t bsic;
1028 /* type of BTS */
1029 enum gsm_bts_type type;
1030 enum gsm_bts_type_variant variant;
1031 struct gsm_bts_model *model;
1032 enum gsm_band band;
1033 char version[MAX_VERSION_LENGTH];
1034 char sub_model[MAX_VERSION_LENGTH];
1035
1036 /* features of a given BTS set/reported via OML */
1037 struct bitvec features;
1038 uint8_t _features_data[MAX_BTS_FEATURES/8];
1039
1040 /* Connected PCU version (if any) */
1041 char pcu_version[MAX_VERSION_LENGTH];
1042
1043 /* maximum Tx power that the MS is permitted to use in this cell */
1044 int ms_max_power;
1045
1046 /* how do we talk OML with this TRX? */
1047 struct gsm_e1_subslot oml_e1_link;
1048 uint8_t oml_tei;
1049 struct e1inp_sign_link *oml_link;
Pau Espin Pedrol9862bcb2018-08-22 21:54:12 +02001050 /* Timer to use for deferred drop of OML link, see \ref ipaccess_drop_oml_deferred */
1051 struct osmo_timer_list oml_drop_link_timer;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001052 /* when OML link was established */
1053 time_t uptime;
1054
1055 /* Abis network management O&M handle */
1056 struct abis_nm_h *nmh;
1057
1058 struct gsm_abis_mo mo;
1059
1060 /* number of this BTS on given E1 link */
1061 uint8_t bts_nr;
1062
1063 /* DTX features of this BTS */
1064 enum gsm48_dtx_mode dtxu;
1065 bool dtxd;
1066
1067 /* paging state and control */
1068 struct gsm_bts_paging_state paging;
1069
1070 /* CCCH is on C0 */
1071 struct gsm_bts_trx *c0;
1072
1073 struct {
1074 struct gsm_abis_mo mo;
1075 } site_mgr;
1076
1077 /* bitmask of all SI that are present/valid in si_buf */
1078 uint32_t si_valid;
1079 /* 3GPP TS 44.018 Table 10.5.2.33b.1 INDEX and COUNT for SI2quater */
1080 uint8_t si2q_index; /* distinguish individual SI2quater messages */
1081 uint8_t si2q_count; /* si2q_index for the last (highest indexed) individual SI2quater message */
1082 /* buffers where we put the pre-computed SI */
1083 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
1084 /* offsets used while generating SI2quater */
1085 size_t e_offset;
1086 size_t u_offset;
Pau Espin Pedrol1cf21de2018-12-05 13:38:10 +01001087 /* 3GPP TS 08.58 §8.5.1 BCCH INFORMATION. Some nanoBTS fail upon
1088 * receival of empty SI disabling unsupported SI. see OS#3707. */
1089 bool si_unused_send_empty;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001090
Martin Haukea29affd2019-11-13 22:10:41 +01001091 /* ip.access Unit ID's have Site/BTS/TRX layout */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001092 union {
1093 struct {
1094 uint16_t site_id;
1095 uint16_t bts_id;
1096 uint32_t flags;
1097 uint32_t rsl_ip;
1098 } ip_access;
1099 struct {
1100 struct {
1101 struct gsm_abis_mo mo;
1102 } cclk;
1103 struct {
1104 struct gsm_abis_mo mo;
1105 } rack;
1106 struct gsm_envabtse envabtse[4];
1107 } bs11;
1108 struct {
1109 struct {
1110 struct om2k_mo om2k_mo;
1111 struct gsm_abis_mo mo;
1112 struct llist_head conn_groups;
1113 } cf;
1114 struct {
1115 struct om2k_mo om2k_mo;
1116 struct gsm_abis_mo mo;
1117 struct llist_head conn_groups;
1118 } is;
1119 struct {
1120 struct om2k_mo om2k_mo;
1121 struct gsm_abis_mo mo;
1122 struct llist_head conn_groups;
1123 } con;
1124 struct {
1125 struct om2k_mo om2k_mo;
1126 struct gsm_abis_mo mo;
1127 } dp;
1128 struct {
1129 struct om2k_mo om2k_mo;
1130 struct gsm_abis_mo mo;
1131 } tf;
Sylvain Munautcbaa1792020-05-05 20:14:44 +02001132 struct {
1133 struct om2k_mo om2k_mo;
1134 struct gsm_abis_mo mo;
1135 } mctr;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001136 uint32_t use_superchannel:1;
Sylvain Munautdbd1b502020-05-05 21:07:58 +02001137 struct {
1138 uint16_t limit;
1139 uint16_t active;
1140 } om2k_version[16];
Neels Hofmeyr10485162018-02-13 23:22:03 +01001141 } rbs2000;
1142 struct {
1143 uint8_t bts_type;
Harald Welte1d7349f2020-05-03 11:48:31 +02001144 unsigned int configured:1, /* we sent the config data request */
1145 skip_reset:1, /* skip reset at bootstrap */
1146 no_loc_rel_cnf:1, /* don't wait for RSL REL CONF */
1147 bts_reset_timer_cnf, /* timer for BTS RESET */
1148 did_reset:1, /* we received a RESET ACK */
Harald Welte456a62e2020-05-03 12:00:52 +02001149 wait_reset:2; /* we are waiting for reset to complete */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001150 struct osmo_timer_list reset_timer;
1151 } nokia;
1152 };
1153
1154 /* Not entirely sure how ip.access specific this is */
1155 struct {
Neels Hofmeyr10485162018-02-13 23:22:03 +01001156 enum bts_gprs_mode mode;
1157 struct {
1158 struct gsm_abis_mo mo;
1159 uint16_t nsei;
1160 uint8_t timer[7];
1161 } nse;
1162 struct {
1163 struct gsm_abis_mo mo;
1164 uint16_t bvci;
1165 uint8_t timer[11];
1166 struct gprs_rlc_cfg rlc_cfg;
1167 } cell;
1168 struct gsm_bts_gprs_nsvc nsvc[2];
1169 uint8_t rac;
1170 uint8_t net_ctrl_ord;
1171 bool ctrl_ack_type_use_block;
Vadim Yanitskiye981f172020-04-06 18:09:55 +07001172 bool egprs_pkt_chan_request;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001173 } gprs;
1174
Harald Welte15400252019-05-24 11:56:23 +02001175 /* threshold (in percent) when BTS shall send CCCH LOAD IND */
1176 int ccch_load_ind_thresh;
1177
Neels Hofmeyr10485162018-02-13 23:22:03 +01001178 /* RACH NM values */
1179 int rach_b_thresh;
1180 int rach_ldavg_slots;
1181
1182 /* transceivers */
1183 int num_trx;
1184 struct llist_head trx_list;
1185
1186 /* SI related items */
1187 int force_combined_si;
Pau Espin Pedrol167cb822018-11-19 17:48:17 +01001188 bool force_combined_si_set;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001189 int bcch_change_mark;
1190
1191 /* Abis NM queue */
1192 struct llist_head abis_queue;
1193 int abis_nm_pend;
1194
1195 struct gsm_network *network;
1196
1197 /* should the channel allocator allocate channels from high TRX to TRX0,
1198 * rather than starting from TRX0 and go upwards? */
1199 int chan_alloc_reverse;
1200
1201 enum neigh_list_manual_mode neigh_list_manual_mode;
1202 /* parameters from which we build SYSTEM INFORMATION */
1203 struct {
1204 struct gsm48_rach_control rach_control;
1205 uint8_t ncc_permitted;
1206 struct gsm48_cell_sel_par cell_sel_par;
1207 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
1208 struct gsm48_cell_options cell_options;
1209 struct gsm48_control_channel_descr chan_desc;
1210 struct bitvec neigh_list;
1211 struct bitvec cell_alloc;
1212 struct bitvec si5_neigh_list;
1213 struct osmo_earfcn_si2q si2quater_neigh_list;
1214 size_t uarfcn_length; /* index for uarfcn and scramble lists */
1215 struct {
1216 /* bitmask large enough for all possible ARFCN's */
1217 uint8_t neigh_list[1024/8];
1218 uint8_t cell_alloc[1024/8];
1219 /* If the user wants a different neighbor list in SI5 than in SI2 */
1220 uint8_t si5_neigh_list[1024/8];
1221 uint8_t meas_bw_list[MAX_EARFCN_LIST];
1222 uint16_t earfcn_list[MAX_EARFCN_LIST];
1223 uint16_t uarfcn_list[MAX_EARFCN_LIST];
1224 uint16_t scramble_list[MAX_EARFCN_LIST];
1225 } data;
1226 } si_common;
1227 bool early_classmark_allowed;
1228 bool early_classmark_allowed_3g;
1229 /* for testing only: Have an infinitely long radio link timeout */
1230 bool infinite_radio_link_timeout;
1231
1232 /* do we use static (user-defined) system information messages? (bitmask) */
1233 uint32_t si_mode_static;
1234
Stefan Sperling6442e432018-02-06 14:44:54 +01001235 /* access control class ramping */
1236 struct acc_ramp acc_ramp;
1237
Neels Hofmeyr10485162018-02-13 23:22:03 +01001238 /* exclude the BTS from the global RF Lock handling */
1239 int excl_from_rf_lock;
1240
1241 /* supported codecs beside FR */
1242 struct bts_codec_conf codec;
1243
1244 /* BTS dependencies bit field */
1245 uint32_t depends_on[256/(8*4)];
1246
1247 /* full and half rate multirate config */
1248 struct amr_multirate_conf mr_full;
1249 struct amr_multirate_conf mr_half;
1250
1251 /* PCU socket state */
1252 char *pcu_sock_path;
1253 struct pcu_sock_state *pcu_state;
1254
1255 struct rate_ctr_group *bts_ctrs;
1256 struct osmo_stat_item_group *bts_statg;
1257
1258 struct handover_cfg *ho;
1259
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001260 /* A list of struct gsm_bts_ref, indicating neighbors of this BTS.
1261 * When the si_common neigh_list is in automatic mode, it is populated from this list as well as
1262 * gsm_network->neighbor_bss_cells. */
1263 struct llist_head local_neighbors;
1264
Neels Hofmeyr10485162018-02-13 23:22:03 +01001265 /* BTS-specific overrides for timer values from struct gsm_network. */
Martin Haukea29affd2019-11-13 22:10:41 +01001266 uint8_t T3122; /* ASSIGNMENT REJECT wait indication */
Pau Espin Pedrol1b963342018-11-07 14:19:32 +01001267 bool T3113_dynamic; /* Calculate T3113 timeout dynamically based on BTS channel config and load */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001268
1269 /* Periodic channel load measurements are used to maintain T3122. */
1270 struct load_counter chan_load_samples[7];
1271 int chan_load_samples_idx;
Stefan Sperling6442e432018-02-06 14:44:54 +01001272 uint8_t chan_load_avg; /* current channel load average in percent (0 - 100). */
Harald Welted41b7c72019-06-13 09:41:58 +02001273
1274 /* cell broadcast system */
1275 struct osmo_timer_list cbch_timer;
1276 struct bts_smscb_chan_state cbch_basic;
1277 struct bts_smscb_chan_state cbch_extended;
Harald Welte7d888442019-09-06 23:18:27 +02001278 struct osmo_timer_list etws_timer; /* when to stop ETWS PN */
Oliver Smithba0a1222020-03-18 12:39:30 +01001279
1280 struct llist_head oml_fail_rep;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001281};
1282
Oliver Smith8d8d7102018-10-23 15:35:43 +02001283/* One rejected BTS */
1284struct gsm_bts_rejected {
1285 /* list header in net->bts_rejected */
1286 struct llist_head list;
1287
1288 uint16_t site_id;
1289 uint16_t bts_id;
1290 char ip[INET6_ADDRSTRLEN];
1291 time_t time;
1292};
Neels Hofmeyr10485162018-02-13 23:22:03 +01001293
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001294struct gsm_network *gsm_network_init(void *ctx);
1295
Neels Hofmeyr10485162018-02-13 23:22:03 +01001296struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, uint8_t bts_num);
Neels Hofmeyr6d568ed2018-07-09 16:49:18 +02001297struct gsm_bts *gsm_bts_num(const struct gsm_network *net, int num);
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001298bool gsm_bts_matches_lai(const struct gsm_bts *bts, const struct osmo_location_area_id *lai);
1299bool gsm_bts_matches_cell_id(const struct gsm_bts *bts, const struct gsm0808_cell_id *cell_id);
1300struct gsm_bts *gsm_bts_by_cell_id(const struct gsm_network *net,
1301 const struct gsm0808_cell_id *cell_id,
1302 int match_idx);
1303int gsm_bts_local_neighbor_add(struct gsm_bts *bts, struct gsm_bts *neighbor);
1304int gsm_bts_local_neighbor_del(struct gsm_bts *bts, const struct gsm_bts *neighbor);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001305
1306struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
1307struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
1308
1309enum gsm_bts_type str2btstype(const char *arg);
1310const char *btstype2str(enum gsm_bts_type type);
1311
1312enum bts_attribute str2btsattr(const char *s);
1313const char *btsatttr2str(enum bts_attribute v);
1314
1315enum gsm_bts_type_variant str2btsvariant(const char *arg);
1316const char *btsvariant2str(enum gsm_bts_type_variant v);
1317
1318extern const struct value_string gsm_chreq_descs[];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001319extern const struct value_string gsm_pchant_names[];
1320extern const struct value_string gsm_pchant_descs[];
1321extern const struct value_string gsm_pchan_ids[];
Neels Hofmeyr10485162018-02-13 23:22:03 +01001322const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001323static inline const char *gsm_pchan_id(enum gsm_phys_chan_config c)
1324{ return get_value_string(gsm_pchan_ids, c); }
Neels Hofmeyr10485162018-02-13 23:22:03 +01001325enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
1326const char *gsm_lchant_name(enum gsm_chan_t c);
1327const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte57658ec2019-02-04 12:30:44 +01001328char *gsm_bts_name(const struct gsm_bts *bts);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001329char *gsm_trx_name(const struct gsm_bts_trx *trx);
1330char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
1331char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
1332char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001333
1334static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
1335{
1336 return lchan->name;
1337}
1338
Neels Hofmeyr10485162018-02-13 23:22:03 +01001339void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
1340
1341struct gsm_nm_state *
1342gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
1343 const struct abis_om_obj_inst *obj_inst);
1344void *
1345gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
1346 const struct abis_om_obj_inst *obj_inst);
1347
1348/* reset the state of all MO in the BTS */
1349void gsm_bts_mo_reset(struct gsm_bts *bts);
1350
1351uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
1352 uint8_t ts_nr, uint8_t lchan_nr);
1353uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
1354uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
1355 enum gsm_phys_chan_config as_pchan);
1356
Harald Welte251bec12018-09-09 17:14:09 +02001357void gsm48_lchan2chan_desc(struct gsm48_chan_desc *cd,
1358 const struct gsm_lchan *lchan);
Harald Welte24286f32018-09-09 17:17:44 +02001359void gsm48_lchan2chan_desc_as_configured(struct gsm48_chan_desc *cd, const struct gsm_lchan *lchan);
Harald Welte251bec12018-09-09 17:14:09 +02001360
Neels Hofmeyr10485162018-02-13 23:22:03 +01001361/* return the gsm_lchan for the CBCH (if it exists at all) */
1362struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
1363
Neels Hofmeyr10485162018-02-13 23:22:03 +01001364static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
1365{
1366 if (ts->tsc != -1)
1367 return ts->tsc;
1368 else
1369 return ts->trx->bts->bsic & 7;
1370}
1371
1372struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
1373 int *rc);
1374
1375enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001376uint8_t pchan_subslots(enum gsm_phys_chan_config pchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001377bool ts_is_tch(struct gsm_bts_trx_ts *ts);
1378
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01001379
Harald Welteb7948872017-12-18 18:48:21 +01001380static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection *conn) {
1381 OSMO_ASSERT(conn->lchan);
1382 return conn->lchan->ts->trx->bts;
1383}
1384
Pau Espin Pedrol7950e5d2019-10-31 15:59:49 +01001385void conn_update_ms_power_class(struct gsm_subscriber_connection *conn, uint8_t power_class);
1386void lchan_update_ms_power_ctrl_level(struct gsm_lchan *lchan, int ms_power_dbm);
1387
Alexander Chemeris5d638272020-05-11 00:30:11 +03001388enum bts_counter_id {
Harald Welted82101e2017-12-09 23:07:38 +01001389 BTS_CTR_CHREQ_TOTAL,
1390 BTS_CTR_CHREQ_NO_CHANNEL,
1391 BTS_CTR_CHAN_RF_FAIL,
1392 BTS_CTR_CHAN_RLL_ERR,
1393 BTS_CTR_BTS_OML_FAIL,
1394 BTS_CTR_BTS_RSL_FAIL,
1395 BTS_CTR_CODEC_AMR_F,
1396 BTS_CTR_CODEC_AMR_H,
1397 BTS_CTR_CODEC_EFR,
1398 BTS_CTR_CODEC_V1_FR,
1399 BTS_CTR_CODEC_V1_HR,
Harald Weltecf9d4312017-12-13 23:17:16 +01001400 BTS_CTR_PAGING_ATTEMPTED,
1401 BTS_CTR_PAGING_ALREADY,
1402 BTS_CTR_PAGING_RESPONDED,
1403 BTS_CTR_PAGING_EXPIRED,
Alexander Chemeris43def742020-05-16 18:49:59 +03001404 BTS_CTR_PAGING_NO_ACTIVE_PAGING,
Alexander Chemeris001a2df2020-05-22 21:43:57 +03001405 BTS_CTR_PAGING_MSC_FLUSH,
Harald Welte4f598922017-12-14 13:47:02 +01001406 BTS_CTR_CHAN_ACT_TOTAL,
1407 BTS_CTR_CHAN_ACT_NACK,
Harald Welte62d9cb02017-12-14 14:00:26 +01001408 BTS_CTR_RSL_UNKNOWN,
Harald Welte581398a2017-12-14 14:29:44 +01001409 BTS_CTR_RSL_IPA_NACK,
Harald Welte00d64fd2017-12-14 14:34:16 +01001410 BTS_CTR_MODE_MODIFY_NACK,
Alexander Chemeris5d638272020-05-11 00:30:11 +03001411 BTS_CTR_LCHAN_BORKEN_FROM_UNUSED,
1412 BTS_CTR_LCHAN_BORKEN_FROM_WAIT_ACTIV_ACK,
1413 BTS_CTR_LCHAN_BORKEN_FROM_WAIT_RF_RELEASE_ACK,
1414 BTS_CTR_LCHAN_BORKEN_FROM_BORKEN,
1415 BTS_CTR_LCHAN_BORKEN_FROM_UNKNOWN,
1416 BTS_CTR_LCHAN_BORKEN_EV_CHAN_ACTIV_ACK,
1417 BTS_CTR_LCHAN_BORKEN_EV_CHAN_ACTIV_NACK,
1418 BTS_CTR_LCHAN_BORKEN_EV_RF_CHAN_REL_ACK,
1419 BTS_CTR_LCHAN_BORKEN_EV_VTY,
1420 BTS_CTR_LCHAN_BORKEN_EV_TEARDOWN,
1421 BTS_CTR_TS_BORKEN_FROM_NOT_INITIALIZED,
1422 BTS_CTR_TS_BORKEN_FROM_UNUSED,
1423 BTS_CTR_TS_BORKEN_FROM_WAIT_PDCH_ACT,
1424 BTS_CTR_TS_BORKEN_FROM_PDCH,
1425 BTS_CTR_TS_BORKEN_FROM_WAIT_PDCH_DEACT,
1426 BTS_CTR_TS_BORKEN_FROM_IN_USE,
1427 BTS_CTR_TS_BORKEN_FROM_BORKEN,
1428 BTS_CTR_TS_BORKEN_FROM_UNKNOWN,
1429 BTS_CTR_TS_BORKEN_EV_PDCH_ACT_ACK_NACK,
1430 BTS_CTR_TS_BORKEN_EV_PDCH_DEACT_ACK_NACK,
1431 BTS_CTR_TS_BORKEN_EV_TEARDOWN,
Harald Welted82101e2017-12-09 23:07:38 +01001432};
1433
1434static const struct rate_ctr_desc bts_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001435 [BTS_CTR_CHREQ_TOTAL] = {"chreq:total", "Received channel requests."},
1436 [BTS_CTR_CHREQ_NO_CHANNEL] = {"chreq:no_channel", "Sent to MS no channel available."},
1437 [BTS_CTR_CHAN_RF_FAIL] = {"chan:rf_fail", "Received a RF failure indication from BTS."},
1438 [BTS_CTR_CHAN_RLL_ERR] = {"chan:rll_err", "Received a RLL failure with T200 cause from BTS."},
Harald Welted82101e2017-12-09 23:07:38 +01001439 [BTS_CTR_BTS_OML_FAIL] = {"oml_fail", "Received a TEI down on a OML link."},
1440 [BTS_CTR_BTS_RSL_FAIL] = {"rsl_fail", "Received a TEI down on a OML link."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001441 [BTS_CTR_CODEC_AMR_F] = {"codec:amr_f", "Count the usage of AMR/F codec by channel mode requested."},
1442 [BTS_CTR_CODEC_AMR_H] = {"codec:amr_h", "Count the usage of AMR/H codec by channel mode requested."},
1443 [BTS_CTR_CODEC_EFR] = {"codec:efr", "Count the usage of EFR codec by channel mode requested."},
1444 [BTS_CTR_CODEC_V1_FR] = {"codec:fr", "Count the usage of FR codec by channel mode requested."},
1445 [BTS_CTR_CODEC_V1_HR] = {"codec:hr", "Count the usage of HR codec by channel mode requested."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001446
1447 [BTS_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Martin Haukea29affd2019-11-13 22:10:41 +01001448 [BTS_CTR_PAGING_ALREADY] = {"paging:already", "Paging attempts ignored as subscriber was already being paged."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001449 [BTS_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful paging response."},
1450 [BTS_CTR_PAGING_EXPIRED] = {"paging:expired", "Paging Request expired because of timeout T3113."},
Alexander Chemeris43def742020-05-16 18:49:59 +03001451 [BTS_CTR_PAGING_NO_ACTIVE_PAGING] = {"paging:no_active_paging", "Paging response without an active paging request (arrived after paging expiration?)."},
Alexander Chemeris001a2df2020-05-22 21:43:57 +03001452 [BTS_CTR_PAGING_MSC_FLUSH] = {"paging:msc_flush", "Paging flushed due to MSC Reset BSSMAP message."},
Harald Welte4f598922017-12-14 13:47:02 +01001453 [BTS_CTR_CHAN_ACT_TOTAL] = {"chan_act:total", "Total number of Channel Activations."},
1454 [BTS_CTR_CHAN_ACT_NACK] = {"chan_act:nack", "Number of Channel Activations that the BTS NACKed"},
Harald Welte62d9cb02017-12-14 14:00:26 +01001455 [BTS_CTR_RSL_UNKNOWN] = {"rsl:unknown", "Number of unknown/unsupported RSL messages received from BTS"},
Harald Welte581398a2017-12-14 14:29:44 +01001456 [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 +01001457 [BTS_CTR_MODE_MODIFY_NACK] = {"chan:mode_modify_nack", "Number of Channel Mode Modify NACKs received from BTS"},
Alexander Chemeris5d638272020-05-11 00:30:11 +03001458
1459 /* lchan/TS BORKEN state counters */
1460 [BTS_CTR_LCHAN_BORKEN_FROM_UNUSED] = {"lchan_borken:from_state:unused", "Transitions from lchan UNUSED state to BORKEN state"},
1461 [BTS_CTR_LCHAN_BORKEN_FROM_WAIT_ACTIV_ACK] = {"lchan_borken:from_state:wait_activ_ack", "Transitions from lchan WAIT_ACTIV_ACK state to BORKEN state"},
1462 [BTS_CTR_LCHAN_BORKEN_FROM_WAIT_RF_RELEASE_ACK] = {"lchan_borken:from_state:wait_rf_release_ack", "Transitions from lchan WAIT_RF_RELEASE_ACK state to BORKEN state"},
1463 [BTS_CTR_LCHAN_BORKEN_FROM_BORKEN] = {"lchan_borken:from_state:borken", "Transitions from lchan BORKEN state to BORKEN state"},
1464 [BTS_CTR_LCHAN_BORKEN_FROM_UNKNOWN] = {"lchan_borken:from_state:unknown", "Transitions from an unknown lchan state to BORKEN state"},
1465 [BTS_CTR_LCHAN_BORKEN_EV_CHAN_ACTIV_ACK] = {"lchan_borken:event:chan_activ_ack", "CHAN_ACTIV_ACK received in the lchan BORKEN state"},
1466 [BTS_CTR_LCHAN_BORKEN_EV_CHAN_ACTIV_NACK] = {"lchan_borken:event:chan_activ_nack", "CHAN_ACTIV_NACK received in the lchan BORKEN state"},
1467 [BTS_CTR_LCHAN_BORKEN_EV_RF_CHAN_REL_ACK] = {"lchan_borken:event:rf_chan_rel_ack", "RF_CHAN_REL_ACK received in the lchan BORKEN state"},
1468 [BTS_CTR_LCHAN_BORKEN_EV_VTY] = {"lchan_borken:event:vty", "VTY commands received in the lchan BORKEN state"},
1469 [BTS_CTR_LCHAN_BORKEN_EV_TEARDOWN] = {"lchan_borken:event:teardown", "lchan in a BORKEN state is shutting down (BTS disconnected?)"},
1470 [BTS_CTR_TS_BORKEN_FROM_NOT_INITIALIZED] = {"ts_borken:from_state:not_initialized", "Transitions from TS NOT_INITIALIZED state to BORKEN state"},
1471 [BTS_CTR_TS_BORKEN_FROM_UNUSED] = {"ts_borken:from_state:unused", "Transitions from TS UNUSED state to BORKEN state"},
1472 [BTS_CTR_TS_BORKEN_FROM_WAIT_PDCH_ACT] = {"ts_borken:from_state:wait_pdch_act", "Transitions from TS WAIT_PDCH_ACT state to BORKEN state"},
1473 [BTS_CTR_TS_BORKEN_FROM_PDCH] = {"ts_borken:from_state:pdch", "Transitions from TS PDCH state to BORKEN state"},
1474 [BTS_CTR_TS_BORKEN_FROM_WAIT_PDCH_DEACT] = {"ts_borken:from_state:wait_pdch_deact", "Transitions from TS WAIT_PDCH_DEACT state to BORKEN state"},
1475 [BTS_CTR_TS_BORKEN_FROM_IN_USE] = {"ts_borken:from_state:in_use", "Transitions from TS IN_USE state to BORKEN state"},
1476 [BTS_CTR_TS_BORKEN_FROM_BORKEN] = {"ts_borken:from_state:borken", "Transitions from TS BORKEN state to BORKEN state"},
1477 [BTS_CTR_TS_BORKEN_FROM_UNKNOWN] = {"ts_borken:from_state:unknown", "Transitions from an unknown TS state to BORKEN state"},
1478 [BTS_CTR_TS_BORKEN_EV_PDCH_ACT_ACK_NACK] = {"ts_borken:event:pdch_act_ack_nack", "PDCH_ACT_ACK/NACK received in the TS BORKEN state"},
1479 [BTS_CTR_TS_BORKEN_EV_PDCH_DEACT_ACK_NACK] = {"ts_borken:event:pdch_deact_ack_nack", "PDCH_DEACT_ACK/NACK received in the TS BORKEN state"},
1480 [BTS_CTR_TS_BORKEN_EV_TEARDOWN] = {"ts_borken:event:teardown", "TS in a BORKEN state is shutting down (BTS disconnected?)"},
Harald Welted82101e2017-12-09 23:07:38 +01001481};
1482
1483static const struct rate_ctr_group_desc bts_ctrg_desc = {
1484 "bts",
1485 "base transceiver station",
1486 OSMO_STATS_CLASS_GLOBAL,
1487 ARRAY_SIZE(bts_ctr_description),
1488 bts_ctr_description,
1489};
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001490
Alexander Couzens20423ea2016-07-12 15:42:02 +02001491enum {
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001492 BTS_STAT_CHAN_LOAD_AVERAGE,
Alexander Chemerisb091def2020-05-06 23:17:49 +03001493 BTS_STAT_CHAN_CCCH_SDCCH4_USED,
1494 BTS_STAT_CHAN_CCCH_SDCCH4_TOTAL,
1495 BTS_STAT_CHAN_TCH_F_USED,
1496 BTS_STAT_CHAN_TCH_F_TOTAL,
1497 BTS_STAT_CHAN_TCH_H_USED,
1498 BTS_STAT_CHAN_TCH_H_TOTAL,
1499 BTS_STAT_CHAN_SDCCH8_USED,
1500 BTS_STAT_CHAN_SDCCH8_TOTAL,
1501 BTS_STAT_CHAN_TCH_F_PDCH_USED,
1502 BTS_STAT_CHAN_TCH_F_PDCH_TOTAL,
1503 BTS_STAT_CHAN_CCCH_SDCCH4_CBCH_USED,
1504 BTS_STAT_CHAN_CCCH_SDCCH4_CBCH_TOTAL,
1505 BTS_STAT_CHAN_SDCCH8_CBCH_USED,
1506 BTS_STAT_CHAN_SDCCH8_CBCH_TOTAL,
1507 BTS_STAT_CHAN_TCH_F_TCH_H_PDCH_USED,
1508 BTS_STAT_CHAN_TCH_F_TCH_H_PDCH_TOTAL,
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001509 BTS_STAT_T3122,
Harald Weltebe86caa2019-05-24 09:30:28 +02001510 BTS_STAT_RACH_BUSY,
1511 BTS_STAT_RACH_ACCESS,
Alexander Chemeris8b0f6872020-05-07 16:46:47 +03001512 BTS_STAT_OML_CONNECTED,
1513 BTS_STAT_RSL_CONNECTED,
Alexander Chemeris5d638272020-05-11 00:30:11 +03001514 BTS_STAT_LCHAN_BORKEN,
1515 BTS_STAT_TS_BORKEN,
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001516};
1517
1518enum {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001519 BSC_CTR_ASSIGNMENT_ATTEMPTED,
1520 BSC_CTR_ASSIGNMENT_COMPLETED,
1521 BSC_CTR_ASSIGNMENT_STOPPED,
1522 BSC_CTR_ASSIGNMENT_NO_CHANNEL,
1523 BSC_CTR_ASSIGNMENT_TIMEOUT,
1524 BSC_CTR_ASSIGNMENT_FAILED,
1525 BSC_CTR_ASSIGNMENT_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001526 BSC_CTR_HANDOVER_ATTEMPTED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001527 BSC_CTR_HANDOVER_COMPLETED,
1528 BSC_CTR_HANDOVER_STOPPED,
Alexander Couzensb847a212016-08-02 11:34:11 +02001529 BSC_CTR_HANDOVER_NO_CHANNEL,
1530 BSC_CTR_HANDOVER_TIMEOUT,
Alexander Couzensb847a212016-08-02 11:34:11 +02001531 BSC_CTR_HANDOVER_FAILED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001532 BSC_CTR_HANDOVER_ERROR,
1533 BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED,
1534 BSC_CTR_INTER_BSC_HO_OUT_COMPLETED,
1535 BSC_CTR_INTER_BSC_HO_OUT_STOPPED,
1536 BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT,
1537 BSC_CTR_INTER_BSC_HO_OUT_ERROR,
1538 BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED,
1539 BSC_CTR_INTER_BSC_HO_IN_COMPLETED,
1540 BSC_CTR_INTER_BSC_HO_IN_STOPPED,
1541 BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL,
1542 BSC_CTR_INTER_BSC_HO_IN_FAILED,
1543 BSC_CTR_INTER_BSC_HO_IN_TIMEOUT,
1544 BSC_CTR_INTER_BSC_HO_IN_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001545 BSC_CTR_PAGING_ATTEMPTED,
1546 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +01001547 BSC_CTR_PAGING_RESPONDED,
Alexander Chemeris43def742020-05-16 18:49:59 +03001548 BSC_CTR_PAGING_NO_ACTIVE_PAGING,
Stefan Sperling7926d982018-05-17 14:52:02 +02001549 BSC_CTR_UNKNOWN_UNIT_ID,
Alexander Couzensb847a212016-08-02 11:34:11 +02001550};
1551
1552static const struct rate_ctr_desc bsc_ctr_description[] = {
Neels Hofmeyrdbb38d52018-07-11 19:53:56 +02001553 [BSC_CTR_ASSIGNMENT_ATTEMPTED] = {"assignment:attempted", "Assignment attempts."},
1554 [BSC_CTR_ASSIGNMENT_COMPLETED] = {"assignment:completed", "Assignment completed."},
1555 [BSC_CTR_ASSIGNMENT_STOPPED] = {"assignment:stopped", "Connection ended during Assignment."},
1556 [BSC_CTR_ASSIGNMENT_NO_CHANNEL] = {"assignment:no_channel", "Failure to allocate lchan for Assignment."},
1557 [BSC_CTR_ASSIGNMENT_TIMEOUT] = {"assignment:timeout", "Assignment timed out."},
1558 [BSC_CTR_ASSIGNMENT_FAILED] = {"assignment:failed", "Received Assignment Failure message."},
Martin Haukea29affd2019-11-13 22:10:41 +01001559 [BSC_CTR_ASSIGNMENT_ERROR] = {"assignment:error", "Assignment failed for other reason."},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001560
1561 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Intra-BSC handover attempts."},
1562 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Intra-BSC handover completed."},
1563 [BSC_CTR_HANDOVER_STOPPED] = {"handover:stopped", "Connection ended during HO."},
1564 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Failure to allocate lchan for HO."},
1565 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Handover timed out."},
1566 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Received Handover Fail messages."},
Martin Haukea29affd2019-11-13 22:10:41 +01001567 [BSC_CTR_HANDOVER_ERROR] = {"handover:error", "Re-assignment failed for other reason."},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001568
1569 [BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED] = {"interbsc_ho_out:attempted",
1570 "Attempts to handover to remote BSS."},
1571 [BSC_CTR_INTER_BSC_HO_OUT_COMPLETED] = {"interbsc_ho_out:completed",
1572 "Handover to remote BSS completed."},
1573 [BSC_CTR_INTER_BSC_HO_OUT_STOPPED] = {"interbsc_ho_out:stopped", "Connection ended during HO."},
1574 [BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT] = {"interbsc_ho_out:timeout", "Handover timed out."},
1575 [BSC_CTR_INTER_BSC_HO_OUT_ERROR] = {"interbsc_ho_out:error",
1576 "Handover to remote BSS failed for other reason."},
1577
1578 [BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED] = {"interbsc_ho_in:attempted",
1579 "Attempts to handover from remote BSS."},
1580 [BSC_CTR_INTER_BSC_HO_IN_COMPLETED] = {"interbsc_ho_in:completed",
1581 "Handover from remote BSS completed."},
1582 [BSC_CTR_INTER_BSC_HO_IN_STOPPED] = {"interbsc_ho_in:stopped", "Connection ended during HO."},
1583 [BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL] = {"interbsc_ho_in:no_channel",
1584 "Failure to allocate lchan for HO."},
1585 [BSC_CTR_INTER_BSC_HO_IN_TIMEOUT] = {"interbsc_ho_in:timeout", "Handover from remote BSS timed out."},
1586 [BSC_CTR_INTER_BSC_HO_IN_FAILED] = {"interbsc_ho_in:failed", "Received Handover Fail message."},
1587 [BSC_CTR_INTER_BSC_HO_IN_ERROR] = {"interbsc_ho_in:error",
1588 "Handover from remote BSS failed for other reason."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001589
1590 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001591 [BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Paging request send failures because no responsible BTS was found."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001592 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response."},
Alexander Chemeris43def742020-05-16 18:49:59 +03001593 [BSC_CTR_PAGING_NO_ACTIVE_PAGING] = {"paging:no_active_paging", "Paging response without an active paging request (arrived after paging expiration?)."},
Stefan Sperling7926d982018-05-17 14:52:02 +02001594
1595 [BSC_CTR_UNKNOWN_UNIT_ID] = {"abis:unknown_unit_id", "Connection attempts from unknown IPA CCM Unit ID."},
Alexander Couzensb847a212016-08-02 11:34:11 +02001596};
1597
Alexander Couzensb847a212016-08-02 11:34:11 +02001598
1599
1600static const struct rate_ctr_group_desc bsc_ctrg_desc = {
1601 "bsc",
1602 "base station controller",
1603 OSMO_STATS_CLASS_GLOBAL,
1604 ARRAY_SIZE(bsc_ctr_description),
1605 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +02001606};
1607
Alexander Chemerisdb542832020-05-08 01:49:12 +03001608/* Constants for the BSC stats */
1609enum {
1610 BSC_STAT_NUM_BTS_TOTAL,
1611};
1612
Neels Hofmeyr73983952016-05-10 13:29:33 +02001613struct gsm_tz {
1614 int override; /* if 0, use system's time zone instead. */
1615 int hr; /* hour */
1616 int mn; /* minute */
1617 int dst; /* daylight savings */
1618};
1619
Harald Welte52b1f982008-12-23 20:25:15 +00001620struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001621 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
1622 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
1623 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
1624 * these have in common, like country and network code, put in yet
1625 * separate structs and placed as members in osmo_bsc and osmo_msc. */
1626
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001627 struct osmo_plmn_id plmn;
1628
Harald Welte51e4bf32017-12-23 17:30:18 +01001629 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
1630 uint8_t a5_encryption_mask;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001631 int neci;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001632
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001633 struct handover_cfg *ho;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001634 struct {
1635 unsigned int congestion_check_interval_s;
1636 struct osmo_timer_list congestion_check_timer;
1637 } hodec2;
Harald Welte52b1f982008-12-23 20:25:15 +00001638
Alexander Chemerisdb542832020-05-08 01:49:12 +03001639 /* structures for keeping rate counters and gauge stats */
Alexander Couzensb847a212016-08-02 11:34:11 +02001640 struct rate_ctr_group *bsc_ctrs;
Alexander Chemerisdb542832020-05-08 01:49:12 +03001641 struct osmo_stat_item_group *bsc_statg;
Harald Welte24ff6ee2009-12-22 00:41:05 +01001642
Harald Welte52b1f982008-12-23 20:25:15 +00001643 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +02001644 struct llist_head bts_list;
Oliver Smith8d8d7102018-10-23 15:35:43 +02001645 struct llist_head bts_rejected;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001646
Neels Hofmeyr08822a32019-07-11 03:43:34 +02001647 /* see gsm_network_T_defs */
Neels Hofmeyra6078fe2019-01-28 03:52:14 +01001648 struct osmo_tdef *T_defs;
Harald Welteeab84a12009-12-13 10:53:12 +01001649
Alexander Couzens547c2072017-11-21 12:03:04 +01001650 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +08001651
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +08001652 /* Use a TCH for handling requests of type paging any */
1653 int pag_any_tch;
1654
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08001655 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +02001656 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +01001657
Daniel Willmann6fc4a982011-07-22 17:55:42 +02001658 /* control interface */
1659 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +02001660
1661 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
1662 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +02001663
1664 /* all active subscriber connections. */
1665 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +02001666
1667 /* if override is nonzero, this timezone data is used for all MM
1668 * contexts. */
1669 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
1670 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +01001671 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +02001672 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +01001673
1674 /* List of all struct bsc_subscr used in libbsc. This llist_head is
1675 * allocated so that the llist_head pointer itself can serve as a
1676 * talloc context (useful to not have to pass the entire gsm_network
1677 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
1678 * not require gsm_data.h). In an MSC-without-BSC environment, this
1679 * pointer is NULL to indicate absence of a bsc_subscribers list. */
1680 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +02001681
Stefan Sperling6cee8932018-01-30 18:14:22 +01001682 /* Timer for periodic channel load measurements to maintain each BTS's T3122. */
1683 struct osmo_timer_list t3122_chan_load_timer;
1684
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001685 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +02001686 struct mgcp_client_conf *conf;
1687 struct mgcp_client *client;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +02001688 struct osmo_tdef *tdefs;
Philipp Maier39c609b2017-09-27 15:51:34 +02001689 } mgw;
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001690
1691 /* Remote BSS Cell Identifier Lists */
1692 struct neighbor_ident_list *neighbor_bss_cells;
Oliver Smitha595db12020-03-17 12:21:00 +01001693
1694 /* Don't refuse to start with mutually exclusive codec settings */
1695 bool allow_unusable_timeslots;
Harald Welte7e310b12009-03-30 20:56:32 +00001696};
1697
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001698struct gsm_audio_support {
1699 uint8_t hr : 1,
1700 ver : 7;
1701};
1702
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001703static inline const struct osmo_location_area_id *bts_lai(struct gsm_bts *bts)
1704{
1705 static struct osmo_location_area_id lai;
1706 lai = (struct osmo_location_area_id){
1707 .plmn = bts->network->plmn,
1708 .lac = bts->location_area_code,
1709 };
1710 return &lai;
1711}
1712
Neels Hofmeyrc13e6872016-05-11 13:53:47 +02001713extern void talloc_ctx_init(void *ctx_root);
1714
Harald Welte39315c42010-01-10 18:01:52 +01001715int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +02001716
Harald Welte1d014a52009-08-08 15:38:29 +02001717enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +02001718const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +00001719struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
1720 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +00001721
Andreas Eversberg8226fa72009-06-29 15:19:38 +02001722extern void *tall_bsc_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +02001723
Martin Haukea29affd2019-11-13 22:10:41 +01001724/* this actually refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +00001725static inline int is_ipaccess_bts(struct gsm_bts *bts)
1726{
1727 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001728 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001729 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +00001730 return 1;
1731 default:
1732 break;
1733 }
1734 return 0;
1735}
1736
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001737static inline int is_sysmobts_v2(struct gsm_bts *bts)
1738{
1739 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +01001740 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001741 return 1;
1742 default:
1743 break;
1744 }
1745 return 0;
1746}
1747
Harald Welte5b570672009-08-10 10:08:01 +02001748static inline int is_siemens_bts(struct gsm_bts *bts)
1749{
1750 switch (bts->type) {
1751 case GSM_BTS_TYPE_BS11:
1752 return 1;
1753 default:
1754 break;
1755 }
1756
1757 return 0;
1758}
1759
Andreas Eversberg7d8fa342013-12-05 13:25:06 +01001760static inline int is_nokia_bts(struct gsm_bts *bts)
1761{
1762 switch (bts->type) {
1763 case GSM_BTS_TYPE_NOKIA_SITE:
1764 return 1;
1765 default:
1766 break;
1767 }
1768
1769 return 0;
1770}
1771
Sylvain Munaut57a1ec52020-05-08 09:58:26 +02001772static inline int is_ericsson_bts(struct gsm_bts *bts)
1773{
1774 switch (bts->type) {
1775 case GSM_BTS_TYPE_RBS2000:
1776 return 1;
1777 default:
1778 break;
1779 }
1780
1781 return 0;
1782}
1783
Andreas Eversbergdcf38e12013-12-05 14:37:11 +01001784static inline int is_e1_bts(struct gsm_bts *bts)
1785{
1786 switch (bts->type) {
1787 case GSM_BTS_TYPE_BS11:
1788 case GSM_BTS_TYPE_RBS2000:
1789 case GSM_BTS_TYPE_NOKIA_SITE:
1790 return 1;
1791 default:
1792 break;
1793 }
1794
1795 return 0;
1796}
1797
Harald Welte1876c312018-05-27 11:53:43 +02001798extern struct gsm_network *bsc_gsmnet;
1799
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001800enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +02001801const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001802int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +02001803
Neels Hofmeyr4d358c02018-02-22 03:19:05 +01001804void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +08001805void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +01001806
Harald Weltefbda4e12010-03-04 11:04:52 +01001807int gsm_bts_model_register(struct gsm_bts_model *model);
1808
Harald Welte3561bd42018-01-28 03:04:16 +01001809struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *network);
Neels Hofmeyr42eb0142016-05-20 17:15:44 +02001810
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001811struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, uint8_t bsic);
1812struct 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 +01001813
Harald Welte3300c012011-06-05 13:31:33 +02001814void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
1815 uint8_t e1_ts, uint8_t e1_ts_ss);
1816
Maxbe356ed2017-09-07 19:10:09 +02001817void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Harald Welte3300c012011-06-05 13:31:33 +02001818struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +01001819int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -04001820int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +02001821
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +02001822/* generic E1 line operations for all ISDN-based BTS. */
1823extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
1824
Harald Weltee555c2b2012-08-17 13:02:12 +02001825extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
1826extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
1827
Max3d049d22017-10-09 17:12:53 +02001828char *get_model_oml_status(const struct gsm_bts *bts);
1829
Max25cc4072017-10-10 14:50:35 +02001830unsigned long long bts_uptime(const struct gsm_bts *bts);
1831
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +01001832/* control interface handling */
1833int bsc_base_ctrl_cmds_install(void);
1834
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001835/* dependency handling */
1836void bts_depend_mark(struct gsm_bts *bts, int dep);
1837void bts_depend_clear(struct gsm_bts *bts, int dep);
1838int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +01001839int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001840
Harald Welte2f8b9d22017-06-18 11:12:13 +03001841int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
1842void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
1843
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001844bool trx_is_usable(const struct gsm_bts_trx *trx);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001845bool ts_is_usable(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001846
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001847int gsm_lchan_type_by_pchan(enum gsm_phys_chan_config pchan);
1848enum gsm_phys_chan_config gsm_pchan_by_lchan_type(enum gsm_chan_t type);
1849
1850void gsm_bts_all_ts_dispatch(struct gsm_bts *bts, uint32_t ts_ev, void *data);
1851void gsm_trx_all_ts_dispatch(struct gsm_bts_trx *trx, uint32_t ts_ev, void *data);
1852
1853int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001854
Vadim Yanitskiy73bd4632019-11-02 00:57:23 +07001855bool trx_has_valid_pchan_config(const struct gsm_bts_trx *trx);
1856
Harald Welte6be350c2011-05-25 13:10:08 +02001857#endif /* _GSM_DATA_H */