eap.h
Go to the documentation of this file.
1 /**
2  * @file eap.h
3  * @brief EAP (Extensible Authentication Protocol)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2022-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneEAP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _EAP_H
32 #define _EAP_H
33 
34 //Dependencies
35 #include "eap_config.h"
36 #include "core/net.h"
37 #include "core/crypto.h"
38 
39 
40 /*
41  * CycloneEAP Open is licensed under GPL version 2. In particular:
42  *
43  * - If you link your program to CycloneEAP Open, the result is a derivative
44  * work that can only be distributed under the same GPL license terms.
45  *
46  * - If additions or changes to CycloneEAP Open are made, the result is a
47  * derivative work that can only be distributed under the same license terms.
48  *
49  * - The GPL license requires that you make the source code available to
50  * whoever you make the binary available to.
51  *
52  * - If you sell or distribute a hardware product that runs CycloneEAP Open,
53  * the GPL license requires you to provide public and full access to all
54  * source code on a nondiscriminatory basis.
55  *
56  * If you fully understand and accept the terms of the GPL license, then edit
57  * the os_port_config.h header and add the following directive:
58  *
59  * #define GPL_LICENSE_TERMS_ACCEPTED
60  */
61 
62 #ifndef GPL_LICENSE_TERMS_ACCEPTED
63  #error Before compiling CycloneEAP Open, you must accept the terms of the GPL license
64 #endif
65 
66 //Version string
67 #define CYCLONE_EAP_VERSION_STRING "2.4.0"
68 //Major version
69 #define CYCLONE_EAP_MAJOR_VERSION 2
70 //Minor version
71 #define CYCLONE_EAP_MINOR_VERSION 4
72 //Revision number
73 #define CYCLONE_EAP_REV_NUMBER 0
74 
75 //EAP support
76 #ifndef EAP_SUPPORT
77  #define EAP_SUPPORT ENABLED
78 #elif (EAP_SUPPORT != ENABLED && EAP_SUPPORT != DISABLED)
79  #error EAP_SUPPORT parameter is not valid
80 #endif
81 
82 //MD5-Challenge authentication method support
83 #ifndef EAP_MD5_SUPPORT
84  #define EAP_MD5_SUPPORT DISABLED
85 #elif (EAP_MD5_SUPPORT != ENABLED && EAP_MD5_SUPPORT != DISABLED)
86  #error EAP_MD5_SUPPORT parameter is not valid
87 #endif
88 
89 //EAP-TLS authentication method support
90 #ifndef EAP_TLS_SUPPORT
91  #define EAP_TLS_SUPPORT DISABLED
92 #elif (EAP_TLS_SUPPORT != ENABLED && EAP_TLS_SUPPORT != DISABLED)
93  #error EAP_TLS_SUPPORT parameter is not valid
94 #endif
95 
96 //Maximum fragment size
97 #ifndef EAP_MAX_FRAG_SIZE
98  #define EAP_MAX_FRAG_SIZE 1000
99 #elif (EAP_MAX_FRAG_SIZE < 100 || EAP_MAX_FRAG_SIZE > 1500)
100  #error EAP_DEFAULT_CLIENT_TIMEOUT parameter is not valid
101 #endif
102 
103 //Default client timeout
104 #ifndef EAP_DEFAULT_CLIENT_TIMEOUT
105  #define EAP_DEFAULT_CLIENT_TIMEOUT 30
106 #elif (EAP_DEFAULT_CLIENT_TIMEOUT < 0)
107  #error EAP_DEFAULT_CLIENT_TIMEOUT parameter is not valid
108 #endif
109 
110 //C++ guard
111 #ifdef __cplusplus
112 extern "C" {
113 #endif
114 
115 
116 /**
117  * @brief EAPOL protocol versions
118  **/
119 
120 typedef enum
121 {
122  EAPOL_VERSION_1 = 1, ///<IEEE 802.1X-2001
123  EAPOL_VERSION_2 = 2, ///<IEEE 802.1X-2004
124  EAPOL_VERSION_3 = 3 ///<IEEE 802.1X-2010
126 
127 
128 /**
129  * @brief EAPOL packet types
130  **/
131 
132 typedef enum
133 {
134  EAPOL_TYPE_EAP = 0, ///<EAPOL-EAP
135  EAPOL_TYPE_START = 1, ///<EAPOL-Start
136  EAPOL_TYPE_LOGOFF = 2, ///<EAPOL-Logoff
137  EAPOL_TYPE_KEY = 3, ///<EAPOL-Key
138  EAPOL_TYPE_ENCAPSULATED_ASF_ALERT = 4, ///<EAPOL-Encapsulated-ASF-Alert
139  EAPOL_TYPE_MKA = 5, ///<EAPOL-MKA
140  EAPOL_TYPE_ANNOUNCEMENT_GENERIC = 6, ///<EAPOL-Announcement (Generic)
141  EAPOL_TYPE_ANNOUNCEMENT_SPECIFIC = 7, ///<EAPOL-Announcement (Specific)
142  EAPOL_TYPE_ANNOUNCEMENT_REQ = 8 ///<EAPOL-Announcement-Req
144 
145 
146 /**
147  * @brief EAP codes
148  **/
149 
150 typedef enum
151 {
152  EAP_CODE_REQUEST = 1, ///<Request
153  EAP_CODE_RESPONSE = 2, ///<Response
154  EAP_CODE_SUCCESS = 3, ///<Success
155  EAP_CODE_FAILURE = 4 ///<Failure
157 
158 
159 /**
160  * @brief EAP method types
161  **/
162 
163 typedef enum
164 {
165  EAP_METHOD_TYPE_NONE = 0, ///<None
166  EAP_METHOD_TYPE_IDENTITY = 1, ///<Identity
167  EAP_METHOD_TYPE_NOTIFICATION = 2, ///<Notification
168  EAP_METHOD_TYPE_NAK = 3, ///<Legacy Nak
169  EAP_METHOD_TYPE_MD5_CHALLENGE = 4, ///<MD5-Challenge
170  EAP_METHOD_TYPE_OTP = 5, ///<One-Time Password (OTP)
171  EAP_METHOD_TYPE_GTC = 6, ///<Generic Token Card (GTC)
172  EAP_METHOD_TYPE_TLS = 13, ///<EAP-TLS
173  EAP_METHOD_TYPE_TTLS = 21, ///<EAP-TTLS
174  EAP_METHOD_TYPE_PEAP = 25, ///<PEAP
175  EAP_METHOD_TYPE_MSCHAP_V2 = 29, ///<EAP-MSCHAP-V2
176  EAP_METHOD_TYPE_EXPANDED_NAK = 254 ///<Expanded NAK
178 
179 
180 /**
181  * @brief EAP-TLS flags
182  **/
183 
184 typedef enum
185 {
186  EAP_TLS_FLAGS_L = 0x80, ///<Length included
187  EAP_TLS_FLAGS_M = 0x40, ///<More fragments
188  EAP_TLS_FLAGS_S = 0x20, ///<EAP-TLS start
189  EAP_TLS_FLAGS_R = 0x1F ///<Reserved
191 
192 
193 //CC-RX, CodeWarrior or Win32 compiler?
194 #if defined(__CCRX__)
195  #pragma pack
196 #elif defined(__CWCC__) || defined(_WIN32)
197  #pragma pack(push, 1)
198 #endif
199 
200 
201 /**
202  * @brief EAPOL PDU
203  **/
204 
206 {
207  uint8_t protocolVersion; //0
208  uint8_t packetType; //1
209  uint16_t packetBodyLen; //2-3
210  uint8_t packetBody[]; //4
212 
213 
214 /**
215  * @brief EAP packet
216  **/
217 
218 typedef __packed_struct
219 {
220  uint8_t code; //0
221  uint8_t identifier; //1
222  uint16_t length; //2-3
223  uint8_t data[]; //4
225 
226 
227 /**
228  * @brief EAP request
229  **/
230 
231 typedef __packed_struct
232 {
233  uint8_t code; //0
234  uint8_t identifier; //1
235  uint16_t length; //2-3
236  uint8_t type; //4
237  uint8_t data[]; //5
239 
240 
241 /**
242  * @brief EAP response
243  **/
244 
245 typedef __packed_struct
246 {
247  uint8_t code; //0
248  uint8_t identifier; //1
249  uint16_t length; //2-3
250  uint8_t type; //4
251  uint8_t data[]; //5
253 
254 
255 /**
256  * @brief EAP-TLS packet
257  **/
258 
259 typedef __packed_struct
260 {
261  uint8_t code; //0
262  uint8_t identifier; //1
263  uint16_t length; //2-3
264  uint8_t type; //4
265  uint8_t flags; //5
266  uint8_t data[]; //6
268 
269 
270 //CC-RX, CodeWarrior or Win32 compiler?
271 #if defined(__CCRX__)
272  #pragma unpack
273 #elif defined(__CWCC__) || defined(_WIN32)
274  #pragma pack(pop)
275 #endif
276 
277 //C++ guard
278 #ifdef __cplusplus
279 }
280 #endif
281 
282 #endif
uint8_t code
Definition: coap_common.h:179
General definitions for cryptographic algorithms.
EapCode
EAP codes.
Definition: eap.h:151
@ EAP_CODE_FAILURE
Failure.
Definition: eap.h:155
@ EAP_CODE_REQUEST
Request.
Definition: eap.h:152
@ EAP_CODE_RESPONSE
Response.
Definition: eap.h:153
@ EAP_CODE_SUCCESS
Success.
Definition: eap.h:154
uint16_t length
Definition: eap.h:222
uint8_t type
Definition: eap.h:236
uint8_t packetBody[]
Definition: eap.h:210
EapRequest
Definition: eap.h:238
EapolPdu
Definition: eap.h:211
uint8_t packetType
Definition: eap.h:208
EapTlsFlags
EAP-TLS flags.
Definition: eap.h:185
@ EAP_TLS_FLAGS_L
Length included.
Definition: eap.h:186
@ EAP_TLS_FLAGS_R
Reserved.
Definition: eap.h:189
@ EAP_TLS_FLAGS_S
EAP-TLS start.
Definition: eap.h:188
@ EAP_TLS_FLAGS_M
More fragments.
Definition: eap.h:187
uint8_t data[]
Definition: eap.h:223
EapResponse
Definition: eap.h:252
EapPacket
Definition: eap.h:224
uint8_t flags
Definition: eap.h:265
EapolVersion
EAPOL protocol versions.
Definition: eap.h:121
@ EAPOL_VERSION_1
IEEE 802.1X-2001.
Definition: eap.h:122
@ EAPOL_VERSION_3
IEEE 802.1X-2010.
Definition: eap.h:124
@ EAPOL_VERSION_2
IEEE 802.1X-2004.
Definition: eap.h:123
EapTlsPacket
Definition: eap.h:267
typedef __packed_struct
EAPOL PDU.
Definition: eap.h:206
uint8_t identifier
Definition: eap.h:221
EapolType
EAPOL packet types.
Definition: eap.h:133
@ EAPOL_TYPE_START
EAPOL-Start.
Definition: eap.h:135
@ EAPOL_TYPE_LOGOFF
EAPOL-Logoff.
Definition: eap.h:136
@ EAPOL_TYPE_KEY
EAPOL-Key.
Definition: eap.h:137
@ EAPOL_TYPE_ANNOUNCEMENT_GENERIC
EAPOL-Announcement (Generic)
Definition: eap.h:140
@ EAPOL_TYPE_MKA
EAPOL-MKA.
Definition: eap.h:139
@ EAPOL_TYPE_ENCAPSULATED_ASF_ALERT
EAPOL-Encapsulated-ASF-Alert.
Definition: eap.h:138
@ EAPOL_TYPE_ANNOUNCEMENT_SPECIFIC
EAPOL-Announcement (Specific)
Definition: eap.h:141
@ EAPOL_TYPE_EAP
EAPOL-EAP.
Definition: eap.h:134
@ EAPOL_TYPE_ANNOUNCEMENT_REQ
EAPOL-Announcement-Req.
Definition: eap.h:142
uint16_t packetBodyLen
Definition: eap.h:209
EapMethodType
EAP method types.
Definition: eap.h:164
@ EAP_METHOD_TYPE_EXPANDED_NAK
Expanded NAK.
Definition: eap.h:176
@ EAP_METHOD_TYPE_OTP
One-Time Password (OTP)
Definition: eap.h:170
@ EAP_METHOD_TYPE_NOTIFICATION
Notification.
Definition: eap.h:167
@ EAP_METHOD_TYPE_MSCHAP_V2
EAP-MSCHAP-V2.
Definition: eap.h:175
@ EAP_METHOD_TYPE_PEAP
PEAP.
Definition: eap.h:174
@ EAP_METHOD_TYPE_GTC
Generic Token Card (GTC)
Definition: eap.h:171
@ EAP_METHOD_TYPE_TLS
EAP-TLS.
Definition: eap.h:172
@ EAP_METHOD_TYPE_NONE
None.
Definition: eap.h:165
@ EAP_METHOD_TYPE_NAK
Legacy Nak.
Definition: eap.h:168
@ EAP_METHOD_TYPE_MD5_CHALLENGE
MD5-Challenge.
Definition: eap.h:169
@ EAP_METHOD_TYPE_TTLS
EAP-TTLS.
Definition: eap.h:173
@ EAP_METHOD_TYPE_IDENTITY
Identity.
Definition: eap.h:166
TCP/IP stack core.