OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
6 | 6 |
7 #include <iphlpapi.h> | 7 #include <iphlpapi.h> |
8 #include <wlanapi.h> | 8 #include <wlanapi.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 ::GetProcAddress(module, "WlanQueryInterface")); | 54 ::GetProcAddress(module, "WlanQueryInterface")); |
55 free_memory_func = reinterpret_cast<WlanFreeMemoryFunc>( | 55 free_memory_func = reinterpret_cast<WlanFreeMemoryFunc>( |
56 ::GetProcAddress(module, "WlanFreeMemory")); | 56 ::GetProcAddress(module, "WlanFreeMemory")); |
57 close_handle_func = reinterpret_cast<WlanCloseHandleFunc>( | 57 close_handle_func = reinterpret_cast<WlanCloseHandleFunc>( |
58 ::GetProcAddress(module, "WlanCloseHandle")); | 58 ::GetProcAddress(module, "WlanCloseHandle")); |
59 initialized = open_handle_func && enum_interfaces_func && | 59 initialized = open_handle_func && enum_interfaces_func && |
60 query_interface_func && free_memory_func && | 60 query_interface_func && free_memory_func && |
61 close_handle_func; | 61 close_handle_func; |
62 } | 62 } |
63 | 63 |
| 64 template <typename T> |
| 65 DWORD OpenHandle(DWORD client_version, DWORD* cur_version, T* handle) const { |
| 66 HANDLE temp_handle; |
| 67 DWORD result = open_handle_func(client_version, NULL, cur_version, |
| 68 &temp_handle); |
| 69 if (result != ERROR_SUCCESS) |
| 70 return result; |
| 71 handle->Set(temp_handle); |
| 72 return ERROR_SUCCESS; |
| 73 } |
| 74 |
64 HMODULE module; | 75 HMODULE module; |
65 WlanOpenHandleFunc open_handle_func; | 76 WlanOpenHandleFunc open_handle_func; |
66 WlanEnumInterfacesFunc enum_interfaces_func; | 77 WlanEnumInterfacesFunc enum_interfaces_func; |
67 WlanQueryInterfaceFunc query_interface_func; | 78 WlanQueryInterfaceFunc query_interface_func; |
68 WlanFreeMemoryFunc free_memory_func; | 79 WlanFreeMemoryFunc free_memory_func; |
69 WlanCloseHandleFunc close_handle_func; | 80 WlanCloseHandleFunc close_handle_func; |
70 bool initialized; | 81 bool initialized; |
71 }; | 82 }; |
72 | 83 |
73 } // namespace | 84 } // namespace |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 240 } |
230 }; | 241 }; |
231 | 242 |
232 const WlanApi& wlanapi = lazy_wlanapi.Get(); | 243 const WlanApi& wlanapi = lazy_wlanapi.Get(); |
233 if (!wlanapi.initialized) | 244 if (!wlanapi.initialized) |
234 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 245 return WIFI_PHY_LAYER_PROTOCOL_NONE; |
235 | 246 |
236 WlanHandle client; | 247 WlanHandle client; |
237 DWORD cur_version = 0; | 248 DWORD cur_version = 0; |
238 const DWORD kMaxClientVersion = 2; | 249 const DWORD kMaxClientVersion = 2; |
239 DWORD result = wlanapi.open_handle_func(kMaxClientVersion, NULL, &cur_version, | 250 DWORD result = wlanapi.OpenHandle(kMaxClientVersion, &cur_version, &client); |
240 client.Receive()); | |
241 if (result != ERROR_SUCCESS) | 251 if (result != ERROR_SUCCESS) |
242 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 252 return WIFI_PHY_LAYER_PROTOCOL_NONE; |
243 | 253 |
244 WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; | 254 WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; |
245 result = wlanapi.enum_interfaces_func(client, NULL, &interface_list_ptr); | 255 result = wlanapi.enum_interfaces_func(client, NULL, &interface_list_ptr); |
246 if (result != ERROR_SUCCESS) | 256 if (result != ERROR_SUCCESS) |
247 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 257 return WIFI_PHY_LAYER_PROTOCOL_NONE; |
248 scoped_ptr<WLAN_INTERFACE_INFO_LIST, WlanApiDeleter> interface_list( | 258 scoped_ptr<WLAN_INTERFACE_INFO_LIST, WlanApiDeleter> interface_list( |
249 interface_list_ptr); | 259 interface_list_ptr); |
250 | 260 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 case dot11_phy_type_erp: | 296 case dot11_phy_type_erp: |
287 return WIFI_PHY_LAYER_PROTOCOL_G; | 297 return WIFI_PHY_LAYER_PROTOCOL_G; |
288 case dot11_phy_type_ht: | 298 case dot11_phy_type_ht: |
289 return WIFI_PHY_LAYER_PROTOCOL_N; | 299 return WIFI_PHY_LAYER_PROTOCOL_N; |
290 default: | 300 default: |
291 return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; | 301 return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; |
292 } | 302 } |
293 } | 303 } |
294 | 304 |
295 } // namespace net | 305 } // namespace net |
OLD | NEW |