blob: 2173c51c5cf503d535e2ad66796570d3bd387c01 [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>
7
Harald Welte8470bf22008-12-25 23:28:35 +00008#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
9
Harald Welte52b1f982008-12-23 20:25:15 +000010#define GSM_MAX_BTS 8
11#define BTS_MAX_TRX 8
Harald Welte85770c72009-01-18 17:47:32 +000012#define TRX_NR_TS 8
Harald Welte8470bf22008-12-25 23:28:35 +000013#define TS_MAX_LCHAN 8
Harald Welte52b1f982008-12-23 20:25:15 +000014
15#define HARDCODED_ARFCN 123
16
Harald Welte8e1e3ee2009-02-01 13:32:45 +000017enum gsm_hooks {
18 GSM_HOOK_NM_SWLOAD,
19};
20
21struct msgb;
22typedef int gsm_cbfn(unsigned int hooknum,
23 unsigned int event,
24 struct msgb *msg,
25 void *data, void *param);
26
Holger Freytherc6ea9db2008-12-30 19:18:21 +000027/*
28 * Use the channel. As side effect the lchannel recycle timer
29 * will be started.
30 */
31#define LCHAN_RELEASE_TIMEOUT 4, 0
32#define use_lchan(lchan) \
33 do { lchan->use_count++; \
34 schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
35
36#define put_lchan(lchan) \
37 do { lchan->use_count--; } while(0);
38
Harald Welte52b1f982008-12-23 20:25:15 +000039/* communications link with a BTS */
40struct gsm_bts_link {
41 struct gsm_bts *bts;
42};
43
Harald Weltea3d04382008-12-27 17:02:56 +000044enum gsm_call_type {
45 GSM_CT_NONE,
46 GSM_CT_MO,
47 GSM_CT_MT,
48};
49
50enum gsm_call_state {
51 GSM_CSTATE_NULL,
52 GSM_CSTATE_INITIATED,
53 GSM_CSTATE_ACTIVE,
54 GSM_CSTATE_RELEASE_REQ,
55};
56
57/* One end of a call */
58struct gsm_call {
59 enum gsm_call_type type;
60 enum gsm_call_state state;
61 u_int8_t transaction_id; /* 10.3.2 */
62
63 /* the 'local' subscriber */
64 struct gsm_subscriber *subscr;
65};
66
67
Harald Welte8470bf22008-12-25 23:28:35 +000068enum gsm_phys_chan_config {
69 GSM_PCHAN_NONE,
70 GSM_PCHAN_CCCH,
71 GSM_PCHAN_CCCH_SDCCH4,
72 GSM_PCHAN_TCH_F,
73 GSM_PCHAN_TCH_H,
74 GSM_PCHAN_SDCCH8_SACCH8C,
75 GSM_PCHAN_UNKNOWN,
76};
77
78enum gsm_chan_t {
79 GSM_LCHAN_NONE,
80 GSM_LCHAN_SDCCH,
81 GSM_LCHAN_TCH_F,
82 GSM_LCHAN_TCH_H,
83 GSM_LCHAN_UNKNOWN,
84};
85
Harald Weltee14a57c2008-12-29 04:08:28 +000086
87/* Channel Request reason */
88enum gsm_chreq_reason_t {
89 GSM_CHREQ_REASON_EMERG,
90 GSM_CHREQ_REASON_PAG,
91 GSM_CHREQ_REASON_CALL,
92 GSM_CHREQ_REASON_LOCATION_UPD,
93 GSM_CHREQ_REASON_OTHER,
94};
95
Holger Freyther73487a22008-12-31 18:53:57 +000096/*
97 * LOCATION UPDATING REQUEST state
98 *
99 * Our current operation is:
100 * - Get imei/tmsi
101 * - Accept/Reject according to global policy
102 */
103struct gsm_loc_updating_operation {
104 struct timer_list updating_timer;
105 int waiting_for_imsi : 1;
106 int waiting_for_imei : 1;
107};
108
Harald Welte8470bf22008-12-25 23:28:35 +0000109struct gsm_lchan {
110 /* The TS that we're part of */
111 struct gsm_bts_trx_ts *ts;
112 /* The logical subslot number in the TS */
113 u_int8_t nr;
114 /* The lotical channel type */
115 enum gsm_chan_t type;
116 /* To whom we are allocated at the moment */
117 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000118
119 /* Timer started to release the channel */
120 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000121
122 /* local end of a call, if any */
123 struct gsm_call call;
Holger Freyther3186bf22008-12-29 06:23:49 +0000124
125 /* temporary user data, to be removed... and merged into gsm_call */
126 void *user_data;
Holger Freytherb7193e42008-12-29 17:44:08 +0000127
Holger Freyther73487a22008-12-31 18:53:57 +0000128 /*
129 * Operations that have a state and might be pending
130 */
131 struct gsm_loc_updating_operation *loc_operation;
132
Holger Freytherb7193e42008-12-29 17:44:08 +0000133 /* use count. how many users use this channel */
134 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000135};
136
Harald Welte85770c72009-01-18 17:47:32 +0000137struct gsm_e1_subslot {
138 /* Number of E1 link */
139 u_int8_t e1_nr;
140 /* Number of E1 TS inside E1 link */
141 u_int8_t e1_ts;
142 /* Sub-slot within the E1 TS, 0xff if full TS */
143 u_int8_t e1_ts_ss;
144};
145
Harald Welte52b1f982008-12-23 20:25:15 +0000146#define BTS_TRX_F_ACTIVATED 0x0001
147/* One Timeslot in a TRX */
148struct gsm_bts_trx_ts {
149 struct gsm_bts_trx *trx;
150 /* number of this timeslot at the TRX */
151 u_int8_t nr;
152
Harald Welte8470bf22008-12-25 23:28:35 +0000153 enum gsm_phys_chan_config pchan;
154
Harald Welte52b1f982008-12-23 20:25:15 +0000155 unsigned int flags;
Harald Welte8470bf22008-12-25 23:28:35 +0000156
Harald Welte85770c72009-01-18 17:47:32 +0000157 /* To which E1 subslot are we connected */
158 struct gsm_e1_subslot e1_link;
159
Harald Welte8470bf22008-12-25 23:28:35 +0000160 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000161};
162
163/* One TRX in a BTS */
164struct gsm_bts_trx {
165 struct gsm_bts *bts;
166 /* number of this TRX in the BTS */
167 u_int8_t nr;
168
169 u_int16_t arfcn;
Harald Welte85770c72009-01-18 17:47:32 +0000170 struct gsm_bts_trx_ts ts[TRX_NR_TS];
Harald Welte52b1f982008-12-23 20:25:15 +0000171};
172
Harald Welte978cb422009-01-18 17:57:27 +0000173enum gsm_bts_type {
174 GSM_BTS_TYPE_UNKNOWN,
175 GSM_BTS_TYPE_BS11,
176};
177
Harald Welte52b1f982008-12-23 20:25:15 +0000178/* One BTS */
179struct gsm_bts {
180 struct gsm_network *network;
181 /* number of ths BTS in network */
182 u_int8_t nr;
183 /* location area code of this BTS */
184 u_int8_t location_area_code;
Harald Welte978cb422009-01-18 17:57:27 +0000185 /* type of BTS */
186 enum gsm_bts_type type;
Harald Welte52b1f982008-12-23 20:25:15 +0000187
188 /* Abis network management O&M handle */
189 struct abis_nm_h *nmh;
Harald Welte978cb422009-01-18 17:57:27 +0000190
Harald Welte52b1f982008-12-23 20:25:15 +0000191 /* number of this BTS on given E1 link */
192 u_int8_t bts_nr;
193
194 /* CCCH is on C0 */
195 struct gsm_bts_trx *c0;
196 /* transceivers */
197 int num_trx;
198 struct gsm_bts_trx trx[BTS_MAX_TRX+1];
199};
200
Harald Welte52b1f982008-12-23 20:25:15 +0000201struct gsm_network {
202 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000203 u_int16_t country_code;
204 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000205 char *name_long;
206 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000207
208 unsigned int num_bts;
209 /* private lists */
210 struct gsm_bts bts[GSM_MAX_BTS+1];
Harald Welte52b1f982008-12-23 20:25:15 +0000211};
212
Harald Welteb84e2f42008-12-28 23:42:04 +0000213struct gsm_network *gsm_network_init(unsigned int num_bts, u_int16_t country_code,
214 u_int16_t network_code);
Harald Welte8470bf22008-12-25 23:28:35 +0000215
Harald Weltea72c98e2009-01-04 16:10:38 +0000216const char *gsm_pchan_name(enum gsm_phys_chan_config c);
217const char *gsm_lchan_name(enum gsm_chan_t c);
218const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
219
Harald Weltead384642008-12-26 10:20:07 +0000220enum gsm_e1_event {
221 EVT_E1_NONE,
222 EVT_E1_OML_UP,
223 EVT_E1_RSL_UP,
224 EVT_E1_OML_DN,
225 EVT_E1_RSL_DN,
226};
227
Harald Welte52b1f982008-12-23 20:25:15 +0000228#endif