blob: 1b7382d5c149aa550b13c3fa0153dd91acc598a9 [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>
Harald Welte6be350c2011-05-25 13:10:08 +020017
18#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)
108
109/* is the data link established? who established it? */
110#define LCHAN_SAPI_UNUSED 0
111#define LCHAN_SAPI_MS 1
112#define LCHAN_SAPI_NET 2
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100113#define LCHAN_SAPI_REL 3
Harald Welte6be350c2011-05-25 13:10:08 +0200114
115/* state of a logical channel */
116enum gsm_lchan_state {
117 LCHAN_S_NONE, /* channel is not active */
Holger Hans Peter Freytherded02682012-01-15 00:02:17 +0100118 LCHAN_S_ACT_REQ, /* channel activation requested */
Harald Welte6be350c2011-05-25 13:10:08 +0200119 LCHAN_S_ACTIVE, /* channel is active and operational */
120 LCHAN_S_REL_REQ, /* channel release has been requested */
121 LCHAN_S_REL_ERR, /* channel is in an error state */
Holger Hans Peter Freyther638da512012-12-06 19:25:06 +0100122 LCHAN_S_BROKEN, /* channel is somehow unusable */
Harald Welte6be350c2011-05-25 13:10:08 +0200123 LCHAN_S_INACTIVE, /* channel is set inactive */
124};
125
Harald Weltec7921c92011-06-29 10:38:34 +0200126/* BTS ONLY */
127#define MAX_NUM_UL_MEAS 104
128#define LC_UL_M_F_L1_VALID (1 << 0)
129#define LC_UL_M_F_RES_VALID (1 << 1)
130
131struct bts_ul_meas {
132 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
133 uint16_t ber10k;
134 /* timing advance offset (in quarter bits) */
135 int16_t ta_offs_qbits;
136 /* C/I ratio in dB */
137 float c_i;
138 /* flags */
139 uint8_t is_sub:1;
140 /* RSSI in dBm * -1 */
141 uint8_t inv_rssi;
142};
Harald Weltef3b59322011-09-06 22:14:43 +0200143
Andreas Eversberga83d5112013-12-07 18:32:28 +0100144struct bts_codec_conf {
145 uint8_t hr;
146 uint8_t efr;
147 uint8_t amr;
148};
149
Harald Weltef3b59322011-09-06 22:14:43 +0200150struct amr_mode {
151 uint8_t mode;
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200152 uint8_t threshold;
153 uint8_t hysteresis;
Harald Weltef3b59322011-09-06 22:14:43 +0200154};
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200155
Harald Weltef3b59322011-09-06 22:14:43 +0200156struct amr_multirate_conf {
157 uint8_t gsm48_ie[2];
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200158 struct amr_mode ms_mode[4];
159 struct amr_mode bts_mode[4];
Harald Weltef3b59322011-09-06 22:14:43 +0200160 uint8_t num_modes;
161};
Harald Weltec7921c92011-06-29 10:38:34 +0200162/* /BTS ONLY */
163
Harald Weltee4227982012-08-24 15:33:56 +0200164enum lchan_csd_mode {
165 LCHAN_CSD_M_NT,
166 LCHAN_CSD_M_T_1200_75,
167 LCHAN_CSD_M_T_600,
168 LCHAN_CSD_M_T_1200,
169 LCHAN_CSD_M_T_2400,
170 LCHAN_CSD_M_T_9600,
171 LCHAN_CSD_M_T_14400,
172 LCHAN_CSD_M_T_29000,
173 LCHAN_CSD_M_T_32000,
174};
175
Daniel Willmann324c8052012-12-29 12:32:30 +0100176/* State of the SAPIs in the lchan */
177enum lchan_sapi_state {
178 LCHAN_SAPI_S_NONE,
179 LCHAN_SAPI_S_REQ,
180 LCHAN_SAPI_S_ASSIGNED,
181 LCHAN_SAPI_S_REL,
182 LCHAN_SAPI_S_ERROR,
183};
184
Harald Welte6be350c2011-05-25 13:10:08 +0200185struct gsm_lchan {
186 /* The TS that we're part of */
187 struct gsm_bts_trx_ts *ts;
188 /* The logical subslot number in the TS */
189 uint8_t nr;
190 /* The logical channel type */
191 enum gsm_chan_t type;
192 /* RSL channel mode */
193 enum rsl_cmod_spd rsl_cmode;
194 /* If TCH, traffic channel mode */
195 enum gsm48_chan_mode tch_mode;
Harald Weltee4227982012-08-24 15:33:56 +0200196 enum lchan_csd_mode csd_mode;
Harald Welte6be350c2011-05-25 13:10:08 +0200197 /* State */
198 enum gsm_lchan_state state;
Holger Hans Peter Freyther454140e2014-12-28 12:08:28 +0100199 const char *broken_reason;
Harald Welte6be350c2011-05-25 13:10:08 +0200200 /* Power levels for MS and BTS */
201 uint8_t bs_power;
202 uint8_t ms_power;
203 /* Encryption information */
204 struct {
205 uint8_t alg_id;
206 uint8_t key_len;
207 uint8_t key[MAX_A5_KEY_LEN];
208 } encr;
209
210 /* AMR bits */
Andreas Eversberg73266522014-01-19 11:47:44 +0100211 uint8_t mr_ms_lv[7];
212 uint8_t mr_bts_lv[7];
Harald Welte6be350c2011-05-25 13:10:08 +0200213
214 /* Established data link layer services */
215 uint8_t sapis[8];
Holger Hans Peter Freytherb9b828b2013-01-01 19:20:28 +0100216 int sacch_deact;
Holger Hans Peter Freytherdfcfe652011-12-27 20:49:53 +0100217
Harald Welte6be350c2011-05-25 13:10:08 +0200218 struct {
219 uint32_t bound_ip;
220 uint32_t connect_ip;
221 uint16_t bound_port;
222 uint16_t connect_port;
223 uint16_t conn_id;
224 uint8_t rtp_payload;
225 uint8_t rtp_payload2;
226 uint8_t speech_mode;
Harald Welte135a6bd2011-09-04 13:53:26 +0200227#ifdef ROLE_BSC
Harald Welte6be350c2011-05-25 13:10:08 +0200228 struct rtp_socket *rtp_socket;
Harald Welte135a6bd2011-09-04 13:53:26 +0200229#else
230 struct osmo_rtp_socket *rtp_socket;
231#endif
Harald Welte6be350c2011-05-25 13:10:08 +0200232 } abis_ip;
233
Harald Welte2c1ae472011-06-26 14:13:37 +0200234 uint8_t rqd_ta;
235
Harald Welte6be350c2011-05-25 13:10:08 +0200236#ifdef ROLE_BSC
237 struct osmo_timer_list T3101;
Holger Hans Peter Freytherb3489392011-12-28 16:21:05 +0100238 struct osmo_timer_list T3109;
Harald Welte6be350c2011-05-25 13:10:08 +0200239 struct osmo_timer_list T3111;
240 struct osmo_timer_list error_timer;
Harald Weltee8bd9e82011-08-10 23:26:33 +0200241 struct osmo_timer_list act_timer;
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100242 struct osmo_timer_list rel_work;
Holger Hans Peter Freyther638da512012-12-06 19:25:06 +0100243 uint8_t error_cause;
Harald Welte6be350c2011-05-25 13:10:08 +0200244
245 /* table of neighbor cell measurements */
246 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
247
248 /* cache of last measurement reports on this lchan */
249 struct gsm_meas_rep meas_rep[6];
250 int meas_rep_idx;
251
252 /* GSM Random Access data */
253 struct gsm48_req_ref *rqd_ref;
Harald Welte6be350c2011-05-25 13:10:08 +0200254
255 struct gsm_subscriber_connection *conn;
Harald Weltef6093a42011-06-25 10:02:33 +0200256#else
Daniel Willmann324c8052012-12-29 12:32:30 +0100257 /* Number of different GsmL1_Sapi_t used in osmo_bts_sysmo is 23.
258 * Currently we don't share these headers so this is a magic number. */
Holger Hans Peter Freyther30156e12013-04-05 18:41:45 +0200259 struct llist_head sapi_cmds;
Daniel Willmann324c8052012-12-29 12:32:30 +0100260 uint8_t sapis_dl[23];
261 uint8_t sapis_ul[23];
Harald Weltef6093a42011-06-25 10:02:33 +0200262 struct lapdm_channel lapdm_ch;
Harald Welte135a6bd2011-09-04 13:53:26 +0200263 struct llist_head dl_tch_queue;
Harald Welte2c1ae472011-06-26 14:13:37 +0200264 struct {
265 /* bitmask of all SI that are present/valid in si_buf */
266 uint32_t valid;
267 uint32_t last;
268 /* buffers where we put the pre-computed SI */
269 sysinfo_buf_t buf[_MAX_SYSINFO_TYPE];
270 } si;
Harald Weltec7921c92011-06-29 10:38:34 +0200271 struct {
272 uint8_t flags;
273 /* RSL measurment result number, 0 at lchan_act */
274 uint8_t res_nr;
275 /* current Tx power level of the BTS */
276 uint8_t bts_tx_pwr;
277 /* number of measurements stored in array below */
278 uint8_t num_ul_meas;
279 struct bts_ul_meas uplink[MAX_NUM_UL_MEAS];
280 /* last L1 header from the MS */
281 uint8_t l1_info[2];
Harald Welte7ff4f0e2013-03-07 18:38:09 +0000282 struct gsm_meas_rep_unidir ul_res;
Harald Weltec7921c92011-06-29 10:38:34 +0200283 } meas;
Harald Weltef3b59322011-09-06 22:14:43 +0200284 struct {
285 struct amr_multirate_conf amr_mr;
Harald Welte43290992011-09-07 12:41:38 +0200286 struct {
287 uint8_t buf[16];
288 uint8_t len;
289 } last_sid;
Holger Hans Peter Freyther922ef5d2014-07-24 21:05:32 +0200290 uint8_t last_cmr;
Harald Weltef3b59322011-09-06 22:14:43 +0200291 } tch;
Harald Welte5d52c972012-04-08 20:23:28 +0200292 /* BTS-side ciphering state (rx only, bi-directional, ...) */
293 uint8_t ciph_state;
Holger Hans Peter Freyther2c6b59c2014-08-09 09:43:53 +0200294 uint8_t ciph_ns;
Harald Welte46cb8512012-04-19 23:13:35 +0200295 uint8_t loopback;
Harald Welte704cb862012-06-16 14:57:08 +0800296 struct {
297 uint8_t active;
298 uint8_t ref;
299 /* T3105: PHYS INF retransmission */
300 struct osmo_timer_list t3105;
301 /* counts up to Ny1 */
302 unsigned int phys_info_count;
303 } ho;
Andreas Eversberg1af682a2013-02-20 16:06:20 +0100304 /* S counter for link loss */
305 int s;
Holger Hans Peter Freytherfc7a75f2013-10-25 18:58:30 +0200306 /* Kind of the release/activation. E.g. RSL or PCU */
307 int rel_act_kind;
Holger Hans Peter Freytherf6f86b02015-02-05 22:25:03 +0100308
309 /* power handling */
310 struct {
311 uint8_t current;
312 uint8_t fixed;
313 } ms_power_ctrl;
Harald Welte6be350c2011-05-25 13:10:08 +0200314#endif
315};
316
Harald Welte6be350c2011-05-25 13:10:08 +0200317#define TS_F_PDCH_MODE 0x1000
318/* One Timeslot in a TRX */
319struct gsm_bts_trx_ts {
320 struct gsm_bts_trx *trx;
321 /* number of this timeslot at the TRX */
322 uint8_t nr;
323
324 enum gsm_phys_chan_config pchan;
325
326 unsigned int flags;
Harald Welted64c0bc2011-05-30 12:07:53 +0200327 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200328 struct tlv_parsed nm_attr;
329 uint8_t nm_chan_comb;
Harald Welte135a6482011-05-30 12:09:13 +0200330 int tsc; /* -1 == use BTS TSC */
Harald Welte6be350c2011-05-25 13:10:08 +0200331
332 struct {
333 /* Parameters below are configured by VTY */
334 int enabled;
335 uint8_t maio;
336 uint8_t hsn;
337 struct bitvec arfcns;
338 uint8_t arfcns_data[1024/8];
339 /* This is the pre-computed MA for channel assignments */
340 struct bitvec ma;
341 uint8_t ma_len; /* part of ma_data that is used */
342 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
343 } hopping;
344
345 /* To which E1 subslot are we connected */
346 struct gsm_e1_subslot e1_link;
347
348 struct gsm_lchan lchan[TS_MAX_LCHAN];
349};
350
351/* One TRX in a BTS */
352struct gsm_bts_trx {
353 /* list header in bts->trx_list */
354 struct llist_head list;
355
356 struct gsm_bts *bts;
357 /* number of this TRX in the BTS */
358 uint8_t nr;
359 /* human readable name / description */
360 char *description;
361 /* how do we talk RSL with this TRX? */
362 struct gsm_e1_subslot rsl_e1_link;
363 uint8_t rsl_tei;
364 struct e1inp_sign_link *rsl_link;
Holger Hans Peter Freythercaa98d52013-10-06 15:52:14 +0200365
Harald Welte6be350c2011-05-25 13:10:08 +0200366 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
367 struct e1inp_sign_link *oml_link;
368
Harald Welted64c0bc2011-05-30 12:07:53 +0200369 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200370 struct tlv_parsed nm_attr;
371 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200372 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200373 } bb_transc;
374
375 uint16_t arfcn;
376 int nominal_power; /* in dBm */
377 unsigned int max_power_red; /* in actual dB */
Holger Hans Peter Freyther9b625802014-07-30 18:20:51 +0200378
379#ifndef ROLE_BSC
Harald Welte101c5c22014-08-22 16:12:03 +0200380 struct trx_power_params power_params;
Holger Hans Peter Freytherf6f86b02015-02-05 22:25:03 +0100381 int ms_power_control;
Harald Welte6be350c2011-05-25 13:10:08 +0200382
Harald Welted134cc72011-06-07 00:12:53 +0200383 struct {
384 void *l1h;
385 } role_bts;
Holger Hans Peter Freyther9b625802014-07-30 18:20:51 +0200386#endif
Harald Welted134cc72011-06-07 00:12:53 +0200387
Harald Welte6be350c2011-05-25 13:10:08 +0200388 union {
389 struct {
390 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200391 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200392 } bbsig;
393 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200394 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200395 } pa;
396 } bs11;
397 struct {
398 unsigned int test_state;
399 uint8_t test_nr;
400 struct rxlev_stats rxlev_stat;
401 } ipaccess;
402 };
403 struct gsm_bts_trx_ts ts[TRX_NR_TS];
404};
405
406#define GSM_BTS_SI(bts, i) (void *)(bts->si_buf[i])
407
408enum gsm_bts_type {
409 GSM_BTS_TYPE_UNKNOWN,
410 GSM_BTS_TYPE_BS11,
411 GSM_BTS_TYPE_NANOBTS,
412 GSM_BTS_TYPE_RBS2000,
Dieter Spaar16646022011-07-28 00:01:50 +0200413 GSM_BTS_TYPE_NOKIA_SITE,
Harald Weltef383aa12012-07-02 19:51:55 +0200414 GSM_BTS_TYPE_OSMO_SYSMO,
Harald Weltee555c2b2012-08-17 13:02:12 +0200415 _NUM_GSM_BTS_TYPE
Harald Welte6be350c2011-05-25 13:10:08 +0200416};
417
418struct vty;
419
420struct gsm_bts_model {
421 struct llist_head list;
422
423 enum gsm_bts_type type;
424 const char *name;
425
426 bool started;
427 int (*start)(struct gsm_network *net);
428 int (*oml_rcvmsg)(struct msgb *msg);
429
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200430 void (*e1line_bind_ops)(struct e1inp_line *line);
431
Harald Welte6be350c2011-05-25 13:10:08 +0200432 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
433 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
434 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
435
436 struct tlv_definition nm_att_tlvdef;
437
438 struct bitvec features;
439 uint8_t _features_data[128/8];
440};
441
442enum gsm_bts_features {
443 BTS_FEAT_HSCSD,
444 BTS_FEAT_GPRS,
445 BTS_FEAT_EGPRS,
446 BTS_FEAT_ECSD,
447 BTS_FEAT_HOPPING,
Harald Welte903aaea2014-01-19 17:10:50 +0100448 BTS_FEAT_MULTI_TSC,
Harald Welte6be350c2011-05-25 13:10:08 +0200449};
450
451/*
452 * This keeps track of the paging status of one BTS. It
453 * includes a number of pending requests, a back pointer
454 * to the gsm_bts, a timer and some more state.
455 */
456struct gsm_bts_paging_state {
457 /* pending requests */
458 struct llist_head pending_requests;
459 struct gsm_bts *bts;
460
461 struct osmo_timer_list work_timer;
462 struct osmo_timer_list credit_timer;
463
464 /* free chans needed */
465 int free_chans_need;
466
467 /* load */
468 uint16_t available_slots;
469};
470
471struct gsm_envabtse {
Harald Welted64c0bc2011-05-30 12:07:53 +0200472 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200473};
474
475struct gsm_bts_gprs_nsvc {
476 struct gsm_bts *bts;
477 /* data read via VTY config file, to configure the BTS
478 * via OML from BSC */
479 int id;
480 uint16_t nsvci;
481 uint16_t local_port; /* on the BTS */
482 uint16_t remote_port; /* on the SGSN */
483 uint32_t remote_ip; /* on the SGSN */
484
Harald Welted64c0bc2011-05-30 12:07:53 +0200485 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200486};
487
Harald Welte019f9132012-06-28 08:43:14 +0200488enum gprs_rlc_par {
489 RLC_T3142,
490 RLC_T3169,
491 RLC_T3191,
492 RLC_T3193,
493 RLC_T3195,
494 RLC_N3101,
495 RLC_N3103,
496 RLC_N3105,
497 CV_COUNTDOWN,
498 T_DL_TBF_EXT, /* ms */
499 T_UL_TBF_EXT, /* ms */
500 _NUM_RLC_PAR
501};
502
503enum gprs_cs {
504 GPRS_CS1,
505 GPRS_CS2,
506 GPRS_CS3,
507 GPRS_CS4,
508 GPRS_MCS1,
509 GPRS_MCS2,
510 GPRS_MCS3,
511 GPRS_MCS4,
512 GPRS_MCS5,
513 GPRS_MCS6,
514 GPRS_MCS7,
515 GPRS_MCS8,
516 GPRS_MCS9,
517 _NUM_GRPS_CS
518};
519
520struct gprs_rlc_cfg {
521 uint16_t parameter[_NUM_RLC_PAR];
522 struct {
523 uint16_t repeat_time; /* ms */
524 uint8_t repeat_count;
525 } paging;
526 uint32_t cs_mask; /* bitmask of gprs_cs */
527 uint8_t initial_cs;
528 uint8_t initial_mcs;
529};
530
531
Harald Welte6be350c2011-05-25 13:10:08 +0200532enum neigh_list_manual_mode {
533 NL_MODE_AUTOMATIC = 0,
534 NL_MODE_MANUAL = 1,
535 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
536};
537
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200538enum bts_loc_fix {
539 BTS_LOC_FIX_INVALID = 0,
540 BTS_LOC_FIX_2D = 1,
541 BTS_LOC_FIX_3D = 2,
542};
543
Daniel Willmann7d109832012-05-14 18:43:23 +0200544extern const struct value_string bts_loc_fix_names[];
545
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200546struct bts_location {
547 struct llist_head list;
548 time_t tstamp;
549 enum bts_loc_fix valid;
550 double lat;
551 double lon;
552 double height;
553};
554
Harald Welte6be350c2011-05-25 13:10:08 +0200555/* One BTS */
556struct gsm_bts {
557 /* list header in net->bts_list */
558 struct llist_head list;
559
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200560 /* Geographical location of the BTS */
561 struct llist_head loc_list;
562
Harald Welte6be350c2011-05-25 13:10:08 +0200563 /* number of ths BTS in network */
564 uint8_t nr;
565 /* human readable name / description */
566 char *description;
567 /* Cell Identity */
568 uint16_t cell_identity;
569 /* location area code of this BTS */
570 uint16_t location_area_code;
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100571 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
572 * which is used as TSC for the CCCH */
Harald Welte6be350c2011-05-25 13:10:08 +0200573 uint8_t bsic;
574 /* type of BTS */
575 enum gsm_bts_type type;
576 struct gsm_bts_model *model;
577 enum gsm_band band;
578 /* maximum Tx power that the MS is permitted to use in this cell */
579 int ms_max_power;
580
581 /* how do we talk OML with this TRX? */
582 struct gsm_e1_subslot oml_e1_link;
583 uint8_t oml_tei;
584 struct e1inp_sign_link *oml_link;
585
586 /* Abis network management O&M handle */
587 struct abis_nm_h *nmh;
Harald Welted64c0bc2011-05-30 12:07:53 +0200588
589 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200590
591 /* number of this BTS on given E1 link */
592 uint8_t bts_nr;
593
594 /* paging state and control */
595 struct gsm_bts_paging_state paging;
596
597 /* CCCH is on C0 */
598 struct gsm_bts_trx *c0;
599
600 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200601 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200602 } site_mgr;
603
604 /* bitmask of all SI that are present/valid in si_buf */
605 uint32_t si_valid;
606 /* buffers where we put the pre-computed SI */
607 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE];
608
Gus Bourg1c5dd2c2011-12-02 10:18:17 +0100609 /* TimeZone hours, mins, and bts specific */
Harald Welte45f91712012-07-08 16:48:11 +0200610 struct {
611 int hr;
612 int mn;
613 int override;
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200614 int dst;
Harald Welte45f91712012-07-08 16:48:11 +0200615 } tz;
Gus Bourg1c5dd2c2011-12-02 10:18:17 +0100616
Harald Welte6be350c2011-05-25 13:10:08 +0200617 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
618 union {
619 struct {
620 uint16_t site_id;
621 uint16_t bts_id;
622 uint32_t flags;
Harald Welte8b291802013-03-12 13:57:05 +0100623 uint32_t rsl_ip;
Harald Welte6be350c2011-05-25 13:10:08 +0200624 } ip_access;
625 struct {
626 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200627 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200628 } cclk;
629 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200630 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200631 } rack;
632 struct gsm_envabtse envabtse[4];
633 } bs11;
634 struct {
635 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200636 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200637 struct llist_head conn_groups;
638 } is;
639 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200640 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200641 struct llist_head conn_groups;
642 } con;
643 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200644 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200645 } dp;
646 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200647 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200648 } tf;
649 } rbs2000;
650 struct {
Harald Weltec8755af2011-07-28 00:22:17 +0200651 uint8_t bts_type;
Holger Hans Peter Freyther3e603482012-03-02 14:14:33 +0100652 unsigned int configured:1,
653 skip_reset:1,
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100654 no_loc_rel_cnf:1,
Sipos Csaba56e17662015-02-07 13:27:36 +0100655 bts_reset_timer_cnf,
Holger Hans Peter Freyther3e603482012-03-02 14:14:33 +0100656 did_reset:1,
657 wait_reset:1;
Harald Weltec8755af2011-07-28 00:22:17 +0200658 struct osmo_timer_list reset_timer;
659 } nokia;
Harald Welte6be350c2011-05-25 13:10:08 +0200660 };
661
662 /* Not entirely sure how ip.access specific this is */
663 struct {
664 enum bts_gprs_mode mode;
665 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200666 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200667 uint16_t nsei;
668 uint8_t timer[7];
669 } nse;
670 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200671 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200672 uint16_t bvci;
673 uint8_t timer[11];
Harald Welte019f9132012-06-28 08:43:14 +0200674 struct gprs_rlc_cfg rlc_cfg;
Harald Welte6be350c2011-05-25 13:10:08 +0200675 } cell;
676 struct gsm_bts_gprs_nsvc nsvc[2];
677 uint8_t rac;
Andreas Eversberg0c8f9ca2013-03-16 16:31:26 +0100678 uint8_t net_ctrl_ord;
Harald Welte6be350c2011-05-25 13:10:08 +0200679 } gprs;
680
681 /* RACH NM values */
682 int rach_b_thresh;
683 int rach_ldavg_slots;
684
685 /* transceivers */
686 int num_trx;
687 struct llist_head trx_list;
688
Holger Hans Peter Freytherb92a5382014-11-21 10:00:39 +0100689 /* SI related items */
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100690 int force_combined_si;
Holger Hans Peter Freytherb92a5382014-11-21 10:00:39 +0100691 int bcch_change_mark;
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100692
Harald Welte6be350c2011-05-25 13:10:08 +0200693#ifdef ROLE_BSC
694 /* Abis NM queue */
695 struct llist_head abis_queue;
696 int abis_nm_pend;
697
698 struct gsm_network *network;
699
700 /* should the channel allocator allocate channels from high TRX to TRX0,
701 * rather than starting from TRX0 and go upwards? */
702 int chan_alloc_reverse;
703
704 enum neigh_list_manual_mode neigh_list_manual_mode;
705 /* parameters from which we build SYSTEM INFORMATION */
706 struct {
707 struct gsm48_rach_control rach_control;
708 uint8_t ncc_permitted;
709 struct gsm48_cell_sel_par cell_sel_par;
710 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
711 struct gsm48_cell_options cell_options;
712 struct gsm48_control_channel_descr chan_desc;
713 struct bitvec neigh_list;
714 struct bitvec cell_alloc;
715 struct bitvec si5_neigh_list;
716 struct {
717 /* bitmask large enough for all possible ARFCN's */
718 uint8_t neigh_list[1024/8];
719 uint8_t cell_alloc[1024/8];
720 /* If the user wants a different neighbor list in SI5 than in SI2 */
721 uint8_t si5_neigh_list[1024/8];
722 } data;
723 } si_common;
724
725 /* do we use static (user-defined) system information messages? (bitmask) */
726 uint32_t si_mode_static;
Holger Hans Peter Freythere30d40d2012-07-20 10:27:31 +0200727
728 /* exclude the BTS from the global RF Lock handling */
729 int excl_from_rf_lock;
Andreas Eversberga83d5112013-12-07 18:32:28 +0100730
731 /* supported codecs beside FR */
732 struct bts_codec_conf codec;
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100733
734 /* BTS dependencies bit field */
735 uint32_t depends_on[256/(8*4)];
Andreas Eversberg73266522014-01-19 11:47:44 +0100736
737 /* full and half rate multirate config */
738 struct amr_multirate_conf mr_full;
739 struct amr_multirate_conf mr_half;
740
Harald Welte6be350c2011-05-25 13:10:08 +0200741#endif /* ROLE_BSC */
Harald Welte978714d2011-06-06 18:31:20 +0200742 void *role;
Harald Welte6be350c2011-05-25 13:10:08 +0200743};
744
745
Harald Welte3300c012011-06-05 13:31:33 +0200746struct gsm_bts *gsm_bts_alloc(void *talloc_ctx);
Harald Welte1449c9f2014-08-24 09:50:10 +0200747struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Harald Welte6be350c2011-05-25 13:10:08 +0200748
Harald Welte1449c9f2014-08-24 09:50:10 +0200749struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
Harald Welte4f8ad532011-09-19 14:21:51 +0200750struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
Harald Welte6be350c2011-05-25 13:10:08 +0200751
Harald Welte4ab9d7c2012-08-17 12:42:06 +0200752
Harald Welte30f1f372014-12-28 15:00:45 +0100753const struct value_string gsm_pchant_names[12];
754const struct value_string gsm_pchant_descs[12];
755const struct value_string gsm_lchant_names[8];
Harald Welte6be350c2011-05-25 13:10:08 +0200756const char *gsm_pchan_name(enum gsm_phys_chan_config c);
757enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
758const char *gsm_lchant_name(enum gsm_chan_t c);
759const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte4f8ad532011-09-19 14:21:51 +0200760char *gsm_trx_name(const struct gsm_bts_trx *trx);
761char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
762char *gsm_lchan_name(const struct gsm_lchan *lchan);
Harald Welte6be350c2011-05-25 13:10:08 +0200763const char *gsm_lchans_name(enum gsm_lchan_state s);
764
Harald Welte6be350c2011-05-25 13:10:08 +0200765
Harald Welteb7849982011-06-29 16:49:03 +0200766void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
767
Harald Welte978714d2011-06-06 18:31:20 +0200768struct gsm_abis_mo *
769gsm_objclass2mo(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200770 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200771
772struct gsm_nm_state *
773gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200774 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200775void *
776gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200777 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200778
Harald Welteb7849982011-06-29 16:49:03 +0200779/* reset the state of all MO in the BTS */
780void gsm_bts_mo_reset(struct gsm_bts *bts);
781
Harald Weltef6093a42011-06-25 10:02:33 +0200782uint8_t gsm_ts2chan_nr(const struct gsm_bts_trx_ts *ts, uint8_t lchan_nr);
783uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
784
Harald Welte142d12d2014-12-29 17:47:08 +0100785/* return the gsm_lchan for the CBCH (if it exists at all) */
786struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
787
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200788/*
789 * help with parsing regexps
790 */
791int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
792 int argc, const char **argv) __attribute__ ((warn_unused_result));
793
Harald Welte1fe24122014-01-19 17:18:21 +0100794static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
795{
796 if (ts->tsc != -1)
797 return ts->tsc;
798 else
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100799 return ts->trx->bts->bsic & 7;
Harald Welte1fe24122014-01-19 17:18:21 +0100800}
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200801
802
Harald Welte6be350c2011-05-25 13:10:08 +0200803#endif