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

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: Addressed comments 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Sets |success| to true if WLAN connection attributes are available and
204 // 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.
205 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>
206 GetConnectionAttributes(bool* success) {
207 *success = false;
208 WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr = nullptr;
209
204 const internal::WlanApi& wlanapi = internal::WlanApi::GetInstance(); 210 const internal::WlanApi& wlanapi = internal::WlanApi::GetInstance();
205 if (!wlanapi.initialized) 211 if (!wlanapi.initialized) {
206 return WIFI_PHY_LAYER_PROTOCOL_NONE; 212 return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(
213 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.
214 }
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 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(
227 new WLAN_CONNECTION_ATTRIBUTES());
228 }
219 } 229 }
220 230
221 WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; 231 WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL;
222 DWORD result = 232 DWORD result =
223 wlanapi.enum_interfaces_func(client.Get(), NULL, &interface_list_ptr); 233 wlanapi.enum_interfaces_func(client.Get(), NULL, &interface_list_ptr);
224 if (result != ERROR_SUCCESS) 234 if (result != ERROR_SUCCESS) {
225 return WIFI_PHY_LAYER_PROTOCOL_NONE; 235 return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(
236 new WLAN_CONNECTION_ATTRIBUTES());
237 }
226 scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list( 238 scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list(
227 interface_list_ptr); 239 interface_list_ptr);
228 240
229 // Assume at most one connected wifi interface. 241 // Assume at most one connected wifi interface.
230 WLAN_INTERFACE_INFO* info = NULL; 242 WLAN_INTERFACE_INFO* info = NULL;
231 for (unsigned i = 0; i < interface_list->dwNumberOfItems; ++i) { 243 for (unsigned i = 0; i < interface_list->dwNumberOfItems; ++i) {
232 if (interface_list->InterfaceInfo[i].isState == 244 if (interface_list->InterfaceInfo[i].isState ==
233 wlan_interface_state_connected) { 245 wlan_interface_state_connected) {
234 info = &interface_list->InterfaceInfo[i]; 246 info = &interface_list->InterfaceInfo[i];
235 break; 247 break;
236 } 248 }
237 } 249 }
238 250
239 if (info == NULL) 251 if (info == NULL) {
240 return WIFI_PHY_LAYER_PROTOCOL_NONE; 252 return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(
253 new WLAN_CONNECTION_ATTRIBUTES());
254 }
241 255
242 WLAN_CONNECTION_ATTRIBUTES* conn_info_ptr;
243 DWORD conn_info_size = 0; 256 DWORD conn_info_size = 0;
244 WLAN_OPCODE_VALUE_TYPE op_code; 257 WLAN_OPCODE_VALUE_TYPE op_code;
245 result = wlanapi.query_interface_func( 258 result = wlanapi.query_interface_func(
246 client.Get(), &info->InterfaceGuid, wlan_intf_opcode_current_connection, 259 client.Get(), &info->InterfaceGuid, wlan_intf_opcode_current_connection,
247 NULL, &conn_info_size, reinterpret_cast<VOID**>(&conn_info_ptr), 260 NULL, &conn_info_size, reinterpret_cast<VOID**>(&conn_info_ptr),
248 &op_code); 261 &op_code);
249 if (result != ERROR_SUCCESS) 262 if (result != ERROR_SUCCESS) {
250 return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; 263 return scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter>(
264 new WLAN_CONNECTION_ATTRIBUTES());
265 }
266
251 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info( 267 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info(
252 conn_info_ptr); 268 conn_info_ptr);
253 269
270 DCHECK(conn_info.get());
271 *success = true;
272 return conn_info.Pass();
273 }
274
275 WifiPHYLayerProtocol GetWifiPHYLayerProtocol() {
276 bool success = false;
277 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info =
278 GetConnectionAttributes(&success);
279
280 if (!success)
281 return WIFI_PHY_LAYER_PROTOCOL_NONE;
282
254 switch (conn_info->wlanAssociationAttributes.dot11PhyType) { 283 switch (conn_info->wlanAssociationAttributes.dot11PhyType) {
255 case dot11_phy_type_fhss: 284 case dot11_phy_type_fhss:
256 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; 285 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT;
257 case dot11_phy_type_dsss: 286 case dot11_phy_type_dsss:
258 return WIFI_PHY_LAYER_PROTOCOL_B; 287 return WIFI_PHY_LAYER_PROTOCOL_B;
259 case dot11_phy_type_irbaseband: 288 case dot11_phy_type_irbaseband:
260 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT; 289 return WIFI_PHY_LAYER_PROTOCOL_ANCIENT;
261 case dot11_phy_type_ofdm: 290 case dot11_phy_type_ofdm:
262 return WIFI_PHY_LAYER_PROTOCOL_A; 291 return WIFI_PHY_LAYER_PROTOCOL_A;
263 case dot11_phy_type_hrdsss: 292 case dot11_phy_type_hrdsss:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 350
322 private: 351 private:
323 internal::WlanHandle client_; 352 internal::WlanHandle client_;
324 }; 353 };
325 354
326 scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options) { 355 scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options) {
327 return scoped_ptr<ScopedWifiOptions>(new WifiOptionSetter(options)); 356 return scoped_ptr<ScopedWifiOptions>(new WifiOptionSetter(options));
328 } 357 }
329 358
330 std::string GetWifiSSID() { 359 std::string GetWifiSSID() {
331 NOTIMPLEMENTED(); 360 bool success = false;
332 return ""; 361 scoped_ptr<WLAN_CONNECTION_ATTRIBUTES, internal::WlanApiDeleter> conn_info =
362 GetConnectionAttributes(&success);
363
364 if (!success)
365 return "";
366
367 const DOT11_SSID dot11_ssid = conn_info->wlanAssociationAttributes.dot11Ssid;
368 return std::string(reinterpret_cast<const char*>(dot11_ssid.ucSSID),
369 dot11_ssid.uSSIDLength);
333 } 370 }
334 371
335 } // namespace net 372 } // 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