]>
git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libstrongswan/eap/eap.c
2 * Copyright (C) 2012 Tobias Brunner
3 * Copyright (C) 2006 Martin Willi
4 * Hochschule fuer Technik Rapperswil
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 #include <utils/debug.h>
24 ENUM(eap_code_names
, EAP_REQUEST
, EAP_FAILURE
,
31 ENUM(eap_code_short_names
, EAP_REQUEST
, EAP_FAILURE
,
38 ENUM_BEGIN(eap_type_names
, EAP_IDENTITY
, EAP_GTC
,
45 ENUM_NEXT(eap_type_names
, EAP_TLS
, EAP_TLS
, EAP_GTC
,
47 ENUM_NEXT(eap_type_names
, EAP_SIM
, EAP_SIM
, EAP_TLS
,
49 ENUM_NEXT(eap_type_names
, EAP_TTLS
, EAP_TTLS
, EAP_SIM
,
51 ENUM_NEXT(eap_type_names
, EAP_AKA
, EAP_AKA
, EAP_TTLS
,
53 ENUM_NEXT(eap_type_names
, EAP_PEAP
, EAP_MSCHAPV2
, EAP_AKA
,
56 ENUM_NEXT(eap_type_names
, EAP_MSTLV
, EAP_MSTLV
, EAP_MSCHAPV2
,
58 ENUM_NEXT(eap_type_names
, EAP_TNC
, EAP_TNC
, EAP_MSTLV
,
60 ENUM_NEXT(eap_type_names
, EAP_EXPANDED
, EAP_DYNAMIC
, EAP_TNC
,
65 ENUM_END(eap_type_names
, EAP_DYNAMIC
);
67 ENUM_BEGIN(eap_type_short_names
, EAP_IDENTITY
, EAP_GTC
,
74 ENUM_NEXT(eap_type_short_names
, EAP_TLS
, EAP_TLS
, EAP_GTC
,
76 ENUM_NEXT(eap_type_short_names
, EAP_SIM
, EAP_SIM
, EAP_TLS
,
78 ENUM_NEXT(eap_type_short_names
, EAP_TTLS
, EAP_TTLS
, EAP_SIM
,
80 ENUM_NEXT(eap_type_short_names
, EAP_AKA
, EAP_AKA
, EAP_TTLS
,
82 ENUM_NEXT(eap_type_short_names
, EAP_PEAP
, EAP_MSCHAPV2
, EAP_AKA
,
85 ENUM_NEXT(eap_type_short_names
, EAP_MSTLV
, EAP_MSTLV
, EAP_MSCHAPV2
,
87 ENUM_NEXT(eap_type_short_names
, EAP_TNC
, EAP_TNC
, EAP_MSTLV
,
89 ENUM_NEXT(eap_type_short_names
, EAP_EXPANDED
, EAP_DYNAMIC
, EAP_TNC
,
94 ENUM_END(eap_type_short_names
, EAP_DYNAMIC
);
99 eap_type_t
eap_type_from_string(char *name
)
106 {"identity", EAP_IDENTITY
},
115 {"mschapv2", EAP_MSCHAPV2
},
117 {"dynamic", EAP_DYNAMIC
},
118 {"radius", EAP_RADIUS
},
121 for (i
= 0; i
< countof(types
); i
++)
123 if (strcaseeq(name
, types
[i
].name
))
125 return types
[i
].type
;
134 eap_vendor_type_t
*eap_vendor_type_from_string(char *str
)
136 enumerator_t
*enumerator
;
137 eap_vendor_type_t
*result
= NULL
;
139 u_int32_t vendor
= 0;
142 /* parse EAP method string of the form: [eap-]type[-vendor] */
143 enumerator
= enumerator_create_token(str
, "-", " ");
144 while (enumerator
->enumerate(enumerator
, &part
))
148 if (streq(part
, "eap"))
149 { /* skip 'eap' at the beginning */
152 type
= eap_type_from_string(part
);
155 type
= strtoul(part
, &end
, 0);
156 if (*end
!= '\0' || errno
)
158 DBG1(DBG_LIB
, "unknown or invalid EAP method: %s", part
);
164 vendor
= strtoul(part
, &end
, 0);
165 if (*end
!= '\0' || errno
)
167 DBG1(DBG_LIB
, "invalid EAP vendor: %s", part
);
172 enumerator
->destroy(enumerator
);