blob: 2acfa07c058e5557ea1ab87bd3bbf3daafa2dc82 [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 Masone9be4a9d2011-05-16 15:44:09 -07005#ifndef SHILL_SERVICE_
6#define SHILL_SERVICE_
Paul Stewart75897df2011-04-27 09:05:53 -07007
mukesh agrawal568b5c62012-02-28 14:44:47 -08008#include <time.h>
9
Chris Masone9be4a9d2011-05-16 15:44:09 -070010#include <string>
Chris Masone8fe2c7e2011-06-09 15:51:19 -070011#include <map>
Paul Stewartcb59fed2012-03-21 21:14:46 -070012#include <set>
Chris Masone8fe2c7e2011-06-09 15:51:19 -070013#include <vector>
Chris Masone9be4a9d2011-05-16 15:44:09 -070014
15#include <base/memory/ref_counted.h>
Paul Stewartba41b992011-05-26 07:02:46 -070016#include <base/memory/scoped_ptr.h>
Darin Petkovba40dd32011-07-11 20:06:39 -070017#include <gtest/gtest_prod.h> // for FRIEND_TEST
Paul Stewart75897df2011-04-27 09:05:53 -070018
Eric Shienbrood9a245532012-03-07 14:20:39 -050019#include "shill/adaptor_interfaces.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070020#include "shill/accessor_interface.h"
Eric Shienbrood9a245532012-03-07 14:20:39 -050021#include "shill/callbacks.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070022#include "shill/property_store.h"
Chris Masone7aa5f902011-07-11 11:13:35 -070023#include "shill/refptr_types.h"
Paul Stewart1062d9d2012-04-27 10:42:27 -070024#include "shill/static_ip_parameters.h"
Paul Stewart22aa71b2011-09-16 12:15:11 -070025#include "shill/technology.h"
Chris Masonec1e50412011-06-07 13:04:53 -070026
Thieu Leb84ba342012-03-02 15:15:19 -080027namespace chromeos_metrics {
28class Timer;
29}
30
Paul Stewart75897df2011-04-27 09:05:53 -070031namespace shill {
32
Paul Stewart75897df2011-04-27 09:05:53 -070033class Configuration;
Chris Masone9be4a9d2011-05-16 15:44:09 -070034class ControlInterface;
Paul Stewart75897df2011-04-27 09:05:53 -070035class Endpoint;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070036class Error;
Chris Masone9be4a9d2011-05-16 15:44:09 -070037class EventDispatcher;
Paul Stewartbe5f5b32011-12-07 17:11:11 -080038class HTTPProxy;
mukesh agrawal7a4e4002011-09-06 11:26:05 -070039class KeyValueStore;
Chris Masone6791a432011-07-12 13:23:19 -070040class Manager;
Thieu Le48e6d6d2011-12-06 00:40:27 +000041class Metrics;
Chris Masone9be4a9d2011-05-16 15:44:09 -070042class ServiceAdaptorInterface;
Darin Petkov5eb05422012-05-11 15:45:25 +020043class Sockets;
Darin Petkovba40dd32011-07-11 20:06:39 -070044class StoreInterface;
Paul Stewart75897df2011-04-27 09:05:53 -070045
Chris Masone7aa5f902011-07-11 11:13:35 -070046// A Service is a uniquely named entity, which the system can
47// connect in order to begin sending and receiving network traffic.
48// All Services are bound to an Entry, which represents the persistable
49// state of the Service. If the Entry is populated at the time of Service
50// creation, that information is used to prime the Service. If not, the Entry
51// becomes populated over time.
Chris Masone27c4aa52011-07-02 13:10:14 -070052class Service : public base::RefCounted<Service> {
Paul Stewart75897df2011-04-27 09:05:53 -070053 public:
Darin Petkovba40dd32011-07-11 20:06:39 -070054 static const char kCheckPortalAuto[];
55 static const char kCheckPortalFalse[];
56 static const char kCheckPortalTrue[];
57
Paul Stewart0756db92012-01-27 08:34:47 -080058 // TODO(pstew): Storage constants shouldn't need to be public
59 // crosbug.com/25813
60 static const char kStorageAutoConnect[];
61 static const char kStorageCheckPortal[];
62 static const char kStorageEapAnonymousIdentity[];
63 static const char kStorageEapCACert[];
64 static const char kStorageEapCACertID[];
Paul Stewartecf4cd12012-04-17 11:08:39 -070065 static const char kStorageEapCACertNSS[];
Paul Stewart0756db92012-01-27 08:34:47 -080066 static const char kStorageEapCertID[];
67 static const char kStorageEapClientCert[];
68 static const char kStorageEapEap[];
69 static const char kStorageEapIdentity[];
70 static const char kStorageEapInnerEap[];
71 static const char kStorageEapKeyID[];
72 static const char kStorageEapKeyManagement[];
73 static const char kStorageEapPIN[];
74 static const char kStorageEapPassword[];
75 static const char kStorageEapPrivateKey[];
76 static const char kStorageEapPrivateKeyPassword[];
77 static const char kStorageEapUseSystemCAs[];
78 static const char kStorageError[];
79 static const char kStorageFavorite[];
80 static const char kStorageGUID[];
81 static const char kStorageName[];
82 static const char kStoragePriority[];
83 static const char kStorageProxyConfig[];
84 static const char kStorageSaveCredentials[];
85 static const char kStorageType[];
86 static const char kStorageUIData[];
87
mukesh agrawal8f3f7752012-02-17 19:42:09 -080088 static const uint8 kStrengthMax;
89 static const uint8 kStrengthMin;
90
Paul Stewart75897df2011-04-27 09:05:53 -070091 enum ConnectFailure {
Paul Stewart03dba0b2011-08-22 16:32:45 -070092 kFailureUnknown,
93 kFailureActivationFailure,
94 kFailureOutOfRange,
95 kFailurePinMissing,
96 kFailureConfigurationFailed,
97 kFailureBadCredentials,
98 kFailureNeedEVDO,
99 kFailureNeedHomeNetwork,
100 kFailureOTASPFailure,
Thieu Le48e6d6d2011-12-06 00:40:27 +0000101 kFailureAAAFailure,
102 kFailureMax
Paul Stewart75897df2011-04-27 09:05:53 -0700103 };
Chris Masone9be4a9d2011-05-16 15:44:09 -0700104 enum ConnectState {
Paul Stewart03dba0b2011-08-22 16:32:45 -0700105 kStateUnknown,
106 kStateIdle,
107 kStateAssociating,
108 kStateConfiguring,
109 kStateConnected,
110 kStateDisconnected,
Thieu Le48e6d6d2011-12-06 00:40:27 +0000111 kStatePortal,
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800112 kStateFailure,
113 kStateOnline
Chris Masone9be4a9d2011-05-16 15:44:09 -0700114 };
Chris Masoneb2e326b2011-07-12 13:28:51 -0700115 struct EapCredentials {
Paul Stewart20550982012-04-16 12:16:11 -0700116 EapCredentials() : use_system_cas(true) {}
Chris Masoneb2e326b2011-07-12 13:28:51 -0700117 std::string identity;
118 std::string eap;
119 std::string inner_eap;
120 std::string anonymous_identity;
121 std::string client_cert;
122 std::string cert_id;
123 std::string private_key;
124 std::string private_key_password;
125 std::string key_id;
126 std::string ca_cert;
127 std::string ca_cert_id;
Paul Stewartecf4cd12012-04-17 11:08:39 -0700128 std::string ca_cert_nss;
Chris Masoneb2e326b2011-07-12 13:28:51 -0700129 bool use_system_cas;
130 std::string pin;
131 std::string password;
132 std::string key_management;
133 };
Chris Masone9be4a9d2011-05-16 15:44:09 -0700134
Paul Stewartac4ac002011-08-26 12:04:26 -0700135 static const int kPriorityNone;
136
Chris Masone9be4a9d2011-05-16 15:44:09 -0700137 // A constructor for the Service object
138 Service(ControlInterface *control_interface,
139 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -0800140 Metrics *metrics,
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700141 Manager *manager,
Gaurav Shah435de2c2011-11-17 19:01:07 -0800142 Technology::Identifier technology);
Darin Petkovba40dd32011-07-11 20:06:39 -0700143
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000144 // AutoConnect MAY choose to ignore the connection request in some
145 // cases. For example, if the corresponding Device only supports one
146 // concurrent connection, and another Service is already connected
147 // or connecting.
148 //
149 // AutoConnect MAY issue RPCs immediately. So AutoConnect MUST NOT
150 // be called from a D-Bus signal handler context.
151 virtual void AutoConnect();
152 // Queue up a connection attempt.
mukesh agrawaladb68482012-01-17 16:31:51 -0800153 virtual void Connect(Error *error);
154 // Disconnect this service. The service will not be eligible for
155 // auto-connect until a subsequent call to Connect, or Load.
156 virtual void Disconnect(Error *error);
Chris Masonea82b7112011-05-25 15:16:29 -0700157
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500158 // The default implementation returns the error kInvalidArguments.
159 virtual void ActivateCellularModem(const std::string &carrier,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500160 Error *error,
161 const ResultCallback &callback);
Darin Petkovc408e692011-08-17 13:47:15 -0700162
Paul Stewart22aa71b2011-09-16 12:15:11 -0700163 // Base method always returns false.
164 virtual bool TechnologyIs(const Technology::Identifier type) const;
165
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800166 virtual bool IsActive(Error *error);
Paul Stewart03dba0b2011-08-22 16:32:45 -0700167
168 virtual ConnectState state() const { return state_; }
169 // Updates the state of the Service and alerts the manager. Also
170 // clears |failure_| if the new state isn't a failure.
171 virtual void SetState(ConnectState state);
172
Paul Stewart22aa71b2011-09-16 12:15:11 -0700173 // State utility functions
Paul Stewart20088d82012-02-16 06:58:55 -0800174 virtual bool IsConnected() const {
175 return state() == kStateConnected || state() == kStatePortal ||
176 state() == kStateOnline;
177 }
Gaurav Shah435de2c2011-11-17 19:01:07 -0800178 virtual bool IsConnecting() const {
Paul Stewart22aa71b2011-09-16 12:15:11 -0700179 return state() == kStateAssociating || state() == kStateConfiguring;
180 }
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000181 virtual bool IsFailed() const {
mukesh agrawal568b5c62012-02-28 14:44:47 -0800182 // We sometimes lie about the failure state, to keep Chrome happy
183 // (see comment in WiFi::HandleDisconnect). Hence, we check both
184 // state and |failed_time_|.
185 return state() == kStateFailure || failed_time_ > 0;
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000186 }
Paul Stewart22aa71b2011-09-16 12:15:11 -0700187
Paul Stewart03dba0b2011-08-22 16:32:45 -0700188 virtual ConnectFailure failure() const { return failure_; }
mukesh agrawal568b5c62012-02-28 14:44:47 -0800189 // Records the failure mode and time. Sets the Service state to "Failure".
Paul Stewart03dba0b2011-08-22 16:32:45 -0700190 virtual void SetFailure(ConnectFailure failure);
mukesh agrawal568b5c62012-02-28 14:44:47 -0800191 // Records the failure mode and time. Sets the Service state to "Idle".
192 // Avoids showing a failure mole in the UI.
193 virtual void SetFailureSilent(ConnectFailure failure);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700194
Darin Petkovba40dd32011-07-11 20:06:39 -0700195 // Returns a string that is guaranteed to uniquely identify this Service
196 // instance.
mukesh agrawald835b202011-10-07 15:26:47 -0700197 const std::string &UniqueName() const { return unique_name_; }
Darin Petkovafa6fc42011-06-21 16:21:08 -0700198
Chris Masone6791a432011-07-12 13:23:19 -0700199 virtual std::string GetRpcIdentifier() const;
Chris Masone3c3f6a12011-07-01 10:01:41 -0700200
Darin Petkovba40dd32011-07-11 20:06:39 -0700201 // Returns the unique persistent storage identifier for the service.
Chris Masone6515aab2011-10-12 16:19:09 -0700202 virtual std::string GetStorageIdentifier() const = 0;
Darin Petkovba40dd32011-07-11 20:06:39 -0700203
Paul Stewartbba6a5b2011-11-02 18:45:59 -0700204 // Returns whether the service configuration can be loaded from |storage|.
205 virtual bool IsLoadableFrom(StoreInterface *storage) const;
206
Paul Stewart81426132012-05-16 10:05:10 -0700207 // Returns true if the service uses 802.1x for key management.
208 virtual bool Is8021x() const { return false; };
209
Darin Petkovba40dd32011-07-11 20:06:39 -0700210 // Loads the service from persistent |storage|. Returns true on success.
Chris Masone9d779932011-08-25 16:33:41 -0700211 virtual bool Load(StoreInterface *storage);
Darin Petkovba40dd32011-07-11 20:06:39 -0700212
Paul Stewarta41e38d2011-11-11 07:47:29 -0800213 // Indicate to service that it is no longer persisted to storage. It
Paul Stewart65512e12012-03-26 18:01:08 -0700214 // should purge any stored profile state (e.g., credentials). Returns
215 // true to indicate that this service should also be unregistered from
216 // the manager, false otherwise.
217 virtual bool Unload();
Paul Stewarta41e38d2011-11-11 07:47:29 -0800218
Darin Petkovba40dd32011-07-11 20:06:39 -0700219 // Saves the service to persistent |storage|. Returns true on success.
Chris Masone9d779932011-08-25 16:33:41 -0700220 virtual bool Save(StoreInterface *storage);
Darin Petkovba40dd32011-07-11 20:06:39 -0700221
Thieu Led4e9e552012-02-16 16:26:07 -0800222 // Saves the service to the current profile.
Gary Moraind93615e2012-04-27 11:50:03 -0700223 virtual void SaveToCurrentProfile();
Thieu Led4e9e552012-02-16 16:26:07 -0800224
Paul Stewartcb59fed2012-03-21 21:14:46 -0700225 // Applies all the properties in |args| to this service object's mutable
226 // store, except for those in parameters_ignored_for_configure_.
227 // Returns an error in |error| if one or more parameter set attempts
228 // fails, but will only return the first error.
229 virtual void Configure(const KeyValueStore &args, Error *error);
230
Paul Stewartd215af62012-04-24 23:25:50 -0700231 // Returns whether portal detection is explicitly disabled on this service
232 // via a property set on it.
233 virtual bool IsPortalDetectionDisabled() const;
234
235 // Returns whether portal detection is set to follow the default setting
236 // of this service's technology via a property set on it.
237 virtual bool IsPortalDetectionAuto() const;
238
Paul Stewart10ccbb32012-04-26 15:59:30 -0700239 // Returns true if the service is persisted to a non-ephemeral profile.
240 virtual bool IsRemembered() const;
241
Paul Stewarta41e38d2011-11-11 07:47:29 -0800242 // Returns true if the service RPC identifier should be part of the
243 // manager's advertised services list, false otherwise.
244 virtual bool IsVisible() const { return true; }
245
Paul Stewart20088d82012-02-16 06:58:55 -0800246 // Returns true if there is a proxy configuration set on this service.
247 virtual bool HasProxyConfig() const { return !proxy_config_.empty(); }
248
mukesh agrawal00917ce2011-11-22 23:56:55 +0000249 virtual void MakeFavorite();
250
Darin Petkov5eb05422012-05-11 15:45:25 +0200251 // Set the connection for this service. If the connection is non-NULL, create
252 // an HTTP Proxy that will utilize this service's connection to serve
253 // requests.
254 virtual void SetConnection(const ConnectionRefPtr &connection);
255 virtual const ConnectionRefPtr &connection() const { return connection_; }
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800256
Gaurav Shah10109f22011-11-11 20:16:22 -0800257 // Examines the EAP credentials for the service and returns true if a
258 // connection attempt can be made.
259 bool Is8021xConnectable() const;
260
Thieu Le48e6d6d2011-12-06 00:40:27 +0000261 // The inherited class should register any custom metrics in this method.
262 virtual void InitializeCustomMetrics() const {}
263
264 // The inherited class that needs to send metrics after the service has
Thieu Leb84ba342012-03-02 15:15:19 -0800265 // transitioned to the ready state should override this method.
266 // |time_resume_to_ready_milliseconds| holds the elapsed time from when
267 // the system was resumed until when the service transitioned to the
268 // connected state. This value is non-zero for the first service transition
269 // to the connected state after a resume.
270 virtual void SendPostReadyStateMetrics(
271 int64 /*time_resume_to_ready_milliseconds*/) const {}
Thieu Le48e6d6d2011-12-06 00:40:27 +0000272
Darin Petkovafa6fc42011-06-21 16:21:08 -0700273 bool auto_connect() const { return auto_connect_; }
274 void set_auto_connect(bool connect) { auto_connect_ = connect; }
Paul Stewart75897df2011-04-27 09:05:53 -0700275
Gaurav Shah435de2c2011-11-17 19:01:07 -0800276 bool connectable() const { return connectable_; }
mukesh agrawal29c13a12011-11-24 00:09:19 +0000277 void set_connectable(bool connectable);
Gaurav Shah435de2c2011-11-17 19:01:07 -0800278
Thieu Le67370f62012-02-14 23:01:42 +0000279 virtual bool explicitly_disconnected() const {
280 return explicitly_disconnected_;
281 }
282
Paul Stewart22aa71b2011-09-16 12:15:11 -0700283 bool favorite() const { return favorite_; }
mukesh agrawal00917ce2011-11-22 23:56:55 +0000284 // Setter is deliberately omitted; use MakeFavorite.
Paul Stewart22aa71b2011-09-16 12:15:11 -0700285
mukesh agrawal15908392011-11-16 18:29:25 +0000286 const std::string &friendly_name() const { return friendly_name_; }
Darin Petkov7f060332012-03-14 11:46:47 +0100287 void set_friendly_name(const std::string &n) { friendly_name_ = n; }
mukesh agrawal15908392011-11-16 18:29:25 +0000288
Paul Stewart4c561612012-03-21 12:49:01 -0700289 const std::string &guid() const { return guid_; }
290 void set_guid(const std::string &guid) { guid_ = guid; }
291
Paul Stewart22aa71b2011-09-16 12:15:11 -0700292 int32 priority() const { return priority_; }
293 void set_priority(int32 priority) { priority_ = priority; }
294
Paul Stewart1ca3e852011-11-04 07:50:49 -0700295 int32 security_level() const { return security_level_; }
296 void set_security_level(int32 security) { security_level_ = security; }
Paul Stewart22aa71b2011-09-16 12:15:11 -0700297
Darin Petkovd78ee7e2012-01-12 11:21:10 +0100298 void SetStrength(uint8 strength);
mukesh agrawale1d90e92012-02-15 17:36:08 -0800299
300 // uint8 streams out as a char. Coerce to a larger type, so that
301 // it prints as a number.
302 uint16 strength() const { return strength_; }
Paul Stewart22aa71b2011-09-16 12:15:11 -0700303
Gaurav Shah435de2c2011-11-17 19:01:07 -0800304 virtual Technology::Identifier technology() const { return technology_; }
305 std::string GetTechnologyString(Error *error);
306
Gaurav Shah10109f22011-11-11 20:16:22 -0800307 const EapCredentials &eap() const { return eap_; }
308 virtual void set_eap(const EapCredentials &eap);
309
Darin Petkovcb715292012-04-25 13:04:37 +0200310 bool save_credentials() const { return save_credentials_; }
311 void set_save_credentials(bool save) { save_credentials_ = save; }
312
Darin Petkov51489002011-08-18 13:13:20 -0700313 const std::string &error() const { return error_; }
314 void set_error(const std::string &error) { error_ = error; }
315
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800316 static const char *ConnectFailureToString(const ConnectFailure &state);
317 static const char *ConnectStateToString(const ConnectState &state);
318
Paul Stewart22aa71b2011-09-16 12:15:11 -0700319 // Compare two services. Returns true if Service a should be displayed
320 // above Service b
321 static bool Compare(ServiceRefPtr a,
322 ServiceRefPtr b,
mukesh agrawalddc378f2012-02-17 18:26:20 -0800323 const std::vector<Technology::Identifier> &tech_order,
324 const char **reason);
Paul Stewart22aa71b2011-09-16 12:15:11 -0700325
Chris Masone34af2182011-08-22 11:59:36 -0700326 // These are defined in service.cc so that we don't have to include profile.h
Chris Masone9d779932011-08-25 16:33:41 -0700327 // TODO(cmasone): right now, these are here only so that we can get the
328 // profile name as a property. Can we store just the name, and then handle
329 // setting the profile for this service via |manager_|?
Chris Masone6791a432011-07-12 13:23:19 -0700330 const ProfileRefPtr &profile() const;
331 void set_profile(const ProfileRefPtr &p);
332
Paul Stewart4357f4e2012-04-26 17:39:26 -0700333 // Notification that occurs when a service now has profile data saved
334 // on its behalf. Some service types like WiFi can choose to register
335 // themselves at this point.
336 virtual void OnProfileConfigured() {}
337
Paul Stewartff14b022012-04-24 20:06:23 -0700338 // Notification that occurs when a single property has been changed via
339 // the RPC adaptor.
Paul Stewart81426132012-05-16 10:05:10 -0700340 virtual void OnPropertyChanged(const std::string &property);
Paul Stewartff14b022012-04-24 20:06:23 -0700341
mukesh agrawalde29fa82011-09-16 16:16:36 -0700342 PropertyStore *mutable_store() { return &store_; }
343 const PropertyStore &store() const { return store_; }
Paul Stewart1062d9d2012-04-27 10:42:27 -0700344 const StaticIPParameters &static_ip_parameters() const {
345 return static_ip_parameters_;
346 }
Chris Masone27c4aa52011-07-02 13:10:14 -0700347
mukesh agrawalb54601c2011-06-07 17:39:22 -0700348 protected:
Darin Petkov5eb05422012-05-11 15:45:25 +0200349 friend class base::RefCounted<Service>;
350
351 virtual ~Service();
352
Chris Masone34af2182011-08-22 11:59:36 -0700353 // Returns true if a character is allowed to be in a service storage id.
354 static bool LegalChar(char a) { return isalnum(a) || a == '_'; }
355
Darin Petkov31332412012-01-28 01:50:02 +0100356 // Returns true if a character is disallowed to be in a service storage id.
357 static bool IllegalChar(char a) { return !LegalChar(a); }
358
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800359 virtual std::string CalculateState(Error *error);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700360
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000361 // Returns whether this service is in a state conducive to auto-connect.
362 // This should include any tests used for computing connectable(),
363 // as well as other critera such as whether the device associated with
364 // this service is busy with another connection.
mukesh agrawalbf14e942012-03-02 14:36:34 -0800365 //
366 // If the service is not auto-connectable, |*reason| will be set to
367 // point to C-string explaining why the service is not auto-connectable.
368 virtual bool IsAutoConnectable(const char **reason) const;
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000369
mukesh agrawal292dc0f2012-01-26 18:02:46 -0800370 // HelpRegisterDerived*: Expose a property over RPC, with the name |name|.
371 //
372 // Reads of the property will be handled by invoking |get|.
373 // Writes to the property will be handled by invoking |set|.
374 // Clearing the property will be handled by PropertyStore.
mukesh agrawalffa3d042011-10-06 15:26:10 -0700375 void HelpRegisterDerivedBool(
376 const std::string &name,
Hristo Stefanoved2c28c2011-11-29 15:37:30 -0800377 bool(Service::*get)(Error *error),
378 void(Service::*set)(const bool &value, Error *error));
mukesh agrawalffa3d042011-10-06 15:26:10 -0700379 void HelpRegisterDerivedString(
380 const std::string &name,
Hristo Stefanoved2c28c2011-11-29 15:37:30 -0800381 std::string(Service::*get)(Error *error),
382 void(Service::*set)(const std::string &value, Error *error));
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800383 void HelpRegisterDerivedUint16(
384 const std::string &name,
385 uint16(Service::*get)(Error *error),
386 void(Service::*set)(const uint16 &value, Error *error));
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400387 void HelpRegisterDerivedRpcIdentifier(
388 const std::string &name,
389 std::string(Service::*get)(Error *),
390 void(Service::*set)(const RpcIdentifier&, Error *));
mukesh agrawal292dc0f2012-01-26 18:02:46 -0800391 // Expose a property over RPC, with the name |name|.
392 //
393 // Reads of the property will be handled by invoking |get|.
394 // Writes to the property will be handled by invoking |set|.
395 //
396 // Clearing the property will be handled by invoking |clear|, or
397 // calling |set| with |default_value| (whichever is non-NULL). It
398 // is an error to call this method with both |clear| and
399 // |default_value| non-NULL.
400 void HelpRegisterWriteOnlyDerivedString(
401 const std::string &name,
402 void(Service::*set)(const std::string &value, Error *error),
403 void(Service::*clear)(Error *error),
404 const std::string *default_value);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700405
Darin Petkovb72cf402011-11-22 14:51:39 +0100406 ServiceAdaptorInterface *adaptor() const { return adaptor_.get(); }
407
Darin Petkovba40dd32011-07-11 20:06:39 -0700408 // Assigns |value| to |key| in |storage| if |value| is non-empty and |save| is
409 // true. Otherwise, removes |key| from |storage|. If |crypted| is true, the
410 // value is encrypted.
411 void SaveString(StoreInterface *storage,
Chris Masone34af2182011-08-22 11:59:36 -0700412 const std::string &id,
Darin Petkovba40dd32011-07-11 20:06:39 -0700413 const std::string &key,
414 const std::string &value,
415 bool crypted,
416 bool save);
417
Chris Masone34af2182011-08-22 11:59:36 -0700418 void LoadEapCredentials(StoreInterface *storage, const std::string &id);
419 void SaveEapCredentials(StoreInterface *storage, const std::string &id);
Paul Stewartd8ad3c42012-01-09 12:39:38 -0800420 void UnloadEapCredentials();
Darin Petkovba40dd32011-07-11 20:06:39 -0700421
Paul Stewartcb59fed2012-03-21 21:14:46 -0700422 // Ignore |parameter| when performing a Configure() operation.
423 void IgnoreParameterForConfigure(const std::string &parameter);
424
Paul Stewartac4ac002011-08-26 12:04:26 -0700425 // Property accessors reserved for subclasses
426 EventDispatcher *dispatcher() const { return dispatcher_; }
427 const std::string &GetEAPKeyManagement() const;
428 void SetEAPKeyManagement(const std::string &key_management);
Paul Stewart9f32d192012-01-30 20:37:50 -0800429 void SetEAPPassword(const std::string &password, Error *error);
430 void SetEAPPrivateKeyPassword(const std::string &password, Error *error);
Paul Stewart65512e12012-03-26 18:01:08 -0700431 Manager *manager() const { return manager_; }
Thieu Le48e6d6d2011-12-06 00:40:27 +0000432 Metrics *metrics() const { return metrics_; }
mukesh agrawalb54601c2011-06-07 17:39:22 -0700433
Darin Petkov1d0080a2012-04-30 17:10:36 +0200434 void set_favorite(bool favorite) { favorite_ = favorite; }
435
Paul Stewart75897df2011-04-27 09:05:53 -0700436 private:
Thieu Le48e6d6d2011-12-06 00:40:27 +0000437 friend class MetricsTest;
Paul Stewart0756db92012-01-27 08:34:47 -0800438 friend class ServiceAdaptorInterface;
Darin Petkov5eb05422012-05-11 15:45:25 +0200439 friend class VPNServiceTest;
mukesh agrawale1d90e92012-02-15 17:36:08 -0800440 friend class WiFiServiceTest;
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700441 FRIEND_TEST(DeviceTest, IPConfigUpdatedFailureWithStatic);
Paul Stewartcb59fed2012-03-21 21:14:46 -0700442 FRIEND_TEST(ServiceTest, ConfigureIgnoredProperty);
443 FRIEND_TEST(ServiceTest, ConfigureStringProperty);
Darin Petkovba40dd32011-07-11 20:06:39 -0700444 FRIEND_TEST(ServiceTest, Constructor);
Paul Stewart10241e32012-04-23 18:15:06 -0700445 FRIEND_TEST(ServiceTest, GetIPConfigRpcIdentifier);
Thieu Le284fe792012-01-31 17:53:19 -0800446 FRIEND_TEST(ServiceTest, GetProperties);
mukesh agrawal76d13882012-01-12 15:23:11 -0800447 FRIEND_TEST(ServiceTest, IsAutoConnectable);
Paul Stewartd215af62012-04-24 23:25:50 -0700448 FRIEND_TEST(ServiceTest, RecheckPortal);
Darin Petkovba40dd32011-07-11 20:06:39 -0700449 FRIEND_TEST(ServiceTest, Save);
450 FRIEND_TEST(ServiceTest, SaveString);
451 FRIEND_TEST(ServiceTest, SaveStringCrypted);
452 FRIEND_TEST(ServiceTest, SaveStringDontSave);
453 FRIEND_TEST(ServiceTest, SaveStringEmpty);
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -0800454 FRIEND_TEST(ServiceTest, SetProperty);
Paul Stewartd215af62012-04-24 23:25:50 -0700455 FRIEND_TEST(ServiceTest, SetCheckPortal);
mukesh agrawal568b5c62012-02-28 14:44:47 -0800456 FRIEND_TEST(ServiceTest, State);
Paul Stewartd8ad3c42012-01-09 12:39:38 -0800457 FRIEND_TEST(ServiceTest, Unload);
Darin Petkovba40dd32011-07-11 20:06:39 -0700458
mukesh agrawalbf14e942012-03-02 14:36:34 -0800459 static const char kAutoConnConnected[];
460 static const char kAutoConnConnecting[];
461 static const char kAutoConnExplicitDisconnect[];
462 static const char kAutoConnNotConnectable[];
463
Darin Petkov2f903b32012-04-18 12:56:43 +0200464 static const char kServiceSortAutoConnect[];
465 static const char kServiceSortConnectable[];
466 static const char kServiceSortFavorite[];
mukesh agrawalddc378f2012-02-17 18:26:20 -0800467 static const char kServiceSortIsConnected[];
468 static const char kServiceSortIsConnecting[];
469 static const char kServiceSortIsFailed[];
Darin Petkov2f903b32012-04-18 12:56:43 +0200470 static const char kServiceSortPriority[];
mukesh agrawalddc378f2012-02-17 18:26:20 -0800471 static const char kServiceSortSecurityEtc[];
Darin Petkov2f903b32012-04-18 12:56:43 +0200472 static const char kServiceSortTechnology[];
mukesh agrawalddc378f2012-02-17 18:26:20 -0800473 static const char kServiceSortUniqueName[];
474
Thieu Le284fe792012-01-31 17:53:19 -0800475 bool GetAutoConnect(Error *error);
476 void SetAutoConnect(const bool &connect, Error *error);
477
Paul Stewartd215af62012-04-24 23:25:50 -0700478 std::string GetCheckPortal(Error *error);
479 void SetCheckPortal(const std::string &check_portal, Error *error);
480
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800481 virtual std::string GetDeviceRpcId(Error *error) = 0;
Chris Masone95207da2011-06-29 16:50:49 -0700482
Paul Stewart10241e32012-04-23 18:15:06 -0700483 std::string GetIPConfigRpcIdentifier(Error *error);
484
Paul Stewart0c438332012-04-11 07:55:27 -0700485 std::string GetNameProperty(Error *error);
486 void AssertTrivialSetNameProperty(const std::string &name, Error *error);
487
Paul Stewart1b1a7f22012-01-06 16:24:06 -0800488 std::string GetProfileRpcId(Error *error);
489 void SetProfileRpcId(const std::string &profile, Error *error);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700490
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800491 // Returns TCP port of service's HTTP proxy in host order.
492 uint16 GetHTTPProxyPort(Error *error);
493
Paul Stewart22aa71b2011-09-16 12:15:11 -0700494 // Utility function that returns true if a is different from b. When they
495 // are, "decision" is populated with the boolean value of "a > b".
496 static bool DecideBetween(int a, int b, bool *decision);
497
Paul Stewartac4ac002011-08-26 12:04:26 -0700498 ConnectState state_;
499 ConnectFailure failure_;
500 bool auto_connect_;
501 std::string check_portal_;
502 bool connectable_;
503 std::string error_;
mukesh agrawaladb68482012-01-17 16:31:51 -0800504 bool explicitly_disconnected_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700505 bool favorite_;
506 int32 priority_;
Paul Stewart1ca3e852011-11-04 07:50:49 -0700507 int32 security_level_;
Darin Petkovd78ee7e2012-01-12 11:21:10 +0100508 uint8 strength_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700509 std::string proxy_config_;
Paul Stewart987e71e2011-12-05 09:45:06 -0800510 std::string ui_data_;
Paul Stewart4c561612012-03-21 12:49:01 -0700511 std::string guid_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700512 bool save_credentials_;
513 EapCredentials eap_; // Only saved if |save_credentials_| is true.
Gaurav Shah435de2c2011-11-17 19:01:07 -0800514 Technology::Identifier technology_;
mukesh agrawal568b5c62012-02-28 14:44:47 -0800515 // The time of the most recent failure. Value is 0 if the service is
516 // not currently failed.
517 time_t failed_time_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700518
519 ProfileRefPtr profile_;
520 PropertyStore store_;
Paul Stewartcb59fed2012-03-21 21:14:46 -0700521 std::set<std::string> parameters_ignored_for_configure_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700522
523 EventDispatcher *dispatcher_;
mukesh agrawal51a7e932011-07-27 16:18:26 -0700524 static unsigned int serial_number_;
mukesh agrawald835b202011-10-07 15:26:47 -0700525 std::string unique_name_; // MUST be unique amongst service instances
526 std::string friendly_name_; // MAY be same as |unique_name_|
Paul Stewart75897df2011-04-27 09:05:53 -0700527 bool available_;
528 bool configured_;
Paul Stewart75897df2011-04-27 09:05:53 -0700529 Configuration *configuration_;
Paul Stewartba41b992011-05-26 07:02:46 -0700530 scoped_ptr<ServiceAdaptorInterface> adaptor_;
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800531 scoped_ptr<HTTPProxy> http_proxy_;
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800532 ConnectionRefPtr connection_;
Paul Stewart1062d9d2012-04-27 10:42:27 -0700533 StaticIPParameters static_ip_parameters_;
Thieu Le3426c8f2012-01-11 17:35:11 -0800534 Metrics *metrics_;
Chris Masone6791a432011-07-12 13:23:19 -0700535 Manager *manager_;
Darin Petkov5eb05422012-05-11 15:45:25 +0200536 scoped_ptr<Sockets> sockets_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700537
mukesh agrawalb54601c2011-06-07 17:39:22 -0700538 DISALLOW_COPY_AND_ASSIGN(Service);
Paul Stewart75897df2011-04-27 09:05:53 -0700539};
540
541} // namespace shill
542
543#endif // SHILL_SERVICE_