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