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