eap_server_methods.c
Go to the documentation of this file.
00001 /*
00002  * EAP server method registration
00003  * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  */
00014 
00015 #include "includes.h"
00016 
00017 #include "common.h"
00018 #include "eap_i.h"
00019 #include "eap_methods.h"
00020 
00021 
00022 static struct eap_method *eap_methods;
00023 
00024 
00031 const struct eap_method * eap_server_get_eap_method(int vendor, EapType method)
00032 {
00033         struct eap_method *m;
00034         for (m = eap_methods; m; m = m->next) {
00035                 if (m->vendor == vendor && m->method == method)
00036                         return m;
00037         }
00038         return NULL;
00039 }
00040 
00041 
00051 EapType eap_server_get_type(const char *name, int *vendor)
00052 {
00053         struct eap_method *m;
00054         for (m = eap_methods; m; m = m->next) {
00055                 if (os_strcmp(m->name, name) == 0) {
00056                         *vendor = m->vendor;
00057                         return m->method;
00058                 }
00059         }
00060         *vendor = EAP_VENDOR_IETF;
00061         return EAP_TYPE_NONE;
00062 }
00063 
00064 
00077 struct eap_method * eap_server_method_alloc(int version, int vendor,
00078                                             EapType method, const char *name)
00079 {
00080         struct eap_method *eap;
00081         eap = os_zalloc(sizeof(*eap));
00082         if (eap == NULL)
00083                 return NULL;
00084         eap->version = version;
00085         eap->vendor = vendor;
00086         eap->method = method;
00087         eap->name = name;
00088         return eap;
00089 }
00090 
00091 
00096 void eap_server_method_free(struct eap_method *method)
00097 {
00098         os_free(method);
00099 }
00100 
00101 
00111 int eap_server_method_register(struct eap_method *method)
00112 {
00113         struct eap_method *m, *last = NULL;
00114 
00115         if (method == NULL || method->name == NULL ||
00116             method->version != EAP_SERVER_METHOD_INTERFACE_VERSION)
00117                 return -1;
00118 
00119         for (m = eap_methods; m; m = m->next) {
00120                 if ((m->vendor == method->vendor &&
00121                      m->method == method->method) ||
00122                     os_strcmp(m->name, method->name) == 0)
00123                         return -2;
00124                 last = m;
00125         }
00126 
00127         if (last)
00128                 last->next = method;
00129         else
00130                 eap_methods = method;
00131 
00132         return 0;
00133 }
00134 
00135 
00142 void eap_server_unregister_methods(void)
00143 {
00144         struct eap_method *m;
00145 
00146         while (eap_methods) {
00147                 m = eap_methods;
00148                 eap_methods = eap_methods->next;
00149 
00150                 if (m->free)
00151                         m->free(m);
00152                 else
00153                         eap_server_method_free(m);
00154         }
00155 }
00156 
00157 
00167 const char * eap_server_get_name(int vendor, EapType type)
00168 {
00169         struct eap_method *m;
00170         for (m = eap_methods; m; m = m->next) {
00171                 if (m->vendor == vendor && m->method == type)
00172                         return m->name;
00173         }
00174         return NULL;
00175 }


wpa_supplicant
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:34:34