mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -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/manager_dbus_adaptor.h" |
| 6 | |
| 7 | #include <map> |
| 8 | #include <string> |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 9 | #include <vector> |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 10 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 11 | #include <dbus-c++/dbus.h> |
| 12 | |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 13 | #include "shill/callbacks.h" |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 14 | #include "shill/device.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 15 | #include "shill/error.h" |
Gaurav Shah | b790aa2 | 2012-10-23 12:51:12 -0700 | [diff] [blame] | 16 | #include "shill/geolocation_info.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 17 | #include "shill/key_value_store.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 18 | #include "shill/logging.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 19 | #include "shill/manager.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 20 | #include "shill/wifi_service.h" |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 21 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 22 | using std::map; |
| 23 | using std::string; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 24 | using std::vector; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 25 | |
| 26 | namespace shill { |
| 27 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 28 | // static |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 29 | const char ManagerDBusAdaptor::kPath[] = "/"; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 30 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 31 | ManagerDBusAdaptor::ManagerDBusAdaptor(DBus::Connection *conn, Manager *manager) |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 32 | : DBusAdaptor(conn, kPath), |
| 33 | manager_(manager) { |
| 34 | } |
Chris Masone | ec6b18b | 2011-06-08 14:09:10 -0700 | [diff] [blame] | 35 | |
| 36 | ManagerDBusAdaptor::~ManagerDBusAdaptor() { |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame^] | 37 | manager_ = nullptr; |
Chris Masone | ec6b18b | 2011-06-08 14:09:10 -0700 | [diff] [blame] | 38 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 39 | |
| 40 | void ManagerDBusAdaptor::UpdateRunning() {} |
| 41 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 42 | void ManagerDBusAdaptor::EmitBoolChanged(const string &name, bool value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 43 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 44 | PropertyChanged(name, DBusAdaptor::BoolToVariant(value)); |
| 45 | } |
| 46 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 47 | void ManagerDBusAdaptor::EmitUintChanged(const string &name, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 48 | uint32_t value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 49 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 50 | PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 53 | void ManagerDBusAdaptor::EmitIntChanged(const string &name, int value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 54 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 55 | PropertyChanged(name, DBusAdaptor::Int32ToVariant(value)); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 58 | void ManagerDBusAdaptor::EmitStringChanged(const string &name, |
| 59 | const string &value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 60 | SLOG(DBus, 2) << __func__ << ": " << name; |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 61 | PropertyChanged(name, DBusAdaptor::StringToVariant(value)); |
| 62 | } |
| 63 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 64 | void ManagerDBusAdaptor::EmitStringsChanged(const string &name, |
| 65 | const vector<string> &value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 66 | SLOG(DBus, 2) << __func__ << ": " << name; |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 67 | PropertyChanged(name, DBusAdaptor::StringsToVariant(value)); |
| 68 | } |
| 69 | |
Paul Stewart | 49739c0 | 2012-08-08 17:24:03 -0700 | [diff] [blame] | 70 | void ManagerDBusAdaptor::EmitRpcIdentifierChanged( |
| 71 | const string &name, |
| 72 | const string &value) { |
| 73 | SLOG(DBus, 2) << __func__ << ": " << name; |
| 74 | PropertyChanged(name, DBusAdaptor::PathToVariant(value)); |
| 75 | } |
| 76 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 77 | void ManagerDBusAdaptor::EmitRpcIdentifierArrayChanged( |
| 78 | const string &name, |
| 79 | const vector<string> &value) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 80 | SLOG(DBus, 2) << __func__ << ": " << name; |
Ben Chan | e2ee5e0 | 2014-09-19 19:29:42 -0700 | [diff] [blame] | 81 | vector<DBus::Path> paths; |
Paul Stewart | 6db7b24 | 2014-05-02 15:34:21 -0700 | [diff] [blame] | 82 | for (const auto &element : value) { |
| 83 | paths.push_back(element); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 84 | } |
| 85 | |
mukesh agrawal | 2366eed | 2012-03-20 18:21:50 -0700 | [diff] [blame] | 86 | PropertyChanged(name, DBusAdaptor::PathsToVariant(paths)); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 89 | void ManagerDBusAdaptor::EmitStateChanged(const string &new_state) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 90 | SLOG(DBus, 2) << __func__; |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 91 | StateChanged(new_state); |
| 92 | } |
| 93 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 94 | map<string, DBus::Variant> ManagerDBusAdaptor::GetProperties( |
| 95 | DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 96 | SLOG(DBus, 2) << __func__; |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 97 | map<string, DBus::Variant> properties; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 98 | DBusAdaptor::GetProperties(manager_->store(), &properties, &error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 99 | return properties; |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 102 | void ManagerDBusAdaptor::SetProperty(const string &name, |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 103 | const DBus::Variant &value, |
| 104 | DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 105 | SLOG(DBus, 2) << __func__ << ": " << name; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 106 | if (DBusAdaptor::SetProperty(manager_->mutable_store(), |
| 107 | name, |
| 108 | value, |
| 109 | &error)) { |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 110 | PropertyChanged(name, value); |
| 111 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 114 | string ManagerDBusAdaptor::GetState(DBus::Error &/*error*/) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 115 | SLOG(DBus, 2) << __func__; |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame^] | 116 | return manager_->CalculateState(nullptr); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 119 | DBus::Path ManagerDBusAdaptor::CreateProfile(const string &name, |
| 120 | DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 121 | SLOG(DBus, 2) << __func__ << ": " << name; |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 122 | Error e; |
| 123 | string path; |
| 124 | manager_->CreateProfile(name, &path, &e); |
Paul Stewart | f3eced9 | 2013-04-17 12:18:22 -0700 | [diff] [blame] | 125 | if (e.ToDBusError(&error)) { |
| 126 | return "/"; |
| 127 | } |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 128 | return DBus::Path(path); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Paul Stewart | e73d05c | 2012-03-29 16:26:05 -0700 | [diff] [blame] | 131 | void ManagerDBusAdaptor::RemoveProfile(const string &name, |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 132 | DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 133 | SLOG(DBus, 2) << __func__ << ": " << name; |
Paul Stewart | e73d05c | 2012-03-29 16:26:05 -0700 | [diff] [blame] | 134 | Error e; |
| 135 | manager_->RemoveProfile(name, &e); |
| 136 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 139 | DBus::Path ManagerDBusAdaptor::PushProfile(const string &name, |
| 140 | DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 141 | SLOG(DBus, 2) << __func__ << ": " << name; |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 142 | Error e; |
| 143 | string path; |
| 144 | manager_->PushProfile(name, &path, &e); |
Paul Stewart | f3eced9 | 2013-04-17 12:18:22 -0700 | [diff] [blame] | 145 | if (e.ToDBusError(&error)) { |
| 146 | return "/"; |
| 147 | } |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 148 | return DBus::Path(path); |
Paul Stewart | f3eced9 | 2013-04-17 12:18:22 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 151 | DBus::Path ManagerDBusAdaptor::InsertUserProfile( |
| 152 | const string &name, |
| 153 | const string &user_hash, |
| 154 | DBus::Error &error) { // NOLINT |
Paul Stewart | f3eced9 | 2013-04-17 12:18:22 -0700 | [diff] [blame] | 155 | SLOG(DBus, 2) << __func__ << ": " << name; |
| 156 | Error e; |
| 157 | string path; |
| 158 | manager_->InsertUserProfile(name, user_hash, &path, &e); |
| 159 | if (e.ToDBusError(&error)) { |
| 160 | return "/"; |
| 161 | } |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 162 | return DBus::Path(path); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Paul Stewart | d2e1c36 | 2013-03-03 19:06:07 -0800 | [diff] [blame] | 165 | void ManagerDBusAdaptor::PopProfile(const string &name, |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 166 | DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 167 | SLOG(DBus, 2) << __func__ << ": " << name; |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 168 | Error e; |
| 169 | manager_->PopProfile(name, &e); |
| 170 | e.ToDBusError(&error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 173 | void ManagerDBusAdaptor::PopAnyProfile(DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 174 | SLOG(DBus, 2) << __func__; |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 175 | Error e; |
| 176 | manager_->PopAnyProfile(&e); |
| 177 | e.ToDBusError(&error); |
Chris Masone | ccc8881 | 2011-06-08 18:00:10 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 180 | void ManagerDBusAdaptor::PopAllUserProfiles(DBus::Error &error) { // NOLINT |
Paul Stewart | 307c250 | 2013-03-23 12:32:10 -0700 | [diff] [blame] | 181 | SLOG(DBus, 2) << __func__; |
| 182 | Error e; |
| 183 | manager_->PopAllUserProfiles(&e); |
| 184 | e.ToDBusError(&error); |
| 185 | } |
| 186 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 187 | void ManagerDBusAdaptor::RecheckPortal(DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 188 | SLOG(DBus, 2) << __func__; |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 189 | Error e; |
| 190 | manager_->RecheckPortal(&e); |
| 191 | e.ToDBusError(&error); |
| 192 | } |
| 193 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 194 | void ManagerDBusAdaptor::RequestScan(const string &technology, |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 195 | DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 196 | SLOG(DBus, 2) << __func__ << ": " << technology; |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 197 | Error e; |
Wade Guthrie | 68d4109 | 2013-04-02 12:56:02 -0700 | [diff] [blame] | 198 | manager_->RequestScan(Device::kFullScan, technology, &e); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 199 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 202 | void ManagerDBusAdaptor::EnableTechnology(const string &technology_name, |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 203 | DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 204 | SLOG(DBus, 2) << __func__ << ": " << technology_name; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 205 | Error e(Error::kOperationInitiated); |
| 206 | DBus::Tag *tag = new DBus::Tag(); |
mukesh agrawal | 46c27cc | 2013-07-10 16:39:10 -0700 | [diff] [blame] | 207 | manager_->SetEnabledStateForTechnology(technology_name, true, &e, |
| 208 | GetMethodReplyCallback(tag)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 209 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 212 | void ManagerDBusAdaptor::DisableTechnology(const string &technology_name, |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 213 | DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 214 | SLOG(DBus, 2) << __func__ << ": " << technology_name; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 215 | Error e(Error::kOperationInitiated); |
| 216 | DBus::Tag *tag = new DBus::Tag(); |
mukesh agrawal | 46c27cc | 2013-07-10 16:39:10 -0700 | [diff] [blame] | 217 | manager_->SetEnabledStateForTechnology(technology_name, false, &e, |
| 218 | GetMethodReplyCallback(tag)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 219 | ReturnResultOrDefer(tag, e, &error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 222 | // Called, e.g., to get WiFiService handle for a hidden SSID. |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 223 | DBus::Path ManagerDBusAdaptor::GetService( |
| 224 | const map<string, DBus::Variant> &args, |
| 225 | DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 226 | SLOG(DBus, 2) << __func__; |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 227 | ServiceRefPtr service; |
| 228 | KeyValueStore args_store; |
| 229 | Error e; |
| 230 | DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &e); |
| 231 | if (e.IsSuccess()) { |
| 232 | service = manager_->GetService(args_store, &e); |
| 233 | } |
| 234 | if (e.ToDBusError(&error)) { |
| 235 | return "/"; // ensure return is syntactically valid |
| 236 | } |
| 237 | return service->GetRpcIdentifier(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 240 | // Obsolete, use GetService instead. |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 241 | DBus::Path ManagerDBusAdaptor::GetVPNService( |
| 242 | const map<string, DBus::Variant> &args, |
| 243 | DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 244 | SLOG(DBus, 2) << __func__; |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 245 | return GetService(args, error); |
| 246 | } |
| 247 | |
| 248 | // Obsolete, use GetService instead. |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 249 | DBus::Path ManagerDBusAdaptor::GetWifiService( |
| 250 | const map<string, DBus::Variant> &args, |
| 251 | DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 252 | SLOG(DBus, 2) << __func__; |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 253 | return GetService(args, error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 256 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 257 | DBus::Path ManagerDBusAdaptor::ConfigureService( |
| 258 | const map<string, DBus::Variant> &args, |
| 259 | DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 260 | SLOG(DBus, 2) << __func__; |
Paul Stewart | d39d692 | 2012-12-21 08:59:57 -0800 | [diff] [blame] | 261 | ServiceRefPtr service; |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 262 | KeyValueStore args_store; |
Paul Stewart | d39d692 | 2012-12-21 08:59:57 -0800 | [diff] [blame] | 263 | Error key_value_store_error; |
| 264 | DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &key_value_store_error); |
| 265 | if (key_value_store_error.ToDBusError(&error)) { |
| 266 | return "/"; // ensure return is syntactically valid. |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 267 | } |
Paul Stewart | d39d692 | 2012-12-21 08:59:57 -0800 | [diff] [blame] | 268 | Error configure_error; |
| 269 | service = manager_->ConfigureService(args_store, &configure_error); |
| 270 | if (configure_error.ToDBusError(&error)) { |
| 271 | return "/"; // ensure return is syntactically valid. |
| 272 | } |
| 273 | return service->GetRpcIdentifier(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 276 | DBus::Path ManagerDBusAdaptor::ConfigureServiceForProfile( |
| 277 | const DBus::Path &profile_rpcid, |
| 278 | const map<string, DBus::Variant> &args, |
| 279 | DBus::Error &error) { // NOLINT |
Paul Stewart | d2e1c36 | 2013-03-03 19:06:07 -0800 | [diff] [blame] | 280 | SLOG(DBus, 2) << __func__; |
| 281 | ServiceRefPtr service; |
| 282 | KeyValueStore args_store; |
| 283 | Error key_value_store_error; |
| 284 | DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &key_value_store_error); |
| 285 | if (key_value_store_error.ToDBusError(&error)) { |
| 286 | return "/"; // ensure return is syntactically valid. |
| 287 | } |
| 288 | Error configure_error; |
| 289 | service = manager_->ConfigureServiceForProfile( |
| 290 | profile_rpcid, args_store, &configure_error); |
| 291 | if (!service || configure_error.ToDBusError(&error)) { |
| 292 | return "/"; // ensure return is syntactically valid. |
| 293 | } |
| 294 | return service->GetRpcIdentifier(); |
| 295 | } |
| 296 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 297 | DBus::Path ManagerDBusAdaptor::FindMatchingService( |
| 298 | const map<string, DBus::Variant> &args, |
| 299 | DBus::Error &error) { // NOLINT |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 300 | SLOG(DBus, 2) << __func__; |
| 301 | KeyValueStore args_store; |
| 302 | Error value_error; |
| 303 | DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &value_error); |
| 304 | if (value_error.ToDBusError(&error)) { |
| 305 | return "/"; // ensure return is syntactically valid |
| 306 | } |
| 307 | |
| 308 | Error find_error; |
| 309 | ServiceRefPtr service = |
| 310 | manager_->FindMatchingService(args_store, &find_error); |
| 311 | if (find_error.ToDBusError(&error)) { |
| 312 | return "/"; // ensure return is syntactically valid |
| 313 | } |
| 314 | |
| 315 | return service->GetRpcIdentifier(); |
| 316 | } |
| 317 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 318 | void ManagerDBusAdaptor::AddWakeOnPacketConnection( |
| 319 | const string &ip_endpoint, |
| 320 | DBus::Error &error) { // NOLINT |
Samuel Tan | fe73467 | 2014-08-07 15:50:48 -0700 | [diff] [blame] | 321 | SLOG(DBus, 2) << __func__; |
| 322 | Error e; |
Samuel Tan | c863d06 | 2014-08-14 17:52:16 -0700 | [diff] [blame] | 323 | manager_->AddWakeOnPacketConnection(ip_endpoint, &e); |
Samuel Tan | fe73467 | 2014-08-07 15:50:48 -0700 | [diff] [blame] | 324 | e.ToDBusError(&error); |
| 325 | } |
| 326 | |
| 327 | void ManagerDBusAdaptor::RemoveWakeOnPacketConnection( |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 328 | const string &ip_endpoint, DBus::Error &error) { // NOLINT |
Samuel Tan | fe73467 | 2014-08-07 15:50:48 -0700 | [diff] [blame] | 329 | SLOG(DBus, 2) << __func__; |
| 330 | Error e; |
Samuel Tan | c863d06 | 2014-08-14 17:52:16 -0700 | [diff] [blame] | 331 | manager_->RemoveWakeOnPacketConnection(ip_endpoint, &e); |
Samuel Tan | fe73467 | 2014-08-07 15:50:48 -0700 | [diff] [blame] | 332 | e.ToDBusError(&error); |
| 333 | } |
| 334 | |
| 335 | void ManagerDBusAdaptor::RemoveAllWakeOnPacketConnections( |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 336 | DBus::Error &error) { // NOLINT |
Samuel Tan | fe73467 | 2014-08-07 15:50:48 -0700 | [diff] [blame] | 337 | SLOG(DBus, 2) << __func__; |
| 338 | Error e; |
| 339 | manager_->RemoveAllWakeOnPacketConnections(&e); |
| 340 | e.ToDBusError(&error); |
| 341 | } |
| 342 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 343 | int32_t ManagerDBusAdaptor::GetDebugLevel(DBus::Error &/*error*/) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 344 | SLOG(DBus, 2) << __func__; |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 345 | return logging::GetMinLogLevel(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 348 | void ManagerDBusAdaptor::SetDebugLevel(const int32_t &level, |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 349 | DBus::Error &/*error*/) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 350 | SLOG(DBus, 2) << __func__ << ": " << level; |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 351 | if (level < logging::LOG_NUM_SEVERITIES) { |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 352 | logging::SetMinLogLevel(level); |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 353 | // Like VLOG, SLOG uses negative verbose level. |
| 354 | ScopeLogger::GetInstance()->set_verbose_level(-level); |
| 355 | } else { |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 356 | LOG(WARNING) << "Ignoring attempt to set log level to " << level; |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 357 | } |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 360 | string ManagerDBusAdaptor::GetServiceOrder(DBus::Error &/*error*/) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 361 | SLOG(DBus, 2) << __func__; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 362 | return manager_->GetTechnologyOrder(); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 365 | void ManagerDBusAdaptor::SetServiceOrder(const string &order, |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 366 | DBus::Error &error) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 367 | SLOG(DBus, 2) << __func__ << ": " << order; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 368 | Error e; |
| 369 | manager_->SetTechnologyOrder(order, &e); |
| 370 | e.ToDBusError(&error); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 373 | string ManagerDBusAdaptor::GetDebugTags(DBus::Error &/*error*/) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 374 | SLOG(DBus, 2) << __func__; |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 375 | return ScopeLogger::GetInstance()->GetEnabledScopeNames(); |
Elly Jones | 16227d3 | 2012-02-09 14:17:25 -0500 | [diff] [blame] | 376 | } |
| 377 | |
Paul Stewart | d2e1c36 | 2013-03-03 19:06:07 -0800 | [diff] [blame] | 378 | void ManagerDBusAdaptor::SetDebugTags(const string &tags, |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 379 | DBus::Error &/*error*/) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 380 | SLOG(DBus, 2) << __func__ << ": " << tags; |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 381 | ScopeLogger::GetInstance()->EnableScopesByName(tags); |
Elly Jones | 16227d3 | 2012-02-09 14:17:25 -0500 | [diff] [blame] | 382 | } |
| 383 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 384 | string ManagerDBusAdaptor::ListDebugTags(DBus::Error &/*error*/) { // NOLINT |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 385 | SLOG(DBus, 2) << __func__; |
Ben Chan | bc49ac7 | 2012-04-10 19:59:45 -0700 | [diff] [blame] | 386 | return ScopeLogger::GetInstance()->GetAllScopeNames(); |
Elly Jones | 16227d3 | 2012-02-09 14:17:25 -0500 | [diff] [blame] | 387 | } |
| 388 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 389 | map<string, DBus::Variant> ManagerDBusAdaptor::GetNetworksForGeolocation( |
| 390 | DBus::Error &/*error*/) { // NOLINT |
Gaurav Shah | 645bff8 | 2012-10-08 14:06:04 -0700 | [diff] [blame] | 391 | SLOG(DBus, 2) << __func__; |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 392 | map<string, DBus::Variant> networks; |
Paul Stewart | 6db7b24 | 2014-05-02 15:34:21 -0700 | [diff] [blame] | 393 | for (const auto &network : manager_->GetNetworksForGeolocation()) { |
Gaurav Shah | b790aa2 | 2012-10-23 12:51:12 -0700 | [diff] [blame] | 394 | Stringmaps value; |
| 395 | // Convert GeolocationInfos to their Stringmaps equivalent. |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 396 | for (const auto &info : network.second) { |
Paul Stewart | 6db7b24 | 2014-05-02 15:34:21 -0700 | [diff] [blame] | 397 | value.push_back(info.properties()); |
Gaurav Shah | b790aa2 | 2012-10-23 12:51:12 -0700 | [diff] [blame] | 398 | } |
Paul Stewart | 6db7b24 | 2014-05-02 15:34:21 -0700 | [diff] [blame] | 399 | networks[network.first] = StringmapsToVariant(value); |
Gaurav Shah | b790aa2 | 2012-10-23 12:51:12 -0700 | [diff] [blame] | 400 | } |
Gaurav Shah | 645bff8 | 2012-10-08 14:06:04 -0700 | [diff] [blame] | 401 | return networks; |
| 402 | } |
| 403 | |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 404 | bool ManagerDBusAdaptor::VerifyDestination(const string &certificate, |
| 405 | const string &public_key, |
| 406 | const string &nonce, |
| 407 | const string &signed_data, |
| 408 | const string &destination_udn, |
Christopher Wiley | cdde79f | 2013-05-01 14:26:56 -0700 | [diff] [blame] | 409 | const string &hotspot_ssid, |
| 410 | const string &hotspot_bssid, |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 411 | DBus::Error &error) { // NOLINT |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 412 | SLOG(DBus, 2) << __func__; |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 413 | Error e(Error::kOperationInitiated); |
| 414 | DBus::Tag *tag = new DBus::Tag(); |
| 415 | manager_->VerifyDestination(certificate, public_key, nonce, |
| 416 | signed_data, destination_udn, |
Christopher Wiley | cdde79f | 2013-05-01 14:26:56 -0700 | [diff] [blame] | 417 | hotspot_ssid, hotspot_bssid, |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 418 | GetBoolMethodReplyCallback(tag), &e); |
| 419 | ReturnResultOrDefer(tag, e, &error); |
| 420 | CHECK(e.IsFailure()) << __func__ << " should only return directly on error."; |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 421 | return false; |
| 422 | } |
| 423 | |
| 424 | string ManagerDBusAdaptor::VerifyAndEncryptCredentials( |
| 425 | const string &certificate, |
| 426 | const string &public_key, |
| 427 | const string &nonce, |
| 428 | const string &signed_data, |
| 429 | const string &destination_udn, |
Christopher Wiley | cdde79f | 2013-05-01 14:26:56 -0700 | [diff] [blame] | 430 | const string &hotspot_ssid, |
| 431 | const string &hotspot_bssid, |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 432 | const DBus::Path &network, |
| 433 | DBus::Error &error) { // NOLINT |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 434 | SLOG(DBus, 2) << __func__; |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 435 | Error e(Error::kOperationInitiated); |
| 436 | DBus::Tag *tag = new DBus::Tag(); |
| 437 | manager_->VerifyAndEncryptCredentials(certificate, public_key, nonce, |
| 438 | signed_data, destination_udn, |
Christopher Wiley | cdde79f | 2013-05-01 14:26:56 -0700 | [diff] [blame] | 439 | hotspot_ssid, hotspot_bssid, |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 440 | network, |
| 441 | GetStringMethodReplyCallback(tag), |
| 442 | &e); |
| 443 | ReturnResultOrDefer(tag, e, &error); |
| 444 | CHECK(e.IsFailure()) << __func__ << " should only return directly on error."; |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 445 | return ""; |
| 446 | } |
| 447 | |
| 448 | string ManagerDBusAdaptor::VerifyAndEncryptData( |
| 449 | const string &certificate, |
| 450 | const string &public_key, |
| 451 | const string &nonce, |
| 452 | const string &signed_data, |
| 453 | const string &destination_udn, |
Christopher Wiley | cdde79f | 2013-05-01 14:26:56 -0700 | [diff] [blame] | 454 | const string &hotspot_ssid, |
| 455 | const string &hotspot_bssid, |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 456 | const string &data, |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 457 | DBus::Error &error) { // NOLINT |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 458 | SLOG(DBus, 2) << __func__; |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 459 | Error e(Error::kOperationInitiated); |
| 460 | DBus::Tag *tag = new DBus::Tag(); |
| 461 | manager_->VerifyAndEncryptData(certificate, public_key, nonce, |
| 462 | signed_data, destination_udn, |
Christopher Wiley | cdde79f | 2013-05-01 14:26:56 -0700 | [diff] [blame] | 463 | hotspot_ssid, hotspot_bssid, |
Christopher Wiley | 0d9cf0c | 2013-02-19 19:24:57 -0800 | [diff] [blame] | 464 | data, GetStringMethodReplyCallback(tag), |
| 465 | &e); |
| 466 | ReturnResultOrDefer(tag, e, &error); |
| 467 | CHECK(e.IsFailure()) << __func__ << " should only return directly on error."; |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 468 | return ""; |
| 469 | } |
| 470 | |
Ben Chan | 3f4d4ee | 2014-09-09 07:41:33 -0700 | [diff] [blame] | 471 | void ManagerDBusAdaptor::ConnectToBestServices(DBus::Error &error) { // NOLINT |
Darin Petkov | cbe9c39 | 2013-04-11 11:52:35 +0200 | [diff] [blame] | 472 | SLOG(DBus, 2) << __func__; |
Paul Stewart | 39db5ca | 2013-03-18 14:15:17 -0700 | [diff] [blame] | 473 | Error e; |
| 474 | manager_->ConnectToBestServices(&e); |
| 475 | e.ToDBusError(&error); |
| 476 | } |
Christopher Wiley | 3d5ab40 | 2013-02-15 13:25:58 -0800 | [diff] [blame] | 477 | |
Rebecca Silberstein | 6862b38 | 2014-09-11 08:24:51 -0700 | [diff] [blame] | 478 | void ManagerDBusAdaptor::CreateConnectivityReport(DBus::Error &error) { // NOLINT |
| 479 | SLOG(DBus, 2) << __func__; |
| 480 | Error e; |
| 481 | manager_->CreateConnectivityReport(&e); |
| 482 | e.ToDBusError(&error); |
| 483 | } |
| 484 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 485 | } // namespace shill |