OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/extensions/api/networking_private/networking_private_li nux.h" | 5 #include "chrome/browser/extensions/api/networking_private/networking_private_li nux.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 if (!reader.PopVariantOfByte(&strength)) { | 573 if (!reader.PopVariantOfByte(&strength)) { |
574 LOG(ERROR) << "Unexpected response for " << access_point_path.value() | 574 LOG(ERROR) << "Unexpected response for " << access_point_path.value() |
575 << ": " << response->ToString(); | 575 << ": " << response->ToString(); |
576 return false; | 576 return false; |
577 } | 577 } |
578 | 578 |
579 access_point_info->SetInteger(kAccessPointInfoWifiSignalStrengthDotted, | 579 access_point_info->SetInteger(kAccessPointInfoWifiSignalStrengthDotted, |
580 strength); | 580 strength); |
581 } | 581 } |
582 | 582 |
583 // Read the security type. | 583 // Read the security type. This is from the WpaFlags and RsnFlags property |
584 // which are of the same type and can be OR'd together to find all supported | |
585 // security modes. | |
stevenjb
2014/12/05 20:32:42
nit: blank space since the comment applies to both
zentaro
2014/12/05 21:16:44
Done.
| |
586 uint32 wpa_security_flags = 0; | |
584 { | 587 { |
585 scoped_ptr<dbus::Response> response(GetAccessPointProperty( | 588 scoped_ptr<dbus::Response> response(GetAccessPointProperty( |
586 access_point_proxy, | 589 access_point_proxy, |
587 networking_private::kNetworkManagerWpaFlagsProperty)); | 590 networking_private::kNetworkManagerWpaFlagsProperty)); |
588 if (!response) { | 591 if (!response) { |
589 return false; | 592 return false; |
590 } | 593 } |
591 | 594 |
592 dbus::MessageReader reader(response.get()); | 595 dbus::MessageReader reader(response.get()); |
593 uint32 security_flags = 0; | 596 |
594 if (!reader.PopVariantOfUint32(&security_flags)) { | 597 if (!reader.PopVariantOfUint32(&wpa_security_flags)) { |
595 LOG(ERROR) << "Unexpected response for " << access_point_path.value() | 598 LOG(ERROR) << "Unexpected response for " << access_point_path.value() |
596 << ": " << response->ToString(); | 599 << ": " << response->ToString(); |
597 return false; | 600 return false; |
598 } | 601 } |
599 | |
600 std::string security; | |
601 MapSecurityFlagsToString(security_flags, &security); | |
602 access_point_info->SetString(kAccessPointInfoWifiSecurityDotted, security); | |
603 } | 602 } |
604 | 603 |
604 uint32 rsn_security_flags = 0; | |
605 { | |
606 scoped_ptr<dbus::Response> response(GetAccessPointProperty( | |
607 access_point_proxy, | |
608 networking_private::kNetworkManagerRsnFlagsProperty)); | |
609 if (!response) { | |
610 return false; | |
611 } | |
612 | |
613 dbus::MessageReader reader(response.get()); | |
614 | |
615 if (!reader.PopVariantOfUint32(&rsn_security_flags)) { | |
616 LOG(ERROR) << "Unexpected response for " << access_point_path.value() | |
617 << ": " << response->ToString(); | |
618 return false; | |
619 } | |
620 } | |
621 | |
622 std::string security; | |
623 MapSecurityFlagsToString(rsn_security_flags | wpa_security_flags, &security); | |
624 access_point_info->SetString(kAccessPointInfoWifiSecurityDotted, security); | |
605 access_point_info->SetString(kAccessPointInfoType, kAccessPointInfoTypeWifi); | 625 access_point_info->SetString(kAccessPointInfoType, kAccessPointInfoTypeWifi); |
606 access_point_info->SetBoolean(kAccessPointInfoConnectable, true); | 626 access_point_info->SetBoolean(kAccessPointInfoConnectable, true); |
607 return true; | 627 return true; |
608 } | 628 } |
609 | 629 |
610 bool NetworkingPrivateLinux::AddAccessPointsFromDevice( | 630 bool NetworkingPrivateLinux::AddAccessPointsFromDevice( |
611 const dbus::ObjectPath& device_path, | 631 const dbus::ObjectPath& device_path, |
612 NetworkMap* network_map) { | 632 NetworkMap* network_map) { |
613 AssertOnDBusThread(); | 633 AssertOnDBusThread(); |
614 dbus::ObjectPath connected_access_point; | 634 dbus::ObjectPath connected_access_point; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
710 connection_state); | 730 connection_state); |
711 existing_access_point->SetInteger( | 731 existing_access_point->SetInteger( |
712 kAccessPointInfoWifiSignalStrengthDotted, signal_strength); | 732 kAccessPointInfoWifiSignalStrengthDotted, signal_strength); |
713 existing_access_point->SetString(kAccessPointInfoGuid, network_guid); | 733 existing_access_point->SetString(kAccessPointInfoGuid, network_guid); |
714 } | 734 } |
715 } | 735 } |
716 } | 736 } |
717 | 737 |
718 void NetworkingPrivateLinux::MapSecurityFlagsToString(uint32 security_flags, | 738 void NetworkingPrivateLinux::MapSecurityFlagsToString(uint32 security_flags, |
719 std::string* security) { | 739 std::string* security) { |
720 // TODO(zentaro): Correct mapping - this may not be correct but the underlying | |
721 // API appears not to work on Trusty so I can't verify yet. | |
722 // Everything returns 0. | |
723 // Valid values are None, WEP-PSK, WEP-8021X, WPA-PSK, WPA-EAP | 740 // Valid values are None, WEP-PSK, WEP-8021X, WPA-PSK, WPA-EAP |
724 if (security_flags == NetworkingPrivateLinux::NM_802_11_AP_SEC_NONE) { | 741 if (security_flags == NetworkingPrivateLinux::NM_802_11_AP_SEC_NONE) { |
725 *security = kAccessPointSecurityNone; | 742 *security = kAccessPointSecurityNone; |
726 } else if (security_flags & | 743 } else if (security_flags & |
727 NetworkingPrivateLinux::NM_802_11_AP_SEC_KEY_MGMT_PSK) { | 744 NetworkingPrivateLinux::NM_802_11_AP_SEC_KEY_MGMT_PSK) { |
728 *security = kAccessPointSecurityWpaPsk; | 745 *security = kAccessPointSecurityWpaPsk; |
729 } else if (security_flags & | 746 } else if (security_flags & |
730 NetworkingPrivateLinux::NM_802_11_AP_SEC_KEY_MGMT_802_1X) { | 747 NetworkingPrivateLinux::NM_802_11_AP_SEC_KEY_MGMT_802_1X) { |
731 *security = kAccessPointSecurity9021X; | 748 *security = kAccessPointSecurity9021X; |
732 } else { | 749 } else { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
874 | 891 |
875 if (!variant_reader.PopObjectPath(access_point_path)) { | 892 if (!variant_reader.PopObjectPath(access_point_path)) { |
876 LOG(ERROR) << "Unexpected response: " << response->ToString(); | 893 LOG(ERROR) << "Unexpected response: " << response->ToString(); |
877 return false; | 894 return false; |
878 } | 895 } |
879 | 896 |
880 return true; | 897 return true; |
881 } | 898 } |
882 | 899 |
883 } // namespace extensions | 900 } // namespace extensions |
OLD | NEW |