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/network_interfaces_win.h" | 5 #include "net/base/network_interfaces_win.h" |
6 | 6 |
7 #pragma comment(lib, "iphlpapi.lib") | 7 #pragma comment(lib, "iphlpapi.lib") |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 | 48 |
49 // Returns scoped_ptr to WLAN_CONNECTION_ATTRIBUTES. The scoped_ptr may hold a | 49 // Returns scoped_ptr to WLAN_CONNECTION_ATTRIBUTES. The scoped_ptr may hold a |
50 // NULL pointer if WLAN_CONNECTION_ATTRIBUTES is unavailable. | 50 // NULL pointer if WLAN_CONNECTION_ATTRIBUTES is unavailable. |
51 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> | 51 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> |
52 GetConnectionAttributes() { | 52 GetConnectionAttributes() { |
53 const internal::WlanApi& wlanapi = internal::WlanApi::GetInstance(); | 53 const internal::WlanApi& wlanapi = internal::WlanApi::GetInstance(); |
54 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> | 54 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> |
55 wlan_connection_attributes; | 55 wlan_connection_attributes; |
56 if (!wlanapi.initialized) | 56 if (!wlanapi.initialized) |
57 return wlan_connection_attributes.Pass(); | 57 return wlan_connection_attributes; |
58 | 58 |
59 internal::WlanHandle client; | 59 internal::WlanHandle client; |
60 DWORD cur_version = 0; | 60 DWORD cur_version = 0; |
61 const DWORD kMaxClientVersion = 2; | 61 const DWORD kMaxClientVersion = 2; |
62 DWORD result = wlanapi.OpenHandle(kMaxClientVersion, &cur_version, &client); | 62 DWORD result = wlanapi.OpenHandle(kMaxClientVersion, &cur_version, &client); |
63 if (result != ERROR_SUCCESS) | 63 if (result != ERROR_SUCCESS) |
64 return wlan_connection_attributes.Pass(); | 64 return wlan_connection_attributes; |
65 | 65 |
66 WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; | 66 WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; |
67 result = | 67 result = |
68 wlanapi.enum_interfaces_func(client.Get(), NULL, &interface_list_ptr); | 68 wlanapi.enum_interfaces_func(client.Get(), NULL, &interface_list_ptr); |
69 if (result != ERROR_SUCCESS) | 69 if (result != ERROR_SUCCESS) |
70 return wlan_connection_attributes.Pass(); | 70 return wlan_connection_attributes; |
71 scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list( | 71 scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list( |
72 interface_list_ptr); | 72 interface_list_ptr); |
73 | 73 |
74 // Assume at most one connected wifi interface. | 74 // Assume at most one connected wifi interface. |
75 WLAN_INTERFACE_INFO* info = NULL; | 75 WLAN_INTERFACE_INFO* info = NULL; |
76 for (unsigned i = 0; i < interface_list->dwNumberOfItems; ++i) { | 76 for (unsigned i = 0; i < interface_list->dwNumberOfItems; ++i) { |
77 if (interface_list->InterfaceInfo[i].isState == | 77 if (interface_list->InterfaceInfo[i].isState == |
78 wlan_interface_state_connected) { | 78 wlan_interface_state_connected) { |
79 info = &interface_list->InterfaceInfo[i]; | 79 info = &interface_list->InterfaceInfo[i]; |
80 break; | 80 break; |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 if (info == NULL) | 84 if (info == NULL) |
85 return wlan_connection_attributes.Pass(); | 85 return wlan_connection_attributes; |
86 | 86 |
87 WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr = nullptr; | 87 WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr = nullptr; |
88 DWORD conn_info_size = 0; | 88 DWORD conn_info_size = 0; |
89 WLAN_OPCODE_VALUE_TYPE op_code; | 89 WLAN_OPCODE_VALUE_TYPE op_code; |
90 result = wlanapi.query_interface_func( | 90 result = wlanapi.query_interface_func( |
91 client.Get(), &info->InterfaceGuid, wlan_intf_opcode_current_connection, | 91 client.Get(), &info->InterfaceGuid, wlan_intf_opcode_current_connection, |
92 NULL, &conn_info_size, reinterpret_cast<VOID**>(&conn_info_ptr), | 92 NULL, &conn_info_size, reinterpret_cast<VOID**>(&conn_info_ptr), |
93 &op_code); | 93 &op_code); |
94 wlan_connection_attributes.reset(conn_info_ptr); | 94 wlan_connection_attributes.reset(conn_info_ptr); |
95 if (result == ERROR_SUCCESS) | 95 if (result == ERROR_SUCCESS) |
96 DCHECK(conn_info_ptr); | 96 DCHECK(conn_info_ptr); |
97 else | 97 else |
98 wlan_connection_attributes.reset(); | 98 wlan_connection_attributes.reset(); |
99 return wlan_connection_attributes.Pass(); | 99 return wlan_connection_attributes; |
100 } | 100 } |
101 | 101 |
102 } // namespace | 102 } // namespace |
103 | 103 |
104 namespace internal { | 104 namespace internal { |
105 | 105 |
106 base::LazyInstance<WlanApi>::Leaky lazy_wlanapi = | 106 base::LazyInstance<WlanApi>::Leaky lazy_wlanapi = |
107 LAZY_INSTANCE_INITIALIZER; | 107 LAZY_INSTANCE_INITIALIZER; |
108 | 108 |
109 WlanApi& WlanApi::GetInstance() { | 109 WlanApi& WlanApi::GetInstance() { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 339 |
340 if (!conn_info.get()) | 340 if (!conn_info.get()) |
341 return ""; | 341 return ""; |
342 | 342 |
343 const DOT11_SSID dot11_ssid = conn_info->wlanAssociationAttributes.dot11Ssid; | 343 const DOT11_SSID dot11_ssid = conn_info->wlanAssociationAttributes.dot11Ssid; |
344 return std::string(reinterpret_cast<const char*>(dot11_ssid.ucSSID), | 344 return std::string(reinterpret_cast<const char*>(dot11_ssid.ucSSID), |
345 dot11_ssid.uSSIDLength); | 345 dot11_ssid.uSSIDLength); |
346 } | 346 } |
347 | 347 |
348 } // namespace net | 348 } // namespace net |
OLD | NEW |