blob: cc92a9e35492831e25bc1e4d9509d2bc7e6182ee [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 Welte4bfdfe72009-06-10 23:11:52 +08006enum gsm_phys_chan_config {
7 GSM_PCHAN_NONE,
8 GSM_PCHAN_CCCH,
9 GSM_PCHAN_CCCH_SDCCH4,
10 GSM_PCHAN_TCH_F,
11 GSM_PCHAN_TCH_H,
12 GSM_PCHAN_SDCCH8_SACCH8C,
13 GSM_PCHAN_UNKNOWN,
14};
15
16enum gsm_chan_t {
17 GSM_LCHAN_NONE,
18 GSM_LCHAN_SDCCH,
19 GSM_LCHAN_TCH_F,
20 GSM_LCHAN_TCH_H,
21 GSM_LCHAN_UNKNOWN,
22};
23
24
25/* Channel Request reason */
26enum gsm_chreq_reason_t {
27 GSM_CHREQ_REASON_EMERG,
28 GSM_CHREQ_REASON_PAG,
29 GSM_CHREQ_REASON_CALL,
30 GSM_CHREQ_REASON_LOCATION_UPD,
31 GSM_CHREQ_REASON_OTHER,
32};
33
Harald Welte255539c2008-12-28 02:26:27 +000034#include <openbsc/timer.h>
Holger Freyther1adb4ff2009-02-04 00:04:52 +000035#include <openbsc/gsm_04_08.h>
Harald Welte4bfdfe72009-06-10 23:11:52 +080036#include <openbsc/mncc.h>
Harald Welte255539c2008-12-28 02:26:27 +000037
Harald Welte8470bf22008-12-25 23:28:35 +000038#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
39
Harald Welte52b1f982008-12-23 20:25:15 +000040#define GSM_MAX_BTS 8
41#define BTS_MAX_TRX 8
Harald Welte85770c72009-01-18 17:47:32 +000042#define TRX_NR_TS 8
Harald Welte8470bf22008-12-25 23:28:35 +000043#define TS_MAX_LCHAN 8
Harald Welte52b1f982008-12-23 20:25:15 +000044
45#define HARDCODED_ARFCN 123
Harald Welte02b0e092009-02-28 13:11:07 +000046#define HARDCODED_TSC 7
Harald Welte78f2f502009-05-23 16:56:52 +000047#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
Harald Welte52b1f982008-12-23 20:25:15 +000048
Harald Welte8e1e3ee2009-02-01 13:32:45 +000049enum gsm_hooks {
50 GSM_HOOK_NM_SWLOAD,
Harald Welte0932d1e2009-02-16 22:53:52 +000051 GSM_HOOK_RR_PAGING,
52};
53
54enum gsm_paging_event {
55 GSM_PAGING_SUCCEEDED,
56 GSM_PAGING_EXPIRED,
Holger Freyther85a7b362009-04-18 13:48:55 +020057 GSM_PAGING_OOM,
Harald Welte8e1e3ee2009-02-01 13:32:45 +000058};
59
60struct msgb;
61typedef int gsm_cbfn(unsigned int hooknum,
62 unsigned int event,
63 struct msgb *msg,
64 void *data, void *param);
65
Holger Freytherc6ea9db2008-12-30 19:18:21 +000066/*
67 * Use the channel. As side effect the lchannel recycle timer
68 * will be started.
69 */
70#define LCHAN_RELEASE_TIMEOUT 4, 0
71#define use_lchan(lchan) \
72 do { lchan->use_count++; \
Holger Freyther4f584c32009-06-02 02:55:07 +000073 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
74 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
75 lchan->nr, lchan->use_count); \
Harald Welteff117a82009-05-23 05:22:08 +000076 bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
Holger Freytherc6ea9db2008-12-30 19:18:21 +000077
78#define put_lchan(lchan) \
Holger Freyther4f584c32009-06-02 02:55:07 +000079 do { lchan->use_count--; \
80 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
81 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
82 lchan->nr, lchan->use_count); \
83 } while(0);
84
Holger Freytherc6ea9db2008-12-30 19:18:21 +000085
Harald Welte52b1f982008-12-23 20:25:15 +000086/* communications link with a BTS */
87struct gsm_bts_link {
88 struct gsm_bts *bts;
89};
90
Harald Welte49f48b82009-02-17 15:29:33 +000091struct gsm_lchan;
92struct gsm_subscriber;
Harald Welte4bfdfe72009-06-10 23:11:52 +080093struct gsm_mncc;
Harald Welte49f48b82009-02-17 15:29:33 +000094
Harald Welte4bfdfe72009-06-10 23:11:52 +080095/* One transaction */
96struct gsm_trans {
97 /* Entry in list of all transactions */
98 struct llist_head entry;
Harald Weltea3d04382008-12-27 17:02:56 +000099
Harald Welte4bfdfe72009-06-10 23:11:52 +0800100 /* Network */
101 struct gsm_network *network;
Harald Welte49f48b82009-02-17 15:29:33 +0000102
Harald Welte4bfdfe72009-06-10 23:11:52 +0800103 /* The current transaction ID */
104 u_int8_t transaction_id;
105
106 /* The LCHAN that we're part of */
107 struct gsm_lchan *lchan;
108
109 /* To whom we are allocated at the moment */
110 struct gsm_subscriber *subscr;
111
112 /* reference */
113 u_int32_t callref;
114
115 /* current call state */
116 int state;
117
118 /* current timer and message queue */
119 int Tcurrent; /* current CC timer */
120 int T308_second; /* used to send release again */
121 struct timer_list cc_timer;
122 struct gsm_mncc cc_msg; /* stores setup/disconnect/release message */
Harald Weltea3d04382008-12-27 17:02:56 +0000123};
124
125
Harald Weltebbcc7a52009-02-14 19:45:44 +0000126/* Network Management State */
127struct gsm_nm_state {
128 u_int8_t operational;
129 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000130 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000131};
Harald Welte8c1d0e42009-02-15 03:38:12 +0000132struct gsm_attr {
133 u_int8_t len;
134 u_int8_t data[0];
135};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000136
Holger Freyther73487a22008-12-31 18:53:57 +0000137/*
138 * LOCATION UPDATING REQUEST state
139 *
140 * Our current operation is:
141 * - Get imei/tmsi
142 * - Accept/Reject according to global policy
143 */
144struct gsm_loc_updating_operation {
145 struct timer_list updating_timer;
146 int waiting_for_imsi : 1;
147 int waiting_for_imei : 1;
148};
149
Harald Welte8470bf22008-12-25 23:28:35 +0000150struct gsm_lchan {
151 /* The TS that we're part of */
152 struct gsm_bts_trx_ts *ts;
153 /* The logical subslot number in the TS */
154 u_int8_t nr;
Harald Welte45b407a2009-05-23 15:51:12 +0000155 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000156 enum gsm_chan_t type;
Harald Welte45b407a2009-05-23 15:51:12 +0000157 /* If TCH, traffic channel mode */
158 enum gsm_chan_t tch_mode;
Harald Welted4c9bf32009-02-15 16:56:18 +0000159 /* Power levels for MS and BTS */
160 u_int8_t bs_power;
161 u_int8_t ms_power;
162
Harald Welte8470bf22008-12-25 23:28:35 +0000163 /* To whom we are allocated at the moment */
164 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000165
166 /* Timer started to release the channel */
167 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000168
Holger Freyther73487a22008-12-31 18:53:57 +0000169 /*
170 * Operations that have a state and might be pending
171 */
172 struct gsm_loc_updating_operation *loc_operation;
173
Holger Freytherb7193e42008-12-29 17:44:08 +0000174 /* use count. how many users use this channel */
175 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000176};
177
Harald Welte85770c72009-01-18 17:47:32 +0000178struct gsm_e1_subslot {
179 /* Number of E1 link */
180 u_int8_t e1_nr;
181 /* Number of E1 TS inside E1 link */
182 u_int8_t e1_ts;
183 /* Sub-slot within the E1 TS, 0xff if full TS */
184 u_int8_t e1_ts_ss;
185};
186
Harald Welte52b1f982008-12-23 20:25:15 +0000187#define BTS_TRX_F_ACTIVATED 0x0001
188/* One Timeslot in a TRX */
189struct gsm_bts_trx_ts {
190 struct gsm_bts_trx *trx;
191 /* number of this timeslot at the TRX */
192 u_int8_t nr;
193
Harald Welte8470bf22008-12-25 23:28:35 +0000194 enum gsm_phys_chan_config pchan;
195
Harald Welte52b1f982008-12-23 20:25:15 +0000196 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000197 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000198 struct gsm_attr *nm_attr;
Harald Welte8470bf22008-12-25 23:28:35 +0000199
Harald Welte85770c72009-01-18 17:47:32 +0000200 /* To which E1 subslot are we connected */
201 struct gsm_e1_subslot e1_link;
Harald Welte75099262009-02-16 21:12:08 +0000202 struct {
203 u_int32_t bound_ip;
204 u_int16_t bound_port;
205 u_int8_t attr_fc;
206 u_int16_t attr_f8;
207 } abis_ip;
Harald Welte85770c72009-01-18 17:47:32 +0000208
Harald Welte8470bf22008-12-25 23:28:35 +0000209 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000210};
211
212/* One TRX in a BTS */
213struct gsm_bts_trx {
214 struct gsm_bts *bts;
215 /* number of this TRX in the BTS */
216 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000217 /* how do we talk RSL with this TRX? */
218 struct e1inp_sign_link *rsl_link;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000219 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000220 struct gsm_attr *nm_attr;
221 struct {
222 struct gsm_nm_state nm_state;
223 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000224
225 u_int16_t arfcn;
Harald Welte8b697c72009-06-05 19:18:45 +0000226
227 union {
228 struct {
229 struct {
230 struct gsm_nm_state nm_state;
231 } bbsig;
232 struct {
233 struct gsm_nm_state nm_state;
234 } pa;
235 } bs11;
236 };
Harald Welte85770c72009-01-18 17:47:32 +0000237 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000238};
239
Harald Welte978cb422009-01-18 17:57:27 +0000240enum gsm_bts_type {
241 GSM_BTS_TYPE_UNKNOWN,
242 GSM_BTS_TYPE_BS11,
Harald Weltebbcc7a52009-02-14 19:45:44 +0000243 GSM_BTS_TYPE_NANOBTS_900,
244 GSM_BTS_TYPE_NANOBTS_1800,
Harald Welte978cb422009-01-18 17:57:27 +0000245};
246
Holger Freytherceb59b72009-02-06 18:54:00 +0000247/**
248 * A pending paging request
249 */
250struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000251 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000252 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000253 /* the subscriber which we're paging. Later gsm_paging_request
254 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000255 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000256 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000257 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000258 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000259 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000260
261 /* Timer 3113: how long do we try to page? */
262 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000263
264 /* callback to be called in case paging completes */
265 gsm_cbfn *cbfn;
266 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000267};
Harald Weltecd06bfb2009-02-10 17:33:56 +0000268#define T3113_VALUE 60, 0
Holger Freytherceb59b72009-02-06 18:54:00 +0000269
270/*
271 * This keeps track of the paging status of one BTS. It
272 * includes a number of pending requests, a back pointer
273 * to the gsm_bts, a timer and some more state.
274 */
275struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000276 /* pending requests */
277 struct llist_head pending_requests;
278 struct gsm_paging_request *last_request;
279 struct gsm_bts *bts;
280
Harald Welte75a1fa82009-02-17 01:39:41 +0000281 struct timer_list work_timer;
282
Holger Freyther392209c2009-02-10 00:06:19 +0000283 /* load */
284 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000285};
286
Harald Welte8b697c72009-06-05 19:18:45 +0000287struct gsm_envabtse {
288 struct gsm_nm_state nm_state;
289};
290
Harald Welte52b1f982008-12-23 20:25:15 +0000291/* One BTS */
292struct gsm_bts {
293 struct gsm_network *network;
294 /* number of ths BTS in network */
295 u_int8_t nr;
296 /* location area code of this BTS */
297 u_int8_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000298 /* Training Sequence Code */
299 u_int8_t tsc;
Harald Welte78f2f502009-05-23 16:56:52 +0000300 /* Base Station Identification Code (BSIC) */
301 u_int8_t bsic;
Harald Welte978cb422009-01-18 17:57:27 +0000302 /* type of BTS */
303 enum gsm_bts_type type;
Harald Welte1fa60c82009-02-09 18:13:26 +0000304 /* how do we talk OML with this TRX? */
305 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000306
307 /* Abis network management O&M handle */
308 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000309 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000310 struct gsm_attr *nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000311
Harald Welte52b1f982008-12-23 20:25:15 +0000312 /* number of this BTS on given E1 link */
313 u_int8_t bts_nr;
314
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000315 struct gsm48_control_channel_descr chan_desc;
316
Holger Freytherceb59b72009-02-06 18:54:00 +0000317 /* paging state and control */
318 struct gsm_bts_paging_state paging;
319
Harald Welte52b1f982008-12-23 20:25:15 +0000320 /* CCCH is on C0 */
321 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000322
323 struct {
324 struct gsm_nm_state nm_state;
325 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000326
327 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
Harald Welte7b26bcb2009-05-28 11:39:21 +0000328 union {
329 struct {
330 u_int16_t site_id;
331 u_int16_t bts_id;
332 } ip_access;
333 struct {
334 struct {
335 struct gsm_nm_state nm_state;
336 } cclk;
337 struct {
338 struct gsm_nm_state nm_state;
339 } rack;
Harald Welte8b697c72009-06-05 19:18:45 +0000340 struct gsm_envabtse envabtse[4];
Harald Welte7b26bcb2009-05-28 11:39:21 +0000341 } bs11;
342 };
Harald Weltebbcc7a52009-02-14 19:45:44 +0000343
Harald Welte52b1f982008-12-23 20:25:15 +0000344 /* transceivers */
345 int num_trx;
346 struct gsm_bts_trx trx[BTS_MAX_TRX+1];
347};
348
Harald Welte52b1f982008-12-23 20:25:15 +0000349struct gsm_network {
350 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000351 u_int16_t country_code;
352 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000353 char *name_long;
354 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000355
Harald Welte4bfdfe72009-06-10 23:11:52 +0800356 /* layer 4 */
357 int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
358 struct llist_head upqueue;
359 struct llist_head trans_list;
360
Harald Welte52b1f982008-12-23 20:25:15 +0000361 unsigned int num_bts;
362 /* private lists */
363 struct gsm_bts bts[GSM_MAX_BTS+1];
Harald Welte52b1f982008-12-23 20:25:15 +0000364};
365
Harald Welte7e310b12009-03-30 20:56:32 +0000366#define SMS_HDR_SIZE 128
367#define SMS_TEXT_SIZE 256
368struct gsm_sms {
369 u_int64_t id;
370 struct gsm_subscriber *sender;
371 struct gsm_subscriber *receiver;
372
373 unsigned char header[SMS_HDR_SIZE];
374 char text[SMS_TEXT_SIZE];
375};
376
Harald Welte8c1d0e42009-02-15 03:38:12 +0000377struct gsm_network *gsm_network_init(unsigned int num_bts, enum gsm_bts_type bts_type,
Harald Welte4bfdfe72009-06-10 23:11:52 +0800378 u_int16_t country_code, u_int16_t network_code,
379 int (*mncc_recv)(struct gsm_network *, int, void *));
Harald Welte8470bf22008-12-25 23:28:35 +0000380
Harald Weltea72c98e2009-01-04 16:10:38 +0000381const char *gsm_pchan_name(enum gsm_phys_chan_config c);
382const char *gsm_lchan_name(enum gsm_chan_t c);
383const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte23a68632009-02-19 17:06:42 +0000384char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Weltea72c98e2009-01-04 16:10:38 +0000385
Harald Weltead384642008-12-26 10:20:07 +0000386enum gsm_e1_event {
387 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000388 EVT_E1_TEI_UP,
389 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000390};
391
Harald Weltecd06bfb2009-02-10 17:33:56 +0000392void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
393 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte32201c12009-03-10 12:15:10 +0000394enum gsm_bts_type parse_btstype(char *arg);
395char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000396struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
397 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000398
399static inline int is_ipaccess_bts(struct gsm_bts *bts)
400{
401 switch (bts->type) {
402 case GSM_BTS_TYPE_NANOBTS_900:
403 case GSM_BTS_TYPE_NANOBTS_1800:
404 return 1;
405 default:
406 break;
407 }
408 return 0;
409}
410
Harald Welte52b1f982008-12-23 20:25:15 +0000411#endif