blob: 8dfbc6425da23f5808900825ff38892d241e556e [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>
Harald Welted41b7c72019-06-13 09:41:58 +020017#include <osmocom/gsm/protocol/gsm_48_049.h>
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020018#include <osmocom/gsm/gsm0808.h>
Neels Hofmeyrf93970b2018-03-05 02:09:40 +010019#include <osmocom/gsm/gsm48.h>
Harald Welte3561bd42018-01-28 03:04:16 +010020#include <osmocom/core/fsm.h>
Neels Hofmeyra6078fe2019-01-28 03:52:14 +010021#include <osmocom/core/tdef.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020022
Harald Welte121e9a42016-04-20 13:13:19 +020023#include <osmocom/crypt/auth.h>
Harald Weltef142c972011-05-24 13:25:38 +020024
Neels Hofmeyrc0164792017-09-04 15:15:32 +020025#include <osmocom/bsc/rest_octets.h>
Harald Welteb96be392011-05-25 12:33:33 +020026
Neels Hofmeyr10485162018-02-13 23:22:03 +010027#include <osmocom/core/bitvec.h>
28#include <osmocom/gsm/gsm_utils.h>
29#include <osmocom/gsm/rxlev_stat.h>
30#include <osmocom/gsm/protocol/gsm_08_58.h>
31#include <osmocom/gsm/protocol/gsm_12_21.h>
32#include <osmocom/abis/e1_input.h>
33#include <osmocom/bsc/meas_rep.h>
Harald Welte519c7e12018-01-28 02:45:46 +010034#include <osmocom/bsc/bsc_msg_filter.h>
Stefan Sperling6442e432018-02-06 14:44:54 +010035#include <osmocom/bsc/acc_ramp.h>
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020036#include <osmocom/bsc/neighbor_ident.h>
Pau Espin Pedrol83c0f762019-04-16 20:05:32 +020037#include <osmocom/bsc/osmux.h>
Neels Hofmeyr10485162018-02-13 23:22:03 +010038
Neels Hofmeyr596c4022018-06-16 19:29:50 +020039#define GSM_T3122_DEFAULT 10
40
Harald Welte74b8cdb2018-01-15 19:26:06 +010041struct mgcp_client_conf;
42struct mgcp_client;
Neels Hofmeyr19bed232018-03-22 04:54:57 +010043struct gsm0808_cell_id;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +020044struct osmo_mgcpc_ep;
Philipp Maier39f62bb2017-04-09 12:32:51 +020045
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020046/** annotations for msgb ownership */
47#define __uses
48
Holger Hans Peter Freyther6f615552010-11-15 20:50:42 +010049#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
50
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010051struct bsc_subscr;
Neels Hofmeyr7b656882017-07-09 22:09:18 +020052struct gprs_ra_id;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020053struct handover;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020054
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080055#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
56
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010057#define tmsi_from_string(str) strtoul(str, NULL, 10)
58
Max70fdd242017-06-15 15:10:53 +020059/* 3-bit long values */
60#define EARFCN_PRIO_INVALID 8
61#define EARFCN_MEAS_BW_INVALID 8
62/* 5-bit long values */
63#define EARFCN_QRXLV_INVALID 32
64#define EARFCN_THRESH_LOW_INVALID 32
65
Harald Welte8e1e3ee2009-02-01 13:32:45 +000066struct msgb;
67typedef int gsm_cbfn(unsigned int hooknum,
68 unsigned int event,
69 struct msgb *msg,
70 void *data, void *param);
71
Harald Weltef7c28b02009-12-21 13:30:17 +010072/* Maximum number of neighbor cells whose average we track */
73#define MAX_NEIGH_MEAS 10
74/* Maximum size of the averaging window for neighbor cells */
75#define MAX_WIN_NEIGH_AVG 10
Andreas Eversberg98692032013-06-23 10:44:34 +020076/* Maximum number of report history we store */
77#define MAX_MEAS_REP 10
Harald Weltef7c28b02009-12-21 13:30:17 +010078
79/* processed neighbor measurements for one cell */
80struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020081 uint16_t arfcn;
82 uint8_t bsic;
83 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +010084 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020085 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +010086};
87
Harald Weltea43e0b42016-06-19 18:06:02 +020088struct gsm_classmark {
89 bool classmark1_set;
90 struct gsm48_classmark1 classmark1;
91 uint8_t classmark2_len;
92 uint8_t classmark2[3];
93 uint8_t classmark3_len;
94 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
95};
96
Harald Welte519c7e12018-01-28 02:45:46 +010097enum subscr_sccp_state {
98 SUBSCR_SCCP_ST_NONE,
99 SUBSCR_SCCP_ST_WAIT_CONN_CONF,
100 SUBSCR_SCCP_ST_CONNECTED
101};
102
Sylvain Munautaa824922019-03-07 16:32:02 +0100103enum channel_rate {
104 CH_RATE_SDCCH,
105 CH_RATE_HALF,
106 CH_RATE_FULL,
107};
108
Philipp Maierbb66d102019-01-22 11:29:06 +0100109struct channel_mode_and_rate {
110 enum gsm48_chan_mode chan_mode;
Sylvain Munautaa824922019-03-07 16:32:02 +0100111 enum channel_rate chan_rate;
Philipp Maierbb66d102019-01-22 11:29:06 +0100112 uint16_t s15_s0;
113};
114
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100115/* Information retrieved during an Assignment Request from the MSC. This is storage of the Assignment instructions
116 * parsed from the Assignment Request message, to pass on until the gscon and assignment FSMs have decided whether an
117 * Assignment is actually going to be carried out. Should remain unchanged after initial decoding. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200118struct assignment_request {
119 bool aoip;
120
121 uint16_t msc_assigned_cic;
122
123 char msc_rtp_addr[INET_ADDRSTRLEN];
124 uint16_t msc_rtp_port;
Pau Espin Pedrol83c0f762019-04-16 20:05:32 +0200125 bool use_osmux;
126 uint8_t osmux_cid;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200127
Sylvain Munautaa824922019-03-07 16:32:02 +0100128 /* Rate/codec setting in preference order (need at least 1 !) */
129 int n_ch_mode_rate;
130 struct channel_mode_and_rate ch_mode_rate[3];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200131};
132
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100133/* State of an ongoing Assignment, while the assignment_fsm is still busy. This serves as state separation to keep the
134 * currently used lchan and gscon unmodified until the outcome of an Assignment is known. If the Assignment fails, this
135 * state is simply discarded, and the gscon carries on with the original lchan remaining unchanged. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200136struct assignment_fsm_data {
137 struct assignment_request req;
138 bool requires_voice_stream;
139
140 struct osmo_fsm_inst *fi;
141 struct gsm_lchan *new_lchan;
142
143 /* Whether this assignment triggered creation of the MGW endpoint: if the assignment
144 * fails, we will release that again as soon as possible. (If false, the endpoint already
145 * existed before or isn't needed at all.)*/
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200146 struct osmo_mgcpc_ep_ci *created_ci_for_msc;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200147
148 enum gsm0808_cause failure_cause;
149 enum gsm48_rr_cause rr_cause;
150
151 bool result_rate_ctr_done;
152};
153
154enum hodec_id {
155 HODEC_NONE,
156 HODEC1 = 1,
157 HODEC2 = 2,
158 HODEC_USER,
159 HODEC_REMOTE,
160};
161
162/* For example, to count specific kinds of ongoing handovers, it is useful to be able to OR-combine
163 * scopes. */
164enum handover_scope {
165 HO_NO_HANDOVER = 0,
166 HO_INTRA_CELL = 0x1,
167 HO_INTRA_BSC = 0x2,
168 HO_INTER_BSC_OUT = 0x4,
169 HO_INTER_BSC_IN = 0x8,
170 HO_SCOPE_ALL = 0xffff,
171};
172
173extern const struct value_string handover_scope_names[];
174inline static const char *handover_scope_name(enum handover_scope val)
175{ return get_value_string(handover_scope_names, val); }
176
177struct handover_out_req {
178 enum hodec_id from_hodec_id;
179 struct gsm_lchan *old_lchan;
180 struct neighbor_ident_key target_nik;
181 enum gsm_chan_t new_lchan_type; /*< leave GSM_LCHAN_NONE to use same as old_lchan */
182};
183
184struct handover_in_req {
185 struct gsm0808_channel_type ct;
186 struct gsm0808_speech_codec_list scl;
187 struct gsm0808_encrypt_info ei;
188 struct gsm_classmark classmark;
Neels Hofmeyrc15f6cd2019-03-15 02:48:39 +0100189 /* chosen_encr_alg reflects the encoded value as in RSL_ENC_ALG_A5(a5_numer):
190 * chosen_encr_alg == 1 means A5/0 i.e. no encryption, chosen_encr_alg == 4 means A5/3.
191 * chosen_encr_alg == 0 means no such IE was present. */
192 uint8_t chosen_encr_alg;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200193 struct gsm0808_cell_id cell_id_serving;
194 char cell_id_serving_name[64];
195 struct gsm0808_cell_id cell_id_target;
196 char cell_id_target_name[64];
197 uint16_t msc_assigned_cic;
198 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
199 uint16_t msc_assigned_rtp_port;
200};
201
202struct handover {
203 struct osmo_fsm_inst *fi;
204
205 enum hodec_id from_hodec_id;
206 enum handover_scope scope;
207 enum gsm_chan_t new_lchan_type;
208 struct neighbor_ident_key target_cell;
209
210 uint8_t ho_ref;
211 struct gsm_bts *new_bts;
212 struct gsm_lchan *new_lchan;
213 bool async;
214 struct handover_in_req inter_bsc_in;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200215 struct osmo_mgcpc_ep_ci *created_ci_for_msc;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200216};
217
Neels Hofmeyr378a4922016-05-09 21:07:43 +0200218/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100219struct gsm_subscriber_connection {
Harald Weltea43e0b42016-06-19 18:06:02 +0200220 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +0800221 struct llist_head entry;
222
Harald Welte3561bd42018-01-28 03:04:16 +0100223 /* FSM instance to control the subscriber connection state (RTP, A) */
224 struct osmo_fsm_inst *fi;
225
Harald Weltea43e0b42016-06-19 18:06:02 +0200226 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100227 struct bsc_subscr *bsub;
228
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100229 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200230 struct gsm_network *network;
231
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100232 /* the primary / currently active lchan to the BTS/subscriber. During Assignment and Handover, separate lchans
233 * are kept in the .assignment or .handover sub-structs, respectively, so that this lchan remains unaffected
234 * until Assignment or Handover have actually succeeded. */
Harald Welte4a8ebc82017-12-18 18:34:41 +0100235 struct gsm_lchan *lchan;
Harald Welte3561bd42018-01-28 03:04:16 +0100236
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100237 /* Only valid during an ongoing Assignment; might be overwritten at any time by a failed Assignment attempt.
238 * Once an Assignment was successful, all relevant state must be copied out of this sub-struct. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200239 struct assignment_fsm_data assignment;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100240
Neels Hofmeyr7cfdbe72019-02-06 01:30:19 +0100241 /* handover information, if a handover is pending for this conn. Valid only during an ongoing Handover
242 * operation. If a Handover was successful, all relevant state must be copied out of this sub-struct. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200243 struct handover ho;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100244
Harald Welte4a8ebc82017-12-18 18:34:41 +0100245 /* buffer/cache for classmark of the ME of the subscriber */
Harald Weltea43e0b42016-06-19 18:06:02 +0200246 struct gsm_classmark classmark;
Andreas Eversberg935e5d72013-06-17 11:58:30 +0200247
Neels Hofmeyr149160f2018-06-16 17:20:13 +0200248 /* Queue DTAP messages during handover/assignment (msgb_enqueue()/msgb_dequeue())*/
249 struct llist_head dtap_queue;
250 unsigned int dtap_queue_len;
Andreas Eversberg084b4212013-05-30 14:12:48 +0200251
Neels Hofmeyrec422642018-02-15 14:07:40 +0100252 struct {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100253 int failures;
Neels Hofmeyrec422642018-02-15 14:07:40 +0100254 struct penalty_timers *penalty_timers;
255 } hodec2;
Neels Hofmeyra60f3442018-02-12 16:44:32 +0100256
257 /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment Request. 3GPP 48.008
258 * 3.2.2.103 says:
259 * The "Codec List (MSC Preferred)" shall not include codecs
260 * that are not supported by the MS.
261 * i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed the MS bearer
262 * capabilities, which the MSC is required to translate into the codec list. */
263 struct gsm0808_speech_codec_list codec_list;
Harald Welte519c7e12018-01-28 02:45:46 +0100264
265 /* flag to prevent multiple simultaneous ciphering commands */
266 int ciphering_handled;
267
268 /* state related to welcome USSD */
269 uint8_t new_subscriber;
270
271 /* state related to osmo_bsc_filter.c */
272 struct bsc_filter_state filter_state;
273
274 /* SCCP connection associatd with this subscriber_connection */
275 struct {
276 /* for advanced ping/pong */
277 int send_ping;
278
279 /* SCCP connection realted */
280 struct bsc_msc_data *msc;
281
282 /* Sigtran connection ID */
283 int conn_id;
284 enum subscr_sccp_state state;
285 } sccp;
286
287 /* for audio handling */
288 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200289 uint16_t msc_assigned_cic;
Harald Welte519c7e12018-01-28 02:45:46 +0100290
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200291 /* RTP address where the MSC expects us to send the RTP stream coming from the BTS. */
292 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
293 uint16_t msc_assigned_rtp_port;
Harald Welte519c7e12018-01-28 02:45:46 +0100294
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200295 /* The endpoint at the MGW used to join both BTS and MSC side connections, e.g.
296 * "rtpbridge/23@mgw". */
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200297 struct osmo_mgcpc_ep *mgw_endpoint;
Harald Welte3561bd42018-01-28 03:04:16 +0100298
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200299 /* The connection identifier of the osmo_mgcpc_ep used to transceive RTP towards the MSC.
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200300 * (The BTS side CI is handled by struct gsm_lchan and the lchan_fsm.) */
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200301 struct osmo_mgcpc_ep_ci *mgw_endpoint_ci_msc;
Harald Welte519c7e12018-01-28 02:45:46 +0100302 } user_plane;
Harald Weltec997ceb2018-05-30 01:39:43 +0200303
304 /* LCLS (local call, local switch) related state */
305 struct {
306 uint8_t global_call_ref[15];
307 uint8_t global_call_ref_len; /* length of global_call_ref */
Maxfe65ece2018-11-09 13:36:11 +0100308 enum gsm0808_lcls_config config; /* TS 48.008 3.2.2.116 */
309 enum gsm0808_lcls_control control; /* TS 48.008 3.2.2.117 */
Harald Weltec997ceb2018-05-30 01:39:43 +0200310 /* LCLS FSM */
311 struct osmo_fsm_inst *fi;
312 /* pointer to "other" connection, if Call Leg Relocation was successful */
313 struct gsm_subscriber_connection *other;
314 } lcls;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100315};
316
Harald Weltef142c972011-05-24 13:25:38 +0200317
Neels Hofmeyr10485162018-02-13 23:22:03 +0100318/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 Table 10.5.2.33b.1:
319 4-bit index is used (2#1111 = 10#15) */
320#define SI2Q_MAX_NUM 16
321/* length in bits (for single SI2quater message) */
322#define SI2Q_MAX_LEN 160
323#define SI2Q_MIN_LEN 18
324
325struct osmo_bsc_data;
326
327struct osmo_bsc_sccp_con;
328
329/* Channel Request reason */
330enum gsm_chreq_reason_t {
331 GSM_CHREQ_REASON_EMERG,
332 GSM_CHREQ_REASON_PAG,
333 GSM_CHREQ_REASON_CALL,
334 GSM_CHREQ_REASON_LOCATION_UPD,
335 GSM_CHREQ_REASON_OTHER,
336 GSM_CHREQ_REASON_PDCH,
337};
338
339/* lchans 0..3 are SDCCH in combined channel configuration,
340 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
341#define CCCH_LCHAN 4
342
343#define TRX_NR_TS 8
344#define TS_MAX_LCHAN 8
345
346#define HARDCODED_ARFCN 123
347#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
348
349/* for multi-drop config */
350#define HARDCODED_BTS0_TS 1
351#define HARDCODED_BTS1_TS 6
352#define HARDCODED_BTS2_TS 11
353
354#define MAX_VERSION_LENGTH 64
355
Neels Hofmeyr10485162018-02-13 23:22:03 +0100356enum gsm_hooks {
357 GSM_HOOK_NM_SWLOAD,
358 GSM_HOOK_RR_PAGING,
359 GSM_HOOK_RR_SECURITY,
360};
361
Neels Hofmeyr10485162018-02-13 23:22:03 +0100362enum bts_gprs_mode {
363 BTS_GPRS_NONE = 0,
364 BTS_GPRS_GPRS = 1,
365 BTS_GPRS_EGPRS = 2,
366};
367
368struct gsm_lchan;
369struct osmo_rtp_socket;
370struct rtp_socket;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100371
372/* Network Management State */
373struct gsm_nm_state {
374 uint8_t operational;
375 uint8_t administrative;
376 uint8_t availability;
377};
378
379struct gsm_abis_mo {
380 uint8_t obj_class;
381 uint8_t procedure_pending;
382 struct abis_om_obj_inst obj_inst;
383 const char *name;
384 struct gsm_nm_state nm_state;
385 struct tlv_parsed *nm_attr;
386 struct gsm_bts *bts;
387};
388
389/* Ericsson OM2000 Managed Object */
390struct abis_om2k_mo {
391 uint8_t class;
392 uint8_t bts;
393 uint8_t assoc_so;
394 uint8_t inst;
395} __attribute__ ((packed));
396
397struct om2k_mo {
398 struct abis_om2k_mo addr;
399 struct osmo_fsm_inst *fsm;
400};
401
402#define A38_XOR_MIN_KEY_LEN 12
403#define A38_XOR_MAX_KEY_LEN 16
404#define A38_COMP128_KEY_LEN 16
405#define RSL_ENC_ALG_A5(x) (x+1)
406#define MAX_EARFCN_LIST 32
407
408/* is the data link established? who established it? */
409#define LCHAN_SAPI_UNUSED 0
410#define LCHAN_SAPI_MS 1
411#define LCHAN_SAPI_NET 2
Neels Hofmeyr10485162018-02-13 23:22:03 +0100412
413/* BTS ONLY */
414#define MAX_NUM_UL_MEAS 104
415#define LC_UL_M_F_L1_VALID (1 << 0)
416#define LC_UL_M_F_RES_VALID (1 << 1)
417
418struct bts_ul_meas {
419 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
420 uint16_t ber10k;
421 /* timing advance offset (in quarter bits) */
422 int16_t ta_offs_qbits;
423 /* C/I ratio in dB */
424 float c_i;
425 /* flags */
426 uint8_t is_sub:1;
427 /* RSSI in dBm * -1 */
428 uint8_t inv_rssi;
429};
430
431struct bts_codec_conf {
432 uint8_t hr;
433 uint8_t efr;
434 uint8_t amr;
435};
436
437struct amr_mode {
438 uint8_t mode;
439 uint8_t threshold;
440 uint8_t hysteresis;
441};
442
443struct amr_multirate_conf {
444 uint8_t gsm48_ie[2];
445 struct amr_mode ms_mode[4];
446 struct amr_mode bts_mode[4];
447 uint8_t num_modes;
448};
449/* /BTS ONLY */
450
451enum lchan_csd_mode {
452 LCHAN_CSD_M_NT,
453 LCHAN_CSD_M_T_1200_75,
454 LCHAN_CSD_M_T_600,
455 LCHAN_CSD_M_T_1200,
456 LCHAN_CSD_M_T_2400,
457 LCHAN_CSD_M_T_9600,
458 LCHAN_CSD_M_T_14400,
459 LCHAN_CSD_M_T_29000,
460 LCHAN_CSD_M_T_32000,
461};
462
463/* State of the SAPIs in the lchan */
464enum lchan_sapi_state {
465 LCHAN_SAPI_S_NONE,
466 LCHAN_SAPI_S_REQ,
467 LCHAN_SAPI_S_ASSIGNED,
468 LCHAN_SAPI_S_REL,
469 LCHAN_SAPI_S_ERROR,
470};
471
Neels Hofmeyr92b9f2e2018-02-14 00:19:11 +0100472#define MAX_A5_KEY_LEN (128/8)
473
474struct gsm_encr {
475 uint8_t alg_id;
476 uint8_t key_len;
477 uint8_t key[MAX_A5_KEY_LEN];
478};
479
Neels Hofmeyr8da22332018-04-11 01:43:41 +0200480#define LOGPLCHAN(lchan, ss, level, fmt, args...) \
481 LOGP(ss, level, "%s (ss=%d,%s) (%s) " fmt, \
482 lchan ? gsm_ts_and_pchan_name(lchan->ts) : "-", \
483 lchan ? lchan->nr : 0, \
484 lchan ? gsm_lchant_name(lchan->type) : "-", \
485 bsc_subscr_name(lchan && lchan->conn ? lchan->conn->bsub : NULL), \
486 ## args)
487
Pau Espin Pedrold3e8e0c2018-11-28 16:35:10 +0100488/* Iterate lchans that have an FSM allocated based based on explicit pchan kind
489 * (GSM_PCHAN_* constant).
490 * Remark: PDCH related lchans are not handled in BSC but in PCU, so trying to
491 * iterate through GSM_PCHAN_PDCH is considered a void loop.
492 */
493#define ts_as_pchan_for_each_lchan(lchan, ts, as_pchan) \
494 for (lchan = (ts)->lchan; \
495 ((lchan - (ts)->lchan) < ARRAY_SIZE((ts)->lchan)) \
496 && lchan->fi \
497 && lchan->nr < pchan_subslots(as_pchan); \
498 lchan++)
499
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100500/* Iterate lchans that have an FSM allocated based on current PCHAN
501 * mode set in \ref ts.
502 * usage:
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200503 * struct gsm_lchan *lchan;
504 * struct gsm_bts_trx_ts *ts = get_some_timeslot();
505 * ts_for_each_lchan(lchan, ts) {
506 * LOGPLCHAN(DMAIN, LOGL_DEBUG, "hello world\n");
507 * }
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100508 */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200509#define ts_for_each_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_is)
510
Pau Espin Pedrol0ba20df2018-11-28 16:39:29 +0100511/* Iterate over all possible lchans available that have an FSM allocated based
512 * on PCHAN \ref ts (dynamic) configuration.
513 * Iterate all lchan instances set up by this \ref ts type, including those
514 * lchans currently disabled or in process of being enabled (e.g. due to dynamic
515 * timeslot in switchover). Compare ts_for_each_lchan(), which iterates only the
516 * enabled lchans.
517 * For example, it is useful in case dynamic timeslot \ref ts is in process of
518 * switching from configuration PDCH (no lchans) to TCH_F (1 lchan), where
519 * pchan_is is still set to PDCH but \ref ts may contain already an \ref lchan
520 * of type TCH_F which initiated the request to switch the \ts configuration.
521 */
522#define ts_for_each_potential_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_on_init)
523
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200524enum lchan_activate_mode {
525 FOR_NONE,
526 FOR_MS_CHANNEL_REQUEST,
527 FOR_ASSIGNMENT,
528 FOR_HANDOVER,
529 FOR_VTY,
530};
531
532extern const struct value_string lchan_activate_mode_names[];
533static inline const char *lchan_activate_mode_name(enum lchan_activate_mode activ_for)
534{ return get_value_string(lchan_activate_mode_names, activ_for); }
535
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100536struct lchan_activate_info {
537 enum lchan_activate_mode activ_for;
538 struct gsm_subscriber_connection *for_conn;
539 /* This always is for a specific lchan, so its lchan->type indicates full or half rate.
540 * When a dyn TS was selected, the lchan->type has been set to the desired rate. */
541 enum gsm48_chan_mode chan_mode;
Neels Hofmeyr58cf1b12019-03-15 02:49:18 +0100542 struct gsm_encr encr;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100543 /* AMR config */
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100544 uint16_t s15_s0;
545 bool requires_voice_stream;
546 bool wait_before_switching_rtp; /*< true = requires LCHAN_EV_READY_TO_SWITCH_RTP */
547 uint16_t msc_assigned_cic;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100548 /* During intra-BSC handover, we keep the MGW endpoint intact and just re-route to the new lchan. This
549 * 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 +0100550 struct gsm_lchan *re_use_mgw_endpoint_from_lchan;
551};
552
Neels Hofmeyr10485162018-02-13 23:22:03 +0100553struct gsm_lchan {
554 /* The TS that we're part of */
555 struct gsm_bts_trx_ts *ts;
556 /* The logical subslot number in the TS */
557 uint8_t nr;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200558 char *name;
559
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100560 char *last_error;
561
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200562 struct osmo_fsm_inst *fi;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200563 struct osmo_fsm_inst *fi_rtp;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200564 struct osmo_mgcpc_ep_ci *mgw_endpoint_ci_bts;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200565
566 struct {
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100567 struct lchan_activate_info info;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200568 bool activ_ack; /*< true as soon as RSL Chan Activ Ack is received */
Neels Hofmeyr369fba22018-11-27 01:30:50 +0100569 bool immediate_assignment_sent;
Neels Hofmeyr193c1e32018-08-27 22:06:24 +0200570 /*! This flag ensures that when an lchan activation has succeeded, and we have already
571 * sent ACKs like Immediate Assignment or BSSMAP Assignment Complete, and if other errors
572 * occur later, e.g. during release, that we don't send a NACK out of context. */
573 bool concluded;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200574 enum gsm0808_cause gsm0808_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200575 } activate;
576
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100577 struct {
578 /* If an event to release the lchan comes in while still waiting for responses, just mark this
579 * flag, so that the lchan will gracefully release at the next sensible junction. */
580 bool requested;
581 bool do_rr_release;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200582
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100583 /* There is an RSL error cause of value 0, so we need a separate flag. */
584 bool in_error;
585 /* RSL error code, RSL_ERR_* */
586 uint8_t rsl_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200587
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100588 /* If a release event is being handled, ignore other ricocheting release events until that
589 * release handling has concluded. */
590 bool in_release_handler;
Harald Welte963763d2019-02-03 12:11:12 +0100591
592 /* is this release at the end of a CSFB call? */
593 bool is_csfb;
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100594 } release;
Neels Hofmeyrd5df9a12018-07-20 05:35:47 +0200595
Neels Hofmeyr10485162018-02-13 23:22:03 +0100596 /* The logical channel type */
597 enum gsm_chan_t type;
598 /* RSL channel mode */
599 enum rsl_cmod_spd rsl_cmode;
600 /* If TCH, traffic channel mode */
601 enum gsm48_chan_mode tch_mode;
602 enum lchan_csd_mode csd_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100603 /* Power levels for MS and BTS */
604 uint8_t bs_power;
605 uint8_t ms_power;
606 /* Encryption information */
607 struct gsm_encr encr;
608
609 /* AMR bits */
610 uint8_t mr_ms_lv[7];
611 uint8_t mr_bts_lv[7];
Neels Hofmeyr4daa2102019-01-30 16:46:58 +0100612 /* AMR bits were based on these rate bits: */
613 uint16_t s15_s0;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100614
615 /* Established data link layer services */
616 uint8_t sapis[8];
617
618 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200619 uint32_t bound_ip; /*< where the BTS receives RTP */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100620 uint16_t bound_port;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200621 uint32_t connect_ip; /*< where the BTS sends RTP to (MGW) */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100622 uint16_t connect_port;
623 uint16_t conn_id;
624 uint8_t rtp_payload;
625 uint8_t rtp_payload2;
626 uint8_t speech_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100627
628 /* info we need to postpone the AoIP
629 * assignment completed message */
630 struct {
631 uint8_t rr_cause;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100632 bool valid;
633 } ass_compl;
634 } abis_ip;
635
636 uint8_t rqd_ta;
637
Neels Hofmeyr10485162018-02-13 23:22:03 +0100638 /* table of neighbor cell measurements */
639 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
640
641 /* cache of last measurement reports on this lchan */
642 struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
643 int meas_rep_idx;
644 int meas_rep_count;
Neels Hofmeyr35ba85c2018-02-12 16:47:40 +0100645 uint8_t meas_rep_last_seen_nr;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100646
647 /* GSM Random Access data */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200648 /* TODO: don't allocate this, rather keep an "is_present" flag */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100649 struct gsm48_req_ref *rqd_ref;
650
651 struct gsm_subscriber_connection *conn;
Philipp Maierbb66d102019-01-22 11:29:06 +0100652
653 /* Depending on the preferences that where submitted together with
654 * the assignment and the current channel load, the BSC has to select
655 * one of the offered codec/rates. The final selection by the BSC is
656 * stored here and is used when sending the assignment complete or
657 * when performing a handover procedure. */
658 struct channel_mode_and_rate ch_mode_rate;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100659};
660
Neels Hofmeyr10485162018-02-13 23:22:03 +0100661/* One Timeslot in a TRX */
662struct gsm_bts_trx_ts {
663 struct gsm_bts_trx *trx;
664 /* number of this timeslot at the TRX */
665 uint8_t nr;
666
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200667 struct osmo_fsm_inst *fi;
668 char *last_errmsg;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100669
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200670 /* vty phys_chan_config setting, not necessarily in effect in case it was changed in the telnet
671 * vty after OML activation. Gets written on vty 'write file'. */
672 enum gsm_phys_chan_config pchan_from_config;
673 /* When the timeslot OML is established, pchan_from_config is copied here. This is the pchan
674 * currently in effect; for dynamic ts, this is the dyn kind (GSM_PCHAN_TCH_F_TCH_H_PDCH or
675 * GSM_PCHAN_TCH_F_PDCH) and does not show the pchan type currently active. */
676 enum gsm_phys_chan_config pchan_on_init;
677 /* This is the *actual* pchan type currently active. For dynamic timeslots, this reflects either
678 * GSM_PCHAN_NONE or one of the standard GSM_PCHAN_TCH_F, GSM_PCHAN_TCH_H, GSM_PCHAN_PDCH.
679 * Callers can use this transparently without being aware of dyn ts. */
680 enum gsm_phys_chan_config pchan_is;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100681
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200682 /* After a PDCH ACT NACK, we shall not infinitely loop to try and ACT again.
683 * Also marks a timeslot where PDCH was deactivated by VTY. This is cleared whenever a timeslot
684 * enters IN_USE state, i.e. after each TCH use we try to PDCH ACT once again. */
685 bool pdch_act_allowed;
686
Neels Hofmeyrbcdbfb72018-07-26 20:33:15 +0200687 /* Whether TS_EV_OML_READY was received */
688 bool is_oml_ready;
689 /* Whether TS_EV_RSL_READY was received */
690 bool is_rsl_ready;
691
Neels Hofmeyr10485162018-02-13 23:22:03 +0100692 struct gsm_abis_mo mo;
693 struct tlv_parsed nm_attr;
694 uint8_t nm_chan_comb;
695 int tsc; /* -1 == use BTS TSC */
696
697 struct {
698 /* Parameters below are configured by VTY */
699 int enabled;
700 uint8_t maio;
701 uint8_t hsn;
702 struct bitvec arfcns;
703 uint8_t arfcns_data[1024/8];
704 /* This is the pre-computed MA for channel assignments */
705 struct bitvec ma;
706 uint8_t ma_len; /* part of ma_data that is used */
707 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
708 } hopping;
709
710 /* To which E1 subslot are we connected */
711 struct gsm_e1_subslot e1_link;
712
713 union {
714 struct {
715 struct om2k_mo om2k_mo;
716 } rbs2000;
717 };
718
719 struct gsm_lchan lchan[TS_MAX_LCHAN];
720};
721
722/* One TRX in a BTS */
723struct gsm_bts_trx {
724 /* list header in bts->trx_list */
725 struct llist_head list;
726
727 struct gsm_bts *bts;
728 /* number of this TRX in the BTS */
729 uint8_t nr;
730 /* human readable name / description */
731 char *description;
732 /* how do we talk RSL with this TRX? */
733 struct gsm_e1_subslot rsl_e1_link;
734 uint8_t rsl_tei;
735 struct e1inp_sign_link *rsl_link;
736
737 /* Timeout for initiating the RSL connection. */
738 struct osmo_timer_list rsl_connect_timeout;
739
740 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
741 struct e1inp_sign_link *oml_link;
742
743 struct gsm_abis_mo mo;
744 struct tlv_parsed nm_attr;
745 struct {
746 struct gsm_abis_mo mo;
747 } bb_transc;
748
749 uint16_t arfcn;
750 int nominal_power; /* in dBm */
751 unsigned int max_power_red; /* in actual dB */
752
753 union {
754 struct {
755 struct {
756 struct gsm_abis_mo mo;
757 } bbsig;
758 struct {
759 struct gsm_abis_mo mo;
760 } pa;
761 } bs11;
762 struct {
763 unsigned int test_state;
764 uint8_t test_nr;
765 struct rxlev_stats rxlev_stat;
766 } ipaccess;
767 struct {
768 struct {
769 struct om2k_mo om2k_mo;
770 } trxc;
771 struct {
772 struct om2k_mo om2k_mo;
773 } rx;
774 struct {
775 struct om2k_mo om2k_mo;
776 } tx;
777 } rbs2000;
778 };
779 struct gsm_bts_trx_ts ts[TRX_NR_TS];
780};
781
782#define GSM_BTS_SI2Q(bts, i) (struct gsm48_system_information_type_2quater *)((bts)->si_buf[SYSINFO_TYPE_2quater][i])
783#define GSM_BTS_HAS_SI(bts, i) ((bts)->si_valid & (1 << i))
784#define GSM_BTS_SI(bts, i) (void *)((bts)->si_buf[i][0])
785#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
786
787enum gsm_bts_type {
788 GSM_BTS_TYPE_UNKNOWN,
789 GSM_BTS_TYPE_BS11,
790 GSM_BTS_TYPE_NANOBTS,
791 GSM_BTS_TYPE_RBS2000,
792 GSM_BTS_TYPE_NOKIA_SITE,
793 GSM_BTS_TYPE_OSMOBTS,
794 _NUM_GSM_BTS_TYPE
795};
796
797enum gsm_bts_type_variant {
798 BTS_UNKNOWN,
799 BTS_OSMO_LITECELL15,
800 BTS_OSMO_OCTPHY,
801 BTS_OSMO_SYSMO,
802 BTS_OSMO_TRX,
803 _NUM_BTS_VARIANT
804};
805
806/* Used by OML layer for BTS Attribute reporting */
807enum bts_attribute {
808 BTS_TYPE_VARIANT,
809 BTS_SUB_MODEL,
810 TRX_PHY_VERSION,
811};
812
813struct vty;
814
815struct gsm_bts_model {
816 struct llist_head list;
817
818 enum gsm_bts_type type;
819 enum gsm_bts_type_variant variant;
820 const char *name;
821
822 bool started;
823 int (*start)(struct gsm_network *net);
824 int (*oml_rcvmsg)(struct msgb *msg);
825 char * (*oml_status)(const struct gsm_bts *bts);
826
827 void (*e1line_bind_ops)(struct e1inp_line *line);
828
829 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
830 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
831 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
832
Pau Espin Pedrol167cb822018-11-19 17:48:17 +0100833 /* Should SI2bis and SI2ter be disabled by default on this BTS model? */
834 bool force_combined_si;
835
Neels Hofmeyr10485162018-02-13 23:22:03 +0100836 struct tlv_definition nm_att_tlvdef;
837
838 /* features of a given BTS model set via gsm_bts_model_register() locally */
839 struct bitvec features;
840 uint8_t _features_data[MAX_BTS_FEATURES/8];
841};
842
Neels Hofmeyr10485162018-02-13 23:22:03 +0100843
Neels Hofmeyr10485162018-02-13 23:22:03 +0100844
845/*
846 * This keeps track of the paging status of one BTS. It
847 * includes a number of pending requests, a back pointer
848 * to the gsm_bts, a timer and some more state.
849 */
850struct gsm_bts_paging_state {
851 /* pending requests */
852 struct llist_head pending_requests;
853 struct gsm_bts *bts;
854
855 struct osmo_timer_list work_timer;
856 struct osmo_timer_list credit_timer;
857
858 /* free chans needed */
859 int free_chans_need;
860
861 /* load */
862 uint16_t available_slots;
863};
864
865struct gsm_envabtse {
866 struct gsm_abis_mo mo;
867};
868
869struct gsm_bts_gprs_nsvc {
870 struct gsm_bts *bts;
871 /* data read via VTY config file, to configure the BTS
872 * via OML from BSC */
873 int id;
874 uint16_t nsvci;
875 uint16_t local_port; /* on the BTS */
876 uint16_t remote_port; /* on the SGSN */
877 uint32_t remote_ip; /* on the SGSN */
878
879 struct gsm_abis_mo mo;
880};
881
882enum gprs_rlc_par {
883 RLC_T3142,
884 RLC_T3169,
885 RLC_T3191,
886 RLC_T3193,
887 RLC_T3195,
888 RLC_N3101,
889 RLC_N3103,
890 RLC_N3105,
891 CV_COUNTDOWN,
892 T_DL_TBF_EXT, /* ms */
893 T_UL_TBF_EXT, /* ms */
894 _NUM_RLC_PAR
895};
896
897enum gprs_cs {
898 GPRS_CS1,
899 GPRS_CS2,
900 GPRS_CS3,
901 GPRS_CS4,
902 GPRS_MCS1,
903 GPRS_MCS2,
904 GPRS_MCS3,
905 GPRS_MCS4,
906 GPRS_MCS5,
907 GPRS_MCS6,
908 GPRS_MCS7,
909 GPRS_MCS8,
910 GPRS_MCS9,
911 _NUM_GRPS_CS
912};
913
914struct gprs_rlc_cfg {
915 uint16_t parameter[_NUM_RLC_PAR];
916 struct {
917 uint16_t repeat_time; /* ms */
918 uint8_t repeat_count;
919 } paging;
920 uint32_t cs_mask; /* bitmask of gprs_cs */
921 uint8_t initial_cs;
922 uint8_t initial_mcs;
923};
924
925
926enum neigh_list_manual_mode {
927 NL_MODE_AUTOMATIC = 0,
928 NL_MODE_MANUAL = 1,
929 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
930};
931
932enum bts_loc_fix {
933 BTS_LOC_FIX_INVALID = 0,
934 BTS_LOC_FIX_2D = 1,
935 BTS_LOC_FIX_3D = 2,
936};
937
938extern const struct value_string bts_loc_fix_names[];
939
940struct bts_location {
941 struct llist_head list;
942 time_t tstamp;
943 enum bts_loc_fix valid;
944 double lat;
945 double lon;
946 double height;
947};
948
949/* Channel load counter */
950struct load_counter {
951 unsigned int total;
952 unsigned int used;
953};
954
Neels Hofmeyr19bed232018-03-22 04:54:57 +0100955/* Useful to track N-N relations between BTS, for example neighbors. */
956struct gsm_bts_ref {
957 struct llist_head entry;
958 struct gsm_bts *bts;
959};
960
Harald Welted41b7c72019-06-13 09:41:58 +0200961/* A single Page of a SMSCB message */
962struct bts_smscb_page {
963 /* SMSCB message we're part of */
964 struct bts_smscb_message *msg;
965 /* Page Number within message (1 to 15) */
966 uint8_t nr;
967 /* number of valid blocks in data (up to 4) */
968 uint8_t num_blocks;
969 /* up to four blocks of 22 bytes each */
970 uint8_t data[88];
971};
972
973/* A SMSCB message (received from CBSP) */
974struct bts_smscb_message {
975 /* entry in bts_smscb_chan_state.messages */
976 struct llist_head list;
977 struct {
978 /* input data from CBSP (CBC) side */
979 uint16_t msg_id;
980 uint16_t serial_nr;
981 enum cbsp_category category;
982 uint16_t rep_period;
983 uint16_t num_bcast_req;
984 uint8_t dcs;
985 } input;
986 /* how often have all pages of this message been broadcast? */
987 uint32_t bcast_count;
988 /* actual page data of this message */
989 uint8_t num_pages; /* up to 15 */
990 struct bts_smscb_page page[15];
991};
992
993/* per-channel (basic/extended) CBCH state for a single BTS */
994struct bts_smscb_chan_state {
995 /* back-pointer to BTS */
996 struct gsm_bts *bts;
997 /* list of bts_smscb_message */
998 struct llist_head messages;
999 /* scheduling array; pointer of SMSCB pages */
1000 struct bts_smscb_page **sched_arr;
1001 size_t sched_arr_size;
1002 /* index of the next to be transmitted page into the scheduler array */
1003 size_t next_idx;
1004 /* number of messages we have to pause due to overflow */
1005 uint8_t overflow;
1006};
1007
Neels Hofmeyr10485162018-02-13 23:22:03 +01001008/* One BTS */
1009struct gsm_bts {
1010 /* list header in net->bts_list */
1011 struct llist_head list;
1012
1013 /* Geographical location of the BTS */
1014 struct llist_head loc_list;
1015
1016 /* number of ths BTS in network */
1017 uint8_t nr;
1018 /* human readable name / description */
1019 char *description;
1020 /* Cell Identity */
1021 uint16_t cell_identity;
1022 /* location area code of this BTS */
1023 uint16_t location_area_code;
1024 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
1025 * which is used as TSC for the CCCH */
1026 uint8_t bsic;
1027 /* type of BTS */
1028 enum gsm_bts_type type;
1029 enum gsm_bts_type_variant variant;
1030 struct gsm_bts_model *model;
1031 enum gsm_band band;
1032 char version[MAX_VERSION_LENGTH];
1033 char sub_model[MAX_VERSION_LENGTH];
1034
1035 /* features of a given BTS set/reported via OML */
1036 struct bitvec features;
1037 uint8_t _features_data[MAX_BTS_FEATURES/8];
1038
1039 /* Connected PCU version (if any) */
1040 char pcu_version[MAX_VERSION_LENGTH];
1041
1042 /* maximum Tx power that the MS is permitted to use in this cell */
1043 int ms_max_power;
1044
1045 /* how do we talk OML with this TRX? */
1046 struct gsm_e1_subslot oml_e1_link;
1047 uint8_t oml_tei;
1048 struct e1inp_sign_link *oml_link;
Pau Espin Pedrol9862bcb2018-08-22 21:54:12 +02001049 /* Timer to use for deferred drop of OML link, see \ref ipaccess_drop_oml_deferred */
1050 struct osmo_timer_list oml_drop_link_timer;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001051 /* when OML link was established */
1052 time_t uptime;
1053
1054 /* Abis network management O&M handle */
1055 struct abis_nm_h *nmh;
1056
1057 struct gsm_abis_mo mo;
1058
1059 /* number of this BTS on given E1 link */
1060 uint8_t bts_nr;
1061
1062 /* DTX features of this BTS */
1063 enum gsm48_dtx_mode dtxu;
1064 bool dtxd;
1065
1066 /* paging state and control */
1067 struct gsm_bts_paging_state paging;
1068
1069 /* CCCH is on C0 */
1070 struct gsm_bts_trx *c0;
1071
1072 struct {
1073 struct gsm_abis_mo mo;
1074 } site_mgr;
1075
1076 /* bitmask of all SI that are present/valid in si_buf */
1077 uint32_t si_valid;
1078 /* 3GPP TS 44.018 Table 10.5.2.33b.1 INDEX and COUNT for SI2quater */
1079 uint8_t si2q_index; /* distinguish individual SI2quater messages */
1080 uint8_t si2q_count; /* si2q_index for the last (highest indexed) individual SI2quater message */
1081 /* buffers where we put the pre-computed SI */
1082 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
1083 /* offsets used while generating SI2quater */
1084 size_t e_offset;
1085 size_t u_offset;
Pau Espin Pedrol1cf21de2018-12-05 13:38:10 +01001086 /* 3GPP TS 08.58 §8.5.1 BCCH INFORMATION. Some nanoBTS fail upon
1087 * receival of empty SI disabling unsupported SI. see OS#3707. */
1088 bool si_unused_send_empty;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001089
1090 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
1091 union {
1092 struct {
1093 uint16_t site_id;
1094 uint16_t bts_id;
1095 uint32_t flags;
1096 uint32_t rsl_ip;
1097 } ip_access;
1098 struct {
1099 struct {
1100 struct gsm_abis_mo mo;
1101 } cclk;
1102 struct {
1103 struct gsm_abis_mo mo;
1104 } rack;
1105 struct gsm_envabtse envabtse[4];
1106 } bs11;
1107 struct {
1108 struct {
1109 struct om2k_mo om2k_mo;
1110 struct gsm_abis_mo mo;
1111 struct llist_head conn_groups;
1112 } cf;
1113 struct {
1114 struct om2k_mo om2k_mo;
1115 struct gsm_abis_mo mo;
1116 struct llist_head conn_groups;
1117 } is;
1118 struct {
1119 struct om2k_mo om2k_mo;
1120 struct gsm_abis_mo mo;
1121 struct llist_head conn_groups;
1122 } con;
1123 struct {
1124 struct om2k_mo om2k_mo;
1125 struct gsm_abis_mo mo;
1126 } dp;
1127 struct {
1128 struct om2k_mo om2k_mo;
1129 struct gsm_abis_mo mo;
1130 } tf;
1131 uint32_t use_superchannel:1;
1132 } rbs2000;
1133 struct {
1134 uint8_t bts_type;
1135 unsigned int configured:1,
1136 skip_reset:1,
1137 no_loc_rel_cnf:1,
1138 bts_reset_timer_cnf,
1139 did_reset:1,
1140 wait_reset:1;
1141 struct osmo_timer_list reset_timer;
1142 } nokia;
1143 };
1144
1145 /* Not entirely sure how ip.access specific this is */
1146 struct {
1147 uint8_t supports_egprs_11bit_rach;
1148 enum bts_gprs_mode mode;
1149 struct {
1150 struct gsm_abis_mo mo;
1151 uint16_t nsei;
1152 uint8_t timer[7];
1153 } nse;
1154 struct {
1155 struct gsm_abis_mo mo;
1156 uint16_t bvci;
1157 uint8_t timer[11];
1158 struct gprs_rlc_cfg rlc_cfg;
1159 } cell;
1160 struct gsm_bts_gprs_nsvc nsvc[2];
1161 uint8_t rac;
1162 uint8_t net_ctrl_ord;
1163 bool ctrl_ack_type_use_block;
1164 } gprs;
1165
Harald Welte15400252019-05-24 11:56:23 +02001166 /* threshold (in percent) when BTS shall send CCCH LOAD IND */
1167 int ccch_load_ind_thresh;
1168
Neels Hofmeyr10485162018-02-13 23:22:03 +01001169 /* RACH NM values */
1170 int rach_b_thresh;
1171 int rach_ldavg_slots;
1172
1173 /* transceivers */
1174 int num_trx;
1175 struct llist_head trx_list;
1176
1177 /* SI related items */
1178 int force_combined_si;
Pau Espin Pedrol167cb822018-11-19 17:48:17 +01001179 bool force_combined_si_set;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001180 int bcch_change_mark;
1181
1182 /* Abis NM queue */
1183 struct llist_head abis_queue;
1184 int abis_nm_pend;
1185
1186 struct gsm_network *network;
1187
1188 /* should the channel allocator allocate channels from high TRX to TRX0,
1189 * rather than starting from TRX0 and go upwards? */
1190 int chan_alloc_reverse;
1191
1192 enum neigh_list_manual_mode neigh_list_manual_mode;
1193 /* parameters from which we build SYSTEM INFORMATION */
1194 struct {
1195 struct gsm48_rach_control rach_control;
1196 uint8_t ncc_permitted;
1197 struct gsm48_cell_sel_par cell_sel_par;
1198 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
1199 struct gsm48_cell_options cell_options;
1200 struct gsm48_control_channel_descr chan_desc;
1201 struct bitvec neigh_list;
1202 struct bitvec cell_alloc;
1203 struct bitvec si5_neigh_list;
1204 struct osmo_earfcn_si2q si2quater_neigh_list;
1205 size_t uarfcn_length; /* index for uarfcn and scramble lists */
1206 struct {
1207 /* bitmask large enough for all possible ARFCN's */
1208 uint8_t neigh_list[1024/8];
1209 uint8_t cell_alloc[1024/8];
1210 /* If the user wants a different neighbor list in SI5 than in SI2 */
1211 uint8_t si5_neigh_list[1024/8];
1212 uint8_t meas_bw_list[MAX_EARFCN_LIST];
1213 uint16_t earfcn_list[MAX_EARFCN_LIST];
1214 uint16_t uarfcn_list[MAX_EARFCN_LIST];
1215 uint16_t scramble_list[MAX_EARFCN_LIST];
1216 } data;
1217 } si_common;
1218 bool early_classmark_allowed;
1219 bool early_classmark_allowed_3g;
1220 /* for testing only: Have an infinitely long radio link timeout */
1221 bool infinite_radio_link_timeout;
1222
1223 /* do we use static (user-defined) system information messages? (bitmask) */
1224 uint32_t si_mode_static;
1225
Stefan Sperling6442e432018-02-06 14:44:54 +01001226 /* access control class ramping */
1227 struct acc_ramp acc_ramp;
1228
Neels Hofmeyr10485162018-02-13 23:22:03 +01001229 /* exclude the BTS from the global RF Lock handling */
1230 int excl_from_rf_lock;
1231
1232 /* supported codecs beside FR */
1233 struct bts_codec_conf codec;
1234
1235 /* BTS dependencies bit field */
1236 uint32_t depends_on[256/(8*4)];
1237
1238 /* full and half rate multirate config */
1239 struct amr_multirate_conf mr_full;
1240 struct amr_multirate_conf mr_half;
1241
1242 /* PCU socket state */
1243 char *pcu_sock_path;
1244 struct pcu_sock_state *pcu_state;
1245
1246 struct rate_ctr_group *bts_ctrs;
1247 struct osmo_stat_item_group *bts_statg;
1248
1249 struct handover_cfg *ho;
1250
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001251 /* A list of struct gsm_bts_ref, indicating neighbors of this BTS.
1252 * When the si_common neigh_list is in automatic mode, it is populated from this list as well as
1253 * gsm_network->neighbor_bss_cells. */
1254 struct llist_head local_neighbors;
1255
Neels Hofmeyr10485162018-02-13 23:22:03 +01001256 /* BTS-specific overrides for timer values from struct gsm_network. */
1257 uint8_t T3122; /* ASSIGMENT REJECT wait indication */
Pau Espin Pedrol1b963342018-11-07 14:19:32 +01001258 bool T3113_dynamic; /* Calculate T3113 timeout dynamically based on BTS channel config and load */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001259
1260 /* Periodic channel load measurements are used to maintain T3122. */
1261 struct load_counter chan_load_samples[7];
1262 int chan_load_samples_idx;
Stefan Sperling6442e432018-02-06 14:44:54 +01001263 uint8_t chan_load_avg; /* current channel load average in percent (0 - 100). */
Harald Welted41b7c72019-06-13 09:41:58 +02001264
1265 /* cell broadcast system */
1266 struct osmo_timer_list cbch_timer;
1267 struct bts_smscb_chan_state cbch_basic;
1268 struct bts_smscb_chan_state cbch_extended;
Neels Hofmeyr10485162018-02-13 23:22:03 +01001269};
1270
Oliver Smith8d8d7102018-10-23 15:35:43 +02001271/* One rejected BTS */
1272struct gsm_bts_rejected {
1273 /* list header in net->bts_rejected */
1274 struct llist_head list;
1275
1276 uint16_t site_id;
1277 uint16_t bts_id;
1278 char ip[INET6_ADDRSTRLEN];
1279 time_t time;
1280};
Neels Hofmeyr10485162018-02-13 23:22:03 +01001281
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001282struct gsm_network *gsm_network_init(void *ctx);
1283
Neels Hofmeyr10485162018-02-13 23:22:03 +01001284struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, uint8_t bts_num);
Neels Hofmeyr6d568ed2018-07-09 16:49:18 +02001285struct gsm_bts *gsm_bts_num(const struct gsm_network *net, int num);
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001286bool gsm_bts_matches_lai(const struct gsm_bts *bts, const struct osmo_location_area_id *lai);
1287bool gsm_bts_matches_cell_id(const struct gsm_bts *bts, const struct gsm0808_cell_id *cell_id);
1288struct gsm_bts *gsm_bts_by_cell_id(const struct gsm_network *net,
1289 const struct gsm0808_cell_id *cell_id,
1290 int match_idx);
1291int gsm_bts_local_neighbor_add(struct gsm_bts *bts, struct gsm_bts *neighbor);
1292int gsm_bts_local_neighbor_del(struct gsm_bts *bts, const struct gsm_bts *neighbor);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001293
1294struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
1295struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
1296
1297enum gsm_bts_type str2btstype(const char *arg);
1298const char *btstype2str(enum gsm_bts_type type);
1299
1300enum bts_attribute str2btsattr(const char *s);
1301const char *btsatttr2str(enum bts_attribute v);
1302
1303enum gsm_bts_type_variant str2btsvariant(const char *arg);
1304const char *btsvariant2str(enum gsm_bts_type_variant v);
1305
1306extern const struct value_string gsm_chreq_descs[];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001307extern const struct value_string gsm_pchant_names[];
1308extern const struct value_string gsm_pchant_descs[];
1309extern const struct value_string gsm_pchan_ids[];
Neels Hofmeyr10485162018-02-13 23:22:03 +01001310const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001311static inline const char *gsm_pchan_id(enum gsm_phys_chan_config c)
1312{ return get_value_string(gsm_pchan_ids, c); }
Neels Hofmeyr10485162018-02-13 23:22:03 +01001313enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
1314const char *gsm_lchant_name(enum gsm_chan_t c);
1315const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte57658ec2019-02-04 12:30:44 +01001316char *gsm_bts_name(const struct gsm_bts *bts);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001317char *gsm_trx_name(const struct gsm_bts_trx *trx);
1318char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
1319char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
1320char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001321
1322static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
1323{
1324 return lchan->name;
1325}
1326
Neels Hofmeyr10485162018-02-13 23:22:03 +01001327void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
1328
1329struct gsm_nm_state *
1330gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
1331 const struct abis_om_obj_inst *obj_inst);
1332void *
1333gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
1334 const struct abis_om_obj_inst *obj_inst);
1335
1336/* reset the state of all MO in the BTS */
1337void gsm_bts_mo_reset(struct gsm_bts *bts);
1338
1339uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
1340 uint8_t ts_nr, uint8_t lchan_nr);
1341uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
1342uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
1343 enum gsm_phys_chan_config as_pchan);
1344
Harald Welte251bec12018-09-09 17:14:09 +02001345void gsm48_lchan2chan_desc(struct gsm48_chan_desc *cd,
1346 const struct gsm_lchan *lchan);
Harald Welte24286f32018-09-09 17:17:44 +02001347void gsm48_lchan2chan_desc_as_configured(struct gsm48_chan_desc *cd, const struct gsm_lchan *lchan);
Harald Welte251bec12018-09-09 17:14:09 +02001348
Neels Hofmeyr10485162018-02-13 23:22:03 +01001349/* return the gsm_lchan for the CBCH (if it exists at all) */
1350struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
1351
1352/*
1353 * help with parsing regexps
1354 */
1355int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
1356 int argc, const char **argv) __attribute__ ((warn_unused_result));
1357
1358static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
1359{
1360 if (ts->tsc != -1)
1361 return ts->tsc;
1362 else
1363 return ts->trx->bts->bsic & 7;
1364}
1365
1366struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
1367 int *rc);
1368
1369enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001370uint8_t pchan_subslots(enum gsm_phys_chan_config pchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001371bool ts_is_tch(struct gsm_bts_trx_ts *ts);
1372
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01001373
Harald Welteb7948872017-12-18 18:48:21 +01001374static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection *conn) {
1375 OSMO_ASSERT(conn->lchan);
1376 return conn->lchan->ts->trx->bts;
1377}
1378
Harald Welted82101e2017-12-09 23:07:38 +01001379enum {
1380 BTS_CTR_CHREQ_TOTAL,
1381 BTS_CTR_CHREQ_NO_CHANNEL,
1382 BTS_CTR_CHAN_RF_FAIL,
1383 BTS_CTR_CHAN_RLL_ERR,
1384 BTS_CTR_BTS_OML_FAIL,
1385 BTS_CTR_BTS_RSL_FAIL,
1386 BTS_CTR_CODEC_AMR_F,
1387 BTS_CTR_CODEC_AMR_H,
1388 BTS_CTR_CODEC_EFR,
1389 BTS_CTR_CODEC_V1_FR,
1390 BTS_CTR_CODEC_V1_HR,
Harald Weltecf9d4312017-12-13 23:17:16 +01001391 BTS_CTR_PAGING_ATTEMPTED,
1392 BTS_CTR_PAGING_ALREADY,
1393 BTS_CTR_PAGING_RESPONDED,
1394 BTS_CTR_PAGING_EXPIRED,
Harald Welte4f598922017-12-14 13:47:02 +01001395 BTS_CTR_CHAN_ACT_TOTAL,
1396 BTS_CTR_CHAN_ACT_NACK,
Harald Welte62d9cb02017-12-14 14:00:26 +01001397 BTS_CTR_RSL_UNKNOWN,
Harald Welte581398a2017-12-14 14:29:44 +01001398 BTS_CTR_RSL_IPA_NACK,
Harald Welte00d64fd2017-12-14 14:34:16 +01001399 BTS_CTR_MODE_MODIFY_NACK,
Harald Welted82101e2017-12-09 23:07:38 +01001400};
1401
1402static const struct rate_ctr_desc bts_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001403 [BTS_CTR_CHREQ_TOTAL] = {"chreq:total", "Received channel requests."},
1404 [BTS_CTR_CHREQ_NO_CHANNEL] = {"chreq:no_channel", "Sent to MS no channel available."},
1405 [BTS_CTR_CHAN_RF_FAIL] = {"chan:rf_fail", "Received a RF failure indication from BTS."},
1406 [BTS_CTR_CHAN_RLL_ERR] = {"chan:rll_err", "Received a RLL failure with T200 cause from BTS."},
Harald Welted82101e2017-12-09 23:07:38 +01001407 [BTS_CTR_BTS_OML_FAIL] = {"oml_fail", "Received a TEI down on a OML link."},
1408 [BTS_CTR_BTS_RSL_FAIL] = {"rsl_fail", "Received a TEI down on a OML link."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001409 [BTS_CTR_CODEC_AMR_F] = {"codec:amr_f", "Count the usage of AMR/F codec by channel mode requested."},
1410 [BTS_CTR_CODEC_AMR_H] = {"codec:amr_h", "Count the usage of AMR/H codec by channel mode requested."},
1411 [BTS_CTR_CODEC_EFR] = {"codec:efr", "Count the usage of EFR codec by channel mode requested."},
1412 [BTS_CTR_CODEC_V1_FR] = {"codec:fr", "Count the usage of FR codec by channel mode requested."},
1413 [BTS_CTR_CODEC_V1_HR] = {"codec:hr", "Count the usage of HR codec by channel mode requested."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001414
1415 [BTS_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
1416 [BTS_CTR_PAGING_ALREADY] = {"paging:already", "Paging attempts ignored as subsciber was already being paged."},
1417 [BTS_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful paging response."},
1418 [BTS_CTR_PAGING_EXPIRED] = {"paging:expired", "Paging Request expired because of timeout T3113."},
Harald Welte4f598922017-12-14 13:47:02 +01001419 [BTS_CTR_CHAN_ACT_TOTAL] = {"chan_act:total", "Total number of Channel Activations."},
1420 [BTS_CTR_CHAN_ACT_NACK] = {"chan_act:nack", "Number of Channel Activations that the BTS NACKed"},
Harald Welte62d9cb02017-12-14 14:00:26 +01001421 [BTS_CTR_RSL_UNKNOWN] = {"rsl:unknown", "Number of unknown/unsupported RSL messages received from BTS"},
Harald Welte581398a2017-12-14 14:29:44 +01001422 [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 +01001423 [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 +01001424};
1425
1426static const struct rate_ctr_group_desc bts_ctrg_desc = {
1427 "bts",
1428 "base transceiver station",
1429 OSMO_STATS_CLASS_GLOBAL,
1430 ARRAY_SIZE(bts_ctr_description),
1431 bts_ctr_description,
1432};
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001433
Alexander Couzens20423ea2016-07-12 15:42:02 +02001434enum {
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001435 BTS_STAT_CHAN_LOAD_AVERAGE,
1436 BTS_STAT_T3122,
Harald Weltebe86caa2019-05-24 09:30:28 +02001437 BTS_STAT_RACH_BUSY,
1438 BTS_STAT_RACH_ACCESS,
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001439};
1440
1441enum {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001442 BSC_CTR_ASSIGNMENT_ATTEMPTED,
1443 BSC_CTR_ASSIGNMENT_COMPLETED,
1444 BSC_CTR_ASSIGNMENT_STOPPED,
1445 BSC_CTR_ASSIGNMENT_NO_CHANNEL,
1446 BSC_CTR_ASSIGNMENT_TIMEOUT,
1447 BSC_CTR_ASSIGNMENT_FAILED,
1448 BSC_CTR_ASSIGNMENT_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001449 BSC_CTR_HANDOVER_ATTEMPTED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001450 BSC_CTR_HANDOVER_COMPLETED,
1451 BSC_CTR_HANDOVER_STOPPED,
Alexander Couzensb847a212016-08-02 11:34:11 +02001452 BSC_CTR_HANDOVER_NO_CHANNEL,
1453 BSC_CTR_HANDOVER_TIMEOUT,
Alexander Couzensb847a212016-08-02 11:34:11 +02001454 BSC_CTR_HANDOVER_FAILED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001455 BSC_CTR_HANDOVER_ERROR,
1456 BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED,
1457 BSC_CTR_INTER_BSC_HO_OUT_COMPLETED,
1458 BSC_CTR_INTER_BSC_HO_OUT_STOPPED,
1459 BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT,
1460 BSC_CTR_INTER_BSC_HO_OUT_ERROR,
1461 BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED,
1462 BSC_CTR_INTER_BSC_HO_IN_COMPLETED,
1463 BSC_CTR_INTER_BSC_HO_IN_STOPPED,
1464 BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL,
1465 BSC_CTR_INTER_BSC_HO_IN_FAILED,
1466 BSC_CTR_INTER_BSC_HO_IN_TIMEOUT,
1467 BSC_CTR_INTER_BSC_HO_IN_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001468 BSC_CTR_PAGING_ATTEMPTED,
1469 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +01001470 BSC_CTR_PAGING_RESPONDED,
Stefan Sperling7926d982018-05-17 14:52:02 +02001471 BSC_CTR_UNKNOWN_UNIT_ID,
Alexander Couzensb847a212016-08-02 11:34:11 +02001472};
1473
1474static const struct rate_ctr_desc bsc_ctr_description[] = {
Neels Hofmeyrdbb38d52018-07-11 19:53:56 +02001475 [BSC_CTR_ASSIGNMENT_ATTEMPTED] = {"assignment:attempted", "Assignment attempts."},
1476 [BSC_CTR_ASSIGNMENT_COMPLETED] = {"assignment:completed", "Assignment completed."},
1477 [BSC_CTR_ASSIGNMENT_STOPPED] = {"assignment:stopped", "Connection ended during Assignment."},
1478 [BSC_CTR_ASSIGNMENT_NO_CHANNEL] = {"assignment:no_channel", "Failure to allocate lchan for Assignment."},
1479 [BSC_CTR_ASSIGNMENT_TIMEOUT] = {"assignment:timeout", "Assignment timed out."},
1480 [BSC_CTR_ASSIGNMENT_FAILED] = {"assignment:failed", "Received Assignment Failure message."},
1481 [BSC_CTR_ASSIGNMENT_ERROR] = {"assignment:error", "Assigment failed for other reason."},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001482
1483 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Intra-BSC handover attempts."},
1484 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Intra-BSC handover completed."},
1485 [BSC_CTR_HANDOVER_STOPPED] = {"handover:stopped", "Connection ended during HO."},
1486 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Failure to allocate lchan for HO."},
1487 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Handover timed out."},
1488 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Received Handover Fail messages."},
1489 [BSC_CTR_HANDOVER_ERROR] = {"handover:error", "Re-assigment failed for other reason."},
1490
1491 [BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED] = {"interbsc_ho_out:attempted",
1492 "Attempts to handover to remote BSS."},
1493 [BSC_CTR_INTER_BSC_HO_OUT_COMPLETED] = {"interbsc_ho_out:completed",
1494 "Handover to remote BSS completed."},
1495 [BSC_CTR_INTER_BSC_HO_OUT_STOPPED] = {"interbsc_ho_out:stopped", "Connection ended during HO."},
1496 [BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT] = {"interbsc_ho_out:timeout", "Handover timed out."},
1497 [BSC_CTR_INTER_BSC_HO_OUT_ERROR] = {"interbsc_ho_out:error",
1498 "Handover to remote BSS failed for other reason."},
1499
1500 [BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED] = {"interbsc_ho_in:attempted",
1501 "Attempts to handover from remote BSS."},
1502 [BSC_CTR_INTER_BSC_HO_IN_COMPLETED] = {"interbsc_ho_in:completed",
1503 "Handover from remote BSS completed."},
1504 [BSC_CTR_INTER_BSC_HO_IN_STOPPED] = {"interbsc_ho_in:stopped", "Connection ended during HO."},
1505 [BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL] = {"interbsc_ho_in:no_channel",
1506 "Failure to allocate lchan for HO."},
1507 [BSC_CTR_INTER_BSC_HO_IN_TIMEOUT] = {"interbsc_ho_in:timeout", "Handover from remote BSS timed out."},
1508 [BSC_CTR_INTER_BSC_HO_IN_FAILED] = {"interbsc_ho_in:failed", "Received Handover Fail message."},
1509 [BSC_CTR_INTER_BSC_HO_IN_ERROR] = {"interbsc_ho_in:error",
1510 "Handover from remote BSS failed for other reason."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001511
1512 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001513 [BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Paging request send failures because no responsible BTS was found."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001514 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response."},
Stefan Sperling7926d982018-05-17 14:52:02 +02001515
1516 [BSC_CTR_UNKNOWN_UNIT_ID] = {"abis:unknown_unit_id", "Connection attempts from unknown IPA CCM Unit ID."},
Alexander Couzensb847a212016-08-02 11:34:11 +02001517};
1518
Alexander Couzensb847a212016-08-02 11:34:11 +02001519
1520
1521static const struct rate_ctr_group_desc bsc_ctrg_desc = {
1522 "bsc",
1523 "base station controller",
1524 OSMO_STATS_CLASS_GLOBAL,
1525 ARRAY_SIZE(bsc_ctr_description),
1526 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +02001527};
1528
Neels Hofmeyr73983952016-05-10 13:29:33 +02001529struct gsm_tz {
1530 int override; /* if 0, use system's time zone instead. */
1531 int hr; /* hour */
1532 int mn; /* minute */
1533 int dst; /* daylight savings */
1534};
1535
Harald Welte52b1f982008-12-23 20:25:15 +00001536struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001537 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
1538 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
1539 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
1540 * these have in common, like country and network code, put in yet
1541 * separate structs and placed as members in osmo_bsc and osmo_msc. */
1542
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001543 struct osmo_plmn_id plmn;
1544
Harald Welte51e4bf32017-12-23 17:30:18 +01001545 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
1546 uint8_t a5_encryption_mask;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001547 int neci;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001548
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001549 struct handover_cfg *ho;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001550 struct {
1551 unsigned int congestion_check_interval_s;
1552 struct osmo_timer_list congestion_check_timer;
1553 } hodec2;
Harald Welte52b1f982008-12-23 20:25:15 +00001554
Alexander Couzensb847a212016-08-02 11:34:11 +02001555 struct rate_ctr_group *bsc_ctrs;
Harald Welte24ff6ee2009-12-22 00:41:05 +01001556
Harald Welte52b1f982008-12-23 20:25:15 +00001557 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +02001558 struct llist_head bts_list;
Oliver Smith8d8d7102018-10-23 15:35:43 +02001559 struct llist_head bts_rejected;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001560
Neels Hofmeyr08822a32019-07-11 03:43:34 +02001561 /* see gsm_network_T_defs */
Neels Hofmeyra6078fe2019-01-28 03:52:14 +01001562 struct osmo_tdef *T_defs;
Harald Welteeab84a12009-12-13 10:53:12 +01001563
Alexander Couzens547c2072017-11-21 12:03:04 +01001564 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +08001565
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +08001566 /* Use a TCH for handling requests of type paging any */
1567 int pag_any_tch;
1568
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08001569 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +02001570 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +01001571
Daniel Willmann6fc4a982011-07-22 17:55:42 +02001572 /* control interface */
1573 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +02001574
1575 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
1576 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +02001577
1578 /* all active subscriber connections. */
1579 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +02001580
1581 /* if override is nonzero, this timezone data is used for all MM
1582 * contexts. */
1583 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
1584 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +01001585 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +02001586 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +01001587
1588 /* List of all struct bsc_subscr used in libbsc. This llist_head is
1589 * allocated so that the llist_head pointer itself can serve as a
1590 * talloc context (useful to not have to pass the entire gsm_network
1591 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
1592 * not require gsm_data.h). In an MSC-without-BSC environment, this
1593 * pointer is NULL to indicate absence of a bsc_subscribers list. */
1594 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +02001595
Stefan Sperling6cee8932018-01-30 18:14:22 +01001596 /* Timer for periodic channel load measurements to maintain each BTS's T3122. */
1597 struct osmo_timer_list t3122_chan_load_timer;
1598
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001599 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +02001600 struct mgcp_client_conf *conf;
1601 struct mgcp_client *client;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +02001602 struct osmo_tdef *tdefs;
Philipp Maier39c609b2017-09-27 15:51:34 +02001603 } mgw;
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001604
1605 /* Remote BSS Cell Identifier Lists */
1606 struct neighbor_ident_list *neighbor_bss_cells;
Harald Welte7e310b12009-03-30 20:56:32 +00001607};
1608
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001609struct gsm_audio_support {
1610 uint8_t hr : 1,
1611 ver : 7;
1612};
1613
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001614static inline const struct osmo_location_area_id *bts_lai(struct gsm_bts *bts)
1615{
1616 static struct osmo_location_area_id lai;
1617 lai = (struct osmo_location_area_id){
1618 .plmn = bts->network->plmn,
1619 .lac = bts->location_area_code,
1620 };
1621 return &lai;
1622}
1623
Neels Hofmeyrc13e6872016-05-11 13:53:47 +02001624extern void talloc_ctx_init(void *ctx_root);
1625
Harald Welte39315c42010-01-10 18:01:52 +01001626int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +02001627
Harald Welte1d014a52009-08-08 15:38:29 +02001628enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +02001629const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +00001630struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
1631 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +00001632
Andreas Eversberg8226fa72009-06-29 15:19:38 +02001633extern void *tall_bsc_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +02001634
Harald Weltef383aa12012-07-02 19:51:55 +02001635/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +00001636static inline int is_ipaccess_bts(struct gsm_bts *bts)
1637{
1638 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001639 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001640 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +00001641 return 1;
1642 default:
1643 break;
1644 }
1645 return 0;
1646}
1647
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001648static inline int is_sysmobts_v2(struct gsm_bts *bts)
1649{
1650 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +01001651 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001652 return 1;
1653 default:
1654 break;
1655 }
1656 return 0;
1657}
1658
Harald Welte5b570672009-08-10 10:08:01 +02001659static inline int is_siemens_bts(struct gsm_bts *bts)
1660{
1661 switch (bts->type) {
1662 case GSM_BTS_TYPE_BS11:
1663 return 1;
1664 default:
1665 break;
1666 }
1667
1668 return 0;
1669}
1670
Andreas Eversberg7d8fa342013-12-05 13:25:06 +01001671static inline int is_nokia_bts(struct gsm_bts *bts)
1672{
1673 switch (bts->type) {
1674 case GSM_BTS_TYPE_NOKIA_SITE:
1675 return 1;
1676 default:
1677 break;
1678 }
1679
1680 return 0;
1681}
1682
Andreas Eversbergdcf38e12013-12-05 14:37:11 +01001683static inline int is_e1_bts(struct gsm_bts *bts)
1684{
1685 switch (bts->type) {
1686 case GSM_BTS_TYPE_BS11:
1687 case GSM_BTS_TYPE_RBS2000:
1688 case GSM_BTS_TYPE_NOKIA_SITE:
1689 return 1;
1690 default:
1691 break;
1692 }
1693
1694 return 0;
1695}
1696
Harald Welte1876c312018-05-27 11:53:43 +02001697extern struct gsm_network *bsc_gsmnet;
1698
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001699enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +02001700const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001701int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +02001702
Neels Hofmeyr4d358c02018-02-22 03:19:05 +01001703void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +08001704void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +01001705
Harald Weltefbda4e12010-03-04 11:04:52 +01001706int gsm_bts_model_register(struct gsm_bts_model *model);
1707
Harald Welte3561bd42018-01-28 03:04:16 +01001708struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *network);
Neels Hofmeyr42eb0142016-05-20 17:15:44 +02001709
1710struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
1711void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +08001712
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001713struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, uint8_t bsic);
1714struct 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 +01001715
Harald Welte3300c012011-06-05 13:31:33 +02001716void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
1717 uint8_t e1_ts, uint8_t e1_ts_ss);
1718
Maxbe356ed2017-09-07 19:10:09 +02001719void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Harald Welte3300c012011-06-05 13:31:33 +02001720struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +01001721int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -04001722int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +02001723
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +02001724/* generic E1 line operations for all ISDN-based BTS. */
1725extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
1726
Harald Weltee555c2b2012-08-17 13:02:12 +02001727extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
1728extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
1729
Max3d049d22017-10-09 17:12:53 +02001730char *get_model_oml_status(const struct gsm_bts *bts);
1731
Max25cc4072017-10-10 14:50:35 +02001732unsigned long long bts_uptime(const struct gsm_bts *bts);
1733
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +01001734/* control interface handling */
1735int bsc_base_ctrl_cmds_install(void);
1736
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001737/* dependency handling */
1738void bts_depend_mark(struct gsm_bts *bts, int dep);
1739void bts_depend_clear(struct gsm_bts *bts, int dep);
1740int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +01001741int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001742
Harald Welte2f8b9d22017-06-18 11:12:13 +03001743int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
1744void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
1745
Harald Weltea43e0b42016-06-19 18:06:02 +02001746bool classmark_is_r99(struct gsm_classmark *cm);
1747
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001748bool trx_is_usable(const struct gsm_bts_trx *trx);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001749bool ts_is_usable(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001750
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001751int gsm_lchan_type_by_pchan(enum gsm_phys_chan_config pchan);
1752enum gsm_phys_chan_config gsm_pchan_by_lchan_type(enum gsm_chan_t type);
1753
1754void gsm_bts_all_ts_dispatch(struct gsm_bts *bts, uint32_t ts_ev, void *data);
1755void gsm_trx_all_ts_dispatch(struct gsm_bts_trx *trx, uint32_t ts_ev, void *data);
1756
1757int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001758
Harald Welte6be350c2011-05-25 13:10:08 +02001759#endif /* _GSM_DATA_H */