blob: 986f331277f949892da54a8c5e3850705a073c47 [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
Harald Welte8470bf22008-12-25 23:28:35 +000085struct gsm_lchan {
86 /* The TS that we're part of */
87 struct gsm_bts_trx_ts *ts;
88 /* The logical subslot number in the TS */
89 u_int8_t nr;
90 /* The lotical channel type */
91 enum gsm_chan_t type;
92 /* To whom we are allocated at the moment */
93 struct gsm_subscriber *subscr;
Holger Freytherc6ea9db2008-12-30 19:18:21 +000094
95 /* Timer started to release the channel */
96 struct timer_list release_timer;
97 struct timer_list updating_timer;
Harald Weltea3d04382008-12-27 17:02:56 +000098
99 /* local end of a call, if any */
100 struct gsm_call call;
Holger Freyther3186bf22008-12-29 06:23:49 +0000101
102 /* temporary user data, to be removed... and merged into gsm_call */
103 void *user_data;
Holger Freytherb7193e42008-12-29 17:44:08 +0000104
105 /* use count. how many users use this channel */
106 unsigned int use_count;
107 unsigned int pending_update_request : 1;
Harald Welte8470bf22008-12-25 23:28:35 +0000108};
109
Harald Welte52b1f982008-12-23 20:25:15 +0000110#define BTS_TRX_F_ACTIVATED 0x0001
111/* One Timeslot in a TRX */
112struct gsm_bts_trx_ts {
113 struct gsm_bts_trx *trx;
114 /* number of this timeslot at the TRX */
115 u_int8_t nr;
116
Harald Welte8470bf22008-12-25 23:28:35 +0000117 enum gsm_phys_chan_config pchan;
118
Harald Welte52b1f982008-12-23 20:25:15 +0000119 unsigned int flags;
Harald Welte8470bf22008-12-25 23:28:35 +0000120
121 struct gsm_lchan lchan[TS_MAX_LCHAN];
Harald Welte52b1f982008-12-23 20:25:15 +0000122};
123
124/* One TRX in a BTS */
125struct gsm_bts_trx {
126 struct gsm_bts *bts;
127 /* number of this TRX in the BTS */
128 u_int8_t nr;
129
130 u_int16_t arfcn;
131 struct gsm_bts_trx_ts ts[8];
132};
133
134/* One BTS */
135struct gsm_bts {
136 struct gsm_network *network;
137 /* number of ths BTS in network */
138 u_int8_t nr;
139 /* location area code of this BTS */
140 u_int8_t location_area_code;
141
142 /* Abis network management O&M handle */
143 struct abis_nm_h *nmh;
144 /* number of this BTS on given E1 link */
145 u_int8_t bts_nr;
146
147 /* CCCH is on C0 */
148 struct gsm_bts_trx *c0;
149 /* transceivers */
150 int num_trx;
151 struct gsm_bts_trx trx[BTS_MAX_TRX+1];
152};
153
154struct gsm_ms {
155 unsigned long imei;
156};
157
158struct gsm_network {
159 /* global parameters */
Harald Welteb84e2f42008-12-28 23:42:04 +0000160 u_int16_t country_code;
161 u_int16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000162 char *name_long;
163 char *name_short;
Harald Welte52b1f982008-12-23 20:25:15 +0000164
165 unsigned int num_bts;
166 /* private lists */
167 struct gsm_bts bts[GSM_MAX_BTS+1];
168 struct gsm_ms *ms;
169 struct gsm_subscriber *subscriber;
Holger Freyther07cc8d82008-12-29 06:23:46 +0000170
Holger Freytherb7193e42008-12-29 17:44:08 +0000171 /* management of the lower layers to allow the bsc to hook into it */
172 void (*update_request)(struct gsm_bts *, u_int32_t tmsi, int accepted);
Holger Freyther3186bf22008-12-29 06:23:49 +0000173 void (*channel_allocated)(struct gsm_lchan *bts, enum gsm_chreq_reason_t);
Holger Freytherb7193e42008-12-29 17:44:08 +0000174 void (*channel_deallocated)(struct gsm_lchan *bts);
Holger Freyther88ea8322008-12-29 06:23:52 +0000175 void (*channel_response)(struct gsm_lchan *, int acked);
Holger Freytherb7193e42008-12-29 17:44:08 +0000176 void (*channel_subscriber_assigned)(struct gsm_lchan *);
177 void (*call_state_changed)(struct gsm_lchan *, enum gsm_call_state new_state);
Harald Welte52b1f982008-12-23 20:25:15 +0000178};
179
Harald Welteb84e2f42008-12-28 23:42:04 +0000180struct gsm_network *gsm_network_init(unsigned int num_bts, u_int16_t country_code,
181 u_int16_t network_code);
Harald Welte8470bf22008-12-25 23:28:35 +0000182
Harald Weltead384642008-12-26 10:20:07 +0000183enum gsm_e1_event {
184 EVT_E1_NONE,
185 EVT_E1_OML_UP,
186 EVT_E1_RSL_UP,
187 EVT_E1_OML_DN,
188 EVT_E1_RSL_DN,
189};
190
Harald Welte52b1f982008-12-23 20:25:15 +0000191#endif