blob: 30e8b4617ba17f346f00941d8a7f29de5946996a [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 Welte8470bf22008-12-25 23:28:35 +000012#define TS_MAX_LCHAN 8
Harald Welte52b1f982008-12-23 20:25:15 +000013
14#define HARDCODED_ARFCN 123
15
Holger Freytherc6ea9db2008-12-30 19:18:21 +000016/*
17 * Use the channel. As side effect the lchannel recycle timer
18 * will be started.
19 */
20#define LCHAN_RELEASE_TIMEOUT 4, 0
21#define use_lchan(lchan) \
22 do { lchan->use_count++; \
23 schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
24
25#define put_lchan(lchan) \
26 do { lchan->use_count--; } while(0);
27
Harald Welte52b1f982008-12-23 20:25:15 +000028/* communications link with a BTS */
29struct gsm_bts_link {
30 struct gsm_bts *bts;
31};
32
Harald Weltea3d04382008-12-27 17:02:56 +000033enum gsm_call_type {
34 GSM_CT_NONE,
35 GSM_CT_MO,
36 GSM_CT_MT,
37};
38
39enum gsm_call_state {
40 GSM_CSTATE_NULL,
41 GSM_CSTATE_INITIATED,
42 GSM_CSTATE_ACTIVE,
43 GSM_CSTATE_RELEASE_REQ,
44};
45
46/* One end of a call */
47struct gsm_call {
48 enum gsm_call_type type;
49 enum gsm_call_state state;
50 u_int8_t transaction_id; /* 10.3.2 */
51
52 /* the 'local' subscriber */
53 struct gsm_subscriber *subscr;
54};
55
56
Harald Welte8470bf22008-12-25 23:28:35 +000057enum gsm_phys_chan_config {
58 GSM_PCHAN_NONE,
59 GSM_PCHAN_CCCH,
60 GSM_PCHAN_CCCH_SDCCH4,
61 GSM_PCHAN_TCH_F,
62 GSM_PCHAN_TCH_H,
63 GSM_PCHAN_SDCCH8_SACCH8C,
64 GSM_PCHAN_UNKNOWN,
65};
66
67enum gsm_chan_t {
68 GSM_LCHAN_NONE,
69 GSM_LCHAN_SDCCH,
70 GSM_LCHAN_TCH_F,
71 GSM_LCHAN_TCH_H,
72 GSM_LCHAN_UNKNOWN,
73};
74
Harald Weltee14a57c2008-12-29 04:08:28 +000075
76/* Channel Request reason */
77enum gsm_chreq_reason_t {
78 GSM_CHREQ_REASON_EMERG,
79 GSM_CHREQ_REASON_PAG,
80 GSM_CHREQ_REASON_CALL,
81 GSM_CHREQ_REASON_LOCATION_UPD,
82 GSM_CHREQ_REASON_OTHER,
83};
84
Holger Freyther73487a22008-12-31 18:53:57 +000085/*
86 * LOCATION UPDATING REQUEST state
87 *
88 * Our current operation is:
89 * - Get imei/tmsi
90 * - Accept/Reject according to global policy
91 */
92struct gsm_loc_updating_operation {
93 struct timer_list updating_timer;
94 int waiting_for_imsi : 1;
95 int waiting_for_imei : 1;
96};
97
Harald Welte8470bf22008-12-25 23:28:35 +000098struct gsm_lchan {
99 /* The TS that we're part of */
100 struct gsm_bts_trx_ts *ts;
101 /* The logical subslot number in the TS */
102 u_int8_t nr;
103 /* The lotical channel type */
104 enum gsm_chan_t type;
105 /* To whom we are allocated at the moment */
106 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000107
108 /* Timer started to release the channel */
109 struct timer_list release_timer;
Harald Weltea3d04382008-12-27 17:02:56 +0000110
111 /* local end of a call, if any */
112 struct gsm_call call;
Holger Freyther3186bf22008-12-29 06:23:49 +0000113
114 /* temporary user data, to be removed... and merged into gsm_call */
115 void *user_data;
Holger Freytherb7193e42008-12-29 17:44:08 +0000116
Holger Freyther73487a22008-12-31 18:53:57 +0000117 /*
118 * Operations that have a state and might be pending
119 */
120 struct gsm_loc_updating_operation *loc_operation;
121
Holger Freytherb7193e42008-12-29 17:44:08 +0000122 /* use count. how many users use this channel */
123 unsigned int use_count;
Harald Welte8470bf22008-12-25 23:28:35 +0000124};
125
Harald Welte52b1f982008-12-23 20:25:15 +0000126#define BTS_TRX_F_ACTIVATED 0x0001
127/* One Timeslot in a TRX */
128struct gsm_bts_trx_ts {
129 struct gsm_bts_trx *trx;
130 /* number of this timeslot at the TRX */
131 u_int8_t nr;
132
Harald Welte8470bf22008-12-25 23:28:35 +0000133 enum gsm_phys_chan_config pchan;
134
Harald Welte52b1f982008-12-23 20:25:15 +0000135 unsigned int flags;
Harald Welte8470bf22008-12-25 23:28:35 +0000136
137 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000138};
139
140/* One TRX in a BTS */
141struct gsm_bts_trx {
142 struct gsm_bts *bts;
143 /* number of this TRX in the BTS */
144 u_int8_t nr;
145
146 u_int16_t arfcn;
147 struct gsm_bts_trx_ts ts[8];
148};
149
150/* One BTS */
151struct gsm_bts {
152 struct gsm_network *network;
153 /* number of ths BTS in network */
154 u_int8_t nr;
155 /* location area code of this BTS */
156 u_int8_t location_area_code;
157
158 /* Abis network management O&M handle */
159 struct abis_nm_h *nmh;
160 /* number of this BTS on given E1 link */
161 u_int8_t bts_nr;
162
163 /* CCCH is on C0 */
164 struct gsm_bts_trx *c0;
165 /* transceivers */
166 int num_trx;
167 struct gsm_bts_trx trx[BTS_MAX_TRX+1];
168};
169
170struct gsm_ms {
171 unsigned long imei;
172};
173
174struct gsm_network {
175 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000176 u_int16_t country_code;
177 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000178 char *name_long;
179 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000180
181 unsigned int num_bts;
182 /* private lists */
183 struct gsm_bts bts[GSM_MAX_BTS+1];
184 struct gsm_ms *ms;
185 struct gsm_subscriber *subscriber;
Holger Freyther07cc8d82008-12-29 06:23:46 +0000186
Holger Freytherb7193e42008-12-29 17:44:08 +0000187 /* management of the lower layers to allow the bsc to hook into it */
188 void (*update_request)(struct gsm_bts *, u_int32_t tmsi, int accepted);
Holger Freyther3186bf22008-12-29 06:23:49 +0000189 void (*channel_allocated)(struct gsm_lchan *bts, enum gsm_chreq_reason_t);
Holger Freytherb7193e42008-12-29 17:44:08 +0000190 void (*channel_deallocated)(struct gsm_lchan *bts);
Holger Freyther88ea8322008-12-29 06:23:52 +0000191 void (*channel_response)(struct gsm_lchan *, int acked);
Holger Freytherb7193e42008-12-29 17:44:08 +0000192 void (*channel_subscriber_assigned)(struct gsm_lchan *);
193 void (*call_state_changed)(struct gsm_lchan *, enum gsm_call_state new_state);
Harald Welte52b1f982008-12-23 20:25:15 +0000194};
195
Harald Welteb84e2f42008-12-28 23:42:04 +0000196struct gsm_network *gsm_network_init(unsigned int num_bts, u_int16_t country_code,
197 u_int16_t network_code);
Harald Welte8470bf22008-12-25 23:28:35 +0000198
Harald Weltead384642008-12-26 10:20:07 +0000199enum gsm_e1_event {
200 EVT_E1_NONE,
201 EVT_E1_OML_UP,
202 EVT_E1_RSL_UP,
203 EVT_E1_OML_DN,
204 EVT_E1_RSL_DN,
205};
206
Harald Welte52b1f982008-12-23 20:25:15 +0000207#endif