Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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; | |
|
afontan
2014/04/23 13:54:17
Don't we need to verify that we are actually conne
mef
2014/04/23 16:35:21
Done.
| |
| 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 Loading... | |
| 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 && |
| 900 connected_network_properties.connection_state == | |
| 901 onc::connection_state::kConnected) { | |
| 884 DVLOG(1) << "WiFi Connected, Reset DHCP: " << network_guid; | 902 DVLOG(1) << "WiFi Connected, Reset DHCP: " << network_guid; |
| 885 // Even though wireless network is now connected, it may still be unusable, | 903 // 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 | 904 // e.g. after Chromecast device reset. Reset DHCP on wireless network to |
| 887 // work around this issue. | 905 // work around this issue. |
| 888 error = ResetDHCP(); | 906 error = ResetDHCP(); |
| 889 // There is no need to keep created profile as network is connected. | 907 // There is no need to keep created profile as network is connected. |
| 890 created_profiles_.RemoveWithoutPathExpansion(network_guid, NULL); | 908 created_profiles_.RemoveWithoutPathExpansion(network_guid, NULL); |
| 891 // Restore previously suppressed notifications. | 909 // Restore previously suppressed notifications. |
| 892 enable_notify_network_changed_ = true; | 910 enable_notify_network_changed_ = true; |
| 893 RestoreNwCategoryWizard(); | 911 RestoreNwCategoryWizard(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 922 ++it) { | 940 ++it) { |
| 923 if (it->guid == network_guid) | 941 if (it->guid == network_guid) |
| 924 return it; | 942 return it; |
| 925 } | 943 } |
| 926 return networks.end(); | 944 return networks.end(); |
| 927 } | 945 } |
| 928 | 946 |
| 929 DWORD WiFiServiceImpl::SaveCurrentConnectedNetwork( | 947 DWORD WiFiServiceImpl::SaveCurrentConnectedNetwork( |
| 930 std::string* connected_network_guid) { | 948 std::string* connected_network_guid) { |
| 931 // Find currently connected network. | 949 // Find currently connected network. |
| 932 DWORD error = FindConnectedNetwork(connected_network_guid); | 950 NetworkProperties connected_network_properties; |
| 933 if (error == ERROR_SUCCESS && !connected_network_guid->empty()) { | 951 DWORD error = GetConnectedProperties(&connected_network_properties); |
| 952 if (error == ERROR_SUCCESS && !connected_network_properties.guid.empty()) { | |
|
afontan
2014/04/23 13:54:17
Don't we need to verify the connection state?
mef
2014/04/23 16:35:21
Done.
| |
| 953 *connected_network_guid = connected_network_properties.guid; | |
| 954 SaveTempProfile(*connected_network_guid); | |
| 955 std::string profile_xml; | |
| 956 error = GetProfile(*connected_network_guid, false, &profile_xml); | |
| 934 if (error == ERROR_SUCCESS) { | 957 if (error == ERROR_SUCCESS) { |
| 935 SaveTempProfile(*connected_network_guid); | 958 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 } | 959 } |
| 942 } | 960 } |
| 943 return error; | 961 return error; |
| 944 } | 962 } |
| 945 | 963 |
| 946 void WiFiServiceImpl::SortNetworks(NetworkList* networks) { | 964 void WiFiServiceImpl::SortNetworks(NetworkList* networks) { |
| 947 networks->sort(NetworkProperties::OrderByType); | 965 networks->sort(NetworkProperties::OrderByType); |
| 948 } | 966 } |
| 949 | 967 |
| 950 DWORD WiFiServiceImpl::LoadWlanLibrary() { | 968 DWORD WiFiServiceImpl::LoadWlanLibrary() { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1225 return onc::wifi::kWPA_PSK; | 1243 return onc::wifi::kWPA_PSK; |
| 1226 case DOT11_AUTH_ALGO_80211_SHARED_KEY: | 1244 case DOT11_AUTH_ALGO_80211_SHARED_KEY: |
| 1227 return onc::wifi::kWEP_PSK; | 1245 return onc::wifi::kWEP_PSK; |
| 1228 case DOT11_AUTH_ALGO_80211_OPEN: | 1246 case DOT11_AUTH_ALGO_80211_OPEN: |
| 1229 return onc::wifi::kNone; | 1247 return onc::wifi::kNone; |
| 1230 default: | 1248 default: |
| 1231 return onc::wifi::kWPA_EAP; | 1249 return onc::wifi::kWPA_EAP; |
| 1232 } | 1250 } |
| 1233 } | 1251 } |
| 1234 | 1252 |
| 1253 std::string WiFiServiceImpl::ConnectionStateFromInterfaceState( | |
| 1254 WLAN_INTERFACE_STATE wlan_state) const { | |
| 1255 switch (wlan_state) { | |
| 1256 case wlan_interface_state_connected: | |
| 1257 // TODO(mef): Even if |wlan_state| is connected, the network may still | |
| 1258 // not be reachable, and should be resported as |kConnecting|. | |
| 1259 return onc::connection_state::kConnected; | |
| 1260 case wlan_interface_state_associating: | |
| 1261 case wlan_interface_state_discovering: | |
| 1262 case wlan_interface_state_authenticating: | |
| 1263 return onc::connection_state::kConnecting; | |
| 1264 default: | |
| 1265 return onc::connection_state::kNotConnected; | |
| 1266 } | |
| 1267 } | |
| 1268 | |
| 1235 void WiFiServiceImpl::NetworkPropertiesFromAvailableNetwork( | 1269 void WiFiServiceImpl::NetworkPropertiesFromAvailableNetwork( |
| 1236 const WLAN_AVAILABLE_NETWORK& wlan, | 1270 const WLAN_AVAILABLE_NETWORK& wlan, |
| 1237 const WLAN_BSS_LIST& wlan_bss_list, | |
| 1238 NetworkProperties* properties) { | 1271 NetworkProperties* properties) { |
| 1272 // TODO(mef): It would be nice for the connection states in | |
| 1273 // getVisibleNetworks and getProperties results to be consistent. | |
| 1239 if (wlan.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) { | 1274 if (wlan.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) { |
| 1240 properties->connection_state = onc::connection_state::kConnected; | 1275 properties->connection_state = onc::connection_state::kConnected; |
| 1241 } else { | 1276 } else { |
| 1242 properties->connection_state = onc::connection_state::kNotConnected; | 1277 properties->connection_state = onc::connection_state::kNotConnected; |
| 1243 } | 1278 } |
| 1244 | 1279 |
| 1245 properties->ssid = SSIDFromWLAN(wlan); | 1280 properties->ssid = SSIDFromWLAN(wlan); |
| 1246 properties->name = properties->ssid; | 1281 properties->name = properties->ssid; |
| 1247 properties->guid = GUIDFromWLAN(wlan); | 1282 properties->guid = GUIDFromWLAN(wlan); |
| 1248 properties->type = onc::network_type::kWiFi; | 1283 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 = | 1284 properties->security = |
| 1264 SecurityFromDot11AuthAlg(wlan.dot11DefaultAuthAlgorithm); | 1285 SecurityFromDot11AuthAlg(wlan.dot11DefaultAuthAlgorithm); |
| 1265 properties->signal_strength = wlan.wlanSignalQuality; | 1286 properties->signal_strength = wlan.wlanSignalQuality; |
| 1266 } | 1287 } |
| 1267 | 1288 |
| 1289 void WiFiServiceImpl::UpdateNetworkPropertiesFromBssList( | |
| 1290 const std::string& network_guid, | |
| 1291 const WLAN_BSS_LIST& wlan_bss_list, | |
| 1292 NetworkProperties* properties) { | |
| 1293 if (network_guid.empty()) | |
| 1294 return; | |
| 1295 | |
| 1296 DOT11_SSID ssid = SSIDFromGUID(network_guid); | |
| 1297 for (size_t bss = 0; bss < wlan_bss_list.dwNumberOfItems; ++bss) { | |
| 1298 const WLAN_BSS_ENTRY& bss_entry(wlan_bss_list.wlanBssEntries[bss]); | |
| 1299 if (bss_entry.dot11Ssid.uSSIDLength == ssid.uSSIDLength && | |
| 1300 0 == memcmp(bss_entry.dot11Ssid.ucSSID, | |
| 1301 ssid.ucSSID, | |
| 1302 bss_entry.dot11Ssid.uSSIDLength)) { | |
| 1303 std::string bssid = NetworkProperties::MacAddressAsString( | |
| 1304 bss_entry.dot11Bssid); | |
| 1305 Frequency frequency = GetNormalizedFrequency( | |
| 1306 bss_entry.ulChCenterFrequency / 1000); | |
| 1307 properties->frequency_set.insert(frequency); | |
| 1308 if (properties->bssid.empty() || properties->bssid == bssid) { | |
| 1309 properties->frequency = frequency; | |
| 1310 properties->bssid = bssid; | |
| 1311 } | |
| 1312 } | |
| 1313 } | |
| 1314 } | |
| 1315 | |
| 1268 // Get the list of visible wireless networks | 1316 // Get the list of visible wireless networks |
| 1269 DWORD WiFiServiceImpl::GetVisibleNetworkList(NetworkList* network_list) { | 1317 DWORD WiFiServiceImpl::GetVisibleNetworkList(NetworkList* network_list) { |
| 1270 if (client_ == NULL) { | 1318 if (client_ == NULL) { |
| 1271 NOTREACHED(); | 1319 NOTREACHED(); |
| 1272 return ERROR_NOINTERFACE; | 1320 return ERROR_NOINTERFACE; |
| 1273 } | 1321 } |
| 1274 | 1322 |
| 1275 DWORD error = ERROR_SUCCESS; | 1323 DWORD error = ERROR_SUCCESS; |
| 1276 PWLAN_AVAILABLE_NETWORK_LIST available_network_list = NULL; | 1324 PWLAN_AVAILABLE_NETWORK_LIST available_network_list = NULL; |
| 1277 PWLAN_BSS_LIST bss_list = NULL; | 1325 PWLAN_BSS_LIST bss_list = NULL; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1296 NULL, | 1344 NULL, |
| 1297 dot11_BSS_type_any, | 1345 dot11_BSS_type_any, |
| 1298 FALSE, | 1346 FALSE, |
| 1299 NULL, | 1347 NULL, |
| 1300 &bss_list); | 1348 &bss_list); |
| 1301 if (error == ERROR_SUCCESS && NULL != bss_list) { | 1349 if (error == ERROR_SUCCESS && NULL != bss_list) { |
| 1302 for (DWORD i = 0; i < available_network_list->dwNumberOfItems; ++i) { | 1350 for (DWORD i = 0; i < available_network_list->dwNumberOfItems; ++i) { |
| 1303 NetworkProperties network_properties; | 1351 NetworkProperties network_properties; |
| 1304 NetworkPropertiesFromAvailableNetwork( | 1352 NetworkPropertiesFromAvailableNetwork( |
| 1305 available_network_list->Network[i], | 1353 available_network_list->Network[i], |
| 1306 *bss_list, | |
| 1307 &network_properties); | 1354 &network_properties); |
| 1355 UpdateNetworkPropertiesFromBssList(network_properties.guid, | |
| 1356 *bss_list, | |
| 1357 &network_properties); | |
| 1308 // Check for duplicate network guids. | 1358 // Check for duplicate network guids. |
| 1309 if (network_guids.count(network_properties.guid)) { | 1359 if (network_guids.count(network_properties.guid)) { |
| 1310 // There should be no difference between properties except for | 1360 // There should be no difference between properties except for |
| 1311 // |connection_state|, so mark it as |kConnected| if either one is. | 1361 // |connection_state|, so mark it as |kConnected| if either one is. |
| 1312 if (network_properties.connection_state == | 1362 if (network_properties.connection_state == |
| 1313 onc::connection_state::kConnected) { | 1363 onc::connection_state::kConnected) { |
| 1314 NetworkList::iterator previous_network_properties = | 1364 NetworkList::iterator previous_network_properties = |
| 1315 FindNetwork(*network_list, network_properties.guid); | 1365 FindNetwork(*network_list, network_properties.guid); |
| 1316 DCHECK(previous_network_properties != network_list->end()); | 1366 DCHECK(previous_network_properties != network_list->end()); |
| 1317 previous_network_properties->connection_state = | 1367 previous_network_properties->connection_state = |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1328 // Clean up. | 1378 // Clean up. |
| 1329 if (available_network_list != NULL) { | 1379 if (available_network_list != NULL) { |
| 1330 WlanFreeMemory_function_(available_network_list); | 1380 WlanFreeMemory_function_(available_network_list); |
| 1331 } | 1381 } |
| 1332 if (bss_list != NULL) { | 1382 if (bss_list != NULL) { |
| 1333 WlanFreeMemory_function_(bss_list); | 1383 WlanFreeMemory_function_(bss_list); |
| 1334 } | 1384 } |
| 1335 return error; | 1385 return error; |
| 1336 } | 1386 } |
| 1337 | 1387 |
| 1338 // Find currently connected network. | 1388 DWORD WiFiServiceImpl::GetConnectedProperties(NetworkProperties* properties) { |
| 1339 DWORD WiFiServiceImpl::FindConnectedNetwork( | |
| 1340 std::string* connected_network_guid) { | |
| 1341 if (client_ == NULL) { | 1389 if (client_ == NULL) { |
| 1342 NOTREACHED(); | 1390 NOTREACHED(); |
| 1343 return ERROR_NOINTERFACE; | 1391 return ERROR_NOINTERFACE; |
| 1344 } | 1392 } |
| 1345 | 1393 |
| 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 | 1394 // 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 | 1395 // needed, then different method of getting BSS (e.g. OID query) will have |
| 1378 // to be used. | 1396 // to be used. |
| 1379 if (WlanGetNetworkBssList_function_ == NULL) | 1397 if (WlanGetNetworkBssList_function_ == NULL) |
| 1380 return kFrequencyUnknown; | 1398 return ERROR_NOINTERFACE; |
| 1381 | 1399 |
| 1382 Frequency frequency = kFrequencyUnknown; | 1400 Frequency frequency = kFrequencyUnknown; |
| 1383 DWORD error = ERROR_SUCCESS; | 1401 DWORD error = ERROR_SUCCESS; |
| 1384 DWORD data_size = 0; | 1402 DWORD data_size = 0; |
| 1385 PWLAN_CONNECTION_ATTRIBUTES wlan_connection_attributes = NULL; | 1403 PWLAN_CONNECTION_ATTRIBUTES wlan_connection_attributes = NULL; |
| 1386 PWLAN_BSS_LIST bss_list = NULL; | 1404 PWLAN_BSS_LIST bss_list = NULL; |
| 1387 error = WlanQueryInterface_function_( | 1405 error = WlanQueryInterface_function_( |
| 1388 client_, | 1406 client_, |
| 1389 &interface_guid_, | 1407 &interface_guid_, |
| 1390 wlan_intf_opcode_current_connection, | 1408 wlan_intf_opcode_current_connection, |
| 1391 NULL, | 1409 NULL, |
| 1392 &data_size, | 1410 &data_size, |
| 1393 reinterpret_cast<PVOID*>(&wlan_connection_attributes), | 1411 reinterpret_cast<PVOID*>(&wlan_connection_attributes), |
| 1394 NULL); | 1412 NULL); |
| 1395 if (error == ERROR_SUCCESS && | 1413 if (error == ERROR_SUCCESS && |
| 1396 wlan_connection_attributes != NULL && | 1414 wlan_connection_attributes != NULL) { |
| 1397 wlan_connection_attributes->isState == wlan_interface_state_connected) { | |
| 1398 WLAN_ASSOCIATION_ATTRIBUTES& connected_wlan = | 1415 WLAN_ASSOCIATION_ATTRIBUTES& connected_wlan = |
| 1399 wlan_connection_attributes->wlanAssociationAttributes; | 1416 wlan_connection_attributes->wlanAssociationAttributes; |
| 1400 // Try to find connected frequency based on bss. | 1417 |
| 1401 if (GUIDFromSSID(connected_wlan.dot11Ssid) == network_guid && | 1418 properties->connection_state = ConnectionStateFromInterfaceState( |
| 1402 WlanGetNetworkBssList_function_ != NULL) { | 1419 wlan_connection_attributes->isState); |
| 1403 error = WlanGetNetworkBssList_function_(client_, | 1420 properties->ssid = GUIDFromSSID(connected_wlan.dot11Ssid); |
| 1404 &interface_guid_, | 1421 properties->name = properties->ssid; |
| 1405 &connected_wlan.dot11Ssid, | 1422 properties->guid = GUIDFromSSID(connected_wlan.dot11Ssid); |
| 1406 connected_wlan.dot11BssType, | 1423 properties->type = onc::network_type::kWiFi; |
| 1407 FALSE, | 1424 properties->bssid = NetworkProperties::MacAddressAsString( |
| 1408 NULL, | 1425 connected_wlan.dot11Bssid); |
| 1409 &bss_list); | 1426 properties->security = SecurityFromDot11AuthAlg( |
| 1410 if (error == ERROR_SUCCESS && NULL != bss_list) { | 1427 wlan_connection_attributes->wlanSecurityAttributes.dot11AuthAlgorithm); |
| 1411 // Go through bss_list and find matching BSSID. | 1428 properties->signal_strength = connected_wlan.wlanSignalQuality; |
| 1412 for (size_t bss = 0; bss < bss_list->dwNumberOfItems; ++bss) { | 1429 |
| 1413 const WLAN_BSS_ENTRY& bss_entry(bss_list->wlanBssEntries[bss]); | 1430 // TODO(mef): WlanGetNetworkBssList is not available on XP. If XP support is |
| 1414 if (0 == memcmp(bss_entry.dot11Bssid, | 1431 // needed, then different method of getting BSS (e.g. OID query) will have |
| 1415 connected_wlan.dot11Bssid, | 1432 // to be used. |
| 1416 sizeof(bss_entry.dot11Bssid))) { | 1433 error = WlanGetNetworkBssList_function_(client_, |
| 1417 frequency = GetNormalizedFrequency( | 1434 &interface_guid_, |
| 1418 bss_entry.ulChCenterFrequency / 1000); | 1435 &connected_wlan.dot11Ssid, |
| 1419 break; | 1436 connected_wlan.dot11BssType, |
| 1420 } | 1437 FALSE, |
| 1421 } | 1438 NULL, |
| 1422 } | 1439 &bss_list); |
| 1440 if (error == ERROR_SUCCESS && NULL != bss_list) { | |
| 1441 UpdateNetworkPropertiesFromBssList(properties->guid, | |
| 1442 *bss_list, | |
| 1443 properties); | |
| 1423 } | 1444 } |
| 1424 } | 1445 } |
| 1425 | 1446 |
| 1426 // Clean up. | 1447 // Clean up. |
| 1427 if (wlan_connection_attributes != NULL) { | 1448 if (wlan_connection_attributes != NULL) |
| 1428 WlanFreeMemory_function_(wlan_connection_attributes); | 1449 WlanFreeMemory_function_(wlan_connection_attributes); |
| 1429 } | |
| 1430 | 1450 |
| 1431 if (bss_list != NULL) { | 1451 if (bss_list != NULL) |
| 1432 WlanFreeMemory_function_(bss_list); | 1452 WlanFreeMemory_function_(bss_list); |
| 1433 } | |
| 1434 | 1453 |
| 1435 return frequency; | 1454 return frequency; |
|
afontan
2014/04/23 13:54:17
return error;
mef
2014/04/23 16:35:21
Done.
| |
| 1436 } | 1455 } |
| 1437 | 1456 |
| 1438 WiFiService::Frequency WiFiServiceImpl::GetFrequencyToConnect( | 1457 WiFiService::Frequency WiFiServiceImpl::GetFrequencyToConnect( |
| 1439 const std::string& network_guid) const { | 1458 const std::string& network_guid) const { |
| 1440 // Check whether desired frequency is set in |connect_properties_|. | 1459 // Check whether desired frequency is set in |connect_properties_|. |
| 1441 const base::DictionaryValue* properties; | 1460 const base::DictionaryValue* properties; |
| 1442 const base::DictionaryValue* wifi; | 1461 const base::DictionaryValue* wifi; |
| 1443 int frequency; | 1462 int frequency; |
| 1444 if (connect_properties_.GetDictionaryWithoutPathExpansion( | 1463 if (connect_properties_.GetDictionaryWithoutPathExpansion( |
| 1445 network_guid, &properties) && | 1464 network_guid, &properties) && |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1799 NetworkGuidList changed_networks(1, network_guid); | 1818 NetworkGuidList changed_networks(1, network_guid); |
| 1800 message_loop_proxy_->PostTask( | 1819 message_loop_proxy_->PostTask( |
| 1801 FROM_HERE, | 1820 FROM_HERE, |
| 1802 base::Bind(networks_changed_observer_, changed_networks)); | 1821 base::Bind(networks_changed_observer_, changed_networks)); |
| 1803 } | 1822 } |
| 1804 } | 1823 } |
| 1805 | 1824 |
| 1806 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } | 1825 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } |
| 1807 | 1826 |
| 1808 } // namespace wifi | 1827 } // namespace wifi |
| OLD | NEW |