Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Unified Diff: net/base/network_interfaces_win.cc

Issue 1265453004: Get WiFi SSID information for Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/network_interfaces.h ('k') | net/base/network_quality_estimator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « net/base/network_interfaces.h ('k') | net/base/network_quality_estimator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698