mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/wifi_service.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include <base/logging.h> |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 10 | #include <base/stringprintf.h> |
| 11 | #include <base/string_number_conversions.h> |
| 12 | #include <base/string_util.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 13 | #include <chromeos/dbus/service_constants.h> |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 14 | #include <dbus/dbus.h> |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 15 | #include <glib.h> |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 16 | |
| 17 | #include "shill/control_interface.h" |
| 18 | #include "shill/device.h" |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 19 | #include "shill/error.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 20 | #include "shill/event_dispatcher.h" |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 21 | #include "shill/ieee80211.h" |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 22 | #include "shill/store_interface.h" |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 23 | #include "shill/wifi.h" |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 24 | #include "shill/wifi_endpoint.h" |
| 25 | #include "shill/wpa_supplicant.h" |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 26 | |
| 27 | using std::string; |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 28 | using std::vector; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 29 | |
| 30 | namespace shill { |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 31 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 32 | const char WiFiService::kStorageHiddenSSID[] = "WiFi.HiddenSSID"; |
| 33 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 34 | WiFiService::WiFiService(ControlInterface *control_interface, |
| 35 | EventDispatcher *dispatcher, |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 36 | Manager *manager, |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 37 | const WiFiRefPtr &device, |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 38 | const std::vector<uint8_t> ssid, |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 39 | const std::string &mode, |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 40 | const std::string &security, |
| 41 | bool hidden_ssid) |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 42 | : Service(control_interface, dispatcher, manager, flimflam::kTypeWifi), |
Chris Masone | 7561230 | 2011-10-12 16:31:21 -0700 | [diff] [blame] | 43 | need_passphrase_(false), |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 44 | security_(security), |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 45 | mode_(mode), |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 46 | hidden_ssid_(hidden_ssid), |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 47 | task_factory_(this), |
| 48 | wifi_(device), |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 49 | ssid_(ssid) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 50 | PropertyStore *store = this->mutable_store(); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 51 | store->RegisterConstString(flimflam::kModeProperty, &mode_); |
| 52 | store->RegisterString(flimflam::kPassphraseProperty, &passphrase_); |
| 53 | store->RegisterBool(flimflam::kPassphraseRequiredProperty, &need_passphrase_); |
| 54 | store->RegisterConstString(flimflam::kSecurityProperty, &security_); |
| 55 | store->RegisterConstUint8(flimflam::kSignalStrengthProperty, &strength_); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 56 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 57 | store->RegisterConstString(flimflam::kWifiAuthMode, &auth_mode_); |
| 58 | store->RegisterConstBool(flimflam::kWifiHiddenSsid, &hidden_ssid_); |
| 59 | store->RegisterConstUint16(flimflam::kWifiFrequency, &frequency_); |
| 60 | store->RegisterConstUint16(flimflam::kWifiPhyMode, &physical_mode_); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 61 | |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 62 | hex_ssid_ = base::HexEncode(ssid_.data(), ssid_.size()); |
| 63 | string ssid_string( |
| 64 | reinterpret_cast<const char *>(ssid_.data()), ssid_.size()); |
| 65 | if (SanitizeSSID(&ssid_string)) { |
| 66 | // WifiHexSsid property should only be present if Name property |
| 67 | // has been munged. |
| 68 | store->RegisterConstString(flimflam::kWifiHexSsid, &hex_ssid_); |
| 69 | } |
| 70 | set_friendly_name(ssid_string); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 71 | |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 72 | // TODO(quiche): determine if it is okay to set EAP.KeyManagement for |
| 73 | // a service that is not 802.1x. |
| 74 | if (security_ == flimflam::kSecurity8021x) { |
| 75 | NOTIMPLEMENTED(); |
| 76 | // XXX needs_passpharse_ = false ? |
| 77 | } else if (security_ == flimflam::kSecurityPsk) { |
| 78 | SetEAPKeyManagement("WPA-PSK"); |
| 79 | need_passphrase_ = true; |
| 80 | } else if (security_ == flimflam::kSecurityRsn) { |
| 81 | SetEAPKeyManagement("WPA-PSK"); |
| 82 | need_passphrase_ = true; |
| 83 | } else if (security_ == flimflam::kSecurityWpa) { |
| 84 | SetEAPKeyManagement("WPA-PSK"); |
| 85 | need_passphrase_ = true; |
| 86 | } else if (security_ == flimflam::kSecurityWep) { |
| 87 | SetEAPKeyManagement("NONE"); |
| 88 | need_passphrase_ = true; |
| 89 | } else if (security_ == flimflam::kSecurityNone) { |
| 90 | SetEAPKeyManagement("NONE"); |
| 91 | need_passphrase_ = false; |
| 92 | } else { |
| 93 | LOG(ERROR) << "unsupported security method " << security_; |
| 94 | } |
| 95 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 96 | // Until we know better (at Profile load time), use the generic name. |
| 97 | storage_identifier_ = GetGenericStorageIdentifier(); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | WiFiService::~WiFiService() { |
| 101 | LOG(INFO) << __func__; |
| 102 | } |
| 103 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 104 | void WiFiService::Connect(Error */*error*/) { |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 105 | LOG(INFO) << __func__; |
| 106 | |
| 107 | // NB(quiche) defer handling, since dbus-c++ does not permit us to |
| 108 | // send an outbound request while processing an inbound one. |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 109 | dispatcher()->PostTask( |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 110 | task_factory_.NewRunnableMethod(&WiFiService::ConnectTask)); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 113 | void WiFiService::Disconnect() { |
| 114 | // TODO(quiche) RemoveNetwork from supplicant |
| 115 | // XXX remove from favorite networks list? |
| 116 | } |
| 117 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 118 | bool WiFiService::TechnologyIs(const Technology::Identifier type) const { |
| 119 | return wifi_->TechnologyIs(type); |
| 120 | } |
| 121 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 122 | string WiFiService::GetStorageIdentifier() const { |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 123 | return storage_identifier_; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 124 | } |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 125 | const string &WiFiService::mode() const { |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 126 | return mode_; |
| 127 | } |
| 128 | |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 129 | const string &WiFiService::key_management() const { |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 130 | return GetEAPKeyManagement(); |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | const std::vector<uint8_t> &WiFiService::ssid() const { |
| 134 | return ssid_; |
| 135 | } |
| 136 | |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 137 | void WiFiService::SetPassphrase(const string &passphrase, Error *error) { |
| 138 | if (security_ == flimflam::kSecurityWep) { |
| 139 | passphrase_ = ParseWEPPassphrase(passphrase, error); |
| 140 | } else if (security_ == flimflam::kSecurityPsk || |
| 141 | security_ == flimflam::kSecurityWpa || |
| 142 | security_ == flimflam::kSecurityRsn) { |
| 143 | passphrase_ = ParseWPAPassphrase(passphrase, error); |
| 144 | } |
| 145 | } |
| 146 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 147 | bool WiFiService::IsLoadableFrom(StoreInterface *storage) const { |
| 148 | return storage->ContainsGroup(GetGenericStorageIdentifier()) || |
| 149 | storage->ContainsGroup(GetSpecificStorageIdentifier()); |
| 150 | } |
| 151 | |
| 152 | bool WiFiService::Load(StoreInterface *storage) { |
| 153 | // First find out which storage identifier is available in priority order |
| 154 | // of specific, generic. |
| 155 | string id = GetSpecificStorageIdentifier(); |
| 156 | if (!storage->ContainsGroup(id)) { |
| 157 | id = GetGenericStorageIdentifier(); |
| 158 | if (!storage->ContainsGroup(id)) { |
| 159 | LOG(WARNING) << "Service is not available in the persistent store: " |
| 160 | << id; |
| 161 | return false; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // Set our storage identifier to match the storage name in the Profile. |
| 166 | storage_identifier_ = id; |
| 167 | |
| 168 | // Load properties common to all Services. |
| 169 | if (!Service::Load(storage)) { |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | // Load properties specific to WiFi services. |
| 174 | storage->GetBool(id, kStorageHiddenSSID, &hidden_ssid_); |
| 175 | return true; |
| 176 | } |
| 177 | |
| 178 | bool WiFiService::Save(StoreInterface *storage) { |
| 179 | // Save properties common to all Services. |
| 180 | if (!Service::Save(storage)) { |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | // Save properties specific to WiFi services. |
| 185 | const string id = GetStorageIdentifier(); |
| 186 | storage->SetBool(id, kStorageHiddenSSID, &hidden_ssid_); |
| 187 | return true; |
| 188 | } |
| 189 | |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 190 | bool WiFiService::IsSecurityMatch(const string &security) const { |
| 191 | return GetSecurityClass(security) == GetSecurityClass(security_); |
| 192 | } |
| 193 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 194 | // private methods |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 195 | void WiFiService::ConnectTask() { |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 196 | std::map<string, DBus::Variant> params; |
| 197 | DBus::MessageIter writer; |
| 198 | |
| 199 | params[wpa_supplicant::kNetworkPropertyMode].writer(). |
| 200 | append_uint32(WiFiEndpoint::ModeStringToUint(mode_)); |
| 201 | |
| 202 | if (security_ == flimflam::kSecurity8021x) { |
| 203 | NOTIMPLEMENTED(); |
| 204 | } else if (security_ == flimflam::kSecurityPsk) { |
Gaurav Shah | f8721ee | 2011-11-07 09:12:46 -0800 | [diff] [blame] | 205 | const string psk_proto = StringPrintf("%s %s", |
| 206 | wpa_supplicant::kSecurityModeWPA, |
| 207 | wpa_supplicant::kSecurityModeRSN); |
| 208 | params[wpa_supplicant::kPropertySecurityProtocol].writer(). |
| 209 | append_string(psk_proto.c_str()); |
| 210 | params[wpa_supplicant::kPropertyPreSharedKey].writer(). |
| 211 | append_string(passphrase_.c_str()); |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 212 | } else if (security_ == flimflam::kSecurityRsn) { |
mukesh agrawal | f2fd745 | 2011-10-03 16:38:47 -0700 | [diff] [blame] | 213 | params[wpa_supplicant::kPropertySecurityProtocol].writer(). |
| 214 | append_string(wpa_supplicant::kSecurityModeRSN); |
| 215 | params[wpa_supplicant::kPropertyPreSharedKey].writer(). |
| 216 | append_string(passphrase_.c_str()); |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 217 | } else if (security_ == flimflam::kSecurityWpa) { |
| 218 | params[wpa_supplicant::kPropertySecurityProtocol].writer(). |
| 219 | append_string(wpa_supplicant::kSecurityModeWPA); |
| 220 | params[wpa_supplicant::kPropertyPreSharedKey].writer(). |
| 221 | append_string(passphrase_.c_str()); |
| 222 | } else if (security_ == flimflam::kSecurityWep) { |
| 223 | NOTIMPLEMENTED(); |
| 224 | } else if (security_ == flimflam::kSecurityNone) { |
Gaurav Shah | f8721ee | 2011-11-07 09:12:46 -0800 | [diff] [blame] | 225 | // Nothing special to do here. |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 226 | } else { |
Gaurav Shah | f8721ee | 2011-11-07 09:12:46 -0800 | [diff] [blame] | 227 | LOG(ERROR) << "Can't connect. Unsupported security method " << security_; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | params[wpa_supplicant::kPropertyKeyManagement].writer(). |
| 231 | append_string(key_management().c_str()); |
| 232 | // TODO(quiche): figure out why we can't use operator<< without the |
| 233 | // temporary variable. |
| 234 | writer = params[wpa_supplicant::kNetworkPropertySSID].writer(); |
| 235 | writer << ssid_; |
| 236 | |
| 237 | wifi_->ConnectTo(this, params); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame^] | 240 | string WiFiService::GetDeviceRpcId(Error */*error*/) { |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 241 | return wifi_->GetRpcIdentifier(); |
| 242 | } |
| 243 | |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 244 | // static |
| 245 | string WiFiService::ParseWEPPassphrase(const string &passphrase, Error *error) { |
| 246 | unsigned int length = passphrase.length(); |
| 247 | |
| 248 | switch (length) { |
| 249 | case IEEE_80211::kWEP40AsciiLen: |
| 250 | case IEEE_80211::kWEP104AsciiLen: |
| 251 | break; |
| 252 | case IEEE_80211::kWEP40AsciiLen + 2: |
| 253 | case IEEE_80211::kWEP104AsciiLen + 2: |
| 254 | CheckWEPKeyIndex(passphrase, error); |
| 255 | break; |
| 256 | case IEEE_80211::kWEP40HexLen: |
| 257 | case IEEE_80211::kWEP104HexLen: |
| 258 | CheckWEPIsHex(passphrase, error); |
| 259 | break; |
| 260 | case IEEE_80211::kWEP40HexLen + 2: |
| 261 | case IEEE_80211::kWEP104HexLen + 2: |
| 262 | (CheckWEPKeyIndex(passphrase, error) || |
| 263 | CheckWEPPrefix(passphrase, error)) && |
| 264 | CheckWEPIsHex(passphrase.substr(2), error); |
| 265 | break; |
| 266 | case IEEE_80211::kWEP40HexLen + 4: |
| 267 | case IEEE_80211::kWEP104HexLen + 4: |
| 268 | CheckWEPKeyIndex(passphrase, error) && |
| 269 | CheckWEPPrefix(passphrase.substr(2), error) && |
| 270 | CheckWEPIsHex(passphrase.substr(4), error); |
| 271 | break; |
| 272 | default: |
| 273 | error->Populate(Error::kInvalidPassphrase); |
| 274 | break; |
| 275 | } |
| 276 | |
| 277 | // TODO(quiche): may need to normalize passphrase format |
| 278 | if (error->IsSuccess()) { |
| 279 | return passphrase; |
| 280 | } else { |
| 281 | return ""; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | // static |
| 286 | string WiFiService::ParseWPAPassphrase(const string &passphrase, Error *error) { |
| 287 | unsigned int length = passphrase.length(); |
| 288 | vector<uint8> passphrase_bytes; |
| 289 | |
| 290 | if (base::HexStringToBytes(passphrase, &passphrase_bytes)) { |
| 291 | if (length != IEEE_80211::kWPAHexLen && |
| 292 | (length < IEEE_80211::kWPAAsciiMinLen || |
| 293 | length > IEEE_80211::kWPAAsciiMaxLen)) { |
| 294 | error->Populate(Error::kInvalidPassphrase); |
| 295 | } |
| 296 | } else { |
| 297 | if (length < IEEE_80211::kWPAAsciiMinLen || |
| 298 | length > IEEE_80211::kWPAAsciiMaxLen) { |
| 299 | error->Populate(Error::kInvalidPassphrase); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | // TODO(quiche): may need to normalize passphrase format |
| 304 | if (error->IsSuccess()) { |
| 305 | return passphrase; |
| 306 | } else { |
| 307 | return ""; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | // static |
| 312 | bool WiFiService::CheckWEPIsHex(const string &passphrase, Error *error) { |
| 313 | vector<uint8> passphrase_bytes; |
| 314 | if (base::HexStringToBytes(passphrase, &passphrase_bytes)) { |
| 315 | return true; |
| 316 | } else { |
| 317 | error->Populate(Error::kInvalidPassphrase); |
| 318 | return false; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | // static |
| 323 | bool WiFiService::CheckWEPKeyIndex(const string &passphrase, Error *error) { |
| 324 | if (StartsWithASCII(passphrase, "0:", false) || |
| 325 | StartsWithASCII(passphrase, "1:", false) || |
| 326 | StartsWithASCII(passphrase, "2:", false) || |
| 327 | StartsWithASCII(passphrase, "3:", false)) { |
| 328 | return true; |
| 329 | } else { |
| 330 | error->Populate(Error::kInvalidPassphrase); |
| 331 | return false; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | // static |
| 336 | bool WiFiService::CheckWEPPrefix(const string &passphrase, Error *error) { |
| 337 | if (StartsWithASCII(passphrase, "0x", false)) { |
| 338 | return true; |
| 339 | } else { |
| 340 | error->Populate(Error::kInvalidPassphrase); |
| 341 | return false; |
| 342 | } |
| 343 | } |
| 344 | |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 345 | // static |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 346 | bool WiFiService::SanitizeSSID(string *ssid) { |
| 347 | CHECK(ssid); |
| 348 | |
| 349 | size_t ssid_len = ssid->length(); |
| 350 | size_t i; |
| 351 | bool changed = false; |
| 352 | |
| 353 | for (i=0; i < ssid_len; ++i) { |
| 354 | if (!g_ascii_isprint((*ssid)[i])) { |
| 355 | (*ssid)[i] = '?'; |
| 356 | changed = true; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | return changed; |
| 361 | } |
| 362 | |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 363 | // static |
| 364 | string WiFiService::GetSecurityClass(const string &security) { |
| 365 | if (security == flimflam::kSecurityRsn || |
| 366 | security == flimflam::kSecurityWpa) { |
| 367 | return flimflam::kSecurityPsk; |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 368 | } else { |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 369 | return security; |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 373 | string WiFiService::GetGenericStorageIdentifier() const { |
| 374 | return GetStorageIdentifierForSecurity(GetSecurityClass(security_)); |
| 375 | } |
| 376 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 377 | string WiFiService::GetSpecificStorageIdentifier() const { |
| 378 | return GetStorageIdentifierForSecurity(security_); |
| 379 | } |
| 380 | |
| 381 | string WiFiService::GetStorageIdentifierForSecurity( |
| 382 | const string &security) const { |
| 383 | return StringToLowerASCII(base::StringPrintf("%s_%s_%s_%s_%s", |
| 384 | flimflam::kTypeWifi, |
| 385 | wifi_->address().c_str(), |
| 386 | hex_ssid_.c_str(), |
| 387 | mode_.c_str(), |
| 388 | security.c_str())); |
| 389 | } |
| 390 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 391 | } // namespace shill |