1 // 2 // Copyright (C) 2015 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef SHILL_DBUS_CHROMEOS_SUPPLICANT_INTERFACE_PROXY_H_ 18 #define SHILL_DBUS_CHROMEOS_SUPPLICANT_INTERFACE_PROXY_H_ 19 20 #include <string> 21 #include <vector> 22 23 #include <base/macros.h> 24 25 #include "shill/refptr_types.h" 26 #include "shill/supplicant/supplicant_interface_proxy_interface.h" 27 #include "supplicant/dbus-proxies.h" 28 29 namespace shill { 30 31 class SupplicantEventDelegateInterface; 32 33 // ChromeosSupplicantInterfaceProxy. provides access to wpa_supplicant's 34 // network-interface APIs via D-Bus. This takes a delegate, which 35 // is an interface that is used to send notifications of supplicant 36 // events. This pointer is not owned by ChromeosSupplicantInterfaceProxy 37 // and must outlive the proxy. 38 class ChromeosSupplicantInterfaceProxy 39 : public SupplicantInterfaceProxyInterface { 40 public: 41 ChromeosSupplicantInterfaceProxy( 42 const scoped_refptr<dbus::Bus>& bus, 43 const std::string& object_path, 44 SupplicantEventDelegateInterface* delegate); 45 ~ChromeosSupplicantInterfaceProxy() override; 46 47 // Implementation of SupplicantInterfaceProxyInterface. 48 bool AddNetwork(const KeyValueStore& args, std::string* network) override; 49 bool EnableHighBitrates() override; 50 bool EAPLogon() override; 51 bool EAPLogoff() override; 52 bool Disconnect() override; 53 bool FlushBSS(const uint32_t& age) override; 54 bool NetworkReply(const std::string& network, 55 const std::string& field, 56 const std::string& value) override; 57 bool Reassociate() override; 58 bool Reattach() override; 59 bool RemoveAllNetworks() override; 60 bool RemoveNetwork(const std::string& network) override; 61 bool Roam(const std::string& addr) override; 62 bool Scan(const KeyValueStore& args) override; 63 bool SelectNetwork(const std::string& network) override; 64 bool TDLSDiscover(const std::string& peer) override; 65 bool TDLSSetup(const std::string& peer) override; 66 bool TDLSStatus(const std::string& peer, std::string* status) override; 67 bool TDLSTeardown(const std::string& peer) override; 68 bool SetHT40Enable(const std::string& network, bool enable) override; 69 // The below set functions will always return true, since PropertySet::Set 70 // is an async method. Any failures will be logged in the callback. 71 bool SetFastReauth(bool enabled) override; 72 bool SetRoamThreshold(uint16_t threshold) override; 73 bool SetScanInterval(int seconds) override; 74 bool SetDisableHighBitrates(bool disable_high_bitrates) override; 75 bool SetSchedScan(bool enable) override; 76 bool SetScan(bool enable) override; 77 78 private: 79 class PropertySet : public dbus::PropertySet { 80 public: 81 PropertySet(dbus::ObjectProxy* object_proxy, 82 const std::string& interface_name, 83 const PropertyChangedCallback& callback); 84 brillo::dbus_utils::Property<bool> disable_high_bitrates; 85 brillo::dbus_utils::Property<bool> fast_reauth; 86 brillo::dbus_utils::Property<uint16_t> roam_threshold; 87 brillo::dbus_utils::Property<bool> scan; 88 brillo::dbus_utils::Property<int32_t> scan_interval; 89 brillo::dbus_utils::Property<bool> sched_scan; 90 91 private: 92 DISALLOW_COPY_AND_ASSIGN(PropertySet); 93 }; 94 95 static const char kInterfaceName[]; 96 static const char kPropertyDisableHighBitrates[]; 97 static const char kPropertyFastReauth[]; 98 static const char kPropertyRoamThreshold[]; 99 static const char kPropertyScan[]; 100 static const char kPropertyScanInterval[]; 101 static const char kPropertySchedScan[]; 102 103 // Signal handlers. 104 void BlobAdded(const std::string& blobname); 105 void BlobRemoved(const std::string& blobname); 106 void BSSAdded(const dbus::ObjectPath& BSS, 107 const brillo::VariantDictionary& properties); 108 void BSSRemoved(const dbus::ObjectPath& BSS); 109 void Certification(const brillo::VariantDictionary& properties); 110 void EAP(const std::string& status, const std::string& parameter); 111 void NetworkAdded(const dbus::ObjectPath& network, 112 const brillo::VariantDictionary& properties); 113 void NetworkRemoved(const dbus::ObjectPath& network); 114 void NetworkSelected(const dbus::ObjectPath& network); 115 void PropertiesChanged( 116 const brillo::VariantDictionary& properties); 117 void ScanDone(bool success); 118 void TDLSDiscoverResponse(const std::string& peer_address); 119 120 // Callback invoked when the value of property |property_name| is changed. 121 void OnPropertyChanged(const std::string& property_name); 122 123 // Called when signal is connected to the ObjectProxy. 124 void OnSignalConnected(const std::string& interface_name, 125 const std::string& signal_name, 126 bool success); 127 128 std::unique_ptr<fi::w1::wpa_supplicant1::InterfaceProxy> interface_proxy_; 129 std::unique_ptr<PropertySet> properties_; 130 131 // This pointer is owned by the object that created |this|. That object 132 // MUST destroy |this| before destroying itself. 133 SupplicantEventDelegateInterface* delegate_; 134 135 base::WeakPtrFactory<ChromeosSupplicantInterfaceProxy> weak_factory_{this}; 136 DISALLOW_COPY_AND_ASSIGN(ChromeosSupplicantInterfaceProxy); 137 }; 138 139 } // namespace shill 140 141 #endif // SHILL_DBUS_CHROMEOS_SUPPLICANT_INTERFACE_PROXY_H_ 142