| 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 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 int PerformQuery(HANDLE adapter_handle, | 146 int PerformQuery(HANDLE adapter_handle, |
| 147 BYTE* buffer, | 147 BYTE* buffer, |
| 148 DWORD buffer_size, | 148 DWORD buffer_size, |
| 149 DWORD* bytes_out); | 149 DWORD* bytes_out); |
| 150 bool ResizeBuffer(int requested_size, scoped_ptr_malloc<BYTE>* buffer); | 150 bool ResizeBuffer(int requested_size, scoped_ptr_malloc<BYTE>* buffer); |
| 151 // Gets the system directory and appends a trailing slash if not already | 151 // Gets the system directory and appends a trailing slash if not already |
| 152 // present. | 152 // present. |
| 153 bool GetSystemDirectory(string16* path); | 153 bool GetSystemDirectory(string16* path); |
| 154 } // namespace | 154 } // namespace |
| 155 | 155 |
| 156 template<> | |
| 157 WifiDataProviderImplBase* WifiDataProvider::DefaultFactoryFunction() { | 156 WifiDataProviderImplBase* WifiDataProvider::DefaultFactoryFunction() { |
| 158 return new Win32WifiDataProvider(); | 157 return new Win32WifiDataProvider(); |
| 159 } | 158 } |
| 160 | 159 |
| 161 Win32WifiDataProvider::Win32WifiDataProvider() { | 160 Win32WifiDataProvider::Win32WifiDataProvider() { |
| 162 } | 161 } |
| 163 | 162 |
| 164 Win32WifiDataProvider::~Win32WifiDataProvider() { | 163 Win32WifiDataProvider::~Win32WifiDataProvider() { |
| 165 } | 164 } |
| 166 | 165 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 177 PollingPolicyInterface* Win32WifiDataProvider::NewPollingPolicy() { | 176 PollingPolicyInterface* Win32WifiDataProvider::NewPollingPolicy() { |
| 178 return new GenericPollingPolicy<kDefaultPollingInterval, | 177 return new GenericPollingPolicy<kDefaultPollingInterval, |
| 179 kNoChangePollingInterval, | 178 kNoChangePollingInterval, |
| 180 kTwoNoChangePollingInterval, | 179 kTwoNoChangePollingInterval, |
| 181 kNoWifiPollingIntervalMilliseconds>; | 180 kNoWifiPollingIntervalMilliseconds>; |
| 182 } | 181 } |
| 183 | 182 |
| 184 // Local classes and functions | 183 // Local classes and functions |
| 185 namespace { | 184 namespace { |
| 186 | 185 |
| 186 bool ConvertToAccessPointData(const NDIS_WLAN_BSSID& data, |
| 187 AccessPointData *access_point_data) { |
| 188 // Currently we get only MAC address, signal strength and SSID. |
| 189 // TODO(steveblock): Work out how to get age, channel and signal-to-noise. |
| 190 DCHECK(access_point_data); |
| 191 access_point_data->mac_address = MacAddressAsString16(data.MacAddress); |
| 192 access_point_data->radio_signal_strength = data.Rssi; |
| 193 // Note that _NDIS_802_11_SSID::Ssid::Ssid is not null-terminated. |
| 194 UTF8ToUTF16(reinterpret_cast<const char*>(data.Ssid.Ssid), |
| 195 data.Ssid.SsidLength, |
| 196 &access_point_data->ssid); |
| 197 return true; |
| 198 } |
| 199 |
| 200 int GetDataFromBssIdList(const NDIS_802_11_BSSID_LIST& bss_id_list, |
| 201 int list_size, |
| 202 WifiData::AccessPointDataSet* data) { |
| 203 // Walk through the BSS IDs. |
| 204 int found = 0; |
| 205 const uint8 *iterator = reinterpret_cast<const uint8*>(&bss_id_list.Bssid[0]); |
| 206 const uint8 *end_of_buffer = |
| 207 reinterpret_cast<const uint8*>(&bss_id_list) + list_size; |
| 208 for (int i = 0; i < static_cast<int>(bss_id_list.NumberOfItems); ++i) { |
| 209 const NDIS_WLAN_BSSID *bss_id = |
| 210 reinterpret_cast<const NDIS_WLAN_BSSID*>(iterator); |
| 211 // Check that the length of this BSS ID is reasonable. |
| 212 if (bss_id->Length < sizeof(NDIS_WLAN_BSSID) || |
| 213 iterator + bss_id->Length > end_of_buffer) { |
| 214 break; |
| 215 } |
| 216 AccessPointData access_point_data; |
| 217 if (ConvertToAccessPointData(*bss_id, &access_point_data)) { |
| 218 data->insert(access_point_data); |
| 219 ++found; |
| 220 } |
| 221 // Move to the next BSS ID. |
| 222 iterator += bss_id->Length; |
| 223 } |
| 224 return found; |
| 225 } |
| 226 |
| 187 // WindowsWlanApi | 227 // WindowsWlanApi |
| 188 WindowsWlanApi::WindowsWlanApi(HINSTANCE library) | 228 WindowsWlanApi::WindowsWlanApi(HINSTANCE library) |
| 189 : library_(library) { | 229 : library_(library) { |
| 190 GetWLANFunctions(library_); | 230 GetWLANFunctions(library_); |
| 191 } | 231 } |
| 192 | 232 |
| 193 WindowsWlanApi::~WindowsWlanApi() { | 233 WindowsWlanApi::~WindowsWlanApi() { |
| 194 FreeLibrary(library_); | 234 FreeLibrary(library_); |
| 195 } | 235 } |
| 196 | 236 |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 | 638 |
| 599 path->assign(buffer.get(), characters_written); | 639 path->assign(buffer.get(), characters_written); |
| 600 | 640 |
| 601 if (*path->rbegin() != L'\\') { | 641 if (*path->rbegin() != L'\\') { |
| 602 path->append(L"\\"); | 642 path->append(L"\\"); |
| 603 } | 643 } |
| 604 DCHECK_EQ(L'\\', *path->rbegin()); | 644 DCHECK_EQ(L'\\', *path->rbegin()); |
| 605 return true; | 645 return true; |
| 606 } | 646 } |
| 607 } // namespace | 647 } // namespace |
| OLD | NEW |