blob: 25da171128a23eaf02d57b7f168901da0e8af2e4 [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
64/* One end of a call */
65struct gsm_call {
66 enum gsm_call_type type;
67 enum gsm_call_state state;
68 u_int8_t transaction_id; /* 10.3.2 */
69
70 /* the 'local' subscriber */
71 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +000072 /* the 'remote' subscriber */
73 struct gsm_subscriber *called_subscr;
Harald Weltea3d04382008-12-27 17:02:56 +000074};
75
76
Harald Welte8470bf22008-12-25 23:28:35 +000077enum gsm_phys_chan_config {
78 GSM_PCHAN_NONE,
79 GSM_PCHAN_CCCH,
80 GSM_PCHAN_CCCH_SDCCH4,
81 GSM_PCHAN_TCH_F,
82 GSM_PCHAN_TCH_H,
83 GSM_PCHAN_SDCCH8_SACCH8C,
84 GSM_PCHAN_UNKNOWN,
85};
86
87enum gsm_chan_t {
88 GSM_LCHAN_NONE,
89 GSM_LCHAN_SDCCH,
90 GSM_LCHAN_TCH_F,
91 GSM_LCHAN_TCH_H,
92 GSM_LCHAN_UNKNOWN,
93};
94
Harald Weltee14a57c2008-12-29 04:08:28 +000095
96/* Channel Request reason */
97enum gsm_chreq_reason_t {
98 GSM_CHREQ_REASON_EMERG,
99 GSM_CHREQ_REASON_PAG,
100 GSM_CHREQ_REASON_CALL,
101 GSM_CHREQ_REASON_LOCATION_UPD,
102 GSM_CHREQ_REASON_OTHER,
103};
104
Harald Weltebbcc7a52009-02-14 19:45:44 +0000105/* Network Management State */
106struct gsm_nm_state {
107 u_int8_t operational;
108 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000109 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000110};
Harald Welte8c1d0e42009-02-15 03:38:12 +0000111struct gsm_attr {
112 u_int8_t len;
113 u_int8_t data[0];
114};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000115
Holger Freyther73487a22008-12-31 18:53:57 +0000116/*
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
Harald Welte8470bf22008-12-25 23:28:35 +0000129struct 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 lotical channel type */
135 enum gsm_chan_t type;
Harald Welted4c9bf32009-02-15 16:56:18 +0000136 /* Power levels for MS and BTS */
137 u_int8_t bs_power;
138 u_int8_t ms_power;
139
Harald Welte8470bf22008-12-25 23:28:35 +0000140 /* To whom we are allocated at the moment */
141 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000142
143 /* Timer started to release the channel */
144 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000145
146 /* local end of a call, if any */
147 struct gsm_call call;
Holger Freyther3186bf22008-12-29 06:23:49 +0000148
149 /* temporary user data, to be removed... and merged into gsm_call */
150 void *user_data;
Holger Freytherb7193e42008-12-29 17:44:08 +0000151
Holger Freyther73487a22008-12-31 18:53:57 +0000152 /*
153 * Operations that have a state and might be pending
154 */
155 struct gsm_loc_updating_operation *loc_operation;
156
Holger Freytherb7193e42008-12-29 17:44:08 +0000157 /* use count. how many users use this channel */
158 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000159};
160
Harald Welte85770c72009-01-18 17:47:32 +0000161struct gsm_e1_subslot {
162 /* Number of E1 link */
163 u_int8_t e1_nr;
164 /* Number of E1 TS inside E1 link */
165 u_int8_t e1_ts;
166 /* Sub-slot within the E1 TS, 0xff if full TS */
167 u_int8_t e1_ts_ss;
168};
169
Harald Welte52b1f982008-12-23 20:25:15 +0000170#define BTS_TRX_F_ACTIVATED 0x0001
171/* One Timeslot in a TRX */
172struct gsm_bts_trx_ts {
173 struct gsm_bts_trx *trx;
174 /* number of this timeslot at the TRX */
175 u_int8_t nr;
176
Harald Welte8470bf22008-12-25 23:28:35 +0000177 enum gsm_phys_chan_config pchan;
178
Harald Welte52b1f982008-12-23 20:25:15 +0000179 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000180 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000181 struct gsm_attr *nm_attr;
Harald Welte8470bf22008-12-25 23:28:35 +0000182
Harald Welte85770c72009-01-18 17:47:32 +0000183 /* To which E1 subslot are we connected */
184 struct gsm_e1_subslot e1_link;
Harald Welte75099262009-02-16 21:12:08 +0000185 struct {
186 u_int32_t bound_ip;
187 u_int16_t bound_port;
188 u_int8_t attr_fc;
189 u_int16_t attr_f8;
190 } abis_ip;
Harald Welte85770c72009-01-18 17:47:32 +0000191
Harald Welte8470bf22008-12-25 23:28:35 +0000192 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000193};
194
195/* One TRX in a BTS */
196struct gsm_bts_trx {
197 struct gsm_bts *bts;
198 /* number of this TRX in the BTS */
199 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000200 /* how do we talk RSL with this TRX? */
201 struct e1inp_sign_link *rsl_link;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000202 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000203 struct gsm_attr *nm_attr;
204 struct {
205 struct gsm_nm_state nm_state;
206 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000207
208 u_int16_t arfcn;
Harald Welte85770c72009-01-18 17:47:32 +0000209 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000210};
211
Harald Welte978cb422009-01-18 17:57:27 +0000212enum gsm_bts_type {
213 GSM_BTS_TYPE_UNKNOWN,
214 GSM_BTS_TYPE_BS11,
Harald Weltebbcc7a52009-02-14 19:45:44 +0000215 GSM_BTS_TYPE_NANOBTS_900,
216 GSM_BTS_TYPE_NANOBTS_1800,
Harald Welte978cb422009-01-18 17:57:27 +0000217};
218
Holger Freytherceb59b72009-02-06 18:54:00 +0000219/**
220 * A pending paging request
221 */
222struct gsm_paging_request {
Harald Welte0932d1e2009-02-16 22:53:52 +0000223 /* list_head for list of all paging requests */
Holger Freytherceb59b72009-02-06 18:54:00 +0000224 struct llist_head entry;
Harald Welte0932d1e2009-02-16 22:53:52 +0000225 /* the subscriber which we're paging. Later gsm_paging_request
226 * should probably become a part of the gsm_subscriber struct? */
Holger Freytherceb59b72009-02-06 18:54:00 +0000227 struct gsm_subscriber *subscr;
Harald Welte0932d1e2009-02-16 22:53:52 +0000228 /* back-pointer to the BTS on which we are paging */
Holger Freytherceb59b72009-02-06 18:54:00 +0000229 struct gsm_bts *bts;
Harald Welte0932d1e2009-02-16 22:53:52 +0000230 /* what kind of channel type do we ask the MS to establish */
Holger Freytherceb59b72009-02-06 18:54:00 +0000231 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000232
233 /* Timer 3113: how long do we try to page? */
234 struct timer_list T3113;
Harald Welte0932d1e2009-02-16 22:53:52 +0000235
236 /* callback to be called in case paging completes */
237 gsm_cbfn *cbfn;
238 void *cbfn_param;
Holger Freytherceb59b72009-02-06 18:54:00 +0000239};
Harald Weltecd06bfb2009-02-10 17:33:56 +0000240#define T3113_VALUE 60, 0
Holger Freytherceb59b72009-02-06 18:54:00 +0000241
242/*
243 * This keeps track of the paging status of one BTS. It
244 * includes a number of pending requests, a back pointer
245 * to the gsm_bts, a timer and some more state.
246 */
247struct gsm_bts_paging_state {
248 /* public callbacks */
249 void (*channel_allocated)(struct gsm_lchan *lchan);
250
251 /* pending requests */
252 struct llist_head pending_requests;
253 struct gsm_paging_request *last_request;
254 struct gsm_bts *bts;
255
Holger Freyther392209c2009-02-10 00:06:19 +0000256 /* load */
257 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000258};
259
Harald Welte52b1f982008-12-23 20:25:15 +0000260/* One BTS */
261struct gsm_bts {
262 struct gsm_network *network;
263 /* number of ths BTS in network */
264 u_int8_t nr;
265 /* location area code of this BTS */
266 u_int8_t location_area_code;
Harald Welte978cb422009-01-18 17:57:27 +0000267 /* type of BTS */
268 enum gsm_bts_type type;
Harald Welte1fa60c82009-02-09 18:13:26 +0000269 /* how do we talk OML with this TRX? */
270 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000271
272 /* Abis network management O&M handle */
273 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000274 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000275 struct gsm_attr *nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000276
Harald Welte52b1f982008-12-23 20:25:15 +0000277 /* number of this BTS on given E1 link */
278 u_int8_t bts_nr;
279
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000280 struct gsm48_control_channel_descr chan_desc;
281
Holger Freytherceb59b72009-02-06 18:54:00 +0000282 /* paging state and control */
283 struct gsm_bts_paging_state paging;
284
Harald Welte52b1f982008-12-23 20:25:15 +0000285 /* CCCH is on C0 */
286 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000287
288 struct {
289 struct gsm_nm_state nm_state;
290 } site_mgr;
291
Harald Welte52b1f982008-12-23 20:25:15 +0000292 /* transceivers */
293 int num_trx;
294 struct gsm_bts_trx trx[BTS_MAX_TRX+1];
295};
296
Harald Welte52b1f982008-12-23 20:25:15 +0000297struct gsm_network {
298 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000299 u_int16_t country_code;
300 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000301 char *name_long;
302 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000303
304 unsigned int num_bts;
305 /* private lists */
306 struct gsm_bts bts[GSM_MAX_BTS+1];
Harald Welte52b1f982008-12-23 20:25:15 +0000307};
308
Harald Welte8c1d0e42009-02-15 03:38:12 +0000309struct gsm_network *gsm_network_init(unsigned int num_bts, enum gsm_bts_type bts_type,
310 u_int16_t country_code, u_int16_t network_code);
Harald Welte8470bf22008-12-25 23:28:35 +0000311
Harald Weltea72c98e2009-01-04 16:10:38 +0000312const char *gsm_pchan_name(enum gsm_phys_chan_config c);
313const char *gsm_lchan_name(enum gsm_chan_t c);
314const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
315
Harald Weltead384642008-12-26 10:20:07 +0000316enum gsm_e1_event {
317 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000318 EVT_E1_TEI_UP,
319 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000320};
321
Harald Weltecd06bfb2009-02-10 17:33:56 +0000322void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
323 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte52b1f982008-12-23 20:25:15 +0000324#endif