blob: 9b4cf9df373521131ee7c21d5759a01453547054 [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 Welte85770c72009-01-18 17:47:32 +000049#define TRX_NR_TS 8
Harald Welte8470bf22008-12-25 23:28:35 +000050#define TS_MAX_LCHAN 8
Harald Welte52b1f982008-12-23 20:25:15 +000051
52#define HARDCODED_ARFCN 123
Harald Welte02b0e092009-02-28 13:11:07 +000053#define HARDCODED_TSC 7
Harald Welte78f2f502009-05-23 16:56:52 +000054#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
Harald Welte52b1f982008-12-23 20:25:15 +000055
Harald Welte8e1e3ee2009-02-01 13:32:45 +000056enum gsm_hooks {
57 GSM_HOOK_NM_SWLOAD,
Harald Welte0932d1e2009-02-16 22:53:52 +000058 GSM_HOOK_RR_PAGING,
59};
60
61enum gsm_paging_event {
62 GSM_PAGING_SUCCEEDED,
63 GSM_PAGING_EXPIRED,
Holger Freyther85a7b362009-04-18 13:48:55 +020064 GSM_PAGING_OOM,
Harald Welte8e1e3ee2009-02-01 13:32:45 +000065};
66
67struct msgb;
68typedef int gsm_cbfn(unsigned int hooknum,
69 unsigned int event,
70 struct msgb *msg,
71 void *data, void *param);
72
Holger Freytherc6ea9db2008-12-30 19:18:21 +000073/*
74 * Use the channel. As side effect the lchannel recycle timer
75 * will be started.
76 */
Harald Welteb8955072009-06-12 02:41:10 +080077#define LCHAN_RELEASE_TIMEOUT 10, 0
Holger Freytherc6ea9db2008-12-30 19:18:21 +000078#define use_lchan(lchan) \
79 do { lchan->use_count++; \
Holger Freyther4f584c32009-06-02 02:55:07 +000080 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
81 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
82 lchan->nr, lchan->use_count); \
Harald Welteff117a82009-05-23 05:22:08 +000083 bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
Holger Freytherc6ea9db2008-12-30 19:18:21 +000084
85#define put_lchan(lchan) \
Holger Freyther4f584c32009-06-02 02:55:07 +000086 do { lchan->use_count--; \
87 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
88 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
89 lchan->nr, lchan->use_count); \
90 } while(0);
91
Holger Freytherc6ea9db2008-12-30 19:18:21 +000092
Harald Welte52b1f982008-12-23 20:25:15 +000093/* communications link with a BTS */
94struct gsm_bts_link {
95 struct gsm_bts *bts;
96};
97
Harald Welte49f48b82009-02-17 15:29:33 +000098struct gsm_lchan;
99struct gsm_subscriber;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800100struct gsm_mncc;
Harald Welte49f48b82009-02-17 15:29:33 +0000101
Harald Welte4bfdfe72009-06-10 23:11:52 +0800102/* One transaction */
103struct gsm_trans {
104 /* Entry in list of all transactions */
105 struct llist_head entry;
Harald Weltea3d04382008-12-27 17:02:56 +0000106
Harald Welte4bfdfe72009-06-10 23:11:52 +0800107 /* Network */
108 struct gsm_network *network;
Harald Welte49f48b82009-02-17 15:29:33 +0000109
Harald Welte4bfdfe72009-06-10 23:11:52 +0800110 /* The current transaction ID */
111 u_int8_t transaction_id;
112
113 /* The LCHAN that we're part of */
114 struct gsm_lchan *lchan;
115
116 /* To whom we are allocated at the moment */
117 struct gsm_subscriber *subscr;
118
119 /* reference */
120 u_int32_t callref;
121
122 /* current call state */
123 int state;
124
125 /* current timer and message queue */
126 int Tcurrent; /* current CC timer */
127 int T308_second; /* used to send release again */
128 struct timer_list cc_timer;
129 struct gsm_mncc cc_msg; /* stores setup/disconnect/release message */
Harald Weltea3d04382008-12-27 17:02:56 +0000130};
131
132
Harald Weltebbcc7a52009-02-14 19:45:44 +0000133/* Network Management State */
134struct gsm_nm_state {
135 u_int8_t operational;
136 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000137 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000138};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000139
Holger Freyther73487a22008-12-31 18:53:57 +0000140/*
141 * LOCATION UPDATING REQUEST state
142 *
143 * Our current operation is:
144 * - Get imei/tmsi
145 * - Accept/Reject according to global policy
146 */
147struct gsm_loc_updating_operation {
148 struct timer_list updating_timer;
149 int waiting_for_imsi : 1;
150 int waiting_for_imei : 1;
151};
152
Harald Welte8470bf22008-12-25 23:28:35 +0000153struct gsm_lchan {
154 /* The TS that we're part of */
155 struct gsm_bts_trx_ts *ts;
156 /* The logical subslot number in the TS */
157 u_int8_t nr;
Harald Welte45b407a2009-05-23 15:51:12 +0000158 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000159 enum gsm_chan_t type;
Harald Welte45b407a2009-05-23 15:51:12 +0000160 /* If TCH, traffic channel mode */
161 enum gsm_chan_t tch_mode;
Harald Welted4c9bf32009-02-15 16:56:18 +0000162 /* Power levels for MS and BTS */
163 u_int8_t bs_power;
164 u_int8_t ms_power;
165
Harald Welte8470bf22008-12-25 23:28:35 +0000166 /* To whom we are allocated at the moment */
167 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000168
169 /* Timer started to release the channel */
170 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000171
Holger Freyther73487a22008-12-31 18:53:57 +0000172 /*
173 * Operations that have a state and might be pending
174 */
175 struct gsm_loc_updating_operation *loc_operation;
176
Holger Freytherb7193e42008-12-29 17:44:08 +0000177 /* use count. how many users use this channel */
178 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000179};
180
Harald Welte85770c72009-01-18 17:47:32 +0000181struct gsm_e1_subslot {
182 /* Number of E1 link */
183 u_int8_t e1_nr;
184 /* Number of E1 TS inside E1 link */
185 u_int8_t e1_ts;
186 /* Sub-slot within the E1 TS, 0xff if full TS */
187 u_int8_t e1_ts_ss;
188};
189
Harald Welte52b1f982008-12-23 20:25:15 +0000190#define BTS_TRX_F_ACTIVATED 0x0001
191/* One Timeslot in a TRX */
192struct gsm_bts_trx_ts {
193 struct gsm_bts_trx *trx;
194 /* number of this timeslot at the TRX */
195 u_int8_t nr;
196
Harald Welte8470bf22008-12-25 23:28:35 +0000197 enum gsm_phys_chan_config pchan;
198
Harald Welte52b1f982008-12-23 20:25:15 +0000199 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000200 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200201 struct tlv_parsed nm_attr;
Harald Welte8470bf22008-12-25 23:28:35 +0000202
Harald Welte85770c72009-01-18 17:47:32 +0000203 /* To which E1 subslot are we connected */
204 struct gsm_e1_subslot e1_link;
Harald Welte75099262009-02-16 21:12:08 +0000205 struct {
206 u_int32_t bound_ip;
207 u_int16_t bound_port;
208 u_int8_t attr_fc;
209 u_int16_t attr_f8;
210 } abis_ip;
Harald Welte85770c72009-01-18 17:47:32 +0000211
Harald Welte8470bf22008-12-25 23:28:35 +0000212 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000213};
214
215/* One TRX in a BTS */
216struct gsm_bts_trx {
Harald Weltee441d9c2009-06-21 16:17:15 +0200217 /* list header in bts->trx_list */
218 struct llist_head list;
219
Harald Welte52b1f982008-12-23 20:25:15 +0000220 struct gsm_bts *bts;
221 /* number of this TRX in the BTS */
222 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000223 /* how do we talk RSL with this TRX? */
224 struct e1inp_sign_link *rsl_link;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000225 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200226 struct tlv_parsed nm_attr;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000227 struct {
228 struct gsm_nm_state nm_state;
229 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000230
231 u_int16_t arfcn;
Harald Weltefcd24452009-06-20 18:15:19 +0200232 int nominal_power; /* in dBm */
233 unsigned int max_power_red; /* in actual dB */
Harald Welte8b697c72009-06-05 19:18:45 +0000234
235 union {
236 struct {
237 struct {
238 struct gsm_nm_state nm_state;
239 } bbsig;
240 struct {
241 struct gsm_nm_state nm_state;
242 } pa;
243 } bs11;
244 };
Harald Welte85770c72009-01-18 17:47:32 +0000245 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000246};
247
Harald Welte978cb422009-01-18 17:57:27 +0000248enum gsm_bts_type {
249 GSM_BTS_TYPE_UNKNOWN,
250 GSM_BTS_TYPE_BS11,
Harald Weltebbcc7a52009-02-14 19:45:44 +0000251 GSM_BTS_TYPE_NANOBTS_900,
252 GSM_BTS_TYPE_NANOBTS_1800,
Harald Welte978cb422009-01-18 17:57:27 +0000253};
254
Holger Freytherceb59b72009-02-06 18:54:00 +0000255/**
256 * A pending paging request
257 */
258struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000259 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000260 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000261 /* the subscriber which we're paging. Later gsm_paging_request
262 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000263 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000264 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000265 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000266 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000267 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000268
269 /* Timer 3113: how long do we try to page? */
270 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000271
272 /* callback to be called in case paging completes */
273 gsm_cbfn *cbfn;
274 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000275};
Harald Weltecd06bfb2009-02-10 17:33:56 +0000276#define T3113_VALUE 60, 0
Holger Freytherceb59b72009-02-06 18:54:00 +0000277
278/*
279 * This keeps track of the paging status of one BTS. It
280 * includes a number of pending requests, a back pointer
281 * to the gsm_bts, a timer and some more state.
282 */
283struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000284 /* pending requests */
285 struct llist_head pending_requests;
286 struct gsm_paging_request *last_request;
287 struct gsm_bts *bts;
288
Harald Welte75a1fa82009-02-17 01:39:41 +0000289 struct timer_list work_timer;
290
Holger Freyther392209c2009-02-10 00:06:19 +0000291 /* load */
292 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000293};
294
Harald Welte8b697c72009-06-05 19:18:45 +0000295struct gsm_envabtse {
296 struct gsm_nm_state nm_state;
297};
298
Harald Welte52b1f982008-12-23 20:25:15 +0000299/* One BTS */
300struct gsm_bts {
Harald Weltee441d9c2009-06-21 16:17:15 +0200301 /* list header in net->bts_list */
302 struct llist_head list;
303
Harald Welte52b1f982008-12-23 20:25:15 +0000304 struct gsm_network *network;
305 /* number of ths BTS in network */
306 u_int8_t nr;
307 /* location area code of this BTS */
308 u_int8_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000309 /* Training Sequence Code */
310 u_int8_t tsc;
Harald Welte78f2f502009-05-23 16:56:52 +0000311 /* Base Station Identification Code (BSIC) */
312 u_int8_t bsic;
Harald Welte978cb422009-01-18 17:57:27 +0000313 /* type of BTS */
314 enum gsm_bts_type type;
Harald Weltefcd24452009-06-20 18:15:19 +0200315 enum gsm_band band;
Harald Welte1fa60c82009-02-09 18:13:26 +0000316 /* how do we talk OML with this TRX? */
317 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000318
319 /* Abis network management O&M handle */
320 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000321 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200322 struct tlv_parsed nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000323
Harald Welte52b1f982008-12-23 20:25:15 +0000324 /* number of this BTS on given E1 link */
325 u_int8_t bts_nr;
326
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000327 struct gsm48_control_channel_descr chan_desc;
328
Holger Freytherceb59b72009-02-06 18:54:00 +0000329 /* paging state and control */
330 struct gsm_bts_paging_state paging;
331
Harald Welte52b1f982008-12-23 20:25:15 +0000332 /* CCCH is on C0 */
333 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000334
335 struct {
336 struct gsm_nm_state nm_state;
337 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000338
339 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
Harald Welte7b26bcb2009-05-28 11:39:21 +0000340 union {
341 struct {
342 u_int16_t site_id;
343 u_int16_t bts_id;
344 } ip_access;
345 struct {
346 struct {
347 struct gsm_nm_state nm_state;
348 } cclk;
349 struct {
350 struct gsm_nm_state nm_state;
351 } rack;
Harald Welte8b697c72009-06-05 19:18:45 +0000352 struct gsm_envabtse envabtse[4];
Harald Welte7b26bcb2009-05-28 11:39:21 +0000353 } bs11;
354 };
Harald Weltebbcc7a52009-02-14 19:45:44 +0000355
Harald Welte52b1f982008-12-23 20:25:15 +0000356 /* transceivers */
357 int num_trx;
Harald Weltee441d9c2009-06-21 16:17:15 +0200358 struct llist_head trx_list;
Harald Welte52b1f982008-12-23 20:25:15 +0000359};
360
Harald Welte52b1f982008-12-23 20:25:15 +0000361struct gsm_network {
362 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000363 u_int16_t country_code;
364 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000365 char *name_long;
366 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000367
Harald Welte4bfdfe72009-06-10 23:11:52 +0800368 /* layer 4 */
369 int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
370 struct llist_head upqueue;
371 struct llist_head trans_list;
372
Harald Welte52b1f982008-12-23 20:25:15 +0000373 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200374 struct llist_head bts_list;
Harald Welte52b1f982008-12-23 20:25:15 +0000375};
376
Harald Welte7e310b12009-03-30 20:56:32 +0000377#define SMS_HDR_SIZE 128
378#define SMS_TEXT_SIZE 256
379struct gsm_sms {
380 u_int64_t id;
381 struct gsm_subscriber *sender;
382 struct gsm_subscriber *receiver;
383
384 unsigned char header[SMS_HDR_SIZE];
385 char text[SMS_TEXT_SIZE];
386};
387
Harald Weltee441d9c2009-06-21 16:17:15 +0200388struct gsm_network *gsm_network_init(u_int16_t country_code, u_int16_t network_code,
Harald Welte4bfdfe72009-06-10 23:11:52 +0800389 int (*mncc_recv)(struct gsm_network *, int, void *));
Harald Weltee441d9c2009-06-21 16:17:15 +0200390struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type,
391 u_int8_t tsc, u_int8_t bsic);
392struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
393
394struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
395struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
Harald Welte8470bf22008-12-25 23:28:35 +0000396
Harald Weltea72c98e2009-01-04 16:10:38 +0000397const char *gsm_pchan_name(enum gsm_phys_chan_config c);
398const char *gsm_lchan_name(enum gsm_chan_t c);
399const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte23a68632009-02-19 17:06:42 +0000400char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Weltea72c98e2009-01-04 16:10:38 +0000401
Harald Weltead384642008-12-26 10:20:07 +0000402enum gsm_e1_event {
403 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000404 EVT_E1_TEI_UP,
405 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000406};
407
Harald Weltecd06bfb2009-02-10 17:33:56 +0000408void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
409 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte32201c12009-03-10 12:15:10 +0000410enum gsm_bts_type parse_btstype(char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200411const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000412struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
413 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000414
Harald Weltefcd24452009-06-20 18:15:19 +0200415char *gsm_band_name(enum gsm_band band);
416enum gsm_band gsm_band_parse(int mhz);
417
Harald Welte2cf161b2009-06-20 22:36:41 +0200418void *tall_bsc_ctx;
419
Harald Welte32201c12009-03-10 12:15:10 +0000420static inline int is_ipaccess_bts(struct gsm_bts *bts)
421{
422 switch (bts->type) {
423 case GSM_BTS_TYPE_NANOBTS_900:
424 case GSM_BTS_TYPE_NANOBTS_1800:
425 return 1;
426 default:
427 break;
428 }
429 return 0;
430}
431
Harald Welte52b1f982008-12-23 20:25:15 +0000432#endif