blob: 1f0c06927ea389f0fa6dff779fb138a9a73cb44a [file] [log] [blame]
Brian Waters13d96012017-12-08 16:53:31 -06001/*****************************************************************************************************
2 * Software License Agreement (BSD License)
3 * Author : Souheil Ben Ayed <souheil@tera.ics.keio.ac.jp>
4 *
5 * Copyright (c) 2009-2010, Souheil Ben Ayed, Teraoka Laboratory of Keio University, and the WIDE Project
6 * All rights reserved.
7 *
8 * Redistribution and use of this software in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Souheil Ben Ayed <souheil@tera.ics.keio.ac.jp>.
21 *
22 * 4. Neither the name of Souheil Ben Ayed, Teraoka Laboratory of Keio University or the WIDE Project nor the
23 * names of its contributors may be used to endorse or promote products
24 * derived from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY
27 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
30 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *****************************************************************************************************/
37
38
39#ifndef DIAMEAP_EAPPACKET_H_
40#define DIAMEAP_EAPPACKET_H_
41
42#include "diameap_defs.h"
43
44/*EAP Packet definition : the Extensible Authentication Protocol (RFC3748) */
45
46/* Define Length/Size */
47#define EAP_HEADER 4 /* EAP Packet header size : 4 Bytes */
48#define EAP_TYPE 1 /* EAP Type field size : 1 Byte */
49#define MAX_EAP_PACKET (u16)0xffff /* Maximum value allowed for an EAP Packet */
50
51/*EAP Packet Codes Type*/
52typedef enum
53{
54 ERROR = 0, /* EAP Packet Code should not be set to ERROR. Indicates a wrong Code value received. */
55 EAP_REQUEST = 1, /* EAP Request (value=1). */
56 EAP_RESPONSE = 2, /* EAP Response (value=2). */
57 EAP_SUCCESS = 3, /* EAP Success (value=3). */
58 EAP_FAILURE = 4 /* EAP Failure (value=4). */
59} eap_code;
60
61/* EAP Packet */
62struct eap_packet
63{
64 u16 length; /* Length of data (equivalent to the length field). */
65 u16 ulength; /* Length of received or inserted bytes in the data pointer. */
66 u8 *data; /* Data buffer (including Code, Identifier, Length, (also Type and Data fields if exists)). */
67};
68
69/* EAP Methods Types */
70typedef enum
71{
72 TYPE_NONE = 0, /* Indicate no method specified */
73 TYPE_IDENTITY = 1, /* EAP Identity (RFC3748) */
74 TYPE_NOTIFICATION = 2, /* EAP Notification (RFC3748) */
75 TYPE_NAK = 3, /* EAP NAK (RFC3748) */
76 TYPE_EAP_MD5 = 4, /* EAP MD5 (RFC3748) */
77 TYPE_OTP = 5, /* EAP OTP (RFC3748) */
78 TYPE_GTC = 6, /* EAP GTC (RFC3748) */
79 TYPE_EAP_TLS = 13, /* EAP TLS (RFC5216) */
80 TYPE_EXPANDED_TYPES = 254, /* EAP Expanded NAK (RFC3748) */
81 TYPE_EXPERIMENTAL_USE = 255 /* for Experimental use (RFC3748) */
82} eap_type;
83
84
85/* Function : diameap_eap_get_code
86 *
87 * Parameters:
88 * eapPacket : an EAP Packet
89 * eapcode : On successful return, the EAP Code is stored here.
90 *
91 * Description:
92 * Get the EAP Code of an EAP Packet. If NULL EAP Packet or empty packet ERROR is stored in eapcode.
93 *
94 * Return value:
95 * 0 : if successful
96* EINVAL : if EAP Packet is NULL or empty
97 */
98
99int diameap_eap_get_code(struct eap_packet *eapPacket, eap_code * eapcode);
100
101
102/* Function : diameap_eap_get_identifier
103 *
104 * Parameters:
105 * eapPacket : an EAP Packet
106 * identifier : on successful return, the identifier value is stored here.
107 *
108 * Description:
109 * Get the Identifier field of an EAP Packet.
110 *
111 * Return value:
112 * 0 : if successful
113 * EINVAL : if the EAP Packet is NULL or the EAP identifier value is not valid or data length < 2
114 *
115 */
116
117int diameap_eap_get_identifier(struct eap_packet *eapPacket, u8 * identifier);
118
119
120/* Function : diameap_eap_get_length
121 *
122 * Parameters:
123 * eapPacket : an EAP Packet
124 * length : on successful return, the EAP Packet length field is stored here.
125 *
126 * Description:
127 * Get the Length field of an EAP Packet
128 *
129 * Return value:
130 * 0 : if successful
131 * EINVAL : if the data length < 4, or the EAP Packet is NULL.
132 */
133
134int diameap_eap_get_length(struct eap_packet *eapPacket, u16 *length);
135
136
137/* Function : diameap_eap_get_packetlength
138 *
139 * Parameters:
140 * eapPacket : an EAP Packet
141 * length : on successful return, the length of EAP Packet is stored here.
142 *
143 * Description:
144 * Get the received or inserted length of Bytes in an EAP Packet.
145 *
146 * Return value:
147 * 0 : if successful
148 * EINVAL : if the EAP Packet is NULL
149 */
150
151int diameap_eap_get_packetlength(struct eap_packet *eapPacket, u16 *length);
152
153
154/* Function : diameap_eap_get_type
155 *
156 * Parameters:
157 * eapPacket : an EAP Packet
158 * eaptype : on successful return, the EAP Type field is stored here.
159 *
160 * Description:
161 * Get the Type field of an EAP Packet.
162 *
163 * Return value:
164 * 0 : if successful
165 * EINVAL : if the EAP Packet is NULL or data length < 5
166 */
167
168int diameap_eap_get_type(struct eap_packet *eapPacket,eap_type * eaptype);
169
170
171/* Function : diameap_eap_get_packetdata
172 *
173 * Parameters:
174 * eapPacket : an EAP Packet
175 * eapdata : on successful return, the content of EAP Packet is stored here.
176 * eapdatalen : on successful return, the length of EAP Packet is stored here.
177 *
178 * Description:
179 * Get the data content of an EAP Packet.
180 *
181 * Return value:
182 * 0 : if successful
183 * EINVAL : if there is no data in the current EAP Packet (ulength<1)
184 */
185
186int diameap_eap_get_packetdata(struct eap_packet *eapPacket, u8 ** data, int *len);
187
188
189/* Function : diameap_eap_get_data
190 *
191 * Parameters:
192 * eapPacket : an EAP Packet
193 * data : on successful return, the content of data field is stored here.
194 * datalen : on successful return, the length of data field is stored here.
195 *
196 * Description:
197 * Return the Data field of an EAP Packet
198 *
199 * Return value:
200 * 0 : if successful
201 * EINVAL : if there is no data in the current EAP Packet (ulength<6)
202 */
203
204int diameap_eap_get_data(struct eap_packet *eapPacket, u8 ** data, int * len);
205
206
207/* Function : diameap_eap_chech_code
208 *
209 * Parameters:
210 * code : an EAP Code value
211 *
212 * Description:
213 * Check if the code value is valid or not
214 *
215 * Return value:
216 * TRUE : if valid value
217 * FALSE : if not valid value
218 *
219 */
220
221boolean diameap_eap_check_code(eap_code code);
222
223
224/* Function : diameap_eap_dump
225 *
226 * Parameters:
227 * eapPacket : an EAP Packet
228 * level : Debug level
229 *
230 * Description:
231 * Dump the structure and the content of all the fields in this EAP Packet
232 *
233 */
234
235void diameap_eap_dump(int level, struct eap_packet *eapPacket);
236
237
238/* Function : diameap_eap_new
239 *
240 * Parameters:
241 * code : EAP CODE field value
242 * id : EAP Identifier field value
243 * type : (optional) EAP type field value if exist, otherwise NULL
244 * data : (optional) EAP data field value if exist, otherwise NULL
245 * dataLength : (optional) Length of the data to be inserted in the Packet, otherwise 0
246 * eappacket : on successful return, pointer to eap packet is stored here.
247 * Description:
248 * Create a new EAP Packet with the specified parameters and data
249 *
250 * Return value:
251 * 0 : if successful
252 * EINVAL : Invalid parameter
253 */
254
255int diameap_eap_new(eap_code code, u8 id, eap_type type,
256 u8 * data, u16 dataLength, struct eap_packet *eappacket);
257
258#endif /* DIAMEAP_EAPPACKET_H_ */