blob: 2d1fd5753a5870ae11d2b59b49bc019fb885355f [file] [log] [blame]
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Masoned7732e42011-05-20 11:08:56 -07002// 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 Masone8fe2c7e2011-06-09 15:51:19 -07009#include <vector>
Chris Masoned7732e42011-05-20 11:08:56 -070010
Christopher Wiley0d9cf0c2013-02-19 19:24:57 -080011#include <base/bind.h>
Chris Masone8fe2c7e2011-06-09 15:51:19 -070012#include <dbus-c++/dbus.h>
13
Christopher Wiley0d9cf0c2013-02-19 19:24:57 -080014#include "shill/callbacks.h"
mukesh agrawal32399322011-09-01 10:53:43 -070015#include "shill/device.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070016#include "shill/error.h"
Gaurav Shahb790aa22012-10-23 12:51:12 -070017#include "shill/geolocation_info.h"
mukesh agrawal7a4e4002011-09-06 11:26:05 -070018#include "shill/key_value_store.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070019#include "shill/logging.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070020#include "shill/manager.h"
mukesh agrawal7a4e4002011-09-06 11:26:05 -070021#include "shill/wifi_service.h"
Chris Masone7ccc8192011-05-24 14:54:49 -070022
Christopher Wiley0d9cf0c2013-02-19 19:24:57 -080023using base::Bind;
Chris Masoned7732e42011-05-20 11:08:56 -070024using std::map;
25using std::string;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070026using std::vector;
Chris Masoned7732e42011-05-20 11:08:56 -070027
28namespace shill {
29
Chris Masoned7732e42011-05-20 11:08:56 -070030// static
Chris Masone19e30402011-07-19 15:48:47 -070031const char ManagerDBusAdaptor::kPath[] = "/";
Chris Masoned7732e42011-05-20 11:08:56 -070032
Chris Masoned0ceb8c2011-06-02 10:05:39 -070033ManagerDBusAdaptor::ManagerDBusAdaptor(DBus::Connection* conn, Manager *manager)
Chris Masoned7732e42011-05-20 11:08:56 -070034 : DBusAdaptor(conn, kPath),
35 manager_(manager) {
36}
Chris Masoneec6b18b2011-06-08 14:09:10 -070037
38ManagerDBusAdaptor::~ManagerDBusAdaptor() {
39 manager_ = NULL;
40}
Chris Masoned7732e42011-05-20 11:08:56 -070041
42void ManagerDBusAdaptor::UpdateRunning() {}
43
Chris Masone8fe2c7e2011-06-09 15:51:19 -070044void ManagerDBusAdaptor::EmitBoolChanged(const string &name, bool value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070045 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070046 PropertyChanged(name, DBusAdaptor::BoolToVariant(value));
47}
48
Chris Masone8fe2c7e2011-06-09 15:51:19 -070049void ManagerDBusAdaptor::EmitUintChanged(const string &name,
Chris Masoned0ceb8c2011-06-02 10:05:39 -070050 uint32 value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070051 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070052 PropertyChanged(name, DBusAdaptor::Uint32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070053}
54
Chris Masone8fe2c7e2011-06-09 15:51:19 -070055void ManagerDBusAdaptor::EmitIntChanged(const string &name, int value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070056 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070057 PropertyChanged(name, DBusAdaptor::Int32ToVariant(value));
Chris Masoned0ceb8c2011-06-02 10:05:39 -070058}
59
Chris Masone8fe2c7e2011-06-09 15:51:19 -070060void ManagerDBusAdaptor::EmitStringChanged(const string &name,
61 const string &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070062 SLOG(DBus, 2) << __func__ << ": " << name;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070063 PropertyChanged(name, DBusAdaptor::StringToVariant(value));
64}
65
Gaurav Shah435de2c2011-11-17 19:01:07 -080066void ManagerDBusAdaptor::EmitStringsChanged(const string &name,
67 const vector<string> &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070068 SLOG(DBus, 2) << __func__ << ": " << name;
Gaurav Shah435de2c2011-11-17 19:01:07 -080069 PropertyChanged(name, DBusAdaptor::StringsToVariant(value));
70}
71
Paul Stewart49739c02012-08-08 17:24:03 -070072void ManagerDBusAdaptor::EmitRpcIdentifierChanged(
73 const string &name,
74 const string &value) {
75 SLOG(DBus, 2) << __func__ << ": " << name;
76 PropertyChanged(name, DBusAdaptor::PathToVariant(value));
77}
78
mukesh agrawal32399322011-09-01 10:53:43 -070079void ManagerDBusAdaptor::EmitRpcIdentifierArrayChanged(
80 const string &name,
81 const vector<string> &value) {
mukesh agrawal06175d72012-04-23 16:46:01 -070082 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal32399322011-09-01 10:53:43 -070083 vector< ::DBus::Path> paths;
84 vector<string>::const_iterator it;
85 for (it = value.begin(); it != value.end(); ++it) {
86 paths.push_back(*it);
87 }
88
mukesh agrawal2366eed2012-03-20 18:21:50 -070089 PropertyChanged(name, DBusAdaptor::PathsToVariant(paths));
mukesh agrawal32399322011-09-01 10:53:43 -070090}
91
Chris Masone8fe2c7e2011-06-09 15:51:19 -070092void ManagerDBusAdaptor::EmitStateChanged(const string &new_state) {
mukesh agrawal06175d72012-04-23 16:46:01 -070093 SLOG(DBus, 2) << __func__;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070094 StateChanged(new_state);
95}
96
Chris Masoned7732e42011-05-20 11:08:56 -070097map<string, ::DBus::Variant> ManagerDBusAdaptor::GetProperties(
98 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -070099 SLOG(DBus, 2) << __func__;
Chris Masonea8a2c252011-06-27 22:16:30 -0700100 map<string, ::DBus::Variant> properties;
Chris Masone27c4aa52011-07-02 13:10:14 -0700101 DBusAdaptor::GetProperties(manager_->store(), &properties, &error);
Chris Masonea8a2c252011-06-27 22:16:30 -0700102 return properties;
Chris Masoned7732e42011-05-20 11:08:56 -0700103}
104
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700105void ManagerDBusAdaptor::SetProperty(const string &name,
106 const ::DBus::Variant &value,
Chris Masoned7732e42011-05-20 11:08:56 -0700107 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700108 SLOG(DBus, 2) << __func__ << ": " << name;
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -0800109 if (DBusAdaptor::SetProperty(manager_->mutable_store(),
110 name,
111 value,
112 &error)) {
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700113 PropertyChanged(name, value);
114 }
Chris Masoned7732e42011-05-20 11:08:56 -0700115}
116
mukesh agrawal1830fa12011-09-26 14:31:40 -0700117string ManagerDBusAdaptor::GetState(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700118 SLOG(DBus, 2) << __func__;
Paul Stewart38fd24c2012-04-25 14:06:29 -0700119 return manager_->CalculateState(NULL);
Chris Masoned7732e42011-05-20 11:08:56 -0700120}
121
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700122::DBus::Path ManagerDBusAdaptor::CreateProfile(const string &name,
Paul Stewart19c871d2011-12-15 16:10:13 -0800123 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700124 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewart19c871d2011-12-15 16:10:13 -0800125 Error e;
126 string path;
127 manager_->CreateProfile(name, &path, &e);
Paul Stewartf3eced92013-04-17 12:18:22 -0700128 if (e.ToDBusError(&error)) {
129 return "/";
130 }
Paul Stewart19c871d2011-12-15 16:10:13 -0800131 return ::DBus::Path(path);
Chris Masoned7732e42011-05-20 11:08:56 -0700132}
133
Paul Stewarte73d05c2012-03-29 16:26:05 -0700134void ManagerDBusAdaptor::RemoveProfile(const string &name,
135 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700136 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewarte73d05c2012-03-29 16:26:05 -0700137 Error e;
138 manager_->RemoveProfile(name, &e);
139 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700140}
141
Paul Stewartd2e1c362013-03-03 19:06:07 -0800142::DBus::Path ManagerDBusAdaptor::PushProfile(const string &name,
Paul Stewart19c871d2011-12-15 16:10:13 -0800143 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700144 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewart19c871d2011-12-15 16:10:13 -0800145 Error e;
146 string path;
147 manager_->PushProfile(name, &path, &e);
Paul Stewartf3eced92013-04-17 12:18:22 -0700148 if (e.ToDBusError(&error)) {
149 return "/";
150 }
151 return ::DBus::Path(path);
152}
153
154::DBus::Path ManagerDBusAdaptor::InsertUserProfile(const string &name,
155 const string &user_hash,
156 ::DBus::Error &error) {
157 SLOG(DBus, 2) << __func__ << ": " << name;
158 Error e;
159 string path;
160 manager_->InsertUserProfile(name, user_hash, &path, &e);
161 if (e.ToDBusError(&error)) {
162 return "/";
163 }
Paul Stewart19c871d2011-12-15 16:10:13 -0800164 return ::DBus::Path(path);
Chris Masoneccc88812011-06-08 18:00:10 -0700165}
166
Paul Stewartd2e1c362013-03-03 19:06:07 -0800167void ManagerDBusAdaptor::PopProfile(const string &name,
Paul Stewart19c871d2011-12-15 16:10:13 -0800168 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700169 SLOG(DBus, 2) << __func__ << ": " << name;
Paul Stewart19c871d2011-12-15 16:10:13 -0800170 Error e;
171 manager_->PopProfile(name, &e);
172 e.ToDBusError(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700173}
174
Paul Stewart19c871d2011-12-15 16:10:13 -0800175void ManagerDBusAdaptor::PopAnyProfile(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700176 SLOG(DBus, 2) << __func__;
Paul Stewart19c871d2011-12-15 16:10:13 -0800177 Error e;
178 manager_->PopAnyProfile(&e);
179 e.ToDBusError(&error);
Chris Masoneccc88812011-06-08 18:00:10 -0700180}
181
Paul Stewart307c2502013-03-23 12:32:10 -0700182void ManagerDBusAdaptor::PopAllUserProfiles(::DBus::Error &error) {
183 SLOG(DBus, 2) << __func__;
184 Error e;
185 manager_->PopAllUserProfiles(&e);
186 e.ToDBusError(&error);
187}
188
Paul Stewartc681fa02012-03-02 19:40:04 -0800189void ManagerDBusAdaptor::RecheckPortal(::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700190 SLOG(DBus, 2) << __func__;
Paul Stewartc681fa02012-03-02 19:40:04 -0800191 Error e;
192 manager_->RecheckPortal(&e);
193 e.ToDBusError(&error);
194}
195
mukesh agrawal32399322011-09-01 10:53:43 -0700196void ManagerDBusAdaptor::RequestScan(const string &technology,
Chris Masoned7732e42011-05-20 11:08:56 -0700197 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700198 SLOG(DBus, 2) << __func__ << ": " << technology;
mukesh agrawal32399322011-09-01 10:53:43 -0700199 Error e;
Wade Guthrie68d41092013-04-02 12:56:02 -0700200 manager_->RequestScan(Device::kFullScan, technology, &e);
mukesh agrawal32399322011-09-01 10:53:43 -0700201 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700202}
203
Eric Shienbrood9a245532012-03-07 14:20:39 -0500204void ManagerDBusAdaptor::EnableTechnology(const string &technology_name,
205 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700206 SLOG(DBus, 2) << __func__ << ": " << technology_name;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500207 Error e(Error::kOperationInitiated);
208 DBus::Tag *tag = new DBus::Tag();
209 manager_->EnableTechnology(technology_name, &e, GetMethodReplyCallback(tag));
210 ReturnResultOrDefer(tag, e, &error);
211 // TODO(ers): A reply will be sent to the client as soon as the first
212 // device of a given technology has finished being enabled. It would
213 // seem arguably more correct to wait until all the devices were enabled.
Chris Masoned7732e42011-05-20 11:08:56 -0700214}
215
Eric Shienbrood9a245532012-03-07 14:20:39 -0500216void ManagerDBusAdaptor::DisableTechnology(const string &technology_name,
217 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700218 SLOG(DBus, 2) << __func__ << ": " << technology_name;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500219 Error e(Error::kOperationInitiated);
220 DBus::Tag *tag = new DBus::Tag();
221 manager_->DisableTechnology(technology_name, &e, GetMethodReplyCallback(tag));
222 ReturnResultOrDefer(tag, e, &error);
223 // TODO(ers): A reply will be sent to the client as soon as the first
224 // device of a given technology has finished being disabled. It would
225 // seem arguably more correct to wait until all the devices were enabled.
Chris Masoned7732e42011-05-20 11:08:56 -0700226}
227
Darin Petkovb65c2452012-02-23 15:17:06 +0100228// Called, e.g., to get WiFiService handle for a hidden SSID.
Chris Masoned7732e42011-05-20 11:08:56 -0700229::DBus::Path ManagerDBusAdaptor::GetService(
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700230 const map<string, ::DBus::Variant> &args,
Chris Masoned7732e42011-05-20 11:08:56 -0700231 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700232 SLOG(DBus, 2) << __func__;
Darin Petkovb65c2452012-02-23 15:17:06 +0100233 ServiceRefPtr service;
234 KeyValueStore args_store;
235 Error e;
236 DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &e);
237 if (e.IsSuccess()) {
238 service = manager_->GetService(args_store, &e);
239 }
240 if (e.ToDBusError(&error)) {
241 return "/"; // ensure return is syntactically valid
242 }
243 return service->GetRpcIdentifier();
Chris Masoned7732e42011-05-20 11:08:56 -0700244}
245
Darin Petkovb65c2452012-02-23 15:17:06 +0100246// Obsolete, use GetService instead.
247::DBus::Path ManagerDBusAdaptor::GetVPNService(
248 const map<string, ::DBus::Variant> &args,
249 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700250 SLOG(DBus, 2) << __func__;
Darin Petkovb65c2452012-02-23 15:17:06 +0100251 return GetService(args, error);
252}
253
254// Obsolete, use GetService instead.
Chris Masoned7732e42011-05-20 11:08:56 -0700255::DBus::Path ManagerDBusAdaptor::GetWifiService(
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700256 const map<string, ::DBus::Variant> &args,
Chris Masoned7732e42011-05-20 11:08:56 -0700257 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700258 SLOG(DBus, 2) << __func__;
Darin Petkovb65c2452012-02-23 15:17:06 +0100259 return GetService(args, error);
Chris Masoned7732e42011-05-20 11:08:56 -0700260}
261
Paul Stewart7f61e522012-03-22 11:13:45 -0700262
Paul Stewartd39d6922012-12-21 08:59:57 -0800263::DBus::Path ManagerDBusAdaptor::ConfigureService(
Paul Stewart7f61e522012-03-22 11:13:45 -0700264 const map<string, ::DBus::Variant> &args,
265 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700266 SLOG(DBus, 2) << __func__;
Paul Stewartd39d6922012-12-21 08:59:57 -0800267 ServiceRefPtr service;
Paul Stewart7f61e522012-03-22 11:13:45 -0700268 KeyValueStore args_store;
Paul Stewartd39d6922012-12-21 08:59:57 -0800269 Error key_value_store_error;
270 DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &key_value_store_error);
271 if (key_value_store_error.ToDBusError(&error)) {
272 return "/"; // ensure return is syntactically valid.
Paul Stewart7f61e522012-03-22 11:13:45 -0700273 }
Paul Stewartd39d6922012-12-21 08:59:57 -0800274 Error configure_error;
275 service = manager_->ConfigureService(args_store, &configure_error);
276 if (configure_error.ToDBusError(&error)) {
277 return "/"; // ensure return is syntactically valid.
278 }
279 return service->GetRpcIdentifier();
Chris Masoned7732e42011-05-20 11:08:56 -0700280}
281
Paul Stewartd2e1c362013-03-03 19:06:07 -0800282::DBus::Path ManagerDBusAdaptor::ConfigureServiceForProfile(
283 const ::DBus::Path &profile_rpcid,
284 const map<string, ::DBus::Variant> &args,
285 ::DBus::Error &error) {
286 SLOG(DBus, 2) << __func__;
287 ServiceRefPtr service;
288 KeyValueStore args_store;
289 Error key_value_store_error;
290 DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &key_value_store_error);
291 if (key_value_store_error.ToDBusError(&error)) {
292 return "/"; // ensure return is syntactically valid.
293 }
294 Error configure_error;
295 service = manager_->ConfigureServiceForProfile(
296 profile_rpcid, args_store, &configure_error);
297 if (!service || configure_error.ToDBusError(&error)) {
298 return "/"; // ensure return is syntactically valid.
299 }
300 return service->GetRpcIdentifier();
301}
302
Paul Stewart7a20aa42013-01-17 12:21:41 -0800303::DBus::Path ManagerDBusAdaptor::FindMatchingService(
304 const map<string, ::DBus::Variant> &args,
305 ::DBus::Error &error) {
306 SLOG(DBus, 2) << __func__;
307 KeyValueStore args_store;
308 Error value_error;
309 DBusAdaptor::ArgsToKeyValueStore(args, &args_store, &value_error);
310 if (value_error.ToDBusError(&error)) {
311 return "/"; // ensure return is syntactically valid
312 }
313
314 Error find_error;
315 ServiceRefPtr service =
316 manager_->FindMatchingService(args_store, &find_error);
317 if (find_error.ToDBusError(&error)) {
318 return "/"; // ensure return is syntactically valid
319 }
320
321 return service->GetRpcIdentifier();
322}
323
mukesh agrawal1830fa12011-09-26 14:31:40 -0700324int32_t ManagerDBusAdaptor::GetDebugLevel(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700325 SLOG(DBus, 2) << __func__;
Chris Masone7ccc8192011-05-24 14:54:49 -0700326 return logging::GetMinLogLevel();
Chris Masoned7732e42011-05-20 11:08:56 -0700327}
328
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700329void ManagerDBusAdaptor::SetDebugLevel(const int32_t &level,
mukesh agrawal1830fa12011-09-26 14:31:40 -0700330 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700331 SLOG(DBus, 2) << __func__ << ": " << level;
Ben Chanbc49ac72012-04-10 19:59:45 -0700332 if (level < logging::LOG_NUM_SEVERITIES) {
Chris Masone7ccc8192011-05-24 14:54:49 -0700333 logging::SetMinLogLevel(level);
Ben Chanbc49ac72012-04-10 19:59:45 -0700334 // Like VLOG, SLOG uses negative verbose level.
335 ScopeLogger::GetInstance()->set_verbose_level(-level);
336 } else {
Chris Masone7ccc8192011-05-24 14:54:49 -0700337 LOG(WARNING) << "Ignoring attempt to set log level to " << level;
Ben Chanbc49ac72012-04-10 19:59:45 -0700338 }
Chris Masoned7732e42011-05-20 11:08:56 -0700339}
340
mukesh agrawal1830fa12011-09-26 14:31:40 -0700341string ManagerDBusAdaptor::GetServiceOrder(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700342 SLOG(DBus, 2) << __func__;
Paul Stewart22aa71b2011-09-16 12:15:11 -0700343 return manager_->GetTechnologyOrder();
Chris Masoned7732e42011-05-20 11:08:56 -0700344}
345
Paul Stewart22aa71b2011-09-16 12:15:11 -0700346void ManagerDBusAdaptor::SetServiceOrder(const string &order,
Chris Masoned7732e42011-05-20 11:08:56 -0700347 ::DBus::Error &error) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700348 SLOG(DBus, 2) << __func__ << ": " << order;
Paul Stewart22aa71b2011-09-16 12:15:11 -0700349 Error e;
350 manager_->SetTechnologyOrder(order, &e);
351 e.ToDBusError(&error);
Chris Masoned7732e42011-05-20 11:08:56 -0700352}
353
Paul Stewartd2e1c362013-03-03 19:06:07 -0800354string ManagerDBusAdaptor::GetDebugTags(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700355 SLOG(DBus, 2) << __func__;
Ben Chanbc49ac72012-04-10 19:59:45 -0700356 return ScopeLogger::GetInstance()->GetEnabledScopeNames();
Elly Jones16227d32012-02-09 14:17:25 -0500357}
358
Paul Stewartd2e1c362013-03-03 19:06:07 -0800359void ManagerDBusAdaptor::SetDebugTags(const string &tags,
Elly Jones16227d32012-02-09 14:17:25 -0500360 ::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700361 SLOG(DBus, 2) << __func__ << ": " << tags;
Ben Chanbc49ac72012-04-10 19:59:45 -0700362 ScopeLogger::GetInstance()->EnableScopesByName(tags);
Elly Jones16227d32012-02-09 14:17:25 -0500363}
364
Paul Stewartd2e1c362013-03-03 19:06:07 -0800365string ManagerDBusAdaptor::ListDebugTags(::DBus::Error &/*error*/) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700366 SLOG(DBus, 2) << __func__;
Ben Chanbc49ac72012-04-10 19:59:45 -0700367 return ScopeLogger::GetInstance()->GetAllScopeNames();
Elly Jones16227d32012-02-09 14:17:25 -0500368}
369
Gaurav Shah645bff82012-10-08 14:06:04 -0700370map<string, ::DBus::Variant> ManagerDBusAdaptor::GetNetworksForGeolocation(
371 ::DBus::Error &/*error*/) {
372 SLOG(DBus, 2) << __func__;
373 map<string, ::DBus::Variant> networks;
Gaurav Shahb790aa22012-10-23 12:51:12 -0700374 map<string, GeolocationInfos> geoinfo_map =
375 manager_->GetNetworksForGeolocation();
376 for (map<string, GeolocationInfos>::iterator it = geoinfo_map.begin();
377 it != geoinfo_map.end(); ++it) {
378 Stringmaps value;
379 // Convert GeolocationInfos to their Stringmaps equivalent.
380 for(GeolocationInfos::const_iterator geoinfo_it = it->second.begin();
381 geoinfo_it != it->second.end(); ++geoinfo_it) {
382 value.push_back(geoinfo_it->properties());
383 }
384 networks[it->first] = StringmapsToVariant(value);
385 }
Gaurav Shah645bff82012-10-08 14:06:04 -0700386 return networks;
387}
388
Christopher Wiley3d5ab402013-02-15 13:25:58 -0800389bool ManagerDBusAdaptor::VerifyDestination(const string &certificate,
390 const string &public_key,
391 const string &nonce,
392 const string &signed_data,
393 const string &destination_udn,
Christopher Wileycdde79f2013-05-01 14:26:56 -0700394 const string &hotspot_ssid,
395 const string &hotspot_bssid,
Christopher Wiley3d5ab402013-02-15 13:25:58 -0800396 ::DBus::Error &error) {
397 SLOG(DBus, 2) << __func__;
Christopher Wiley0d9cf0c2013-02-19 19:24:57 -0800398 Error e(Error::kOperationInitiated);
399 DBus::Tag *tag = new DBus::Tag();
400 manager_->VerifyDestination(certificate, public_key, nonce,
401 signed_data, destination_udn,
Christopher Wileycdde79f2013-05-01 14:26:56 -0700402 hotspot_ssid, hotspot_bssid,
Christopher Wiley0d9cf0c2013-02-19 19:24:57 -0800403 GetBoolMethodReplyCallback(tag), &e);
404 ReturnResultOrDefer(tag, e, &error);
405 CHECK(e.IsFailure()) << __func__ << " should only return directly on error.";
Christopher Wiley3d5ab402013-02-15 13:25:58 -0800406 return false;
407}
408
409string ManagerDBusAdaptor::VerifyAndEncryptCredentials(
410 const string &certificate,
411 const string &public_key,
412 const string &nonce,
413 const string &signed_data,
414 const string &destination_udn,
Christopher Wileycdde79f2013-05-01 14:26:56 -0700415 const string &hotspot_ssid,
416 const string &hotspot_bssid,
Christopher Wiley3d5ab402013-02-15 13:25:58 -0800417 const ::DBus::Path &network,
418 ::DBus::Error &error) {
419 SLOG(DBus, 2) << __func__;
Christopher Wiley0d9cf0c2013-02-19 19:24:57 -0800420 Error e(Error::kOperationInitiated);
421 DBus::Tag *tag = new DBus::Tag();
422 manager_->VerifyAndEncryptCredentials(certificate, public_key, nonce,
423 signed_data, destination_udn,
Christopher Wileycdde79f2013-05-01 14:26:56 -0700424 hotspot_ssid, hotspot_bssid,
Christopher Wiley0d9cf0c2013-02-19 19:24:57 -0800425 network,
426 GetStringMethodReplyCallback(tag),
427 &e);
428 ReturnResultOrDefer(tag, e, &error);
429 CHECK(e.IsFailure()) << __func__ << " should only return directly on error.";
Christopher Wiley3d5ab402013-02-15 13:25:58 -0800430 return "";
431}
432
433string ManagerDBusAdaptor::VerifyAndEncryptData(
434 const string &certificate,
435 const string &public_key,
436 const string &nonce,
437 const string &signed_data,
438 const string &destination_udn,
Christopher Wileycdde79f2013-05-01 14:26:56 -0700439 const string &hotspot_ssid,
440 const string &hotspot_bssid,
Christopher Wiley3d5ab402013-02-15 13:25:58 -0800441 const string &data,
442 ::DBus::Error &error) {
443 SLOG(DBus, 2) << __func__;
Christopher Wiley0d9cf0c2013-02-19 19:24:57 -0800444 Error e(Error::kOperationInitiated);
445 DBus::Tag *tag = new DBus::Tag();
446 manager_->VerifyAndEncryptData(certificate, public_key, nonce,
447 signed_data, destination_udn,
Christopher Wileycdde79f2013-05-01 14:26:56 -0700448 hotspot_ssid, hotspot_bssid,
Christopher Wiley0d9cf0c2013-02-19 19:24:57 -0800449 data, GetStringMethodReplyCallback(tag),
450 &e);
451 ReturnResultOrDefer(tag, e, &error);
452 CHECK(e.IsFailure()) << __func__ << " should only return directly on error.";
Christopher Wiley3d5ab402013-02-15 13:25:58 -0800453 return "";
454}
455
Paul Stewart39db5ca2013-03-18 14:15:17 -0700456void ManagerDBusAdaptor::ConnectToBestServices(::DBus::Error &error) {
Darin Petkovcbe9c392013-04-11 11:52:35 +0200457 SLOG(DBus, 2) << __func__;
Paul Stewart39db5ca2013-03-18 14:15:17 -0700458 Error e;
459 manager_->ConnectToBestServices(&e);
460 e.ToDBusError(&error);
461}
Christopher Wiley3d5ab402013-02-15 13:25:58 -0800462
Chris Masoned7732e42011-05-20 11:08:56 -0700463} // namespace shill