blob: a5b5a50f7218a6adfdc7d3516cf48c7321c4e5a2 [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001#ifndef _GSM_DATA_H
2#define _GSM_DATA_H
3
Harald Weltef142c972011-05-24 13:25:38 +02004#include <stdint.h>
Maxddee01f2016-05-24 14:23:27 +02005#include <sys/types.h>
Maxe6052c42016-06-30 10:25:49 +02006#include <stdbool.h>
Harald Weltef142c972011-05-24 13:25:38 +02007
8#include <osmocom/core/timer.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +02009#include <osmocom/core/rate_ctr.h>
Harald Welte6be350c2011-05-25 13:10:08 +020010#include <osmocom/core/select.h>
Alexander Couzens2f9df962020-09-21 18:35:24 +020011#include <osmocom/core/socket.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020012#include <osmocom/core/stats.h>
Stefan Sperling81dc9e72018-02-05 17:34:36 +010013#include <osmocom/core/stat_item.h>
Philipp Maier8c498fc2018-02-21 13:24:36 +010014#include <osmocom/gsm/bts_features.h>
Neels Hofmeyra60f3442018-02-12 16:44:32 +010015#include <osmocom/gsm/protocol/gsm_08_08.h>
Harald Welted41b7c72019-06-13 09:41:58 +020016#include <osmocom/gsm/protocol/gsm_48_049.h>
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020017#include <osmocom/gsm/gsm0808.h>
Neels Hofmeyrf93970b2018-03-05 02:09:40 +010018#include <osmocom/gsm/gsm48.h>
Harald Welte3561bd42018-01-28 03:04:16 +010019#include <osmocom/core/fsm.h>
Neels Hofmeyra6078fe2019-01-28 03:52:14 +010020#include <osmocom/core/tdef.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020021
Harald Welte121e9a42016-04-20 13:13:19 +020022#include <osmocom/crypt/auth.h>
Harald Weltef142c972011-05-24 13:25:38 +020023
Neels Hofmeyrc0164792017-09-04 15:15:32 +020024#include <osmocom/bsc/rest_octets.h>
Harald Welteb96be392011-05-25 12:33:33 +020025
Neels Hofmeyr10485162018-02-13 23:22:03 +010026#include <osmocom/core/bitvec.h>
27#include <osmocom/gsm/gsm_utils.h>
28#include <osmocom/gsm/rxlev_stat.h>
29#include <osmocom/gsm/protocol/gsm_08_58.h>
30#include <osmocom/gsm/protocol/gsm_12_21.h>
31#include <osmocom/abis/e1_input.h>
32#include <osmocom/bsc/meas_rep.h>
Pau Espin Pedrol02f20562020-07-20 16:21:54 +020033#include <osmocom/bsc/acc.h>
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020034#include <osmocom/bsc/neighbor_ident.h>
Pau Espin Pedrol83c0f762019-04-16 20:05:32 +020035#include <osmocom/bsc/osmux.h>
Neels Hofmeyr10485162018-02-13 23:22:03 +010036
Neels Hofmeyr596c4022018-06-16 19:29:50 +020037#define GSM_T3122_DEFAULT 10
38
Harald Welte74b8cdb2018-01-15 19:26:06 +010039struct mgcp_client_conf;
40struct mgcp_client;
Neels Hofmeyr19bed232018-03-22 04:54:57 +010041struct gsm0808_cell_id;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +020042struct osmo_mgcpc_ep;
Pau Espin Pedrol388ed582020-07-15 20:53:16 +020043struct gsm_bts;
Pau Espin Pedrolaca53202020-07-16 14:49:36 +020044struct gsm_bts_trx;
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;
Neels Hofmeyra33ef3a2020-10-01 04:23:32 +020054struct osmo_sccp_instance;
Neels Hofmeyr4ae338d2020-09-17 17:54:39 +020055struct smlc_config;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020056
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080057#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
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
Pau Espin Pedrol657f3102020-08-28 18:35:22 +0200123 char msc_rtp_addr[INET6_ADDRSTRLEN];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200124 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;
Pau Espin Pedrol657f3102020-08-28 18:35:22 +0200198 char msc_assigned_rtp_addr[INET6_ADDRSTRLEN];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200199 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
Neels Hofmeyr149160f2018-06-16 17:20:13 +0200245 /* Queue DTAP messages during handover/assignment (msgb_enqueue()/msgb_dequeue())*/
246 struct llist_head dtap_queue;
247 unsigned int dtap_queue_len;
Andreas Eversberg084b4212013-05-30 14:12:48 +0200248
Neels Hofmeyrec422642018-02-15 14:07:40 +0100249 struct {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100250 int failures;
Neels Hofmeyrec422642018-02-15 14:07:40 +0100251 struct penalty_timers *penalty_timers;
252 } hodec2;
Neels Hofmeyra60f3442018-02-12 16:44:32 +0100253
254 /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment Request. 3GPP 48.008
255 * 3.2.2.103 says:
256 * The "Codec List (MSC Preferred)" shall not include codecs
257 * that are not supported by the MS.
258 * i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed the MS bearer
259 * capabilities, which the MSC is required to translate into the codec list. */
260 struct gsm0808_speech_codec_list codec_list;
Harald Welte519c7e12018-01-28 02:45:46 +0100261
262 /* flag to prevent multiple simultaneous ciphering commands */
263 int ciphering_handled;
264
Harald Welte519c7e12018-01-28 02:45:46 +0100265 /* SCCP connection associatd with this subscriber_connection */
266 struct {
Martin Haukea29affd2019-11-13 22:10:41 +0100267 /* SCCP connection related */
Harald Welte519c7e12018-01-28 02:45:46 +0100268 struct bsc_msc_data *msc;
269
270 /* Sigtran connection ID */
271 int conn_id;
272 enum subscr_sccp_state state;
273 } sccp;
274
275 /* for audio handling */
276 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200277 uint16_t msc_assigned_cic;
Harald Welte519c7e12018-01-28 02:45:46 +0100278
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200279 /* RTP address where the MSC expects us to send the RTP stream coming from the BTS. */
Pau Espin Pedrol657f3102020-08-28 18:35:22 +0200280 char msc_assigned_rtp_addr[INET6_ADDRSTRLEN];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200281 uint16_t msc_assigned_rtp_port;
Harald Welte519c7e12018-01-28 02:45:46 +0100282
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200283 /* The endpoint at the MGW used to join both BTS and MSC side connections, e.g.
284 * "rtpbridge/23@mgw". */
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200285 struct osmo_mgcpc_ep *mgw_endpoint;
Harald Welte3561bd42018-01-28 03:04:16 +0100286
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200287 /* The connection identifier of the osmo_mgcpc_ep used to transceive RTP towards the MSC.
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200288 * (The BTS side CI is handled by struct gsm_lchan and the lchan_fsm.) */
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200289 struct osmo_mgcpc_ep_ci *mgw_endpoint_ci_msc;
Harald Welte519c7e12018-01-28 02:45:46 +0100290 } user_plane;
Harald Weltec997ceb2018-05-30 01:39:43 +0200291
292 /* LCLS (local call, local switch) related state */
293 struct {
294 uint8_t global_call_ref[15];
295 uint8_t global_call_ref_len; /* length of global_call_ref */
Maxfe65ece2018-11-09 13:36:11 +0100296 enum gsm0808_lcls_config config; /* TS 48.008 3.2.2.116 */
297 enum gsm0808_lcls_control control; /* TS 48.008 3.2.2.117 */
Harald Weltec997ceb2018-05-30 01:39:43 +0200298 /* LCLS FSM */
299 struct osmo_fsm_inst *fi;
300 /* pointer to "other" connection, if Call Leg Relocation was successful */
301 struct gsm_subscriber_connection *other;
302 } lcls;
Pau Espin Pedrol7950e5d2019-10-31 15:59:49 +0100303
304 /* MS Power Class, TS 05.05 sec 4.1.1 "Mobile station". 0 means unset. */
305 uint8_t ms_power_class:3;
Neels Hofmeyr90f7c3c2020-08-29 23:01:44 +0000306
307 bool rx_clear_command;
Neels Hofmeyr4ae338d2020-09-17 17:54:39 +0200308
309 /* Location Services handling for this subscriber */
310 struct {
311 /* FSM to handle Perform Location Request coming in from the MSC via A interface,
312 * and receive BSSMAP-LE responses from the SMLC. */
313 struct lcs_loc_req *loc_req;
314
315 /* FSM to handle BSSLAP requests coming in from the SMLC via Lb interface.
316 * BSSLAP APDU are encapsulated in BSSMAP-LE Connection Oriented Information messages. */
317 struct lcs_bsslap *bsslap;
318
319 /* Lb interface to the SMLC: BSSMAP-LE/SCCP connection associated with this subscriber */
320 struct {
321 int conn_id;
322 enum subscr_sccp_state state;
323 } lb;
324 } lcs;
Philipp Maier0eb479e2020-11-06 23:19:45 +0100325
326 struct gsm48_classmark3 cm3;
327 bool cm3_valid;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100328};
329
Harald Weltef142c972011-05-24 13:25:38 +0200330
Neels Hofmeyr10485162018-02-13 23:22:03 +0100331/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 Table 10.5.2.33b.1:
332 4-bit index is used (2#1111 = 10#15) */
333#define SI2Q_MAX_NUM 16
334/* length in bits (for single SI2quater message) */
335#define SI2Q_MAX_LEN 160
336#define SI2Q_MIN_LEN 18
337
338struct osmo_bsc_data;
339
340struct osmo_bsc_sccp_con;
341
342/* Channel Request reason */
343enum gsm_chreq_reason_t {
344 GSM_CHREQ_REASON_EMERG,
345 GSM_CHREQ_REASON_PAG,
346 GSM_CHREQ_REASON_CALL,
347 GSM_CHREQ_REASON_LOCATION_UPD,
348 GSM_CHREQ_REASON_OTHER,
349 GSM_CHREQ_REASON_PDCH,
350};
351
352/* lchans 0..3 are SDCCH in combined channel configuration,
353 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
354#define CCCH_LCHAN 4
355
Neels Hofmeyr10485162018-02-13 23:22:03 +0100356#define TS_MAX_LCHAN 8
357
358#define HARDCODED_ARFCN 123
359#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
360
361/* for multi-drop config */
362#define HARDCODED_BTS0_TS 1
363#define HARDCODED_BTS1_TS 6
364#define HARDCODED_BTS2_TS 11
365
366#define MAX_VERSION_LENGTH 64
367
Neels Hofmeyr10485162018-02-13 23:22:03 +0100368enum gsm_hooks {
369 GSM_HOOK_NM_SWLOAD,
370 GSM_HOOK_RR_PAGING,
371 GSM_HOOK_RR_SECURITY,
372};
373
Neels Hofmeyr10485162018-02-13 23:22:03 +0100374enum bts_gprs_mode {
375 BTS_GPRS_NONE = 0,
376 BTS_GPRS_GPRS = 1,
377 BTS_GPRS_EGPRS = 2,
378};
379
380struct gsm_lchan;
381struct osmo_rtp_socket;
382struct rtp_socket;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100383
384/* Network Management State */
385struct gsm_nm_state {
386 uint8_t operational;
387 uint8_t administrative;
388 uint8_t availability;
389};
390
391struct gsm_abis_mo {
392 uint8_t obj_class;
393 uint8_t procedure_pending;
394 struct abis_om_obj_inst obj_inst;
395 const char *name;
396 struct gsm_nm_state nm_state;
397 struct tlv_parsed *nm_attr;
398 struct gsm_bts *bts;
Pau Espin Pedrol4338de52020-09-30 12:52:04 +0200399 struct osmo_fsm_inst *fi;
400 bool opstart_sent;
Pau Espin Pedrol6adeb602020-09-30 12:52:53 +0200401 bool adm_unlock_sent;
402 bool set_attr_sent;
403 bool set_attr_ack_received;
Pau Espin Pedrold9d105c2020-09-30 14:43:09 +0200404 bool force_rf_lock;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100405};
406
407/* Ericsson OM2000 Managed Object */
408struct abis_om2k_mo {
409 uint8_t class;
410 uint8_t bts;
411 uint8_t assoc_so;
412 uint8_t inst;
413} __attribute__ ((packed));
414
415struct om2k_mo {
416 struct abis_om2k_mo addr;
417 struct osmo_fsm_inst *fsm;
418};
419
420#define A38_XOR_MIN_KEY_LEN 12
421#define A38_XOR_MAX_KEY_LEN 16
422#define A38_COMP128_KEY_LEN 16
423#define RSL_ENC_ALG_A5(x) (x+1)
Neels Hofmeyr19ec3742020-07-08 02:58:52 +0200424/* Up to 16 SI2quater are multiplexed; each fits 3 EARFCNS, so the practical maximum is 3*16.
425 * The real maximum that fits in a total of 16 SI2quater rest octets also depends on the bits left by other SI2quater
426 * rest octets elements, so to really fit 48 EARFCNs most other SI2quater elements need to be omitted. */
427#define MAX_EARFCN_LIST (3*16)
Neels Hofmeyr10485162018-02-13 23:22:03 +0100428
429/* is the data link established? who established it? */
430#define LCHAN_SAPI_UNUSED 0
431#define LCHAN_SAPI_MS 1
432#define LCHAN_SAPI_NET 2
Neels Hofmeyr10485162018-02-13 23:22:03 +0100433
434/* BTS ONLY */
435#define MAX_NUM_UL_MEAS 104
436#define LC_UL_M_F_L1_VALID (1 << 0)
437#define LC_UL_M_F_RES_VALID (1 << 1)
438
439struct bts_ul_meas {
440 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
441 uint16_t ber10k;
442 /* timing advance offset (in quarter bits) */
443 int16_t ta_offs_qbits;
444 /* C/I ratio in dB */
445 float c_i;
446 /* flags */
447 uint8_t is_sub:1;
448 /* RSSI in dBm * -1 */
449 uint8_t inv_rssi;
450};
451
452struct bts_codec_conf {
453 uint8_t hr;
454 uint8_t efr;
455 uint8_t amr;
456};
457
458struct amr_mode {
459 uint8_t mode;
460 uint8_t threshold;
461 uint8_t hysteresis;
462};
463
464struct amr_multirate_conf {
465 uint8_t gsm48_ie[2];
466 struct amr_mode ms_mode[4];
467 struct amr_mode bts_mode[4];
468 uint8_t num_modes;
469};
470/* /BTS ONLY */
471
472enum lchan_csd_mode {
473 LCHAN_CSD_M_NT,
474 LCHAN_CSD_M_T_1200_75,
475 LCHAN_CSD_M_T_600,
476 LCHAN_CSD_M_T_1200,
477 LCHAN_CSD_M_T_2400,
478 LCHAN_CSD_M_T_9600,
479 LCHAN_CSD_M_T_14400,
480 LCHAN_CSD_M_T_29000,
481 LCHAN_CSD_M_T_32000,
482};
483
484/* State of the SAPIs in the lchan */
485enum lchan_sapi_state {
486 LCHAN_SAPI_S_NONE,
487 LCHAN_SAPI_S_REQ,
488 LCHAN_SAPI_S_ASSIGNED,
489 LCHAN_SAPI_S_REL,
490 LCHAN_SAPI_S_ERROR,
491};
492
Neels Hofmeyr92b9f2e2018-02-14 00:19:11 +0100493#define MAX_A5_KEY_LEN (128/8)
494
495struct gsm_encr {
496 uint8_t alg_id;
497 uint8_t key_len;
498 uint8_t key[MAX_A5_KEY_LEN];
499};
500
Neels Hofmeyr8da22332018-04-11 01:43:41 +0200501#define LOGPLCHAN(lchan, ss, level, fmt, args...) \
502 LOGP(ss, level, "%s (ss=%d,%s) (%s) " fmt, \
503 lchan ? gsm_ts_and_pchan_name(lchan->ts) : "-", \
504 lchan ? lchan->nr : 0, \
505 lchan ? gsm_lchant_name(lchan->type) : "-", \
506 bsc_subscr_name(lchan && lchan->conn ? lchan->conn->bsub : NULL), \
507 ## args)
508
Pau Espin Pedrold3e8e0c2018-11-28 16:35:10 +0100509/* Iterate lchans that have an FSM allocated based based on explicit pchan kind
510 * (GSM_PCHAN_* constant).
511 * Remark: PDCH related lchans are not handled in BSC but in PCU, so trying to
512 * iterate through GSM_PCHAN_PDCH is considered a void loop.
513 */
514#define ts_as_pchan_for_each_lchan(lchan, ts, as_pchan) \
515 for (lchan = (ts)->lchan; \
516 ((lchan - (ts)->lchan) < ARRAY_SIZE((ts)->lchan)) \
517 && lchan->fi \
518 && lchan->nr < pchan_subslots(as_pchan); \
519 lchan++)
520
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100521/* Iterate lchans that have an FSM allocated based on current PCHAN
522 * mode set in \ref ts.
523 * usage:
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200524 * struct gsm_lchan *lchan;
525 * struct gsm_bts_trx_ts *ts = get_some_timeslot();
526 * ts_for_each_lchan(lchan, ts) {
527 * LOGPLCHAN(DMAIN, LOGL_DEBUG, "hello world\n");
528 * }
Pau Espin Pedrol7ae0f9c2018-11-28 16:37:37 +0100529 */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200530#define ts_for_each_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_is)
531
Pau Espin Pedrol0ba20df2018-11-28 16:39:29 +0100532/* Iterate over all possible lchans available that have an FSM allocated based
533 * on PCHAN \ref ts (dynamic) configuration.
534 * Iterate all lchan instances set up by this \ref ts type, including those
535 * lchans currently disabled or in process of being enabled (e.g. due to dynamic
536 * timeslot in switchover). Compare ts_for_each_lchan(), which iterates only the
537 * enabled lchans.
538 * For example, it is useful in case dynamic timeslot \ref ts is in process of
539 * switching from configuration PDCH (no lchans) to TCH_F (1 lchan), where
540 * pchan_is is still set to PDCH but \ref ts may contain already an \ref lchan
541 * of type TCH_F which initiated the request to switch the \ts configuration.
542 */
543#define ts_for_each_potential_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_on_init)
544
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200545enum lchan_activate_mode {
546 FOR_NONE,
547 FOR_MS_CHANNEL_REQUEST,
548 FOR_ASSIGNMENT,
549 FOR_HANDOVER,
550 FOR_VTY,
551};
552
553extern const struct value_string lchan_activate_mode_names[];
554static inline const char *lchan_activate_mode_name(enum lchan_activate_mode activ_for)
555{ return get_value_string(lchan_activate_mode_names, activ_for); }
556
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100557struct lchan_activate_info {
558 enum lchan_activate_mode activ_for;
559 struct gsm_subscriber_connection *for_conn;
560 /* This always is for a specific lchan, so its lchan->type indicates full or half rate.
561 * When a dyn TS was selected, the lchan->type has been set to the desired rate. */
562 enum gsm48_chan_mode chan_mode;
Neels Hofmeyr58cf1b12019-03-15 02:49:18 +0100563 struct gsm_encr encr;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100564 /* AMR config */
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100565 uint16_t s15_s0;
566 bool requires_voice_stream;
567 bool wait_before_switching_rtp; /*< true = requires LCHAN_EV_READY_TO_SWITCH_RTP */
568 uint16_t msc_assigned_cic;
Neels Hofmeyr38134ea2018-12-21 03:01:00 +0100569 /* During intra-BSC handover, we keep the MGW endpoint intact and just re-route to the new lchan. This
570 * 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 +0100571 struct gsm_lchan *re_use_mgw_endpoint_from_lchan;
572};
573
Neels Hofmeyr10485162018-02-13 23:22:03 +0100574struct gsm_lchan {
575 /* The TS that we're part of */
576 struct gsm_bts_trx_ts *ts;
577 /* The logical subslot number in the TS */
578 uint8_t nr;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200579 char *name;
580
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100581 char *last_error;
582
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200583 struct osmo_fsm_inst *fi;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200584 struct osmo_fsm_inst *fi_rtp;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200585 struct osmo_mgcpc_ep_ci *mgw_endpoint_ci_bts;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200586
587 struct {
Neels Hofmeyr700e5182018-12-19 17:19:02 +0100588 struct lchan_activate_info info;
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200589 bool activ_ack; /*< true as soon as RSL Chan Activ Ack is received */
Neels Hofmeyr369fba22018-11-27 01:30:50 +0100590 bool immediate_assignment_sent;
Neels Hofmeyr193c1e32018-08-27 22:06:24 +0200591 /*! This flag ensures that when an lchan activation has succeeded, and we have already
592 * sent ACKs like Immediate Assignment or BSSMAP Assignment Complete, and if other errors
593 * occur later, e.g. during release, that we don't send a NACK out of context. */
594 bool concluded;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200595 enum gsm0808_cause gsm0808_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200596 } activate;
597
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100598 struct {
599 /* If an event to release the lchan comes in while still waiting for responses, just mark this
600 * flag, so that the lchan will gracefully release at the next sensible junction. */
601 bool requested;
602 bool do_rr_release;
Neels Hofmeyrb523f542020-07-09 15:54:40 +0200603 enum gsm48_rr_cause rr_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200604
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100605 /* There is an RSL error cause of value 0, so we need a separate flag. */
606 bool in_error;
607 /* RSL error code, RSL_ERR_* */
608 uint8_t rsl_error_cause;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200609
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100610 /* If a release event is being handled, ignore other ricocheting release events until that
611 * release handling has concluded. */
612 bool in_release_handler;
Harald Welte963763d2019-02-03 12:11:12 +0100613
614 /* is this release at the end of a CSFB call? */
615 bool is_csfb;
Neels Hofmeyreee24eb2018-11-06 21:39:15 +0100616 } release;
Neels Hofmeyrd5df9a12018-07-20 05:35:47 +0200617
Neels Hofmeyr10485162018-02-13 23:22:03 +0100618 /* The logical channel type */
619 enum gsm_chan_t type;
620 /* RSL channel mode */
621 enum rsl_cmod_spd rsl_cmode;
622 /* If TCH, traffic channel mode */
623 enum gsm48_chan_mode tch_mode;
624 enum lchan_csd_mode csd_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100625 /* Power levels for MS and BTS */
626 uint8_t bs_power;
627 uint8_t ms_power;
628 /* Encryption information */
629 struct gsm_encr encr;
630
631 /* AMR bits */
632 uint8_t mr_ms_lv[7];
633 uint8_t mr_bts_lv[7];
Neels Hofmeyr4daa2102019-01-30 16:46:58 +0100634 /* AMR bits were based on these rate bits: */
635 uint16_t s15_s0;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100636
637 /* Established data link layer services */
638 uint8_t sapis[8];
639
640 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200641 uint32_t bound_ip; /*< where the BTS receives RTP */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100642 uint16_t bound_port;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200643 uint32_t connect_ip; /*< where the BTS sends RTP to (MGW) */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100644 uint16_t connect_port;
645 uint16_t conn_id;
646 uint8_t rtp_payload;
647 uint8_t rtp_payload2;
648 uint8_t speech_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100649
650 /* info we need to postpone the AoIP
651 * assignment completed message */
652 struct {
653 uint8_t rr_cause;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100654 bool valid;
655 } ass_compl;
656 } abis_ip;
657
658 uint8_t rqd_ta;
659
Neels Hofmeyr10485162018-02-13 23:22:03 +0100660 /* table of neighbor cell measurements */
661 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
662
663 /* cache of last measurement reports on this lchan */
664 struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
665 int meas_rep_idx;
666 int meas_rep_count;
Neels Hofmeyr35ba85c2018-02-12 16:47:40 +0100667 uint8_t meas_rep_last_seen_nr;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100668
669 /* GSM Random Access data */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200670 /* TODO: don't allocate this, rather keep an "is_present" flag */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100671 struct gsm48_req_ref *rqd_ref;
672
673 struct gsm_subscriber_connection *conn;
Philipp Maierbb66d102019-01-22 11:29:06 +0100674
675 /* Depending on the preferences that where submitted together with
676 * the assignment and the current channel load, the BSC has to select
677 * one of the offered codec/rates. The final selection by the BSC is
678 * stored here and is used when sending the assignment complete or
679 * when performing a handover procedure. */
680 struct channel_mode_and_rate ch_mode_rate;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100681};
682
Neels Hofmeyr10485162018-02-13 23:22:03 +0100683/* One Timeslot in a TRX */
684struct gsm_bts_trx_ts {
685 struct gsm_bts_trx *trx;
686 /* number of this timeslot at the TRX */
687 uint8_t nr;
688
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200689 struct osmo_fsm_inst *fi;
690 char *last_errmsg;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100691
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200692 /* vty phys_chan_config setting, not necessarily in effect in case it was changed in the telnet
693 * vty after OML activation. Gets written on vty 'write file'. */
694 enum gsm_phys_chan_config pchan_from_config;
695 /* When the timeslot OML is established, pchan_from_config is copied here. This is the pchan
696 * currently in effect; for dynamic ts, this is the dyn kind (GSM_PCHAN_TCH_F_TCH_H_PDCH or
697 * GSM_PCHAN_TCH_F_PDCH) and does not show the pchan type currently active. */
698 enum gsm_phys_chan_config pchan_on_init;
699 /* This is the *actual* pchan type currently active. For dynamic timeslots, this reflects either
700 * GSM_PCHAN_NONE or one of the standard GSM_PCHAN_TCH_F, GSM_PCHAN_TCH_H, GSM_PCHAN_PDCH.
701 * Callers can use this transparently without being aware of dyn ts. */
702 enum gsm_phys_chan_config pchan_is;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100703
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200704 /* After a PDCH ACT NACK, we shall not infinitely loop to try and ACT again.
705 * Also marks a timeslot where PDCH was deactivated by VTY. This is cleared whenever a timeslot
706 * enters IN_USE state, i.e. after each TCH use we try to PDCH ACT once again. */
707 bool pdch_act_allowed;
708
Neels Hofmeyrbcdbfb72018-07-26 20:33:15 +0200709 /* Whether TS_EV_OML_READY was received */
710 bool is_oml_ready;
711 /* Whether TS_EV_RSL_READY was received */
712 bool is_rsl_ready;
713
Neels Hofmeyr10485162018-02-13 23:22:03 +0100714 struct gsm_abis_mo mo;
715 struct tlv_parsed nm_attr;
716 uint8_t nm_chan_comb;
717 int tsc; /* -1 == use BTS TSC */
718
719 struct {
720 /* Parameters below are configured by VTY */
721 int enabled;
722 uint8_t maio;
723 uint8_t hsn;
724 struct bitvec arfcns;
725 uint8_t arfcns_data[1024/8];
726 /* This is the pre-computed MA for channel assignments */
727 struct bitvec ma;
728 uint8_t ma_len; /* part of ma_data that is used */
729 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
730 } hopping;
731
732 /* To which E1 subslot are we connected */
733 struct gsm_e1_subslot e1_link;
734
735 union {
736 struct {
737 struct om2k_mo om2k_mo;
738 } rbs2000;
739 };
740
741 struct gsm_lchan lchan[TS_MAX_LCHAN];
742};
743
Neels Hofmeyr10485162018-02-13 23:22:03 +0100744#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
745
Neels Hofmeyr10485162018-02-13 23:22:03 +0100746/*
747 * This keeps track of the paging status of one BTS. It
748 * includes a number of pending requests, a back pointer
749 * to the gsm_bts, a timer and some more state.
750 */
751struct gsm_bts_paging_state {
752 /* pending requests */
753 struct llist_head pending_requests;
754 struct gsm_bts *bts;
755
756 struct osmo_timer_list work_timer;
757 struct osmo_timer_list credit_timer;
758
759 /* free chans needed */
760 int free_chans_need;
761
762 /* load */
763 uint16_t available_slots;
764};
765
766struct gsm_envabtse {
767 struct gsm_abis_mo mo;
768};
769
770struct gsm_bts_gprs_nsvc {
771 struct gsm_bts *bts;
772 /* data read via VTY config file, to configure the BTS
773 * via OML from BSC */
774 int id;
775 uint16_t nsvci;
776 uint16_t local_port; /* on the BTS */
Alexander Couzens2f9df962020-09-21 18:35:24 +0200777 struct osmo_sockaddr remote;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100778 struct gsm_abis_mo mo;
779};
780
781enum gprs_rlc_par {
782 RLC_T3142,
783 RLC_T3169,
784 RLC_T3191,
785 RLC_T3193,
786 RLC_T3195,
787 RLC_N3101,
788 RLC_N3103,
789 RLC_N3105,
790 CV_COUNTDOWN,
791 T_DL_TBF_EXT, /* ms */
792 T_UL_TBF_EXT, /* ms */
793 _NUM_RLC_PAR
794};
795
796enum gprs_cs {
797 GPRS_CS1,
798 GPRS_CS2,
799 GPRS_CS3,
800 GPRS_CS4,
801 GPRS_MCS1,
802 GPRS_MCS2,
803 GPRS_MCS3,
804 GPRS_MCS4,
805 GPRS_MCS5,
806 GPRS_MCS6,
807 GPRS_MCS7,
808 GPRS_MCS8,
809 GPRS_MCS9,
810 _NUM_GRPS_CS
811};
812
813struct gprs_rlc_cfg {
814 uint16_t parameter[_NUM_RLC_PAR];
815 struct {
816 uint16_t repeat_time; /* ms */
817 uint8_t repeat_count;
818 } paging;
819 uint32_t cs_mask; /* bitmask of gprs_cs */
820 uint8_t initial_cs;
821 uint8_t initial_mcs;
822};
823
824
825enum neigh_list_manual_mode {
826 NL_MODE_AUTOMATIC = 0,
827 NL_MODE_MANUAL = 1,
828 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
829};
830
831enum bts_loc_fix {
832 BTS_LOC_FIX_INVALID = 0,
833 BTS_LOC_FIX_2D = 1,
834 BTS_LOC_FIX_3D = 2,
835};
836
837extern const struct value_string bts_loc_fix_names[];
838
839struct bts_location {
840 struct llist_head list;
841 time_t tstamp;
842 enum bts_loc_fix valid;
843 double lat;
844 double lon;
845 double height;
846};
847
848/* Channel load counter */
849struct load_counter {
850 unsigned int total;
851 unsigned int used;
852};
853
Neels Hofmeyr19bed232018-03-22 04:54:57 +0100854/* Useful to track N-N relations between BTS, for example neighbors. */
855struct gsm_bts_ref {
856 struct llist_head entry;
857 struct gsm_bts *bts;
858};
859
Harald Welted41b7c72019-06-13 09:41:58 +0200860/* A single Page of a SMSCB message */
861struct bts_smscb_page {
862 /* SMSCB message we're part of */
863 struct bts_smscb_message *msg;
864 /* Page Number within message (1 to 15) */
865 uint8_t nr;
866 /* number of valid blocks in data (up to 4) */
867 uint8_t num_blocks;
868 /* up to four blocks of 22 bytes each */
869 uint8_t data[88];
870};
871
872/* A SMSCB message (received from CBSP) */
873struct bts_smscb_message {
874 /* entry in bts_smscb_chan_state.messages */
875 struct llist_head list;
876 struct {
877 /* input data from CBSP (CBC) side */
878 uint16_t msg_id;
879 uint16_t serial_nr;
880 enum cbsp_category category;
881 uint16_t rep_period;
882 uint16_t num_bcast_req;
883 uint8_t dcs;
884 } input;
885 /* how often have all pages of this message been broadcast? */
886 uint32_t bcast_count;
887 /* actual page data of this message */
888 uint8_t num_pages; /* up to 15 */
889 struct bts_smscb_page page[15];
890};
891
892/* per-channel (basic/extended) CBCH state for a single BTS */
893struct bts_smscb_chan_state {
894 /* back-pointer to BTS */
895 struct gsm_bts *bts;
896 /* list of bts_smscb_message */
897 struct llist_head messages;
898 /* scheduling array; pointer of SMSCB pages */
899 struct bts_smscb_page **sched_arr;
900 size_t sched_arr_size;
901 /* index of the next to be transmitted page into the scheduler array */
902 size_t next_idx;
903 /* number of messages we have to pause due to overflow */
904 uint8_t overflow;
905};
906
Oliver Smithba0a1222020-03-18 12:39:30 +0100907struct bts_oml_fail_rep {
908 struct llist_head list;
909 time_t time;
910 struct msgb *mb;
911};
912
Oliver Smith8d8d7102018-10-23 15:35:43 +0200913/* One rejected BTS */
914struct gsm_bts_rejected {
915 /* list header in net->bts_rejected */
916 struct llist_head list;
917
918 uint16_t site_id;
919 uint16_t bts_id;
920 char ip[INET6_ADDRSTRLEN];
921 time_t time;
922};
Neels Hofmeyr10485162018-02-13 23:22:03 +0100923
Neels Hofmeyr638eb992020-09-16 00:56:19 +0200924extern struct osmo_tdef_group bsc_tdef_group[];
925
Neels Hofmeyr958f2592018-05-27 01:26:31 +0200926struct gsm_network *gsm_network_init(void *ctx);
927
Neels Hofmeyr6d568ed2018-07-09 16:49:18 +0200928struct gsm_bts *gsm_bts_num(const struct gsm_network *net, int num);
Neels Hofmeyr19bed232018-03-22 04:54:57 +0100929struct gsm_bts *gsm_bts_by_cell_id(const struct gsm_network *net,
930 const struct gsm0808_cell_id *cell_id,
931 int match_idx);
Neels Hofmeyr10485162018-02-13 23:22:03 +0100932
Neels Hofmeyr10485162018-02-13 23:22:03 +0100933extern const struct value_string gsm_chreq_descs[];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200934extern const struct value_string gsm_pchant_names[];
935extern const struct value_string gsm_pchant_descs[];
936extern const struct value_string gsm_pchan_ids[];
Neels Hofmeyr10485162018-02-13 23:22:03 +0100937const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200938static inline const char *gsm_pchan_id(enum gsm_phys_chan_config c)
939{ return get_value_string(gsm_pchan_ids, c); }
Neels Hofmeyr10485162018-02-13 23:22:03 +0100940enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
941const char *gsm_lchant_name(enum gsm_chan_t c);
942const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Neels Hofmeyr10485162018-02-13 23:22:03 +0100943char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
944char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
945char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +0100946
947static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
948{
949 return lchan->name;
950}
951
Neels Hofmeyr10485162018-02-13 23:22:03 +0100952void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
Pau Espin Pedrol388ed582020-07-15 20:53:16 +0200953void gsm_mo_init(struct gsm_abis_mo *mo, struct gsm_bts *bts,
954 uint8_t obj_class, uint8_t p1, uint8_t p2, uint8_t p3);
Neels Hofmeyr10485162018-02-13 23:22:03 +0100955
956struct gsm_nm_state *
957gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
958 const struct abis_om_obj_inst *obj_inst);
959void *
960gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
961 const struct abis_om_obj_inst *obj_inst);
962
Neels Hofmeyr10485162018-02-13 23:22:03 +0100963uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
964 uint8_t ts_nr, uint8_t lchan_nr);
965uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
966uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
967 enum gsm_phys_chan_config as_pchan);
968
Harald Welte251bec12018-09-09 17:14:09 +0200969void gsm48_lchan2chan_desc(struct gsm48_chan_desc *cd,
970 const struct gsm_lchan *lchan);
Harald Welte24286f32018-09-09 17:17:44 +0200971void gsm48_lchan2chan_desc_as_configured(struct gsm48_chan_desc *cd, const struct gsm_lchan *lchan);
Harald Welte251bec12018-09-09 17:14:09 +0200972
Pau Espin Pedrol388ed582020-07-15 20:53:16 +0200973uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr10485162018-02-13 23:22:03 +0100974
Neels Hofmeyr10485162018-02-13 23:22:03 +0100975enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200976uint8_t pchan_subslots(enum gsm_phys_chan_config pchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +0100977bool ts_is_tch(struct gsm_bts_trx_ts *ts);
978
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100979
Pau Espin Pedrol388ed582020-07-15 20:53:16 +0200980struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection *conn);
Harald Welteb7948872017-12-18 18:48:21 +0100981
Pau Espin Pedrol7950e5d2019-10-31 15:59:49 +0100982void conn_update_ms_power_class(struct gsm_subscriber_connection *conn, uint8_t power_class);
983void lchan_update_ms_power_ctrl_level(struct gsm_lchan *lchan, int ms_power_dbm);
984
Stefan Sperling81dc9e72018-02-05 17:34:36 +0100985enum {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200986 BSC_CTR_ASSIGNMENT_ATTEMPTED,
987 BSC_CTR_ASSIGNMENT_COMPLETED,
988 BSC_CTR_ASSIGNMENT_STOPPED,
989 BSC_CTR_ASSIGNMENT_NO_CHANNEL,
990 BSC_CTR_ASSIGNMENT_TIMEOUT,
991 BSC_CTR_ASSIGNMENT_FAILED,
992 BSC_CTR_ASSIGNMENT_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +0200993 BSC_CTR_HANDOVER_ATTEMPTED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200994 BSC_CTR_HANDOVER_COMPLETED,
995 BSC_CTR_HANDOVER_STOPPED,
Alexander Couzensb847a212016-08-02 11:34:11 +0200996 BSC_CTR_HANDOVER_NO_CHANNEL,
997 BSC_CTR_HANDOVER_TIMEOUT,
Alexander Couzensb847a212016-08-02 11:34:11 +0200998 BSC_CTR_HANDOVER_FAILED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200999 BSC_CTR_HANDOVER_ERROR,
Daniel Willmannbf2a4b62020-08-20 15:25:37 +02001000 BSC_CTR_INTRA_CELL_HO_ATTEMPTED,
1001 BSC_CTR_INTRA_CELL_HO_COMPLETED,
1002 BSC_CTR_INTRA_CELL_HO_STOPPED,
1003 BSC_CTR_INTRA_CELL_HO_NO_CHANNEL,
1004 BSC_CTR_INTRA_CELL_HO_TIMEOUT,
1005 BSC_CTR_INTRA_CELL_HO_FAILED,
1006 BSC_CTR_INTRA_CELL_HO_ERROR,
1007 BSC_CTR_INTRA_BSC_HO_ATTEMPTED,
1008 BSC_CTR_INTRA_BSC_HO_COMPLETED,
1009 BSC_CTR_INTRA_BSC_HO_STOPPED,
1010 BSC_CTR_INTRA_BSC_HO_NO_CHANNEL,
1011 BSC_CTR_INTRA_BSC_HO_TIMEOUT,
1012 BSC_CTR_INTRA_BSC_HO_FAILED,
1013 BSC_CTR_INTRA_BSC_HO_ERROR,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001014 BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED,
1015 BSC_CTR_INTER_BSC_HO_OUT_COMPLETED,
1016 BSC_CTR_INTER_BSC_HO_OUT_STOPPED,
1017 BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT,
Neels Hofmeyrdbe59f62020-08-29 03:23:31 +00001018 BSC_CTR_INTER_BSC_HO_OUT_FAILED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001019 BSC_CTR_INTER_BSC_HO_OUT_ERROR,
1020 BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED,
1021 BSC_CTR_INTER_BSC_HO_IN_COMPLETED,
1022 BSC_CTR_INTER_BSC_HO_IN_STOPPED,
1023 BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL,
1024 BSC_CTR_INTER_BSC_HO_IN_FAILED,
1025 BSC_CTR_INTER_BSC_HO_IN_TIMEOUT,
1026 BSC_CTR_INTER_BSC_HO_IN_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001027 BSC_CTR_PAGING_ATTEMPTED,
1028 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +01001029 BSC_CTR_PAGING_RESPONDED,
Alexander Chemeris43def742020-05-16 18:49:59 +03001030 BSC_CTR_PAGING_NO_ACTIVE_PAGING,
Stefan Sperling7926d982018-05-17 14:52:02 +02001031 BSC_CTR_UNKNOWN_UNIT_ID,
Neels Hofmeyr1c963eb2020-06-16 12:08:39 +02001032 BSC_CTR_MSCPOOL_SUBSCR_NO_MSC,
1033 BSC_CTR_MSCPOOL_EMERG_FORWARDED,
1034 BSC_CTR_MSCPOOL_EMERG_LOST,
Alexander Couzensb847a212016-08-02 11:34:11 +02001035};
1036
1037static const struct rate_ctr_desc bsc_ctr_description[] = {
Daniel Willmann45062b42020-08-20 18:37:51 +02001038 [BSC_CTR_ASSIGNMENT_ATTEMPTED] = {"assignment:attempted", "Assignment attempts"},
1039 [BSC_CTR_ASSIGNMENT_COMPLETED] = {"assignment:completed", "Assignment completed"},
1040 [BSC_CTR_ASSIGNMENT_STOPPED] = {"assignment:stopped", "Connection ended during Assignment"},
1041 [BSC_CTR_ASSIGNMENT_NO_CHANNEL] = {"assignment:no_channel", "Failure to allocate lchan for Assignment"},
1042 [BSC_CTR_ASSIGNMENT_TIMEOUT] = {"assignment:timeout", "Assignment timed out"},
1043 [BSC_CTR_ASSIGNMENT_FAILED] = {"assignment:failed", "Received Assignment Failure message"},
1044 [BSC_CTR_ASSIGNMENT_ERROR] = {"assignment:error", "Assignment failed for other reason"},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001045
Daniel Willmann45062b42020-08-20 18:37:51 +02001046 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Intra-BSC handover attempts"},
1047 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Intra-BSC handover completed"},
1048 [BSC_CTR_HANDOVER_STOPPED] = {"handover:stopped", "Connection ended during HO"},
1049 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Failure to allocate lchan for HO"},
1050 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Handover timed out"},
1051 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Received Handover Fail messages"},
1052 [BSC_CTR_HANDOVER_ERROR] = {"handover:error", "Re-assignment failed for other reason"},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001053
Daniel Willmannbf2a4b62020-08-20 15:25:37 +02001054 [BSC_CTR_INTRA_CELL_HO_ATTEMPTED] = {"intra_cell_ho:attempted", "Intra-Cell handover attempts"},
1055 [BSC_CTR_INTRA_CELL_HO_COMPLETED] = {"intra_cell_ho:completed", "Intra-Cell handover completed"},
1056 [BSC_CTR_INTRA_CELL_HO_STOPPED] = {"intra_cell_ho:stopped", "Connection ended during HO"},
1057 [BSC_CTR_INTRA_CELL_HO_NO_CHANNEL] = {"intra_cell_ho:no_channel", "Failure to allocate lchan for HO"},
1058 [BSC_CTR_INTRA_CELL_HO_TIMEOUT] = {"intra_cell_ho:timeout", "Handover timed out"},
1059 [BSC_CTR_INTRA_CELL_HO_FAILED] = {"intra_cell_ho:failed", "Received Handover Fail messages"},
1060 [BSC_CTR_INTRA_CELL_HO_ERROR] = {"intra_cell_ho:error", "Re-assignment failed for other reason"},
1061
1062 [BSC_CTR_INTRA_BSC_HO_ATTEMPTED] = {"intra_bsc_ho:attempted", "Intra-BSC handover attempts"},
1063 [BSC_CTR_INTRA_BSC_HO_COMPLETED] = {"intra_bsc_ho:completed", "Intra-BSC handover completed"},
1064 [BSC_CTR_INTRA_BSC_HO_STOPPED] = {"intra_bsc_ho:stopped", "Connection ended during HO"},
1065 [BSC_CTR_INTRA_BSC_HO_NO_CHANNEL] = {"intra_bsc_ho:no_channel", "Failure to allocate lchan for HO"},
1066 [BSC_CTR_INTRA_BSC_HO_TIMEOUT] = {"intra_bsc_ho:timeout", "Handover timed out"},
1067 [BSC_CTR_INTRA_BSC_HO_FAILED] = {"intra_bsc_ho:failed", "Received Handover Fail messages"},
1068 [BSC_CTR_INTRA_BSC_HO_ERROR] = {"intra_bsc_ho:error", "Re-assignment failed for other reason"},
1069
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001070 [BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED] = {"interbsc_ho_out:attempted",
Daniel Willmann45062b42020-08-20 18:37:51 +02001071 "Attempts to handover to remote BSS"},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001072 [BSC_CTR_INTER_BSC_HO_OUT_COMPLETED] = {"interbsc_ho_out:completed",
Daniel Willmann45062b42020-08-20 18:37:51 +02001073 "Handover to remote BSS completed"},
1074 [BSC_CTR_INTER_BSC_HO_OUT_STOPPED] = {"interbsc_ho_out:stopped", "Connection ended during HO"},
1075 [BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT] = {"interbsc_ho_out:timeout", "Handover timed out"},
Neels Hofmeyrdbe59f62020-08-29 03:23:31 +00001076 [BSC_CTR_INTER_BSC_HO_OUT_FAILED] = {"interbsc_ho_out:failed", "Received Handover Fail message"},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001077 [BSC_CTR_INTER_BSC_HO_OUT_ERROR] = {"interbsc_ho_out:error",
Daniel Willmann45062b42020-08-20 18:37:51 +02001078 "Handover to remote BSS failed for other reason"},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001079
1080 [BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED] = {"interbsc_ho_in:attempted",
Daniel Willmann45062b42020-08-20 18:37:51 +02001081 "Attempts to handover from remote BSS"},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001082 [BSC_CTR_INTER_BSC_HO_IN_COMPLETED] = {"interbsc_ho_in:completed",
Daniel Willmann45062b42020-08-20 18:37:51 +02001083 "Handover from remote BSS completed"},
1084 [BSC_CTR_INTER_BSC_HO_IN_STOPPED] = {"interbsc_ho_in:stopped", "Connection ended during HO"},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001085 [BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL] = {"interbsc_ho_in:no_channel",
Daniel Willmann45062b42020-08-20 18:37:51 +02001086 "Failure to allocate lchan for HO"},
1087 [BSC_CTR_INTER_BSC_HO_IN_TIMEOUT] = {"interbsc_ho_in:timeout", "Handover from remote BSS timed out"},
1088 [BSC_CTR_INTER_BSC_HO_IN_FAILED] = {"interbsc_ho_in:failed", "Received Handover Fail message"},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001089 [BSC_CTR_INTER_BSC_HO_IN_ERROR] = {"interbsc_ho_in:error",
Daniel Willmann45062b42020-08-20 18:37:51 +02001090 "Handover from remote BSS failed for other reason"},
Harald Weltecf9d4312017-12-13 23:17:16 +01001091
Daniel Willmann45062b42020-08-20 18:37:51 +02001092 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber"},
1093 [BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Paging request send failures because no responsible BTS was found"},
1094 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response"},
1095 [BSC_CTR_PAGING_NO_ACTIVE_PAGING] = {"paging:no_active_paging", "Paging response without an active paging request (arrived after paging expiration?)"},
Stefan Sperling7926d982018-05-17 14:52:02 +02001096
Daniel Willmann45062b42020-08-20 18:37:51 +02001097 [BSC_CTR_UNKNOWN_UNIT_ID] = {"abis:unknown_unit_id", "Connection attempts from unknown IPA CCM Unit ID"},
Neels Hofmeyr1c963eb2020-06-16 12:08:39 +02001098
1099 [BSC_CTR_MSCPOOL_SUBSCR_NO_MSC] = {"mscpool:subscr:no_msc",
Daniel Willmann45062b42020-08-20 18:37:51 +02001100 "Complete Layer 3 requests lost because no connected MSC is found available"},
Neels Hofmeyr1c963eb2020-06-16 12:08:39 +02001101 [BSC_CTR_MSCPOOL_EMERG_FORWARDED] = {"mscpool:emerg:forwarded",
Daniel Willmann45062b42020-08-20 18:37:51 +02001102 "Emergency call requests forwarded to an MSC (see also per-MSC counters"},
Neels Hofmeyr1c963eb2020-06-16 12:08:39 +02001103 [BSC_CTR_MSCPOOL_EMERG_LOST] = {"mscpool:emerg:lost",
Daniel Willmann45062b42020-08-20 18:37:51 +02001104 "Emergency call requests lost because no MSC was found available"},
Alexander Couzensb847a212016-08-02 11:34:11 +02001105};
1106
Alexander Couzensb847a212016-08-02 11:34:11 +02001107
1108
1109static const struct rate_ctr_group_desc bsc_ctrg_desc = {
1110 "bsc",
1111 "base station controller",
1112 OSMO_STATS_CLASS_GLOBAL,
1113 ARRAY_SIZE(bsc_ctr_description),
1114 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +02001115};
1116
Alexander Chemerisdb542832020-05-08 01:49:12 +03001117/* Constants for the BSC stats */
1118enum {
1119 BSC_STAT_NUM_BTS_TOTAL,
1120};
1121
Daniel Willmannaa420ce2020-08-20 15:37:35 +02001122/* BTS counter index if a BTS could not be found
1123 * Currently we are limited to bts 0 - 255 in the VTY, but that might change in
1124 * the future so use 2**16 */
1125#define BTS_STAT_IDX_UNKNOWN (UINT16_MAX + 1)
1126
Neels Hofmeyr73983952016-05-10 13:29:33 +02001127struct gsm_tz {
1128 int override; /* if 0, use system's time zone instead. */
1129 int hr; /* hour */
1130 int mn; /* minute */
1131 int dst; /* daylight savings */
1132};
1133
Harald Welte52b1f982008-12-23 20:25:15 +00001134struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001135 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
1136 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
1137 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
1138 * these have in common, like country and network code, put in yet
1139 * separate structs and placed as members in osmo_bsc and osmo_msc. */
1140
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001141 struct osmo_plmn_id plmn;
1142
Harald Welte51e4bf32017-12-23 17:30:18 +01001143 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
1144 uint8_t a5_encryption_mask;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001145 int neci;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001146
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001147 struct handover_cfg *ho;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001148 struct {
1149 unsigned int congestion_check_interval_s;
1150 struct osmo_timer_list congestion_check_timer;
1151 } hodec2;
Harald Welte52b1f982008-12-23 20:25:15 +00001152
Alexander Chemerisdb542832020-05-08 01:49:12 +03001153 /* structures for keeping rate counters and gauge stats */
Alexander Couzensb847a212016-08-02 11:34:11 +02001154 struct rate_ctr_group *bsc_ctrs;
Alexander Chemerisdb542832020-05-08 01:49:12 +03001155 struct osmo_stat_item_group *bsc_statg;
Harald Welte24ff6ee2009-12-22 00:41:05 +01001156
Harald Welte52b1f982008-12-23 20:25:15 +00001157 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +02001158 struct llist_head bts_list;
Oliver Smith8d8d7102018-10-23 15:35:43 +02001159 struct llist_head bts_rejected;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001160
Daniel Willmannaa420ce2020-08-20 15:37:35 +02001161 /* BTS-based counters when we can't find the actual BTS
1162 * e.g. when conn->lchan is NULL */
1163 struct rate_ctr_group *bts_unknown_ctrs;
1164 struct osmo_stat_item_group *bts_unknown_statg;
1165
Neels Hofmeyr08822a32019-07-11 03:43:34 +02001166 /* see gsm_network_T_defs */
Neels Hofmeyra6078fe2019-01-28 03:52:14 +01001167 struct osmo_tdef *T_defs;
Harald Welteeab84a12009-12-13 10:53:12 +01001168
Alexander Couzens547c2072017-11-21 12:03:04 +01001169 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +08001170
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +08001171 /* Use a TCH for handling requests of type paging any */
1172 int pag_any_tch;
1173
Neels Hofmeyr06a14d22020-05-26 12:41:18 +02001174 /* msc configuration */
1175 struct llist_head mscs;
Neels Hofmeyreec776e2020-05-25 00:02:56 +02001176 uint8_t mscs_round_robin_next_nr;
1177 /* Emergency calls potentially select a different set of MSCs, so to not mess up the normal round-robin
1178 * behavior, emergency calls need a separate round-robin counter. */
1179 uint8_t mscs_round_robin_next_emerg_nr;
Neels Hofmeyr06a14d22020-05-26 12:41:18 +02001180
1181 /* rf ctl related bits */
1182 int mid_call_timeout;
1183 char *rf_ctrl_name;
1184 struct osmo_bsc_rf *rf_ctrl;
1185 int auto_off_timeout;
1186
1187 struct bsc_cbc_link *cbc;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +01001188
Daniel Willmann6fc4a982011-07-22 17:55:42 +02001189 /* control interface */
1190 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +02001191
1192 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
1193 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +02001194
1195 /* all active subscriber connections. */
1196 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +02001197
1198 /* if override is nonzero, this timezone data is used for all MM
1199 * contexts. */
1200 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
1201 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +01001202 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +02001203 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +01001204
1205 /* List of all struct bsc_subscr used in libbsc. This llist_head is
1206 * allocated so that the llist_head pointer itself can serve as a
1207 * talloc context (useful to not have to pass the entire gsm_network
1208 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
1209 * not require gsm_data.h). In an MSC-without-BSC environment, this
1210 * pointer is NULL to indicate absence of a bsc_subscribers list. */
1211 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +02001212
Stefan Sperling6cee8932018-01-30 18:14:22 +01001213 /* Timer for periodic channel load measurements to maintain each BTS's T3122. */
1214 struct osmo_timer_list t3122_chan_load_timer;
1215
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001216 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +02001217 struct mgcp_client_conf *conf;
1218 struct mgcp_client *client;
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +02001219 struct osmo_tdef *tdefs;
Philipp Maier39c609b2017-09-27 15:51:34 +02001220 } mgw;
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001221
1222 /* Remote BSS Cell Identifier Lists */
1223 struct neighbor_ident_list *neighbor_bss_cells;
Oliver Smitha595db12020-03-17 12:21:00 +01001224
1225 /* Don't refuse to start with mutually exclusive codec settings */
1226 bool allow_unusable_timeslots;
Neels Hofmeyr4099f1d2020-05-26 03:58:14 +02001227
1228 uint8_t nri_bitlen;
1229 struct osmo_nri_ranges *null_nri_ranges;
Neels Hofmeyr4ae338d2020-09-17 17:54:39 +02001230
1231 struct smlc_config *smlc;
Harald Welte7e310b12009-03-30 20:56:32 +00001232};
1233
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001234struct gsm_audio_support {
1235 uint8_t hr : 1,
1236 ver : 7;
1237};
1238
Neels Hofmeyrc13e6872016-05-11 13:53:47 +02001239extern void talloc_ctx_init(void *ctx_root);
1240
Harald Welte1d014a52009-08-08 15:38:29 +02001241enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +02001242const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +00001243struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
1244 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +00001245
Andreas Eversberg8226fa72009-06-29 15:19:38 +02001246extern void *tall_bsc_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +02001247
Harald Welte1876c312018-05-27 11:53:43 +02001248extern struct gsm_network *bsc_gsmnet;
1249
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001250enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +02001251const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
1252
Neels Hofmeyr4d358c02018-02-22 03:19:05 +01001253void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +08001254void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +01001255
Harald Welte3561bd42018-01-28 03:04:16 +01001256struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *network);
Neels Hofmeyr42eb0142016-05-20 17:15:44 +02001257
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001258struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, uint8_t bsic);
1259struct 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 +01001260
Harald Welte3300c012011-06-05 13:31:33 +02001261void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
1262 uint8_t e1_ts, uint8_t e1_ts_ss);
1263
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +02001264/* generic E1 line operations for all ISDN-based BTS. */
1265extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
1266
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +01001267/* control interface handling */
1268int bsc_base_ctrl_cmds_install(void);
1269
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001270bool ts_is_usable(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001271
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001272int gsm_lchan_type_by_pchan(enum gsm_phys_chan_config pchan);
1273enum gsm_phys_chan_config gsm_pchan_by_lchan_type(enum gsm_chan_t type);
1274
Neels Hofmeyrb523f542020-07-09 15:54:40 +02001275enum gsm48_rr_cause bsc_gsm48_rr_cause_from_gsm0808_cause(enum gsm0808_cause c);
Neels Hofmeyr3405c772020-07-11 01:44:08 +02001276enum gsm48_rr_cause bsc_gsm48_rr_cause_from_rsl_cause(uint8_t c);
Neels Hofmeyrb523f542020-07-09 15:54:40 +02001277
Neels Hofmeyra33ef3a2020-10-01 04:23:32 +02001278int bsc_sccp_inst_next_conn_id(struct osmo_sccp_instance *sccp);
1279
Harald Welte6be350c2011-05-25 13:10:08 +02001280#endif /* _GSM_DATA_H */