Added a pseudo EAP type to allow an implementation to select the real type dynamically
[strongswan.git] / src / libstrongswan / eap / eap.c
1 /*
2 * Copyright (C) 2006 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "eap.h"
17
18 ENUM(eap_code_names, EAP_REQUEST, EAP_FAILURE,
19 "EAP_REQUEST",
20 "EAP_RESPONSE",
21 "EAP_SUCCESS",
22 "EAP_FAILURE",
23 );
24
25 ENUM(eap_code_short_names, EAP_REQUEST, EAP_FAILURE,
26 "REQ",
27 "RES",
28 "SUCC",
29 "FAIL",
30 );
31
32 ENUM_BEGIN(eap_type_names, EAP_IDENTITY, EAP_GTC,
33 "EAP_IDENTITY",
34 "EAP_NOTIFICATION",
35 "EAP_NAK",
36 "EAP_MD5",
37 "EAP_OTP",
38 "EAP_GTC");
39 ENUM_NEXT(eap_type_names, EAP_TLS, EAP_TLS, EAP_GTC,
40 "EAP_TLS");
41 ENUM_NEXT(eap_type_names, EAP_SIM, EAP_SIM, EAP_TLS,
42 "EAP_SIM");
43 ENUM_NEXT(eap_type_names, EAP_TTLS, EAP_TTLS, EAP_SIM,
44 "EAP_TTLS");
45 ENUM_NEXT(eap_type_names, EAP_AKA, EAP_AKA, EAP_TTLS,
46 "EAP_AKA");
47 ENUM_NEXT(eap_type_names, EAP_MSCHAPV2, EAP_MSCHAPV2, EAP_AKA,
48 "EAP_MSCHAPV2");
49 ENUM_NEXT(eap_type_names, EAP_TNC, EAP_TNC, EAP_MSCHAPV2,
50 "EAP_TNC");
51 ENUM_NEXT(eap_type_names, EAP_DYNAMIC, EAP_EXPERIMENTAL, EAP_TNC,
52 "EAP_DYNAMIC",
53 "EAP_RADIUS",
54 "EAP_EXPANDED",
55 "EAP_EXPERIMENTAL");
56 ENUM_END(eap_type_names, EAP_EXPERIMENTAL);
57
58 ENUM_BEGIN(eap_type_short_names, EAP_IDENTITY, EAP_GTC,
59 "ID",
60 "NTF",
61 "NAK",
62 "MD5",
63 "OTP",
64 "GTC");
65 ENUM_NEXT(eap_type_short_names, EAP_TLS, EAP_TLS, EAP_GTC,
66 "TLS");
67 ENUM_NEXT(eap_type_short_names, EAP_SIM, EAP_SIM, EAP_TLS,
68 "SIM");
69 ENUM_NEXT(eap_type_short_names, EAP_TTLS, EAP_TTLS, EAP_SIM,
70 "TTLS");
71 ENUM_NEXT(eap_type_short_names, EAP_AKA, EAP_AKA, EAP_TTLS,
72 "AKA");
73 ENUM_NEXT(eap_type_short_names, EAP_MSCHAPV2, EAP_MSCHAPV2, EAP_AKA,
74 "MSCHAPV2");
75 ENUM_NEXT(eap_type_short_names, EAP_TNC, EAP_TNC, EAP_MSCHAPV2,
76 "TNC");
77 ENUM_NEXT(eap_type_short_names, EAP_DYNAMIC, EAP_EXPERIMENTAL, EAP_TNC,
78 "DYN",
79 "RAD",
80 "EXP",
81 "XP");
82 ENUM_END(eap_type_short_names, EAP_EXPERIMENTAL);
83
84 ENUM(auth_rule_names, AUTH_RULE_IDENTITY, AUTH_HELPER_SUBJECT_HASH_URL,
85 "RULE_IDENTITY",
86 "RULE_AUTH_CLASS",
87 "RULE_EAP_IDENTITY",
88 "RULE_EAP_TYPE",
89 "RULE_EAP_VENDOR",
90 "RULE_CA_CERT",
91 "RULE_IM_CERT",
92 "RULE_SUBJECT_CERT",
93 "RULE_CRL_VALIDATION",
94 "RULE_OCSP_VALIDATION",
95 "RULE_GROUP",
96 "HELPER_IM_CERT",
97 "HELPER_SUBJECT_CERT",
98 "HELPER_IM_HASH_URL",
99 "HELPER_SUBJECT_HASH_URL",
100 );
101
102 /*
103 * See header
104 */
105 eap_type_t eap_type_from_string(char *name)
106 {
107 int i;
108 static struct {
109 char *name;
110 eap_type_t type;
111 } types[] = {
112 {"identity", EAP_IDENTITY},
113 {"md5", EAP_MD5},
114 {"otp", EAP_OTP},
115 {"gtc", EAP_GTC},
116 {"tls", EAP_TLS},
117 {"ttls", EAP_TTLS},
118 {"sim", EAP_SIM},
119 {"aka", EAP_AKA},
120 {"mschapv2", EAP_MSCHAPV2},
121 {"tnc", EAP_TNC},
122 {"radius", EAP_RADIUS},
123 };
124
125 for (i = 0; i < countof(types); i++)
126 {
127 if (strcaseeq(name, types[i].name))
128 {
129 return types[i].type;
130 }
131 }
132 return 0;
133 }