blob: 9407b82627598c23db9ea6056c4196ce359924fa [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,
49};
50
Max582e4f62016-10-18 16:19:33 +020051/* lchans 0..3 are SDCCH in combined channel configuration,
52 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
53#define CCCH_LCHAN 4
54
Harald Welte6be350c2011-05-25 13:10:08 +020055#define TRX_NR_TS 8
56#define TS_MAX_LCHAN 8
57
58#define HARDCODED_ARFCN 123
Harald Welte6be350c2011-05-25 13:10:08 +020059#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
60
61/* for multi-drop config */
62#define HARDCODED_BTS0_TS 1
63#define HARDCODED_BTS1_TS 6
64#define HARDCODED_BTS2_TS 11
65
Harald Welte6be350c2011-05-25 13:10:08 +020066enum gsm_hooks {
67 GSM_HOOK_NM_SWLOAD,
68 GSM_HOOK_RR_PAGING,
69 GSM_HOOK_RR_SECURITY,
70};
71
72enum gsm_paging_event {
73 GSM_PAGING_SUCCEEDED,
74 GSM_PAGING_EXPIRED,
75 GSM_PAGING_OOM,
76 GSM_PAGING_BUSY,
77};
78
79enum bts_gprs_mode {
80 BTS_GPRS_NONE = 0,
81 BTS_GPRS_GPRS = 1,
82 BTS_GPRS_EGPRS = 2,
83};
84
85struct gsm_lchan;
86struct gsm_subscriber;
87struct gsm_mncc;
Harald Welte135a6bd2011-09-04 13:53:26 +020088struct osmo_rtp_socket;
Harald Welte6be350c2011-05-25 13:10:08 +020089struct rtp_socket;
90struct bsc_api;
91
92/* Network Management State */
93struct gsm_nm_state {
94 uint8_t operational;
95 uint8_t administrative;
96 uint8_t availability;
97};
98
Harald Welted64c0bc2011-05-30 12:07:53 +020099struct gsm_abis_mo {
Harald Welte3300c012011-06-05 13:31:33 +0200100 uint8_t obj_class;
Holger Hans Peter Freyther49976f42013-11-05 16:06:17 +0100101 uint8_t procedure_pending;
Harald Welte3300c012011-06-05 13:31:33 +0200102 struct abis_om_obj_inst obj_inst;
Harald Welted64c0bc2011-05-30 12:07:53 +0200103 const char *name;
104 struct gsm_nm_state nm_state;
105 struct tlv_parsed *nm_attr;
Harald Welte32bc1162011-06-06 18:58:48 +0200106 struct gsm_bts *bts;
Harald Welted64c0bc2011-05-30 12:07:53 +0200107};
108
Harald Welte591e1d72016-07-09 22:20:57 +0200109/* Ericsson OM2000 Managed Object */
110struct abis_om2k_mo {
111 uint8_t class;
112 uint8_t bts;
113 uint8_t assoc_so;
114 uint8_t inst;
115} __attribute__ ((packed));
116
117struct om2k_mo {
118 struct abis_om2k_mo addr;
119 struct osmo_fsm_inst *fsm;
120};
121
Harald Welte6be350c2011-05-25 13:10:08 +0200122#define A38_XOR_MIN_KEY_LEN 12
123#define A38_XOR_MAX_KEY_LEN 16
124#define A38_COMP128_KEY_LEN 16
125#define RSL_ENC_ALG_A5(x) (x+1)
Max27c3e762016-04-20 15:57:12 +0200126#define MAX_EARFCN_LIST 32
Harald Welte6be350c2011-05-25 13:10:08 +0200127
128/* is the data link established? who established it? */
129#define LCHAN_SAPI_UNUSED 0
130#define LCHAN_SAPI_MS 1
131#define LCHAN_SAPI_NET 2
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100132#define LCHAN_SAPI_REL 3
Harald Welte6be350c2011-05-25 13:10:08 +0200133
134/* state of a logical channel */
135enum gsm_lchan_state {
136 LCHAN_S_NONE, /* channel is not active */
Holger Hans Peter Freytherded02682012-01-15 00:02:17 +0100137 LCHAN_S_ACT_REQ, /* channel activation requested */
Harald Welte6be350c2011-05-25 13:10:08 +0200138 LCHAN_S_ACTIVE, /* channel is active and operational */
139 LCHAN_S_REL_REQ, /* channel release has been requested */
140 LCHAN_S_REL_ERR, /* channel is in an error state */
Holger Hans Peter Freyther638da512012-12-06 19:25:06 +0100141 LCHAN_S_BROKEN, /* channel is somehow unusable */
Harald Welte6be350c2011-05-25 13:10:08 +0200142 LCHAN_S_INACTIVE, /* channel is set inactive */
143};
144
Harald Weltec7921c92011-06-29 10:38:34 +0200145/* BTS ONLY */
146#define MAX_NUM_UL_MEAS 104
147#define LC_UL_M_F_L1_VALID (1 << 0)
148#define LC_UL_M_F_RES_VALID (1 << 1)
149
150struct bts_ul_meas {
151 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
152 uint16_t ber10k;
153 /* timing advance offset (in quarter bits) */
154 int16_t ta_offs_qbits;
155 /* C/I ratio in dB */
156 float c_i;
157 /* flags */
158 uint8_t is_sub:1;
159 /* RSSI in dBm * -1 */
160 uint8_t inv_rssi;
161};
Harald Weltef3b59322011-09-06 22:14:43 +0200162
Andreas Eversberga83d5112013-12-07 18:32:28 +0100163struct bts_codec_conf {
164 uint8_t hr;
165 uint8_t efr;
166 uint8_t amr;
167};
168
Harald Weltef3b59322011-09-06 22:14:43 +0200169struct amr_mode {
170 uint8_t mode;
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200171 uint8_t threshold;
172 uint8_t hysteresis;
Harald Weltef3b59322011-09-06 22:14:43 +0200173};
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200174
Harald Weltef3b59322011-09-06 22:14:43 +0200175struct amr_multirate_conf {
176 uint8_t gsm48_ie[2];
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200177 struct amr_mode ms_mode[4];
178 struct amr_mode bts_mode[4];
Harald Weltef3b59322011-09-06 22:14:43 +0200179 uint8_t num_modes;
180};
Harald Weltec7921c92011-06-29 10:38:34 +0200181/* /BTS ONLY */
182
Harald Weltee4227982012-08-24 15:33:56 +0200183enum lchan_csd_mode {
184 LCHAN_CSD_M_NT,
185 LCHAN_CSD_M_T_1200_75,
186 LCHAN_CSD_M_T_600,
187 LCHAN_CSD_M_T_1200,
188 LCHAN_CSD_M_T_2400,
189 LCHAN_CSD_M_T_9600,
190 LCHAN_CSD_M_T_14400,
191 LCHAN_CSD_M_T_29000,
192 LCHAN_CSD_M_T_32000,
193};
194
Daniel Willmann324c8052012-12-29 12:32:30 +0100195/* State of the SAPIs in the lchan */
196enum lchan_sapi_state {
197 LCHAN_SAPI_S_NONE,
198 LCHAN_SAPI_S_REQ,
199 LCHAN_SAPI_S_ASSIGNED,
200 LCHAN_SAPI_S_REL,
201 LCHAN_SAPI_S_ERROR,
202};
203
Harald Welte6be350c2011-05-25 13:10:08 +0200204struct gsm_lchan {
205 /* The TS that we're part of */
206 struct gsm_bts_trx_ts *ts;
207 /* The logical subslot number in the TS */
208 uint8_t nr;
209 /* The logical channel type */
210 enum gsm_chan_t type;
211 /* RSL channel mode */
212 enum rsl_cmod_spd rsl_cmode;
213 /* If TCH, traffic channel mode */
214 enum gsm48_chan_mode tch_mode;
Harald Weltee4227982012-08-24 15:33:56 +0200215 enum lchan_csd_mode csd_mode;
Harald Welte6be350c2011-05-25 13:10:08 +0200216 /* State */
217 enum gsm_lchan_state state;
Holger Hans Peter Freyther454140e2014-12-28 12:08:28 +0100218 const char *broken_reason;
Harald Welte6be350c2011-05-25 13:10:08 +0200219 /* Power levels for MS and BTS */
220 uint8_t bs_power;
221 uint8_t ms_power;
222 /* Encryption information */
Neels Hofmeyrac1f1432016-05-10 13:30:17 +0200223 struct gsm_encr encr;
Harald Welte6be350c2011-05-25 13:10:08 +0200224
225 /* AMR bits */
Andreas Eversberg73266522014-01-19 11:47:44 +0100226 uint8_t mr_ms_lv[7];
227 uint8_t mr_bts_lv[7];
Harald Welte6be350c2011-05-25 13:10:08 +0200228
229 /* Established data link layer services */
230 uint8_t sapis[8];
Holger Hans Peter Freytherb9b828b2013-01-01 19:20:28 +0100231 int sacch_deact;
Holger Hans Peter Freytherdfcfe652011-12-27 20:49:53 +0100232
Harald Welte6be350c2011-05-25 13:10:08 +0200233 struct {
234 uint32_t bound_ip;
235 uint32_t connect_ip;
236 uint16_t bound_port;
237 uint16_t connect_port;
238 uint16_t conn_id;
239 uint8_t rtp_payload;
240 uint8_t rtp_payload2;
241 uint8_t speech_mode;
Harald Welte135a6bd2011-09-04 13:53:26 +0200242#ifdef ROLE_BSC
Harald Welte6be350c2011-05-25 13:10:08 +0200243 struct rtp_socket *rtp_socket;
Harald Welte135a6bd2011-09-04 13:53:26 +0200244#else
245 struct osmo_rtp_socket *rtp_socket;
246#endif
Harald Welte6be350c2011-05-25 13:10:08 +0200247 } abis_ip;
248
Harald Welte2c1ae472011-06-26 14:13:37 +0200249 uint8_t rqd_ta;
250
Harald Weltec696cc22015-12-05 16:19:21 +0100251 char *name;
252
Harald Welte6be350c2011-05-25 13:10:08 +0200253#ifdef ROLE_BSC
254 struct osmo_timer_list T3101;
Holger Hans Peter Freytherb3489392011-12-28 16:21:05 +0100255 struct osmo_timer_list T3109;
Harald Welte6be350c2011-05-25 13:10:08 +0200256 struct osmo_timer_list T3111;
257 struct osmo_timer_list error_timer;
Harald Weltee8bd9e82011-08-10 23:26:33 +0200258 struct osmo_timer_list act_timer;
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100259 struct osmo_timer_list rel_work;
Holger Hans Peter Freyther638da512012-12-06 19:25:06 +0100260 uint8_t error_cause;
Harald Welte6be350c2011-05-25 13:10:08 +0200261
262 /* table of neighbor cell measurements */
263 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
264
265 /* cache of last measurement reports on this lchan */
266 struct gsm_meas_rep meas_rep[6];
267 int meas_rep_idx;
268
269 /* GSM Random Access data */
270 struct gsm48_req_ref *rqd_ref;
Harald Welte6be350c2011-05-25 13:10:08 +0200271
272 struct gsm_subscriber_connection *conn;
Andreas Eversberg9df268e2013-10-11 13:32:30 +0200273
274 struct {
275 /* channel activation type and handover ref */
276 uint8_t act_type;
277 uint8_t ho_ref;
Neels Hofmeyrb91e6002016-07-23 19:45:15 +0200278 struct gsm48_req_ref *rqd_ref;
279 uint8_t rqd_ta;
Neels Hofmeyr6e999b72016-07-23 21:00:51 +0200280 } dyn;
Harald Weltef6093a42011-06-25 10:02:33 +0200281#else
Daniel Willmann324c8052012-12-29 12:32:30 +0100282 /* Number of different GsmL1_Sapi_t used in osmo_bts_sysmo is 23.
283 * Currently we don't share these headers so this is a magic number. */
Holger Hans Peter Freyther30156e12013-04-05 18:41:45 +0200284 struct llist_head sapi_cmds;
Daniel Willmann324c8052012-12-29 12:32:30 +0100285 uint8_t sapis_dl[23];
286 uint8_t sapis_ul[23];
Harald Weltef6093a42011-06-25 10:02:33 +0200287 struct lapdm_channel lapdm_ch;
Harald Welte135a6bd2011-09-04 13:53:26 +0200288 struct llist_head dl_tch_queue;
Harald Welte2c1ae472011-06-26 14:13:37 +0200289 struct {
290 /* bitmask of all SI that are present/valid in si_buf */
291 uint32_t valid;
292 uint32_t last;
293 /* buffers where we put the pre-computed SI */
294 sysinfo_buf_t buf[_MAX_SYSINFO_TYPE];
295 } si;
Harald Weltec7921c92011-06-29 10:38:34 +0200296 struct {
297 uint8_t flags;
298 /* RSL measurment result number, 0 at lchan_act */
299 uint8_t res_nr;
300 /* current Tx power level of the BTS */
301 uint8_t bts_tx_pwr;
302 /* number of measurements stored in array below */
303 uint8_t num_ul_meas;
304 struct bts_ul_meas uplink[MAX_NUM_UL_MEAS];
305 /* last L1 header from the MS */
306 uint8_t l1_info[2];
Harald Welte7ff4f0e2013-03-07 18:38:09 +0000307 struct gsm_meas_rep_unidir ul_res;
Harald Weltec7921c92011-06-29 10:38:34 +0200308 } meas;
Harald Weltef3b59322011-09-06 22:14:43 +0200309 struct {
310 struct amr_multirate_conf amr_mr;
Harald Welte43290992011-09-07 12:41:38 +0200311 struct {
Max1e646f02016-10-05 17:29:02 +0200312 struct osmo_fsm_inst *dl_amr_fsm;
Max1b76a032016-10-25 20:22:16 +0200313 /* TCH cache */
Max1e646f02016-10-05 17:29:02 +0200314 uint8_t cache[20];
Max1b76a032016-10-25 20:22:16 +0200315 /* FACCH cache */
316 uint8_t facch[GSM_MACBLOCK_LEN];
Harald Welte43290992011-09-07 12:41:38 +0200317 uint8_t len;
Maxf5fe31d2016-06-10 14:09:07 +0200318 uint32_t fn;
319 bool is_update;
Max1e646f02016-10-05 17:29:02 +0200320 /* set for each SID frame to detect talkspurt for codecs
321 without explicit ONSET event */
322 bool ul_sid;
323 /* indicates if DTXd was active during DL measurement
324 period */
325 bool dl_active;
326 } dtx;
Holger Hans Peter Freyther922ef5d2014-07-24 21:05:32 +0200327 uint8_t last_cmr;
Maxd7df7ae2016-06-03 12:06:26 +0200328 uint32_t last_fn;
Harald Weltef3b59322011-09-06 22:14:43 +0200329 } tch;
Harald Welte5d52c972012-04-08 20:23:28 +0200330 /* BTS-side ciphering state (rx only, bi-directional, ...) */
331 uint8_t ciph_state;
Holger Hans Peter Freyther2c6b59c2014-08-09 09:43:53 +0200332 uint8_t ciph_ns;
Harald Welte46cb8512012-04-19 23:13:35 +0200333 uint8_t loopback;
Harald Welte704cb862012-06-16 14:57:08 +0800334 struct {
335 uint8_t active;
336 uint8_t ref;
337 /* T3105: PHYS INF retransmission */
338 struct osmo_timer_list t3105;
339 /* counts up to Ny1 */
340 unsigned int phys_info_count;
341 } ho;
Andreas Eversberg1af682a2013-02-20 16:06:20 +0100342 /* S counter for link loss */
343 int s;
Holger Hans Peter Freytherfc7a75f2013-10-25 18:58:30 +0200344 /* Kind of the release/activation. E.g. RSL or PCU */
345 int rel_act_kind;
Maxec744652016-05-18 16:42:16 +0200346 /* RTP header Marker bit to indicate beginning of speech after pause */
347 bool rtp_tx_marker;
Holger Hans Peter Freytherf6f86b02015-02-05 22:25:03 +0100348 /* power handling */
349 struct {
350 uint8_t current;
351 uint8_t fixed;
352 } ms_power_ctrl;
Harald Welte6be350c2011-05-25 13:10:08 +0200353#endif
354};
355
Neels Hofmeyr2ebacce2016-06-14 14:08:35 +0200356enum {
357 TS_F_PDCH_ACTIVE = 0x1000,
358 TS_F_PDCH_ACT_PENDING = 0x2000,
359 TS_F_PDCH_DEACT_PENDING = 0x4000,
360 TS_F_PDCH_PENDING_MASK = 0x6000 /*<
361 TS_F_PDCH_ACT_PENDING | TS_F_PDCH_DEACT_PENDING */
362} gsm_bts_trx_ts_flags;
363
Harald Welte6be350c2011-05-25 13:10:08 +0200364/* One Timeslot in a TRX */
365struct gsm_bts_trx_ts {
366 struct gsm_bts_trx *trx;
367 /* number of this timeslot at the TRX */
368 uint8_t nr;
369
370 enum gsm_phys_chan_config pchan;
371
Neels Hofmeyrc1658762016-07-23 16:14:06 +0200372 struct {
373 enum gsm_phys_chan_config pchan_is;
374 enum gsm_phys_chan_config pchan_want;
375 struct msgb *pending_chan_activ;
376 } dyn;
377
Harald Welte6be350c2011-05-25 13:10:08 +0200378 unsigned int flags;
Harald Welted64c0bc2011-05-30 12:07:53 +0200379 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200380 struct tlv_parsed nm_attr;
381 uint8_t nm_chan_comb;
Harald Welte135a6482011-05-30 12:09:13 +0200382 int tsc; /* -1 == use BTS TSC */
Harald Welte6be350c2011-05-25 13:10:08 +0200383
384 struct {
385 /* Parameters below are configured by VTY */
386 int enabled;
387 uint8_t maio;
388 uint8_t hsn;
389 struct bitvec arfcns;
390 uint8_t arfcns_data[1024/8];
391 /* This is the pre-computed MA for channel assignments */
392 struct bitvec ma;
393 uint8_t ma_len; /* part of ma_data that is used */
394 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
395 } hopping;
396
397 /* To which E1 subslot are we connected */
398 struct gsm_e1_subslot e1_link;
399
Harald Welte591e1d72016-07-09 22:20:57 +0200400 union {
401 struct {
402 struct om2k_mo om2k_mo;
403 } rbs2000;
404 };
405
Harald Welte6be350c2011-05-25 13:10:08 +0200406 struct gsm_lchan lchan[TS_MAX_LCHAN];
407};
408
409/* One TRX in a BTS */
410struct gsm_bts_trx {
411 /* list header in bts->trx_list */
412 struct llist_head list;
413
414 struct gsm_bts *bts;
415 /* number of this TRX in the BTS */
416 uint8_t nr;
417 /* human readable name / description */
418 char *description;
419 /* how do we talk RSL with this TRX? */
420 struct gsm_e1_subslot rsl_e1_link;
421 uint8_t rsl_tei;
422 struct e1inp_sign_link *rsl_link;
Holger Hans Peter Freythercaa98d52013-10-06 15:52:14 +0200423
Harald Welte6be350c2011-05-25 13:10:08 +0200424 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
425 struct e1inp_sign_link *oml_link;
426
Harald Welted64c0bc2011-05-30 12:07:53 +0200427 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200428 struct tlv_parsed nm_attr;
429 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200430 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200431 } bb_transc;
432
433 uint16_t arfcn;
434 int nominal_power; /* in dBm */
435 unsigned int max_power_red; /* in actual dB */
Holger Hans Peter Freyther9b625802014-07-30 18:20:51 +0200436
437#ifndef ROLE_BSC
Harald Welte101c5c22014-08-22 16:12:03 +0200438 struct trx_power_params power_params;
Holger Hans Peter Freytherf6f86b02015-02-05 22:25:03 +0100439 int ms_power_control;
Harald Welte6be350c2011-05-25 13:10:08 +0200440
Harald Welted134cc72011-06-07 00:12:53 +0200441 struct {
442 void *l1h;
443 } role_bts;
Holger Hans Peter Freyther9b625802014-07-30 18:20:51 +0200444#endif
Harald Welted134cc72011-06-07 00:12:53 +0200445
Harald Welte6be350c2011-05-25 13:10:08 +0200446 union {
447 struct {
448 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200449 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200450 } bbsig;
451 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200452 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200453 } pa;
454 } bs11;
455 struct {
456 unsigned int test_state;
457 uint8_t test_nr;
458 struct rxlev_stats rxlev_stat;
459 } ipaccess;
Harald Welte591e1d72016-07-09 22:20:57 +0200460 struct {
461 struct {
462 struct om2k_mo om2k_mo;
463 } trxc;
464 struct {
465 struct om2k_mo om2k_mo;
466 } rx;
467 struct {
468 struct om2k_mo om2k_mo;
469 } tx;
470 } rbs2000;
Harald Welte6be350c2011-05-25 13:10:08 +0200471 };
472 struct gsm_bts_trx_ts ts[TRX_NR_TS];
473};
474
475#define GSM_BTS_SI(bts, i) (void *)(bts->si_buf[i])
476
477enum gsm_bts_type {
478 GSM_BTS_TYPE_UNKNOWN,
479 GSM_BTS_TYPE_BS11,
480 GSM_BTS_TYPE_NANOBTS,
481 GSM_BTS_TYPE_RBS2000,
Dieter Spaar16646022011-07-28 00:01:50 +0200482 GSM_BTS_TYPE_NOKIA_SITE,
Harald Weltef383aa12012-07-02 19:51:55 +0200483 GSM_BTS_TYPE_OSMO_SYSMO,
Harald Weltee555c2b2012-08-17 13:02:12 +0200484 _NUM_GSM_BTS_TYPE
Harald Welte6be350c2011-05-25 13:10:08 +0200485};
486
487struct vty;
488
489struct gsm_bts_model {
490 struct llist_head list;
491
492 enum gsm_bts_type type;
493 const char *name;
494
495 bool started;
496 int (*start)(struct gsm_network *net);
497 int (*oml_rcvmsg)(struct msgb *msg);
498
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200499 void (*e1line_bind_ops)(struct e1inp_line *line);
500
Harald Welte6be350c2011-05-25 13:10:08 +0200501 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
502 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
503 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
504
505 struct tlv_definition nm_att_tlvdef;
506
507 struct bitvec features;
508 uint8_t _features_data[128/8];
509};
510
511enum gsm_bts_features {
512 BTS_FEAT_HSCSD,
513 BTS_FEAT_GPRS,
514 BTS_FEAT_EGPRS,
515 BTS_FEAT_ECSD,
516 BTS_FEAT_HOPPING,
Harald Welte903aaea2014-01-19 17:10:50 +0100517 BTS_FEAT_MULTI_TSC,
Harald Welte6be350c2011-05-25 13:10:08 +0200518};
519
520/*
521 * This keeps track of the paging status of one BTS. It
522 * includes a number of pending requests, a back pointer
523 * to the gsm_bts, a timer and some more state.
524 */
525struct gsm_bts_paging_state {
526 /* pending requests */
527 struct llist_head pending_requests;
528 struct gsm_bts *bts;
529
530 struct osmo_timer_list work_timer;
531 struct osmo_timer_list credit_timer;
532
533 /* free chans needed */
534 int free_chans_need;
535
536 /* load */
537 uint16_t available_slots;
538};
539
540struct gsm_envabtse {
Harald Welted64c0bc2011-05-30 12:07:53 +0200541 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200542};
543
544struct gsm_bts_gprs_nsvc {
545 struct gsm_bts *bts;
546 /* data read via VTY config file, to configure the BTS
547 * via OML from BSC */
548 int id;
549 uint16_t nsvci;
550 uint16_t local_port; /* on the BTS */
551 uint16_t remote_port; /* on the SGSN */
552 uint32_t remote_ip; /* on the SGSN */
553
Harald Welted64c0bc2011-05-30 12:07:53 +0200554 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200555};
556
Harald Welte019f9132012-06-28 08:43:14 +0200557enum gprs_rlc_par {
558 RLC_T3142,
559 RLC_T3169,
560 RLC_T3191,
561 RLC_T3193,
562 RLC_T3195,
563 RLC_N3101,
564 RLC_N3103,
565 RLC_N3105,
566 CV_COUNTDOWN,
567 T_DL_TBF_EXT, /* ms */
568 T_UL_TBF_EXT, /* ms */
569 _NUM_RLC_PAR
570};
571
572enum gprs_cs {
573 GPRS_CS1,
574 GPRS_CS2,
575 GPRS_CS3,
576 GPRS_CS4,
577 GPRS_MCS1,
578 GPRS_MCS2,
579 GPRS_MCS3,
580 GPRS_MCS4,
581 GPRS_MCS5,
582 GPRS_MCS6,
583 GPRS_MCS7,
584 GPRS_MCS8,
585 GPRS_MCS9,
586 _NUM_GRPS_CS
587};
588
589struct gprs_rlc_cfg {
590 uint16_t parameter[_NUM_RLC_PAR];
591 struct {
592 uint16_t repeat_time; /* ms */
593 uint8_t repeat_count;
594 } paging;
595 uint32_t cs_mask; /* bitmask of gprs_cs */
596 uint8_t initial_cs;
597 uint8_t initial_mcs;
598};
599
600
Harald Welte6be350c2011-05-25 13:10:08 +0200601enum neigh_list_manual_mode {
602 NL_MODE_AUTOMATIC = 0,
603 NL_MODE_MANUAL = 1,
604 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
605};
606
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200607enum bts_loc_fix {
608 BTS_LOC_FIX_INVALID = 0,
609 BTS_LOC_FIX_2D = 1,
610 BTS_LOC_FIX_3D = 2,
611};
612
Daniel Willmann7d109832012-05-14 18:43:23 +0200613extern const struct value_string bts_loc_fix_names[];
614
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200615struct bts_location {
616 struct llist_head list;
617 time_t tstamp;
618 enum bts_loc_fix valid;
619 double lat;
620 double lon;
621 double height;
622};
623
Harald Welte6be350c2011-05-25 13:10:08 +0200624/* One BTS */
625struct gsm_bts {
626 /* list header in net->bts_list */
627 struct llist_head list;
628
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200629 /* Geographical location of the BTS */
630 struct llist_head loc_list;
631
Harald Welte6be350c2011-05-25 13:10:08 +0200632 /* number of ths BTS in network */
633 uint8_t nr;
634 /* human readable name / description */
635 char *description;
636 /* Cell Identity */
637 uint16_t cell_identity;
638 /* location area code of this BTS */
639 uint16_t location_area_code;
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100640 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
641 * which is used as TSC for the CCCH */
Harald Welte6be350c2011-05-25 13:10:08 +0200642 uint8_t bsic;
643 /* type of BTS */
644 enum gsm_bts_type type;
645 struct gsm_bts_model *model;
646 enum gsm_band band;
647 /* maximum Tx power that the MS is permitted to use in this cell */
648 int ms_max_power;
649
650 /* how do we talk OML with this TRX? */
651 struct gsm_e1_subslot oml_e1_link;
652 uint8_t oml_tei;
653 struct e1inp_sign_link *oml_link;
654
655 /* Abis network management O&M handle */
656 struct abis_nm_h *nmh;
Harald Welted64c0bc2011-05-30 12:07:53 +0200657
658 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200659
660 /* number of this BTS on given E1 link */
661 uint8_t bts_nr;
662
Maxc08ee712016-05-11 12:45:13 +0200663 /* DTX features of this BTS */
664 enum gsm48_dtx_mode dtxu;
665 bool dtxd;
666
Harald Welte6be350c2011-05-25 13:10:08 +0200667 /* paging state and control */
668 struct gsm_bts_paging_state paging;
669
670 /* CCCH is on C0 */
671 struct gsm_bts_trx *c0;
672
673 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200674 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200675 } site_mgr;
676
677 /* bitmask of all SI that are present/valid in si_buf */
678 uint32_t si_valid;
679 /* buffers where we put the pre-computed SI */
680 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE];
681
682 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
683 union {
684 struct {
685 uint16_t site_id;
686 uint16_t bts_id;
687 uint32_t flags;
Harald Welte8b291802013-03-12 13:57:05 +0100688 uint32_t rsl_ip;
Harald Welte6be350c2011-05-25 13:10:08 +0200689 } ip_access;
690 struct {
691 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200692 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200693 } cclk;
694 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200695 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200696 } rack;
697 struct gsm_envabtse envabtse[4];
698 } bs11;
699 struct {
700 struct {
Harald Welte591e1d72016-07-09 22:20:57 +0200701 struct om2k_mo om2k_mo;
702 struct gsm_abis_mo mo;
703 struct llist_head conn_groups;
704 } cf;
705 struct {
706 struct om2k_mo om2k_mo;
Harald Welted64c0bc2011-05-30 12:07:53 +0200707 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200708 struct llist_head conn_groups;
709 } is;
710 struct {
Harald Welte591e1d72016-07-09 22:20:57 +0200711 struct om2k_mo om2k_mo;
Harald Welted64c0bc2011-05-30 12:07:53 +0200712 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200713 struct llist_head conn_groups;
714 } con;
715 struct {
Harald Welte591e1d72016-07-09 22:20:57 +0200716 struct om2k_mo om2k_mo;
Harald Welted64c0bc2011-05-30 12:07:53 +0200717 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200718 } dp;
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 } tf;
723 } rbs2000;
724 struct {
Harald Weltec8755af2011-07-28 00:22:17 +0200725 uint8_t bts_type;
Holger Hans Peter Freyther3e603482012-03-02 14:14:33 +0100726 unsigned int configured:1,
727 skip_reset:1,
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100728 no_loc_rel_cnf:1,
Sipos Csaba56e17662015-02-07 13:27:36 +0100729 bts_reset_timer_cnf,
Holger Hans Peter Freyther3e603482012-03-02 14:14:33 +0100730 did_reset:1,
731 wait_reset:1;
Harald Weltec8755af2011-07-28 00:22:17 +0200732 struct osmo_timer_list reset_timer;
733 } nokia;
Harald Welte6be350c2011-05-25 13:10:08 +0200734 };
735
736 /* Not entirely sure how ip.access specific this is */
737 struct {
bhargava350533c2016-07-21 11:14:34 +0530738 uint8_t supports_egprs_11bit_rach;
Harald Welte6be350c2011-05-25 13:10:08 +0200739 enum bts_gprs_mode mode;
740 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200741 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200742 uint16_t nsei;
743 uint8_t timer[7];
744 } nse;
745 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200746 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200747 uint16_t bvci;
748 uint8_t timer[11];
Harald Welte019f9132012-06-28 08:43:14 +0200749 struct gprs_rlc_cfg rlc_cfg;
Harald Welte6be350c2011-05-25 13:10:08 +0200750 } cell;
751 struct gsm_bts_gprs_nsvc nsvc[2];
752 uint8_t rac;
Andreas Eversberg0c8f9ca2013-03-16 16:31:26 +0100753 uint8_t net_ctrl_ord;
Max292ec582016-07-28 11:55:37 +0200754 bool ctrl_ack_type_use_block;
Harald Welte6be350c2011-05-25 13:10:08 +0200755 } gprs;
756
757 /* RACH NM values */
758 int rach_b_thresh;
759 int rach_ldavg_slots;
760
761 /* transceivers */
762 int num_trx;
763 struct llist_head trx_list;
764
Holger Hans Peter Freytherb92a5382014-11-21 10:00:39 +0100765 /* SI related items */
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100766 int force_combined_si;
Holger Hans Peter Freytherb92a5382014-11-21 10:00:39 +0100767 int bcch_change_mark;
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100768
Harald Welte6be350c2011-05-25 13:10:08 +0200769#ifdef ROLE_BSC
770 /* Abis NM queue */
771 struct llist_head abis_queue;
772 int abis_nm_pend;
773
774 struct gsm_network *network;
775
776 /* should the channel allocator allocate channels from high TRX to TRX0,
777 * rather than starting from TRX0 and go upwards? */
778 int chan_alloc_reverse;
779
780 enum neigh_list_manual_mode neigh_list_manual_mode;
781 /* parameters from which we build SYSTEM INFORMATION */
782 struct {
783 struct gsm48_rach_control rach_control;
784 uint8_t ncc_permitted;
785 struct gsm48_cell_sel_par cell_sel_par;
786 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
787 struct gsm48_cell_options cell_options;
788 struct gsm48_control_channel_descr chan_desc;
789 struct bitvec neigh_list;
790 struct bitvec cell_alloc;
791 struct bitvec si5_neigh_list;
Max59a1bf32016-04-15 16:04:46 +0200792 struct osmo_earfcn_si2q si2quater_neigh_list;
Max26679e02016-04-20 15:57:13 +0200793 size_t uarfcn_length; /* index for uarfcn and scramble lists */
Harald Welte6be350c2011-05-25 13:10:08 +0200794 struct {
795 /* bitmask large enough for all possible ARFCN's */
796 uint8_t neigh_list[1024/8];
797 uint8_t cell_alloc[1024/8];
798 /* If the user wants a different neighbor list in SI5 than in SI2 */
799 uint8_t si5_neigh_list[1024/8];
Max59a1bf32016-04-15 16:04:46 +0200800 uint8_t meas_bw_list[MAX_EARFCN_LIST];
801 uint16_t earfcn_list[MAX_EARFCN_LIST];
Max26679e02016-04-20 15:57:13 +0200802 uint16_t uarfcn_list[MAX_EARFCN_LIST];
803 uint16_t scramble_list[MAX_EARFCN_LIST];
Harald Welte6be350c2011-05-25 13:10:08 +0200804 } data;
805 } si_common;
806
807 /* do we use static (user-defined) system information messages? (bitmask) */
808 uint32_t si_mode_static;
Holger Hans Peter Freythere30d40d2012-07-20 10:27:31 +0200809
810 /* exclude the BTS from the global RF Lock handling */
811 int excl_from_rf_lock;
Andreas Eversberga83d5112013-12-07 18:32:28 +0100812
813 /* supported codecs beside FR */
814 struct bts_codec_conf codec;
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100815
816 /* BTS dependencies bit field */
817 uint32_t depends_on[256/(8*4)];
Andreas Eversberg73266522014-01-19 11:47:44 +0100818
819 /* full and half rate multirate config */
820 struct amr_multirate_conf mr_full;
821 struct amr_multirate_conf mr_half;
822
Harald Welte6be350c2011-05-25 13:10:08 +0200823#endif /* ROLE_BSC */
Harald Welte978714d2011-06-06 18:31:20 +0200824 void *role;
Harald Welte6be350c2011-05-25 13:10:08 +0200825};
826
827
Harald Welte3300c012011-06-05 13:31:33 +0200828struct gsm_bts *gsm_bts_alloc(void *talloc_ctx);
Harald Welte1449c9f2014-08-24 09:50:10 +0200829struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Harald Welte6be350c2011-05-25 13:10:08 +0200830
Harald Welte1449c9f2014-08-24 09:50:10 +0200831struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
Harald Welte4f8ad532011-09-19 14:21:51 +0200832struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
Harald Welte6be350c2011-05-25 13:10:08 +0200833
Harald Welte4ab9d7c2012-08-17 12:42:06 +0200834
Neels Hofmeyr17a6bab2016-07-23 16:14:06 +0200835const struct value_string gsm_pchant_names[13];
836const struct value_string gsm_pchant_descs[13];
Harald Welte6be350c2011-05-25 13:10:08 +0200837const char *gsm_pchan_name(enum gsm_phys_chan_config c);
838enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
839const char *gsm_lchant_name(enum gsm_chan_t c);
840const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte4f8ad532011-09-19 14:21:51 +0200841char *gsm_trx_name(const struct gsm_bts_trx *trx);
842char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr34b8b5b2016-07-16 23:59:32 +0200843char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
Harald Weltec696cc22015-12-05 16:19:21 +0100844char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
Harald Welte6be350c2011-05-25 13:10:08 +0200845const char *gsm_lchans_name(enum gsm_lchan_state s);
846
Harald Weltec696cc22015-12-05 16:19:21 +0100847static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
848{
849 return lchan->name;
850}
Harald Welte6be350c2011-05-25 13:10:08 +0200851
Harald Welteb7849982011-06-29 16:49:03 +0200852void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
853
Harald Welte978714d2011-06-06 18:31:20 +0200854struct gsm_abis_mo *
855gsm_objclass2mo(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200856 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200857
858struct gsm_nm_state *
859gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200860 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200861void *
862gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200863 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200864
Harald Welteb7849982011-06-29 16:49:03 +0200865/* reset the state of all MO in the BTS */
866void gsm_bts_mo_reset(struct gsm_bts *bts);
867
Neels Hofmeyrd3841102016-07-18 23:43:44 +0200868uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
869 uint8_t ts_nr, uint8_t lchan_nr);
Harald Weltef6093a42011-06-25 10:02:33 +0200870uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
Neels Hofmeyrd3841102016-07-18 23:43:44 +0200871uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
872 enum gsm_phys_chan_config as_pchan);
Harald Weltef6093a42011-06-25 10:02:33 +0200873
Harald Welte142d12d2014-12-29 17:47:08 +0100874/* return the gsm_lchan for the CBCH (if it exists at all) */
875struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
876
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200877/*
878 * help with parsing regexps
879 */
880int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
881 int argc, const char **argv) __attribute__ ((warn_unused_result));
882
Harald Welte1fe24122014-01-19 17:18:21 +0100883static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
884{
885 if (ts->tsc != -1)
886 return ts->tsc;
887 else
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100888 return ts->trx->bts->bsic & 7;
Harald Welte1fe24122014-01-19 17:18:21 +0100889}
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200890
Neels Hofmeyr74585722016-07-23 17:38:22 +0200891struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
892 int *rc);
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200893
Neels Hofmeyrec16c162016-10-17 01:03:53 +0200894enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr76a0ad72016-07-29 18:12:06 +0200895uint8_t ts_subslots(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr255dbfe2016-09-25 15:07:01 +0200896bool ts_is_tch(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr76a0ad72016-07-29 18:12:06 +0200897
Harald Welte6be350c2011-05-25 13:10:08 +0200898#endif