blob: d8d10c95d5d67d01b491d1b36390d2f31e1597cb [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001#ifndef _GSM_DATA_H
2#define _GSM_DATA_H
3
Harald Weltef142c972011-05-24 13:25:38 +02004#include <stdint.h>
Maxddee01f2016-05-24 14:23:27 +02005#include <regex.h>
6#include <sys/types.h>
Maxe6052c42016-06-30 10:25:49 +02007#include <stdbool.h>
Neels Hofmeyr10485162018-02-13 23:22:03 +01008#include <stdint.h>
Harald Weltef142c972011-05-24 13:25:38 +02009
10#include <osmocom/core/timer.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020011#include <osmocom/core/rate_ctr.h>
Harald Welte6be350c2011-05-25 13:10:08 +020012#include <osmocom/core/select.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020013#include <osmocom/core/stats.h>
Stefan Sperling81dc9e72018-02-05 17:34:36 +010014#include <osmocom/core/stat_item.h>
Philipp Maier8c498fc2018-02-21 13:24:36 +010015#include <osmocom/gsm/bts_features.h>
Neels Hofmeyra60f3442018-02-12 16:44:32 +010016#include <osmocom/gsm/protocol/gsm_08_08.h>
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020017#include <osmocom/gsm/gsm0808.h>
Neels Hofmeyrf93970b2018-03-05 02:09:40 +010018#include <osmocom/gsm/gsm48.h>
Harald Welte3561bd42018-01-28 03:04:16 +010019#include <osmocom/core/fsm.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020020
Harald Welte121e9a42016-04-20 13:13:19 +020021#include <osmocom/crypt/auth.h>
Harald Weltef142c972011-05-24 13:25:38 +020022
Neels Hofmeyrc0164792017-09-04 15:15:32 +020023#include <osmocom/bsc/rest_octets.h>
Harald Welteb96be392011-05-25 12:33:33 +020024
Neels Hofmeyr10485162018-02-13 23:22:03 +010025#include <osmocom/core/bitvec.h>
26#include <osmocom/gsm/gsm_utils.h>
27#include <osmocom/gsm/rxlev_stat.h>
28#include <osmocom/gsm/protocol/gsm_08_58.h>
29#include <osmocom/gsm/protocol/gsm_12_21.h>
30#include <osmocom/abis/e1_input.h>
31#include <osmocom/bsc/meas_rep.h>
Harald Welte519c7e12018-01-28 02:45:46 +010032#include <osmocom/bsc/bsc_msg_filter.h>
Stefan Sperling6442e432018-02-06 14:44:54 +010033#include <osmocom/bsc/acc_ramp.h>
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020034#include <osmocom/bsc/gsm_timers.h>
35#include <osmocom/bsc/neighbor_ident.h>
Neels Hofmeyr10485162018-02-13 23:22:03 +010036
Neels Hofmeyr596c4022018-06-16 19:29:50 +020037#define GSM_T3122_DEFAULT 10
38
Harald Welte74b8cdb2018-01-15 19:26:06 +010039struct mgcp_client_conf;
40struct mgcp_client;
41struct mgcp_ctx;
Neels Hofmeyr19bed232018-03-22 04:54:57 +010042struct gsm0808_cell_id;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020043struct mgw_endpoint;
Philipp Maier39f62bb2017-04-09 12:32:51 +020044
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020045/** annotations for msgb ownership */
46#define __uses
47
Holger Hans Peter Freyther6f615552010-11-15 20:50:42 +010048#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
49
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010050struct bsc_subscr;
Neels Hofmeyr7b656882017-07-09 22:09:18 +020051struct gprs_ra_id;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020052struct handover;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020053
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080054#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
55
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010056#define tmsi_from_string(str) strtoul(str, NULL, 10)
57
Max70fdd242017-06-15 15:10:53 +020058/* 3-bit long values */
59#define EARFCN_PRIO_INVALID 8
60#define EARFCN_MEAS_BW_INVALID 8
61/* 5-bit long values */
62#define EARFCN_QRXLV_INVALID 32
63#define EARFCN_THRESH_LOW_INVALID 32
64
Harald Welte8e1e3ee2009-02-01 13:32:45 +000065struct msgb;
66typedef int gsm_cbfn(unsigned int hooknum,
67 unsigned int event,
68 struct msgb *msg,
69 void *data, void *param);
70
Harald Weltef7c28b02009-12-21 13:30:17 +010071/* Maximum number of neighbor cells whose average we track */
72#define MAX_NEIGH_MEAS 10
73/* Maximum size of the averaging window for neighbor cells */
74#define MAX_WIN_NEIGH_AVG 10
Andreas Eversberg98692032013-06-23 10:44:34 +020075/* Maximum number of report history we store */
76#define MAX_MEAS_REP 10
Harald Weltef7c28b02009-12-21 13:30:17 +010077
78/* processed neighbor measurements for one cell */
79struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020080 uint16_t arfcn;
81 uint8_t bsic;
82 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +010083 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020084 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +010085};
86
Harald Weltea43e0b42016-06-19 18:06:02 +020087struct gsm_classmark {
88 bool classmark1_set;
89 struct gsm48_classmark1 classmark1;
90 uint8_t classmark2_len;
91 uint8_t classmark2[3];
92 uint8_t classmark3_len;
93 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
94};
95
Harald Welte519c7e12018-01-28 02:45:46 +010096enum subscr_sccp_state {
97 SUBSCR_SCCP_ST_NONE,
98 SUBSCR_SCCP_ST_WAIT_CONN_CONF,
99 SUBSCR_SCCP_ST_CONNECTED
100};
101
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200102struct assignment_request {
103 bool aoip;
104
105 uint16_t msc_assigned_cic;
106
107 char msc_rtp_addr[INET_ADDRSTRLEN];
108 uint16_t msc_rtp_port;
109
110 enum gsm48_chan_mode chan_mode;
111 bool full_rate;
112};
113
114struct assignment_fsm_data {
115 struct assignment_request req;
116 bool requires_voice_stream;
117
118 struct osmo_fsm_inst *fi;
119 struct gsm_lchan *new_lchan;
120
121 /* Whether this assignment triggered creation of the MGW endpoint: if the assignment
122 * fails, we will release that again as soon as possible. (If false, the endpoint already
123 * existed before or isn't needed at all.)*/
124 struct mgwep_ci *created_ci_for_msc;
125
126 enum gsm0808_cause failure_cause;
127 enum gsm48_rr_cause rr_cause;
128
129 bool result_rate_ctr_done;
130};
131
132enum hodec_id {
133 HODEC_NONE,
134 HODEC1 = 1,
135 HODEC2 = 2,
136 HODEC_USER,
137 HODEC_REMOTE,
138};
139
140/* For example, to count specific kinds of ongoing handovers, it is useful to be able to OR-combine
141 * scopes. */
142enum handover_scope {
143 HO_NO_HANDOVER = 0,
144 HO_INTRA_CELL = 0x1,
145 HO_INTRA_BSC = 0x2,
146 HO_INTER_BSC_OUT = 0x4,
147 HO_INTER_BSC_IN = 0x8,
148 HO_SCOPE_ALL = 0xffff,
149};
150
151extern const struct value_string handover_scope_names[];
152inline static const char *handover_scope_name(enum handover_scope val)
153{ return get_value_string(handover_scope_names, val); }
154
155struct handover_out_req {
156 enum hodec_id from_hodec_id;
157 struct gsm_lchan *old_lchan;
158 struct neighbor_ident_key target_nik;
159 enum gsm_chan_t new_lchan_type; /*< leave GSM_LCHAN_NONE to use same as old_lchan */
160};
161
162struct handover_in_req {
163 struct gsm0808_channel_type ct;
164 struct gsm0808_speech_codec_list scl;
165 struct gsm0808_encrypt_info ei;
166 struct gsm_classmark classmark;
167 struct gsm0808_cell_id cell_id_serving;
168 char cell_id_serving_name[64];
169 struct gsm0808_cell_id cell_id_target;
170 char cell_id_target_name[64];
171 uint16_t msc_assigned_cic;
172 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
173 uint16_t msc_assigned_rtp_port;
174};
175
176struct handover {
177 struct osmo_fsm_inst *fi;
178
179 enum hodec_id from_hodec_id;
180 enum handover_scope scope;
181 enum gsm_chan_t new_lchan_type;
182 struct neighbor_ident_key target_cell;
183
184 uint8_t ho_ref;
185 struct gsm_bts *new_bts;
186 struct gsm_lchan *new_lchan;
187 bool async;
188 struct handover_in_req inter_bsc_in;
189 struct mgwep_ci *created_ci_for_msc;
190};
191
Neels Hofmeyr378a4922016-05-09 21:07:43 +0200192/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100193struct gsm_subscriber_connection {
Harald Weltea43e0b42016-06-19 18:06:02 +0200194 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +0800195 struct llist_head entry;
196
Harald Welte3561bd42018-01-28 03:04:16 +0100197 /* FSM instance to control the subscriber connection state (RTP, A) */
198 struct osmo_fsm_inst *fi;
199
Harald Weltea43e0b42016-06-19 18:06:02 +0200200 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100201 struct bsc_subscr *bsub;
202
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100203 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200204 struct gsm_network *network;
205
Harald Welte4a8ebc82017-12-18 18:34:41 +0100206 /* the primary / currently active lchan to the BTS/subscriber */
207 struct gsm_lchan *lchan;
Harald Welte3561bd42018-01-28 03:04:16 +0100208
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200209 struct assignment_fsm_data assignment;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100210
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200211 /* handover information, if a handover is pending for this conn. */
212 struct handover ho;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100213
Harald Welte4a8ebc82017-12-18 18:34:41 +0100214 /* buffer/cache for classmark of the ME of the subscriber */
Harald Weltea43e0b42016-06-19 18:06:02 +0200215 struct gsm_classmark classmark;
Andreas Eversberg935e5d72013-06-17 11:58:30 +0200216
Neels Hofmeyr149160f2018-06-16 17:20:13 +0200217 /* Queue DTAP messages during handover/assignment (msgb_enqueue()/msgb_dequeue())*/
218 struct llist_head dtap_queue;
219 unsigned int dtap_queue_len;
Andreas Eversberg084b4212013-05-30 14:12:48 +0200220
Neels Hofmeyrec422642018-02-15 14:07:40 +0100221 struct {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100222 int failures;
Neels Hofmeyrec422642018-02-15 14:07:40 +0100223 struct penalty_timers *penalty_timers;
224 } hodec2;
Neels Hofmeyra60f3442018-02-12 16:44:32 +0100225
226 /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment Request. 3GPP 48.008
227 * 3.2.2.103 says:
228 * The "Codec List (MSC Preferred)" shall not include codecs
229 * that are not supported by the MS.
230 * i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed the MS bearer
231 * capabilities, which the MSC is required to translate into the codec list. */
232 struct gsm0808_speech_codec_list codec_list;
Harald Welte519c7e12018-01-28 02:45:46 +0100233
234 /* flag to prevent multiple simultaneous ciphering commands */
235 int ciphering_handled;
236
237 /* state related to welcome USSD */
238 uint8_t new_subscriber;
239
240 /* state related to osmo_bsc_filter.c */
241 struct bsc_filter_state filter_state;
242
243 /* SCCP connection associatd with this subscriber_connection */
244 struct {
245 /* for advanced ping/pong */
246 int send_ping;
247
248 /* SCCP connection realted */
249 struct bsc_msc_data *msc;
250
251 /* Sigtran connection ID */
252 int conn_id;
253 enum subscr_sccp_state state;
254 } sccp;
255
256 /* for audio handling */
257 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200258 uint16_t msc_assigned_cic;
Harald Welte519c7e12018-01-28 02:45:46 +0100259
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200260 /* RTP address where the MSC expects us to send the RTP stream coming from the BTS. */
261 char msc_assigned_rtp_addr[INET_ADDRSTRLEN];
262 uint16_t msc_assigned_rtp_port;
Harald Welte519c7e12018-01-28 02:45:46 +0100263
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200264 /* The endpoint at the MGW used to join both BTS and MSC side connections, e.g.
265 * "rtpbridge/23@mgw". */
266 struct mgw_endpoint *mgw_endpoint;
Harald Welte3561bd42018-01-28 03:04:16 +0100267
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200268 /* The connection identifier of the mgw_endpoint used to transceive RTP towards the MSC.
269 * (The BTS side CI is handled by struct gsm_lchan and the lchan_fsm.) */
270 struct mgwep_ci *mgw_endpoint_ci_msc;
Harald Welte3561bd42018-01-28 03:04:16 +0100271
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200272 /* Channel rate flag requested by the MSC, FR=1, HR=0, Invalid=-1 */
Harald Welte3561bd42018-01-28 03:04:16 +0100273 int full_rate;
274
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200275 /* Channel mode requested by the MSC (signalling or voice channel) */
Harald Welte3561bd42018-01-28 03:04:16 +0100276 enum gsm48_chan_mode chan_mode;
277
Harald Welte519c7e12018-01-28 02:45:46 +0100278 } user_plane;
Harald Weltec997ceb2018-05-30 01:39:43 +0200279
280 /* LCLS (local call, local switch) related state */
281 struct {
282 uint8_t global_call_ref[15];
283 uint8_t global_call_ref_len; /* length of global_call_ref */
284 uint8_t config; /* TS 48.008 3.2.2.116 */
285 uint8_t control;/* TS 48.008 3.2.2.117 */
286 /* LCLS FSM */
287 struct osmo_fsm_inst *fi;
288 /* pointer to "other" connection, if Call Leg Relocation was successful */
289 struct gsm_subscriber_connection *other;
290 } lcls;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100291};
292
Harald Weltef142c972011-05-24 13:25:38 +0200293
Neels Hofmeyr10485162018-02-13 23:22:03 +0100294/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 Table 10.5.2.33b.1:
295 4-bit index is used (2#1111 = 10#15) */
296#define SI2Q_MAX_NUM 16
297/* length in bits (for single SI2quater message) */
298#define SI2Q_MAX_LEN 160
299#define SI2Q_MIN_LEN 18
300
301struct osmo_bsc_data;
302
303struct osmo_bsc_sccp_con;
304
305/* Channel Request reason */
306enum gsm_chreq_reason_t {
307 GSM_CHREQ_REASON_EMERG,
308 GSM_CHREQ_REASON_PAG,
309 GSM_CHREQ_REASON_CALL,
310 GSM_CHREQ_REASON_LOCATION_UPD,
311 GSM_CHREQ_REASON_OTHER,
312 GSM_CHREQ_REASON_PDCH,
313};
314
315/* lchans 0..3 are SDCCH in combined channel configuration,
316 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
317#define CCCH_LCHAN 4
318
319#define TRX_NR_TS 8
320#define TS_MAX_LCHAN 8
321
322#define HARDCODED_ARFCN 123
323#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
324
325/* for multi-drop config */
326#define HARDCODED_BTS0_TS 1
327#define HARDCODED_BTS1_TS 6
328#define HARDCODED_BTS2_TS 11
329
330#define MAX_VERSION_LENGTH 64
331
Neels Hofmeyr10485162018-02-13 23:22:03 +0100332enum gsm_hooks {
333 GSM_HOOK_NM_SWLOAD,
334 GSM_HOOK_RR_PAGING,
335 GSM_HOOK_RR_SECURITY,
336};
337
Neels Hofmeyr10485162018-02-13 23:22:03 +0100338enum bts_gprs_mode {
339 BTS_GPRS_NONE = 0,
340 BTS_GPRS_GPRS = 1,
341 BTS_GPRS_EGPRS = 2,
342};
343
344struct gsm_lchan;
345struct osmo_rtp_socket;
346struct rtp_socket;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100347
348/* Network Management State */
349struct gsm_nm_state {
350 uint8_t operational;
351 uint8_t administrative;
352 uint8_t availability;
353};
354
355struct gsm_abis_mo {
356 uint8_t obj_class;
357 uint8_t procedure_pending;
358 struct abis_om_obj_inst obj_inst;
359 const char *name;
360 struct gsm_nm_state nm_state;
361 struct tlv_parsed *nm_attr;
362 struct gsm_bts *bts;
363};
364
365/* Ericsson OM2000 Managed Object */
366struct abis_om2k_mo {
367 uint8_t class;
368 uint8_t bts;
369 uint8_t assoc_so;
370 uint8_t inst;
371} __attribute__ ((packed));
372
373struct om2k_mo {
374 struct abis_om2k_mo addr;
375 struct osmo_fsm_inst *fsm;
376};
377
378#define A38_XOR_MIN_KEY_LEN 12
379#define A38_XOR_MAX_KEY_LEN 16
380#define A38_COMP128_KEY_LEN 16
381#define RSL_ENC_ALG_A5(x) (x+1)
382#define MAX_EARFCN_LIST 32
383
384/* is the data link established? who established it? */
385#define LCHAN_SAPI_UNUSED 0
386#define LCHAN_SAPI_MS 1
387#define LCHAN_SAPI_NET 2
Neels Hofmeyr10485162018-02-13 23:22:03 +0100388
389/* BTS ONLY */
390#define MAX_NUM_UL_MEAS 104
391#define LC_UL_M_F_L1_VALID (1 << 0)
392#define LC_UL_M_F_RES_VALID (1 << 1)
393
394struct bts_ul_meas {
395 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
396 uint16_t ber10k;
397 /* timing advance offset (in quarter bits) */
398 int16_t ta_offs_qbits;
399 /* C/I ratio in dB */
400 float c_i;
401 /* flags */
402 uint8_t is_sub:1;
403 /* RSSI in dBm * -1 */
404 uint8_t inv_rssi;
405};
406
407struct bts_codec_conf {
408 uint8_t hr;
409 uint8_t efr;
410 uint8_t amr;
411};
412
413struct amr_mode {
414 uint8_t mode;
415 uint8_t threshold;
416 uint8_t hysteresis;
417};
418
419struct amr_multirate_conf {
420 uint8_t gsm48_ie[2];
421 struct amr_mode ms_mode[4];
422 struct amr_mode bts_mode[4];
423 uint8_t num_modes;
424};
425/* /BTS ONLY */
426
427enum lchan_csd_mode {
428 LCHAN_CSD_M_NT,
429 LCHAN_CSD_M_T_1200_75,
430 LCHAN_CSD_M_T_600,
431 LCHAN_CSD_M_T_1200,
432 LCHAN_CSD_M_T_2400,
433 LCHAN_CSD_M_T_9600,
434 LCHAN_CSD_M_T_14400,
435 LCHAN_CSD_M_T_29000,
436 LCHAN_CSD_M_T_32000,
437};
438
439/* State of the SAPIs in the lchan */
440enum lchan_sapi_state {
441 LCHAN_SAPI_S_NONE,
442 LCHAN_SAPI_S_REQ,
443 LCHAN_SAPI_S_ASSIGNED,
444 LCHAN_SAPI_S_REL,
445 LCHAN_SAPI_S_ERROR,
446};
447
Neels Hofmeyr92b9f2e2018-02-14 00:19:11 +0100448#define MAX_A5_KEY_LEN (128/8)
449
450struct gsm_encr {
451 uint8_t alg_id;
452 uint8_t key_len;
453 uint8_t key[MAX_A5_KEY_LEN];
454};
455
Neels Hofmeyr8da22332018-04-11 01:43:41 +0200456#define LOGPLCHAN(lchan, ss, level, fmt, args...) \
457 LOGP(ss, level, "%s (ss=%d,%s) (%s) " fmt, \
458 lchan ? gsm_ts_and_pchan_name(lchan->ts) : "-", \
459 lchan ? lchan->nr : 0, \
460 lchan ? gsm_lchant_name(lchan->type) : "-", \
461 bsc_subscr_name(lchan && lchan->conn ? lchan->conn->bsub : NULL), \
462 ## args)
463
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200464/* usage:
465 * struct gsm_lchan *lchan;
466 * struct gsm_bts_trx_ts *ts = get_some_timeslot();
467 * ts_for_each_lchan(lchan, ts) {
468 * LOGPLCHAN(DMAIN, LOGL_DEBUG, "hello world\n");
469 * }
470 * Iterate only those lchans that have an FSM allocated. */
471#define ts_for_each_lchan(lchan, ts) ts_as_pchan_for_each_lchan(lchan, ts, (ts)->pchan_is)
472
473/* Same as ts_for_each_lchan() but with an explicit pchan kind (GSM_PCHAN_* constant).
474 * Iterate only those lchans that have an FSM allocated. */
475#define ts_as_pchan_for_each_lchan(lchan, ts, as_pchan) \
476 for (lchan = (ts)->lchan; \
477 ((lchan - (ts)->lchan) < ARRAY_SIZE((ts)->lchan)) \
478 && lchan->fi \
479 && lchan->nr < pchan_subslots(as_pchan); \
480 lchan++)
481
482enum lchan_activate_mode {
483 FOR_NONE,
484 FOR_MS_CHANNEL_REQUEST,
485 FOR_ASSIGNMENT,
486 FOR_HANDOVER,
487 FOR_VTY,
488};
489
490extern const struct value_string lchan_activate_mode_names[];
491static inline const char *lchan_activate_mode_name(enum lchan_activate_mode activ_for)
492{ return get_value_string(lchan_activate_mode_names, activ_for); }
493
Neels Hofmeyr10485162018-02-13 23:22:03 +0100494struct gsm_lchan {
495 /* The TS that we're part of */
496 struct gsm_bts_trx_ts *ts;
497 /* The logical subslot number in the TS */
498 uint8_t nr;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200499 char *name;
500
501 struct osmo_fsm_inst *fi;
502 struct mgwep_ci *mgw_endpoint_ci_bts;
503
504 struct {
505 enum lchan_activate_mode activ_for;
506 bool concluded; /*< true as soon as LCHAN_ST_ESTABLISHED is reached */
507 bool requires_voice_stream;
508 bool mgw_endpoint_available;
509 uint16_t msc_assigned_cic;
510 enum gsm0808_cause gsm0808_error_cause;
511 struct gsm_lchan *re_use_mgw_endpoint_from_lchan;
512 } activate;
513
514 /* If an event to release the lchan comes in while still waiting for responses, just mark this
515 * flag, so that the lchan will gracefully release at the next sensible junction. */
516 bool release_requested;
517 bool deact_sacch;
518
519 char *last_error;
520
521 /* There is an RSL error cause of value 0, so we need a separate flag. */
522 bool release_in_error;
523 /* RSL error code, RSL_ERR_* */
524 uint8_t rsl_error_cause;
525
Neels Hofmeyr10485162018-02-13 23:22:03 +0100526 /* The logical channel type */
527 enum gsm_chan_t type;
528 /* RSL channel mode */
529 enum rsl_cmod_spd rsl_cmode;
530 /* If TCH, traffic channel mode */
531 enum gsm48_chan_mode tch_mode;
532 enum lchan_csd_mode csd_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100533 /* Power levels for MS and BTS */
534 uint8_t bs_power;
535 uint8_t ms_power;
536 /* Encryption information */
537 struct gsm_encr encr;
538
539 /* AMR bits */
540 uint8_t mr_ms_lv[7];
541 uint8_t mr_bts_lv[7];
542
543 /* Established data link layer services */
544 uint8_t sapis[8];
545
546 struct {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200547 uint32_t bound_ip; /*< where the BTS receives RTP */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100548 uint16_t bound_port;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200549 uint32_t connect_ip; /*< where the BTS sends RTP to (MGW) */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100550 uint16_t connect_port;
551 uint16_t conn_id;
552 uint8_t rtp_payload;
553 uint8_t rtp_payload2;
554 uint8_t speech_mode;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100555
556 /* info we need to postpone the AoIP
557 * assignment completed message */
558 struct {
559 uint8_t rr_cause;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100560 bool valid;
561 } ass_compl;
562 } abis_ip;
563
564 uint8_t rqd_ta;
565
Neels Hofmeyr10485162018-02-13 23:22:03 +0100566 /* table of neighbor cell measurements */
567 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
568
569 /* cache of last measurement reports on this lchan */
570 struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
571 int meas_rep_idx;
572 int meas_rep_count;
Neels Hofmeyr35ba85c2018-02-12 16:47:40 +0100573 uint8_t meas_rep_last_seen_nr;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100574
575 /* GSM Random Access data */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200576 /* TODO: don't allocate this, rather keep an "is_present" flag */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100577 struct gsm48_req_ref *rqd_ref;
578
579 struct gsm_subscriber_connection *conn;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100580};
581
Neels Hofmeyr10485162018-02-13 23:22:03 +0100582/* One Timeslot in a TRX */
583struct gsm_bts_trx_ts {
584 struct gsm_bts_trx *trx;
585 /* number of this timeslot at the TRX */
586 uint8_t nr;
587
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200588 struct osmo_fsm_inst *fi;
589 char *last_errmsg;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100590
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200591 /* vty phys_chan_config setting, not necessarily in effect in case it was changed in the telnet
592 * vty after OML activation. Gets written on vty 'write file'. */
593 enum gsm_phys_chan_config pchan_from_config;
594 /* When the timeslot OML is established, pchan_from_config is copied here. This is the pchan
595 * currently in effect; for dynamic ts, this is the dyn kind (GSM_PCHAN_TCH_F_TCH_H_PDCH or
596 * GSM_PCHAN_TCH_F_PDCH) and does not show the pchan type currently active. */
597 enum gsm_phys_chan_config pchan_on_init;
598 /* This is the *actual* pchan type currently active. For dynamic timeslots, this reflects either
599 * GSM_PCHAN_NONE or one of the standard GSM_PCHAN_TCH_F, GSM_PCHAN_TCH_H, GSM_PCHAN_PDCH.
600 * Callers can use this transparently without being aware of dyn ts. */
601 enum gsm_phys_chan_config pchan_is;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100602
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200603 /* After a PDCH ACT NACK, we shall not infinitely loop to try and ACT again.
604 * Also marks a timeslot where PDCH was deactivated by VTY. This is cleared whenever a timeslot
605 * enters IN_USE state, i.e. after each TCH use we try to PDCH ACT once again. */
606 bool pdch_act_allowed;
607
Neels Hofmeyrbcdbfb72018-07-26 20:33:15 +0200608 /* Whether TS_EV_OML_READY was received */
609 bool is_oml_ready;
610 /* Whether TS_EV_RSL_READY was received */
611 bool is_rsl_ready;
612
Neels Hofmeyr10485162018-02-13 23:22:03 +0100613 struct gsm_abis_mo mo;
614 struct tlv_parsed nm_attr;
615 uint8_t nm_chan_comb;
616 int tsc; /* -1 == use BTS TSC */
617
618 struct {
619 /* Parameters below are configured by VTY */
620 int enabled;
621 uint8_t maio;
622 uint8_t hsn;
623 struct bitvec arfcns;
624 uint8_t arfcns_data[1024/8];
625 /* This is the pre-computed MA for channel assignments */
626 struct bitvec ma;
627 uint8_t ma_len; /* part of ma_data that is used */
628 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
629 } hopping;
630
631 /* To which E1 subslot are we connected */
632 struct gsm_e1_subslot e1_link;
633
634 union {
635 struct {
636 struct om2k_mo om2k_mo;
637 } rbs2000;
638 };
639
640 struct gsm_lchan lchan[TS_MAX_LCHAN];
641};
642
643/* One TRX in a BTS */
644struct gsm_bts_trx {
645 /* list header in bts->trx_list */
646 struct llist_head list;
647
648 struct gsm_bts *bts;
649 /* number of this TRX in the BTS */
650 uint8_t nr;
651 /* human readable name / description */
652 char *description;
653 /* how do we talk RSL with this TRX? */
654 struct gsm_e1_subslot rsl_e1_link;
655 uint8_t rsl_tei;
656 struct e1inp_sign_link *rsl_link;
657
658 /* Timeout for initiating the RSL connection. */
659 struct osmo_timer_list rsl_connect_timeout;
660
661 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
662 struct e1inp_sign_link *oml_link;
663
664 struct gsm_abis_mo mo;
665 struct tlv_parsed nm_attr;
666 struct {
667 struct gsm_abis_mo mo;
668 } bb_transc;
669
670 uint16_t arfcn;
671 int nominal_power; /* in dBm */
672 unsigned int max_power_red; /* in actual dB */
673
674 union {
675 struct {
676 struct {
677 struct gsm_abis_mo mo;
678 } bbsig;
679 struct {
680 struct gsm_abis_mo mo;
681 } pa;
682 } bs11;
683 struct {
684 unsigned int test_state;
685 uint8_t test_nr;
686 struct rxlev_stats rxlev_stat;
687 } ipaccess;
688 struct {
689 struct {
690 struct om2k_mo om2k_mo;
691 } trxc;
692 struct {
693 struct om2k_mo om2k_mo;
694 } rx;
695 struct {
696 struct om2k_mo om2k_mo;
697 } tx;
698 } rbs2000;
699 };
700 struct gsm_bts_trx_ts ts[TRX_NR_TS];
701};
702
703#define GSM_BTS_SI2Q(bts, i) (struct gsm48_system_information_type_2quater *)((bts)->si_buf[SYSINFO_TYPE_2quater][i])
704#define GSM_BTS_HAS_SI(bts, i) ((bts)->si_valid & (1 << i))
705#define GSM_BTS_SI(bts, i) (void *)((bts)->si_buf[i][0])
706#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
707
708enum gsm_bts_type {
709 GSM_BTS_TYPE_UNKNOWN,
710 GSM_BTS_TYPE_BS11,
711 GSM_BTS_TYPE_NANOBTS,
712 GSM_BTS_TYPE_RBS2000,
713 GSM_BTS_TYPE_NOKIA_SITE,
714 GSM_BTS_TYPE_OSMOBTS,
715 _NUM_GSM_BTS_TYPE
716};
717
718enum gsm_bts_type_variant {
719 BTS_UNKNOWN,
720 BTS_OSMO_LITECELL15,
721 BTS_OSMO_OCTPHY,
722 BTS_OSMO_SYSMO,
723 BTS_OSMO_TRX,
724 _NUM_BTS_VARIANT
725};
726
727/* Used by OML layer for BTS Attribute reporting */
728enum bts_attribute {
729 BTS_TYPE_VARIANT,
730 BTS_SUB_MODEL,
731 TRX_PHY_VERSION,
732};
733
734struct vty;
735
736struct gsm_bts_model {
737 struct llist_head list;
738
739 enum gsm_bts_type type;
740 enum gsm_bts_type_variant variant;
741 const char *name;
742
743 bool started;
744 int (*start)(struct gsm_network *net);
745 int (*oml_rcvmsg)(struct msgb *msg);
746 char * (*oml_status)(const struct gsm_bts *bts);
747
748 void (*e1line_bind_ops)(struct e1inp_line *line);
749
750 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
751 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
752 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
753
754 struct tlv_definition nm_att_tlvdef;
755
756 /* features of a given BTS model set via gsm_bts_model_register() locally */
757 struct bitvec features;
758 uint8_t _features_data[MAX_BTS_FEATURES/8];
759};
760
Neels Hofmeyr10485162018-02-13 23:22:03 +0100761
Neels Hofmeyr10485162018-02-13 23:22:03 +0100762
763/*
764 * This keeps track of the paging status of one BTS. It
765 * includes a number of pending requests, a back pointer
766 * to the gsm_bts, a timer and some more state.
767 */
768struct gsm_bts_paging_state {
769 /* pending requests */
770 struct llist_head pending_requests;
771 struct gsm_bts *bts;
772
773 struct osmo_timer_list work_timer;
774 struct osmo_timer_list credit_timer;
775
776 /* free chans needed */
777 int free_chans_need;
778
779 /* load */
780 uint16_t available_slots;
781};
782
783struct gsm_envabtse {
784 struct gsm_abis_mo mo;
785};
786
787struct gsm_bts_gprs_nsvc {
788 struct gsm_bts *bts;
789 /* data read via VTY config file, to configure the BTS
790 * via OML from BSC */
791 int id;
792 uint16_t nsvci;
793 uint16_t local_port; /* on the BTS */
794 uint16_t remote_port; /* on the SGSN */
795 uint32_t remote_ip; /* on the SGSN */
796
797 struct gsm_abis_mo mo;
798};
799
800enum gprs_rlc_par {
801 RLC_T3142,
802 RLC_T3169,
803 RLC_T3191,
804 RLC_T3193,
805 RLC_T3195,
806 RLC_N3101,
807 RLC_N3103,
808 RLC_N3105,
809 CV_COUNTDOWN,
810 T_DL_TBF_EXT, /* ms */
811 T_UL_TBF_EXT, /* ms */
812 _NUM_RLC_PAR
813};
814
815enum gprs_cs {
816 GPRS_CS1,
817 GPRS_CS2,
818 GPRS_CS3,
819 GPRS_CS4,
820 GPRS_MCS1,
821 GPRS_MCS2,
822 GPRS_MCS3,
823 GPRS_MCS4,
824 GPRS_MCS5,
825 GPRS_MCS6,
826 GPRS_MCS7,
827 GPRS_MCS8,
828 GPRS_MCS9,
829 _NUM_GRPS_CS
830};
831
832struct gprs_rlc_cfg {
833 uint16_t parameter[_NUM_RLC_PAR];
834 struct {
835 uint16_t repeat_time; /* ms */
836 uint8_t repeat_count;
837 } paging;
838 uint32_t cs_mask; /* bitmask of gprs_cs */
839 uint8_t initial_cs;
840 uint8_t initial_mcs;
841};
842
843
844enum neigh_list_manual_mode {
845 NL_MODE_AUTOMATIC = 0,
846 NL_MODE_MANUAL = 1,
847 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
848};
849
850enum bts_loc_fix {
851 BTS_LOC_FIX_INVALID = 0,
852 BTS_LOC_FIX_2D = 1,
853 BTS_LOC_FIX_3D = 2,
854};
855
856extern const struct value_string bts_loc_fix_names[];
857
858struct bts_location {
859 struct llist_head list;
860 time_t tstamp;
861 enum bts_loc_fix valid;
862 double lat;
863 double lon;
864 double height;
865};
866
867/* Channel load counter */
868struct load_counter {
869 unsigned int total;
870 unsigned int used;
871};
872
Neels Hofmeyr19bed232018-03-22 04:54:57 +0100873/* Useful to track N-N relations between BTS, for example neighbors. */
874struct gsm_bts_ref {
875 struct llist_head entry;
876 struct gsm_bts *bts;
877};
878
Neels Hofmeyr10485162018-02-13 23:22:03 +0100879/* One BTS */
880struct gsm_bts {
881 /* list header in net->bts_list */
882 struct llist_head list;
883
884 /* Geographical location of the BTS */
885 struct llist_head loc_list;
886
887 /* number of ths BTS in network */
888 uint8_t nr;
889 /* human readable name / description */
890 char *description;
891 /* Cell Identity */
892 uint16_t cell_identity;
893 /* location area code of this BTS */
894 uint16_t location_area_code;
895 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
896 * which is used as TSC for the CCCH */
897 uint8_t bsic;
898 /* type of BTS */
899 enum gsm_bts_type type;
900 enum gsm_bts_type_variant variant;
901 struct gsm_bts_model *model;
902 enum gsm_band band;
903 char version[MAX_VERSION_LENGTH];
904 char sub_model[MAX_VERSION_LENGTH];
905
906 /* features of a given BTS set/reported via OML */
907 struct bitvec features;
908 uint8_t _features_data[MAX_BTS_FEATURES/8];
909
910 /* Connected PCU version (if any) */
911 char pcu_version[MAX_VERSION_LENGTH];
912
913 /* maximum Tx power that the MS is permitted to use in this cell */
914 int ms_max_power;
915
916 /* how do we talk OML with this TRX? */
917 struct gsm_e1_subslot oml_e1_link;
918 uint8_t oml_tei;
919 struct e1inp_sign_link *oml_link;
920 /* when OML link was established */
921 time_t uptime;
922
923 /* Abis network management O&M handle */
924 struct abis_nm_h *nmh;
925
926 struct gsm_abis_mo mo;
927
928 /* number of this BTS on given E1 link */
929 uint8_t bts_nr;
930
931 /* DTX features of this BTS */
932 enum gsm48_dtx_mode dtxu;
933 bool dtxd;
934
935 /* paging state and control */
936 struct gsm_bts_paging_state paging;
937
938 /* CCCH is on C0 */
939 struct gsm_bts_trx *c0;
940
941 struct {
942 struct gsm_abis_mo mo;
943 } site_mgr;
944
945 /* bitmask of all SI that are present/valid in si_buf */
946 uint32_t si_valid;
947 /* 3GPP TS 44.018 Table 10.5.2.33b.1 INDEX and COUNT for SI2quater */
948 uint8_t si2q_index; /* distinguish individual SI2quater messages */
949 uint8_t si2q_count; /* si2q_index for the last (highest indexed) individual SI2quater message */
950 /* buffers where we put the pre-computed SI */
951 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
952 /* offsets used while generating SI2quater */
953 size_t e_offset;
954 size_t u_offset;
955
956 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
957 union {
958 struct {
959 uint16_t site_id;
960 uint16_t bts_id;
961 uint32_t flags;
962 uint32_t rsl_ip;
963 } ip_access;
964 struct {
965 struct {
966 struct gsm_abis_mo mo;
967 } cclk;
968 struct {
969 struct gsm_abis_mo mo;
970 } rack;
971 struct gsm_envabtse envabtse[4];
972 } bs11;
973 struct {
974 struct {
975 struct om2k_mo om2k_mo;
976 struct gsm_abis_mo mo;
977 struct llist_head conn_groups;
978 } cf;
979 struct {
980 struct om2k_mo om2k_mo;
981 struct gsm_abis_mo mo;
982 struct llist_head conn_groups;
983 } is;
984 struct {
985 struct om2k_mo om2k_mo;
986 struct gsm_abis_mo mo;
987 struct llist_head conn_groups;
988 } con;
989 struct {
990 struct om2k_mo om2k_mo;
991 struct gsm_abis_mo mo;
992 } dp;
993 struct {
994 struct om2k_mo om2k_mo;
995 struct gsm_abis_mo mo;
996 } tf;
997 uint32_t use_superchannel:1;
998 } rbs2000;
999 struct {
1000 uint8_t bts_type;
1001 unsigned int configured:1,
1002 skip_reset:1,
1003 no_loc_rel_cnf:1,
1004 bts_reset_timer_cnf,
1005 did_reset:1,
1006 wait_reset:1;
1007 struct osmo_timer_list reset_timer;
1008 } nokia;
1009 };
1010
1011 /* Not entirely sure how ip.access specific this is */
1012 struct {
1013 uint8_t supports_egprs_11bit_rach;
1014 enum bts_gprs_mode mode;
1015 struct {
1016 struct gsm_abis_mo mo;
1017 uint16_t nsei;
1018 uint8_t timer[7];
1019 } nse;
1020 struct {
1021 struct gsm_abis_mo mo;
1022 uint16_t bvci;
1023 uint8_t timer[11];
1024 struct gprs_rlc_cfg rlc_cfg;
1025 } cell;
1026 struct gsm_bts_gprs_nsvc nsvc[2];
1027 uint8_t rac;
1028 uint8_t net_ctrl_ord;
1029 bool ctrl_ack_type_use_block;
1030 } gprs;
1031
1032 /* RACH NM values */
1033 int rach_b_thresh;
1034 int rach_ldavg_slots;
1035
1036 /* transceivers */
1037 int num_trx;
1038 struct llist_head trx_list;
1039
1040 /* SI related items */
1041 int force_combined_si;
1042 int bcch_change_mark;
1043
1044 /* Abis NM queue */
1045 struct llist_head abis_queue;
1046 int abis_nm_pend;
1047
1048 struct gsm_network *network;
1049
1050 /* should the channel allocator allocate channels from high TRX to TRX0,
1051 * rather than starting from TRX0 and go upwards? */
1052 int chan_alloc_reverse;
1053
1054 enum neigh_list_manual_mode neigh_list_manual_mode;
1055 /* parameters from which we build SYSTEM INFORMATION */
1056 struct {
1057 struct gsm48_rach_control rach_control;
1058 uint8_t ncc_permitted;
1059 struct gsm48_cell_sel_par cell_sel_par;
1060 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
1061 struct gsm48_cell_options cell_options;
1062 struct gsm48_control_channel_descr chan_desc;
1063 struct bitvec neigh_list;
1064 struct bitvec cell_alloc;
1065 struct bitvec si5_neigh_list;
1066 struct osmo_earfcn_si2q si2quater_neigh_list;
1067 size_t uarfcn_length; /* index for uarfcn and scramble lists */
1068 struct {
1069 /* bitmask large enough for all possible ARFCN's */
1070 uint8_t neigh_list[1024/8];
1071 uint8_t cell_alloc[1024/8];
1072 /* If the user wants a different neighbor list in SI5 than in SI2 */
1073 uint8_t si5_neigh_list[1024/8];
1074 uint8_t meas_bw_list[MAX_EARFCN_LIST];
1075 uint16_t earfcn_list[MAX_EARFCN_LIST];
1076 uint16_t uarfcn_list[MAX_EARFCN_LIST];
1077 uint16_t scramble_list[MAX_EARFCN_LIST];
1078 } data;
1079 } si_common;
1080 bool early_classmark_allowed;
1081 bool early_classmark_allowed_3g;
1082 /* for testing only: Have an infinitely long radio link timeout */
1083 bool infinite_radio_link_timeout;
1084
1085 /* do we use static (user-defined) system information messages? (bitmask) */
1086 uint32_t si_mode_static;
1087
Stefan Sperling6442e432018-02-06 14:44:54 +01001088 /* access control class ramping */
1089 struct acc_ramp acc_ramp;
1090
Neels Hofmeyr10485162018-02-13 23:22:03 +01001091 /* exclude the BTS from the global RF Lock handling */
1092 int excl_from_rf_lock;
1093
1094 /* supported codecs beside FR */
1095 struct bts_codec_conf codec;
1096
1097 /* BTS dependencies bit field */
1098 uint32_t depends_on[256/(8*4)];
1099
1100 /* full and half rate multirate config */
1101 struct amr_multirate_conf mr_full;
1102 struct amr_multirate_conf mr_half;
1103
1104 /* PCU socket state */
1105 char *pcu_sock_path;
1106 struct pcu_sock_state *pcu_state;
1107
1108 struct rate_ctr_group *bts_ctrs;
1109 struct osmo_stat_item_group *bts_statg;
1110
1111 struct handover_cfg *ho;
1112
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001113 /* A list of struct gsm_bts_ref, indicating neighbors of this BTS.
1114 * When the si_common neigh_list is in automatic mode, it is populated from this list as well as
1115 * gsm_network->neighbor_bss_cells. */
1116 struct llist_head local_neighbors;
1117
Neels Hofmeyr10485162018-02-13 23:22:03 +01001118 /* BTS-specific overrides for timer values from struct gsm_network. */
1119 uint8_t T3122; /* ASSIGMENT REJECT wait indication */
1120
1121 /* Periodic channel load measurements are used to maintain T3122. */
1122 struct load_counter chan_load_samples[7];
1123 int chan_load_samples_idx;
Stefan Sperling6442e432018-02-06 14:44:54 +01001124 uint8_t chan_load_avg; /* current channel load average in percent (0 - 100). */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001125};
1126
1127
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001128struct gsm_network *gsm_network_init(void *ctx);
1129
Neels Hofmeyr10485162018-02-13 23:22:03 +01001130struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, uint8_t bts_num);
1131struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001132bool gsm_bts_matches_lai(const struct gsm_bts *bts, const struct osmo_location_area_id *lai);
1133bool gsm_bts_matches_cell_id(const struct gsm_bts *bts, const struct gsm0808_cell_id *cell_id);
1134struct gsm_bts *gsm_bts_by_cell_id(const struct gsm_network *net,
1135 const struct gsm0808_cell_id *cell_id,
1136 int match_idx);
1137int gsm_bts_local_neighbor_add(struct gsm_bts *bts, struct gsm_bts *neighbor);
1138int gsm_bts_local_neighbor_del(struct gsm_bts *bts, const struct gsm_bts *neighbor);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001139
1140struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
1141struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
1142
1143enum gsm_bts_type str2btstype(const char *arg);
1144const char *btstype2str(enum gsm_bts_type type);
1145
1146enum bts_attribute str2btsattr(const char *s);
1147const char *btsatttr2str(enum bts_attribute v);
1148
1149enum gsm_bts_type_variant str2btsvariant(const char *arg);
1150const char *btsvariant2str(enum gsm_bts_type_variant v);
1151
1152extern const struct value_string gsm_chreq_descs[];
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001153extern const struct value_string gsm_pchant_names[];
1154extern const struct value_string gsm_pchant_descs[];
1155extern const struct value_string gsm_pchan_ids[];
Neels Hofmeyr10485162018-02-13 23:22:03 +01001156const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001157static inline const char *gsm_pchan_id(enum gsm_phys_chan_config c)
1158{ return get_value_string(gsm_pchan_ids, c); }
Neels Hofmeyr10485162018-02-13 23:22:03 +01001159enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
1160const char *gsm_lchant_name(enum gsm_chan_t c);
1161const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
1162char *gsm_trx_name(const struct gsm_bts_trx *trx);
1163char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
1164char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
1165char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001166
1167static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
1168{
1169 return lchan->name;
1170}
1171
Neels Hofmeyr10485162018-02-13 23:22:03 +01001172void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
1173
1174struct gsm_nm_state *
1175gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
1176 const struct abis_om_obj_inst *obj_inst);
1177void *
1178gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
1179 const struct abis_om_obj_inst *obj_inst);
1180
1181/* reset the state of all MO in the BTS */
1182void gsm_bts_mo_reset(struct gsm_bts *bts);
1183
1184uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
1185 uint8_t ts_nr, uint8_t lchan_nr);
1186uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
1187uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
1188 enum gsm_phys_chan_config as_pchan);
1189
1190/* return the gsm_lchan for the CBCH (if it exists at all) */
1191struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
1192
1193/*
1194 * help with parsing regexps
1195 */
1196int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
1197 int argc, const char **argv) __attribute__ ((warn_unused_result));
1198
1199static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
1200{
1201 if (ts->tsc != -1)
1202 return ts->tsc;
1203 else
1204 return ts->trx->bts->bsic & 7;
1205}
1206
1207struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
1208 int *rc);
1209
1210enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001211uint8_t pchan_subslots(enum gsm_phys_chan_config pchan);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001212bool ts_is_tch(struct gsm_bts_trx_ts *ts);
1213
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01001214
Harald Welteb7948872017-12-18 18:48:21 +01001215static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection *conn) {
1216 OSMO_ASSERT(conn->lchan);
1217 return conn->lchan->ts->trx->bts;
1218}
1219
Harald Welted82101e2017-12-09 23:07:38 +01001220enum {
1221 BTS_CTR_CHREQ_TOTAL,
1222 BTS_CTR_CHREQ_NO_CHANNEL,
1223 BTS_CTR_CHAN_RF_FAIL,
1224 BTS_CTR_CHAN_RLL_ERR,
1225 BTS_CTR_BTS_OML_FAIL,
1226 BTS_CTR_BTS_RSL_FAIL,
1227 BTS_CTR_CODEC_AMR_F,
1228 BTS_CTR_CODEC_AMR_H,
1229 BTS_CTR_CODEC_EFR,
1230 BTS_CTR_CODEC_V1_FR,
1231 BTS_CTR_CODEC_V1_HR,
Harald Weltecf9d4312017-12-13 23:17:16 +01001232 BTS_CTR_PAGING_ATTEMPTED,
1233 BTS_CTR_PAGING_ALREADY,
1234 BTS_CTR_PAGING_RESPONDED,
1235 BTS_CTR_PAGING_EXPIRED,
Harald Welte4f598922017-12-14 13:47:02 +01001236 BTS_CTR_CHAN_ACT_TOTAL,
1237 BTS_CTR_CHAN_ACT_NACK,
Harald Welte62d9cb02017-12-14 14:00:26 +01001238 BTS_CTR_RSL_UNKNOWN,
Harald Welte581398a2017-12-14 14:29:44 +01001239 BTS_CTR_RSL_IPA_NACK,
Harald Welte00d64fd2017-12-14 14:34:16 +01001240 BTS_CTR_MODE_MODIFY_NACK,
Harald Welted82101e2017-12-09 23:07:38 +01001241};
1242
1243static const struct rate_ctr_desc bts_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001244 [BTS_CTR_CHREQ_TOTAL] = {"chreq:total", "Received channel requests."},
1245 [BTS_CTR_CHREQ_NO_CHANNEL] = {"chreq:no_channel", "Sent to MS no channel available."},
1246 [BTS_CTR_CHAN_RF_FAIL] = {"chan:rf_fail", "Received a RF failure indication from BTS."},
1247 [BTS_CTR_CHAN_RLL_ERR] = {"chan:rll_err", "Received a RLL failure with T200 cause from BTS."},
Harald Welted82101e2017-12-09 23:07:38 +01001248 [BTS_CTR_BTS_OML_FAIL] = {"oml_fail", "Received a TEI down on a OML link."},
1249 [BTS_CTR_BTS_RSL_FAIL] = {"rsl_fail", "Received a TEI down on a OML link."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001250 [BTS_CTR_CODEC_AMR_F] = {"codec:amr_f", "Count the usage of AMR/F codec by channel mode requested."},
1251 [BTS_CTR_CODEC_AMR_H] = {"codec:amr_h", "Count the usage of AMR/H codec by channel mode requested."},
1252 [BTS_CTR_CODEC_EFR] = {"codec:efr", "Count the usage of EFR codec by channel mode requested."},
1253 [BTS_CTR_CODEC_V1_FR] = {"codec:fr", "Count the usage of FR codec by channel mode requested."},
1254 [BTS_CTR_CODEC_V1_HR] = {"codec:hr", "Count the usage of HR codec by channel mode requested."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001255
1256 [BTS_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
1257 [BTS_CTR_PAGING_ALREADY] = {"paging:already", "Paging attempts ignored as subsciber was already being paged."},
1258 [BTS_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful paging response."},
1259 [BTS_CTR_PAGING_EXPIRED] = {"paging:expired", "Paging Request expired because of timeout T3113."},
Harald Welte4f598922017-12-14 13:47:02 +01001260 [BTS_CTR_CHAN_ACT_TOTAL] = {"chan_act:total", "Total number of Channel Activations."},
1261 [BTS_CTR_CHAN_ACT_NACK] = {"chan_act:nack", "Number of Channel Activations that the BTS NACKed"},
Harald Welte62d9cb02017-12-14 14:00:26 +01001262 [BTS_CTR_RSL_UNKNOWN] = {"rsl:unknown", "Number of unknown/unsupported RSL messages received from BTS"},
Harald Welte581398a2017-12-14 14:29:44 +01001263 [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 +01001264 [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 +01001265};
1266
1267static const struct rate_ctr_group_desc bts_ctrg_desc = {
1268 "bts",
1269 "base transceiver station",
1270 OSMO_STATS_CLASS_GLOBAL,
1271 ARRAY_SIZE(bts_ctr_description),
1272 bts_ctr_description,
1273};
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001274
Alexander Couzens20423ea2016-07-12 15:42:02 +02001275enum {
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001276 BTS_STAT_CHAN_LOAD_AVERAGE,
1277 BTS_STAT_T3122,
1278};
1279
1280enum {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001281 BSC_CTR_ASSIGNMENT_ATTEMPTED,
1282 BSC_CTR_ASSIGNMENT_COMPLETED,
1283 BSC_CTR_ASSIGNMENT_STOPPED,
1284 BSC_CTR_ASSIGNMENT_NO_CHANNEL,
1285 BSC_CTR_ASSIGNMENT_TIMEOUT,
1286 BSC_CTR_ASSIGNMENT_FAILED,
1287 BSC_CTR_ASSIGNMENT_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001288 BSC_CTR_HANDOVER_ATTEMPTED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001289 BSC_CTR_HANDOVER_COMPLETED,
1290 BSC_CTR_HANDOVER_STOPPED,
Alexander Couzensb847a212016-08-02 11:34:11 +02001291 BSC_CTR_HANDOVER_NO_CHANNEL,
1292 BSC_CTR_HANDOVER_TIMEOUT,
Alexander Couzensb847a212016-08-02 11:34:11 +02001293 BSC_CTR_HANDOVER_FAILED,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001294 BSC_CTR_HANDOVER_ERROR,
1295 BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED,
1296 BSC_CTR_INTER_BSC_HO_OUT_COMPLETED,
1297 BSC_CTR_INTER_BSC_HO_OUT_STOPPED,
1298 BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT,
1299 BSC_CTR_INTER_BSC_HO_OUT_ERROR,
1300 BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED,
1301 BSC_CTR_INTER_BSC_HO_IN_COMPLETED,
1302 BSC_CTR_INTER_BSC_HO_IN_STOPPED,
1303 BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL,
1304 BSC_CTR_INTER_BSC_HO_IN_FAILED,
1305 BSC_CTR_INTER_BSC_HO_IN_TIMEOUT,
1306 BSC_CTR_INTER_BSC_HO_IN_ERROR,
Alexander Couzensb847a212016-08-02 11:34:11 +02001307 BSC_CTR_PAGING_ATTEMPTED,
1308 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +01001309 BSC_CTR_PAGING_RESPONDED,
Stefan Sperling7926d982018-05-17 14:52:02 +02001310 BSC_CTR_UNKNOWN_UNIT_ID,
Alexander Couzensb847a212016-08-02 11:34:11 +02001311};
1312
1313static const struct rate_ctr_desc bsc_ctr_description[] = {
Neels Hofmeyrdbb38d52018-07-11 19:53:56 +02001314 [BSC_CTR_ASSIGNMENT_ATTEMPTED] = {"assignment:attempted", "Assignment attempts."},
1315 [BSC_CTR_ASSIGNMENT_COMPLETED] = {"assignment:completed", "Assignment completed."},
1316 [BSC_CTR_ASSIGNMENT_STOPPED] = {"assignment:stopped", "Connection ended during Assignment."},
1317 [BSC_CTR_ASSIGNMENT_NO_CHANNEL] = {"assignment:no_channel", "Failure to allocate lchan for Assignment."},
1318 [BSC_CTR_ASSIGNMENT_TIMEOUT] = {"assignment:timeout", "Assignment timed out."},
1319 [BSC_CTR_ASSIGNMENT_FAILED] = {"assignment:failed", "Received Assignment Failure message."},
1320 [BSC_CTR_ASSIGNMENT_ERROR] = {"assignment:error", "Assigment failed for other reason."},
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001321
1322 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Intra-BSC handover attempts."},
1323 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Intra-BSC handover completed."},
1324 [BSC_CTR_HANDOVER_STOPPED] = {"handover:stopped", "Connection ended during HO."},
1325 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Failure to allocate lchan for HO."},
1326 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Handover timed out."},
1327 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Received Handover Fail messages."},
1328 [BSC_CTR_HANDOVER_ERROR] = {"handover:error", "Re-assigment failed for other reason."},
1329
1330 [BSC_CTR_INTER_BSC_HO_OUT_ATTEMPTED] = {"interbsc_ho_out:attempted",
1331 "Attempts to handover to remote BSS."},
1332 [BSC_CTR_INTER_BSC_HO_OUT_COMPLETED] = {"interbsc_ho_out:completed",
1333 "Handover to remote BSS completed."},
1334 [BSC_CTR_INTER_BSC_HO_OUT_STOPPED] = {"interbsc_ho_out:stopped", "Connection ended during HO."},
1335 [BSC_CTR_INTER_BSC_HO_OUT_TIMEOUT] = {"interbsc_ho_out:timeout", "Handover timed out."},
1336 [BSC_CTR_INTER_BSC_HO_OUT_ERROR] = {"interbsc_ho_out:error",
1337 "Handover to remote BSS failed for other reason."},
1338
1339 [BSC_CTR_INTER_BSC_HO_IN_ATTEMPTED] = {"interbsc_ho_in:attempted",
1340 "Attempts to handover from remote BSS."},
1341 [BSC_CTR_INTER_BSC_HO_IN_COMPLETED] = {"interbsc_ho_in:completed",
1342 "Handover from remote BSS completed."},
1343 [BSC_CTR_INTER_BSC_HO_IN_STOPPED] = {"interbsc_ho_in:stopped", "Connection ended during HO."},
1344 [BSC_CTR_INTER_BSC_HO_IN_NO_CHANNEL] = {"interbsc_ho_in:no_channel",
1345 "Failure to allocate lchan for HO."},
1346 [BSC_CTR_INTER_BSC_HO_IN_TIMEOUT] = {"interbsc_ho_in:timeout", "Handover from remote BSS timed out."},
1347 [BSC_CTR_INTER_BSC_HO_IN_FAILED] = {"interbsc_ho_in:failed", "Received Handover Fail message."},
1348 [BSC_CTR_INTER_BSC_HO_IN_ERROR] = {"interbsc_ho_in:error",
1349 "Handover from remote BSS failed for other reason."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001350
1351 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001352 [BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Paging request send failures because no responsible BTS was found."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001353 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response."},
Stefan Sperling7926d982018-05-17 14:52:02 +02001354
1355 [BSC_CTR_UNKNOWN_UNIT_ID] = {"abis:unknown_unit_id", "Connection attempts from unknown IPA CCM Unit ID."},
Alexander Couzensb847a212016-08-02 11:34:11 +02001356};
1357
Alexander Couzensb847a212016-08-02 11:34:11 +02001358
1359
1360static const struct rate_ctr_group_desc bsc_ctrg_desc = {
1361 "bsc",
1362 "base station controller",
1363 OSMO_STATS_CLASS_GLOBAL,
1364 ARRAY_SIZE(bsc_ctr_description),
1365 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +02001366};
1367
Neels Hofmeyr73983952016-05-10 13:29:33 +02001368struct gsm_tz {
1369 int override; /* if 0, use system's time zone instead. */
1370 int hr; /* hour */
1371 int mn; /* minute */
1372 int dst; /* daylight savings */
1373};
1374
Harald Welte52b1f982008-12-23 20:25:15 +00001375struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001376 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
1377 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
1378 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
1379 * these have in common, like country and network code, put in yet
1380 * separate structs and placed as members in osmo_bsc and osmo_msc. */
1381
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001382 struct osmo_plmn_id plmn;
1383
Harald Welte51e4bf32017-12-23 17:30:18 +01001384 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
1385 uint8_t a5_encryption_mask;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001386 int neci;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001387
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001388 struct handover_cfg *ho;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001389 struct {
1390 unsigned int congestion_check_interval_s;
1391 struct osmo_timer_list congestion_check_timer;
1392 } hodec2;
Harald Welte52b1f982008-12-23 20:25:15 +00001393
Alexander Couzensb847a212016-08-02 11:34:11 +02001394 struct rate_ctr_group *bsc_ctrs;
Harald Welte24ff6ee2009-12-22 00:41:05 +01001395
Harald Welte52b1f982008-12-23 20:25:15 +00001396 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +02001397 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001398
Neels Hofmeyr596c4022018-06-16 19:29:50 +02001399 /* shall reference gsm_network_T[] */
1400 struct T_def *T_defs;
Harald Welteeab84a12009-12-13 10:53:12 +01001401
Alexander Couzens547c2072017-11-21 12:03:04 +01001402 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +08001403
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +08001404 /* Use a TCH for handling requests of type paging any */
1405 int pag_any_tch;
1406
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08001407 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +02001408 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +01001409
Daniel Willmann6fc4a982011-07-22 17:55:42 +02001410 /* control interface */
1411 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +02001412
1413 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
1414 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +02001415
1416 /* all active subscriber connections. */
1417 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +02001418
1419 /* if override is nonzero, this timezone data is used for all MM
1420 * contexts. */
1421 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
1422 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +01001423 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +02001424 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +01001425
1426 /* List of all struct bsc_subscr used in libbsc. This llist_head is
1427 * allocated so that the llist_head pointer itself can serve as a
1428 * talloc context (useful to not have to pass the entire gsm_network
1429 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
1430 * not require gsm_data.h). In an MSC-without-BSC environment, this
1431 * pointer is NULL to indicate absence of a bsc_subscribers list. */
1432 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +02001433
Stefan Sperling6cee8932018-01-30 18:14:22 +01001434 /* Timer for periodic channel load measurements to maintain each BTS's T3122. */
1435 struct osmo_timer_list t3122_chan_load_timer;
1436
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001437 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +02001438 struct mgcp_client_conf *conf;
1439 struct mgcp_client *client;
1440 } mgw;
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001441
1442 /* Remote BSS Cell Identifier Lists */
1443 struct neighbor_ident_list *neighbor_bss_cells;
Harald Welte7e310b12009-03-30 20:56:32 +00001444};
1445
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001446struct gsm_audio_support {
1447 uint8_t hr : 1,
1448 ver : 7;
1449};
1450
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001451static inline const struct osmo_location_area_id *bts_lai(struct gsm_bts *bts)
1452{
1453 static struct osmo_location_area_id lai;
1454 lai = (struct osmo_location_area_id){
1455 .plmn = bts->network->plmn,
1456 .lac = bts->location_area_code,
1457 };
1458 return &lai;
1459}
1460
Neels Hofmeyrc13e6872016-05-11 13:53:47 +02001461extern void talloc_ctx_init(void *ctx_root);
1462
Harald Welte39315c42010-01-10 18:01:52 +01001463int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +02001464
Harald Welte1d014a52009-08-08 15:38:29 +02001465enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +02001466const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +00001467struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
1468 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +00001469
Andreas Eversberg8226fa72009-06-29 15:19:38 +02001470extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +01001471extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +02001472
Harald Weltef383aa12012-07-02 19:51:55 +02001473/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +00001474static inline int is_ipaccess_bts(struct gsm_bts *bts)
1475{
1476 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001477 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001478 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +00001479 return 1;
1480 default:
1481 break;
1482 }
1483 return 0;
1484}
1485
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001486static inline int is_sysmobts_v2(struct gsm_bts *bts)
1487{
1488 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +01001489 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001490 return 1;
1491 default:
1492 break;
1493 }
1494 return 0;
1495}
1496
Harald Welte5b570672009-08-10 10:08:01 +02001497static inline int is_siemens_bts(struct gsm_bts *bts)
1498{
1499 switch (bts->type) {
1500 case GSM_BTS_TYPE_BS11:
1501 return 1;
1502 default:
1503 break;
1504 }
1505
1506 return 0;
1507}
1508
Andreas Eversberg7d8fa342013-12-05 13:25:06 +01001509static inline int is_nokia_bts(struct gsm_bts *bts)
1510{
1511 switch (bts->type) {
1512 case GSM_BTS_TYPE_NOKIA_SITE:
1513 return 1;
1514 default:
1515 break;
1516 }
1517
1518 return 0;
1519}
1520
Andreas Eversbergdcf38e12013-12-05 14:37:11 +01001521static inline int is_e1_bts(struct gsm_bts *bts)
1522{
1523 switch (bts->type) {
1524 case GSM_BTS_TYPE_BS11:
1525 case GSM_BTS_TYPE_RBS2000:
1526 case GSM_BTS_TYPE_NOKIA_SITE:
1527 return 1;
1528 default:
1529 break;
1530 }
1531
1532 return 0;
1533}
1534
Harald Welte1876c312018-05-27 11:53:43 +02001535extern struct gsm_network *bsc_gsmnet;
1536
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001537enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +02001538const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001539int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +02001540
Neels Hofmeyr4d358c02018-02-22 03:19:05 +01001541void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +08001542void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +01001543
Harald Weltefbda4e12010-03-04 11:04:52 +01001544int gsm_bts_model_register(struct gsm_bts_model *model);
1545
Harald Welte3561bd42018-01-28 03:04:16 +01001546struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *network);
Neels Hofmeyr42eb0142016-05-20 17:15:44 +02001547
1548struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
1549void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +08001550
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001551struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, uint8_t bsic);
1552struct 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 +01001553
Harald Welte3300c012011-06-05 13:31:33 +02001554void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
1555 uint8_t e1_ts, uint8_t e1_ts_ss);
1556
Maxbe356ed2017-09-07 19:10:09 +02001557void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Harald Welte3300c012011-06-05 13:31:33 +02001558struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +01001559int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -04001560int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +02001561
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +02001562/* generic E1 line operations for all ISDN-based BTS. */
1563extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
1564
Harald Weltee555c2b2012-08-17 13:02:12 +02001565extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
1566extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
1567
Max3d049d22017-10-09 17:12:53 +02001568char *get_model_oml_status(const struct gsm_bts *bts);
1569
Max25cc4072017-10-10 14:50:35 +02001570unsigned long long bts_uptime(const struct gsm_bts *bts);
1571
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +01001572/* control interface handling */
1573int bsc_base_ctrl_cmds_install(void);
1574
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001575/* dependency handling */
1576void bts_depend_mark(struct gsm_bts *bts, int dep);
1577void bts_depend_clear(struct gsm_bts *bts, int dep);
1578int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +01001579int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001580
Harald Welte2f8b9d22017-06-18 11:12:13 +03001581int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
1582void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
1583
Harald Weltea43e0b42016-06-19 18:06:02 +02001584bool classmark_is_r99(struct gsm_classmark *cm);
1585
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001586bool trx_is_usable(const struct gsm_bts_trx *trx);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001587bool ts_is_usable(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001588
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001589int gsm_lchan_type_by_pchan(enum gsm_phys_chan_config pchan);
1590enum gsm_phys_chan_config gsm_pchan_by_lchan_type(enum gsm_chan_t type);
1591
1592void gsm_bts_all_ts_dispatch(struct gsm_bts *bts, uint32_t ts_ev, void *data);
1593void gsm_trx_all_ts_dispatch(struct gsm_bts_trx *trx, uint32_t ts_ev, void *data);
1594
1595int bts_count_free_ts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan);
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001596
Harald Welte6be350c2011-05-25 13:10:08 +02001597#endif /* _GSM_DATA_H */