blob: b1fceb3ea8ce6df1c151189fe98fcdbd84e9c85e [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 Hofmeyrf93970b2018-03-05 02:09:40 +010017#include <osmocom/gsm/gsm48.h>
Harald Welte3561bd42018-01-28 03:04:16 +010018#include <osmocom/core/fsm.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020019
Harald Welte121e9a42016-04-20 13:13:19 +020020#include <osmocom/crypt/auth.h>
Harald Weltef142c972011-05-24 13:25:38 +020021
Neels Hofmeyrc0164792017-09-04 15:15:32 +020022#include <osmocom/bsc/rest_octets.h>
Harald Welte3561bd42018-01-28 03:04:16 +010023#include <osmocom/bsc/handover.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 Hofmeyr10485162018-02-13 23:22:03 +010034
Harald Welte74b8cdb2018-01-15 19:26:06 +010035struct mgcp_client_conf;
36struct mgcp_client;
37struct mgcp_ctx;
Philipp Maier39f62bb2017-04-09 12:32:51 +020038
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020039/** annotations for msgb ownership */
40#define __uses
41
Holger Hans Peter Freyther6f615552010-11-15 20:50:42 +010042#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
43
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010044struct bsc_subscr;
Neels Hofmeyr7b656882017-07-09 22:09:18 +020045struct gprs_ra_id;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020046
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080047#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
48
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010049#define tmsi_from_string(str) strtoul(str, NULL, 10)
50
Max70fdd242017-06-15 15:10:53 +020051/* 3-bit long values */
52#define EARFCN_PRIO_INVALID 8
53#define EARFCN_MEAS_BW_INVALID 8
54/* 5-bit long values */
55#define EARFCN_QRXLV_INVALID 32
56#define EARFCN_THRESH_LOW_INVALID 32
57
Harald Welte8e1e3ee2009-02-01 13:32:45 +000058struct msgb;
59typedef int gsm_cbfn(unsigned int hooknum,
60 unsigned int event,
61 struct msgb *msg,
62 void *data, void *param);
63
Harald Weltef7c28b02009-12-21 13:30:17 +010064/* Maximum number of neighbor cells whose average we track */
65#define MAX_NEIGH_MEAS 10
66/* Maximum size of the averaging window for neighbor cells */
67#define MAX_WIN_NEIGH_AVG 10
Andreas Eversberg98692032013-06-23 10:44:34 +020068/* Maximum number of report history we store */
69#define MAX_MEAS_REP 10
Harald Weltef7c28b02009-12-21 13:30:17 +010070
71/* processed neighbor measurements for one cell */
72struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020073 uint16_t arfcn;
74 uint8_t bsic;
75 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +010076 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020077 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +010078};
79
Harald Weltea43e0b42016-06-19 18:06:02 +020080struct gsm_classmark {
81 bool classmark1_set;
82 struct gsm48_classmark1 classmark1;
83 uint8_t classmark2_len;
84 uint8_t classmark2[3];
85 uint8_t classmark3_len;
86 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
87};
88
Harald Welte519c7e12018-01-28 02:45:46 +010089enum subscr_sccp_state {
90 SUBSCR_SCCP_ST_NONE,
91 SUBSCR_SCCP_ST_WAIT_CONN_CONF,
92 SUBSCR_SCCP_ST_CONNECTED
93};
94
Neels Hofmeyr378a4922016-05-09 21:07:43 +020095/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010096struct gsm_subscriber_connection {
Harald Weltea43e0b42016-06-19 18:06:02 +020097 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +080098 struct llist_head entry;
99
Harald Welte3561bd42018-01-28 03:04:16 +0100100 /* FSM instance to control the subscriber connection state (RTP, A) */
101 struct osmo_fsm_inst *fi;
102
Harald Weltea43e0b42016-06-19 18:06:02 +0200103 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100104 struct bsc_subscr *bsub;
105
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100106 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200107 struct gsm_network *network;
108
Harald Welte4a8ebc82017-12-18 18:34:41 +0100109 /* the primary / currently active lchan to the BTS/subscriber */
110 struct gsm_lchan *lchan;
Harald Welte3561bd42018-01-28 03:04:16 +0100111
112 /* handover information, if a handover is pending for this conn. */
113 struct bsc_handover *ho;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100114
Harald Welte4a8ebc82017-12-18 18:34:41 +0100115 /* timer for assignment handling */
116 struct osmo_timer_list T10;
117 /* the future allocated but not yet used lchan during ASSIGNMENT */
118 struct gsm_lchan *secondary_lchan;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100119
Harald Welte4a8ebc82017-12-18 18:34:41 +0100120 /* buffer/cache for classmark of the ME of the subscriber */
Harald Weltea43e0b42016-06-19 18:06:02 +0200121 struct gsm_classmark classmark;
Andreas Eversberg935e5d72013-06-17 11:58:30 +0200122
123 /* Cache DTAP messages during handover/assignment (msgb_enqueue()/msgb_dequeue())*/
124 struct llist_head ho_dtap_cache;
125 unsigned int ho_dtap_cache_len;
Andreas Eversberg084b4212013-05-30 14:12:48 +0200126
Neels Hofmeyrec422642018-02-15 14:07:40 +0100127 struct {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100128 int failures;
Neels Hofmeyrec422642018-02-15 14:07:40 +0100129 struct penalty_timers *penalty_timers;
130 } hodec2;
Neels Hofmeyra60f3442018-02-12 16:44:32 +0100131
132 /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment Request. 3GPP 48.008
133 * 3.2.2.103 says:
134 * The "Codec List (MSC Preferred)" shall not include codecs
135 * that are not supported by the MS.
136 * i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed the MS bearer
137 * capabilities, which the MSC is required to translate into the codec list. */
138 struct gsm0808_speech_codec_list codec_list;
139 bool codec_list_present;
Harald Welte519c7e12018-01-28 02:45:46 +0100140
141 /* flag to prevent multiple simultaneous ciphering commands */
142 int ciphering_handled;
143
144 /* state related to welcome USSD */
145 uint8_t new_subscriber;
146
147 /* state related to osmo_bsc_filter.c */
148 struct bsc_filter_state filter_state;
149
150 /* SCCP connection associatd with this subscriber_connection */
151 struct {
152 /* for advanced ping/pong */
153 int send_ping;
154
155 /* SCCP connection realted */
156 struct bsc_msc_data *msc;
157
158 /* Sigtran connection ID */
159 int conn_id;
160 enum subscr_sccp_state state;
161 } sccp;
162
163 /* for audio handling */
164 struct {
165 uint16_t cic;
166 uint32_t rtp_ip;
167 int rtp_port;
168 /* RTP address of the remote end (assigned by MSC through assignment request) */
169 struct sockaddr_storage aoip_rtp_addr_remote;
170
171 /* Local RTP address (reported back to the MSC by us with the
172 * assignment complete message) */
173 struct sockaddr_storage aoip_rtp_addr_local;
174
Harald Welte3561bd42018-01-28 03:04:16 +0100175 /* FSM instance to control the BTS sided RTP connection */
176 struct osmo_fsm_inst *fi_bts;
177
178 /* FSM instance to control the MSC sided RTP connection */
179 struct osmo_fsm_inst *fi_msc;
180
181 /* Endpoint identifier of the MGCP endpoint the connection uses */
182 char *mgw_endpoint;
183
184 /* Channel rate flag, FR=1, HR=0, Invalid=-1 */
185 int full_rate;
186
Philipp Maier79745fc2018-03-21 10:53:24 +0100187 /* Channel mode flag (signaling or voice channel) */
Harald Welte3561bd42018-01-28 03:04:16 +0100188 enum gsm48_chan_mode chan_mode;
189
Harald Welte519c7e12018-01-28 02:45:46 +0100190 } user_plane;
Harald Weltec997ceb2018-05-30 01:39:43 +0200191
192 /* LCLS (local call, local switch) related state */
193 struct {
194 uint8_t global_call_ref[15];
195 uint8_t global_call_ref_len; /* length of global_call_ref */
196 uint8_t config; /* TS 48.008 3.2.2.116 */
197 uint8_t control;/* TS 48.008 3.2.2.117 */
198 /* LCLS FSM */
199 struct osmo_fsm_inst *fi;
200 /* pointer to "other" connection, if Call Leg Relocation was successful */
201 struct gsm_subscriber_connection *other;
202 } lcls;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100203};
204
Harald Weltef142c972011-05-24 13:25:38 +0200205
Neels Hofmeyr10485162018-02-13 23:22:03 +0100206/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 Table 10.5.2.33b.1:
207 4-bit index is used (2#1111 = 10#15) */
208#define SI2Q_MAX_NUM 16
209/* length in bits (for single SI2quater message) */
210#define SI2Q_MAX_LEN 160
211#define SI2Q_MIN_LEN 18
212
213struct osmo_bsc_data;
214
215struct osmo_bsc_sccp_con;
216
217/* Channel Request reason */
218enum gsm_chreq_reason_t {
219 GSM_CHREQ_REASON_EMERG,
220 GSM_CHREQ_REASON_PAG,
221 GSM_CHREQ_REASON_CALL,
222 GSM_CHREQ_REASON_LOCATION_UPD,
223 GSM_CHREQ_REASON_OTHER,
224 GSM_CHREQ_REASON_PDCH,
225};
226
227/* lchans 0..3 are SDCCH in combined channel configuration,
228 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
229#define CCCH_LCHAN 4
230
231#define TRX_NR_TS 8
232#define TS_MAX_LCHAN 8
233
234#define HARDCODED_ARFCN 123
235#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
236
237/* for multi-drop config */
238#define HARDCODED_BTS0_TS 1
239#define HARDCODED_BTS1_TS 6
240#define HARDCODED_BTS2_TS 11
241
242#define MAX_VERSION_LENGTH 64
243
Neels Hofmeyr10485162018-02-13 23:22:03 +0100244enum gsm_hooks {
245 GSM_HOOK_NM_SWLOAD,
246 GSM_HOOK_RR_PAGING,
247 GSM_HOOK_RR_SECURITY,
248};
249
Neels Hofmeyr10485162018-02-13 23:22:03 +0100250enum bts_gprs_mode {
251 BTS_GPRS_NONE = 0,
252 BTS_GPRS_GPRS = 1,
253 BTS_GPRS_EGPRS = 2,
254};
255
256struct gsm_lchan;
257struct osmo_rtp_socket;
258struct rtp_socket;
259struct bsc_api;
260
261/* Network Management State */
262struct gsm_nm_state {
263 uint8_t operational;
264 uint8_t administrative;
265 uint8_t availability;
266};
267
268struct gsm_abis_mo {
269 uint8_t obj_class;
270 uint8_t procedure_pending;
271 struct abis_om_obj_inst obj_inst;
272 const char *name;
273 struct gsm_nm_state nm_state;
274 struct tlv_parsed *nm_attr;
275 struct gsm_bts *bts;
276};
277
278/* Ericsson OM2000 Managed Object */
279struct abis_om2k_mo {
280 uint8_t class;
281 uint8_t bts;
282 uint8_t assoc_so;
283 uint8_t inst;
284} __attribute__ ((packed));
285
286struct om2k_mo {
287 struct abis_om2k_mo addr;
288 struct osmo_fsm_inst *fsm;
289};
290
291#define A38_XOR_MIN_KEY_LEN 12
292#define A38_XOR_MAX_KEY_LEN 16
293#define A38_COMP128_KEY_LEN 16
294#define RSL_ENC_ALG_A5(x) (x+1)
295#define MAX_EARFCN_LIST 32
296
297/* is the data link established? who established it? */
298#define LCHAN_SAPI_UNUSED 0
299#define LCHAN_SAPI_MS 1
300#define LCHAN_SAPI_NET 2
301#define LCHAN_SAPI_REL 3
302
303/* state of a logical channel */
304enum gsm_lchan_state {
305 LCHAN_S_NONE, /* channel is not active */
306 LCHAN_S_ACT_REQ, /* channel activation requested */
307 LCHAN_S_ACTIVE, /* channel is active and operational */
308 LCHAN_S_REL_REQ, /* channel release has been requested */
309 LCHAN_S_REL_ERR, /* channel is in an error state */
310 LCHAN_S_BROKEN, /* channel is somehow unusable */
311 LCHAN_S_INACTIVE, /* channel is set inactive */
312};
313
314/* BTS ONLY */
315#define MAX_NUM_UL_MEAS 104
316#define LC_UL_M_F_L1_VALID (1 << 0)
317#define LC_UL_M_F_RES_VALID (1 << 1)
318
319struct bts_ul_meas {
320 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
321 uint16_t ber10k;
322 /* timing advance offset (in quarter bits) */
323 int16_t ta_offs_qbits;
324 /* C/I ratio in dB */
325 float c_i;
326 /* flags */
327 uint8_t is_sub:1;
328 /* RSSI in dBm * -1 */
329 uint8_t inv_rssi;
330};
331
332struct bts_codec_conf {
333 uint8_t hr;
334 uint8_t efr;
335 uint8_t amr;
336};
337
338struct amr_mode {
339 uint8_t mode;
340 uint8_t threshold;
341 uint8_t hysteresis;
342};
343
344struct amr_multirate_conf {
345 uint8_t gsm48_ie[2];
346 struct amr_mode ms_mode[4];
347 struct amr_mode bts_mode[4];
348 uint8_t num_modes;
349};
350/* /BTS ONLY */
351
352enum lchan_csd_mode {
353 LCHAN_CSD_M_NT,
354 LCHAN_CSD_M_T_1200_75,
355 LCHAN_CSD_M_T_600,
356 LCHAN_CSD_M_T_1200,
357 LCHAN_CSD_M_T_2400,
358 LCHAN_CSD_M_T_9600,
359 LCHAN_CSD_M_T_14400,
360 LCHAN_CSD_M_T_29000,
361 LCHAN_CSD_M_T_32000,
362};
363
364/* State of the SAPIs in the lchan */
365enum lchan_sapi_state {
366 LCHAN_SAPI_S_NONE,
367 LCHAN_SAPI_S_REQ,
368 LCHAN_SAPI_S_ASSIGNED,
369 LCHAN_SAPI_S_REL,
370 LCHAN_SAPI_S_ERROR,
371};
372
Neels Hofmeyr92b9f2e2018-02-14 00:19:11 +0100373#define MAX_A5_KEY_LEN (128/8)
374
375struct gsm_encr {
376 uint8_t alg_id;
377 uint8_t key_len;
378 uint8_t key[MAX_A5_KEY_LEN];
379};
380
Neels Hofmeyr8da22332018-04-11 01:43:41 +0200381#define LOGPLCHAN(lchan, ss, level, fmt, args...) \
382 LOGP(ss, level, "%s (ss=%d,%s) (%s) " fmt, \
383 lchan ? gsm_ts_and_pchan_name(lchan->ts) : "-", \
384 lchan ? lchan->nr : 0, \
385 lchan ? gsm_lchant_name(lchan->type) : "-", \
386 bsc_subscr_name(lchan && lchan->conn ? lchan->conn->bsub : NULL), \
387 ## args)
388
Neels Hofmeyr10485162018-02-13 23:22:03 +0100389struct gsm_lchan {
390 /* The TS that we're part of */
391 struct gsm_bts_trx_ts *ts;
392 /* The logical subslot number in the TS */
393 uint8_t nr;
394 /* The logical channel type */
395 enum gsm_chan_t type;
396 /* RSL channel mode */
397 enum rsl_cmod_spd rsl_cmode;
398 /* If TCH, traffic channel mode */
399 enum gsm48_chan_mode tch_mode;
400 enum lchan_csd_mode csd_mode;
401 /* State */
402 enum gsm_lchan_state state;
403 const char *broken_reason;
404 /* Power levels for MS and BTS */
405 uint8_t bs_power;
406 uint8_t ms_power;
407 /* Encryption information */
408 struct gsm_encr encr;
409
410 /* AMR bits */
411 uint8_t mr_ms_lv[7];
412 uint8_t mr_bts_lv[7];
413
414 /* Established data link layer services */
415 uint8_t sapis[8];
416
417 struct {
418 uint32_t bound_ip;
419 uint32_t connect_ip;
420 uint16_t bound_port;
421 uint16_t connect_port;
422 uint16_t conn_id;
423 uint8_t rtp_payload;
424 uint8_t rtp_payload2;
425 uint8_t speech_mode;
426 struct rtp_socket *rtp_socket;
427
428 /* info we need to postpone the AoIP
429 * assignment completed message */
430 struct {
431 uint8_t rr_cause;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100432 bool valid;
433 } ass_compl;
434 } abis_ip;
435
436 uint8_t rqd_ta;
437
438 char *name;
439
440 struct osmo_timer_list T3101;
441 struct osmo_timer_list T3109;
442 struct osmo_timer_list T3111;
443 struct osmo_timer_list error_timer;
444 struct osmo_timer_list act_timer;
445 struct osmo_timer_list rel_work;
446 uint8_t error_cause;
447
448 /* table of neighbor cell measurements */
449 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
450
451 /* cache of last measurement reports on this lchan */
452 struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
453 int meas_rep_idx;
454 int meas_rep_count;
Neels Hofmeyr35ba85c2018-02-12 16:47:40 +0100455 uint8_t meas_rep_last_seen_nr;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100456
457 /* GSM Random Access data */
458 struct gsm48_req_ref *rqd_ref;
459
460 struct gsm_subscriber_connection *conn;
461
462 struct {
463 /* channel activation type and handover ref */
464 uint8_t act_type;
465 uint8_t ho_ref;
466 struct gsm48_req_ref *rqd_ref;
467 uint8_t rqd_ta;
468 } dyn;
469};
470
471enum {
472 TS_F_PDCH_ACTIVE = 0x1000,
473 TS_F_PDCH_ACT_PENDING = 0x2000,
474 TS_F_PDCH_DEACT_PENDING = 0x4000,
Neels Hofmeyr163f6312018-05-08 01:11:04 +0200475 TS_F_PDCH_PENDING_MASK = (TS_F_PDCH_ACT_PENDING | TS_F_PDCH_DEACT_PENDING),
Neels Hofmeyr10485162018-02-13 23:22:03 +0100476} gsm_bts_trx_ts_flags;
477
478/* One Timeslot in a TRX */
479struct gsm_bts_trx_ts {
480 struct gsm_bts_trx *trx;
Neels Hofmeyr91aa68f2018-05-09 17:46:22 +0200481 bool initialized;
482
Neels Hofmeyr10485162018-02-13 23:22:03 +0100483 /* number of this timeslot at the TRX */
484 uint8_t nr;
485
486 enum gsm_phys_chan_config pchan;
487
488 struct {
489 enum gsm_phys_chan_config pchan_is;
490 enum gsm_phys_chan_config pchan_want;
491 struct msgb *pending_chan_activ;
492 } dyn;
493
494 unsigned int flags;
495 struct gsm_abis_mo mo;
496 struct tlv_parsed nm_attr;
497 uint8_t nm_chan_comb;
498 int tsc; /* -1 == use BTS TSC */
499
500 struct {
501 /* Parameters below are configured by VTY */
502 int enabled;
503 uint8_t maio;
504 uint8_t hsn;
505 struct bitvec arfcns;
506 uint8_t arfcns_data[1024/8];
507 /* This is the pre-computed MA for channel assignments */
508 struct bitvec ma;
509 uint8_t ma_len; /* part of ma_data that is used */
510 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
511 } hopping;
512
513 /* To which E1 subslot are we connected */
514 struct gsm_e1_subslot e1_link;
515
516 union {
517 struct {
518 struct om2k_mo om2k_mo;
519 } rbs2000;
520 };
521
522 struct gsm_lchan lchan[TS_MAX_LCHAN];
523};
524
525/* One TRX in a BTS */
526struct gsm_bts_trx {
527 /* list header in bts->trx_list */
528 struct llist_head list;
529
530 struct gsm_bts *bts;
531 /* number of this TRX in the BTS */
532 uint8_t nr;
533 /* human readable name / description */
534 char *description;
535 /* how do we talk RSL with this TRX? */
536 struct gsm_e1_subslot rsl_e1_link;
537 uint8_t rsl_tei;
538 struct e1inp_sign_link *rsl_link;
539
540 /* Timeout for initiating the RSL connection. */
541 struct osmo_timer_list rsl_connect_timeout;
542
543 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
544 struct e1inp_sign_link *oml_link;
545
546 struct gsm_abis_mo mo;
547 struct tlv_parsed nm_attr;
548 struct {
549 struct gsm_abis_mo mo;
550 } bb_transc;
551
552 uint16_t arfcn;
553 int nominal_power; /* in dBm */
554 unsigned int max_power_red; /* in actual dB */
555
556 union {
557 struct {
558 struct {
559 struct gsm_abis_mo mo;
560 } bbsig;
561 struct {
562 struct gsm_abis_mo mo;
563 } pa;
564 } bs11;
565 struct {
566 unsigned int test_state;
567 uint8_t test_nr;
568 struct rxlev_stats rxlev_stat;
569 } ipaccess;
570 struct {
571 struct {
572 struct om2k_mo om2k_mo;
573 } trxc;
574 struct {
575 struct om2k_mo om2k_mo;
576 } rx;
577 struct {
578 struct om2k_mo om2k_mo;
579 } tx;
580 } rbs2000;
581 };
582 struct gsm_bts_trx_ts ts[TRX_NR_TS];
583};
584
585#define GSM_BTS_SI2Q(bts, i) (struct gsm48_system_information_type_2quater *)((bts)->si_buf[SYSINFO_TYPE_2quater][i])
586#define GSM_BTS_HAS_SI(bts, i) ((bts)->si_valid & (1 << i))
587#define GSM_BTS_SI(bts, i) (void *)((bts)->si_buf[i][0])
588#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
589
590enum gsm_bts_type {
591 GSM_BTS_TYPE_UNKNOWN,
592 GSM_BTS_TYPE_BS11,
593 GSM_BTS_TYPE_NANOBTS,
594 GSM_BTS_TYPE_RBS2000,
595 GSM_BTS_TYPE_NOKIA_SITE,
596 GSM_BTS_TYPE_OSMOBTS,
597 _NUM_GSM_BTS_TYPE
598};
599
600enum gsm_bts_type_variant {
601 BTS_UNKNOWN,
602 BTS_OSMO_LITECELL15,
603 BTS_OSMO_OCTPHY,
604 BTS_OSMO_SYSMO,
605 BTS_OSMO_TRX,
606 _NUM_BTS_VARIANT
607};
608
609/* Used by OML layer for BTS Attribute reporting */
610enum bts_attribute {
611 BTS_TYPE_VARIANT,
612 BTS_SUB_MODEL,
613 TRX_PHY_VERSION,
614};
615
616struct vty;
617
618struct gsm_bts_model {
619 struct llist_head list;
620
621 enum gsm_bts_type type;
622 enum gsm_bts_type_variant variant;
623 const char *name;
624
625 bool started;
626 int (*start)(struct gsm_network *net);
627 int (*oml_rcvmsg)(struct msgb *msg);
628 char * (*oml_status)(const struct gsm_bts *bts);
Neels Hofmeyr91aa68f2018-05-09 17:46:22 +0200629 bool (*oml_is_ts_ready)(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr10485162018-02-13 23:22:03 +0100630
631 void (*e1line_bind_ops)(struct e1inp_line *line);
632
633 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
634 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
635 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
636
637 struct tlv_definition nm_att_tlvdef;
638
639 /* features of a given BTS model set via gsm_bts_model_register() locally */
640 struct bitvec features;
641 uint8_t _features_data[MAX_BTS_FEATURES/8];
642};
643
Neels Hofmeyr10485162018-02-13 23:22:03 +0100644
Neels Hofmeyr10485162018-02-13 23:22:03 +0100645
646/*
647 * This keeps track of the paging status of one BTS. It
648 * includes a number of pending requests, a back pointer
649 * to the gsm_bts, a timer and some more state.
650 */
651struct gsm_bts_paging_state {
652 /* pending requests */
653 struct llist_head pending_requests;
654 struct gsm_bts *bts;
655
656 struct osmo_timer_list work_timer;
657 struct osmo_timer_list credit_timer;
658
659 /* free chans needed */
660 int free_chans_need;
661
662 /* load */
663 uint16_t available_slots;
664};
665
666struct gsm_envabtse {
667 struct gsm_abis_mo mo;
668};
669
670struct gsm_bts_gprs_nsvc {
671 struct gsm_bts *bts;
672 /* data read via VTY config file, to configure the BTS
673 * via OML from BSC */
674 int id;
675 uint16_t nsvci;
676 uint16_t local_port; /* on the BTS */
677 uint16_t remote_port; /* on the SGSN */
678 uint32_t remote_ip; /* on the SGSN */
679
680 struct gsm_abis_mo mo;
681};
682
683enum gprs_rlc_par {
684 RLC_T3142,
685 RLC_T3169,
686 RLC_T3191,
687 RLC_T3193,
688 RLC_T3195,
689 RLC_N3101,
690 RLC_N3103,
691 RLC_N3105,
692 CV_COUNTDOWN,
693 T_DL_TBF_EXT, /* ms */
694 T_UL_TBF_EXT, /* ms */
695 _NUM_RLC_PAR
696};
697
698enum gprs_cs {
699 GPRS_CS1,
700 GPRS_CS2,
701 GPRS_CS3,
702 GPRS_CS4,
703 GPRS_MCS1,
704 GPRS_MCS2,
705 GPRS_MCS3,
706 GPRS_MCS4,
707 GPRS_MCS5,
708 GPRS_MCS6,
709 GPRS_MCS7,
710 GPRS_MCS8,
711 GPRS_MCS9,
712 _NUM_GRPS_CS
713};
714
715struct gprs_rlc_cfg {
716 uint16_t parameter[_NUM_RLC_PAR];
717 struct {
718 uint16_t repeat_time; /* ms */
719 uint8_t repeat_count;
720 } paging;
721 uint32_t cs_mask; /* bitmask of gprs_cs */
722 uint8_t initial_cs;
723 uint8_t initial_mcs;
724};
725
726
727enum neigh_list_manual_mode {
728 NL_MODE_AUTOMATIC = 0,
729 NL_MODE_MANUAL = 1,
730 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
731};
732
733enum bts_loc_fix {
734 BTS_LOC_FIX_INVALID = 0,
735 BTS_LOC_FIX_2D = 1,
736 BTS_LOC_FIX_3D = 2,
737};
738
739extern const struct value_string bts_loc_fix_names[];
740
741struct bts_location {
742 struct llist_head list;
743 time_t tstamp;
744 enum bts_loc_fix valid;
745 double lat;
746 double lon;
747 double height;
748};
749
750/* Channel load counter */
751struct load_counter {
752 unsigned int total;
753 unsigned int used;
754};
755
756/* One BTS */
757struct gsm_bts {
758 /* list header in net->bts_list */
759 struct llist_head list;
760
761 /* Geographical location of the BTS */
762 struct llist_head loc_list;
763
764 /* number of ths BTS in network */
765 uint8_t nr;
766 /* human readable name / description */
767 char *description;
768 /* Cell Identity */
769 uint16_t cell_identity;
770 /* location area code of this BTS */
771 uint16_t location_area_code;
772 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
773 * which is used as TSC for the CCCH */
774 uint8_t bsic;
775 /* type of BTS */
776 enum gsm_bts_type type;
777 enum gsm_bts_type_variant variant;
778 struct gsm_bts_model *model;
779 enum gsm_band band;
780 char version[MAX_VERSION_LENGTH];
781 char sub_model[MAX_VERSION_LENGTH];
782
783 /* features of a given BTS set/reported via OML */
784 struct bitvec features;
785 uint8_t _features_data[MAX_BTS_FEATURES/8];
786
787 /* Connected PCU version (if any) */
788 char pcu_version[MAX_VERSION_LENGTH];
789
790 /* maximum Tx power that the MS is permitted to use in this cell */
791 int ms_max_power;
792
793 /* how do we talk OML with this TRX? */
794 struct gsm_e1_subslot oml_e1_link;
795 uint8_t oml_tei;
796 struct e1inp_sign_link *oml_link;
797 /* when OML link was established */
798 time_t uptime;
799
800 /* Abis network management O&M handle */
801 struct abis_nm_h *nmh;
802
803 struct gsm_abis_mo mo;
804
805 /* number of this BTS on given E1 link */
806 uint8_t bts_nr;
807
808 /* DTX features of this BTS */
809 enum gsm48_dtx_mode dtxu;
810 bool dtxd;
811
812 /* paging state and control */
813 struct gsm_bts_paging_state paging;
814
815 /* CCCH is on C0 */
816 struct gsm_bts_trx *c0;
817
818 struct {
819 struct gsm_abis_mo mo;
820 } site_mgr;
821
822 /* bitmask of all SI that are present/valid in si_buf */
823 uint32_t si_valid;
824 /* 3GPP TS 44.018 Table 10.5.2.33b.1 INDEX and COUNT for SI2quater */
825 uint8_t si2q_index; /* distinguish individual SI2quater messages */
826 uint8_t si2q_count; /* si2q_index for the last (highest indexed) individual SI2quater message */
827 /* buffers where we put the pre-computed SI */
828 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
829 /* offsets used while generating SI2quater */
830 size_t e_offset;
831 size_t u_offset;
832
833 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
834 union {
835 struct {
836 uint16_t site_id;
837 uint16_t bts_id;
838 uint32_t flags;
839 uint32_t rsl_ip;
840 } ip_access;
841 struct {
842 struct {
843 struct gsm_abis_mo mo;
844 } cclk;
845 struct {
846 struct gsm_abis_mo mo;
847 } rack;
848 struct gsm_envabtse envabtse[4];
849 } bs11;
850 struct {
851 struct {
852 struct om2k_mo om2k_mo;
853 struct gsm_abis_mo mo;
854 struct llist_head conn_groups;
855 } cf;
856 struct {
857 struct om2k_mo om2k_mo;
858 struct gsm_abis_mo mo;
859 struct llist_head conn_groups;
860 } is;
861 struct {
862 struct om2k_mo om2k_mo;
863 struct gsm_abis_mo mo;
864 struct llist_head conn_groups;
865 } con;
866 struct {
867 struct om2k_mo om2k_mo;
868 struct gsm_abis_mo mo;
869 } dp;
870 struct {
871 struct om2k_mo om2k_mo;
872 struct gsm_abis_mo mo;
873 } tf;
874 uint32_t use_superchannel:1;
875 } rbs2000;
876 struct {
877 uint8_t bts_type;
878 unsigned int configured:1,
879 skip_reset:1,
880 no_loc_rel_cnf:1,
881 bts_reset_timer_cnf,
882 did_reset:1,
883 wait_reset:1;
884 struct osmo_timer_list reset_timer;
885 } nokia;
886 };
887
888 /* Not entirely sure how ip.access specific this is */
889 struct {
890 uint8_t supports_egprs_11bit_rach;
891 enum bts_gprs_mode mode;
892 struct {
893 struct gsm_abis_mo mo;
894 uint16_t nsei;
895 uint8_t timer[7];
896 } nse;
897 struct {
898 struct gsm_abis_mo mo;
899 uint16_t bvci;
900 uint8_t timer[11];
901 struct gprs_rlc_cfg rlc_cfg;
902 } cell;
903 struct gsm_bts_gprs_nsvc nsvc[2];
904 uint8_t rac;
905 uint8_t net_ctrl_ord;
906 bool ctrl_ack_type_use_block;
907 } gprs;
908
909 /* RACH NM values */
910 int rach_b_thresh;
911 int rach_ldavg_slots;
912
913 /* transceivers */
914 int num_trx;
915 struct llist_head trx_list;
916
917 /* SI related items */
918 int force_combined_si;
919 int bcch_change_mark;
920
921 /* Abis NM queue */
922 struct llist_head abis_queue;
923 int abis_nm_pend;
924
925 struct gsm_network *network;
926
927 /* should the channel allocator allocate channels from high TRX to TRX0,
928 * rather than starting from TRX0 and go upwards? */
929 int chan_alloc_reverse;
930
931 enum neigh_list_manual_mode neigh_list_manual_mode;
932 /* parameters from which we build SYSTEM INFORMATION */
933 struct {
934 struct gsm48_rach_control rach_control;
935 uint8_t ncc_permitted;
936 struct gsm48_cell_sel_par cell_sel_par;
937 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
938 struct gsm48_cell_options cell_options;
939 struct gsm48_control_channel_descr chan_desc;
940 struct bitvec neigh_list;
941 struct bitvec cell_alloc;
942 struct bitvec si5_neigh_list;
943 struct osmo_earfcn_si2q si2quater_neigh_list;
944 size_t uarfcn_length; /* index for uarfcn and scramble lists */
945 struct {
946 /* bitmask large enough for all possible ARFCN's */
947 uint8_t neigh_list[1024/8];
948 uint8_t cell_alloc[1024/8];
949 /* If the user wants a different neighbor list in SI5 than in SI2 */
950 uint8_t si5_neigh_list[1024/8];
951 uint8_t meas_bw_list[MAX_EARFCN_LIST];
952 uint16_t earfcn_list[MAX_EARFCN_LIST];
953 uint16_t uarfcn_list[MAX_EARFCN_LIST];
954 uint16_t scramble_list[MAX_EARFCN_LIST];
955 } data;
956 } si_common;
957 bool early_classmark_allowed;
958 bool early_classmark_allowed_3g;
959 /* for testing only: Have an infinitely long radio link timeout */
960 bool infinite_radio_link_timeout;
961
962 /* do we use static (user-defined) system information messages? (bitmask) */
963 uint32_t si_mode_static;
964
Stefan Sperling6442e432018-02-06 14:44:54 +0100965 /* access control class ramping */
966 struct acc_ramp acc_ramp;
967
Neels Hofmeyr10485162018-02-13 23:22:03 +0100968 /* exclude the BTS from the global RF Lock handling */
969 int excl_from_rf_lock;
970
971 /* supported codecs beside FR */
972 struct bts_codec_conf codec;
973
974 /* BTS dependencies bit field */
975 uint32_t depends_on[256/(8*4)];
976
977 /* full and half rate multirate config */
978 struct amr_multirate_conf mr_full;
979 struct amr_multirate_conf mr_half;
980
981 /* PCU socket state */
982 char *pcu_sock_path;
983 struct pcu_sock_state *pcu_state;
984
985 struct rate_ctr_group *bts_ctrs;
986 struct osmo_stat_item_group *bts_statg;
987
988 struct handover_cfg *ho;
989
990 /* BTS-specific overrides for timer values from struct gsm_network. */
991 uint8_t T3122; /* ASSIGMENT REJECT wait indication */
992
993 /* Periodic channel load measurements are used to maintain T3122. */
994 struct load_counter chan_load_samples[7];
995 int chan_load_samples_idx;
Stefan Sperling6442e432018-02-06 14:44:54 +0100996 uint8_t chan_load_avg; /* current channel load average in percent (0 - 100). */
Neels Hofmeyr10485162018-02-13 23:22:03 +0100997};
998
999
1000struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, uint8_t bts_num);
1001struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
1002
1003struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
1004struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
1005
1006enum gsm_bts_type str2btstype(const char *arg);
1007const char *btstype2str(enum gsm_bts_type type);
1008
1009enum bts_attribute str2btsattr(const char *s);
1010const char *btsatttr2str(enum bts_attribute v);
1011
1012enum gsm_bts_type_variant str2btsvariant(const char *arg);
1013const char *btsvariant2str(enum gsm_bts_type_variant v);
1014
1015extern const struct value_string gsm_chreq_descs[];
1016const struct value_string gsm_pchant_names[13];
1017const struct value_string gsm_pchant_descs[13];
1018const char *gsm_pchan_name(enum gsm_phys_chan_config c);
1019enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
1020const char *gsm_lchant_name(enum gsm_chan_t c);
1021const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
1022char *gsm_trx_name(const struct gsm_bts_trx *trx);
1023char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
1024char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
1025char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
1026const char *gsm_lchans_name(enum gsm_lchan_state s);
1027
1028static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
1029{
1030 return lchan->name;
1031}
1032
Neels Hofmeyr10485162018-02-13 23:22:03 +01001033void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
1034
1035struct gsm_nm_state *
1036gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
1037 const struct abis_om_obj_inst *obj_inst);
1038void *
1039gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
1040 const struct abis_om_obj_inst *obj_inst);
1041
1042/* reset the state of all MO in the BTS */
1043void gsm_bts_mo_reset(struct gsm_bts *bts);
1044
1045uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
1046 uint8_t ts_nr, uint8_t lchan_nr);
1047uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
1048uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
1049 enum gsm_phys_chan_config as_pchan);
1050
1051/* return the gsm_lchan for the CBCH (if it exists at all) */
1052struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
1053
1054/*
1055 * help with parsing regexps
1056 */
1057int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
1058 int argc, const char **argv) __attribute__ ((warn_unused_result));
1059
1060static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
1061{
1062 if (ts->tsc != -1)
1063 return ts->tsc;
1064 else
1065 return ts->trx->bts->bsic & 7;
1066}
1067
1068struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
1069 int *rc);
1070
1071enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
1072uint8_t ts_subslots(struct gsm_bts_trx_ts *ts);
1073bool ts_is_tch(struct gsm_bts_trx_ts *ts);
1074
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01001075
Harald Welteb7948872017-12-18 18:48:21 +01001076static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection *conn) {
1077 OSMO_ASSERT(conn->lchan);
1078 return conn->lchan->ts->trx->bts;
1079}
1080
Harald Welted82101e2017-12-09 23:07:38 +01001081enum {
1082 BTS_CTR_CHREQ_TOTAL,
1083 BTS_CTR_CHREQ_NO_CHANNEL,
1084 BTS_CTR_CHAN_RF_FAIL,
1085 BTS_CTR_CHAN_RLL_ERR,
1086 BTS_CTR_BTS_OML_FAIL,
1087 BTS_CTR_BTS_RSL_FAIL,
1088 BTS_CTR_CODEC_AMR_F,
1089 BTS_CTR_CODEC_AMR_H,
1090 BTS_CTR_CODEC_EFR,
1091 BTS_CTR_CODEC_V1_FR,
1092 BTS_CTR_CODEC_V1_HR,
Harald Weltecf9d4312017-12-13 23:17:16 +01001093 BTS_CTR_PAGING_ATTEMPTED,
1094 BTS_CTR_PAGING_ALREADY,
1095 BTS_CTR_PAGING_RESPONDED,
1096 BTS_CTR_PAGING_EXPIRED,
Harald Welte4f598922017-12-14 13:47:02 +01001097 BTS_CTR_CHAN_ACT_TOTAL,
1098 BTS_CTR_CHAN_ACT_NACK,
Harald Welte62d9cb02017-12-14 14:00:26 +01001099 BTS_CTR_RSL_UNKNOWN,
Harald Welte581398a2017-12-14 14:29:44 +01001100 BTS_CTR_RSL_IPA_NACK,
Harald Welte00d64fd2017-12-14 14:34:16 +01001101 BTS_CTR_MODE_MODIFY_NACK,
Harald Welted82101e2017-12-09 23:07:38 +01001102};
1103
1104static const struct rate_ctr_desc bts_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001105 [BTS_CTR_CHREQ_TOTAL] = {"chreq:total", "Received channel requests."},
1106 [BTS_CTR_CHREQ_NO_CHANNEL] = {"chreq:no_channel", "Sent to MS no channel available."},
1107 [BTS_CTR_CHAN_RF_FAIL] = {"chan:rf_fail", "Received a RF failure indication from BTS."},
1108 [BTS_CTR_CHAN_RLL_ERR] = {"chan:rll_err", "Received a RLL failure with T200 cause from BTS."},
Harald Welted82101e2017-12-09 23:07:38 +01001109 [BTS_CTR_BTS_OML_FAIL] = {"oml_fail", "Received a TEI down on a OML link."},
1110 [BTS_CTR_BTS_RSL_FAIL] = {"rsl_fail", "Received a TEI down on a OML link."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001111 [BTS_CTR_CODEC_AMR_F] = {"codec:amr_f", "Count the usage of AMR/F codec by channel mode requested."},
1112 [BTS_CTR_CODEC_AMR_H] = {"codec:amr_h", "Count the usage of AMR/H codec by channel mode requested."},
1113 [BTS_CTR_CODEC_EFR] = {"codec:efr", "Count the usage of EFR codec by channel mode requested."},
1114 [BTS_CTR_CODEC_V1_FR] = {"codec:fr", "Count the usage of FR codec by channel mode requested."},
1115 [BTS_CTR_CODEC_V1_HR] = {"codec:hr", "Count the usage of HR codec by channel mode requested."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001116
1117 [BTS_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
1118 [BTS_CTR_PAGING_ALREADY] = {"paging:already", "Paging attempts ignored as subsciber was already being paged."},
1119 [BTS_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful paging response."},
1120 [BTS_CTR_PAGING_EXPIRED] = {"paging:expired", "Paging Request expired because of timeout T3113."},
Harald Welte4f598922017-12-14 13:47:02 +01001121 [BTS_CTR_CHAN_ACT_TOTAL] = {"chan_act:total", "Total number of Channel Activations."},
1122 [BTS_CTR_CHAN_ACT_NACK] = {"chan_act:nack", "Number of Channel Activations that the BTS NACKed"},
Harald Welte62d9cb02017-12-14 14:00:26 +01001123 [BTS_CTR_RSL_UNKNOWN] = {"rsl:unknown", "Number of unknown/unsupported RSL messages received from BTS"},
Harald Welte581398a2017-12-14 14:29:44 +01001124 [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 +01001125 [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 +01001126};
1127
1128static const struct rate_ctr_group_desc bts_ctrg_desc = {
1129 "bts",
1130 "base transceiver station",
1131 OSMO_STATS_CLASS_GLOBAL,
1132 ARRAY_SIZE(bts_ctr_description),
1133 bts_ctr_description,
1134};
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001135
Alexander Couzens20423ea2016-07-12 15:42:02 +02001136enum {
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001137 BTS_STAT_CHAN_LOAD_AVERAGE,
1138 BTS_STAT_T3122,
1139};
1140
1141enum {
Alexander Couzensb847a212016-08-02 11:34:11 +02001142 BSC_CTR_HANDOVER_ATTEMPTED,
1143 BSC_CTR_HANDOVER_NO_CHANNEL,
1144 BSC_CTR_HANDOVER_TIMEOUT,
1145 BSC_CTR_HANDOVER_COMPLETED,
1146 BSC_CTR_HANDOVER_FAILED,
1147 BSC_CTR_PAGING_ATTEMPTED,
1148 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +01001149 BSC_CTR_PAGING_RESPONDED,
Stefan Sperling7926d982018-05-17 14:52:02 +02001150 BSC_CTR_UNKNOWN_UNIT_ID,
Alexander Couzensb847a212016-08-02 11:34:11 +02001151};
1152
1153static const struct rate_ctr_desc bsc_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001154 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Received handover attempts."},
1155 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Sent no channel available responses."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001156 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Timeouts of timer T3103."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001157 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Received handover completed."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001158 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Received HO FAIL messages."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001159
1160 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001161 [BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Paging request send failures because no responsible BTS was found."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001162 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response."},
Stefan Sperling7926d982018-05-17 14:52:02 +02001163
1164 [BSC_CTR_UNKNOWN_UNIT_ID] = {"abis:unknown_unit_id", "Connection attempts from unknown IPA CCM Unit ID."},
Alexander Couzensb847a212016-08-02 11:34:11 +02001165};
1166
Alexander Couzensb847a212016-08-02 11:34:11 +02001167
1168
1169static const struct rate_ctr_group_desc bsc_ctrg_desc = {
1170 "bsc",
1171 "base station controller",
1172 OSMO_STATS_CLASS_GLOBAL,
1173 ARRAY_SIZE(bsc_ctr_description),
1174 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +02001175};
1176
Harald Weltedea252d2017-12-10 19:55:18 +01001177#define GSM_T3101_DEFAULT 3 /* s */
Harald Weltea0d324b2017-07-20 01:47:39 +02001178#define GSM_T3103_DEFAULT 5 /* s */
1179#define GSM_T3105_DEFAULT 100 /* ms */
1180#define GSM_T3107_DEFAULT 5 /* s */
Harald Welteed23c1d2017-12-10 19:58:16 +01001181#define GSM_T3109_DEFAULT 5 /* s, must be 2s + radio_link_timeout*0.48 */
Harald Weltea0d324b2017-07-20 01:47:39 +02001182#define GSM_T3111_DEFAULT 2 /* s */
Harald Welte6e59ced2017-12-14 12:49:43 +01001183#define GSM_T3113_DEFAULT 10 /* s */
Harald Weltea0d324b2017-07-20 01:47:39 +02001184#define GSM_T3115_DEFAULT 10
1185#define GSM_T3117_DEFAULT 10
1186#define GSM_T3119_DEFAULT 10
Andreas Eversberg75e13a42013-02-07 11:51:16 +01001187#define GSM_T3122_DEFAULT 10
Harald Weltea0d324b2017-07-20 01:47:39 +02001188#define GSM_T3141_DEFAULT 10
Harald Welteb84ddfc2009-12-01 17:36:54 +05301189
Neels Hofmeyr73983952016-05-10 13:29:33 +02001190struct gsm_tz {
1191 int override; /* if 0, use system's time zone instead. */
1192 int hr; /* hour */
1193 int mn; /* minute */
1194 int dst; /* daylight savings */
1195};
1196
Harald Welte52b1f982008-12-23 20:25:15 +00001197struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001198 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
1199 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
1200 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
1201 * these have in common, like country and network code, put in yet
1202 * separate structs and placed as members in osmo_bsc and osmo_msc. */
1203
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001204 struct osmo_plmn_id plmn;
1205
Harald Welte51e4bf32017-12-23 17:30:18 +01001206 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
1207 uint8_t a5_encryption_mask;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001208 int neci;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001209
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001210 struct handover_cfg *ho;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001211 struct {
1212 unsigned int congestion_check_interval_s;
1213 struct osmo_timer_list congestion_check_timer;
1214 } hodec2;
Harald Welte52b1f982008-12-23 20:25:15 +00001215
Alexander Couzensb847a212016-08-02 11:34:11 +02001216 struct rate_ctr_group *bsc_ctrs;
Harald Welte24ff6ee2009-12-22 00:41:05 +01001217
Holger Hans Peter Freytherabcddf12010-06-14 18:20:15 +08001218 struct bsc_api *bsc_api;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001219
Harald Welte52b1f982008-12-23 20:25:15 +00001220 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +02001221 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001222
1223 /* timer values */
1224 int T3101;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +01001225 int T3103;
1226 int T3105;
1227 int T3107;
1228 int T3109;
1229 int T3111;
1230 int T3113;
1231 int T3115;
1232 int T3117;
1233 int T3119;
Harald Welte2862dca2010-12-23 14:39:29 +01001234 int T3122;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +01001235 int T3141;
Harald Welteeab84a12009-12-13 10:53:12 +01001236
Alexander Couzens547c2072017-11-21 12:03:04 +01001237 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +08001238
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +08001239 /* Use a TCH for handling requests of type paging any */
1240 int pag_any_tch;
1241
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08001242 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +02001243 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +01001244
Daniel Willmann6fc4a982011-07-22 17:55:42 +02001245 /* control interface */
1246 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +02001247
1248 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
1249 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +02001250
1251 /* all active subscriber connections. */
1252 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +02001253
1254 /* if override is nonzero, this timezone data is used for all MM
1255 * contexts. */
1256 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
1257 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +01001258 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +02001259 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +01001260
1261 /* List of all struct bsc_subscr used in libbsc. This llist_head is
1262 * allocated so that the llist_head pointer itself can serve as a
1263 * talloc context (useful to not have to pass the entire gsm_network
1264 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
1265 * not require gsm_data.h). In an MSC-without-BSC environment, this
1266 * pointer is NULL to indicate absence of a bsc_subscribers list. */
1267 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +02001268
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001269 /* Periodic location update default value */
1270 uint8_t t3212;
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001271
Stefan Sperling6cee8932018-01-30 18:14:22 +01001272 /* Timer for periodic channel load measurements to maintain each BTS's T3122. */
1273 struct osmo_timer_list t3122_chan_load_timer;
1274
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001275 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +02001276 struct mgcp_client_conf *conf;
1277 struct mgcp_client *client;
1278 } mgw;
Harald Welte7e310b12009-03-30 20:56:32 +00001279};
1280
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001281static inline const struct osmo_location_area_id *bts_lai(struct gsm_bts *bts)
1282{
1283 static struct osmo_location_area_id lai;
1284 lai = (struct osmo_location_area_id){
1285 .plmn = bts->network->plmn,
1286 .lac = bts->location_area_code,
1287 };
1288 return &lai;
1289}
1290
Neels Hofmeyrc13e6872016-05-11 13:53:47 +02001291extern void talloc_ctx_init(void *ctx_root);
1292
Harald Welte39315c42010-01-10 18:01:52 +01001293int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +02001294
Harald Welte1d014a52009-08-08 15:38:29 +02001295enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +02001296const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +00001297struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
1298 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +00001299
Andreas Eversberg8226fa72009-06-29 15:19:38 +02001300extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +01001301extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +02001302
Harald Weltef383aa12012-07-02 19:51:55 +02001303/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +00001304static inline int is_ipaccess_bts(struct gsm_bts *bts)
1305{
1306 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001307 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001308 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +00001309 return 1;
1310 default:
1311 break;
1312 }
1313 return 0;
1314}
1315
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001316static inline int is_sysmobts_v2(struct gsm_bts *bts)
1317{
1318 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +01001319 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001320 return 1;
1321 default:
1322 break;
1323 }
1324 return 0;
1325}
1326
Harald Welte5b570672009-08-10 10:08:01 +02001327static inline int is_siemens_bts(struct gsm_bts *bts)
1328{
1329 switch (bts->type) {
1330 case GSM_BTS_TYPE_BS11:
1331 return 1;
1332 default:
1333 break;
1334 }
1335
1336 return 0;
1337}
1338
Andreas Eversberg7d8fa342013-12-05 13:25:06 +01001339static inline int is_nokia_bts(struct gsm_bts *bts)
1340{
1341 switch (bts->type) {
1342 case GSM_BTS_TYPE_NOKIA_SITE:
1343 return 1;
1344 default:
1345 break;
1346 }
1347
1348 return 0;
1349}
1350
Andreas Eversbergdcf38e12013-12-05 14:37:11 +01001351static inline int is_e1_bts(struct gsm_bts *bts)
1352{
1353 switch (bts->type) {
1354 case GSM_BTS_TYPE_BS11:
1355 case GSM_BTS_TYPE_RBS2000:
1356 case GSM_BTS_TYPE_NOKIA_SITE:
1357 return 1;
1358 default:
1359 break;
1360 }
1361
1362 return 0;
1363}
1364
Harald Welte1876c312018-05-27 11:53:43 +02001365extern struct gsm_network *bsc_gsmnet;
1366
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001367enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +02001368const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001369int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +02001370
Neels Hofmeyr4d358c02018-02-22 03:19:05 +01001371void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +08001372void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +01001373
Harald Weltefbda4e12010-03-04 11:04:52 +01001374int gsm_bts_model_register(struct gsm_bts_model *model);
1375
Harald Welte3561bd42018-01-28 03:04:16 +01001376struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *network);
Neels Hofmeyr42eb0142016-05-20 17:15:44 +02001377
1378struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
1379void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +08001380
Harald Welte3300c012011-06-05 13:31:33 +02001381struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net,
1382 enum gsm_bts_type type,
Harald Weltea2bbc5e2015-11-20 10:43:31 +01001383 uint8_t bsic);
Harald Welte142d12d2014-12-29 17:47:08 +01001384
Harald Welte3300c012011-06-05 13:31:33 +02001385void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
1386 uint8_t e1_ts, uint8_t e1_ts_ss);
1387
Maxbe356ed2017-09-07 19:10:09 +02001388void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Harald Welte3300c012011-06-05 13:31:33 +02001389struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +01001390int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -04001391int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +02001392
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +02001393/* generic E1 line operations for all ISDN-based BTS. */
1394extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
1395
Harald Weltee555c2b2012-08-17 13:02:12 +02001396extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
1397extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
1398
Max3d049d22017-10-09 17:12:53 +02001399char *get_model_oml_status(const struct gsm_bts *bts);
1400
Max25cc4072017-10-10 14:50:35 +02001401unsigned long long bts_uptime(const struct gsm_bts *bts);
1402
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +01001403/* control interface handling */
1404int bsc_base_ctrl_cmds_install(void);
1405
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001406/* dependency handling */
1407void bts_depend_mark(struct gsm_bts *bts, int dep);
1408void bts_depend_clear(struct gsm_bts *bts, int dep);
1409int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +01001410int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001411
Harald Welte2f8b9d22017-06-18 11:12:13 +03001412int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
1413void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
1414
Harald Weltea43e0b42016-06-19 18:06:02 +02001415bool classmark_is_r99(struct gsm_classmark *cm);
1416
Neels Hofmeyr91aa68f2018-05-09 17:46:22 +02001417void gsm_ts_check_init(struct gsm_bts_trx_ts *ts);
1418void gsm_trx_mark_all_ts_uninitialized(struct gsm_bts_trx *trx);
1419void gsm_bts_mark_all_ts_uninitialized(struct gsm_bts *bts);
1420
Harald Welte6be350c2011-05-25 13:10:08 +02001421#endif /* _GSM_DATA_H */