blob: fe6a8c394c4b2e37d0f8e4e9086958d5087f2f71 [file] [log] [blame]
Christopher Wiley4b5f04c2014-03-27 14:45:37 -07001// Copyright 2014 The Chromium OS Authors. All rights reserved.
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 "buffet/manager.h"
6
Alex Vakulenko7c3226e2014-05-07 17:35:24 -07007#include <map>
Alex Vakulenkoec41a0c2015-04-17 15:35:34 -07008#include <set>
Alex Vakulenko7c3226e2014-05-07 17:35:24 -07009#include <string>
10
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070011#include <base/bind.h>
12#include <base/bind_helpers.h>
Alex Vakulenko4f7778e2014-09-11 16:57:24 -070013#include <base/json/json_reader.h>
Christopher Wiley2ffa0042014-05-05 16:09:16 -070014#include <base/json/json_writer.h>
Alex Vakulenkof7754542015-06-26 12:59:50 -070015#include <base/message_loop/message_loop.h>
Christopher Wiley8994e012015-02-06 17:51:43 -080016#include <base/time/time.h>
Alex Vakulenko24e5f5d2014-08-27 11:00:57 -070017#include <chromeos/dbus/async_event_sequencer.h>
18#include <chromeos/dbus/exported_object_manager.h>
19#include <chromeos/errors/error.h>
Garret Kelly89ba0362015-05-29 15:56:52 -040020#include <chromeos/http/http_transport.h>
Anton Muhin53e882a2014-11-22 05:59:14 +040021#include <chromeos/key_value_store.h>
Vitaly Bukae74c8722015-08-13 00:33:00 -070022#include <chromeos/message_loops/message_loop.h>
Christopher Wiley2ffa0042014-05-05 16:09:16 -070023#include <dbus/bus.h>
Christopher Wiley54028f92014-04-01 17:33:29 -070024#include <dbus/object_path.h>
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070025#include <dbus/values_util.h>
Vitaly Bukae2713ac2015-08-03 13:50:01 -070026#include <weave/enum_to_string.h>
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070027
Vitaly Bukaa0305d32015-07-27 16:08:51 -070028#include "buffet/dbus_command_dispatcher.h"
29#include "buffet/dbus_conversion.h"
Vitaly Buka00882b72015-08-06 00:32:11 -070030#include "buffet/http_transport_client.h"
Alex Vakulenko8473fb72015-08-18 00:55:40 +000031//#include "buffet/shill_client.h"
Christopher Wileye925bb32015-08-03 20:09:18 -070032
33#ifdef BUFFET_USE_WIFI_BOOTSTRAPPING
34//#include "buffet/peerd_client.h"
Alex Vakulenkod78756d2015-08-11 12:32:02 -070035//#include "buffet/webserv_client.h"
Christopher Wileye925bb32015-08-03 20:09:18 -070036#endif // BUFFET_USE_WIFI_BOOTSTRAPPING
Vitaly Buka03319c22015-07-17 14:48:30 -070037
Christopher Wiley68c07cc2014-07-29 14:07:10 -070038using chromeos::dbus_utils::AsyncEventSequencer;
Christopher Wiley1aa980e2014-08-11 10:51:20 -070039using chromeos::dbus_utils::ExportedObjectManager;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070040
41namespace buffet {
42
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070043namespace {
Vitaly Buka7b3ba792015-06-09 17:01:54 -070044
Vitaly Buka7b3ba792015-06-09 17:01:54 -070045const char kPairingSessionIdKey[] = "sessionId";
46const char kPairingModeKey[] = "mode";
47const char kPairingCodeKey[] = "code";
48
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070049const char kErrorDomain[] = "buffet";
50const char kNotImplemented[] = "notImplemented";
51
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070052} // anonymous namespace
53
Vitaly Bukae74c8722015-08-13 00:33:00 -070054class Manager::TaskRunner : public weave::TaskRunner {
55 public:
56 void PostDelayedTask(const tracked_objects::Location& from_here,
57 const base::Closure& task,
58 base::TimeDelta delay) override {
59 chromeos::MessageLoop::current()->PostDelayedTask(from_here, task, delay);
60 }
61};
62
Alex Vakulenkob6351532014-08-15 11:49:35 -070063Manager::Manager(const base::WeakPtr<ExportedObjectManager>& object_manager)
64 : dbus_object_(object_manager.get(),
65 object_manager->GetBus(),
Vitaly Buka91cc7152015-03-20 09:46:57 -070066 org::chromium::Buffet::ManagerAdaptor::GetObjectPath()) {
67}
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070068
Vitaly Buka91cc7152015-03-20 09:46:57 -070069Manager::~Manager() {
70}
Alex Vakulenkoecf961a2014-10-28 13:50:16 -070071
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070072void Manager::Start(const weave::Device::Options& options,
Vitaly Buka58a288b2015-07-31 00:33:31 -070073 const std::set<std::string>& device_whitelist,
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070074 AsyncEventSequencer* sequencer) {
Vitaly Bukae74c8722015-08-13 00:33:00 -070075 task_runner_.reset(new TaskRunner{});
Vitaly Buka00882b72015-08-06 00:32:11 -070076 http_client_.reset(new HttpTransportClient);
Alex Vakulenko8473fb72015-08-18 00:55:40 +000077// shill_client_.reset(new ShillClient{dbus_object_.GetBus(), device_whitelist});
Christopher Wileye925bb32015-08-03 20:09:18 -070078 weave::Mdns* mdns{nullptr};
79 weave::HttpServer* http_server{nullptr};
80#ifdef BUFFET_USE_WIFI_BOOTSTRAPPING
Alex Vakulenko8473fb72015-08-18 00:55:40 +000081// if (!options.disable_privet) {
82// peerd_client_.reset(new PeerdClient{dbus_object_.GetBus()});
Alex Vakulenkod78756d2015-08-11 12:32:02 -070083// web_serv_client_.reset(new WebServClient{dbus_object_.GetBus(), sequencer});
Christopher Wileye925bb32015-08-03 20:09:18 -070084// mdns = peerd_client_.get();
85// http_server = web_serv_client_.get();
Alex Vakulenko8473fb72015-08-18 00:55:40 +000086// }
Christopher Wileye925bb32015-08-03 20:09:18 -070087#endif // BUFFET_USE_WIFI_BOOTSTRAPPING
Vitaly Buka7042c582015-07-30 17:02:14 -070088
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070089 device_ = weave::Device::Create();
Vitaly Bukae74c8722015-08-13 00:33:00 -070090 device_->Start(options, task_runner_.get(), http_client_.get(),
Vitaly Buka670b1e62015-08-12 21:15:40 -070091 nullptr /*shill_client_.get()*/, mdns, http_server);
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070092
Vitaly Bukaa0305d32015-07-27 16:08:51 -070093 command_dispatcher_.reset(new DBusCommandDispacher{
Vitaly Bukae8c3bab2015-07-29 16:39:34 -070094 dbus_object_.GetObjectManager(), device_->GetCommands()});
95
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070096 device_->GetState()->AddOnChangedCallback(
Vitaly Buka2b30e7a2015-05-27 09:27:08 -070097 base::Bind(&Manager::OnStateChanged, weak_ptr_factory_.GetWeakPtr()));
Vitaly Bukabf4ba652015-05-14 16:57:23 -070098
Vitaly Buka0c6dcd22015-07-10 00:12:25 -070099 device_->GetConfig()->AddOnChangedCallback(
Vitaly Bukabf4ba652015-05-14 16:57:23 -0700100 base::Bind(&Manager::OnConfigChanged, weak_ptr_factory_.GetWeakPtr()));
Vitaly Bukabf4ba652015-05-14 16:57:23 -0700101
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700102 device_->GetCloud()->AddOnRegistrationChangedCallback(base::Bind(
Vitaly Bukabf4ba652015-05-14 16:57:23 -0700103 &Manager::OnRegistrationChanged, weak_ptr_factory_.GetWeakPtr()));
Vitaly Bukae74fe3c2015-05-13 13:48:59 -0700104
Vitaly Buka1d63c9c2015-07-17 14:34:35 -0700105 if (device_->GetPrivet()) {
106 device_->GetPrivet()->AddOnWifiSetupChangedCallback(base::Bind(
107 &Manager::UpdateWiFiBootstrapState, weak_ptr_factory_.GetWeakPtr()));
Vitaly Bukae74fe3c2015-05-13 13:48:59 -0700108
Vitaly Buka1d63c9c2015-07-17 14:34:35 -0700109 device_->GetPrivet()->AddOnPairingChangedCallbacks(
110 base::Bind(&Manager::OnPairingStart, weak_ptr_factory_.GetWeakPtr()),
111 base::Bind(&Manager::OnPairingEnd, weak_ptr_factory_.GetWeakPtr()));
112 } else {
113 UpdateWiFiBootstrapState(weave::WifiSetupState::kDisabled);
114 }
Vitaly Buka84fd6dd2015-06-09 17:22:18 -0700115
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -0800116 dbus_adaptor_.RegisterWithDBusObject(&dbus_object_);
Vitaly Buka84fd6dd2015-06-09 17:22:18 -0700117 dbus_object_.RegisterAsync(
118 sequencer->GetHandler("Manager.RegisterAsync() failed.", true));
Vitaly Buka84fd6dd2015-06-09 17:22:18 -0700119}
120
121void Manager::Stop() {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700122 device_.reset();
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700123}
124
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700125// TODO(vitalybuka): Remove, it's just duplicate of property.
Alex Vakulenko6c375262015-06-19 11:01:42 -0700126void Manager::CheckDeviceRegistered(
127 DBusMethodResponsePtr<std::string> response) {
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700128 LOG(INFO) << "Received call to Manager.CheckDeviceRegistered()";
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700129 response->Return(dbus_adaptor_.GetDeviceId());
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700130}
131
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700132// TODO(vitalybuka): Remove or rename to leave for testing.
Alex Vakulenko6c375262015-06-19 11:01:42 -0700133void Manager::GetDeviceInfo(DBusMethodResponsePtr<std::string> response) {
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700134 LOG(INFO) << "Received call to Manager.GetDeviceInfo()";
Alex Vakulenko6c375262015-06-19 11:01:42 -0700135 std::shared_ptr<DBusMethodResponse<std::string>> shared_response =
136 std::move(response);
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700137
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700138 device_->GetCloud()->GetDeviceInfo(
Alex Vakulenko6c375262015-06-19 11:01:42 -0700139 base::Bind(&Manager::OnGetDeviceInfoSuccess,
140 weak_ptr_factory_.GetWeakPtr(), shared_response),
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700141 base::Bind(&Manager::OnGetDeviceInfoError, weak_ptr_factory_.GetWeakPtr(),
142 shared_response));
Alex Vakulenko6c375262015-06-19 11:01:42 -0700143}
Alex Vakulenko7c3226e2014-05-07 17:35:24 -0700144
Alex Vakulenko6c375262015-06-19 11:01:42 -0700145void Manager::OnGetDeviceInfoSuccess(
146 const std::shared_ptr<DBusMethodResponse<std::string>>& response,
147 const base::DictionaryValue& device_info) {
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700148 std::string device_info_str;
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700149 base::JSONWriter::WriteWithOptions(
Alex Vakulenko6c375262015-06-19 11:01:42 -0700150 device_info, base::JSONWriter::OPTIONS_PRETTY_PRINT, &device_info_str);
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700151 response->Return(device_info_str);
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700152}
153
Alex Vakulenko6c375262015-06-19 11:01:42 -0700154void Manager::OnGetDeviceInfoError(
155 const std::shared_ptr<DBusMethodResponse<std::string>>& response,
156 const chromeos::Error* error) {
157 response->ReplyWithError(error);
158}
159
160void Manager::RegisterDevice(DBusMethodResponsePtr<std::string> response,
Vitaly Bukacbadabe2015-05-14 23:33:32 -0700161 const std::string& ticket_id) {
Anton Muhin9cc03fd2014-10-16 18:59:57 +0400162 LOG(INFO) << "Received call to Manager.RegisterDevice()";
Alex Vakulenkof3d77e52014-04-15 11:36:32 -0700163
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700164 chromeos::ErrorPtr error;
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700165 std::string device_id =
166 device_->GetCloud()->RegisterDevice(ticket_id, &error);
David Zeuthen2101c082015-02-12 15:24:21 -0500167 if (!device_id.empty()) {
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700168 response->Return(device_id);
David Zeuthen2101c082015-02-12 15:24:21 -0500169 return;
170 }
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700171 CHECK(error);
David Zeuthen2101c082015-02-12 15:24:21 -0500172 response->ReplyWithError(error.get());
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700173}
174
Alex Vakulenko6c375262015-06-19 11:01:42 -0700175void Manager::UpdateState(DBusMethodResponsePtr<> response,
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -0800176 const chromeos::VariantDictionary& property_set) {
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700177 chromeos::ErrorPtr error;
Vitaly Bukaa0305d32015-07-27 16:08:51 -0700178 auto properties = DictionaryFromDBusVariantDictionary(property_set, &error);
Vitaly Bukafb2584b2015-07-28 21:39:45 -0700179 if (!properties)
180 response->ReplyWithError(error.get());
181
182 if (!device_->GetState()->SetProperties(*properties, &error))
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700183 response->ReplyWithError(error.get());
184 else
185 response->Return();
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700186}
187
Alex Vakulenkoceab1772015-01-20 10:50:04 -0800188bool Manager::GetState(chromeos::ErrorPtr* error, std::string* state) {
Vitaly Bukacd5e5562015-07-28 15:33:55 -0700189 auto json = device_->GetState()->GetStateValuesAsJson();
190 CHECK(json);
Nathan Bullockf5b91bf2015-04-01 15:32:58 -0400191 base::JSONWriter::WriteWithOptions(
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700192 *json, base::JSONWriter::OPTIONS_PRETTY_PRINT, state);
Alex Vakulenkoceab1772015-01-20 10:50:04 -0800193 return true;
194}
195
Alex Vakulenko6c375262015-06-19 11:01:42 -0700196void Manager::AddCommand(DBusMethodResponsePtr<std::string> response,
Vitaly Bukac03ec2b2015-05-31 23:32:46 -0700197 const std::string& json_command,
198 const std::string& in_user_role) {
Alex Vakulenko4f7778e2014-09-11 16:57:24 -0700199 std::string error_message;
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700200 std::unique_ptr<base::Value> value(
201 base::JSONReader::ReadAndReturnError(json_command, base::JSON_PARSE_RFC,
202 nullptr, &error_message)
203 .release());
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700204 const base::DictionaryValue* command{nullptr};
205 if (!value || !value->GetAsDictionary(&command)) {
206 return response->ReplyWithError(FROM_HERE, chromeos::errors::json::kDomain,
207 chromeos::errors::json::kParseError,
208 error_message);
Alex Vakulenko4f7778e2014-09-11 16:57:24 -0700209 }
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700210
Alex Vakulenkob91dcfe2014-10-30 16:28:38 -0700211 chromeos::ErrorPtr error;
Vitaly Buka3b086312015-07-09 14:59:23 -0700212 weave::UserRole role;
Vitaly Buka03319c22015-07-17 14:48:30 -0700213 if (!StringToEnum(in_user_role, &role)) {
214 chromeos::Error::AddToPrintf(&error, FROM_HERE, kErrorDomain,
215 "invalid_user_role", "Invalid role: '%s'",
216 in_user_role.c_str());
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700217 return response->ReplyWithError(error.get());
Vitaly Buka03319c22015-07-17 14:48:30 -0700218 }
Vitaly Bukac03ec2b2015-05-31 23:32:46 -0700219
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700220 std::string id;
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700221 if (!device_->GetCommands()->AddCommand(*command, role, &id, &error))
Vitaly Bukaa4e8d7f2015-06-09 09:46:53 -0700222 return response->ReplyWithError(error.get());
Vitaly Bukac03ec2b2015-05-31 23:32:46 -0700223
Vitaly Buka59af7ac2015-03-24 12:42:24 -0700224 response->Return(id);
Alex Vakulenko4f7778e2014-09-11 16:57:24 -0700225}
226
Alex Vakulenko6c375262015-06-19 11:01:42 -0700227void Manager::GetCommand(DBusMethodResponsePtr<std::string> response,
Vitaly Buka5515de02015-03-24 11:39:40 -0700228 const std::string& id) {
Vitaly Bukaba463732015-07-14 19:19:39 -0700229 const weave::Command* command = device_->GetCommands()->FindCommand(id);
Vitaly Buka5515de02015-03-24 11:39:40 -0700230 if (!command) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700231 response->ReplyWithError(FROM_HERE, kErrorDomain, "unknown_command",
Vitaly Buka5515de02015-03-24 11:39:40 -0700232 "Can't find command with id: " + id);
233 return;
234 }
235 std::string command_str;
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700236 base::JSONWriter::WriteWithOptions(
237 *command->ToJson(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &command_str);
Vitaly Buka5515de02015-03-24 11:39:40 -0700238 response->Return(command_str);
239}
240
Alex Vakulenko12e2c1a2014-11-21 08:57:57 -0800241std::string Manager::TestMethod(const std::string& message) {
Alex Vakulenko35e3bab2014-08-15 11:45:46 -0700242 LOG(INFO) << "Received call to test method: " << message;
243 return message;
Christopher Wiley2ffa0042014-05-05 16:09:16 -0700244}
245
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700246bool Manager::EnableWiFiBootstrapping(
247 chromeos::ErrorPtr* error,
248 const dbus::ObjectPath& in_listener_path,
249 const chromeos::VariantDictionary& in_options) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700250 chromeos::Error::AddTo(error, FROM_HERE, kErrorDomain, kNotImplemented,
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700251 "Manual WiFi bootstrapping is not implemented");
252 return false;
253}
254
255bool Manager::DisableWiFiBootstrapping(chromeos::ErrorPtr* error) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700256 chromeos::Error::AddTo(error, FROM_HERE, kErrorDomain, kNotImplemented,
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700257 "Manual WiFi bootstrapping is not implemented");
258 return false;
259}
260
261bool Manager::EnableGCDBootstrapping(
262 chromeos::ErrorPtr* error,
263 const dbus::ObjectPath& in_listener_path,
264 const chromeos::VariantDictionary& in_options) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700265 chromeos::Error::AddTo(error, FROM_HERE, kErrorDomain, kNotImplemented,
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700266 "Manual GCD bootstrapping is not implemented");
267 return false;
268}
269
270bool Manager::DisableGCDBootstrapping(chromeos::ErrorPtr* error) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700271 chromeos::Error::AddTo(error, FROM_HERE, kErrorDomain, kNotImplemented,
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700272 "Manual GCD bootstrapping is not implemented");
273 return false;
274}
275
Vitaly Buka760d6322015-04-17 00:41:31 -0700276bool Manager::UpdateDeviceInfo(chromeos::ErrorPtr* error,
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700277 const std::string& name,
278 const std::string& description,
279 const std::string& location) {
280 return device_->GetCloud()->UpdateDeviceInfo(name, description, location,
281 error);
Christopher Wiley2f772932015-02-15 15:42:04 -0800282}
283
Vitaly Buka7cd01972015-05-14 21:25:45 -0700284bool Manager::UpdateServiceConfig(chromeos::ErrorPtr* error,
285 const std::string& client_id,
286 const std::string& client_secret,
287 const std::string& api_key,
288 const std::string& oauth_url,
289 const std::string& service_url) {
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700290 return device_->GetCloud()->UpdateServiceConfig(
291 client_id, client_secret, api_key, oauth_url, service_url, error);
Vitaly Buka7cd01972015-05-14 21:25:45 -0700292}
293
Vitaly Buka2b30e7a2015-05-27 09:27:08 -0700294void Manager::OnStateChanged() {
Vitaly Bukacd5e5562015-07-28 15:33:55 -0700295 auto state = device_->GetState()->GetStateValuesAsJson();
Vitaly Buka2b30e7a2015-05-27 09:27:08 -0700296 CHECK(state);
297 std::string json;
298 base::JSONWriter::WriteWithOptions(
Alex Vakulenkoab4e4ff2015-06-15 12:53:22 -0700299 *state, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
Vitaly Buka2b30e7a2015-05-27 09:27:08 -0700300 dbus_adaptor_.SetState(json);
301}
302
Vitaly Buka3b086312015-07-09 14:59:23 -0700303void Manager::OnRegistrationChanged(weave::RegistrationStatus status) {
Vitaly Buka03319c22015-07-17 14:48:30 -0700304 dbus_adaptor_.SetStatus(weave::EnumToString(status));
Vitaly Bukabf4ba652015-05-14 16:57:23 -0700305}
306
Vitaly Buka00b83492015-07-20 00:37:48 -0700307void Manager::OnConfigChanged(const weave::Settings& settings) {
308 dbus_adaptor_.SetDeviceId(settings.device_id);
309 dbus_adaptor_.SetOemName(settings.oem_name);
310 dbus_adaptor_.SetModelName(settings.model_name);
311 dbus_adaptor_.SetModelId(settings.model_id);
312 dbus_adaptor_.SetName(settings.name);
313 dbus_adaptor_.SetDescription(settings.description);
314 dbus_adaptor_.SetLocation(settings.location);
315 dbus_adaptor_.SetAnonymousAccessRole(settings.local_anonymous_access_role);
Vitaly Bukabf4ba652015-05-14 16:57:23 -0700316}
317
Vitaly Buka03319c22015-07-17 14:48:30 -0700318void Manager::UpdateWiFiBootstrapState(weave::WifiSetupState state) {
319 dbus_adaptor_.SetWiFiBootstrapState(weave::EnumToString(state));
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700320}
321
322void Manager::OnPairingStart(const std::string& session_id,
Vitaly Buka0c6dcd22015-07-10 00:12:25 -0700323 weave::PairingType pairing_type,
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700324 const std::vector<uint8_t>& code) {
325 // For now, just overwrite the exposed PairInfo with
326 // the most recent pairing attempt.
327 dbus_adaptor_.SetPairingInfo(chromeos::VariantDictionary{
328 {kPairingSessionIdKey, session_id},
Vitaly Buka03319c22015-07-17 14:48:30 -0700329 {kPairingModeKey, weave::EnumToString(pairing_type)},
Vitaly Buka7b3ba792015-06-09 17:01:54 -0700330 {kPairingCodeKey, code},
331 });
332}
333
334void Manager::OnPairingEnd(const std::string& session_id) {
335 auto exposed_pairing_attempt = dbus_adaptor_.GetPairingInfo();
336 auto it = exposed_pairing_attempt.find(kPairingSessionIdKey);
337 if (it == exposed_pairing_attempt.end()) {
338 return;
339 }
340 std::string exposed_session{it->second.TryGet<std::string>()};
341 if (exposed_session == session_id) {
342 dbus_adaptor_.SetPairingInfo(chromeos::VariantDictionary{});
343 }
344}
345
Christopher Wiley4b5f04c2014-03-27 14:45:37 -0700346} // namespace buffet