| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/wifi/wifi_service.h" | 5 #include "components/wifi/wifi_service.h" |
| 6 | 6 |
| 7 #include <iphlpapi.h> | 7 #include <iphlpapi.h> |
| 8 #include <objbase.h> | 8 #include <objbase.h> |
| 9 #include <wlanapi.h> | 9 #include <wlanapi.h> |
| 10 | 10 |
| 11 #include <set> | 11 #include <set> |
| 12 | 12 |
| 13 #include "base/base_paths_win.h" | 13 #include "base/base_paths_win.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/win/registry.h" | 22 #include "base/win/registry.h" |
| 23 #include "components/onc/onc_constants.h" | 23 #include "components/onc/onc_constants.h" |
| 24 #include "components/wifi/network_properties.h" |
| 24 #include "third_party/libxml/chromium/libxml_utils.h" | 25 #include "third_party/libxml/chromium/libxml_utils.h" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 const wchar_t kNwCategoryWizardRegKey[] = | 28 const wchar_t kNwCategoryWizardRegKey[] = |
| 28 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Network\\" | 29 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Network\\" |
| 29 L"NwCategoryWizard"; | 30 L"NwCategoryWizard"; |
| 30 const wchar_t kNwCategoryWizardRegValue[] = L"Show"; | 31 const wchar_t kNwCategoryWizardRegValue[] = L"Show"; |
| 31 const wchar_t kNwCategoryWizardSavedRegValue[] = L"ShowSaved"; | 32 const wchar_t kNwCategoryWizardSavedRegValue[] = L"ShowSaved"; |
| 32 const wchar_t kNwCategoryWizardDeleteRegValue[] = L"ShowDelete"; | 33 const wchar_t kNwCategoryWizardDeleteRegValue[] = L"ShowDelete"; |
| 33 const wchar_t kWlanApiDll[] = L"wlanapi.dll"; | 34 const wchar_t kWlanApiDll[] = L"wlanapi.dll"; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 virtual void SetProperties(const std::string& network_guid, | 197 virtual void SetProperties(const std::string& network_guid, |
| 197 scoped_ptr<base::DictionaryValue> properties, | 198 scoped_ptr<base::DictionaryValue> properties, |
| 198 std::string* error) OVERRIDE; | 199 std::string* error) OVERRIDE; |
| 199 | 200 |
| 200 virtual void CreateNetwork(bool shared, | 201 virtual void CreateNetwork(bool shared, |
| 201 scoped_ptr<base::DictionaryValue> properties, | 202 scoped_ptr<base::DictionaryValue> properties, |
| 202 std::string* network_guid, | 203 std::string* network_guid, |
| 203 std::string* error) OVERRIDE; | 204 std::string* error) OVERRIDE; |
| 204 | 205 |
| 205 virtual void GetVisibleNetworks(const std::string& network_type, | 206 virtual void GetVisibleNetworks(const std::string& network_type, |
| 206 base::ListValue* network_list) OVERRIDE; | 207 base::ListValue* network_list, |
| 208 bool include_details) OVERRIDE; |
| 207 | 209 |
| 208 virtual void RequestNetworkScan() OVERRIDE; | 210 virtual void RequestNetworkScan() OVERRIDE; |
| 209 | 211 |
| 210 virtual void StartConnect(const std::string& network_guid, | 212 virtual void StartConnect(const std::string& network_guid, |
| 211 std::string* error) OVERRIDE; | 213 std::string* error) OVERRIDE; |
| 212 | 214 |
| 213 virtual void StartDisconnect(const std::string& network_guid, | 215 virtual void StartDisconnect(const std::string& network_guid, |
| 214 std::string* error) OVERRIDE; | 216 std::string* error) OVERRIDE; |
| 215 | 217 |
| 216 virtual void GetKeyFromSystem(const std::string& network_guid, | 218 virtual void GetKeyFromSystem(const std::string& network_guid, |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 | 576 |
| 575 void WiFiServiceImpl::CreateNetwork( | 577 void WiFiServiceImpl::CreateNetwork( |
| 576 bool shared, | 578 bool shared, |
| 577 scoped_ptr<base::DictionaryValue> properties, | 579 scoped_ptr<base::DictionaryValue> properties, |
| 578 std::string* network_guid, | 580 std::string* network_guid, |
| 579 std::string* error) { | 581 std::string* error) { |
| 580 DWORD error_code = EnsureInitialized(); | 582 DWORD error_code = EnsureInitialized(); |
| 581 if (CheckError(error_code, kErrorWiFiService, error)) | 583 if (CheckError(error_code, kErrorWiFiService, error)) |
| 582 return; | 584 return; |
| 583 | 585 |
| 584 WiFiService::NetworkProperties network_properties; | 586 NetworkProperties network_properties; |
| 585 if (!network_properties.UpdateFromValue(*properties)) { | 587 if (!network_properties.UpdateFromValue(*properties)) { |
| 586 CheckError(ERROR_INVALID_DATA, kErrorWiFiService, error); | 588 CheckError(ERROR_INVALID_DATA, kErrorWiFiService, error); |
| 587 return; | 589 return; |
| 588 } | 590 } |
| 589 | 591 |
| 590 network_properties.guid = network_properties.ssid; | 592 network_properties.guid = network_properties.ssid; |
| 591 std::string profile_xml; | 593 std::string profile_xml; |
| 592 if (!CreateProfile(network_properties, kEncryptionTypeAny, &profile_xml)) { | 594 if (!CreateProfile(network_properties, kEncryptionTypeAny, &profile_xml)) { |
| 593 CheckError(ERROR_INVALID_DATA, kErrorWiFiService, error); | 595 CheckError(ERROR_INVALID_DATA, kErrorWiFiService, error); |
| 594 return; | 596 return; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 616 tkip_profile->SetString(kProfileXmlKey, tkip_profile_xml); | 618 tkip_profile->SetString(kProfileXmlKey, tkip_profile_xml); |
| 617 tkip_profile->SetBoolean(kProfileSharedKey, shared); | 619 tkip_profile->SetBoolean(kProfileSharedKey, shared); |
| 618 created_profiles_.SetWithoutPathExpansion(network_properties.guid, | 620 created_profiles_.SetWithoutPathExpansion(network_properties.guid, |
| 619 tkip_profile.release()); | 621 tkip_profile.release()); |
| 620 } | 622 } |
| 621 | 623 |
| 622 *network_guid = network_properties.guid; | 624 *network_guid = network_properties.guid; |
| 623 } | 625 } |
| 624 | 626 |
| 625 void WiFiServiceImpl::GetVisibleNetworks(const std::string& network_type, | 627 void WiFiServiceImpl::GetVisibleNetworks(const std::string& network_type, |
| 626 base::ListValue* network_list) { | 628 base::ListValue* network_list, |
| 629 bool include_details) { |
| 627 if (!network_type.empty() && | 630 if (!network_type.empty() && |
| 628 network_type != onc::network_type::kAllTypes && | 631 network_type != onc::network_type::kAllTypes && |
| 629 network_type != onc::network_type::kWiFi) { | 632 network_type != onc::network_type::kWiFi) { |
| 630 return; | 633 return; |
| 631 } | 634 } |
| 632 | 635 |
| 633 DWORD error = EnsureInitialized(); | 636 DWORD error = EnsureInitialized(); |
| 634 if (error == ERROR_SUCCESS) { | 637 if (error == ERROR_SUCCESS) { |
| 635 NetworkList networks; | 638 NetworkList networks; |
| 636 error = GetVisibleNetworkList(&networks); | 639 error = GetVisibleNetworkList(&networks); |
| 637 if (error == ERROR_SUCCESS && !networks.empty()) { | 640 if (error == ERROR_SUCCESS && !networks.empty()) { |
| 638 SortNetworks(&networks); | 641 SortNetworks(&networks); |
| 639 for (WiFiService::NetworkList::const_iterator it = networks.begin(); | 642 for (NetworkList::const_iterator it = networks.begin(); |
| 640 it != networks.end(); | 643 it != networks.end(); |
| 641 ++it) { | 644 ++it) { |
| 642 scoped_ptr<base::DictionaryValue> network(it->ToValue(true)); | 645 scoped_ptr<base::DictionaryValue> network( |
| 646 it->ToValue(!include_details)); |
| 643 network_list->Append(network.release()); | 647 network_list->Append(network.release()); |
| 644 } | 648 } |
| 645 } | 649 } |
| 646 } | 650 } |
| 647 } | 651 } |
| 648 | 652 |
| 649 void WiFiServiceImpl::RequestNetworkScan() { | 653 void WiFiServiceImpl::RequestNetworkScan() { |
| 650 DWORD error = EnsureInitialized(); | 654 DWORD error = EnsureInitialized(); |
| 651 if (error == ERROR_SUCCESS) { | 655 if (error == ERROR_SUCCESS) { |
| 652 WlanScan_function_(client_, &interface_guid_, NULL, NULL, NULL); | 656 WlanScan_function_(client_, &interface_guid_, NULL, NULL, NULL); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 const std::string& error_name, | 933 const std::string& error_name, |
| 930 std::string* error) const { | 934 std::string* error) const { |
| 931 if (error_code != ERROR_SUCCESS) { | 935 if (error_code != ERROR_SUCCESS) { |
| 932 DLOG(ERROR) << "WiFiService Error " << error_code << ": " << error_name; | 936 DLOG(ERROR) << "WiFiService Error " << error_code << ": " << error_name; |
| 933 *error = error_name; | 937 *error = error_name; |
| 934 return true; | 938 return true; |
| 935 } | 939 } |
| 936 return false; | 940 return false; |
| 937 } | 941 } |
| 938 | 942 |
| 939 WiFiService::NetworkList::iterator WiFiServiceImpl::FindNetwork( | 943 NetworkList::iterator WiFiServiceImpl::FindNetwork( |
| 940 NetworkList& networks, | 944 NetworkList& networks, |
| 941 const std::string& network_guid) { | 945 const std::string& network_guid) { |
| 942 for (NetworkList::iterator it = networks.begin(); it != networks.end(); | 946 for (NetworkList::iterator it = networks.begin(); it != networks.end(); |
| 943 ++it) { | 947 ++it) { |
| 944 if (it->guid == network_guid) | 948 if (it->guid == network_guid) |
| 945 return it; | 949 return it; |
| 946 } | 950 } |
| 947 return networks.end(); | 951 return networks.end(); |
| 948 } | 952 } |
| 949 | 953 |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1450 // Clean up. | 1454 // Clean up. |
| 1451 if (wlan_connection_attributes != NULL) | 1455 if (wlan_connection_attributes != NULL) |
| 1452 WlanFreeMemory_function_(wlan_connection_attributes); | 1456 WlanFreeMemory_function_(wlan_connection_attributes); |
| 1453 | 1457 |
| 1454 if (bss_list != NULL) | 1458 if (bss_list != NULL) |
| 1455 WlanFreeMemory_function_(bss_list); | 1459 WlanFreeMemory_function_(bss_list); |
| 1456 | 1460 |
| 1457 return error; | 1461 return error; |
| 1458 } | 1462 } |
| 1459 | 1463 |
| 1460 WiFiService::Frequency WiFiServiceImpl::GetFrequencyToConnect( | 1464 Frequency WiFiServiceImpl::GetFrequencyToConnect( |
| 1461 const std::string& network_guid) const { | 1465 const std::string& network_guid) const { |
| 1462 // Check whether desired frequency is set in |connect_properties_|. | 1466 // Check whether desired frequency is set in |connect_properties_|. |
| 1463 const base::DictionaryValue* properties; | 1467 const base::DictionaryValue* properties; |
| 1464 const base::DictionaryValue* wifi; | 1468 const base::DictionaryValue* wifi; |
| 1465 int frequency; | 1469 int frequency; |
| 1466 if (connect_properties_.GetDictionaryWithoutPathExpansion( | 1470 if (connect_properties_.GetDictionaryWithoutPathExpansion( |
| 1467 network_guid, &properties) && | 1471 network_guid, &properties) && |
| 1468 properties->GetDictionary(onc::network_type::kWiFi, &wifi) && | 1472 properties->GetDictionary(onc::network_type::kWiFi, &wifi) && |
| 1469 wifi->GetInteger(onc::wifi::kFrequency, &frequency)) { | 1473 wifi->GetInteger(onc::wifi::kFrequency, &frequency)) { |
| 1470 return GetNormalizedFrequency(frequency); | 1474 return GetNormalizedFrequency(frequency); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1546 } | 1550 } |
| 1547 } | 1551 } |
| 1548 | 1552 |
| 1549 // Clean up. | 1553 // Clean up. |
| 1550 if (bss_list != NULL) { | 1554 if (bss_list != NULL) { |
| 1551 WlanFreeMemory_function_(bss_list); | 1555 WlanFreeMemory_function_(bss_list); |
| 1552 } | 1556 } |
| 1553 return error; | 1557 return error; |
| 1554 } | 1558 } |
| 1555 | 1559 |
| 1556 WiFiService::Frequency WiFiServiceImpl::GetNormalizedFrequency( | 1560 Frequency WiFiServiceImpl::GetNormalizedFrequency(int frequency_in_mhz) const { |
| 1557 int frequency_in_mhz) const { | |
| 1558 if (frequency_in_mhz == 0) | 1561 if (frequency_in_mhz == 0) |
| 1559 return kFrequencyAny; | 1562 return kFrequencyAny; |
| 1560 if (frequency_in_mhz < 3000) | 1563 if (frequency_in_mhz < 3000) |
| 1561 return kFrequency2400; | 1564 return kFrequency2400; |
| 1562 return kFrequency5000; | 1565 return kFrequency5000; |
| 1563 } | 1566 } |
| 1564 | 1567 |
| 1565 DWORD WiFiServiceImpl::Connect(const std::string& network_guid, | 1568 DWORD WiFiServiceImpl::Connect(const std::string& network_guid, |
| 1566 Frequency frequency) { | 1569 Frequency frequency) { |
| 1567 if (client_ == NULL) { | 1570 if (client_ == NULL) { |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1836 NetworkGuidList changed_networks(1, network_guid); | 1839 NetworkGuidList changed_networks(1, network_guid); |
| 1837 message_loop_proxy_->PostTask( | 1840 message_loop_proxy_->PostTask( |
| 1838 FROM_HERE, | 1841 FROM_HERE, |
| 1839 base::Bind(networks_changed_observer_, changed_networks)); | 1842 base::Bind(networks_changed_observer_, changed_networks)); |
| 1840 } | 1843 } |
| 1841 } | 1844 } |
| 1842 | 1845 |
| 1843 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } | 1846 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } |
| 1844 | 1847 |
| 1845 } // namespace wifi | 1848 } // namespace wifi |
| OLD | NEW |