blob: dacc63b15bf3845d05e5342b029e4fc3bcc084c3 [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
Philipp Maierbb66d102019-01-22 11:29:06 +0100101struct channel_mode_and_rate {
102 enum gsm48_chan_mode chan_mode;
Neels Hofmeyr0848ff82019-03-14 22:11:45 +0000103 bool full_rate;
Philipp Maierbb66d102019-01-22 11:29:06 +0100104 uint16_t s15_s0;
105};
106
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100107/* Information retrieved during an Assignment Request from the MSC. This is storage of the Assignment instructions
108 * parsed from the Assignment Request message, to pass on until the gscon and assignment FSMs have decided whether an
109 * Assignment is actually going to be carried out. Should remain unchanged after initial decoding. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200110struct assignment_request {
111 bool aoip;
112
113 uint16_t msc_assigned_cic;
114
115 char msc_rtp_addr[INET_ADDRSTRLEN];
116 uint16_t msc_rtp_port;
117
Neels Hofmeyr0848ff82019-03-14 22:11:45 +0000118 /* Prefered rate/codec setting (mandatory) */
119 struct channel_mode_and_rate ch_mode_rate_pref;
120
121 /* Alternate rate/codec setting (optional) */
122 bool ch_mode_rate_alt_present;
123 struct channel_mode_and_rate ch_mode_rate_alt;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200124};
125
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100126/* State of an ongoing Assignment, while the assignment_fsm is still busy. This serves as state separation to keep the
127 * currently used lchan and gscon unmodified until the outcome of an Assignment is known. If the Assignment fails, this
128 * state is simply discarded, and the gscon carries on with the original lchan remaining unchanged. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200129struct assignment_fsm_data {
130 struct assignment_request req;
131 bool requires_voice_stream;
132
133 struct osmo_fsm_inst *fi;
134 struct gsm_lchan *new_lchan;
135
136 /* Whether this assignment triggered creation of the MGW endpoint: if the assignment
137 * fails, we will release that again as soon as possible. (If false, the endpoint already
138 * existed before or isn't needed at all.)*/
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200139 struct osmo_mgcpc_ep_ci *created_ci_for_msc;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200140
141 enum gsm0808_cause failure_cause;
142 enum gsm48_rr_cause rr_cause;
143
144 bool result_rate_ctr_done;
145};
146
147enum hodec_id {
148 HODEC_NONE,
149 HODEC1 = 1,
150 HODEC2 = 2,
151 HODEC_USER,
152 HODEC_REMOTE,
153};
154
155/* For example, to count specific kinds of ongoing handovers, it is useful to be able to OR-combine
156 * scopes. */
157enum handover_scope {
158 HO_NO_HANDOVER = 0,
159 HO_INTRA_CELL = 0x1,
160 HO_INTRA_BSC = 0x2,
161 HO_INTER_BSC_OUT = 0x4,
162 HO_INTER_BSC_IN = 0x8,
163 HO_SCOPE_ALL = 0xffff,
164};
165
166extern const struct value_string handover_scope_names[];
167inline static const char *handover_scope_name(enum handover_scope val)
168{ return get_value_string(handover_scope_names, val); }
169
170struct handover_out_req {
171 enum hodec_id from_hodec_id;
172 struct gsm_lchan *old_lchan;
173 struct neighbor_ident_key target_nik;
174 enum gsm_chan_t new_lchan_type; /*< leave GSM_LCHAN_NONE to use same as old_lchan */
175};
176
177struct handover_in_req {
178 struct gsm0808_channel_type ct;
179 struct gsm0808_speech_codec_list scl;
180 struct gsm0808_encrypt_info ei;
181 struct gsm_classmark classmark;
Neels Hofmeyrc15f6cd2019-03-15 02:48:39 +0100182 /* chosen_encr_alg reflects the encoded value as in RSL_ENC_ALG_A5(a5_numer):
183 * chosen_encr_alg == 1 means A5/0 i.e. no encryption, chosen_encr_alg == 4 means A5/3.
184 * chosen_encr_alg == 0 means no such IE was present. */
185 uint8_t chosen_encr_alg;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200186 struct gsm0808_cell_id cell_id_serving;
187 char cell_id_serving_name[64];
188 struct gsm0808_cell_id cell_id_target;
189 char cell_id_target_name[64];
190 uint16_t msc_assigned_cic;
191 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
192 uint16_t msc_assigned_rtp_port;
193};
194
195struct handover {
196 struct osmo_fsm_inst *fi;
197
198 enum hodec_id from_hodec_id;
199 enum handover_scope scope;
200 enum gsm_chan_t new_lchan_type;
201 struct neighbor_ident_key target_cell;
202
203 uint8_t ho_ref;
204 struct gsm_bts *new_bts;
205 struct gsm_lchan *new_lchan;
206 bool async;
207 struct handover_in_req inter_bsc_in;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200208 struct osmo_mgcpc_ep_ci *created_ci_for_msc;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200209};
210
Neels Hofmeyr378a4922016-05-09 21:07:43 +0200211/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100212struct gsm_subscriber_connection {
Harald Weltea43e0b42016-06-19 18:06:02 +0200213 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +0800214 struct llist_head entry;
215
Harald Welte3561bd42018-01-28 03:04:16 +0100216 /* FSM instance to control the subscriber connection state (RTP, A) */
217 struct osmo_fsm_inst *fi;
218
Harald Weltea43e0b42016-06-19 18:06:02 +0200219 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100220 struct bsc_subscr *bsub;
221
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100222 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200223 struct gsm_network *network;
224
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100225 /* the primary / currently active lchan to the BTS/subscriber. During Assignment and Handover, separate lchans
226 * are kept in the .assignment or .handover sub-structs, respectively, so that this lchan remains unaffected
227 * until Assignment or Handover have actually succeeded. */
Harald Welte4a8ebc82017-12-18 18:34:41 +0100228 struct gsm_lchan *lchan;
Harald Welte3561bd42018-01-28 03:04:16 +0100229
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100230 /* Only valid during an ongoing Assignment; might be overwritten at any time by a failed Assignment attempt.
231 * Once an Assignment was successful, all relevant state must be copied out of this sub-struct. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200232 struct assignment_fsm_data assignment;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100233
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100234 /* handover information, if a handover is pending for this conn. Valid only during an ongoing Handover
235 * operation. If a Handover was successful, all relevant state must be copied out of this sub-struct. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200236 struct handover ho;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100237
Harald Welte4a8ebc82017-12-18 18:34:41 +0100238 /* buffer/cache for classmark of the ME of the subscriber */
Harald Weltea43e0b42016-06-19 18:06:02 +0200239 struct gsm_classmark classmark;
Andreas Eversberg935e5d72013-06-17 11:58:30 +0200240
Neels Hofmeyr149160f2018-06-16 17:20:13 +0200241 /* Queue DTAP messages during handover/assignment (msgb_enqueue()/msgb_dequeue())*/
242 struct llist_head dtap_queue;
243 unsigned int dtap_queue_len;
Andreas Eversberg084b4212013-05-30 14:12:48 +0200244
Neels Hofmeyrec422642018-02-15 14:07:40 +0100245 struct {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100246 int failures;
Neels Hofmeyrec422642018-02-15 14:07:40 +0100247 struct penalty_timers *penalty_timers;
248 } hodec2;
Neels Hofmeyra60f3442018-02-12 16:44:32 +0100249
250 /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment Request. 3GPP 48.008
251 * 3.2.2.103 says:
252 * The "Codec List (MSC Preferred)" shall not include codecs
253 * that are not supported by the MS.
254 * i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed the MS bearer
255 * capabilities, which the MSC is required to translate into the codec list. */
256 struct gsm0808_speech_codec_list codec_list;
Harald Welte519c7e12018-01-28 02:45:46 +0100257
258 /* flag to prevent multiple simultaneous ciphering commands */
259 int ciphering_handled;
260
261 /* state related to welcome USSD */
262 uint8_t new_subscriber;
263
264 /* state related to osmo_bsc_filter.c */
265 struct bsc_filter_state filter_state;
266
267 /* SCCP connection associatd with this subscriber_connection */
268 struct {
269 /* for advanced ping/pong */
270 int send_ping;
271
272 /* SCCP connection realted */
273 struct bsc_msc_data *msc;
274
275 /* Sigtran connection ID */
276 int conn_id;
277 enum subscr_sccp_state state;
278 } sccp;
279
280 /* for audio handling */
281 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200282 uint16_t msc_assigned_cic;
Harald Welte519c7e12018-01-28 02:45:46 +0100283
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200284 /* RTP address where the MSC expects us to send the RTP stream coming from the BTS. */
285 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
286 uint16_t msc_assigned_rtp_port;
Harald Welte519c7e12018-01-28 02:45:46 +0100287
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200288 /* The endpoint at the MGW used to join both BTS and MSC side connections, e.g.
289 * "rtpbridge/23@mgw". */
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200290 struct osmo_mgcpc_ep *mgw_endpoint;
Harald Welte3561bd42018-01-28 03:04:16 +0100291
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200292 /* The connection identifier of the osmo_mgcpc_ep used to transceive RTP towards the MSC.
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200293 * (The BTS side CI is handled by struct gsm_lchan and the lchan_fsm.) */
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200294 struct osmo_mgcpc_ep_ci *mgw_endpoint_ci_msc;
Harald Welte519c7e12018-01-28 02:45:46 +0100295 } user_plane;
Harald Weltec997ceb2018-05-30 01:39:43 +0200296
297 /* LCLS (local call, local switch) related state */
298 struct {
299 uint8_t global_call_ref[15];
300 uint8_t global_call_ref_len; /* length of global_call_ref */
Maxfe65ece2018-11-09 13:36:11 +0100301 enum gsm0808_lcls_config config; /* TS 48.008 3.2.2.116 */
302 enum gsm0808_lcls_control control; /* TS 48.008 3.2.2.117 */
Harald Weltec997ceb2018-05-30 01:39:43 +0200303 /* LCLS FSM */
304 struct osmo_fsm_inst *fi;
305 /* pointer to "other" connection, if Call Leg Relocation was successful */
306 struct gsm_subscriber_connection *other;
307 } lcls;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100308};
309
Harald Weltef142c972011-05-24 13:25:38 +0200310
Neels Hofmeyr10485162018-02-13 23:22:03 +0100311/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 Table 10.5.2.33b.1:
312 4-bit index is used (2#1111 = 10#15) */
313#define SI2Q_MAX_NUM 16
314/* length in bits (for single SI2quater message) */
315#define SI2Q_MAX_LEN 160
316#define SI2Q_MIN_LEN 18
317
318struct osmo_bsc_data;
319
320struct osmo_bsc_sccp_con;
321
322/* Channel Request reason */
323enum gsm_chreq_reason_t {
324 GSM_CHREQ_REASON_EMERG,
325 GSM_CHREQ_REASON_PAG,
326 GSM_CHREQ_REASON_CALL,
327 GSM_CHREQ_REASON_LOCATION_UPD,
328 GSM_CHREQ_REASON_OTHER,
329 GSM_CHREQ_REASON_PDCH,
330};
331
332/* lchans 0..3 are SDCCH in combined channel configuration,
333 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
334#define CCCH_LCHAN 4
335
336#define TRX_NR_TS 8
337#define TS_MAX_LCHAN 8
338
339#define HARDCODED_ARFCN 123
340#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
341
342/* for multi-drop config */
343#define HARDCODED_BTS0_TS 1
344#define HARDCODED_BTS1_TS 6
345#define HARDCODED_BTS2_TS 11
346
347#define MAX_VERSION_LENGTH 64
348
Neels Hofmeyr10485162018-02-13 23:22:03 +0100349enum gsm_hooks {
350 GSM_HOOK_NM_SWLOAD,
351 GSM_HOOK_RR_PAGING,
352 GSM_HOOK_RR_SECURITY,
353};
354
Neels Hofmeyr10485162018-02-13 23:22:03 +0100355enum bts_gprs_mode {
356 BTS_GPRS_NONE = 0,
357 BTS_GPRS_GPRS = 1,
358 BTS_GPRS_EGPRS = 2,
359};
360
361struct gsm_lchan;
362struct osmo_rtp_socket;
363struct rtp_socket;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100364
365/* Network Management State */
366struct gsm_nm_state {
367 uint8_t operational;
368 uint8_t administrative;
369 uint8_t availability;
370};
371
372struct gsm_abis_mo {
373 uint8_t obj_class;
374 uint8_t procedure_pending;
375 struct abis_om_obj_inst obj_inst;
376 const char *name;
377 struct gsm_nm_state nm_state;
378 struct tlv_parsed *nm_attr;
379 struct gsm_bts *bts;
380};
381
382/* Ericsson OM2000 Managed Object */
383struct abis_om2k_mo {
384 uint8_t class;
385 uint8_t bts;
386 uint8_t assoc_so;
387 uint8_t inst;
388} __attribute__ ((packed));
389
390struct om2k_mo {
391 struct abis_om2k_mo addr;
392 struct osmo_fsm_inst *fsm;
393};
394
395#define A38_XOR_MIN_KEY_LEN 12
396#define A38_XOR_MAX_KEY_LEN 16
397#define A38_COMP128_KEY_LEN 16
398#define RSL_ENC_ALG_A5(x) (x+1)
399#define MAX_EARFCN_LIST 32
400
401/* is the data link established? who established it? */
402#define LCHAN_SAPI_UNUSED 0
403#define LCHAN_SAPI_MS 1
404#define LCHAN_SAPI_NET 2
Neels Hofmeyr10485162018-02-13 23:22:03 +0100405
406/* BTS ONLY */
407#define MAX_NUM_UL_MEAS 104
408#define LC_UL_M_F_L1_VALID (1 << 0)
409#define LC_UL_M_F_RES_VALID (1 << 1)
410
411struct bts_ul_meas {
412 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
413 uint16_t ber10k;
414 /* timing advance offset (in quarter bits) */
415 int16_t ta_offs_qbits;
416 /* C/I ratio in dB */
417 float c_i;
418 /* flags */
419 uint8_t is_sub:1;
420 /* RSSI in dBm * -1 */
421 uint8_t inv_rssi;
422};
423
424struct bts_codec_conf {
425 uint8_t hr;
426 uint8_t efr;
427 uint8_t amr;
428};
429
430struct amr_mode {
431 uint8_t mode;
432 uint8_t threshold;
433 uint8_t hysteresis;
434};
435
436struct amr_multirate_conf {
437 uint8_t gsm48_ie[2];
438 struct amr_mode ms_mode[4];
439 struct amr_mode bts_mode[4];
440 uint8_t num_modes;
441};
442/* /BTS ONLY */
443
444enum lchan_csd_mode {
445 LCHAN_CSD_M_NT,
446 LCHAN_CSD_M_T_1200_75,
447 LCHAN_CSD_M_T_600,
448 LCHAN_CSD_M_T_1200,
449 LCHAN_CSD_M_T_2400,
450 LCHAN_CSD_M_T_9600,
451 LCHAN_CSD_M_T_14400,
452 LCHAN_CSD_M_T_29000,
453 LCHAN_CSD_M_T_32000,
454};
455
456/* State of the SAPIs in the lchan */
457enum lchan_sapi_state {
458 LCHAN_SAPI_S_NONE,
459 LCHAN_SAPI_S_REQ,
460 LCHAN_SAPI_S_ASSIGNED,
461 LCHAN_SAPI_S_REL,
462 LCHAN_SAPI_S_ERROR,
463};
464
Neels Hofmeyr92b9f2e2018-02-14 00:19:11 +0100465#define MAX_A5_KEY_LEN (128/8)
466
467struct gsm_encr {
468 uint8_t alg_id;
469 uint8_t key_len;
470 uint8_t key[MAX_A5_KEY_LEN];
471};
472
Neels Hofmeyr8da22332018-04-11 01:43:41 +0200473#define LOGPLCHAN(lchan, ss, level, fmt, args...) \
474 LOGP(ss, level, "%s (ss=%d,%s) (%s) " fmt, \
475 lchan ? gsm_ts_and_pchan_name(lchan->ts) : "-", \
476 lchan ? lchan->nr : 0, \
477 lchan ? gsm_lchant_name(lchan->type) : "-", \
478 bsc_subscr_name(lchan && lchan->conn ? lchan->conn->bsub : NULL), \
479 ## args)
480
Pau Espin Pedrold3e8e0c2018-11-28 16:35:10 +0100481/* Iterate lchans that have an FSM allocated based based on explicit pchan kind
482 * (GSM_PCHAN_* constant).
483 * Remark: PDCH related lchans are not handled in BSC but in PCU, so trying to
484 * iterate through GSM_PCHAN_PDCH is considered a void loop.
485 */
486#define ts_as_pchan_for_each_lchan(lchan, ts, as_pchan) \
487 for (lchan = (ts)->lchan; \
488 ((lchan - (ts)->lchan) < ARRAY_SIZE((ts)->lchan)) \
489 && lchan->fi \
490 && lchan->nr < pchan_subslots(as_pchan); \
491 lchan++)
492
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100493/* Iterate lchans that have an FSM allocated based on current PCHAN
494 * mode set in \ref ts.
495 * usage:
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200496 * struct gsm_lchan *lchan;
497 * struct gsm_bts_trx_ts *ts = get_some_timeslot();
498 * ts_for_each_lchan(lchan, ts) {
499 * LOGPLCHAN(DMAIN, LOGL_DEBUG, "hello world\n");
500 * }
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100501 */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200502#define ts_for_each_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_is)
503
Pau Espin Pedrol0ba20df2018-11-28 16:39:29 +0100504/* Iterate over all possible lchans available that have an FSM allocated based
505 * on PCHAN \ref ts (dynamic) configuration.
506 * Iterate all lchan instances set up by this \ref ts type, including those
507 * lchans currently disabled or in process of being enabled (e.g. due to dynamic
508 * timeslot in switchover). Compare ts_for_each_lchan(), which iterates only the
509 * enabled lchans.
510 * For example, it is useful in case dynamic timeslot \ref ts is in process of
511 * switching from configuration PDCH (no lchans) to TCH_F (1 lchan), where
512 * pchan_is is still set to PDCH but \ref ts may contain already an \ref lchan
513 * of type TCH_F which initiated the request to switch the \ts configuration.
514 */
515#define ts_for_each_potential_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_on_init)
516
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200517enum lchan_activate_mode {
518 FOR_NONE,
519 FOR_MS_CHANNEL_REQUEST,
520 FOR_ASSIGNMENT,
521 FOR_HANDOVER,
522 FOR_VTY,
523};
524
525extern const struct value_string lchan_activate_mode_names[];
526static inline const char *lchan_activate_mode_name(enum lchan_activate_mode activ_for)
527{ return get_value_string(lchan_activate_mode_names, activ_for); }
528
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100529struct lchan_activate_info {
530 enum lchan_activate_mode activ_for;
531 struct gsm_subscriber_connection *for_conn;
532 /* This always is for a specific lchan, so its lchan->type indicates full or half rate.
533 * When a dyn TS was selected, the lchan->type has been set to the desired rate. */
534 enum gsm48_chan_mode chan_mode;
Neels Hofmeyr58cf1b12019-03-15 02:49:18 +0100535 struct gsm_encr encr;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100536 /* AMR config */
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100537 uint16_t s15_s0;
538 bool requires_voice_stream;
539 bool wait_before_switching_rtp; /*< true = requires LCHAN_EV_READY_TO_SWITCH_RTP */
540 uint16_t msc_assigned_cic;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100541 /* During intra-BSC handover, we keep the MGW endpoint intact and just re-route to the new lchan. This
542 * 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 +0100543 struct gsm_lchan *re_use_mgw_endpoint_from_lchan;
544};
545
Neels Hofmeyr10485162018-02-13 23:22:03 +0100546struct gsm_lchan {
547 /* The TS that we're part of */
548 struct gsm_bts_trx_ts *ts;
549 /* The logical subslot number in the TS */
550 uint8_t nr;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200551 char *name;
552
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100553 char *last_error;
554
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200555 struct osmo_fsm_inst *fi;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200556 struct osmo_fsm_inst *fi_rtp;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200557 struct osmo_mgcpc_ep_ci *mgw_endpoint_ci_bts;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200558
559 struct {
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100560 struct lchan_activate_info info;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200561 bool activ_ack; /*< true as soon as RSL Chan Activ Ack is received */
Neels Hofmeyr369fba22018-11-27 01:30:50 +0100562 bool immediate_assignment_sent;
Neels Hofmeyr193c1e32018-08-27 22:06:24 +0200563 /*! This flag ensures that when an lchan activation has succeeded, and we have already
564 * sent ACKs like Immediate Assignment or BSSMAP Assignment Complete, and if other errors
565 * occur later, e.g. during release, that we don't send a NACK out of context. */
566 bool concluded;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200567 enum gsm0808_cause gsm0808_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200568 } activate;
569
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100570 struct {
571 /* If an event to release the lchan comes in while still waiting for responses, just mark this
572 * flag, so that the lchan will gracefully release at the next sensible junction. */
573 bool requested;
574 bool do_rr_release;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200575
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100576 /* There is an RSL error cause of value 0, so we need a separate flag. */
577 bool in_error;
578 /* RSL error code, RSL_ERR_* */
579 uint8_t rsl_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200580
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100581 /* If a release event is being handled, ignore other ricocheting release events until that
582 * release handling has concluded. */
583 bool in_release_handler;
Harald Welte963763d2019-02-03 12:11:12 +0100584
585 /* is this release at the end of a CSFB call? */
586 bool is_csfb;
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100587 } release;
Neels Hofmeyrd5df9a12018-07-20 05:35:47 +0200588
Neels Hofmeyr10485162018-02-13 23:22:03 +0100589 /* The logical channel type */
590 enum gsm_chan_t type;
591 /* RSL channel mode */
592 enum rsl_cmod_spd rsl_cmode;
593 /* If TCH, traffic channel mode */
594 enum gsm48_chan_mode tch_mode;
595 enum lchan_csd_mode csd_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100596 /* Power levels for MS and BTS */
597 uint8_t bs_power;
598 uint8_t ms_power;
599 /* Encryption information */
600 struct gsm_encr encr;
601
602 /* AMR bits */
603 uint8_t mr_ms_lv[7];
604 uint8_t mr_bts_lv[7];
Neels Hofmeyr4daa2102019-01-30 16:46:58 +0100605 /* AMR bits were based on these rate bits: */
606 uint16_t s15_s0;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100607
608 /* Established data link layer services */
609 uint8_t sapis[8];
610
611 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200612 uint32_t bound_ip; /*< where the BTS receives RTP */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100613 uint16_t bound_port;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200614 uint32_t connect_ip; /*< where the BTS sends RTP to (MGW) */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100615 uint16_t connect_port;
616 uint16_t conn_id;
617 uint8_t rtp_payload;
618 uint8_t rtp_payload2;
619 uint8_t speech_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100620
621 /* info we need to postpone the AoIP
622 * assignment completed message */
623 struct {
624 uint8_t rr_cause;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100625 bool valid;
626 } ass_compl;
627 } abis_ip;
628
629 uint8_t rqd_ta;
630
Neels Hofmeyr10485162018-02-13 23:22:03 +0100631 /* table of neighbor cell measurements */
632 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
633
634 /* cache of last measurement reports on this lchan */
635 struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
636 int meas_rep_idx;
637 int meas_rep_count;
Neels Hofmeyr35ba85c2018-02-12 16:47:40 +0100638 uint8_t meas_rep_last_seen_nr;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100639
640 /* GSM Random Access data */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200641 /* TODO: don't allocate this, rather keep an "is_present" flag */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100642 struct gsm48_req_ref *rqd_ref;
643
644 struct gsm_subscriber_connection *conn;
Philipp Maierbb66d102019-01-22 11:29:06 +0100645
646 /* Depending on the preferences that where submitted together with
647 * the assignment and the current channel load, the BSC has to select
648 * one of the offered codec/rates. The final selection by the BSC is
649 * stored here and is used when sending the assignment complete or
650 * when performing a handover procedure. */
651 struct channel_mode_and_rate ch_mode_rate;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100652};
653
Neels Hofmeyr10485162018-02-13 23:22:03 +0100654/* One Timeslot in a TRX */
655struct gsm_bts_trx_ts {
656 struct gsm_bts_trx *trx;
657 /* number of this timeslot at the TRX */
658 uint8_t nr;
659
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200660 struct osmo_fsm_inst *fi;
661 char *last_errmsg;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100662
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200663 /* vty phys_chan_config setting, not necessarily in effect in case it was changed in the telnet
664 * vty after OML activation. Gets written on vty 'write file'. */
665 enum gsm_phys_chan_config pchan_from_config;
666 /* When the timeslot OML is established, pchan_from_config is copied here. This is the pchan
667 * currently in effect; for dynamic ts, this is the dyn kind (GSM_PCHAN_TCH_F_TCH_H_PDCH or
668 * GSM_PCHAN_TCH_F_PDCH) and does not show the pchan type currently active. */
669 enum gsm_phys_chan_config pchan_on_init;
670 /* This is the *actual* pchan type currently active. For dynamic timeslots, this reflects either
671 * GSM_PCHAN_NONE or one of the standard GSM_PCHAN_TCH_F, GSM_PCHAN_TCH_H, GSM_PCHAN_PDCH.
672 * Callers can use this transparently without being aware of dyn ts. */
673 enum gsm_phys_chan_config pchan_is;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100674
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200675 /* After a PDCH ACT NACK, we shall not infinitely loop to try and ACT again.
676 * Also marks a timeslot where PDCH was deactivated by VTY. This is cleared whenever a timeslot
677 * enters IN_USE state, i.e. after each TCH use we try to PDCH ACT once again. */
678 bool pdch_act_allowed;
679
Neels Hofmeyrbcdbfb72018-07-26 20:33:15 +0200680 /* Whether TS_EV_OML_READY was received */
681 bool is_oml_ready;
682 /* Whether TS_EV_RSL_READY was received */
683 bool is_rsl_ready;
684
Neels Hofmeyr10485162018-02-13 23:22:03 +0100685 struct gsm_abis_mo mo;
686 struct tlv_parsed nm_attr;
687 uint8_t nm_chan_comb;
688 int tsc; /* -1 == use BTS TSC */
689
690 struct {
691 /* Parameters below are configured by VTY */
692 int enabled;
693 uint8_t maio;
694 uint8_t hsn;
695 struct bitvec arfcns;
696 uint8_t arfcns_data[1024/8];
697 /* This is the pre-computed MA for channel assignments */
698 struct bitvec ma;
699 uint8_t ma_len; /* part of ma_data that is used */
700 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
701 } hopping;
702
703 /* To which E1 subslot are we connected */
704 struct gsm_e1_subslot e1_link;
705
706 union {
707 struct {
708 struct om2k_mo om2k_mo;
709 } rbs2000;
710 };
711
712 struct gsm_lchan lchan[TS_MAX_LCHAN];
713};
714
715/* One TRX in a BTS */
716struct gsm_bts_trx {
717 /* list header in bts->trx_list */
718 struct llist_head list;
719
720 struct gsm_bts *bts;
721 /* number of this TRX in the BTS */
722 uint8_t nr;
723 /* human readable name / description */
724 char *description;
725 /* how do we talk RSL with this TRX? */
726 struct gsm_e1_subslot rsl_e1_link;
727 uint8_t rsl_tei;
728 struct e1inp_sign_link *rsl_link;
729
730 /* Timeout for initiating the RSL connection. */
731 struct osmo_timer_list rsl_connect_timeout;
732
733 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
734 struct e1inp_sign_link *oml_link;
735
736 struct gsm_abis_mo mo;
737 struct tlv_parsed nm_attr;
738 struct {
739 struct gsm_abis_mo mo;
740 } bb_transc;
741
742 uint16_t arfcn;
743 int nominal_power; /* in dBm */
744 unsigned int max_power_red; /* in actual dB */
745
746 union {
747 struct {
748 struct {
749 struct gsm_abis_mo mo;
750 } bbsig;
751 struct {
752 struct gsm_abis_mo mo;
753 } pa;
754 } bs11;
755 struct {
756 unsigned int test_state;
757 uint8_t test_nr;
758 struct rxlev_stats rxlev_stat;
759 } ipaccess;
760 struct {
761 struct {
762 struct om2k_mo om2k_mo;
763 } trxc;
764 struct {
765 struct om2k_mo om2k_mo;
766 } rx;
767 struct {
768 struct om2k_mo om2k_mo;
769 } tx;
770 } rbs2000;
771 };
772 struct gsm_bts_trx_ts ts[TRX_NR_TS];
773};
774
775#define GSM_BTS_SI2Q(bts, i) (struct gsm48_system_information_type_2quater *)((bts)->si_buf[SYSINFO_TYPE_2quater][i])
776#define GSM_BTS_HAS_SI(bts, i) ((bts)->si_valid & (1 << i))
777#define GSM_BTS_SI(bts, i) (void *)((bts)->si_buf[i][0])
778#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
779
780enum gsm_bts_type {
781 GSM_BTS_TYPE_UNKNOWN,
782 GSM_BTS_TYPE_BS11,
783 GSM_BTS_TYPE_NANOBTS,
784 GSM_BTS_TYPE_RBS2000,
785 GSM_BTS_TYPE_NOKIA_SITE,
786 GSM_BTS_TYPE_OSMOBTS,
787 _NUM_GSM_BTS_TYPE
788};
789
790enum gsm_bts_type_variant {
791 BTS_UNKNOWN,
792 BTS_OSMO_LITECELL15,
793 BTS_OSMO_OCTPHY,
794 BTS_OSMO_SYSMO,
795 BTS_OSMO_TRX,
796 _NUM_BTS_VARIANT
797};
798
799/* Used by OML layer for BTS Attribute reporting */
800enum bts_attribute {
801 BTS_TYPE_VARIANT,
802 BTS_SUB_MODEL,
803 TRX_PHY_VERSION,
804};
805
806struct vty;
807
808struct gsm_bts_model {
809 struct llist_head list;
810
811 enum gsm_bts_type type;
812 enum gsm_bts_type_variant variant;
813 const char *name;
814
815 bool started;
816 int (*start)(struct gsm_network *net);
817 int (*oml_rcvmsg)(struct msgb *msg);
818 char * (*oml_status)(const struct gsm_bts *bts);
819
820 void (*e1line_bind_ops)(struct e1inp_line *line);
821
822 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
823 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
824 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
825
Pau Espin Pedrol167cb822018-11-19 17:48:17 +0100826 /* Should SI2bis and SI2ter be disabled by default on this BTS model? */
827 bool force_combined_si;
828
Neels Hofmeyr10485162018-02-13 23:22:03 +0100829 struct tlv_definition nm_att_tlvdef;
830
831 /* features of a given BTS model set via gsm_bts_model_register() locally */
832 struct bitvec features;
833 uint8_t _features_data[MAX_BTS_FEATURES/8];
834};
835
Neels Hofmeyr10485162018-02-13 23:22:03 +0100836
Neels Hofmeyr10485162018-02-13 23:22:03 +0100837
838/*
839 * This keeps track of the paging status of one BTS. It
840 * includes a number of pending requests, a back pointer
841 * to the gsm_bts, a timer and some more state.
842 */
843struct gsm_bts_paging_state {
844 /* pending requests */
845 struct llist_head pending_requests;
846 struct gsm_bts *bts;
847
848 struct osmo_timer_list work_timer;
849 struct osmo_timer_list credit_timer;
850
851 /* free chans needed */
852 int free_chans_need;
853
854 /* load */
855 uint16_t available_slots;
856};
857
858struct gsm_envabtse {
859 struct gsm_abis_mo mo;
860};
861
862struct gsm_bts_gprs_nsvc {
863 struct gsm_bts *bts;
864 /* data read via VTY config file, to configure the BTS
865 * via OML from BSC */
866 int id;
867 uint16_t nsvci;
868 uint16_t local_port; /* on the BTS */
869 uint16_t remote_port; /* on the SGSN */
870 uint32_t remote_ip; /* on the SGSN */
871
872 struct gsm_abis_mo mo;
873};
874
875enum gprs_rlc_par {
876 RLC_T3142,
877 RLC_T3169,
878 RLC_T3191,
879 RLC_T3193,
880 RLC_T3195,
881 RLC_N3101,
882 RLC_N3103,
883 RLC_N3105,
884 CV_COUNTDOWN,
885 T_DL_TBF_EXT, /* ms */
886 T_UL_TBF_EXT, /* ms */
887 _NUM_RLC_PAR
888};
889
890enum gprs_cs {
891 GPRS_CS1,
892 GPRS_CS2,
893 GPRS_CS3,
894 GPRS_CS4,
895 GPRS_MCS1,
896 GPRS_MCS2,
897 GPRS_MCS3,
898 GPRS_MCS4,
899 GPRS_MCS5,
900 GPRS_MCS6,
901 GPRS_MCS7,
902 GPRS_MCS8,
903 GPRS_MCS9,
904 _NUM_GRPS_CS
905};
906
907struct gprs_rlc_cfg {
908 uint16_t parameter[_NUM_RLC_PAR];
909 struct {
910 uint16_t repeat_time; /* ms */
911 uint8_t repeat_count;
912 } paging;
913 uint32_t cs_mask; /* bitmask of gprs_cs */
914 uint8_t initial_cs;
915 uint8_t initial_mcs;
916};
917
918
919enum neigh_list_manual_mode {
920 NL_MODE_AUTOMATIC = 0,
921 NL_MODE_MANUAL = 1,
922 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
923};
924
925enum bts_loc_fix {
926 BTS_LOC_FIX_INVALID = 0,
927 BTS_LOC_FIX_2D = 1,
928 BTS_LOC_FIX_3D = 2,
929};
930
931extern const struct value_string bts_loc_fix_names[];
932
933struct bts_location {
934 struct llist_head list;
935 time_t tstamp;
936 enum bts_loc_fix valid;
937 double lat;
938 double lon;
939 double height;
940};
941
942/* Channel load counter */
943struct load_counter {
944 unsigned int total;
945 unsigned int used;
946};
947
Neels Hofmeyr19bed232018-03-22 04:54:57 +0100948/* Useful to track N-N relations between BTS, for example neighbors. */
949struct gsm_bts_ref {
950 struct llist_head entry;
951 struct gsm_bts *bts;
952};
953
Neels Hofmeyr10485162018-02-13 23:22:03 +0100954/* One BTS */
955struct gsm_bts {
956 /* list header in net->bts_list */
957 struct llist_head list;
958
959 /* Geographical location of the BTS */
960 struct llist_head loc_list;
961
962 /* number of ths BTS in network */
963 uint8_t nr;
964 /* human readable name / description */
965 char *description;
966 /* Cell Identity */
967 uint16_t cell_identity;
968 /* location area code of this BTS */
969 uint16_t location_area_code;
970 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
971 * which is used as TSC for the CCCH */
972 uint8_t bsic;
973 /* type of BTS */
974 enum gsm_bts_type type;
975 enum gsm_bts_type_variant variant;
976 struct gsm_bts_model *model;
977 enum gsm_band band;
978 char version[MAX_VERSION_LENGTH];
979 char sub_model[MAX_VERSION_LENGTH];
980
981 /* features of a given BTS set/reported via OML */
982 struct bitvec features;
983 uint8_t _features_data[MAX_BTS_FEATURES/8];
984
985 /* Connected PCU version (if any) */
986 char pcu_version[MAX_VERSION_LENGTH];
987
988 /* maximum Tx power that the MS is permitted to use in this cell */
989 int ms_max_power;
990
991 /* how do we talk OML with this TRX? */
992 struct gsm_e1_subslot oml_e1_link;
993 uint8_t oml_tei;
994 struct e1inp_sign_link *oml_link;
Pau Espin Pedrol9862bcb2018-08-22 21:54:12 +0200995 /* Timer to use for deferred drop of OML link, see \ref ipaccess_drop_oml_deferred */
996 struct osmo_timer_list oml_drop_link_timer;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100997 /* when OML link was established */
998 time_t uptime;
999
1000 /* Abis network management O&M handle */
1001 struct abis_nm_h *nmh;
1002
1003 struct gsm_abis_mo mo;
1004
1005 /* number of this BTS on given E1 link */
1006 uint8_t bts_nr;
1007
1008 /* DTX features of this BTS */
1009 enum gsm48_dtx_mode dtxu;
1010 bool dtxd;
1011
1012 /* paging state and control */
1013 struct gsm_bts_paging_state paging;
1014
1015 /* CCCH is on C0 */
1016 struct gsm_bts_trx *c0;
1017
1018 struct {
1019 struct gsm_abis_mo mo;
1020 } site_mgr;
1021
1022 /* bitmask of all SI that are present/valid in si_buf */
1023 uint32_t si_valid;
1024 /* 3GPP TS 44.018 Table 10.5.2.33b.1 INDEX and COUNT for SI2quater */
1025 uint8_t si2q_index; /* distinguish individual SI2quater messages */
1026 uint8_t si2q_count; /* si2q_index for the last (highest indexed) individual SI2quater message */
1027 /* buffers where we put the pre-computed SI */
1028 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
1029 /* offsets used while generating SI2quater */
1030 size_t e_offset;
1031 size_t u_offset;
Pau Espin Pedrol1cf21de2018-12-05 13:38:10 +01001032 /* 3GPP TS 08.58 §8.5.1 BCCH INFORMATION. Some nanoBTS fail upon
1033 * receival of empty SI disabling unsupported SI. see OS#3707. */
1034 bool si_unused_send_empty;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001035
1036 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
1037 union {
1038 struct {
1039 uint16_t site_id;
1040 uint16_t bts_id;
1041 uint32_t flags;
1042 uint32_t rsl_ip;
1043 } ip_access;
1044 struct {
1045 struct {
1046 struct gsm_abis_mo mo;
1047 } cclk;
1048 struct {
1049 struct gsm_abis_mo mo;
1050 } rack;
1051 struct gsm_envabtse envabtse[4];
1052 } bs11;
1053 struct {
1054 struct {
1055 struct om2k_mo om2k_mo;
1056 struct gsm_abis_mo mo;
1057 struct llist_head conn_groups;
1058 } cf;
1059 struct {
1060 struct om2k_mo om2k_mo;
1061 struct gsm_abis_mo mo;
1062 struct llist_head conn_groups;
1063 } is;
1064 struct {
1065 struct om2k_mo om2k_mo;
1066 struct gsm_abis_mo mo;
1067 struct llist_head conn_groups;
1068 } con;
1069 struct {
1070 struct om2k_mo om2k_mo;
1071 struct gsm_abis_mo mo;
1072 } dp;
1073 struct {
1074 struct om2k_mo om2k_mo;
1075 struct gsm_abis_mo mo;
1076 } tf;
1077 uint32_t use_superchannel:1;
1078 } rbs2000;
1079 struct {
1080 uint8_t bts_type;
1081 unsigned int configured:1,
1082 skip_reset:1,
1083 no_loc_rel_cnf:1,
1084 bts_reset_timer_cnf,
1085 did_reset:1,
1086 wait_reset:1;
1087 struct osmo_timer_list reset_timer;
1088 } nokia;
1089 };
1090
1091 /* Not entirely sure how ip.access specific this is */
1092 struct {
1093 uint8_t supports_egprs_11bit_rach;
1094 enum bts_gprs_mode mode;
1095 struct {
1096 struct gsm_abis_mo mo;
1097 uint16_t nsei;
1098 uint8_t timer[7];
1099 } nse;
1100 struct {
1101 struct gsm_abis_mo mo;
1102 uint16_t bvci;
1103 uint8_t timer[11];
1104 struct gprs_rlc_cfg rlc_cfg;
1105 } cell;
1106 struct gsm_bts_gprs_nsvc nsvc[2];
1107 uint8_t rac;
1108 uint8_t net_ctrl_ord;
1109 bool ctrl_ack_type_use_block;
1110 } gprs;
1111
1112 /* RACH NM values */
1113 int rach_b_thresh;
1114 int rach_ldavg_slots;
1115
1116 /* transceivers */
1117 int num_trx;
1118 struct llist_head trx_list;
1119
1120 /* SI related items */
1121 int force_combined_si;
Pau Espin Pedrol167cb822018-11-19 17:48:17 +01001122 bool force_combined_si_set;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001123 int bcch_change_mark;
1124
1125 /* Abis NM queue */
1126 struct llist_head abis_queue;
1127 int abis_nm_pend;
1128
1129 struct gsm_network *network;
1130
1131 /* should the channel allocator allocate channels from high TRX to TRX0,
1132 * rather than starting from TRX0 and go upwards? */
1133 int chan_alloc_reverse;
1134
1135 enum neigh_list_manual_mode neigh_list_manual_mode;
1136 /* parameters from which we build SYSTEM INFORMATION */
1137 struct {
1138 struct gsm48_rach_control rach_control;
1139 uint8_t ncc_permitted;
1140 struct gsm48_cell_sel_par cell_sel_par;
1141 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
1142 struct gsm48_cell_options cell_options;
1143 struct gsm48_control_channel_descr chan_desc;
1144 struct bitvec neigh_list;
1145 struct bitvec cell_alloc;
1146 struct bitvec si5_neigh_list;
1147 struct osmo_earfcn_si2q si2quater_neigh_list;
1148 size_t uarfcn_length; /* index for uarfcn and scramble lists */
1149 struct {
1150 /* bitmask large enough for all possible ARFCN's */
1151 uint8_t neigh_list[1024/8];
1152 uint8_t cell_alloc[1024/8];
1153 /* If the user wants a different neighbor list in SI5 than in SI2 */
1154 uint8_t si5_neigh_list[1024/8];
1155 uint8_t meas_bw_list[MAX_EARFCN_LIST];
1156 uint16_t earfcn_list[MAX_EARFCN_LIST];
1157 uint16_t uarfcn_list[MAX_EARFCN_LIST];
1158 uint16_t scramble_list[MAX_EARFCN_LIST];
1159 } data;
1160 } si_common;
1161 bool early_classmark_allowed;
1162 bool early_classmark_allowed_3g;
1163 /* for testing only: Have an infinitely long radio link timeout */
1164 bool infinite_radio_link_timeout;
1165
1166 /* do we use static (user-defined) system information messages? (bitmask) */
1167 uint32_t si_mode_static;
1168
Stefan Sperling6442e432018-02-06 14:44:54 +01001169 /* access control class ramping */
1170 struct acc_ramp acc_ramp;
1171
Neels Hofmeyr10485162018-02-13 23:22:03 +01001172 /* exclude the BTS from the global RF Lock handling */
1173 int excl_from_rf_lock;
1174
1175 /* supported codecs beside FR */
1176 struct bts_codec_conf codec;
1177
1178 /* BTS dependencies bit field */
1179 uint32_t depends_on[256/(8*4)];
1180
1181 /* full and half rate multirate config */
1182 struct amr_multirate_conf mr_full;
1183 struct amr_multirate_conf mr_half;
1184
1185 /* PCU socket state */
1186 char *pcu_sock_path;
1187 struct pcu_sock_state *pcu_state;
1188
1189 struct rate_ctr_group *bts_ctrs;
1190 struct osmo_stat_item_group *bts_statg;
1191
1192 struct handover_cfg *ho;
1193
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001194 /* A list of struct gsm_bts_ref, indicating neighbors of this BTS.
1195 * When the si_common neigh_list is in automatic mode, it is populated from this list as well as
1196 * gsm_network->neighbor_bss_cells. */
1197 struct llist_head local_neighbors;
1198
Neels Hofmeyr10485162018-02-13 23:22:03 +01001199 /* BTS-specific overrides for timer values from struct gsm_network. */
1200 uint8_t T3122; /* ASSIGMENT REJECT wait indication */
Pau Espin Pedrol1b963342018-11-07 14:19:32 +01001201 bool T3113_dynamic; /* Calculate T3113 timeout dynamically based on BTS channel config and load */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001202
1203 /* Periodic channel load measurements are used to maintain T3122. */
1204 struct load_counter chan_load_samples[7];
1205 int chan_load_samples_idx;
Stefan Sperling6442e432018-02-06 14:44:54 +01001206 uint8_t chan_load_avg; /* current channel load average in percent (0 - 100). */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001207};
1208
Oliver Smith8d8d7102018-10-23 15:35:43 +02001209/* One rejected BTS */
1210struct gsm_bts_rejected {
1211 /* list header in net->bts_rejected */
1212 struct llist_head list;
1213
1214 uint16_t site_id;
1215 uint16_t bts_id;
1216 char ip[INET6_ADDRSTRLEN];
1217 time_t time;
1218};
Neels Hofmeyr10485162018-02-13 23:22:03 +01001219
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001220struct gsm_network *gsm_network_init(void *ctx);
1221
Neels Hofmeyr10485162018-02-13 23:22:03 +01001222struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, uint8_t bts_num);
Neels Hofmeyr6d568ed2018-07-09 16:49:18 +02001223struct gsm_bts *gsm_bts_num(const struct gsm_network *net, int num);
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001224bool gsm_bts_matches_lai(const struct gsm_bts *bts, const struct osmo_location_area_id *lai);
1225bool gsm_bts_matches_cell_id(const struct gsm_bts *bts, const struct gsm0808_cell_id *cell_id);
1226struct gsm_bts *gsm_bts_by_cell_id(const struct gsm_network *net,
1227 const struct gsm0808_cell_id *cell_id,
1228 int match_idx);
1229int gsm_bts_local_neighbor_add(struct gsm_bts *bts, struct gsm_bts *neighbor);
1230int gsm_bts_local_neighbor_del(struct gsm_bts *bts, const struct gsm_bts *neighbor);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001231
1232struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
1233struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
1234
1235enum gsm_bts_type str2btstype(const char *arg);
1236const char *btstype2str(enum gsm_bts_type type);
1237
1238enum bts_attribute str2btsattr(const char *s);
1239const char *btsatttr2str(enum bts_attribute v);
1240
1241enum gsm_bts_type_variant str2btsvariant(const char *arg);
1242const char *btsvariant2str(enum gsm_bts_type_variant v);
1243
1244extern const struct value_string gsm_chreq_descs[];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001245extern const struct value_string gsm_pchant_names[];
1246extern const struct value_string gsm_pchant_descs[];
1247extern const struct value_string gsm_pchan_ids[];
Neels Hofmeyr10485162018-02-13 23:22:03 +01001248const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001249static inline const char *gsm_pchan_id(enum gsm_phys_chan_config c)
1250{ return get_value_string(gsm_pchan_ids, c); }
Neels Hofmeyr10485162018-02-13 23:22:03 +01001251enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
1252const char *gsm_lchant_name(enum gsm_chan_t c);
1253const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte57658ec2019-02-04 12:30:44 +01001254char *gsm_bts_name(const struct gsm_bts *bts);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001255char *gsm_trx_name(const struct gsm_bts_trx *trx);
1256char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
1257char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
1258char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001259
1260static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
1261{
1262 return lchan->name;
1263}
1264
Neels Hofmeyr10485162018-02-13 23:22:03 +01001265void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
1266
1267struct gsm_nm_state *
1268gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
1269 const struct abis_om_obj_inst *obj_inst);
1270void *
1271gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
1272 const struct abis_om_obj_inst *obj_inst);
1273
1274/* reset the state of all MO in the BTS */
1275void gsm_bts_mo_reset(struct gsm_bts *bts);
1276
1277uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
1278 uint8_t ts_nr, uint8_t lchan_nr);
1279uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
1280uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
1281 enum gsm_phys_chan_config as_pchan);
1282
Harald Welte251bec12018-09-09 17:14:09 +02001283void gsm48_lchan2chan_desc(struct gsm48_chan_desc *cd,
1284 const struct gsm_lchan *lchan);
Harald Welte24286f32018-09-09 17:17:44 +02001285void gsm48_lchan2chan_desc_as_configured(struct gsm48_chan_desc *cd, const struct gsm_lchan *lchan);
Harald Welte251bec12018-09-09 17:14:09 +02001286
Neels Hofmeyr10485162018-02-13 23:22:03 +01001287/* return the gsm_lchan for the CBCH (if it exists at all) */
1288struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
1289
1290/*
1291 * help with parsing regexps
1292 */
1293int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
1294 int argc, const char **argv) __attribute__ ((warn_unused_result));
1295
1296static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
1297{
1298 if (ts->tsc != -1)
1299 return ts->tsc;
1300 else
1301 return ts->trx->bts->bsic & 7;
1302}
1303
1304struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
1305 int *rc);
1306
1307enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001308uint8_t pchan_subslots(enum gsm_phys_chan_config pchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001309bool ts_is_tch(struct gsm_bts_trx_ts *ts);
1310
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01001311
Harald Welteb7948872017-12-18 18:48:21 +01001312static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection *conn) {
1313 OSMO_ASSERT(conn->lchan);
1314 return conn->lchan->ts->trx->bts;
1315}
1316
Harald Welted82101e2017-12-09 23:07:38 +01001317enum {
1318 BTS_CTR_CHREQ_TOTAL,
1319 BTS_CTR_CHREQ_NO_CHANNEL,
1320 BTS_CTR_CHAN_RF_FAIL,
1321 BTS_CTR_CHAN_RLL_ERR,
1322 BTS_CTR_BTS_OML_FAIL,
1323 BTS_CTR_BTS_RSL_FAIL,
1324 BTS_CTR_CODEC_AMR_F,
1325 BTS_CTR_CODEC_AMR_H,
1326 BTS_CTR_CODEC_EFR,
1327 BTS_CTR_CODEC_V1_FR,
1328 BTS_CTR_CODEC_V1_HR,
Harald Weltecf9d4312017-12-13 23:17:16 +01001329 BTS_CTR_PAGING_ATTEMPTED,
1330 BTS_CTR_PAGING_ALREADY,
1331 BTS_CTR_PAGING_RESPONDED,
1332 BTS_CTR_PAGING_EXPIRED,
Harald Welte4f598922017-12-14 13:47:02 +01001333 BTS_CTR_CHAN_ACT_TOTAL,
1334 BTS_CTR_CHAN_ACT_NACK,
Harald Welte62d9cb02017-12-14 14:00:26 +01001335 BTS_CTR_RSL_UNKNOWN,
Harald Welte581398a2017-12-14 14:29:44 +01001336 BTS_CTR_RSL_IPA_NACK,
Harald Welte00d64fd2017-12-14 14:34:16 +01001337 BTS_CTR_MODE_MODIFY_NACK,
Harald Welted82101e2017-12-09 23:07:38 +01001338};
1339
1340static const struct rate_ctr_desc bts_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001341 [BTS_CTR_CHREQ_TOTAL] = {"chreq:total", "Received channel requests."},
1342 [BTS_CTR_CHREQ_NO_CHANNEL] = {"chreq:no_channel", "Sent to MS no channel available."},
1343 [BTS_CTR_CHAN_RF_FAIL] = {"chan:rf_fail", "Received a RF failure indication from BTS."},
1344 [BTS_CTR_CHAN_RLL_ERR] = {"chan:rll_err", "Received a RLL failure with T200 cause from BTS."},
Harald Welted82101e2017-12-09 23:07:38 +01001345 [BTS_CTR_BTS_OML_FAIL] = {"oml_fail", "Received a TEI down on a OML link."},
1346 [BTS_CTR_BTS_RSL_FAIL] = {"rsl_fail", "Received a TEI down on a OML link."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001347 [BTS_CTR_CODEC_AMR_F] = {"codec:amr_f", "Count the usage of AMR/F codec by channel mode requested."},
1348 [BTS_CTR_CODEC_AMR_H] = {"codec:amr_h", "Count the usage of AMR/H codec by channel mode requested."},
1349 [BTS_CTR_CODEC_EFR] = {"codec:efr", "Count the usage of EFR codec by channel mode requested."},
1350 [BTS_CTR_CODEC_V1_FR] = {"codec:fr", "Count the usage of FR codec by channel mode requested."},
1351 [BTS_CTR_CODEC_V1_HR] = {"codec:hr", "Count the usage of HR codec by channel mode requested."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001352
1353 [BTS_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
1354 [BTS_CTR_PAGING_ALREADY] = {"paging:already", "Paging attempts ignored as subsciber was already being paged."},
1355 [BTS_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful paging response."},
1356 [BTS_CTR_PAGING_EXPIRED] = {"paging:expired", "Paging Request expired because of timeout T3113."},
Harald Welte4f598922017-12-14 13:47:02 +01001357 [BTS_CTR_CHAN_ACT_TOTAL] = {"chan_act:total", "Total number of Channel Activations."},
1358 [BTS_CTR_CHAN_ACT_NACK] = {"chan_act:nack", "Number of Channel Activations that the BTS NACKed"},
Harald Welte62d9cb02017-12-14 14:00:26 +01001359 [BTS_CTR_RSL_UNKNOWN] = {"rsl:unknown", "Number of unknown/unsupported RSL messages received from BTS"},
Harald Welte581398a2017-12-14 14:29:44 +01001360 [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 +01001361 [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 +01001362};
1363
1364static const struct rate_ctr_group_desc bts_ctrg_desc = {
1365 "bts",
1366 "base transceiver station",
1367 OSMO_STATS_CLASS_GLOBAL,
1368 ARRAY_SIZE(bts_ctr_description),
1369 bts_ctr_description,
1370};
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001371
Alexander Couzens20423ea2016-07-12 15:42:02 +02001372enum {
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001373 BTS_STAT_CHAN_LOAD_AVERAGE,
1374 BTS_STAT_T3122,
1375};
1376
1377enum {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001378 BSC_CTR_ASSIGNMENT_ATTEMPTED,
1379 BSC_CTR_ASSIGNMENT_COMPLETED,
1380 BSC_CTR_ASSIGNMENT_STOPPED,
1381 BSC_CTR_ASSIGNMENT_NO_CHANNEL,
1382 BSC_CTR_ASSIGNMENT_TIMEOUT,
1383 BSC_CTR_ASSIGNMENT_FAILED,
1384 BSC_CTR_ASSIGNMENT_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001385 BSC_CTR_HANDOVER_ATTEMPTED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001386 BSC_CTR_HANDOVER_COMPLETED,
1387 BSC_CTR_HANDOVER_STOPPED,
Alexander Couzensb847a212016-08-02 11:34:11 +02001388 BSC_CTR_HANDOVER_NO_CHANNEL,
1389 BSC_CTR_HANDOVER_TIMEOUT,
Alexander Couzensb847a212016-08-02 11:34:11 +02001390 BSC_CTR_HANDOVER_FAILED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001391 BSC_CTR_HANDOVER_ERROR,
1392 BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED,
1393 BSC_CTR_INTER_BSC_HO_OUT_COMPLETED,
1394 BSC_CTR_INTER_BSC_HO_OUT_STOPPED,
1395 BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT,
1396 BSC_CTR_INTER_BSC_HO_OUT_ERROR,
1397 BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED,
1398 BSC_CTR_INTER_BSC_HO_IN_COMPLETED,
1399 BSC_CTR_INTER_BSC_HO_IN_STOPPED,
1400 BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL,
1401 BSC_CTR_INTER_BSC_HO_IN_FAILED,
1402 BSC_CTR_INTER_BSC_HO_IN_TIMEOUT,
1403 BSC_CTR_INTER_BSC_HO_IN_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001404 BSC_CTR_PAGING_ATTEMPTED,
1405 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +01001406 BSC_CTR_PAGING_RESPONDED,
Stefan Sperling7926d982018-05-17 14:52:02 +02001407 BSC_CTR_UNKNOWN_UNIT_ID,
Alexander Couzensb847a212016-08-02 11:34:11 +02001408};
1409
1410static const struct rate_ctr_desc bsc_ctr_description[] = {
Neels Hofmeyrdbb38d52018-07-11 19:53:56 +02001411 [BSC_CTR_ASSIGNMENT_ATTEMPTED] = {"assignment:attempted", "Assignment attempts."},
1412 [BSC_CTR_ASSIGNMENT_COMPLETED] = {"assignment:completed", "Assignment completed."},
1413 [BSC_CTR_ASSIGNMENT_STOPPED] = {"assignment:stopped", "Connection ended during Assignment."},
1414 [BSC_CTR_ASSIGNMENT_NO_CHANNEL] = {"assignment:no_channel", "Failure to allocate lchan for Assignment."},
1415 [BSC_CTR_ASSIGNMENT_TIMEOUT] = {"assignment:timeout", "Assignment timed out."},
1416 [BSC_CTR_ASSIGNMENT_FAILED] = {"assignment:failed", "Received Assignment Failure message."},
1417 [BSC_CTR_ASSIGNMENT_ERROR] = {"assignment:error", "Assigment failed for other reason."},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001418
1419 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Intra-BSC handover attempts."},
1420 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Intra-BSC handover completed."},
1421 [BSC_CTR_HANDOVER_STOPPED] = {"handover:stopped", "Connection ended during HO."},
1422 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Failure to allocate lchan for HO."},
1423 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Handover timed out."},
1424 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Received Handover Fail messages."},
1425 [BSC_CTR_HANDOVER_ERROR] = {"handover:error", "Re-assigment failed for other reason."},
1426
1427 [BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED] = {"interbsc_ho_out:attempted",
1428 "Attempts to handover to remote BSS."},
1429 [BSC_CTR_INTER_BSC_HO_OUT_COMPLETED] = {"interbsc_ho_out:completed",
1430 "Handover to remote BSS completed."},
1431 [BSC_CTR_INTER_BSC_HO_OUT_STOPPED] = {"interbsc_ho_out:stopped", "Connection ended during HO."},
1432 [BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT] = {"interbsc_ho_out:timeout", "Handover timed out."},
1433 [BSC_CTR_INTER_BSC_HO_OUT_ERROR] = {"interbsc_ho_out:error",
1434 "Handover to remote BSS failed for other reason."},
1435
1436 [BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED] = {"interbsc_ho_in:attempted",
1437 "Attempts to handover from remote BSS."},
1438 [BSC_CTR_INTER_BSC_HO_IN_COMPLETED] = {"interbsc_ho_in:completed",
1439 "Handover from remote BSS completed."},
1440 [BSC_CTR_INTER_BSC_HO_IN_STOPPED] = {"interbsc_ho_in:stopped", "Connection ended during HO."},
1441 [BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL] = {"interbsc_ho_in:no_channel",
1442 "Failure to allocate lchan for HO."},
1443 [BSC_CTR_INTER_BSC_HO_IN_TIMEOUT] = {"interbsc_ho_in:timeout", "Handover from remote BSS timed out."},
1444 [BSC_CTR_INTER_BSC_HO_IN_FAILED] = {"interbsc_ho_in:failed", "Received Handover Fail message."},
1445 [BSC_CTR_INTER_BSC_HO_IN_ERROR] = {"interbsc_ho_in:error",
1446 "Handover from remote BSS failed for other reason."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001447
1448 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001449 [BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Paging request send failures because no responsible BTS was found."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001450 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response."},
Stefan Sperling7926d982018-05-17 14:52:02 +02001451
1452 [BSC_CTR_UNKNOWN_UNIT_ID] = {"abis:unknown_unit_id", "Connection attempts from unknown IPA CCM Unit ID."},
Alexander Couzensb847a212016-08-02 11:34:11 +02001453};
1454
Alexander Couzensb847a212016-08-02 11:34:11 +02001455
1456
1457static const struct rate_ctr_group_desc bsc_ctrg_desc = {
1458 "bsc",
1459 "base station controller",
1460 OSMO_STATS_CLASS_GLOBAL,
1461 ARRAY_SIZE(bsc_ctr_description),
1462 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +02001463};
1464
Neels Hofmeyr73983952016-05-10 13:29:33 +02001465struct gsm_tz {
1466 int override; /* if 0, use system's time zone instead. */
1467 int hr; /* hour */
1468 int mn; /* minute */
1469 int dst; /* daylight savings */
1470};
1471
Harald Welte52b1f982008-12-23 20:25:15 +00001472struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001473 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
1474 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
1475 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
1476 * these have in common, like country and network code, put in yet
1477 * separate structs and placed as members in osmo_bsc and osmo_msc. */
1478
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001479 struct osmo_plmn_id plmn;
1480
Harald Welte51e4bf32017-12-23 17:30:18 +01001481 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
1482 uint8_t a5_encryption_mask;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001483 int neci;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001484
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001485 struct handover_cfg *ho;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001486 struct {
1487 unsigned int congestion_check_interval_s;
1488 struct osmo_timer_list congestion_check_timer;
1489 } hodec2;
Harald Welte52b1f982008-12-23 20:25:15 +00001490
Alexander Couzensb847a212016-08-02 11:34:11 +02001491 struct rate_ctr_group *bsc_ctrs;
Harald Welte24ff6ee2009-12-22 00:41:05 +01001492
Harald Welte52b1f982008-12-23 20:25:15 +00001493 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +02001494 struct llist_head bts_list;
Oliver Smith8d8d7102018-10-23 15:35:43 +02001495 struct llist_head bts_rejected;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001496
Neels Hofmeyr596c4022018-06-16 19:29:50 +02001497 /* shall reference gsm_network_T[] */
Neels Hofmeyra6078fe2019-01-28 03:52:14 +01001498 struct osmo_tdef *T_defs;
Harald Welteeab84a12009-12-13 10:53:12 +01001499
Alexander Couzens547c2072017-11-21 12:03:04 +01001500 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +08001501
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +08001502 /* Use a TCH for handling requests of type paging any */
1503 int pag_any_tch;
1504
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08001505 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +02001506 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +01001507
Daniel Willmann6fc4a982011-07-22 17:55:42 +02001508 /* control interface */
1509 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +02001510
1511 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
1512 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +02001513
1514 /* all active subscriber connections. */
1515 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +02001516
1517 /* if override is nonzero, this timezone data is used for all MM
1518 * contexts. */
1519 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
1520 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +01001521 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +02001522 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +01001523
1524 /* List of all struct bsc_subscr used in libbsc. This llist_head is
1525 * allocated so that the llist_head pointer itself can serve as a
1526 * talloc context (useful to not have to pass the entire gsm_network
1527 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
1528 * not require gsm_data.h). In an MSC-without-BSC environment, this
1529 * pointer is NULL to indicate absence of a bsc_subscribers list. */
1530 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +02001531
Stefan Sperling6cee8932018-01-30 18:14:22 +01001532 /* Timer for periodic channel load measurements to maintain each BTS's T3122. */
1533 struct osmo_timer_list t3122_chan_load_timer;
1534
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001535 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +02001536 struct mgcp_client_conf *conf;
1537 struct mgcp_client *client;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +02001538 struct osmo_tdef *tdefs;
Philipp Maier39c609b2017-09-27 15:51:34 +02001539 } mgw;
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001540
1541 /* Remote BSS Cell Identifier Lists */
1542 struct neighbor_ident_list *neighbor_bss_cells;
Harald Welte7e310b12009-03-30 20:56:32 +00001543};
1544
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001545struct gsm_audio_support {
1546 uint8_t hr : 1,
1547 ver : 7;
1548};
1549
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001550static inline const struct osmo_location_area_id *bts_lai(struct gsm_bts *bts)
1551{
1552 static struct osmo_location_area_id lai;
1553 lai = (struct osmo_location_area_id){
1554 .plmn = bts->network->plmn,
1555 .lac = bts->location_area_code,
1556 };
1557 return &lai;
1558}
1559
Neels Hofmeyrc13e6872016-05-11 13:53:47 +02001560extern void talloc_ctx_init(void *ctx_root);
1561
Harald Welte39315c42010-01-10 18:01:52 +01001562int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +02001563
Harald Welte1d014a52009-08-08 15:38:29 +02001564enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +02001565const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +00001566struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
1567 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +00001568
Andreas Eversberg8226fa72009-06-29 15:19:38 +02001569extern void *tall_bsc_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +02001570
Harald Weltef383aa12012-07-02 19:51:55 +02001571/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +00001572static inline int is_ipaccess_bts(struct gsm_bts *bts)
1573{
1574 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001575 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001576 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +00001577 return 1;
1578 default:
1579 break;
1580 }
1581 return 0;
1582}
1583
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001584static inline int is_sysmobts_v2(struct gsm_bts *bts)
1585{
1586 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +01001587 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001588 return 1;
1589 default:
1590 break;
1591 }
1592 return 0;
1593}
1594
Harald Welte5b570672009-08-10 10:08:01 +02001595static inline int is_siemens_bts(struct gsm_bts *bts)
1596{
1597 switch (bts->type) {
1598 case GSM_BTS_TYPE_BS11:
1599 return 1;
1600 default:
1601 break;
1602 }
1603
1604 return 0;
1605}
1606
Andreas Eversberg7d8fa342013-12-05 13:25:06 +01001607static inline int is_nokia_bts(struct gsm_bts *bts)
1608{
1609 switch (bts->type) {
1610 case GSM_BTS_TYPE_NOKIA_SITE:
1611 return 1;
1612 default:
1613 break;
1614 }
1615
1616 return 0;
1617}
1618
Andreas Eversbergdcf38e12013-12-05 14:37:11 +01001619static inline int is_e1_bts(struct gsm_bts *bts)
1620{
1621 switch (bts->type) {
1622 case GSM_BTS_TYPE_BS11:
1623 case GSM_BTS_TYPE_RBS2000:
1624 case GSM_BTS_TYPE_NOKIA_SITE:
1625 return 1;
1626 default:
1627 break;
1628 }
1629
1630 return 0;
1631}
1632
Harald Welte1876c312018-05-27 11:53:43 +02001633extern struct gsm_network *bsc_gsmnet;
1634
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001635enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +02001636const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001637int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +02001638
Neels Hofmeyr4d358c02018-02-22 03:19:05 +01001639void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +08001640void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +01001641
Harald Weltefbda4e12010-03-04 11:04:52 +01001642int gsm_bts_model_register(struct gsm_bts_model *model);
1643
Harald Welte3561bd42018-01-28 03:04:16 +01001644struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *network);
Neels Hofmeyr42eb0142016-05-20 17:15:44 +02001645
1646struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
1647void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +08001648
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001649struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, uint8_t bsic);
1650struct 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 +01001651
Harald Welte3300c012011-06-05 13:31:33 +02001652void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
1653 uint8_t e1_ts, uint8_t e1_ts_ss);
1654
Maxbe356ed2017-09-07 19:10:09 +02001655void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Harald Welte3300c012011-06-05 13:31:33 +02001656struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +01001657int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -04001658int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +02001659
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +02001660/* generic E1 line operations for all ISDN-based BTS. */
1661extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
1662
Harald Weltee555c2b2012-08-17 13:02:12 +02001663extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
1664extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
1665
Max3d049d22017-10-09 17:12:53 +02001666char *get_model_oml_status(const struct gsm_bts *bts);
1667
Max25cc4072017-10-10 14:50:35 +02001668unsigned long long bts_uptime(const struct gsm_bts *bts);
1669
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +01001670/* control interface handling */
1671int bsc_base_ctrl_cmds_install(void);
1672
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001673/* dependency handling */
1674void bts_depend_mark(struct gsm_bts *bts, int dep);
1675void bts_depend_clear(struct gsm_bts *bts, int dep);
1676int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +01001677int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001678
Harald Welte2f8b9d22017-06-18 11:12:13 +03001679int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
1680void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
1681
Harald Weltea43e0b42016-06-19 18:06:02 +02001682bool classmark_is_r99(struct gsm_classmark *cm);
1683
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001684bool trx_is_usable(const struct gsm_bts_trx *trx);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001685bool ts_is_usable(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001686
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001687int gsm_lchan_type_by_pchan(enum gsm_phys_chan_config pchan);
1688enum gsm_phys_chan_config gsm_pchan_by_lchan_type(enum gsm_chan_t type);
1689
1690void gsm_bts_all_ts_dispatch(struct gsm_bts *bts, uint32_t ts_ev, void *data);
1691void gsm_trx_all_ts_dispatch(struct gsm_bts_trx *trx, uint32_t ts_ev, void *data);
1692
1693int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001694
Harald Welte6be350c2011-05-25 13:10:08 +02001695#endif /* _GSM_DATA_H */