blob: 11791529a821370db76c55754c2d10df8803106a [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
17
Harald Welte8e1e3ee2009-02-01 13:32:45 +000018enum gsm_hooks {
19 GSM_HOOK_NM_SWLOAD,
Harald Welte0932d1e2009-02-16 22:53:52 +000020 GSM_HOOK_RR_PAGING,
21};
22
23enum gsm_paging_event {
24 GSM_PAGING_SUCCEEDED,
25 GSM_PAGING_EXPIRED,
Harald Welte8e1e3ee2009-02-01 13:32:45 +000026};
27
28struct msgb;
29typedef int gsm_cbfn(unsigned int hooknum,
30 unsigned int event,
31 struct msgb *msg,
32 void *data, void *param);
33
Holger Freytherc6ea9db2008-12-30 19:18:21 +000034/*
35 * Use the channel. As side effect the lchannel recycle timer
36 * will be started.
37 */
38#define LCHAN_RELEASE_TIMEOUT 4, 0
39#define use_lchan(lchan) \
40 do { lchan->use_count++; \
41 schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
42
43#define put_lchan(lchan) \
44 do { lchan->use_count--; } while(0);
45
Harald Welte52b1f982008-12-23 20:25:15 +000046/* communications link with a BTS */
47struct gsm_bts_link {
48 struct gsm_bts *bts;
49};
50
Harald Weltea3d04382008-12-27 17:02:56 +000051enum gsm_call_type {
52 GSM_CT_NONE,
53 GSM_CT_MO,
54 GSM_CT_MT,
55};
56
57enum gsm_call_state {
58 GSM_CSTATE_NULL,
59 GSM_CSTATE_INITIATED,
60 GSM_CSTATE_ACTIVE,
61 GSM_CSTATE_RELEASE_REQ,
62};
63
Harald Welte49f48b82009-02-17 15:29:33 +000064struct gsm_lchan;
65struct gsm_subscriber;
66
Harald Weltea3d04382008-12-27 17:02:56 +000067/* One end of a call */
68struct gsm_call {
69 enum gsm_call_type type;
70 enum gsm_call_state state;
71 u_int8_t transaction_id; /* 10.3.2 */
72
Harald Welte49f48b82009-02-17 15:29:33 +000073 /* the 'local' channel */
74 struct gsm_lchan *local_lchan;
75 /* the 'remote' channel */
76 struct gsm_lchan *remote_lchan;
77
Harald Welte0932d1e2009-02-16 22:53:52 +000078 /* the 'remote' subscriber */
79 struct gsm_subscriber *called_subscr;
Harald Weltea3d04382008-12-27 17:02:56 +000080};
81
82
Harald Welte8470bf22008-12-25 23:28:35 +000083enum gsm_phys_chan_config {
84 GSM_PCHAN_NONE,
85 GSM_PCHAN_CCCH,
86 GSM_PCHAN_CCCH_SDCCH4,
87 GSM_PCHAN_TCH_F,
88 GSM_PCHAN_TCH_H,
89 GSM_PCHAN_SDCCH8_SACCH8C,
90 GSM_PCHAN_UNKNOWN,
91};
92
93enum gsm_chan_t {
94 GSM_LCHAN_NONE,
95 GSM_LCHAN_SDCCH,
96 GSM_LCHAN_TCH_F,
97 GSM_LCHAN_TCH_H,
98 GSM_LCHAN_UNKNOWN,
99};
100
Harald Weltee14a57c2008-12-29 04:08:28 +0000101
102/* Channel Request reason */
103enum gsm_chreq_reason_t {
104 GSM_CHREQ_REASON_EMERG,
105 GSM_CHREQ_REASON_PAG,
106 GSM_CHREQ_REASON_CALL,
107 GSM_CHREQ_REASON_LOCATION_UPD,
108 GSM_CHREQ_REASON_OTHER,
109};
110
Harald Weltebbcc7a52009-02-14 19:45:44 +0000111/* Network Management State */
112struct gsm_nm_state {
113 u_int8_t operational;
114 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000115 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000116};
Harald Welte8c1d0e42009-02-15 03:38:12 +0000117struct gsm_attr {
118 u_int8_t len;
119 u_int8_t data[0];
120};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000121
Holger Freyther73487a22008-12-31 18:53:57 +0000122/*
123 * LOCATION UPDATING REQUEST state
124 *
125 * Our current operation is:
126 * - Get imei/tmsi
127 * - Accept/Reject according to global policy
128 */
129struct gsm_loc_updating_operation {
130 struct timer_list updating_timer;
131 int waiting_for_imsi : 1;
132 int waiting_for_imei : 1;
133};
134
Harald Welte8470bf22008-12-25 23:28:35 +0000135struct gsm_lchan {
136 /* The TS that we're part of */
137 struct gsm_bts_trx_ts *ts;
138 /* The logical subslot number in the TS */
139 u_int8_t nr;
140 /* The lotical channel type */
141 enum gsm_chan_t type;
Harald Welted4c9bf32009-02-15 16:56:18 +0000142 /* Power levels for MS and BTS */
143 u_int8_t bs_power;
144 u_int8_t ms_power;
145
Harald Welte8470bf22008-12-25 23:28:35 +0000146 /* To whom we are allocated at the moment */
147 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000148
149 /* Timer started to release the channel */
150 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000151
152 /* local end of a call, if any */
153 struct gsm_call call;
Holger Freyther3186bf22008-12-29 06:23:49 +0000154
155 /* temporary user data, to be removed... and merged into gsm_call */
156 void *user_data;
Holger Freytherb7193e42008-12-29 17:44:08 +0000157
Holger Freyther73487a22008-12-31 18:53:57 +0000158 /*
159 * Operations that have a state and might be pending
160 */
161 struct gsm_loc_updating_operation *loc_operation;
162
Holger Freytherb7193e42008-12-29 17:44:08 +0000163 /* use count. how many users use this channel */
164 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000165};
166
Harald Welte85770c72009-01-18 17:47:32 +0000167struct gsm_e1_subslot {
168 /* Number of E1 link */
169 u_int8_t e1_nr;
170 /* Number of E1 TS inside E1 link */
171 u_int8_t e1_ts;
172 /* Sub-slot within the E1 TS, 0xff if full TS */
173 u_int8_t e1_ts_ss;
174};
175
Harald Welte52b1f982008-12-23 20:25:15 +0000176#define BTS_TRX_F_ACTIVATED 0x0001
177/* One Timeslot in a TRX */
178struct gsm_bts_trx_ts {
179 struct gsm_bts_trx *trx;
180 /* number of this timeslot at the TRX */
181 u_int8_t nr;
182
Harald Welte8470bf22008-12-25 23:28:35 +0000183 enum gsm_phys_chan_config pchan;
184
Harald Welte52b1f982008-12-23 20:25:15 +0000185 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000186 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000187 struct gsm_attr *nm_attr;
Harald Welte8470bf22008-12-25 23:28:35 +0000188
Harald Welte85770c72009-01-18 17:47:32 +0000189 /* To which E1 subslot are we connected */
190 struct gsm_e1_subslot e1_link;
Harald Welte75099262009-02-16 21:12:08 +0000191 struct {
192 u_int32_t bound_ip;
193 u_int16_t bound_port;
194 u_int8_t attr_fc;
195 u_int16_t attr_f8;
196 } abis_ip;
Harald Welte85770c72009-01-18 17:47:32 +0000197
Harald Welte8470bf22008-12-25 23:28:35 +0000198 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000199};
200
201/* One TRX in a BTS */
202struct gsm_bts_trx {
203 struct gsm_bts *bts;
204 /* number of this TRX in the BTS */
205 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000206 /* how do we talk RSL with this TRX? */
207 struct e1inp_sign_link *rsl_link;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000208 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000209 struct gsm_attr *nm_attr;
210 struct {
211 struct gsm_nm_state nm_state;
212 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000213
214 u_int16_t arfcn;
Harald Welte85770c72009-01-18 17:47:32 +0000215 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000216};
217
Harald Welte978cb422009-01-18 17:57:27 +0000218enum gsm_bts_type {
219 GSM_BTS_TYPE_UNKNOWN,
220 GSM_BTS_TYPE_BS11,
Harald Weltebbcc7a52009-02-14 19:45:44 +0000221 GSM_BTS_TYPE_NANOBTS_900,
222 GSM_BTS_TYPE_NANOBTS_1800,
Harald Welte978cb422009-01-18 17:57:27 +0000223};
224
Holger Freytherceb59b72009-02-06 18:54:00 +0000225/**
226 * A pending paging request
227 */
228struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000229 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000230 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000231 /* the subscriber which we're paging. Later gsm_paging_request
232 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000233 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000234 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000235 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000236 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000237 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000238
239 /* Timer 3113: how long do we try to page? */
240 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000241
242 /* callback to be called in case paging completes */
243 gsm_cbfn *cbfn;
244 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000245};
Harald Weltecd06bfb2009-02-10 17:33:56 +0000246#define T3113_VALUE 60, 0
Holger Freytherceb59b72009-02-06 18:54:00 +0000247
248/*
249 * This keeps track of the paging status of one BTS. It
250 * includes a number of pending requests, a back pointer
251 * to the gsm_bts, a timer and some more state.
252 */
253struct gsm_bts_paging_state {
254 /* public callbacks */
255 void (*channel_allocated)(struct gsm_lchan *lchan);
256
257 /* 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 Welte978cb422009-01-18 17:57:27 +0000275 /* type of BTS */
276 enum gsm_bts_type type;
Harald Welte1fa60c82009-02-09 18:13:26 +0000277 /* how do we talk OML with this TRX? */
278 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000279
280 /* Abis network management O&M handle */
281 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000282 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000283 struct gsm_attr *nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000284
Harald Welte52b1f982008-12-23 20:25:15 +0000285 /* number of this BTS on given E1 link */
286 u_int8_t bts_nr;
287
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000288 struct gsm48_control_channel_descr chan_desc;
289
Holger Freytherceb59b72009-02-06 18:54:00 +0000290 /* paging state and control */
291 struct gsm_bts_paging_state paging;
292
Harald Welte52b1f982008-12-23 20:25:15 +0000293 /* CCCH is on C0 */
294 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000295
296 struct {
297 struct gsm_nm_state nm_state;
298 } site_mgr;
299
Harald Welte52b1f982008-12-23 20:25:15 +0000300 /* transceivers */
301 int num_trx;
302 struct gsm_bts_trx trx[BTS_MAX_TRX+1];
303};
304
Harald Welte52b1f982008-12-23 20:25:15 +0000305struct gsm_network {
306 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000307 u_int16_t country_code;
308 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000309 char *name_long;
310 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000311
312 unsigned int num_bts;
313 /* private lists */
314 struct gsm_bts bts[GSM_MAX_BTS+1];
Harald Welte52b1f982008-12-23 20:25:15 +0000315};
316
Harald Welte8c1d0e42009-02-15 03:38:12 +0000317struct gsm_network *gsm_network_init(unsigned int num_bts, enum gsm_bts_type bts_type,
318 u_int16_t country_code, u_int16_t network_code);
Harald Welte8470bf22008-12-25 23:28:35 +0000319
Harald Weltea72c98e2009-01-04 16:10:38 +0000320const char *gsm_pchan_name(enum gsm_phys_chan_config c);
321const char *gsm_lchan_name(enum gsm_chan_t c);
322const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
Harald Welte23a68632009-02-19 17:06:42 +0000323char *gsm_ts_name(struct gsm_bts_trx_ts *ts);
Harald Weltea72c98e2009-01-04 16:10:38 +0000324
Harald Weltead384642008-12-26 10:20:07 +0000325enum gsm_e1_event {
326 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000327 EVT_E1_TEI_UP,
328 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000329};
330
Harald Weltecd06bfb2009-02-10 17:33:56 +0000331void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
332 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte52b1f982008-12-23 20:25:15 +0000333#endif