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