blob: 614c63d17a4c65c96eae6d325339c4f351f68d1f [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 Welte52b1f982008-12-23 20:25:15 +000018
Harald Welte8e1e3ee2009-02-01 13:32:45 +000019enum gsm_hooks {
20 GSM_HOOK_NM_SWLOAD,
Harald Welte0932d1e2009-02-16 22:53:52 +000021 GSM_HOOK_RR_PAGING,
22};
23
24enum gsm_paging_event {
25 GSM_PAGING_SUCCEEDED,
26 GSM_PAGING_EXPIRED,
Harald Welte8e1e3ee2009-02-01 13:32:45 +000027};
28
29struct msgb;
30typedef int gsm_cbfn(unsigned int hooknum,
31 unsigned int event,
32 struct msgb *msg,
33 void *data, void *param);
34
Holger Freytherc6ea9db2008-12-30 19:18:21 +000035/*
36 * Use the channel. As side effect the lchannel recycle timer
37 * will be started.
38 */
39#define LCHAN_RELEASE_TIMEOUT 4, 0
40#define use_lchan(lchan) \
41 do { lchan->use_count++; \
42 schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
43
44#define put_lchan(lchan) \
45 do { lchan->use_count--; } while(0);
46
Harald Welte52b1f982008-12-23 20:25:15 +000047/* communications link with a BTS */
48struct gsm_bts_link {
49 struct gsm_bts *bts;
50};
51
Harald Weltea3d04382008-12-27 17:02:56 +000052enum gsm_call_type {
53 GSM_CT_NONE,
54 GSM_CT_MO,
55 GSM_CT_MT,
56};
57
58enum gsm_call_state {
59 GSM_CSTATE_NULL,
60 GSM_CSTATE_INITIATED,
61 GSM_CSTATE_ACTIVE,
62 GSM_CSTATE_RELEASE_REQ,
63};
64
Harald Welte49f48b82009-02-17 15:29:33 +000065struct gsm_lchan;
66struct gsm_subscriber;
67
Harald Weltea3d04382008-12-27 17:02:56 +000068/* One end of a call */
69struct gsm_call {
70 enum gsm_call_type type;
71 enum gsm_call_state state;
72 u_int8_t transaction_id; /* 10.3.2 */
73
Harald Welte49f48b82009-02-17 15:29:33 +000074 /* the 'local' channel */
75 struct gsm_lchan *local_lchan;
76 /* the 'remote' channel */
77 struct gsm_lchan *remote_lchan;
78
Harald Welte0932d1e2009-02-16 22:53:52 +000079 /* the 'remote' subscriber */
80 struct gsm_subscriber *called_subscr;
Harald Weltea3d04382008-12-27 17:02:56 +000081};
82
83
Harald Welte8470bf22008-12-25 23:28:35 +000084enum gsm_phys_chan_config {
85 GSM_PCHAN_NONE,
86 GSM_PCHAN_CCCH,
87 GSM_PCHAN_CCCH_SDCCH4,
88 GSM_PCHAN_TCH_F,
89 GSM_PCHAN_TCH_H,
90 GSM_PCHAN_SDCCH8_SACCH8C,
91 GSM_PCHAN_UNKNOWN,
92};
93
94enum gsm_chan_t {
95 GSM_LCHAN_NONE,
96 GSM_LCHAN_SDCCH,
97 GSM_LCHAN_TCH_F,
98 GSM_LCHAN_TCH_H,
99 GSM_LCHAN_UNKNOWN,
100};
101
Harald Weltee14a57c2008-12-29 04:08:28 +0000102
103/* Channel Request reason */
104enum gsm_chreq_reason_t {
105 GSM_CHREQ_REASON_EMERG,
106 GSM_CHREQ_REASON_PAG,
107 GSM_CHREQ_REASON_CALL,
108 GSM_CHREQ_REASON_LOCATION_UPD,
109 GSM_CHREQ_REASON_OTHER,
110};
111
Harald Weltebbcc7a52009-02-14 19:45:44 +0000112/* Network Management State */
113struct gsm_nm_state {
114 u_int8_t operational;
115 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000116 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000117};
Harald Welte8c1d0e42009-02-15 03:38:12 +0000118struct gsm_attr {
119 u_int8_t len;
120 u_int8_t data[0];
121};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000122
Holger Freyther73487a22008-12-31 18:53:57 +0000123/*
124 * LOCATION UPDATING REQUEST state
125 *
126 * Our current operation is:
127 * - Get imei/tmsi
128 * - Accept/Reject according to global policy
129 */
130struct gsm_loc_updating_operation {
131 struct timer_list updating_timer;
132 int waiting_for_imsi : 1;
133 int waiting_for_imei : 1;
134};
135
Harald Welte8470bf22008-12-25 23:28:35 +0000136struct gsm_lchan {
137 /* The TS that we're part of */
138 struct gsm_bts_trx_ts *ts;
139 /* The logical subslot number in the TS */
140 u_int8_t nr;
141 /* The lotical channel type */
142 enum gsm_chan_t type;
Harald Welted4c9bf32009-02-15 16:56:18 +0000143 /* Power levels for MS and BTS */
144 u_int8_t bs_power;
145 u_int8_t ms_power;
146
Harald Welte8470bf22008-12-25 23:28:35 +0000147 /* To whom we are allocated at the moment */
148 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000149
150 /* Timer started to release the channel */
151 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000152
153 /* local end of a call, if any */
154 struct gsm_call call;
Holger Freyther3186bf22008-12-29 06:23:49 +0000155
156 /* temporary user data, to be removed... and merged into gsm_call */
157 void *user_data;
Holger Freytherb7193e42008-12-29 17:44:08 +0000158
Holger Freyther73487a22008-12-31 18:53:57 +0000159 /*
160 * Operations that have a state and might be pending
161 */
162 struct gsm_loc_updating_operation *loc_operation;
163
Holger Freytherb7193e42008-12-29 17:44:08 +0000164 /* use count. how many users use this channel */
165 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000166};
167
Harald Welte85770c72009-01-18 17:47:32 +0000168struct gsm_e1_subslot {
169 /* Number of E1 link */
170 u_int8_t e1_nr;
171 /* Number of E1 TS inside E1 link */
172 u_int8_t e1_ts;
173 /* Sub-slot within the E1 TS, 0xff if full TS */
174 u_int8_t e1_ts_ss;
175};
176
Harald Welte52b1f982008-12-23 20:25:15 +0000177#define BTS_TRX_F_ACTIVATED 0x0001
178/* One Timeslot in a TRX */
179struct gsm_bts_trx_ts {
180 struct gsm_bts_trx *trx;
181 /* number of this timeslot at the TRX */
182 u_int8_t nr;
183
Harald Welte8470bf22008-12-25 23:28:35 +0000184 enum gsm_phys_chan_config pchan;
185
Harald Welte52b1f982008-12-23 20:25:15 +0000186 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000187 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000188 struct gsm_attr *nm_attr;
Harald Welte8470bf22008-12-25 23:28:35 +0000189
Harald Welte85770c72009-01-18 17:47:32 +0000190 /* To which E1 subslot are we connected */
191 struct gsm_e1_subslot e1_link;
Harald Welte75099262009-02-16 21:12:08 +0000192 struct {
193 u_int32_t bound_ip;
194 u_int16_t bound_port;
195 u_int8_t attr_fc;
196 u_int16_t attr_f8;
197 } abis_ip;
Harald Welte85770c72009-01-18 17:47:32 +0000198
Harald Welte8470bf22008-12-25 23:28:35 +0000199 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000200};
201
202/* One TRX in a BTS */
203struct gsm_bts_trx {
204 struct gsm_bts *bts;
205 /* number of this TRX in the BTS */
206 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000207 /* how do we talk RSL with this TRX? */
208 struct e1inp_sign_link *rsl_link;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000209 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000210 struct gsm_attr *nm_attr;
211 struct {
212 struct gsm_nm_state nm_state;
213 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000214
215 u_int16_t arfcn;
Harald Welte85770c72009-01-18 17:47:32 +0000216 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000217};
218
Harald Welte978cb422009-01-18 17:57:27 +0000219enum gsm_bts_type {
220 GSM_BTS_TYPE_UNKNOWN,
221 GSM_BTS_TYPE_BS11,
Harald Weltebbcc7a52009-02-14 19:45:44 +0000222 GSM_BTS_TYPE_NANOBTS_900,
223 GSM_BTS_TYPE_NANOBTS_1800,
Harald Welte978cb422009-01-18 17:57:27 +0000224};
225
Holger Freytherceb59b72009-02-06 18:54:00 +0000226/**
227 * A pending paging request
228 */
229struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000230 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000231 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000232 /* the subscriber which we're paging. Later gsm_paging_request
233 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000234 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000235 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000236 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000237 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000238 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000239
240 /* Timer 3113: how long do we try to page? */
241 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000242
243 /* callback to be called in case paging completes */
244 gsm_cbfn *cbfn;
245 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000246};
Harald Weltecd06bfb2009-02-10 17:33:56 +0000247#define T3113_VALUE 60, 0
Holger Freytherceb59b72009-02-06 18:54:00 +0000248
249/*
250 * This keeps track of the paging status of one BTS. It
251 * includes a number of pending requests, a back pointer
252 * to the gsm_bts, a timer and some more state.
253 */
254struct gsm_bts_paging_state {
255 /* public callbacks */
256 void (*channel_allocated)(struct gsm_lchan *lchan);
257
258 /* pending requests */
259 struct llist_head pending_requests;
260 struct gsm_paging_request *last_request;
261 struct gsm_bts *bts;
262
Harald Welte75a1fa82009-02-17 01:39:41 +0000263 struct timer_list work_timer;
264
Holger Freyther392209c2009-02-10 00:06:19 +0000265 /* load */
266 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000267};
268
Harald Welte52b1f982008-12-23 20:25:15 +0000269/* One BTS */
270struct gsm_bts {
271 struct gsm_network *network;
272 /* number of ths BTS in network */
273 u_int8_t nr;
274 /* location area code of this BTS */
275 u_int8_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000276 /* Training Sequence Code */
277 u_int8_t tsc;
Harald Welte978cb422009-01-18 17:57:27 +0000278 /* type of BTS */
279 enum gsm_bts_type type;
Harald Welte1fa60c82009-02-09 18:13:26 +0000280 /* how do we talk OML with this TRX? */
281 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000282
283 /* Abis network management O&M handle */
284 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000285 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000286 struct gsm_attr *nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000287
Harald Welte52b1f982008-12-23 20:25:15 +0000288 /* number of this BTS on given E1 link */
289 u_int8_t bts_nr;
290
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000291 struct gsm48_control_channel_descr chan_desc;
292
Holger Freytherceb59b72009-02-06 18:54:00 +0000293 /* paging state and control */
294 struct gsm_bts_paging_state paging;
295
Harald Welte52b1f982008-12-23 20:25:15 +0000296 /* CCCH is on C0 */
297 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000298
299 struct {
300 struct gsm_nm_state nm_state;
301 } site_mgr;
302
Harald Welte52b1f982008-12-23 20:25:15 +0000303 /* transceivers */
304 int num_trx;
305 struct gsm_bts_trx trx[BTS_MAX_TRX+1];
306};
307
Harald Welte52b1f982008-12-23 20:25:15 +0000308struct gsm_network {
309 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000310 u_int16_t country_code;
311 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000312 char *name_long;
313 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000314
315 unsigned int num_bts;
316 /* private lists */
317 struct gsm_bts bts[GSM_MAX_BTS+1];
Harald Welte52b1f982008-12-23 20:25:15 +0000318};
319
Harald Welte7e310b12009-03-30 20:56:32 +0000320#define SMS_HDR_SIZE 128
321#define SMS_TEXT_SIZE 256
322struct gsm_sms {
323 u_int64_t id;
324 struct gsm_subscriber *sender;
325 struct gsm_subscriber *receiver;
326
327 unsigned char header[SMS_HDR_SIZE];
328 char text[SMS_TEXT_SIZE];
329};
330
Harald Welte8c1d0e42009-02-15 03:38:12 +0000331struct gsm_network *gsm_network_init(unsigned int num_bts, enum gsm_bts_type bts_type,
332 u_int16_t country_code, u_int16_t network_code);
Harald Welte8470bf22008-12-25 23:28:35 +0000333
Harald Weltea72c98e2009-01-04 16:10:38 +0000334const char *gsm_pchan_name(enum gsm_phys_chan_config c);
335const char *gsm_lchan_name(enum gsm_chan_t c);
336const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte23a68632009-02-19 17:06:42 +0000337char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Weltea72c98e2009-01-04 16:10:38 +0000338
Harald Weltead384642008-12-26 10:20:07 +0000339enum gsm_e1_event {
340 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000341 EVT_E1_TEI_UP,
342 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000343};
344
Harald Weltecd06bfb2009-02-10 17:33:56 +0000345void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
346 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte32201c12009-03-10 12:15:10 +0000347enum gsm_bts_type parse_btstype(char *arg);
348char *btstype2str(enum gsm_bts_type type);
349
350static inline int is_ipaccess_bts(struct gsm_bts *bts)
351{
352 switch (bts->type) {
353 case GSM_BTS_TYPE_NANOBTS_900:
354 case GSM_BTS_TYPE_NANOBTS_1800:
355 return 1;
356 default:
357 break;
358 }
359 return 0;
360}
361
Harald Welte52b1f982008-12-23 20:25:15 +0000362#endif