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 24 using std::map; 25 using std::string; 26 27 namespace shill { 28 29 // static 30 const char WPASupplicant::kBSSPropertyBSSID[] = "BSSID"; 31 const char WPASupplicant::kBSSPropertyFrequency[] = "Frequency"; 32 const char WPASupplicant::kBSSPropertyIEs[] = "IEs"; 33 const char WPASupplicant::kBSSPropertyMode[] = "Mode"; 34 const char WPASupplicant::kBSSPropertyRates[] = "Rates"; 35 const char WPASupplicant::kBSSPropertySSID[] = "SSID"; 36 const 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. 39 const char WPASupplicant::kCaPath[] = "/etc/ssl/certs"; 40 const char WPASupplicant::kCurrentBSSNull[] = "/"; 41 const char WPASupplicant::kDBusAddr[] = "fi.w1.wpa_supplicant1"; 42 const char WPASupplicant::kDBusPath[] = "/fi/w1/wpa_supplicant1"; 43 const char WPASupplicant::kDebugLevelDebug[] = "debug"; 44 const char WPASupplicant::kDebugLevelError[] = "error"; 45 const char WPASupplicant::kDebugLevelExcessive[] = "excessive"; 46 const char WPASupplicant::kDebugLevelInfo[] = "info"; 47 const char WPASupplicant::kDebugLevelMsgDump[] = "msgdump"; 48 const char WPASupplicant::kDebugLevelWarning[] = "warning"; 49 const char WPASupplicant::kDriverNL80211[] = "nl80211"; 50 const char WPASupplicant::kDriverWired[] = "wired"; 51 const char WPASupplicant::kEAPParameterAlertUnknownCA[] = "unknown CA"; 52 const char WPASupplicant::kEAPParameterFailure[] = "failure"; 53 const char WPASupplicant::kEAPParameterSuccess[] = "success"; 54 const char WPASupplicant::kEAPRequestedParameterPIN[] = "PIN"; 55 const char WPASupplicant::kEAPStatusAcceptProposedMethod[] = 56 "accept proposed method"; 57 const char WPASupplicant::kEAPStatusCompletion[] = "completion"; 58 const char WPASupplicant::kEAPStatusLocalTLSAlert[] = "local TLS alert"; 59 const char WPASupplicant::kEAPStatusParameterNeeded[] = "eap parameter needed"; 60 const char WPASupplicant::kEAPStatusRemoteCertificateVerification[] = 61 "remote certificate verification"; 62 const char WPASupplicant::kEAPStatusRemoteTLSAlert[] = "remote TLS alert"; 63 const char WPASupplicant::kEAPStatusStarted[] = "started"; 64 const char WPASupplicant::kEnginePKCS11[] = "pkcs11"; 65 const char WPASupplicant::kErrorNetworkUnknown[] 66 = "fi.w1.wpa_supplicant1.NetworkUnknown"; 67 const char WPASupplicant::kErrorInterfaceExists[] 68 = "fi.w1.wpa_supplicant1.InterfaceExists"; 69 const char WPASupplicant::kInterfacePropertyConfigFile[] = "ConfigFile"; 70 const char WPASupplicant::kInterfacePropertyCurrentBSS[] = "CurrentBSS"; 71 const char WPASupplicant::kInterfacePropertyDepth[] = "depth"; 72 const char WPASupplicant::kInterfacePropertyDisconnectReason[] 73 = "DisconnectReason"; 74 const char WPASupplicant::kInterfacePropertyDriver[] = "Driver"; 75 const char WPASupplicant::kInterfacePropertyName[] = "Ifname"; 76 const char WPASupplicant::kInterfacePropertyState[] = "State"; 77 const char WPASupplicant::kInterfacePropertySubject[] = "subject"; 78 const char WPASupplicant::kInterfaceState4WayHandshake[] = "4way_handshake"; 79 const char WPASupplicant::kInterfaceStateAssociated[] = "associated"; 80 const char WPASupplicant::kInterfaceStateAssociating[] = "associating"; 81 const char WPASupplicant::kInterfaceStateAuthenticating[] = "authenticating"; 82 const char WPASupplicant::kInterfaceStateCompleted[] = "completed"; 83 const char WPASupplicant::kInterfaceStateDisconnected[] = "disconnected"; 84 const char WPASupplicant::kInterfaceStateGroupHandshake[] = "group_handshake"; 85 const char WPASupplicant::kInterfaceStateInactive[] = "inactive"; 86 const char WPASupplicant::kInterfaceStateScanning[] = "scanning"; 87 const char WPASupplicant::kKeyManagementIeee8021X[] = "IEEE8021X"; 88 const char WPASupplicant::kKeyManagementMethodSuffixEAP[] = "-eap"; 89 const char WPASupplicant::kKeyManagementMethodSuffixPSK[] = "-psk"; 90 const char WPASupplicant::kKeyModeNone[] = "NONE"; 91 const 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. 94 const char WPASupplicant::kNetworkBgscanMethodNone[] = "none"; 95 const char WPASupplicant::kNetworkBgscanMethodSimple[] = "simple"; 96 const char WPASupplicant::kNetworkModeInfrastructure[] = "infrastructure"; 97 const char WPASupplicant::kNetworkModeAdHoc[] = "ad-hoc"; 98 const char WPASupplicant::kNetworkModeAccessPoint[] = "ap"; 99 const char WPASupplicant::kNetworkPropertyBgscan[] = "bgscan"; 100 const char WPASupplicant::kNetworkPropertyCaPath[] = "ca_path"; 101 const char WPASupplicant::kNetworkPropertyDisableVHT[] = "disable_vht"; 102 const char WPASupplicant::kNetworkPropertyEapIdentity[] = "identity"; 103 const char WPASupplicant::kNetworkPropertyEapKeyManagement[] = "key_mgmt"; 104 const char WPASupplicant::kNetworkPropertyEapEap[] = "eap"; 105 const char WPASupplicant::kNetworkPropertyEapInnerEap[] = "phase2"; 106 const char WPASupplicant::kNetworkPropertyEapAnonymousIdentity[] 107 = "anonymous_identity"; 108 const char WPASupplicant::kNetworkPropertyEapClientCert[] = "client_cert"; 109 const char WPASupplicant::kNetworkPropertyEapPrivateKey[] = "private_key"; 110 const char WPASupplicant::kNetworkPropertyEapPrivateKeyPassword[] 111 = "private_key_passwd"; 112 const char WPASupplicant::kNetworkPropertyEapProactiveKeyCaching[] 113 = "proactive_key_caching"; 114 const char WPASupplicant::kNetworkPropertyEapCaCert[] = "ca_cert"; 115 const char WPASupplicant::kNetworkPropertyEapCaPassword[] = "password"; 116 const char WPASupplicant::kNetworkPropertyEapCertId[] = "cert_id"; 117 const char WPASupplicant::kNetworkPropertyEapKeyId[] = "key_id"; 118 const char WPASupplicant::kNetworkPropertyEapCaCertId[] = "ca_cert_id"; 119 const char WPASupplicant::kNetworkPropertyEapPin[] = "pin"; 120 const char WPASupplicant::kNetworkPropertyEapSubjectMatch[] = "subject_match"; 121 const char WPASupplicant::kNetworkPropertyEapolFlags[] = "eapol_flags"; 122 const char WPASupplicant::kNetworkPropertyEngine[] = "engine"; 123 const char WPASupplicant::kNetworkPropertyEngineId[] = "engine_id"; 124 const char WPASupplicant::kNetworkPropertyFrequency[] = "frequency"; 125 const char WPASupplicant::kNetworkPropertyIeee80211w[] = "ieee80211w"; 126 const char WPASupplicant::kNetworkPropertyMode[] = "mode"; 127 const char WPASupplicant::kNetworkPropertyScanSSID[] = "scan_ssid"; 128 const char WPASupplicant::kNetworkPropertySSID[] = "ssid"; 129 const char WPASupplicant::kPropertyAuthAlg[] = "auth_alg"; 130 const char WPASupplicant::kPropertyPreSharedKey[] = "psk"; 131 const char WPASupplicant::kPropertyPrivacy[] = "Privacy"; 132 const char WPASupplicant::kPropertyRSN[] = "RSN"; 133 const char WPASupplicant::kPropertyScanSSIDs[] = "SSIDs"; 134 const char WPASupplicant::kPropertyScanType[] = "Type"; 135 const char WPASupplicant::kPropertySecurityProtocol[] = "proto"; 136 const char WPASupplicant::kPropertyWEPKey[] = "wep_key"; 137 const char WPASupplicant::kPropertyWEPTxKeyIndex[] = "wep_tx_keyidx"; 138 const char WPASupplicant::kPropertyWPA[] = "WPA"; 139 const char WPASupplicant::kScanTypeActive[] = "active"; 140 const char WPASupplicant::kSecurityAuthAlg[] = "OPEN SHARED"; 141 const char WPASupplicant::kSecurityMethodPropertyKeyManagement[] = "KeyMgmt"; 142 const char WPASupplicant::kSecurityModeRSN[] = "RSN"; 143 const char WPASupplicant::kSecurityModeWPA[] = "WPA"; 144 145 const char WPASupplicant::kTDLSStateConnected[] = "connected"; 146 const char WPASupplicant::kTDLSStateDisabled[] = "disabled"; 147 const char WPASupplicant::kTDLSStatePeerDoesNotExist[] = "peer does not exist"; 148 const char WPASupplicant::kTDLSStatePeerNotConnected[] = "peer not connected"; 149 150 const uint32_t WPASupplicant::kDefaultEngine = 1; 151 const uint32_t WPASupplicant::kNetworkIeee80211wDisabled = 0; 152 const uint32_t WPASupplicant::kNetworkIeee80211wEnabled = 1; 153 const uint32_t WPASupplicant::kNetworkIeee80211wRequired = 2; 154 const uint32_t WPASupplicant::kNetworkModeInfrastructureInt = 0; 155 const uint32_t WPASupplicant::kNetworkModeAdHocInt = 1; 156 const uint32_t WPASupplicant::kNetworkModeAccessPointInt = 2; 157 const uint32_t WPASupplicant::kScanMaxSSIDsPerScan = 4; 158 159 const uint32_t WPASupplicant::kProactiveKeyCachingDisabled = 0; 160 const uint32_t WPASupplicant::kProactiveKeyCachingEnabled = 1; 161 162 const char WPASupplicant::kSupplicantConfPath[] = 163 SHIMDIR "/wpa_supplicant.conf"; 164 165 // static ExtractRemoteCertification(const KeyValueStore & properties,string * subject,uint32_t * depth)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