| 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 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 | 575 |
| 575 void WiFiServiceImpl::CreateNetwork( | 576 void WiFiServiceImpl::CreateNetwork( |
| 576 bool shared, | 577 bool shared, |
| 577 scoped_ptr<base::DictionaryValue> properties, | 578 scoped_ptr<base::DictionaryValue> properties, |
| 578 std::string* network_guid, | 579 std::string* network_guid, |
| 579 std::string* error) { | 580 std::string* error) { |
| 580 DWORD error_code = EnsureInitialized(); | 581 DWORD error_code = EnsureInitialized(); |
| 581 if (CheckError(error_code, kErrorWiFiService, error)) | 582 if (CheckError(error_code, kErrorWiFiService, error)) |
| 582 return; | 583 return; |
| 583 | 584 |
| 584 WiFiService::NetworkProperties network_properties; | 585 NetworkProperties network_properties; |
| 585 if (!network_properties.UpdateFromValue(*properties)) { | 586 if (!network_properties.UpdateFromValue(*properties)) { |
| 586 CheckError(ERROR_INVALID_DATA, kErrorWiFiService, error); | 587 CheckError(ERROR_INVALID_DATA, kErrorWiFiService, error); |
| 587 return; | 588 return; |
| 588 } | 589 } |
| 589 | 590 |
| 590 network_properties.guid = network_properties.ssid; | 591 network_properties.guid = network_properties.ssid; |
| 591 std::string profile_xml; | 592 std::string profile_xml; |
| 592 if (!CreateProfile(network_properties, kEncryptionTypeAny, &profile_xml)) { | 593 if (!CreateProfile(network_properties, kEncryptionTypeAny, &profile_xml)) { |
| 593 CheckError(ERROR_INVALID_DATA, kErrorWiFiService, error); | 594 CheckError(ERROR_INVALID_DATA, kErrorWiFiService, error); |
| 594 return; | 595 return; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 network_type != onc::network_type::kWiFi) { | 630 network_type != onc::network_type::kWiFi) { |
| 630 return; | 631 return; |
| 631 } | 632 } |
| 632 | 633 |
| 633 DWORD error = EnsureInitialized(); | 634 DWORD error = EnsureInitialized(); |
| 634 if (error == ERROR_SUCCESS) { | 635 if (error == ERROR_SUCCESS) { |
| 635 NetworkList networks; | 636 NetworkList networks; |
| 636 error = GetVisibleNetworkList(&networks); | 637 error = GetVisibleNetworkList(&networks); |
| 637 if (error == ERROR_SUCCESS && !networks.empty()) { | 638 if (error == ERROR_SUCCESS && !networks.empty()) { |
| 638 SortNetworks(&networks); | 639 SortNetworks(&networks); |
| 639 for (WiFiService::NetworkList::const_iterator it = networks.begin(); | 640 for (NetworkList::const_iterator it = networks.begin(); |
| 640 it != networks.end(); | 641 it != networks.end(); |
| 641 ++it) { | 642 ++it) { |
| 642 scoped_ptr<base::DictionaryValue> network(it->ToValue(true)); | 643 scoped_ptr<base::DictionaryValue> network(it->ToValue(true)); |
| 643 network_list->Append(network.release()); | 644 network_list->Append(network.release()); |
| 644 } | 645 } |
| 645 } | 646 } |
| 646 } | 647 } |
| 647 } | 648 } |
| 648 | 649 |
| 649 void WiFiServiceImpl::RequestNetworkScan() { | 650 void WiFiServiceImpl::RequestNetworkScan() { |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 const std::string& error_name, | 930 const std::string& error_name, |
| 930 std::string* error) const { | 931 std::string* error) const { |
| 931 if (error_code != ERROR_SUCCESS) { | 932 if (error_code != ERROR_SUCCESS) { |
| 932 DLOG(ERROR) << "WiFiService Error " << error_code << ": " << error_name; | 933 DLOG(ERROR) << "WiFiService Error " << error_code << ": " << error_name; |
| 933 *error = error_name; | 934 *error = error_name; |
| 934 return true; | 935 return true; |
| 935 } | 936 } |
| 936 return false; | 937 return false; |
| 937 } | 938 } |
| 938 | 939 |
| 939 WiFiService::NetworkList::iterator WiFiServiceImpl::FindNetwork( | 940 NetworkList::iterator WiFiServiceImpl::FindNetwork( |
| 940 NetworkList& networks, | 941 NetworkList& networks, |
| 941 const std::string& network_guid) { | 942 const std::string& network_guid) { |
| 942 for (NetworkList::iterator it = networks.begin(); it != networks.end(); | 943 for (NetworkList::iterator it = networks.begin(); it != networks.end(); |
| 943 ++it) { | 944 ++it) { |
| 944 if (it->guid == network_guid) | 945 if (it->guid == network_guid) |
| 945 return it; | 946 return it; |
| 946 } | 947 } |
| 947 return networks.end(); | 948 return networks.end(); |
| 948 } | 949 } |
| 949 | 950 |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1450 // Clean up. | 1451 // Clean up. |
| 1451 if (wlan_connection_attributes != NULL) | 1452 if (wlan_connection_attributes != NULL) |
| 1452 WlanFreeMemory_function_(wlan_connection_attributes); | 1453 WlanFreeMemory_function_(wlan_connection_attributes); |
| 1453 | 1454 |
| 1454 if (bss_list != NULL) | 1455 if (bss_list != NULL) |
| 1455 WlanFreeMemory_function_(bss_list); | 1456 WlanFreeMemory_function_(bss_list); |
| 1456 | 1457 |
| 1457 return error; | 1458 return error; |
| 1458 } | 1459 } |
| 1459 | 1460 |
| 1460 WiFiService::Frequency WiFiServiceImpl::GetFrequencyToConnect( | 1461 Frequency WiFiServiceImpl::GetFrequencyToConnect( |
| 1461 const std::string& network_guid) const { | 1462 const std::string& network_guid) const { |
| 1462 // Check whether desired frequency is set in |connect_properties_|. | 1463 // Check whether desired frequency is set in |connect_properties_|. |
| 1463 const base::DictionaryValue* properties; | 1464 const base::DictionaryValue* properties; |
| 1464 const base::DictionaryValue* wifi; | 1465 const base::DictionaryValue* wifi; |
| 1465 int frequency; | 1466 int frequency; |
| 1466 if (connect_properties_.GetDictionaryWithoutPathExpansion( | 1467 if (connect_properties_.GetDictionaryWithoutPathExpansion( |
| 1467 network_guid, &properties) && | 1468 network_guid, &properties) && |
| 1468 properties->GetDictionary(onc::network_type::kWiFi, &wifi) && | 1469 properties->GetDictionary(onc::network_type::kWiFi, &wifi) && |
| 1469 wifi->GetInteger(onc::wifi::kFrequency, &frequency)) { | 1470 wifi->GetInteger(onc::wifi::kFrequency, &frequency)) { |
| 1470 return GetNormalizedFrequency(frequency); | 1471 return GetNormalizedFrequency(frequency); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1546 } | 1547 } |
| 1547 } | 1548 } |
| 1548 | 1549 |
| 1549 // Clean up. | 1550 // Clean up. |
| 1550 if (bss_list != NULL) { | 1551 if (bss_list != NULL) { |
| 1551 WlanFreeMemory_function_(bss_list); | 1552 WlanFreeMemory_function_(bss_list); |
| 1552 } | 1553 } |
| 1553 return error; | 1554 return error; |
| 1554 } | 1555 } |
| 1555 | 1556 |
| 1556 WiFiService::Frequency WiFiServiceImpl::GetNormalizedFrequency( | 1557 Frequency WiFiServiceImpl::GetNormalizedFrequency(int frequency_in_mhz) const { |
| 1557 int frequency_in_mhz) const { | |
| 1558 if (frequency_in_mhz == 0) | 1558 if (frequency_in_mhz == 0) |
| 1559 return kFrequencyAny; | 1559 return kFrequencyAny; |
| 1560 if (frequency_in_mhz < 3000) | 1560 if (frequency_in_mhz < 3000) |
| 1561 return kFrequency2400; | 1561 return kFrequency2400; |
| 1562 return kFrequency5000; | 1562 return kFrequency5000; |
| 1563 } | 1563 } |
| 1564 | 1564 |
| 1565 DWORD WiFiServiceImpl::Connect(const std::string& network_guid, | 1565 DWORD WiFiServiceImpl::Connect(const std::string& network_guid, |
| 1566 Frequency frequency) { | 1566 Frequency frequency) { |
| 1567 if (client_ == NULL) { | 1567 if (client_ == NULL) { |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1836 NetworkGuidList changed_networks(1, network_guid); | 1836 NetworkGuidList changed_networks(1, network_guid); |
| 1837 message_loop_proxy_->PostTask( | 1837 message_loop_proxy_->PostTask( |
| 1838 FROM_HERE, | 1838 FROM_HERE, |
| 1839 base::Bind(networks_changed_observer_, changed_networks)); | 1839 base::Bind(networks_changed_observer_, changed_networks)); |
| 1840 } | 1840 } |
| 1841 } | 1841 } |
| 1842 | 1842 |
| 1843 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } | 1843 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } |
| 1844 | 1844 |
| 1845 } // namespace wifi | 1845 } // namespace wifi |
| OLD | NEW |