blob: 8af07816fe9d6e0577645cf5bc9f216906951487 [file] [log] [blame]
Harald Welte59b04682009-06-10 05:40:52 +08001#ifndef _GSM_DATA_H
2#define _GSM_DATA_H
3
4#include <sys/types.h>
5
Harald Welte91afe4c2009-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 Welte03740842009-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 Welte59b04682009-06-10 05:40:52 +080042#include <openbsc/timer.h>
43#include <openbsc/gsm_04_08.h>
Harald Welte39274f42009-07-29 15:41:29 +020044#include <openbsc/abis_rsl.h>
Harald Welte03740842009-06-10 23:11:52 +080045#include <openbsc/mncc.h>
Harald Welte3ae3cec2009-06-20 19:04:31 +020046#include <openbsc/tlv.h>
Harald Welte59b04682009-06-10 05:40:52 +080047
48#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
49
Harald Welte59b04682009-06-10 05:40:52 +080050#define TRX_NR_TS 8
51#define TS_MAX_LCHAN 8
52
53#define HARDCODED_ARFCN 123
54#define HARDCODED_TSC 7
55#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
56
Harald Welte2d73d4e2009-08-06 17:38:10 +020057/* for multi-drop config */
58#define HARDCODED_BTS0_TS 1
59#define HARDCODED_BTS1_TS 6
60#define HARDCODED_BTS2_TS 11
61
Harald Welte59b04682009-06-10 05:40:52 +080062enum gsm_hooks {
63 GSM_HOOK_NM_SWLOAD,
64 GSM_HOOK_RR_PAGING,
65};
66
67enum gsm_paging_event {
68 GSM_PAGING_SUCCEEDED,
69 GSM_PAGING_EXPIRED,
Holger Freyther8bdf7622009-04-18 13:48:55 +020070 GSM_PAGING_OOM,
Harald Welte59b04682009-06-10 05:40:52 +080071};
72
73struct msgb;
74typedef int gsm_cbfn(unsigned int hooknum,
75 unsigned int event,
76 struct msgb *msg,
77 void *data, void *param);
78
79/*
80 * Use the channel. As side effect the lchannel recycle timer
81 * will be started.
82 */
Harald Welte156c5e62009-07-05 14:02:46 +020083#define LCHAN_RELEASE_TIMEOUT 20, 0
Harald Welte59b04682009-06-10 05:40:52 +080084#define use_lchan(lchan) \
85 do { lchan->use_count++; \
86 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
87 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
88 lchan->nr, lchan->use_count); \
89 bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
90
91#define put_lchan(lchan) \
92 do { lchan->use_count--; \
93 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
94 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
95 lchan->nr, lchan->use_count); \
96 } while(0);
97
98
99/* communications link with a BTS */
100struct gsm_bts_link {
101 struct gsm_bts *bts;
102};
103
Harald Welte59b04682009-06-10 05:40:52 +0800104struct gsm_lchan;
105struct gsm_subscriber;
Harald Welte03740842009-06-10 23:11:52 +0800106struct gsm_mncc;
Harald Welte3c062072009-07-28 18:25:29 +0200107struct rtp_socket;
Harald Welte59b04682009-06-10 05:40:52 +0800108
Harald Welte59b04682009-06-10 05:40:52 +0800109/* Network Management State */
110struct gsm_nm_state {
111 u_int8_t operational;
112 u_int8_t administrative;
113 u_int8_t availability;
114};
Harald Welte59b04682009-06-10 05:40:52 +0800115
116/*
117 * LOCATION UPDATING REQUEST state
118 *
119 * Our current operation is:
120 * - Get imei/tmsi
121 * - Accept/Reject according to global policy
122 */
123struct gsm_loc_updating_operation {
124 struct timer_list updating_timer;
125 int waiting_for_imsi : 1;
126 int waiting_for_imei : 1;
127};
128
129struct gsm_lchan {
130 /* The TS that we're part of */
131 struct gsm_bts_trx_ts *ts;
132 /* The logical subslot number in the TS */
133 u_int8_t nr;
134 /* The logical channel type */
135 enum gsm_chan_t type;
Harald Welte39274f42009-07-29 15:41:29 +0200136 /* RSL channel mode */
137 enum rsl_cmod_spd rsl_cmode;
Harald Welte59b04682009-06-10 05:40:52 +0800138 /* If TCH, traffic channel mode */
Harald Welte39274f42009-07-29 15:41:29 +0200139 enum gsm48_chan_mode tch_mode;
Harald Welte59b04682009-06-10 05:40:52 +0800140 /* Power levels for MS and BTS */
141 u_int8_t bs_power;
142 u_int8_t ms_power;
143
144 /* To whom we are allocated at the moment */
145 struct gsm_subscriber *subscr;
146
147 /* Timer started to release the channel */
148 struct timer_list release_timer;
149
Harald Welte59b04682009-06-10 05:40:52 +0800150 /*
151 * Operations that have a state and might be pending
152 */
153 struct gsm_loc_updating_operation *loc_operation;
154
155 /* use count. how many users use this channel */
156 unsigned int use_count;
157};
158
159struct gsm_e1_subslot {
160 /* Number of E1 link */
161 u_int8_t e1_nr;
162 /* Number of E1 TS inside E1 link */
163 u_int8_t e1_ts;
164 /* Sub-slot within the E1 TS, 0xff if full TS */
165 u_int8_t e1_ts_ss;
166};
167
168#define BTS_TRX_F_ACTIVATED 0x0001
169/* One Timeslot in a TRX */
170struct gsm_bts_trx_ts {
171 struct gsm_bts_trx *trx;
172 /* number of this timeslot at the TRX */
173 u_int8_t nr;
174
175 enum gsm_phys_chan_config pchan;
176
177 unsigned int flags;
178 struct gsm_nm_state nm_state;
Harald Welte3ae3cec2009-06-20 19:04:31 +0200179 struct tlv_parsed nm_attr;
Harald Welte59b04682009-06-10 05:40:52 +0800180
181 /* To which E1 subslot are we connected */
182 struct gsm_e1_subslot e1_link;
183 struct {
184 u_int32_t bound_ip;
185 u_int16_t bound_port;
Harald Welte8cdeaad2009-07-12 09:50:35 +0200186 u_int8_t rtp_payload2;
187 u_int16_t conn_id;
Harald Welte3c062072009-07-28 18:25:29 +0200188 struct rtp_socket *rtp_socket;
Harald Welte59b04682009-06-10 05:40:52 +0800189 } abis_ip;
190
191 struct gsm_lchan lchan[TS_MAX_LCHAN];
192};
193
194/* One TRX in a BTS */
195struct gsm_bts_trx {
Harald Weltee712a5f2009-06-21 16:17:15 +0200196 /* list header in bts->trx_list */
197 struct llist_head list;
198
Harald Welte59b04682009-06-10 05:40:52 +0800199 struct gsm_bts *bts;
200 /* number of this TRX in the BTS */
201 u_int8_t nr;
202 /* how do we talk RSL with this TRX? */
Harald Welte62868882009-08-08 16:12:58 +0200203 struct gsm_e1_subslot rsl_e1_link;
204 u_int8_t rsl_tei;
Harald Welte59b04682009-06-10 05:40:52 +0800205 struct e1inp_sign_link *rsl_link;
Harald Welte62868882009-08-08 16:12:58 +0200206
Harald Welte59b04682009-06-10 05:40:52 +0800207 struct gsm_nm_state nm_state;
Harald Welte3ae3cec2009-06-20 19:04:31 +0200208 struct tlv_parsed nm_attr;
Harald Welte59b04682009-06-10 05:40:52 +0800209 struct {
210 struct gsm_nm_state nm_state;
211 } bb_transc;
212
213 u_int16_t arfcn;
Harald Welte91afe4c2009-06-20 18:15:19 +0200214 int nominal_power; /* in dBm */
215 unsigned int max_power_red; /* in actual dB */
Harald Welte59b04682009-06-10 05:40:52 +0800216
217 union {
218 struct {
219 struct {
220 struct gsm_nm_state nm_state;
221 } bbsig;
222 struct {
223 struct gsm_nm_state nm_state;
224 } pa;
225 } bs11;
226 };
227 struct gsm_bts_trx_ts ts[TRX_NR_TS];
228};
229
230enum gsm_bts_type {
231 GSM_BTS_TYPE_UNKNOWN,
232 GSM_BTS_TYPE_BS11,
233 GSM_BTS_TYPE_NANOBTS_900,
234 GSM_BTS_TYPE_NANOBTS_1800,
235};
236
237/**
238 * A pending paging request
239 */
240struct gsm_paging_request {
241 /* list_head for list of all paging requests */
242 struct llist_head entry;
243 /* the subscriber which we're paging. Later gsm_paging_request
244 * should probably become a part of the gsm_subscriber struct? */
245 struct gsm_subscriber *subscr;
246 /* back-pointer to the BTS on which we are paging */
247 struct gsm_bts *bts;
248 /* what kind of channel type do we ask the MS to establish */
249 int chan_type;
250
251 /* Timer 3113: how long do we try to page? */
252 struct timer_list T3113;
253
254 /* callback to be called in case paging completes */
255 gsm_cbfn *cbfn;
256 void *cbfn_param;
257};
258#define T3113_VALUE 60, 0
259
260/*
261 * This keeps track of the paging status of one BTS. It
262 * includes a number of pending requests, a back pointer
263 * to the gsm_bts, a timer and some more state.
264 */
265struct gsm_bts_paging_state {
266 /* pending requests */
267 struct llist_head pending_requests;
268 struct gsm_paging_request *last_request;
269 struct gsm_bts *bts;
270
271 struct timer_list work_timer;
272
273 /* load */
274 u_int16_t available_slots;
275};
276
277struct gsm_envabtse {
278 struct gsm_nm_state nm_state;
279};
280
281/* One BTS */
282struct gsm_bts {
Harald Weltee712a5f2009-06-21 16:17:15 +0200283 /* list header in net->bts_list */
284 struct llist_head list;
285
Harald Welte59b04682009-06-10 05:40:52 +0800286 struct gsm_network *network;
287 /* number of ths BTS in network */
288 u_int8_t nr;
289 /* location area code of this BTS */
290 u_int8_t location_area_code;
291 /* Training Sequence Code */
292 u_int8_t tsc;
293 /* Base Station Identification Code (BSIC) */
294 u_int8_t bsic;
295 /* type of BTS */
296 enum gsm_bts_type type;
Harald Welte91afe4c2009-06-20 18:15:19 +0200297 enum gsm_band band;
Harald Welte59b04682009-06-10 05:40:52 +0800298 /* how do we talk OML with this TRX? */
Harald Welte62868882009-08-08 16:12:58 +0200299 struct gsm_e1_subslot oml_e1_link;
300 u_int8_t oml_tei;
Harald Welte59b04682009-06-10 05:40:52 +0800301 struct e1inp_sign_link *oml_link;
302
303 /* Abis network management O&M handle */
304 struct abis_nm_h *nmh;
305 struct gsm_nm_state nm_state;
Harald Welte3ae3cec2009-06-20 19:04:31 +0200306 struct tlv_parsed nm_attr;
Harald Welte59b04682009-06-10 05:40:52 +0800307
308 /* number of this BTS on given E1 link */
309 u_int8_t bts_nr;
310
311 struct gsm48_control_channel_descr chan_desc;
312
313 /* paging state and control */
314 struct gsm_bts_paging_state paging;
315
316 /* CCCH is on C0 */
317 struct gsm_bts_trx *c0;
318
319 struct {
320 struct gsm_nm_state nm_state;
321 } site_mgr;
322
323 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
324 union {
325 struct {
326 u_int16_t site_id;
327 u_int16_t bts_id;
328 } ip_access;
329 struct {
330 struct {
331 struct gsm_nm_state nm_state;
332 } cclk;
333 struct {
334 struct gsm_nm_state nm_state;
335 } rack;
336 struct gsm_envabtse envabtse[4];
337 } bs11;
338 };
339
340 /* transceivers */
341 int num_trx;
Harald Weltee712a5f2009-06-21 16:17:15 +0200342 struct llist_head trx_list;
Harald Welte59b04682009-06-10 05:40:52 +0800343};
344
345struct gsm_network {
346 /* global parameters */
347 u_int16_t country_code;
348 u_int16_t network_code;
349 char *name_long;
350 char *name_short;
351
Harald Welte03740842009-06-10 23:11:52 +0800352 /* layer 4 */
353 int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
354 struct llist_head upqueue;
355 struct llist_head trans_list;
356
Harald Welte59b04682009-06-10 05:40:52 +0800357 unsigned int num_bts;
Harald Weltee712a5f2009-06-21 16:17:15 +0200358 struct llist_head bts_list;
Harald Welte59b04682009-06-10 05:40:52 +0800359};
360
361#define SMS_HDR_SIZE 128
362#define SMS_TEXT_SIZE 256
363struct gsm_sms {
364 u_int64_t id;
365 struct gsm_subscriber *sender;
366 struct gsm_subscriber *receiver;
367
Harald Welte156c5e62009-07-05 14:02:46 +0200368 unsigned long validity_minutes;
Harald Welte68b7df22009-08-08 16:03:15 +0200369 u_int8_t reply_path_req;
370 u_int8_t status_rep_req;
371 u_int8_t ud_hdr_ind;
372 u_int8_t protocol_id;
373 u_int8_t data_coding_scheme;
374 u_int8_t msg_ref;
375 char dest_addr[20+1]; /* DA LV is 12 bytes max, i.e. 10 bytes
376 * BCD == 20 bytes string */
377 u_int8_t user_data_len;
378 u_int8_t user_data[SMS_TEXT_SIZE];
Harald Welteb78996d2009-07-27 20:11:35 +0200379
Harald Welte59b04682009-06-10 05:40:52 +0800380 char text[SMS_TEXT_SIZE];
381};
382
Harald Weltee712a5f2009-06-21 16:17:15 +0200383struct gsm_network *gsm_network_init(u_int16_t country_code, u_int16_t network_code,
Harald Welte03740842009-06-10 23:11:52 +0800384 int (*mncc_recv)(struct gsm_network *, int, void *));
Harald Weltee712a5f2009-06-21 16:17:15 +0200385struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type,
386 u_int8_t tsc, u_int8_t bsic);
387struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
388
389struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
390struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
Harald Welte59b04682009-06-10 05:40:52 +0800391
392const char *gsm_pchan_name(enum gsm_phys_chan_config c);
Harald Welte2ef33202009-08-07 00:32:22 +0200393enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
Harald Welte59b04682009-06-10 05:40:52 +0800394const char *gsm_lchan_name(enum gsm_chan_t c);
395const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
396char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
397
398enum gsm_e1_event {
399 EVT_E1_NONE,
400 EVT_E1_TEI_UP,
401 EVT_E1_TEI_DN,
402};
403
404void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
405 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte498feae2009-08-08 15:38:29 +0200406enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther56f59bb2009-06-12 17:39:38 +0200407const char *btstype2str(enum gsm_bts_type type);
Harald Welte59b04682009-06-10 05:40:52 +0800408struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
409 struct gsm_bts *start_bts);
410
Harald Welte91afe4c2009-06-20 18:15:19 +0200411char *gsm_band_name(enum gsm_band band);
Harald Welte62868882009-08-08 16:12:58 +0200412enum gsm_band gsm_band_parse(const char *mhz);
Harald Welte91afe4c2009-06-20 18:15:19 +0200413
Andreas Eversberge4d51462009-06-29 15:19:38 +0200414extern void *tall_bsc_ctx;
Harald Weltea8379772009-06-20 22:36:41 +0200415
Harald Welte59b04682009-06-10 05:40:52 +0800416static inline int is_ipaccess_bts(struct gsm_bts *bts)
417{
418 switch (bts->type) {
419 case GSM_BTS_TYPE_NANOBTS_900:
420 case GSM_BTS_TYPE_NANOBTS_1800:
421 return 1;
422 default:
423 break;
424 }
425 return 0;
426}
427
428#endif