Chromium Code Reviews| 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" | |
|
rvargas (doing something else)
2013/02/11 21:14:44
not good.
Note that I failed to mention the other
szym
2013/02/11 22:51:19
Done.
| |
| 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; | |
|
rvargas (doing something else)
2013/02/11 21:14:44
This should be a GenericScopedHandle with a custom
szym
2013/02/11 22:51:19
Done.
| |
| 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; | |
|
rvargas (doing something else)
2013/02/11 21:14:44
scoped_ptr with custom Deleter
szym
2013/02/11 22:51:19
Done, although there does not seem to be something
| |
| 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 // Assume one wifi interface. | |
| 185 WLAN_INTERFACE_INFO& info = interface_list->InterfaceInfo[0]; | |
| 186 if (info.isState != wlan_interface_state_connected) | |
| 187 return WIFI_PHY_MODE_NONE; | |
|
rvargas (doing something else)
2013/02/11 21:14:44
look at the next interface?
szym
2013/02/11 22:51:19
Done.
| |
| 188 | |
| 189 WLAN_CONNECTION_ATTRIBUTES* conn_info = NULL; | |
|
rvargas (doing something else)
2013/02/11 21:14:44
same here
szym
2013/02/11 22:51:19
Done.
| |
| 190 DWORD conn_info_size = 0; | |
| 191 WLAN_OPCODE_VALUE_TYPE op_code; | |
| 192 | |
| 193 result = query_interface_func( | |
| 194 client, &info.InterfaceGuid, wlan_intf_opcode_current_connection, NULL, | |
| 195 &conn_info_size, (VOID**)&conn_info, &op_code); | |
|
rvargas (doing something else)
2013/02/11 21:14:44
c++ cast (Doesn't this work without a cast?)
szym
2013/02/11 22:51:19
Done.
| |
| 196 if (result != ERROR_SUCCESS) | |
| 197 return WIFI_PHY_MODE_UNKNOWN; | |
| 198 base::ScopedClosureRunner free_conn_info( | |
| 199 base::Bind(free_memory_func, conn_info)); | |
| 200 | |
| 201 switch (conn_info->wlanAssociationAttributes.dot11PhyType) { | |
| 202 case dot11_phy_type_fhss: | |
| 203 return WIFI_PHY_MODE_ANCIENT; | |
| 204 case dot11_phy_type_dsss: | |
| 205 return WIFI_PHY_MODE_B; | |
| 206 case dot11_phy_type_irbaseband: | |
| 207 return WIFI_PHY_MODE_ANCIENT; | |
| 208 case dot11_phy_type_ofdm: | |
| 209 return WIFI_PHY_MODE_A; | |
| 210 case dot11_phy_type_hrdsss: | |
| 211 return WIFI_PHY_MODE_B; | |
| 212 case dot11_phy_type_erp: | |
| 213 return WIFI_PHY_MODE_G; | |
| 214 case dot11_phy_type_ht: | |
| 215 return WIFI_PHY_MODE_N; | |
| 216 default: | |
| 217 return WIFI_PHY_MODE_UNKNOWN; | |
| 218 } | |
| 219 } | |
| 220 | |
| 130 } // namespace net | 221 } // namespace net |
| OLD | NEW |