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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 254 return WIFI_PHY_LAYER_PROTOCOL_NONE; |
255 | 255 |
256 WlanHandle client; | 256 WlanHandle client; |
257 DWORD cur_version = 0; | 257 DWORD cur_version = 0; |
258 const DWORD kMaxClientVersion = 2; | 258 const DWORD kMaxClientVersion = 2; |
259 DWORD result = wlanapi.OpenHandle(kMaxClientVersion, &cur_version, &client); | 259 DWORD result = wlanapi.OpenHandle(kMaxClientVersion, &cur_version, &client); |
260 if (result != ERROR_SUCCESS) | 260 if (result != ERROR_SUCCESS) |
261 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 261 return WIFI_PHY_LAYER_PROTOCOL_NONE; |
262 | 262 |
263 WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; | 263 WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; |
264 result = wlanapi.enum_interfaces_func(client, NULL, &interface_list_ptr); | 264 result = wlanapi.enum_interfaces_func(client.Get(), NULL, |
| 265 &interface_list_ptr); |
265 if (result != ERROR_SUCCESS) | 266 if (result != ERROR_SUCCESS) |
266 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 267 return WIFI_PHY_LAYER_PROTOCOL_NONE; |
267 scoped_ptr<WLAN_INTERFACE_INFO_LIST, WlanApiDeleter> interface_list( | 268 scoped_ptr<WLAN_INTERFACE_INFO_LIST, WlanApiDeleter> interface_list( |
268 interface_list_ptr); | 269 interface_list_ptr); |
269 | 270 |
270 // Assume at most one connected wifi interface. | 271 // Assume at most one connected wifi interface. |
271 WLAN_INTERFACE_INFO* info = NULL; | 272 WLAN_INTERFACE_INFO* info = NULL; |
272 for (unsigned i = 0; i < interface_list->dwNumberOfItems; ++i) { | 273 for (unsigned i = 0; i < interface_list->dwNumberOfItems; ++i) { |
273 if (interface_list->InterfaceInfo[i].isState == | 274 if (interface_list->InterfaceInfo[i].isState == |
274 wlan_interface_state_connected) { | 275 wlan_interface_state_connected) { |
275 info = &interface_list->InterfaceInfo[i]; | 276 info = &interface_list->InterfaceInfo[i]; |
276 break; | 277 break; |
277 } | 278 } |
278 } | 279 } |
279 | 280 |
280 if (info == NULL) | 281 if (info == NULL) |
281 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 282 return WIFI_PHY_LAYER_PROTOCOL_NONE; |
282 | 283 |
283 WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr; | 284 WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr; |
284 DWORD conn_info_size = 0; | 285 DWORD conn_info_size = 0; |
285 WLAN_OPCODE_VALUE_TYPE op_code; | 286 WLAN_OPCODE_VALUE_TYPE op_code; |
286 result = wlanapi.query_interface_func( | 287 result = wlanapi.query_interface_func( |
287 client, &info->InterfaceGuid, wlan_intf_opcode_current_connection, NULL, | 288 client.Get(), &info->InterfaceGuid, wlan_intf_opcode_current_connection, |
288 &conn_info_size, reinterpret_cast<VOID**>(&conn_info_ptr), &op_code); | 289 NULL, &conn_info_size, reinterpret_cast<VOID**>(&conn_info_ptr), |
| 290 &op_code); |
289 if (result != ERROR_SUCCESS) | 291 if (result != ERROR_SUCCESS) |
290 return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; | 292 return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; |
291 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, WlanApiDeleter> conn_info( | 293 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, WlanApiDeleter> conn_info( |
292 conn_info_ptr); | 294 conn_info_ptr); |
293 | 295 |
294 switch (conn_info->wlanAssociationAttributes.dot11PhyType) { | 296 switch (conn_info->wlanAssociationAttributes.dot11PhyType) { |
295 case dot11_phy_type_fhss: | 297 case dot11_phy_type_fhss: |
296 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; | 298 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; |
297 case dot11_phy_type_dsss: | 299 case dot11_phy_type_dsss: |
298 return WIFI_PHY_LAYER_PROTOCOL_B; | 300 return WIFI_PHY_LAYER_PROTOCOL_B; |
299 case dot11_phy_type_irbaseband: | 301 case dot11_phy_type_irbaseband: |
300 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; | 302 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; |
301 case dot11_phy_type_ofdm: | 303 case dot11_phy_type_ofdm: |
302 return WIFI_PHY_LAYER_PROTOCOL_A; | 304 return WIFI_PHY_LAYER_PROTOCOL_A; |
303 case dot11_phy_type_hrdsss: | 305 case dot11_phy_type_hrdsss: |
304 return WIFI_PHY_LAYER_PROTOCOL_B; | 306 return WIFI_PHY_LAYER_PROTOCOL_B; |
305 case dot11_phy_type_erp: | 307 case dot11_phy_type_erp: |
306 return WIFI_PHY_LAYER_PROTOCOL_G; | 308 return WIFI_PHY_LAYER_PROTOCOL_G; |
307 case dot11_phy_type_ht: | 309 case dot11_phy_type_ht: |
308 return WIFI_PHY_LAYER_PROTOCOL_N; | 310 return WIFI_PHY_LAYER_PROTOCOL_N; |
309 default: | 311 default: |
310 return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; | 312 return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; |
311 } | 313 } |
312 } | 314 } |
313 | 315 |
314 } // namespace net | 316 } // namespace net |
OLD | NEW |