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 | 9 |
9 #include <algorithm> | 10 #include <algorithm> |
10 | 11 |
| 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" |
11 #include "base/file_path.h" | 14 #include "base/file_path.h" |
12 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/scoped_native_library.h" |
13 #include "base/string_piece.h" | 17 #include "base/string_piece.h" |
14 #include "base/string_util.h" | 18 #include "base/string_util.h" |
15 #include "base/sys_string_conversions.h" | 19 #include "base/sys_string_conversions.h" |
16 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
17 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
18 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
19 #include "net/base/escape.h" | 23 #include "net/base/escape.h" |
20 #include "net/base/ip_endpoint.h" | 24 #include "net/base/ip_endpoint.h" |
21 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
22 | 26 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 std::string name = adapter->AdapterName; | 124 std::string name = adapter->AdapterName; |
121 networks->push_back(NetworkInterface(name, endpoint.address())); | 125 networks->push_back(NetworkInterface(name, endpoint.address())); |
122 } | 126 } |
123 } | 127 } |
124 } | 128 } |
125 } | 129 } |
126 | 130 |
127 return true; | 131 return true; |
128 } | 132 } |
129 | 133 |
| 134 WifiPhyMode GetWifiPhyMode() { |
| 135 typedef DWORD (WINAPI *WlanOpenHandleFunc)( |
| 136 DWORD, VOID*, DWORD*, HANDLE*); |
| 137 typedef DWORD (WINAPI *WlanEnumInterfacesFunc)( |
| 138 HANDLE, VOID*, WLAN_INTERFACE_INFO_LIST **); |
| 139 typedef DWORD (WINAPI *WlanQueryInterfaceFunc)( |
| 140 HANDLE, const GUID *, WLAN_INTF_OPCODE, VOID*, DWORD*, VOID**, |
| 141 WLAN_OPCODE_VALUE_TYPE*); |
| 142 typedef VOID (WINAPI *WlanFreeMemoryFunc)(VOID*); |
| 143 typedef DWORD (WINAPI *WlanCloseHandleFunc)(HANDLE, VOID*); |
| 144 |
| 145 base::ScopedNativeLibrary wlanapi( |
| 146 FilePath(FILE_PATH_LITERAL("wlanapi.dll"))); |
| 147 WlanOpenHandleFunc open_handle_func = reinterpret_cast<WlanOpenHandleFunc>( |
| 148 wlanapi.GetFunctionPointer("WlanOpenHandle")); |
| 149 WlanEnumInterfacesFunc enum_interfaces_func = |
| 150 reinterpret_cast<WlanEnumInterfacesFunc>( |
| 151 wlanapi.GetFunctionPointer("WlanEnumInterfaces")); |
| 152 WlanQueryInterfaceFunc query_interface_func = |
| 153 reinterpret_cast<WlanQueryInterfaceFunc>( |
| 154 wlanapi.GetFunctionPointer("WlanQueryInterface")); |
| 155 WlanFreeMemoryFunc free_memory_func = reinterpret_cast<WlanFreeMemoryFunc>( |
| 156 wlanapi.GetFunctionPointer("WlanFreeMemory")); |
| 157 WlanCloseHandleFunc close_handle_func = |
| 158 reinterpret_cast<WlanCloseHandleFunc>( |
| 159 wlanapi.GetFunctionPointer("WlanCloseHandle")); |
| 160 if (!(open_handle_func && enum_interfaces_func && query_interface_func && |
| 161 free_memory_func && close_handle_func)) { |
| 162 return WIFI_PHY_MODE_NONE; |
| 163 } |
| 164 |
| 165 HANDLE client = NULL; |
| 166 DWORD cur_version = 0; |
| 167 DWORD result = open_handle_func(2 /* max_client */, NULL, &cur_version, |
| 168 &client); |
| 169 if (result != ERROR_SUCCESS) |
| 170 return WIFI_PHY_MODE_NONE; |
| 171 base::ScopedClosureRunner close_handle( |
| 172 base::Bind(base::IgnoreResult(close_handle_func), client, (VOID*)NULL)); |
| 173 |
| 174 WLAN_INTERFACE_INFO_LIST* interface_list = NULL; |
| 175 result = enum_interfaces_func(client, NULL, &interface_list); |
| 176 if (result != ERROR_SUCCESS) |
| 177 return WIFI_PHY_MODE_NONE; |
| 178 base::ScopedClosureRunner free_interfaces( |
| 179 base::Bind(free_memory_func, interface_list)); |
| 180 |
| 181 if (interface_list->dwNumberOfItems == 0) |
| 182 return WIFI_PHY_MODE_NONE; |
| 183 |
| 184 WLAN_INTERFACE_INFO& info = interface_list->InterfaceInfo[0]; |
| 185 if (info.isState != wlan_interface_state_connected) |
| 186 return WIFI_PHY_MODE_NONE; |
| 187 |
| 188 WLAN_CONNECTION_ATTRIBUTES* conn_info = NULL; |
| 189 DWORD conn_info_size = 0; |
| 190 WLAN_OPCODE_VALUE_TYPE op_code; |
| 191 |
| 192 result = query_interface_func( |
| 193 client, &info.InterfaceGuid, wlan_intf_opcode_current_connection, NULL, |
| 194 &conn_info_size, (VOID**) &conn_info, &op_code); |
| 195 if (result != ERROR_SUCCESS) |
| 196 return WIFI_PHY_MODE_UNKNOWN; // ?? |
| 197 base::ScopedClosureRunner free_conn_info( |
| 198 base::Bind(free_memory_func, conn_info)); |
| 199 |
| 200 switch (conn_info->wlanAssociationAttributes.dot11PhyType) { |
| 201 case dot11_phy_type_fhss: |
| 202 return WIFI_PHY_MODE_ANCIENT; |
| 203 case dot11_phy_type_dsss: |
| 204 return WIFI_PHY_MODE_B; |
| 205 case dot11_phy_type_irbaseband: |
| 206 return WIFI_PHY_MODE_ANCIENT; |
| 207 case dot11_phy_type_ofdm: |
| 208 return WIFI_PHY_MODE_A; |
| 209 case dot11_phy_type_hrdsss: |
| 210 return WIFI_PHY_MODE_B; |
| 211 case dot11_phy_type_erp: |
| 212 return WIFI_PHY_MODE_G; |
| 213 case dot11_phy_type_ht: |
| 214 return WIFI_PHY_MODE_N; |
| 215 default: |
| 216 return WIFI_PHY_MODE_UNKNOWN; |
| 217 } |
| 218 } |
| 219 |
130 } // namespace net | 220 } // namespace net |
OLD | NEW |