blob: 071b1c6ec3da476b10315ef9ffa27170f354ec2b [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++; \
Harald Welteff117a82009-05-23 05:22:08 +000042 bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
Holger Freytherc6ea9db2008-12-30 19:18:21 +000043
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;
Harald Welte45b407a2009-05-23 15:51:12 +0000141 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000142 enum gsm_chan_t type;
Harald Welte45b407a2009-05-23 15:51:12 +0000143 /* If TCH, traffic channel mode */
144 enum gsm_chan_t tch_mode;
Harald Welted4c9bf32009-02-15 16:56:18 +0000145 /* Power levels for MS and BTS */
146 u_int8_t bs_power;
147 u_int8_t ms_power;
148
Harald Welte8470bf22008-12-25 23:28:35 +0000149 /* To whom we are allocated at the moment */
150 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000151
152 /* Timer started to release the channel */
153 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000154
155 /* local end of a call, if any */
156 struct gsm_call call;
Holger Freyther3186bf22008-12-29 06:23:49 +0000157
158 /* temporary user data, to be removed... and merged into gsm_call */
159 void *user_data;
Holger Freytherb7193e42008-12-29 17:44:08 +0000160
Holger Freyther73487a22008-12-31 18:53:57 +0000161 /*
162 * Operations that have a state and might be pending
163 */
164 struct gsm_loc_updating_operation *loc_operation;
165
Holger Freytherb7193e42008-12-29 17:44:08 +0000166 /* use count. how many users use this channel */
167 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000168};
169
Harald Welte85770c72009-01-18 17:47:32 +0000170struct gsm_e1_subslot {
171 /* Number of E1 link */
172 u_int8_t e1_nr;
173 /* Number of E1 TS inside E1 link */
174 u_int8_t e1_ts;
175 /* Sub-slot within the E1 TS, 0xff if full TS */
176 u_int8_t e1_ts_ss;
177};
178
Harald Welte52b1f982008-12-23 20:25:15 +0000179#define BTS_TRX_F_ACTIVATED 0x0001
180/* One Timeslot in a TRX */
181struct gsm_bts_trx_ts {
182 struct gsm_bts_trx *trx;
183 /* number of this timeslot at the TRX */
184 u_int8_t nr;
185
Harald Welte8470bf22008-12-25 23:28:35 +0000186 enum gsm_phys_chan_config pchan;
187
Harald Welte52b1f982008-12-23 20:25:15 +0000188 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000189 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000190 struct gsm_attr *nm_attr;
Harald Welte8470bf22008-12-25 23:28:35 +0000191
Harald Welte85770c72009-01-18 17:47:32 +0000192 /* To which E1 subslot are we connected */
193 struct gsm_e1_subslot e1_link;
Harald Welte75099262009-02-16 21:12:08 +0000194 struct {
195 u_int32_t bound_ip;
196 u_int16_t bound_port;
197 u_int8_t attr_fc;
198 u_int16_t attr_f8;
199 } abis_ip;
Harald Welte85770c72009-01-18 17:47:32 +0000200
Harald Welte8470bf22008-12-25 23:28:35 +0000201 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000202};
203
204/* One TRX in a BTS */
205struct gsm_bts_trx {
206 struct gsm_bts *bts;
207 /* number of this TRX in the BTS */
208 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000209 /* how do we talk RSL with this TRX? */
210 struct e1inp_sign_link *rsl_link;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000211 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000212 struct gsm_attr *nm_attr;
213 struct {
214 struct gsm_nm_state nm_state;
215 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000216
217 u_int16_t arfcn;
Harald Welte85770c72009-01-18 17:47:32 +0000218 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000219};
220
Harald Welte978cb422009-01-18 17:57:27 +0000221enum gsm_bts_type {
222 GSM_BTS_TYPE_UNKNOWN,
223 GSM_BTS_TYPE_BS11,
Harald Weltebbcc7a52009-02-14 19:45:44 +0000224 GSM_BTS_TYPE_NANOBTS_900,
225 GSM_BTS_TYPE_NANOBTS_1800,
Harald Welte978cb422009-01-18 17:57:27 +0000226};
227
Holger Freytherceb59b72009-02-06 18:54:00 +0000228/**
229 * A pending paging request
230 */
231struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000232 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000233 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000234 /* the subscriber which we're paging. Later gsm_paging_request
235 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000236 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000237 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000238 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000239 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000240 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000241
242 /* Timer 3113: how long do we try to page? */
243 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000244
245 /* callback to be called in case paging completes */
246 gsm_cbfn *cbfn;
247 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000248};
Harald Weltecd06bfb2009-02-10 17:33:56 +0000249#define T3113_VALUE 60, 0
Holger Freytherceb59b72009-02-06 18:54:00 +0000250
251/*
252 * This keeps track of the paging status of one BTS. It
253 * includes a number of pending requests, a back pointer
254 * to the gsm_bts, a timer and some more state.
255 */
256struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000257 /* pending requests */
258 struct llist_head pending_requests;
259 struct gsm_paging_request *last_request;
260 struct gsm_bts *bts;
261
Harald Welte75a1fa82009-02-17 01:39:41 +0000262 struct timer_list work_timer;
263
Holger Freyther392209c2009-02-10 00:06:19 +0000264 /* load */
265 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000266};
267
Harald Welte52b1f982008-12-23 20:25:15 +0000268/* One BTS */
269struct gsm_bts {
270 struct gsm_network *network;
271 /* number of ths BTS in network */
272 u_int8_t nr;
273 /* location area code of this BTS */
274 u_int8_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000275 /* Training Sequence Code */
276 u_int8_t tsc;
Harald Welte978cb422009-01-18 17:57:27 +0000277 /* type of BTS */
278 enum gsm_bts_type type;
Harald Welte1fa60c82009-02-09 18:13:26 +0000279 /* how do we talk OML with this TRX? */
280 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000281
282 /* Abis network management O&M handle */
283 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000284 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000285 struct gsm_attr *nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000286
Harald Welte52b1f982008-12-23 20:25:15 +0000287 /* number of this BTS on given E1 link */
288 u_int8_t bts_nr;
289
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000290 struct gsm48_control_channel_descr chan_desc;
291
Holger Freytherceb59b72009-02-06 18:54:00 +0000292 /* paging state and control */
293 struct gsm_bts_paging_state paging;
294
Harald Welte52b1f982008-12-23 20:25:15 +0000295 /* CCCH is on C0 */
296 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000297
298 struct {
299 struct gsm_nm_state nm_state;
300 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000301
302 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
303 struct {
304 u_int16_t site_id;
305 u_int16_t bts_id;
306 } ip_access;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000307
Harald Welte52b1f982008-12-23 20:25:15 +0000308 /* transceivers */
309 int num_trx;
310 struct gsm_bts_trx trx[BTS_MAX_TRX+1];
311};
312
Harald Welte52b1f982008-12-23 20:25:15 +0000313struct gsm_network {
314 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000315 u_int16_t country_code;
316 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000317 char *name_long;
318 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000319
320 unsigned int num_bts;
321 /* private lists */
322 struct gsm_bts bts[GSM_MAX_BTS+1];
Harald Welte52b1f982008-12-23 20:25:15 +0000323};
324
Harald Welte7e310b12009-03-30 20:56:32 +0000325#define SMS_HDR_SIZE 128
326#define SMS_TEXT_SIZE 256
327struct gsm_sms {
328 u_int64_t id;
329 struct gsm_subscriber *sender;
330 struct gsm_subscriber *receiver;
331
332 unsigned char header[SMS_HDR_SIZE];
333 char text[SMS_TEXT_SIZE];
334};
335
Harald Welte8c1d0e42009-02-15 03:38:12 +0000336struct gsm_network *gsm_network_init(unsigned int num_bts, enum gsm_bts_type bts_type,
337 u_int16_t country_code, u_int16_t network_code);
Harald Welte8470bf22008-12-25 23:28:35 +0000338
Harald Weltea72c98e2009-01-04 16:10:38 +0000339const char *gsm_pchan_name(enum gsm_phys_chan_config c);
340const char *gsm_lchan_name(enum gsm_chan_t c);
341const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte23a68632009-02-19 17:06:42 +0000342char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Weltea72c98e2009-01-04 16:10:38 +0000343
Harald Weltead384642008-12-26 10:20:07 +0000344enum gsm_e1_event {
345 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000346 EVT_E1_TEI_UP,
347 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000348};
349
Harald Weltecd06bfb2009-02-10 17:33:56 +0000350void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
351 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte32201c12009-03-10 12:15:10 +0000352enum gsm_bts_type parse_btstype(char *arg);
353char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000354struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
355 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000356
357static inline int is_ipaccess_bts(struct gsm_bts *bts)
358{
359 switch (bts->type) {
360 case GSM_BTS_TYPE_NANOBTS_900:
361 case GSM_BTS_TYPE_NANOBTS_1800:
362 return 1;
363 default:
364 break;
365 }
366 return 0;
367}
368
Harald Welte52b1f982008-12-23 20:25:15 +0000369#endif