gsm: Implement the size checking of the hello packet
[lcr.git] / mncc.h
1
2 #include <stdint.h>
3
4 #define MNCC_SETUP_REQ          0x0101
5 #define MNCC_SETUP_IND          0x0102
6 #define MNCC_SETUP_RSP          0x0103
7 #define MNCC_SETUP_CNF          0x0104
8 #define MNCC_SETUP_COMPL_REQ    0x0105
9 #define MNCC_SETUP_COMPL_IND    0x0106
10 /* MNCC_REJ_* is perfomed via MNCC_REL_* */
11 #define MNCC_CALL_CONF_IND      0x0107
12 #define MNCC_CALL_PROC_REQ      0x0108
13 #define MNCC_PROGRESS_REQ       0x0109
14 #define MNCC_ALERT_REQ          0x010a
15 #define MNCC_ALERT_IND          0x010b
16 #define MNCC_NOTIFY_REQ         0x010c
17 #define MNCC_NOTIFY_IND         0x010d
18 #define MNCC_DISC_REQ           0x010e
19 #define MNCC_DISC_IND           0x010f
20 #define MNCC_REL_REQ            0x0110
21 #define MNCC_REL_IND            0x0111
22 #define MNCC_REL_CNF            0x0112
23 #define MNCC_FACILITY_REQ       0x0113
24 #define MNCC_FACILITY_IND       0x0114
25 #define MNCC_START_DTMF_IND     0x0115
26 #define MNCC_START_DTMF_RSP     0x0116
27 #define MNCC_START_DTMF_REJ     0x0117
28 #define MNCC_STOP_DTMF_IND      0x0118
29 #define MNCC_STOP_DTMF_RSP      0x0119
30 #define MNCC_MODIFY_REQ         0x011a
31 #define MNCC_MODIFY_IND         0x011b
32 #define MNCC_MODIFY_RSP         0x011c
33 #define MNCC_MODIFY_CNF         0x011d
34 #define MNCC_MODIFY_REJ         0x011e
35 #define MNCC_HOLD_IND           0x011f
36 #define MNCC_HOLD_CNF           0x0120
37 #define MNCC_HOLD_REJ           0x0121
38 #define MNCC_RETRIEVE_IND       0x0122
39 #define MNCC_RETRIEVE_CNF       0x0123
40 #define MNCC_RETRIEVE_REJ       0x0124
41 #define MNCC_USERINFO_REQ       0x0125
42 #define MNCC_USERINFO_IND       0x0126
43 #define MNCC_REJ_REQ            0x0127
44 #define MNCC_REJ_IND            0x0128
45 #define MNCC_PROGRESS_IND       0x0129
46 #define MNCC_CALL_PROC_IND      0x012a
47 #define MNCC_CALL_CONF_REQ      0x012b
48 #define MNCC_START_DTMF_REQ     0x012c
49 #define MNCC_STOP_DTMF_REQ      0x012d
50 #define MNCC_HOLD_REQ           0x012e
51 #define MNCC_RETRIEVE_REQ       0x012f
52
53 #define MNCC_BRIDGE             0x0200
54 #define MNCC_FRAME_RECV         0x0201
55 #define MNCC_FRAME_DROP         0x0202
56 #define MNCC_LCHAN_MODIFY       0x0203
57 #define MNCC_RTP_CREATE         0x0204
58 #define MNCC_RTP_CONNECT        0x0205
59 #define MNCC_RTP_FREE           0x0206
60
61 #define GSM_TCHF_FRAME          0x0300
62 #define GSM_TCHF_FRAME_EFR      0x0301
63 #define GSM_TCHH_FRAME          0x0302
64 #define GSM_TCH_FRAME_AMR       0x0303
65 #define GSM_BAD_FRAME           0x03ff
66
67 #define MNCC_SOCKET_HELLO       0x0400
68
69 #define GSM_MAX_FACILITY        128
70 #define GSM_MAX_SSVERSION       128
71 #define GSM_MAX_USERUSER        128
72
73 #define MNCC_F_BEARER_CAP       0x0001
74 #define MNCC_F_CALLED           0x0002
75 #define MNCC_F_CALLING          0x0004
76 #define MNCC_F_REDIRECTING      0x0008
77 #define MNCC_F_CONNECTED        0x0010
78 #define MNCC_F_CAUSE            0x0020
79 #define MNCC_F_USERUSER         0x0040
80 #define MNCC_F_PROGRESS         0x0080
81 #define MNCC_F_EMERGENCY        0x0100
82 #define MNCC_F_FACILITY         0x0200
83 #define MNCC_F_SSVERSION        0x0400
84 #define MNCC_F_CCCAP            0x0800
85 #define MNCC_F_KEYPAD           0x1000
86 #define MNCC_F_SIGNAL           0x2000
87
88 #define GSM_MAX_FACILITY       128
89 #define GSM_MAX_SSVERSION      128
90 #define GSM_MAX_USERUSER       128
91
92 /* Expanded fields from GSM TS 04.08, Table 10.5.102 */
93 struct gsm_mncc_bearer_cap {
94         int             transfer;       /* Information Transfer Capability */
95         int             mode;           /* Transfer Mode */
96         int             coding;         /* Coding Standard */
97         int             radio;          /* Radio Channel Requirement */
98         int             speech_ctm;     /* CTM text telephony indication */
99         int             speech_ver[8];  /* Speech version indication */
100 };
101
102 struct gsm_mncc_number {
103         int             type;
104         int             plan;
105         int             present;
106         int             screen;
107         char            number[33];
108 };
109
110 struct gsm_mncc_cause {
111         int             location;
112         int             coding;
113         int             rec;
114         int             rec_val;
115         int             value;
116         int             diag_len;
117         char            diag[32];
118 };
119
120 struct gsm_mncc_useruser {
121         int             proto;
122         char            info[GSM_MAX_USERUSER + 1]; /* + termination char */
123 };
124
125 struct gsm_mncc_progress {
126         int             coding;
127         int             location;
128         int             descr;
129 };
130
131 struct gsm_mncc_facility {
132         int             len;
133         char            info[GSM_MAX_FACILITY];
134 };
135
136 struct gsm_mncc_ssversion {
137         int             len;
138         char            info[GSM_MAX_SSVERSION];
139 };
140
141 struct gsm_mncc_cccap {
142         int             dtmf;
143         int             pcp;
144 };
145
146 enum {
147         GSM_MNCC_BCAP_SPEECH    = 0,
148         GSM_MNCC_BCAP_UNR_DIG   = 1,
149         GSM_MNCC_BCAP_AUDIO     = 2,
150         GSM_MNCC_BCAP_FAX_G3    = 3,
151         GSM_MNCC_BCAP_OTHER_ITC = 5,
152         GSM_MNCC_BCAP_RESERVED  = 7,
153 };
154
155 struct gsm_mncc {
156         /* context based information */
157         uint32_t        msg_type;
158         uint32_t        callref;
159
160         /* which fields are present */
161         uint32_t        fields;
162
163         /* data derived informations (MNCC_F_ based) */
164         struct gsm_mncc_bearer_cap      bearer_cap;
165         struct gsm_mncc_number          called;
166         struct gsm_mncc_number          calling;
167         struct gsm_mncc_number          redirecting;
168         struct gsm_mncc_number          connected;
169         struct gsm_mncc_cause           cause;
170         struct gsm_mncc_progress        progress;
171         struct gsm_mncc_useruser        useruser;
172         struct gsm_mncc_facility        facility;
173         struct gsm_mncc_cccap           cccap;
174         struct gsm_mncc_ssversion       ssversion;
175         struct  {
176                 int             sup;
177                 int             inv;
178         } clir;
179         int             signal;
180
181         /* data derived information, not MNCC_F based */
182         int             keypad;
183         int             more;
184         int             notify; /* 0..127 */
185         int             emergency;
186         char            imsi[16];
187
188         unsigned char   lchan_type;
189         unsigned char   lchan_mode;
190 };
191
192 struct gsm_data_frame {
193         uint32_t        msg_type;
194         uint32_t        callref;
195         unsigned char   data[0];
196 };
197
198 struct gsm_mncc_rtp {
199         u_int32_t       msg_type;
200         u_int32_t       callref;
201         u_int32_t       ip;
202         u_int16_t       port;
203         u_int32_t       payload_type;
204         u_int32_t       payload_msg_type;
205 };
206
207
208 #define MNCC_SOCK_VERSION       2
209 struct gsm_mncc_hello {
210         uint32_t        msg_type;
211         uint32_t        version;
212
213         /* send the sizes of the structs */
214         uint32_t        mncc_size;
215         uint32_t        data_frame_size;
216
217         /* send some offsets */
218         uint32_t        called_offset;
219         uint32_t        signal_offset;
220         uint32_t        emergency_offset;
221         uint32_t        lchan_type_offset;
222 };