blob: 953bac62e13b5207dd30cb4b0422cb9044d9a8c1 [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
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +020027struct osmo_bsc_data;
28
Harald Welte6be350c2011-05-25 13:10:08 +020029struct osmo_bsc_sccp_con;
30struct gsm_sms_queue;
31
32/* RRLP mode of operation */
33enum rrlp_mode {
34 RRLP_MODE_NONE,
35 RRLP_MODE_MS_BASED,
36 RRLP_MODE_MS_PREF,
37 RRLP_MODE_ASS_PREF,
38};
39
40/* Channel Request reason */
41enum gsm_chreq_reason_t {
42 GSM_CHREQ_REASON_EMERG,
43 GSM_CHREQ_REASON_PAG,
44 GSM_CHREQ_REASON_CALL,
45 GSM_CHREQ_REASON_LOCATION_UPD,
46 GSM_CHREQ_REASON_OTHER,
47};
48
49#define TRX_NR_TS 8
50#define TS_MAX_LCHAN 8
51
52#define HARDCODED_ARFCN 123
Harald Welte6be350c2011-05-25 13:10:08 +020053#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
54
55/* for multi-drop config */
56#define HARDCODED_BTS0_TS 1
57#define HARDCODED_BTS1_TS 6
58#define HARDCODED_BTS2_TS 11
59
Harald Welte6be350c2011-05-25 13:10:08 +020060enum gsm_hooks {
61 GSM_HOOK_NM_SWLOAD,
62 GSM_HOOK_RR_PAGING,
63 GSM_HOOK_RR_SECURITY,
64};
65
66enum gsm_paging_event {
67 GSM_PAGING_SUCCEEDED,
68 GSM_PAGING_EXPIRED,
69 GSM_PAGING_OOM,
70 GSM_PAGING_BUSY,
71};
72
73enum bts_gprs_mode {
74 BTS_GPRS_NONE = 0,
75 BTS_GPRS_GPRS = 1,
76 BTS_GPRS_EGPRS = 2,
77};
78
79struct gsm_lchan;
80struct gsm_subscriber;
81struct gsm_mncc;
Harald Welte135a6bd2011-09-04 13:53:26 +020082struct osmo_rtp_socket;
Harald Welte6be350c2011-05-25 13:10:08 +020083struct rtp_socket;
84struct bsc_api;
85
86/* Network Management State */
87struct gsm_nm_state {
88 uint8_t operational;
89 uint8_t administrative;
90 uint8_t availability;
91};
92
Harald Welted64c0bc2011-05-30 12:07:53 +020093struct gsm_abis_mo {
Harald Welte3300c012011-06-05 13:31:33 +020094 uint8_t obj_class;
Holger Hans Peter Freyther49976f42013-11-05 16:06:17 +010095 uint8_t procedure_pending;
Harald Welte3300c012011-06-05 13:31:33 +020096 struct abis_om_obj_inst obj_inst;
Harald Welted64c0bc2011-05-30 12:07:53 +020097 const char *name;
98 struct gsm_nm_state nm_state;
99 struct tlv_parsed *nm_attr;
Harald Welte32bc1162011-06-06 18:58:48 +0200100 struct gsm_bts *bts;
Harald Welted64c0bc2011-05-30 12:07:53 +0200101};
102
Harald Welte6be350c2011-05-25 13:10:08 +0200103#define MAX_A5_KEY_LEN (128/8)
104#define A38_XOR_MIN_KEY_LEN 12
105#define A38_XOR_MAX_KEY_LEN 16
106#define A38_COMP128_KEY_LEN 16
107#define RSL_ENC_ALG_A5(x) (x+1)
Max27c3e762016-04-20 15:57:12 +0200108#define MAX_EARFCN_LIST 32
Harald Welte6be350c2011-05-25 13:10:08 +0200109
110/* is the data link established? who established it? */
111#define LCHAN_SAPI_UNUSED 0
112#define LCHAN_SAPI_MS 1
113#define LCHAN_SAPI_NET 2
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100114#define LCHAN_SAPI_REL 3
Harald Welte6be350c2011-05-25 13:10:08 +0200115
116/* state of a logical channel */
117enum gsm_lchan_state {
118 LCHAN_S_NONE, /* channel is not active */
Holger Hans Peter Freytherded02682012-01-15 00:02:17 +0100119 LCHAN_S_ACT_REQ, /* channel activation requested */
Harald Welte6be350c2011-05-25 13:10:08 +0200120 LCHAN_S_ACTIVE, /* channel is active and operational */
121 LCHAN_S_REL_REQ, /* channel release has been requested */
122 LCHAN_S_REL_ERR, /* channel is in an error state */
Holger Hans Peter Freyther638da512012-12-06 19:25:06 +0100123 LCHAN_S_BROKEN, /* channel is somehow unusable */
Harald Welte6be350c2011-05-25 13:10:08 +0200124 LCHAN_S_INACTIVE, /* channel is set inactive */
125};
126
Harald Weltec7921c92011-06-29 10:38:34 +0200127/* BTS ONLY */
128#define MAX_NUM_UL_MEAS 104
129#define LC_UL_M_F_L1_VALID (1 << 0)
130#define LC_UL_M_F_RES_VALID (1 << 1)
131
132struct bts_ul_meas {
133 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
134 uint16_t ber10k;
135 /* timing advance offset (in quarter bits) */
136 int16_t ta_offs_qbits;
137 /* C/I ratio in dB */
138 float c_i;
139 /* flags */
140 uint8_t is_sub:1;
141 /* RSSI in dBm * -1 */
142 uint8_t inv_rssi;
143};
Harald Weltef3b59322011-09-06 22:14:43 +0200144
Andreas Eversberga83d5112013-12-07 18:32:28 +0100145struct bts_codec_conf {
146 uint8_t hr;
147 uint8_t efr;
148 uint8_t amr;
149};
150
Harald Weltef3b59322011-09-06 22:14:43 +0200151struct amr_mode {
152 uint8_t mode;
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200153 uint8_t threshold;
154 uint8_t hysteresis;
Harald Weltef3b59322011-09-06 22:14:43 +0200155};
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200156
Harald Weltef3b59322011-09-06 22:14:43 +0200157struct amr_multirate_conf {
158 uint8_t gsm48_ie[2];
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200159 struct amr_mode ms_mode[4];
160 struct amr_mode bts_mode[4];
Harald Weltef3b59322011-09-06 22:14:43 +0200161 uint8_t num_modes;
162};
Harald Weltec7921c92011-06-29 10:38:34 +0200163/* /BTS ONLY */
164
Harald Weltee4227982012-08-24 15:33:56 +0200165enum lchan_csd_mode {
166 LCHAN_CSD_M_NT,
167 LCHAN_CSD_M_T_1200_75,
168 LCHAN_CSD_M_T_600,
169 LCHAN_CSD_M_T_1200,
170 LCHAN_CSD_M_T_2400,
171 LCHAN_CSD_M_T_9600,
172 LCHAN_CSD_M_T_14400,
173 LCHAN_CSD_M_T_29000,
174 LCHAN_CSD_M_T_32000,
175};
176
Daniel Willmann324c8052012-12-29 12:32:30 +0100177/* State of the SAPIs in the lchan */
178enum lchan_sapi_state {
179 LCHAN_SAPI_S_NONE,
180 LCHAN_SAPI_S_REQ,
181 LCHAN_SAPI_S_ASSIGNED,
182 LCHAN_SAPI_S_REL,
183 LCHAN_SAPI_S_ERROR,
184};
185
Harald Welte6be350c2011-05-25 13:10:08 +0200186struct gsm_lchan {
187 /* The TS that we're part of */
188 struct gsm_bts_trx_ts *ts;
189 /* The logical subslot number in the TS */
190 uint8_t nr;
191 /* The logical channel type */
192 enum gsm_chan_t type;
193 /* RSL channel mode */
194 enum rsl_cmod_spd rsl_cmode;
195 /* If TCH, traffic channel mode */
196 enum gsm48_chan_mode tch_mode;
Harald Weltee4227982012-08-24 15:33:56 +0200197 enum lchan_csd_mode csd_mode;
Harald Welte6be350c2011-05-25 13:10:08 +0200198 /* State */
199 enum gsm_lchan_state state;
Holger Hans Peter Freyther454140e2014-12-28 12:08:28 +0100200 const char *broken_reason;
Harald Welte6be350c2011-05-25 13:10:08 +0200201 /* Power levels for MS and BTS */
202 uint8_t bs_power;
203 uint8_t ms_power;
204 /* Encryption information */
205 struct {
206 uint8_t alg_id;
207 uint8_t key_len;
208 uint8_t key[MAX_A5_KEY_LEN];
209 } encr;
210
211 /* AMR bits */
Andreas Eversberg73266522014-01-19 11:47:44 +0100212 uint8_t mr_ms_lv[7];
213 uint8_t mr_bts_lv[7];
Harald Welte6be350c2011-05-25 13:10:08 +0200214
215 /* Established data link layer services */
216 uint8_t sapis[8];
Holger Hans Peter Freytherb9b828b2013-01-01 19:20:28 +0100217 int sacch_deact;
Holger Hans Peter Freytherdfcfe652011-12-27 20:49:53 +0100218
Harald Welte6be350c2011-05-25 13:10:08 +0200219 struct {
220 uint32_t bound_ip;
221 uint32_t connect_ip;
222 uint16_t bound_port;
223 uint16_t connect_port;
224 uint16_t conn_id;
225 uint8_t rtp_payload;
226 uint8_t rtp_payload2;
227 uint8_t speech_mode;
Harald Welte135a6bd2011-09-04 13:53:26 +0200228#ifdef ROLE_BSC
Harald Welte6be350c2011-05-25 13:10:08 +0200229 struct rtp_socket *rtp_socket;
Harald Welte135a6bd2011-09-04 13:53:26 +0200230#else
231 struct osmo_rtp_socket *rtp_socket;
232#endif
Harald Welte6be350c2011-05-25 13:10:08 +0200233 } abis_ip;
234
Harald Welte2c1ae472011-06-26 14:13:37 +0200235 uint8_t rqd_ta;
236
Harald Weltec696cc22015-12-05 16:19:21 +0100237 char *name;
238
Harald Welte6be350c2011-05-25 13:10:08 +0200239#ifdef ROLE_BSC
240 struct osmo_timer_list T3101;
Holger Hans Peter Freytherb3489392011-12-28 16:21:05 +0100241 struct osmo_timer_list T3109;
Harald Welte6be350c2011-05-25 13:10:08 +0200242 struct osmo_timer_list T3111;
243 struct osmo_timer_list error_timer;
Harald Weltee8bd9e82011-08-10 23:26:33 +0200244 struct osmo_timer_list act_timer;
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100245 struct osmo_timer_list rel_work;
Holger Hans Peter Freyther638da512012-12-06 19:25:06 +0100246 uint8_t error_cause;
Harald Welte6be350c2011-05-25 13:10:08 +0200247
248 /* table of neighbor cell measurements */
249 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
250
251 /* cache of last measurement reports on this lchan */
252 struct gsm_meas_rep meas_rep[6];
253 int meas_rep_idx;
254
255 /* GSM Random Access data */
256 struct gsm48_req_ref *rqd_ref;
Harald Welte6be350c2011-05-25 13:10:08 +0200257
258 struct gsm_subscriber_connection *conn;
Andreas Eversberg9df268e2013-10-11 13:32:30 +0200259
260 struct {
261 /* channel activation type and handover ref */
262 uint8_t act_type;
263 uint8_t ho_ref;
Neels Hofmeyrb91e6002016-07-23 19:45:15 +0200264 struct gsm48_req_ref *rqd_ref;
265 uint8_t rqd_ta;
Neels Hofmeyr6e999b72016-07-23 21:00:51 +0200266 } dyn;
Harald Weltef6093a42011-06-25 10:02:33 +0200267#else
Daniel Willmann324c8052012-12-29 12:32:30 +0100268 /* Number of different GsmL1_Sapi_t used in osmo_bts_sysmo is 23.
269 * Currently we don't share these headers so this is a magic number. */
Holger Hans Peter Freyther30156e12013-04-05 18:41:45 +0200270 struct llist_head sapi_cmds;
Daniel Willmann324c8052012-12-29 12:32:30 +0100271 uint8_t sapis_dl[23];
272 uint8_t sapis_ul[23];
Harald Weltef6093a42011-06-25 10:02:33 +0200273 struct lapdm_channel lapdm_ch;
Harald Welte135a6bd2011-09-04 13:53:26 +0200274 struct llist_head dl_tch_queue;
Harald Welte2c1ae472011-06-26 14:13:37 +0200275 struct {
276 /* bitmask of all SI that are present/valid in si_buf */
277 uint32_t valid;
278 uint32_t last;
279 /* buffers where we put the pre-computed SI */
280 sysinfo_buf_t buf[_MAX_SYSINFO_TYPE];
281 } si;
Harald Weltec7921c92011-06-29 10:38:34 +0200282 struct {
283 uint8_t flags;
284 /* RSL measurment result number, 0 at lchan_act */
285 uint8_t res_nr;
286 /* current Tx power level of the BTS */
287 uint8_t bts_tx_pwr;
288 /* number of measurements stored in array below */
289 uint8_t num_ul_meas;
290 struct bts_ul_meas uplink[MAX_NUM_UL_MEAS];
291 /* last L1 header from the MS */
292 uint8_t l1_info[2];
Harald Welte7ff4f0e2013-03-07 18:38:09 +0000293 struct gsm_meas_rep_unidir ul_res;
Harald Weltec7921c92011-06-29 10:38:34 +0200294 } meas;
Harald Weltef3b59322011-09-06 22:14:43 +0200295 struct {
296 struct amr_multirate_conf amr_mr;
Harald Welte43290992011-09-07 12:41:38 +0200297 struct {
298 uint8_t buf[16];
299 uint8_t len;
Maxf5fe31d2016-06-10 14:09:07 +0200300 uint32_t fn;
301 bool is_update;
Harald Welte43290992011-09-07 12:41:38 +0200302 } last_sid;
Maxf5fe31d2016-06-10 14:09:07 +0200303 /* set for each SID frame to detect talkspurt for codecs without
304 explicit ONSET event */
305 bool ul_sid;
Holger Hans Peter Freyther922ef5d2014-07-24 21:05:32 +0200306 uint8_t last_cmr;
Maxd7df7ae2016-06-03 12:06:26 +0200307 uint32_t last_fn;
Maxae3f0712016-06-09 12:29:50 +0200308 /* indicates if DTXd was active during DL measurement period */
309 bool dtxd_active;
Harald Weltef3b59322011-09-06 22:14:43 +0200310 } tch;
Harald Welte5d52c972012-04-08 20:23:28 +0200311 /* BTS-side ciphering state (rx only, bi-directional, ...) */
312 uint8_t ciph_state;
Holger Hans Peter Freyther2c6b59c2014-08-09 09:43:53 +0200313 uint8_t ciph_ns;
Harald Welte46cb8512012-04-19 23:13:35 +0200314 uint8_t loopback;
Harald Welte704cb862012-06-16 14:57:08 +0800315 struct {
316 uint8_t active;
317 uint8_t ref;
318 /* T3105: PHYS INF retransmission */
319 struct osmo_timer_list t3105;
320 /* counts up to Ny1 */
321 unsigned int phys_info_count;
322 } ho;
Andreas Eversberg1af682a2013-02-20 16:06:20 +0100323 /* S counter for link loss */
324 int s;
Holger Hans Peter Freytherfc7a75f2013-10-25 18:58:30 +0200325 /* Kind of the release/activation. E.g. RSL or PCU */
326 int rel_act_kind;
Maxec744652016-05-18 16:42:16 +0200327 /* RTP header Marker bit to indicate beginning of speech after pause */
328 bool rtp_tx_marker;
Holger Hans Peter Freytherf6f86b02015-02-05 22:25:03 +0100329 /* power handling */
330 struct {
331 uint8_t current;
332 uint8_t fixed;
333 } ms_power_ctrl;
Harald Welte6be350c2011-05-25 13:10:08 +0200334#endif
335};
336
Neels Hofmeyr2ebacce2016-06-14 14:08:35 +0200337enum {
338 TS_F_PDCH_ACTIVE = 0x1000,
339 TS_F_PDCH_ACT_PENDING = 0x2000,
340 TS_F_PDCH_DEACT_PENDING = 0x4000,
341 TS_F_PDCH_PENDING_MASK = 0x6000 /*<
342 TS_F_PDCH_ACT_PENDING | TS_F_PDCH_DEACT_PENDING */
343} gsm_bts_trx_ts_flags;
344
Harald Welte6be350c2011-05-25 13:10:08 +0200345/* One Timeslot in a TRX */
346struct gsm_bts_trx_ts {
347 struct gsm_bts_trx *trx;
348 /* number of this timeslot at the TRX */
349 uint8_t nr;
350
351 enum gsm_phys_chan_config pchan;
352
Neels Hofmeyrc1658762016-07-23 16:14:06 +0200353 struct {
354 enum gsm_phys_chan_config pchan_is;
355 enum gsm_phys_chan_config pchan_want;
356 struct msgb *pending_chan_activ;
357 } dyn;
358
Harald Welte6be350c2011-05-25 13:10:08 +0200359 unsigned int flags;
Harald Welted64c0bc2011-05-30 12:07:53 +0200360 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200361 struct tlv_parsed nm_attr;
362 uint8_t nm_chan_comb;
Harald Welte135a6482011-05-30 12:09:13 +0200363 int tsc; /* -1 == use BTS TSC */
Harald Welte6be350c2011-05-25 13:10:08 +0200364
365 struct {
366 /* Parameters below are configured by VTY */
367 int enabled;
368 uint8_t maio;
369 uint8_t hsn;
370 struct bitvec arfcns;
371 uint8_t arfcns_data[1024/8];
372 /* This is the pre-computed MA for channel assignments */
373 struct bitvec ma;
374 uint8_t ma_len; /* part of ma_data that is used */
375 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
376 } hopping;
377
378 /* To which E1 subslot are we connected */
379 struct gsm_e1_subslot e1_link;
380
381 struct gsm_lchan lchan[TS_MAX_LCHAN];
382};
383
384/* One TRX in a BTS */
385struct gsm_bts_trx {
386 /* list header in bts->trx_list */
387 struct llist_head list;
388
389 struct gsm_bts *bts;
390 /* number of this TRX in the BTS */
391 uint8_t nr;
392 /* human readable name / description */
393 char *description;
394 /* how do we talk RSL with this TRX? */
395 struct gsm_e1_subslot rsl_e1_link;
396 uint8_t rsl_tei;
397 struct e1inp_sign_link *rsl_link;
Holger Hans Peter Freythercaa98d52013-10-06 15:52:14 +0200398
Harald Welte6be350c2011-05-25 13:10:08 +0200399 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
400 struct e1inp_sign_link *oml_link;
401
Harald Welted64c0bc2011-05-30 12:07:53 +0200402 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200403 struct tlv_parsed nm_attr;
404 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200405 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200406 } bb_transc;
407
408 uint16_t arfcn;
409 int nominal_power; /* in dBm */
410 unsigned int max_power_red; /* in actual dB */
Holger Hans Peter Freyther9b625802014-07-30 18:20:51 +0200411
412#ifndef ROLE_BSC
Harald Welte101c5c22014-08-22 16:12:03 +0200413 struct trx_power_params power_params;
Holger Hans Peter Freytherf6f86b02015-02-05 22:25:03 +0100414 int ms_power_control;
Harald Welte6be350c2011-05-25 13:10:08 +0200415
Harald Welted134cc72011-06-07 00:12:53 +0200416 struct {
417 void *l1h;
418 } role_bts;
Holger Hans Peter Freyther9b625802014-07-30 18:20:51 +0200419#endif
Harald Welted134cc72011-06-07 00:12:53 +0200420
Harald Welte6be350c2011-05-25 13:10:08 +0200421 union {
422 struct {
423 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200424 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200425 } bbsig;
426 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200427 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200428 } pa;
429 } bs11;
430 struct {
431 unsigned int test_state;
432 uint8_t test_nr;
433 struct rxlev_stats rxlev_stat;
434 } ipaccess;
435 };
436 struct gsm_bts_trx_ts ts[TRX_NR_TS];
437};
438
439#define GSM_BTS_SI(bts, i) (void *)(bts->si_buf[i])
440
441enum gsm_bts_type {
442 GSM_BTS_TYPE_UNKNOWN,
443 GSM_BTS_TYPE_BS11,
444 GSM_BTS_TYPE_NANOBTS,
445 GSM_BTS_TYPE_RBS2000,
Dieter Spaar16646022011-07-28 00:01:50 +0200446 GSM_BTS_TYPE_NOKIA_SITE,
Harald Weltef383aa12012-07-02 19:51:55 +0200447 GSM_BTS_TYPE_OSMO_SYSMO,
Harald Weltee555c2b2012-08-17 13:02:12 +0200448 _NUM_GSM_BTS_TYPE
Harald Welte6be350c2011-05-25 13:10:08 +0200449};
450
451struct vty;
452
453struct gsm_bts_model {
454 struct llist_head list;
455
456 enum gsm_bts_type type;
457 const char *name;
458
459 bool started;
460 int (*start)(struct gsm_network *net);
461 int (*oml_rcvmsg)(struct msgb *msg);
462
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200463 void (*e1line_bind_ops)(struct e1inp_line *line);
464
Harald Welte6be350c2011-05-25 13:10:08 +0200465 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
466 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
467 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
468
469 struct tlv_definition nm_att_tlvdef;
470
471 struct bitvec features;
472 uint8_t _features_data[128/8];
473};
474
475enum gsm_bts_features {
476 BTS_FEAT_HSCSD,
477 BTS_FEAT_GPRS,
478 BTS_FEAT_EGPRS,
479 BTS_FEAT_ECSD,
480 BTS_FEAT_HOPPING,
Harald Welte903aaea2014-01-19 17:10:50 +0100481 BTS_FEAT_MULTI_TSC,
Harald Welte6be350c2011-05-25 13:10:08 +0200482};
483
484/*
485 * This keeps track of the paging status of one BTS. It
486 * includes a number of pending requests, a back pointer
487 * to the gsm_bts, a timer and some more state.
488 */
489struct gsm_bts_paging_state {
490 /* pending requests */
491 struct llist_head pending_requests;
492 struct gsm_bts *bts;
493
494 struct osmo_timer_list work_timer;
495 struct osmo_timer_list credit_timer;
496
497 /* free chans needed */
498 int free_chans_need;
499
500 /* load */
501 uint16_t available_slots;
502};
503
504struct gsm_envabtse {
Harald Welted64c0bc2011-05-30 12:07:53 +0200505 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200506};
507
508struct gsm_bts_gprs_nsvc {
509 struct gsm_bts *bts;
510 /* data read via VTY config file, to configure the BTS
511 * via OML from BSC */
512 int id;
513 uint16_t nsvci;
514 uint16_t local_port; /* on the BTS */
515 uint16_t remote_port; /* on the SGSN */
516 uint32_t remote_ip; /* on the SGSN */
517
Harald Welted64c0bc2011-05-30 12:07:53 +0200518 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200519};
520
Harald Welte019f9132012-06-28 08:43:14 +0200521enum gprs_rlc_par {
522 RLC_T3142,
523 RLC_T3169,
524 RLC_T3191,
525 RLC_T3193,
526 RLC_T3195,
527 RLC_N3101,
528 RLC_N3103,
529 RLC_N3105,
530 CV_COUNTDOWN,
531 T_DL_TBF_EXT, /* ms */
532 T_UL_TBF_EXT, /* ms */
533 _NUM_RLC_PAR
534};
535
536enum gprs_cs {
537 GPRS_CS1,
538 GPRS_CS2,
539 GPRS_CS3,
540 GPRS_CS4,
541 GPRS_MCS1,
542 GPRS_MCS2,
543 GPRS_MCS3,
544 GPRS_MCS4,
545 GPRS_MCS5,
546 GPRS_MCS6,
547 GPRS_MCS7,
548 GPRS_MCS8,
549 GPRS_MCS9,
550 _NUM_GRPS_CS
551};
552
553struct gprs_rlc_cfg {
554 uint16_t parameter[_NUM_RLC_PAR];
555 struct {
556 uint16_t repeat_time; /* ms */
557 uint8_t repeat_count;
558 } paging;
559 uint32_t cs_mask; /* bitmask of gprs_cs */
560 uint8_t initial_cs;
561 uint8_t initial_mcs;
562};
563
564
Harald Welte6be350c2011-05-25 13:10:08 +0200565enum neigh_list_manual_mode {
566 NL_MODE_AUTOMATIC = 0,
567 NL_MODE_MANUAL = 1,
568 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
569};
570
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200571enum bts_loc_fix {
572 BTS_LOC_FIX_INVALID = 0,
573 BTS_LOC_FIX_2D = 1,
574 BTS_LOC_FIX_3D = 2,
575};
576
Daniel Willmann7d109832012-05-14 18:43:23 +0200577extern const struct value_string bts_loc_fix_names[];
578
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200579struct bts_location {
580 struct llist_head list;
581 time_t tstamp;
582 enum bts_loc_fix valid;
583 double lat;
584 double lon;
585 double height;
586};
587
Harald Welte6be350c2011-05-25 13:10:08 +0200588/* One BTS */
589struct gsm_bts {
590 /* list header in net->bts_list */
591 struct llist_head list;
592
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200593 /* Geographical location of the BTS */
594 struct llist_head loc_list;
595
Harald Welte6be350c2011-05-25 13:10:08 +0200596 /* number of ths BTS in network */
597 uint8_t nr;
598 /* human readable name / description */
599 char *description;
600 /* Cell Identity */
601 uint16_t cell_identity;
602 /* location area code of this BTS */
603 uint16_t location_area_code;
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100604 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
605 * which is used as TSC for the CCCH */
Harald Welte6be350c2011-05-25 13:10:08 +0200606 uint8_t bsic;
607 /* type of BTS */
608 enum gsm_bts_type type;
609 struct gsm_bts_model *model;
610 enum gsm_band band;
611 /* maximum Tx power that the MS is permitted to use in this cell */
612 int ms_max_power;
613
614 /* how do we talk OML with this TRX? */
615 struct gsm_e1_subslot oml_e1_link;
616 uint8_t oml_tei;
617 struct e1inp_sign_link *oml_link;
618
619 /* Abis network management O&M handle */
620 struct abis_nm_h *nmh;
Harald Welted64c0bc2011-05-30 12:07:53 +0200621
622 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200623
624 /* number of this BTS on given E1 link */
625 uint8_t bts_nr;
626
Maxc08ee712016-05-11 12:45:13 +0200627 /* DTX features of this BTS */
628 enum gsm48_dtx_mode dtxu;
629 bool dtxd;
630
Harald Welte6be350c2011-05-25 13:10:08 +0200631 /* paging state and control */
632 struct gsm_bts_paging_state paging;
633
634 /* CCCH is on C0 */
635 struct gsm_bts_trx *c0;
636
637 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200638 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200639 } site_mgr;
640
641 /* bitmask of all SI that are present/valid in si_buf */
642 uint32_t si_valid;
643 /* buffers where we put the pre-computed SI */
644 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE];
645
Gus Bourg1c5dd2c2011-12-02 10:18:17 +0100646 /* TimeZone hours, mins, and bts specific */
Harald Welte45f91712012-07-08 16:48:11 +0200647 struct {
648 int hr;
649 int mn;
650 int override;
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200651 int dst;
Harald Welte45f91712012-07-08 16:48:11 +0200652 } tz;
Gus Bourg1c5dd2c2011-12-02 10:18:17 +0100653
Harald Welte6be350c2011-05-25 13:10:08 +0200654 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
655 union {
656 struct {
657 uint16_t site_id;
658 uint16_t bts_id;
659 uint32_t flags;
Harald Welte8b291802013-03-12 13:57:05 +0100660 uint32_t rsl_ip;
Harald Welte6be350c2011-05-25 13:10:08 +0200661 } ip_access;
662 struct {
663 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200664 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200665 } cclk;
666 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200667 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200668 } rack;
669 struct gsm_envabtse envabtse[4];
670 } bs11;
671 struct {
672 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200673 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200674 struct llist_head conn_groups;
675 } is;
676 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200677 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200678 struct llist_head conn_groups;
679 } con;
680 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200681 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200682 } dp;
683 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200684 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200685 } tf;
686 } rbs2000;
687 struct {
Harald Weltec8755af2011-07-28 00:22:17 +0200688 uint8_t bts_type;
Holger Hans Peter Freyther3e603482012-03-02 14:14:33 +0100689 unsigned int configured:1,
690 skip_reset:1,
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100691 no_loc_rel_cnf:1,
Sipos Csaba56e17662015-02-07 13:27:36 +0100692 bts_reset_timer_cnf,
Holger Hans Peter Freyther3e603482012-03-02 14:14:33 +0100693 did_reset:1,
694 wait_reset:1;
Harald Weltec8755af2011-07-28 00:22:17 +0200695 struct osmo_timer_list reset_timer;
696 } nokia;
Harald Welte6be350c2011-05-25 13:10:08 +0200697 };
698
699 /* Not entirely sure how ip.access specific this is */
700 struct {
bhargava350533c2016-07-21 11:14:34 +0530701 uint8_t supports_egprs_11bit_rach;
Harald Welte6be350c2011-05-25 13:10:08 +0200702 enum bts_gprs_mode mode;
703 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200704 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200705 uint16_t nsei;
706 uint8_t timer[7];
707 } nse;
708 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200709 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200710 uint16_t bvci;
711 uint8_t timer[11];
Harald Welte019f9132012-06-28 08:43:14 +0200712 struct gprs_rlc_cfg rlc_cfg;
Harald Welte6be350c2011-05-25 13:10:08 +0200713 } cell;
714 struct gsm_bts_gprs_nsvc nsvc[2];
715 uint8_t rac;
Andreas Eversberg0c8f9ca2013-03-16 16:31:26 +0100716 uint8_t net_ctrl_ord;
Harald Welte6be350c2011-05-25 13:10:08 +0200717 } gprs;
718
719 /* RACH NM values */
720 int rach_b_thresh;
721 int rach_ldavg_slots;
722
723 /* transceivers */
724 int num_trx;
725 struct llist_head trx_list;
726
Holger Hans Peter Freytherb92a5382014-11-21 10:00:39 +0100727 /* SI related items */
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100728 int force_combined_si;
Holger Hans Peter Freytherb92a5382014-11-21 10:00:39 +0100729 int bcch_change_mark;
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100730
Harald Welte6be350c2011-05-25 13:10:08 +0200731#ifdef ROLE_BSC
732 /* Abis NM queue */
733 struct llist_head abis_queue;
734 int abis_nm_pend;
735
736 struct gsm_network *network;
737
738 /* should the channel allocator allocate channels from high TRX to TRX0,
739 * rather than starting from TRX0 and go upwards? */
740 int chan_alloc_reverse;
741
742 enum neigh_list_manual_mode neigh_list_manual_mode;
743 /* parameters from which we build SYSTEM INFORMATION */
744 struct {
745 struct gsm48_rach_control rach_control;
746 uint8_t ncc_permitted;
747 struct gsm48_cell_sel_par cell_sel_par;
748 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
749 struct gsm48_cell_options cell_options;
750 struct gsm48_control_channel_descr chan_desc;
751 struct bitvec neigh_list;
752 struct bitvec cell_alloc;
753 struct bitvec si5_neigh_list;
Max59a1bf32016-04-15 16:04:46 +0200754 struct osmo_earfcn_si2q si2quater_neigh_list;
Max26679e02016-04-20 15:57:13 +0200755 size_t uarfcn_length; /* index for uarfcn and scramble lists */
Harald Welte6be350c2011-05-25 13:10:08 +0200756 struct {
757 /* bitmask large enough for all possible ARFCN's */
758 uint8_t neigh_list[1024/8];
759 uint8_t cell_alloc[1024/8];
760 /* If the user wants a different neighbor list in SI5 than in SI2 */
761 uint8_t si5_neigh_list[1024/8];
Max59a1bf32016-04-15 16:04:46 +0200762 uint8_t meas_bw_list[MAX_EARFCN_LIST];
763 uint16_t earfcn_list[MAX_EARFCN_LIST];
Max26679e02016-04-20 15:57:13 +0200764 uint16_t uarfcn_list[MAX_EARFCN_LIST];
765 uint16_t scramble_list[MAX_EARFCN_LIST];
Harald Welte6be350c2011-05-25 13:10:08 +0200766 } data;
767 } si_common;
768
769 /* do we use static (user-defined) system information messages? (bitmask) */
770 uint32_t si_mode_static;
Holger Hans Peter Freythere30d40d2012-07-20 10:27:31 +0200771
772 /* exclude the BTS from the global RF Lock handling */
773 int excl_from_rf_lock;
Andreas Eversberga83d5112013-12-07 18:32:28 +0100774
775 /* supported codecs beside FR */
776 struct bts_codec_conf codec;
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100777
778 /* BTS dependencies bit field */
779 uint32_t depends_on[256/(8*4)];
Andreas Eversberg73266522014-01-19 11:47:44 +0100780
781 /* full and half rate multirate config */
782 struct amr_multirate_conf mr_full;
783 struct amr_multirate_conf mr_half;
784
Harald Welte6be350c2011-05-25 13:10:08 +0200785#endif /* ROLE_BSC */
Harald Welte978714d2011-06-06 18:31:20 +0200786 void *role;
Harald Welte6be350c2011-05-25 13:10:08 +0200787};
788
789
Harald Welte3300c012011-06-05 13:31:33 +0200790struct gsm_bts *gsm_bts_alloc(void *talloc_ctx);
Harald Welte1449c9f2014-08-24 09:50:10 +0200791struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Harald Welte6be350c2011-05-25 13:10:08 +0200792
Harald Welte1449c9f2014-08-24 09:50:10 +0200793struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
Harald Welte4f8ad532011-09-19 14:21:51 +0200794struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
Harald Welte6be350c2011-05-25 13:10:08 +0200795
Harald Welte4ab9d7c2012-08-17 12:42:06 +0200796
Neels Hofmeyr17a6bab2016-07-23 16:14:06 +0200797const struct value_string gsm_pchant_names[13];
798const struct value_string gsm_pchant_descs[13];
Harald Welte6be350c2011-05-25 13:10:08 +0200799const char *gsm_pchan_name(enum gsm_phys_chan_config c);
800enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
801const char *gsm_lchant_name(enum gsm_chan_t c);
802const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte4f8ad532011-09-19 14:21:51 +0200803char *gsm_trx_name(const struct gsm_bts_trx *trx);
804char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr34b8b5b2016-07-16 23:59:32 +0200805char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
Harald Weltec696cc22015-12-05 16:19:21 +0100806char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
Harald Welte6be350c2011-05-25 13:10:08 +0200807const char *gsm_lchans_name(enum gsm_lchan_state s);
808
Harald Weltec696cc22015-12-05 16:19:21 +0100809static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
810{
811 return lchan->name;
812}
Harald Welte6be350c2011-05-25 13:10:08 +0200813
Harald Welteb7849982011-06-29 16:49:03 +0200814void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
815
Harald Welte978714d2011-06-06 18:31:20 +0200816struct gsm_abis_mo *
817gsm_objclass2mo(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200818 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200819
820struct gsm_nm_state *
821gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200822 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200823void *
824gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200825 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200826
Harald Welteb7849982011-06-29 16:49:03 +0200827/* reset the state of all MO in the BTS */
828void gsm_bts_mo_reset(struct gsm_bts *bts);
829
Neels Hofmeyrd3841102016-07-18 23:43:44 +0200830uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
831 uint8_t ts_nr, uint8_t lchan_nr);
Harald Weltef6093a42011-06-25 10:02:33 +0200832uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
Neels Hofmeyrd3841102016-07-18 23:43:44 +0200833uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
834 enum gsm_phys_chan_config as_pchan);
Harald Weltef6093a42011-06-25 10:02:33 +0200835
Harald Welte142d12d2014-12-29 17:47:08 +0100836/* return the gsm_lchan for the CBCH (if it exists at all) */
837struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
838
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200839/*
840 * help with parsing regexps
841 */
842int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
843 int argc, const char **argv) __attribute__ ((warn_unused_result));
844
Harald Welte1fe24122014-01-19 17:18:21 +0100845static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
846{
847 if (ts->tsc != -1)
848 return ts->tsc;
849 else
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100850 return ts->trx->bts->bsic & 7;
Harald Welte1fe24122014-01-19 17:18:21 +0100851}
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200852
Neels Hofmeyr74585722016-07-23 17:38:22 +0200853struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
854 int *rc);
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200855
Harald Welte6be350c2011-05-25 13:10:08 +0200856#endif