blob: 2c05260149f3bb452d6a34fc9e7ede8d6930cd5b [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++; \
Harald Welteff117a82009-05-23 05:22:08 +000043 bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
Holger Freytherc6ea9db2008-12-30 19:18:21 +000044
45#define put_lchan(lchan) \
46 do { lchan->use_count--; } while(0);
47
Harald Welte52b1f982008-12-23 20:25:15 +000048/* communications link with a BTS */
49struct gsm_bts_link {
50 struct gsm_bts *bts;
51};
52
Harald Weltea3d04382008-12-27 17:02:56 +000053enum gsm_call_type {
54 GSM_CT_NONE,
55 GSM_CT_MO,
56 GSM_CT_MT,
57};
58
59enum gsm_call_state {
60 GSM_CSTATE_NULL,
61 GSM_CSTATE_INITIATED,
62 GSM_CSTATE_ACTIVE,
63 GSM_CSTATE_RELEASE_REQ,
64};
65
Harald Welte49f48b82009-02-17 15:29:33 +000066struct gsm_lchan;
67struct gsm_subscriber;
68
Harald Weltea3d04382008-12-27 17:02:56 +000069/* One end of a call */
70struct gsm_call {
71 enum gsm_call_type type;
72 enum gsm_call_state state;
73 u_int8_t transaction_id; /* 10.3.2 */
74
Harald Welte49f48b82009-02-17 15:29:33 +000075 /* the 'local' channel */
76 struct gsm_lchan *local_lchan;
77 /* the 'remote' channel */
78 struct gsm_lchan *remote_lchan;
79
Harald Welte0932d1e2009-02-16 22:53:52 +000080 /* the 'remote' subscriber */
81 struct gsm_subscriber *called_subscr;
Harald Weltea3d04382008-12-27 17:02:56 +000082};
83
84
Harald Welte8470bf22008-12-25 23:28:35 +000085enum gsm_phys_chan_config {
86 GSM_PCHAN_NONE,
87 GSM_PCHAN_CCCH,
88 GSM_PCHAN_CCCH_SDCCH4,
89 GSM_PCHAN_TCH_F,
90 GSM_PCHAN_TCH_H,
91 GSM_PCHAN_SDCCH8_SACCH8C,
92 GSM_PCHAN_UNKNOWN,
93};
94
95enum gsm_chan_t {
96 GSM_LCHAN_NONE,
97 GSM_LCHAN_SDCCH,
98 GSM_LCHAN_TCH_F,
99 GSM_LCHAN_TCH_H,
100 GSM_LCHAN_UNKNOWN,
101};
102
Harald Weltee14a57c2008-12-29 04:08:28 +0000103
104/* Channel Request reason */
105enum gsm_chreq_reason_t {
106 GSM_CHREQ_REASON_EMERG,
107 GSM_CHREQ_REASON_PAG,
108 GSM_CHREQ_REASON_CALL,
109 GSM_CHREQ_REASON_LOCATION_UPD,
110 GSM_CHREQ_REASON_OTHER,
111};
112
Harald Weltebbcc7a52009-02-14 19:45:44 +0000113/* Network Management State */
114struct gsm_nm_state {
115 u_int8_t operational;
116 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000117 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000118};
Harald Welte8c1d0e42009-02-15 03:38:12 +0000119struct gsm_attr {
120 u_int8_t len;
121 u_int8_t data[0];
122};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000123
Holger Freyther73487a22008-12-31 18:53:57 +0000124/*
125 * LOCATION UPDATING REQUEST state
126 *
127 * Our current operation is:
128 * - Get imei/tmsi
129 * - Accept/Reject according to global policy
130 */
131struct gsm_loc_updating_operation {
132 struct timer_list updating_timer;
133 int waiting_for_imsi : 1;
134 int waiting_for_imei : 1;
135};
136
Harald Welte8470bf22008-12-25 23:28:35 +0000137struct gsm_lchan {
138 /* The TS that we're part of */
139 struct gsm_bts_trx_ts *ts;
140 /* The logical subslot number in the TS */
141 u_int8_t nr;
Harald Welte45b407a2009-05-23 15:51:12 +0000142 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000143 enum gsm_chan_t type;
Harald Welte45b407a2009-05-23 15:51:12 +0000144 /* If TCH, traffic channel mode */
145 enum gsm_chan_t tch_mode;
Harald Welted4c9bf32009-02-15 16:56:18 +0000146 /* Power levels for MS and BTS */
147 u_int8_t bs_power;
148 u_int8_t ms_power;
149
Harald Welte8470bf22008-12-25 23:28:35 +0000150 /* To whom we are allocated at the moment */
151 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000152
153 /* Timer started to release the channel */
154 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000155
156 /* local end of a call, if any */
157 struct gsm_call call;
Holger Freyther3186bf22008-12-29 06:23:49 +0000158
159 /* temporary user data, to be removed... and merged into gsm_call */
160 void *user_data;
Holger Freytherb7193e42008-12-29 17:44:08 +0000161
Holger Freyther73487a22008-12-31 18:53:57 +0000162 /*
163 * Operations that have a state and might be pending
164 */
165 struct gsm_loc_updating_operation *loc_operation;
166
Holger Freytherb7193e42008-12-29 17:44:08 +0000167 /* use count. how many users use this channel */
168 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000169};
170
Harald Welte85770c72009-01-18 17:47:32 +0000171struct gsm_e1_subslot {
172 /* Number of E1 link */
173 u_int8_t e1_nr;
174 /* Number of E1 TS inside E1 link */
175 u_int8_t e1_ts;
176 /* Sub-slot within the E1 TS, 0xff if full TS */
177 u_int8_t e1_ts_ss;
178};
179
Harald Welte52b1f982008-12-23 20:25:15 +0000180#define BTS_TRX_F_ACTIVATED 0x0001
181/* One Timeslot in a TRX */
182struct gsm_bts_trx_ts {
183 struct gsm_bts_trx *trx;
184 /* number of this timeslot at the TRX */
185 u_int8_t nr;
186
Harald Welte8470bf22008-12-25 23:28:35 +0000187 enum gsm_phys_chan_config pchan;
188
Harald Welte52b1f982008-12-23 20:25:15 +0000189 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000190 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000191 struct gsm_attr *nm_attr;
Harald Welte8470bf22008-12-25 23:28:35 +0000192
Harald Welte85770c72009-01-18 17:47:32 +0000193 /* To which E1 subslot are we connected */
194 struct gsm_e1_subslot e1_link;
Harald Welte75099262009-02-16 21:12:08 +0000195 struct {
196 u_int32_t bound_ip;
197 u_int16_t bound_port;
198 u_int8_t attr_fc;
199 u_int16_t attr_f8;
200 } abis_ip;
Harald Welte85770c72009-01-18 17:47:32 +0000201
Harald Welte8470bf22008-12-25 23:28:35 +0000202 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000203};
204
205/* One TRX in a BTS */
206struct gsm_bts_trx {
207 struct gsm_bts *bts;
208 /* number of this TRX in the BTS */
209 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000210 /* how do we talk RSL with this TRX? */
211 struct e1inp_sign_link *rsl_link;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000212 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000213 struct gsm_attr *nm_attr;
214 struct {
215 struct gsm_nm_state nm_state;
216 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000217
218 u_int16_t arfcn;
Harald Welte85770c72009-01-18 17:47:32 +0000219 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000220};
221
Harald Welte978cb422009-01-18 17:57:27 +0000222enum gsm_bts_type {
223 GSM_BTS_TYPE_UNKNOWN,
224 GSM_BTS_TYPE_BS11,
Harald Weltebbcc7a52009-02-14 19:45:44 +0000225 GSM_BTS_TYPE_NANOBTS_900,
226 GSM_BTS_TYPE_NANOBTS_1800,
Harald Welte978cb422009-01-18 17:57:27 +0000227};
228
Holger Freytherceb59b72009-02-06 18:54:00 +0000229/**
230 * A pending paging request
231 */
232struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000233 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000234 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000235 /* the subscriber which we're paging. Later gsm_paging_request
236 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000237 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000238 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000239 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000240 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000241 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000242
243 /* Timer 3113: how long do we try to page? */
244 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000245
246 /* callback to be called in case paging completes */
247 gsm_cbfn *cbfn;
248 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000249};
Harald Weltecd06bfb2009-02-10 17:33:56 +0000250#define T3113_VALUE 60, 0
Holger Freytherceb59b72009-02-06 18:54:00 +0000251
252/*
253 * This keeps track of the paging status of one BTS. It
254 * includes a number of pending requests, a back pointer
255 * to the gsm_bts, a timer and some more state.
256 */
257struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000258 /* 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 Welte78f2f502009-05-23 16:56:52 +0000278 /* Base Station Identification Code (BSIC) */
279 u_int8_t bsic;
Harald Welte978cb422009-01-18 17:57:27 +0000280 /* type of BTS */
281 enum gsm_bts_type type;
Harald Welte1fa60c82009-02-09 18:13:26 +0000282 /* how do we talk OML with this TRX? */
283 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000284
285 /* Abis network management O&M handle */
286 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000287 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000288 struct gsm_attr *nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000289
Harald Welte52b1f982008-12-23 20:25:15 +0000290 /* number of this BTS on given E1 link */
291 u_int8_t bts_nr;
292
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000293 struct gsm48_control_channel_descr chan_desc;
294
Holger Freytherceb59b72009-02-06 18:54:00 +0000295 /* paging state and control */
296 struct gsm_bts_paging_state paging;
297
Harald Welte52b1f982008-12-23 20:25:15 +0000298 /* CCCH is on C0 */
299 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000300
301 struct {
302 struct gsm_nm_state nm_state;
303 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000304
305 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
306 struct {
307 u_int16_t site_id;
308 u_int16_t bts_id;
309 } ip_access;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000310
Harald Welte52b1f982008-12-23 20:25:15 +0000311 /* transceivers */
312 int num_trx;
313 struct gsm_bts_trx trx[BTS_MAX_TRX+1];
314};
315
Harald Welte52b1f982008-12-23 20:25:15 +0000316struct gsm_network {
317 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000318 u_int16_t country_code;
319 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000320 char *name_long;
321 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000322
323 unsigned int num_bts;
324 /* private lists */
325 struct gsm_bts bts[GSM_MAX_BTS+1];
Harald Welte52b1f982008-12-23 20:25:15 +0000326};
327
Harald Welte7e310b12009-03-30 20:56:32 +0000328#define SMS_HDR_SIZE 128
329#define SMS_TEXT_SIZE 256
330struct gsm_sms {
331 u_int64_t id;
332 struct gsm_subscriber *sender;
333 struct gsm_subscriber *receiver;
334
335 unsigned char header[SMS_HDR_SIZE];
336 char text[SMS_TEXT_SIZE];
337};
338
Harald Welte8c1d0e42009-02-15 03:38:12 +0000339struct gsm_network *gsm_network_init(unsigned int num_bts, enum gsm_bts_type bts_type,
340 u_int16_t country_code, u_int16_t network_code);
Harald Welte8470bf22008-12-25 23:28:35 +0000341
Harald Weltea72c98e2009-01-04 16:10:38 +0000342const char *gsm_pchan_name(enum gsm_phys_chan_config c);
343const char *gsm_lchan_name(enum gsm_chan_t c);
344const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte23a68632009-02-19 17:06:42 +0000345char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Weltea72c98e2009-01-04 16:10:38 +0000346
Harald Weltead384642008-12-26 10:20:07 +0000347enum gsm_e1_event {
348 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000349 EVT_E1_TEI_UP,
350 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000351};
352
Harald Weltecd06bfb2009-02-10 17:33:56 +0000353void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
354 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte32201c12009-03-10 12:15:10 +0000355enum gsm_bts_type parse_btstype(char *arg);
356char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000357struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
358 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000359
360static inline int is_ipaccess_bts(struct gsm_bts *bts)
361{
362 switch (bts->type) {
363 case GSM_BTS_TYPE_NANOBTS_900:
364 case GSM_BTS_TYPE_NANOBTS_1800:
365 return 1;
366 default:
367 break;
368 }
369 return 0;
370}
371
Harald Welte52b1f982008-12-23 20:25:15 +0000372#endif