blob: e85adf82956c3a6471ea6185b6010a453484f351 [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,
Harald Welte8e1e3ee2009-02-01 13:32:45 +000028};
29
30struct msgb;
31typedef int gsm_cbfn(unsigned int hooknum,
32 unsigned int event,
33 struct msgb *msg,
34 void *data, void *param);
35
Holger Freytherc6ea9db2008-12-30 19:18:21 +000036/*
37 * Use the channel. As side effect the lchannel recycle timer
38 * will be started.
39 */
40#define LCHAN_RELEASE_TIMEOUT 4, 0
41#define use_lchan(lchan) \
42 do { lchan->use_count++; \
Holger Freyther4f584c32009-06-02 02:55:07 +000043 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
44 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
45 lchan->nr, lchan->use_count); \
Harald Welteff117a82009-05-23 05:22:08 +000046 bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
Holger Freytherc6ea9db2008-12-30 19:18:21 +000047
48#define put_lchan(lchan) \
Holger Freyther4f584c32009-06-02 02:55:07 +000049 do { lchan->use_count--; \
50 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
51 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
52 lchan->nr, lchan->use_count); \
53 } while(0);
54
Holger Freytherc6ea9db2008-12-30 19:18:21 +000055
Harald Welte52b1f982008-12-23 20:25:15 +000056/* communications link with a BTS */
57struct gsm_bts_link {
58 struct gsm_bts *bts;
59};
60
Harald Weltea3d04382008-12-27 17:02:56 +000061enum gsm_call_type {
62 GSM_CT_NONE,
63 GSM_CT_MO,
64 GSM_CT_MT,
65};
66
67enum gsm_call_state {
68 GSM_CSTATE_NULL,
69 GSM_CSTATE_INITIATED,
70 GSM_CSTATE_ACTIVE,
71 GSM_CSTATE_RELEASE_REQ,
72};
73
Harald Welte49f48b82009-02-17 15:29:33 +000074struct gsm_lchan;
75struct gsm_subscriber;
76
Harald Weltea3d04382008-12-27 17:02:56 +000077/* One end of a call */
78struct gsm_call {
79 enum gsm_call_type type;
80 enum gsm_call_state state;
81 u_int8_t transaction_id; /* 10.3.2 */
82
Harald Welte49f48b82009-02-17 15:29:33 +000083 /* the 'local' channel */
84 struct gsm_lchan *local_lchan;
85 /* the 'remote' channel */
86 struct gsm_lchan *remote_lchan;
87
Harald Welte0932d1e2009-02-16 22:53:52 +000088 /* the 'remote' subscriber */
89 struct gsm_subscriber *called_subscr;
Harald Weltea3d04382008-12-27 17:02:56 +000090};
91
92
Harald Welte8470bf22008-12-25 23:28:35 +000093enum gsm_phys_chan_config {
94 GSM_PCHAN_NONE,
95 GSM_PCHAN_CCCH,
96 GSM_PCHAN_CCCH_SDCCH4,
97 GSM_PCHAN_TCH_F,
98 GSM_PCHAN_TCH_H,
99 GSM_PCHAN_SDCCH8_SACCH8C,
100 GSM_PCHAN_UNKNOWN,
101};
102
103enum gsm_chan_t {
104 GSM_LCHAN_NONE,
105 GSM_LCHAN_SDCCH,
106 GSM_LCHAN_TCH_F,
107 GSM_LCHAN_TCH_H,
108 GSM_LCHAN_UNKNOWN,
109};
110
Harald Weltee14a57c2008-12-29 04:08:28 +0000111
112/* Channel Request reason */
113enum gsm_chreq_reason_t {
114 GSM_CHREQ_REASON_EMERG,
115 GSM_CHREQ_REASON_PAG,
116 GSM_CHREQ_REASON_CALL,
117 GSM_CHREQ_REASON_LOCATION_UPD,
118 GSM_CHREQ_REASON_OTHER,
119};
120
Harald Weltebbcc7a52009-02-14 19:45:44 +0000121/* Network Management State */
122struct gsm_nm_state {
123 u_int8_t operational;
124 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000125 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000126};
Harald Welte8c1d0e42009-02-15 03:38:12 +0000127struct gsm_attr {
128 u_int8_t len;
129 u_int8_t data[0];
130};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000131
Holger Freyther73487a22008-12-31 18:53:57 +0000132/*
133 * LOCATION UPDATING REQUEST state
134 *
135 * Our current operation is:
136 * - Get imei/tmsi
137 * - Accept/Reject according to global policy
138 */
139struct gsm_loc_updating_operation {
140 struct timer_list updating_timer;
141 int waiting_for_imsi : 1;
142 int waiting_for_imei : 1;
143};
144
Harald Welte8470bf22008-12-25 23:28:35 +0000145struct gsm_lchan {
146 /* The TS that we're part of */
147 struct gsm_bts_trx_ts *ts;
148 /* The logical subslot number in the TS */
149 u_int8_t nr;
Harald Welte45b407a2009-05-23 15:51:12 +0000150 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000151 enum gsm_chan_t type;
Harald Welte45b407a2009-05-23 15:51:12 +0000152 /* If TCH, traffic channel mode */
153 enum gsm_chan_t tch_mode;
Harald Welted4c9bf32009-02-15 16:56:18 +0000154 /* Power levels for MS and BTS */
155 u_int8_t bs_power;
156 u_int8_t ms_power;
157
Harald Welte8470bf22008-12-25 23:28:35 +0000158 /* To whom we are allocated at the moment */
159 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000160
161 /* Timer started to release the channel */
162 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000163
164 /* local end of a call, if any */
165 struct gsm_call call;
Holger Freyther3186bf22008-12-29 06:23:49 +0000166
167 /* temporary user data, to be removed... and merged into gsm_call */
168 void *user_data;
Holger Freytherb7193e42008-12-29 17:44:08 +0000169
Holger Freyther73487a22008-12-31 18:53:57 +0000170 /*
171 * Operations that have a state and might be pending
172 */
173 struct gsm_loc_updating_operation *loc_operation;
174
Holger Freytherb7193e42008-12-29 17:44:08 +0000175 /* use count. how many users use this channel */
176 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000177};
178
Harald Welte85770c72009-01-18 17:47:32 +0000179struct gsm_e1_subslot {
180 /* Number of E1 link */
181 u_int8_t e1_nr;
182 /* Number of E1 TS inside E1 link */
183 u_int8_t e1_ts;
184 /* Sub-slot within the E1 TS, 0xff if full TS */
185 u_int8_t e1_ts_ss;
186};
187
Harald Welte52b1f982008-12-23 20:25:15 +0000188#define BTS_TRX_F_ACTIVATED 0x0001
189/* One Timeslot in a TRX */
190struct gsm_bts_trx_ts {
191 struct gsm_bts_trx *trx;
192 /* number of this timeslot at the TRX */
193 u_int8_t nr;
194
Harald Welte8470bf22008-12-25 23:28:35 +0000195 enum gsm_phys_chan_config pchan;
196
Harald Welte52b1f982008-12-23 20:25:15 +0000197 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000198 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000199 struct gsm_attr *nm_attr;
Harald Welte8470bf22008-12-25 23:28:35 +0000200
Harald Welte85770c72009-01-18 17:47:32 +0000201 /* To which E1 subslot are we connected */
202 struct gsm_e1_subslot e1_link;
Harald Welte75099262009-02-16 21:12:08 +0000203 struct {
204 u_int32_t bound_ip;
205 u_int16_t bound_port;
206 u_int8_t attr_fc;
207 u_int16_t attr_f8;
208 } abis_ip;
Harald Welte85770c72009-01-18 17:47:32 +0000209
Harald Welte8470bf22008-12-25 23:28:35 +0000210 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000211};
212
213/* One TRX in a BTS */
214struct gsm_bts_trx {
215 struct gsm_bts *bts;
216 /* number of this TRX in the BTS */
217 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000218 /* how do we talk RSL with this TRX? */
219 struct e1inp_sign_link *rsl_link;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000220 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000221 struct gsm_attr *nm_attr;
222 struct {
223 struct gsm_nm_state nm_state;
224 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000225
226 u_int16_t arfcn;
Harald Welte8b697c72009-06-05 19:18:45 +0000227
228 union {
229 struct {
230 struct {
231 struct gsm_nm_state nm_state;
232 } bbsig;
233 struct {
234 struct gsm_nm_state nm_state;
235 } pa;
236 } bs11;
237 };
Harald Welte85770c72009-01-18 17:47:32 +0000238 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000239};
240
Harald Welte978cb422009-01-18 17:57:27 +0000241enum gsm_bts_type {
242 GSM_BTS_TYPE_UNKNOWN,
243 GSM_BTS_TYPE_BS11,
Harald Weltebbcc7a52009-02-14 19:45:44 +0000244 GSM_BTS_TYPE_NANOBTS_900,
245 GSM_BTS_TYPE_NANOBTS_1800,
Harald Welte978cb422009-01-18 17:57:27 +0000246};
247
Holger Freytherceb59b72009-02-06 18:54:00 +0000248/**
249 * A pending paging request
250 */
251struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000252 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000253 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000254 /* the subscriber which we're paging. Later gsm_paging_request
255 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000256 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000257 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000258 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000259 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000260 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000261
262 /* Timer 3113: how long do we try to page? */
263 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000264
265 /* callback to be called in case paging completes */
266 gsm_cbfn *cbfn;
267 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000268};
Harald Weltecd06bfb2009-02-10 17:33:56 +0000269#define T3113_VALUE 60, 0
Holger Freytherceb59b72009-02-06 18:54:00 +0000270
271/*
272 * This keeps track of the paging status of one BTS. It
273 * includes a number of pending requests, a back pointer
274 * to the gsm_bts, a timer and some more state.
275 */
276struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000277 /* pending requests */
278 struct llist_head pending_requests;
279 struct gsm_paging_request *last_request;
280 struct gsm_bts *bts;
281
Harald Welte75a1fa82009-02-17 01:39:41 +0000282 struct timer_list work_timer;
283
Holger Freyther392209c2009-02-10 00:06:19 +0000284 /* load */
285 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000286};
287
Harald Welte8b697c72009-06-05 19:18:45 +0000288struct gsm_envabtse {
289 struct gsm_nm_state nm_state;
290};
291
Harald Welte52b1f982008-12-23 20:25:15 +0000292/* One BTS */
293struct gsm_bts {
294 struct gsm_network *network;
295 /* number of ths BTS in network */
296 u_int8_t nr;
297 /* location area code of this BTS */
298 u_int8_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000299 /* Training Sequence Code */
300 u_int8_t tsc;
Harald Welte78f2f502009-05-23 16:56:52 +0000301 /* Base Station Identification Code (BSIC) */
302 u_int8_t bsic;
Harald Welte978cb422009-01-18 17:57:27 +0000303 /* type of BTS */
304 enum gsm_bts_type type;
Harald Welte1fa60c82009-02-09 18:13:26 +0000305 /* how do we talk OML with this TRX? */
306 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000307
308 /* Abis network management O&M handle */
309 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000310 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000311 struct gsm_attr *nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000312
Harald Welte52b1f982008-12-23 20:25:15 +0000313 /* number of this BTS on given E1 link */
314 u_int8_t bts_nr;
315
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000316 struct gsm48_control_channel_descr chan_desc;
317
Holger Freytherceb59b72009-02-06 18:54:00 +0000318 /* paging state and control */
319 struct gsm_bts_paging_state paging;
320
Harald Welte52b1f982008-12-23 20:25:15 +0000321 /* CCCH is on C0 */
322 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000323
324 struct {
325 struct gsm_nm_state nm_state;
326 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000327
328 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
Harald Welte7b26bcb2009-05-28 11:39:21 +0000329 union {
330 struct {
331 u_int16_t site_id;
332 u_int16_t bts_id;
333 } ip_access;
334 struct {
335 struct {
336 struct gsm_nm_state nm_state;
337 } cclk;
338 struct {
339 struct gsm_nm_state nm_state;
340 } rack;
Harald Welte8b697c72009-06-05 19:18:45 +0000341 struct gsm_envabtse envabtse[4];
Harald Welte7b26bcb2009-05-28 11:39:21 +0000342 } bs11;
343 };
Harald Weltebbcc7a52009-02-14 19:45:44 +0000344
Harald Welte52b1f982008-12-23 20:25:15 +0000345 /* transceivers */
346 int num_trx;
347 struct gsm_bts_trx trx[BTS_MAX_TRX+1];
348};
349
Harald Welte52b1f982008-12-23 20:25:15 +0000350struct gsm_network {
351 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000352 u_int16_t country_code;
353 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000354 char *name_long;
355 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000356
357 unsigned int num_bts;
358 /* private lists */
359 struct gsm_bts bts[GSM_MAX_BTS+1];
Harald Welte52b1f982008-12-23 20:25:15 +0000360};
361
Harald Welte7e310b12009-03-30 20:56:32 +0000362#define SMS_HDR_SIZE 128
363#define SMS_TEXT_SIZE 256
364struct gsm_sms {
365 u_int64_t id;
366 struct gsm_subscriber *sender;
367 struct gsm_subscriber *receiver;
368
369 unsigned char header[SMS_HDR_SIZE];
370 char text[SMS_TEXT_SIZE];
371};
372
Harald Welte8c1d0e42009-02-15 03:38:12 +0000373struct gsm_network *gsm_network_init(unsigned int num_bts, enum gsm_bts_type bts_type,
374 u_int16_t country_code, u_int16_t network_code);
Harald Welte8470bf22008-12-25 23:28:35 +0000375
Harald Weltea72c98e2009-01-04 16:10:38 +0000376const char *gsm_pchan_name(enum gsm_phys_chan_config c);
377const char *gsm_lchan_name(enum gsm_chan_t c);
378const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte23a68632009-02-19 17:06:42 +0000379char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Weltea72c98e2009-01-04 16:10:38 +0000380
Harald Weltead384642008-12-26 10:20:07 +0000381enum gsm_e1_event {
382 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000383 EVT_E1_TEI_UP,
384 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000385};
386
Harald Weltecd06bfb2009-02-10 17:33:56 +0000387void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
388 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte32201c12009-03-10 12:15:10 +0000389enum gsm_bts_type parse_btstype(char *arg);
390char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000391struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
392 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000393
394static inline int is_ipaccess_bts(struct gsm_bts *bts)
395{
396 switch (bts->type) {
397 case GSM_BTS_TYPE_NANOBTS_900:
398 case GSM_BTS_TYPE_NANOBTS_1800:
399 return 1;
400 default:
401 break;
402 }
403 return 0;
404}
405
Harald Welte52b1f982008-12-23 20:25:15 +0000406#endif