We are using 4.1.2 really.
[dragonfly/netmp.git] / contrib / hostapd-0.5.8 / eap_methods.c
blob671d5486c3166255fc8b90c180b944e8e5d12cd8
1 /*
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
10 * license.
12 * See README and COPYING for more details.
15 #include "includes.h"
17 #include "hostapd.h"
18 #include "eap_i.h"
19 #include "eap_methods.h"
22 static struct eap_method *eap_methods;
25 /**
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)
33 struct eap_method *m;
34 for (m = eap_methods; m; m = m->next) {
35 if (m->vendor == vendor && m->method == method)
36 return m;
38 return NULL;
42 /**
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)
53 struct eap_method *m;
54 for (m = eap_methods; m; m = m->next) {
55 if (strcmp(m->name, name) == 0) {
56 *vendor = m->vendor;
57 return m->method;
60 *vendor = EAP_VENDOR_IETF;
61 return EAP_TYPE_NONE;
65 /**
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));
82 if (eap == NULL)
83 return NULL;
84 eap->version = version;
85 eap->vendor = vendor;
86 eap->method = method;
87 eap->name = name;
88 return eap;
92 /**
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)
98 free(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)
117 return -1;
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)
123 return -2;
124 last = m;
127 if (last)
128 last->next = method;
129 else
130 eap_methods = method;
132 return 0;
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)
145 int ret = 0;
147 if (ret == 0) {
148 int eap_server_identity_register(void);
149 ret = eap_server_identity_register();
152 #ifdef EAP_MD5
153 if (ret == 0) {
154 int eap_server_md5_register(void);
155 ret = eap_server_md5_register();
157 #endif /* EAP_MD5 */
159 #ifdef EAP_TLS
160 if (ret == 0) {
161 int eap_server_tls_register(void);
162 ret = eap_server_tls_register();
164 #endif /* EAP_TLS */
166 #ifdef EAP_MSCHAPv2
167 if (ret == 0) {
168 int eap_server_mschapv2_register(void);
169 ret = eap_server_mschapv2_register();
171 #endif /* EAP_MSCHAPv2 */
173 #ifdef EAP_PEAP
174 if (ret == 0) {
175 int eap_server_peap_register(void);
176 ret = eap_server_peap_register();
178 #endif /* EAP_PEAP */
180 #ifdef EAP_TLV
181 if (ret == 0) {
182 int eap_server_tlv_register(void);
183 ret = eap_server_tlv_register();
185 #endif /* EAP_TLV */
187 #ifdef EAP_GTC
188 if (ret == 0) {
189 int eap_server_gtc_register(void);
190 ret = eap_server_gtc_register();
192 #endif /* EAP_GTC */
194 #ifdef EAP_TTLS
195 if (ret == 0) {
196 int eap_server_ttls_register(void);
197 ret = eap_server_ttls_register();
199 #endif /* EAP_TTLS */
201 #ifdef EAP_SIM
202 if (ret == 0) {
203 int eap_server_sim_register(void);
204 ret = eap_server_sim_register();
206 #endif /* EAP_SIM */
208 #ifdef EAP_AKA
209 if (ret == 0) {
210 int eap_server_aka_register(void);
211 ret = eap_server_aka_register();
213 #endif /* EAP_AKA */
215 #ifdef EAP_PAX
216 if (ret == 0) {
217 int eap_server_pax_register(void);
218 ret = eap_server_pax_register();
220 #endif /* EAP_PAX */
222 #ifdef EAP_PSK
223 if (ret == 0) {
224 int eap_server_psk_register(void);
225 ret = eap_server_psk_register();
227 #endif /* EAP_PSK */
229 #ifdef EAP_SAKE
230 if (ret == 0) {
231 int eap_server_sake_register(void);
232 ret = eap_server_sake_register();
234 #endif /* EAP_SAKE */
236 #ifdef EAP_GPSK
237 if (ret == 0) {
238 int eap_server_gpsk_register(void);
239 ret = eap_server_gpsk_register();
241 #endif /* EAP_GPSK */
243 #ifdef EAP_VENDOR_TEST
244 if (ret == 0) {
245 int eap_server_vendor_test_register(void);
246 ret = eap_server_vendor_test_register();
248 #endif /* EAP_VENDOR_TEST */
250 return ret;
255 * eap_server_unregister_methods - Unregister EAP server methods
257 * This function is called at program termination to unregister all EAP server
258 * methods.
260 void eap_server_unregister_methods(void)
262 struct eap_method *m;
264 while (eap_methods) {
265 m = eap_methods;
266 eap_methods = eap_methods->next;
268 if (m->free)
269 m->free(m);
270 else
271 eap_server_method_free(m);