efd3ee98170e7b5c0627a52cf5fd4679f4ef7a38
[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_PEAP, EAP_MSCHAPV2, EAP_AKA,
48 "EAP_PEAP",
49 "EAP_MSCHAPV2");
50 ENUM_NEXT(eap_type_names, EAP_MSTLV, EAP_MSTLV, EAP_MSCHAPV2,
51 "EAP_MSTLV");
52 ENUM_NEXT(eap_type_names, EAP_TNC, EAP_TNC, EAP_MSTLV,
53 "EAP_TNC");
54 ENUM_NEXT(eap_type_names, EAP_DYNAMIC, EAP_EXPERIMENTAL, EAP_TNC,
55 "EAP_DYNAMIC",
56 "EAP_RADIUS",
57 "EAP_EXPANDED",
58 "EAP_EXPERIMENTAL");
59 ENUM_END(eap_type_names, EAP_EXPERIMENTAL);
60
61 ENUM_BEGIN(eap_type_short_names, EAP_IDENTITY, EAP_GTC,
62 "ID",
63 "NTF",
64 "NAK",
65 "MD5",
66 "OTP",
67 "GTC");
68 ENUM_NEXT(eap_type_short_names, EAP_TLS, EAP_TLS, EAP_GTC,
69 "TLS");
70 ENUM_NEXT(eap_type_short_names, EAP_SIM, EAP_SIM, EAP_TLS,
71 "SIM");
72 ENUM_NEXT(eap_type_short_names, EAP_TTLS, EAP_TTLS, EAP_SIM,
73 "TTLS");
74 ENUM_NEXT(eap_type_short_names, EAP_AKA, EAP_AKA, EAP_TTLS,
75 "AKA");
76 ENUM_NEXT(eap_type_short_names, EAP_PEAP, EAP_MSCHAPV2, EAP_AKA,
77 "PEAP",
78 "MSCHAPV2");
79 ENUM_NEXT(eap_type_short_names, EAP_MSTLV, EAP_MSTLV, EAP_MSCHAPV2,
80 "MSTLV");
81 ENUM_NEXT(eap_type_short_names, EAP_TNC, EAP_TNC, EAP_MSTLV,
82 "TNC");
83 ENUM_NEXT(eap_type_short_names, EAP_DYNAMIC, EAP_EXPERIMENTAL, EAP_TNC,
84 "DYN",
85 "RAD",
86 "EXP",
87 "XP");
88 ENUM_END(eap_type_short_names, EAP_EXPERIMENTAL);
89
90 /*
91 * See header
92 */
93 eap_type_t eap_type_from_string(char *name)
94 {
95 int i;
96 static struct {
97 char *name;
98 eap_type_t type;
99 } types[] = {
100 {"identity", EAP_IDENTITY},
101 {"md5", EAP_MD5},
102 {"otp", EAP_OTP},
103 {"gtc", EAP_GTC},
104 {"tls", EAP_TLS},
105 {"ttls", EAP_TTLS},
106 {"sim", EAP_SIM},
107 {"aka", EAP_AKA},
108 {"peap", EAP_PEAP},
109 {"mschapv2", EAP_MSCHAPV2},
110 {"tnc", EAP_TNC},
111 {"radius", EAP_RADIUS},
112 };
113
114 for (i = 0; i < countof(types); i++)
115 {
116 if (strcaseeq(name, types[i].name))
117 {
118 return types[i].type;
119 }
120 }
121 return 0;
122 }