Chromium Code Reviews| Index: net/base/network_interfaces_win.cc |
| diff --git a/net/base/network_interfaces_win.cc b/net/base/network_interfaces_win.cc |
| index ec9aeeb19f713f4a3b2a6ed474e02184cc8279cf..80340fb580ca2283da25e04bdc070cfc040d7363 100644 |
| --- a/net/base/network_interfaces_win.cc |
| +++ b/net/base/network_interfaces_win.cc |
| @@ -200,10 +200,18 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) { |
| return internal::GetNetworkListImpl(networks, policy, is_xp, adapters); |
| } |
| -WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| +// Sets |success| to true if WLAN connection attributes are available and |
| +// returns them. |
|
pauljensen
2015/07/30 13:47:40
How about removing |success| and just returning an
tbansal1
2015/07/30 18:52:49
Done.
|
| +scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> |
| +GetConnectionAttributes(bool* success) { |
| + *success = false; |
| + WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr = nullptr; |
| + |
| const internal::WlanApi& wlanapi = internal::WlanApi::GetInstance(); |
| - if (!wlanapi.initialized) |
| - return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + if (!wlanapi.initialized) { |
| + return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>( |
| + new WLAN_CONNECTION_ATTRIBUTES()); |
|
pauljensen
2015/07/30 13:47:40
eh why not just "scoped_ptr<blah,blah>()"? ditto f
tbansal1
2015/07/30 18:52:49
Done.
|
| + } |
| internal::WlanHandle client; |
| DWORD cur_version = 0; |
| @@ -214,15 +222,19 @@ WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| tracked_objects::ScopedTracker tracking_profile( |
| FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 OpenHandle()")); |
| DWORD result = wlanapi.OpenHandle(kMaxClientVersion, &cur_version, &client); |
| - if (result != ERROR_SUCCESS) |
| - return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + if (result != ERROR_SUCCESS) { |
| + return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>( |
| + new WLAN_CONNECTION_ATTRIBUTES()); |
| + } |
| } |
| WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; |
| DWORD result = |
| wlanapi.enum_interfaces_func(client.Get(), NULL, &interface_list_ptr); |
| - if (result != ERROR_SUCCESS) |
| - return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + if (result != ERROR_SUCCESS) { |
| + return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>( |
| + new WLAN_CONNECTION_ATTRIBUTES()); |
| + } |
| scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list( |
| interface_list_ptr); |
| @@ -236,21 +248,38 @@ WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| } |
| } |
| - if (info == NULL) |
| - return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + if (info == NULL) { |
| + return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>( |
| + new WLAN_CONNECTION_ATTRIBUTES()); |
| + } |
| - WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr; |
| DWORD conn_info_size = 0; |
| WLAN_OPCODE_VALUE_TYPE op_code; |
| result = wlanapi.query_interface_func( |
| client.Get(), &info->InterfaceGuid, wlan_intf_opcode_current_connection, |
| NULL, &conn_info_size, reinterpret_cast<VOID**>(&conn_info_ptr), |
| &op_code); |
| - if (result != ERROR_SUCCESS) |
| - return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; |
| + if (result != ERROR_SUCCESS) { |
| + return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>( |
| + new WLAN_CONNECTION_ATTRIBUTES()); |
| + } |
| + |
| scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info( |
| conn_info_ptr); |
| + DCHECK(conn_info.get()); |
| + *success = true; |
| + return conn_info.Pass(); |
| +} |
| + |
| +WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| + bool success = false; |
| + scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info = |
| + GetConnectionAttributes(&success); |
| + |
| + if (!success) |
| + return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + |
| switch (conn_info->wlanAssociationAttributes.dot11PhyType) { |
| case dot11_phy_type_fhss: |
| return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; |
| @@ -328,8 +357,16 @@ scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options) { |
| } |
| std::string GetWifiSSID() { |
| - NOTIMPLEMENTED(); |
| - return ""; |
| + bool success = false; |
| + scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info = |
| + GetConnectionAttributes(&success); |
| + |
| + if (!success) |
| + return ""; |
| + |
| + const DOT11_SSID dot11_ssid = conn_info->wlanAssociationAttributes.dot11Ssid; |
| + return std::string(reinterpret_cast<const char*>(dot11_ssid.ucSSID), |
| + dot11_ssid.uSSIDLength); |
| } |
| } // namespace net |