gsm: Verify the MNCC_VERSION of the BSC/MS and close the socket on mismatch
[lcr.git] / mncc.h
1
2 #define MNCC_SETUP_REQ          0x0101
3 #define MNCC_SETUP_IND          0x0102
4 #define MNCC_SETUP_RSP          0x0103
5 #define MNCC_SETUP_CNF          0x0104
6 #define MNCC_SETUP_COMPL_REQ    0x0105
7 #define MNCC_SETUP_COMPL_IND    0x0106
8 /* MNCC_REJ_* is perfomed via MNCC_REL_* */
9 #define MNCC_CALL_CONF_IND      0x0107
10 #define MNCC_CALL_PROC_REQ      0x0108
11 #define MNCC_PROGRESS_REQ       0x0109
12 #define MNCC_ALERT_REQ          0x010a
13 #define MNCC_ALERT_IND          0x010b
14 #define MNCC_NOTIFY_REQ         0x010c
15 #define MNCC_NOTIFY_IND         0x010d
16 #define MNCC_DISC_REQ           0x010e
17 #define MNCC_DISC_IND           0x010f
18 #define MNCC_REL_REQ            0x0110
19 #define MNCC_REL_IND            0x0111
20 #define MNCC_REL_CNF            0x0112
21 #define MNCC_FACILITY_REQ       0x0113
22 #define MNCC_FACILITY_IND       0x0114
23 #define MNCC_START_DTMF_IND     0x0115
24 #define MNCC_START_DTMF_RSP     0x0116
25 #define MNCC_START_DTMF_REJ     0x0117
26 #define MNCC_STOP_DTMF_IND      0x0118
27 #define MNCC_STOP_DTMF_RSP      0x0119
28 #define MNCC_MODIFY_REQ         0x011a
29 #define MNCC_MODIFY_IND         0x011b
30 #define MNCC_MODIFY_RSP         0x011c
31 #define MNCC_MODIFY_CNF         0x011d
32 #define MNCC_MODIFY_REJ         0x011e
33 #define MNCC_HOLD_IND           0x011f
34 #define MNCC_HOLD_CNF           0x0120
35 #define MNCC_HOLD_REJ           0x0121
36 #define MNCC_RETRIEVE_IND       0x0122
37 #define MNCC_RETRIEVE_CNF       0x0123
38 #define MNCC_RETRIEVE_REJ       0x0124
39 #define MNCC_USERINFO_REQ       0x0125
40 #define MNCC_USERINFO_IND       0x0126
41 #define MNCC_REJ_REQ            0x0127
42 #define MNCC_REJ_IND            0x0128
43 #define MNCC_PROGRESS_IND       0x0129
44 #define MNCC_CALL_PROC_IND      0x012a
45 #define MNCC_CALL_CONF_REQ      0x012b
46 #define MNCC_START_DTMF_REQ     0x012c
47 #define MNCC_STOP_DTMF_REQ      0x012d
48 #define MNCC_HOLD_REQ           0x012e
49 #define MNCC_RETRIEVE_REQ       0x012f
50
51 #define MNCC_BRIDGE             0x0200
52 #define MNCC_FRAME_RECV         0x0201
53 #define MNCC_FRAME_DROP         0x0202
54 #define MNCC_LCHAN_MODIFY       0x0203
55 #define MNCC_RTP_CREATE         0x0204
56 #define MNCC_RTP_CONNECT        0x0205
57 #define MNCC_RTP_FREE           0x0206
58
59 #define GSM_TCHF_FRAME          0x0300
60 #define GSM_TCHF_FRAME_EFR      0x0301
61 #define GSM_TCHH_FRAME          0x0302
62 #define GSM_TCH_FRAME_AMR       0x0303
63 #define GSM_BAD_FRAME           0x03ff
64
65 #define MNCC_SOCKET_HELLO       0x0400
66
67 #define GSM_MAX_FACILITY        128
68 #define GSM_MAX_SSVERSION       128
69 #define GSM_MAX_USERUSER        128
70
71 #define MNCC_F_BEARER_CAP       0x0001
72 #define MNCC_F_CALLED           0x0002
73 #define MNCC_F_CALLING          0x0004
74 #define MNCC_F_REDIRECTING      0x0008
75 #define MNCC_F_CONNECTED        0x0010
76 #define MNCC_F_CAUSE            0x0020
77 #define MNCC_F_USERUSER         0x0040
78 #define MNCC_F_PROGRESS         0x0080
79 #define MNCC_F_EMERGENCY        0x0100
80 #define MNCC_F_FACILITY         0x0200
81 #define MNCC_F_SSVERSION        0x0400
82 #define MNCC_F_CCCAP            0x0800
83 #define MNCC_F_KEYPAD           0x1000
84 #define MNCC_F_SIGNAL           0x2000
85
86 #define GSM_MAX_FACILITY       128
87 #define GSM_MAX_SSVERSION      128
88 #define GSM_MAX_USERUSER       128
89
90 /* GSM 04.08 Bearer Capability: Information Transfer Capability */
91 enum gsm48_bcap_itcap {
92         GSM48_BCAP_ITCAP_SPEECH         = 0,
93         GSM48_BCAP_ITCAP_UNR_DIG_INF    = 1,
94         GSM48_BCAP_ITCAP_3k1_AUDIO      = 2,
95         GSM48_BCAP_ITCAP_FAX_G3         = 3,
96         GSM48_BCAP_ITCAP_OTHER          = 5,
97         GSM48_BCAP_ITCAP_RESERVED       = 7,
98 };
99
100 /* GSM 04.08 Bearer Capability: Transfer Mode */
101 enum gsm48_bcap_tmod {
102         GSM48_BCAP_TMOD_CIRCUIT         = 0,
103         GSM48_BCAP_TMOD_PACKET          = 1,
104 };
105
106 /* GSM 04.08 Bearer Capability: Coding Standard */
107 enum gsm48_bcap_coding {
108         GSM48_BCAP_CODING_GSM_STD       = 0,
109 };
110
111 /* GSM 04.08 Bearer Capability: Radio Channel Requirements */
112 enum gsm48_bcap_rrq {
113         GSM48_BCAP_RRQ_FR_ONLY  = 1,
114         GSM48_BCAP_RRQ_DUAL_HR  = 2,
115         GSM48_BCAP_RRQ_DUAL_FR  = 3,
116 };
117
118 /* GSM 04.08 Bearer Capability: Rate Adaption */
119 enum gsm48_bcap_ra {
120         GSM48_BCAP_RA_NONE      = 0,
121         GSM48_BCAP_RA_V110_X30  = 1,
122         GSM48_BCAP_RA_X31       = 2,
123         GSM48_BCAP_RA_OTHER     = 3,
124 };
125
126 /* GSM 04.08 Bearer Capability: Signalling access protocol */
127 enum gsm48_bcap_sig_access {
128         GSM48_BCAP_SA_I440_I450 = 1,
129         GSM48_BCAP_SA_X21       = 2,
130         GSM48_BCAP_SA_X28_DP_IN = 3,
131         GSM48_BCAP_SA_X28_DP_UN = 4,
132         GSM48_BCAP_SA_X28_NDP   = 5,
133         GSM48_BCAP_SA_X32       = 6,
134 };
135
136 /* GSM 04.08 Bearer Capability: User Rate */
137 enum gsm48_bcap_user_rate {
138         GSM48_BCAP_UR_300       = 1,
139         GSM48_BCAP_UR_1200      = 2,
140         GSM48_BCAP_UR_2400      = 3,
141         GSM48_BCAP_UR_4800      = 4,
142         GSM48_BCAP_UR_9600      = 5,
143         GSM48_BCAP_UR_12000     = 6,
144         GSM48_BCAP_UR_1200_75   = 7,
145 };
146
147 /* GSM 04.08 Bearer Capability: Parity */
148 enum gsm48_bcap_parity {
149         GSM48_BCAP_PAR_ODD      = 0,
150         GSM48_BCAP_PAR_EVEN     = 2,
151         GSM48_BCAP_PAR_NONE     = 3,
152         GSM48_BCAP_PAR_ZERO     = 4,
153         GSM48_BCAP_PAR_ONE      = 5,
154 };
155
156 /* GSM 04.08 Bearer Capability: Intermediate Rate */
157 enum gsm48_bcap_interm_rate {
158         GSM48_BCAP_IR_8k        = 2,
159         GSM48_BCAP_IR_16k       = 3,
160 };
161
162 /* GSM 04.08 Bearer Capability: Transparency */
163 enum gsm48_bcap_transp {
164         GSM48_BCAP_TR_TRANSP    = 0,
165         GSM48_BCAP_TR_RLP       = 1,
166         GSM48_BCAP_TR_TR_PREF   = 2,
167         GSM48_BCAP_TR_RLP_PREF  = 3,
168 };
169
170 /* GSM 04.08 Bearer Capability: Modem Type */
171 enum gsm48_bcap_modem_type {
172         GSM48_BCAP_MT_NONE      = 0,
173         GSM48_BCAP_MT_V21       = 1,
174         GSM48_BCAP_MT_V22       = 2,
175         GSM48_BCAP_MT_V22bis    = 3,
176         GSM48_BCAP_MT_V23       = 4,
177         GSM48_BCAP_MT_V26ter    = 5,
178         GSM48_BCAP_MT_V32       = 6,
179         GSM48_BCAP_MT_UNDEF     = 7,
180         GSM48_BCAP_MT_AUTO_1    = 8,
181 };
182
183 /* GSM 04.08 Bearer Capability: Speech Version Indication */
184 enum gsm48_bcap_speech_ver {
185         GSM48_BCAP_SV_FR        = 0,
186         GSM48_BCAP_SV_HR        = 1,
187         GSM48_BCAP_SV_EFR       = 2,
188         GSM48_BCAP_SV_AMR_F     = 4,
189         GSM48_BCAP_SV_AMR_H     = 5,
190 };
191
192 /* Expanded fields from GSM TS 04.08, Table 10.5.102 */
193 struct gsm_mncc_bearer_cap {
194         int             transfer;       /* Information Transfer Capability */
195         int             mode;           /* Transfer Mode */
196         int             coding;         /* Coding Standard */
197         int             radio;          /* Radio Channel Requirement */
198         int             speech_ctm;     /* CTM text telephony indication */
199         int             speech_ver[8];  /* Speech version indication */
200         struct {
201                 enum gsm48_bcap_ra              rate_adaption;
202                 enum gsm48_bcap_sig_access      sig_access;
203                 int                             async;
204                 int                             nr_stop_bits;
205                 int                             nr_data_bits;
206                 enum gsm48_bcap_user_rate       user_rate;
207                 enum gsm48_bcap_parity          parity;
208                 enum gsm48_bcap_interm_rate     interm_rate;
209                 enum gsm48_bcap_transp          transp;
210                 enum gsm48_bcap_modem_type      modem_type;
211         } data;
212 };
213
214 struct gsm_mncc_number {
215         int             type;
216         int             plan;
217         int             present;
218         int             screen;
219         char            number[33];
220 };
221
222 struct gsm_mncc_cause {
223         int             location;
224         int             coding;
225         int             rec;
226         int             rec_val;
227         int             value;
228         int             diag_len;
229         char            diag[32];
230 };
231
232 struct gsm_mncc_useruser {
233         int             proto;
234         char            info[GSM_MAX_USERUSER + 1]; /* + termination char */
235 };
236
237 struct gsm_mncc_progress {
238         int             coding;
239         int             location;
240         int             descr;
241 };
242
243 struct gsm_mncc_facility {
244         int             len;
245         char            info[GSM_MAX_FACILITY];
246 };
247
248 struct gsm_mncc_ssversion {
249         int             len;
250         char            info[GSM_MAX_SSVERSION];
251 };
252
253 struct gsm_mncc_cccap {
254         int             dtmf;
255         int             pcp;
256 };
257
258 enum {
259         GSM_MNCC_BCAP_SPEECH    = 0,
260         GSM_MNCC_BCAP_UNR_DIG   = 1,
261         GSM_MNCC_BCAP_AUDIO     = 2,
262         GSM_MNCC_BCAP_FAX_G3    = 3,
263         GSM_MNCC_BCAP_OTHER_ITC = 5,
264         GSM_MNCC_BCAP_RESERVED  = 7,
265 };
266
267 enum {
268         GSM_LCHAN_NONE,
269         GSM_LCHAN_SDCCH,
270         GSM_LCHAN_TCH_F,
271         GSM_LCHAN_TCH_H,
272         GSM_LCHAN_UNKNOWN,
273         GSM_LCHAN_CCCH,
274         GSM_LCHAN_PDTCH,
275         _GSM_LCHAN_MAX
276 };
277
278 struct gsm_mncc {
279         /* context based information */
280         u_int32_t       msg_type;
281         u_int32_t       callref;
282
283         /* which fields are present */
284         u_int32_t       fields;
285
286         /* data derived informations (MNCC_F_ based) */
287         struct gsm_mncc_bearer_cap      bearer_cap;
288         struct gsm_mncc_number          called;
289         struct gsm_mncc_number          calling;
290         struct gsm_mncc_number          redirecting;
291         struct gsm_mncc_number          connected;
292         struct gsm_mncc_cause           cause;
293         struct gsm_mncc_progress        progress;
294         struct gsm_mncc_useruser        useruser;
295         struct gsm_mncc_facility        facility;
296         struct gsm_mncc_cccap           cccap;
297         struct gsm_mncc_ssversion       ssversion;
298         struct  {
299                 int             sup;
300                 int             inv;
301         } clir;
302         int             signal;
303
304         /* data derived information, not MNCC_F based */
305         int             keypad;
306         int             more;
307         int             notify; /* 0..127 */
308         int             emergency;
309         char            imsi[16];
310
311         unsigned char   lchan_type;
312         unsigned char   lchan_mode;
313 };
314
315 struct gsm_data_frame {
316         u_int32_t       msg_type;
317         u_int32_t       callref;
318         unsigned char   data[0];
319 };
320
321 struct gsm_mncc_rtp {
322         u_int32_t       msg_type;
323         u_int32_t       callref;
324         u_int32_t       ip;
325         u_int16_t       port;
326         u_int32_t       payload_type;
327         u_int32_t       payload_msg_type;
328 };
329
330
331 #define MNCC_SOCK_VERSION       1
332 struct gsm_mncc_hello {
333         u_int32_t       msg_type;
334         u_int32_t       version;
335 };