blob: 4472310e3384450c72c6290ed7d8924954ed1148 [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
Max582e4f62016-10-18 16:19:33 +020049/* lchans 0..3 are SDCCH in combined channel configuration,
50 use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
51#define CCCH_LCHAN 4
52
Harald Welte6be350c2011-05-25 13:10:08 +020053#define TRX_NR_TS 8
54#define TS_MAX_LCHAN 8
55
56#define HARDCODED_ARFCN 123
Harald Welte6be350c2011-05-25 13:10:08 +020057#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
58
59/* for multi-drop config */
60#define HARDCODED_BTS0_TS 1
61#define HARDCODED_BTS1_TS 6
62#define HARDCODED_BTS2_TS 11
63
Harald Welte6be350c2011-05-25 13:10:08 +020064enum gsm_hooks {
65 GSM_HOOK_NM_SWLOAD,
66 GSM_HOOK_RR_PAGING,
67 GSM_HOOK_RR_SECURITY,
68};
69
70enum gsm_paging_event {
71 GSM_PAGING_SUCCEEDED,
72 GSM_PAGING_EXPIRED,
73 GSM_PAGING_OOM,
74 GSM_PAGING_BUSY,
75};
76
77enum bts_gprs_mode {
78 BTS_GPRS_NONE = 0,
79 BTS_GPRS_GPRS = 1,
80 BTS_GPRS_EGPRS = 2,
81};
82
83struct gsm_lchan;
84struct gsm_subscriber;
85struct gsm_mncc;
Harald Welte135a6bd2011-09-04 13:53:26 +020086struct osmo_rtp_socket;
Harald Welte6be350c2011-05-25 13:10:08 +020087struct rtp_socket;
88struct bsc_api;
89
90/* Network Management State */
91struct gsm_nm_state {
92 uint8_t operational;
93 uint8_t administrative;
94 uint8_t availability;
95};
96
Harald Welted64c0bc2011-05-30 12:07:53 +020097struct gsm_abis_mo {
Harald Welte3300c012011-06-05 13:31:33 +020098 uint8_t obj_class;
Holger Hans Peter Freyther49976f42013-11-05 16:06:17 +010099 uint8_t procedure_pending;
Harald Welte3300c012011-06-05 13:31:33 +0200100 struct abis_om_obj_inst obj_inst;
Harald Welted64c0bc2011-05-30 12:07:53 +0200101 const char *name;
102 struct gsm_nm_state nm_state;
103 struct tlv_parsed *nm_attr;
Harald Welte32bc1162011-06-06 18:58:48 +0200104 struct gsm_bts *bts;
Harald Welted64c0bc2011-05-30 12:07:53 +0200105};
106
Harald Welte6be350c2011-05-25 13:10:08 +0200107#define MAX_A5_KEY_LEN (128/8)
108#define A38_XOR_MIN_KEY_LEN 12
109#define A38_XOR_MAX_KEY_LEN 16
110#define A38_COMP128_KEY_LEN 16
111#define RSL_ENC_ALG_A5(x) (x+1)
Max27c3e762016-04-20 15:57:12 +0200112#define MAX_EARFCN_LIST 32
Harald Welte6be350c2011-05-25 13:10:08 +0200113
114/* is the data link established? who established it? */
115#define LCHAN_SAPI_UNUSED 0
116#define LCHAN_SAPI_MS 1
117#define LCHAN_SAPI_NET 2
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100118#define LCHAN_SAPI_REL 3
Harald Welte6be350c2011-05-25 13:10:08 +0200119
120/* state of a logical channel */
121enum gsm_lchan_state {
122 LCHAN_S_NONE, /* channel is not active */
Holger Hans Peter Freytherded02682012-01-15 00:02:17 +0100123 LCHAN_S_ACT_REQ, /* channel activation requested */
Harald Welte6be350c2011-05-25 13:10:08 +0200124 LCHAN_S_ACTIVE, /* channel is active and operational */
125 LCHAN_S_REL_REQ, /* channel release has been requested */
126 LCHAN_S_REL_ERR, /* channel is in an error state */
Holger Hans Peter Freyther638da512012-12-06 19:25:06 +0100127 LCHAN_S_BROKEN, /* channel is somehow unusable */
Harald Welte6be350c2011-05-25 13:10:08 +0200128 LCHAN_S_INACTIVE, /* channel is set inactive */
129};
130
Harald Weltec7921c92011-06-29 10:38:34 +0200131/* BTS ONLY */
132#define MAX_NUM_UL_MEAS 104
133#define LC_UL_M_F_L1_VALID (1 << 0)
134#define LC_UL_M_F_RES_VALID (1 << 1)
135
136struct bts_ul_meas {
137 /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
138 uint16_t ber10k;
139 /* timing advance offset (in quarter bits) */
140 int16_t ta_offs_qbits;
141 /* C/I ratio in dB */
142 float c_i;
143 /* flags */
144 uint8_t is_sub:1;
145 /* RSSI in dBm * -1 */
146 uint8_t inv_rssi;
147};
Harald Weltef3b59322011-09-06 22:14:43 +0200148
Andreas Eversberga83d5112013-12-07 18:32:28 +0100149struct bts_codec_conf {
150 uint8_t hr;
151 uint8_t efr;
152 uint8_t amr;
153};
154
Harald Weltef3b59322011-09-06 22:14:43 +0200155struct amr_mode {
156 uint8_t mode;
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200157 uint8_t threshold;
158 uint8_t hysteresis;
Harald Weltef3b59322011-09-06 22:14:43 +0200159};
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200160
Harald Weltef3b59322011-09-06 22:14:43 +0200161struct amr_multirate_conf {
162 uint8_t gsm48_ie[2];
Holger Hans Peter Freyther615ed462015-09-24 11:30:58 +0200163 struct amr_mode ms_mode[4];
164 struct amr_mode bts_mode[4];
Harald Weltef3b59322011-09-06 22:14:43 +0200165 uint8_t num_modes;
166};
Harald Weltec7921c92011-06-29 10:38:34 +0200167/* /BTS ONLY */
168
Harald Weltee4227982012-08-24 15:33:56 +0200169enum lchan_csd_mode {
170 LCHAN_CSD_M_NT,
171 LCHAN_CSD_M_T_1200_75,
172 LCHAN_CSD_M_T_600,
173 LCHAN_CSD_M_T_1200,
174 LCHAN_CSD_M_T_2400,
175 LCHAN_CSD_M_T_9600,
176 LCHAN_CSD_M_T_14400,
177 LCHAN_CSD_M_T_29000,
178 LCHAN_CSD_M_T_32000,
179};
180
Daniel Willmann324c8052012-12-29 12:32:30 +0100181/* State of the SAPIs in the lchan */
182enum lchan_sapi_state {
183 LCHAN_SAPI_S_NONE,
184 LCHAN_SAPI_S_REQ,
185 LCHAN_SAPI_S_ASSIGNED,
186 LCHAN_SAPI_S_REL,
187 LCHAN_SAPI_S_ERROR,
188};
189
Harald Welte6be350c2011-05-25 13:10:08 +0200190struct gsm_lchan {
191 /* The TS that we're part of */
192 struct gsm_bts_trx_ts *ts;
193 /* The logical subslot number in the TS */
194 uint8_t nr;
195 /* The logical channel type */
196 enum gsm_chan_t type;
197 /* RSL channel mode */
198 enum rsl_cmod_spd rsl_cmode;
199 /* If TCH, traffic channel mode */
200 enum gsm48_chan_mode tch_mode;
Harald Weltee4227982012-08-24 15:33:56 +0200201 enum lchan_csd_mode csd_mode;
Harald Welte6be350c2011-05-25 13:10:08 +0200202 /* State */
203 enum gsm_lchan_state state;
Holger Hans Peter Freyther454140e2014-12-28 12:08:28 +0100204 const char *broken_reason;
Harald Welte6be350c2011-05-25 13:10:08 +0200205 /* Power levels for MS and BTS */
206 uint8_t bs_power;
207 uint8_t ms_power;
208 /* Encryption information */
209 struct {
210 uint8_t alg_id;
211 uint8_t key_len;
212 uint8_t key[MAX_A5_KEY_LEN];
213 } encr;
214
215 /* AMR bits */
Andreas Eversberg73266522014-01-19 11:47:44 +0100216 uint8_t mr_ms_lv[7];
217 uint8_t mr_bts_lv[7];
Harald Welte6be350c2011-05-25 13:10:08 +0200218
219 /* Established data link layer services */
220 uint8_t sapis[8];
Holger Hans Peter Freytherb9b828b2013-01-01 19:20:28 +0100221 int sacch_deact;
Holger Hans Peter Freytherdfcfe652011-12-27 20:49:53 +0100222
Harald Welte6be350c2011-05-25 13:10:08 +0200223 struct {
224 uint32_t bound_ip;
225 uint32_t connect_ip;
226 uint16_t bound_port;
227 uint16_t connect_port;
228 uint16_t conn_id;
229 uint8_t rtp_payload;
230 uint8_t rtp_payload2;
231 uint8_t speech_mode;
Harald Welte135a6bd2011-09-04 13:53:26 +0200232#ifdef ROLE_BSC
Harald Welte6be350c2011-05-25 13:10:08 +0200233 struct rtp_socket *rtp_socket;
Harald Welte135a6bd2011-09-04 13:53:26 +0200234#else
235 struct osmo_rtp_socket *rtp_socket;
236#endif
Harald Welte6be350c2011-05-25 13:10:08 +0200237 } abis_ip;
238
Harald Welte2c1ae472011-06-26 14:13:37 +0200239 uint8_t rqd_ta;
240
Harald Weltec696cc22015-12-05 16:19:21 +0100241 char *name;
242
Harald Welte6be350c2011-05-25 13:10:08 +0200243#ifdef ROLE_BSC
244 struct osmo_timer_list T3101;
Holger Hans Peter Freytherb3489392011-12-28 16:21:05 +0100245 struct osmo_timer_list T3109;
Harald Welte6be350c2011-05-25 13:10:08 +0200246 struct osmo_timer_list T3111;
247 struct osmo_timer_list error_timer;
Harald Weltee8bd9e82011-08-10 23:26:33 +0200248 struct osmo_timer_list act_timer;
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100249 struct osmo_timer_list rel_work;
Holger Hans Peter Freyther638da512012-12-06 19:25:06 +0100250 uint8_t error_cause;
Harald Welte6be350c2011-05-25 13:10:08 +0200251
252 /* table of neighbor cell measurements */
253 struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
254
255 /* cache of last measurement reports on this lchan */
256 struct gsm_meas_rep meas_rep[6];
257 int meas_rep_idx;
258
259 /* GSM Random Access data */
260 struct gsm48_req_ref *rqd_ref;
Harald Welte6be350c2011-05-25 13:10:08 +0200261
262 struct gsm_subscriber_connection *conn;
Andreas Eversberg9df268e2013-10-11 13:32:30 +0200263
264 struct {
265 /* channel activation type and handover ref */
266 uint8_t act_type;
267 uint8_t ho_ref;
Neels Hofmeyrb91e6002016-07-23 19:45:15 +0200268 struct gsm48_req_ref *rqd_ref;
269 uint8_t rqd_ta;
Neels Hofmeyr6e999b72016-07-23 21:00:51 +0200270 } dyn;
Harald Weltef6093a42011-06-25 10:02:33 +0200271#else
Daniel Willmann324c8052012-12-29 12:32:30 +0100272 /* Number of different GsmL1_Sapi_t used in osmo_bts_sysmo is 23.
273 * Currently we don't share these headers so this is a magic number. */
Holger Hans Peter Freyther30156e12013-04-05 18:41:45 +0200274 struct llist_head sapi_cmds;
Daniel Willmann324c8052012-12-29 12:32:30 +0100275 uint8_t sapis_dl[23];
276 uint8_t sapis_ul[23];
Harald Weltef6093a42011-06-25 10:02:33 +0200277 struct lapdm_channel lapdm_ch;
Harald Welte135a6bd2011-09-04 13:53:26 +0200278 struct llist_head dl_tch_queue;
Harald Welte2c1ae472011-06-26 14:13:37 +0200279 struct {
280 /* bitmask of all SI that are present/valid in si_buf */
281 uint32_t valid;
282 uint32_t last;
283 /* buffers where we put the pre-computed SI */
284 sysinfo_buf_t buf[_MAX_SYSINFO_TYPE];
285 } si;
Harald Weltec7921c92011-06-29 10:38:34 +0200286 struct {
287 uint8_t flags;
288 /* RSL measurment result number, 0 at lchan_act */
289 uint8_t res_nr;
290 /* current Tx power level of the BTS */
291 uint8_t bts_tx_pwr;
292 /* number of measurements stored in array below */
293 uint8_t num_ul_meas;
294 struct bts_ul_meas uplink[MAX_NUM_UL_MEAS];
295 /* last L1 header from the MS */
296 uint8_t l1_info[2];
Harald Welte7ff4f0e2013-03-07 18:38:09 +0000297 struct gsm_meas_rep_unidir ul_res;
Harald Weltec7921c92011-06-29 10:38:34 +0200298 } meas;
Harald Weltef3b59322011-09-06 22:14:43 +0200299 struct {
300 struct amr_multirate_conf amr_mr;
Harald Welte43290992011-09-07 12:41:38 +0200301 struct {
Max1e646f02016-10-05 17:29:02 +0200302 struct osmo_fsm_inst *dl_amr_fsm;
Max1b76a032016-10-25 20:22:16 +0200303 /* TCH cache */
Max1e646f02016-10-05 17:29:02 +0200304 uint8_t cache[20];
Max1b76a032016-10-25 20:22:16 +0200305 /* FACCH cache */
306 uint8_t facch[GSM_MACBLOCK_LEN];
Harald Welte43290992011-09-07 12:41:38 +0200307 uint8_t len;
Maxf5fe31d2016-06-10 14:09:07 +0200308 uint32_t fn;
309 bool is_update;
Max1e646f02016-10-05 17:29:02 +0200310 /* set for each SID frame to detect talkspurt for codecs
311 without explicit ONSET event */
312 bool ul_sid;
313 /* indicates if DTXd was active during DL measurement
314 period */
315 bool dl_active;
316 } dtx;
Holger Hans Peter Freyther922ef5d2014-07-24 21:05:32 +0200317 uint8_t last_cmr;
Maxd7df7ae2016-06-03 12:06:26 +0200318 uint32_t last_fn;
Harald Weltef3b59322011-09-06 22:14:43 +0200319 } tch;
Harald Welte5d52c972012-04-08 20:23:28 +0200320 /* BTS-side ciphering state (rx only, bi-directional, ...) */
321 uint8_t ciph_state;
Holger Hans Peter Freyther2c6b59c2014-08-09 09:43:53 +0200322 uint8_t ciph_ns;
Harald Welte46cb8512012-04-19 23:13:35 +0200323 uint8_t loopback;
Harald Welte704cb862012-06-16 14:57:08 +0800324 struct {
325 uint8_t active;
326 uint8_t ref;
327 /* T3105: PHYS INF retransmission */
328 struct osmo_timer_list t3105;
329 /* counts up to Ny1 */
330 unsigned int phys_info_count;
331 } ho;
Andreas Eversberg1af682a2013-02-20 16:06:20 +0100332 /* S counter for link loss */
333 int s;
Holger Hans Peter Freytherfc7a75f2013-10-25 18:58:30 +0200334 /* Kind of the release/activation. E.g. RSL or PCU */
335 int rel_act_kind;
Maxec744652016-05-18 16:42:16 +0200336 /* RTP header Marker bit to indicate beginning of speech after pause */
337 bool rtp_tx_marker;
Holger Hans Peter Freytherf6f86b02015-02-05 22:25:03 +0100338 /* power handling */
339 struct {
340 uint8_t current;
341 uint8_t fixed;
342 } ms_power_ctrl;
Harald Welte6be350c2011-05-25 13:10:08 +0200343#endif
344};
345
Neels Hofmeyr2ebacce2016-06-14 14:08:35 +0200346enum {
347 TS_F_PDCH_ACTIVE = 0x1000,
348 TS_F_PDCH_ACT_PENDING = 0x2000,
349 TS_F_PDCH_DEACT_PENDING = 0x4000,
350 TS_F_PDCH_PENDING_MASK = 0x6000 /*<
351 TS_F_PDCH_ACT_PENDING | TS_F_PDCH_DEACT_PENDING */
352} gsm_bts_trx_ts_flags;
353
Harald Welte6be350c2011-05-25 13:10:08 +0200354/* One Timeslot in a TRX */
355struct gsm_bts_trx_ts {
356 struct gsm_bts_trx *trx;
357 /* number of this timeslot at the TRX */
358 uint8_t nr;
359
360 enum gsm_phys_chan_config pchan;
361
Neels Hofmeyrc1658762016-07-23 16:14:06 +0200362 struct {
363 enum gsm_phys_chan_config pchan_is;
364 enum gsm_phys_chan_config pchan_want;
365 struct msgb *pending_chan_activ;
366 } dyn;
367
Harald Welte6be350c2011-05-25 13:10:08 +0200368 unsigned int flags;
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 uint8_t nm_chan_comb;
Harald Welte135a6482011-05-30 12:09:13 +0200372 int tsc; /* -1 == use BTS TSC */
Harald Welte6be350c2011-05-25 13:10:08 +0200373
374 struct {
375 /* Parameters below are configured by VTY */
376 int enabled;
377 uint8_t maio;
378 uint8_t hsn;
379 struct bitvec arfcns;
380 uint8_t arfcns_data[1024/8];
381 /* This is the pre-computed MA for channel assignments */
382 struct bitvec ma;
383 uint8_t ma_len; /* part of ma_data that is used */
384 uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
385 } hopping;
386
387 /* To which E1 subslot are we connected */
388 struct gsm_e1_subslot e1_link;
389
390 struct gsm_lchan lchan[TS_MAX_LCHAN];
391};
392
393/* One TRX in a BTS */
394struct gsm_bts_trx {
395 /* list header in bts->trx_list */
396 struct llist_head list;
397
398 struct gsm_bts *bts;
399 /* number of this TRX in the BTS */
400 uint8_t nr;
401 /* human readable name / description */
402 char *description;
403 /* how do we talk RSL with this TRX? */
404 struct gsm_e1_subslot rsl_e1_link;
405 uint8_t rsl_tei;
406 struct e1inp_sign_link *rsl_link;
Holger Hans Peter Freythercaa98d52013-10-06 15:52:14 +0200407
Harald Welte6be350c2011-05-25 13:10:08 +0200408 /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
409 struct e1inp_sign_link *oml_link;
410
Harald Welted64c0bc2011-05-30 12:07:53 +0200411 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200412 struct tlv_parsed nm_attr;
413 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200414 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200415 } bb_transc;
416
417 uint16_t arfcn;
418 int nominal_power; /* in dBm */
419 unsigned int max_power_red; /* in actual dB */
Holger Hans Peter Freyther9b625802014-07-30 18:20:51 +0200420
421#ifndef ROLE_BSC
Harald Welte101c5c22014-08-22 16:12:03 +0200422 struct trx_power_params power_params;
Holger Hans Peter Freytherf6f86b02015-02-05 22:25:03 +0100423 int ms_power_control;
Harald Welte6be350c2011-05-25 13:10:08 +0200424
Harald Welted134cc72011-06-07 00:12:53 +0200425 struct {
426 void *l1h;
427 } role_bts;
Holger Hans Peter Freyther9b625802014-07-30 18:20:51 +0200428#endif
Harald Welted134cc72011-06-07 00:12:53 +0200429
Harald Welte6be350c2011-05-25 13:10:08 +0200430 union {
431 struct {
432 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200433 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200434 } bbsig;
435 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200436 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200437 } pa;
438 } bs11;
439 struct {
440 unsigned int test_state;
441 uint8_t test_nr;
442 struct rxlev_stats rxlev_stat;
443 } ipaccess;
444 };
445 struct gsm_bts_trx_ts ts[TRX_NR_TS];
446};
447
448#define GSM_BTS_SI(bts, i) (void *)(bts->si_buf[i])
449
450enum gsm_bts_type {
451 GSM_BTS_TYPE_UNKNOWN,
452 GSM_BTS_TYPE_BS11,
453 GSM_BTS_TYPE_NANOBTS,
454 GSM_BTS_TYPE_RBS2000,
Dieter Spaar16646022011-07-28 00:01:50 +0200455 GSM_BTS_TYPE_NOKIA_SITE,
Harald Weltef383aa12012-07-02 19:51:55 +0200456 GSM_BTS_TYPE_OSMO_SYSMO,
Harald Weltee555c2b2012-08-17 13:02:12 +0200457 _NUM_GSM_BTS_TYPE
Harald Welte6be350c2011-05-25 13:10:08 +0200458};
459
460struct vty;
461
462struct gsm_bts_model {
463 struct llist_head list;
464
465 enum gsm_bts_type type;
466 const char *name;
467
468 bool started;
469 int (*start)(struct gsm_network *net);
470 int (*oml_rcvmsg)(struct msgb *msg);
471
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200472 void (*e1line_bind_ops)(struct e1inp_line *line);
473
Harald Welte6be350c2011-05-25 13:10:08 +0200474 void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
475 void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
476 void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
477
478 struct tlv_definition nm_att_tlvdef;
479
480 struct bitvec features;
481 uint8_t _features_data[128/8];
482};
483
484enum gsm_bts_features {
485 BTS_FEAT_HSCSD,
486 BTS_FEAT_GPRS,
487 BTS_FEAT_EGPRS,
488 BTS_FEAT_ECSD,
489 BTS_FEAT_HOPPING,
Harald Welte903aaea2014-01-19 17:10:50 +0100490 BTS_FEAT_MULTI_TSC,
Harald Welte6be350c2011-05-25 13:10:08 +0200491};
492
493/*
494 * This keeps track of the paging status of one BTS. It
495 * includes a number of pending requests, a back pointer
496 * to the gsm_bts, a timer and some more state.
497 */
498struct gsm_bts_paging_state {
499 /* pending requests */
500 struct llist_head pending_requests;
501 struct gsm_bts *bts;
502
503 struct osmo_timer_list work_timer;
504 struct osmo_timer_list credit_timer;
505
506 /* free chans needed */
507 int free_chans_need;
508
509 /* load */
510 uint16_t available_slots;
511};
512
513struct gsm_envabtse {
Harald Welted64c0bc2011-05-30 12:07:53 +0200514 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200515};
516
517struct gsm_bts_gprs_nsvc {
518 struct gsm_bts *bts;
519 /* data read via VTY config file, to configure the BTS
520 * via OML from BSC */
521 int id;
522 uint16_t nsvci;
523 uint16_t local_port; /* on the BTS */
524 uint16_t remote_port; /* on the SGSN */
525 uint32_t remote_ip; /* on the SGSN */
526
Harald Welted64c0bc2011-05-30 12:07:53 +0200527 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200528};
529
Harald Welte019f9132012-06-28 08:43:14 +0200530enum gprs_rlc_par {
531 RLC_T3142,
532 RLC_T3169,
533 RLC_T3191,
534 RLC_T3193,
535 RLC_T3195,
536 RLC_N3101,
537 RLC_N3103,
538 RLC_N3105,
539 CV_COUNTDOWN,
540 T_DL_TBF_EXT, /* ms */
541 T_UL_TBF_EXT, /* ms */
542 _NUM_RLC_PAR
543};
544
545enum gprs_cs {
546 GPRS_CS1,
547 GPRS_CS2,
548 GPRS_CS3,
549 GPRS_CS4,
550 GPRS_MCS1,
551 GPRS_MCS2,
552 GPRS_MCS3,
553 GPRS_MCS4,
554 GPRS_MCS5,
555 GPRS_MCS6,
556 GPRS_MCS7,
557 GPRS_MCS8,
558 GPRS_MCS9,
559 _NUM_GRPS_CS
560};
561
562struct gprs_rlc_cfg {
563 uint16_t parameter[_NUM_RLC_PAR];
564 struct {
565 uint16_t repeat_time; /* ms */
566 uint8_t repeat_count;
567 } paging;
568 uint32_t cs_mask; /* bitmask of gprs_cs */
569 uint8_t initial_cs;
570 uint8_t initial_mcs;
571};
572
573
Harald Welte6be350c2011-05-25 13:10:08 +0200574enum neigh_list_manual_mode {
575 NL_MODE_AUTOMATIC = 0,
576 NL_MODE_MANUAL = 1,
577 NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
578};
579
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200580enum bts_loc_fix {
581 BTS_LOC_FIX_INVALID = 0,
582 BTS_LOC_FIX_2D = 1,
583 BTS_LOC_FIX_3D = 2,
584};
585
Daniel Willmann7d109832012-05-14 18:43:23 +0200586extern const struct value_string bts_loc_fix_names[];
587
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200588struct bts_location {
589 struct llist_head list;
590 time_t tstamp;
591 enum bts_loc_fix valid;
592 double lat;
593 double lon;
594 double height;
595};
596
Harald Welte6be350c2011-05-25 13:10:08 +0200597/* One BTS */
598struct gsm_bts {
599 /* list header in net->bts_list */
600 struct llist_head list;
601
Daniel Willmann47b5b3e2011-08-05 13:51:27 +0200602 /* Geographical location of the BTS */
603 struct llist_head loc_list;
604
Harald Welte6be350c2011-05-25 13:10:08 +0200605 /* number of ths BTS in network */
606 uint8_t nr;
607 /* human readable name / description */
608 char *description;
609 /* Cell Identity */
610 uint16_t cell_identity;
611 /* location area code of this BTS */
612 uint16_t location_area_code;
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100613 /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
614 * which is used as TSC for the CCCH */
Harald Welte6be350c2011-05-25 13:10:08 +0200615 uint8_t bsic;
616 /* type of BTS */
617 enum gsm_bts_type type;
618 struct gsm_bts_model *model;
619 enum gsm_band band;
620 /* maximum Tx power that the MS is permitted to use in this cell */
621 int ms_max_power;
622
623 /* how do we talk OML with this TRX? */
624 struct gsm_e1_subslot oml_e1_link;
625 uint8_t oml_tei;
626 struct e1inp_sign_link *oml_link;
627
628 /* Abis network management O&M handle */
629 struct abis_nm_h *nmh;
Harald Welted64c0bc2011-05-30 12:07:53 +0200630
631 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200632
633 /* number of this BTS on given E1 link */
634 uint8_t bts_nr;
635
Maxc08ee712016-05-11 12:45:13 +0200636 /* DTX features of this BTS */
637 enum gsm48_dtx_mode dtxu;
638 bool dtxd;
639
Harald Welte6be350c2011-05-25 13:10:08 +0200640 /* paging state and control */
641 struct gsm_bts_paging_state paging;
642
643 /* CCCH is on C0 */
644 struct gsm_bts_trx *c0;
645
646 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200647 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200648 } site_mgr;
649
650 /* bitmask of all SI that are present/valid in si_buf */
651 uint32_t si_valid;
652 /* buffers where we put the pre-computed SI */
653 sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE];
654
Gus Bourg1c5dd2c2011-12-02 10:18:17 +0100655 /* TimeZone hours, mins, and bts specific */
Harald Welte45f91712012-07-08 16:48:11 +0200656 struct {
657 int hr;
658 int mn;
659 int override;
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200660 int dst;
Harald Welte45f91712012-07-08 16:48:11 +0200661 } tz;
Gus Bourg1c5dd2c2011-12-02 10:18:17 +0100662
Harald Welte6be350c2011-05-25 13:10:08 +0200663 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
664 union {
665 struct {
666 uint16_t site_id;
667 uint16_t bts_id;
668 uint32_t flags;
Harald Welte8b291802013-03-12 13:57:05 +0100669 uint32_t rsl_ip;
Harald Welte6be350c2011-05-25 13:10:08 +0200670 } ip_access;
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 } cclk;
675 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200676 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200677 } rack;
678 struct gsm_envabtse envabtse[4];
679 } bs11;
680 struct {
681 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200682 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200683 struct llist_head conn_groups;
684 } is;
685 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200686 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200687 struct llist_head conn_groups;
688 } con;
689 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200690 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200691 } dp;
692 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200693 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200694 } tf;
695 } rbs2000;
696 struct {
Harald Weltec8755af2011-07-28 00:22:17 +0200697 uint8_t bts_type;
Holger Hans Peter Freyther3e603482012-03-02 14:14:33 +0100698 unsigned int configured:1,
699 skip_reset:1,
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100700 no_loc_rel_cnf:1,
Sipos Csaba56e17662015-02-07 13:27:36 +0100701 bts_reset_timer_cnf,
Holger Hans Peter Freyther3e603482012-03-02 14:14:33 +0100702 did_reset:1,
703 wait_reset:1;
Harald Weltec8755af2011-07-28 00:22:17 +0200704 struct osmo_timer_list reset_timer;
705 } nokia;
Harald Welte6be350c2011-05-25 13:10:08 +0200706 };
707
708 /* Not entirely sure how ip.access specific this is */
709 struct {
bhargava350533c2016-07-21 11:14:34 +0530710 uint8_t supports_egprs_11bit_rach;
Harald Welte6be350c2011-05-25 13:10:08 +0200711 enum bts_gprs_mode mode;
712 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200713 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200714 uint16_t nsei;
715 uint8_t timer[7];
716 } nse;
717 struct {
Harald Welted64c0bc2011-05-30 12:07:53 +0200718 struct gsm_abis_mo mo;
Harald Welte6be350c2011-05-25 13:10:08 +0200719 uint16_t bvci;
720 uint8_t timer[11];
Harald Welte019f9132012-06-28 08:43:14 +0200721 struct gprs_rlc_cfg rlc_cfg;
Harald Welte6be350c2011-05-25 13:10:08 +0200722 } cell;
723 struct gsm_bts_gprs_nsvc nsvc[2];
724 uint8_t rac;
Andreas Eversberg0c8f9ca2013-03-16 16:31:26 +0100725 uint8_t net_ctrl_ord;
Max292ec582016-07-28 11:55:37 +0200726 bool ctrl_ack_type_use_block;
Harald Welte6be350c2011-05-25 13:10:08 +0200727 } gprs;
728
729 /* RACH NM values */
730 int rach_b_thresh;
731 int rach_ldavg_slots;
732
733 /* transceivers */
734 int num_trx;
735 struct llist_head trx_list;
736
Holger Hans Peter Freytherb92a5382014-11-21 10:00:39 +0100737 /* SI related items */
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100738 int force_combined_si;
Holger Hans Peter Freytherb92a5382014-11-21 10:00:39 +0100739 int bcch_change_mark;
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100740
Harald Welte6be350c2011-05-25 13:10:08 +0200741#ifdef ROLE_BSC
742 /* Abis NM queue */
743 struct llist_head abis_queue;
744 int abis_nm_pend;
745
746 struct gsm_network *network;
747
748 /* should the channel allocator allocate channels from high TRX to TRX0,
749 * rather than starting from TRX0 and go upwards? */
750 int chan_alloc_reverse;
751
752 enum neigh_list_manual_mode neigh_list_manual_mode;
753 /* parameters from which we build SYSTEM INFORMATION */
754 struct {
755 struct gsm48_rach_control rach_control;
756 uint8_t ncc_permitted;
757 struct gsm48_cell_sel_par cell_sel_par;
758 struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
759 struct gsm48_cell_options cell_options;
760 struct gsm48_control_channel_descr chan_desc;
761 struct bitvec neigh_list;
762 struct bitvec cell_alloc;
763 struct bitvec si5_neigh_list;
Max59a1bf32016-04-15 16:04:46 +0200764 struct osmo_earfcn_si2q si2quater_neigh_list;
Max26679e02016-04-20 15:57:13 +0200765 size_t uarfcn_length; /* index for uarfcn and scramble lists */
Harald Welte6be350c2011-05-25 13:10:08 +0200766 struct {
767 /* bitmask large enough for all possible ARFCN's */
768 uint8_t neigh_list[1024/8];
769 uint8_t cell_alloc[1024/8];
770 /* If the user wants a different neighbor list in SI5 than in SI2 */
771 uint8_t si5_neigh_list[1024/8];
Max59a1bf32016-04-15 16:04:46 +0200772 uint8_t meas_bw_list[MAX_EARFCN_LIST];
773 uint16_t earfcn_list[MAX_EARFCN_LIST];
Max26679e02016-04-20 15:57:13 +0200774 uint16_t uarfcn_list[MAX_EARFCN_LIST];
775 uint16_t scramble_list[MAX_EARFCN_LIST];
Harald Welte6be350c2011-05-25 13:10:08 +0200776 } data;
777 } si_common;
778
779 /* do we use static (user-defined) system information messages? (bitmask) */
780 uint32_t si_mode_static;
Holger Hans Peter Freythere30d40d2012-07-20 10:27:31 +0200781
782 /* exclude the BTS from the global RF Lock handling */
783 int excl_from_rf_lock;
Andreas Eversberga83d5112013-12-07 18:32:28 +0100784
785 /* supported codecs beside FR */
786 struct bts_codec_conf codec;
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100787
788 /* BTS dependencies bit field */
789 uint32_t depends_on[256/(8*4)];
Andreas Eversberg73266522014-01-19 11:47:44 +0100790
791 /* full and half rate multirate config */
792 struct amr_multirate_conf mr_full;
793 struct amr_multirate_conf mr_half;
794
Harald Welte6be350c2011-05-25 13:10:08 +0200795#endif /* ROLE_BSC */
Harald Welte978714d2011-06-06 18:31:20 +0200796 void *role;
Harald Welte6be350c2011-05-25 13:10:08 +0200797};
798
799
Harald Welte3300c012011-06-05 13:31:33 +0200800struct gsm_bts *gsm_bts_alloc(void *talloc_ctx);
Harald Welte1449c9f2014-08-24 09:50:10 +0200801struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
Harald Welte6be350c2011-05-25 13:10:08 +0200802
Harald Welte1449c9f2014-08-24 09:50:10 +0200803struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
Harald Welte4f8ad532011-09-19 14:21:51 +0200804struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
Harald Welte6be350c2011-05-25 13:10:08 +0200805
Harald Welte4ab9d7c2012-08-17 12:42:06 +0200806
Neels Hofmeyr17a6bab2016-07-23 16:14:06 +0200807const struct value_string gsm_pchant_names[13];
808const struct value_string gsm_pchant_descs[13];
Harald Welte6be350c2011-05-25 13:10:08 +0200809const char *gsm_pchan_name(enum gsm_phys_chan_config c);
810enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
811const char *gsm_lchant_name(enum gsm_chan_t c);
812const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte4f8ad532011-09-19 14:21:51 +0200813char *gsm_trx_name(const struct gsm_bts_trx *trx);
814char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
Neels Hofmeyr34b8b5b2016-07-16 23:59:32 +0200815char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
Harald Weltec696cc22015-12-05 16:19:21 +0100816char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
Harald Welte6be350c2011-05-25 13:10:08 +0200817const char *gsm_lchans_name(enum gsm_lchan_state s);
818
Harald Weltec696cc22015-12-05 16:19:21 +0100819static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
820{
821 return lchan->name;
822}
Harald Welte6be350c2011-05-25 13:10:08 +0200823
Harald Welteb7849982011-06-29 16:49:03 +0200824void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
825
Harald Welte978714d2011-06-06 18:31:20 +0200826struct gsm_abis_mo *
827gsm_objclass2mo(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200828 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200829
830struct gsm_nm_state *
831gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200832 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200833void *
834gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
Harald Welte4f8ad532011-09-19 14:21:51 +0200835 const struct abis_om_obj_inst *obj_inst);
Harald Welte978714d2011-06-06 18:31:20 +0200836
Harald Welteb7849982011-06-29 16:49:03 +0200837/* reset the state of all MO in the BTS */
838void gsm_bts_mo_reset(struct gsm_bts *bts);
839
Neels Hofmeyrd3841102016-07-18 23:43:44 +0200840uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
841 uint8_t ts_nr, uint8_t lchan_nr);
Harald Weltef6093a42011-06-25 10:02:33 +0200842uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
Neels Hofmeyrd3841102016-07-18 23:43:44 +0200843uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
844 enum gsm_phys_chan_config as_pchan);
Harald Weltef6093a42011-06-25 10:02:33 +0200845
Harald Welte142d12d2014-12-29 17:47:08 +0100846/* return the gsm_lchan for the CBCH (if it exists at all) */
847struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
848
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200849/*
850 * help with parsing regexps
851 */
852int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
853 int argc, const char **argv) __attribute__ ((warn_unused_result));
854
Harald Welte1fe24122014-01-19 17:18:21 +0100855static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
856{
857 if (ts->tsc != -1)
858 return ts->tsc;
859 else
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100860 return ts->trx->bts->bsic & 7;
Harald Welte1fe24122014-01-19 17:18:21 +0100861}
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200862
Neels Hofmeyr74585722016-07-23 17:38:22 +0200863struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
864 int *rc);
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200865
Neels Hofmeyr76a0ad72016-07-29 18:12:06 +0200866uint8_t ts_subslots(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr255dbfe2016-09-25 15:07:01 +0200867bool ts_is_tch(struct gsm_bts_trx_ts *ts);
Neels Hofmeyr76a0ad72016-07-29 18:12:06 +0200868
Harald Welte6be350c2011-05-25 13:10:08 +0200869#endif