blob: 68c95e187ed1237fedfe943798e38ecf12c81cbb [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>
Pau Espin Pedrol83c0f762019-04-16 20:05:32 +020036#include <osmocom/bsc/osmux.h>
Neels Hofmeyr10485162018-02-13 23:22:03 +010037
Neels Hofmeyr596c4022018-06-16 19:29:50 +020038#define GSM_T3122_DEFAULT 10
39
Harald Welte74b8cdb2018-01-15 19:26:06 +010040struct mgcp_client_conf;
41struct mgcp_client;
Neels Hofmeyr19bed232018-03-22 04:54:57 +010042struct gsm0808_cell_id;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +020043struct osmo_mgcpc_ep;
Philipp Maier39f62bb2017-04-09 12:32:51 +020044
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020045/** annotations for msgb ownership */
46#define __uses
47
Holger Hans Peter Freyther6f615552010-11-15 20:50:42 +010048#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
49
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010050struct bsc_subscr;
Neels Hofmeyr7b656882017-07-09 22:09:18 +020051struct gprs_ra_id;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020052struct handover;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020053
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080054#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
55
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010056#define tmsi_from_string(str) strtoul(str, NULL, 10)
57
Max70fdd242017-06-15 15:10:53 +020058/* 3-bit long values */
59#define EARFCN_PRIO_INVALID 8
60#define EARFCN_MEAS_BW_INVALID 8
61/* 5-bit long values */
62#define EARFCN_QRXLV_INVALID 32
63#define EARFCN_THRESH_LOW_INVALID 32
64
Harald Welte8e1e3ee2009-02-01 13:32:45 +000065struct msgb;
66typedef int gsm_cbfn(unsigned int hooknum,
67 unsigned int event,
68 struct msgb *msg,
69 void *data, void *param);
70
Harald Weltef7c28b02009-12-21 13:30:17 +010071/* Maximum number of neighbor cells whose average we track */
72#define MAX_NEIGH_MEAS 10
73/* Maximum size of the averaging window for neighbor cells */
74#define MAX_WIN_NEIGH_AVG 10
Andreas Eversberg98692032013-06-23 10:44:34 +020075/* Maximum number of report history we store */
76#define MAX_MEAS_REP 10
Harald Weltef7c28b02009-12-21 13:30:17 +010077
78/* processed neighbor measurements for one cell */
79struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020080 uint16_t arfcn;
81 uint8_t bsic;
82 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +010083 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020084 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +010085};
86
Harald Weltea43e0b42016-06-19 18:06:02 +020087struct gsm_classmark {
88 bool classmark1_set;
89 struct gsm48_classmark1 classmark1;
90 uint8_t classmark2_len;
91 uint8_t classmark2[3];
92 uint8_t classmark3_len;
93 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
94};
95
Harald Welte519c7e12018-01-28 02:45:46 +010096enum subscr_sccp_state {
97 SUBSCR_SCCP_ST_NONE,
98 SUBSCR_SCCP_ST_WAIT_CONN_CONF,
99 SUBSCR_SCCP_ST_CONNECTED
100};
101
Sylvain Munautaa824922019-03-07 16:32:02 +0100102enum channel_rate {
103 CH_RATE_SDCCH,
104 CH_RATE_HALF,
105 CH_RATE_FULL,
106};
107
Philipp Maierbb66d102019-01-22 11:29:06 +0100108struct channel_mode_and_rate {
109 enum gsm48_chan_mode chan_mode;
Sylvain Munautaa824922019-03-07 16:32:02 +0100110 enum channel_rate chan_rate;
Philipp Maierbb66d102019-01-22 11:29:06 +0100111 uint16_t s15_s0;
112};
113
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100114/* Information retrieved during an Assignment Request from the MSC. This is storage of the Assignment instructions
115 * parsed from the Assignment Request message, to pass on until the gscon and assignment FSMs have decided whether an
116 * Assignment is actually going to be carried out. Should remain unchanged after initial decoding. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200117struct assignment_request {
118 bool aoip;
119
120 uint16_t msc_assigned_cic;
121
122 char msc_rtp_addr[INET_ADDRSTRLEN];
123 uint16_t msc_rtp_port;
Pau Espin Pedrol83c0f762019-04-16 20:05:32 +0200124 bool use_osmux;
125 uint8_t osmux_cid;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200126
Sylvain Munautaa824922019-03-07 16:32:02 +0100127 /* Rate/codec setting in preference order (need at least 1 !) */
128 int n_ch_mode_rate;
129 struct channel_mode_and_rate ch_mode_rate[3];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200130};
131
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100132/* State of an ongoing Assignment, while the assignment_fsm is still busy. This serves as state separation to keep the
133 * currently used lchan and gscon unmodified until the outcome of an Assignment is known. If the Assignment fails, this
134 * state is simply discarded, and the gscon carries on with the original lchan remaining unchanged. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200135struct assignment_fsm_data {
136 struct assignment_request req;
137 bool requires_voice_stream;
138
139 struct osmo_fsm_inst *fi;
140 struct gsm_lchan *new_lchan;
141
142 /* Whether this assignment triggered creation of the MGW endpoint: if the assignment
143 * fails, we will release that again as soon as possible. (If false, the endpoint already
144 * existed before or isn't needed at all.)*/
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200145 struct osmo_mgcpc_ep_ci *created_ci_for_msc;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200146
147 enum gsm0808_cause failure_cause;
148 enum gsm48_rr_cause rr_cause;
149
150 bool result_rate_ctr_done;
151};
152
153enum hodec_id {
154 HODEC_NONE,
155 HODEC1 = 1,
156 HODEC2 = 2,
157 HODEC_USER,
158 HODEC_REMOTE,
159};
160
161/* For example, to count specific kinds of ongoing handovers, it is useful to be able to OR-combine
162 * scopes. */
163enum handover_scope {
164 HO_NO_HANDOVER = 0,
165 HO_INTRA_CELL = 0x1,
166 HO_INTRA_BSC = 0x2,
167 HO_INTER_BSC_OUT = 0x4,
168 HO_INTER_BSC_IN = 0x8,
169 HO_SCOPE_ALL = 0xffff,
170};
171
172extern const struct value_string handover_scope_names[];
173inline static const char *handover_scope_name(enum handover_scope val)
174{ return get_value_string(handover_scope_names, val); }
175
176struct handover_out_req {
177 enum hodec_id from_hodec_id;
178 struct gsm_lchan *old_lchan;
179 struct neighbor_ident_key target_nik;
180 enum gsm_chan_t new_lchan_type; /*< leave GSM_LCHAN_NONE to use same as old_lchan */
181};
182
183struct handover_in_req {
184 struct gsm0808_channel_type ct;
185 struct gsm0808_speech_codec_list scl;
186 struct gsm0808_encrypt_info ei;
187 struct gsm_classmark classmark;
Neels Hofmeyrc15f6cd2019-03-15 02:48:39 +0100188 /* chosen_encr_alg reflects the encoded value as in RSL_ENC_ALG_A5(a5_numer):
189 * chosen_encr_alg == 1 means A5/0 i.e. no encryption, chosen_encr_alg == 4 means A5/3.
190 * chosen_encr_alg == 0 means no such IE was present. */
191 uint8_t chosen_encr_alg;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200192 struct gsm0808_cell_id cell_id_serving;
193 char cell_id_serving_name[64];
194 struct gsm0808_cell_id cell_id_target;
195 char cell_id_target_name[64];
196 uint16_t msc_assigned_cic;
197 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
198 uint16_t msc_assigned_rtp_port;
199};
200
201struct handover {
202 struct osmo_fsm_inst *fi;
203
204 enum hodec_id from_hodec_id;
205 enum handover_scope scope;
206 enum gsm_chan_t new_lchan_type;
207 struct neighbor_ident_key target_cell;
208
209 uint8_t ho_ref;
210 struct gsm_bts *new_bts;
211 struct gsm_lchan *new_lchan;
212 bool async;
213 struct handover_in_req inter_bsc_in;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200214 struct osmo_mgcpc_ep_ci *created_ci_for_msc;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200215};
216
Neels Hofmeyr378a4922016-05-09 21:07:43 +0200217/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100218struct gsm_subscriber_connection {
Harald Weltea43e0b42016-06-19 18:06:02 +0200219 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +0800220 struct llist_head entry;
221
Harald Welte3561bd42018-01-28 03:04:16 +0100222 /* FSM instance to control the subscriber connection state (RTP, A) */
223 struct osmo_fsm_inst *fi;
224
Harald Weltea43e0b42016-06-19 18:06:02 +0200225 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100226 struct bsc_subscr *bsub;
227
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100228 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200229 struct gsm_network *network;
230
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100231 /* the primary / currently active lchan to the BTS/subscriber. During Assignment and Handover, separate lchans
232 * are kept in the .assignment or .handover sub-structs, respectively, so that this lchan remains unaffected
233 * until Assignment or Handover have actually succeeded. */
Harald Welte4a8ebc82017-12-18 18:34:41 +0100234 struct gsm_lchan *lchan;
Harald Welte3561bd42018-01-28 03:04:16 +0100235
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100236 /* Only valid during an ongoing Assignment; might be overwritten at any time by a failed Assignment attempt.
237 * Once an Assignment was successful, all relevant state must be copied out of this sub-struct. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200238 struct assignment_fsm_data assignment;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100239
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100240 /* handover information, if a handover is pending for this conn. Valid only during an ongoing Handover
241 * operation. If a Handover was successful, all relevant state must be copied out of this sub-struct. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200242 struct handover ho;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100243
Harald Welte4a8ebc82017-12-18 18:34:41 +0100244 /* buffer/cache for classmark of the ME of the subscriber */
Harald Weltea43e0b42016-06-19 18:06:02 +0200245 struct gsm_classmark classmark;
Andreas Eversberg935e5d72013-06-17 11:58:30 +0200246
Neels Hofmeyr149160f2018-06-16 17:20:13 +0200247 /* Queue DTAP messages during handover/assignment (msgb_enqueue()/msgb_dequeue())*/
248 struct llist_head dtap_queue;
249 unsigned int dtap_queue_len;
Andreas Eversberg084b4212013-05-30 14:12:48 +0200250
Neels Hofmeyrec422642018-02-15 14:07:40 +0100251 struct {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100252 int failures;
Neels Hofmeyrec422642018-02-15 14:07:40 +0100253 struct penalty_timers *penalty_timers;
254 } hodec2;
Neels Hofmeyra60f3442018-02-12 16:44:32 +0100255
256 /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment Request. 3GPP 48.008
257 * 3.2.2.103 says:
258 * The "Codec List (MSC Preferred)" shall not include codecs
259 * that are not supported by the MS.
260 * i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed the MS bearer
261 * capabilities, which the MSC is required to translate into the codec list. */
262 struct gsm0808_speech_codec_list codec_list;
Harald Welte519c7e12018-01-28 02:45:46 +0100263
264 /* flag to prevent multiple simultaneous ciphering commands */
265 int ciphering_handled;
266
267 /* state related to welcome USSD */
268 uint8_t new_subscriber;
269
270 /* state related to osmo_bsc_filter.c */
271 struct bsc_filter_state filter_state;
272
273 /* SCCP connection associatd with this subscriber_connection */
274 struct {
275 /* for advanced ping/pong */
276 int send_ping;
277
278 /* SCCP connection realted */
279 struct bsc_msc_data *msc;
280
281 /* Sigtran connection ID */
282 int conn_id;
283 enum subscr_sccp_state state;
284 } sccp;
285
286 /* for audio handling */
287 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200288 uint16_t msc_assigned_cic;
Harald Welte519c7e12018-01-28 02:45:46 +0100289
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200290 /* RTP address where the MSC expects us to send the RTP stream coming from the BTS. */
291 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
292 uint16_t msc_assigned_rtp_port;
Harald Welte519c7e12018-01-28 02:45:46 +0100293
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200294 /* The endpoint at the MGW used to join both BTS and MSC side connections, e.g.
295 * "rtpbridge/23@mgw". */
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200296 struct osmo_mgcpc_ep *mgw_endpoint;
Harald Welte3561bd42018-01-28 03:04:16 +0100297
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200298 /* The connection identifier of the osmo_mgcpc_ep used to transceive RTP towards the MSC.
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200299 * (The BTS side CI is handled by struct gsm_lchan and the lchan_fsm.) */
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200300 struct osmo_mgcpc_ep_ci *mgw_endpoint_ci_msc;
Harald Welte519c7e12018-01-28 02:45:46 +0100301 } user_plane;
Harald Weltec997ceb2018-05-30 01:39:43 +0200302
303 /* LCLS (local call, local switch) related state */
304 struct {
305 uint8_t global_call_ref[15];
306 uint8_t global_call_ref_len; /* length of global_call_ref */
Maxfe65ece2018-11-09 13:36:11 +0100307 enum gsm0808_lcls_config config; /* TS 48.008 3.2.2.116 */
308 enum gsm0808_lcls_control control; /* TS 48.008 3.2.2.117 */
Harald Weltec997ceb2018-05-30 01:39:43 +0200309 /* LCLS FSM */
310 struct osmo_fsm_inst *fi;
311 /* pointer to "other" connection, if Call Leg Relocation was successful */
312 struct gsm_subscriber_connection *other;
313 } lcls;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100314};
315
Harald Weltef142c972011-05-24 13:25:38 +0200316
Neels Hofmeyr10485162018-02-13 23:22:03 +0100317/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 Table 10.5.2.33b.1:
318 4-bit index is used (2#1111 = 10#15) */
319#define SI2Q_MAX_NUM 16
320/* length in bits (for single SI2quater message) */
321#define SI2Q_MAX_LEN 160
322#define SI2Q_MIN_LEN 18
323
324struct osmo_bsc_data;
325
326struct osmo_bsc_sccp_con;
327
328/* Channel Request reason */
329enum gsm_chreq_reason_t {
330 GSM_CHREQ_REASON_EMERG,
331 GSM_CHREQ_REASON_PAG,
332 GSM_CHREQ_REASON_CALL,
333 GSM_CHREQ_REASON_LOCATION_UPD,
334 GSM_CHREQ_REASON_OTHER,
335 GSM_CHREQ_REASON_PDCH,
336};
337
338/* lchans 0..3 are SDCCH in combined channel configuration,
339 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
340#define CCCH_LCHAN 4
341
342#define TRX_NR_TS 8
343#define TS_MAX_LCHAN 8
344
345#define HARDCODED_ARFCN 123
346#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
347
348/* for multi-drop config */
349#define HARDCODED_BTS0_TS 1
350#define HARDCODED_BTS1_TS 6
351#define HARDCODED_BTS2_TS 11
352
353#define MAX_VERSION_LENGTH 64
354
Neels Hofmeyr10485162018-02-13 23:22:03 +0100355enum gsm_hooks {
356 GSM_HOOK_NM_SWLOAD,
357 GSM_HOOK_RR_PAGING,
358 GSM_HOOK_RR_SECURITY,
359};
360
Neels Hofmeyr10485162018-02-13 23:22:03 +0100361enum bts_gprs_mode {
362 BTS_GPRS_NONE = 0,
363 BTS_GPRS_GPRS = 1,
364 BTS_GPRS_EGPRS = 2,
365};
366
367struct gsm_lchan;
368struct osmo_rtp_socket;
369struct rtp_socket;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100370
371/* Network Management State */
372struct gsm_nm_state {
373 uint8_t operational;
374 uint8_t administrative;
375 uint8_t availability;
376};
377
378struct gsm_abis_mo {
379 uint8_t obj_class;
380 uint8_t procedure_pending;
381 struct abis_om_obj_inst obj_inst;
382 const char *name;
383 struct gsm_nm_state nm_state;
384 struct tlv_parsed *nm_attr;
385 struct gsm_bts *bts;
386};
387
388/* Ericsson OM2000 Managed Object */
389struct abis_om2k_mo {
390 uint8_t class;
391 uint8_t bts;
392 uint8_t assoc_so;
393 uint8_t inst;
394} __attribute__ ((packed));
395
396struct om2k_mo {
397 struct abis_om2k_mo addr;
398 struct osmo_fsm_inst *fsm;
399};
400
401#define A38_XOR_MIN_KEY_LEN 12
402#define A38_XOR_MAX_KEY_LEN 16
403#define A38_COMP128_KEY_LEN 16
404#define RSL_ENC_ALG_A5(x) (x+1)
405#define MAX_EARFCN_LIST 32
406
407/* is the data link established? who established it? */
408#define LCHAN_SAPI_UNUSED 0
409#define LCHAN_SAPI_MS 1
410#define LCHAN_SAPI_NET 2
Neels Hofmeyr10485162018-02-13 23:22:03 +0100411
412/* BTS ONLY */
413#define MAX_NUM_UL_MEAS 104
414#define LC_UL_M_F_L1_VALID (1 << 0)
415#define LC_UL_M_F_RES_VALID (1 << 1)
416
417struct bts_ul_meas {
418 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
419 uint16_t ber10k;
420 /* timing advance offset (in quarter bits) */
421 int16_t ta_offs_qbits;
422 /* C/I ratio in dB */
423 float c_i;
424 /* flags */
425 uint8_t is_sub:1;
426 /* RSSI in dBm * -1 */
427 uint8_t inv_rssi;
428};
429
430struct bts_codec_conf {
431 uint8_t hr;
432 uint8_t efr;
433 uint8_t amr;
434};
435
436struct amr_mode {
437 uint8_t mode;
438 uint8_t threshold;
439 uint8_t hysteresis;
440};
441
442struct amr_multirate_conf {
443 uint8_t gsm48_ie[2];
444 struct amr_mode ms_mode[4];
445 struct amr_mode bts_mode[4];
446 uint8_t num_modes;
447};
448/* /BTS ONLY */
449
450enum lchan_csd_mode {
451 LCHAN_CSD_M_NT,
452 LCHAN_CSD_M_T_1200_75,
453 LCHAN_CSD_M_T_600,
454 LCHAN_CSD_M_T_1200,
455 LCHAN_CSD_M_T_2400,
456 LCHAN_CSD_M_T_9600,
457 LCHAN_CSD_M_T_14400,
458 LCHAN_CSD_M_T_29000,
459 LCHAN_CSD_M_T_32000,
460};
461
462/* State of the SAPIs in the lchan */
463enum lchan_sapi_state {
464 LCHAN_SAPI_S_NONE,
465 LCHAN_SAPI_S_REQ,
466 LCHAN_SAPI_S_ASSIGNED,
467 LCHAN_SAPI_S_REL,
468 LCHAN_SAPI_S_ERROR,
469};
470
Neels Hofmeyr92b9f2e2018-02-14 00:19:11 +0100471#define MAX_A5_KEY_LEN (128/8)
472
473struct gsm_encr {
474 uint8_t alg_id;
475 uint8_t key_len;
476 uint8_t key[MAX_A5_KEY_LEN];
477};
478
Neels Hofmeyr8da22332018-04-11 01:43:41 +0200479#define LOGPLCHAN(lchan, ss, level, fmt, args...) \
480 LOGP(ss, level, "%s (ss=%d,%s) (%s) " fmt, \
481 lchan ? gsm_ts_and_pchan_name(lchan->ts) : "-", \
482 lchan ? lchan->nr : 0, \
483 lchan ? gsm_lchant_name(lchan->type) : "-", \
484 bsc_subscr_name(lchan && lchan->conn ? lchan->conn->bsub : NULL), \
485 ## args)
486
Pau Espin Pedrold3e8e0c2018-11-28 16:35:10 +0100487/* Iterate lchans that have an FSM allocated based based on explicit pchan kind
488 * (GSM_PCHAN_* constant).
489 * Remark: PDCH related lchans are not handled in BSC but in PCU, so trying to
490 * iterate through GSM_PCHAN_PDCH is considered a void loop.
491 */
492#define ts_as_pchan_for_each_lchan(lchan, ts, as_pchan) \
493 for (lchan = (ts)->lchan; \
494 ((lchan - (ts)->lchan) < ARRAY_SIZE((ts)->lchan)) \
495 && lchan->fi \
496 && lchan->nr < pchan_subslots(as_pchan); \
497 lchan++)
498
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100499/* Iterate lchans that have an FSM allocated based on current PCHAN
500 * mode set in \ref ts.
501 * usage:
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200502 * struct gsm_lchan *lchan;
503 * struct gsm_bts_trx_ts *ts = get_some_timeslot();
504 * ts_for_each_lchan(lchan, ts) {
505 * LOGPLCHAN(DMAIN, LOGL_DEBUG, "hello world\n");
506 * }
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100507 */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200508#define ts_for_each_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_is)
509
Pau Espin Pedrol0ba20df2018-11-28 16:39:29 +0100510/* Iterate over all possible lchans available that have an FSM allocated based
511 * on PCHAN \ref ts (dynamic) configuration.
512 * Iterate all lchan instances set up by this \ref ts type, including those
513 * lchans currently disabled or in process of being enabled (e.g. due to dynamic
514 * timeslot in switchover). Compare ts_for_each_lchan(), which iterates only the
515 * enabled lchans.
516 * For example, it is useful in case dynamic timeslot \ref ts is in process of
517 * switching from configuration PDCH (no lchans) to TCH_F (1 lchan), where
518 * pchan_is is still set to PDCH but \ref ts may contain already an \ref lchan
519 * of type TCH_F which initiated the request to switch the \ts configuration.
520 */
521#define ts_for_each_potential_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_on_init)
522
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200523enum lchan_activate_mode {
524 FOR_NONE,
525 FOR_MS_CHANNEL_REQUEST,
526 FOR_ASSIGNMENT,
527 FOR_HANDOVER,
528 FOR_VTY,
529};
530
531extern const struct value_string lchan_activate_mode_names[];
532static inline const char *lchan_activate_mode_name(enum lchan_activate_mode activ_for)
533{ return get_value_string(lchan_activate_mode_names, activ_for); }
534
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100535struct lchan_activate_info {
536 enum lchan_activate_mode activ_for;
537 struct gsm_subscriber_connection *for_conn;
538 /* This always is for a specific lchan, so its lchan->type indicates full or half rate.
539 * When a dyn TS was selected, the lchan->type has been set to the desired rate. */
540 enum gsm48_chan_mode chan_mode;
Neels Hofmeyr58cf1b12019-03-15 02:49:18 +0100541 struct gsm_encr encr;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100542 /* AMR config */
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100543 uint16_t s15_s0;
544 bool requires_voice_stream;
545 bool wait_before_switching_rtp; /*< true = requires LCHAN_EV_READY_TO_SWITCH_RTP */
546 uint16_t msc_assigned_cic;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100547 /* During intra-BSC handover, we keep the MGW endpoint intact and just re-route to the new lchan. This
548 * 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 +0100549 struct gsm_lchan *re_use_mgw_endpoint_from_lchan;
550};
551
Neels Hofmeyr10485162018-02-13 23:22:03 +0100552struct gsm_lchan {
553 /* The TS that we're part of */
554 struct gsm_bts_trx_ts *ts;
555 /* The logical subslot number in the TS */
556 uint8_t nr;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200557 char *name;
558
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100559 char *last_error;
560
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200561 struct osmo_fsm_inst *fi;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200562 struct osmo_fsm_inst *fi_rtp;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200563 struct osmo_mgcpc_ep_ci *mgw_endpoint_ci_bts;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200564
565 struct {
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100566 struct lchan_activate_info info;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200567 bool activ_ack; /*< true as soon as RSL Chan Activ Ack is received */
Neels Hofmeyr369fba22018-11-27 01:30:50 +0100568 bool immediate_assignment_sent;
Neels Hofmeyr193c1e32018-08-27 22:06:24 +0200569 /*! This flag ensures that when an lchan activation has succeeded, and we have already
570 * sent ACKs like Immediate Assignment or BSSMAP Assignment Complete, and if other errors
571 * occur later, e.g. during release, that we don't send a NACK out of context. */
572 bool concluded;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200573 enum gsm0808_cause gsm0808_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200574 } activate;
575
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100576 struct {
577 /* If an event to release the lchan comes in while still waiting for responses, just mark this
578 * flag, so that the lchan will gracefully release at the next sensible junction. */
579 bool requested;
580 bool do_rr_release;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200581
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100582 /* There is an RSL error cause of value 0, so we need a separate flag. */
583 bool in_error;
584 /* RSL error code, RSL_ERR_* */
585 uint8_t rsl_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200586
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100587 /* If a release event is being handled, ignore other ricocheting release events until that
588 * release handling has concluded. */
589 bool in_release_handler;
Harald Welte963763d2019-02-03 12:11:12 +0100590
591 /* is this release at the end of a CSFB call? */
592 bool is_csfb;
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100593 } release;
Neels Hofmeyrd5df9a12018-07-20 05:35:47 +0200594
Neels Hofmeyr10485162018-02-13 23:22:03 +0100595 /* The logical channel type */
596 enum gsm_chan_t type;
597 /* RSL channel mode */
598 enum rsl_cmod_spd rsl_cmode;
599 /* If TCH, traffic channel mode */
600 enum gsm48_chan_mode tch_mode;
601 enum lchan_csd_mode csd_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100602 /* Power levels for MS and BTS */
603 uint8_t bs_power;
604 uint8_t ms_power;
605 /* Encryption information */
606 struct gsm_encr encr;
607
608 /* AMR bits */
609 uint8_t mr_ms_lv[7];
610 uint8_t mr_bts_lv[7];
Neels Hofmeyr4daa2102019-01-30 16:46:58 +0100611 /* AMR bits were based on these rate bits: */
612 uint16_t s15_s0;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100613
614 /* Established data link layer services */
615 uint8_t sapis[8];
616
617 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200618 uint32_t bound_ip; /*< where the BTS receives RTP */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100619 uint16_t bound_port;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200620 uint32_t connect_ip; /*< where the BTS sends RTP to (MGW) */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100621 uint16_t connect_port;
622 uint16_t conn_id;
623 uint8_t rtp_payload;
624 uint8_t rtp_payload2;
625 uint8_t speech_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100626
627 /* info we need to postpone the AoIP
628 * assignment completed message */
629 struct {
630 uint8_t rr_cause;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100631 bool valid;
632 } ass_compl;
633 } abis_ip;
634
635 uint8_t rqd_ta;
636
Neels Hofmeyr10485162018-02-13 23:22:03 +0100637 /* table of neighbor cell measurements */
638 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
639
640 /* cache of last measurement reports on this lchan */
641 struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
642 int meas_rep_idx;
643 int meas_rep_count;
Neels Hofmeyr35ba85c2018-02-12 16:47:40 +0100644 uint8_t meas_rep_last_seen_nr;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100645
646 /* GSM Random Access data */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200647 /* TODO: don't allocate this, rather keep an "is_present" flag */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100648 struct gsm48_req_ref *rqd_ref;
649
650 struct gsm_subscriber_connection *conn;
Philipp Maierbb66d102019-01-22 11:29:06 +0100651
652 /* Depending on the preferences that where submitted together with
653 * the assignment and the current channel load, the BSC has to select
654 * one of the offered codec/rates. The final selection by the BSC is
655 * stored here and is used when sending the assignment complete or
656 * when performing a handover procedure. */
657 struct channel_mode_and_rate ch_mode_rate;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100658};
659
Neels Hofmeyr10485162018-02-13 23:22:03 +0100660/* One Timeslot in a TRX */
661struct gsm_bts_trx_ts {
662 struct gsm_bts_trx *trx;
663 /* number of this timeslot at the TRX */
664 uint8_t nr;
665
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200666 struct osmo_fsm_inst *fi;
667 char *last_errmsg;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100668
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200669 /* vty phys_chan_config setting, not necessarily in effect in case it was changed in the telnet
670 * vty after OML activation. Gets written on vty 'write file'. */
671 enum gsm_phys_chan_config pchan_from_config;
672 /* When the timeslot OML is established, pchan_from_config is copied here. This is the pchan
673 * currently in effect; for dynamic ts, this is the dyn kind (GSM_PCHAN_TCH_F_TCH_H_PDCH or
674 * GSM_PCHAN_TCH_F_PDCH) and does not show the pchan type currently active. */
675 enum gsm_phys_chan_config pchan_on_init;
676 /* This is the *actual* pchan type currently active. For dynamic timeslots, this reflects either
677 * GSM_PCHAN_NONE or one of the standard GSM_PCHAN_TCH_F, GSM_PCHAN_TCH_H, GSM_PCHAN_PDCH.
678 * Callers can use this transparently without being aware of dyn ts. */
679 enum gsm_phys_chan_config pchan_is;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100680
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200681 /* After a PDCH ACT NACK, we shall not infinitely loop to try and ACT again.
682 * Also marks a timeslot where PDCH was deactivated by VTY. This is cleared whenever a timeslot
683 * enters IN_USE state, i.e. after each TCH use we try to PDCH ACT once again. */
684 bool pdch_act_allowed;
685
Neels Hofmeyrbcdbfb72018-07-26 20:33:15 +0200686 /* Whether TS_EV_OML_READY was received */
687 bool is_oml_ready;
688 /* Whether TS_EV_RSL_READY was received */
689 bool is_rsl_ready;
690
Neels Hofmeyr10485162018-02-13 23:22:03 +0100691 struct gsm_abis_mo mo;
692 struct tlv_parsed nm_attr;
693 uint8_t nm_chan_comb;
694 int tsc; /* -1 == use BTS TSC */
695
696 struct {
697 /* Parameters below are configured by VTY */
698 int enabled;
699 uint8_t maio;
700 uint8_t hsn;
701 struct bitvec arfcns;
702 uint8_t arfcns_data[1024/8];
703 /* This is the pre-computed MA for channel assignments */
704 struct bitvec ma;
705 uint8_t ma_len; /* part of ma_data that is used */
706 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
707 } hopping;
708
709 /* To which E1 subslot are we connected */
710 struct gsm_e1_subslot e1_link;
711
712 union {
713 struct {
714 struct om2k_mo om2k_mo;
715 } rbs2000;
716 };
717
718 struct gsm_lchan lchan[TS_MAX_LCHAN];
719};
720
721/* One TRX in a BTS */
722struct gsm_bts_trx {
723 /* list header in bts->trx_list */
724 struct llist_head list;
725
726 struct gsm_bts *bts;
727 /* number of this TRX in the BTS */
728 uint8_t nr;
729 /* human readable name / description */
730 char *description;
731 /* how do we talk RSL with this TRX? */
732 struct gsm_e1_subslot rsl_e1_link;
733 uint8_t rsl_tei;
734 struct e1inp_sign_link *rsl_link;
735
736 /* Timeout for initiating the RSL connection. */
737 struct osmo_timer_list rsl_connect_timeout;
738
739 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
740 struct e1inp_sign_link *oml_link;
741
742 struct gsm_abis_mo mo;
743 struct tlv_parsed nm_attr;
744 struct {
745 struct gsm_abis_mo mo;
746 } bb_transc;
747
748 uint16_t arfcn;
749 int nominal_power; /* in dBm */
750 unsigned int max_power_red; /* in actual dB */
751
752 union {
753 struct {
754 struct {
755 struct gsm_abis_mo mo;
756 } bbsig;
757 struct {
758 struct gsm_abis_mo mo;
759 } pa;
760 } bs11;
761 struct {
762 unsigned int test_state;
763 uint8_t test_nr;
764 struct rxlev_stats rxlev_stat;
765 } ipaccess;
766 struct {
767 struct {
768 struct om2k_mo om2k_mo;
769 } trxc;
770 struct {
771 struct om2k_mo om2k_mo;
772 } rx;
773 struct {
774 struct om2k_mo om2k_mo;
775 } tx;
776 } rbs2000;
777 };
778 struct gsm_bts_trx_ts ts[TRX_NR_TS];
779};
780
781#define GSM_BTS_SI2Q(bts, i) (struct gsm48_system_information_type_2quater *)((bts)->si_buf[SYSINFO_TYPE_2quater][i])
782#define GSM_BTS_HAS_SI(bts, i) ((bts)->si_valid & (1 << i))
783#define GSM_BTS_SI(bts, i) (void *)((bts)->si_buf[i][0])
784#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
785
786enum gsm_bts_type {
787 GSM_BTS_TYPE_UNKNOWN,
788 GSM_BTS_TYPE_BS11,
789 GSM_BTS_TYPE_NANOBTS,
790 GSM_BTS_TYPE_RBS2000,
791 GSM_BTS_TYPE_NOKIA_SITE,
792 GSM_BTS_TYPE_OSMOBTS,
793 _NUM_GSM_BTS_TYPE
794};
795
796enum gsm_bts_type_variant {
797 BTS_UNKNOWN,
798 BTS_OSMO_LITECELL15,
799 BTS_OSMO_OCTPHY,
800 BTS_OSMO_SYSMO,
801 BTS_OSMO_TRX,
802 _NUM_BTS_VARIANT
803};
804
805/* Used by OML layer for BTS Attribute reporting */
806enum bts_attribute {
807 BTS_TYPE_VARIANT,
808 BTS_SUB_MODEL,
809 TRX_PHY_VERSION,
810};
811
812struct vty;
813
814struct gsm_bts_model {
815 struct llist_head list;
816
817 enum gsm_bts_type type;
818 enum gsm_bts_type_variant variant;
819 const char *name;
820
821 bool started;
822 int (*start)(struct gsm_network *net);
823 int (*oml_rcvmsg)(struct msgb *msg);
824 char * (*oml_status)(const struct gsm_bts *bts);
825
826 void (*e1line_bind_ops)(struct e1inp_line *line);
827
828 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
829 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
830 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
831
Pau Espin Pedrol167cb822018-11-19 17:48:17 +0100832 /* Should SI2bis and SI2ter be disabled by default on this BTS model? */
833 bool force_combined_si;
834
Neels Hofmeyr10485162018-02-13 23:22:03 +0100835 struct tlv_definition nm_att_tlvdef;
836
837 /* features of a given BTS model set via gsm_bts_model_register() locally */
838 struct bitvec features;
839 uint8_t _features_data[MAX_BTS_FEATURES/8];
840};
841
Neels Hofmeyr10485162018-02-13 23:22:03 +0100842
Neels Hofmeyr10485162018-02-13 23:22:03 +0100843
844/*
845 * This keeps track of the paging status of one BTS. It
846 * includes a number of pending requests, a back pointer
847 * to the gsm_bts, a timer and some more state.
848 */
849struct gsm_bts_paging_state {
850 /* pending requests */
851 struct llist_head pending_requests;
852 struct gsm_bts *bts;
853
854 struct osmo_timer_list work_timer;
855 struct osmo_timer_list credit_timer;
856
857 /* free chans needed */
858 int free_chans_need;
859
860 /* load */
861 uint16_t available_slots;
862};
863
864struct gsm_envabtse {
865 struct gsm_abis_mo mo;
866};
867
868struct gsm_bts_gprs_nsvc {
869 struct gsm_bts *bts;
870 /* data read via VTY config file, to configure the BTS
871 * via OML from BSC */
872 int id;
873 uint16_t nsvci;
874 uint16_t local_port; /* on the BTS */
875 uint16_t remote_port; /* on the SGSN */
876 uint32_t remote_ip; /* on the SGSN */
877
878 struct gsm_abis_mo mo;
879};
880
881enum gprs_rlc_par {
882 RLC_T3142,
883 RLC_T3169,
884 RLC_T3191,
885 RLC_T3193,
886 RLC_T3195,
887 RLC_N3101,
888 RLC_N3103,
889 RLC_N3105,
890 CV_COUNTDOWN,
891 T_DL_TBF_EXT, /* ms */
892 T_UL_TBF_EXT, /* ms */
893 _NUM_RLC_PAR
894};
895
896enum gprs_cs {
897 GPRS_CS1,
898 GPRS_CS2,
899 GPRS_CS3,
900 GPRS_CS4,
901 GPRS_MCS1,
902 GPRS_MCS2,
903 GPRS_MCS3,
904 GPRS_MCS4,
905 GPRS_MCS5,
906 GPRS_MCS6,
907 GPRS_MCS7,
908 GPRS_MCS8,
909 GPRS_MCS9,
910 _NUM_GRPS_CS
911};
912
913struct gprs_rlc_cfg {
914 uint16_t parameter[_NUM_RLC_PAR];
915 struct {
916 uint16_t repeat_time; /* ms */
917 uint8_t repeat_count;
918 } paging;
919 uint32_t cs_mask; /* bitmask of gprs_cs */
920 uint8_t initial_cs;
921 uint8_t initial_mcs;
922};
923
924
925enum neigh_list_manual_mode {
926 NL_MODE_AUTOMATIC = 0,
927 NL_MODE_MANUAL = 1,
928 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
929};
930
931enum bts_loc_fix {
932 BTS_LOC_FIX_INVALID = 0,
933 BTS_LOC_FIX_2D = 1,
934 BTS_LOC_FIX_3D = 2,
935};
936
937extern const struct value_string bts_loc_fix_names[];
938
939struct bts_location {
940 struct llist_head list;
941 time_t tstamp;
942 enum bts_loc_fix valid;
943 double lat;
944 double lon;
945 double height;
946};
947
948/* Channel load counter */
949struct load_counter {
950 unsigned int total;
951 unsigned int used;
952};
953
Neels Hofmeyr19bed232018-03-22 04:54:57 +0100954/* Useful to track N-N relations between BTS, for example neighbors. */
955struct gsm_bts_ref {
956 struct llist_head entry;
957 struct gsm_bts *bts;
958};
959
Neels Hofmeyr10485162018-02-13 23:22:03 +0100960/* One BTS */
961struct gsm_bts {
962 /* list header in net->bts_list */
963 struct llist_head list;
964
965 /* Geographical location of the BTS */
966 struct llist_head loc_list;
967
968 /* number of ths BTS in network */
969 uint8_t nr;
970 /* human readable name / description */
971 char *description;
972 /* Cell Identity */
973 uint16_t cell_identity;
974 /* location area code of this BTS */
975 uint16_t location_area_code;
976 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
977 * which is used as TSC for the CCCH */
978 uint8_t bsic;
979 /* type of BTS */
980 enum gsm_bts_type type;
981 enum gsm_bts_type_variant variant;
982 struct gsm_bts_model *model;
983 enum gsm_band band;
984 char version[MAX_VERSION_LENGTH];
985 char sub_model[MAX_VERSION_LENGTH];
986
987 /* features of a given BTS set/reported via OML */
988 struct bitvec features;
989 uint8_t _features_data[MAX_BTS_FEATURES/8];
990
991 /* Connected PCU version (if any) */
992 char pcu_version[MAX_VERSION_LENGTH];
993
994 /* maximum Tx power that the MS is permitted to use in this cell */
995 int ms_max_power;
996
997 /* how do we talk OML with this TRX? */
998 struct gsm_e1_subslot oml_e1_link;
999 uint8_t oml_tei;
1000 struct e1inp_sign_link *oml_link;
Pau Espin Pedrol9862bcb2018-08-22 21:54:12 +02001001 /* Timer to use for deferred drop of OML link, see \ref ipaccess_drop_oml_deferred */
1002 struct osmo_timer_list oml_drop_link_timer;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001003 /* when OML link was established */
1004 time_t uptime;
1005
1006 /* Abis network management O&M handle */
1007 struct abis_nm_h *nmh;
1008
1009 struct gsm_abis_mo mo;
1010
1011 /* number of this BTS on given E1 link */
1012 uint8_t bts_nr;
1013
1014 /* DTX features of this BTS */
1015 enum gsm48_dtx_mode dtxu;
1016 bool dtxd;
1017
1018 /* paging state and control */
1019 struct gsm_bts_paging_state paging;
1020
1021 /* CCCH is on C0 */
1022 struct gsm_bts_trx *c0;
1023
1024 struct {
1025 struct gsm_abis_mo mo;
1026 } site_mgr;
1027
1028 /* bitmask of all SI that are present/valid in si_buf */
1029 uint32_t si_valid;
1030 /* 3GPP TS 44.018 Table 10.5.2.33b.1 INDEX and COUNT for SI2quater */
1031 uint8_t si2q_index; /* distinguish individual SI2quater messages */
1032 uint8_t si2q_count; /* si2q_index for the last (highest indexed) individual SI2quater message */
1033 /* buffers where we put the pre-computed SI */
1034 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
1035 /* offsets used while generating SI2quater */
1036 size_t e_offset;
1037 size_t u_offset;
Pau Espin Pedrol1cf21de2018-12-05 13:38:10 +01001038 /* 3GPP TS 08.58 §8.5.1 BCCH INFORMATION. Some nanoBTS fail upon
1039 * receival of empty SI disabling unsupported SI. see OS#3707. */
1040 bool si_unused_send_empty;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001041
1042 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
1043 union {
1044 struct {
1045 uint16_t site_id;
1046 uint16_t bts_id;
1047 uint32_t flags;
1048 uint32_t rsl_ip;
1049 } ip_access;
1050 struct {
1051 struct {
1052 struct gsm_abis_mo mo;
1053 } cclk;
1054 struct {
1055 struct gsm_abis_mo mo;
1056 } rack;
1057 struct gsm_envabtse envabtse[4];
1058 } bs11;
1059 struct {
1060 struct {
1061 struct om2k_mo om2k_mo;
1062 struct gsm_abis_mo mo;
1063 struct llist_head conn_groups;
1064 } cf;
1065 struct {
1066 struct om2k_mo om2k_mo;
1067 struct gsm_abis_mo mo;
1068 struct llist_head conn_groups;
1069 } is;
1070 struct {
1071 struct om2k_mo om2k_mo;
1072 struct gsm_abis_mo mo;
1073 struct llist_head conn_groups;
1074 } con;
1075 struct {
1076 struct om2k_mo om2k_mo;
1077 struct gsm_abis_mo mo;
1078 } dp;
1079 struct {
1080 struct om2k_mo om2k_mo;
1081 struct gsm_abis_mo mo;
1082 } tf;
1083 uint32_t use_superchannel:1;
1084 } rbs2000;
1085 struct {
1086 uint8_t bts_type;
1087 unsigned int configured:1,
1088 skip_reset:1,
1089 no_loc_rel_cnf:1,
1090 bts_reset_timer_cnf,
1091 did_reset:1,
1092 wait_reset:1;
1093 struct osmo_timer_list reset_timer;
1094 } nokia;
1095 };
1096
1097 /* Not entirely sure how ip.access specific this is */
1098 struct {
1099 uint8_t supports_egprs_11bit_rach;
1100 enum bts_gprs_mode mode;
1101 struct {
1102 struct gsm_abis_mo mo;
1103 uint16_t nsei;
1104 uint8_t timer[7];
1105 } nse;
1106 struct {
1107 struct gsm_abis_mo mo;
1108 uint16_t bvci;
1109 uint8_t timer[11];
1110 struct gprs_rlc_cfg rlc_cfg;
1111 } cell;
1112 struct gsm_bts_gprs_nsvc nsvc[2];
1113 uint8_t rac;
1114 uint8_t net_ctrl_ord;
1115 bool ctrl_ack_type_use_block;
1116 } gprs;
1117
1118 /* RACH NM values */
1119 int rach_b_thresh;
1120 int rach_ldavg_slots;
1121
1122 /* transceivers */
1123 int num_trx;
1124 struct llist_head trx_list;
1125
1126 /* SI related items */
1127 int force_combined_si;
Pau Espin Pedrol167cb822018-11-19 17:48:17 +01001128 bool force_combined_si_set;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001129 int bcch_change_mark;
1130
1131 /* Abis NM queue */
1132 struct llist_head abis_queue;
1133 int abis_nm_pend;
1134
1135 struct gsm_network *network;
1136
1137 /* should the channel allocator allocate channels from high TRX to TRX0,
1138 * rather than starting from TRX0 and go upwards? */
1139 int chan_alloc_reverse;
1140
1141 enum neigh_list_manual_mode neigh_list_manual_mode;
1142 /* parameters from which we build SYSTEM INFORMATION */
1143 struct {
1144 struct gsm48_rach_control rach_control;
1145 uint8_t ncc_permitted;
1146 struct gsm48_cell_sel_par cell_sel_par;
1147 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
1148 struct gsm48_cell_options cell_options;
1149 struct gsm48_control_channel_descr chan_desc;
1150 struct bitvec neigh_list;
1151 struct bitvec cell_alloc;
1152 struct bitvec si5_neigh_list;
1153 struct osmo_earfcn_si2q si2quater_neigh_list;
1154 size_t uarfcn_length; /* index for uarfcn and scramble lists */
1155 struct {
1156 /* bitmask large enough for all possible ARFCN's */
1157 uint8_t neigh_list[1024/8];
1158 uint8_t cell_alloc[1024/8];
1159 /* If the user wants a different neighbor list in SI5 than in SI2 */
1160 uint8_t si5_neigh_list[1024/8];
1161 uint8_t meas_bw_list[MAX_EARFCN_LIST];
1162 uint16_t earfcn_list[MAX_EARFCN_LIST];
1163 uint16_t uarfcn_list[MAX_EARFCN_LIST];
1164 uint16_t scramble_list[MAX_EARFCN_LIST];
1165 } data;
1166 } si_common;
1167 bool early_classmark_allowed;
1168 bool early_classmark_allowed_3g;
1169 /* for testing only: Have an infinitely long radio link timeout */
1170 bool infinite_radio_link_timeout;
1171
1172 /* do we use static (user-defined) system information messages? (bitmask) */
1173 uint32_t si_mode_static;
1174
Stefan Sperling6442e432018-02-06 14:44:54 +01001175 /* access control class ramping */
1176 struct acc_ramp acc_ramp;
1177
Neels Hofmeyr10485162018-02-13 23:22:03 +01001178 /* exclude the BTS from the global RF Lock handling */
1179 int excl_from_rf_lock;
1180
1181 /* supported codecs beside FR */
1182 struct bts_codec_conf codec;
1183
1184 /* BTS dependencies bit field */
1185 uint32_t depends_on[256/(8*4)];
1186
1187 /* full and half rate multirate config */
1188 struct amr_multirate_conf mr_full;
1189 struct amr_multirate_conf mr_half;
1190
1191 /* PCU socket state */
1192 char *pcu_sock_path;
1193 struct pcu_sock_state *pcu_state;
1194
1195 struct rate_ctr_group *bts_ctrs;
1196 struct osmo_stat_item_group *bts_statg;
1197
1198 struct handover_cfg *ho;
1199
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001200 /* A list of struct gsm_bts_ref, indicating neighbors of this BTS.
1201 * When the si_common neigh_list is in automatic mode, it is populated from this list as well as
1202 * gsm_network->neighbor_bss_cells. */
1203 struct llist_head local_neighbors;
1204
Neels Hofmeyr10485162018-02-13 23:22:03 +01001205 /* BTS-specific overrides for timer values from struct gsm_network. */
1206 uint8_t T3122; /* ASSIGMENT REJECT wait indication */
Pau Espin Pedrol1b963342018-11-07 14:19:32 +01001207 bool T3113_dynamic; /* Calculate T3113 timeout dynamically based on BTS channel config and load */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001208
1209 /* Periodic channel load measurements are used to maintain T3122. */
1210 struct load_counter chan_load_samples[7];
1211 int chan_load_samples_idx;
Stefan Sperling6442e432018-02-06 14:44:54 +01001212 uint8_t chan_load_avg; /* current channel load average in percent (0 - 100). */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001213};
1214
Oliver Smith8d8d7102018-10-23 15:35:43 +02001215/* One rejected BTS */
1216struct gsm_bts_rejected {
1217 /* list header in net->bts_rejected */
1218 struct llist_head list;
1219
1220 uint16_t site_id;
1221 uint16_t bts_id;
1222 char ip[INET6_ADDRSTRLEN];
1223 time_t time;
1224};
Neels Hofmeyr10485162018-02-13 23:22:03 +01001225
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001226struct gsm_network *gsm_network_init(void *ctx);
1227
Neels Hofmeyr10485162018-02-13 23:22:03 +01001228struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, uint8_t bts_num);
Neels Hofmeyr6d568ed2018-07-09 16:49:18 +02001229struct gsm_bts *gsm_bts_num(const struct gsm_network *net, int num);
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001230bool gsm_bts_matches_lai(const struct gsm_bts *bts, const struct osmo_location_area_id *lai);
1231bool gsm_bts_matches_cell_id(const struct gsm_bts *bts, const struct gsm0808_cell_id *cell_id);
1232struct gsm_bts *gsm_bts_by_cell_id(const struct gsm_network *net,
1233 const struct gsm0808_cell_id *cell_id,
1234 int match_idx);
1235int gsm_bts_local_neighbor_add(struct gsm_bts *bts, struct gsm_bts *neighbor);
1236int gsm_bts_local_neighbor_del(struct gsm_bts *bts, const struct gsm_bts *neighbor);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001237
1238struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
1239struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
1240
1241enum gsm_bts_type str2btstype(const char *arg);
1242const char *btstype2str(enum gsm_bts_type type);
1243
1244enum bts_attribute str2btsattr(const char *s);
1245const char *btsatttr2str(enum bts_attribute v);
1246
1247enum gsm_bts_type_variant str2btsvariant(const char *arg);
1248const char *btsvariant2str(enum gsm_bts_type_variant v);
1249
1250extern const struct value_string gsm_chreq_descs[];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001251extern const struct value_string gsm_pchant_names[];
1252extern const struct value_string gsm_pchant_descs[];
1253extern const struct value_string gsm_pchan_ids[];
Neels Hofmeyr10485162018-02-13 23:22:03 +01001254const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001255static inline const char *gsm_pchan_id(enum gsm_phys_chan_config c)
1256{ return get_value_string(gsm_pchan_ids, c); }
Neels Hofmeyr10485162018-02-13 23:22:03 +01001257enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
1258const char *gsm_lchant_name(enum gsm_chan_t c);
1259const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte57658ec2019-02-04 12:30:44 +01001260char *gsm_bts_name(const struct gsm_bts *bts);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001261char *gsm_trx_name(const struct gsm_bts_trx *trx);
1262char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
1263char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
1264char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001265
1266static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
1267{
1268 return lchan->name;
1269}
1270
Neels Hofmeyr10485162018-02-13 23:22:03 +01001271void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
1272
1273struct gsm_nm_state *
1274gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
1275 const struct abis_om_obj_inst *obj_inst);
1276void *
1277gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
1278 const struct abis_om_obj_inst *obj_inst);
1279
1280/* reset the state of all MO in the BTS */
1281void gsm_bts_mo_reset(struct gsm_bts *bts);
1282
1283uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
1284 uint8_t ts_nr, uint8_t lchan_nr);
1285uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
1286uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
1287 enum gsm_phys_chan_config as_pchan);
1288
Harald Welte251bec12018-09-09 17:14:09 +02001289void gsm48_lchan2chan_desc(struct gsm48_chan_desc *cd,
1290 const struct gsm_lchan *lchan);
Harald Welte24286f32018-09-09 17:17:44 +02001291void gsm48_lchan2chan_desc_as_configured(struct gsm48_chan_desc *cd, const struct gsm_lchan *lchan);
Harald Welte251bec12018-09-09 17:14:09 +02001292
Neels Hofmeyr10485162018-02-13 23:22:03 +01001293/* return the gsm_lchan for the CBCH (if it exists at all) */
1294struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
1295
1296/*
1297 * help with parsing regexps
1298 */
1299int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
1300 int argc, const char **argv) __attribute__ ((warn_unused_result));
1301
1302static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
1303{
1304 if (ts->tsc != -1)
1305 return ts->tsc;
1306 else
1307 return ts->trx->bts->bsic & 7;
1308}
1309
1310struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
1311 int *rc);
1312
1313enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001314uint8_t pchan_subslots(enum gsm_phys_chan_config pchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001315bool ts_is_tch(struct gsm_bts_trx_ts *ts);
1316
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01001317
Harald Welteb7948872017-12-18 18:48:21 +01001318static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection *conn) {
1319 OSMO_ASSERT(conn->lchan);
1320 return conn->lchan->ts->trx->bts;
1321}
1322
Harald Welted82101e2017-12-09 23:07:38 +01001323enum {
1324 BTS_CTR_CHREQ_TOTAL,
1325 BTS_CTR_CHREQ_NO_CHANNEL,
1326 BTS_CTR_CHAN_RF_FAIL,
1327 BTS_CTR_CHAN_RLL_ERR,
1328 BTS_CTR_BTS_OML_FAIL,
1329 BTS_CTR_BTS_RSL_FAIL,
1330 BTS_CTR_CODEC_AMR_F,
1331 BTS_CTR_CODEC_AMR_H,
1332 BTS_CTR_CODEC_EFR,
1333 BTS_CTR_CODEC_V1_FR,
1334 BTS_CTR_CODEC_V1_HR,
Harald Weltecf9d4312017-12-13 23:17:16 +01001335 BTS_CTR_PAGING_ATTEMPTED,
1336 BTS_CTR_PAGING_ALREADY,
1337 BTS_CTR_PAGING_RESPONDED,
1338 BTS_CTR_PAGING_EXPIRED,
Harald Welte4f598922017-12-14 13:47:02 +01001339 BTS_CTR_CHAN_ACT_TOTAL,
1340 BTS_CTR_CHAN_ACT_NACK,
Harald Welte62d9cb02017-12-14 14:00:26 +01001341 BTS_CTR_RSL_UNKNOWN,
Harald Welte581398a2017-12-14 14:29:44 +01001342 BTS_CTR_RSL_IPA_NACK,
Harald Welte00d64fd2017-12-14 14:34:16 +01001343 BTS_CTR_MODE_MODIFY_NACK,
Harald Welted82101e2017-12-09 23:07:38 +01001344};
1345
1346static const struct rate_ctr_desc bts_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001347 [BTS_CTR_CHREQ_TOTAL] = {"chreq:total", "Received channel requests."},
1348 [BTS_CTR_CHREQ_NO_CHANNEL] = {"chreq:no_channel", "Sent to MS no channel available."},
1349 [BTS_CTR_CHAN_RF_FAIL] = {"chan:rf_fail", "Received a RF failure indication from BTS."},
1350 [BTS_CTR_CHAN_RLL_ERR] = {"chan:rll_err", "Received a RLL failure with T200 cause from BTS."},
Harald Welted82101e2017-12-09 23:07:38 +01001351 [BTS_CTR_BTS_OML_FAIL] = {"oml_fail", "Received a TEI down on a OML link."},
1352 [BTS_CTR_BTS_RSL_FAIL] = {"rsl_fail", "Received a TEI down on a OML link."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001353 [BTS_CTR_CODEC_AMR_F] = {"codec:amr_f", "Count the usage of AMR/F codec by channel mode requested."},
1354 [BTS_CTR_CODEC_AMR_H] = {"codec:amr_h", "Count the usage of AMR/H codec by channel mode requested."},
1355 [BTS_CTR_CODEC_EFR] = {"codec:efr", "Count the usage of EFR codec by channel mode requested."},
1356 [BTS_CTR_CODEC_V1_FR] = {"codec:fr", "Count the usage of FR codec by channel mode requested."},
1357 [BTS_CTR_CODEC_V1_HR] = {"codec:hr", "Count the usage of HR codec by channel mode requested."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001358
1359 [BTS_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
1360 [BTS_CTR_PAGING_ALREADY] = {"paging:already", "Paging attempts ignored as subsciber was already being paged."},
1361 [BTS_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful paging response."},
1362 [BTS_CTR_PAGING_EXPIRED] = {"paging:expired", "Paging Request expired because of timeout T3113."},
Harald Welte4f598922017-12-14 13:47:02 +01001363 [BTS_CTR_CHAN_ACT_TOTAL] = {"chan_act:total", "Total number of Channel Activations."},
1364 [BTS_CTR_CHAN_ACT_NACK] = {"chan_act:nack", "Number of Channel Activations that the BTS NACKed"},
Harald Welte62d9cb02017-12-14 14:00:26 +01001365 [BTS_CTR_RSL_UNKNOWN] = {"rsl:unknown", "Number of unknown/unsupported RSL messages received from BTS"},
Harald Welte581398a2017-12-14 14:29:44 +01001366 [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 +01001367 [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 +01001368};
1369
1370static const struct rate_ctr_group_desc bts_ctrg_desc = {
1371 "bts",
1372 "base transceiver station",
1373 OSMO_STATS_CLASS_GLOBAL,
1374 ARRAY_SIZE(bts_ctr_description),
1375 bts_ctr_description,
1376};
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001377
Alexander Couzens20423ea2016-07-12 15:42:02 +02001378enum {
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001379 BTS_STAT_CHAN_LOAD_AVERAGE,
1380 BTS_STAT_T3122,
1381};
1382
1383enum {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001384 BSC_CTR_ASSIGNMENT_ATTEMPTED,
1385 BSC_CTR_ASSIGNMENT_COMPLETED,
1386 BSC_CTR_ASSIGNMENT_STOPPED,
1387 BSC_CTR_ASSIGNMENT_NO_CHANNEL,
1388 BSC_CTR_ASSIGNMENT_TIMEOUT,
1389 BSC_CTR_ASSIGNMENT_FAILED,
1390 BSC_CTR_ASSIGNMENT_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001391 BSC_CTR_HANDOVER_ATTEMPTED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001392 BSC_CTR_HANDOVER_COMPLETED,
1393 BSC_CTR_HANDOVER_STOPPED,
Alexander Couzensb847a212016-08-02 11:34:11 +02001394 BSC_CTR_HANDOVER_NO_CHANNEL,
1395 BSC_CTR_HANDOVER_TIMEOUT,
Alexander Couzensb847a212016-08-02 11:34:11 +02001396 BSC_CTR_HANDOVER_FAILED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001397 BSC_CTR_HANDOVER_ERROR,
1398 BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED,
1399 BSC_CTR_INTER_BSC_HO_OUT_COMPLETED,
1400 BSC_CTR_INTER_BSC_HO_OUT_STOPPED,
1401 BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT,
1402 BSC_CTR_INTER_BSC_HO_OUT_ERROR,
1403 BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED,
1404 BSC_CTR_INTER_BSC_HO_IN_COMPLETED,
1405 BSC_CTR_INTER_BSC_HO_IN_STOPPED,
1406 BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL,
1407 BSC_CTR_INTER_BSC_HO_IN_FAILED,
1408 BSC_CTR_INTER_BSC_HO_IN_TIMEOUT,
1409 BSC_CTR_INTER_BSC_HO_IN_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001410 BSC_CTR_PAGING_ATTEMPTED,
1411 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +01001412 BSC_CTR_PAGING_RESPONDED,
Stefan Sperling7926d982018-05-17 14:52:02 +02001413 BSC_CTR_UNKNOWN_UNIT_ID,
Alexander Couzensb847a212016-08-02 11:34:11 +02001414};
1415
1416static const struct rate_ctr_desc bsc_ctr_description[] = {
Neels Hofmeyrdbb38d52018-07-11 19:53:56 +02001417 [BSC_CTR_ASSIGNMENT_ATTEMPTED] = {"assignment:attempted", "Assignment attempts."},
1418 [BSC_CTR_ASSIGNMENT_COMPLETED] = {"assignment:completed", "Assignment completed."},
1419 [BSC_CTR_ASSIGNMENT_STOPPED] = {"assignment:stopped", "Connection ended during Assignment."},
1420 [BSC_CTR_ASSIGNMENT_NO_CHANNEL] = {"assignment:no_channel", "Failure to allocate lchan for Assignment."},
1421 [BSC_CTR_ASSIGNMENT_TIMEOUT] = {"assignment:timeout", "Assignment timed out."},
1422 [BSC_CTR_ASSIGNMENT_FAILED] = {"assignment:failed", "Received Assignment Failure message."},
1423 [BSC_CTR_ASSIGNMENT_ERROR] = {"assignment:error", "Assigment failed for other reason."},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001424
1425 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Intra-BSC handover attempts."},
1426 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Intra-BSC handover completed."},
1427 [BSC_CTR_HANDOVER_STOPPED] = {"handover:stopped", "Connection ended during HO."},
1428 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Failure to allocate lchan for HO."},
1429 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Handover timed out."},
1430 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Received Handover Fail messages."},
1431 [BSC_CTR_HANDOVER_ERROR] = {"handover:error", "Re-assigment failed for other reason."},
1432
1433 [BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED] = {"interbsc_ho_out:attempted",
1434 "Attempts to handover to remote BSS."},
1435 [BSC_CTR_INTER_BSC_HO_OUT_COMPLETED] = {"interbsc_ho_out:completed",
1436 "Handover to remote BSS completed."},
1437 [BSC_CTR_INTER_BSC_HO_OUT_STOPPED] = {"interbsc_ho_out:stopped", "Connection ended during HO."},
1438 [BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT] = {"interbsc_ho_out:timeout", "Handover timed out."},
1439 [BSC_CTR_INTER_BSC_HO_OUT_ERROR] = {"interbsc_ho_out:error",
1440 "Handover to remote BSS failed for other reason."},
1441
1442 [BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED] = {"interbsc_ho_in:attempted",
1443 "Attempts to handover from remote BSS."},
1444 [BSC_CTR_INTER_BSC_HO_IN_COMPLETED] = {"interbsc_ho_in:completed",
1445 "Handover from remote BSS completed."},
1446 [BSC_CTR_INTER_BSC_HO_IN_STOPPED] = {"interbsc_ho_in:stopped", "Connection ended during HO."},
1447 [BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL] = {"interbsc_ho_in:no_channel",
1448 "Failure to allocate lchan for HO."},
1449 [BSC_CTR_INTER_BSC_HO_IN_TIMEOUT] = {"interbsc_ho_in:timeout", "Handover from remote BSS timed out."},
1450 [BSC_CTR_INTER_BSC_HO_IN_FAILED] = {"interbsc_ho_in:failed", "Received Handover Fail message."},
1451 [BSC_CTR_INTER_BSC_HO_IN_ERROR] = {"interbsc_ho_in:error",
1452 "Handover from remote BSS failed for other reason."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001453
1454 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001455 [BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Paging request send failures because no responsible BTS was found."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001456 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response."},
Stefan Sperling7926d982018-05-17 14:52:02 +02001457
1458 [BSC_CTR_UNKNOWN_UNIT_ID] = {"abis:unknown_unit_id", "Connection attempts from unknown IPA CCM Unit ID."},
Alexander Couzensb847a212016-08-02 11:34:11 +02001459};
1460
Alexander Couzensb847a212016-08-02 11:34:11 +02001461
1462
1463static const struct rate_ctr_group_desc bsc_ctrg_desc = {
1464 "bsc",
1465 "base station controller",
1466 OSMO_STATS_CLASS_GLOBAL,
1467 ARRAY_SIZE(bsc_ctr_description),
1468 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +02001469};
1470
Neels Hofmeyr73983952016-05-10 13:29:33 +02001471struct gsm_tz {
1472 int override; /* if 0, use system's time zone instead. */
1473 int hr; /* hour */
1474 int mn; /* minute */
1475 int dst; /* daylight savings */
1476};
1477
Harald Welte52b1f982008-12-23 20:25:15 +00001478struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001479 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
1480 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
1481 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
1482 * these have in common, like country and network code, put in yet
1483 * separate structs and placed as members in osmo_bsc and osmo_msc. */
1484
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001485 struct osmo_plmn_id plmn;
1486
Harald Welte51e4bf32017-12-23 17:30:18 +01001487 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
1488 uint8_t a5_encryption_mask;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001489 int neci;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001490
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001491 struct handover_cfg *ho;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001492 struct {
1493 unsigned int congestion_check_interval_s;
1494 struct osmo_timer_list congestion_check_timer;
1495 } hodec2;
Harald Welte52b1f982008-12-23 20:25:15 +00001496
Alexander Couzensb847a212016-08-02 11:34:11 +02001497 struct rate_ctr_group *bsc_ctrs;
Harald Welte24ff6ee2009-12-22 00:41:05 +01001498
Harald Welte52b1f982008-12-23 20:25:15 +00001499 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +02001500 struct llist_head bts_list;
Oliver Smith8d8d7102018-10-23 15:35:43 +02001501 struct llist_head bts_rejected;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001502
Neels Hofmeyr596c4022018-06-16 19:29:50 +02001503 /* shall reference gsm_network_T[] */
Neels Hofmeyra6078fe2019-01-28 03:52:14 +01001504 struct osmo_tdef *T_defs;
Harald Welteeab84a12009-12-13 10:53:12 +01001505
Alexander Couzens547c2072017-11-21 12:03:04 +01001506 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +08001507
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +08001508 /* Use a TCH for handling requests of type paging any */
1509 int pag_any_tch;
1510
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08001511 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +02001512 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +01001513
Daniel Willmann6fc4a982011-07-22 17:55:42 +02001514 /* control interface */
1515 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +02001516
1517 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
1518 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +02001519
1520 /* all active subscriber connections. */
1521 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +02001522
1523 /* if override is nonzero, this timezone data is used for all MM
1524 * contexts. */
1525 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
1526 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +01001527 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +02001528 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +01001529
1530 /* List of all struct bsc_subscr used in libbsc. This llist_head is
1531 * allocated so that the llist_head pointer itself can serve as a
1532 * talloc context (useful to not have to pass the entire gsm_network
1533 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
1534 * not require gsm_data.h). In an MSC-without-BSC environment, this
1535 * pointer is NULL to indicate absence of a bsc_subscribers list. */
1536 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +02001537
Stefan Sperling6cee8932018-01-30 18:14:22 +01001538 /* Timer for periodic channel load measurements to maintain each BTS's T3122. */
1539 struct osmo_timer_list t3122_chan_load_timer;
1540
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001541 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +02001542 struct mgcp_client_conf *conf;
1543 struct mgcp_client *client;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +02001544 struct osmo_tdef *tdefs;
Philipp Maier39c609b2017-09-27 15:51:34 +02001545 } mgw;
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001546
1547 /* Remote BSS Cell Identifier Lists */
1548 struct neighbor_ident_list *neighbor_bss_cells;
Harald Welte7e310b12009-03-30 20:56:32 +00001549};
1550
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001551struct gsm_audio_support {
1552 uint8_t hr : 1,
1553 ver : 7;
1554};
1555
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001556static inline const struct osmo_location_area_id *bts_lai(struct gsm_bts *bts)
1557{
1558 static struct osmo_location_area_id lai;
1559 lai = (struct osmo_location_area_id){
1560 .plmn = bts->network->plmn,
1561 .lac = bts->location_area_code,
1562 };
1563 return &lai;
1564}
1565
Neels Hofmeyrc13e6872016-05-11 13:53:47 +02001566extern void talloc_ctx_init(void *ctx_root);
1567
Harald Welte39315c42010-01-10 18:01:52 +01001568int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +02001569
Harald Welte1d014a52009-08-08 15:38:29 +02001570enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +02001571const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +00001572struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
1573 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +00001574
Andreas Eversberg8226fa72009-06-29 15:19:38 +02001575extern void *tall_bsc_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +02001576
Harald Weltef383aa12012-07-02 19:51:55 +02001577/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +00001578static inline int is_ipaccess_bts(struct gsm_bts *bts)
1579{
1580 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001581 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001582 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +00001583 return 1;
1584 default:
1585 break;
1586 }
1587 return 0;
1588}
1589
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001590static inline int is_sysmobts_v2(struct gsm_bts *bts)
1591{
1592 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +01001593 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001594 return 1;
1595 default:
1596 break;
1597 }
1598 return 0;
1599}
1600
Harald Welte5b570672009-08-10 10:08:01 +02001601static inline int is_siemens_bts(struct gsm_bts *bts)
1602{
1603 switch (bts->type) {
1604 case GSM_BTS_TYPE_BS11:
1605 return 1;
1606 default:
1607 break;
1608 }
1609
1610 return 0;
1611}
1612
Andreas Eversberg7d8fa342013-12-05 13:25:06 +01001613static inline int is_nokia_bts(struct gsm_bts *bts)
1614{
1615 switch (bts->type) {
1616 case GSM_BTS_TYPE_NOKIA_SITE:
1617 return 1;
1618 default:
1619 break;
1620 }
1621
1622 return 0;
1623}
1624
Andreas Eversbergdcf38e12013-12-05 14:37:11 +01001625static inline int is_e1_bts(struct gsm_bts *bts)
1626{
1627 switch (bts->type) {
1628 case GSM_BTS_TYPE_BS11:
1629 case GSM_BTS_TYPE_RBS2000:
1630 case GSM_BTS_TYPE_NOKIA_SITE:
1631 return 1;
1632 default:
1633 break;
1634 }
1635
1636 return 0;
1637}
1638
Harald Welte1876c312018-05-27 11:53:43 +02001639extern struct gsm_network *bsc_gsmnet;
1640
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001641enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +02001642const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001643int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +02001644
Neels Hofmeyr4d358c02018-02-22 03:19:05 +01001645void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +08001646void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +01001647
Harald Weltefbda4e12010-03-04 11:04:52 +01001648int gsm_bts_model_register(struct gsm_bts_model *model);
1649
Harald Welte3561bd42018-01-28 03:04:16 +01001650struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *network);
Neels Hofmeyr42eb0142016-05-20 17:15:44 +02001651
1652struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
1653void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +08001654
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001655struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, uint8_t bsic);
1656struct 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 +01001657
Harald Welte3300c012011-06-05 13:31:33 +02001658void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
1659 uint8_t e1_ts, uint8_t e1_ts_ss);
1660
Maxbe356ed2017-09-07 19:10:09 +02001661void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Harald Welte3300c012011-06-05 13:31:33 +02001662struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +01001663int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -04001664int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +02001665
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +02001666/* generic E1 line operations for all ISDN-based BTS. */
1667extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
1668
Harald Weltee555c2b2012-08-17 13:02:12 +02001669extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
1670extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
1671
Max3d049d22017-10-09 17:12:53 +02001672char *get_model_oml_status(const struct gsm_bts *bts);
1673
Max25cc4072017-10-10 14:50:35 +02001674unsigned long long bts_uptime(const struct gsm_bts *bts);
1675
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +01001676/* control interface handling */
1677int bsc_base_ctrl_cmds_install(void);
1678
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001679/* dependency handling */
1680void bts_depend_mark(struct gsm_bts *bts, int dep);
1681void bts_depend_clear(struct gsm_bts *bts, int dep);
1682int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +01001683int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001684
Harald Welte2f8b9d22017-06-18 11:12:13 +03001685int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
1686void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
1687
Harald Weltea43e0b42016-06-19 18:06:02 +02001688bool classmark_is_r99(struct gsm_classmark *cm);
1689
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001690bool trx_is_usable(const struct gsm_bts_trx *trx);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001691bool ts_is_usable(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001692
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001693int gsm_lchan_type_by_pchan(enum gsm_phys_chan_config pchan);
1694enum gsm_phys_chan_config gsm_pchan_by_lchan_type(enum gsm_chan_t type);
1695
1696void gsm_bts_all_ts_dispatch(struct gsm_bts *bts, uint32_t ts_ev, void *data);
1697void gsm_trx_all_ts_dispatch(struct gsm_bts_trx *trx, uint32_t ts_ev, void *data);
1698
1699int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001700
Harald Welte6be350c2011-05-25 13:10:08 +02001701#endif /* _GSM_DATA_H */