updated Doxyfile
[strongswan.git] / src / charon / encoding / payloads / encodings.h
1 /*
2 * Copyright (C) 2005-2006 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * $Id$
17 */
18
19 /**
20 * @defgroup encodings encodings
21 * @{ @ingroup payloads
22 */
23
24 #ifndef ENCODINGS_H_
25 #define ENCODINGS_H_
26
27 typedef enum encoding_type_t encoding_type_t;
28 typedef struct encoding_rule_t encoding_rule_t;
29
30 #include <library.h>
31
32 /**
33 * All different kinds of encoding types.
34 *
35 * Each field of an IKEv2-Message (in header or payload)
36 * which has to be parsed or generated differently has its own
37 * type defined here.
38 *
39 * Header is parsed like a payload and gets its one payload_id
40 * from PRIVATE USE space. Also the substructures
41 * of specific payload types get their own payload_id
42 * from PRIVATE_USE space. See IKEv2-Draft for more informations.
43 */
44 enum encoding_type_t {
45
46 /**
47 * Representing a 4 Bit unsigned int value.
48 *
49 *
50 * When generating it must be changed from host to network order.
51 * The value is read from the associated data struct.
52 * The current write position is moved 4 bit forward afterwards.
53 *
54 * When parsing it must be changed from network to host order.
55 * The value is written to the associated data struct.
56 * The current read pointer is moved 4 bit forward afterwards.
57 */
58 U_INT_4,
59
60 /**
61 * Representing a 8 Bit unsigned int value.
62 *
63 *
64 * When generating it must be changed from host to network order.
65 * The value is read from the associated data struct.
66 * The current write position is moved 8 bit forward afterwards.
67 *
68 * When parsing it must be changed from network to host order.
69 * The value is written to the associated data struct.
70 * The current read pointer is moved 8 bit forward afterwards.
71 */
72 U_INT_8,
73
74 /**
75 * Representing a 16 Bit unsigned int value.
76 *
77 *
78 * When generating it must be changed from host to network order.
79 * The value is read from the associated data struct.
80 * The current write position is moved 16 bit forward afterwards.
81 *
82 * When parsing it must be changed from network to host order.
83 * The value is written to the associated data struct.
84 * The current read pointer is moved 16 bit forward afterwards.
85 */
86 U_INT_16,
87
88 /**
89 * Representing a 32 Bit unsigned int value.
90 *
91 * When generating it must be changed from host to network order.
92 * The value is read from the associated data struct.
93 * The current write position is moved 32 bit forward afterwards.
94 *
95 * When parsing it must be changed from network to host order.
96 * The value is written to the associated data struct.
97 * The current read pointer is moved 32 bit forward afterwards.
98 */
99 U_INT_32,
100
101 /**
102 * Representing a 64 Bit unsigned int value.
103 *
104 * When generating it must be changed from host to network order.
105 * The value is read from the associated data struct.
106 * The current write position is moved 64 bit forward afterwards.
107 *
108 * When parsing it must be changed from network to host order.
109 * The value is written to the associated data struct.
110 * The current read pointer is moved 64 bit forward afterwards.
111 */
112 U_INT_64,
113
114 /**
115 * represents a RESERVED_BIT used in FLAG-Bytes.
116 *
117 * When generating, the next bit is set to zero and the current write
118 * position is moved one bit forward.
119 * No value is read from the associated data struct.
120 * The current write position is moved 1 bit forward afterwards.
121 *
122 * When parsing, the current read pointer is moved one bit forward.
123 * No value is written to the associated data struct.
124 * The current read pointer is moved 1 bit forward afterwards.
125 */
126 RESERVED_BIT,
127
128 /**
129 * represents a RESERVED_BYTE.
130 *
131 * When generating, the next byte is set to zero and the current write
132 * position is moved one byte forward.
133 * No value is read from the associated data struct.
134 * The current write position is moved 1 byte forward afterwards.
135 *
136 * When parsing, the current read pointer is moved one byte forward.
137 * No value is written to the associated data struct.
138 * The current read pointer is moved 1 byte forward afterwards.
139 */
140 RESERVED_BYTE,
141
142 /**
143 * Representing a 1 Bit flag.
144 *
145 * When generation, the next bit is set to 1 if the associated value
146 * in the data struct is TRUE, 0 otherwise. The current write position
147 * is moved 1 bit forward afterwards.
148 *
149 * When parsing, the next bit is read and stored in the associated data
150 * struct. 0 means FALSE, 1 means TRUE, The current read pointer
151 * is moved 1 bit forward afterwards
152 */
153 FLAG,
154
155 /**
156 * Representating a length field of a payload.
157 *
158 * When generating it must be changed from host to network order.
159 * The value is read from the associated data struct.
160 * The current write position is moved 16 bit forward afterwards.
161 *
162 * When parsing it must be changed from network to host order.
163 * The value is written to the associated data struct.
164 * The current read pointer is moved 16 bit forward afterwards.
165 */
166 PAYLOAD_LENGTH,
167
168 /**
169 * Representating a length field of a header.
170 *
171 * When generating it must be changed from host to network order.
172 * The value is read from the associated data struct.
173 * The current write position is moved 32 bit forward afterwards.
174 *
175 * When parsing it must be changed from network to host order.
176 * The value is written to the associated data struct.
177 * The current read pointer is moved 32 bit forward afterwards.
178 */
179 HEADER_LENGTH,
180
181 /**
182 * Representating a spi size field.
183 *
184 * When generating it must be changed from host to network order.
185 * The value is read from the associated data struct.
186 * The current write position is moved 8 bit forward afterwards.
187 *
188 * When parsing it must be changed from network to host order.
189 * The value is written to the associated data struct.
190 * The current read pointer is moved 8 bit forward afterwards.
191 */
192 SPI_SIZE,
193
194 /**
195 * Representating a spi field.
196 *
197 * When generating the content of the chunkt pointing to
198 * is written.
199 *
200 * When parsing SPI_SIZE bytes are read and written into the chunk pointing to.
201 */
202 SPI,
203
204 /**
205 * Representating a Key Exchange Data field.
206 *
207 * When generating the content of the chunkt pointing to
208 * is written.
209 *
210 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
211 */
212 KEY_EXCHANGE_DATA,
213
214 /**
215 * Representating a Notification field.
216 *
217 * When generating the content of the chunkt pointing to
218 * is written.
219 *
220 * When parsing (Payload Length - spi size - 8) bytes are read and written into the chunk pointing to.
221 */
222 NOTIFICATION_DATA,
223
224 /**
225 * Representating one or more proposal substructures.
226 *
227 * The offset points to a linked_list_t pointer.
228 *
229 * When generating the proposal_substructure_t objects are stored
230 * in the pointed linked_list.
231 *
232 * When parsing the parsed proposal_substructure_t objects have
233 * to be stored in the pointed linked_list.
234 */
235 PROPOSALS,
236
237 /**
238 * Representating one or more transform substructures.
239 *
240 * The offset points to a linked_list_t pointer.
241 *
242 * When generating the transform_substructure_t objects are stored
243 * in the pointed linked_list.
244 *
245 * When parsing the parsed transform_substructure_t objects have
246 * to be stored in the pointed linked_list.
247 */
248 TRANSFORMS,
249
250 /**
251 * Representating one or more Attributes of a transform substructure.
252 *
253 * The offset points to a linked_list_t pointer.
254 *
255 * When generating the transform_attribute_t objects are stored
256 * in the pointed linked_list.
257 *
258 * When parsing the parsed transform_attribute_t objects have
259 * to be stored in the pointed linked_list.
260 */
261 TRANSFORM_ATTRIBUTES,
262
263 /**
264 * Representating one or more Attributes of a configuration payload.
265 *
266 * The offset points to a linked_list_t pointer.
267 *
268 * When generating the configuration_attribute_t objects are stored
269 * in the pointed linked_list.
270 *
271 * When parsing the parsed configuration_attribute_t objects have
272 * to be stored in the pointed linked_list.
273 */
274 CONFIGURATION_ATTRIBUTES,
275
276 /**
277 *
278 * When generating the content of the chunkt pointing to
279 * is written.
280 *
281 * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
282 */
283 CONFIGURATION_ATTRIBUTE_VALUE,
284
285 /**
286 * Representing a 1 Bit flag specifying the format of a transform attribute.
287 *
288 * When generation, the next bit is set to 1 if the associated value
289 * in the data struct is TRUE, 0 otherwise. The current write position
290 * is moved 1 bit forward afterwards.
291 *
292 * When parsing, the next bit is read and stored in the associated data
293 * struct. 0 means FALSE, 1 means TRUE, The current read pointer
294 * is moved 1 bit forward afterwards.
295 */
296 ATTRIBUTE_FORMAT,
297 /**
298 * Representing a 15 Bit unsigned int value used as attribute type
299 * in an attribute transform.
300 *
301 *
302 * When generating it must be changed from host to network order.
303 * The value is read from the associated data struct.
304 * The current write position is moved 15 bit forward afterwards.
305 *
306 * When parsing it must be changed from network to host order.
307 * The value is written to the associated data struct.
308 * The current read pointer is moved 15 bit forward afterwards.
309 */
310 ATTRIBUTE_TYPE,
311
312 /**
313 * Depending on the field of type ATTRIBUTE_FORMAT
314 * this field contains the length or the value of an transform attribute.
315 * Its stored in a 16 unsigned integer field.
316 *
317 * When generating it must be changed from host to network order.
318 * The value is read from the associated data struct.
319 * The current write position is moved 16 bit forward afterwards.
320 *
321 * When parsing it must be changed from network to host order.
322 * The value is written to the associated data struct.
323 * The current read pointer is moved 16 bit forward afterwards.
324 */
325 ATTRIBUTE_LENGTH_OR_VALUE,
326
327 /**
328 * This field contains the length or the value of an configuration attribute.
329 * Its stored in a 16 unsigned integer field.
330 *
331 * When generating it must be changed from host to network order.
332 * The value is read from the associated data struct.
333 * The current write position is moved 16 bit forward afterwards.
334 *
335 * When parsing it must be changed from network to host order.
336 * The value is written to the associated data struct.
337 * The current read pointer is moved 16 bit forward afterwards.
338 */
339 CONFIGURATION_ATTRIBUTE_LENGTH,
340
341 /**
342 * Depending on the field of type ATTRIBUTE_FORMAT
343 * this field is available or missing and so parsed/generated
344 * or not parsed/not generated.
345 *
346 * When generating the content of the chunkt pointing to
347 * is written.
348 *
349 * When parsing SPI_SIZE bytes are read and written into the chunk pointing to.
350 */
351 ATTRIBUTE_VALUE,
352
353 /**
354 * Representating one or more Traffic selectors of a TS payload.
355 *
356 * The offset points to a linked_list_t pointer.
357 *
358 * When generating the traffic_selector_substructure_t objects are stored
359 * in the pointed linked_list.
360 *
361 * When parsing the parsed traffic_selector_substructure_t objects have
362 * to be stored in the pointed linked_list.
363 */
364 TRAFFIC_SELECTORS,
365
366 /**
367 * Representating a Traffic selector type field.
368 *
369 * When generating it must be changed from host to network order.
370 * The value is read from the associated data struct.
371 * The current write position is moved 16 bit forward afterwards.
372 *
373 * When parsing it must be changed from network to host order.
374 * The value is written to the associated data struct.
375 * The current read pointer is moved 16 bit forward afterwards.
376 */
377 TS_TYPE,
378
379 /**
380 * Representating an address field in a traffic selector.
381 *
382 * Depending on the last field of type TS_TYPE
383 * this field is either 4 or 16 byte long.
384 *
385 * When generating the content of the chunkt pointing to
386 * is written.
387 *
388 * When parsing 4 or 16 bytes are read and written into the chunk pointing to.
389 */
390 ADDRESS,
391
392 /**
393 * Representating a Nonce Data field.
394 *
395 * When generating the content of the chunkt pointing to
396 * is written.
397 *
398 * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
399 */
400 NONCE_DATA,
401
402 /**
403 * Representating a ID Data field.
404 *
405 * When generating the content of the chunkt pointing to
406 * is written.
407 *
408 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
409 */
410 ID_DATA,
411
412 /**
413 * Representating a AUTH Data field.
414 *
415 * When generating the content of the chunkt pointing to
416 * is written.
417 *
418 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
419 */
420 AUTH_DATA,
421
422 /**
423 * Representating a CERT Data field.
424 *
425 * When generating the content of the chunkt pointing to
426 * is written.
427 *
428 * When parsing (Payload Length - 5) bytes are read and written into the chunk pointing to.
429 */
430 CERT_DATA,
431
432 /**
433 * Representating a CERTREQ Data field.
434 *
435 * When generating the content of the chunkt pointing to
436 * is written.
437 *
438 * When parsing (Payload Length - 5) bytes are read and written into the chunk pointing to.
439 */
440 CERTREQ_DATA,
441
442 /**
443 * Representating an EAP message field.
444 *
445 * When generating the content of the chunkt pointing to
446 * is written.
447 *
448 * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
449 */
450 EAP_DATA,
451
452 /**
453 * Representating the SPIS field in a DELETE payload.
454 *
455 * When generating the content of the chunkt pointing to
456 * is written.
457 *
458 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
459 */
460 SPIS,
461
462 /**
463 * Representating the VID DATA field in a VENDOR ID payload.
464 *
465 * When generating the content of the chunkt pointing to
466 * is written.
467 *
468 * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
469 */
470 VID_DATA,
471
472 /**
473 * Representating the DATA of an unknown payload.
474 *
475 * When generating the content of the chunkt pointing to
476 * is written.
477 *
478 * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
479 */
480 UNKNOWN_DATA,
481
482 /**
483 * Representating an IKE_SPI field in an IKEv2 Header.
484 *
485 * When generating the value of the u_int64_t pointing to
486 * is written (host and networ order is not changed).
487 *
488 * When parsing 8 bytes are read and written into the u_int64_t pointing to.
489 */
490 IKE_SPI,
491
492 /**
493 * Representing the encrypted data body of a encryption payload.
494 */
495 ENCRYPTED_DATA,
496 };
497
498 /**
499 * enum name for encoding_type_t
500 */
501 extern enum_name_t *encoding_type_names;
502
503 /**
504 * Rule how to en-/decode a payload field.
505 *
506 * An encoding rule is a mapping of a specific encoding type to
507 * a location in the data struct where the current field is stored to
508 * or read from.
509 * This rules are used by parser and generator.
510 */
511 struct encoding_rule_t {
512
513 /**
514 * Encoding type.
515 */
516 encoding_type_t type;
517
518 /**
519 * Offset in the data struct.
520 *
521 * When parsing, data are written to this offset of the
522 * data struct.
523 *
524 * When generating, data are read from this offset in the
525 * data struct.
526 */
527 u_int32_t offset;
528 };
529
530 #endif /** ENCODINGS_H_ @}*/