Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Chan | d6a8b51 | 2014-11-18 10:45:15 -0800 | [diff] [blame] | 5 | #include "shill/wifi/wifi_endpoint.h" |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 6 | |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 9 | #include <base/stl_util.h> |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 10 | #include <base/strings/stringprintf.h> |
| 11 | #include <base/strings/string_number_conversions.h> |
| 12 | #include <base/strings/string_util.h> |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 13 | #include <chromeos/dbus/service_constants.h> |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 14 | |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 15 | #include "shill/logging.h" |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 16 | #include "shill/metrics.h" |
Peter Qiu | 02e3dc3 | 2014-10-31 10:15:00 -0700 | [diff] [blame] | 17 | #include "shill/net/ieee80211.h" |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 18 | #include "shill/proxy_factory.h" |
Ben Chan | da69ecf | 2014-11-19 07:44:42 -0800 | [diff] [blame] | 19 | #include "shill/supplicant/supplicant_bss_proxy_interface.h" |
| 20 | #include "shill/supplicant/wpa_supplicant.h" |
Paul Stewart | fa11e28 | 2013-12-02 22:04:25 -0800 | [diff] [blame] | 21 | #include "shill/tethering.h" |
Ben Chan | d6a8b51 | 2014-11-18 10:45:15 -0800 | [diff] [blame] | 22 | #include "shill/wifi/wifi.h" |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 23 | |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 24 | using base::StringPrintf; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 25 | using std::map; |
| 26 | using std::set; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 27 | using std::string; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 28 | using std::vector; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 29 | |
| 30 | namespace shill { |
| 31 | |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 32 | namespace Logging { |
| 33 | static auto kModuleLogScope = ScopeLogger::kWiFi; |
| 34 | static string ObjectID(WiFiEndpoint *w) { return "(wifi_endpoint)"; } |
| 35 | } |
| 36 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 37 | WiFiEndpoint::WiFiEndpoint(ProxyFactory *proxy_factory, |
| 38 | const WiFiRefPtr &device, |
| 39 | const string &rpc_id, |
| 40 | const map<string, ::DBus::Variant> &properties) |
| 41 | : frequency_(0), |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 42 | physical_mode_(Metrics::kWiFiNetworkPhyModeUndef), |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 43 | ieee80211w_required_(false), |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 44 | proxy_factory_(proxy_factory), |
| 45 | device_(device), |
| 46 | rpc_id_(rpc_id) { |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 47 | // XXX will segfault on missing properties |
| 48 | ssid_ = |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 49 | properties.find(WPASupplicant::kBSSPropertySSID)->second. |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 50 | operator std::vector<uint8_t>(); |
| 51 | bssid_ = |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 52 | properties.find(WPASupplicant::kBSSPropertyBSSID)->second. |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 53 | operator std::vector<uint8_t>(); |
| 54 | signal_strength_ = |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 55 | properties.find(WPASupplicant::kBSSPropertySignal)->second. |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 56 | reader().get_int16(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 57 | map<string, ::DBus::Variant>::const_iterator it = |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 58 | properties.find(WPASupplicant::kBSSPropertyFrequency); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 59 | if (it != properties.end()) |
| 60 | frequency_ = it->second.reader().get_uint16(); |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 61 | |
| 62 | Metrics::WiFiNetworkPhyMode phy_mode = Metrics::kWiFiNetworkPhyModeUndef; |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 63 | if (!ParseIEs(properties, &phy_mode, &vendor_information_, |
Paul Stewart | bdbd3c3 | 2013-04-17 09:47:21 -0700 | [diff] [blame] | 64 | &ieee80211w_required_, &country_code_)) { |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 65 | phy_mode = DeterminePhyModeFromFrequency(properties, frequency_); |
| 66 | } |
| 67 | physical_mode_ = phy_mode; |
| 68 | |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 69 | network_mode_ = ParseMode( |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 70 | properties.find(WPASupplicant::kBSSPropertyMode)->second); |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 71 | set_security_mode(ParseSecurity(properties, &security_flags_)); |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 72 | has_rsn_property_ = ContainsKey(properties, WPASupplicant::kPropertyRSN); |
| 73 | has_wpa_property_ = ContainsKey(properties, WPASupplicant::kPropertyWPA); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 74 | |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 75 | if (network_mode_.empty()) { |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 76 | // XXX log error? |
| 77 | } |
| 78 | |
| 79 | ssid_string_ = string(ssid_.begin(), ssid_.end()); |
mukesh agrawal | 16bc1b8 | 2012-02-09 18:38:26 -0800 | [diff] [blame] | 80 | WiFi::SanitizeSSID(&ssid_string_); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 81 | ssid_hex_ = base::HexEncode(&(*ssid_.begin()), ssid_.size()); |
Peter Qiu | 62abf31 | 2015-05-05 12:58:05 -0700 | [diff] [blame] | 82 | bssid_string_ = Device::MakeStringFromHardwareAddress(bssid_); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 83 | bssid_hex_ = base::HexEncode(&(*bssid_.begin()), bssid_.size()); |
Paul Stewart | fa11e28 | 2013-12-02 22:04:25 -0800 | [diff] [blame] | 84 | |
| 85 | CheckForTetheringSignature(); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | WiFiEndpoint::~WiFiEndpoint() {} |
| 89 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 90 | void WiFiEndpoint::Start() { |
| 91 | supplicant_bss_proxy_.reset( |
| 92 | proxy_factory_->CreateSupplicantBSSProxy( |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 93 | this, rpc_id_, WPASupplicant::kDBusAddr)); |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | void WiFiEndpoint::PropertiesChanged( |
| 97 | const map<string, ::DBus::Variant> &properties) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 98 | SLOG(this, 2) << __func__; |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 99 | bool should_notify = false; |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 100 | map<string, ::DBus::Variant>::const_iterator properties_it = |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 101 | properties.find(WPASupplicant::kBSSPropertySignal); |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 102 | if (properties_it != properties.end()) { |
| 103 | signal_strength_ = properties_it->second.reader().get_int16(); |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 104 | SLOG(this, 2) << "WiFiEndpoint " << bssid_string_ << " signal is now " |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 105 | << signal_strength_; |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 106 | should_notify = true; |
| 107 | } |
| 108 | |
| 109 | properties_it = properties.find(WPASupplicant::kBSSPropertyMode); |
| 110 | if (properties_it != properties.end()) { |
| 111 | string new_mode = ParseMode(properties_it->second); |
| 112 | if (new_mode != network_mode_) { |
| 113 | network_mode_ = new_mode; |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 114 | SLOG(this, 2) << "WiFiEndpoint " << bssid_string_ << " mode is now " |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 115 | << network_mode_; |
| 116 | should_notify = true; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | const char *new_security_mode = ParseSecurity(properties, &security_flags_); |
| 121 | if (new_security_mode != security_mode()) { |
| 122 | set_security_mode(new_security_mode); |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 123 | SLOG(this, 2) << "WiFiEndpoint " << bssid_string_ << " security is now " |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 124 | << security_mode(); |
| 125 | should_notify = true; |
| 126 | } |
| 127 | |
| 128 | if (should_notify) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 129 | device_->NotifyEndpointChanged(this); |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 133 | void WiFiEndpoint::UpdateSignalStrength(int16_t strength) { |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 134 | if (signal_strength_ == strength) { |
Paul Stewart | 7cd4572 | 2013-08-12 14:50:14 -0700 | [diff] [blame] | 135 | return; |
| 136 | } |
| 137 | |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 138 | SLOG(this, 2) << __func__ << ": signal strength " |
Paul Stewart | 7cd4572 | 2013-08-12 14:50:14 -0700 | [diff] [blame] | 139 | << signal_strength_ << " -> " << strength; |
| 140 | signal_strength_ = strength; |
| 141 | device_->NotifyEndpointChanged(this); |
| 142 | } |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 143 | |
| 144 | map<string, string> WiFiEndpoint::GetVendorInformation() const { |
| 145 | map<string, string> vendor_information; |
| 146 | if (!vendor_information_.wps_manufacturer.empty()) { |
| 147 | vendor_information[kVendorWPSManufacturerProperty] = |
| 148 | vendor_information_.wps_manufacturer; |
| 149 | } |
| 150 | if (!vendor_information_.wps_model_name.empty()) { |
| 151 | vendor_information[kVendorWPSModelNameProperty] = |
| 152 | vendor_information_.wps_model_name; |
| 153 | } |
| 154 | if (!vendor_information_.wps_model_number.empty()) { |
| 155 | vendor_information[kVendorWPSModelNumberProperty] = |
| 156 | vendor_information_.wps_model_number; |
| 157 | } |
| 158 | if (!vendor_information_.wps_device_name.empty()) { |
| 159 | vendor_information[kVendorWPSDeviceNameProperty] = |
| 160 | vendor_information_.wps_device_name; |
| 161 | } |
Paul Stewart | e2c1b9f | 2013-12-03 19:55:46 -0800 | [diff] [blame] | 162 | if (!vendor_information_.oui_set.empty()) { |
| 163 | vector<string> oui_vector; |
Paul Stewart | 6db7b24 | 2014-05-02 15:34:21 -0700 | [diff] [blame] | 164 | for (auto oui : vendor_information_.oui_set) { |
Paul Stewart | e2c1b9f | 2013-12-03 19:55:46 -0800 | [diff] [blame] | 165 | oui_vector.push_back( |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 166 | StringPrintf("%02x-%02x-%02x", |
Paul Stewart | 6db7b24 | 2014-05-02 15:34:21 -0700 | [diff] [blame] | 167 | oui >> 16, (oui >> 8) & 0xff, oui & 0xff)); |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 168 | } |
| 169 | vendor_information[kVendorOUIListProperty] = |
Paul Stewart | e2c1b9f | 2013-12-03 19:55:46 -0800 | [diff] [blame] | 170 | JoinString(oui_vector, ' '); |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 171 | } |
| 172 | return vendor_information; |
| 173 | } |
| 174 | |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 175 | // static |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 176 | uint32_t WiFiEndpoint::ModeStringToUint(const string &mode_string) { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 177 | if (mode_string == kModeManaged) |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 178 | return WPASupplicant::kNetworkModeInfrastructureInt; |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 179 | else if (mode_string == kModeAdhoc) |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 180 | return WPASupplicant::kNetworkModeAdHocInt; |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 181 | else |
| 182 | NOTIMPLEMENTED() << "Shill dos not support " << mode_string |
| 183 | << " mode at this time."; |
| 184 | return 0; |
| 185 | } |
| 186 | |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 187 | const vector<uint8_t> &WiFiEndpoint::ssid() const { |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 188 | return ssid_; |
| 189 | } |
| 190 | |
| 191 | const string &WiFiEndpoint::ssid_string() const { |
| 192 | return ssid_string_; |
| 193 | } |
| 194 | |
| 195 | const string &WiFiEndpoint::ssid_hex() const { |
| 196 | return ssid_hex_; |
| 197 | } |
| 198 | |
| 199 | const string &WiFiEndpoint::bssid_string() const { |
| 200 | return bssid_string_; |
| 201 | } |
| 202 | |
| 203 | const string &WiFiEndpoint::bssid_hex() const { |
| 204 | return bssid_hex_; |
| 205 | } |
| 206 | |
Paul Stewart | bdbd3c3 | 2013-04-17 09:47:21 -0700 | [diff] [blame] | 207 | const string &WiFiEndpoint::country_code() const { |
| 208 | return country_code_; |
| 209 | } |
| 210 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 211 | const WiFiRefPtr &WiFiEndpoint::device() const { |
| 212 | return device_; |
| 213 | } |
| 214 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 215 | int16_t WiFiEndpoint::signal_strength() const { |
| 216 | return signal_strength_; |
| 217 | } |
| 218 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 219 | uint16_t WiFiEndpoint::frequency() const { |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 220 | return frequency_; |
| 221 | } |
| 222 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 223 | uint16_t WiFiEndpoint::physical_mode() const { |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame] | 224 | return physical_mode_; |
| 225 | } |
| 226 | |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 227 | const string &WiFiEndpoint::network_mode() const { |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 228 | return network_mode_; |
| 229 | } |
| 230 | |
| 231 | const string &WiFiEndpoint::security_mode() const { |
| 232 | return security_mode_; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 235 | bool WiFiEndpoint::ieee80211w_required() const { |
| 236 | return ieee80211w_required_; |
| 237 | } |
| 238 | |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 239 | bool WiFiEndpoint::has_rsn_property() const { |
| 240 | return has_rsn_property_; |
| 241 | } |
| 242 | |
| 243 | bool WiFiEndpoint::has_wpa_property() const { |
| 244 | return has_wpa_property_; |
| 245 | } |
| 246 | |
Paul Stewart | fa11e28 | 2013-12-02 22:04:25 -0800 | [diff] [blame] | 247 | bool WiFiEndpoint::has_tethering_signature() const { |
| 248 | return has_tethering_signature_; |
| 249 | } |
| 250 | |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 251 | // static |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 252 | WiFiEndpoint *WiFiEndpoint::MakeOpenEndpoint(ProxyFactory *proxy_factory, |
| 253 | const WiFiRefPtr &wifi, |
| 254 | const string &ssid, |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 255 | const string &bssid, |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 256 | const string &network_mode, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 257 | uint16_t frequency, |
| 258 | int16_t signal_dbm) { |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 259 | return MakeEndpoint(proxy_factory, wifi, ssid, bssid, network_mode, |
| 260 | frequency, signal_dbm, false, false); |
| 261 | } |
| 262 | |
Paul Stewart | c67f0bd | 2013-12-06 12:14:50 -0800 | [diff] [blame] | 263 | |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 264 | // static |
| 265 | WiFiEndpoint *WiFiEndpoint::MakeEndpoint(ProxyFactory *proxy_factory, |
| 266 | const WiFiRefPtr &wifi, |
| 267 | const string &ssid, |
| 268 | const string &bssid, |
| 269 | const string &network_mode, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 270 | uint16_t frequency, |
| 271 | int16_t signal_dbm, |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 272 | bool has_wpa_property, |
| 273 | bool has_rsn_property) { |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 274 | map <string, ::DBus::Variant> args; |
| 275 | ::DBus::MessageIter writer; |
| 276 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 277 | writer = args[WPASupplicant::kBSSPropertySSID].writer(); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 278 | writer << vector<uint8_t>(ssid.begin(), ssid.end()); |
| 279 | |
Peter Qiu | 62abf31 | 2015-05-05 12:58:05 -0700 | [diff] [blame] | 280 | vector<uint8_t> bssid_bytes = |
| 281 | Device::MakeHardwareAddressFromString(bssid); |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 282 | writer = args[WPASupplicant::kBSSPropertyBSSID].writer(); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 283 | writer << bssid_bytes; |
| 284 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 285 | args[WPASupplicant::kBSSPropertySignal].writer().append_int16(signal_dbm); |
| 286 | args[WPASupplicant::kBSSPropertyFrequency].writer().append_uint16(frequency); |
| 287 | args[WPASupplicant::kBSSPropertyMode].writer().append_string( |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 288 | network_mode.c_str()); |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 289 | |
| 290 | if (has_wpa_property) { |
| 291 | ::DBus::MessageIter writer; // local is required; see HACKING |
| 292 | map <string, string> empty_dict; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 293 | writer = args[WPASupplicant::kPropertyWPA].writer(); |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 294 | writer << empty_dict; |
| 295 | } |
| 296 | if (has_rsn_property) { |
| 297 | ::DBus::MessageIter writer; // local is required; see HACKING |
| 298 | map <string, string> empty_dict; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 299 | writer = args[WPASupplicant::kPropertyRSN].writer(); |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 300 | writer << empty_dict; |
| 301 | } |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 302 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 303 | return new WiFiEndpoint( |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 304 | proxy_factory, wifi, bssid, args); // |bssid| fakes an RPC ID |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | // static |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 308 | const char *WiFiEndpoint::ParseMode(const string &mode_string) { |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 309 | if (mode_string == WPASupplicant::kNetworkModeInfrastructure) { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 310 | return kModeManaged; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 311 | } else if (mode_string == WPASupplicant::kNetworkModeAdHoc) { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 312 | return kModeAdhoc; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 313 | } else if (mode_string == WPASupplicant::kNetworkModeAccessPoint) { |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 314 | NOTREACHED() << "Shill does not support AP mode at this time."; |
Ben Chan | 0afd90f | 2014-09-30 13:34:45 -0700 | [diff] [blame] | 315 | return nullptr; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 316 | } else { |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 317 | NOTREACHED() << "Unknown WiFi endpoint mode!"; |
Ben Chan | 0afd90f | 2014-09-30 13:34:45 -0700 | [diff] [blame] | 318 | return nullptr; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 322 | // static |
| 323 | const char *WiFiEndpoint::ParseSecurity( |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 324 | const map<string, ::DBus::Variant> &properties, SecurityFlags *flags) { |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 325 | if (ContainsKey(properties, WPASupplicant::kPropertyRSN)) { |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 326 | // TODO(quiche): check type before casting |
| 327 | const map<string, ::DBus::Variant> rsn_properties( |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 328 | properties.find(WPASupplicant::kPropertyRSN)->second. |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 329 | operator map<string, ::DBus::Variant>()); |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 330 | set<KeyManagement> key_management; |
| 331 | ParseKeyManagementMethods(rsn_properties, &key_management); |
| 332 | flags->rsn_8021x = ContainsKey(key_management, kKeyManagement802_1x); |
| 333 | flags->rsn_psk = ContainsKey(key_management, kKeyManagementPSK); |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 336 | if (ContainsKey(properties, WPASupplicant::kPropertyWPA)) { |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 337 | // TODO(quiche): check type before casting |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 338 | const map<string, ::DBus::Variant> rsn_properties( |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 339 | properties.find(WPASupplicant::kPropertyWPA)->second. |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 340 | operator map<string, ::DBus::Variant>()); |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 341 | set<KeyManagement> key_management; |
| 342 | ParseKeyManagementMethods(rsn_properties, &key_management); |
| 343 | flags->wpa_8021x = ContainsKey(key_management, kKeyManagement802_1x); |
| 344 | flags->wpa_psk = ContainsKey(key_management, kKeyManagementPSK); |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 347 | if (ContainsKey(properties, WPASupplicant::kPropertyPrivacy)) { |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 348 | flags->privacy = properties.find(WPASupplicant::kPropertyPrivacy)->second. |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 349 | reader().get_bool(); |
| 350 | } |
| 351 | |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 352 | if (flags->rsn_8021x || flags->wpa_8021x) { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 353 | return kSecurity8021x; |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 354 | } else if (flags->rsn_psk) { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 355 | return kSecurityRsn; |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 356 | } else if (flags->wpa_psk) { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 357 | return kSecurityWpa; |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 358 | } else if (flags->privacy) { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 359 | return kSecurityWep; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 360 | } else { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 361 | return kSecurityNone; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
| 365 | // static |
| 366 | void WiFiEndpoint::ParseKeyManagementMethods( |
| 367 | const map<string, ::DBus::Variant> &security_method_properties, |
| 368 | set<KeyManagement> *key_management_methods) { |
| 369 | if (!ContainsKey(security_method_properties, |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 370 | WPASupplicant::kSecurityMethodPropertyKeyManagement)) { |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 371 | return; |
| 372 | } |
| 373 | |
| 374 | // TODO(quiche): check type before cast |
| 375 | const vector<string> key_management_vec = |
| 376 | security_method_properties. |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 377 | find(WPASupplicant::kSecurityMethodPropertyKeyManagement)->second. |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 378 | operator vector<string>(); |
Paul Stewart | 6db7b24 | 2014-05-02 15:34:21 -0700 | [diff] [blame] | 379 | for (const auto &method : key_management_vec) { |
Alex Vakulenko | ccab3f9 | 2015-06-15 12:53:22 -0700 | [diff] [blame] | 380 | if (base::EndsWith(method, WPASupplicant::kKeyManagementMethodSuffixEAP, |
| 381 | true)) { |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 382 | key_management_methods->insert(kKeyManagement802_1x); |
Alex Vakulenko | ccab3f9 | 2015-06-15 12:53:22 -0700 | [diff] [blame] | 383 | } else if (base::EndsWith(method, |
| 384 | WPASupplicant::kKeyManagementMethodSuffixPSK, |
| 385 | true)) { |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 386 | key_management_methods->insert(kKeyManagementPSK); |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame] | 391 | // static |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 392 | Metrics::WiFiNetworkPhyMode WiFiEndpoint::DeterminePhyModeFromFrequency( |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 393 | const map<string, ::DBus::Variant> &properties, uint16_t frequency) { |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame] | 394 | uint32_t max_rate = 0; |
| 395 | map<string, ::DBus::Variant>::const_iterator it = |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 396 | properties.find(WPASupplicant::kBSSPropertyRates); |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame] | 397 | if (it != properties.end()) { |
| 398 | vector<uint32_t> rates = it->second.operator vector<uint32_t>(); |
| 399 | if (rates.size() > 0) |
| 400 | max_rate = rates[0]; // Rates are sorted in descending order |
| 401 | } |
| 402 | |
| 403 | Metrics::WiFiNetworkPhyMode phy_mode = Metrics::kWiFiNetworkPhyModeUndef; |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame] | 404 | if (frequency < 3000) { |
| 405 | // 2.4GHz legacy, check for tx rate for 11b-only |
| 406 | // (note 22M is valid) |
| 407 | if (max_rate < 24000000) |
| 408 | phy_mode = Metrics::kWiFiNetworkPhyMode11b; |
| 409 | else |
| 410 | phy_mode = Metrics::kWiFiNetworkPhyMode11g; |
| 411 | } else { |
| 412 | phy_mode = Metrics::kWiFiNetworkPhyMode11a; |
| 413 | } |
| 414 | |
| 415 | return phy_mode; |
| 416 | } |
| 417 | |
| 418 | // static |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 419 | bool WiFiEndpoint::ParseIEs( |
| 420 | const map<string, ::DBus::Variant> &properties, |
| 421 | Metrics::WiFiNetworkPhyMode *phy_mode, |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 422 | VendorInformation *vendor_information, |
Paul Stewart | bdbd3c3 | 2013-04-17 09:47:21 -0700 | [diff] [blame] | 423 | bool *ieee80211w_required, string *country_code) { |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 424 | |
| 425 | map<string, ::DBus::Variant>::const_iterator ies_property = |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 426 | properties.find(WPASupplicant::kBSSPropertyIEs); |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 427 | if (ies_property == properties.end()) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 428 | SLOG(nullptr, 2) << __func__ << ": No IE property in BSS."; |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 429 | return false; |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame] | 430 | } |
| 431 | |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 432 | vector<uint8_t> ies = ies_property->second.operator vector<uint8_t>(); |
| 433 | |
| 434 | |
| 435 | // Format of an information element: |
| 436 | // 1 1 1 - 252 |
| 437 | // +------+--------+----------------+ |
| 438 | // | Type | Length | Data | |
| 439 | // +------+--------+----------------+ |
| 440 | *phy_mode = Metrics::kWiFiNetworkPhyModeUndef; |
| 441 | bool found_ht = false; |
| 442 | bool found_erp = false; |
| 443 | int ie_len = 0; |
| 444 | vector<uint8_t>::iterator it; |
| 445 | for (it = ies.begin(); |
| 446 | std::distance(it, ies.end()) > 1; // Ensure Length field is within PDU. |
| 447 | it += ie_len) { |
| 448 | ie_len = 2 + *(it + 1); |
| 449 | if (std::distance(it, ies.end()) < ie_len) { |
| 450 | LOG(ERROR) << __func__ << ": IE extends past containing PDU."; |
| 451 | break; |
| 452 | } |
| 453 | switch (*it) { |
Paul Stewart | bdbd3c3 | 2013-04-17 09:47:21 -0700 | [diff] [blame] | 454 | case IEEE_80211::kElemIdCountry: |
| 455 | // Retrieve 2-character country code from the beginning of the element. |
| 456 | if (ie_len >= 4) { |
| 457 | *country_code = string(it + 2, it + 4); |
| 458 | } |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 459 | case IEEE_80211::kElemIdErp: |
| 460 | if (!found_ht) { |
| 461 | *phy_mode = Metrics::kWiFiNetworkPhyMode11g; |
| 462 | } |
| 463 | found_erp = true; |
| 464 | break; |
| 465 | case IEEE_80211::kElemIdHTCap: |
| 466 | case IEEE_80211::kElemIdHTInfo: |
| 467 | *phy_mode = Metrics::kWiFiNetworkPhyMode11n; |
| 468 | found_ht = true; |
| 469 | break; |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 470 | case IEEE_80211::kElemIdRSN: |
| 471 | ParseWPACapabilities(it + 2, it + ie_len, ieee80211w_required); |
| 472 | break; |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 473 | case IEEE_80211::kElemIdVendor: |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 474 | ParseVendorIE(it + 2, it + ie_len, vendor_information, |
| 475 | ieee80211w_required); |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 476 | break; |
| 477 | } |
| 478 | } |
| 479 | return found_ht || found_erp; |
| 480 | } |
| 481 | |
| 482 | // static |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 483 | void WiFiEndpoint::ParseWPACapabilities( |
| 484 | vector<uint8_t>::const_iterator ie, |
| 485 | vector<uint8_t>::const_iterator end, |
| 486 | bool *ieee80211w_required) { |
| 487 | // Format of an RSN Information Element: |
| 488 | // 2 4 |
| 489 | // +------+--------------------+ |
| 490 | // | Type | Group Cipher Suite | |
| 491 | // +------+--------------------+ |
| 492 | // 2 4 * pairwise count |
| 493 | // +-----------------------+---------------------+ |
| 494 | // | Pairwise Cipher Count | Pairwise Ciphers... | |
| 495 | // +-----------------------+---------------------+ |
| 496 | // 2 4 * authkey count |
| 497 | // +-----------------------+---------------------+ |
| 498 | // | AuthKey Suite Count | AuthKey Suites... | |
| 499 | // +-----------------------+---------------------+ |
| 500 | // 2 |
| 501 | // +------------------+ |
| 502 | // | RSN Capabilities | |
| 503 | // +------------------+ |
| 504 | // 2 16 * pmkid count |
| 505 | // +------------------+-------------------+ |
| 506 | // | PMKID Count | PMKIDs... | |
| 507 | // +------------------+-------------------+ |
| 508 | // 4 |
| 509 | // +-------------------------------+ |
| 510 | // | Group Management Cipher Suite | |
| 511 | // +-------------------------------+ |
| 512 | if (std::distance(ie, end) < IEEE_80211::kRSNIECipherCountOffset) { |
| 513 | return; |
| 514 | } |
| 515 | ie += IEEE_80211::kRSNIECipherCountOffset; |
| 516 | |
| 517 | // Advance past the pairwise and authkey ciphers. Each is a little-endian |
| 518 | // cipher count followed by n * cipher_selector. |
| 519 | for (int i = 0; i < IEEE_80211::kRSNIENumCiphers; ++i) { |
| 520 | // Retrieve a little-endian cipher count. |
| 521 | if (std::distance(ie, end) < IEEE_80211::kRSNIECipherCountLen) { |
| 522 | return; |
| 523 | } |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 524 | uint16_t cipher_count = *ie | (*(ie + 1) << 8); |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 525 | |
| 526 | // Skip over the cipher selectors. |
| 527 | int skip_length = IEEE_80211::kRSNIECipherCountLen + |
| 528 | cipher_count * IEEE_80211::kRSNIESelectorLen; |
| 529 | if (std::distance(ie, end) < skip_length) { |
| 530 | return; |
| 531 | } |
| 532 | ie += skip_length; |
| 533 | } |
| 534 | |
| 535 | if (std::distance(ie, end) < IEEE_80211::kRSNIECapabilitiesLen) { |
| 536 | return; |
| 537 | } |
| 538 | |
| 539 | // Retrieve a little-endian capabilities bitfield. |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 540 | uint16_t capabilities = *ie | (*(ie + 1) << 8); |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 541 | |
| 542 | if (capabilities & IEEE_80211::kRSNCapabilityFrameProtectionRequired && |
| 543 | ieee80211w_required) { |
| 544 | // Never set this value to false, since there may be multiple RSN |
| 545 | // information elements. |
| 546 | *ieee80211w_required = true; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | |
| 551 | // static |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 552 | void WiFiEndpoint::ParseVendorIE(vector<uint8_t>::const_iterator ie, |
| 553 | vector<uint8_t>::const_iterator end, |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 554 | VendorInformation *vendor_information, |
| 555 | bool *ieee80211w_required) { |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 556 | // Format of an vendor-specific information element (with type |
| 557 | // and length field for the IE removed by the caller): |
| 558 | // 3 1 1 - 248 |
| 559 | // +------------+----------+----------------+ |
| 560 | // | OUI | OUI Type | Data | |
| 561 | // +------------+----------+----------------+ |
| 562 | |
| 563 | if (std::distance(ie, end) < 4) { |
| 564 | LOG(ERROR) << __func__ << ": no room in IE for OUI and type field."; |
| 565 | return; |
| 566 | } |
| 567 | uint32_t oui = (*ie << 16) | (*(ie + 1) << 8) | *(ie + 2); |
| 568 | uint8_t oui_type = *(ie + 3); |
| 569 | ie += 4; |
| 570 | |
| 571 | if (oui == IEEE_80211::kOUIVendorMicrosoft && |
| 572 | oui_type == IEEE_80211::kOUIMicrosoftWPS) { |
| 573 | // Format of a WPS data element: |
| 574 | // 2 2 |
| 575 | // +------+--------+----------------+ |
| 576 | // | Type | Length | Data | |
| 577 | // +------+--------+----------------+ |
| 578 | while (std::distance(ie, end) >= 4) { |
| 579 | int element_type = (*ie << 8) | *(ie + 1); |
| 580 | int element_length = (*(ie + 2) << 8) | *(ie + 3); |
| 581 | ie += 4; |
| 582 | if (std::distance(ie, end) < element_length) { |
| 583 | LOG(ERROR) << __func__ << ": WPS element extends past containing PDU."; |
| 584 | break; |
| 585 | } |
| 586 | string s(ie, ie + element_length); |
Ben Chan | 6fbf64f | 2014-05-21 18:07:01 -0700 | [diff] [blame] | 587 | if (base::IsStringASCII(s)) { |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 588 | switch (element_type) { |
| 589 | case IEEE_80211::kWPSElementManufacturer: |
| 590 | vendor_information->wps_manufacturer = s; |
| 591 | break; |
| 592 | case IEEE_80211::kWPSElementModelName: |
| 593 | vendor_information->wps_model_name = s; |
| 594 | break; |
| 595 | case IEEE_80211::kWPSElementModelNumber: |
| 596 | vendor_information->wps_model_number = s; |
| 597 | break; |
| 598 | case IEEE_80211::kWPSElementDeviceName: |
| 599 | vendor_information->wps_device_name = s; |
| 600 | break; |
| 601 | } |
| 602 | } |
| 603 | ie += element_length; |
| 604 | } |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 605 | } else if (oui == IEEE_80211::kOUIVendorMicrosoft && |
| 606 | oui_type == IEEE_80211::kOUIMicrosoftWPA) { |
| 607 | ParseWPACapabilities(ie, end, ieee80211w_required); |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 608 | } else if (oui != IEEE_80211::kOUIVendorEpigram && |
| 609 | oui != IEEE_80211::kOUIVendorMicrosoft) { |
Paul Stewart | e2c1b9f | 2013-12-03 19:55:46 -0800 | [diff] [blame] | 610 | vendor_information->oui_set.insert(oui); |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 611 | } |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame] | 612 | } |
| 613 | |
Paul Stewart | fa11e28 | 2013-12-02 22:04:25 -0800 | [diff] [blame] | 614 | void WiFiEndpoint::CheckForTetheringSignature() { |
| 615 | has_tethering_signature_ = |
| 616 | Tethering::IsAndroidBSSID(bssid_) || |
| 617 | (Tethering::IsLocallyAdministeredBSSID(bssid_) && |
| 618 | Tethering::HasIosOui(vendor_information_.oui_set)); |
| 619 | } |
| 620 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 621 | } // namespace shill |