blob: 54ce7e6fdad3e8756b2186ed2cd2df731c00ed2b [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 Weltefcd24452009-06-20 18:15:19 +02006enum gsm_band {
7 GSM_BAND_400,
8 GSM_BAND_850,
9 GSM_BAND_900,
10 GSM_BAND_1800,
11 GSM_BAND_1900,
12};
13
Harald Welte4bfdfe72009-06-10 23:11:52 +080014enum gsm_phys_chan_config {
15 GSM_PCHAN_NONE,
16 GSM_PCHAN_CCCH,
17 GSM_PCHAN_CCCH_SDCCH4,
18 GSM_PCHAN_TCH_F,
19 GSM_PCHAN_TCH_H,
20 GSM_PCHAN_SDCCH8_SACCH8C,
21 GSM_PCHAN_UNKNOWN,
22};
23
24enum gsm_chan_t {
25 GSM_LCHAN_NONE,
26 GSM_LCHAN_SDCCH,
27 GSM_LCHAN_TCH_F,
28 GSM_LCHAN_TCH_H,
29 GSM_LCHAN_UNKNOWN,
30};
31
32
33/* Channel Request reason */
34enum gsm_chreq_reason_t {
35 GSM_CHREQ_REASON_EMERG,
36 GSM_CHREQ_REASON_PAG,
37 GSM_CHREQ_REASON_CALL,
38 GSM_CHREQ_REASON_LOCATION_UPD,
39 GSM_CHREQ_REASON_OTHER,
40};
41
Harald Welte255539c2008-12-28 02:26:27 +000042#include <openbsc/timer.h>
Holger Freyther1adb4ff2009-02-04 00:04:52 +000043#include <openbsc/gsm_04_08.h>
Harald Welte4bfdfe72009-06-10 23:11:52 +080044#include <openbsc/mncc.h>
Harald Welte93e9d172009-06-20 19:04:31 +020045#include <openbsc/tlv.h>
Harald Welte255539c2008-12-28 02:26:27 +000046
Harald Welte8470bf22008-12-25 23:28:35 +000047#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
48
Harald Welte52b1f982008-12-23 20:25:15 +000049#define GSM_MAX_BTS 8
50#define BTS_MAX_TRX 8
Harald Welte85770c72009-01-18 17:47:32 +000051#define TRX_NR_TS 8
Harald Welte8470bf22008-12-25 23:28:35 +000052#define TS_MAX_LCHAN 8
Harald Welte52b1f982008-12-23 20:25:15 +000053
54#define HARDCODED_ARFCN 123
Harald Welte02b0e092009-02-28 13:11:07 +000055#define HARDCODED_TSC 7
Harald Welte78f2f502009-05-23 16:56:52 +000056#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
Harald Welte52b1f982008-12-23 20:25:15 +000057
Harald Welte8e1e3ee2009-02-01 13:32:45 +000058enum gsm_hooks {
59 GSM_HOOK_NM_SWLOAD,
Harald Welte0932d1e2009-02-16 22:53:52 +000060 GSM_HOOK_RR_PAGING,
61};
62
63enum gsm_paging_event {
64 GSM_PAGING_SUCCEEDED,
65 GSM_PAGING_EXPIRED,
Holger Freyther85a7b362009-04-18 13:48:55 +020066 GSM_PAGING_OOM,
Harald Welte8e1e3ee2009-02-01 13:32:45 +000067};
68
69struct msgb;
70typedef int gsm_cbfn(unsigned int hooknum,
71 unsigned int event,
72 struct msgb *msg,
73 void *data, void *param);
74
Holger Freytherc6ea9db2008-12-30 19:18:21 +000075/*
76 * Use the channel. As side effect the lchannel recycle timer
77 * will be started.
78 */
Harald Welteb8955072009-06-12 02:41:10 +080079#define LCHAN_RELEASE_TIMEOUT 10, 0
Holger Freytherc6ea9db2008-12-30 19:18:21 +000080#define use_lchan(lchan) \
81 do { lchan->use_count++; \
Holger Freyther4f584c32009-06-02 02:55:07 +000082 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
83 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
84 lchan->nr, lchan->use_count); \
Harald Welteff117a82009-05-23 05:22:08 +000085 bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
Holger Freytherc6ea9db2008-12-30 19:18:21 +000086
87#define put_lchan(lchan) \
Holger Freyther4f584c32009-06-02 02:55:07 +000088 do { lchan->use_count--; \
89 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
90 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
91 lchan->nr, lchan->use_count); \
92 } while(0);
93
Holger Freytherc6ea9db2008-12-30 19:18:21 +000094
Harald Welte52b1f982008-12-23 20:25:15 +000095/* communications link with a BTS */
96struct gsm_bts_link {
97 struct gsm_bts *bts;
98};
99
Harald Welte49f48b82009-02-17 15:29:33 +0000100struct gsm_lchan;
101struct gsm_subscriber;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800102struct gsm_mncc;
Harald Welte49f48b82009-02-17 15:29:33 +0000103
Harald Welte4bfdfe72009-06-10 23:11:52 +0800104/* One transaction */
105struct gsm_trans {
106 /* Entry in list of all transactions */
107 struct llist_head entry;
Harald Weltea3d04382008-12-27 17:02:56 +0000108
Harald Welte4bfdfe72009-06-10 23:11:52 +0800109 /* Network */
110 struct gsm_network *network;
Harald Welte49f48b82009-02-17 15:29:33 +0000111
Harald Welte4bfdfe72009-06-10 23:11:52 +0800112 /* The current transaction ID */
113 u_int8_t transaction_id;
114
115 /* The LCHAN that we're part of */
116 struct gsm_lchan *lchan;
117
118 /* To whom we are allocated at the moment */
119 struct gsm_subscriber *subscr;
120
121 /* reference */
122 u_int32_t callref;
123
124 /* current call state */
125 int state;
126
127 /* current timer and message queue */
128 int Tcurrent; /* current CC timer */
129 int T308_second; /* used to send release again */
130 struct timer_list cc_timer;
131 struct gsm_mncc cc_msg; /* stores setup/disconnect/release message */
Harald Weltea3d04382008-12-27 17:02:56 +0000132};
133
134
Harald Weltebbcc7a52009-02-14 19:45:44 +0000135/* Network Management State */
136struct gsm_nm_state {
137 u_int8_t operational;
138 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000139 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000140};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000141
Holger Freyther73487a22008-12-31 18:53:57 +0000142/*
143 * LOCATION UPDATING REQUEST state
144 *
145 * Our current operation is:
146 * - Get imei/tmsi
147 * - Accept/Reject according to global policy
148 */
149struct gsm_loc_updating_operation {
150 struct timer_list updating_timer;
151 int waiting_for_imsi : 1;
152 int waiting_for_imei : 1;
153};
154
Harald Welte8470bf22008-12-25 23:28:35 +0000155struct gsm_lchan {
156 /* The TS that we're part of */
157 struct gsm_bts_trx_ts *ts;
158 /* The logical subslot number in the TS */
159 u_int8_t nr;
Harald Welte45b407a2009-05-23 15:51:12 +0000160 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000161 enum gsm_chan_t type;
Harald Welte45b407a2009-05-23 15:51:12 +0000162 /* If TCH, traffic channel mode */
163 enum gsm_chan_t tch_mode;
Harald Welted4c9bf32009-02-15 16:56:18 +0000164 /* Power levels for MS and BTS */
165 u_int8_t bs_power;
166 u_int8_t ms_power;
167
Harald Welte8470bf22008-12-25 23:28:35 +0000168 /* To whom we are allocated at the moment */
169 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000170
171 /* Timer started to release the channel */
172 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000173
Holger Freyther73487a22008-12-31 18:53:57 +0000174 /*
175 * Operations that have a state and might be pending
176 */
177 struct gsm_loc_updating_operation *loc_operation;
178
Holger Freytherb7193e42008-12-29 17:44:08 +0000179 /* use count. how many users use this channel */
180 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000181};
182
Harald Welte85770c72009-01-18 17:47:32 +0000183struct gsm_e1_subslot {
184 /* Number of E1 link */
185 u_int8_t e1_nr;
186 /* Number of E1 TS inside E1 link */
187 u_int8_t e1_ts;
188 /* Sub-slot within the E1 TS, 0xff if full TS */
189 u_int8_t e1_ts_ss;
190};
191
Harald Welte52b1f982008-12-23 20:25:15 +0000192#define BTS_TRX_F_ACTIVATED 0x0001
193/* One Timeslot in a TRX */
194struct gsm_bts_trx_ts {
195 struct gsm_bts_trx *trx;
196 /* number of this timeslot at the TRX */
197 u_int8_t nr;
198
Harald Welte8470bf22008-12-25 23:28:35 +0000199 enum gsm_phys_chan_config pchan;
200
Harald Welte52b1f982008-12-23 20:25:15 +0000201 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000202 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200203 struct tlv_parsed nm_attr;
Harald Welte8470bf22008-12-25 23:28:35 +0000204
Harald Welte85770c72009-01-18 17:47:32 +0000205 /* To which E1 subslot are we connected */
206 struct gsm_e1_subslot e1_link;
Harald Welte75099262009-02-16 21:12:08 +0000207 struct {
208 u_int32_t bound_ip;
209 u_int16_t bound_port;
210 u_int8_t attr_fc;
211 u_int16_t attr_f8;
212 } abis_ip;
Harald Welte85770c72009-01-18 17:47:32 +0000213
Harald Welte8470bf22008-12-25 23:28:35 +0000214 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000215};
216
217/* One TRX in a BTS */
218struct gsm_bts_trx {
219 struct gsm_bts *bts;
220 /* number of this TRX in the BTS */
221 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000222 /* how do we talk RSL with this TRX? */
223 struct e1inp_sign_link *rsl_link;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000224 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200225 struct tlv_parsed nm_attr;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000226 struct {
227 struct gsm_nm_state nm_state;
228 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000229
230 u_int16_t arfcn;
Harald Weltefcd24452009-06-20 18:15:19 +0200231 int nominal_power; /* in dBm */
232 unsigned int max_power_red; /* in actual dB */
Harald Welte8b697c72009-06-05 19:18:45 +0000233
234 union {
235 struct {
236 struct {
237 struct gsm_nm_state nm_state;
238 } bbsig;
239 struct {
240 struct gsm_nm_state nm_state;
241 } pa;
242 } bs11;
243 };
Harald Welte85770c72009-01-18 17:47:32 +0000244 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000245};
246
Harald Welte978cb422009-01-18 17:57:27 +0000247enum gsm_bts_type {
248 GSM_BTS_TYPE_UNKNOWN,
249 GSM_BTS_TYPE_BS11,
Harald Weltebbcc7a52009-02-14 19:45:44 +0000250 GSM_BTS_TYPE_NANOBTS_900,
251 GSM_BTS_TYPE_NANOBTS_1800,
Harald Welte978cb422009-01-18 17:57:27 +0000252};
253
Holger Freytherceb59b72009-02-06 18:54:00 +0000254/**
255 * A pending paging request
256 */
257struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000258 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000259 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000260 /* the subscriber which we're paging. Later gsm_paging_request
261 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000262 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000263 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000264 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000265 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000266 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000267
268 /* Timer 3113: how long do we try to page? */
269 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000270
271 /* callback to be called in case paging completes */
272 gsm_cbfn *cbfn;
273 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000274};
Harald Weltecd06bfb2009-02-10 17:33:56 +0000275#define T3113_VALUE 60, 0
Holger Freytherceb59b72009-02-06 18:54:00 +0000276
277/*
278 * This keeps track of the paging status of one BTS. It
279 * includes a number of pending requests, a back pointer
280 * to the gsm_bts, a timer and some more state.
281 */
282struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000283 /* pending requests */
284 struct llist_head pending_requests;
285 struct gsm_paging_request *last_request;
286 struct gsm_bts *bts;
287
Harald Welte75a1fa82009-02-17 01:39:41 +0000288 struct timer_list work_timer;
289
Holger Freyther392209c2009-02-10 00:06:19 +0000290 /* load */
291 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000292};
293
Harald Welte8b697c72009-06-05 19:18:45 +0000294struct gsm_envabtse {
295 struct gsm_nm_state nm_state;
296};
297
Harald Welte52b1f982008-12-23 20:25:15 +0000298/* One BTS */
299struct gsm_bts {
300 struct gsm_network *network;
301 /* number of ths BTS in network */
302 u_int8_t nr;
303 /* location area code of this BTS */
304 u_int8_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000305 /* Training Sequence Code */
306 u_int8_t tsc;
Harald Welte78f2f502009-05-23 16:56:52 +0000307 /* Base Station Identification Code (BSIC) */
308 u_int8_t bsic;
Harald Welte978cb422009-01-18 17:57:27 +0000309 /* type of BTS */
310 enum gsm_bts_type type;
Harald Weltefcd24452009-06-20 18:15:19 +0200311 enum gsm_band band;
Harald Welte1fa60c82009-02-09 18:13:26 +0000312 /* how do we talk OML with this TRX? */
313 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000314
315 /* Abis network management O&M handle */
316 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000317 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200318 struct tlv_parsed nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000319
Harald Welte52b1f982008-12-23 20:25:15 +0000320 /* number of this BTS on given E1 link */
321 u_int8_t bts_nr;
322
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000323 struct gsm48_control_channel_descr chan_desc;
324
Holger Freytherceb59b72009-02-06 18:54:00 +0000325 /* paging state and control */
326 struct gsm_bts_paging_state paging;
327
Harald Welte52b1f982008-12-23 20:25:15 +0000328 /* CCCH is on C0 */
329 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000330
331 struct {
332 struct gsm_nm_state nm_state;
333 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000334
335 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
Harald Welte7b26bcb2009-05-28 11:39:21 +0000336 union {
337 struct {
338 u_int16_t site_id;
339 u_int16_t bts_id;
340 } ip_access;
341 struct {
342 struct {
343 struct gsm_nm_state nm_state;
344 } cclk;
345 struct {
346 struct gsm_nm_state nm_state;
347 } rack;
Harald Welte8b697c72009-06-05 19:18:45 +0000348 struct gsm_envabtse envabtse[4];
Harald Welte7b26bcb2009-05-28 11:39:21 +0000349 } bs11;
350 };
Harald Weltebbcc7a52009-02-14 19:45:44 +0000351
Harald Welte52b1f982008-12-23 20:25:15 +0000352 /* transceivers */
353 int num_trx;
354 struct gsm_bts_trx trx[BTS_MAX_TRX+1];
355};
356
Harald Welte52b1f982008-12-23 20:25:15 +0000357struct gsm_network {
358 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000359 u_int16_t country_code;
360 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000361 char *name_long;
362 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000363
Harald Welte4bfdfe72009-06-10 23:11:52 +0800364 /* layer 4 */
365 int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
366 struct llist_head upqueue;
367 struct llist_head trans_list;
368
Harald Welte52b1f982008-12-23 20:25:15 +0000369 unsigned int num_bts;
370 /* private lists */
371 struct gsm_bts bts[GSM_MAX_BTS+1];
Harald Welte52b1f982008-12-23 20:25:15 +0000372};
373
Harald Welte7e310b12009-03-30 20:56:32 +0000374#define SMS_HDR_SIZE 128
375#define SMS_TEXT_SIZE 256
376struct gsm_sms {
377 u_int64_t id;
378 struct gsm_subscriber *sender;
379 struct gsm_subscriber *receiver;
380
381 unsigned char header[SMS_HDR_SIZE];
382 char text[SMS_TEXT_SIZE];
383};
384
Harald Welte8c1d0e42009-02-15 03:38:12 +0000385struct gsm_network *gsm_network_init(unsigned int num_bts, enum gsm_bts_type bts_type,
Harald Welte4bfdfe72009-06-10 23:11:52 +0800386 u_int16_t country_code, u_int16_t network_code,
387 int (*mncc_recv)(struct gsm_network *, int, void *));
Harald Welte8470bf22008-12-25 23:28:35 +0000388
Harald Weltea72c98e2009-01-04 16:10:38 +0000389const char *gsm_pchan_name(enum gsm_phys_chan_config c);
390const char *gsm_lchan_name(enum gsm_chan_t c);
391const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte23a68632009-02-19 17:06:42 +0000392char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Weltea72c98e2009-01-04 16:10:38 +0000393
Harald Weltead384642008-12-26 10:20:07 +0000394enum gsm_e1_event {
395 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000396 EVT_E1_TEI_UP,
397 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000398};
399
Harald Weltecd06bfb2009-02-10 17:33:56 +0000400void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
401 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte32201c12009-03-10 12:15:10 +0000402enum gsm_bts_type parse_btstype(char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200403const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000404struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
405 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000406
Harald Weltefcd24452009-06-20 18:15:19 +0200407char *gsm_band_name(enum gsm_band band);
408enum gsm_band gsm_band_parse(int mhz);
409
Harald Welte32201c12009-03-10 12:15:10 +0000410static inline int is_ipaccess_bts(struct gsm_bts *bts)
411{
412 switch (bts->type) {
413 case GSM_BTS_TYPE_NANOBTS_900:
414 case GSM_BTS_TYPE_NANOBTS_1800:
415 return 1;
416 default:
417 break;
418 }
419 return 0;
420}
421
Harald Welte52b1f982008-12-23 20:25:15 +0000422#endif