07762e1ad1f8e7309ad8c6b036b7e073dd59c27c
[strongswan.git] / Source / charon / encodings.h
1 /**
2 * @file encodings.h
3 *
4 * @brief Type definitions for parser and generator,
5 * also payload types are defined here.
6 *
7 * Header is parsed like a payload and gets its one payload_id
8 * from PRIVATE USE space. Also the substructures
9 * of specific payload types get their own payload_id
10 * from PRIVATE_USE space. See RFC for mor informations.
11 *
12 */
13
14 /*
15 * Copyright (C) 2005 Jan Hutter, Martin Willi
16 * Hochschule fuer Technik Rapperswil
17 *
18 * This program is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the
20 * Free Software Foundation; either version 2 of the License, or (at your
21 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
22 *
23 * This program is distributed in the hope that it will be useful, but
24 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 * for more details.
27 */
28
29 #ifndef ENCODINGS_H_
30 #define ENCODINGS_H_
31
32 #include "types.h"
33
34
35 /**
36 * @brief All different kinds of encoding types.
37 *
38 * Each field of an IKEv2-Message (in header or payload)
39 * which has to be parsed or generated differently has its own
40 * type defined here.
41 */
42 typedef enum encoding_type_e encoding_type_t;
43
44 enum encoding_type_e{
45 /**
46 * Representing a 4 Bit unsigned int value
47 *
48 *
49 * When generating it must be changed from host to network order.
50 * The value is read from the associated data struct.
51 * The current write position is moved 4 bit forward afterwards.
52 *
53 * When parsing it must be changed from network to host order.
54 * The value is written to the associated data struct.
55 * The current read pointer is moved 4 bit forward afterwards.
56 */
57 U_INT_4,
58 /**
59 * Representing a 8 Bit unsigned int value
60 *
61 *
62 * When generating it must be changed from host to network order.
63 * The value is read from the associated data struct.
64 * The current write position is moved 8 bit forward afterwards.
65 *
66 * When parsing it must be changed from network to host order.
67 * The value is written to the associated data struct.
68 * The current read pointer is moved 8 bit forward afterwards.
69 */
70 U_INT_8,
71 /**
72 * Representing a 16 Bit unsigned int value
73 *
74 *
75 * When generating it must be changed from host to network order.
76 * The value is read from the associated data struct.
77 * The current write position is moved 16 bit forward afterwards.
78 *
79 * When parsing it must be changed from network to host order.
80 * The value is written to the associated data struct.
81 * The current read pointer is moved 16 bit forward afterwards.
82 */
83 U_INT_16,
84 /**
85 * Representing a 32 Bit unsigned int value
86 *
87 * When generating it must be changed from host to network order.
88 * The value is read from the associated data struct.
89 * The current write position is moved 32 bit forward afterwards.
90 *
91 * When parsing it must be changed from network to host order.
92 * The value is written to the associated data struct.
93 * The current read pointer is moved 32 bit forward afterwards.
94 */
95
96 U_INT_32,
97 /**
98 * Representing a 64 Bit unsigned int value
99 *
100 * When generating it must be changed from host to network order.
101 * The value is read from the associated data struct.
102 * The current write position is moved 64 bit forward afterwards.
103 *
104 * When parsing it must be changed from network to host order.
105 * The value is written to the associated data struct.
106 * The current read pointer is moved 64 bit forward afterwards.
107 */
108 U_INT_64,
109 /**
110 * @brief represents a RESERVED_BIT used in FLAG-Bytes
111 *
112 * When generating, the next bit is set to zero and the current write
113 * position is moved one bit forward.
114 * No value is read from the associated data struct.
115 * The current write position is moved 1 bit forward afterwards.
116 *
117 * When parsing, the current read pointer is moved one bit forward.
118 * No value is written to the associated data struct.
119 * The current read pointer is moved 1 bit forward afterwards.
120 */
121 RESERVED_BIT,
122 /**
123 * @brief represents a RESERVED_BYTE
124 *
125 * When generating, the next byte is set to zero and the current write
126 * position is moved one byte forward.
127 * No value is read from the associated data struct.
128 * The current write position is moved 1 byte forward afterwards.
129 *
130 * When parsing, the current read pointer is moved one byte forward.
131 * No value is written to the associated data struct.
132 * The current read pointer is moved 1 byte forward afterwards.
133 */
134 RESERVED_BYTE,
135 /**
136 * Representing a 1 Bit flag.
137 *
138 * When generation, the next bit is set to 1 if the associated value
139 * in the data struct is TRUE, 0 otherwise. The current write position
140 * is moved 1 bit forward afterwards.
141 *
142 * When parsing, the next bit is read and stored in the associated data
143 * struct. 0 means FALSE, 1 means TRUE, The current read pointer
144 * is moved 1 bit forward afterwards
145 */
146 FLAG,
147 /**
148 * Representating a length field
149 *
150 * When generating it must be changed from host to network order.
151 * The value is read from the associated data struct.
152 * The current write position is moved 32 bit forward afterwards.
153 *
154 * When parsing it must be changed from network to host order.
155 * The value is written to the associated data struct.
156 * The current read pointer is moved 32 bit forward afterwards.
157 */
158 LENGTH,
159 /**
160 * Representating a spi size field
161 *
162 * When generating it must be changed from host to network order.
163 * The value is read from the associated data struct.
164 * The current write position is moved 32 bit forward afterwards.
165 *
166 * When parsing it must be changed from network to host order.
167 * The value is written to the associated data struct.
168 * The current read pointer is moved 32 bit forward afterwards.
169 */
170 SPI_SIZE
171 };
172
173 /**
174 * An encoding rule is a mapping of a specific encoding type to
175 * a location in the data struct where the current field is stored to
176 * or read from.
177 *
178 * For examples see directory encodings/.
179 *
180 * This rules are used by parser and generator.
181 */
182 typedef struct encoding_rule_s encoding_rule_t;
183
184 struct encoding_rule_s{
185 /**
186 * Encoding type
187 */
188 encoding_type_t type;
189 /**
190 * Offset in the data struct
191 *
192 * When parsing, data are written to this offset of the
193 * data struct.
194 *
195 * When generating, data are read from this offset in the
196 * data struct.
197 */
198 u_int32_t offset;
199 };
200
201
202 /**
203 * Payload-Types of a IKEv2-Message
204 *
205 *
206 * Header and substructures are also defined as
207 * payload types with values from PRIVATE USE space.
208 */
209 typedef enum payload_type_e payload_type_t;
210
211 enum payload_type_e{
212
213 /**
214 * NO_PAYLOAD
215 */
216 NO_PAYLOAD = 0,
217
218 /**
219 * SA
220 */
221 SECURITY_ASSOCIATION = 33,
222 /**
223 * KE
224 */
225 KEY_EXCHANGE = 34,
226 /**
227 * IDi
228 */
229 ID_INITIATOR = 35,
230 /**
231 * IDr
232 */
233 ID_RESPONDER = 36,
234 /**
235 * CERT
236 */
237 CERTIFICATE = 37,
238 /**
239 * CERTREQ
240 */
241 CERTIFICATE_REQUEST = 38,
242 /**
243 * AUTH
244 */
245 AUTHENTICATION = 39,
246 /**
247 * Ni, Nr
248 */
249 NONCE = 40,
250 /**
251 * N
252 */
253 NOTIFY = 41,
254 /**
255 * D
256 */
257 DELETE = 42,
258 /**
259 * V
260 */
261 VENDOR_ID = 43,
262 /**
263 * TSi
264 */
265 TRAFFIC_SELECTOR_INITIATOR = 44,
266 /**
267 * TSr
268 */
269 TRAFFIC_SELECTOR_RESPONDER = 45,
270 /**
271 * E
272 */
273 ENCRYPTED = 46,
274 /**
275 * CP
276 */
277 CONFIGURATION = 47,
278 /**
279 * EAP
280 */
281 EXTENSIBLE_AUTHENTICATION = 48,
282
283 /**
284 * Header has value 140 of PRIVATE USE space
285 *
286 * This payload type is not send over wire and just
287 * used internally to handle IKEv2-Header like a payload.
288 */
289 HEADER = 140
290 };
291
292 /**
293 * Information of a specific payload are stored in this struct
294 *
295 * The following informations are needed for each payload
296 * - payload type
297 * - length of its associated data struct in bytes
298 * - encoding rules array
299 * - encoding rules count
300 */
301 typedef struct payload_info_s payload_info_t;
302
303 struct payload_info_s{
304 /**
305 * Type of payload
306 */
307 payload_type_t payload_type;
308 /**
309 * Length of associated data struct in bytes
310 */
311 size_t data_struct_length;
312
313 /**
314 * Pointer to the encoding rules array
315 */
316 encoding_rule_t *ecoding_rules;
317
318 /**
319 * Number of encoding rules for the specific payload_type
320 */
321 size_t encoding_rules_count;
322 };
323
324 #endif /*ENCODINGS_H_*/