blob: 9bbc2921df870760b1e17cbfe9ff73cc3888ff30 [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 Welteaa0b29c2009-07-23 18:56:43 +0200110 /* The protocol within which we live */
111 u_int8_t protocol;
112
Harald Welte4bfdfe72009-06-10 23:11:52 +0800113 /* The current transaction ID */
114 u_int8_t transaction_id;
115
Harald Welteaa0b29c2009-07-23 18:56:43 +0200116 /* To whom we belong, unique identifier of remote MM entity */
Harald Welte4bfdfe72009-06-10 23:11:52 +0800117 struct gsm_subscriber *subscr;
118
Harald Welteaa0b29c2009-07-23 18:56:43 +0200119 /* The LCHAN that we're currently using to transmit messages */
120 struct gsm_lchan *lchan;
121
122 /* reference from MNCC or other application */
Harald Welte4bfdfe72009-06-10 23:11:52 +0800123 u_int32_t callref;
124
Harald Welteaa0b29c2009-07-23 18:56:43 +0200125 union {
126 struct {
Harald Welte4bfdfe72009-06-10 23:11:52 +0800127
Harald Welteaa0b29c2009-07-23 18:56:43 +0200128 /* current call state */
129 int state;
130
131 /* current timer and message queue */
132 int Tcurrent; /* current CC timer */
133 int T308_second; /* used to send release again */
134 struct timer_list timer;
135 struct gsm_mncc msg; /* stores setup/disconnect/release message */
136 } cc;
137 struct {
138 } sms;
139 };
Harald Weltea3d04382008-12-27 17:02:56 +0000140};
141
142
Harald Weltebbcc7a52009-02-14 19:45:44 +0000143/* Network Management State */
144struct gsm_nm_state {
145 u_int8_t operational;
146 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000147 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000148};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000149
Holger Freyther73487a22008-12-31 18:53:57 +0000150/*
151 * LOCATION UPDATING REQUEST state
152 *
153 * Our current operation is:
154 * - Get imei/tmsi
155 * - Accept/Reject according to global policy
156 */
157struct gsm_loc_updating_operation {
158 struct timer_list updating_timer;
159 int waiting_for_imsi : 1;
160 int waiting_for_imei : 1;
161};
162
Harald Welte8470bf22008-12-25 23:28:35 +0000163struct gsm_lchan {
164 /* The TS that we're part of */
165 struct gsm_bts_trx_ts *ts;
166 /* The logical subslot number in the TS */
167 u_int8_t nr;
Harald Welte45b407a2009-05-23 15:51:12 +0000168 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000169 enum gsm_chan_t type;
Harald Welte45b407a2009-05-23 15:51:12 +0000170 /* If TCH, traffic channel mode */
171 enum gsm_chan_t tch_mode;
Harald Welted4c9bf32009-02-15 16:56:18 +0000172 /* Power levels for MS and BTS */
173 u_int8_t bs_power;
174 u_int8_t ms_power;
175
Harald Welte8470bf22008-12-25 23:28:35 +0000176 /* To whom we are allocated at the moment */
177 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000178
179 /* Timer started to release the channel */
180 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000181
Holger Freyther73487a22008-12-31 18:53:57 +0000182 /*
183 * Operations that have a state and might be pending
184 */
185 struct gsm_loc_updating_operation *loc_operation;
186
Holger Freytherb7193e42008-12-29 17:44:08 +0000187 /* use count. how many users use this channel */
188 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000189};
190
Harald Welte85770c72009-01-18 17:47:32 +0000191struct gsm_e1_subslot {
192 /* Number of E1 link */
193 u_int8_t e1_nr;
194 /* Number of E1 TS inside E1 link */
195 u_int8_t e1_ts;
196 /* Sub-slot within the E1 TS, 0xff if full TS */
197 u_int8_t e1_ts_ss;
198};
199
Harald Welte52b1f982008-12-23 20:25:15 +0000200#define BTS_TRX_F_ACTIVATED 0x0001
201/* One Timeslot in a TRX */
202struct gsm_bts_trx_ts {
203 struct gsm_bts_trx *trx;
204 /* number of this timeslot at the TRX */
205 u_int8_t nr;
206
Harald Welte8470bf22008-12-25 23:28:35 +0000207 enum gsm_phys_chan_config pchan;
208
Harald Welte52b1f982008-12-23 20:25:15 +0000209 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000210 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200211 struct tlv_parsed nm_attr;
Harald Welte8470bf22008-12-25 23:28:35 +0000212
Harald Welte85770c72009-01-18 17:47:32 +0000213 /* To which E1 subslot are we connected */
214 struct gsm_e1_subslot e1_link;
Harald Welte75099262009-02-16 21:12:08 +0000215 struct {
216 u_int32_t bound_ip;
217 u_int16_t bound_port;
Harald Welte20855542009-07-12 09:50:35 +0200218 u_int8_t rtp_payload2;
219 u_int16_t conn_id;
Harald Welte75099262009-02-16 21:12:08 +0000220 } abis_ip;
Harald Welte85770c72009-01-18 17:47:32 +0000221
Harald Welte8470bf22008-12-25 23:28:35 +0000222 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000223};
224
225/* One TRX in a BTS */
226struct gsm_bts_trx {
Harald Weltee441d9c2009-06-21 16:17:15 +0200227 /* list header in bts->trx_list */
228 struct llist_head list;
229
Harald Welte52b1f982008-12-23 20:25:15 +0000230 struct gsm_bts *bts;
231 /* number of this TRX in the BTS */
232 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000233 /* how do we talk RSL with this TRX? */
234 struct e1inp_sign_link *rsl_link;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000235 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200236 struct tlv_parsed nm_attr;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000237 struct {
238 struct gsm_nm_state nm_state;
239 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000240
241 u_int16_t arfcn;
Harald Weltefcd24452009-06-20 18:15:19 +0200242 int nominal_power; /* in dBm */
243 unsigned int max_power_red; /* in actual dB */
Harald Welte8b697c72009-06-05 19:18:45 +0000244
245 union {
246 struct {
247 struct {
248 struct gsm_nm_state nm_state;
249 } bbsig;
250 struct {
251 struct gsm_nm_state nm_state;
252 } pa;
253 } bs11;
254 };
Harald Welte85770c72009-01-18 17:47:32 +0000255 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000256};
257
Harald Welte978cb422009-01-18 17:57:27 +0000258enum gsm_bts_type {
259 GSM_BTS_TYPE_UNKNOWN,
260 GSM_BTS_TYPE_BS11,
Harald Weltebbcc7a52009-02-14 19:45:44 +0000261 GSM_BTS_TYPE_NANOBTS_900,
262 GSM_BTS_TYPE_NANOBTS_1800,
Harald Welte978cb422009-01-18 17:57:27 +0000263};
264
Holger Freytherceb59b72009-02-06 18:54:00 +0000265/**
266 * A pending paging request
267 */
268struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000269 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000270 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000271 /* the subscriber which we're paging. Later gsm_paging_request
272 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000273 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000274 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000275 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000276 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000277 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000278
279 /* Timer 3113: how long do we try to page? */
280 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000281
282 /* callback to be called in case paging completes */
283 gsm_cbfn *cbfn;
284 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000285};
Harald Weltecd06bfb2009-02-10 17:33:56 +0000286#define T3113_VALUE 60, 0
Holger Freytherceb59b72009-02-06 18:54:00 +0000287
288/*
289 * This keeps track of the paging status of one BTS. It
290 * includes a number of pending requests, a back pointer
291 * to the gsm_bts, a timer and some more state.
292 */
293struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000294 /* pending requests */
295 struct llist_head pending_requests;
296 struct gsm_paging_request *last_request;
297 struct gsm_bts *bts;
298
Harald Welte75a1fa82009-02-17 01:39:41 +0000299 struct timer_list work_timer;
300
Holger Freyther392209c2009-02-10 00:06:19 +0000301 /* load */
302 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000303};
304
Harald Welte8b697c72009-06-05 19:18:45 +0000305struct gsm_envabtse {
306 struct gsm_nm_state nm_state;
307};
308
Harald Welte52b1f982008-12-23 20:25:15 +0000309/* One BTS */
310struct gsm_bts {
Harald Weltee441d9c2009-06-21 16:17:15 +0200311 /* list header in net->bts_list */
312 struct llist_head list;
313
Harald Welte52b1f982008-12-23 20:25:15 +0000314 struct gsm_network *network;
315 /* number of ths BTS in network */
316 u_int8_t nr;
317 /* location area code of this BTS */
318 u_int8_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000319 /* Training Sequence Code */
320 u_int8_t tsc;
Harald Welte78f2f502009-05-23 16:56:52 +0000321 /* Base Station Identification Code (BSIC) */
322 u_int8_t bsic;
Harald Welte978cb422009-01-18 17:57:27 +0000323 /* type of BTS */
324 enum gsm_bts_type type;
Harald Weltefcd24452009-06-20 18:15:19 +0200325 enum gsm_band band;
Harald Welte1fa60c82009-02-09 18:13:26 +0000326 /* how do we talk OML with this TRX? */
327 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000328
329 /* Abis network management O&M handle */
330 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000331 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200332 struct tlv_parsed nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000333
Harald Welte52b1f982008-12-23 20:25:15 +0000334 /* number of this BTS on given E1 link */
335 u_int8_t bts_nr;
336
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000337 struct gsm48_control_channel_descr chan_desc;
338
Holger Freytherceb59b72009-02-06 18:54:00 +0000339 /* paging state and control */
340 struct gsm_bts_paging_state paging;
341
Harald Welte52b1f982008-12-23 20:25:15 +0000342 /* CCCH is on C0 */
343 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000344
345 struct {
346 struct gsm_nm_state nm_state;
347 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000348
349 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
Harald Welte7b26bcb2009-05-28 11:39:21 +0000350 union {
351 struct {
352 u_int16_t site_id;
353 u_int16_t bts_id;
354 } ip_access;
355 struct {
356 struct {
357 struct gsm_nm_state nm_state;
358 } cclk;
359 struct {
360 struct gsm_nm_state nm_state;
361 } rack;
Harald Welte8b697c72009-06-05 19:18:45 +0000362 struct gsm_envabtse envabtse[4];
Harald Welte7b26bcb2009-05-28 11:39:21 +0000363 } bs11;
364 };
Harald Weltebbcc7a52009-02-14 19:45:44 +0000365
Harald Welte52b1f982008-12-23 20:25:15 +0000366 /* transceivers */
367 int num_trx;
Harald Weltee441d9c2009-06-21 16:17:15 +0200368 struct llist_head trx_list;
Harald Welte52b1f982008-12-23 20:25:15 +0000369};
370
Harald Welte52b1f982008-12-23 20:25:15 +0000371struct gsm_network {
372 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000373 u_int16_t country_code;
374 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000375 char *name_long;
376 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000377
Harald Welte4bfdfe72009-06-10 23:11:52 +0800378 /* layer 4 */
379 int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
380 struct llist_head upqueue;
381 struct llist_head trans_list;
382
Harald Welte52b1f982008-12-23 20:25:15 +0000383 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200384 struct llist_head bts_list;
Harald Welte52b1f982008-12-23 20:25:15 +0000385};
386
Harald Welte7e310b12009-03-30 20:56:32 +0000387#define SMS_HDR_SIZE 128
388#define SMS_TEXT_SIZE 256
389struct gsm_sms {
390 u_int64_t id;
391 struct gsm_subscriber *sender;
392 struct gsm_subscriber *receiver;
393
394 unsigned char header[SMS_HDR_SIZE];
395 char text[SMS_TEXT_SIZE];
396};
397
Harald Weltee441d9c2009-06-21 16:17:15 +0200398struct gsm_network *gsm_network_init(u_int16_t country_code, u_int16_t network_code,
Harald Welte4bfdfe72009-06-10 23:11:52 +0800399 int (*mncc_recv)(struct gsm_network *, int, void *));
Harald Weltee441d9c2009-06-21 16:17:15 +0200400struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type,
401 u_int8_t tsc, u_int8_t bsic);
402struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
403
404struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
405struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
Harald Welte8470bf22008-12-25 23:28:35 +0000406
Harald Weltea72c98e2009-01-04 16:10:38 +0000407const char *gsm_pchan_name(enum gsm_phys_chan_config c);
408const char *gsm_lchan_name(enum gsm_chan_t c);
409const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte23a68632009-02-19 17:06:42 +0000410char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Weltea72c98e2009-01-04 16:10:38 +0000411
Harald Weltead384642008-12-26 10:20:07 +0000412enum gsm_e1_event {
413 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000414 EVT_E1_TEI_UP,
415 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000416};
417
Harald Weltecd06bfb2009-02-10 17:33:56 +0000418void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
419 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte32201c12009-03-10 12:15:10 +0000420enum gsm_bts_type parse_btstype(char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200421const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000422struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
423 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000424
Harald Weltefcd24452009-06-20 18:15:19 +0200425char *gsm_band_name(enum gsm_band band);
426enum gsm_band gsm_band_parse(int mhz);
427
Andreas Eversberg8226fa72009-06-29 15:19:38 +0200428extern void *tall_bsc_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +0200429
Harald Welte32201c12009-03-10 12:15:10 +0000430static inline int is_ipaccess_bts(struct gsm_bts *bts)
431{
432 switch (bts->type) {
433 case GSM_BTS_TYPE_NANOBTS_900:
434 case GSM_BTS_TYPE_NANOBTS_1800:
435 return 1;
436 default:
437 break;
438 }
439 return 0;
440}
441
Harald Welte52b1f982008-12-23 20:25:15 +0000442#endif