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