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 #include <wlanapi.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 reinterpret_cast<IP_ADAPTER_ADDRESSES*>(buf.get()); | 193 reinterpret_cast<IP_ADAPTER_ADDRESSES*>(buf.get()); |
| 194 result = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapters, &len); | 194 result = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapters, &len); |
| 195 if (result != NO_ERROR) { | 195 if (result != NO_ERROR) { |
| 196 LOG(ERROR) << "GetAdaptersAddresses failed: " << result; | 196 LOG(ERROR) << "GetAdaptersAddresses failed: " << result; |
| 197 return false; | 197 return false; |
| 198 } | 198 } |
| 199 | 199 |
| 200 return internal::GetNetworkListImpl(networks, policy, is_xp, adapters); | 200 return internal::GetNetworkListImpl(networks, policy, is_xp, adapters); |
| 201 } | 201 } |
| 202 | 202 |
| 203 WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { | 203 // Returns scoped_ptr to WLAN_CONNECTION_ATTRIBUTES. The scoped_ptr may hold a |
| 204 // NULL pointer if WLAN_CONNECTION_ATTRIBUTES is unavailable. | |
| 205 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> | |
| 206 GetConnectionAttributes() { | |
|
pauljensen
2015/07/31 12:59:42
Move this function up into the anonymous namespace
tbansal1
2015/07/31 19:49:43
Done.
| |
| 204 const internal::WlanApi& wlanapi = internal::WlanApi::GetInstance(); | 207 const internal::WlanApi& wlanapi = internal::WlanApi::GetInstance(); |
| 205 if (!wlanapi.initialized) | 208 if (!wlanapi.initialized) |
| 206 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 209 return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(); |
| 207 | 210 |
| 208 internal::WlanHandle client; | 211 internal::WlanHandle client; |
| 209 DWORD cur_version = 0; | 212 DWORD cur_version = 0; |
| 210 const DWORD kMaxClientVersion = 2; | 213 const DWORD kMaxClientVersion = 2; |
| 211 { | 214 { |
| 212 // TODO(rtenneti): Remove ScopedTracker below once crbug.com/422516 is | 215 // TODO(rtenneti): Remove ScopedTracker below once crbug.com/422516 is |
| 213 // fixed. | 216 // fixed. |
| 214 tracked_objects::ScopedTracker tracking_profile( | 217 tracked_objects::ScopedTracker tracking_profile( |
| 215 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 OpenHandle()")); | 218 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 OpenHandle()")); |
| 216 DWORD result = wlanapi.OpenHandle(kMaxClientVersion, &cur_version, &client); | 219 DWORD result = wlanapi.OpenHandle(kMaxClientVersion, &cur_version, &client); |
| 217 if (result != ERROR_SUCCESS) | 220 if (result != ERROR_SUCCESS) |
| 218 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 221 return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(); |
| 219 } | 222 } |
| 220 | 223 |
| 221 WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; | 224 WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; |
| 222 DWORD result = | 225 DWORD result = |
| 223 wlanapi.enum_interfaces_func(client.Get(), NULL, &interface_list_ptr); | 226 wlanapi.enum_interfaces_func(client.Get(), NULL, &interface_list_ptr); |
| 224 if (result != ERROR_SUCCESS) | 227 if (result != ERROR_SUCCESS) |
| 225 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 228 return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(); |
| 226 scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list( | 229 scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list( |
| 227 interface_list_ptr); | 230 interface_list_ptr); |
| 228 | 231 |
| 229 // Assume at most one connected wifi interface. | 232 // Assume at most one connected wifi interface. |
| 230 WLAN_INTERFACE_INFO* info = NULL; | 233 WLAN_INTERFACE_INFO* info = NULL; |
| 231 for (unsigned i = 0; i < interface_list->dwNumberOfItems; ++i) { | 234 for (unsigned i = 0; i < interface_list->dwNumberOfItems; ++i) { |
| 232 if (interface_list->InterfaceInfo[i].isState == | 235 if (interface_list->InterfaceInfo[i].isState == |
| 233 wlan_interface_state_connected) { | 236 wlan_interface_state_connected) { |
| 234 info = &interface_list->InterfaceInfo[i]; | 237 info = &interface_list->InterfaceInfo[i]; |
| 235 break; | 238 break; |
| 236 } | 239 } |
| 237 } | 240 } |
| 238 | 241 |
| 239 if (info == NULL) | 242 if (info == NULL) |
| 240 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 243 return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(); |
| 241 | 244 |
| 242 WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr; | 245 WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr = nullptr; |
| 243 DWORD conn_info_size = 0; | 246 DWORD conn_info_size = 0; |
| 244 WLAN_OPCODE_VALUE_TYPE op_code; | 247 WLAN_OPCODE_VALUE_TYPE op_code; |
| 245 result = wlanapi.query_interface_func( | 248 result = wlanapi.query_interface_func( |
| 246 client.Get(), &info->InterfaceGuid, wlan_intf_opcode_current_connection, | 249 client.Get(), &info->InterfaceGuid, wlan_intf_opcode_current_connection, |
| 247 NULL, &conn_info_size, reinterpret_cast<VOID**>(&conn_info_ptr), | 250 NULL, &conn_info_size, reinterpret_cast<VOID**>(&conn_info_ptr), |
| 248 &op_code); | 251 &op_code); |
| 249 if (result != ERROR_SUCCESS) | 252 if (result != ERROR_SUCCESS) |
| 250 return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; | 253 return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(); |
| 251 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info( | 254 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info( |
| 252 conn_info_ptr); | 255 conn_info_ptr); |
| 253 | 256 |
| 257 DCHECK(conn_info.get()); | |
| 258 return conn_info.Pass(); | |
|
pauljensen
2015/07/31 12:59:42
Lets change these five lines to:
DCHECK(conn_info_
tbansal1
2015/07/31 19:49:43
Done.
| |
| 259 } | |
| 260 | |
| 261 WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { | |
| 262 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info = | |
|
pauljensen
2015/07/31 12:59:42
I think using auto here might be nice as the type
tbansal1
2015/07/31 19:49:43
Done.
| |
| 263 GetConnectionAttributes(); | |
| 264 | |
| 265 if (!conn_info.get()) | |
| 266 return WIFI_PHY_LAYER_PROTOCOL_NONE; | |
| 267 | |
| 254 switch (conn_info->wlanAssociationAttributes.dot11PhyType) { | 268 switch (conn_info->wlanAssociationAttributes.dot11PhyType) { |
| 255 case dot11_phy_type_fhss: | 269 case dot11_phy_type_fhss: |
| 256 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; | 270 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; |
| 257 case dot11_phy_type_dsss: | 271 case dot11_phy_type_dsss: |
| 258 return WIFI_PHY_LAYER_PROTOCOL_B; | 272 return WIFI_PHY_LAYER_PROTOCOL_B; |
| 259 case dot11_phy_type_irbaseband: | 273 case dot11_phy_type_irbaseband: |
| 260 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; | 274 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; |
| 261 case dot11_phy_type_ofdm: | 275 case dot11_phy_type_ofdm: |
| 262 return WIFI_PHY_LAYER_PROTOCOL_A; | 276 return WIFI_PHY_LAYER_PROTOCOL_A; |
| 263 case dot11_phy_type_hrdsss: | 277 case dot11_phy_type_hrdsss: |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 | 335 |
| 322 private: | 336 private: |
| 323 internal::WlanHandle client_; | 337 internal::WlanHandle client_; |
| 324 }; | 338 }; |
| 325 | 339 |
| 326 scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options) { | 340 scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options) { |
| 327 return scoped_ptr<ScopedWifiOptions>(new WifiOptionSetter(options)); | 341 return scoped_ptr<ScopedWifiOptions>(new WifiOptionSetter(options)); |
| 328 } | 342 } |
| 329 | 343 |
| 330 std::string GetWifiSSID() { | 344 std::string GetWifiSSID() { |
| 331 NOTIMPLEMENTED(); | 345 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info = |
| 332 return ""; | 346 GetConnectionAttributes(); |
|
pauljensen
2015/07/31 12:59:42
ditto
tbansal1
2015/07/31 19:49:43
Done.
| |
| 347 | |
| 348 if (!conn_info.get()) | |
| 349 return ""; | |
| 350 | |
| 351 const DOT11_SSID dot11_ssid = conn_info->wlanAssociationAttributes.dot11Ssid; | |
| 352 return std::string(reinterpret_cast<const char*>(dot11_ssid.ucSSID), | |
| 353 dot11_ssid.uSSIDLength); | |
| 333 } | 354 } |
| 334 | 355 |
| 335 } // namespace net | 356 } // namespace net |
| OLD | NEW |