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