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

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: 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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 std::string WpaEncryptionFromEncryptionType( 330 std::string WpaEncryptionFromEncryptionType(
331 EncryptionType encryption_type) const; 331 EncryptionType encryption_type) const;
332 332
333 // Deduce WLANProfile |authEncryption| values from |onc::wifi| security. 333 // Deduce WLANProfile |authEncryption| values from |onc::wifi| security.
334 bool AuthEncryptionFromSecurity(const std::string& security, 334 bool AuthEncryptionFromSecurity(const std::string& security,
335 EncryptionType encryption_type, 335 EncryptionType encryption_type,
336 std::string* authentication, 336 std::string* authentication,
337 std::string* encryption, 337 std::string* encryption,
338 std::string* key_type) const; 338 std::string* key_type) const;
339 339
340 // Populate |properties| based on |wlan| and its corresponding bss info from 340 // Populate |properties| based on |wlan|.
341 // |wlan_bss_list|.
342 void NetworkPropertiesFromAvailableNetwork(const WLAN_AVAILABLE_NETWORK& wlan, 341 void NetworkPropertiesFromAvailableNetwork(const WLAN_AVAILABLE_NETWORK& wlan,
343 const WLAN_BSS_LIST& wlan_bss_list,
344 NetworkProperties* properties); 342 NetworkProperties* properties);
345 343
344 // Populate |properties| based on bss info from |wlan_bss_list|.
345 void NetworkPropertiesFromBssList(const WLAN_BSS_LIST& wlan_bss_list,
tbarzic 2014/04/21 18:43:43 suggestions for naming (I understood the current n
mef 2014/04/21 22:23:19 Done.
346 NetworkProperties* properties);
347
346 // Get the list of visible wireless networks. 348 // Get the list of visible wireless networks.
347 DWORD GetVisibleNetworkList(NetworkList* network_list); 349 DWORD GetVisibleNetworkList(NetworkList* network_list);
348 350
349 // Find currently connected network if any. Populate |connected_network_guid| 351 // Find currently connected network if any. Populate |connected_properties|
350 // on success. 352 // on success.
351 DWORD FindConnectedNetwork(std::string* connected_network_guid); 353 DWORD GetConnectedProperties(NetworkProperties* connected_properties);
352 354
353 // Connect to network |network_guid| using previosly stored profile if exists, 355 // Connect to network |network_guid| using previosly stored profile if exists,
354 // or just network sid. If |frequency| is not |kFrequencyUnknown| then 356 // or just network sid. If |frequency| is not |kFrequencyUnknown| then
355 // connects only to BSS which uses that frequency and returns 357 // connects only to BSS which uses that frequency and returns
356 // |ERROR_NOT_FOUND| if such BSS cannot be found. 358 // |ERROR_NOT_FOUND| if such BSS cannot be found.
357 DWORD Connect(const std::string& network_guid, Frequency frequency); 359 DWORD Connect(const std::string& network_guid, Frequency frequency);
358 360
359 // Disconnect from currently connected network if any. 361 // Disconnect from currently connected network if any.
360 DWORD Disconnect(); 362 DWORD Disconnect();
361 363
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|. 364 // Get desired connection freqency if it was set using |SetProperties|.
367 // Default to |kFrequencyAny|. 365 // Default to |kFrequencyAny|.
368 Frequency GetFrequencyToConnect(const std::string& network_guid) const; 366 Frequency GetFrequencyToConnect(const std::string& network_guid) const;
369 367
370 // Get DOT11_BSSID_LIST of desired BSSIDs to connect to |ssid| network on 368 // Get DOT11_BSSID_LIST of desired BSSIDs to connect to |ssid| network on
371 // given |frequency|. 369 // given |frequency|.
372 DWORD GetDesiredBssList(DOT11_SSID& ssid, 370 DWORD GetDesiredBssList(DOT11_SSID& ssid,
373 Frequency frequency, 371 Frequency frequency,
374 scoped_ptr<DOT11_BSSID_LIST>* desired_list); 372 scoped_ptr<DOT11_BSSID_LIST>* desired_list);
375 373
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 497 }
500 498
501 void WiFiServiceImpl::UnInitialize() { 499 void WiFiServiceImpl::UnInitialize() {
502 CloseClientHandle(); 500 CloseClientHandle();
503 } 501 }
504 502
505 void WiFiServiceImpl::GetProperties(const std::string& network_guid, 503 void WiFiServiceImpl::GetProperties(const std::string& network_guid,
506 base::DictionaryValue* properties, 504 base::DictionaryValue* properties,
507 std::string* error) { 505 std::string* error) {
508 DWORD error_code = EnsureInitialized(); 506 DWORD error_code = EnsureInitialized();
507 if (CheckError(error_code, kWiFiServiceError, error))
508 return;
509
510 NetworkProperties connected_properties;
511 error_code = GetConnectedProperties(&connected_properties);
512 if (error_code == ERROR_SUCCESS &&
513 connected_properties.guid == network_guid) {
514 properties->Swap(connected_properties.ToValue(false).get());
515 return;
516 }
517
518 NetworkList network_list;
519 error_code = GetVisibleNetworkList(&network_list);
509 if (error_code == ERROR_SUCCESS) { 520 if (error_code == ERROR_SUCCESS) {
510 NetworkList network_list; 521 NetworkList::const_iterator it = FindNetwork(network_list, network_guid);
511 error_code = GetVisibleNetworkList(&network_list); 522 if (it != network_list.end()) {
512 if (error_code == ERROR_SUCCESS && !network_list.empty()) { 523 DVLOG(1) << "Get Properties: " << network_guid << ":"
513 NetworkList::const_iterator it = FindNetwork(network_list, network_guid); 524 << it->connection_state;
514 if (it != network_list.end()) { 525 properties->Swap(it->ToValue(false).get());
515 DVLOG(1) << "Get Properties: " << network_guid << ":" 526 return;
516 << it->connection_state;
517 properties->Swap(it->ToValue(false).get());
518 return;
519 } else {
520 error_code = ERROR_NOT_FOUND;
521 }
522 } 527 }
528 error_code = ERROR_NOT_FOUND;
523 } 529 }
524 530
525 CheckError(error_code, kWiFiServiceError, error); 531 CheckError(error_code, kWiFiServiceError, error);
526 } 532 }
527 533
528 void WiFiServiceImpl::GetManagedProperties( 534 void WiFiServiceImpl::GetManagedProperties(
529 const std::string& network_guid, 535 const std::string& network_guid,
530 base::DictionaryValue* managed_properties, 536 base::DictionaryValue* managed_properties,
531 std::string* error) { 537 std::string* error) {
532 CheckError(ERROR_CALL_NOT_IMPLEMENTED, kWiFiServiceError, error); 538 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; 655 DVLOG(1) << "Start Connect: " << network_guid;
650 DWORD error_code = EnsureInitialized(); 656 DWORD error_code = EnsureInitialized();
651 if (error_code == ERROR_SUCCESS) { 657 if (error_code == ERROR_SUCCESS) {
652 std::string connected_network_guid; 658 std::string connected_network_guid;
653 error_code = SaveCurrentConnectedNetwork(&connected_network_guid); 659 error_code = SaveCurrentConnectedNetwork(&connected_network_guid);
654 if (error_code == ERROR_SUCCESS) { 660 if (error_code == ERROR_SUCCESS) {
655 // Check, if the network is already connected on desired frequency. 661 // Check, if the network is already connected on desired frequency.
656 bool already_connected = (network_guid == connected_network_guid); 662 bool already_connected = (network_guid == connected_network_guid);
657 Frequency frequency = GetFrequencyToConnect(network_guid); 663 Frequency frequency = GetFrequencyToConnect(network_guid);
658 if (already_connected && frequency != kFrequencyAny) { 664 if (already_connected && frequency != kFrequencyAny) {
659 Frequency connected_frequency = GetConnectedFrequency(network_guid); 665 NetworkProperties connected_properties;
660 already_connected = (frequency == connected_frequency); 666 if (GetConnectedProperties(&connected_properties) == ERROR_SUCCESS) {
667 already_connected = (frequency == connected_properties.frequency) &&
tbarzic 2014/04/21 18:43:43 nit: no need for ()
mef 2014/04/21 22:23:19 Done.
668 (network_guid == connected_properties.guid);
669 }
661 } 670 }
662 // Connect only if network |network_guid| is not connected already. 671 // Connect only if network |network_guid| is not connected already.
663 if (!already_connected) 672 if (!already_connected)
664 error_code = Connect(network_guid, frequency); 673 error_code = Connect(network_guid, frequency);
665 if (error_code == ERROR_SUCCESS) { 674 if (error_code == ERROR_SUCCESS) {
666 // Notify that previously connected network has changed. 675 // Notify that previously connected network has changed.
667 NotifyNetworkChanged(connected_network_guid); 676 NotifyNetworkChanged(connected_network_guid);
668 // Start waiting for network connection state change. 677 // Start waiting for network connection state change.
669 if (!networks_changed_observer_.is_null()) { 678 if (!networks_changed_observer_.is_null()) {
670 DisableNwCategoryWizard(); 679 DisableNwCategoryWizard();
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 LOG(ERROR) << "Failed to delete created profile for " << network_guid 880 LOG(ERROR) << "Failed to delete created profile for " << network_guid
872 << " error=" << error_code; 881 << " error=" << error_code;
873 } 882 }
874 } 883 }
875 } 884 }
876 // Restore automatic network change notifications and stop waiting. 885 // Restore automatic network change notifications and stop waiting.
877 enable_notify_network_changed_ = true; 886 enable_notify_network_changed_ = true;
878 RestoreNwCategoryWizard(); 887 RestoreNwCategoryWizard();
879 return; 888 return;
880 } 889 }
881 std::string connected_network_guid; 890 NetworkProperties connected_network_properties;
882 DWORD error = FindConnectedNetwork(&connected_network_guid); 891 DWORD error = GetConnectedProperties(&connected_network_properties);
883 if (network_guid == connected_network_guid) { 892 if (network_guid == connected_network_properties.guid) {
884 DVLOG(1) << "WiFi Connected, Reset DHCP: " << network_guid; 893 DVLOG(1) << "WiFi Connected, Reset DHCP: " << network_guid;
885 // Even though wireless network is now connected, it may still be unusable, 894 // 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 895 // e.g. after Chromecast device reset. Reset DHCP on wireless network to
887 // work around this issue. 896 // work around this issue.
888 error = ResetDHCP(); 897 error = ResetDHCP();
889 // There is no need to keep created profile as network is connected. 898 // There is no need to keep created profile as network is connected.
890 created_profiles_.RemoveWithoutPathExpansion(network_guid, NULL); 899 created_profiles_.RemoveWithoutPathExpansion(network_guid, NULL);
891 // Restore previously suppressed notifications. 900 // Restore previously suppressed notifications.
892 enable_notify_network_changed_ = true; 901 enable_notify_network_changed_ = true;
893 RestoreNwCategoryWizard(); 902 RestoreNwCategoryWizard();
(...skipping 28 matching lines...) Expand all
922 ++it) { 931 ++it) {
923 if (it->guid == network_guid) 932 if (it->guid == network_guid)
924 return it; 933 return it;
925 } 934 }
926 return networks.end(); 935 return networks.end();
927 } 936 }
928 937
929 DWORD WiFiServiceImpl::SaveCurrentConnectedNetwork( 938 DWORD WiFiServiceImpl::SaveCurrentConnectedNetwork(
930 std::string* connected_network_guid) { 939 std::string* connected_network_guid) {
931 // Find currently connected network. 940 // Find currently connected network.
932 DWORD error = FindConnectedNetwork(connected_network_guid); 941 NetworkProperties connected_network_properties;
933 if (error == ERROR_SUCCESS && !connected_network_guid->empty()) { 942 DWORD error = GetConnectedProperties(&connected_network_properties);
943 if (error == ERROR_SUCCESS && !connected_network_properties.guid.empty()) {
944 *connected_network_guid = connected_network_properties.guid;
945 SaveTempProfile(*connected_network_guid);
946 std::string profile_xml;
947 error = GetProfile(*connected_network_guid, false, &profile_xml);
934 if (error == ERROR_SUCCESS) { 948 if (error == ERROR_SUCCESS) {
935 SaveTempProfile(*connected_network_guid); 949 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 } 950 }
942 } 951 }
943 return error; 952 return error;
944 } 953 }
945 954
946 void WiFiServiceImpl::SortNetworks(NetworkList* networks) { 955 void WiFiServiceImpl::SortNetworks(NetworkList* networks) {
947 networks->sort(NetworkProperties::OrderByType); 956 networks->sort(NetworkProperties::OrderByType);
948 } 957 }
949 958
950 DWORD WiFiServiceImpl::LoadWlanLibrary() { 959 DWORD WiFiServiceImpl::LoadWlanLibrary() {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 return onc::wifi::kWEP_PSK; 1236 return onc::wifi::kWEP_PSK;
1228 case DOT11_AUTH_ALGO_80211_OPEN: 1237 case DOT11_AUTH_ALGO_80211_OPEN:
1229 return onc::wifi::kNone; 1238 return onc::wifi::kNone;
1230 default: 1239 default:
1231 return onc::wifi::kWPA_EAP; 1240 return onc::wifi::kWPA_EAP;
1232 } 1241 }
1233 } 1242 }
1234 1243
1235 void WiFiServiceImpl::NetworkPropertiesFromAvailableNetwork( 1244 void WiFiServiceImpl::NetworkPropertiesFromAvailableNetwork(
1236 const WLAN_AVAILABLE_NETWORK& wlan, 1245 const WLAN_AVAILABLE_NETWORK& wlan,
1237 const WLAN_BSS_LIST& wlan_bss_list,
1238 NetworkProperties* properties) { 1246 NetworkProperties* properties) {
1239 if (wlan.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) { 1247 if (wlan.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) {
1240 properties->connection_state = onc::connection_state::kConnected; 1248 properties->connection_state = onc::connection_state::kConnected;
tbarzic 2014/04/21 18:43:43 how does this relate to wlan_connection_attributes
mef 2014/04/21 22:23:19 I've added TODO. It should also take network conne
1241 } else { 1249 } else {
1242 properties->connection_state = onc::connection_state::kNotConnected; 1250 properties->connection_state = onc::connection_state::kNotConnected;
1243 } 1251 }
1244 1252
1245 properties->ssid = SSIDFromWLAN(wlan); 1253 properties->ssid = SSIDFromWLAN(wlan);
1246 properties->name = properties->ssid; 1254 properties->name = properties->ssid;
1247 properties->guid = GUIDFromWLAN(wlan); 1255 properties->guid = GUIDFromWLAN(wlan);
1248 properties->type = onc::network_type::kWiFi; 1256 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 = 1257 properties->security =
1264 SecurityFromDot11AuthAlg(wlan.dot11DefaultAuthAlgorithm); 1258 SecurityFromDot11AuthAlg(wlan.dot11DefaultAuthAlgorithm);
1265 properties->signal_strength = wlan.wlanSignalQuality; 1259 properties->signal_strength = wlan.wlanSignalQuality;
1266 } 1260 }
1267 1261
1262 void WiFiServiceImpl::NetworkPropertiesFromBssList(
1263 const WLAN_BSS_LIST& wlan_bss_list,
1264 NetworkProperties* properties) {
1265 DOT11_SSID ssid = SSIDFromGUID(properties->guid);
tbarzic 2014/04/21 18:43:43 this can return immediately if ssid is empty (or
mef 2014/04/21 22:23:19 Done.
1266 for (size_t bss = 0; bss < wlan_bss_list.dwNumberOfItems; ++bss) {
1267 const WLAN_BSS_ENTRY& bss_entry(wlan_bss_list.wlanBssEntries[bss]);
1268 if (bss_entry.dot11Ssid.uSSIDLength == ssid.uSSIDLength &&
1269 0 == memcmp(bss_entry.dot11Ssid.ucSSID,
1270 ssid.ucSSID,
1271 bss_entry.dot11Ssid.uSSIDLength)) {
1272 std::string bssid = NetworkProperties::MacAddressAsString(
1273 bss_entry.dot11Bssid);
1274 Frequency frequency = GetNormalizedFrequency(
1275 bss_entry.ulChCenterFrequency / 1000);
1276 properties->frequency_set.insert(frequency);
1277 if (properties->bssid.empty() || properties->bssid == bssid) {
1278 properties->frequency = frequency;
1279 properties->bssid = bssid;
1280 }
1281 }
1282 }
1283 }
1284
1268 // Get the list of visible wireless networks 1285 // Get the list of visible wireless networks
1269 DWORD WiFiServiceImpl::GetVisibleNetworkList(NetworkList* network_list) { 1286 DWORD WiFiServiceImpl::GetVisibleNetworkList(NetworkList* network_list) {
1270 if (client_ == NULL) { 1287 if (client_ == NULL) {
1271 NOTREACHED(); 1288 NOTREACHED();
1272 return ERROR_NOINTERFACE; 1289 return ERROR_NOINTERFACE;
1273 } 1290 }
1274 1291
1275 DWORD error = ERROR_SUCCESS; 1292 DWORD error = ERROR_SUCCESS;
1276 PWLAN_AVAILABLE_NETWORK_LIST available_network_list = NULL; 1293 PWLAN_AVAILABLE_NETWORK_LIST available_network_list = NULL;
1277 PWLAN_BSS_LIST bss_list = NULL; 1294 PWLAN_BSS_LIST bss_list = NULL;
(...skipping 18 matching lines...) Expand all
1296 NULL, 1313 NULL,
1297 dot11_BSS_type_any, 1314 dot11_BSS_type_any,
1298 FALSE, 1315 FALSE,
1299 NULL, 1316 NULL,
1300 &bss_list); 1317 &bss_list);
1301 if (error == ERROR_SUCCESS && NULL != bss_list) { 1318 if (error == ERROR_SUCCESS && NULL != bss_list) {
1302 for (DWORD i = 0; i < available_network_list->dwNumberOfItems; ++i) { 1319 for (DWORD i = 0; i < available_network_list->dwNumberOfItems; ++i) {
1303 NetworkProperties network_properties; 1320 NetworkProperties network_properties;
1304 NetworkPropertiesFromAvailableNetwork( 1321 NetworkPropertiesFromAvailableNetwork(
1305 available_network_list->Network[i], 1322 available_network_list->Network[i],
1306 *bss_list,
1307 &network_properties); 1323 &network_properties);
1324 NetworkPropertiesFromBssList(*bss_list, &network_properties);
1308 // Check for duplicate network guids. 1325 // Check for duplicate network guids.
1309 if (network_guids.count(network_properties.guid)) { 1326 if (network_guids.count(network_properties.guid)) {
1310 // There should be no difference between properties except for 1327 // There should be no difference between properties except for
1311 // |connection_state|, so mark it as |kConnected| if either one is. 1328 // |connection_state|, so mark it as |kConnected| if either one is.
1312 if (network_properties.connection_state == 1329 if (network_properties.connection_state ==
1313 onc::connection_state::kConnected) { 1330 onc::connection_state::kConnected) {
1314 NetworkList::iterator previous_network_properties = 1331 NetworkList::iterator previous_network_properties =
1315 FindNetwork(*network_list, network_properties.guid); 1332 FindNetwork(*network_list, network_properties.guid);
1316 DCHECK(previous_network_properties != network_list->end()); 1333 DCHECK(previous_network_properties != network_list->end());
1317 previous_network_properties->connection_state = 1334 previous_network_properties->connection_state =
(...skipping 10 matching lines...) Expand all
1328 // Clean up. 1345 // Clean up.
1329 if (available_network_list != NULL) { 1346 if (available_network_list != NULL) {
1330 WlanFreeMemory_function_(available_network_list); 1347 WlanFreeMemory_function_(available_network_list);
1331 } 1348 }
1332 if (bss_list != NULL) { 1349 if (bss_list != NULL) {
1333 WlanFreeMemory_function_(bss_list); 1350 WlanFreeMemory_function_(bss_list);
1334 } 1351 }
1335 return error; 1352 return error;
1336 } 1353 }
1337 1354
1338 // Find currently connected network. 1355 DWORD WiFiServiceImpl::GetConnectedProperties(NetworkProperties* properties) {
1339 DWORD WiFiServiceImpl::FindConnectedNetwork(
1340 std::string* connected_network_guid) {
1341 if (client_ == NULL) { 1356 if (client_ == NULL) {
1342 NOTREACHED(); 1357 NOTREACHED();
1343 return ERROR_NOINTERFACE; 1358 return ERROR_NOINTERFACE;
1344 } 1359 }
1345 1360
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 1361 // 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 1362 // needed, then different method of getting BSS (e.g. OID query) will have
1378 // to be used. 1363 // to be used.
1379 if (WlanGetNetworkBssList_function_ == NULL) 1364 if (WlanGetNetworkBssList_function_ == NULL)
1380 return kFrequencyUnknown; 1365 return ERROR_NOINTERFACE;
1381 1366
1382 Frequency frequency = kFrequencyUnknown; 1367 Frequency frequency = kFrequencyUnknown;
1383 DWORD error = ERROR_SUCCESS; 1368 DWORD error = ERROR_SUCCESS;
1384 DWORD data_size = 0; 1369 DWORD data_size = 0;
1385 PWLAN_CONNECTION_ATTRIBUTES wlan_connection_attributes = NULL; 1370 PWLAN_CONNECTION_ATTRIBUTES wlan_connection_attributes = NULL;
1386 PWLAN_BSS_LIST bss_list = NULL; 1371 PWLAN_BSS_LIST bss_list = NULL;
1387 error = WlanQueryInterface_function_( 1372 error = WlanQueryInterface_function_(
1388 client_, 1373 client_,
1389 &interface_guid_, 1374 &interface_guid_,
1390 wlan_intf_opcode_current_connection, 1375 wlan_intf_opcode_current_connection,
1391 NULL, 1376 NULL,
1392 &data_size, 1377 &data_size,
1393 reinterpret_cast<PVOID*>(&wlan_connection_attributes), 1378 reinterpret_cast<PVOID*>(&wlan_connection_attributes),
1394 NULL); 1379 NULL);
1395 if (error == ERROR_SUCCESS && 1380 if (error == ERROR_SUCCESS &&
1396 wlan_connection_attributes != NULL && 1381 wlan_connection_attributes != NULL &&
1397 wlan_connection_attributes->isState == wlan_interface_state_connected) { 1382 wlan_connection_attributes->isState == wlan_interface_state_connected) {
tbarzic 2014/04/21 18:43:43 can we set connection_state to Connecting for wlan
mef 2014/04/21 22:23:19 Good idea, I think doing it separately will be cle
1398 WLAN_ASSOCIATION_ATTRIBUTES& connected_wlan = 1383 WLAN_ASSOCIATION_ATTRIBUTES& connected_wlan =
1399 wlan_connection_attributes->wlanAssociationAttributes; 1384 wlan_connection_attributes->wlanAssociationAttributes;
1400 // Try to find connected frequency based on bss. 1385
1401 if (GUIDFromSSID(connected_wlan.dot11Ssid) == network_guid && 1386 properties->connection_state = onc::connection_state::kConnected;
1402 WlanGetNetworkBssList_function_ != NULL) { 1387 properties->ssid = GUIDFromSSID(connected_wlan.dot11Ssid);
1403 error = WlanGetNetworkBssList_function_(client_, 1388 properties->name = properties->ssid;
1404 &interface_guid_, 1389 properties->guid = GUIDFromSSID(connected_wlan.dot11Ssid);
1405 &connected_wlan.dot11Ssid, 1390 properties->type = onc::network_type::kWiFi;
1406 connected_wlan.dot11BssType, 1391 properties->bssid = NetworkProperties::MacAddressAsString(
1407 FALSE, 1392 connected_wlan.dot11Bssid);
1408 NULL, 1393 properties->security = SecurityFromDot11AuthAlg(
1409 &bss_list); 1394 wlan_connection_attributes->wlanSecurityAttributes.dot11AuthAlgorithm);
1410 if (error == ERROR_SUCCESS && NULL != bss_list) { 1395 properties->signal_strength = connected_wlan.wlanSignalQuality;
1411 // Go through bss_list and find matching BSSID. 1396
1412 for (size_t bss = 0; bss < bss_list->dwNumberOfItems; ++bss) { 1397 // TODO(mef): WlanGetNetworkBssList is not available on XP. If XP support is
1413 const WLAN_BSS_ENTRY& bss_entry(bss_list->wlanBssEntries[bss]); 1398 // needed, then different method of getting BSS (e.g. OID query) will have
1414 if (0 == memcmp(bss_entry.dot11Bssid, 1399 // to be used.
1415 connected_wlan.dot11Bssid, 1400 error = WlanGetNetworkBssList_function_(client_,
1416 sizeof(bss_entry.dot11Bssid))) { 1401 &interface_guid_,
1417 frequency = GetNormalizedFrequency( 1402 &connected_wlan.dot11Ssid,
1418 bss_entry.ulChCenterFrequency / 1000); 1403 connected_wlan.dot11BssType,
1419 break; 1404 FALSE,
1420 } 1405 NULL,
1421 } 1406 &bss_list);
1422 } 1407 if (error == ERROR_SUCCESS && NULL != bss_list) {
1408 NetworkPropertiesFromBssList(*bss_list, properties);
1423 } 1409 }
1424 } 1410 }
1425 1411
1426 // Clean up. 1412 // Clean up.
1427 if (wlan_connection_attributes != NULL) { 1413 if (wlan_connection_attributes != NULL)
1428 WlanFreeMemory_function_(wlan_connection_attributes); 1414 WlanFreeMemory_function_(wlan_connection_attributes);
1429 }
1430 1415
1431 if (bss_list != NULL) { 1416 if (bss_list != NULL)
1432 WlanFreeMemory_function_(bss_list); 1417 WlanFreeMemory_function_(bss_list);
1433 }
1434 1418
1435 return frequency; 1419 return frequency;
1436 } 1420 }
1437 1421
1438 WiFiService::Frequency WiFiServiceImpl::GetFrequencyToConnect( 1422 WiFiService::Frequency WiFiServiceImpl::GetFrequencyToConnect(
1439 const std::string& network_guid) const { 1423 const std::string& network_guid) const {
1440 // Check whether desired frequency is set in |connect_properties_|. 1424 // Check whether desired frequency is set in |connect_properties_|.
1441 const base::DictionaryValue* properties; 1425 const base::DictionaryValue* properties;
1442 const base::DictionaryValue* wifi; 1426 const base::DictionaryValue* wifi;
1443 int frequency; 1427 int frequency;
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 NetworkGuidList changed_networks(1, network_guid); 1783 NetworkGuidList changed_networks(1, network_guid);
1800 message_loop_proxy_->PostTask( 1784 message_loop_proxy_->PostTask(
1801 FROM_HERE, 1785 FROM_HERE,
1802 base::Bind(networks_changed_observer_, changed_networks)); 1786 base::Bind(networks_changed_observer_, changed_networks));
1803 } 1787 }
1804 } 1788 }
1805 1789
1806 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } 1790 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); }
1807 1791
1808 } // namespace wifi 1792 } // 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