blob: 1fb80a2f3e92a58ce3d84cb6f0225917494e663d [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001#ifndef _GSM_DATA_H
2#define _GSM_DATA_H
3
4#include <sys/types.h>
5
Harald Welte255539c2008-12-28 02:26:27 +00006#include <openbsc/timer.h>
Holger Freyther1adb4ff2009-02-04 00:04:52 +00007#include <openbsc/gsm_04_08.h>
Harald Welte255539c2008-12-28 02:26:27 +00008
Harald Welte8470bf22008-12-25 23:28:35 +00009#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
10
Harald Welte52b1f982008-12-23 20:25:15 +000011#define GSM_MAX_BTS 8
12#define BTS_MAX_TRX 8
Harald Welte85770c72009-01-18 17:47:32 +000013#define TRX_NR_TS 8
Harald Welte8470bf22008-12-25 23:28:35 +000014#define TS_MAX_LCHAN 8
Harald Welte52b1f982008-12-23 20:25:15 +000015
16#define HARDCODED_ARFCN 123
Harald Welte02b0e092009-02-28 13:11:07 +000017#define HARDCODED_TSC 7
Harald Welte78f2f502009-05-23 16:56:52 +000018#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
Harald Welte52b1f982008-12-23 20:25:15 +000019
Harald Welte8e1e3ee2009-02-01 13:32:45 +000020enum gsm_hooks {
21 GSM_HOOK_NM_SWLOAD,
Harald Welte0932d1e2009-02-16 22:53:52 +000022 GSM_HOOK_RR_PAGING,
23};
24
25enum gsm_paging_event {
26 GSM_PAGING_SUCCEEDED,
27 GSM_PAGING_EXPIRED,
Holger Freyther85a7b362009-04-18 13:48:55 +020028 GSM_PAGING_OOM,
Harald Welte8e1e3ee2009-02-01 13:32:45 +000029};
30
31struct msgb;
32typedef int gsm_cbfn(unsigned int hooknum,
33 unsigned int event,
34 struct msgb *msg,
35 void *data, void *param);
36
Holger Freytherc6ea9db2008-12-30 19:18:21 +000037/*
38 * Use the channel. As side effect the lchannel recycle timer
39 * will be started.
40 */
41#define LCHAN_RELEASE_TIMEOUT 4, 0
42#define use_lchan(lchan) \
43 do { lchan->use_count++; \
Holger Freyther4f584c32009-06-02 02:55:07 +000044 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
45 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
46 lchan->nr, lchan->use_count); \
Harald Welteff117a82009-05-23 05:22:08 +000047 bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
Holger Freytherc6ea9db2008-12-30 19:18:21 +000048
49#define put_lchan(lchan) \
Holger Freyther4f584c32009-06-02 02:55:07 +000050 do { lchan->use_count--; \
51 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
52 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
53 lchan->nr, lchan->use_count); \
54 } while(0);
55
Holger Freytherc6ea9db2008-12-30 19:18:21 +000056
Harald Welte52b1f982008-12-23 20:25:15 +000057/* communications link with a BTS */
58struct gsm_bts_link {
59 struct gsm_bts *bts;
60};
61
Harald Weltea3d04382008-12-27 17:02:56 +000062enum gsm_call_type {
63 GSM_CT_NONE,
64 GSM_CT_MO,
65 GSM_CT_MT,
66};
67
68enum gsm_call_state {
69 GSM_CSTATE_NULL,
70 GSM_CSTATE_INITIATED,
71 GSM_CSTATE_ACTIVE,
72 GSM_CSTATE_RELEASE_REQ,
73};
74
Harald Welte49f48b82009-02-17 15:29:33 +000075struct gsm_lchan;
76struct gsm_subscriber;
77
Harald Weltea3d04382008-12-27 17:02:56 +000078/* One end of a call */
79struct gsm_call {
80 enum gsm_call_type type;
81 enum gsm_call_state state;
82 u_int8_t transaction_id; /* 10.3.2 */
83
Harald Welte49f48b82009-02-17 15:29:33 +000084 /* the 'local' channel */
85 struct gsm_lchan *local_lchan;
86 /* the 'remote' channel */
87 struct gsm_lchan *remote_lchan;
88
Harald Welte0932d1e2009-02-16 22:53:52 +000089 /* the 'remote' subscriber */
90 struct gsm_subscriber *called_subscr;
Harald Weltea3d04382008-12-27 17:02:56 +000091};
92
93
Harald Welte8470bf22008-12-25 23:28:35 +000094enum gsm_phys_chan_config {
95 GSM_PCHAN_NONE,
96 GSM_PCHAN_CCCH,
97 GSM_PCHAN_CCCH_SDCCH4,
98 GSM_PCHAN_TCH_F,
99 GSM_PCHAN_TCH_H,
100 GSM_PCHAN_SDCCH8_SACCH8C,
101 GSM_PCHAN_UNKNOWN,
102};
103
104enum gsm_chan_t {
105 GSM_LCHAN_NONE,
106 GSM_LCHAN_SDCCH,
107 GSM_LCHAN_TCH_F,
108 GSM_LCHAN_TCH_H,
109 GSM_LCHAN_UNKNOWN,
110};
111
Harald Weltee14a57c2008-12-29 04:08:28 +0000112
113/* Channel Request reason */
114enum gsm_chreq_reason_t {
115 GSM_CHREQ_REASON_EMERG,
116 GSM_CHREQ_REASON_PAG,
117 GSM_CHREQ_REASON_CALL,
118 GSM_CHREQ_REASON_LOCATION_UPD,
119 GSM_CHREQ_REASON_OTHER,
120};
121
Harald Weltebbcc7a52009-02-14 19:45:44 +0000122/* Network Management State */
123struct gsm_nm_state {
124 u_int8_t operational;
125 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000126 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000127};
Harald Welte8c1d0e42009-02-15 03:38:12 +0000128struct gsm_attr {
129 u_int8_t len;
130 u_int8_t data[0];
131};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000132
Holger Freyther73487a22008-12-31 18:53:57 +0000133/*
134 * LOCATION UPDATING REQUEST state
135 *
136 * Our current operation is:
137 * - Get imei/tmsi
138 * - Accept/Reject according to global policy
139 */
140struct gsm_loc_updating_operation {
141 struct timer_list updating_timer;
142 int waiting_for_imsi : 1;
143 int waiting_for_imei : 1;
144};
145
Harald Welte8470bf22008-12-25 23:28:35 +0000146struct gsm_lchan {
147 /* The TS that we're part of */
148 struct gsm_bts_trx_ts *ts;
149 /* The logical subslot number in the TS */
150 u_int8_t nr;
Harald Welte45b407a2009-05-23 15:51:12 +0000151 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000152 enum gsm_chan_t type;
Harald Welte45b407a2009-05-23 15:51:12 +0000153 /* If TCH, traffic channel mode */
154 enum gsm_chan_t tch_mode;
Harald Welted4c9bf32009-02-15 16:56:18 +0000155 /* Power levels for MS and BTS */
156 u_int8_t bs_power;
157 u_int8_t ms_power;
158
Harald Welte8470bf22008-12-25 23:28:35 +0000159 /* To whom we are allocated at the moment */
160 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000161
162 /* Timer started to release the channel */
163 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000164
165 /* local end of a call, if any */
166 struct gsm_call call;
Holger Freyther3186bf22008-12-29 06:23:49 +0000167
168 /* temporary user data, to be removed... and merged into gsm_call */
169 void *user_data;
Holger Freytherb7193e42008-12-29 17:44:08 +0000170
Holger Freyther73487a22008-12-31 18:53:57 +0000171 /*
172 * Operations that have a state and might be pending
173 */
174 struct gsm_loc_updating_operation *loc_operation;
175
Holger Freytherb7193e42008-12-29 17:44:08 +0000176 /* use count. how many users use this channel */
177 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000178};
179
Harald Welte85770c72009-01-18 17:47:32 +0000180struct gsm_e1_subslot {
181 /* Number of E1 link */
182 u_int8_t e1_nr;
183 /* Number of E1 TS inside E1 link */
184 u_int8_t e1_ts;
185 /* Sub-slot within the E1 TS, 0xff if full TS */
186 u_int8_t e1_ts_ss;
187};
188
Harald Welte52b1f982008-12-23 20:25:15 +0000189#define BTS_TRX_F_ACTIVATED 0x0001
190/* One Timeslot in a TRX */
191struct gsm_bts_trx_ts {
192 struct gsm_bts_trx *trx;
193 /* number of this timeslot at the TRX */
194 u_int8_t nr;
195
Harald Welte8470bf22008-12-25 23:28:35 +0000196 enum gsm_phys_chan_config pchan;
197
Harald Welte52b1f982008-12-23 20:25:15 +0000198 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000199 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000200 struct gsm_attr *nm_attr;
Harald Welte8470bf22008-12-25 23:28:35 +0000201
Harald Welte85770c72009-01-18 17:47:32 +0000202 /* To which E1 subslot are we connected */
203 struct gsm_e1_subslot e1_link;
Harald Welte75099262009-02-16 21:12:08 +0000204 struct {
205 u_int32_t bound_ip;
206 u_int16_t bound_port;
207 u_int8_t attr_fc;
208 u_int16_t attr_f8;
209 } abis_ip;
Harald Welte85770c72009-01-18 17:47:32 +0000210
Harald Welte8470bf22008-12-25 23:28:35 +0000211 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000212};
213
214/* One TRX in a BTS */
215struct gsm_bts_trx {
216 struct gsm_bts *bts;
217 /* number of this TRX in the BTS */
218 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000219 /* how do we talk RSL with this TRX? */
220 struct e1inp_sign_link *rsl_link;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000221 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000222 struct gsm_attr *nm_attr;
223 struct {
224 struct gsm_nm_state nm_state;
225 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000226
227 u_int16_t arfcn;
Harald Welte8b697c72009-06-05 19:18:45 +0000228
229 union {
230 struct {
231 struct {
232 struct gsm_nm_state nm_state;
233 } bbsig;
234 struct {
235 struct gsm_nm_state nm_state;
236 } pa;
237 } bs11;
238 };
Harald Welte85770c72009-01-18 17:47:32 +0000239 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000240};
241
Harald Welte978cb422009-01-18 17:57:27 +0000242enum gsm_bts_type {
243 GSM_BTS_TYPE_UNKNOWN,
244 GSM_BTS_TYPE_BS11,
Harald Weltebbcc7a52009-02-14 19:45:44 +0000245 GSM_BTS_TYPE_NANOBTS_900,
246 GSM_BTS_TYPE_NANOBTS_1800,
Harald Welte978cb422009-01-18 17:57:27 +0000247};
248
Holger Freytherceb59b72009-02-06 18:54:00 +0000249/**
250 * A pending paging request
251 */
252struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000253 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000254 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000255 /* the subscriber which we're paging. Later gsm_paging_request
256 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000257 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000258 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000259 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000260 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000261 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000262
263 /* Timer 3113: how long do we try to page? */
264 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000265
266 /* callback to be called in case paging completes */
267 gsm_cbfn *cbfn;
268 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000269};
Harald Weltecd06bfb2009-02-10 17:33:56 +0000270#define T3113_VALUE 60, 0
Holger Freytherceb59b72009-02-06 18:54:00 +0000271
272/*
273 * This keeps track of the paging status of one BTS. It
274 * includes a number of pending requests, a back pointer
275 * to the gsm_bts, a timer and some more state.
276 */
277struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000278 /* pending requests */
279 struct llist_head pending_requests;
280 struct gsm_paging_request *last_request;
281 struct gsm_bts *bts;
282
Harald Welte75a1fa82009-02-17 01:39:41 +0000283 struct timer_list work_timer;
284
Holger Freyther392209c2009-02-10 00:06:19 +0000285 /* load */
286 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000287};
288
Harald Welte8b697c72009-06-05 19:18:45 +0000289struct gsm_envabtse {
290 struct gsm_nm_state nm_state;
291};
292
Harald Welte52b1f982008-12-23 20:25:15 +0000293/* One BTS */
294struct gsm_bts {
295 struct gsm_network *network;
296 /* number of ths BTS in network */
297 u_int8_t nr;
298 /* location area code of this BTS */
299 u_int8_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000300 /* Training Sequence Code */
301 u_int8_t tsc;
Harald Welte78f2f502009-05-23 16:56:52 +0000302 /* Base Station Identification Code (BSIC) */
303 u_int8_t bsic;
Harald Welte978cb422009-01-18 17:57:27 +0000304 /* type of BTS */
305 enum gsm_bts_type type;
Harald Welte1fa60c82009-02-09 18:13:26 +0000306 /* how do we talk OML with this TRX? */
307 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000308
309 /* Abis network management O&M handle */
310 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000311 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000312 struct gsm_attr *nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000313
Harald Welte52b1f982008-12-23 20:25:15 +0000314 /* number of this BTS on given E1 link */
315 u_int8_t bts_nr;
316
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000317 struct gsm48_control_channel_descr chan_desc;
318
Holger Freytherceb59b72009-02-06 18:54:00 +0000319 /* paging state and control */
320 struct gsm_bts_paging_state paging;
321
Harald Welte52b1f982008-12-23 20:25:15 +0000322 /* CCCH is on C0 */
323 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000324
325 struct {
326 struct gsm_nm_state nm_state;
327 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000328
329 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
Harald Welte7b26bcb2009-05-28 11:39:21 +0000330 union {
331 struct {
332 u_int16_t site_id;
333 u_int16_t bts_id;
334 } ip_access;
335 struct {
336 struct {
337 struct gsm_nm_state nm_state;
338 } cclk;
339 struct {
340 struct gsm_nm_state nm_state;
341 } rack;
Harald Welte8b697c72009-06-05 19:18:45 +0000342 struct gsm_envabtse envabtse[4];
Harald Welte7b26bcb2009-05-28 11:39:21 +0000343 } bs11;
344 };
Harald Weltebbcc7a52009-02-14 19:45:44 +0000345
Harald Welte52b1f982008-12-23 20:25:15 +0000346 /* transceivers */
347 int num_trx;
348 struct gsm_bts_trx trx[BTS_MAX_TRX+1];
349};
350
Harald Welte52b1f982008-12-23 20:25:15 +0000351struct gsm_network {
352 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000353 u_int16_t country_code;
354 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000355 char *name_long;
356 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000357
358 unsigned int num_bts;
359 /* private lists */
360 struct gsm_bts bts[GSM_MAX_BTS+1];
Harald Welte52b1f982008-12-23 20:25:15 +0000361};
362
Harald Welte7e310b12009-03-30 20:56:32 +0000363#define SMS_HDR_SIZE 128
364#define SMS_TEXT_SIZE 256
365struct gsm_sms {
366 u_int64_t id;
367 struct gsm_subscriber *sender;
368 struct gsm_subscriber *receiver;
369
370 unsigned char header[SMS_HDR_SIZE];
371 char text[SMS_TEXT_SIZE];
372};
373
Harald Welte8c1d0e42009-02-15 03:38:12 +0000374struct gsm_network *gsm_network_init(unsigned int num_bts, enum gsm_bts_type bts_type,
375 u_int16_t country_code, u_int16_t network_code);
Harald Welte8470bf22008-12-25 23:28:35 +0000376
Harald Weltea72c98e2009-01-04 16:10:38 +0000377const char *gsm_pchan_name(enum gsm_phys_chan_config c);
378const char *gsm_lchan_name(enum gsm_chan_t c);
379const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte23a68632009-02-19 17:06:42 +0000380char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Weltea72c98e2009-01-04 16:10:38 +0000381
Harald Weltead384642008-12-26 10:20:07 +0000382enum gsm_e1_event {
383 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000384 EVT_E1_TEI_UP,
385 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000386};
387
Harald Weltecd06bfb2009-02-10 17:33:56 +0000388void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
389 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte32201c12009-03-10 12:15:10 +0000390enum gsm_bts_type parse_btstype(char *arg);
391char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000392struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
393 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000394
395static inline int is_ipaccess_bts(struct gsm_bts *bts)
396{
397 switch (bts->type) {
398 case GSM_BTS_TYPE_NANOBTS_900:
399 case GSM_BTS_TYPE_NANOBTS_1800:
400 return 1;
401 default:
402 break;
403 }
404 return 0;
405}
406
Harald Welte52b1f982008-12-23 20:25:15 +0000407#endif