- added notify message handling to ike_sa_init_requested_t and
[strongswan.git] / Source / charon / encoding / payloads / proposal_substructure.h
1 /**
2 * @file proposal_substructure.h
3 *
4 * @brief Interface of proposal_substructure_t.
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 PROPOSAL_SUBSTRUCTURE_H_
24 #define PROPOSAL_SUBSTRUCTURE_H_
25
26 #include <types.h>
27 #include <encoding/payloads/payload.h>
28 #include <encoding/payloads/transform_substructure.h>
29 #include <utils/linked_list.h>
30
31 /**
32 * IKEv1 Value for a proposal payload.
33 *
34 * @ingroup payloads
35 */
36 #define PROPOSAL_TYPE_VALUE 2
37
38 /**
39 * Length of the proposal substructure header
40 * (without spi).
41 *
42 * @ingroup payloads
43 */
44 #define PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH 8
45
46
47 typedef enum protocol_id_t protocol_id_t;
48
49 /**
50 * Protocol ID of a proposal.
51 *
52 * @ingroup payloads
53 */
54 enum protocol_id_t {
55 UNDEFINED_PROTOCOL_ID = 201,
56 IKE = 1,
57 AH = 2,
58 ESP = 3,
59 };
60
61 /**
62 * String mappings for protocol_id_t.
63 */
64 extern mapping_t protocol_id_m[];
65
66 typedef struct proposal_substructure_t proposal_substructure_t;
67
68 /**
69 * Object representing an IKEv2-PROPOSAL SUBSTRUCTURE.
70 *
71 * The PROPOSAL SUBSTRUCTURE format is described in RFC section 3.3.1.
72 *
73 * @ingroup payloads
74 */
75 struct proposal_substructure_t {
76 /**
77 * The payload_t interface.
78 */
79 payload_t payload_interface;
80
81 /**
82 * @brief Creates an iterator of stored transform_substructure_t objects.
83 *
84 * @warning The created iterator has to get destroyed by the caller!
85 * When deleting any transform over this iterator, call
86 * get_size to make sure the length and number values are ok.
87 *
88 * @param this calling proposal_substructure_t object
89 * @param[in] forward iterator direction (TRUE: front to end)
90 * @return created iterator_t object
91 */
92 iterator_t * (*create_transform_substructure_iterator) (proposal_substructure_t *this, bool forward);
93
94 /**
95 * @brief Adds a transform_substructure_t object to this object.
96 *
97 * @warning The added transform_substructure_t object is
98 * getting destroyed in destroy function of proposal_substructure_t.
99 *
100 * @param this calling proposal_substructure_t object
101 * @param transform transform_substructure_t object to add
102 */
103 void (*add_transform_substructure) (proposal_substructure_t *this,transform_substructure_t *transform);
104
105 /**
106 * @brief Sets the proposal number of current proposal.
107 *
108 * @param this calling proposal_substructure_t object
109 * @param id proposal number to set
110 */
111 void (*set_proposal_number) (proposal_substructure_t *this,u_int8_t proposal_number);
112
113 /**
114 * @brief get proposal number of current proposal.
115 *
116 * @param this calling proposal_substructure_t object
117 * @return proposal number of current proposal substructure.
118 */
119 u_int8_t (*get_proposal_number) (proposal_substructure_t *this);
120
121 /**
122 * @brief get the number of transforms in current proposal.
123 *
124 * @param this calling proposal_substructure_t object
125 * @return transform count in current proposal
126 */
127 size_t (*get_transform_count) (proposal_substructure_t *this);
128
129 /**
130 * @brief get size of the set spi in bytes.
131 *
132 * @param this calling proposal_substructure_t object
133 * @return size of the spi in bytes
134 */
135 size_t (*get_spi_size) (proposal_substructure_t *this);
136
137 /**
138 * @brief Sets the protocol id of current proposal.
139 *
140 * @param this calling proposal_substructure_t object
141 * @param id protocol id to set
142 */
143 void (*set_protocol_id) (proposal_substructure_t *this,u_int8_t protocol_id);
144
145 /**
146 * @brief get protocol id of current proposal.
147 *
148 * @param this calling proposal_substructure_t object
149 * @return protocol id of current proposal substructure.
150 */
151 u_int8_t (*get_protocol_id) (proposal_substructure_t *this);
152
153 /**
154 * @brief Get informations for a specific transform type.
155 *
156 * @param this calling proposal_substructure_t object
157 * @param type type to get informations for
158 * @param transform_id transform id of the specific type
159 * @param key_length key length of the specific key length transform attribute
160 * @return
161 * - SUCCESS if transform type is part of this proposal and
162 * all data (incl. key length) could be fetched
163 * - NOT_FOUND if transform type is not part of this proposal
164 */
165 status_t (*get_info_for_transform_type) (proposal_substructure_t *this,transform_type_t type, u_int16_t *transform_id, u_int16_t *key_length);
166
167 /**
168 * @brief Sets the next_payload field of this substructure
169 *
170 * If this is the last proposal, next payload field is set to 0,
171 * otherwise to 2
172 *
173 * @param this calling proposal_substructure_t object
174 * @param is_last When TRUE, next payload field is set to 0, otherwise to 2
175 */
176 void (*set_is_last_proposal) (proposal_substructure_t *this, bool is_last);
177
178 /**
179 * @brief Returns the currently set SPI of this proposal.
180 *
181 * @warning Returned data are not copied
182 *
183 * @param this calling proposal_substructure_t object
184 * @return chunk_t pointing to the value
185 */
186 chunk_t (*get_spi) (proposal_substructure_t *this);
187
188 /**
189 * @brief Sets the SPI of the current proposal.
190 *
191 * @warning SPI is getting copied
192 *
193 * @param this calling proposal_substructure_t object
194 * @param spi chunk_t pointing to the value to set
195 */
196 void (*set_spi) (proposal_substructure_t *this, chunk_t spi);
197
198 /**
199 * @brief Clones an proposal_substructure_t object.
200 *
201 * @param this proposal_substructure_t object to clone
202 * @return cloned object
203 */
204 proposal_substructure_t* (*clone) (proposal_substructure_t *this);
205
206 /**
207 * @brief Destroys an proposal_substructure_t object.
208 *
209 * @param this proposal_substructure_t object to destroy
210 */
211 void (*destroy) (proposal_substructure_t *this);
212 };
213
214 /**
215 * @brief Creates an empty proposal_substructure_t object
216 *
217 * @return created proposal_substructure_t object
218 *
219 * @ingroup payloads
220 */
221 proposal_substructure_t *proposal_substructure_create();
222
223
224
225 #endif /*PROPOSAL_SUBSTRUCTURE_H_*/