2 * EAP server method registration
3 * Copyright (c) 2004-2009, 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_server_get_eap_method - 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_server_get_eap_method(int vendor, EapType method)
34 for (m = eap_methods; m; m = m->next) {
35 if (m->vendor == vendor && m->method == method)
43 * eap_server_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_server_get_type(const char *name, int *vendor)
54 for (m = eap_methods; m; m = m->next) {
55 if (os_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 = os_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 os_strcmp(m->name, method->name) == 0)
130 eap_methods = method;
137 * eap_server_unregister_methods - Unregister EAP server methods
139 * This function is called at program termination to unregister all EAP server
142 void eap_server_unregister_methods(void)
144 struct eap_method *m;
146 while (eap_methods) {
148 eap_methods = eap_methods->next;
153 eap_server_method_free(m);
159 * eap_server_get_name - Get EAP method name for the given EAP type
160 * @vendor: EAP Vendor-Id (0 = IETF)
161 * @type: EAP method type
162 * Returns: EAP method name, e.g., TLS, or %NULL if not found
164 * This function maps EAP type numbers into EAP type names based on the list of
165 * EAP methods included in the build.
167 const char * eap_server_get_name(int vendor, EapType type)
169 struct eap_method *m;
170 if (vendor == EAP_VENDOR_IETF && type == EAP_TYPE_EXPANDED)
172 for (m = eap_methods; m; m = m->next) {
173 if (m->vendor == vendor && m->method == type)