OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Windows Vista uses the Native Wifi (WLAN) API for accessing WiFi cards. See | 5 // Windows Vista uses the Native Wifi (WLAN) API for accessing WiFi cards. See |
6 // http://msdn.microsoft.com/en-us/library/ms705945(VS.85).aspx. Windows XP | 6 // http://msdn.microsoft.com/en-us/library/ms705945(VS.85).aspx. Windows XP |
7 // Service Pack 3 (and Windows XP Service Pack 2, if upgraded with a hot fix) | 7 // Service Pack 3 (and Windows XP Service Pack 2, if upgraded with a hot fix) |
8 // also support a limited version of the WLAN API. See | 8 // also support a limited version of the WLAN API. See |
9 // http://msdn.microsoft.com/en-us/library/bb204766.aspx. The WLAN API uses | 9 // http://msdn.microsoft.com/en-us/library/bb204766.aspx. The WLAN API uses |
10 // wlanapi.h, which is not part of the SDK used by Gears, so is replicated | 10 // wlanapi.h, which is not part of the SDK used by Gears, so is replicated |
11 // locally using data from the MSDN. | 11 // locally using data from the MSDN. |
12 // | 12 // |
13 // Windows XP from Service Pack 2 onwards supports the Wireless Zero | 13 // Windows XP from Service Pack 2 onwards supports the Wireless Zero |
14 // Configuration (WZC) programming interface. See | 14 // Configuration (WZC) programming interface. See |
15 // http://msdn.microsoft.com/en-us/library/ms706587(VS.85).aspx. | 15 // http://msdn.microsoft.com/en-us/library/ms706587(VS.85).aspx. |
16 // | 16 // |
17 // The MSDN recommends that one use the WLAN API where available, and WZC | 17 // The MSDN recommends that one use the WLAN API where available, and WZC |
18 // otherwise. | 18 // otherwise. |
19 // | 19 // |
20 // However, it seems that WZC fails for some wireless cards. Also, WLAN seems | 20 // However, it seems that WZC fails for some wireless cards. Also, WLAN seems |
21 // not to work on XP SP3. So we use WLAN on Vista, and use NDIS directly | 21 // not to work on XP SP3. So we use WLAN on Vista, and use NDIS directly |
22 // otherwise. | 22 // otherwise. |
23 | 23 |
24 #include "chrome/browser/geolocation/wifi_data_provider_win.h" | 24 #include "chrome/browser/geolocation/wifi_data_provider_win.h" |
25 | 25 |
26 #include <windows.h> | 26 #include <windows.h> |
27 #include <winioctl.h> | 27 #include <winioctl.h> |
28 #include <wlanapi.h> | 28 #include <wlanapi.h> |
| 29 |
29 #include "base/utf_string_conversions.h" | 30 #include "base/utf_string_conversions.h" |
30 #include "base/win_util.h" | 31 #include "base/win/windows_version.h" |
31 #include "chrome/browser/geolocation/wifi_data_provider_common.h" | 32 #include "chrome/browser/geolocation/wifi_data_provider_common.h" |
32 #include "chrome/browser/geolocation/wifi_data_provider_common_win.h" | 33 #include "chrome/browser/geolocation/wifi_data_provider_common_win.h" |
33 | 34 |
34 // Taken from ndis.h for WinCE. | 35 // Taken from ndis.h for WinCE. |
35 #define NDIS_STATUS_INVALID_LENGTH ((NDIS_STATUS)0xC0010014L) | 36 #define NDIS_STATUS_INVALID_LENGTH ((NDIS_STATUS)0xC0010014L) |
36 #define NDIS_STATUS_BUFFER_TOO_SHORT ((NDIS_STATUS)0xC0010016L) | 37 #define NDIS_STATUS_BUFFER_TOO_SHORT ((NDIS_STATUS)0xC0010016L) |
37 | 38 |
38 namespace { | 39 namespace { |
39 // The limits on the size of the buffer used for the OID query. | 40 // The limits on the size of the buffer used for the OID query. |
40 const int kInitialBufferSize = 2 << 12; // Good for about 50 APs. | 41 const int kInitialBufferSize = 2 << 12; // Good for about 50 APs. |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 WindowsWlanApi::WindowsWlanApi(HINSTANCE library) | 188 WindowsWlanApi::WindowsWlanApi(HINSTANCE library) |
188 : library_(library) { | 189 : library_(library) { |
189 GetWLANFunctions(library_); | 190 GetWLANFunctions(library_); |
190 } | 191 } |
191 | 192 |
192 WindowsWlanApi::~WindowsWlanApi() { | 193 WindowsWlanApi::~WindowsWlanApi() { |
193 FreeLibrary(library_); | 194 FreeLibrary(library_); |
194 } | 195 } |
195 | 196 |
196 WindowsWlanApi* WindowsWlanApi::Create() { | 197 WindowsWlanApi* WindowsWlanApi::Create() { |
197 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) | 198 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
198 return NULL; | 199 return NULL; |
199 // We use an absolute path to load the DLL to avoid DLL preloading attacks. | 200 // We use an absolute path to load the DLL to avoid DLL preloading attacks. |
200 string16 system_directory; | 201 string16 system_directory; |
201 if (!GetSystemDirectory(&system_directory)) { | 202 if (!GetSystemDirectory(&system_directory)) { |
202 return NULL; | 203 return NULL; |
203 } | 204 } |
204 DCHECK(!system_directory.empty()); | 205 DCHECK(!system_directory.empty()); |
205 string16 dll_path = system_directory + L"wlanapi.dll"; | 206 string16 dll_path = system_directory + L"wlanapi.dll"; |
206 HINSTANCE library = LoadLibraryEx(dll_path.c_str(), | 207 HINSTANCE library = LoadLibraryEx(dll_path.c_str(), |
207 NULL, | 208 NULL, |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 | 598 |
598 path->assign(buffer.get(), characters_written); | 599 path->assign(buffer.get(), characters_written); |
599 | 600 |
600 if (*path->rbegin() != L'\\') { | 601 if (*path->rbegin() != L'\\') { |
601 path->append(L"\\"); | 602 path->append(L"\\"); |
602 } | 603 } |
603 DCHECK_EQ(L'\\', *path->rbegin()); | 604 DCHECK_EQ(L'\\', *path->rbegin()); |
604 return true; | 605 return true; |
605 } | 606 } |
606 } // namespace | 607 } // namespace |
OLD | NEW |