| 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 |
| (...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 NetworkProperties current_properties; | 899 NetworkProperties current_properties; |
| 900 DWORD error = GetCurrentProperties(¤t_properties); | 900 DWORD error = GetCurrentProperties(¤t_properties); |
| 901 if (network_guid == current_properties.guid && | 901 if (network_guid == current_properties.guid && |
| 902 current_properties.connection_state == | 902 current_properties.connection_state == |
| 903 onc::connection_state::kConnected) { | 903 onc::connection_state::kConnected) { |
| 904 DVLOG(1) << "WiFi Connected, Reset DHCP: " << network_guid; | 904 DVLOG(1) << "WiFi Connected, Reset DHCP: " << network_guid; |
| 905 // Even though wireless network is now connected, it may still be unusable, | 905 // Even though wireless network is now connected, it may still be unusable, |
| 906 // e.g. after Chromecast device reset. Reset DHCP on wireless network to | 906 // e.g. after Chromecast device reset. Reset DHCP on wireless network to |
| 907 // work around this issue. | 907 // work around this issue. |
| 908 error = ResetDHCP(); | 908 error = ResetDHCP(); |
| 909 if (error != ERROR_SUCCESS) |
| 910 LOG(ERROR) << error; |
| 909 // There is no need to keep created profile as network is connected. | 911 // There is no need to keep created profile as network is connected. |
| 910 created_profiles_.RemoveWithoutPathExpansion(network_guid, NULL); | 912 created_profiles_.RemoveWithoutPathExpansion(network_guid, NULL); |
| 911 // Restore previously suppressed notifications. | 913 // Restore previously suppressed notifications. |
| 912 enable_notify_network_changed_ = true; | 914 enable_notify_network_changed_ = true; |
| 913 RestoreNwCategoryWizard(); | 915 RestoreNwCategoryWizard(); |
| 914 NotifyNetworkChanged(network_guid); | 916 NotifyNetworkChanged(network_guid); |
| 915 } else { | 917 } else { |
| 916 // Continue waiting for network connection state change. | 918 // Continue waiting for network connection state change. |
| 917 task_runner_->PostDelayedTask( | 919 task_runner_->PostDelayedTask( |
| 918 FROM_HERE, | 920 FROM_HERE, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 } | 968 } |
| 967 | 969 |
| 968 void WiFiServiceImpl::SortNetworks(NetworkList* networks) { | 970 void WiFiServiceImpl::SortNetworks(NetworkList* networks) { |
| 969 networks->sort(NetworkProperties::OrderByType); | 971 networks->sort(NetworkProperties::OrderByType); |
| 970 } | 972 } |
| 971 | 973 |
| 972 DWORD WiFiServiceImpl::LoadWlanLibrary() { | 974 DWORD WiFiServiceImpl::LoadWlanLibrary() { |
| 973 // Use an absolute path to load the DLL to avoid DLL preloading attacks. | 975 // Use an absolute path to load the DLL to avoid DLL preloading attacks. |
| 974 base::FilePath path; | 976 base::FilePath path; |
| 975 if (!PathService::Get(base::DIR_SYSTEM, &path)) { | 977 if (!PathService::Get(base::DIR_SYSTEM, &path)) { |
| 976 DLOG(ERROR) << "Unable to get system path."; | 978 LOG(ERROR) << "Unable to get system path."; |
| 977 return ERROR_NOT_FOUND; | 979 return ERROR_NOT_FOUND; |
| 978 } | 980 } |
| 979 wlan_api_library_ = ::LoadLibraryEx(path.Append(kWlanApiDll).value().c_str(), | 981 wlan_api_library_ = ::LoadLibraryEx(path.Append(kWlanApiDll).value().c_str(), |
| 980 NULL, | 982 NULL, |
| 981 LOAD_WITH_ALTERED_SEARCH_PATH); | 983 LOAD_WITH_ALTERED_SEARCH_PATH); |
| 982 if (!wlan_api_library_) { | 984 if (!wlan_api_library_) { |
| 983 DLOG(ERROR) << "Unable to load WlanApi.dll."; | 985 LOG(ERROR) << "Unable to load WlanApi.dll."; |
| 984 return ERROR_NOT_FOUND; | 986 return ERROR_NOT_FOUND; |
| 985 } | 987 } |
| 986 | 988 |
| 987 // Initialize WlanApi function pointers | 989 // Initialize WlanApi function pointers |
| 988 WlanConnect_function_ = | 990 WlanConnect_function_ = |
| 989 reinterpret_cast<WlanConnectFunction>( | 991 reinterpret_cast<WlanConnectFunction>( |
| 990 ::GetProcAddress(wlan_api_library_, kWlanConnect)); | 992 ::GetProcAddress(wlan_api_library_, kWlanConnect)); |
| 991 WlanCloseHandle_function_ = | 993 WlanCloseHandle_function_ = |
| 992 reinterpret_cast<WlanCloseHandleFunction>( | 994 reinterpret_cast<WlanCloseHandleFunction>( |
| 993 ::GetProcAddress(wlan_api_library_, kWlanCloseHandle)); | 995 ::GetProcAddress(wlan_api_library_, kWlanCloseHandle)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 !WlanDisconnect_function_ || | 1039 !WlanDisconnect_function_ || |
| 1038 !WlanEnumInterfaces_function_ || | 1040 !WlanEnumInterfaces_function_ || |
| 1039 !WlanFreeMemory_function_ || | 1041 !WlanFreeMemory_function_ || |
| 1040 !WlanGetAvailableNetworkList_function_ || | 1042 !WlanGetAvailableNetworkList_function_ || |
| 1041 !WlanGetProfile_function_ || | 1043 !WlanGetProfile_function_ || |
| 1042 !WlanOpenHandle_function_ || | 1044 !WlanOpenHandle_function_ || |
| 1043 !WlanQueryInterface_function_ || | 1045 !WlanQueryInterface_function_ || |
| 1044 !WlanRegisterNotification_function_ || | 1046 !WlanRegisterNotification_function_ || |
| 1045 !WlanScan_function_ || | 1047 !WlanScan_function_ || |
| 1046 !WlanSetProfile_function_) { | 1048 !WlanSetProfile_function_) { |
| 1047 DLOG(ERROR) << "Unable to find required WlanApi function."; | 1049 LOG(ERROR) << "Unable to find required WlanApi function."; |
| 1048 FreeLibrary(wlan_api_library_); | 1050 FreeLibrary(wlan_api_library_); |
| 1049 wlan_api_library_ = NULL; | 1051 wlan_api_library_ = NULL; |
| 1050 return ERROR_NOT_FOUND; | 1052 return ERROR_NOT_FOUND; |
| 1051 } | 1053 } |
| 1052 | 1054 |
| 1053 // Some WlanApi functions may not be available on XP. | 1055 // Some WlanApi functions may not be available on XP. |
| 1054 if (!WlanGetNetworkBssList_function_ || | 1056 if (!WlanGetNetworkBssList_function_ || |
| 1055 !WlanSaveTemporaryProfile_function_) { | 1057 !WlanSaveTemporaryProfile_function_) { |
| 1056 DVLOG(1) << "WlanApi function is not be available on XP."; | 1058 DVLOG(1) << "WlanApi function is not be available on XP."; |
| 1057 } | 1059 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 // Clean up.. | 1095 // Clean up.. |
| 1094 if (interface_list != NULL) | 1096 if (interface_list != NULL) |
| 1095 WlanFreeMemory_function_(interface_list); | 1097 WlanFreeMemory_function_(interface_list); |
| 1096 } | 1098 } |
| 1097 return error; | 1099 return error; |
| 1098 } | 1100 } |
| 1099 | 1101 |
| 1100 DWORD WiFiServiceImpl::ResetDHCP() { | 1102 DWORD WiFiServiceImpl::ResetDHCP() { |
| 1101 IP_ADAPTER_INDEX_MAP adapter_index_map = {0}; | 1103 IP_ADAPTER_INDEX_MAP adapter_index_map = {0}; |
| 1102 DWORD error = FindAdapterIndexMapByGUID(interface_guid_, &adapter_index_map); | 1104 DWORD error = FindAdapterIndexMapByGUID(interface_guid_, &adapter_index_map); |
| 1103 if (error == ERROR_SUCCESS) { | 1105 if (error != ERROR_SUCCESS) { |
| 1104 error = ::IpReleaseAddress(&adapter_index_map); | 1106 LOG(ERROR) << error; |
| 1105 if (error == ERROR_SUCCESS) { | 1107 return error; |
| 1106 error = ::IpRenewAddress(&adapter_index_map); | 1108 } |
| 1109 error = ::IpReleaseAddress(&adapter_index_map); |
| 1110 if (error != ERROR_SUCCESS) { |
| 1111 if (error != ERROR_ADDRESS_NOT_ASSOCIATED) { |
| 1112 LOG(ERROR) << error; |
| 1113 return error; |
| 1107 } | 1114 } |
| 1115 DVLOG(1) << "Ignoring IpReleaseAddress Error: " << error; |
| 1108 } | 1116 } |
| 1117 error = ::IpRenewAddress(&adapter_index_map); |
| 1118 if (error != ERROR_SUCCESS) |
| 1119 LOG(ERROR) << error; |
| 1109 return error; | 1120 return error; |
| 1110 } | 1121 } |
| 1111 | 1122 |
| 1112 DWORD WiFiServiceImpl::FindAdapterIndexMapByGUID( | 1123 DWORD WiFiServiceImpl::FindAdapterIndexMapByGUID( |
| 1113 const GUID& interface_guid, | 1124 const GUID& interface_guid, |
| 1114 IP_ADAPTER_INDEX_MAP* adapter_index_map) { | 1125 IP_ADAPTER_INDEX_MAP* adapter_index_map) { |
| 1115 base::string16 guid_string; | 1126 base::string16 guid_string; |
| 1116 const int kGUIDSize = 39; | 1127 const int kGUIDSize = 39; |
| 1117 ::StringFromGUID2( | 1128 ::StringFromGUID2( |
| 1118 interface_guid, WriteInto(&guid_string, kGUIDSize), kGUIDSize); | 1129 interface_guid, WriteInto(&guid_string, kGUIDSize), kGUIDSize); |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 NetworkGuidList changed_networks(1, network_guid); | 1829 NetworkGuidList changed_networks(1, network_guid); |
| 1819 message_loop_proxy_->PostTask( | 1830 message_loop_proxy_->PostTask( |
| 1820 FROM_HERE, | 1831 FROM_HERE, |
| 1821 base::Bind(networks_changed_observer_, changed_networks)); | 1832 base::Bind(networks_changed_observer_, changed_networks)); |
| 1822 } | 1833 } |
| 1823 } | 1834 } |
| 1824 | 1835 |
| 1825 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } | 1836 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } |
| 1826 | 1837 |
| 1827 } // namespace wifi | 1838 } // namespace wifi |
| OLD | NEW |