1//
2// Copyright (C) 2012 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#include "shill/supplicant/wpa_supplicant.h"
18
19#include <map>
20#include <string>
21
22#include "shill/logging.h"
23
24using std::map;
25using std::string;
26
27namespace shill {
28
29// static
30const char WPASupplicant::kBSSPropertyBSSID[] = "BSSID";
31const char WPASupplicant::kBSSPropertyFrequency[] = "Frequency";
32const char WPASupplicant::kBSSPropertyIEs[] = "IEs";
33const char WPASupplicant::kBSSPropertyMode[] = "Mode";
34const char WPASupplicant::kBSSPropertyRates[] = "Rates";
35const char WPASupplicant::kBSSPropertySSID[] = "SSID";
36const char WPASupplicant::kBSSPropertySignal[] = "Signal";
37// TODO(gauravsh): Make this path be a configurable option. crbug.com/208594
38// Location of the system root CA certificates.
39const char WPASupplicant::kCaPath[] = "/etc/ssl/certs";
40const char WPASupplicant::kCurrentBSSNull[] = "/";
41const char WPASupplicant::kDBusAddr[] = "fi.w1.wpa_supplicant1";
42const char WPASupplicant::kDBusPath[] = "/fi/w1/wpa_supplicant1";
43const char WPASupplicant::kDebugLevelDebug[] = "debug";
44const char WPASupplicant::kDebugLevelError[] = "error";
45const char WPASupplicant::kDebugLevelExcessive[] = "excessive";
46const char WPASupplicant::kDebugLevelInfo[] = "info";
47const char WPASupplicant::kDebugLevelMsgDump[] = "msgdump";
48const char WPASupplicant::kDebugLevelWarning[] = "warning";
49const char WPASupplicant::kDriverNL80211[] = "nl80211";
50const char WPASupplicant::kDriverWired[] = "wired";
51const char WPASupplicant::kEAPParameterAlertUnknownCA[] = "unknown CA";
52const char WPASupplicant::kEAPParameterFailure[] = "failure";
53const char WPASupplicant::kEAPParameterSuccess[] = "success";
54const char WPASupplicant::kEAPRequestedParameterPIN[] = "PIN";
55const char WPASupplicant::kEAPStatusAcceptProposedMethod[] =
56    "accept proposed method";
57const char WPASupplicant::kEAPStatusCompletion[] = "completion";
58const char WPASupplicant::kEAPStatusLocalTLSAlert[] = "local TLS alert";
59const char WPASupplicant::kEAPStatusParameterNeeded[] = "eap parameter needed";
60const char WPASupplicant::kEAPStatusRemoteCertificateVerification[] =
61    "remote certificate verification";
62const char WPASupplicant::kEAPStatusRemoteTLSAlert[] = "remote TLS alert";
63const char WPASupplicant::kEAPStatusStarted[] = "started";
64const char WPASupplicant::kEnginePKCS11[] = "pkcs11";
65const char WPASupplicant::kErrorNetworkUnknown[]
66    = "fi.w1.wpa_supplicant1.NetworkUnknown";
67const char WPASupplicant::kErrorInterfaceExists[]
68    = "fi.w1.wpa_supplicant1.InterfaceExists";
69const char WPASupplicant::kInterfacePropertyConfigFile[] = "ConfigFile";
70const char WPASupplicant::kInterfacePropertyCurrentBSS[] = "CurrentBSS";
71const char WPASupplicant::kInterfacePropertyDepth[] = "depth";
72const char WPASupplicant::kInterfacePropertyDisconnectReason[]
73    = "DisconnectReason";
74const char WPASupplicant::kInterfacePropertyDriver[] = "Driver";
75const char WPASupplicant::kInterfacePropertyName[] = "Ifname";
76const char WPASupplicant::kInterfacePropertyState[] = "State";
77const char WPASupplicant::kInterfacePropertySubject[] = "subject";
78const char WPASupplicant::kInterfaceState4WayHandshake[] = "4way_handshake";
79const char WPASupplicant::kInterfaceStateAssociated[] = "associated";
80const char WPASupplicant::kInterfaceStateAssociating[] = "associating";
81const char WPASupplicant::kInterfaceStateAuthenticating[] = "authenticating";
82const char WPASupplicant::kInterfaceStateCompleted[] = "completed";
83const char WPASupplicant::kInterfaceStateDisconnected[] = "disconnected";
84const char WPASupplicant::kInterfaceStateGroupHandshake[] = "group_handshake";
85const char WPASupplicant::kInterfaceStateInactive[] = "inactive";
86const char WPASupplicant::kInterfaceStateScanning[] = "scanning";
87const char WPASupplicant::kKeyManagementIeee8021X[] = "IEEE8021X";
88const char WPASupplicant::kKeyManagementMethodSuffixEAP[] = "-eap";
89const char WPASupplicant::kKeyManagementMethodSuffixPSK[] = "-psk";
90const char WPASupplicant::kKeyModeNone[] = "NONE";
91const char WPASupplicant::kNetworkBgscanMethodLearn[] = "learn";
92// None is not a real method name, but we interpret 'none' as a request that
93// no background scan parameter should be supplied to wpa_supplicant.
94const char WPASupplicant::kNetworkBgscanMethodNone[] = "none";
95const char WPASupplicant::kNetworkBgscanMethodSimple[] = "simple";
96const char WPASupplicant::kNetworkModeInfrastructure[] = "infrastructure";
97const char WPASupplicant::kNetworkModeAdHoc[] = "ad-hoc";
98const char WPASupplicant::kNetworkModeAccessPoint[] = "ap";
99const char WPASupplicant::kNetworkPropertyBgscan[] = "bgscan";
100const char WPASupplicant::kNetworkPropertyCaPath[] = "ca_path";
101const char WPASupplicant::kNetworkPropertyDisableVHT[] = "disable_vht";
102const char WPASupplicant::kNetworkPropertyEapIdentity[] = "identity";
103const char WPASupplicant::kNetworkPropertyEapKeyManagement[] = "key_mgmt";
104const char WPASupplicant::kNetworkPropertyEapEap[] = "eap";
105const char WPASupplicant::kNetworkPropertyEapInnerEap[] = "phase2";
106const char WPASupplicant::kNetworkPropertyEapAnonymousIdentity[]
107    = "anonymous_identity";
108const char WPASupplicant::kNetworkPropertyEapClientCert[] = "client_cert";
109const char WPASupplicant::kNetworkPropertyEapPrivateKey[] = "private_key";
110const char WPASupplicant::kNetworkPropertyEapPrivateKeyPassword[]
111    = "private_key_passwd";
112const char WPASupplicant::kNetworkPropertyEapProactiveKeyCaching[]
113    = "proactive_key_caching";
114const char WPASupplicant::kNetworkPropertyEapCaCert[] = "ca_cert";
115const char WPASupplicant::kNetworkPropertyEapCaPassword[] = "password";
116const char WPASupplicant::kNetworkPropertyEapCertId[] = "cert_id";
117const char WPASupplicant::kNetworkPropertyEapKeyId[] = "key_id";
118const char WPASupplicant::kNetworkPropertyEapCaCertId[] = "ca_cert_id";
119const char WPASupplicant::kNetworkPropertyEapPin[] = "pin";
120const char WPASupplicant::kNetworkPropertyEapSubjectMatch[] = "subject_match";
121const char WPASupplicant::kNetworkPropertyEapolFlags[] = "eapol_flags";
122const char WPASupplicant::kNetworkPropertyEngine[] = "engine";
123const char WPASupplicant::kNetworkPropertyEngineId[] = "engine_id";
124const char WPASupplicant::kNetworkPropertyFrequency[] = "frequency";
125const char WPASupplicant::kNetworkPropertyIeee80211w[] = "ieee80211w";
126const char WPASupplicant::kNetworkPropertyMode[] = "mode";
127const char WPASupplicant::kNetworkPropertyScanSSID[] = "scan_ssid";
128const char WPASupplicant::kNetworkPropertySSID[] = "ssid";
129const char WPASupplicant::kPropertyAuthAlg[] = "auth_alg";
130const char WPASupplicant::kPropertyPreSharedKey[] = "psk";
131const char WPASupplicant::kPropertyPrivacy[] = "Privacy";
132const char WPASupplicant::kPropertyRSN[] = "RSN";
133const char WPASupplicant::kPropertyScanSSIDs[] = "SSIDs";
134const char WPASupplicant::kPropertyScanType[] = "Type";
135const char WPASupplicant::kPropertySecurityProtocol[] = "proto";
136const char WPASupplicant::kPropertyWEPKey[] = "wep_key";
137const char WPASupplicant::kPropertyWEPTxKeyIndex[] = "wep_tx_keyidx";
138const char WPASupplicant::kPropertyWPA[] = "WPA";
139const char WPASupplicant::kScanTypeActive[] = "active";
140const char WPASupplicant::kSecurityAuthAlg[] = "OPEN SHARED";
141const char WPASupplicant::kSecurityMethodPropertyKeyManagement[] = "KeyMgmt";
142const char WPASupplicant::kSecurityModeRSN[] = "RSN";
143const char WPASupplicant::kSecurityModeWPA[] = "WPA";
144
145const char WPASupplicant::kTDLSStateConnected[] = "connected";
146const char WPASupplicant::kTDLSStateDisabled[] = "disabled";
147const char WPASupplicant::kTDLSStatePeerDoesNotExist[] = "peer does not exist";
148const char WPASupplicant::kTDLSStatePeerNotConnected[] = "peer not connected";
149
150const uint32_t WPASupplicant::kDefaultEngine = 1;
151const uint32_t WPASupplicant::kNetworkIeee80211wDisabled = 0;
152const uint32_t WPASupplicant::kNetworkIeee80211wEnabled = 1;
153const uint32_t WPASupplicant::kNetworkIeee80211wRequired = 2;
154const uint32_t WPASupplicant::kNetworkModeInfrastructureInt = 0;
155const uint32_t WPASupplicant::kNetworkModeAdHocInt = 1;
156const uint32_t WPASupplicant::kNetworkModeAccessPointInt = 2;
157const uint32_t WPASupplicant::kScanMaxSSIDsPerScan = 4;
158
159const uint32_t WPASupplicant::kProactiveKeyCachingDisabled = 0;
160const uint32_t WPASupplicant::kProactiveKeyCachingEnabled = 1;
161
162const char WPASupplicant::kSupplicantConfPath[] =
163    SHIMDIR "/wpa_supplicant.conf";
164
165// static
166bool WPASupplicant::ExtractRemoteCertification(const KeyValueStore& properties,
167                                               string* subject,
168                                               uint32_t* depth) {
169  if (!properties.ContainsUint(WPASupplicant::kInterfacePropertyDepth)) {
170    LOG(ERROR) << __func__ << " no depth parameter.";
171    return false;
172  }
173  if (!properties.ContainsString(WPASupplicant::kInterfacePropertySubject)) {
174    LOG(ERROR) << __func__ << " no subject parameter.";
175    return false;
176  }
177
178  *depth = properties.GetUint(WPASupplicant::kInterfacePropertyDepth);
179  *subject = properties.GetString(WPASupplicant::kInterfacePropertySubject);
180  return true;
181}
182
183}  // namespace shill
184