2 * hostapd / EAP method registration
3 * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
19 #include "eap_methods.h"
22 static struct eap_method
*eap_methods
;
26 * eap_sm_get_eap_methods - Get EAP method based on type number
27 * @vendor: EAP Vendor-Id (0 = IETF)
28 * @method: EAP type number
29 * Returns: Pointer to EAP method or %NULL if not found
31 const struct eap_method
* eap_sm_get_eap_methods(int vendor
, EapType method
)
34 for (m
= eap_methods
; m
; m
= m
->next
) {
35 if (m
->vendor
== vendor
&& m
->method
== method
)
43 * eap_get_type - Get EAP type for the given EAP method name
44 * @name: EAP method name, e.g., TLS
45 * @vendor: Buffer for returning EAP Vendor-Id
46 * Returns: EAP method type or %EAP_TYPE_NONE if not found
48 * This function maps EAP type names into EAP type numbers based on the list of
49 * EAP methods included in the build.
51 EapType
eap_get_type(const char *name
, int *vendor
)
54 for (m
= eap_methods
; m
; m
= m
->next
) {
55 if (strcmp(m
->name
, name
) == 0) {
60 *vendor
= EAP_VENDOR_IETF
;
66 * eap_server_method_alloc - Allocate EAP server method structure
67 * @version: Version of the EAP server method interface (set to
68 * EAP_SERVER_METHOD_INTERFACE_VERSION)
69 * @vendor: EAP Vendor-ID (EAP_VENDOR_*) (0 = IETF)
70 * @method: EAP type number (EAP_TYPE_*)
71 * name: Name of the method (e.g., "TLS")
72 * Returns: Allocated EAP method structure or %NULL on failure
74 * The returned structure should be freed with eap_server_method_free() when it
75 * is not needed anymore.
77 struct eap_method
* eap_server_method_alloc(int version
, int vendor
,
78 EapType method
, const char *name
)
80 struct eap_method
*eap
;
81 eap
= wpa_zalloc(sizeof(*eap
));
84 eap
->version
= version
;
93 * eap_server_method_free - Free EAP server method structure
94 * @method: Method structure allocated with eap_server_method_alloc()
96 void eap_server_method_free(struct eap_method
*method
)
103 * eap_server_method_register - Register an EAP server method
104 * @method: EAP method to register
105 * Returns: 0 on success, -1 on invalid method, or -2 if a matching EAP method
106 * has already been registered
108 * Each EAP server method needs to call this function to register itself as a
109 * supported EAP method.
111 int eap_server_method_register(struct eap_method
*method
)
113 struct eap_method
*m
, *last
= NULL
;
115 if (method
== NULL
|| method
->name
== NULL
||
116 method
->version
!= EAP_SERVER_METHOD_INTERFACE_VERSION
)
119 for (m
= eap_methods
; m
; m
= m
->next
) {
120 if ((m
->vendor
== method
->vendor
&&
121 m
->method
== method
->method
) ||
122 strcmp(m
->name
, method
->name
) == 0)
130 eap_methods
= method
;
137 * eap_server_register_methods - Register statically linked EAP server methods
138 * Returns: 0 on success, -1 on failure
140 * This function is called at program initialization to register all EAP server
141 * methods that were linked in statically.
143 int eap_server_register_methods(void)
148 int eap_server_identity_register(void);
149 ret
= eap_server_identity_register();
154 int eap_server_md5_register(void);
155 ret
= eap_server_md5_register();
161 int eap_server_tls_register(void);
162 ret
= eap_server_tls_register();
168 int eap_server_mschapv2_register(void);
169 ret
= eap_server_mschapv2_register();
171 #endif /* EAP_MSCHAPv2 */
175 int eap_server_peap_register(void);
176 ret
= eap_server_peap_register();
178 #endif /* EAP_PEAP */
182 int eap_server_tlv_register(void);
183 ret
= eap_server_tlv_register();
189 int eap_server_gtc_register(void);
190 ret
= eap_server_gtc_register();
196 int eap_server_ttls_register(void);
197 ret
= eap_server_ttls_register();
199 #endif /* EAP_TTLS */
203 int eap_server_sim_register(void);
204 ret
= eap_server_sim_register();
210 int eap_server_aka_register(void);
211 ret
= eap_server_aka_register();
217 int eap_server_pax_register(void);
218 ret
= eap_server_pax_register();
224 int eap_server_psk_register(void);
225 ret
= eap_server_psk_register();
231 int eap_server_sake_register(void);
232 ret
= eap_server_sake_register();
234 #endif /* EAP_SAKE */
238 int eap_server_gpsk_register(void);
239 ret
= eap_server_gpsk_register();
241 #endif /* EAP_GPSK */
243 #ifdef EAP_VENDOR_TEST
245 int eap_server_vendor_test_register(void);
246 ret
= eap_server_vendor_test_register();
248 #endif /* EAP_VENDOR_TEST */
255 * eap_server_unregister_methods - Unregister EAP server methods
257 * This function is called at program termination to unregister all EAP server
260 void eap_server_unregister_methods(void)
262 struct eap_method
*m
;
264 while (eap_methods
) {
266 eap_methods
= eap_methods
->next
;
271 eap_server_method_free(m
);