blob: ae03b4547e1064253d8adb2ddc741fceffaebe98 [file] [log] [blame]
mukesh agrawal8a3188d2011-12-01 20:56:44 +00001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewart75897df2011-04-27 09:05:53 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Chris Masoneb2e326b2011-07-12 13:28:51 -07005#include "shill/service.h"
6
Paul Stewart75897df2011-04-27 09:05:53 -07007#include <time.h>
Paul Stewart75897df2011-04-27 09:05:53 -07008#include <stdio.h>
Chris Masoneee929b72011-05-10 10:02:18 -07009
Chris Masone8fe2c7e2011-06-09 15:51:19 -070010#include <map>
Paul Stewart75897df2011-04-27 09:05:53 -070011#include <string>
Chris Masone8fe2c7e2011-06-09 15:51:19 -070012#include <vector>
Paul Stewart75897df2011-04-27 09:05:53 -070013
Chris Masoneee929b72011-05-10 10:02:18 -070014#include <base/logging.h>
Chris Masone3bd3c8c2011-06-13 08:20:26 -070015#include <base/memory/scoped_ptr.h>
mukesh agrawal51a7e932011-07-27 16:18:26 -070016#include <base/string_number_conversions.h>
Chris Masone3bd3c8c2011-06-13 08:20:26 -070017#include <chromeos/dbus/service_constants.h>
Chris Masoneee929b72011-05-10 10:02:18 -070018
Paul Stewartbe5f5b32011-12-07 17:11:11 -080019#include "shill/connection.h"
Paul Stewart75897df2011-04-27 09:05:53 -070020#include "shill/control_interface.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070021#include "shill/error.h"
Paul Stewartbe5f5b32011-12-07 17:11:11 -080022#include "shill/http_proxy.h"
Chris Masone6791a432011-07-12 13:23:19 -070023#include "shill/manager.h"
Thieu Le48e6d6d2011-12-06 00:40:27 +000024#include "shill/metrics.h"
Chris Masone7aa5f902011-07-11 11:13:35 -070025#include "shill/profile.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070026#include "shill/property_accessor.h"
Chris Masone7aa5f902011-07-11 11:13:35 -070027#include "shill/refptr_types.h"
Chris Masoned7732e42011-05-20 11:08:56 -070028#include "shill/service_dbus_adaptor.h"
Darin Petkovba40dd32011-07-11 20:06:39 -070029#include "shill/store_interface.h"
Paul Stewart75897df2011-04-27 09:05:53 -070030
Chris Masone8fe2c7e2011-06-09 15:51:19 -070031using std::map;
Paul Stewart75897df2011-04-27 09:05:53 -070032using std::string;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070033using std::vector;
Paul Stewart75897df2011-04-27 09:05:53 -070034
35namespace shill {
Darin Petkovba40dd32011-07-11 20:06:39 -070036
mukesh agrawalbf14e942012-03-02 14:36:34 -080037const char Service::kAutoConnConnected[] = "connected";
38const char Service::kAutoConnConnecting[] = "connecting";
39const char Service::kAutoConnExplicitDisconnect[] = "explicitly disconnected";
40const char Service::kAutoConnNotConnectable[] = "not connectable";
41
Darin Petkovba40dd32011-07-11 20:06:39 -070042const char Service::kCheckPortalAuto[] = "auto";
43const char Service::kCheckPortalFalse[] = "false";
44const char Service::kCheckPortalTrue[] = "true";
45
Paul Stewartac4ac002011-08-26 12:04:26 -070046const int Service::kPriorityNone = 0;
47
mukesh agrawalddc378f2012-02-17 18:26:20 -080048const char Service::kServiceSortConnectEtc[] = "ConnectableEtc";
49const char Service::kServiceSortIsConnected[] = "IsConnected";
50const char Service::kServiceSortIsConnecting[] = "IsConnecting";
51const char Service::kServiceSortIsFailed[] = "IsFailed";
52const char Service::kServiceSortTechnology[] = "Technology";
53const char Service::kServiceSortSecurityEtc[] = "SecurityEtc";
54const char Service::kServiceSortUniqueName[] = "UniqueName";
55
Darin Petkovba40dd32011-07-11 20:06:39 -070056const char Service::kStorageAutoConnect[] = "AutoConnect";
57const char Service::kStorageCheckPortal[] = "CheckPortal";
58const char Service::kStorageEapAnonymousIdentity[] = "EAP.AnonymousIdentity";
59const char Service::kStorageEapCACert[] = "EAP.CACert";
60const char Service::kStorageEapCACertID[] = "EAP.CACertID";
61const char Service::kStorageEapCertID[] = "EAP.CertID";
62const char Service::kStorageEapClientCert[] = "EAP.ClientCert";
63const char Service::kStorageEapEap[] = "EAP.EAP";
64const char Service::kStorageEapIdentity[] = "EAP.Identity";
65const char Service::kStorageEapInnerEap[] = "EAP.InnerEAP";
66const char Service::kStorageEapKeyID[] = "EAP.KeyID";
67const char Service::kStorageEapKeyManagement[] = "EAP.KeyMgmt";
68const char Service::kStorageEapPIN[] = "EAP.PIN";
69const char Service::kStorageEapPassword[] = "EAP.Password";
70const char Service::kStorageEapPrivateKey[] = "EAP.PrivateKey";
71const char Service::kStorageEapPrivateKeyPassword[] = "EAP.PrivateKeyPassword";
72const char Service::kStorageEapUseSystemCAs[] = "EAP.UseSystemCAs";
Paul Stewart0756db92012-01-27 08:34:47 -080073const char Service::kStorageError[] = "Error";
Darin Petkovba40dd32011-07-11 20:06:39 -070074const char Service::kStorageFavorite[] = "Favorite";
Paul Stewart0756db92012-01-27 08:34:47 -080075const char Service::kStorageGUID[] = "GUID";
Darin Petkovba40dd32011-07-11 20:06:39 -070076const char Service::kStorageName[] = "Name";
77const char Service::kStoragePriority[] = "Priority";
78const char Service::kStorageProxyConfig[] = "ProxyConfig";
79const char Service::kStorageSaveCredentials[] = "SaveCredentials";
Paul Stewart2706aaf2011-12-14 16:44:04 -080080const char Service::kStorageType[] = "Type";
Paul Stewart987e71e2011-12-05 09:45:06 -080081const char Service::kStorageUIData[] = "UIData";
Darin Petkovba40dd32011-07-11 20:06:39 -070082
mukesh agrawal8f3f7752012-02-17 19:42:09 -080083const uint8 Service::kStrengthMax = 100;
84const uint8 Service::kStrengthMin = 0;
85
mukesh agrawal51a7e932011-07-27 16:18:26 -070086// static
87unsigned int Service::serial_number_ = 0;
88
Paul Stewart75897df2011-04-27 09:05:53 -070089Service::Service(ControlInterface *control_interface,
mukesh agrawalb54601c2011-06-07 17:39:22 -070090 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080091 Metrics *metrics,
mukesh agrawal7a4e4002011-09-06 11:26:05 -070092 Manager *manager,
Gaurav Shah435de2c2011-11-17 19:01:07 -080093 Technology::Identifier technology)
Eric Shienbroodcc95c5d2012-03-30 15:25:49 -040094 : state_(kStateIdle),
Paul Stewart03dba0b2011-08-22 16:32:45 -070095 failure_(kFailureUnknown),
96 auto_connect_(false),
Darin Petkovba40dd32011-07-11 20:06:39 -070097 check_portal_(kCheckPortalAuto),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070098 connectable_(false),
mukesh agrawaladb68482012-01-17 16:31:51 -080099 explicitly_disconnected_(false),
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700100 favorite_(false),
Darin Petkovba40dd32011-07-11 20:06:39 -0700101 priority_(kPriorityNone),
Paul Stewart1ca3e852011-11-04 07:50:49 -0700102 security_level_(0),
Paul Stewart22aa71b2011-09-16 12:15:11 -0700103 strength_(0),
Darin Petkovba40dd32011-07-11 20:06:39 -0700104 save_credentials_(true),
Gaurav Shah435de2c2011-11-17 19:01:07 -0800105 technology_(technology),
mukesh agrawal568b5c62012-02-28 14:44:47 -0800106 failed_time_(0),
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700107 dispatcher_(dispatcher),
mukesh agrawald835b202011-10-07 15:26:47 -0700108 unique_name_(base::UintToString(serial_number_++)),
109 friendly_name_(unique_name_),
Chris Masonea82b7112011-05-25 15:16:29 -0700110 available_(false),
111 configured_(false),
Chris Masonea82b7112011-05-25 15:16:29 -0700112 configuration_(NULL),
Chris Masone6791a432011-07-12 13:23:19 -0700113 adaptor_(control_interface->CreateServiceAdaptor(this)),
Thieu Le3426c8f2012-01-11 17:35:11 -0800114 metrics_(metrics),
115 manager_(manager) {
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700116
Thieu Le284fe792012-01-31 17:53:19 -0800117 HelpRegisterDerivedBool(flimflam::kAutoConnectProperty,
118 &Service::GetAutoConnect,
119 &Service::SetAutoConnect);
Chris Masone4d42df82011-07-02 17:09:39 -0700120
121 // flimflam::kActivationStateProperty: Registered in CellularService
122 // flimflam::kCellularApnProperty: Registered in CellularService
123 // flimflam::kCellularLastGoodApnProperty: Registered in CellularService
124 // flimflam::kNetworkTechnologyProperty: Registered in CellularService
Darin Petkov3335b372011-08-22 11:05:32 -0700125 // flimflam::kOperatorNameProperty: DEPRECATED
126 // flimflam::kOperatorCodeProperty: DEPRECATED
Chris Masone4d42df82011-07-02 17:09:39 -0700127 // flimflam::kRoamingStateProperty: Registered in CellularService
Darin Petkov3335b372011-08-22 11:05:32 -0700128 // flimflam::kServingOperatorProperty: Registered in CellularService
Chris Masone4d42df82011-07-02 17:09:39 -0700129 // flimflam::kPaymentURLProperty: Registered in CellularService
130
Chris Masone27c4aa52011-07-02 13:10:14 -0700131 store_.RegisterString(flimflam::kCheckPortalProperty, &check_portal_);
132 store_.RegisterConstBool(flimflam::kConnectableProperty, &connectable_);
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400133 HelpRegisterDerivedRpcIdentifier(flimflam::kDeviceProperty,
134 &Service::GetDeviceRpcId,
135 NULL);
Paul Stewart4c561612012-03-21 12:49:01 -0700136 store_.RegisterString(flimflam::kGuidProperty, &guid_);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700137
Chris Masoneb2e326b2011-07-12 13:28:51 -0700138 store_.RegisterString(flimflam::kEapIdentityProperty, &eap_.identity);
139 store_.RegisterString(flimflam::kEAPEAPProperty, &eap_.eap);
140 store_.RegisterString(flimflam::kEapPhase2AuthProperty, &eap_.inner_eap);
Chris Masone27c4aa52011-07-02 13:10:14 -0700141 store_.RegisterString(flimflam::kEapAnonymousIdentityProperty,
Chris Masoneb2e326b2011-07-12 13:28:51 -0700142 &eap_.anonymous_identity);
143 store_.RegisterString(flimflam::kEAPClientCertProperty, &eap_.client_cert);
144 store_.RegisterString(flimflam::kEAPCertIDProperty, &eap_.cert_id);
145 store_.RegisterString(flimflam::kEapPrivateKeyProperty, &eap_.private_key);
mukesh agrawal292dc0f2012-01-26 18:02:46 -0800146 HelpRegisterWriteOnlyDerivedString(flimflam::kEapPrivateKeyPasswordProperty,
147 &Service::SetEAPPrivateKeyPassword,
148 NULL,
149 &eap_.private_key_password);
Chris Masoneb2e326b2011-07-12 13:28:51 -0700150 store_.RegisterString(flimflam::kEAPKeyIDProperty, &eap_.key_id);
151 store_.RegisterString(flimflam::kEapCaCertProperty, &eap_.ca_cert);
152 store_.RegisterString(flimflam::kEapCaCertIDProperty, &eap_.ca_cert_id);
153 store_.RegisterString(flimflam::kEAPPINProperty, &eap_.pin);
mukesh agrawal292dc0f2012-01-26 18:02:46 -0800154 HelpRegisterWriteOnlyDerivedString(flimflam::kEapPasswordProperty,
155 &Service::SetEAPPassword,
156 NULL,
157 &eap_.password);
Chris Masoneb2e326b2011-07-12 13:28:51 -0700158 store_.RegisterString(flimflam::kEapKeyMgmtProperty, &eap_.key_management);
159 store_.RegisterBool(flimflam::kEapUseSystemCAsProperty, &eap_.use_system_cas);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700160
Eric Shienbroodcc95c5d2012-03-30 15:25:49 -0400161 // TODO(ers): in flimflam clearing Error has the side-effect of
162 // setting the service state to IDLE. Is this important? I could
163 // see an autotest depending on it.
Chris Masone27c4aa52011-07-02 13:10:14 -0700164 store_.RegisterConstString(flimflam::kErrorProperty, &error_);
165 store_.RegisterConstBool(flimflam::kFavoriteProperty, &favorite_);
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800166 HelpRegisterDerivedUint16(shill::kHTTPProxyPortProperty,
167 &Service::GetHTTPProxyPort,
168 NULL);
Chris Masone27c4aa52011-07-02 13:10:14 -0700169 HelpRegisterDerivedBool(flimflam::kIsActiveProperty,
Chris Masoneb2e326b2011-07-12 13:28:51 -0700170 &Service::IsActive,
171 NULL);
Chris Masone4d42df82011-07-02 17:09:39 -0700172 // flimflam::kModeProperty: Registered in WiFiService
mukesh agrawald835b202011-10-07 15:26:47 -0700173 store_.RegisterConstString(flimflam::kNameProperty, &friendly_name_);
Chris Masone4d42df82011-07-02 17:09:39 -0700174 // flimflam::kPassphraseProperty: Registered in WiFiService
175 // flimflam::kPassphraseRequiredProperty: Registered in WiFiService
Chris Masone27c4aa52011-07-02 13:10:14 -0700176 store_.RegisterInt32(flimflam::kPriorityProperty, &priority_);
177 HelpRegisterDerivedString(flimflam::kProfileProperty,
178 &Service::GetProfileRpcId,
Paul Stewart1b1a7f22012-01-06 16:24:06 -0800179 &Service::SetProfileRpcId);
Chris Masone4d42df82011-07-02 17:09:39 -0700180 store_.RegisterString(flimflam::kProxyConfigProperty, &proxy_config_);
Chris Masone43b48a12011-07-01 13:37:07 -0700181 // TODO(cmasone): Create VPN Service with this property
Chris Masone27c4aa52011-07-02 13:10:14 -0700182 // store_.RegisterConstStringmap(flimflam::kProviderProperty, &provider_);
Chris Masone4d42df82011-07-02 17:09:39 -0700183
Chris Masoneb2e326b2011-07-12 13:28:51 -0700184 store_.RegisterBool(flimflam::kSaveCredentialsProperty, &save_credentials_);
Gaurav Shah435de2c2011-11-17 19:01:07 -0800185 HelpRegisterDerivedString(flimflam::kTypeProperty,
186 &Service::GetTechnologyString,
187 NULL);
Chris Masone4d42df82011-07-02 17:09:39 -0700188 // flimflam::kSecurityProperty: Registered in WiFiService
Chris Masone27c4aa52011-07-02 13:10:14 -0700189 HelpRegisterDerivedString(flimflam::kStateProperty,
190 &Service::CalculateState,
191 NULL);
Darin Petkovd78ee7e2012-01-12 11:21:10 +0100192 store_.RegisterConstUint8(flimflam::kSignalStrengthProperty, &strength_);
Paul Stewart987e71e2011-12-05 09:45:06 -0800193 store_.RegisterString(flimflam::kUIDataProperty, &ui_data_);
Chris Masone4d42df82011-07-02 17:09:39 -0700194 // flimflam::kWifiAuthMode: Registered in WiFiService
195 // flimflam::kWifiHiddenSsid: Registered in WiFiService
196 // flimflam::kWifiFrequency: Registered in WiFiService
197 // flimflam::kWifiPhyMode: Registered in WiFiService
198 // flimflam::kWifiHexSsid: Registered in WiFiService
Thieu Le48e6d6d2011-12-06 00:40:27 +0000199
200 metrics_->RegisterService(this);
201
Paul Stewartcb59fed2012-03-21 21:14:46 -0700202 IgnoreParameterForConfigure(flimflam::kTypeProperty);
Paul Stewart7f61e522012-03-22 11:13:45 -0700203 IgnoreParameterForConfigure(flimflam::kProfileProperty);
Paul Stewartcb59fed2012-03-21 21:14:46 -0700204
Chris Masoneb07006b2011-05-14 16:10:04 -0700205 VLOG(2) << "Service initialized.";
Paul Stewart75897df2011-04-27 09:05:53 -0700206}
207
Thieu Le48e6d6d2011-12-06 00:40:27 +0000208Service::~Service() {
209 metrics_->DeregisterService(this);
210}
Paul Stewart75897df2011-04-27 09:05:53 -0700211
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000212void Service::AutoConnect() {
mukesh agrawalbf14e942012-03-02 14:36:34 -0800213 const char *reason;
214 if (this->IsAutoConnectable(&reason)) {
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000215 Error error;
216 Connect(&error);
mukesh agrawal76d13882012-01-12 15:23:11 -0800217 } else {
mukesh agrawalbf14e942012-03-02 14:36:34 -0800218 LOG(INFO) << "Suppressed autoconnect to " << friendly_name() << " "
219 << "(" << reason << ")";
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000220 }
221}
222
mukesh agrawaladb68482012-01-17 16:31:51 -0800223void Service::Connect(Error */*error*/) {
224 explicitly_disconnected_ = false;
Eric Shienbroodcc95c5d2012-03-30 15:25:49 -0400225 // clear any failure state from a previous connect attempt
226 SetState(kStateIdle);
mukesh agrawaladb68482012-01-17 16:31:51 -0800227}
228
229void Service::Disconnect(Error */*error*/) {
230 explicitly_disconnected_ = true;
231}
232
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500233void Service::ActivateCellularModem(const string &/*carrier*/,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500234 Error *error,
235 const ResultCallback &/*callback*/) {
236 Error::PopulateAndLog(error, Error::kNotSupported,
237 "Service doesn't support cellular modem activation.");
Darin Petkovc408e692011-08-17 13:47:15 -0700238}
239
mukesh agrawal1830fa12011-09-26 14:31:40 -0700240bool Service::TechnologyIs(const Technology::Identifier /*type*/) const {
Paul Stewart22aa71b2011-09-16 12:15:11 -0700241 return false;
242}
243
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800244bool Service::IsActive(Error */*error*/) {
Paul Stewart03dba0b2011-08-22 16:32:45 -0700245 return state_ != kStateUnknown &&
246 state_ != kStateIdle &&
247 state_ != kStateFailure;
248}
249
250void Service::SetState(ConnectState state) {
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800251 LOG(INFO) << "In " << __func__ << "(): Service " << friendly_name_
252 << " state " << ConnectStateToString(state_) << " -> "
253 << ConnectStateToString(state);
mukesh agrawal7ec71312011-11-10 02:08:26 +0000254
Paul Stewart03dba0b2011-08-22 16:32:45 -0700255 if (state == state_) {
256 return;
257 }
258
259 state_ = state;
260 if (state != kStateFailure) {
261 failure_ = kFailureUnknown;
mukesh agrawal568b5c62012-02-28 14:44:47 -0800262 failed_time_ = 0;
Paul Stewart03dba0b2011-08-22 16:32:45 -0700263 }
264 manager_->UpdateService(this);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000265 metrics_->NotifyServiceStateChanged(this, state);
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800266 Error error;
267 adaptor_->EmitStringChanged(flimflam::kStateProperty, CalculateState(&error));
Paul Stewart03dba0b2011-08-22 16:32:45 -0700268}
269
270void Service::SetFailure(ConnectFailure failure) {
271 failure_ = failure;
mukesh agrawal568b5c62012-02-28 14:44:47 -0800272 failed_time_ = time(NULL);
Paul Stewart03dba0b2011-08-22 16:32:45 -0700273 SetState(kStateFailure);
274}
275
mukesh agrawal568b5c62012-02-28 14:44:47 -0800276void Service::SetFailureSilent(ConnectFailure failure) {
277 // Note that order matters here, since SetState modifies |failure_| and
278 // |failed_time_|.
279 SetState(kStateIdle);
280 failure_ = failure;
281 failed_time_ = time(NULL);
282}
283
Chris Masone6791a432011-07-12 13:23:19 -0700284string Service::GetRpcIdentifier() const {
Chris Masone3c3f6a12011-07-01 10:01:41 -0700285 return adaptor_->GetRpcIdentifier();
286}
287
Paul Stewartbba6a5b2011-11-02 18:45:59 -0700288bool Service::IsLoadableFrom(StoreInterface *storage) const {
289 return storage->ContainsGroup(GetStorageIdentifier());
290}
291
Chris Masone9d779932011-08-25 16:33:41 -0700292bool Service::Load(StoreInterface *storage) {
293 const string id = GetStorageIdentifier();
Chris Masone34af2182011-08-22 11:59:36 -0700294 if (!storage->ContainsGroup(id)) {
295 LOG(WARNING) << "Service is not available in the persistent store: " << id;
296 return false;
297 }
298 storage->GetBool(id, kStorageAutoConnect, &auto_connect_);
299 storage->GetString(id, kStorageCheckPortal, &check_portal_);
300 storage->GetBool(id, kStorageFavorite, &favorite_);
301 storage->GetInt(id, kStoragePriority, &priority_);
302 storage->GetString(id, kStorageProxyConfig, &proxy_config_);
303 storage->GetBool(id, kStorageSaveCredentials, &save_credentials_);
Paul Stewart987e71e2011-12-05 09:45:06 -0800304 storage->GetString(id, kStorageUIData, &ui_data_);
Paul Stewart4c561612012-03-21 12:49:01 -0700305 storage->GetString(id, kStorageGUID, &guid_);
Chris Masone34af2182011-08-22 11:59:36 -0700306
307 LoadEapCredentials(storage, id);
308
309 // TODO(petkov): Load these:
310
Chris Masone34af2182011-08-22 11:59:36 -0700311 // "Failure"
312 // "Modified"
313 // "LastAttempt"
Chris Masone34af2182011-08-22 11:59:36 -0700314 // "APN"
315 // "LastGoodAPN"
316
mukesh agrawaladb68482012-01-17 16:31:51 -0800317 explicitly_disconnected_ = false;
Paul Stewarta41e38d2011-11-11 07:47:29 -0800318 favorite_ = true;
319
Chris Masone34af2182011-08-22 11:59:36 -0700320 return true;
Darin Petkovba40dd32011-07-11 20:06:39 -0700321}
322
Paul Stewart65512e12012-03-26 18:01:08 -0700323bool Service::Unload() {
Paul Stewarta41e38d2011-11-11 07:47:29 -0800324 auto_connect_ = false;
Paul Stewartd8ad3c42012-01-09 12:39:38 -0800325 check_portal_ = kCheckPortalAuto;
Paul Stewarta41e38d2011-11-11 07:47:29 -0800326 favorite_ = false;
Paul Stewartd8ad3c42012-01-09 12:39:38 -0800327 priority_ = kPriorityNone;
328 proxy_config_ = "";
329 save_credentials_ = true;
330 ui_data_ = "";
331
332 UnloadEapCredentials();
Paul Stewart65512e12012-03-26 18:01:08 -0700333 return false;
Paul Stewarta41e38d2011-11-11 07:47:29 -0800334}
335
Chris Masone9d779932011-08-25 16:33:41 -0700336bool Service::Save(StoreInterface *storage) {
337 const string id = GetStorageIdentifier();
Chris Masone34af2182011-08-22 11:59:36 -0700338
Paul Stewart2706aaf2011-12-14 16:44:04 -0800339 storage->SetString(id, kStorageType, GetTechnologyString(NULL));
340
Chris Masone34af2182011-08-22 11:59:36 -0700341 // TODO(petkov): We could choose to simplify the saving code by removing most
342 // conditionals thus saving even default values.
343 if (favorite_) {
344 storage->SetBool(id, kStorageAutoConnect, auto_connect_);
345 }
346 if (check_portal_ == kCheckPortalAuto) {
347 storage->DeleteKey(id, kStorageCheckPortal);
348 } else {
349 storage->SetString(id, kStorageCheckPortal, check_portal_);
350 }
351 storage->SetBool(id, kStorageFavorite, favorite_);
mukesh agrawald835b202011-10-07 15:26:47 -0700352 storage->SetString(id, kStorageName, friendly_name_);
Chris Masone34af2182011-08-22 11:59:36 -0700353 if (priority_ != kPriorityNone) {
354 storage->SetInt(id, kStoragePriority, priority_);
355 } else {
356 storage->DeleteKey(id, kStoragePriority);
357 }
Paul Stewart987e71e2011-12-05 09:45:06 -0800358 SaveString(storage, id, kStorageProxyConfig, proxy_config_, false, true);
Chris Masone34af2182011-08-22 11:59:36 -0700359 if (save_credentials_) {
360 storage->DeleteKey(id, kStorageSaveCredentials);
361 } else {
362 storage->SetBool(id, kStorageSaveCredentials, false);
363 }
Paul Stewart987e71e2011-12-05 09:45:06 -0800364 SaveString(storage, id, kStorageUIData, ui_data_, false, true);
Paul Stewart4c561612012-03-21 12:49:01 -0700365 SaveString(storage, id, kStorageGUID, guid_, false, true);
Chris Masone34af2182011-08-22 11:59:36 -0700366
367 SaveEapCredentials(storage, id);
368
369 // TODO(petkov): Save these:
370
371 // "WiFi.HiddenSSID"
372 // "SSID"
373 // "Failure"
374 // "Modified"
375 // "LastAttempt"
376 // WiFiService: "Passphrase"
Chris Masone34af2182011-08-22 11:59:36 -0700377
378 return true;
379}
380
Thieu Led4e9e552012-02-16 16:26:07 -0800381bool Service::SaveToCurrentProfile() {
382 return profile()->UpdateService(this);
383}
384
Paul Stewartcb59fed2012-03-21 21:14:46 -0700385void Service::Configure(const KeyValueStore &args, Error *error) {
386 map<string, bool>::const_iterator bool_it;
387 VLOG(5) << "Configuring bool properties:";
388 for (bool_it = args.bool_properties().begin();
389 bool_it != args.bool_properties().end();
390 ++bool_it) {
391 if (ContainsKey(parameters_ignored_for_configure_, bool_it->first)) {
392 continue;
393 }
394 VLOG(5) << " " << bool_it->first;
395 Error set_error;
396 store_.SetBoolProperty(bool_it->first, bool_it->second, &set_error);
397 if (error->IsSuccess() && set_error.IsFailure()) {
398 error->CopyFrom(set_error);
399 }
400 }
401 VLOG(5) << "Configuring string properties:";
402 map<string, string>::const_iterator string_it;
403 for (string_it = args.string_properties().begin();
404 string_it != args.string_properties().end();
405 ++string_it) {
406 if (ContainsKey(parameters_ignored_for_configure_, string_it->first)) {
407 continue;
408 }
409 VLOG(5) << " " << string_it->first;
410 Error set_error;
411 store_.SetStringProperty(string_it->first, string_it->second, &set_error);
412 if (error->IsSuccess() && set_error.IsFailure()) {
413 error->CopyFrom(set_error);
414 }
415 }
416 VLOG(5) << "Configuring uint32 properties:";
417 map<string, uint32>::const_iterator int_it;
418 for (int_it = args.uint_properties().begin();
419 int_it != args.uint_properties().end();
420 ++int_it) {
421 if (ContainsKey(parameters_ignored_for_configure_, int_it->first)) {
422 continue;
423 }
424 VLOG(5) << " " << int_it->first;
425 Error set_error;
426 store_.SetUint32Property(int_it->first, int_it->second, &set_error);
427 if (error->IsSuccess() && set_error.IsFailure()) {
428 error->CopyFrom(set_error);
429 }
430 }
431}
432
mukesh agrawal00917ce2011-11-22 23:56:55 +0000433void Service::MakeFavorite() {
434 if (favorite_) {
435 // We do not want to clobber the value of auto_connect_ (it may
436 // be user-set). So return early.
437 return;
438 }
439
440 auto_connect_ = true;
441 favorite_ = true;
442}
443
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800444void Service::SetConnection(ConnectionRefPtr connection) {
445 if (connection.get()) {
Paul Stewartc8f4bef2011-12-13 09:45:51 -0800446 http_proxy_.reset(new HTTPProxy(connection));
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800447 http_proxy_->Start(dispatcher_, &sockets_);
448 } else {
449 http_proxy_.reset();
450 }
451 connection_ = connection;
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800452}
453
Gaurav Shah10109f22011-11-11 20:16:22 -0800454bool Service::Is8021xConnectable() const {
455 // We mirror all the flimflam checks (see service.c:is_connectable()).
456
457 // Identity is required.
458 if (eap_.identity.empty()) {
459 VLOG(2) << "Not connectable: Identity is empty.";
460 return false;
461 }
462
463 if (!eap_.client_cert.empty() || !eap_.cert_id.empty()) {
464 // If a client certificate is being used, we must have a private key.
465 if (eap_.private_key.empty() && eap_.key_id.empty()) {
466 VLOG(2) << "Not connectable. Client certificate but no private key.";
467 return false;
468 }
469 }
470 if (!eap_.cert_id.empty() || !eap_.key_id.empty() ||
471 !eap_.ca_cert_id.empty()) {
472 // If PKCS#11 data is needed, a PIN is required.
473 if (eap_.pin.empty()) {
474 VLOG(2) << "Not connectable. PKCS#11 data but no PIN.";
475 return false;
476 }
477 }
478
479 // For EAP-TLS, a client certificate is required.
480 if (eap_.eap.empty() || eap_.eap == "TLS") {
481 if (!eap_.client_cert.empty() || !eap_.cert_id.empty()) {
482 VLOG(2) << "Connectable. EAP-TLS with a client cert.";
483 return true;
484 }
485 }
486
487 // For EAP types other than TLS (e.g. EAP-TTLS or EAP-PEAP, password is the
488 // minimum requirement), at least an identity + password is required.
489 if (eap_.eap.empty() || eap_.eap != "TLS") {
490 if (!eap_.password.empty()) {
491 VLOG(2) << "Connectable. !EAP-TLS and has a password.";
492 return true;
493 }
494 }
495
496 VLOG(2) << "Not connectable. No suitable EAP configuration was found.";
497 return false;
498}
499
500void Service::set_eap(const EapCredentials &eap) {
501 eap_ = eap;
502 // Note: Connectability can only be updated by a subclass of Service
503 // with knowledge of whether the service actually uses 802.1x credentials.
504}
505
mukesh agrawal00917ce2011-11-22 23:56:55 +0000506// static
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800507const char *Service::ConnectFailureToString(const ConnectFailure &state) {
508 switch (state) {
509 case kFailureUnknown:
510 return "Unknown";
511 case kFailureActivationFailure:
512 return "Activation Failure";
513 case kFailureOutOfRange:
514 return "Out of range";
515 case kFailurePinMissing:
516 return "PIN missing";
517 case kFailureConfigurationFailed:
518 return "Configuration Failed";
519 case kFailureBadCredentials:
520 return "Bad Credentials";
521 case kFailureNeedEVDO:
522 return "Need EVDO";
523 case kFailureNeedHomeNetwork:
524 return "Need Home Network";
525 case kFailureOTASPFailure:
526 return "OTASP Failure";
527 case kFailureAAAFailure:
528 return "AAA Failure";
Thieu Le48e6d6d2011-12-06 00:40:27 +0000529 case kFailureMax:
530 return "Max failure error code";
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800531 }
532 return "Invalid";
533}
534
535// static
536const char *Service::ConnectStateToString(const ConnectState &state) {
537 switch (state) {
538 case kStateUnknown:
539 return "Unknown";
540 case kStateIdle:
541 return "Idle";
542 case kStateAssociating:
543 return "Associating";
544 case kStateConfiguring:
545 return "Configuring";
546 case kStateConnected:
547 return "Connected";
548 case kStateDisconnected:
549 return "Disconnected";
Thieu Le48e6d6d2011-12-06 00:40:27 +0000550 case kStatePortal:
551 return "Portal";
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800552 case kStateFailure:
553 return "Failure";
554 case kStateOnline:
555 return "Online";
556 }
557 return "Invalid";
558}
559
Gaurav Shah435de2c2011-11-17 19:01:07 -0800560string Service::GetTechnologyString(Error */*error*/) {
561 return Technology::NameFromIdentifier(technology());
562}
563
Jason Glasgowb5790052012-01-27 01:03:52 -0500564// static
Paul Stewart22aa71b2011-09-16 12:15:11 -0700565bool Service::DecideBetween(int a, int b, bool *decision) {
566 if (a == b)
567 return false;
568 *decision = (a > b);
569 return true;
570}
571
mukesh agrawal00917ce2011-11-22 23:56:55 +0000572// static
Paul Stewart22aa71b2011-09-16 12:15:11 -0700573bool Service::Compare(ServiceRefPtr a,
574 ServiceRefPtr b,
mukesh agrawalddc378f2012-02-17 18:26:20 -0800575 const vector<Technology::Identifier> &tech_order,
576 const char **reason) {
Paul Stewart22aa71b2011-09-16 12:15:11 -0700577 bool ret;
578
579 if (a->state() != b->state()) {
580 if (DecideBetween(a->IsConnected(), b->IsConnected(), &ret)) {
mukesh agrawalddc378f2012-02-17 18:26:20 -0800581 *reason = kServiceSortIsConnected;
Paul Stewart22aa71b2011-09-16 12:15:11 -0700582 return ret;
583 }
584
585 // TODO(pstew): Services don't know about portal state yet
586
587 if (DecideBetween(a->IsConnecting(), b->IsConnecting(), &ret)) {
mukesh agrawalddc378f2012-02-17 18:26:20 -0800588 *reason = kServiceSortIsConnecting;
Paul Stewart22aa71b2011-09-16 12:15:11 -0700589 return ret;
590 }
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000591
592 if (DecideBetween(!a->IsFailed(), !b->IsFailed(), &ret)) {
mukesh agrawalddc378f2012-02-17 18:26:20 -0800593 *reason = kServiceSortIsFailed;
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000594 return ret;
595 }
Paul Stewart22aa71b2011-09-16 12:15:11 -0700596 }
597
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000598 if (DecideBetween(a->connectable(), b->connectable(), &ret) ||
599 DecideBetween(a->auto_connect(), b->auto_connect(), &ret) ||
600 DecideBetween(a->favorite(), b->favorite(), &ret) ||
Paul Stewart22aa71b2011-09-16 12:15:11 -0700601 DecideBetween(a->priority(), b->priority(), &ret)) {
mukesh agrawalddc378f2012-02-17 18:26:20 -0800602 *reason = kServiceSortConnectEtc;
Paul Stewart22aa71b2011-09-16 12:15:11 -0700603 return ret;
604 }
605
606 // TODO(pstew): Below this point we are making value judgements on
607 // services that are not related to anything intrinsic or
608 // user-specified. These heuristics should be richer (contain
609 // historical information, for example) and be subject to user
610 // customization.
611
612 for (vector<Technology::Identifier>::const_iterator it = tech_order.begin();
613 it != tech_order.end();
614 ++it) {
mukesh agrawalddc378f2012-02-17 18:26:20 -0800615 if (DecideBetween(a->TechnologyIs(*it), b->TechnologyIs(*it), &ret)) {
616 *reason = kServiceSortTechnology;
Paul Stewart22aa71b2011-09-16 12:15:11 -0700617 return ret;
mukesh agrawalddc378f2012-02-17 18:26:20 -0800618 }
Paul Stewart22aa71b2011-09-16 12:15:11 -0700619 }
620
Paul Stewart1ca3e852011-11-04 07:50:49 -0700621 if (DecideBetween(a->security_level(), b->security_level(), &ret) ||
Paul Stewart22aa71b2011-09-16 12:15:11 -0700622 DecideBetween(a->strength(), b->strength(), &ret)) {
mukesh agrawalddc378f2012-02-17 18:26:20 -0800623 *reason = kServiceSortSecurityEtc;
Paul Stewart22aa71b2011-09-16 12:15:11 -0700624 return ret;
625 }
626
mukesh agrawalddc378f2012-02-17 18:26:20 -0800627 *reason = kServiceSortUniqueName;
Paul Stewart22aa71b2011-09-16 12:15:11 -0700628 return a->UniqueName() < b->UniqueName();
629}
630
Chris Masone34af2182011-08-22 11:59:36 -0700631const ProfileRefPtr &Service::profile() const { return profile_; }
632
633void Service::set_profile(const ProfileRefPtr &p) { profile_ = p; }
634
mukesh agrawal29c13a12011-11-24 00:09:19 +0000635void Service::set_connectable(bool connectable) {
636 connectable_ = connectable;
637 adaptor_->EmitBoolChanged(flimflam::kConnectableProperty, connectable_);
638}
639
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800640string Service::CalculateState(Error */*error*/) {
mukesh agrawalf2f68a52011-09-01 12:15:48 -0700641 switch (state_) {
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800642 case kStateIdle:
643 return flimflam::kStateIdle;
644 case kStateAssociating:
645 return flimflam::kStateAssociation;
646 case kStateConfiguring:
647 return flimflam::kStateConfiguration;
mukesh agrawalf2f68a52011-09-01 12:15:48 -0700648 case kStateConnected:
Paul Stewart20088d82012-02-16 06:58:55 -0800649 return flimflam::kStateReady;
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800650 case kStateDisconnected:
651 return flimflam::kStateDisconnect;
652 case kStateFailure:
653 return flimflam::kStateFailure;
Paul Stewart20088d82012-02-16 06:58:55 -0800654 case kStatePortal:
655 return flimflam::kStatePortal;
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800656 case kStateOnline:
657 return flimflam::kStateOnline;
658 case kStateUnknown:
mukesh agrawalf2f68a52011-09-01 12:15:48 -0700659 default:
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800660 return "";
mukesh agrawalf2f68a52011-09-01 12:15:48 -0700661 }
662}
663
mukesh agrawalbf14e942012-03-02 14:36:34 -0800664bool Service::IsAutoConnectable(const char **reason) const {
665 if (!connectable()) {
666 *reason = kAutoConnNotConnectable;
667 return false;
668 }
669
670 if (IsConnected()) {
671 *reason = kAutoConnConnected;
672 return false;
673 }
674
675 if (IsConnecting()) {
676 *reason = kAutoConnConnecting;
677 return false;
678 }
679
680 if (explicitly_disconnected_) {
681 *reason = kAutoConnExplicitDisconnect;
682 return false;
683 }
684
685 return true;
mukesh agrawal76d13882012-01-12 15:23:11 -0800686}
687
mukesh agrawalffa3d042011-10-06 15:26:10 -0700688void Service::HelpRegisterDerivedBool(
689 const string &name,
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800690 bool(Service::*get)(Error *),
mukesh agrawalffa3d042011-10-06 15:26:10 -0700691 void(Service::*set)(const bool&, Error *)) {
Chris Masone27c4aa52011-07-02 13:10:14 -0700692 store_.RegisterDerivedBool(
693 name,
694 BoolAccessor(new CustomAccessor<Service, bool>(this, get, set)));
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700695}
696
mukesh agrawalffa3d042011-10-06 15:26:10 -0700697void Service::HelpRegisterDerivedString(
698 const string &name,
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800699 string(Service::*get)(Error *),
mukesh agrawalffa3d042011-10-06 15:26:10 -0700700 void(Service::*set)(const string&, Error *)) {
Chris Masone27c4aa52011-07-02 13:10:14 -0700701 store_.RegisterDerivedString(
702 name,
703 StringAccessor(new CustomAccessor<Service, string>(this, get, set)));
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700704}
705
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400706void Service::HelpRegisterDerivedRpcIdentifier(
707 const string &name,
708 RpcIdentifier(Service::*get)(Error *),
709 void(Service::*set)(const RpcIdentifier&, Error *)) {
710 store_.RegisterDerivedRpcIdentifier(
711 name,
712 RpcIdentifierAccessor(new CustomAccessor<Service, RpcIdentifier>(
713 this, get, set)));
714}
715
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800716void Service::HelpRegisterDerivedUint16(
717 const string &name,
718 uint16(Service::*get)(Error *),
719 void(Service::*set)(const uint16&, Error *)) {
720 store_.RegisterDerivedUint16(
721 name,
722 Uint16Accessor(new CustomAccessor<Service, uint16>(this, get, set)));
723}
724
mukesh agrawal292dc0f2012-01-26 18:02:46 -0800725void Service::HelpRegisterWriteOnlyDerivedString(
726 const string &name,
727 void(Service::*set)(const string &, Error *),
728 void(Service::*clear)(Error *),
729 const string *default_value) {
730 store_.RegisterDerivedString(
731 name,
732 StringAccessor(
733 new CustomWriteOnlyAccessor<Service, string>(
734 this, set, clear, default_value)));
735}
736
Darin Petkovba40dd32011-07-11 20:06:39 -0700737void Service::SaveString(StoreInterface *storage,
Chris Masone34af2182011-08-22 11:59:36 -0700738 const string &id,
Darin Petkovba40dd32011-07-11 20:06:39 -0700739 const string &key,
740 const string &value,
741 bool crypted,
742 bool save) {
743 if (value.empty() || !save) {
Chris Masone34af2182011-08-22 11:59:36 -0700744 storage->DeleteKey(id, key);
Darin Petkovba40dd32011-07-11 20:06:39 -0700745 return;
746 }
747 if (crypted) {
Chris Masone34af2182011-08-22 11:59:36 -0700748 storage->SetCryptedString(id, key, value);
Darin Petkovba40dd32011-07-11 20:06:39 -0700749 return;
750 }
Chris Masone34af2182011-08-22 11:59:36 -0700751 storage->SetString(id, key, value);
Darin Petkovba40dd32011-07-11 20:06:39 -0700752}
753
Chris Masone34af2182011-08-22 11:59:36 -0700754void Service::LoadEapCredentials(StoreInterface *storage, const string &id) {
Gaurav Shah10109f22011-11-11 20:16:22 -0800755 EapCredentials eap;
756 storage->GetCryptedString(id, kStorageEapIdentity, &eap.identity);
757 storage->GetString(id, kStorageEapEap, &eap.eap);
758 storage->GetString(id, kStorageEapInnerEap, &eap.inner_eap);
Darin Petkovba40dd32011-07-11 20:06:39 -0700759 storage->GetCryptedString(id,
760 kStorageEapAnonymousIdentity,
Gaurav Shah10109f22011-11-11 20:16:22 -0800761 &eap.anonymous_identity);
762 storage->GetString(id, kStorageEapClientCert, &eap.client_cert);
763 storage->GetString(id, kStorageEapCertID, &eap.cert_id);
764 storage->GetString(id, kStorageEapPrivateKey, &eap.private_key);
Darin Petkovba40dd32011-07-11 20:06:39 -0700765 storage->GetCryptedString(id,
766 kStorageEapPrivateKeyPassword,
Gaurav Shah10109f22011-11-11 20:16:22 -0800767 &eap.private_key_password);
768 storage->GetString(id, kStorageEapKeyID, &eap.key_id);
769 storage->GetString(id, kStorageEapCACert, &eap.ca_cert);
770 storage->GetString(id, kStorageEapCACertID, &eap.ca_cert_id);
771 storage->GetBool(id, kStorageEapUseSystemCAs, &eap.use_system_cas);
772 storage->GetString(id, kStorageEapPIN, &eap.pin);
773 storage->GetCryptedString(id, kStorageEapPassword, &eap.password);
774 storage->GetString(id, kStorageEapKeyManagement, &eap.key_management);
775 set_eap(eap);
Darin Petkovba40dd32011-07-11 20:06:39 -0700776}
777
Chris Masone34af2182011-08-22 11:59:36 -0700778void Service::SaveEapCredentials(StoreInterface *storage, const string &id) {
Darin Petkovba40dd32011-07-11 20:06:39 -0700779 bool save = save_credentials_;
Chris Masone34af2182011-08-22 11:59:36 -0700780 SaveString(storage, id, kStorageEapIdentity, eap_.identity, true, save);
781 SaveString(storage, id, kStorageEapEap, eap_.eap, false, true);
782 SaveString(storage, id, kStorageEapInnerEap, eap_.inner_eap, false, true);
Darin Petkovba40dd32011-07-11 20:06:39 -0700783 SaveString(storage,
Chris Masone34af2182011-08-22 11:59:36 -0700784 id,
Darin Petkovba40dd32011-07-11 20:06:39 -0700785 kStorageEapAnonymousIdentity,
786 eap_.anonymous_identity,
787 true,
788 save);
Chris Masone34af2182011-08-22 11:59:36 -0700789 SaveString(storage, id, kStorageEapClientCert, eap_.client_cert, false, save);
790 SaveString(storage, id, kStorageEapCertID, eap_.cert_id, false, save);
791 SaveString(storage, id, kStorageEapPrivateKey, eap_.private_key, false, save);
Darin Petkovba40dd32011-07-11 20:06:39 -0700792 SaveString(storage,
Chris Masone34af2182011-08-22 11:59:36 -0700793 id,
Darin Petkovba40dd32011-07-11 20:06:39 -0700794 kStorageEapPrivateKeyPassword,
795 eap_.private_key_password,
796 true,
797 save);
Chris Masone34af2182011-08-22 11:59:36 -0700798 SaveString(storage, id, kStorageEapKeyID, eap_.key_id, false, save);
799 SaveString(storage, id, kStorageEapCACert, eap_.ca_cert, false, true);
800 SaveString(storage, id, kStorageEapCACertID, eap_.ca_cert_id, false, true);
801 storage->SetBool(id, kStorageEapUseSystemCAs, eap_.use_system_cas);
802 SaveString(storage, id, kStorageEapPIN, eap_.pin, false, save);
803 SaveString(storage, id, kStorageEapPassword, eap_.password, true, save);
Darin Petkovba40dd32011-07-11 20:06:39 -0700804 SaveString(storage,
Chris Masone34af2182011-08-22 11:59:36 -0700805 id,
Darin Petkovba40dd32011-07-11 20:06:39 -0700806 kStorageEapKeyManagement,
807 eap_.key_management,
808 false,
809 true);
810}
811
Paul Stewartd8ad3c42012-01-09 12:39:38 -0800812void Service::UnloadEapCredentials() {
813 eap_.identity = "";
814 eap_.eap = "";
815 eap_.inner_eap = "";
816 eap_.anonymous_identity = "";
817 eap_.client_cert = "";
818 eap_.cert_id = "";
819 eap_.private_key = "";
820 eap_.private_key_password = "";
821 eap_.key_id = "";
822 eap_.ca_cert = "";
823 eap_.ca_cert_id = "";
824 eap_.use_system_cas = false;
825 eap_.pin = "";
826 eap_.password = "";
827 eap_.key_management = "";
828}
829
Paul Stewartcb59fed2012-03-21 21:14:46 -0700830void Service::IgnoreParameterForConfigure(const string &parameter) {
831 parameters_ignored_for_configure_.insert(parameter);
832}
833
Paul Stewartac4ac002011-08-26 12:04:26 -0700834const string &Service::GetEAPKeyManagement() const {
835 return eap_.key_management;
836}
837
838void Service::SetEAPKeyManagement(const string &key_management) {
839 eap_.key_management = key_management;
840}
841
Thieu Le284fe792012-01-31 17:53:19 -0800842bool Service::GetAutoConnect(Error */*error*/) {
843 return auto_connect();
844}
845
846void Service::SetAutoConnect(const bool &connect, Error *error) {
847 if (favorite_) {
848 set_auto_connect(connect);
849 } else {
850 error->Populate(Error::kInvalidArguments, "Property is read-only");
851 }
852}
853
Paul Stewart9f32d192012-01-30 20:37:50 -0800854void Service::SetEAPPassword(const string &password, Error */*error*/) {
855 eap_.password = password;
856}
857
858void Service::SetEAPPrivateKeyPassword(const string &password,
859 Error */*error*/) {
860 eap_.private_key_password = password;
861}
862
Paul Stewart1b1a7f22012-01-06 16:24:06 -0800863string Service::GetProfileRpcId(Error *error) {
864 if (!profile_) {
865 // This happens in some unit tests where profile_ is not set.
866 error->Populate(Error::kNotFound);
867 return "";
868 }
869 return profile_->GetRpcIdentifier();
870}
871
872void Service::SetProfileRpcId(const string &profile, Error *error) {
873 manager_->SetProfileForService(this, profile, error);
874}
875
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800876uint16 Service::GetHTTPProxyPort(Error */*error*/) {
877 if (http_proxy_.get()) {
878 return static_cast<uint16>(http_proxy_->proxy_port());
879 }
880 return 0;
881}
882
Darin Petkovd78ee7e2012-01-12 11:21:10 +0100883void Service::SetStrength(uint8 strength) {
884 if (strength == strength_) {
885 return;
886 }
887 strength_ = strength;
888 adaptor_->EmitUint8Changed(flimflam::kSignalStrengthProperty, strength);
889}
890
Paul Stewart75897df2011-04-27 09:05:53 -0700891} // namespace shill