blob: a16a4b7438c6acab592b0bc92cadd9d5ce9d6168 [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;
Neels Hofmeyr19bed232018-03-22 04:54:57 +010038struct gsm0808_cell_id;
Philipp Maier39f62bb2017-04-09 12:32:51 +020039
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020040/** annotations for msgb ownership */
41#define __uses
42
Holger Hans Peter Freyther6f615552010-11-15 20:50:42 +010043#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
44
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010045struct bsc_subscr;
Neels Hofmeyr7b656882017-07-09 22:09:18 +020046struct gprs_ra_id;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020047
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080048#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
49
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010050#define tmsi_from_string(str) strtoul(str, NULL, 10)
51
Max70fdd242017-06-15 15:10:53 +020052/* 3-bit long values */
53#define EARFCN_PRIO_INVALID 8
54#define EARFCN_MEAS_BW_INVALID 8
55/* 5-bit long values */
56#define EARFCN_QRXLV_INVALID 32
57#define EARFCN_THRESH_LOW_INVALID 32
58
Harald Welte8e1e3ee2009-02-01 13:32:45 +000059struct msgb;
60typedef int gsm_cbfn(unsigned int hooknum,
61 unsigned int event,
62 struct msgb *msg,
63 void *data, void *param);
64
Harald Weltef7c28b02009-12-21 13:30:17 +010065/* Maximum number of neighbor cells whose average we track */
66#define MAX_NEIGH_MEAS 10
67/* Maximum size of the averaging window for neighbor cells */
68#define MAX_WIN_NEIGH_AVG 10
Andreas Eversberg98692032013-06-23 10:44:34 +020069/* Maximum number of report history we store */
70#define MAX_MEAS_REP 10
Harald Weltef7c28b02009-12-21 13:30:17 +010071
72/* processed neighbor measurements for one cell */
73struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020074 uint16_t arfcn;
75 uint8_t bsic;
76 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +010077 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020078 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +010079};
80
Harald Weltea43e0b42016-06-19 18:06:02 +020081struct gsm_classmark {
82 bool classmark1_set;
83 struct gsm48_classmark1 classmark1;
84 uint8_t classmark2_len;
85 uint8_t classmark2[3];
86 uint8_t classmark3_len;
87 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
88};
89
Harald Welte519c7e12018-01-28 02:45:46 +010090enum subscr_sccp_state {
91 SUBSCR_SCCP_ST_NONE,
92 SUBSCR_SCCP_ST_WAIT_CONN_CONF,
93 SUBSCR_SCCP_ST_CONNECTED
94};
95
Neels Hofmeyr378a4922016-05-09 21:07:43 +020096/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010097struct gsm_subscriber_connection {
Harald Weltea43e0b42016-06-19 18:06:02 +020098 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +080099 struct llist_head entry;
100
Harald Welte3561bd42018-01-28 03:04:16 +0100101 /* FSM instance to control the subscriber connection state (RTP, A) */
102 struct osmo_fsm_inst *fi;
103
Harald Weltea43e0b42016-06-19 18:06:02 +0200104 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100105 struct bsc_subscr *bsub;
106
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100107 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200108 struct gsm_network *network;
109
Harald Welte4a8ebc82017-12-18 18:34:41 +0100110 /* the primary / currently active lchan to the BTS/subscriber */
111 struct gsm_lchan *lchan;
Harald Welte3561bd42018-01-28 03:04:16 +0100112
113 /* handover information, if a handover is pending for this conn. */
114 struct bsc_handover *ho;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100115
Harald Welte4a8ebc82017-12-18 18:34:41 +0100116 /* the future allocated but not yet used lchan during ASSIGNMENT */
117 struct gsm_lchan *secondary_lchan;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100118
Harald Welte4a8ebc82017-12-18 18:34:41 +0100119 /* buffer/cache for classmark of the ME of the subscriber */
Harald Weltea43e0b42016-06-19 18:06:02 +0200120 struct gsm_classmark classmark;
Andreas Eversberg935e5d72013-06-17 11:58:30 +0200121
122 /* Cache DTAP messages during handover/assignment (msgb_enqueue()/msgb_dequeue())*/
123 struct llist_head ho_dtap_cache;
124 unsigned int ho_dtap_cache_len;
Andreas Eversberg084b4212013-05-30 14:12:48 +0200125
Neels Hofmeyrec422642018-02-15 14:07:40 +0100126 struct {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100127 int failures;
Neels Hofmeyrec422642018-02-15 14:07:40 +0100128 struct penalty_timers *penalty_timers;
129 } hodec2;
Neels Hofmeyra60f3442018-02-12 16:44:32 +0100130
131 /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment Request. 3GPP 48.008
132 * 3.2.2.103 says:
133 * The "Codec List (MSC Preferred)" shall not include codecs
134 * that are not supported by the MS.
135 * i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed the MS bearer
136 * capabilities, which the MSC is required to translate into the codec list. */
137 struct gsm0808_speech_codec_list codec_list;
138 bool codec_list_present;
Harald Welte519c7e12018-01-28 02:45:46 +0100139
140 /* flag to prevent multiple simultaneous ciphering commands */
141 int ciphering_handled;
142
143 /* state related to welcome USSD */
144 uint8_t new_subscriber;
145
146 /* state related to osmo_bsc_filter.c */
147 struct bsc_filter_state filter_state;
148
149 /* SCCP connection associatd with this subscriber_connection */
150 struct {
151 /* for advanced ping/pong */
152 int send_ping;
153
154 /* SCCP connection realted */
155 struct bsc_msc_data *msc;
156
157 /* Sigtran connection ID */
158 int conn_id;
159 enum subscr_sccp_state state;
160 } sccp;
161
162 /* for audio handling */
163 struct {
164 uint16_t cic;
165 uint32_t rtp_ip;
166 int rtp_port;
167 /* RTP address of the remote end (assigned by MSC through assignment request) */
168 struct sockaddr_storage aoip_rtp_addr_remote;
169
170 /* Local RTP address (reported back to the MSC by us with the
171 * assignment complete message) */
172 struct sockaddr_storage aoip_rtp_addr_local;
173
Harald Welte3561bd42018-01-28 03:04:16 +0100174 /* FSM instance to control the BTS sided RTP connection */
175 struct osmo_fsm_inst *fi_bts;
176
177 /* FSM instance to control the MSC sided RTP connection */
178 struct osmo_fsm_inst *fi_msc;
179
180 /* Endpoint identifier of the MGCP endpoint the connection uses */
181 char *mgw_endpoint;
182
183 /* Channel rate flag, FR=1, HR=0, Invalid=-1 */
184 int full_rate;
185
Philipp Maier79745fc2018-03-21 10:53:24 +0100186 /* Channel mode flag (signaling or voice channel) */
Harald Welte3561bd42018-01-28 03:04:16 +0100187 enum gsm48_chan_mode chan_mode;
188
Harald Welte519c7e12018-01-28 02:45:46 +0100189 } user_plane;
Harald Weltec997ceb2018-05-30 01:39:43 +0200190
191 /* LCLS (local call, local switch) related state */
192 struct {
193 uint8_t global_call_ref[15];
194 uint8_t global_call_ref_len; /* length of global_call_ref */
195 uint8_t config; /* TS 48.008 3.2.2.116 */
196 uint8_t control;/* TS 48.008 3.2.2.117 */
197 /* LCLS FSM */
198 struct osmo_fsm_inst *fi;
199 /* pointer to "other" connection, if Call Leg Relocation was successful */
200 struct gsm_subscriber_connection *other;
201 } lcls;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100202};
203
Harald Weltef142c972011-05-24 13:25:38 +0200204
Neels Hofmeyr10485162018-02-13 23:22:03 +0100205/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 Table 10.5.2.33b.1:
206 4-bit index is used (2#1111 = 10#15) */
207#define SI2Q_MAX_NUM 16
208/* length in bits (for single SI2quater message) */
209#define SI2Q_MAX_LEN 160
210#define SI2Q_MIN_LEN 18
211
212struct osmo_bsc_data;
213
214struct osmo_bsc_sccp_con;
215
216/* Channel Request reason */
217enum gsm_chreq_reason_t {
218 GSM_CHREQ_REASON_EMERG,
219 GSM_CHREQ_REASON_PAG,
220 GSM_CHREQ_REASON_CALL,
221 GSM_CHREQ_REASON_LOCATION_UPD,
222 GSM_CHREQ_REASON_OTHER,
223 GSM_CHREQ_REASON_PDCH,
224};
225
226/* lchans 0..3 are SDCCH in combined channel configuration,
227 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
228#define CCCH_LCHAN 4
229
230#define TRX_NR_TS 8
231#define TS_MAX_LCHAN 8
232
233#define HARDCODED_ARFCN 123
234#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
235
236/* for multi-drop config */
237#define HARDCODED_BTS0_TS 1
238#define HARDCODED_BTS1_TS 6
239#define HARDCODED_BTS2_TS 11
240
241#define MAX_VERSION_LENGTH 64
242
Neels Hofmeyr10485162018-02-13 23:22:03 +0100243enum gsm_hooks {
244 GSM_HOOK_NM_SWLOAD,
245 GSM_HOOK_RR_PAGING,
246 GSM_HOOK_RR_SECURITY,
247};
248
Neels Hofmeyr10485162018-02-13 23:22:03 +0100249enum bts_gprs_mode {
250 BTS_GPRS_NONE = 0,
251 BTS_GPRS_GPRS = 1,
252 BTS_GPRS_EGPRS = 2,
253};
254
255struct gsm_lchan;
256struct osmo_rtp_socket;
257struct rtp_socket;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100258
259/* Network Management State */
260struct gsm_nm_state {
261 uint8_t operational;
262 uint8_t administrative;
263 uint8_t availability;
264};
265
266struct gsm_abis_mo {
267 uint8_t obj_class;
268 uint8_t procedure_pending;
269 struct abis_om_obj_inst obj_inst;
270 const char *name;
271 struct gsm_nm_state nm_state;
272 struct tlv_parsed *nm_attr;
273 struct gsm_bts *bts;
274};
275
276/* Ericsson OM2000 Managed Object */
277struct abis_om2k_mo {
278 uint8_t class;
279 uint8_t bts;
280 uint8_t assoc_so;
281 uint8_t inst;
282} __attribute__ ((packed));
283
284struct om2k_mo {
285 struct abis_om2k_mo addr;
286 struct osmo_fsm_inst *fsm;
287};
288
289#define A38_XOR_MIN_KEY_LEN 12
290#define A38_XOR_MAX_KEY_LEN 16
291#define A38_COMP128_KEY_LEN 16
292#define RSL_ENC_ALG_A5(x) (x+1)
293#define MAX_EARFCN_LIST 32
294
295/* is the data link established? who established it? */
296#define LCHAN_SAPI_UNUSED 0
297#define LCHAN_SAPI_MS 1
298#define LCHAN_SAPI_NET 2
299#define LCHAN_SAPI_REL 3
300
301/* state of a logical channel */
302enum gsm_lchan_state {
303 LCHAN_S_NONE, /* channel is not active */
304 LCHAN_S_ACT_REQ, /* channel activation requested */
305 LCHAN_S_ACTIVE, /* channel is active and operational */
306 LCHAN_S_REL_REQ, /* channel release has been requested */
307 LCHAN_S_REL_ERR, /* channel is in an error state */
308 LCHAN_S_BROKEN, /* channel is somehow unusable */
309 LCHAN_S_INACTIVE, /* channel is set inactive */
310};
311
312/* BTS ONLY */
313#define MAX_NUM_UL_MEAS 104
314#define LC_UL_M_F_L1_VALID (1 << 0)
315#define LC_UL_M_F_RES_VALID (1 << 1)
316
317struct bts_ul_meas {
318 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
319 uint16_t ber10k;
320 /* timing advance offset (in quarter bits) */
321 int16_t ta_offs_qbits;
322 /* C/I ratio in dB */
323 float c_i;
324 /* flags */
325 uint8_t is_sub:1;
326 /* RSSI in dBm * -1 */
327 uint8_t inv_rssi;
328};
329
330struct bts_codec_conf {
331 uint8_t hr;
332 uint8_t efr;
333 uint8_t amr;
334};
335
336struct amr_mode {
337 uint8_t mode;
338 uint8_t threshold;
339 uint8_t hysteresis;
340};
341
342struct amr_multirate_conf {
343 uint8_t gsm48_ie[2];
344 struct amr_mode ms_mode[4];
345 struct amr_mode bts_mode[4];
346 uint8_t num_modes;
347};
348/* /BTS ONLY */
349
350enum lchan_csd_mode {
351 LCHAN_CSD_M_NT,
352 LCHAN_CSD_M_T_1200_75,
353 LCHAN_CSD_M_T_600,
354 LCHAN_CSD_M_T_1200,
355 LCHAN_CSD_M_T_2400,
356 LCHAN_CSD_M_T_9600,
357 LCHAN_CSD_M_T_14400,
358 LCHAN_CSD_M_T_29000,
359 LCHAN_CSD_M_T_32000,
360};
361
362/* State of the SAPIs in the lchan */
363enum lchan_sapi_state {
364 LCHAN_SAPI_S_NONE,
365 LCHAN_SAPI_S_REQ,
366 LCHAN_SAPI_S_ASSIGNED,
367 LCHAN_SAPI_S_REL,
368 LCHAN_SAPI_S_ERROR,
369};
370
Neels Hofmeyr92b9f2e2018-02-14 00:19:11 +0100371#define MAX_A5_KEY_LEN (128/8)
372
373struct gsm_encr {
374 uint8_t alg_id;
375 uint8_t key_len;
376 uint8_t key[MAX_A5_KEY_LEN];
377};
378
Neels Hofmeyr8da22332018-04-11 01:43:41 +0200379#define LOGPLCHAN(lchan, ss, level, fmt, args...) \
380 LOGP(ss, level, "%s (ss=%d,%s) (%s) " fmt, \
381 lchan ? gsm_ts_and_pchan_name(lchan->ts) : "-", \
382 lchan ? lchan->nr : 0, \
383 lchan ? gsm_lchant_name(lchan->type) : "-", \
384 bsc_subscr_name(lchan && lchan->conn ? lchan->conn->bsub : NULL), \
385 ## args)
386
Neels Hofmeyr10485162018-02-13 23:22:03 +0100387struct gsm_lchan {
388 /* The TS that we're part of */
389 struct gsm_bts_trx_ts *ts;
390 /* The logical subslot number in the TS */
391 uint8_t nr;
392 /* The logical channel type */
393 enum gsm_chan_t type;
394 /* RSL channel mode */
395 enum rsl_cmod_spd rsl_cmode;
396 /* If TCH, traffic channel mode */
397 enum gsm48_chan_mode tch_mode;
398 enum lchan_csd_mode csd_mode;
399 /* State */
400 enum gsm_lchan_state state;
401 const char *broken_reason;
402 /* Power levels for MS and BTS */
403 uint8_t bs_power;
404 uint8_t ms_power;
405 /* Encryption information */
406 struct gsm_encr encr;
407
408 /* AMR bits */
409 uint8_t mr_ms_lv[7];
410 uint8_t mr_bts_lv[7];
411
412 /* Established data link layer services */
413 uint8_t sapis[8];
414
415 struct {
416 uint32_t bound_ip;
417 uint32_t connect_ip;
418 uint16_t bound_port;
419 uint16_t connect_port;
420 uint16_t conn_id;
421 uint8_t rtp_payload;
422 uint8_t rtp_payload2;
423 uint8_t speech_mode;
424 struct rtp_socket *rtp_socket;
425
426 /* info we need to postpone the AoIP
427 * assignment completed message */
428 struct {
429 uint8_t rr_cause;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100430 bool valid;
431 } ass_compl;
432 } abis_ip;
433
434 uint8_t rqd_ta;
435
436 char *name;
437
438 struct osmo_timer_list T3101;
439 struct osmo_timer_list T3109;
440 struct osmo_timer_list T3111;
441 struct osmo_timer_list error_timer;
442 struct osmo_timer_list act_timer;
443 struct osmo_timer_list rel_work;
444 uint8_t error_cause;
445
446 /* table of neighbor cell measurements */
447 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
448
449 /* cache of last measurement reports on this lchan */
450 struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
451 int meas_rep_idx;
452 int meas_rep_count;
Neels Hofmeyr35ba85c2018-02-12 16:47:40 +0100453 uint8_t meas_rep_last_seen_nr;
Neels Hofmeyr10485162018-02-13 23:22:03 +0100454
455 /* GSM Random Access data */
456 struct gsm48_req_ref *rqd_ref;
457
458 struct gsm_subscriber_connection *conn;
459
460 struct {
461 /* channel activation type and handover ref */
462 uint8_t act_type;
463 uint8_t ho_ref;
464 struct gsm48_req_ref *rqd_ref;
465 uint8_t rqd_ta;
466 } dyn;
467};
468
469enum {
470 TS_F_PDCH_ACTIVE = 0x1000,
471 TS_F_PDCH_ACT_PENDING = 0x2000,
472 TS_F_PDCH_DEACT_PENDING = 0x4000,
Neels Hofmeyr163f6312018-05-08 01:11:04 +0200473 TS_F_PDCH_PENDING_MASK = (TS_F_PDCH_ACT_PENDING | TS_F_PDCH_DEACT_PENDING),
Neels Hofmeyr10485162018-02-13 23:22:03 +0100474} gsm_bts_trx_ts_flags;
475
476/* One Timeslot in a TRX */
477struct gsm_bts_trx_ts {
478 struct gsm_bts_trx *trx;
Neels Hofmeyr91aa68f2018-05-09 17:46:22 +0200479 bool initialized;
480
Neels Hofmeyr10485162018-02-13 23:22:03 +0100481 /* number of this timeslot at the TRX */
482 uint8_t nr;
483
484 enum gsm_phys_chan_config pchan;
485
486 struct {
487 enum gsm_phys_chan_config pchan_is;
488 enum gsm_phys_chan_config pchan_want;
489 struct msgb *pending_chan_activ;
490 } dyn;
491
492 unsigned int flags;
493 struct gsm_abis_mo mo;
494 struct tlv_parsed nm_attr;
495 uint8_t nm_chan_comb;
496 int tsc; /* -1 == use BTS TSC */
497
498 struct {
499 /* Parameters below are configured by VTY */
500 int enabled;
501 uint8_t maio;
502 uint8_t hsn;
503 struct bitvec arfcns;
504 uint8_t arfcns_data[1024/8];
505 /* This is the pre-computed MA for channel assignments */
506 struct bitvec ma;
507 uint8_t ma_len; /* part of ma_data that is used */
508 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
509 } hopping;
510
511 /* To which E1 subslot are we connected */
512 struct gsm_e1_subslot e1_link;
513
514 union {
515 struct {
516 struct om2k_mo om2k_mo;
517 } rbs2000;
518 };
519
520 struct gsm_lchan lchan[TS_MAX_LCHAN];
521};
522
523/* One TRX in a BTS */
524struct gsm_bts_trx {
525 /* list header in bts->trx_list */
526 struct llist_head list;
527
528 struct gsm_bts *bts;
529 /* number of this TRX in the BTS */
530 uint8_t nr;
531 /* human readable name / description */
532 char *description;
533 /* how do we talk RSL with this TRX? */
534 struct gsm_e1_subslot rsl_e1_link;
535 uint8_t rsl_tei;
536 struct e1inp_sign_link *rsl_link;
537
538 /* Timeout for initiating the RSL connection. */
539 struct osmo_timer_list rsl_connect_timeout;
540
541 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
542 struct e1inp_sign_link *oml_link;
543
544 struct gsm_abis_mo mo;
545 struct tlv_parsed nm_attr;
546 struct {
547 struct gsm_abis_mo mo;
548 } bb_transc;
549
550 uint16_t arfcn;
551 int nominal_power; /* in dBm */
552 unsigned int max_power_red; /* in actual dB */
553
554 union {
555 struct {
556 struct {
557 struct gsm_abis_mo mo;
558 } bbsig;
559 struct {
560 struct gsm_abis_mo mo;
561 } pa;
562 } bs11;
563 struct {
564 unsigned int test_state;
565 uint8_t test_nr;
566 struct rxlev_stats rxlev_stat;
567 } ipaccess;
568 struct {
569 struct {
570 struct om2k_mo om2k_mo;
571 } trxc;
572 struct {
573 struct om2k_mo om2k_mo;
574 } rx;
575 struct {
576 struct om2k_mo om2k_mo;
577 } tx;
578 } rbs2000;
579 };
580 struct gsm_bts_trx_ts ts[TRX_NR_TS];
581};
582
583#define GSM_BTS_SI2Q(bts, i) (struct gsm48_system_information_type_2quater *)((bts)->si_buf[SYSINFO_TYPE_2quater][i])
584#define GSM_BTS_HAS_SI(bts, i) ((bts)->si_valid & (1 << i))
585#define GSM_BTS_SI(bts, i) (void *)((bts)->si_buf[i][0])
586#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
587
588enum gsm_bts_type {
589 GSM_BTS_TYPE_UNKNOWN,
590 GSM_BTS_TYPE_BS11,
591 GSM_BTS_TYPE_NANOBTS,
592 GSM_BTS_TYPE_RBS2000,
593 GSM_BTS_TYPE_NOKIA_SITE,
594 GSM_BTS_TYPE_OSMOBTS,
595 _NUM_GSM_BTS_TYPE
596};
597
598enum gsm_bts_type_variant {
599 BTS_UNKNOWN,
600 BTS_OSMO_LITECELL15,
601 BTS_OSMO_OCTPHY,
602 BTS_OSMO_SYSMO,
603 BTS_OSMO_TRX,
604 _NUM_BTS_VARIANT
605};
606
607/* Used by OML layer for BTS Attribute reporting */
608enum bts_attribute {
609 BTS_TYPE_VARIANT,
610 BTS_SUB_MODEL,
611 TRX_PHY_VERSION,
612};
613
614struct vty;
615
616struct gsm_bts_model {
617 struct llist_head list;
618
619 enum gsm_bts_type type;
620 enum gsm_bts_type_variant variant;
621 const char *name;
622
623 bool started;
624 int (*start)(struct gsm_network *net);
625 int (*oml_rcvmsg)(struct msgb *msg);
626 char * (*oml_status)(const struct gsm_bts *bts);
Neels Hofmeyr91aa68f2018-05-09 17:46:22 +0200627 bool (*oml_is_ts_ready)(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr10485162018-02-13 23:22:03 +0100628
629 void (*e1line_bind_ops)(struct e1inp_line *line);
630
631 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
632 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
633 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
634
635 struct tlv_definition nm_att_tlvdef;
636
637 /* features of a given BTS model set via gsm_bts_model_register() locally */
638 struct bitvec features;
639 uint8_t _features_data[MAX_BTS_FEATURES/8];
640};
641
Neels Hofmeyr10485162018-02-13 23:22:03 +0100642
Neels Hofmeyr10485162018-02-13 23:22:03 +0100643
644/*
645 * This keeps track of the paging status of one BTS. It
646 * includes a number of pending requests, a back pointer
647 * to the gsm_bts, a timer and some more state.
648 */
649struct gsm_bts_paging_state {
650 /* pending requests */
651 struct llist_head pending_requests;
652 struct gsm_bts *bts;
653
654 struct osmo_timer_list work_timer;
655 struct osmo_timer_list credit_timer;
656
657 /* free chans needed */
658 int free_chans_need;
659
660 /* load */
661 uint16_t available_slots;
662};
663
664struct gsm_envabtse {
665 struct gsm_abis_mo mo;
666};
667
668struct gsm_bts_gprs_nsvc {
669 struct gsm_bts *bts;
670 /* data read via VTY config file, to configure the BTS
671 * via OML from BSC */
672 int id;
673 uint16_t nsvci;
674 uint16_t local_port; /* on the BTS */
675 uint16_t remote_port; /* on the SGSN */
676 uint32_t remote_ip; /* on the SGSN */
677
678 struct gsm_abis_mo mo;
679};
680
681enum gprs_rlc_par {
682 RLC_T3142,
683 RLC_T3169,
684 RLC_T3191,
685 RLC_T3193,
686 RLC_T3195,
687 RLC_N3101,
688 RLC_N3103,
689 RLC_N3105,
690 CV_COUNTDOWN,
691 T_DL_TBF_EXT, /* ms */
692 T_UL_TBF_EXT, /* ms */
693 _NUM_RLC_PAR
694};
695
696enum gprs_cs {
697 GPRS_CS1,
698 GPRS_CS2,
699 GPRS_CS3,
700 GPRS_CS4,
701 GPRS_MCS1,
702 GPRS_MCS2,
703 GPRS_MCS3,
704 GPRS_MCS4,
705 GPRS_MCS5,
706 GPRS_MCS6,
707 GPRS_MCS7,
708 GPRS_MCS8,
709 GPRS_MCS9,
710 _NUM_GRPS_CS
711};
712
713struct gprs_rlc_cfg {
714 uint16_t parameter[_NUM_RLC_PAR];
715 struct {
716 uint16_t repeat_time; /* ms */
717 uint8_t repeat_count;
718 } paging;
719 uint32_t cs_mask; /* bitmask of gprs_cs */
720 uint8_t initial_cs;
721 uint8_t initial_mcs;
722};
723
724
725enum neigh_list_manual_mode {
726 NL_MODE_AUTOMATIC = 0,
727 NL_MODE_MANUAL = 1,
728 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
729};
730
731enum bts_loc_fix {
732 BTS_LOC_FIX_INVALID = 0,
733 BTS_LOC_FIX_2D = 1,
734 BTS_LOC_FIX_3D = 2,
735};
736
737extern const struct value_string bts_loc_fix_names[];
738
739struct bts_location {
740 struct llist_head list;
741 time_t tstamp;
742 enum bts_loc_fix valid;
743 double lat;
744 double lon;
745 double height;
746};
747
748/* Channel load counter */
749struct load_counter {
750 unsigned int total;
751 unsigned int used;
752};
753
Neels Hofmeyr19bed232018-03-22 04:54:57 +0100754/* Useful to track N-N relations between BTS, for example neighbors. */
755struct gsm_bts_ref {
756 struct llist_head entry;
757 struct gsm_bts *bts;
758};
759
Neels Hofmeyr10485162018-02-13 23:22:03 +0100760/* One BTS */
761struct gsm_bts {
762 /* list header in net->bts_list */
763 struct llist_head list;
764
765 /* Geographical location of the BTS */
766 struct llist_head loc_list;
767
768 /* number of ths BTS in network */
769 uint8_t nr;
770 /* human readable name / description */
771 char *description;
772 /* Cell Identity */
773 uint16_t cell_identity;
774 /* location area code of this BTS */
775 uint16_t location_area_code;
776 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
777 * which is used as TSC for the CCCH */
778 uint8_t bsic;
779 /* type of BTS */
780 enum gsm_bts_type type;
781 enum gsm_bts_type_variant variant;
782 struct gsm_bts_model *model;
783 enum gsm_band band;
784 char version[MAX_VERSION_LENGTH];
785 char sub_model[MAX_VERSION_LENGTH];
786
787 /* features of a given BTS set/reported via OML */
788 struct bitvec features;
789 uint8_t _features_data[MAX_BTS_FEATURES/8];
790
791 /* Connected PCU version (if any) */
792 char pcu_version[MAX_VERSION_LENGTH];
793
794 /* maximum Tx power that the MS is permitted to use in this cell */
795 int ms_max_power;
796
797 /* how do we talk OML with this TRX? */
798 struct gsm_e1_subslot oml_e1_link;
799 uint8_t oml_tei;
800 struct e1inp_sign_link *oml_link;
801 /* when OML link was established */
802 time_t uptime;
803
804 /* Abis network management O&M handle */
805 struct abis_nm_h *nmh;
806
807 struct gsm_abis_mo mo;
808
809 /* number of this BTS on given E1 link */
810 uint8_t bts_nr;
811
812 /* DTX features of this BTS */
813 enum gsm48_dtx_mode dtxu;
814 bool dtxd;
815
816 /* paging state and control */
817 struct gsm_bts_paging_state paging;
818
819 /* CCCH is on C0 */
820 struct gsm_bts_trx *c0;
821
822 struct {
823 struct gsm_abis_mo mo;
824 } site_mgr;
825
826 /* bitmask of all SI that are present/valid in si_buf */
827 uint32_t si_valid;
828 /* 3GPP TS 44.018 Table 10.5.2.33b.1 INDEX and COUNT for SI2quater */
829 uint8_t si2q_index; /* distinguish individual SI2quater messages */
830 uint8_t si2q_count; /* si2q_index for the last (highest indexed) individual SI2quater message */
831 /* buffers where we put the pre-computed SI */
832 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
833 /* offsets used while generating SI2quater */
834 size_t e_offset;
835 size_t u_offset;
836
837 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
838 union {
839 struct {
840 uint16_t site_id;
841 uint16_t bts_id;
842 uint32_t flags;
843 uint32_t rsl_ip;
844 } ip_access;
845 struct {
846 struct {
847 struct gsm_abis_mo mo;
848 } cclk;
849 struct {
850 struct gsm_abis_mo mo;
851 } rack;
852 struct gsm_envabtse envabtse[4];
853 } bs11;
854 struct {
855 struct {
856 struct om2k_mo om2k_mo;
857 struct gsm_abis_mo mo;
858 struct llist_head conn_groups;
859 } cf;
860 struct {
861 struct om2k_mo om2k_mo;
862 struct gsm_abis_mo mo;
863 struct llist_head conn_groups;
864 } is;
865 struct {
866 struct om2k_mo om2k_mo;
867 struct gsm_abis_mo mo;
868 struct llist_head conn_groups;
869 } con;
870 struct {
871 struct om2k_mo om2k_mo;
872 struct gsm_abis_mo mo;
873 } dp;
874 struct {
875 struct om2k_mo om2k_mo;
876 struct gsm_abis_mo mo;
877 } tf;
878 uint32_t use_superchannel:1;
879 } rbs2000;
880 struct {
881 uint8_t bts_type;
882 unsigned int configured:1,
883 skip_reset:1,
884 no_loc_rel_cnf:1,
885 bts_reset_timer_cnf,
886 did_reset:1,
887 wait_reset:1;
888 struct osmo_timer_list reset_timer;
889 } nokia;
890 };
891
892 /* Not entirely sure how ip.access specific this is */
893 struct {
894 uint8_t supports_egprs_11bit_rach;
895 enum bts_gprs_mode mode;
896 struct {
897 struct gsm_abis_mo mo;
898 uint16_t nsei;
899 uint8_t timer[7];
900 } nse;
901 struct {
902 struct gsm_abis_mo mo;
903 uint16_t bvci;
904 uint8_t timer[11];
905 struct gprs_rlc_cfg rlc_cfg;
906 } cell;
907 struct gsm_bts_gprs_nsvc nsvc[2];
908 uint8_t rac;
909 uint8_t net_ctrl_ord;
910 bool ctrl_ack_type_use_block;
911 } gprs;
912
913 /* RACH NM values */
914 int rach_b_thresh;
915 int rach_ldavg_slots;
916
917 /* transceivers */
918 int num_trx;
919 struct llist_head trx_list;
920
921 /* SI related items */
922 int force_combined_si;
923 int bcch_change_mark;
924
925 /* Abis NM queue */
926 struct llist_head abis_queue;
927 int abis_nm_pend;
928
929 struct gsm_network *network;
930
931 /* should the channel allocator allocate channels from high TRX to TRX0,
932 * rather than starting from TRX0 and go upwards? */
933 int chan_alloc_reverse;
934
935 enum neigh_list_manual_mode neigh_list_manual_mode;
936 /* parameters from which we build SYSTEM INFORMATION */
937 struct {
938 struct gsm48_rach_control rach_control;
939 uint8_t ncc_permitted;
940 struct gsm48_cell_sel_par cell_sel_par;
941 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
942 struct gsm48_cell_options cell_options;
943 struct gsm48_control_channel_descr chan_desc;
944 struct bitvec neigh_list;
945 struct bitvec cell_alloc;
946 struct bitvec si5_neigh_list;
947 struct osmo_earfcn_si2q si2quater_neigh_list;
948 size_t uarfcn_length; /* index for uarfcn and scramble lists */
949 struct {
950 /* bitmask large enough for all possible ARFCN's */
951 uint8_t neigh_list[1024/8];
952 uint8_t cell_alloc[1024/8];
953 /* If the user wants a different neighbor list in SI5 than in SI2 */
954 uint8_t si5_neigh_list[1024/8];
955 uint8_t meas_bw_list[MAX_EARFCN_LIST];
956 uint16_t earfcn_list[MAX_EARFCN_LIST];
957 uint16_t uarfcn_list[MAX_EARFCN_LIST];
958 uint16_t scramble_list[MAX_EARFCN_LIST];
959 } data;
960 } si_common;
961 bool early_classmark_allowed;
962 bool early_classmark_allowed_3g;
963 /* for testing only: Have an infinitely long radio link timeout */
964 bool infinite_radio_link_timeout;
965
966 /* do we use static (user-defined) system information messages? (bitmask) */
967 uint32_t si_mode_static;
968
Stefan Sperling6442e432018-02-06 14:44:54 +0100969 /* access control class ramping */
970 struct acc_ramp acc_ramp;
971
Neels Hofmeyr10485162018-02-13 23:22:03 +0100972 /* exclude the BTS from the global RF Lock handling */
973 int excl_from_rf_lock;
974
975 /* supported codecs beside FR */
976 struct bts_codec_conf codec;
977
978 /* BTS dependencies bit field */
979 uint32_t depends_on[256/(8*4)];
980
981 /* full and half rate multirate config */
982 struct amr_multirate_conf mr_full;
983 struct amr_multirate_conf mr_half;
984
985 /* PCU socket state */
986 char *pcu_sock_path;
987 struct pcu_sock_state *pcu_state;
988
989 struct rate_ctr_group *bts_ctrs;
990 struct osmo_stat_item_group *bts_statg;
991
992 struct handover_cfg *ho;
993
Neels Hofmeyr19bed232018-03-22 04:54:57 +0100994 /* A list of struct gsm_bts_ref, indicating neighbors of this BTS.
995 * When the si_common neigh_list is in automatic mode, it is populated from this list as well as
996 * gsm_network->neighbor_bss_cells. */
997 struct llist_head local_neighbors;
998
Neels Hofmeyr10485162018-02-13 23:22:03 +0100999 /* BTS-specific overrides for timer values from struct gsm_network. */
1000 uint8_t T3122; /* ASSIGMENT REJECT wait indication */
1001
1002 /* Periodic channel load measurements are used to maintain T3122. */
1003 struct load_counter chan_load_samples[7];
1004 int chan_load_samples_idx;
Stefan Sperling6442e432018-02-06 14:44:54 +01001005 uint8_t chan_load_avg; /* current channel load average in percent (0 - 100). */
Neels Hofmeyr10485162018-02-13 23:22:03 +01001006};
1007
1008
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001009struct gsm_network *gsm_network_init(void *ctx);
1010
Neels Hofmeyr10485162018-02-13 23:22:03 +01001011struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, uint8_t bts_num);
1012struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001013bool gsm_bts_matches_lai(const struct gsm_bts *bts, const struct osmo_location_area_id *lai);
1014bool gsm_bts_matches_cell_id(const struct gsm_bts *bts, const struct gsm0808_cell_id *cell_id);
1015struct gsm_bts *gsm_bts_by_cell_id(const struct gsm_network *net,
1016 const struct gsm0808_cell_id *cell_id,
1017 int match_idx);
1018int gsm_bts_local_neighbor_add(struct gsm_bts *bts, struct gsm_bts *neighbor);
1019int gsm_bts_local_neighbor_del(struct gsm_bts *bts, const struct gsm_bts *neighbor);
Neels Hofmeyr10485162018-02-13 23:22:03 +01001020
1021struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
1022struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
1023
1024enum gsm_bts_type str2btstype(const char *arg);
1025const char *btstype2str(enum gsm_bts_type type);
1026
1027enum bts_attribute str2btsattr(const char *s);
1028const char *btsatttr2str(enum bts_attribute v);
1029
1030enum gsm_bts_type_variant str2btsvariant(const char *arg);
1031const char *btsvariant2str(enum gsm_bts_type_variant v);
1032
1033extern const struct value_string gsm_chreq_descs[];
1034const struct value_string gsm_pchant_names[13];
1035const struct value_string gsm_pchant_descs[13];
1036const char *gsm_pchan_name(enum gsm_phys_chan_config c);
1037enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
1038const char *gsm_lchant_name(enum gsm_chan_t c);
1039const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
1040char *gsm_trx_name(const struct gsm_bts_trx *trx);
1041char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
1042char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
1043char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
1044const char *gsm_lchans_name(enum gsm_lchan_state s);
1045
1046static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
1047{
1048 return lchan->name;
1049}
1050
Neels Hofmeyr10485162018-02-13 23:22:03 +01001051void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
1052
1053struct gsm_nm_state *
1054gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
1055 const struct abis_om_obj_inst *obj_inst);
1056void *
1057gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
1058 const struct abis_om_obj_inst *obj_inst);
1059
1060/* reset the state of all MO in the BTS */
1061void gsm_bts_mo_reset(struct gsm_bts *bts);
1062
1063uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
1064 uint8_t ts_nr, uint8_t lchan_nr);
1065uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
1066uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
1067 enum gsm_phys_chan_config as_pchan);
1068
1069/* return the gsm_lchan for the CBCH (if it exists at all) */
1070struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
1071
1072/*
1073 * help with parsing regexps
1074 */
1075int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
1076 int argc, const char **argv) __attribute__ ((warn_unused_result));
1077
1078static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
1079{
1080 if (ts->tsc != -1)
1081 return ts->tsc;
1082 else
1083 return ts->trx->bts->bsic & 7;
1084}
1085
1086struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
1087 int *rc);
1088
1089enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
1090uint8_t ts_subslots(struct gsm_bts_trx_ts *ts);
1091bool ts_is_tch(struct gsm_bts_trx_ts *ts);
1092
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01001093
Harald Welteb7948872017-12-18 18:48:21 +01001094static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection *conn) {
1095 OSMO_ASSERT(conn->lchan);
1096 return conn->lchan->ts->trx->bts;
1097}
1098
Harald Welted82101e2017-12-09 23:07:38 +01001099enum {
1100 BTS_CTR_CHREQ_TOTAL,
1101 BTS_CTR_CHREQ_NO_CHANNEL,
1102 BTS_CTR_CHAN_RF_FAIL,
1103 BTS_CTR_CHAN_RLL_ERR,
1104 BTS_CTR_BTS_OML_FAIL,
1105 BTS_CTR_BTS_RSL_FAIL,
1106 BTS_CTR_CODEC_AMR_F,
1107 BTS_CTR_CODEC_AMR_H,
1108 BTS_CTR_CODEC_EFR,
1109 BTS_CTR_CODEC_V1_FR,
1110 BTS_CTR_CODEC_V1_HR,
Harald Weltecf9d4312017-12-13 23:17:16 +01001111 BTS_CTR_PAGING_ATTEMPTED,
1112 BTS_CTR_PAGING_ALREADY,
1113 BTS_CTR_PAGING_RESPONDED,
1114 BTS_CTR_PAGING_EXPIRED,
Harald Welte4f598922017-12-14 13:47:02 +01001115 BTS_CTR_CHAN_ACT_TOTAL,
1116 BTS_CTR_CHAN_ACT_NACK,
Harald Welte62d9cb02017-12-14 14:00:26 +01001117 BTS_CTR_RSL_UNKNOWN,
Harald Welte581398a2017-12-14 14:29:44 +01001118 BTS_CTR_RSL_IPA_NACK,
Harald Welte00d64fd2017-12-14 14:34:16 +01001119 BTS_CTR_MODE_MODIFY_NACK,
Harald Welted82101e2017-12-09 23:07:38 +01001120};
1121
1122static const struct rate_ctr_desc bts_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001123 [BTS_CTR_CHREQ_TOTAL] = {"chreq:total", "Received channel requests."},
1124 [BTS_CTR_CHREQ_NO_CHANNEL] = {"chreq:no_channel", "Sent to MS no channel available."},
1125 [BTS_CTR_CHAN_RF_FAIL] = {"chan:rf_fail", "Received a RF failure indication from BTS."},
1126 [BTS_CTR_CHAN_RLL_ERR] = {"chan:rll_err", "Received a RLL failure with T200 cause from BTS."},
Harald Welted82101e2017-12-09 23:07:38 +01001127 [BTS_CTR_BTS_OML_FAIL] = {"oml_fail", "Received a TEI down on a OML link."},
1128 [BTS_CTR_BTS_RSL_FAIL] = {"rsl_fail", "Received a TEI down on a OML link."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001129 [BTS_CTR_CODEC_AMR_F] = {"codec:amr_f", "Count the usage of AMR/F codec by channel mode requested."},
1130 [BTS_CTR_CODEC_AMR_H] = {"codec:amr_h", "Count the usage of AMR/H codec by channel mode requested."},
1131 [BTS_CTR_CODEC_EFR] = {"codec:efr", "Count the usage of EFR codec by channel mode requested."},
1132 [BTS_CTR_CODEC_V1_FR] = {"codec:fr", "Count the usage of FR codec by channel mode requested."},
1133 [BTS_CTR_CODEC_V1_HR] = {"codec:hr", "Count the usage of HR codec by channel mode requested."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001134
1135 [BTS_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
1136 [BTS_CTR_PAGING_ALREADY] = {"paging:already", "Paging attempts ignored as subsciber was already being paged."},
1137 [BTS_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful paging response."},
1138 [BTS_CTR_PAGING_EXPIRED] = {"paging:expired", "Paging Request expired because of timeout T3113."},
Harald Welte4f598922017-12-14 13:47:02 +01001139 [BTS_CTR_CHAN_ACT_TOTAL] = {"chan_act:total", "Total number of Channel Activations."},
1140 [BTS_CTR_CHAN_ACT_NACK] = {"chan_act:nack", "Number of Channel Activations that the BTS NACKed"},
Harald Welte62d9cb02017-12-14 14:00:26 +01001141 [BTS_CTR_RSL_UNKNOWN] = {"rsl:unknown", "Number of unknown/unsupported RSL messages received from BTS"},
Harald Welte581398a2017-12-14 14:29:44 +01001142 [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 +01001143 [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 +01001144};
1145
1146static const struct rate_ctr_group_desc bts_ctrg_desc = {
1147 "bts",
1148 "base transceiver station",
1149 OSMO_STATS_CLASS_GLOBAL,
1150 ARRAY_SIZE(bts_ctr_description),
1151 bts_ctr_description,
1152};
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001153
Alexander Couzens20423ea2016-07-12 15:42:02 +02001154enum {
Stefan Sperling81dc9e72018-02-05 17:34:36 +01001155 BTS_STAT_CHAN_LOAD_AVERAGE,
1156 BTS_STAT_T3122,
1157};
1158
1159enum {
Alexander Couzensb847a212016-08-02 11:34:11 +02001160 BSC_CTR_HANDOVER_ATTEMPTED,
1161 BSC_CTR_HANDOVER_NO_CHANNEL,
1162 BSC_CTR_HANDOVER_TIMEOUT,
1163 BSC_CTR_HANDOVER_COMPLETED,
1164 BSC_CTR_HANDOVER_FAILED,
1165 BSC_CTR_PAGING_ATTEMPTED,
1166 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +01001167 BSC_CTR_PAGING_RESPONDED,
Stefan Sperling7926d982018-05-17 14:52:02 +02001168 BSC_CTR_UNKNOWN_UNIT_ID,
Alexander Couzensb847a212016-08-02 11:34:11 +02001169};
1170
1171static const struct rate_ctr_desc bsc_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +01001172 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Received handover attempts."},
1173 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Sent no channel available responses."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001174 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Timeouts of timer T3103."},
Harald Welte1ef46d92017-12-09 23:10:46 +01001175 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Received handover completed."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001176 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Received HO FAIL messages."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001177
1178 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Stefan Sperling71d524c2018-05-17 14:38:27 +02001179 [BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Paging request send failures because no responsible BTS was found."},
Harald Weltecf9d4312017-12-13 23:17:16 +01001180 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response."},
Stefan Sperling7926d982018-05-17 14:52:02 +02001181
1182 [BSC_CTR_UNKNOWN_UNIT_ID] = {"abis:unknown_unit_id", "Connection attempts from unknown IPA CCM Unit ID."},
Alexander Couzensb847a212016-08-02 11:34:11 +02001183};
1184
Alexander Couzensb847a212016-08-02 11:34:11 +02001185
1186
1187static const struct rate_ctr_group_desc bsc_ctrg_desc = {
1188 "bsc",
1189 "base station controller",
1190 OSMO_STATS_CLASS_GLOBAL,
1191 ARRAY_SIZE(bsc_ctr_description),
1192 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +02001193};
1194
Harald Weltedea252d2017-12-10 19:55:18 +01001195#define GSM_T3101_DEFAULT 3 /* s */
Harald Weltea0d324b2017-07-20 01:47:39 +02001196#define GSM_T3103_DEFAULT 5 /* s */
1197#define GSM_T3105_DEFAULT 100 /* ms */
1198#define GSM_T3107_DEFAULT 5 /* s */
Harald Welteed23c1d2017-12-10 19:58:16 +01001199#define GSM_T3109_DEFAULT 5 /* s, must be 2s + radio_link_timeout*0.48 */
Harald Weltea0d324b2017-07-20 01:47:39 +02001200#define GSM_T3111_DEFAULT 2 /* s */
Harald Welte6e59ced2017-12-14 12:49:43 +01001201#define GSM_T3113_DEFAULT 10 /* s */
Harald Weltea0d324b2017-07-20 01:47:39 +02001202#define GSM_T3115_DEFAULT 10
1203#define GSM_T3117_DEFAULT 10
1204#define GSM_T3119_DEFAULT 10
Andreas Eversberg75e13a42013-02-07 11:51:16 +01001205#define GSM_T3122_DEFAULT 10
Harald Weltea0d324b2017-07-20 01:47:39 +02001206#define GSM_T3141_DEFAULT 10
Neels Hofmeyr0c1ac9f2018-06-05 15:37:59 +02001207#define GSM_T10_DEFAULT 6 /* RR Assignment timeout, in seconds */
Neels Hofmeyr0abe84e2018-05-14 18:14:29 +02001208#define GSM_T7_DEFAULT 10 /* inter-BSC MO Handover first timeout, in seconds */
1209#define GSM_T8_DEFAULT 10 /* inter-BSC MO Handover second timeout, in seconds */
1210#define GSM_T101_DEFAULT 10 /* inter-BSC MT Handover timeout, in seconds */
Harald Welteb84ddfc2009-12-01 17:36:54 +05301211
Neels Hofmeyr73983952016-05-10 13:29:33 +02001212struct gsm_tz {
1213 int override; /* if 0, use system's time zone instead. */
1214 int hr; /* hour */
1215 int mn; /* minute */
1216 int dst; /* daylight savings */
1217};
1218
Harald Welte52b1f982008-12-23 20:25:15 +00001219struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001220 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
1221 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
1222 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
1223 * these have in common, like country and network code, put in yet
1224 * separate structs and placed as members in osmo_bsc and osmo_msc. */
1225
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001226 struct osmo_plmn_id plmn;
1227
Harald Welte51e4bf32017-12-23 17:30:18 +01001228 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
1229 uint8_t a5_encryption_mask;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001230 int neci;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001231
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001232 struct handover_cfg *ho;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001233 struct {
1234 unsigned int congestion_check_interval_s;
1235 struct osmo_timer_list congestion_check_timer;
1236 } hodec2;
Harald Welte52b1f982008-12-23 20:25:15 +00001237
Alexander Couzensb847a212016-08-02 11:34:11 +02001238 struct rate_ctr_group *bsc_ctrs;
Harald Welte24ff6ee2009-12-22 00:41:05 +01001239
Harald Welte52b1f982008-12-23 20:25:15 +00001240 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +02001241 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001242
1243 /* timer values */
1244 int T3101;
Neels Hofmeyr0abe84e2018-05-14 18:14:29 +02001245 int T3103; /*< Handover timeout */
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +01001246 int T3105;
1247 int T3107;
1248 int T3109;
1249 int T3111;
1250 int T3113;
1251 int T3115;
1252 int T3117;
1253 int T3119;
Harald Welte2862dca2010-12-23 14:39:29 +01001254 int T3122;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +01001255 int T3141;
Neels Hofmeyr0c1ac9f2018-06-05 15:37:59 +02001256 int T10; /*< RR Assignment timeout, in seconds */
Neels Hofmeyr0abe84e2018-05-14 18:14:29 +02001257 int T7; /*< inter-BSC handover MO timeout from Handover Required to Handover Command */
1258 int T8; /*< inter-BSC handover MO timeout from Handover Command to final Clear*/
1259 int T101; /*< inter-BSC handover MT timeout from Handover Request to Handover Accept */
Harald Welteeab84a12009-12-13 10:53:12 +01001260
Alexander Couzens547c2072017-11-21 12:03:04 +01001261 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +08001262
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +08001263 /* Use a TCH for handling requests of type paging any */
1264 int pag_any_tch;
1265
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08001266 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +02001267 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +01001268
Daniel Willmann6fc4a982011-07-22 17:55:42 +02001269 /* control interface */
1270 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +02001271
1272 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
1273 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +02001274
1275 /* all active subscriber connections. */
1276 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +02001277
1278 /* if override is nonzero, this timezone data is used for all MM
1279 * contexts. */
1280 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
1281 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +01001282 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +02001283 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +01001284
1285 /* List of all struct bsc_subscr used in libbsc. This llist_head is
1286 * allocated so that the llist_head pointer itself can serve as a
1287 * talloc context (useful to not have to pass the entire gsm_network
1288 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
1289 * not require gsm_data.h). In an MSC-without-BSC environment, this
1290 * pointer is NULL to indicate absence of a bsc_subscribers list. */
1291 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +02001292
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +02001293 /* Periodic location update default value */
1294 uint8_t t3212;
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001295
Stefan Sperling6cee8932018-01-30 18:14:22 +01001296 /* Timer for periodic channel load measurements to maintain each BTS's T3122. */
1297 struct osmo_timer_list t3122_chan_load_timer;
1298
Neels Hofmeyrc29505e2016-05-20 21:59:55 +02001299 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +02001300 struct mgcp_client_conf *conf;
1301 struct mgcp_client *client;
1302 } mgw;
Neels Hofmeyr19bed232018-03-22 04:54:57 +01001303
1304 /* Remote BSS Cell Identifier Lists */
1305 struct neighbor_ident_list *neighbor_bss_cells;
Harald Welte7e310b12009-03-30 20:56:32 +00001306};
1307
Neels Hofmeyrf93970b2018-03-05 02:09:40 +01001308static inline const struct osmo_location_area_id *bts_lai(struct gsm_bts *bts)
1309{
1310 static struct osmo_location_area_id lai;
1311 lai = (struct osmo_location_area_id){
1312 .plmn = bts->network->plmn,
1313 .lac = bts->location_area_code,
1314 };
1315 return &lai;
1316}
1317
Neels Hofmeyrc13e6872016-05-11 13:53:47 +02001318extern void talloc_ctx_init(void *ctx_root);
1319
Harald Welte39315c42010-01-10 18:01:52 +01001320int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +02001321
Harald Welte1d014a52009-08-08 15:38:29 +02001322enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +02001323const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +00001324struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
1325 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +00001326
Andreas Eversberg8226fa72009-06-29 15:19:38 +02001327extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +01001328extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +02001329
Harald Weltef383aa12012-07-02 19:51:55 +02001330/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +00001331static inline int is_ipaccess_bts(struct gsm_bts *bts)
1332{
1333 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001334 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001335 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +00001336 return 1;
1337 default:
1338 break;
1339 }
1340 return 0;
1341}
1342
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001343static inline int is_sysmobts_v2(struct gsm_bts *bts)
1344{
1345 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +01001346 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +02001347 return 1;
1348 default:
1349 break;
1350 }
1351 return 0;
1352}
1353
Harald Welte5b570672009-08-10 10:08:01 +02001354static inline int is_siemens_bts(struct gsm_bts *bts)
1355{
1356 switch (bts->type) {
1357 case GSM_BTS_TYPE_BS11:
1358 return 1;
1359 default:
1360 break;
1361 }
1362
1363 return 0;
1364}
1365
Andreas Eversberg7d8fa342013-12-05 13:25:06 +01001366static inline int is_nokia_bts(struct gsm_bts *bts)
1367{
1368 switch (bts->type) {
1369 case GSM_BTS_TYPE_NOKIA_SITE:
1370 return 1;
1371 default:
1372 break;
1373 }
1374
1375 return 0;
1376}
1377
Andreas Eversbergdcf38e12013-12-05 14:37:11 +01001378static inline int is_e1_bts(struct gsm_bts *bts)
1379{
1380 switch (bts->type) {
1381 case GSM_BTS_TYPE_BS11:
1382 case GSM_BTS_TYPE_RBS2000:
1383 case GSM_BTS_TYPE_NOKIA_SITE:
1384 return 1;
1385 default:
1386 break;
1387 }
1388
1389 return 0;
1390}
1391
Harald Welte1876c312018-05-27 11:53:43 +02001392extern struct gsm_network *bsc_gsmnet;
1393
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001394enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +02001395const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +01001396int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +02001397
Neels Hofmeyr4d358c02018-02-22 03:19:05 +01001398void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +08001399void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +01001400
Harald Weltefbda4e12010-03-04 11:04:52 +01001401int gsm_bts_model_register(struct gsm_bts_model *model);
1402
Harald Welte3561bd42018-01-28 03:04:16 +01001403struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *network);
Neels Hofmeyr42eb0142016-05-20 17:15:44 +02001404
1405struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
1406void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +08001407
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001408struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, uint8_t bsic);
1409struct 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 +01001410
Harald Welte3300c012011-06-05 13:31:33 +02001411void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
1412 uint8_t e1_ts, uint8_t e1_ts_ss);
1413
Maxbe356ed2017-09-07 19:10:09 +02001414void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Harald Welte3300c012011-06-05 13:31:33 +02001415struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +01001416int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -04001417int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +02001418
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +02001419/* generic E1 line operations for all ISDN-based BTS. */
1420extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
1421
Harald Weltee555c2b2012-08-17 13:02:12 +02001422extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
1423extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
1424
Max3d049d22017-10-09 17:12:53 +02001425char *get_model_oml_status(const struct gsm_bts *bts);
1426
Max25cc4072017-10-10 14:50:35 +02001427unsigned long long bts_uptime(const struct gsm_bts *bts);
1428
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +01001429/* control interface handling */
1430int bsc_base_ctrl_cmds_install(void);
1431
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001432/* dependency handling */
1433void bts_depend_mark(struct gsm_bts *bts, int dep);
1434void bts_depend_clear(struct gsm_bts *bts, int dep);
1435int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +01001436int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +01001437
Harald Welte2f8b9d22017-06-18 11:12:13 +03001438int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
1439void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
1440
Harald Weltea43e0b42016-06-19 18:06:02 +02001441bool classmark_is_r99(struct gsm_classmark *cm);
1442
Neels Hofmeyr91aa68f2018-05-09 17:46:22 +02001443void gsm_ts_check_init(struct gsm_bts_trx_ts *ts);
1444void gsm_trx_mark_all_ts_uninitialized(struct gsm_bts_trx *trx);
1445void gsm_bts_mark_all_ts_uninitialized(struct gsm_bts *bts);
1446
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001447bool trx_is_usable(const struct gsm_bts_trx *trx);
1448
1449bool on_gsm_ts_init(struct gsm_bts_trx_ts *ts);
1450
Harald Welte6be350c2011-05-25 13:10:08 +02001451#endif /* _GSM_DATA_H */