d5cca3c850b50d07a179caad9a18d4a073e89fa7
[strongswan.git] / Source / charon / encodings / ike_header.c
1 /**
2 * @file ike_header.c
3 *
4 * @brief Definition of the encoding rules used when parsing or generating
5 * an IKEv2-Header
6 *
7 */
8
9 /*
10 * Copyright (C) 2005 Jan Hutter, Martin Willi
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24 /* offsetof macro */
25 #include <stddef.h>
26
27 #include "../encodings.h"
28 #include "ike_header.h"
29
30 /**
31 * Encoding rules to parse or generate a IKEv2-Header
32 *
33 * The defined offsets are the positions in a struct of type
34 * ike_header_t.
35 *
36 */
37 encoding_rule_t ike_header_encodings[] = {
38 /* 8 Byte SPI, stored in the field initiator_spi */
39 { U_INT_64, offsetof(ike_header_t, initiator_spi) },
40 /* 8 Byte SPI, stored in the field responder_spi */
41 { U_INT_64, offsetof(ike_header_t, responder_spi) },
42 /* 1 Byte next payload type, stored in the field next_payload */
43 { U_INT_8, offsetof(ike_header_t, next_payload) },
44 /* 4 Bit major version, stored in the field maj_version */
45 { U_INT_4, offsetof(ike_header_t, maj_version) },
46 /* 4 Bit minor version, stored in the field min_version */
47 { U_INT_4, offsetof(ike_header_t, min_version) },
48 /* 2 Bit reserved bits, nowhere stored */
49 { RESERVED_BIT, 0 },
50 { RESERVED_BIT, 0 },
51 /* 3 Bit flags, stored in the fields response, version and initiator */
52 { FLAG, offsetof(ike_header_t, flags.response) },
53 { FLAG, offsetof(ike_header_t, flags.version) },
54 { FLAG, offsetof(ike_header_t, flags.initiator) },
55 /* 3 Bit reserved bits, nowhere stored */
56 { RESERVED_BIT, 0 },
57 { RESERVED_BIT, 0 },
58 { RESERVED_BIT, 0 },
59 /* 4 Byte message id, stored in the field message_id */
60 { U_INT_32, offsetof(ike_header_t, message_id) },
61 /* 4 Byte length fied, stored in the field length */
62 { LENGTH, offsetof(ike_header_t, length) }
63 };
64
65 /**
66 * This informations are needed for autmatic parsing of header content
67 */
68 payload_info_t ike_header_info = {HEADER,
69 sizeof(ike_header_t),
70 ike_header_encodings,
71 (sizeof(ike_header_encodings)/sizeof(encoding_rule_t))};