Send EAP-Nak with supported types if requested type is unsupported
[strongswan.git] / src / libcharon / encoding / payloads / eap_payload.h
1 /*
2 * Copyright (C) 2012 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
18 /**
19 * @defgroup eap_payload eap_payload
20 * @{ @ingroup payloads
21 */
22
23 #ifndef EAP_PAYLOAD_H_
24 #define EAP_PAYLOAD_H_
25
26 typedef struct eap_payload_t eap_payload_t;
27
28 #include <library.h>
29 #include <eap/eap.h>
30 #include <encoding/payloads/payload.h>
31
32 /**
33 * Class representing an IKEv2 EAP payload.
34 *
35 * The EAP payload format is described in RFC section 3.16.
36 */
37 struct eap_payload_t {
38
39 /**
40 * The payload_t interface.
41 */
42 payload_t payload_interface;
43
44 /**
45 * Set the contained EAP data.
46 *
47 * This contains the FULL EAP message starting with "code".
48 * Chunk gets cloned.
49 *
50 * @param message EAP data
51 */
52 void (*set_data) (eap_payload_t *this, chunk_t data);
53
54 /**
55 * Get the contained EAP data.
56 *
57 * This contains the FULL EAP message starting with "code".
58 *
59 * @return EAP data (pointer to internal data)
60 */
61 chunk_t (*get_data) (eap_payload_t *this);
62
63 /**
64 * Get the EAP code.
65 *
66 * @return EAP message as chunk_t
67 */
68 eap_code_t (*get_code) (eap_payload_t *this);
69
70 /**
71 * Get the EAP identifier.
72 *
73 * @return unique identifier
74 */
75 u_int8_t (*get_identifier) (eap_payload_t *this);
76
77 /**
78 * Get the EAP method type.
79 *
80 * @param vendor pointer receiving vendor identifier
81 * @return EAP method type, vendor specific if vendor != 0
82 */
83 eap_type_t (*get_type) (eap_payload_t *this, u_int32_t *vendor);
84
85 /**
86 * Destroys an eap_payload_t object.
87 */
88 void (*destroy) (eap_payload_t *this);
89 };
90
91 /**
92 * Creates an empty eap_payload_t object.
93 *
94 * @return eap_payload_t object
95 */
96 eap_payload_t *eap_payload_create(void);
97
98 /**
99 * Creates an eap_payload_t object with data.
100 *
101 * @param data data, gets cloned
102 * @return eap_payload_t object
103 */
104 eap_payload_t *eap_payload_create_data(chunk_t data);
105
106 /**
107 * Creates an eap_payload_t object with data, owning the data.
108 *
109 * @param data data on heap, gets owned and freed
110 * @return eap_payload_t object
111 */
112 eap_payload_t *eap_payload_create_data_own(chunk_t data);
113
114 /**
115 * Creates an eap_payload_t object with a code.
116 *
117 * Could should be either EAP_SUCCESS/EAP_FAILURE, use
118 * constructor above otherwise.
119 *
120 * @param code EAP status code
121 * @param identifier EAP identifier to use in payload
122 * @return eap_payload_t object
123 */
124 eap_payload_t *eap_payload_create_code(eap_code_t code, u_int8_t identifier);
125
126 /**
127 * Creates an eap_payload_t EAP_RESPONSE containing an EAP_NAK.
128 *
129 * @param identifier EAP identifier to use in payload
130 * @param expanded TRUE to send an expanded Nak (as response to an expanded
131 * request, i.e. one with vendor specific type)
132 * @return eap_payload_t object
133 */
134 eap_payload_t *eap_payload_create_nak(u_int8_t identifier, bool expanded);
135
136 #endif /** EAP_PAYLOAD_H_ @}*/