4 * @brief Class message_t. Object of this type represents an IKEv2-Message.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
27 #include <ike_sa_id.h>
28 #include <network/packet.h>
29 #include <encoding/payloads/ike_header.h>
30 #include <utils/linked_list.h>
36 * @brief This class is used to represent an IKEv2-Message.
38 * An IKEv2-Message is either a request or response.
40 typedef struct message_s message_t
;
45 * @brief Sets the IKE major version of the message.
47 * @param this message_t object
48 * @param major_version major version to set
51 status_t (*set_major_version
) (message_t
*this,u_int8_t major_version
);
54 * @brief Gets the IKE major version of the message.
56 * @param this message_t object
57 * @return major version of the message
59 u_int8_t (*get_major_version
) (message_t
*this);
62 * @brief Sets the IKE minor version of the message.
64 * @param this message_t object
65 * @param minor_version minor version to set
68 status_t (*set_minor_version
) (message_t
*this,u_int8_t minor_version
);
71 * @brief Gets the IKE minor version of the message.
73 * @param this message_t object
74 * @return minor version of the message
76 u_int8_t (*get_minor_version
) (message_t
*this);
79 * @brief Sets the Message ID of the message.
81 * @param this message_t object
82 * @param message_id message_id to set
85 status_t (*set_message_id
) (message_t
*this,u_int32_t message_id
);
88 * @brief Gets the Message ID of the message.
90 * @param this message_t object
91 * @return message_id type of the message
93 u_int32_t (*get_message_id
) (message_t
*this);
96 * @brief Gets the responder SPI of the message.
98 * @param this message_t object
99 * @return responder spi of the message
101 u_int64_t (*get_responder_spi
) (message_t
*this);
104 * @brief Sets the IKE_SA ID of the message.
106 * @warning ike_sa_id gets cloned internaly and
107 * so can be destroyed afterwards.
109 * @param this message_t object
110 * @param ike_sa_id ike_sa_id to set
116 status_t (*set_ike_sa_id
) (message_t
*this,ike_sa_id_t
* ike_sa_id
);
119 * @brief Gets the IKE_SA ID of the message.
121 * @warning The returned ike_sa_id is a clone of the internal one.
122 * So it has to be destroyed by the caller.
124 * @param this message_t object
125 * @param ike_sa_id pointer to ike_sa_id pointer which will be set
129 * - FAILED if no ike_sa_id is set
131 status_t (*get_ike_sa_id
) (message_t
*this,ike_sa_id_t
**ike_sa_id
);
134 * @brief Sets the exchange type of the message.
136 * @param this message_t object
137 * @param exchange_type exchange_type to set
140 status_t (*set_exchange_type
) (message_t
*this,exchange_type_t exchange_type
);
143 * @brief Gets the exchange type of the message.
145 * @param this message_t object
146 * @return exchange type of the message
148 exchange_type_t (*get_exchange_type
) (message_t
*this);
151 * @brief Sets the original initiator flag.
153 * @param this message_t object
154 * @param original_initiator TRUE if message is from original initiator
157 status_t (*set_original_initiator
) (message_t
*this,bool original_initiator
);
160 * @brief Gets original initiator flag.
162 * @param this message_t object
163 * @return TRUE if message is from original initiator, FALSE otherwise
165 bool (*get_original_initiator
) (message_t
*this);
168 * @brief Sets the request flag.
170 * @param this message_t object
171 * @param original_initiator TRUE if message is a request, FALSE if it is a reply
174 status_t (*set_request
) (message_t
*this,bool request
);
177 * @brief Gets request flag.
179 * @param this message_t object
180 * @return TRUE if message is a request, FALSE if it is a reply
182 bool (*get_request
) (message_t
*this);
185 * @brief Append a payload to the message.
187 * @param this message_t object
188 * @param payload payload to append
193 status_t (*add_payload
) (message_t
*this, payload_t
*payload
);
196 * @brief Parses header of message
198 * @param this message_t object
200 * - SUCCESS if header could be parsed
201 * - OUT_OF_RES if out of ressources
202 * - PARSE_ERROR if corrupted/invalid data found
203 * - FAILED if consistence check of header failed
205 status_t (*parse_header
) (message_t
*this);
208 * @brief Parses body of message
210 * @param this message_t object
212 * - SUCCESS if header could be parsed
213 * - NOT_SUPPORTED if unsupported payload are contained in body
214 * - OUT_OF_RES if out of ressources
215 * - FAILED if message type is not suppported!
216 * - PARSE_ERROR if corrupted/invalid data found
217 * - VERIFY_ERROR if verification of some payload failed
219 status_t (*parse_body
) (message_t
*this);
222 * @brief Generates the UDP packet of specific message
224 * @param this message_t object
226 * - SUCCESS if packet could be generated
227 * - EXCHANGE_TYPE_NOT_SET if exchange type is currently not set
230 status_t (*generate
) (message_t
*this, packet_t
**packet
);
231 status_t (*get_source
) (message_t
*this, host_t
**host
);
232 status_t (*set_source
) (message_t
*this, host_t
*host
);
233 status_t (*get_destination
) (message_t
*this, host_t
**host
);
234 status_t (*set_destination
) (message_t
*this, host_t
*host
);
235 status_t (*get_payload_iterator
) (message_t
*this, linked_list_iterator_t
**iterator
);
238 * @brief Destroys a message and all including objects
240 * @param this message_t object
243 status_t (*destroy
) (message_t
*this);
247 * Creates an message_t object from a incoming UDP Packet.
249 * @warning the given packet_t object is not copied and gets
250 * destroyed in message_t's destroy call.
252 * @warning Packet is not parsed in here!
254 * - exchange_type is set to NOT_SET
255 * - original_initiator is set to TRUE
256 * - is_request is set to TRUE
258 * @param packet packet_t object which is assigned to message
261 * - created message_t object
262 * - NULL if out of ressources
264 message_t
* message_create_from_packet(packet_t
*packet
);
268 * Creates an empty message_t object.
270 * - exchange_type is set to NOT_SET
271 * - original_initiator is set to TRUE
272 * - is_request is set to TRUE
275 * - created message_t object
276 * - NULL if out of ressources
278 message_t
* message_create();
280 #endif /*MESSAGE_H_*/