blob: 06fa8dd765da6b0f5180fe9336ed37a72179f7bb [file] [log] [blame]
Harald Welte6be350c2011-05-25 13:10:08 +02001#ifndef _GSM_DATA_SHAREDH
2#define _GSM_DATA_SHAREDH
3
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +02004#include <regex.h>
Harald Welte6be350c2011-05-25 13:10:08 +02005#include <stdbool.h>
6#include <stdint.h>
7
8#include <osmocom/core/timer.h>
9#include <osmocom/core/bitvec.h>
10#include <osmocom/core/statistics.h>
11#include <osmocom/core/utils.h>
12#include <osmocom/gsm/gsm_utils.h>
13#include <osmocom/gsm/tlv.h>
14#include <osmocom/gsm/rxlev_stat.h>
15#include <osmocom/gsm/sysinfo.h>
Harald Welte7ff4f0e2013-03-07 18:38:09 +000016#include <osmocom/gsm/meas_rep.h>
Maxc08ee712016-05-11 12:45:13 +020017#include <osmocom/gsm/protocol/gsm_04_08.h>
Harald Welte6be350c2011-05-25 13:10:08 +020018#include <osmocom/gsm/protocol/gsm_08_58.h>
Harald Welte3300c012011-06-05 13:31:33 +020019#include <osmocom/gsm/protocol/gsm_12_21.h>
Harald Welte6be350c2011-05-25 13:10:08 +020020
Harald Welte0eae6132011-08-24 13:52:07 +020021#include <osmocom/abis/e1_input.h>
22
Holger Hans Peter Freyther0e0a09c2012-12-20 19:03:18 +010023#ifndef ROLE_BSC
24#include <osmocom/gsm/lapdm.h>
25#endif
26
Neels Hofmeyrac1f1432016-05-10 13:30:17 +020027#include <openbsc/common_cs.h>
28
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +020029struct osmo_bsc_data;
30
Harald Welte6be350c2011-05-25 13:10:08 +020031struct osmo_bsc_sccp_con;
32struct gsm_sms_queue;
33
34/* RRLP mode of operation */
35enum rrlp_mode {
36 RRLP_MODE_NONE,
37 RRLP_MODE_MS_BASED,
38 RRLP_MODE_MS_PREF,
39 RRLP_MODE_ASS_PREF,
40};
41
42/* Channel Request reason */
43enum gsm_chreq_reason_t {
44 GSM_CHREQ_REASON_EMERG,
45 GSM_CHREQ_REASON_PAG,
46 GSM_CHREQ_REASON_CALL,
47 GSM_CHREQ_REASON_LOCATION_UPD,
48 GSM_CHREQ_REASON_OTHER,
Alexander Couzens11368112016-11-28 23:26:50 +010049 GSM_CHREQ_REASON_PDCH,
Harald Welte6be350c2011-05-25 13:10:08 +020050};
51
Max582e4f62016-10-18 16:19:33 +020052/* lchans 0..3 are SDCCH in combined channel configuration,
53 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
54#define CCCH_LCHAN 4
55
Harald Welte6be350c2011-05-25 13:10:08 +020056#define TRX_NR_TS 8
57#define TS_MAX_LCHAN 8
58
59#define HARDCODED_ARFCN 123
Harald Welte6be350c2011-05-25 13:10:08 +020060#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
61
62/* for multi-drop config */
63#define HARDCODED_BTS0_TS 1
64#define HARDCODED_BTS1_TS 6
65#define HARDCODED_BTS2_TS 11
66
Harald Welte6be350c2011-05-25 13:10:08 +020067enum gsm_hooks {
68 GSM_HOOK_NM_SWLOAD,
69 GSM_HOOK_RR_PAGING,
70 GSM_HOOK_RR_SECURITY,
71};
72
73enum gsm_paging_event {
74 GSM_PAGING_SUCCEEDED,
75 GSM_PAGING_EXPIRED,
76 GSM_PAGING_OOM,
77 GSM_PAGING_BUSY,
78};
79
80enum bts_gprs_mode {
81 BTS_GPRS_NONE = 0,
82 BTS_GPRS_GPRS = 1,
83 BTS_GPRS_EGPRS = 2,
84};
85
86struct gsm_lchan;
87struct gsm_subscriber;
88struct gsm_mncc;
Harald Welte135a6bd2011-09-04 13:53:26 +020089struct osmo_rtp_socket;
Harald Welte6be350c2011-05-25 13:10:08 +020090struct rtp_socket;
91struct bsc_api;
92
93/* Network Management State */
94struct gsm_nm_state {
95 uint8_t operational;
96 uint8_t administrative;
97 uint8_t availability;
98};
99
Harald Welted64c0bc2011-05-30 12:07:53 +0200100struct gsm_abis_mo {
Harald Welte3300c012011-06-05 13:31:33 +0200101 uint8_t obj_class;
Holger Hans Peter Freyther49976f42013-11-05 16:06:17 +0100102 uint8_t procedure_pending;
Harald Welte3300c012011-06-05 13:31:33 +0200103 struct abis_om_obj_inst obj_inst;
Harald Welted64c0bc2011-05-30 12:07:53 +0200104 const char *name;
105 struct gsm_nm_state nm_state;
106 struct tlv_parsed *nm_attr;
Harald Welte32bc1162011-06-06 18:58:48 +0200107 struct gsm_bts *bts;
Harald Welted64c0bc2011-05-30 12:07:53 +0200108};
109
Harald Welte591e1d72016-07-09 22:20:57 +0200110/* Ericsson OM2000 Managed Object */
111struct abis_om2k_mo {
112 uint8_t class;
113 uint8_t bts;
114 uint8_t assoc_so;
115 uint8_t inst;
116} __attribute__ ((packed));
117
118struct om2k_mo {
119 struct abis_om2k_mo addr;
120 struct osmo_fsm_inst *fsm;
121};
122
Harald Welte6be350c2011-05-25 13:10:08 +0200123#define A38_XOR_MIN_KEY_LEN 12
124#define A38_XOR_MAX_KEY_LEN 16
125#define A38_COMP128_KEY_LEN 16
126#define RSL_ENC_ALG_A5(x) (x+1)
Max27c3e762016-04-20 15:57:12 +0200127#define MAX_EARFCN_LIST 32
Harald Welte6be350c2011-05-25 13:10:08 +0200128
129/* is the data link established? who established it? */
130#define LCHAN_SAPI_UNUSED 0
131#define LCHAN_SAPI_MS 1
132#define LCHAN_SAPI_NET 2
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100133#define LCHAN_SAPI_REL 3
Harald Welte6be350c2011-05-25 13:10:08 +0200134
135/* state of a logical channel */
136enum gsm_lchan_state {
137 LCHAN_S_NONE, /* channel is not active */
Holger Hans Peter Freytherded02682012-01-15 00:02:17 +0100138 LCHAN_S_ACT_REQ, /* channel activation requested */
Harald Welte6be350c2011-05-25 13:10:08 +0200139 LCHAN_S_ACTIVE, /* channel is active and operational */
140 LCHAN_S_REL_REQ, /* channel release has been requested */
141 LCHAN_S_REL_ERR, /* channel is in an error state */
Holger Hans Peter Freyther638da512012-12-06 19:25:06 +0100142 LCHAN_S_BROKEN, /* channel is somehow unusable */
Harald Welte6be350c2011-05-25 13:10:08 +0200143 LCHAN_S_INACTIVE, /* channel is set inactive */
144};
145
Harald Weltec7921c92011-06-29 10:38:34 +0200146/* BTS ONLY */
147#define MAX_NUM_UL_MEAS 104
148#define LC_UL_M_F_L1_VALID (1 << 0)
149#define LC_UL_M_F_RES_VALID (1 << 1)
150
151struct bts_ul_meas {
152 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
153 uint16_t ber10k;
154 /* timing advance offset (in quarter bits) */
155 int16_t ta_offs_qbits;
156 /* C/I ratio in dB */
157 float c_i;
158 /* flags */
159 uint8_t is_sub:1;
160 /* RSSI in dBm * -1 */
161 uint8_t inv_rssi;
162};
Harald Weltef3b59322011-09-06 22:14:43 +0200163
Andreas Eversberga83d5112013-12-07 18:32:28 +0100164struct bts_codec_conf {
165 uint8_t hr;
166 uint8_t efr;
167 uint8_t amr;
168};
169
Harald Weltef3b59322011-09-06 22:14:43 +0200170struct amr_mode {
171 uint8_t mode;
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200172 uint8_t threshold;
173 uint8_t hysteresis;
Harald Weltef3b59322011-09-06 22:14:43 +0200174};
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200175
Harald Weltef3b59322011-09-06 22:14:43 +0200176struct amr_multirate_conf {
177 uint8_t gsm48_ie[2];
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200178 struct amr_mode ms_mode[4];
179 struct amr_mode bts_mode[4];
Harald Weltef3b59322011-09-06 22:14:43 +0200180 uint8_t num_modes;
181};
Harald Weltec7921c92011-06-29 10:38:34 +0200182/* /BTS ONLY */
183
Harald Weltee4227982012-08-24 15:33:56 +0200184enum lchan_csd_mode {
185 LCHAN_CSD_M_NT,
186 LCHAN_CSD_M_T_1200_75,
187 LCHAN_CSD_M_T_600,
188 LCHAN_CSD_M_T_1200,
189 LCHAN_CSD_M_T_2400,
190 LCHAN_CSD_M_T_9600,
191 LCHAN_CSD_M_T_14400,
192 LCHAN_CSD_M_T_29000,
193 LCHAN_CSD_M_T_32000,
194};
195
Daniel Willmann324c8052012-12-29 12:32:30 +0100196/* State of the SAPIs in the lchan */
197enum lchan_sapi_state {
198 LCHAN_SAPI_S_NONE,
199 LCHAN_SAPI_S_REQ,
200 LCHAN_SAPI_S_ASSIGNED,
201 LCHAN_SAPI_S_REL,
202 LCHAN_SAPI_S_ERROR,
203};
204
Harald Welte6be350c2011-05-25 13:10:08 +0200205struct gsm_lchan {
206 /* The TS that we're part of */
207 struct gsm_bts_trx_ts *ts;
208 /* The logical subslot number in the TS */
209 uint8_t nr;
210 /* The logical channel type */
211 enum gsm_chan_t type;
212 /* RSL channel mode */
213 enum rsl_cmod_spd rsl_cmode;
214 /* If TCH, traffic channel mode */
215 enum gsm48_chan_mode tch_mode;
Harald Weltee4227982012-08-24 15:33:56 +0200216 enum lchan_csd_mode csd_mode;
Harald Welte6be350c2011-05-25 13:10:08 +0200217 /* State */
218 enum gsm_lchan_state state;
Holger Hans Peter Freyther454140e2014-12-28 12:08:28 +0100219 const char *broken_reason;
Harald Welte6be350c2011-05-25 13:10:08 +0200220 /* Power levels for MS and BTS */
221 uint8_t bs_power;
222 uint8_t ms_power;
223 /* Encryption information */
Neels Hofmeyrac1f1432016-05-10 13:30:17 +0200224 struct gsm_encr encr;
Harald Welte6be350c2011-05-25 13:10:08 +0200225
226 /* AMR bits */
Andreas Eversberg73266522014-01-19 11:47:44 +0100227 uint8_t mr_ms_lv[7];
228 uint8_t mr_bts_lv[7];
Harald Welte6be350c2011-05-25 13:10:08 +0200229
230 /* Established data link layer services */
231 uint8_t sapis[8];
Holger Hans Peter Freytherb9b828b2013-01-01 19:20:28 +0100232 int sacch_deact;
Holger Hans Peter Freytherdfcfe652011-12-27 20:49:53 +0100233
Harald Welte6be350c2011-05-25 13:10:08 +0200234 struct {
235 uint32_t bound_ip;
236 uint32_t connect_ip;
237 uint16_t bound_port;
238 uint16_t connect_port;
239 uint16_t conn_id;
240 uint8_t rtp_payload;
241 uint8_t rtp_payload2;
242 uint8_t speech_mode;
Harald Welte135a6bd2011-09-04 13:53:26 +0200243#ifdef ROLE_BSC
Harald Welte6be350c2011-05-25 13:10:08 +0200244 struct rtp_socket *rtp_socket;
Harald Welte135a6bd2011-09-04 13:53:26 +0200245#else
246 struct osmo_rtp_socket *rtp_socket;
247#endif
Harald Welte6be350c2011-05-25 13:10:08 +0200248 } abis_ip;
249
Harald Welte2c1ae472011-06-26 14:13:37 +0200250 uint8_t rqd_ta;
251
Harald Weltec696cc22015-12-05 16:19:21 +0100252 char *name;
253
Harald Welte6be350c2011-05-25 13:10:08 +0200254#ifdef ROLE_BSC
255 struct osmo_timer_list T3101;
Holger Hans Peter Freytherb3489392011-12-28 16:21:05 +0100256 struct osmo_timer_list T3109;
Harald Welte6be350c2011-05-25 13:10:08 +0200257 struct osmo_timer_list T3111;
258 struct osmo_timer_list error_timer;
Harald Weltee8bd9e82011-08-10 23:26:33 +0200259 struct osmo_timer_list act_timer;
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100260 struct osmo_timer_list rel_work;
Holger Hans Peter Freyther638da512012-12-06 19:25:06 +0100261 uint8_t error_cause;
Harald Welte6be350c2011-05-25 13:10:08 +0200262
263 /* table of neighbor cell measurements */
264 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
265
266 /* cache of last measurement reports on this lchan */
267 struct gsm_meas_rep meas_rep[6];
268 int meas_rep_idx;
269
270 /* GSM Random Access data */
271 struct gsm48_req_ref *rqd_ref;
Harald Welte6be350c2011-05-25 13:10:08 +0200272
273 struct gsm_subscriber_connection *conn;
Andreas Eversberg9df268e2013-10-11 13:32:30 +0200274
275 struct {
276 /* channel activation type and handover ref */
277 uint8_t act_type;
278 uint8_t ho_ref;
Neels Hofmeyrb91e6002016-07-23 19:45:15 +0200279 struct gsm48_req_ref *rqd_ref;
280 uint8_t rqd_ta;
Neels Hofmeyr6e999b72016-07-23 21:00:51 +0200281 } dyn;
Harald Weltef6093a42011-06-25 10:02:33 +0200282#else
Daniel Willmann324c8052012-12-29 12:32:30 +0100283 /* Number of different GsmL1_Sapi_t used in osmo_bts_sysmo is 23.
284 * Currently we don't share these headers so this is a magic number. */
Holger Hans Peter Freyther30156e12013-04-05 18:41:45 +0200285 struct llist_head sapi_cmds;
Daniel Willmann324c8052012-12-29 12:32:30 +0100286 uint8_t sapis_dl[23];
287 uint8_t sapis_ul[23];
Harald Weltef6093a42011-06-25 10:02:33 +0200288 struct lapdm_channel lapdm_ch;
Harald Welte135a6bd2011-09-04 13:53:26 +0200289 struct llist_head dl_tch_queue;
Harald Welte2c1ae472011-06-26 14:13:37 +0200290 struct {
291 /* bitmask of all SI that are present/valid in si_buf */
292 uint32_t valid;
293 uint32_t last;
294 /* buffers where we put the pre-computed SI */
295 sysinfo_buf_t buf[_MAX_SYSINFO_TYPE];
296 } si;
Harald Weltec7921c92011-06-29 10:38:34 +0200297 struct {
298 uint8_t flags;
299 /* RSL measurment result number, 0 at lchan_act */
300 uint8_t res_nr;
301 /* current Tx power level of the BTS */
302 uint8_t bts_tx_pwr;
303 /* number of measurements stored in array below */
304 uint8_t num_ul_meas;
305 struct bts_ul_meas uplink[MAX_NUM_UL_MEAS];
306 /* last L1 header from the MS */
307 uint8_t l1_info[2];
Harald Welte7ff4f0e2013-03-07 18:38:09 +0000308 struct gsm_meas_rep_unidir ul_res;
Harald Weltec7921c92011-06-29 10:38:34 +0200309 } meas;
Harald Weltef3b59322011-09-06 22:14:43 +0200310 struct {
311 struct amr_multirate_conf amr_mr;
Harald Welte43290992011-09-07 12:41:38 +0200312 struct {
Max1e646f02016-10-05 17:29:02 +0200313 struct osmo_fsm_inst *dl_amr_fsm;
Max1b76a032016-10-25 20:22:16 +0200314 /* TCH cache */
Max1e646f02016-10-05 17:29:02 +0200315 uint8_t cache[20];
Max1b76a032016-10-25 20:22:16 +0200316 /* FACCH cache */
317 uint8_t facch[GSM_MACBLOCK_LEN];
Harald Welte43290992011-09-07 12:41:38 +0200318 uint8_t len;
Maxf5fe31d2016-06-10 14:09:07 +0200319 uint32_t fn;
320 bool is_update;
Max1e646f02016-10-05 17:29:02 +0200321 /* set for each SID frame to detect talkspurt for codecs
322 without explicit ONSET event */
323 bool ul_sid;
324 /* indicates if DTXd was active during DL measurement
325 period */
326 bool dl_active;
327 } dtx;
Holger Hans Peter Freyther922ef5d2014-07-24 21:05:32 +0200328 uint8_t last_cmr;
Maxd7df7ae2016-06-03 12:06:26 +0200329 uint32_t last_fn;
Harald Weltef3b59322011-09-06 22:14:43 +0200330 } tch;
Maxabf53d82017-01-25 16:19:20 +0100331
332 /* 3GPP TS 48.058 § 9.3.37: [0; 255] ok, -1 means invalid*/
333 int16_t ms_t_offs;
334 /* 3GPP TS 45.010 § 1.2 round trip propagation delay (in symbols) or -1 */
335 int16_t p_offs;
336
Harald Welte5d52c972012-04-08 20:23:28 +0200337 /* BTS-side ciphering state (rx only, bi-directional, ...) */
338 uint8_t ciph_state;
Holger Hans Peter Freyther2c6b59c2014-08-09 09:43:53 +0200339 uint8_t ciph_ns;
Harald Welte46cb8512012-04-19 23:13:35 +0200340 uint8_t loopback;
Harald Welte704cb862012-06-16 14:57:08 +0800341 struct {
342 uint8_t active;
343 uint8_t ref;
344 /* T3105: PHYS INF retransmission */
345 struct osmo_timer_list t3105;
346 /* counts up to Ny1 */
347 unsigned int phys_info_count;
348 } ho;
Andreas Eversberg1af682a2013-02-20 16:06:20 +0100349 /* S counter for link loss */
350 int s;
Holger Hans Peter Freytherfc7a75f2013-10-25 18:58:30 +0200351 /* Kind of the release/activation. E.g. RSL or PCU */
352 int rel_act_kind;
Maxec744652016-05-18 16:42:16 +0200353 /* RTP header Marker bit to indicate beginning of speech after pause */
354 bool rtp_tx_marker;
Holger Hans Peter Freytherf6f86b02015-02-05 22:25:03 +0100355 /* power handling */
356 struct {
357 uint8_t current;
358 uint8_t fixed;
359 } ms_power_ctrl;
Minh-Quang Nguyenf1886232017-01-18 16:49:00 +0100360
361 struct msgb *pending_rel_ind_msg;
Harald Welte6be350c2011-05-25 13:10:08 +0200362#endif
363};
364
Neels Hofmeyr2ebacce2016-06-14 14:08:35 +0200365enum {
366 TS_F_PDCH_ACTIVE = 0x1000,
367 TS_F_PDCH_ACT_PENDING = 0x2000,
368 TS_F_PDCH_DEACT_PENDING = 0x4000,
369 TS_F_PDCH_PENDING_MASK = 0x6000 /*<
370 TS_F_PDCH_ACT_PENDING | TS_F_PDCH_DEACT_PENDING */
371} gsm_bts_trx_ts_flags;
372
Harald Welte6be350c2011-05-25 13:10:08 +0200373/* One Timeslot in a TRX */
374struct gsm_bts_trx_ts {
375 struct gsm_bts_trx *trx;
376 /* number of this timeslot at the TRX */
377 uint8_t nr;
378
379 enum gsm_phys_chan_config pchan;
380
Neels Hofmeyrc1658762016-07-23 16:14:06 +0200381 struct {
382 enum gsm_phys_chan_config pchan_is;
383 enum gsm_phys_chan_config pchan_want;
384 struct msgb *pending_chan_activ;
385 } dyn;
386
Harald Welte6be350c2011-05-25 13:10:08 +0200387 unsigned int flags;
Harald Welted64c0bc2011-05-30 12:07:53 +0200388 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200389 struct tlv_parsed nm_attr;
390 uint8_t nm_chan_comb;
Harald Welte135a6482011-05-30 12:09:13 +0200391 int tsc; /* -1 == use BTS TSC */
Harald Welte6be350c2011-05-25 13:10:08 +0200392
393 struct {
394 /* Parameters below are configured by VTY */
395 int enabled;
396 uint8_t maio;
397 uint8_t hsn;
398 struct bitvec arfcns;
399 uint8_t arfcns_data[1024/8];
400 /* This is the pre-computed MA for channel assignments */
401 struct bitvec ma;
402 uint8_t ma_len; /* part of ma_data that is used */
403 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
404 } hopping;
405
406 /* To which E1 subslot are we connected */
407 struct gsm_e1_subslot e1_link;
408
Harald Welte591e1d72016-07-09 22:20:57 +0200409 union {
410 struct {
411 struct om2k_mo om2k_mo;
412 } rbs2000;
413 };
414
Harald Welte6be350c2011-05-25 13:10:08 +0200415 struct gsm_lchan lchan[TS_MAX_LCHAN];
416};
417
418/* One TRX in a BTS */
419struct gsm_bts_trx {
420 /* list header in bts->trx_list */
421 struct llist_head list;
422
423 struct gsm_bts *bts;
424 /* number of this TRX in the BTS */
425 uint8_t nr;
426 /* human readable name / description */
427 char *description;
428 /* how do we talk RSL with this TRX? */
429 struct gsm_e1_subslot rsl_e1_link;
430 uint8_t rsl_tei;
431 struct e1inp_sign_link *rsl_link;
Holger Hans Peter Freythercaa98d52013-10-06 15:52:14 +0200432
Harald Welte6be350c2011-05-25 13:10:08 +0200433 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
434 struct e1inp_sign_link *oml_link;
435
Harald Welted64c0bc2011-05-30 12:07:53 +0200436 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200437 struct tlv_parsed nm_attr;
438 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200439 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200440 } bb_transc;
441
442 uint16_t arfcn;
443 int nominal_power; /* in dBm */
444 unsigned int max_power_red; /* in actual dB */
Holger Hans Peter Freyther9b625802014-07-30 18:20:51 +0200445
446#ifndef ROLE_BSC
Harald Welte101c5c22014-08-22 16:12:03 +0200447 struct trx_power_params power_params;
Holger Hans Peter Freytherf6f86b02015-02-05 22:25:03 +0100448 int ms_power_control;
Harald Welte6be350c2011-05-25 13:10:08 +0200449
Harald Welted134cc72011-06-07 00:12:53 +0200450 struct {
451 void *l1h;
452 } role_bts;
Holger Hans Peter Freyther9b625802014-07-30 18:20:51 +0200453#endif
Harald Welted134cc72011-06-07 00:12:53 +0200454
Harald Welte6be350c2011-05-25 13:10:08 +0200455 union {
456 struct {
457 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200458 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200459 } bbsig;
460 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200461 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200462 } pa;
463 } bs11;
464 struct {
465 unsigned int test_state;
466 uint8_t test_nr;
467 struct rxlev_stats rxlev_stat;
468 } ipaccess;
Harald Welte591e1d72016-07-09 22:20:57 +0200469 struct {
470 struct {
471 struct om2k_mo om2k_mo;
472 } trxc;
473 struct {
474 struct om2k_mo om2k_mo;
475 } rx;
476 struct {
477 struct om2k_mo om2k_mo;
478 } tx;
479 } rbs2000;
Harald Welte6be350c2011-05-25 13:10:08 +0200480 };
481 struct gsm_bts_trx_ts ts[TRX_NR_TS];
482};
483
484#define GSM_BTS_SI(bts, i) (void *)(bts->si_buf[i])
485
486enum gsm_bts_type {
487 GSM_BTS_TYPE_UNKNOWN,
488 GSM_BTS_TYPE_BS11,
489 GSM_BTS_TYPE_NANOBTS,
490 GSM_BTS_TYPE_RBS2000,
Dieter Spaar16646022011-07-28 00:01:50 +0200491 GSM_BTS_TYPE_NOKIA_SITE,
Harald Weltef383aa12012-07-02 19:51:55 +0200492 GSM_BTS_TYPE_OSMO_SYSMO,
Harald Weltee555c2b2012-08-17 13:02:12 +0200493 _NUM_GSM_BTS_TYPE
Harald Welte6be350c2011-05-25 13:10:08 +0200494};
495
496struct vty;
497
498struct gsm_bts_model {
499 struct llist_head list;
500
501 enum gsm_bts_type type;
502 const char *name;
503
504 bool started;
505 int (*start)(struct gsm_network *net);
506 int (*oml_rcvmsg)(struct msgb *msg);
507
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200508 void (*e1line_bind_ops)(struct e1inp_line *line);
509
Harald Welte6be350c2011-05-25 13:10:08 +0200510 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
511 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
512 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
513
514 struct tlv_definition nm_att_tlvdef;
515
516 struct bitvec features;
517 uint8_t _features_data[128/8];
518};
519
520enum gsm_bts_features {
521 BTS_FEAT_HSCSD,
522 BTS_FEAT_GPRS,
523 BTS_FEAT_EGPRS,
524 BTS_FEAT_ECSD,
525 BTS_FEAT_HOPPING,
Harald Welte903aaea2014-01-19 17:10:50 +0100526 BTS_FEAT_MULTI_TSC,
Harald Welte6be350c2011-05-25 13:10:08 +0200527};
528
529/*
530 * This keeps track of the paging status of one BTS. It
531 * includes a number of pending requests, a back pointer
532 * to the gsm_bts, a timer and some more state.
533 */
534struct gsm_bts_paging_state {
535 /* pending requests */
536 struct llist_head pending_requests;
537 struct gsm_bts *bts;
538
539 struct osmo_timer_list work_timer;
540 struct osmo_timer_list credit_timer;
541
542 /* free chans needed */
543 int free_chans_need;
544
545 /* load */
546 uint16_t available_slots;
547};
548
549struct gsm_envabtse {
Harald Welted64c0bc2011-05-30 12:07:53 +0200550 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200551};
552
553struct gsm_bts_gprs_nsvc {
554 struct gsm_bts *bts;
555 /* data read via VTY config file, to configure the BTS
556 * via OML from BSC */
557 int id;
558 uint16_t nsvci;
559 uint16_t local_port; /* on the BTS */
560 uint16_t remote_port; /* on the SGSN */
561 uint32_t remote_ip; /* on the SGSN */
562
Harald Welted64c0bc2011-05-30 12:07:53 +0200563 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200564};
565
Harald Welte019f9132012-06-28 08:43:14 +0200566enum gprs_rlc_par {
567 RLC_T3142,
568 RLC_T3169,
569 RLC_T3191,
570 RLC_T3193,
571 RLC_T3195,
572 RLC_N3101,
573 RLC_N3103,
574 RLC_N3105,
575 CV_COUNTDOWN,
576 T_DL_TBF_EXT, /* ms */
577 T_UL_TBF_EXT, /* ms */
578 _NUM_RLC_PAR
579};
580
581enum gprs_cs {
582 GPRS_CS1,
583 GPRS_CS2,
584 GPRS_CS3,
585 GPRS_CS4,
586 GPRS_MCS1,
587 GPRS_MCS2,
588 GPRS_MCS3,
589 GPRS_MCS4,
590 GPRS_MCS5,
591 GPRS_MCS6,
592 GPRS_MCS7,
593 GPRS_MCS8,
594 GPRS_MCS9,
595 _NUM_GRPS_CS
596};
597
598struct gprs_rlc_cfg {
599 uint16_t parameter[_NUM_RLC_PAR];
600 struct {
601 uint16_t repeat_time; /* ms */
602 uint8_t repeat_count;
603 } paging;
604 uint32_t cs_mask; /* bitmask of gprs_cs */
605 uint8_t initial_cs;
606 uint8_t initial_mcs;
607};
608
609
Harald Welte6be350c2011-05-25 13:10:08 +0200610enum neigh_list_manual_mode {
611 NL_MODE_AUTOMATIC = 0,
612 NL_MODE_MANUAL = 1,
613 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
614};
615
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200616enum bts_loc_fix {
617 BTS_LOC_FIX_INVALID = 0,
618 BTS_LOC_FIX_2D = 1,
619 BTS_LOC_FIX_3D = 2,
620};
621
Daniel Willmann7d109832012-05-14 18:43:23 +0200622extern const struct value_string bts_loc_fix_names[];
623
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200624struct bts_location {
625 struct llist_head list;
626 time_t tstamp;
627 enum bts_loc_fix valid;
628 double lat;
629 double lon;
630 double height;
631};
632
Harald Welte6be350c2011-05-25 13:10:08 +0200633/* One BTS */
634struct gsm_bts {
635 /* list header in net->bts_list */
636 struct llist_head list;
637
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200638 /* Geographical location of the BTS */
639 struct llist_head loc_list;
640
Harald Welte6be350c2011-05-25 13:10:08 +0200641 /* number of ths BTS in network */
642 uint8_t nr;
643 /* human readable name / description */
644 char *description;
645 /* Cell Identity */
646 uint16_t cell_identity;
647 /* location area code of this BTS */
648 uint16_t location_area_code;
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100649 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
650 * which is used as TSC for the CCCH */
Harald Welte6be350c2011-05-25 13:10:08 +0200651 uint8_t bsic;
652 /* type of BTS */
653 enum gsm_bts_type type;
654 struct gsm_bts_model *model;
655 enum gsm_band band;
656 /* maximum Tx power that the MS is permitted to use in this cell */
657 int ms_max_power;
658
659 /* how do we talk OML with this TRX? */
660 struct gsm_e1_subslot oml_e1_link;
661 uint8_t oml_tei;
662 struct e1inp_sign_link *oml_link;
663
664 /* Abis network management O&M handle */
665 struct abis_nm_h *nmh;
Harald Welted64c0bc2011-05-30 12:07:53 +0200666
667 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200668
669 /* number of this BTS on given E1 link */
670 uint8_t bts_nr;
671
Maxc08ee712016-05-11 12:45:13 +0200672 /* DTX features of this BTS */
673 enum gsm48_dtx_mode dtxu;
674 bool dtxd;
675
Harald Welte6be350c2011-05-25 13:10:08 +0200676 /* paging state and control */
677 struct gsm_bts_paging_state paging;
678
679 /* CCCH is on C0 */
680 struct gsm_bts_trx *c0;
681
682 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200683 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200684 } site_mgr;
685
686 /* bitmask of all SI that are present/valid in si_buf */
687 uint32_t si_valid;
688 /* buffers where we put the pre-computed SI */
689 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE];
690
691 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
692 union {
693 struct {
694 uint16_t site_id;
695 uint16_t bts_id;
696 uint32_t flags;
Harald Welte8b291802013-03-12 13:57:05 +0100697 uint32_t rsl_ip;
Harald Welte6be350c2011-05-25 13:10:08 +0200698 } ip_access;
699 struct {
700 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200701 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200702 } cclk;
703 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200704 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200705 } rack;
706 struct gsm_envabtse envabtse[4];
707 } bs11;
708 struct {
709 struct {
Harald Welte591e1d72016-07-09 22:20:57 +0200710 struct om2k_mo om2k_mo;
711 struct gsm_abis_mo mo;
712 struct llist_head conn_groups;
713 } cf;
714 struct {
715 struct om2k_mo om2k_mo;
Harald Welted64c0bc2011-05-30 12:07:53 +0200716 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200717 struct llist_head conn_groups;
718 } is;
719 struct {
Harald Welte591e1d72016-07-09 22:20:57 +0200720 struct om2k_mo om2k_mo;
Harald Welted64c0bc2011-05-30 12:07:53 +0200721 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200722 struct llist_head conn_groups;
723 } con;
724 struct {
Harald Welte591e1d72016-07-09 22:20:57 +0200725 struct om2k_mo om2k_mo;
Harald Welted64c0bc2011-05-30 12:07:53 +0200726 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200727 } dp;
728 struct {
Harald Welte591e1d72016-07-09 22:20:57 +0200729 struct om2k_mo om2k_mo;
Harald Welted64c0bc2011-05-30 12:07:53 +0200730 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200731 } tf;
Harald Weltece492582016-11-15 22:59:24 +0100732 uint32_t use_superchannel:1;
Harald Welte6be350c2011-05-25 13:10:08 +0200733 } rbs2000;
734 struct {
Harald Weltec8755af2011-07-28 00:22:17 +0200735 uint8_t bts_type;
Holger Hans Peter Freyther3e603482012-03-02 14:14:33 +0100736 unsigned int configured:1,
737 skip_reset:1,
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100738 no_loc_rel_cnf:1,
Sipos Csaba56e17662015-02-07 13:27:36 +0100739 bts_reset_timer_cnf,
Holger Hans Peter Freyther3e603482012-03-02 14:14:33 +0100740 did_reset:1,
741 wait_reset:1;
Harald Weltec8755af2011-07-28 00:22:17 +0200742 struct osmo_timer_list reset_timer;
743 } nokia;
Harald Welte6be350c2011-05-25 13:10:08 +0200744 };
745
746 /* Not entirely sure how ip.access specific this is */
747 struct {
bhargava350533c2016-07-21 11:14:34 +0530748 uint8_t supports_egprs_11bit_rach;
Harald Welte6be350c2011-05-25 13:10:08 +0200749 enum bts_gprs_mode mode;
750 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200751 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200752 uint16_t nsei;
753 uint8_t timer[7];
754 } nse;
755 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200756 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200757 uint16_t bvci;
758 uint8_t timer[11];
Harald Welte019f9132012-06-28 08:43:14 +0200759 struct gprs_rlc_cfg rlc_cfg;
Harald Welte6be350c2011-05-25 13:10:08 +0200760 } cell;
761 struct gsm_bts_gprs_nsvc nsvc[2];
762 uint8_t rac;
Andreas Eversberg0c8f9ca2013-03-16 16:31:26 +0100763 uint8_t net_ctrl_ord;
Max292ec582016-07-28 11:55:37 +0200764 bool ctrl_ack_type_use_block;
Harald Welte6be350c2011-05-25 13:10:08 +0200765 } gprs;
766
767 /* RACH NM values */
768 int rach_b_thresh;
769 int rach_ldavg_slots;
770
771 /* transceivers */
772 int num_trx;
773 struct llist_head trx_list;
774
Holger Hans Peter Freytherb92a5382014-11-21 10:00:39 +0100775 /* SI related items */
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100776 int force_combined_si;
Holger Hans Peter Freytherb92a5382014-11-21 10:00:39 +0100777 int bcch_change_mark;
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100778
Harald Welte6be350c2011-05-25 13:10:08 +0200779#ifdef ROLE_BSC
780 /* Abis NM queue */
781 struct llist_head abis_queue;
782 int abis_nm_pend;
783
784 struct gsm_network *network;
785
786 /* should the channel allocator allocate channels from high TRX to TRX0,
787 * rather than starting from TRX0 and go upwards? */
788 int chan_alloc_reverse;
789
790 enum neigh_list_manual_mode neigh_list_manual_mode;
791 /* parameters from which we build SYSTEM INFORMATION */
792 struct {
793 struct gsm48_rach_control rach_control;
794 uint8_t ncc_permitted;
795 struct gsm48_cell_sel_par cell_sel_par;
796 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
797 struct gsm48_cell_options cell_options;
798 struct gsm48_control_channel_descr chan_desc;
799 struct bitvec neigh_list;
800 struct bitvec cell_alloc;
801 struct bitvec si5_neigh_list;
Max59a1bf32016-04-15 16:04:46 +0200802 struct osmo_earfcn_si2q si2quater_neigh_list;
Max26679e02016-04-20 15:57:13 +0200803 size_t uarfcn_length; /* index for uarfcn and scramble lists */
Harald Welte6be350c2011-05-25 13:10:08 +0200804 struct {
805 /* bitmask large enough for all possible ARFCN's */
806 uint8_t neigh_list[1024/8];
807 uint8_t cell_alloc[1024/8];
808 /* If the user wants a different neighbor list in SI5 than in SI2 */
809 uint8_t si5_neigh_list[1024/8];
Max59a1bf32016-04-15 16:04:46 +0200810 uint8_t meas_bw_list[MAX_EARFCN_LIST];
811 uint16_t earfcn_list[MAX_EARFCN_LIST];
Max26679e02016-04-20 15:57:13 +0200812 uint16_t uarfcn_list[MAX_EARFCN_LIST];
813 uint16_t scramble_list[MAX_EARFCN_LIST];
Harald Welte6be350c2011-05-25 13:10:08 +0200814 } data;
815 } si_common;
Harald Welte42def722017-01-13 00:10:32 +0100816 bool early_classmark_allowed;
Harald Welte6be350c2011-05-25 13:10:08 +0200817
818 /* do we use static (user-defined) system information messages? (bitmask) */
819 uint32_t si_mode_static;
Holger Hans Peter Freythere30d40d2012-07-20 10:27:31 +0200820
821 /* exclude the BTS from the global RF Lock handling */
822 int excl_from_rf_lock;
Andreas Eversberga83d5112013-12-07 18:32:28 +0100823
824 /* supported codecs beside FR */
825 struct bts_codec_conf codec;
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100826
827 /* BTS dependencies bit field */
828 uint32_t depends_on[256/(8*4)];
Andreas Eversberg73266522014-01-19 11:47:44 +0100829
830 /* full and half rate multirate config */
831 struct amr_multirate_conf mr_full;
832 struct amr_multirate_conf mr_half;
833
Harald Welte6be350c2011-05-25 13:10:08 +0200834#endif /* ROLE_BSC */
Harald Welte978714d2011-06-06 18:31:20 +0200835 void *role;
Harald Welte6be350c2011-05-25 13:10:08 +0200836};
837
838
Harald Welte3300c012011-06-05 13:31:33 +0200839struct gsm_bts *gsm_bts_alloc(void *talloc_ctx);
Harald Welte1449c9f2014-08-24 09:50:10 +0200840struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Harald Welte6be350c2011-05-25 13:10:08 +0200841
Harald Welte1449c9f2014-08-24 09:50:10 +0200842struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
Harald Welte4f8ad532011-09-19 14:21:51 +0200843struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
Harald Welte6be350c2011-05-25 13:10:08 +0200844
Harald Welte4ab9d7c2012-08-17 12:42:06 +0200845
Neels Hofmeyr17a6bab2016-07-23 16:14:06 +0200846const struct value_string gsm_pchant_names[13];
847const struct value_string gsm_pchant_descs[13];
Harald Welte6be350c2011-05-25 13:10:08 +0200848const char *gsm_pchan_name(enum gsm_phys_chan_config c);
849enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
850const char *gsm_lchant_name(enum gsm_chan_t c);
851const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte4f8ad532011-09-19 14:21:51 +0200852char *gsm_trx_name(const struct gsm_bts_trx *trx);
853char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr34b8b5b2016-07-16 23:59:32 +0200854char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
Harald Weltec696cc22015-12-05 16:19:21 +0100855char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
Harald Welte6be350c2011-05-25 13:10:08 +0200856const char *gsm_lchans_name(enum gsm_lchan_state s);
857
Harald Weltec696cc22015-12-05 16:19:21 +0100858static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
859{
860 return lchan->name;
861}
Harald Welte6be350c2011-05-25 13:10:08 +0200862
Harald Welteb7849982011-06-29 16:49:03 +0200863void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
864
Harald Welte978714d2011-06-06 18:31:20 +0200865struct gsm_abis_mo *
866gsm_objclass2mo(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200867 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200868
869struct gsm_nm_state *
870gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200871 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200872void *
873gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200874 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200875
Harald Welteb7849982011-06-29 16:49:03 +0200876/* reset the state of all MO in the BTS */
877void gsm_bts_mo_reset(struct gsm_bts *bts);
878
Neels Hofmeyrd3841102016-07-18 23:43:44 +0200879uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
880 uint8_t ts_nr, uint8_t lchan_nr);
Harald Weltef6093a42011-06-25 10:02:33 +0200881uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
Neels Hofmeyrd3841102016-07-18 23:43:44 +0200882uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
883 enum gsm_phys_chan_config as_pchan);
Harald Weltef6093a42011-06-25 10:02:33 +0200884
Harald Welte142d12d2014-12-29 17:47:08 +0100885/* return the gsm_lchan for the CBCH (if it exists at all) */
886struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
887
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200888/*
889 * help with parsing regexps
890 */
891int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
892 int argc, const char **argv) __attribute__ ((warn_unused_result));
893
Harald Welte1fe24122014-01-19 17:18:21 +0100894static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
895{
896 if (ts->tsc != -1)
897 return ts->tsc;
898 else
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100899 return ts->trx->bts->bsic & 7;
Harald Welte1fe24122014-01-19 17:18:21 +0100900}
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200901
Neels Hofmeyr74585722016-07-23 17:38:22 +0200902struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
903 int *rc);
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200904
Neels Hofmeyrec16c162016-10-17 01:03:53 +0200905enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr76a0ad72016-07-29 18:12:06 +0200906uint8_t ts_subslots(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr255dbfe2016-09-25 15:07:01 +0200907bool ts_is_tch(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr76a0ad72016-07-29 18:12:06 +0200908
Harald Welte6be350c2011-05-25 13:10:08 +0200909#endif