blob: 801284eba38f96c0219e3ac796102134220c27c6 [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,
20};
21
22struct msgb;
23typedef int gsm_cbfn(unsigned int hooknum,
24 unsigned int event,
25 struct msgb *msg,
26 void *data, void *param);
27
Holger Freytherc6ea9db2008-12-30 19:18:21 +000028/*
29 * Use the channel. As side effect the lchannel recycle timer
30 * will be started.
31 */
32#define LCHAN_RELEASE_TIMEOUT 4, 0
33#define use_lchan(lchan) \
34 do { lchan->use_count++; \
35 schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
36
37#define put_lchan(lchan) \
38 do { lchan->use_count--; } while(0);
39
Harald Welte52b1f982008-12-23 20:25:15 +000040/* communications link with a BTS */
41struct gsm_bts_link {
42 struct gsm_bts *bts;
43};
44
Harald Weltea3d04382008-12-27 17:02:56 +000045enum gsm_call_type {
46 GSM_CT_NONE,
47 GSM_CT_MO,
48 GSM_CT_MT,
49};
50
51enum gsm_call_state {
52 GSM_CSTATE_NULL,
53 GSM_CSTATE_INITIATED,
54 GSM_CSTATE_ACTIVE,
55 GSM_CSTATE_RELEASE_REQ,
56};
57
58/* One end of a call */
59struct gsm_call {
60 enum gsm_call_type type;
61 enum gsm_call_state state;
62 u_int8_t transaction_id; /* 10.3.2 */
63
64 /* the 'local' subscriber */
65 struct gsm_subscriber *subscr;
66};
67
68
Harald Welte8470bf22008-12-25 23:28:35 +000069enum gsm_phys_chan_config {
70 GSM_PCHAN_NONE,
71 GSM_PCHAN_CCCH,
72 GSM_PCHAN_CCCH_SDCCH4,
73 GSM_PCHAN_TCH_F,
74 GSM_PCHAN_TCH_H,
75 GSM_PCHAN_SDCCH8_SACCH8C,
76 GSM_PCHAN_UNKNOWN,
77};
78
79enum gsm_chan_t {
80 GSM_LCHAN_NONE,
81 GSM_LCHAN_SDCCH,
82 GSM_LCHAN_TCH_F,
83 GSM_LCHAN_TCH_H,
84 GSM_LCHAN_UNKNOWN,
85};
86
Harald Weltee14a57c2008-12-29 04:08:28 +000087
88/* Channel Request reason */
89enum gsm_chreq_reason_t {
90 GSM_CHREQ_REASON_EMERG,
91 GSM_CHREQ_REASON_PAG,
92 GSM_CHREQ_REASON_CALL,
93 GSM_CHREQ_REASON_LOCATION_UPD,
94 GSM_CHREQ_REASON_OTHER,
95};
96
Harald Weltebbcc7a52009-02-14 19:45:44 +000097/* Network Management State */
98struct gsm_nm_state {
99 u_int8_t operational;
100 u_int8_t administrative;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000101 u_int8_t availability;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000102};
Harald Welte8c1d0e42009-02-15 03:38:12 +0000103struct gsm_attr {
104 u_int8_t len;
105 u_int8_t data[0];
106};
Harald Weltebbcc7a52009-02-14 19:45:44 +0000107
Holger Freyther73487a22008-12-31 18:53:57 +0000108/*
109 * LOCATION UPDATING REQUEST state
110 *
111 * Our current operation is:
112 * - Get imei/tmsi
113 * - Accept/Reject according to global policy
114 */
115struct gsm_loc_updating_operation {
116 struct timer_list updating_timer;
117 int waiting_for_imsi : 1;
118 int waiting_for_imei : 1;
119};
120
Harald Welte8470bf22008-12-25 23:28:35 +0000121struct gsm_lchan {
122 /* The TS that we're part of */
123 struct gsm_bts_trx_ts *ts;
124 /* The logical subslot number in the TS */
125 u_int8_t nr;
126 /* The lotical channel type */
127 enum gsm_chan_t type;
128 /* To whom we are allocated at the moment */
129 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000130
131 /* Timer started to release the channel */
132 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000133
134 /* local end of a call, if any */
135 struct gsm_call call;
Holger Freyther3186bf22008-12-29 06:23:49 +0000136
137 /* temporary user data, to be removed... and merged into gsm_call */
138 void *user_data;
Holger Freytherb7193e42008-12-29 17:44:08 +0000139
Holger Freyther73487a22008-12-31 18:53:57 +0000140 /*
141 * Operations that have a state and might be pending
142 */
143 struct gsm_loc_updating_operation *loc_operation;
144
Holger Freytherb7193e42008-12-29 17:44:08 +0000145 /* use count. how many users use this channel */
146 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000147};
148
Harald Welte85770c72009-01-18 17:47:32 +0000149struct gsm_e1_subslot {
150 /* Number of E1 link */
151 u_int8_t e1_nr;
152 /* Number of E1 TS inside E1 link */
153 u_int8_t e1_ts;
154 /* Sub-slot within the E1 TS, 0xff if full TS */
155 u_int8_t e1_ts_ss;
156};
157
Harald Welte52b1f982008-12-23 20:25:15 +0000158#define BTS_TRX_F_ACTIVATED 0x0001
159/* One Timeslot in a TRX */
160struct gsm_bts_trx_ts {
161 struct gsm_bts_trx *trx;
162 /* number of this timeslot at the TRX */
163 u_int8_t nr;
164
Harald Welte8470bf22008-12-25 23:28:35 +0000165 enum gsm_phys_chan_config pchan;
166
Harald Welte52b1f982008-12-23 20:25:15 +0000167 unsigned int flags;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000168 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000169 struct gsm_attr *nm_attr;
Harald Welte8470bf22008-12-25 23:28:35 +0000170
Harald Welte85770c72009-01-18 17:47:32 +0000171 /* To which E1 subslot are we connected */
172 struct gsm_e1_subslot e1_link;
173
Harald Welte8470bf22008-12-25 23:28:35 +0000174 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000175};
176
177/* One TRX in a BTS */
178struct gsm_bts_trx {
179 struct gsm_bts *bts;
180 /* number of this TRX in the BTS */
181 u_int8_t nr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000182 /* how do we talk RSL with this TRX? */
183 struct e1inp_sign_link *rsl_link;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000184 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000185 struct gsm_attr *nm_attr;
186 struct {
187 struct gsm_nm_state nm_state;
188 } bb_transc;
Harald Welte52b1f982008-12-23 20:25:15 +0000189
190 u_int16_t arfcn;
Harald Welte85770c72009-01-18 17:47:32 +0000191 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000192};
193
Harald Welte978cb422009-01-18 17:57:27 +0000194enum gsm_bts_type {
195 GSM_BTS_TYPE_UNKNOWN,
196 GSM_BTS_TYPE_BS11,
Harald Weltebbcc7a52009-02-14 19:45:44 +0000197 GSM_BTS_TYPE_NANOBTS_900,
198 GSM_BTS_TYPE_NANOBTS_1800,
Harald Welte978cb422009-01-18 17:57:27 +0000199};
200
Holger Freytherceb59b72009-02-06 18:54:00 +0000201/**
202 * A pending paging request
203 */
204struct gsm_paging_request {
205 struct llist_head entry;
206 struct gsm_subscriber *subscr;
207 struct gsm_bts *bts;
Holger Freytherceb59b72009-02-06 18:54:00 +0000208 int chan_type;
Harald Weltecd06bfb2009-02-10 17:33:56 +0000209
210 /* Timer 3113: how long do we try to page? */
211 struct timer_list T3113;
Holger Freytherceb59b72009-02-06 18:54:00 +0000212};
Harald Weltecd06bfb2009-02-10 17:33:56 +0000213#define T3113_VALUE 60, 0
Holger Freytherceb59b72009-02-06 18:54:00 +0000214
215/*
216 * This keeps track of the paging status of one BTS. It
217 * includes a number of pending requests, a back pointer
218 * to the gsm_bts, a timer and some more state.
219 */
220struct gsm_bts_paging_state {
221 /* public callbacks */
222 void (*channel_allocated)(struct gsm_lchan *lchan);
223
224 /* pending requests */
225 struct llist_head pending_requests;
226 struct gsm_paging_request *last_request;
227 struct gsm_bts *bts;
228
Holger Freyther392209c2009-02-10 00:06:19 +0000229 /* load */
230 u_int16_t available_slots;
Holger Freytherceb59b72009-02-06 18:54:00 +0000231};
232
Harald Welte52b1f982008-12-23 20:25:15 +0000233/* One BTS */
234struct gsm_bts {
235 struct gsm_network *network;
236 /* number of ths BTS in network */
237 u_int8_t nr;
238 /* location area code of this BTS */
239 u_int8_t location_area_code;
Harald Welte978cb422009-01-18 17:57:27 +0000240 /* type of BTS */
241 enum gsm_bts_type type;
Harald Welte1fa60c82009-02-09 18:13:26 +0000242 /* how do we talk OML with this TRX? */
243 struct e1inp_sign_link *oml_link;
Harald Welte52b1f982008-12-23 20:25:15 +0000244
245 /* Abis network management O&M handle */
246 struct abis_nm_h *nmh;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000247 struct gsm_nm_state nm_state;
Harald Welte8c1d0e42009-02-15 03:38:12 +0000248 struct gsm_attr *nm_attr;
Harald Welte978cb422009-01-18 17:57:27 +0000249
Harald Welte52b1f982008-12-23 20:25:15 +0000250 /* number of this BTS on given E1 link */
251 u_int8_t bts_nr;
252
Holger Freyther1adb4ff2009-02-04 00:04:52 +0000253 struct gsm48_control_channel_descr chan_desc;
254
Holger Freytherceb59b72009-02-06 18:54:00 +0000255 /* paging state and control */
256 struct gsm_bts_paging_state paging;
257
Harald Welte52b1f982008-12-23 20:25:15 +0000258 /* CCCH is on C0 */
259 struct gsm_bts_trx *c0;
Harald Weltebbcc7a52009-02-14 19:45:44 +0000260
261 struct {
262 struct gsm_nm_state nm_state;
263 } site_mgr;
264
Harald Welte52b1f982008-12-23 20:25:15 +0000265 /* transceivers */
266 int num_trx;
267 struct gsm_bts_trx trx[BTS_MAX_TRX+1];
268};
269
Harald Welte52b1f982008-12-23 20:25:15 +0000270struct gsm_network {
271 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000272 u_int16_t country_code;
273 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000274 char *name_long;
275 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000276
277 unsigned int num_bts;
278 /* private lists */
279 struct gsm_bts bts[GSM_MAX_BTS+1];
Harald Welte52b1f982008-12-23 20:25:15 +0000280};
281
Harald Welte8c1d0e42009-02-15 03:38:12 +0000282struct gsm_network *gsm_network_init(unsigned int num_bts, enum gsm_bts_type bts_type,
283 u_int16_t country_code, u_int16_t network_code);
Harald Welte8470bf22008-12-25 23:28:35 +0000284
Harald Weltea72c98e2009-01-04 16:10:38 +0000285const char *gsm_pchan_name(enum gsm_phys_chan_config c);
286const char *gsm_lchan_name(enum gsm_chan_t c);
287const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
288
Harald Weltead384642008-12-26 10:20:07 +0000289enum gsm_e1_event {
290 EVT_E1_NONE,
Harald Welte1fa60c82009-02-09 18:13:26 +0000291 EVT_E1_TEI_UP,
292 EVT_E1_TEI_DN,
Harald Weltead384642008-12-26 10:20:07 +0000293};
294
Harald Weltecd06bfb2009-02-10 17:33:56 +0000295void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
296 u_int8_t e1_ts, u_int8_t e1_ts_ss);
Harald Welte52b1f982008-12-23 20:25:15 +0000297#endif