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

Side by Side 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: Created 5 years, 4 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 NetworkChangeNotifier::CONNECTION_UNKNOWN; 42 NetworkChangeNotifier::CONNECTION_UNKNOWN;
43 if (ifType == IF_TYPE_ETHERNET_CSMACD) { 43 if (ifType == IF_TYPE_ETHERNET_CSMACD) {
44 type = NetworkChangeNotifier::CONNECTION_ETHERNET; 44 type = NetworkChangeNotifier::CONNECTION_ETHERNET;
45 } else if (ifType == IF_TYPE_IEEE80211) { 45 } else if (ifType == IF_TYPE_IEEE80211) {
46 type = NetworkChangeNotifier::CONNECTION_WIFI; 46 type = NetworkChangeNotifier::CONNECTION_WIFI;
47 } 47 }
48 // TODO(mallinath) - Cellular? 48 // TODO(mallinath) - Cellular?
49 return type; 49 return type;
50 } 50 }
51 51
52 // Get unique |network_guid| string based on |dot11_ssid|.
53 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.
54 return std::string(reinterpret_cast<const char*>(dot11_ssid.ucSSID),
55 dot11_ssid.uSSIDLength);
56 }
57
52 } // namespace 58 } // namespace
53 59
54 namespace internal { 60 namespace internal {
55 61
56 base::LazyInstance<WlanApi>::Leaky lazy_wlanapi = 62 base::LazyInstance<WlanApi>::Leaky lazy_wlanapi =
57 LAZY_INSTANCE_INITIALIZER; 63 LAZY_INSTANCE_INITIALIZER;
58 64
59 WlanApi& WlanApi::GetInstance() { 65 WlanApi& WlanApi::GetInstance() {
60 return lazy_wlanapi.Get(); 66 return lazy_wlanapi.Get();
61 } 67 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 reinterpret_cast<IP_ADAPTER_ADDRESSES*>(buf.get()); 199 reinterpret_cast<IP_ADAPTER_ADDRESSES*>(buf.get());
194 result = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapters, &len); 200 result = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapters, &len);
195 if (result != NO_ERROR) { 201 if (result != NO_ERROR) {
196 LOG(ERROR) << "GetAdaptersAddresses failed: " << result; 202 LOG(ERROR) << "GetAdaptersAddresses failed: " << result;
197 return false; 203 return false;
198 } 204 }
199 205
200 return internal::GetNetworkListImpl(networks, policy, is_xp, adapters); 206 return internal::GetNetworkListImpl(networks, policy, is_xp, adapters);
201 } 207 }
202 208
203 WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { 209 // Returns true if WLAN connection attributes are available and populates
210 // |conn_info_ptr|.
211 bool GetConnectionAttributesPtr(WLAN_CONNECTION_ATTRIBUTES** conn_info_ptr) {
204 const internal::WlanApi& wlanapi = internal::WlanApi::GetInstance(); 212 const internal::WlanApi& wlanapi = internal::WlanApi::GetInstance();
205 if (!wlanapi.initialized) 213 if (!wlanapi.initialized)
206 return WIFI_PHY_LAYER_PROTOCOL_NONE; 214 return false;
207 215
208 internal::WlanHandle client; 216 internal::WlanHandle client;
209 DWORD cur_version = 0; 217 DWORD cur_version = 0;
210 const DWORD kMaxClientVersion = 2; 218 const DWORD kMaxClientVersion = 2;
211 { 219 {
212 // TODO(rtenneti): Remove ScopedTracker below once crbug.com/422516 is 220 // TODO(rtenneti): Remove ScopedTracker below once crbug.com/422516 is
213 // fixed. 221 // fixed.
214 tracked_objects::ScopedTracker tracking_profile( 222 tracked_objects::ScopedTracker tracking_profile(
215 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 OpenHandle()")); 223 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 OpenHandle()"));
216 DWORD result = wlanapi.OpenHandle(kMaxClientVersion, &cur_version, &client); 224 DWORD result = wlanapi.OpenHandle(kMaxClientVersion, &cur_version, &client);
217 if (result != ERROR_SUCCESS) 225 if (result != ERROR_SUCCESS)
218 return WIFI_PHY_LAYER_PROTOCOL_NONE; 226 return false;
219 } 227 }
220 228
221 WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; 229 WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL;
222 DWORD result = 230 DWORD result =
223 wlanapi.enum_interfaces_func(client.Get(), NULL, &interface_list_ptr); 231 wlanapi.enum_interfaces_func(client.Get(), NULL, &interface_list_ptr);
224 if (result != ERROR_SUCCESS) 232 if (result != ERROR_SUCCESS)
225 return WIFI_PHY_LAYER_PROTOCOL_NONE; 233 return false;
226 scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list( 234 scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list(
227 interface_list_ptr); 235 interface_list_ptr);
228 236
229 // Assume at most one connected wifi interface. 237 // Assume at most one connected wifi interface.
230 WLAN_INTERFACE_INFO* info = NULL; 238 WLAN_INTERFACE_INFO* info = NULL;
231 for (unsigned i = 0; i < interface_list->dwNumberOfItems; ++i) { 239 for (unsigned i = 0; i < interface_list->dwNumberOfItems; ++i) {
232 if (interface_list->InterfaceInfo[i].isState == 240 if (interface_list->InterfaceInfo[i].isState ==
233 wlan_interface_state_connected) { 241 wlan_interface_state_connected) {
234 info = &interface_list->InterfaceInfo[i]; 242 info = &interface_list->InterfaceInfo[i];
235 break; 243 break;
236 } 244 }
237 } 245 }
238 246
239 if (info == NULL) 247 if (info == NULL)
240 return WIFI_PHY_LAYER_PROTOCOL_NONE; 248 return false;
241 249
242 WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr;
243 DWORD conn_info_size = 0; 250 DWORD conn_info_size = 0;
244 WLAN_OPCODE_VALUE_TYPE op_code; 251 WLAN_OPCODE_VALUE_TYPE op_code;
245 result = wlanapi.query_interface_func( 252 result = wlanapi.query_interface_func(
246 client.Get(), &info->InterfaceGuid, wlan_intf_opcode_current_connection, 253 client.Get(), &info->InterfaceGuid, wlan_intf_opcode_current_connection,
247 NULL, &conn_info_size, reinterpret_cast<VOID**>(&conn_info_ptr), 254 NULL, &conn_info_size, reinterpret_cast<VOID**>(conn_info_ptr), &op_code);
248 &op_code);
249 if (result != ERROR_SUCCESS) 255 if (result != ERROR_SUCCESS)
250 return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; 256 return false;
257
258 return true;
259 }
260
261 WifiPHYLayerProtocol GetWifiPHYLayerProtocol() {
262 WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr = NULL;
263 if (!GetConnectionAttributesPtr(&conn_info_ptr)) {
264 DCHECK(!conn_info_ptr);
265 return WIFI_PHY_LAYER_PROTOCOL_NONE;
266 }
267 DCHECK(conn_info_ptr);
268
251 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info( 269 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info(
252 conn_info_ptr); 270 conn_info_ptr);
253 271
254 switch (conn_info->wlanAssociationAttributes.dot11PhyType) { 272 switch (conn_info->wlanAssociationAttributes.dot11PhyType) {
255 case dot11_phy_type_fhss: 273 case dot11_phy_type_fhss:
256 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; 274 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT;
257 case dot11_phy_type_dsss: 275 case dot11_phy_type_dsss:
258 return WIFI_PHY_LAYER_PROTOCOL_B; 276 return WIFI_PHY_LAYER_PROTOCOL_B;
259 case dot11_phy_type_irbaseband: 277 case dot11_phy_type_irbaseband:
260 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; 278 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 339
322 private: 340 private:
323 internal::WlanHandle client_; 341 internal::WlanHandle client_;
324 }; 342 };
325 343
326 scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options) { 344 scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options) {
327 return scoped_ptr<ScopedWifiOptions>(new WifiOptionSetter(options)); 345 return scoped_ptr<ScopedWifiOptions>(new WifiOptionSetter(options));
328 } 346 }
329 347
330 std::string GetWifiSSID() { 348 std::string GetWifiSSID() {
331 NOTIMPLEMENTED(); 349 WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr = NULL;
332 return ""; 350 if (!GetConnectionAttributesPtr(&conn_info_ptr)) {
351 DCHECK(!conn_info_ptr);
352 return "";
353 }
354 DCHECK(conn_info_ptr);
355
356 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info(
357 conn_info_ptr);
358
359 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.
333 } 360 }
334 361
335 } // namespace net 362 } // namespace net
OLDNEW
« 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