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 true if WLAN connection attributes are available and populates |
| 204 // |conn_info_ptr|. | |
| 205 bool GetConnectionAttributesPtr(WLAN_CONNECTION_ATTRIBUTES** conn_info_ptr) { | |
|
pauljensen
2015/07/29 12:09:20
Let's not give back a raw pointer that has explici
tbansal1
2015/07/30 02:05:25
IIUC, pointer to scoped_ptr is strongly discourage
| |
| 204 const internal::WlanApi& wlanapi = internal::WlanApi::GetInstance(); | 206 const internal::WlanApi& wlanapi = internal::WlanApi::GetInstance(); |
| 205 if (!wlanapi.initialized) | 207 if (!wlanapi.initialized) |
| 206 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 208 return false; |
| 207 | 209 |
| 208 internal::WlanHandle client; | 210 internal::WlanHandle client; |
| 209 DWORD cur_version = 0; | 211 DWORD cur_version = 0; |
| 210 const DWORD kMaxClientVersion = 2; | 212 const DWORD kMaxClientVersion = 2; |
| 211 { | 213 { |
| 212 // TODO(rtenneti): Remove ScopedTracker below once crbug.com/422516 is | 214 // TODO(rtenneti): Remove ScopedTracker below once crbug.com/422516 is |
| 213 // fixed. | 215 // fixed. |
| 214 tracked_objects::ScopedTracker tracking_profile( | 216 tracked_objects::ScopedTracker tracking_profile( |
| 215 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 OpenHandle()")); | 217 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 OpenHandle()")); |
| 216 DWORD result = wlanapi.OpenHandle(kMaxClientVersion, &cur_version, &client); | 218 DWORD result = wlanapi.OpenHandle(kMaxClientVersion, &cur_version, &client); |
| 217 if (result != ERROR_SUCCESS) | 219 if (result != ERROR_SUCCESS) |
| 218 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 220 return false; |
| 219 } | 221 } |
| 220 | 222 |
| 221 WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; | 223 WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; |
| 222 DWORD result = | 224 DWORD result = |
| 223 wlanapi.enum_interfaces_func(client.Get(), NULL, &interface_list_ptr); | 225 wlanapi.enum_interfaces_func(client.Get(), NULL, &interface_list_ptr); |
| 224 if (result != ERROR_SUCCESS) | 226 if (result != ERROR_SUCCESS) |
| 225 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 227 return false; |
| 226 scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list( | 228 scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list( |
| 227 interface_list_ptr); | 229 interface_list_ptr); |
| 228 | 230 |
| 229 // Assume at most one connected wifi interface. | 231 // Assume at most one connected wifi interface. |
| 230 WLAN_INTERFACE_INFO* info = NULL; | 232 WLAN_INTERFACE_INFO* info = NULL; |
| 231 for (unsigned i = 0; i < interface_list->dwNumberOfItems; ++i) { | 233 for (unsigned i = 0; i < interface_list->dwNumberOfItems; ++i) { |
| 232 if (interface_list->InterfaceInfo[i].isState == | 234 if (interface_list->InterfaceInfo[i].isState == |
| 233 wlan_interface_state_connected) { | 235 wlan_interface_state_connected) { |
| 234 info = &interface_list->InterfaceInfo[i]; | 236 info = &interface_list->InterfaceInfo[i]; |
| 235 break; | 237 break; |
| 236 } | 238 } |
| 237 } | 239 } |
| 238 | 240 |
| 239 if (info == NULL) | 241 if (info == NULL) |
| 240 return WIFI_PHY_LAYER_PROTOCOL_NONE; | 242 return false; |
| 241 | 243 |
| 242 WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr; | |
| 243 DWORD conn_info_size = 0; | 244 DWORD conn_info_size = 0; |
| 244 WLAN_OPCODE_VALUE_TYPE op_code; | 245 WLAN_OPCODE_VALUE_TYPE op_code; |
| 245 result = wlanapi.query_interface_func( | 246 result = wlanapi.query_interface_func( |
| 246 client.Get(), &info->InterfaceGuid, wlan_intf_opcode_current_connection, | 247 client.Get(), &info->InterfaceGuid, wlan_intf_opcode_current_connection, |
| 247 NULL, &conn_info_size, reinterpret_cast<VOID**>(&conn_info_ptr), | 248 NULL, &conn_info_size, reinterpret_cast<VOID**>(conn_info_ptr), &op_code); |
| 248 &op_code); | |
| 249 if (result != ERROR_SUCCESS) | 249 if (result != ERROR_SUCCESS) |
|
pauljensen
2015/07/29 12:09:20
how about combining these lines into "return resul
tbansal1
2015/07/30 02:05:25
After moving DCHECK up, this becomes obsolete.
| |
| 250 return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; | 250 return false; |
| 251 | |
| 252 return true; | |
| 253 } | |
| 254 | |
| 255 WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { | |
| 256 WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr = NULL; | |
|
pauljensen
2015/07/29 12:09:20
nullptr?
tbansal1
2015/07/30 02:05:25
Done.
| |
| 257 if (!GetConnectionAttributesPtr(&conn_info_ptr)) { | |
| 258 DCHECK(!conn_info_ptr); | |
|
pauljensen
2015/07/29 12:09:20
I don't think WlanQueryInterface is guaranteed to
tbansal1
2015/07/30 02:05:25
Done.
| |
| 259 return WIFI_PHY_LAYER_PROTOCOL_NONE; | |
| 260 } | |
| 261 DCHECK(conn_info_ptr); | |
|
pauljensen
2015/07/29 12:09:20
Can we move this into GetConnectionAttributesPtr?
tbansal1
2015/07/30 02:05:25
Done.
| |
| 262 | |
| 251 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info( | 263 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info( |
| 252 conn_info_ptr); | 264 conn_info_ptr); |
| 253 | 265 |
| 254 switch (conn_info->wlanAssociationAttributes.dot11PhyType) { | 266 switch (conn_info->wlanAssociationAttributes.dot11PhyType) { |
| 255 case dot11_phy_type_fhss: | 267 case dot11_phy_type_fhss: |
| 256 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; | 268 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; |
| 257 case dot11_phy_type_dsss: | 269 case dot11_phy_type_dsss: |
| 258 return WIFI_PHY_LAYER_PROTOCOL_B; | 270 return WIFI_PHY_LAYER_PROTOCOL_B; |
| 259 case dot11_phy_type_irbaseband: | 271 case dot11_phy_type_irbaseband: |
| 260 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; | 272 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 | 333 |
| 322 private: | 334 private: |
| 323 internal::WlanHandle client_; | 335 internal::WlanHandle client_; |
| 324 }; | 336 }; |
| 325 | 337 |
| 326 scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options) { | 338 scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options) { |
| 327 return scoped_ptr<ScopedWifiOptions>(new WifiOptionSetter(options)); | 339 return scoped_ptr<ScopedWifiOptions>(new WifiOptionSetter(options)); |
| 328 } | 340 } |
| 329 | 341 |
| 330 std::string GetWifiSSID() { | 342 std::string GetWifiSSID() { |
| 331 NOTIMPLEMENTED(); | 343 WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr = NULL; |
|
pauljensen
2015/07/29 12:09:20
nullptr?
tbansal1
2015/07/30 02:05:25
Done.
| |
| 332 return ""; | 344 if (!GetConnectionAttributesPtr(&conn_info_ptr)) { |
| 345 DCHECK(!conn_info_ptr); | |
| 346 return ""; | |
| 347 } | |
| 348 DCHECK(conn_info_ptr); | |
| 349 | |
| 350 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info( | |
| 351 conn_info_ptr); | |
| 352 const DOT11_SSID dot11_ssid = conn_info->wlanAssociationAttributes.dot11Ssid; | |
| 353 return std::string(reinterpret_cast<const char*>(dot11_ssid.ucSSID), | |
| 354 dot11_ssid.uSSIDLength); | |
| 333 } | 355 } |
| 334 | 356 |
| 335 } // namespace net | 357 } // namespace net |
| OLD | NEW |