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