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

Side by Side Diff: components/wifi/wifi_service_win.cc

Issue 245313002: WiFiService::GetProperties now correctly populates BSSID and Frequency of connected network. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address codereview comments. Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/wifi/wifi_service.h" 5 #include "components/wifi/wifi_service.h"
6 6
7 #include <iphlpapi.h> 7 #include <iphlpapi.h>
8 #include <objbase.h> 8 #include <objbase.h>
9 #include <wlanapi.h> 9 #include <wlanapi.h>
10 10
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 319 }
320 320
321 // Get unique |network_guid| string based on |wlan|. 321 // Get unique |network_guid| string based on |wlan|.
322 std::string GUIDFromWLAN(const WLAN_AVAILABLE_NETWORK& wlan) const { 322 std::string GUIDFromWLAN(const WLAN_AVAILABLE_NETWORK& wlan) const {
323 return SSIDFromWLAN(wlan); 323 return SSIDFromWLAN(wlan);
324 } 324 }
325 325
326 // Deduce |onc::wifi| security from |alg|. 326 // Deduce |onc::wifi| security from |alg|.
327 std::string SecurityFromDot11AuthAlg(DOT11_AUTH_ALGORITHM alg) const; 327 std::string SecurityFromDot11AuthAlg(DOT11_AUTH_ALGORITHM alg) const;
328 328
329 // Deduce |onc::connection_state| from |wlan_state|.
330 std::string ConnectionStateFromInterfaceState(
331 WLAN_INTERFACE_STATE wlan_state) const;
332
329 // Convert |EncryptionType| into WPA(2) encryption type string. 333 // Convert |EncryptionType| into WPA(2) encryption type string.
330 std::string WpaEncryptionFromEncryptionType( 334 std::string WpaEncryptionFromEncryptionType(
331 EncryptionType encryption_type) const; 335 EncryptionType encryption_type) const;
332 336
333 // Deduce WLANProfile |authEncryption| values from |onc::wifi| security. 337 // Deduce WLANProfile |authEncryption| values from |onc::wifi| security.
334 bool AuthEncryptionFromSecurity(const std::string& security, 338 bool AuthEncryptionFromSecurity(const std::string& security,
335 EncryptionType encryption_type, 339 EncryptionType encryption_type,
336 std::string* authentication, 340 std::string* authentication,
337 std::string* encryption, 341 std::string* encryption,
338 std::string* key_type) const; 342 std::string* key_type) const;
339 343
340 // Populate |properties| based on |wlan| and its corresponding bss info from 344 // Populate |properties| based on |wlan|.
341 // |wlan_bss_list|.
342 void NetworkPropertiesFromAvailableNetwork(const WLAN_AVAILABLE_NETWORK& wlan, 345 void NetworkPropertiesFromAvailableNetwork(const WLAN_AVAILABLE_NETWORK& wlan,
343 const WLAN_BSS_LIST& wlan_bss_list,
344 NetworkProperties* properties); 346 NetworkProperties* properties);
345 347
348 // Update |properties| based on bss info from |wlan_bss_list|. If |bssid| in
349 // |properties| is not empty, then it is not changed and |frequency| is set
350 // based on that bssid.
351 void UpdateNetworkPropertiesFromBssList(const std::string& network_guid,
352 const WLAN_BSS_LIST& wlan_bss_list,
353 NetworkProperties* properties);
354
346 // Get the list of visible wireless networks. 355 // Get the list of visible wireless networks.
347 DWORD GetVisibleNetworkList(NetworkList* network_list); 356 DWORD GetVisibleNetworkList(NetworkList* network_list);
348 357
349 // Find currently connected network if any. Populate |connected_network_guid| 358 // Find currently connected network if any. Populate |connected_properties|
350 // on success. 359 // on success.
351 DWORD FindConnectedNetwork(std::string* connected_network_guid); 360 DWORD GetConnectedProperties(NetworkProperties* connected_properties);
352 361
353 // Connect to network |network_guid| using previosly stored profile if exists, 362 // Connect to network |network_guid| using previosly stored profile if exists,
354 // or just network sid. If |frequency| is not |kFrequencyUnknown| then 363 // or just network sid. If |frequency| is not |kFrequencyUnknown| then
355 // connects only to BSS which uses that frequency and returns 364 // connects only to BSS which uses that frequency and returns
356 // |ERROR_NOT_FOUND| if such BSS cannot be found. 365 // |ERROR_NOT_FOUND| if such BSS cannot be found.
357 DWORD Connect(const std::string& network_guid, Frequency frequency); 366 DWORD Connect(const std::string& network_guid, Frequency frequency);
358 367
359 // Disconnect from currently connected network if any. 368 // Disconnect from currently connected network if any.
360 DWORD Disconnect(); 369 DWORD Disconnect();
361 370
362 // Get Frequency of currently connected network |network_guid|. If network is
363 // not connected, then return |kFrequencyUnknown|.
364 Frequency GetConnectedFrequency(const std::string& network_guid);
365
366 // Get desired connection freqency if it was set using |SetProperties|. 371 // Get desired connection freqency if it was set using |SetProperties|.
367 // Default to |kFrequencyAny|. 372 // Default to |kFrequencyAny|.
368 Frequency GetFrequencyToConnect(const std::string& network_guid) const; 373 Frequency GetFrequencyToConnect(const std::string& network_guid) const;
369 374
370 // Get DOT11_BSSID_LIST of desired BSSIDs to connect to |ssid| network on 375 // Get DOT11_BSSID_LIST of desired BSSIDs to connect to |ssid| network on
371 // given |frequency|. 376 // given |frequency|.
372 DWORD GetDesiredBssList(DOT11_SSID& ssid, 377 DWORD GetDesiredBssList(DOT11_SSID& ssid,
373 Frequency frequency, 378 Frequency frequency,
374 scoped_ptr<DOT11_BSSID_LIST>* desired_list); 379 scoped_ptr<DOT11_BSSID_LIST>* desired_list);
375 380
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 504 }
500 505
501 void WiFiServiceImpl::UnInitialize() { 506 void WiFiServiceImpl::UnInitialize() {
502 CloseClientHandle(); 507 CloseClientHandle();
503 } 508 }
504 509
505 void WiFiServiceImpl::GetProperties(const std::string& network_guid, 510 void WiFiServiceImpl::GetProperties(const std::string& network_guid,
506 base::DictionaryValue* properties, 511 base::DictionaryValue* properties,
507 std::string* error) { 512 std::string* error) {
508 DWORD error_code = EnsureInitialized(); 513 DWORD error_code = EnsureInitialized();
514 if (CheckError(error_code, kWiFiServiceError, error))
515 return;
516
517 NetworkProperties connected_properties;
518 error_code = GetConnectedProperties(&connected_properties);
519 if (error_code == ERROR_SUCCESS &&
520 connected_properties.guid == network_guid) {
521 properties->Swap(connected_properties.ToValue(false).get());
522 return;
523 }
524
525 NetworkList network_list;
526 error_code = GetVisibleNetworkList(&network_list);
509 if (error_code == ERROR_SUCCESS) { 527 if (error_code == ERROR_SUCCESS) {
510 NetworkList network_list; 528 NetworkList::const_iterator it = FindNetwork(network_list, network_guid);
511 error_code = GetVisibleNetworkList(&network_list); 529 if (it != network_list.end()) {
512 if (error_code == ERROR_SUCCESS && !network_list.empty()) { 530 DVLOG(1) << "Get Properties: " << network_guid << ":"
513 NetworkList::const_iterator it = FindNetwork(network_list, network_guid); 531 << it->connection_state;
514 if (it != network_list.end()) { 532 properties->Swap(it->ToValue(false).get());
515 DVLOG(1) << "Get Properties: " << network_guid << ":" 533 return;
516 << it->connection_state;
517 properties->Swap(it->ToValue(false).get());
518 return;
519 } else {
520 error_code = ERROR_NOT_FOUND;
521 }
522 } 534 }
535 error_code = ERROR_NOT_FOUND;
523 } 536 }
524 537
525 CheckError(error_code, kWiFiServiceError, error); 538 CheckError(error_code, kWiFiServiceError, error);
526 } 539 }
527 540
528 void WiFiServiceImpl::GetManagedProperties( 541 void WiFiServiceImpl::GetManagedProperties(
529 const std::string& network_guid, 542 const std::string& network_guid,
530 base::DictionaryValue* managed_properties, 543 base::DictionaryValue* managed_properties,
531 std::string* error) { 544 std::string* error) {
532 CheckError(ERROR_CALL_NOT_IMPLEMENTED, kWiFiServiceError, error); 545 CheckError(ERROR_CALL_NOT_IMPLEMENTED, kWiFiServiceError, error);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 DVLOG(1) << "Start Connect: " << network_guid; 662 DVLOG(1) << "Start Connect: " << network_guid;
650 DWORD error_code = EnsureInitialized(); 663 DWORD error_code = EnsureInitialized();
651 if (error_code == ERROR_SUCCESS) { 664 if (error_code == ERROR_SUCCESS) {
652 std::string connected_network_guid; 665 std::string connected_network_guid;
653 error_code = SaveCurrentConnectedNetwork(&connected_network_guid); 666 error_code = SaveCurrentConnectedNetwork(&connected_network_guid);
654 if (error_code == ERROR_SUCCESS) { 667 if (error_code == ERROR_SUCCESS) {
655 // Check, if the network is already connected on desired frequency. 668 // Check, if the network is already connected on desired frequency.
656 bool already_connected = (network_guid == connected_network_guid); 669 bool already_connected = (network_guid == connected_network_guid);
657 Frequency frequency = GetFrequencyToConnect(network_guid); 670 Frequency frequency = GetFrequencyToConnect(network_guid);
658 if (already_connected && frequency != kFrequencyAny) { 671 if (already_connected && frequency != kFrequencyAny) {
659 Frequency connected_frequency = GetConnectedFrequency(network_guid); 672 NetworkProperties connected_properties;
660 already_connected = (frequency == connected_frequency); 673 if (GetConnectedProperties(&connected_properties) == ERROR_SUCCESS) {
674 already_connected = frequency == connected_properties.frequency &&
675 network_guid == connected_properties.guid;
676 }
661 } 677 }
662 // Connect only if network |network_guid| is not connected already. 678 // Connect only if network |network_guid| is not connected already.
663 if (!already_connected) 679 if (!already_connected)
664 error_code = Connect(network_guid, frequency); 680 error_code = Connect(network_guid, frequency);
665 if (error_code == ERROR_SUCCESS) { 681 if (error_code == ERROR_SUCCESS) {
666 // Notify that previously connected network has changed. 682 // Notify that previously connected network has changed.
667 NotifyNetworkChanged(connected_network_guid); 683 NotifyNetworkChanged(connected_network_guid);
668 // Start waiting for network connection state change. 684 // Start waiting for network connection state change.
669 if (!networks_changed_observer_.is_null()) { 685 if (!networks_changed_observer_.is_null()) {
670 DisableNwCategoryWizard(); 686 DisableNwCategoryWizard();
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 LOG(ERROR) << "Failed to delete created profile for " << network_guid 887 LOG(ERROR) << "Failed to delete created profile for " << network_guid
872 << " error=" << error_code; 888 << " error=" << error_code;
873 } 889 }
874 } 890 }
875 } 891 }
876 // Restore automatic network change notifications and stop waiting. 892 // Restore automatic network change notifications and stop waiting.
877 enable_notify_network_changed_ = true; 893 enable_notify_network_changed_ = true;
878 RestoreNwCategoryWizard(); 894 RestoreNwCategoryWizard();
879 return; 895 return;
880 } 896 }
881 std::string connected_network_guid; 897 NetworkProperties connected_network_properties;
882 DWORD error = FindConnectedNetwork(&connected_network_guid); 898 DWORD error = GetConnectedProperties(&connected_network_properties);
883 if (network_guid == connected_network_guid) { 899 if (network_guid == connected_network_properties.guid) {
tbarzic 2014/04/22 04:59:10 && connected_network_properties.connection_state =
mef 2014/04/22 16:43:52 Done.
884 DVLOG(1) << "WiFi Connected, Reset DHCP: " << network_guid; 900 DVLOG(1) << "WiFi Connected, Reset DHCP: " << network_guid;
885 // Even though wireless network is now connected, it may still be unusable, 901 // Even though wireless network is now connected, it may still be unusable,
886 // e.g. after Chromecast device reset. Reset DHCP on wireless network to 902 // e.g. after Chromecast device reset. Reset DHCP on wireless network to
887 // work around this issue. 903 // work around this issue.
888 error = ResetDHCP(); 904 error = ResetDHCP();
889 // There is no need to keep created profile as network is connected. 905 // There is no need to keep created profile as network is connected.
890 created_profiles_.RemoveWithoutPathExpansion(network_guid, NULL); 906 created_profiles_.RemoveWithoutPathExpansion(network_guid, NULL);
891 // Restore previously suppressed notifications. 907 // Restore previously suppressed notifications.
892 enable_notify_network_changed_ = true; 908 enable_notify_network_changed_ = true;
tbarzic 2014/04/22 04:59:10 is enable_notify_network_changed_ still needed?
mef 2014/04/22 16:43:52 Yes, until |GetConnectedProperties| takes network
893 RestoreNwCategoryWizard(); 909 RestoreNwCategoryWizard();
894 NotifyNetworkChanged(network_guid); 910 NotifyNetworkChanged(network_guid);
895 } else { 911 } else {
896 // Continue waiting for network connection state change. 912 // Continue waiting for network connection state change.
897 task_runner_->PostDelayedTask( 913 task_runner_->PostDelayedTask(
898 FROM_HERE, 914 FROM_HERE,
899 base::Bind(&WiFiServiceImpl::WaitForNetworkConnect, 915 base::Bind(&WiFiServiceImpl::WaitForNetworkConnect,
900 base::Unretained(this), 916 base::Unretained(this),
901 network_guid, 917 network_guid,
902 ++attempt), 918 ++attempt),
(...skipping 19 matching lines...) Expand all
922 ++it) { 938 ++it) {
923 if (it->guid == network_guid) 939 if (it->guid == network_guid)
924 return it; 940 return it;
925 } 941 }
926 return networks.end(); 942 return networks.end();
927 } 943 }
928 944
929 DWORD WiFiServiceImpl::SaveCurrentConnectedNetwork( 945 DWORD WiFiServiceImpl::SaveCurrentConnectedNetwork(
930 std::string* connected_network_guid) { 946 std::string* connected_network_guid) {
931 // Find currently connected network. 947 // Find currently connected network.
932 DWORD error = FindConnectedNetwork(connected_network_guid); 948 NetworkProperties connected_network_properties;
933 if (error == ERROR_SUCCESS && !connected_network_guid->empty()) { 949 DWORD error = GetConnectedProperties(&connected_network_properties);
950 if (error == ERROR_SUCCESS && !connected_network_properties.guid.empty()) {
951 *connected_network_guid = connected_network_properties.guid;
952 SaveTempProfile(*connected_network_guid);
953 std::string profile_xml;
954 error = GetProfile(*connected_network_guid, false, &profile_xml);
934 if (error == ERROR_SUCCESS) { 955 if (error == ERROR_SUCCESS) {
935 SaveTempProfile(*connected_network_guid); 956 saved_profiles_xml_[*connected_network_guid] = profile_xml;
936 std::string profile_xml;
937 error = GetProfile(*connected_network_guid, false, &profile_xml);
938 if (error == ERROR_SUCCESS) {
939 saved_profiles_xml_[*connected_network_guid] = profile_xml;
940 }
941 } 957 }
942 } 958 }
943 return error; 959 return error;
944 } 960 }
945 961
946 void WiFiServiceImpl::SortNetworks(NetworkList* networks) { 962 void WiFiServiceImpl::SortNetworks(NetworkList* networks) {
947 networks->sort(NetworkProperties::OrderByType); 963 networks->sort(NetworkProperties::OrderByType);
948 } 964 }
949 965
950 DWORD WiFiServiceImpl::LoadWlanLibrary() { 966 DWORD WiFiServiceImpl::LoadWlanLibrary() {
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 return onc::wifi::kWPA_PSK; 1241 return onc::wifi::kWPA_PSK;
1226 case DOT11_AUTH_ALGO_80211_SHARED_KEY: 1242 case DOT11_AUTH_ALGO_80211_SHARED_KEY:
1227 return onc::wifi::kWEP_PSK; 1243 return onc::wifi::kWEP_PSK;
1228 case DOT11_AUTH_ALGO_80211_OPEN: 1244 case DOT11_AUTH_ALGO_80211_OPEN:
1229 return onc::wifi::kNone; 1245 return onc::wifi::kNone;
1230 default: 1246 default:
1231 return onc::wifi::kWPA_EAP; 1247 return onc::wifi::kWPA_EAP;
1232 } 1248 }
1233 } 1249 }
1234 1250
1251 std::string WiFiServiceImpl::ConnectionStateFromInterfaceState(
1252 WLAN_INTERFACE_STATE wlan_state) const {
1253 switch (wlan_state) {
1254 case wlan_interface_state_connected:
1255 // TODO(mef): Even if |wlan_state| is connected, the network may still
1256 // not be reachable, and should be resported as |kConnecting|.
1257 return onc::connection_state::kConnected;
1258 case wlan_interface_state_associating:
1259 case wlan_interface_state_discovering:
1260 case wlan_interface_state_authenticating:
1261 return onc::connection_state::kConnecting;
1262 default:
1263 return onc::connection_state::kNotConnected;
1264 }
1265 }
1266
1235 void WiFiServiceImpl::NetworkPropertiesFromAvailableNetwork( 1267 void WiFiServiceImpl::NetworkPropertiesFromAvailableNetwork(
1236 const WLAN_AVAILABLE_NETWORK& wlan, 1268 const WLAN_AVAILABLE_NETWORK& wlan,
1237 const WLAN_BSS_LIST& wlan_bss_list,
1238 NetworkProperties* properties) { 1269 NetworkProperties* properties) {
1270 // TODO(mef): It would be nice for the connection states in
1271 // getVisibleNetworks and getProperties results to be consistent.
1239 if (wlan.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) { 1272 if (wlan.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) {
1240 properties->connection_state = onc::connection_state::kConnected; 1273 properties->connection_state = onc::connection_state::kConnected;
1241 } else { 1274 } else {
1242 properties->connection_state = onc::connection_state::kNotConnected; 1275 properties->connection_state = onc::connection_state::kNotConnected;
1243 } 1276 }
1244 1277
1245 properties->ssid = SSIDFromWLAN(wlan); 1278 properties->ssid = SSIDFromWLAN(wlan);
1246 properties->name = properties->ssid; 1279 properties->name = properties->ssid;
1247 properties->guid = GUIDFromWLAN(wlan); 1280 properties->guid = GUIDFromWLAN(wlan);
1248 properties->type = onc::network_type::kWiFi; 1281 properties->type = onc::network_type::kWiFi;
1249
1250 for (size_t bss = 0; bss < wlan_bss_list.dwNumberOfItems; ++bss) {
1251 const WLAN_BSS_ENTRY& bss_entry(wlan_bss_list.wlanBssEntries[bss]);
1252 if (bss_entry.dot11Ssid.uSSIDLength == wlan.dot11Ssid.uSSIDLength &&
1253 0 == memcmp(bss_entry.dot11Ssid.ucSSID,
1254 wlan.dot11Ssid.ucSSID,
1255 bss_entry.dot11Ssid.uSSIDLength)) {
1256 properties->frequency = GetNormalizedFrequency(
1257 bss_entry.ulChCenterFrequency / 1000);
1258 properties->frequency_set.insert(properties->frequency);
1259 properties->bssid = NetworkProperties::MacAddressAsString(
1260 bss_entry.dot11Bssid);
1261 }
1262 }
1263 properties->security = 1282 properties->security =
1264 SecurityFromDot11AuthAlg(wlan.dot11DefaultAuthAlgorithm); 1283 SecurityFromDot11AuthAlg(wlan.dot11DefaultAuthAlgorithm);
1265 properties->signal_strength = wlan.wlanSignalQuality; 1284 properties->signal_strength = wlan.wlanSignalQuality;
1266 } 1285 }
1267 1286
1287 void WiFiServiceImpl::UpdateNetworkPropertiesFromBssList(
1288 const std::string& network_guid,
1289 const WLAN_BSS_LIST& wlan_bss_list,
1290 NetworkProperties* properties) {
1291 if (network_guid.empty())
1292 return;
1293
1294 DOT11_SSID ssid = SSIDFromGUID(network_guid);
1295 for (size_t bss = 0; bss < wlan_bss_list.dwNumberOfItems; ++bss) {
1296 const WLAN_BSS_ENTRY& bss_entry(wlan_bss_list.wlanBssEntries[bss]);
1297 if (bss_entry.dot11Ssid.uSSIDLength == ssid.uSSIDLength &&
1298 0 == memcmp(bss_entry.dot11Ssid.ucSSID,
1299 ssid.ucSSID,
1300 bss_entry.dot11Ssid.uSSIDLength)) {
1301 std::string bssid = NetworkProperties::MacAddressAsString(
1302 bss_entry.dot11Bssid);
1303 Frequency frequency = GetNormalizedFrequency(
1304 bss_entry.ulChCenterFrequency / 1000);
1305 properties->frequency_set.insert(frequency);
1306 if (properties->bssid.empty() || properties->bssid == bssid) {
1307 properties->frequency = frequency;
1308 properties->bssid = bssid;
1309 }
1310 }
1311 }
1312 }
1313
1268 // Get the list of visible wireless networks 1314 // Get the list of visible wireless networks
1269 DWORD WiFiServiceImpl::GetVisibleNetworkList(NetworkList* network_list) { 1315 DWORD WiFiServiceImpl::GetVisibleNetworkList(NetworkList* network_list) {
1270 if (client_ == NULL) { 1316 if (client_ == NULL) {
1271 NOTREACHED(); 1317 NOTREACHED();
1272 return ERROR_NOINTERFACE; 1318 return ERROR_NOINTERFACE;
1273 } 1319 }
1274 1320
1275 DWORD error = ERROR_SUCCESS; 1321 DWORD error = ERROR_SUCCESS;
1276 PWLAN_AVAILABLE_NETWORK_LIST available_network_list = NULL; 1322 PWLAN_AVAILABLE_NETWORK_LIST available_network_list = NULL;
1277 PWLAN_BSS_LIST bss_list = NULL; 1323 PWLAN_BSS_LIST bss_list = NULL;
(...skipping 18 matching lines...) Expand all
1296 NULL, 1342 NULL,
1297 dot11_BSS_type_any, 1343 dot11_BSS_type_any,
1298 FALSE, 1344 FALSE,
1299 NULL, 1345 NULL,
1300 &bss_list); 1346 &bss_list);
1301 if (error == ERROR_SUCCESS && NULL != bss_list) { 1347 if (error == ERROR_SUCCESS && NULL != bss_list) {
1302 for (DWORD i = 0; i < available_network_list->dwNumberOfItems; ++i) { 1348 for (DWORD i = 0; i < available_network_list->dwNumberOfItems; ++i) {
1303 NetworkProperties network_properties; 1349 NetworkProperties network_properties;
1304 NetworkPropertiesFromAvailableNetwork( 1350 NetworkPropertiesFromAvailableNetwork(
1305 available_network_list->Network[i], 1351 available_network_list->Network[i],
1306 *bss_list,
1307 &network_properties); 1352 &network_properties);
1353 UpdateNetworkPropertiesFromBssList(network_properties.guid,
1354 *bss_list,
1355 &network_properties);
1308 // Check for duplicate network guids. 1356 // Check for duplicate network guids.
1309 if (network_guids.count(network_properties.guid)) { 1357 if (network_guids.count(network_properties.guid)) {
tbarzic 2014/04/22 04:59:10 potential future cleanup: you could collect set of
mef 2014/04/22 16:43:52 sgtm.
1310 // There should be no difference between properties except for 1358 // There should be no difference between properties except for
1311 // |connection_state|, so mark it as |kConnected| if either one is. 1359 // |connection_state|, so mark it as |kConnected| if either one is.
1312 if (network_properties.connection_state == 1360 if (network_properties.connection_state ==
1313 onc::connection_state::kConnected) { 1361 onc::connection_state::kConnected) {
1314 NetworkList::iterator previous_network_properties = 1362 NetworkList::iterator previous_network_properties =
1315 FindNetwork(*network_list, network_properties.guid); 1363 FindNetwork(*network_list, network_properties.guid);
1316 DCHECK(previous_network_properties != network_list->end()); 1364 DCHECK(previous_network_properties != network_list->end());
1317 previous_network_properties->connection_state = 1365 previous_network_properties->connection_state =
1318 network_properties.connection_state; 1366 network_properties.connection_state;
1319 } 1367 }
1320 } else { 1368 } else {
1321 network_list->push_back(network_properties); 1369 network_list->push_back(network_properties);
1322 } 1370 }
1323 network_guids.insert(network_properties.guid); 1371 network_guids.insert(network_properties.guid);
1324 } 1372 }
1325 } 1373 }
1326 } 1374 }
1327 1375
1328 // Clean up. 1376 // Clean up.
1329 if (available_network_list != NULL) { 1377 if (available_network_list != NULL) {
1330 WlanFreeMemory_function_(available_network_list); 1378 WlanFreeMemory_function_(available_network_list);
1331 } 1379 }
1332 if (bss_list != NULL) { 1380 if (bss_list != NULL) {
1333 WlanFreeMemory_function_(bss_list); 1381 WlanFreeMemory_function_(bss_list);
1334 } 1382 }
1335 return error; 1383 return error;
1336 } 1384 }
1337 1385
1338 // Find currently connected network. 1386 DWORD WiFiServiceImpl::GetConnectedProperties(NetworkProperties* properties) {
1339 DWORD WiFiServiceImpl::FindConnectedNetwork(
1340 std::string* connected_network_guid) {
1341 if (client_ == NULL) { 1387 if (client_ == NULL) {
1342 NOTREACHED(); 1388 NOTREACHED();
1343 return ERROR_NOINTERFACE; 1389 return ERROR_NOINTERFACE;
1344 } 1390 }
1345 1391
1346 DWORD error = ERROR_SUCCESS;
1347 PWLAN_AVAILABLE_NETWORK_LIST available_network_list = NULL;
1348 error = WlanGetAvailableNetworkList_function_(
1349 client_, &interface_guid_, 0, NULL, &available_network_list);
1350
1351 if (error == ERROR_SUCCESS && NULL != available_network_list) {
1352 for (DWORD i = 0; i < available_network_list->dwNumberOfItems; ++i) {
1353 const WLAN_AVAILABLE_NETWORK& wlan = available_network_list->Network[i];
1354 if (wlan.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) {
1355 *connected_network_guid = GUIDFromWLAN(wlan);
1356 break;
1357 }
1358 }
1359 }
1360
1361 // Clean up.
1362 if (available_network_list != NULL) {
1363 WlanFreeMemory_function_(available_network_list);
1364 }
1365
1366 return error;
1367 }
1368
1369 WiFiService::Frequency WiFiServiceImpl::GetConnectedFrequency(
1370 const std::string& network_guid) {
1371 if (client_ == NULL) {
1372 NOTREACHED();
1373 return kFrequencyUnknown;
1374 }
1375
1376 // TODO(mef): WlanGetNetworkBssList is not available on XP. If XP support is 1392 // TODO(mef): WlanGetNetworkBssList is not available on XP. If XP support is
1377 // needed, then different method of getting BSS (e.g. OID query) will have 1393 // needed, then different method of getting BSS (e.g. OID query) will have
1378 // to be used. 1394 // to be used.
1379 if (WlanGetNetworkBssList_function_ == NULL) 1395 if (WlanGetNetworkBssList_function_ == NULL)
1380 return kFrequencyUnknown; 1396 return ERROR_NOINTERFACE;
1381 1397
1382 Frequency frequency = kFrequencyUnknown; 1398 Frequency frequency = kFrequencyUnknown;
1383 DWORD error = ERROR_SUCCESS; 1399 DWORD error = ERROR_SUCCESS;
1384 DWORD data_size = 0; 1400 DWORD data_size = 0;
1385 PWLAN_CONNECTION_ATTRIBUTES wlan_connection_attributes = NULL; 1401 PWLAN_CONNECTION_ATTRIBUTES wlan_connection_attributes = NULL;
1386 PWLAN_BSS_LIST bss_list = NULL; 1402 PWLAN_BSS_LIST bss_list = NULL;
1387 error = WlanQueryInterface_function_( 1403 error = WlanQueryInterface_function_(
1388 client_, 1404 client_,
1389 &interface_guid_, 1405 &interface_guid_,
1390 wlan_intf_opcode_current_connection, 1406 wlan_intf_opcode_current_connection,
1391 NULL, 1407 NULL,
1392 &data_size, 1408 &data_size,
1393 reinterpret_cast<PVOID*>(&wlan_connection_attributes), 1409 reinterpret_cast<PVOID*>(&wlan_connection_attributes),
1394 NULL); 1410 NULL);
1395 if (error == ERROR_SUCCESS && 1411 if (error == ERROR_SUCCESS &&
1396 wlan_connection_attributes != NULL && 1412 wlan_connection_attributes != NULL) {
1397 wlan_connection_attributes->isState == wlan_interface_state_connected) {
1398 WLAN_ASSOCIATION_ATTRIBUTES& connected_wlan = 1413 WLAN_ASSOCIATION_ATTRIBUTES& connected_wlan =
1399 wlan_connection_attributes->wlanAssociationAttributes; 1414 wlan_connection_attributes->wlanAssociationAttributes;
1400 // Try to find connected frequency based on bss. 1415
1401 if (GUIDFromSSID(connected_wlan.dot11Ssid) == network_guid && 1416 properties->connection_state = ConnectionStateFromInterfaceState(
1402 WlanGetNetworkBssList_function_ != NULL) { 1417 wlan_connection_attributes->isState);
1403 error = WlanGetNetworkBssList_function_(client_, 1418 properties->ssid = GUIDFromSSID(connected_wlan.dot11Ssid);
1404 &interface_guid_, 1419 properties->name = properties->ssid;
1405 &connected_wlan.dot11Ssid, 1420 properties->guid = GUIDFromSSID(connected_wlan.dot11Ssid);
1406 connected_wlan.dot11BssType, 1421 properties->type = onc::network_type::kWiFi;
1407 FALSE, 1422 properties->bssid = NetworkProperties::MacAddressAsString(
1408 NULL, 1423 connected_wlan.dot11Bssid);
1409 &bss_list); 1424 properties->security = SecurityFromDot11AuthAlg(
1410 if (error == ERROR_SUCCESS && NULL != bss_list) { 1425 wlan_connection_attributes->wlanSecurityAttributes.dot11AuthAlgorithm);
1411 // Go through bss_list and find matching BSSID. 1426 properties->signal_strength = connected_wlan.wlanSignalQuality;
1412 for (size_t bss = 0; bss < bss_list->dwNumberOfItems; ++bss) { 1427
1413 const WLAN_BSS_ENTRY& bss_entry(bss_list->wlanBssEntries[bss]); 1428 // TODO(mef): WlanGetNetworkBssList is not available on XP. If XP support is
1414 if (0 == memcmp(bss_entry.dot11Bssid, 1429 // needed, then different method of getting BSS (e.g. OID query) will have
1415 connected_wlan.dot11Bssid, 1430 // to be used.
1416 sizeof(bss_entry.dot11Bssid))) { 1431 error = WlanGetNetworkBssList_function_(client_,
1417 frequency = GetNormalizedFrequency( 1432 &interface_guid_,
1418 bss_entry.ulChCenterFrequency / 1000); 1433 &connected_wlan.dot11Ssid,
1419 break; 1434 connected_wlan.dot11BssType,
1420 } 1435 FALSE,
1421 } 1436 NULL,
1422 } 1437 &bss_list);
1438 if (error == ERROR_SUCCESS && NULL != bss_list) {
1439 UpdateNetworkPropertiesFromBssList(properties->guid,
1440 *bss_list,
1441 properties);
1423 } 1442 }
1424 } 1443 }
1425 1444
1426 // Clean up. 1445 // Clean up.
1427 if (wlan_connection_attributes != NULL) { 1446 if (wlan_connection_attributes != NULL)
1428 WlanFreeMemory_function_(wlan_connection_attributes); 1447 WlanFreeMemory_function_(wlan_connection_attributes);
1429 }
1430 1448
1431 if (bss_list != NULL) { 1449 if (bss_list != NULL)
1432 WlanFreeMemory_function_(bss_list); 1450 WlanFreeMemory_function_(bss_list);
1433 }
1434 1451
1435 return frequency; 1452 return frequency;
1436 } 1453 }
1437 1454
1438 WiFiService::Frequency WiFiServiceImpl::GetFrequencyToConnect( 1455 WiFiService::Frequency WiFiServiceImpl::GetFrequencyToConnect(
1439 const std::string& network_guid) const { 1456 const std::string& network_guid) const {
1440 // Check whether desired frequency is set in |connect_properties_|. 1457 // Check whether desired frequency is set in |connect_properties_|.
1441 const base::DictionaryValue* properties; 1458 const base::DictionaryValue* properties;
1442 const base::DictionaryValue* wifi; 1459 const base::DictionaryValue* wifi;
1443 int frequency; 1460 int frequency;
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 NetworkGuidList changed_networks(1, network_guid); 1816 NetworkGuidList changed_networks(1, network_guid);
1800 message_loop_proxy_->PostTask( 1817 message_loop_proxy_->PostTask(
1801 FROM_HERE, 1818 FROM_HERE,
1802 base::Bind(networks_changed_observer_, changed_networks)); 1819 base::Bind(networks_changed_observer_, changed_networks));
1803 } 1820 }
1804 } 1821 }
1805 1822
1806 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } 1823 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); }
1807 1824
1808 } // namespace wifi 1825 } // namespace wifi
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698