mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/supplicant_interface_proxy.h" |
| 6 | |
| 7 | #include <map> |
| 8 | #include <string> |
| 9 | |
| 10 | #include <base/logging.h> |
| 11 | #include <dbus-c++/dbus.h> |
| 12 | |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 13 | #include "shill/scope_logger.h" |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 14 | #include "shill/wifi.h" |
| 15 | |
| 16 | using std::map; |
| 17 | using std::string; |
| 18 | |
| 19 | namespace shill { |
| 20 | |
| 21 | SupplicantInterfaceProxy::SupplicantInterfaceProxy( |
| 22 | const WiFiRefPtr &wifi, |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 23 | DBus::Connection *bus, |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 24 | const ::DBus::Path &object_path, |
| 25 | const char *dbus_addr) |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 26 | : proxy_(wifi, bus, object_path, dbus_addr) {} |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 27 | |
| 28 | SupplicantInterfaceProxy::~SupplicantInterfaceProxy() {} |
| 29 | |
| 30 | ::DBus::Path SupplicantInterfaceProxy::AddNetwork( |
| 31 | const std::map<std::string, ::DBus::Variant> &args) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 32 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 33 | try { |
| 34 | return proxy_.AddNetwork(args); |
| 35 | } catch (const DBus::Error &e) { |
| 36 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what() |
| 37 | << " args keys are: " << DBusProperties::KeysToString(args); |
| 38 | return ::DBus::Path(); // Make the compiler happy. |
| 39 | } |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 42 | void SupplicantInterfaceProxy::ClearCachedCredentials() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 43 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 44 | try { |
| 45 | return proxy_.ClearCachedCredentials(); |
| 46 | } catch (const DBus::Error &e) { |
| 47 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 48 | } |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 49 | } |
| 50 | |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 51 | void SupplicantInterfaceProxy::Disconnect() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 52 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 53 | try { |
| 54 | return proxy_.Disconnect(); |
| 55 | } catch (const DBus::Error &e) { |
| 56 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 57 | } |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 58 | } |
| 59 | |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 60 | void SupplicantInterfaceProxy::FlushBSS(const uint32_t &age) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 61 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 62 | try { |
| 63 | return proxy_.FlushBSS(age); |
| 64 | } catch (const DBus::Error &e) { |
| 65 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what() |
| 66 | << " age: " << age; |
| 67 | } |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void SupplicantInterfaceProxy::RemoveAllNetworks() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 71 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 72 | try { |
| 73 | return proxy_.RemoveAllNetworks(); |
| 74 | } catch (const DBus::Error &e) { |
| 75 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 76 | } |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 77 | } |
| 78 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 79 | void SupplicantInterfaceProxy::RemoveNetwork(const ::DBus::Path &network) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 80 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 81 | try { |
| 82 | return proxy_.RemoveNetwork(network); |
| 83 | } catch (const DBus::Error &e) { |
| 84 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 85 | } |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 86 | } |
| 87 | |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 88 | void SupplicantInterfaceProxy::Scan( |
| 89 | const std::map<std::string, ::DBus::Variant> &args) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 90 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 91 | try { |
| 92 | return proxy_.Scan(args); |
| 93 | } catch (const DBus::Error &e) { |
| 94 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what() |
| 95 | << " args keys are: " << DBusProperties::KeysToString(args); |
| 96 | } |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | void SupplicantInterfaceProxy::SelectNetwork(const ::DBus::Path &network) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 100 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 101 | try { |
| 102 | return proxy_.SelectNetwork(network); |
| 103 | } catch (const DBus::Error &e) { |
| 104 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 105 | } |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Paul Stewart | 2987dcf | 2012-01-30 15:47:42 -0800 | [diff] [blame] | 108 | void SupplicantInterfaceProxy::SetFastReauth(bool enabled) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 109 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 110 | try { |
| 111 | return proxy_.FastReauth(enabled); |
| 112 | } catch (const DBus::Error &e) { |
| 113 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what() |
| 114 | << "enabled: " << enabled; |
| 115 | } |
Paul Stewart | 2987dcf | 2012-01-30 15:47:42 -0800 | [diff] [blame] | 116 | } |
| 117 | |
mukesh agrawal | f202817 | 2012-03-13 14:20:22 -0700 | [diff] [blame] | 118 | void SupplicantInterfaceProxy::SetScanInterval(int32 scan_interval) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 119 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 120 | try { |
| 121 | return proxy_.ScanInterval(scan_interval); |
| 122 | } catch (const DBus::Error &e) { |
| 123 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what() |
| 124 | << " scan interval: " << scan_interval; |
| 125 | } |
mukesh agrawal | f202817 | 2012-03-13 14:20:22 -0700 | [diff] [blame] | 126 | } |
| 127 | |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 128 | // definitions for private class SupplicantInterfaceProxy::Proxy |
| 129 | |
| 130 | SupplicantInterfaceProxy::Proxy::Proxy( |
| 131 | const WiFiRefPtr &wifi, DBus::Connection *bus, |
| 132 | const DBus::Path &dbus_path, const char *dbus_addr) |
| 133 | : DBus::ObjectProxy(*bus, dbus_path, dbus_addr), |
| 134 | wifi_(wifi) {} |
| 135 | |
| 136 | SupplicantInterfaceProxy::Proxy::~Proxy() {} |
| 137 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 138 | void SupplicantInterfaceProxy::Proxy::BlobAdded(const string &/*blobname*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 139 | SLOG(DBus, 2) << __func__; |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 140 | // XXX |
| 141 | } |
| 142 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 143 | void SupplicantInterfaceProxy::Proxy::BlobRemoved(const string &/*blobname*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 144 | SLOG(DBus, 2) << __func__; |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 145 | // XXX |
| 146 | } |
| 147 | |
| 148 | void SupplicantInterfaceProxy::Proxy::BSSAdded( |
| 149 | const ::DBus::Path &BSS, |
| 150 | const std::map<string, ::DBus::Variant> &properties) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 151 | SLOG(DBus, 2) << __func__; |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 152 | wifi_->BSSAdded(BSS, properties); |
| 153 | } |
| 154 | |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 155 | void SupplicantInterfaceProxy::Proxy::BSSRemoved(const ::DBus::Path &BSS) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 156 | SLOG(DBus, 2) << __func__; |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 157 | wifi_->BSSRemoved(BSS); |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | void SupplicantInterfaceProxy::Proxy::NetworkAdded( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 161 | const ::DBus::Path &/*network*/, |
| 162 | const std::map<string, ::DBus::Variant> &/*properties*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 163 | SLOG(DBus, 2) << __func__; |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 164 | // XXX |
| 165 | } |
| 166 | |
| 167 | void SupplicantInterfaceProxy::Proxy::NetworkRemoved( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 168 | const ::DBus::Path &/*network*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 169 | SLOG(DBus, 2) << __func__; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 170 | // TODO(quiche): Pass this up to WiFi, so that it can clean its |
| 171 | // rpcid_by_service_ map. crosbug.com/24699 |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | void SupplicantInterfaceProxy::Proxy::NetworkSelected( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 175 | const ::DBus::Path &/*network*/) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 176 | SLOG(DBus, 2) << __func__; |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 177 | // XXX |
| 178 | } |
| 179 | |
| 180 | void SupplicantInterfaceProxy::Proxy::PropertiesChanged( |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 181 | const std::map<string, ::DBus::Variant> &properties) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 182 | SLOG(DBus, 2) << __func__; |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 183 | wifi_->PropertiesChanged(properties); |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | void SupplicantInterfaceProxy::Proxy::ScanDone(const bool& success) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 187 | SLOG(DBus, 2) << __func__ << ": " << success; |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 188 | if (success) { |
| 189 | wifi_->ScanDone(); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | } // namespace shill |