06ee328a8180d5a592f4dde069451499e2395c64
[strongswan.git] / src / charon / encoding / payloads / ike_header.h
1 /*
2 * Copyright (C) 2007 Tobias Brunner
3 * Copyright (C) 2005-2006 Martin Willi
4 * Copyright (C) 2005 Jan Hutter
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * $Id$
18 */
19
20 /**
21 * @defgroup ike_header ike_header
22 * @{ @ingroup payloads
23 */
24
25 #ifndef IKE_HEADER_H_
26 #define IKE_HEADER_H_
27
28 typedef enum exchange_type_t exchange_type_t;
29 typedef struct ike_header_t ike_header_t;
30
31 #include <library.h>
32 #include <encoding/payloads/payload.h>
33
34 /**
35 * Major Version of IKEv2.
36 */
37 #define IKE_MAJOR_VERSION 2
38
39 /**
40 * Minor Version of IKEv2.
41 */
42 #define IKE_MINOR_VERSION 0
43
44 /**
45 * Flag in IKEv2-Header. Always 0.
46 */
47 #define HIGHER_VERSION_SUPPORTED_FLAG 0
48
49 /**
50 * Length of IKE Header in Bytes.
51 */
52 #define IKE_HEADER_LENGTH 28
53
54 /**
55 * Different types of IKE-Exchanges.
56 *
57 * See RFC for different types.
58 */
59 enum exchange_type_t{
60
61 /**
62 * EXCHANGE_TYPE_UNDEFINED. In private space, since not a official message type.
63 */
64 EXCHANGE_TYPE_UNDEFINED = 255,
65
66 /**
67 * IKE_SA_INIT.
68 */
69 IKE_SA_INIT = 34,
70
71 /**
72 * IKE_AUTH.
73 */
74 IKE_AUTH = 35,
75
76 /**
77 * CREATE_CHILD_SA.
78 */
79 CREATE_CHILD_SA = 36,
80
81 /**
82 * INFORMATIONAL.
83 */
84 INFORMATIONAL = 37,
85 #ifdef ME
86 /**
87 * ME_CONNECT
88 */
89 ME_CONNECT = 240
90 #endif /* ME */
91 };
92
93 /**
94 * enum name for exchange_type_t
95 */
96 extern enum_name_t *exchange_type_names;
97
98 /**
99 * An object of this type represents an IKEv2 header and is used to
100 * generate and parse IKEv2 headers.
101 *
102 * The header format of an IKEv2-Message is compatible to the
103 * ISAKMP-Header format to allow implementations supporting
104 * both versions of the IKE-protocol.
105 */
106 struct ike_header_t {
107 /**
108 * The payload_t interface.
109 */
110 payload_t payload_interface;
111
112 /**
113 * Get the initiator spi.
114 *
115 * @return initiator_spi
116 */
117 u_int64_t (*get_initiator_spi) (ike_header_t *this);
118
119 /**
120 * Set the initiator spi.
121 *
122 * @param initiator_spi initiator_spi
123 */
124 void (*set_initiator_spi) (ike_header_t *this, u_int64_t initiator_spi);
125
126 /**
127 * Get the responder spi.
128 *
129 * @return responder_spi
130 */
131 u_int64_t (*get_responder_spi) (ike_header_t *this);
132
133 /**
134 * Set the responder spi.
135 *
136 * @param responder_spi responder_spi
137 */
138 void (*set_responder_spi) (ike_header_t *this, u_int64_t responder_spi);
139
140 /**
141 * Get the major version.
142 *
143 * @return major version
144 */
145 u_int8_t (*get_maj_version) (ike_header_t *this);
146
147 /**
148 * Get the minor version.
149 *
150 * @return minor version
151 */
152 u_int8_t (*get_min_version) (ike_header_t *this);
153
154 /**
155 * Get the response flag.
156 *
157 * @return response flag
158 */
159 bool (*get_response_flag) (ike_header_t *this);
160
161 /**
162 * Set the response flag-
163 *
164 * @param response response flag
165 *
166 */
167 void (*set_response_flag) (ike_header_t *this, bool response);
168 /**
169 * Get "higher version supported"-flag.
170 *
171 * @return version flag
172 */
173 bool (*get_version_flag) (ike_header_t *this);
174
175 /**
176 * Get the initiator flag.
177 *
178 * @return initiator flag
179 */
180 bool (*get_initiator_flag) (ike_header_t *this);
181
182 /**
183 * Set the initiator flag.
184 *
185 * @param initiator initiator flag
186 */
187 void (*set_initiator_flag) (ike_header_t *this, bool initiator);
188
189 /**
190 * Get the exchange type.
191 *
192 * @return exchange type
193 */
194 u_int8_t (*get_exchange_type) (ike_header_t *this);
195
196 /**
197 * Set the exchange type.
198 *
199 * @param exchange_type exchange type
200 */
201 void (*set_exchange_type) (ike_header_t *this, u_int8_t exchange_type);
202
203 /**
204 * Get the message id.
205 *
206 * @return message id
207 */
208 u_int32_t (*get_message_id) (ike_header_t *this);
209
210 /**
211 * Set the message id.
212 *
213 * @param initiator_spi message id
214 */
215 void (*set_message_id) (ike_header_t *this, u_int32_t message_id);
216
217 /**
218 * Destroys a ike_header_t object.
219 */
220 void (*destroy) (ike_header_t *this);
221 };
222
223 /**
224 * Create an ike_header_t object
225 *
226 * @return ike_header_t object
227 */
228 ike_header_t *ike_header_create(void);
229
230 #endif /*IKE_HEADER_H_ @} */