blob: 86bf557ad927f8f2e4bda3cf5f5aaba1e414527e [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
53#define HARDCODED_TSC 7
54#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
55
56/* for multi-drop config */
57#define HARDCODED_BTS0_TS 1
58#define HARDCODED_BTS1_TS 6
59#define HARDCODED_BTS2_TS 11
60
Harald Welte6be350c2011-05-25 13:10:08 +020061enum gsm_hooks {
62 GSM_HOOK_NM_SWLOAD,
63 GSM_HOOK_RR_PAGING,
64 GSM_HOOK_RR_SECURITY,
65};
66
67enum gsm_paging_event {
68 GSM_PAGING_SUCCEEDED,
69 GSM_PAGING_EXPIRED,
70 GSM_PAGING_OOM,
71 GSM_PAGING_BUSY,
72};
73
74enum bts_gprs_mode {
75 BTS_GPRS_NONE = 0,
76 BTS_GPRS_GPRS = 1,
77 BTS_GPRS_EGPRS = 2,
78};
79
80struct gsm_lchan;
81struct gsm_subscriber;
82struct gsm_mncc;
Harald Welte135a6bd2011-09-04 13:53:26 +020083struct osmo_rtp_socket;
Harald Welte6be350c2011-05-25 13:10:08 +020084struct rtp_socket;
85struct bsc_api;
86
87/* Network Management State */
88struct gsm_nm_state {
89 uint8_t operational;
90 uint8_t administrative;
91 uint8_t availability;
92};
93
Harald Welted64c0bc2011-05-30 12:07:53 +020094struct gsm_abis_mo {
Harald Welte3300c012011-06-05 13:31:33 +020095 uint8_t obj_class;
Holger Hans Peter Freyther49976f42013-11-05 16:06:17 +010096 uint8_t procedure_pending;
Harald Welte3300c012011-06-05 13:31:33 +020097 struct abis_om_obj_inst obj_inst;
Harald Welted64c0bc2011-05-30 12:07:53 +020098 const char *name;
99 struct gsm_nm_state nm_state;
100 struct tlv_parsed *nm_attr;
Harald Welte32bc1162011-06-06 18:58:48 +0200101 struct gsm_bts *bts;
Harald Welted64c0bc2011-05-30 12:07:53 +0200102};
103
Harald Welte6be350c2011-05-25 13:10:08 +0200104#define MAX_A5_KEY_LEN (128/8)
105#define A38_XOR_MIN_KEY_LEN 12
106#define A38_XOR_MAX_KEY_LEN 16
107#define A38_COMP128_KEY_LEN 16
108#define RSL_ENC_ALG_A5(x) (x+1)
109
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;
153 uint8_t threshold;
154 uint8_t hysteresis;
155};
156struct amr_multirate_conf {
157 uint8_t gsm48_ie[2];
158 struct amr_mode mode[4];
159 uint8_t num_modes;
160};
Harald Weltec7921c92011-06-29 10:38:34 +0200161/* /BTS ONLY */
162
Harald Weltee4227982012-08-24 15:33:56 +0200163enum lchan_csd_mode {
164 LCHAN_CSD_M_NT,
165 LCHAN_CSD_M_T_1200_75,
166 LCHAN_CSD_M_T_600,
167 LCHAN_CSD_M_T_1200,
168 LCHAN_CSD_M_T_2400,
169 LCHAN_CSD_M_T_9600,
170 LCHAN_CSD_M_T_14400,
171 LCHAN_CSD_M_T_29000,
172 LCHAN_CSD_M_T_32000,
173};
174
Daniel Willmann324c8052012-12-29 12:32:30 +0100175/* State of the SAPIs in the lchan */
176enum lchan_sapi_state {
177 LCHAN_SAPI_S_NONE,
178 LCHAN_SAPI_S_REQ,
179 LCHAN_SAPI_S_ASSIGNED,
180 LCHAN_SAPI_S_REL,
181 LCHAN_SAPI_S_ERROR,
182};
183
Harald Welte6be350c2011-05-25 13:10:08 +0200184struct gsm_lchan {
185 /* The TS that we're part of */
186 struct gsm_bts_trx_ts *ts;
187 /* The logical subslot number in the TS */
188 uint8_t nr;
189 /* The logical channel type */
190 enum gsm_chan_t type;
191 /* RSL channel mode */
192 enum rsl_cmod_spd rsl_cmode;
193 /* If TCH, traffic channel mode */
194 enum gsm48_chan_mode tch_mode;
Harald Weltee4227982012-08-24 15:33:56 +0200195 enum lchan_csd_mode csd_mode;
Harald Welte6be350c2011-05-25 13:10:08 +0200196 /* State */
197 enum gsm_lchan_state state;
Holger Hans Peter Freyther454140e2014-12-28 12:08:28 +0100198 const char *broken_reason;
Harald Welte6be350c2011-05-25 13:10:08 +0200199 /* Power levels for MS and BTS */
200 uint8_t bs_power;
201 uint8_t ms_power;
202 /* Encryption information */
203 struct {
204 uint8_t alg_id;
205 uint8_t key_len;
206 uint8_t key[MAX_A5_KEY_LEN];
207 } encr;
208
209 /* AMR bits */
210 struct gsm48_multi_rate_conf mr_conf;
211
212 /* Established data link layer services */
213 uint8_t sapis[8];
Holger Hans Peter Freytherb9b828b2013-01-01 19:20:28 +0100214 int sacch_deact;
Holger Hans Peter Freytherdfcfe652011-12-27 20:49:53 +0100215
Harald Welte6be350c2011-05-25 13:10:08 +0200216 struct {
217 uint32_t bound_ip;
218 uint32_t connect_ip;
219 uint16_t bound_port;
220 uint16_t connect_port;
221 uint16_t conn_id;
222 uint8_t rtp_payload;
223 uint8_t rtp_payload2;
224 uint8_t speech_mode;
Harald Welte135a6bd2011-09-04 13:53:26 +0200225#ifdef ROLE_BSC
Harald Welte6be350c2011-05-25 13:10:08 +0200226 struct rtp_socket *rtp_socket;
Harald Welte135a6bd2011-09-04 13:53:26 +0200227#else
228 struct osmo_rtp_socket *rtp_socket;
229#endif
Harald Welte6be350c2011-05-25 13:10:08 +0200230 } abis_ip;
231
Harald Welte2c1ae472011-06-26 14:13:37 +0200232 uint8_t rqd_ta;
233
Harald Welte6be350c2011-05-25 13:10:08 +0200234#ifdef ROLE_BSC
235 struct osmo_timer_list T3101;
Holger Hans Peter Freytherb3489392011-12-28 16:21:05 +0100236 struct osmo_timer_list T3109;
Harald Welte6be350c2011-05-25 13:10:08 +0200237 struct osmo_timer_list T3111;
238 struct osmo_timer_list error_timer;
Harald Weltee8bd9e82011-08-10 23:26:33 +0200239 struct osmo_timer_list act_timer;
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100240 struct osmo_timer_list rel_work;
Holger Hans Peter Freyther638da512012-12-06 19:25:06 +0100241 uint8_t error_cause;
Harald Welte6be350c2011-05-25 13:10:08 +0200242
243 /* table of neighbor cell measurements */
244 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
245
246 /* cache of last measurement reports on this lchan */
247 struct gsm_meas_rep meas_rep[6];
248 int meas_rep_idx;
249
250 /* GSM Random Access data */
251 struct gsm48_req_ref *rqd_ref;
Harald Welte6be350c2011-05-25 13:10:08 +0200252
253 struct gsm_subscriber_connection *conn;
Harald Weltef6093a42011-06-25 10:02:33 +0200254#else
Daniel Willmann324c8052012-12-29 12:32:30 +0100255 /* Number of different GsmL1_Sapi_t used in osmo_bts_sysmo is 23.
256 * Currently we don't share these headers so this is a magic number. */
Holger Hans Peter Freyther30156e12013-04-05 18:41:45 +0200257 struct llist_head sapi_cmds;
Daniel Willmann324c8052012-12-29 12:32:30 +0100258 uint8_t sapis_dl[23];
259 uint8_t sapis_ul[23];
Harald Weltef6093a42011-06-25 10:02:33 +0200260 struct lapdm_channel lapdm_ch;
Harald Welte135a6bd2011-09-04 13:53:26 +0200261 struct llist_head dl_tch_queue;
Harald Welte2c1ae472011-06-26 14:13:37 +0200262 struct {
263 /* bitmask of all SI that are present/valid in si_buf */
264 uint32_t valid;
265 uint32_t last;
266 /* buffers where we put the pre-computed SI */
267 sysinfo_buf_t buf[_MAX_SYSINFO_TYPE];
268 } si;
Harald Weltec7921c92011-06-29 10:38:34 +0200269 struct {
270 uint8_t flags;
271 /* RSL measurment result number, 0 at lchan_act */
272 uint8_t res_nr;
273 /* current Tx power level of the BTS */
274 uint8_t bts_tx_pwr;
275 /* number of measurements stored in array below */
276 uint8_t num_ul_meas;
277 struct bts_ul_meas uplink[MAX_NUM_UL_MEAS];
278 /* last L1 header from the MS */
279 uint8_t l1_info[2];
Harald Welte7ff4f0e2013-03-07 18:38:09 +0000280 struct gsm_meas_rep_unidir ul_res;
Harald Weltec7921c92011-06-29 10:38:34 +0200281 } meas;
Harald Weltef3b59322011-09-06 22:14:43 +0200282 struct {
283 struct amr_multirate_conf amr_mr;
Harald Welte43290992011-09-07 12:41:38 +0200284 struct {
285 uint8_t buf[16];
286 uint8_t len;
287 } last_sid;
Holger Hans Peter Freyther922ef5d2014-07-24 21:05:32 +0200288 uint8_t last_cmr;
Harald Weltef3b59322011-09-06 22:14:43 +0200289 } tch;
Harald Welte5d52c972012-04-08 20:23:28 +0200290 /* BTS-side ciphering state (rx only, bi-directional, ...) */
291 uint8_t ciph_state;
Holger Hans Peter Freyther2c6b59c2014-08-09 09:43:53 +0200292 uint8_t ciph_ns;
Harald Welte46cb8512012-04-19 23:13:35 +0200293 uint8_t loopback;
Harald Welte704cb862012-06-16 14:57:08 +0800294 struct {
295 uint8_t active;
296 uint8_t ref;
297 /* T3105: PHYS INF retransmission */
298 struct osmo_timer_list t3105;
299 /* counts up to Ny1 */
300 unsigned int phys_info_count;
301 } ho;
Andreas Eversberg1af682a2013-02-20 16:06:20 +0100302 /* S counter for link loss */
303 int s;
Holger Hans Peter Freytherfc7a75f2013-10-25 18:58:30 +0200304 /* Kind of the release/activation. E.g. RSL or PCU */
305 int rel_act_kind;
Holger Hans Peter Freytherf6f86b02015-02-05 22:25:03 +0100306
307 /* power handling */
308 struct {
309 uint8_t current;
310 uint8_t fixed;
311 } ms_power_ctrl;
Harald Welte6be350c2011-05-25 13:10:08 +0200312#endif
313};
314
Harald Welte6be350c2011-05-25 13:10:08 +0200315#define TS_F_PDCH_MODE 0x1000
316/* One Timeslot in a TRX */
317struct gsm_bts_trx_ts {
318 struct gsm_bts_trx *trx;
319 /* number of this timeslot at the TRX */
320 uint8_t nr;
321
322 enum gsm_phys_chan_config pchan;
323
324 unsigned int flags;
Harald Welted64c0bc2011-05-30 12:07:53 +0200325 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200326 struct tlv_parsed nm_attr;
327 uint8_t nm_chan_comb;
Harald Welte135a6482011-05-30 12:09:13 +0200328 int tsc; /* -1 == use BTS TSC */
Harald Welte6be350c2011-05-25 13:10:08 +0200329
330 struct {
331 /* Parameters below are configured by VTY */
332 int enabled;
333 uint8_t maio;
334 uint8_t hsn;
335 struct bitvec arfcns;
336 uint8_t arfcns_data[1024/8];
337 /* This is the pre-computed MA for channel assignments */
338 struct bitvec ma;
339 uint8_t ma_len; /* part of ma_data that is used */
340 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
341 } hopping;
342
343 /* To which E1 subslot are we connected */
344 struct gsm_e1_subslot e1_link;
345
346 struct gsm_lchan lchan[TS_MAX_LCHAN];
347};
348
349/* One TRX in a BTS */
350struct gsm_bts_trx {
351 /* list header in bts->trx_list */
352 struct llist_head list;
353
354 struct gsm_bts *bts;
355 /* number of this TRX in the BTS */
356 uint8_t nr;
357 /* human readable name / description */
358 char *description;
359 /* how do we talk RSL with this TRX? */
360 struct gsm_e1_subslot rsl_e1_link;
361 uint8_t rsl_tei;
362 struct e1inp_sign_link *rsl_link;
Holger Hans Peter Freythercaa98d52013-10-06 15:52:14 +0200363
Harald Welte6be350c2011-05-25 13:10:08 +0200364 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
365 struct e1inp_sign_link *oml_link;
366
Harald Welted64c0bc2011-05-30 12:07:53 +0200367 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200368 struct tlv_parsed nm_attr;
369 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200370 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200371 } bb_transc;
372
373 uint16_t arfcn;
374 int nominal_power; /* in dBm */
375 unsigned int max_power_red; /* in actual dB */
Holger Hans Peter Freyther9b625802014-07-30 18:20:51 +0200376
377#ifndef ROLE_BSC
Harald Welte101c5c22014-08-22 16:12:03 +0200378 struct trx_power_params power_params;
Holger Hans Peter Freytherf6f86b02015-02-05 22:25:03 +0100379 int ms_power_control;
Harald Welte6be350c2011-05-25 13:10:08 +0200380
Harald Welted134cc72011-06-07 00:12:53 +0200381 struct {
382 void *l1h;
383 } role_bts;
Holger Hans Peter Freyther9b625802014-07-30 18:20:51 +0200384#endif
Harald Welted134cc72011-06-07 00:12:53 +0200385
Harald Welte6be350c2011-05-25 13:10:08 +0200386 union {
387 struct {
388 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200389 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200390 } bbsig;
391 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200392 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200393 } pa;
394 } bs11;
395 struct {
396 unsigned int test_state;
397 uint8_t test_nr;
398 struct rxlev_stats rxlev_stat;
399 } ipaccess;
400 };
401 struct gsm_bts_trx_ts ts[TRX_NR_TS];
402};
403
404#define GSM_BTS_SI(bts, i) (void *)(bts->si_buf[i])
405
406enum gsm_bts_type {
407 GSM_BTS_TYPE_UNKNOWN,
408 GSM_BTS_TYPE_BS11,
409 GSM_BTS_TYPE_NANOBTS,
410 GSM_BTS_TYPE_RBS2000,
Dieter Spaar16646022011-07-28 00:01:50 +0200411 GSM_BTS_TYPE_NOKIA_SITE,
Harald Weltef383aa12012-07-02 19:51:55 +0200412 GSM_BTS_TYPE_OSMO_SYSMO,
Harald Weltee555c2b2012-08-17 13:02:12 +0200413 _NUM_GSM_BTS_TYPE
Harald Welte6be350c2011-05-25 13:10:08 +0200414};
415
416struct vty;
417
418struct gsm_bts_model {
419 struct llist_head list;
420
421 enum gsm_bts_type type;
422 const char *name;
423
424 bool started;
425 int (*start)(struct gsm_network *net);
426 int (*oml_rcvmsg)(struct msgb *msg);
427
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200428 void (*e1line_bind_ops)(struct e1inp_line *line);
429
Harald Welte6be350c2011-05-25 13:10:08 +0200430 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
431 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
432 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
433
434 struct tlv_definition nm_att_tlvdef;
435
436 struct bitvec features;
437 uint8_t _features_data[128/8];
438};
439
440enum gsm_bts_features {
441 BTS_FEAT_HSCSD,
442 BTS_FEAT_GPRS,
443 BTS_FEAT_EGPRS,
444 BTS_FEAT_ECSD,
445 BTS_FEAT_HOPPING,
Harald Welte903aaea2014-01-19 17:10:50 +0100446 BTS_FEAT_MULTI_TSC,
Harald Welte6be350c2011-05-25 13:10:08 +0200447};
448
449/*
450 * This keeps track of the paging status of one BTS. It
451 * includes a number of pending requests, a back pointer
452 * to the gsm_bts, a timer and some more state.
453 */
454struct gsm_bts_paging_state {
455 /* pending requests */
456 struct llist_head pending_requests;
457 struct gsm_bts *bts;
458
459 struct osmo_timer_list work_timer;
460 struct osmo_timer_list credit_timer;
461
462 /* free chans needed */
463 int free_chans_need;
464
465 /* load */
466 uint16_t available_slots;
467};
468
469struct gsm_envabtse {
Harald Welted64c0bc2011-05-30 12:07:53 +0200470 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200471};
472
473struct gsm_bts_gprs_nsvc {
474 struct gsm_bts *bts;
475 /* data read via VTY config file, to configure the BTS
476 * via OML from BSC */
477 int id;
478 uint16_t nsvci;
479 uint16_t local_port; /* on the BTS */
480 uint16_t remote_port; /* on the SGSN */
481 uint32_t remote_ip; /* on the SGSN */
482
Harald Welted64c0bc2011-05-30 12:07:53 +0200483 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200484};
485
Harald Welte019f9132012-06-28 08:43:14 +0200486enum gprs_rlc_par {
487 RLC_T3142,
488 RLC_T3169,
489 RLC_T3191,
490 RLC_T3193,
491 RLC_T3195,
492 RLC_N3101,
493 RLC_N3103,
494 RLC_N3105,
495 CV_COUNTDOWN,
496 T_DL_TBF_EXT, /* ms */
497 T_UL_TBF_EXT, /* ms */
498 _NUM_RLC_PAR
499};
500
501enum gprs_cs {
502 GPRS_CS1,
503 GPRS_CS2,
504 GPRS_CS3,
505 GPRS_CS4,
506 GPRS_MCS1,
507 GPRS_MCS2,
508 GPRS_MCS3,
509 GPRS_MCS4,
510 GPRS_MCS5,
511 GPRS_MCS6,
512 GPRS_MCS7,
513 GPRS_MCS8,
514 GPRS_MCS9,
515 _NUM_GRPS_CS
516};
517
518struct gprs_rlc_cfg {
519 uint16_t parameter[_NUM_RLC_PAR];
520 struct {
521 uint16_t repeat_time; /* ms */
522 uint8_t repeat_count;
523 } paging;
524 uint32_t cs_mask; /* bitmask of gprs_cs */
525 uint8_t initial_cs;
526 uint8_t initial_mcs;
527};
528
529
Harald Welte6be350c2011-05-25 13:10:08 +0200530enum neigh_list_manual_mode {
531 NL_MODE_AUTOMATIC = 0,
532 NL_MODE_MANUAL = 1,
533 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
534};
535
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200536enum bts_loc_fix {
537 BTS_LOC_FIX_INVALID = 0,
538 BTS_LOC_FIX_2D = 1,
539 BTS_LOC_FIX_3D = 2,
540};
541
Daniel Willmann7d109832012-05-14 18:43:23 +0200542extern const struct value_string bts_loc_fix_names[];
543
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200544struct bts_location {
545 struct llist_head list;
546 time_t tstamp;
547 enum bts_loc_fix valid;
548 double lat;
549 double lon;
550 double height;
551};
552
Harald Welte6be350c2011-05-25 13:10:08 +0200553/* One BTS */
554struct gsm_bts {
555 /* list header in net->bts_list */
556 struct llist_head list;
557
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200558 /* Geographical location of the BTS */
559 struct llist_head loc_list;
560
Harald Welte6be350c2011-05-25 13:10:08 +0200561 /* number of ths BTS in network */
562 uint8_t nr;
563 /* human readable name / description */
564 char *description;
565 /* Cell Identity */
566 uint16_t cell_identity;
567 /* location area code of this BTS */
568 uint16_t location_area_code;
569 /* Training Sequence Code */
570 uint8_t tsc;
571 /* Base Station Identification Code (BSIC) */
572 uint8_t bsic;
573 /* type of BTS */
574 enum gsm_bts_type type;
575 struct gsm_bts_model *model;
576 enum gsm_band band;
577 /* maximum Tx power that the MS is permitted to use in this cell */
578 int ms_max_power;
579
580 /* how do we talk OML with this TRX? */
581 struct gsm_e1_subslot oml_e1_link;
582 uint8_t oml_tei;
583 struct e1inp_sign_link *oml_link;
584
585 /* Abis network management O&M handle */
586 struct abis_nm_h *nmh;
Harald Welted64c0bc2011-05-30 12:07:53 +0200587
588 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200589
590 /* number of this BTS on given E1 link */
591 uint8_t bts_nr;
592
593 /* paging state and control */
594 struct gsm_bts_paging_state paging;
595
596 /* CCCH is on C0 */
597 struct gsm_bts_trx *c0;
598
599 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200600 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200601 } site_mgr;
602
603 /* bitmask of all SI that are present/valid in si_buf */
604 uint32_t si_valid;
605 /* buffers where we put the pre-computed SI */
606 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE];
607
Gus Bourg1c5dd2c2011-12-02 10:18:17 +0100608 /* TimeZone hours, mins, and bts specific */
Harald Welte45f91712012-07-08 16:48:11 +0200609 struct {
610 int hr;
611 int mn;
612 int override;
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200613 int dst;
Harald Welte45f91712012-07-08 16:48:11 +0200614 } tz;
Gus Bourg1c5dd2c2011-12-02 10:18:17 +0100615
Harald Welte6be350c2011-05-25 13:10:08 +0200616 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
617 union {
618 struct {
619 uint16_t site_id;
620 uint16_t bts_id;
621 uint32_t flags;
Harald Welte8b291802013-03-12 13:57:05 +0100622 uint32_t rsl_ip;
Harald Welte6be350c2011-05-25 13:10:08 +0200623 } ip_access;
624 struct {
625 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200626 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200627 } cclk;
628 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200629 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200630 } rack;
631 struct gsm_envabtse envabtse[4];
632 } bs11;
633 struct {
634 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200635 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200636 struct llist_head conn_groups;
637 } is;
638 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200639 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200640 struct llist_head conn_groups;
641 } con;
642 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200643 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200644 } dp;
645 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200646 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200647 } tf;
648 } rbs2000;
649 struct {
Harald Weltec8755af2011-07-28 00:22:17 +0200650 uint8_t bts_type;
Holger Hans Peter Freyther3e603482012-03-02 14:14:33 +0100651 unsigned int configured:1,
652 skip_reset:1,
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100653 no_loc_rel_cnf:1,
Sipos Csaba56e17662015-02-07 13:27:36 +0100654 bts_reset_timer_cnf,
Holger Hans Peter Freyther3e603482012-03-02 14:14:33 +0100655 did_reset:1,
656 wait_reset:1;
Harald Weltec8755af2011-07-28 00:22:17 +0200657 struct osmo_timer_list reset_timer;
658 } nokia;
Harald Welte6be350c2011-05-25 13:10:08 +0200659 };
660
661 /* Not entirely sure how ip.access specific this is */
662 struct {
663 enum bts_gprs_mode mode;
664 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200665 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200666 uint16_t nsei;
667 uint8_t timer[7];
668 } nse;
669 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200670 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200671 uint16_t bvci;
672 uint8_t timer[11];
Harald Welte019f9132012-06-28 08:43:14 +0200673 struct gprs_rlc_cfg rlc_cfg;
Harald Welte6be350c2011-05-25 13:10:08 +0200674 } cell;
675 struct gsm_bts_gprs_nsvc nsvc[2];
676 uint8_t rac;
Andreas Eversberg0c8f9ca2013-03-16 16:31:26 +0100677 uint8_t net_ctrl_ord;
Harald Welte6be350c2011-05-25 13:10:08 +0200678 } gprs;
679
680 /* RACH NM values */
681 int rach_b_thresh;
682 int rach_ldavg_slots;
683
684 /* transceivers */
685 int num_trx;
686 struct llist_head trx_list;
687
Holger Hans Peter Freytherb92a5382014-11-21 10:00:39 +0100688 /* SI related items */
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100689 int force_combined_si;
Holger Hans Peter Freytherb92a5382014-11-21 10:00:39 +0100690 int bcch_change_mark;
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100691
Harald Welte6be350c2011-05-25 13:10:08 +0200692#ifdef ROLE_BSC
693 /* Abis NM queue */
694 struct llist_head abis_queue;
695 int abis_nm_pend;
696
697 struct gsm_network *network;
698
699 /* should the channel allocator allocate channels from high TRX to TRX0,
700 * rather than starting from TRX0 and go upwards? */
701 int chan_alloc_reverse;
702
703 enum neigh_list_manual_mode neigh_list_manual_mode;
704 /* parameters from which we build SYSTEM INFORMATION */
705 struct {
706 struct gsm48_rach_control rach_control;
707 uint8_t ncc_permitted;
708 struct gsm48_cell_sel_par cell_sel_par;
709 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
710 struct gsm48_cell_options cell_options;
711 struct gsm48_control_channel_descr chan_desc;
712 struct bitvec neigh_list;
713 struct bitvec cell_alloc;
714 struct bitvec si5_neigh_list;
715 struct {
716 /* bitmask large enough for all possible ARFCN's */
717 uint8_t neigh_list[1024/8];
718 uint8_t cell_alloc[1024/8];
719 /* If the user wants a different neighbor list in SI5 than in SI2 */
720 uint8_t si5_neigh_list[1024/8];
721 } data;
722 } si_common;
723
724 /* do we use static (user-defined) system information messages? (bitmask) */
725 uint32_t si_mode_static;
Holger Hans Peter Freythere30d40d2012-07-20 10:27:31 +0200726
727 /* exclude the BTS from the global RF Lock handling */
728 int excl_from_rf_lock;
Andreas Eversberga83d5112013-12-07 18:32:28 +0100729
730 /* supported codecs beside FR */
731 struct bts_codec_conf codec;
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100732
733 /* BTS dependencies bit field */
734 uint32_t depends_on[256/(8*4)];
Harald Welte6be350c2011-05-25 13:10:08 +0200735#endif /* ROLE_BSC */
Harald Welte978714d2011-06-06 18:31:20 +0200736 void *role;
Harald Welte6be350c2011-05-25 13:10:08 +0200737};
738
739
Harald Welte3300c012011-06-05 13:31:33 +0200740struct gsm_bts *gsm_bts_alloc(void *talloc_ctx);
Harald Welte1449c9f2014-08-24 09:50:10 +0200741struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Harald Welte6be350c2011-05-25 13:10:08 +0200742
Harald Welte1449c9f2014-08-24 09:50:10 +0200743struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
Harald Welte4f8ad532011-09-19 14:21:51 +0200744struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
Harald Welte6be350c2011-05-25 13:10:08 +0200745
Harald Welte4ab9d7c2012-08-17 12:42:06 +0200746
Harald Welte30f1f372014-12-28 15:00:45 +0100747const struct value_string gsm_pchant_names[12];
748const struct value_string gsm_pchant_descs[12];
749const struct value_string gsm_lchant_names[8];
Harald Welte6be350c2011-05-25 13:10:08 +0200750const char *gsm_pchan_name(enum gsm_phys_chan_config c);
751enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
752const char *gsm_lchant_name(enum gsm_chan_t c);
753const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte4f8ad532011-09-19 14:21:51 +0200754char *gsm_trx_name(const struct gsm_bts_trx *trx);
755char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
756char *gsm_lchan_name(const struct gsm_lchan *lchan);
Harald Welte6be350c2011-05-25 13:10:08 +0200757const char *gsm_lchans_name(enum gsm_lchan_state s);
758
Harald Welte6be350c2011-05-25 13:10:08 +0200759
Harald Welteb7849982011-06-29 16:49:03 +0200760void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
761
Harald Welte978714d2011-06-06 18:31:20 +0200762struct gsm_abis_mo *
763gsm_objclass2mo(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200764 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200765
766struct gsm_nm_state *
767gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200768 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200769void *
770gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200771 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200772
Harald Welteb7849982011-06-29 16:49:03 +0200773/* reset the state of all MO in the BTS */
774void gsm_bts_mo_reset(struct gsm_bts *bts);
775
Harald Weltef6093a42011-06-25 10:02:33 +0200776uint8_t gsm_ts2chan_nr(const struct gsm_bts_trx_ts *ts, uint8_t lchan_nr);
777uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
778
Harald Welte142d12d2014-12-29 17:47:08 +0100779/* return the gsm_lchan for the CBCH (if it exists at all) */
780struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
781
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200782/*
783 * help with parsing regexps
784 */
785int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
786 int argc, const char **argv) __attribute__ ((warn_unused_result));
787
Harald Welte1fe24122014-01-19 17:18:21 +0100788static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
789{
790 if (ts->tsc != -1)
791 return ts->tsc;
792 else
793 return ts->trx->bts->tsc;
794}
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200795
796
Harald Welte6be350c2011-05-25 13:10:08 +0200797#endif