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..de58fcf76f1dd8682ed2e4f0289830c7d6c81395 100644 |
| --- a/net/base/network_interfaces_win.cc |
| +++ b/net/base/network_interfaces_win.cc |
| @@ -49,6 +49,12 @@ NetworkChangeNotifier::ConnectionType GetNetworkInterfaceType(DWORD ifType) { |
| return type; |
| } |
| +// Get unique |network_guid| string based on |dot11_ssid|. |
| +std::string GUIDFromSSID(const DOT11_SSID& dot11_ssid) { |
|
mef
2015/07/28 16:26:30
The GUID in this name is very WiFiService / networ
tbansal1
2015/07/28 17:34:28
Inlined.
|
| + return std::string(reinterpret_cast<const char*>(dot11_ssid.ucSSID), |
| + dot11_ssid.uSSIDLength); |
| +} |
| + |
| } // namespace |
| namespace internal { |
| @@ -200,10 +206,12 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) { |
| return internal::GetNetworkListImpl(networks, policy, is_xp, adapters); |
| } |
| -WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| +// Returns true if WLAN connection attributes are available and populates |
| +// |conn_info_ptr|. |
| +bool GetConnectionAttributesPtr(WLAN_CONNECTION_ATTRIBUTES** conn_info_ptr) { |
| const internal::WlanApi& wlanapi = internal::WlanApi::GetInstance(); |
| if (!wlanapi.initialized) |
| - return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + return false; |
| internal::WlanHandle client; |
| DWORD cur_version = 0; |
| @@ -215,14 +223,14 @@ WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| 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; |
| + return false; |
| } |
| 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; |
| + return false; |
| scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list( |
| interface_list_ptr); |
| @@ -237,17 +245,27 @@ WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| } |
| if (info == NULL) |
| - return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + return false; |
| - 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); |
| + NULL, &conn_info_size, reinterpret_cast<VOID**>(conn_info_ptr), &op_code); |
| if (result != ERROR_SUCCESS) |
| - return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| +WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { |
| + WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr = NULL; |
| + if (!GetConnectionAttributesPtr(&conn_info_ptr)) { |
| + DCHECK(!conn_info_ptr); |
| + return WIFI_PHY_LAYER_PROTOCOL_NONE; |
| + } |
| + DCHECK(conn_info_ptr); |
| + |
| scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info( |
| conn_info_ptr); |
| @@ -328,8 +346,17 @@ scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options) { |
| } |
| std::string GetWifiSSID() { |
| - NOTIMPLEMENTED(); |
| - return ""; |
| + WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr = NULL; |
| + if (!GetConnectionAttributesPtr(&conn_info_ptr)) { |
| + DCHECK(!conn_info_ptr); |
| + return ""; |
| + } |
| + DCHECK(conn_info_ptr); |
| + |
| + scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info( |
| + conn_info_ptr); |
| + |
| + return GUIDFromSSID(conn_info->wlanAssociationAttributes.dot11Ssid); |
|
mef
2015/07/28 16:26:30
I wouldn't be surprised that wlanAssociationAttrib
tbansal1
2015/07/28 17:34:28
I am confused. How can the |wlanAssociationAttribu
mef
2015/07/28 17:45:09
Oops, never mind.
|
| } |
| } // namespace net |