2 * EAP server method registration
3 * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
13 #include "eap_methods.h"
16 static struct eap_method
*eap_methods
;
20 * eap_server_get_eap_method - Get EAP method based on type number
21 * @vendor: EAP Vendor-Id (0 = IETF)
22 * @method: EAP type number
23 * Returns: Pointer to EAP method or %NULL if not found
25 const struct eap_method
* eap_server_get_eap_method(int vendor
, EapType method
)
28 for (m
= eap_methods
; m
; m
= m
->next
) {
29 if (m
->vendor
== vendor
&& m
->method
== method
)
37 * eap_server_get_type - Get EAP type for the given EAP method name
38 * @name: EAP method name, e.g., TLS
39 * @vendor: Buffer for returning EAP Vendor-Id
40 * Returns: EAP method type or %EAP_TYPE_NONE if not found
42 * This function maps EAP type names into EAP type numbers based on the list of
43 * EAP methods included in the build.
45 EapType
eap_server_get_type(const char *name
, int *vendor
)
48 for (m
= eap_methods
; m
; m
= m
->next
) {
49 if (os_strcmp(m
->name
, name
) == 0) {
54 *vendor
= EAP_VENDOR_IETF
;
60 * eap_server_method_alloc - Allocate EAP server method structure
61 * @version: Version of the EAP server method interface (set to
62 * EAP_SERVER_METHOD_INTERFACE_VERSION)
63 * @vendor: EAP Vendor-ID (EAP_VENDOR_*) (0 = IETF)
64 * @method: EAP type number (EAP_TYPE_*)
65 * @name: Name of the method (e.g., "TLS")
66 * Returns: Allocated EAP method structure or %NULL on failure
68 * The returned structure should be freed with eap_server_method_free() when it
69 * is not needed anymore.
71 struct eap_method
* eap_server_method_alloc(int version
, int vendor
,
72 EapType method
, const char *name
)
74 struct eap_method
*eap
;
75 eap
= os_zalloc(sizeof(*eap
));
78 eap
->version
= version
;
87 * eap_server_method_free - Free EAP server method structure
88 * @method: Method structure allocated with eap_server_method_alloc()
90 static void eap_server_method_free(struct eap_method
*method
)
97 * eap_server_method_register - Register an EAP server method
98 * @method: EAP method to register from eap_server_method_alloc()
99 * Returns: 0 on success, -1 on invalid method, or -2 if a matching EAP method
100 * has already been registered
102 * Each EAP server method needs to call this function to register itself as a
103 * supported EAP method. The caller must not free the allocated method data
104 * regardless of the return value.
106 int eap_server_method_register(struct eap_method
*method
)
108 struct eap_method
*m
, *last
= NULL
;
110 if (method
== NULL
|| method
->name
== NULL
||
111 method
->version
!= EAP_SERVER_METHOD_INTERFACE_VERSION
) {
112 eap_server_method_free(method
);
116 for (m
= eap_methods
; m
; m
= m
->next
) {
117 if ((m
->vendor
== method
->vendor
&&
118 m
->method
== method
->method
) ||
119 os_strcmp(m
->name
, method
->name
) == 0) {
120 eap_server_method_free(method
);
129 eap_methods
= method
;
136 * eap_server_unregister_methods - Unregister EAP server methods
138 * This function is called at program termination to unregister all EAP server
141 void eap_server_unregister_methods(void)
143 struct eap_method
*m
;
145 while (eap_methods
) {
147 eap_methods
= eap_methods
->next
;
152 eap_server_method_free(m
);
158 * eap_server_get_name - Get EAP method name for the given EAP type
159 * @vendor: EAP Vendor-Id (0 = IETF)
160 * @type: EAP method type
161 * Returns: EAP method name, e.g., TLS, or "unknown" if not found
163 * This function maps EAP type numbers into EAP type names based on the list of
164 * EAP methods included in the build.
166 const char * eap_server_get_name(int vendor
, EapType type
)
168 struct eap_method
*m
;
169 if (vendor
== EAP_VENDOR_IETF
&& type
== EAP_TYPE_EXPANDED
)
171 for (m
= eap_methods
; m
; m
= m
->next
) {
172 if (m
->vendor
== vendor
&& m
->method
== type
)