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 17 matching lines...) Expand all Loading... | |
28 const char kWiFiServiceErrorNotImplemented[] = | 28 const char kWiFiServiceErrorNotImplemented[] = |
29 "Error.WiFiService.NotImplemented"; | 29 "Error.WiFiService.NotImplemented"; |
30 const wchar_t kNwCategoryWizardRegKey[] = | 30 const wchar_t kNwCategoryWizardRegKey[] = |
31 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Network\\" | 31 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Network\\" |
32 L"NwCategoryWizard"; | 32 L"NwCategoryWizard"; |
33 const wchar_t kNwCategoryWizardRegValue[] = L"Show"; | 33 const wchar_t kNwCategoryWizardRegValue[] = L"Show"; |
34 const wchar_t kNwCategoryWizardSavedRegValue[] = L"ShowSaved"; | 34 const wchar_t kNwCategoryWizardSavedRegValue[] = L"ShowSaved"; |
35 const wchar_t kNwCategoryWizardDeleteRegValue[] = L"ShowDelete"; | 35 const wchar_t kNwCategoryWizardDeleteRegValue[] = L"ShowDelete"; |
36 const wchar_t kWlanApiDll[] = L"wlanapi.dll"; | 36 const wchar_t kWlanApiDll[] = L"wlanapi.dll"; |
37 | 37 |
38 // TKIP Profile Dictionary keys | |
39 const char kProfileXmlKey[] = "profile"; | |
40 const char kSharedProfileKey[] = "shared"; | |
41 | |
38 // WlanApi function names | 42 // WlanApi function names |
39 const char kWlanConnect[] = "WlanConnect"; | 43 const char kWlanConnect[] = "WlanConnect"; |
40 const char kWlanCloseHandle[] = "WlanCloseHandle"; | 44 const char kWlanCloseHandle[] = "WlanCloseHandle"; |
41 const char kWlanDisconnect[] = "WlanDisconnect"; | 45 const char kWlanDisconnect[] = "WlanDisconnect"; |
42 const char kWlanEnumInterfaces[] = "WlanEnumInterfaces"; | 46 const char kWlanEnumInterfaces[] = "WlanEnumInterfaces"; |
43 const char kWlanFreeMemory[] = "WlanFreeMemory"; | 47 const char kWlanFreeMemory[] = "WlanFreeMemory"; |
44 const char kWlanGetAvailableNetworkList[] = "WlanGetAvailableNetworkList"; | 48 const char kWlanGetAvailableNetworkList[] = "WlanGetAvailableNetworkList"; |
45 const char kWlanGetNetworkBssList[] = "WlanGetNetworkBssList"; | 49 const char kWlanGetNetworkBssList[] = "WlanGetNetworkBssList"; |
46 const char kWlanGetProfile[] = "WlanGetProfile"; | 50 const char kWlanGetProfile[] = "WlanGetProfile"; |
47 const char kWlanOpenHandle[] = "WlanOpenHandle"; | 51 const char kWlanOpenHandle[] = "WlanOpenHandle"; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 std::string* error) OVERRIDE; | 219 std::string* error) OVERRIDE; |
216 | 220 |
217 virtual void SetEventObservers( | 221 virtual void SetEventObservers( |
218 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 222 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
219 const NetworkGuidListCallback& networks_changed_observer, | 223 const NetworkGuidListCallback& networks_changed_observer, |
220 const NetworkGuidListCallback& network_list_changed_observer) OVERRIDE; | 224 const NetworkGuidListCallback& network_list_changed_observer) OVERRIDE; |
221 | 225 |
222 virtual void RequestConnectedNetworkUpdate() OVERRIDE {} | 226 virtual void RequestConnectedNetworkUpdate() OVERRIDE {} |
223 | 227 |
224 private: | 228 private: |
229 typedef int32 EncryptionType; | |
230 enum EncryptionTypeEnum { | |
231 kEncryptionTypeAny = 0, | |
232 kEncryptionTypeAES = 1, | |
233 kEncryptionTypeTKIP = 2 | |
234 }; | |
235 | |
225 // Static callback for Windows WLAN_NOTIFICATION. Calls OnWlanNotification | 236 // Static callback for Windows WLAN_NOTIFICATION. Calls OnWlanNotification |
226 // on WiFiServiceImpl passed back as |context|. | 237 // on WiFiServiceImpl passed back as |context|. |
227 static void __stdcall OnWlanNotificationCallback( | 238 static void __stdcall OnWlanNotificationCallback( |
228 PWLAN_NOTIFICATION_DATA wlan_notification_data, | 239 PWLAN_NOTIFICATION_DATA wlan_notification_data, |
229 PVOID context); | 240 PVOID context); |
230 | 241 |
231 // Callback for Windows WLAN_NOTIFICATION. Called on random thread from | 242 // Callback for Windows WLAN_NOTIFICATION. Called on random thread from |
232 // OnWlanNotificationCallback. Handles network connectivity and scan complete | 243 // OnWlanNotificationCallback. Handles network connectivity and scan complete |
233 // notification and posts tasks to main thread. | 244 // notification and posts tasks to main thread. |
234 void OnWlanNotification(PWLAN_NOTIFICATION_DATA wlan_notification_data); | 245 void OnWlanNotification(PWLAN_NOTIFICATION_DATA wlan_notification_data); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 // Get unique |network_guid| string based on |wlan|. | 319 // Get unique |network_guid| string based on |wlan|. |
309 std::string GUIDFromWLAN(const WLAN_AVAILABLE_NETWORK& wlan) const { | 320 std::string GUIDFromWLAN(const WLAN_AVAILABLE_NETWORK& wlan) const { |
310 return SSIDFromWLAN(wlan); | 321 return SSIDFromWLAN(wlan); |
311 } | 322 } |
312 | 323 |
313 // Deduce |onc::wifi| security from |alg|. | 324 // Deduce |onc::wifi| security from |alg|. |
314 std::string SecurityFromDot11AuthAlg(DOT11_AUTH_ALGORITHM alg) const; | 325 std::string SecurityFromDot11AuthAlg(DOT11_AUTH_ALGORITHM alg) const; |
315 | 326 |
316 // Deduce WLANProfile |authEncryption| values from |onc::wifi| security. | 327 // Deduce WLANProfile |authEncryption| values from |onc::wifi| security. |
317 bool AuthEncryptionFromSecurity(const std::string& security, | 328 bool AuthEncryptionFromSecurity(const std::string& security, |
329 EncryptionType encryption_type, | |
318 std::string* authentication, | 330 std::string* authentication, |
319 std::string* encryption, | 331 std::string* encryption, |
320 std::string* key_type) const; | 332 std::string* key_type) const; |
321 | 333 |
322 // Populate |properties| based on |wlan| and its corresponding bss info from | 334 // Populate |properties| based on |wlan| and its corresponding bss info from |
323 // |wlan_bss_list|. | 335 // |wlan_bss_list|. |
324 void NetworkPropertiesFromAvailableNetwork(const WLAN_AVAILABLE_NETWORK& wlan, | 336 void NetworkPropertiesFromAvailableNetwork(const WLAN_AVAILABLE_NETWORK& wlan, |
325 const WLAN_BSS_LIST& wlan_bss_list, | 337 const WLAN_BSS_LIST& wlan_bss_list, |
326 NetworkProperties* properties); | 338 NetworkProperties* properties); |
327 | 339 |
(...skipping 23 matching lines...) Expand all Loading... | |
351 | 363 |
352 // Get DOT11_BSSID_LIST of desired BSSIDs to connect to |ssid| network on | 364 // Get DOT11_BSSID_LIST of desired BSSIDs to connect to |ssid| network on |
353 // given |frequency|. | 365 // given |frequency|. |
354 DWORD GetDesiredBssList(DOT11_SSID& ssid, | 366 DWORD GetDesiredBssList(DOT11_SSID& ssid, |
355 Frequency frequency, | 367 Frequency frequency, |
356 scoped_ptr<DOT11_BSSID_LIST>* desired_list); | 368 scoped_ptr<DOT11_BSSID_LIST>* desired_list); |
357 | 369 |
358 // Normalizes |frequency_in_mhz| into one of |Frequency| values. | 370 // Normalizes |frequency_in_mhz| into one of |Frequency| values. |
359 Frequency GetNormalizedFrequency(int frequency_in_mhz) const; | 371 Frequency GetNormalizedFrequency(int frequency_in_mhz) const; |
360 | 372 |
361 // Create |profile_xml| based on |network_properties|. | 373 // Create |profile_xml| based on |network_properties|. If |encryptio_type| |
afontan
2014/03/17 19:56:55
typo encryptio_type
mef
2014/03/17 21:40:09
Done.
| |
374 // is |kEncryptionTypeAny| applies the type most suitable for parameters in | |
375 // |network_properties|. | |
362 bool CreateProfile(const NetworkProperties& network_properties, | 376 bool CreateProfile(const NetworkProperties& network_properties, |
377 EncryptionType encryption_type, | |
363 std::string* profile_xml); | 378 std::string* profile_xml); |
364 | 379 |
365 // Save temporary wireless profile for |network_guid|. | 380 // Save temporary wireless profile for |network_guid|. |
366 DWORD SaveTempProfile(const std::string& network_guid); | 381 DWORD SaveTempProfile(const std::string& network_guid); |
367 | 382 |
368 // Get previously stored |profile_xml| for |network_guid|. | 383 // Get previously stored |profile_xml| for |network_guid|. |
369 // If |get_plaintext_key| is true, and process has sufficient privileges, then | 384 // If |get_plaintext_key| is true, and process has sufficient privileges, then |
370 // <sharedKey> data in |profile_xml| will be unprotected. | 385 // <sharedKey> data in |profile_xml| will be unprotected. |
371 DWORD GetProfile(const std::string& network_guid, | 386 DWORD GetProfile(const std::string& network_guid, |
372 bool get_plaintext_key, | 387 bool get_plaintext_key, |
373 std::string* profile_xml); | 388 std::string* profile_xml); |
374 | 389 |
390 // Set |profile_xml| to current user or all users depending on |shared| flag. | |
391 // If |overwrite| is false, then returns an error if profile exists. | |
392 DWORD SetProfile(bool shared, const std::string& profile_xml, bool overwrite); | |
393 | |
375 // Return true if there is previously stored profile xml for |network_guid|. | 394 // Return true if there is previously stored profile xml for |network_guid|. |
376 bool HaveProfile(const std::string& network_guid); | 395 bool HaveProfile(const std::string& network_guid); |
377 | 396 |
378 // Notify |network_list_changed_observer_| that list of visible networks has | 397 // Notify |network_list_changed_observer_| that list of visible networks has |
379 // changed to |networks|. | 398 // changed to |networks|. |
380 void NotifyNetworkListChanged(const NetworkList& networks); | 399 void NotifyNetworkListChanged(const NetworkList& networks); |
381 | 400 |
382 // Notify |networks_changed_observer_| that network |network_guid| status has | 401 // Notify |networks_changed_observer_| that network |network_guid| status has |
383 // changed. | 402 // changed. |
384 void NotifyNetworkChanged(const std::string& network_guid); | 403 void NotifyNetworkChanged(const std::string& network_guid); |
(...skipping 23 matching lines...) Expand all Loading... | |
408 // WLAN service handle. | 427 // WLAN service handle. |
409 HANDLE client_; | 428 HANDLE client_; |
410 // GUID of the currently connected interface, if any, otherwise the GUID of | 429 // GUID of the currently connected interface, if any, otherwise the GUID of |
411 // one of the WLAN interfaces. | 430 // one of the WLAN interfaces. |
412 GUID interface_guid_; | 431 GUID interface_guid_; |
413 // Temporary storage of network properties indexed by |network_guid|. Persist | 432 // Temporary storage of network properties indexed by |network_guid|. Persist |
414 // only in memory. | 433 // only in memory. |
415 base::DictionaryValue connect_properties_; | 434 base::DictionaryValue connect_properties_; |
416 // Preserved WLAN profile xml. | 435 // Preserved WLAN profile xml. |
417 std::map<std::string, std::string> saved_profiles_xml_; | 436 std::map<std::string, std::string> saved_profiles_xml_; |
437 // WLAN profile xml with TKIP encryption type saved by |CreateNetwork| | |
438 // indexed by |network_guid|. Persist only in memory. | |
439 base::DictionaryValue tkip_profiles_; | |
418 // Observer to get notified when network(s) have changed (e.g. connect). | 440 // Observer to get notified when network(s) have changed (e.g. connect). |
419 NetworkGuidListCallback networks_changed_observer_; | 441 NetworkGuidListCallback networks_changed_observer_; |
420 // Observer to get notified when network list has changed (scan complete). | 442 // Observer to get notified when network list has changed (scan complete). |
421 NetworkGuidListCallback network_list_changed_observer_; | 443 NetworkGuidListCallback network_list_changed_observer_; |
422 // Saved value of network location wizard show value. | 444 // Saved value of network location wizard show value. |
423 scoped_ptr<DWORD> saved_nw_category_wizard_; | 445 scoped_ptr<DWORD> saved_nw_category_wizard_; |
424 // MessageLoopProxy to post events on UI thread. | 446 // MessageLoopProxy to post events on UI thread. |
425 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 447 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
426 // Task runner for worker tasks. | 448 // Task runner for worker tasks. |
427 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 449 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 return; | 551 return; |
530 | 552 |
531 WiFiService::NetworkProperties network_properties; | 553 WiFiService::NetworkProperties network_properties; |
532 if (!network_properties.UpdateFromValue(*properties)) { | 554 if (!network_properties.UpdateFromValue(*properties)) { |
533 CheckError(ERROR_INVALID_DATA, kWiFiServiceError, error); | 555 CheckError(ERROR_INVALID_DATA, kWiFiServiceError, error); |
534 return; | 556 return; |
535 } | 557 } |
536 | 558 |
537 network_properties.guid = network_properties.ssid; | 559 network_properties.guid = network_properties.ssid; |
538 std::string profile_xml; | 560 std::string profile_xml; |
539 if (!CreateProfile(network_properties, &profile_xml)) { | 561 if (!CreateProfile(network_properties, kEncryptionTypeAny, &profile_xml)) { |
540 CheckError(ERROR_INVALID_DATA, kWiFiServiceError, error); | 562 CheckError(ERROR_INVALID_DATA, kWiFiServiceError, error); |
541 return; | 563 return; |
542 } | 564 } |
543 | 565 |
544 base::string16 profile_xml16(base::UTF8ToUTF16(profile_xml)); | 566 error_code = SetProfile(shared, profile_xml, false); |
545 DWORD reason_code = 0u; | |
546 | |
547 error_code = WlanSetProfile_function_(client_, | |
548 &interface_guid_, | |
549 shared ? 0 : WLAN_PROFILE_USER, | |
550 profile_xml16.c_str(), | |
551 NULL, | |
552 FALSE, | |
553 NULL, | |
554 &reason_code); | |
555 if (CheckError(error_code, kWiFiServiceError, error)) { | 567 if (CheckError(error_code, kWiFiServiceError, error)) { |
556 DVLOG(0) << profile_xml; | 568 DVLOG(0) << profile_xml; |
557 DVLOG(0) << "SetProfile Reason Code:" << reason_code; | |
558 return; | 569 return; |
559 } | 570 } |
560 | 571 |
572 // WAP and WAP2 networks could use either AES or TKIP encryption type. | |
573 // Preserve alternative profile to use in case if connection with default | |
574 // encryption type fails. | |
575 std::string tkip_profile_xml; | |
576 if (!CreateProfile(network_properties, | |
577 kEncryptionTypeTKIP, | |
578 &tkip_profile_xml)) { | |
579 CheckError(ERROR_INVALID_DATA, kWiFiServiceError, error); | |
580 return; | |
581 } | |
582 | |
583 if (tkip_profile_xml != profile_xml) { | |
584 scoped_ptr<base::DictionaryValue> tkip_profile(new base::DictionaryValue()); | |
585 tkip_profile->SetString(kProfileXmlKey, tkip_profile_xml); | |
586 tkip_profile->SetBoolean(kSharedProfileKey, shared); | |
587 tkip_profiles_.SetWithoutPathExpansion(network_properties.guid, | |
588 tkip_profile.release()); | |
589 } | |
590 | |
561 *network_guid = network_properties.guid; | 591 *network_guid = network_properties.guid; |
562 } | 592 } |
563 | 593 |
564 void WiFiServiceImpl::GetVisibleNetworks(const std::string& network_type, | 594 void WiFiServiceImpl::GetVisibleNetworks(const std::string& network_type, |
565 base::ListValue* network_list) { | 595 base::ListValue* network_list) { |
566 if (!network_type.empty() && | 596 if (!network_type.empty() && |
567 network_type != onc::network_type::kAllTypes && | 597 network_type != onc::network_type::kAllTypes && |
568 network_type != onc::network_type::kWiFi) { | 598 network_type != onc::network_type::kWiFi) { |
569 return; | 599 return; |
570 } | 600 } |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
777 NotifyNetworkListChanged(networks); | 807 NotifyNetworkListChanged(networks); |
778 } | 808 } |
779 | 809 |
780 void WiFiServiceImpl::WaitForNetworkConnect(const std::string& network_guid, | 810 void WiFiServiceImpl::WaitForNetworkConnect(const std::string& network_guid, |
781 int attempt) { | 811 int attempt) { |
782 // If network didn't get connected in |kMaxAttempts|, then restore automatic | 812 // If network didn't get connected in |kMaxAttempts|, then restore automatic |
783 // network change notifications and stop waiting. | 813 // network change notifications and stop waiting. |
784 if (attempt > kMaxAttempts) { | 814 if (attempt > kMaxAttempts) { |
785 DLOG(ERROR) << kMaxAttempts << " attempts exceeded waiting for connect to " | 815 DLOG(ERROR) << kMaxAttempts << " attempts exceeded waiting for connect to " |
786 << network_guid; | 816 << network_guid; |
787 enable_notify_network_changed_ = true; | 817 |
788 RestoreNwCategoryWizard(); | 818 // Check, if there is alternative TKIP profile that should be tried. |
819 // If there is, then set it up and try to connect again. | |
820 const base::DictionaryValue* tkip_profile = NULL; | |
821 if (tkip_profiles_.GetDictionaryWithoutPathExpansion( | |
822 network_guid, &tkip_profile)) { | |
823 std::string tkip_profile_xml; | |
824 bool shared = false; | |
825 tkip_profile->GetString(kProfileXmlKey, &tkip_profile_xml); | |
826 tkip_profile->GetBoolean(kSharedProfileKey, &shared); | |
827 DWORD error_code = SetProfile(shared, tkip_profile_xml, true); | |
828 if (error_code == ERROR_SUCCESS) { | |
829 // Try to connect with new profile. | |
830 error_code = Connect(network_guid, GetFrequencyToConnect(network_guid)); | |
831 if (error_code == ERROR_SUCCESS) | |
832 WaitForNetworkConnect(network_guid, 0); | |
833 } | |
834 tkip_profiles_.RemoveWithoutPathExpansion(network_guid, NULL); | |
835 } else { | |
836 enable_notify_network_changed_ = true; | |
837 RestoreNwCategoryWizard(); | |
838 } | |
789 return; | 839 return; |
790 } | 840 } |
791 std::string connected_network_guid; | 841 std::string connected_network_guid; |
792 DWORD error = FindConnectedNetwork(&connected_network_guid); | 842 DWORD error = FindConnectedNetwork(&connected_network_guid); |
793 if (network_guid == connected_network_guid) { | 843 if (network_guid == connected_network_guid) { |
794 DVLOG(1) << "WiFi Connected, Reset DHCP: " << network_guid; | 844 DVLOG(1) << "WiFi Connected, Reset DHCP: " << network_guid; |
795 // Even though wireless network is now connected, it may still be unusable, | 845 // Even though wireless network is now connected, it may still be unusable, |
796 // e.g. after Chromecast device reset. Reset DHCP on wireless network to | 846 // e.g. after Chromecast device reset. Reset DHCP on wireless network to |
797 // work around this issue. | 847 // work around this issue. |
798 error = ResetDHCP(); | 848 error = ResetDHCP(); |
849 // There is no need to keep TKIP profile as network is connected. | |
850 tkip_profiles_.RemoveWithoutPathExpansion(network_guid, NULL); | |
799 // Restore previously suppressed notifications. | 851 // Restore previously suppressed notifications. |
800 enable_notify_network_changed_ = true; | 852 enable_notify_network_changed_ = true; |
801 RestoreNwCategoryWizard(); | 853 RestoreNwCategoryWizard(); |
802 NotifyNetworkChanged(network_guid); | 854 NotifyNetworkChanged(network_guid); |
803 } else { | 855 } else { |
804 // Continue waiting for network connection state change. | 856 // Continue waiting for network connection state change. |
805 task_runner_->PostDelayedTask( | 857 task_runner_->PostDelayedTask( |
806 FROM_HERE, | 858 FROM_HERE, |
807 base::Bind(&WiFiServiceImpl::WaitForNetworkConnect, | 859 base::Bind(&WiFiServiceImpl::WaitForNetworkConnect, |
808 base::Unretained(this), | 860 base::Unretained(this), |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1545 *profile_xml = base::UTF16ToUTF8(str_profile_xml); | 1597 *profile_xml = base::UTF16ToUTF8(str_profile_xml); |
1546 } | 1598 } |
1547 // Clean up. | 1599 // Clean up. |
1548 if (str_profile_xml != NULL) { | 1600 if (str_profile_xml != NULL) { |
1549 WlanFreeMemory_function_(str_profile_xml); | 1601 WlanFreeMemory_function_(str_profile_xml); |
1550 } | 1602 } |
1551 | 1603 |
1552 return error; | 1604 return error; |
1553 } | 1605 } |
1554 | 1606 |
1607 DWORD WiFiServiceImpl::SetProfile(bool shared, | |
1608 const std::string& profile_xml, | |
1609 bool overwrite) { | |
1610 DWORD error_code = ERROR_SUCCESS; | |
1611 | |
1612 base::string16 profile_xml16(base::UTF8ToUTF16(profile_xml)); | |
1613 DWORD reason_code = 0u; | |
1614 | |
1615 error_code = WlanSetProfile_function_(client_, | |
1616 &interface_guid_, | |
1617 shared ? 0 : WLAN_PROFILE_USER, | |
1618 profile_xml16.c_str(), | |
1619 NULL, | |
1620 overwrite, | |
1621 NULL, | |
1622 &reason_code); | |
afontan
2014/03/17 19:56:55
Why WlanSetProfile instead of WlanSaveTemporaryPro
mef
2014/03/17 21:40:09
Hmm, no apparently good reason. WlanSaveTemporaryP
| |
1623 return error_code; | |
1624 } | |
1625 | |
1555 bool WiFiServiceImpl::HaveProfile(const std::string& network_guid) { | 1626 bool WiFiServiceImpl::HaveProfile(const std::string& network_guid) { |
1556 DWORD error = ERROR_SUCCESS; | 1627 DWORD error = ERROR_SUCCESS; |
1557 std::string profile_xml; | 1628 std::string profile_xml; |
1558 return GetProfile(network_guid, false, &profile_xml) == ERROR_SUCCESS; | 1629 return GetProfile(network_guid, false, &profile_xml) == ERROR_SUCCESS; |
1559 } | 1630 } |
1560 | 1631 |
1561 bool WiFiServiceImpl::AuthEncryptionFromSecurity( | 1632 bool WiFiServiceImpl::AuthEncryptionFromSecurity( |
1562 const std::string& security, | 1633 const std::string& security, |
1634 EncryptionType encryption_type, | |
1563 std::string* authentication, | 1635 std::string* authentication, |
1564 std::string* encryption, | 1636 std::string* encryption, |
1565 std::string* key_type) const { | 1637 std::string* key_type) const { |
1566 if (security == onc::wifi::kNone) { | 1638 if (security == onc::wifi::kNone) { |
1567 *authentication = kAuthenticationOpen; | 1639 *authentication = kAuthenticationOpen; |
1568 *encryption = kEncryptionNone; | 1640 *encryption = kEncryptionNone; |
1569 } else if (security == onc::wifi::kWEP_PSK) { | 1641 } else if (security == onc::wifi::kWEP_PSK) { |
1570 *authentication = kAuthenticationOpen; | 1642 *authentication = kAuthenticationOpen; |
1571 *encryption = kEncryptionWEP; | 1643 *encryption = kEncryptionWEP; |
1572 *key_type = kKeyTypeNetwork; | 1644 *key_type = kKeyTypeNetwork; |
1573 } else if (security == onc::wifi::kWPA_PSK) { | 1645 } else if (security == onc::wifi::kWPA_PSK) { |
1574 *authentication = kAuthenticationWpaPsk; | 1646 *authentication = kAuthenticationWpaPsk; |
1575 // TODO(mef): WAP |encryption| could be either |AES| or |TKIP|. It has to be | 1647 if (encryption_type == kEncryptionTypeTKIP) { |
1576 // determined and adjusted properly during |Connect|. | 1648 *encryption = kEncryptionTKIP; |
1577 *encryption = kEncryptionAES; | 1649 } else { |
1650 *encryption = kEncryptionAES; | |
1651 } | |
1578 *key_type = kKeyTypePassphrase; | 1652 *key_type = kKeyTypePassphrase; |
1579 } else if (security == onc::wifi::kWPA2_PSK) { | 1653 } else if (security == onc::wifi::kWPA2_PSK) { |
1580 *authentication = kAuthenticationWpa2Psk; | 1654 *authentication = kAuthenticationWpa2Psk; |
1581 // TODO(mef): WAP |encryption| could be either |AES| or |TKIP|. It has to be | 1655 if (encryption_type == kEncryptionTypeTKIP) { |
1582 // determined and adjusted properly during |Connect|. | 1656 *encryption = kEncryptionTKIP; |
1583 *encryption = kEncryptionAES; | 1657 } else { |
1658 *encryption = kEncryptionAES; | |
1659 } | |
1584 *key_type = kKeyTypePassphrase; | 1660 *key_type = kKeyTypePassphrase; |
1585 } else { | 1661 } else { |
1586 return false; | 1662 return false; |
1587 } | 1663 } |
1588 return true; | 1664 return true; |
1589 } | 1665 } |
1590 | 1666 |
1591 bool WiFiServiceImpl::CreateProfile( | 1667 bool WiFiServiceImpl::CreateProfile( |
1592 const NetworkProperties& network_properties, | 1668 const NetworkProperties& network_properties, |
1669 EncryptionType encryption_type, | |
1593 std::string* profile_xml) { | 1670 std::string* profile_xml) { |
1594 // Get authentication and encryption values from security. | 1671 // Get authentication and encryption values from security. |
1595 std::string authentication; | 1672 std::string authentication; |
1596 std::string encryption; | 1673 std::string encryption; |
1597 std::string key_type; | 1674 std::string key_type; |
1598 bool valid = AuthEncryptionFromSecurity(network_properties.security, | 1675 bool valid = AuthEncryptionFromSecurity(network_properties.security, |
1676 encryption_type, | |
1599 &authentication, | 1677 &authentication, |
1600 &encryption, | 1678 &encryption, |
1601 &key_type); | 1679 &key_type); |
1602 if (!valid) | 1680 if (!valid) |
1603 return valid; | 1681 return valid; |
1604 | 1682 |
1605 // Generate profile XML. | 1683 // Generate profile XML. |
1606 XmlWriter xml_writer; | 1684 XmlWriter xml_writer; |
1607 xml_writer.StartWriting(); | 1685 xml_writer.StartWriting(); |
1608 xml_writer.StartElement("WLANProfile"); | 1686 xml_writer.StartElement("WLANProfile"); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1662 NetworkGuidList changed_networks(1, network_guid); | 1740 NetworkGuidList changed_networks(1, network_guid); |
1663 message_loop_proxy_->PostTask( | 1741 message_loop_proxy_->PostTask( |
1664 FROM_HERE, | 1742 FROM_HERE, |
1665 base::Bind(networks_changed_observer_, changed_networks)); | 1743 base::Bind(networks_changed_observer_, changed_networks)); |
1666 } | 1744 } |
1667 } | 1745 } |
1668 | 1746 |
1669 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } | 1747 WiFiService* WiFiService::Create() { return new WiFiServiceImpl(); } |
1670 | 1748 |
1671 } // namespace wifi | 1749 } // namespace wifi |
OLD | NEW |