Implemented IKEv1 attribute encoding in SA payload
[strongswan.git] / src / libcharon / encoding / payloads / transform_attribute.h
1 /*
2 * Copyright (C) 2005-2006 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 /**
18 * @defgroup transform_attribute transform_attribute
19 * @{ @ingroup payloads
20 */
21
22 #ifndef TRANSFORM_ATTRIBUTE_H_
23 #define TRANSFORM_ATTRIBUTE_H_
24
25 typedef enum transform_attribute_type_t transform_attribute_type_t;
26 typedef struct transform_attribute_t transform_attribute_t;
27
28 #include <library.h>
29 #include <encoding/payloads/payload.h>
30
31 /**
32 * Type of the attribute.
33 */
34 enum transform_attribute_type_t {
35 /** IKEv1 Phase 1 attributes */
36 TATTR_PH1_ENCRYPTION_ALGORITHM = 1,
37 TATTR_PH1_HASH_ALGORITHM = 2,
38 TATTR_PH1_AUTH_METHOD = 3,
39 TATTR_PH1_GROUP = 4,
40 TATTR_PH1_GROUP_TYPE = 5,
41 TATTR_PH1_GROUP_PRIME = 6,
42 TATTR_PH1_GROUP_GENONE = 7,
43 TATTR_PH1_GROUP_GENTWO = 8,
44 TATTR_PH1_GROUP_CURVE_A = 9,
45 TATTR_PH1_GROUP_CURVE_B = 10,
46 TATTR_PH1_LIFE_TYPE = 11,
47 TATTR_PH1_LIFE_DURATION = 12,
48 TATTR_PH1_PRF = 13,
49 TATTR_PH1_KEY_LENGTH = 14,
50 TATTR_PH1_FIELD_SIZE = 15,
51 TATTR_PH1_GROUP_ORDER = 16,
52 /** IKEv1 Phase 2 attributes */
53 TATTR_PH2_SA_LIFE_TYPE = 1,
54 TATTR_PH2_SA_LIFE_DURATION = 2,
55 TATTR_PH2_GROUP = 3,
56 TATTR_PH2_ENCAP_MODE = 4,
57 TATTR_PH2_AUTH_ALGORITHM = 5,
58 TATTR_PH2_KEY_LENGTH = 6,
59 TATTR_PH2_KEY_ROUNDS = 7,
60 TATTR_PH2_COMP_DICT_SIZE = 8,
61 TATTR_PH2_COMP_PRIV_ALGORITHM = 9,
62 TATTR_PH2_ECN_TUNNEL = 10,
63 TATTR_PH2_EXT_SEQ_NUMBER = 11,
64 /* IKEv2 key length attribute */
65 TATTR_IKEV2_KEY_LENGTH = 14,
66 /* undefined, private use attribute */
67 TATTR_UNDEFINED = 16384,
68 };
69
70 /**
71 * Enum names for IKEv1 Phase 1 transform_attribute_type_t.
72 */
73 extern enum_name_t *tattr_ph1_names;
74
75 /**
76 * Enum names for IKEv1 Phase 2 transform_attribute_type_t.
77 */
78 extern enum_name_t *tattr_ph2_names;
79
80 /**
81 * Enum names for IKEv2 transform_attribute_type_t.
82 */
83 extern enum_name_t *tattr_ikev2_names;
84
85
86 /**
87 * Class representing an IKEv1/IKEv2 TRANSFORM Attribute.
88 */
89 struct transform_attribute_t {
90
91 /**
92 * The payload_t interface.
93 */
94 payload_t payload_interface;
95
96 /**
97 * Returns the currently set value of the attribute.
98 *
99 * Returned data are not copied.
100 *
101 * @return chunk_t pointing to the value
102 */
103 chunk_t (*get_value_chunk) (transform_attribute_t *this);
104
105 /**
106 * Returns the currently set value of the attribute.
107 *
108 * Returned data are not copied.
109 *
110 * @return value
111 */
112 u_int64_t (*get_value) (transform_attribute_t *this);
113
114 /**
115 * Sets the value of the attribute.
116 *
117 * Value is getting copied.
118 *
119 * @param value chunk_t pointing to the value to set
120 */
121 void (*set_value_chunk) (transform_attribute_t *this, chunk_t value);
122
123 /**
124 * Sets the value of the attribute.
125 *
126 * @param value value to set
127 */
128 void (*set_value) (transform_attribute_t *this, u_int16_t value);
129
130 /**
131 * Sets the type of the attribute.
132 *
133 * @param type type to set (most significant bit is set to zero)
134 */
135 void (*set_attribute_type) (transform_attribute_t *this, u_int16_t type);
136
137 /**
138 * get the type of the attribute.
139 *
140 * @return type of the value
141 */
142 u_int16_t (*get_attribute_type) (transform_attribute_t *this);
143
144 /**
145 * Clones an transform_attribute_t object.
146 *
147 * @return cloned transform_attribute_t object
148 */
149 transform_attribute_t * (*clone) (transform_attribute_t *this);
150
151 /**
152 * Destroys an transform_attribute_t object.
153 */
154 void (*destroy) (transform_attribute_t *this);
155 };
156
157 /**
158 * Creates an empty transform_attribute_t object.
159 *
160 * @param type TRANSFORM_ATTRIBUTE or TRANSFORM_ATTRIBUTE_V1
161 * @return transform_attribute_t object
162 */
163 transform_attribute_t *transform_attribute_create(payload_type_t type);
164
165 /**
166 * Creates a two byte value or a larger attribute for a given attribute kind.
167 *
168 * @param type TRANSFORM_ATTRIBUTE or TRANSFORM_ATTRIBUTE_V1
169 * @param kind attribute kind
170 * @param value fixed two byte value
171 * @return transform_attribute_t object
172 */
173 transform_attribute_t *transform_attribute_create_value(payload_type_t type,
174 transform_attribute_type_t kind, u_int64_t value);
175
176 #endif /** TRANSFORM_ATTRIBUTE_H_ @}*/