bfb8df81e2996c8b777c6081178550aa748f02b9
[strongswan.git] / Source / charon / payloads / payload.h
1 /**
2 * @file payload.h
3 *
4 * @brief Generic payload interface
5 *
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 #ifndef PAYLOAD_H_
25 #define PAYLOAD_H_
26
27 #include "encodings.h"
28 #include "../types.h"
29 #include "../definitions.h"
30
31
32 /**
33 * Payload-Types of a IKEv2-Message
34 *
35 *
36 * Header and substructures are also defined as
37 * payload types with values from PRIVATE USE space.
38 */
39 typedef enum payload_type_e payload_type_t;
40
41 enum payload_type_e{
42
43 /**
44 * NO_PAYLOAD
45 */
46 NO_PAYLOAD = 0,
47
48 /**
49 * SA
50 */
51 SECURITY_ASSOCIATION = 33,
52 /**
53 * KE
54 */
55 KEY_EXCHANGE = 34,
56 /**
57 * IDi
58 */
59 ID_INITIATOR = 35,
60 /**
61 * IDr
62 */
63 ID_RESPONDER = 36,
64 /**
65 * CERT
66 */
67 CERTIFICATE = 37,
68 /**
69 * CERTREQ
70 */
71 CERTIFICATE_REQUEST = 38,
72 /**
73 * AUTH
74 */
75 AUTHENTICATION = 39,
76 /**
77 * Ni, Nr
78 */
79 NONCE = 40,
80 /**
81 * N
82 */
83 NOTIFY = 41,
84 /**
85 * D
86 */
87 DELETE = 42,
88 /**
89 * V
90 */
91 VENDOR_ID = 43,
92 /**
93 * TSi
94 */
95 TRAFFIC_SELECTOR_INITIATOR = 44,
96 /**
97 * TSr
98 */
99 TRAFFIC_SELECTOR_RESPONDER = 45,
100 /**
101 * E
102 */
103 ENCRYPTED = 46,
104 /**
105 * CP
106 */
107 CONFIGURATION = 47,
108 /**
109 * EAP
110 */
111 EXTENSIBLE_AUTHENTICATION = 48,
112
113 /**
114 * Header has value 140 of PRIVATE USE space
115 *
116 * This payload type is not send over wire and just
117 * used internally to handle IKEv2-Header like a payload.
118 */
119 HEADER = 140
120 };
121
122
123 /*
124 * build string mapping array for payload_type_t
125 */
126 extern mapping_t payload_type_t_mappings[];
127
128
129 /**
130 * @brief Generic interface for all payload types (inclusive
131 * header and substructures)
132 *
133 *
134 */
135 typedef struct payload_s payload_t;
136
137 struct payload_s {
138 /**
139 * @brief Destroys a payload and all included substructures.
140 *
141 * @param this payload to destroy
142 * @return
143 * SUCCESS in any case
144 */
145 status_t (*destroy) (payload_t *this);
146
147 /**
148 * @brief Get encoding rules for this payload
149 *
150 * @param this calling object
151 * @param[out] rules location to store pointer of first rule
152 * @param[out] rule_count location to store number of rules
153 * @return
154 * SUCCESS in any case
155 */
156 status_t (*get_encoding_rules) (payload_t *this, encoding_rule_t **rules, size_t *rule_count);
157
158 /**
159 * @brief get type of payload
160 *
161 * @param this calling object
162 * @return type of this payload
163 */
164 payload_type_t (*get_type) (payload_t *this);
165
166 /**
167 * @brief get type of next payload or zero if this is the last one
168 *
169 * @param this calling object
170 * @return type of next payload
171 */
172 payload_type_t (*get_next_type) (payload_t *this);
173
174 /**
175 * @brief get length of payload
176 *
177 * @param this calling object
178 * @return length of this payload
179 */
180 size_t (*get_length) (payload_t *this);
181 };
182
183 /**
184 * @brief Create an empty payload.
185 *
186 * Useful for the parser, who wants a generic constructor for all payloads.
187 * It supports all payload_t methods.
188 *
189 * @param type type of the payload to create
190 * @return
191 * - created payload, or
192 * - NULL if failed
193 */
194
195 payload_t *create_payload(payload_type_t type);
196
197 #endif /*PAYLOAD_H_*/