blob: 20e62c3c87d789262aff8bd37a3987f7b01d7937 [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 Weltefcd24452009-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 Welte4bfdfe72009-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 Welte255539c2008-12-28 02:26:27 +000042#include <openbsc/timer.h>
Holger Freyther1adb4ff2009-02-04 00:04:52 +000043#include <openbsc/gsm_04_08.h>
Harald Welte4bfdfe72009-06-10 23:11:52 +080044#include <openbsc/mncc.h>
Harald Welte93e9d172009-06-20 19:04:31 +020045#include <openbsc/tlv.h>
Harald Welte255539c2008-12-28 02:26:27 +000046
Harald Welte8470bf22008-12-25 23:28:35 +000047#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
48
Harald Welte85770c72009-01-18 17:47:32 +000049#define TRX_NR_TS 8
Harald Welte8470bf22008-12-25 23:28:35 +000050#define TS_MAX_LCHAN 8
Harald Welte52b1f982008-12-23 20:25:15 +000051
52#define HARDCODED_ARFCN 123
Harald Welte02b0e092009-02-28 13:11:07 +000053#define HARDCODED_TSC 7
Harald Welte78f2f502009-05-23 16:56:52 +000054#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
Harald Welte52b1f982008-12-23 20:25:15 +000055
Harald Welte8e1e3ee2009-02-01 13:32:45 +000056enum gsm_hooks {
57 GSM_HOOK_NM_SWLOAD,
Harald Welte0932d1e2009-02-16 22:53:52 +000058 GSM_HOOK_RR_PAGING,
59};
60
61enum gsm_paging_event {
62 GSM_PAGING_SUCCEEDED,
63 GSM_PAGING_EXPIRED,
Holger Freyther85a7b362009-04-18 13:48:55 +020064 GSM_PAGING_OOM,
Harald Welte8e1e3ee2009-02-01 13:32:45 +000065};
66
67struct msgb;
68typedef int gsm_cbfn(unsigned int hooknum,
69 unsigned int event,
70 struct msgb *msg,
71 void *data, void *param);
72
Holger Freytherc6ea9db2008-12-30 19:18:21 +000073/*
74 * Use the channel. As side effect the lchannel recycle timer
75 * will be started.
76 */
Harald Welteb9c758b2009-07-05 14:02:46 +020077#define LCHAN_RELEASE_TIMEOUT 20, 0
Holger Freytherc6ea9db2008-12-30 19:18:21 +000078#define use_lchan(lchan) \
79 do { lchan->use_count++; \
Holger Freyther4f584c32009-06-02 02:55:07 +000080 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
81 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
82 lchan->nr, lchan->use_count); \
Harald Welteff117a82009-05-23 05:22:08 +000083 bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
Holger Freytherc6ea9db2008-12-30 19:18:21 +000084
85#define put_lchan(lchan) \
Holger Freyther4f584c32009-06-02 02:55:07 +000086 do { lchan->use_count--; \
87 DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
88 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
89 lchan->nr, lchan->use_count); \
90 } while(0);
91
Holger Freytherc6ea9db2008-12-30 19:18:21 +000092
Harald Welte52b1f982008-12-23 20:25:15 +000093/* communications link with a BTS */
94struct gsm_bts_link {
95 struct gsm_bts *bts;
96};
97
Harald Welte49f48b82009-02-17 15:29:33 +000098struct gsm_lchan;
99struct gsm_subscriber;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800100struct gsm_mncc;
Harald Welte49f48b82009-02-17 15:29:33 +0000101
Harald Weltebbcc7a52009-02-14 19:45:44 +0000102/* Network Management State */
103struct gsm_nm_state {
104 u_int8_t operational;
105 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000106 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000107};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000108
Holger Freyther73487a22008-12-31 18:53:57 +0000109/*
110 * LOCATION UPDATING REQUEST state
111 *
112 * Our current operation is:
113 * - Get imei/tmsi
114 * - Accept/Reject according to global policy
115 */
116struct gsm_loc_updating_operation {
117 struct timer_list updating_timer;
118 int waiting_for_imsi : 1;
119 int waiting_for_imei : 1;
120};
121
Harald Welte8470bf22008-12-25 23:28:35 +0000122struct gsm_lchan {
123 /* The TS that we're part of */
124 struct gsm_bts_trx_ts *ts;
125 /* The logical subslot number in the TS */
126 u_int8_t nr;
Harald Welte45b407a2009-05-23 15:51:12 +0000127 /* The logical channel type */
Harald Welte8470bf22008-12-25 23:28:35 +0000128 enum gsm_chan_t type;
Harald Welte45b407a2009-05-23 15:51:12 +0000129 /* If TCH, traffic channel mode */
130 enum gsm_chan_t tch_mode;
Harald Welted4c9bf32009-02-15 16:56:18 +0000131 /* Power levels for MS and BTS */
132 u_int8_t bs_power;
133 u_int8_t ms_power;
134
Harald Welte8470bf22008-12-25 23:28:35 +0000135 /* To whom we are allocated at the moment */
136 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000137
138 /* Timer started to release the channel */
139 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000140
Holger Freyther73487a22008-12-31 18:53:57 +0000141 /*
142 * Operations that have a state and might be pending
143 */
144 struct gsm_loc_updating_operation *loc_operation;
145
Holger Freytherb7193e42008-12-29 17:44:08 +0000146 /* use count. how many users use this channel */
147 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000148};
149
Harald Welte85770c72009-01-18 17:47:32 +0000150struct gsm_e1_subslot {
151 /* Number of E1 link */
152 u_int8_t e1_nr;
153 /* Number of E1 TS inside E1 link */
154 u_int8_t e1_ts;
155 /* Sub-slot within the E1 TS, 0xff if full TS */
156 u_int8_t e1_ts_ss;
157};
158
Harald Welte52b1f982008-12-23 20:25:15 +0000159#define BTS_TRX_F_ACTIVATED 0x0001
160/* One Timeslot in a TRX */
161struct gsm_bts_trx_ts {
162 struct gsm_bts_trx *trx;
163 /* number of this timeslot at the TRX */
164 u_int8_t nr;
165
Harald Welte8470bf22008-12-25 23:28:35 +0000166 enum gsm_phys_chan_config pchan;
167
Harald Welte52b1f982008-12-23 20:25:15 +0000168 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000169 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200170 struct tlv_parsed nm_attr;
Harald Welte8470bf22008-12-25 23:28:35 +0000171
Harald Welte85770c72009-01-18 17:47:32 +0000172 /* To which E1 subslot are we connected */
173 struct gsm_e1_subslot e1_link;
Harald Welte75099262009-02-16 21:12:08 +0000174 struct {
175 u_int32_t bound_ip;
176 u_int16_t bound_port;
Harald Welte20855542009-07-12 09:50:35 +0200177 u_int8_t rtp_payload2;
178 u_int16_t conn_id;
Harald Welte75099262009-02-16 21:12:08 +0000179 } abis_ip;
Harald Welte85770c72009-01-18 17:47:32 +0000180
Harald Welte8470bf22008-12-25 23:28:35 +0000181 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000182};
183
184/* One TRX in a BTS */
185struct gsm_bts_trx {
Harald Weltee441d9c2009-06-21 16:17:15 +0200186 /* list header in bts->trx_list */
187 struct llist_head list;
188
Harald Welte52b1f982008-12-23 20:25:15 +0000189 struct gsm_bts *bts;
190 /* number of this TRX in the BTS */
191 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000192 /* how do we talk RSL with this TRX? */
193 struct e1inp_sign_link *rsl_link;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000194 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200195 struct tlv_parsed nm_attr;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000196 struct {
197 struct gsm_nm_state nm_state;
198 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000199
200 u_int16_t arfcn;
Harald Weltefcd24452009-06-20 18:15:19 +0200201 int nominal_power; /* in dBm */
202 unsigned int max_power_red; /* in actual dB */
Harald Welte8b697c72009-06-05 19:18:45 +0000203
204 union {
205 struct {
206 struct {
207 struct gsm_nm_state nm_state;
208 } bbsig;
209 struct {
210 struct gsm_nm_state nm_state;
211 } pa;
212 } bs11;
213 };
Harald Welte85770c72009-01-18 17:47:32 +0000214 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000215};
216
Harald Welte978cb422009-01-18 17:57:27 +0000217enum gsm_bts_type {
218 GSM_BTS_TYPE_UNKNOWN,
219 GSM_BTS_TYPE_BS11,
Harald Weltebbcc7a52009-02-14 19:45:44 +0000220 GSM_BTS_TYPE_NANOBTS_900,
221 GSM_BTS_TYPE_NANOBTS_1800,
Harald Welte978cb422009-01-18 17:57:27 +0000222};
223
Holger Freytherceb59b72009-02-06 18:54:00 +0000224/**
225 * A pending paging request
226 */
227struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000228 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000229 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000230 /* the subscriber which we're paging. Later gsm_paging_request
231 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000232 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000233 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000234 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000235 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000236 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000237
238 /* Timer 3113: how long do we try to page? */
239 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000240
241 /* callback to be called in case paging completes */
242 gsm_cbfn *cbfn;
243 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000244};
Harald Weltecd06bfb2009-02-10 17:33:56 +0000245#define T3113_VALUE 60, 0
Holger Freytherceb59b72009-02-06 18:54:00 +0000246
247/*
248 * This keeps track of the paging status of one BTS. It
249 * includes a number of pending requests, a back pointer
250 * to the gsm_bts, a timer and some more state.
251 */
252struct gsm_bts_paging_state {
Holger Freytherceb59b72009-02-06 18:54:00 +0000253 /* pending requests */
254 struct llist_head pending_requests;
255 struct gsm_paging_request *last_request;
256 struct gsm_bts *bts;
257
Harald Welte75a1fa82009-02-17 01:39:41 +0000258 struct timer_list work_timer;
259
Holger Freyther392209c2009-02-10 00:06:19 +0000260 /* load */
261 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000262};
263
Harald Welte8b697c72009-06-05 19:18:45 +0000264struct gsm_envabtse {
265 struct gsm_nm_state nm_state;
266};
267
Harald Welte52b1f982008-12-23 20:25:15 +0000268/* One BTS */
269struct gsm_bts {
Harald Weltee441d9c2009-06-21 16:17:15 +0200270 /* list header in net->bts_list */
271 struct llist_head list;
272
Harald Welte52b1f982008-12-23 20:25:15 +0000273 struct gsm_network *network;
274 /* number of ths BTS in network */
275 u_int8_t nr;
276 /* location area code of this BTS */
277 u_int8_t location_area_code;
Harald Welte02b0e092009-02-28 13:11:07 +0000278 /* Training Sequence Code */
279 u_int8_t tsc;
Harald Welte78f2f502009-05-23 16:56:52 +0000280 /* Base Station Identification Code (BSIC) */
281 u_int8_t bsic;
Harald Welte978cb422009-01-18 17:57:27 +0000282 /* type of BTS */
283 enum gsm_bts_type type;
Harald Weltefcd24452009-06-20 18:15:19 +0200284 enum gsm_band band;
Harald Welte1fa60c82009-02-09 18:13:26 +0000285 /* how do we talk OML with this TRX? */
286 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000287
288 /* Abis network management O&M handle */
289 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000290 struct gsm_nm_state nm_state;
Harald Welte93e9d172009-06-20 19:04:31 +0200291 struct tlv_parsed nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000292
Harald Welte52b1f982008-12-23 20:25:15 +0000293 /* number of this BTS on given E1 link */
294 u_int8_t bts_nr;
295
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000296 struct gsm48_control_channel_descr chan_desc;
297
Holger Freytherceb59b72009-02-06 18:54:00 +0000298 /* paging state and control */
299 struct gsm_bts_paging_state paging;
300
Harald Welte52b1f982008-12-23 20:25:15 +0000301 /* CCCH is on C0 */
302 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000303
304 struct {
305 struct gsm_nm_state nm_state;
306 } site_mgr;
Harald Welteedb37782009-05-01 14:59:07 +0000307
308 /* ip.accesss Unit ID's have Site/BTS/TRX layout */
Harald Welte7b26bcb2009-05-28 11:39:21 +0000309 union {
310 struct {
311 u_int16_t site_id;
312 u_int16_t bts_id;
313 } ip_access;
314 struct {
315 struct {
316 struct gsm_nm_state nm_state;
317 } cclk;
318 struct {
319 struct gsm_nm_state nm_state;
320 } rack;
Harald Welte8b697c72009-06-05 19:18:45 +0000321 struct gsm_envabtse envabtse[4];
Harald Welte7b26bcb2009-05-28 11:39:21 +0000322 } bs11;
323 };
Harald Weltebbcc7a52009-02-14 19:45:44 +0000324
Harald Welte52b1f982008-12-23 20:25:15 +0000325 /* transceivers */
326 int num_trx;
Harald Weltee441d9c2009-06-21 16:17:15 +0200327 struct llist_head trx_list;
Harald Welte52b1f982008-12-23 20:25:15 +0000328};
329
Harald Welte52b1f982008-12-23 20:25:15 +0000330struct gsm_network {
331 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000332 u_int16_t country_code;
333 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000334 char *name_long;
335 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000336
Harald Welte4bfdfe72009-06-10 23:11:52 +0800337 /* layer 4 */
338 int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
339 struct llist_head upqueue;
340 struct llist_head trans_list;
341
Harald Welte52b1f982008-12-23 20:25:15 +0000342 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200343 struct llist_head bts_list;
Harald Welte52b1f982008-12-23 20:25:15 +0000344};
345
Harald Welte7e310b12009-03-30 20:56:32 +0000346#define SMS_HDR_SIZE 128
347#define SMS_TEXT_SIZE 256
348struct gsm_sms {
349 u_int64_t id;
350 struct gsm_subscriber *sender;
351 struct gsm_subscriber *receiver;
352
Harald Welteb9c758b2009-07-05 14:02:46 +0200353 unsigned long validity_minutes;
Harald Weltef3efc592009-07-27 20:11:35 +0200354 unsigned char reply_path_req;
355 unsigned char status_rep_req;
356 unsigned char protocol_id;
357 unsigned char data_coding_scheme;
358
Harald Welteb9c758b2009-07-05 14:02:46 +0200359 unsigned int header_len;
Harald Welte7e310b12009-03-30 20:56:32 +0000360 unsigned char header[SMS_HDR_SIZE];
361 char text[SMS_TEXT_SIZE];
362};
363
Harald Weltee441d9c2009-06-21 16:17:15 +0200364struct gsm_network *gsm_network_init(u_int16_t country_code, u_int16_t network_code,
Harald Welte4bfdfe72009-06-10 23:11:52 +0800365 int (*mncc_recv)(struct gsm_network *, int, void *));
Harald Weltee441d9c2009-06-21 16:17:15 +0200366struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type,
367 u_int8_t tsc, u_int8_t bsic);
368struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
369
370struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
371struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num);
Harald Welte8470bf22008-12-25 23:28:35 +0000372
Harald Weltea72c98e2009-01-04 16:10:38 +0000373const char *gsm_pchan_name(enum gsm_phys_chan_config c);
374const char *gsm_lchan_name(enum gsm_chan_t c);
375const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte23a68632009-02-19 17:06:42 +0000376char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Weltea72c98e2009-01-04 16:10:38 +0000377
Harald Weltead384642008-12-26 10:20:07 +0000378enum gsm_e1_event {
379 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000380 EVT_E1_TEI_UP,
381 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000382};
383
Harald Weltecd06bfb2009-02-10 17:33:56 +0000384void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
385 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte32201c12009-03-10 12:15:10 +0000386enum gsm_bts_type parse_btstype(char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200387const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000388struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
389 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000390
Harald Weltefcd24452009-06-20 18:15:19 +0200391char *gsm_band_name(enum gsm_band band);
392enum gsm_band gsm_band_parse(int mhz);
393
Andreas Eversberg8226fa72009-06-29 15:19:38 +0200394extern void *tall_bsc_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +0200395
Harald Welte32201c12009-03-10 12:15:10 +0000396static inline int is_ipaccess_bts(struct gsm_bts *bts)
397{
398 switch (bts->type) {
399 case GSM_BTS_TYPE_NANOBTS_900:
400 case GSM_BTS_TYPE_NANOBTS_1800:
401 return 1;
402 default:
403 break;
404 }
405 return 0;
406}
407
Harald Welte52b1f982008-12-23 20:25:15 +0000408#endif