| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 The Chromium 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 "chromeos/network/wifi_access_point_info_provider_chromeos.h" |
| 6 |
| 7 #include "chromeos/network/device_state.h" |
| 8 #include "chromeos/network/network_configuration_handler.h" |
| 9 #include "chromeos/network/network_handler.h" |
| 10 #include "chromeos/network/network_state.h" |
| 11 #include "chromeos/network/network_state_handler.h" |
| 12 #include "chromeos/network/shill_property_util.h" |
| 13 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 14 |
| 15 namespace chromeos { |
| 16 |
| 17 WifiAccessPointInfoProviderChromeos::WifiAccessPointInfoProviderChromeos() { |
| 18 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); |
| 19 |
| 20 // Update initial connection state. |
| 21 DefaultNetworkChanged( |
| 22 NetworkHandler::Get()->network_state_handler()->DefaultNetwork()); |
| 23 } |
| 24 |
| 25 WifiAccessPointInfoProviderChromeos::~WifiAccessPointInfoProviderChromeos() { |
| 26 } |
| 27 |
| 28 bool WifiAccessPointInfoProviderChromeos::GetInfo( |
| 29 net::WifiAccessPointInfo* info) { |
| 30 // Wifi access point information is not provided if the BSSID is empty. |
| 31 // This assumes the BSSID is never empty when access point information exists. |
| 32 if (wifi_access_point_info_.bssid.empty()) |
| 33 return false; |
| 34 |
| 35 *info = wifi_access_point_info_; |
| 36 return true; |
| 37 } |
| 38 |
| 39 void WifiAccessPointInfoProviderChromeos::DefaultNetworkChanged( |
| 40 const chromeos::NetworkState* default_network) { |
| 41 // Reset access point info to prevent reporting of out-dated data. |
| 42 wifi_access_point_info_ = net::WifiAccessPointInfo(); |
| 43 |
| 44 if (!default_network) |
| 45 return; |
| 46 |
| 47 // Retrieve access point info for wifi connection. |
| 48 if (default_network->type() == shill::kTypeWifi) { |
| 49 NetworkHandler::Get()->network_configuration_handler()->GetProperties( |
| 50 default_network->path(), |
| 51 base::Bind(&WifiAccessPointInfoProviderChromeos::ParseInfo, |
| 52 AsWeakPtr()), |
| 53 network_handler::ErrorCallback()); |
| 54 } |
| 55 } |
| 56 |
| 57 void WifiAccessPointInfoProviderChromeos::ParseInfo( |
| 58 const std::string &service_path, |
| 59 const base::DictionaryValue& properties) { |
| 60 // Skip services that contain "_nomap" in the SSID. |
| 61 std::string ssid = shill_property_util::GetSSIDFromProperties( |
| 62 properties, NULL); |
| 63 if (ssid.find("_nomap", 0) != std::string::npos) |
| 64 return; |
| 65 |
| 66 // Parse security info. |
| 67 std::string security; |
| 68 properties.GetStringWithoutPathExpansion( |
| 69 shill::kSecurityProperty, &security); |
| 70 wifi_access_point_info_.security = net::WIFI_SECURITY_UNKNOWN; |
| 71 if (security == shill::kSecurityWpa) |
| 72 wifi_access_point_info_.security = net::WIFI_SECURITY_WPA; |
| 73 else if (security == shill::kSecurityWep) |
| 74 wifi_access_point_info_.security = net::WIFI_SECURITY_WEP; |
| 75 else if (security == shill::kSecurityRsn) |
| 76 wifi_access_point_info_.security = net::WIFI_SECURITY_RSN; |
| 77 else if (security == shill::kSecurity8021x) |
| 78 wifi_access_point_info_.security = net::WIFI_SECURITY_802_1X; |
| 79 else if (security == shill::kSecurityPsk) |
| 80 wifi_access_point_info_.security = net::WIFI_SECURITY_PSK; |
| 81 else if (security == shill::kSecurityNone) |
| 82 wifi_access_point_info_.security = net::WIFI_SECURITY_NONE; |
| 83 |
| 84 properties.GetStringWithoutPathExpansion( |
| 85 shill::kWifiBSsid, &wifi_access_point_info_.bssid); |
| 86 const base::DictionaryValue* vendor_dict = NULL; |
| 87 |
| 88 if (!properties.GetDictionaryWithoutPathExpansion( |
| 89 shill::kWifiVendorInformationProperty, |
| 90 &vendor_dict)) |
| 91 return; |
| 92 |
| 93 vendor_dict->GetStringWithoutPathExpansion( |
| 94 shill::kVendorWPSModelNumberProperty, |
| 95 &wifi_access_point_info_.model_number); |
| 96 vendor_dict->GetStringWithoutPathExpansion( |
| 97 shill::kVendorWPSModelNameProperty, |
| 98 &wifi_access_point_info_.model_name); |
| 99 vendor_dict->GetStringWithoutPathExpansion( |
| 100 shill::kVendorWPSDeviceNameProperty, |
| 101 &wifi_access_point_info_.device_name); |
| 102 vendor_dict->GetStringWithoutPathExpansion(shill::kVendorOUIListProperty, |
| 103 &wifi_access_point_info_.oui_list); |
| 104 } |
| 105 |
| 106 } // namespace chromeos |
| 107 |
| 108 // static |
| 109 scoped_ptr<net::WifiAccessPointInfoProvider> |
| 110 net::WifiAccessPointInfoProvider::Create() { |
| 111 return scoped_ptr<net::WifiAccessPointInfoProvider>( |
| 112 new chromeos::WifiAccessPointInfoProviderChromeos()); |
| 113 } |
| OLD | NEW |