blob: 399f72f397066faeb75322bba7442043fafb52fc [file] [log] [blame]
Arman Uguray2717a102013-01-29 23:36:06 -08001// Copyright (c) 2013 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
Ben Chan19f83972012-10-03 23:25:56 -07005#ifndef SHILL_SERVICE_H_
6#define SHILL_SERVICE_H_
Paul Stewart75897df2011-04-27 09:05:53 -07007
mukesh agrawal568b5c62012-02-28 14:44:47 -08008#include <time.h>
9
Chris Masone8fe2c7e2011-06-09 15:51:19 -070010#include <map>
Ben Chancd477322014-10-17 14:19:30 -070011#include <memory>
Paul Stewartcb59fed2012-03-21 21:14:46 -070012#include <set>
Darin Petkov385b9bc2012-12-03 15:25:05 +010013#include <string>
Chris Masone8fe2c7e2011-06-09 15:51:19 -070014#include <vector>
Chris Masone9be4a9d2011-05-16 15:44:09 -070015
Christopher Wiley0801d192012-09-24 11:57:15 -070016#include <base/cancelable_callback.h>
Chris Masone9be4a9d2011-05-16 15:44:09 -070017#include <base/memory/ref_counted.h>
Christopher Wiley0801d192012-09-24 11:57:15 -070018#include <base/memory/weak_ptr.h>
Darin Petkovba40dd32011-07-11 20:06:39 -070019#include <gtest/gtest_prod.h> // for FRIEND_TEST
Paul Stewart75897df2011-04-27 09:05:53 -070020
Chris Masone3bd3c8c2011-06-13 08:20:26 -070021#include "shill/accessor_interface.h"
Alex Vakulenkoa41ab512014-07-23 14:24:23 -070022#include "shill/adaptor_interfaces.h"
Eric Shienbrood9a245532012-03-07 14:20:39 -050023#include "shill/callbacks.h"
Samuel Tan07dfabc2015-01-20 15:10:39 -080024#include "shill/net/event_history.h"
Peter Qiu8d6b5972014-10-28 15:33:34 -070025#include "shill/net/shill_time.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070026#include "shill/property_store.h"
Chris Masone7aa5f902011-07-11 11:13:35 -070027#include "shill/refptr_types.h"
Paul Stewart1062d9d2012-04-27 10:42:27 -070028#include "shill/static_ip_parameters.h"
Paul Stewart22aa71b2011-09-16 12:15:11 -070029#include "shill/technology.h"
Chris Masonec1e50412011-06-07 13:04:53 -070030
Thieu Leb84ba342012-03-02 15:15:19 -080031namespace chromeos_metrics {
32class Timer;
33}
34
Paul Stewart75897df2011-04-27 09:05:53 -070035namespace shill {
36
Chris Masone9be4a9d2011-05-16 15:44:09 -070037class ControlInterface;
Darin Petkov385b9bc2012-12-03 15:25:05 +010038class DiagnosticsReporter;
Paul Stewart75897df2011-04-27 09:05:53 -070039class Endpoint;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070040class Error;
Chris Masone9be4a9d2011-05-16 15:44:09 -070041class EventDispatcher;
Paul Stewartbe5f5b32011-12-07 17:11:11 -080042class HTTPProxy;
mukesh agrawal7a4e4002011-09-06 11:26:05 -070043class KeyValueStore;
Chris Masone6791a432011-07-12 13:23:19 -070044class Manager;
Thieu Le48e6d6d2011-12-06 00:40:27 +000045class Metrics;
mukesh agrawalbebf1b82013-04-23 15:06:33 -070046class MockManager;
Chris Masone9be4a9d2011-05-16 15:44:09 -070047class ServiceAdaptorInterface;
mukesh agrawalcbfb34e2013-04-17 19:33:25 -070048class ServiceMockAdaptor;
Paul Stewart45170bc2014-06-02 15:49:34 -070049class ServicePropertyChangeNotifier;
Darin Petkov5eb05422012-05-11 15:45:25 +020050class Sockets;
Darin Petkovba40dd32011-07-11 20:06:39 -070051class StoreInterface;
Paul Stewart75897df2011-04-27 09:05:53 -070052
Peter Qiu1a72f542015-04-14 16:31:36 -070053#if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X)
54class EapCredentials;
55#endif // DISABLE_WIFI || DISABLE_WIRED_8021X
56
Chris Masone7aa5f902011-07-11 11:13:35 -070057// A Service is a uniquely named entity, which the system can
58// connect in order to begin sending and receiving network traffic.
59// All Services are bound to an Entry, which represents the persistable
60// state of the Service. If the Entry is populated at the time of Service
61// creation, that information is used to prime the Service. If not, the Entry
62// becomes populated over time.
Chris Masone27c4aa52011-07-02 13:10:14 -070063class Service : public base::RefCounted<Service> {
Paul Stewart75897df2011-04-27 09:05:53 -070064 public:
Darin Petkovba40dd32011-07-11 20:06:39 -070065 static const char kCheckPortalAuto[];
66 static const char kCheckPortalFalse[];
67 static const char kCheckPortalTrue[];
68
Darin Petkovaba89322013-03-11 14:48:22 +010069 static const char kErrorDetailsNone[];
70
Paul Stewart0756db92012-01-27 08:34:47 -080071 // TODO(pstew): Storage constants shouldn't need to be public
Paul Stewartee6b3d72013-07-12 16:07:51 -070072 // crbug.com/208736
Paul Stewart0756db92012-01-27 08:34:47 -080073 static const char kStorageAutoConnect[];
74 static const char kStorageCheckPortal[];
Peter Qiua89154b2014-05-23 15:45:42 -070075 static const char kStorageDNSAutoFallback[];
Paul Stewart0756db92012-01-27 08:34:47 -080076 static const char kStorageError[];
77 static const char kStorageFavorite[];
78 static const char kStorageGUID[];
mukesh agrawalcf24a242012-05-21 16:46:11 -070079 static const char kStorageHasEverConnected[];
Paul Stewart0756db92012-01-27 08:34:47 -080080 static const char kStorageName[];
81 static const char kStoragePriority[];
Paul Stewartd9c7cfc2015-01-06 14:26:22 -080082 static const char kStoragePriorityWithinTechnology[];
Paul Stewart0756db92012-01-27 08:34:47 -080083 static const char kStorageProxyConfig[];
84 static const char kStorageSaveCredentials[];
85 static const char kStorageType[];
86 static const char kStorageUIData[];
Peter Qiu9d581932014-04-14 16:37:37 -070087 static const char kStorageConnectionId[];
Peter Qiud49760e2014-09-19 16:13:42 -070088 static const char kStorageLinkMonitorDisabled[];
Paul Stewart3fee7e32014-10-15 21:39:29 -070089 static const char kStorageManagedCredentials[];
Paul Stewart0756db92012-01-27 08:34:47 -080090
Ben Chan7fab8972014-08-10 17:14:46 -070091 static const uint8_t kStrengthMax;
92 static const uint8_t kStrengthMin;
mukesh agrawal8f3f7752012-02-17 19:42:09 -080093
Paul Stewart75897df2011-04-27 09:05:53 -070094 enum ConnectFailure {
Paul Stewart03dba0b2011-08-22 16:32:45 -070095 kFailureUnknown,
Paul Stewartf2d60912012-07-15 08:37:30 -070096 kFailureAAA,
Darin Petkov1c049c72013-03-21 13:15:45 +010097 kFailureActivation,
98 kFailureBadPassphrase,
Paul Stewartf2d60912012-07-15 08:37:30 -070099 kFailureBadWEPKey,
100 kFailureConnect,
Darin Petkov1c049c72013-03-21 13:15:45 +0100101 kFailureDHCP,
Paul Stewartf2d60912012-07-15 08:37:30 -0700102 kFailureDNSLookup,
Paul Stewartdb0f9172012-11-30 16:48:09 -0800103 kFailureEAPAuthentication,
104 kFailureEAPLocalTLS,
105 kFailureEAPRemoteTLS,
Darin Petkov1c049c72013-03-21 13:15:45 +0100106 kFailureHTTPGet,
107 kFailureIPSecCertAuth,
108 kFailureIPSecPSKAuth,
109 kFailureInternal,
110 kFailureNeedEVDO,
111 kFailureNeedHomeNetwork,
112 kFailureOTASP,
113 kFailureOutOfRange,
114 kFailurePPPAuth,
115 kFailurePinMissing,
Thieu Le48e6d6d2011-12-06 00:40:27 +0000116 kFailureMax
Paul Stewart75897df2011-04-27 09:05:53 -0700117 };
Chris Masone9be4a9d2011-05-16 15:44:09 -0700118 enum ConnectState {
Paul Stewart03dba0b2011-08-22 16:32:45 -0700119 kStateUnknown,
120 kStateIdle,
121 kStateAssociating,
122 kStateConfiguring,
123 kStateConnected,
Thieu Le48e6d6d2011-12-06 00:40:27 +0000124 kStatePortal,
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800125 kStateFailure,
126 kStateOnline
Chris Masone9be4a9d2011-05-16 15:44:09 -0700127 };
mukesh agrawal43970a22013-02-15 16:00:07 -0800128 enum CryptoAlgorithm {
129 kCryptoNone,
130 kCryptoRc4,
131 kCryptoAes
132 };
Paul Stewart7b5cee92014-06-25 02:03:34 -0700133
Rebecca Silberstein57776902014-09-15 21:43:02 -0700134 enum UpdateCredentialsReason{
135 kReasonCredentialsLoaded,
136 kReasonPropertyUpdate
137 };
138
Paul Stewartac4ac002011-08-26 12:04:26 -0700139 static const int kPriorityNone;
140
Chris Masone9be4a9d2011-05-16 15:44:09 -0700141 // A constructor for the Service object
Paul Stewart1a212a62015-06-16 13:13:10 -0700142 Service(ControlInterface* control_interface,
143 EventDispatcher* dispatcher,
144 Metrics* metrics,
145 Manager* manager,
Gaurav Shah435de2c2011-11-17 19:01:07 -0800146 Technology::Identifier technology);
Darin Petkovba40dd32011-07-11 20:06:39 -0700147
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000148 // AutoConnect MAY choose to ignore the connection request in some
149 // cases. For example, if the corresponding Device only supports one
150 // concurrent connection, and another Service is already connected
151 // or connecting.
152 //
153 // AutoConnect MAY issue RPCs immediately. So AutoConnect MUST NOT
154 // be called from a D-Bus signal handler context.
155 virtual void AutoConnect();
mukesh agrawaldc7b8442012-09-27 13:48:14 -0700156 // Queue up a connection attempt. Derived classes SHOULD call the
157 // base class implementation before beginning a connect. The base
158 // class will log the connection attempt, and update base-class
159 // state.
Paul Stewart1a212a62015-06-16 13:13:10 -0700160 virtual void Connect(Error* error, const char* reason);
Christopher Wileyabd3b502012-09-26 13:08:52 -0700161 // Disconnect this service. Override this method to add your service specific
162 // disconnect logic, but call the super class's Disconnect() first.
Paul Stewart1a212a62015-06-16 13:13:10 -0700163 virtual void Disconnect(Error* error, const char* reason);
Christopher Wileyabd3b502012-09-26 13:08:52 -0700164 // Disconnects this service via Disconnect(). Marks the service as having
165 // failed with |failure|. Do not override this method.
Samuel Tan0d061192014-07-07 15:45:15 -0700166 virtual void DisconnectWithFailure(ConnectFailure failure,
Paul Stewart1a212a62015-06-16 13:13:10 -0700167 Error* error,
168 const char* reason);
Christopher Wileyabd3b502012-09-26 13:08:52 -0700169 // Disconnects this service via Disconnect(). The service will not be eligible
170 // for auto-connect until a subsequent call to Connect, or Load. Do not
171 // override this method.
Paul Stewart1a212a62015-06-16 13:13:10 -0700172 virtual void UserInitiatedDisconnect(Error* error);
Peter Qiudc4e0992014-05-01 10:02:52 -0700173 // Connect to this service via Connect(). This function indicates that the
174 // connection attempt is user-initiated.
Paul Stewart1a212a62015-06-16 13:13:10 -0700175 virtual void UserInitiatedConnect(Error* error);
Chris Masonea82b7112011-05-25 15:16:29 -0700176
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500177 // The default implementation returns the error kInvalidArguments.
Paul Stewart1a212a62015-06-16 13:13:10 -0700178 virtual void ActivateCellularModem(const std::string& carrier,
179 Error* error,
180 const ResultCallback& callback);
Ben Chan5d924542013-02-14 17:49:08 -0800181 // The default implementation returns the error kNotSupported.
Paul Stewart1a212a62015-06-16 13:13:10 -0700182 virtual void CompleteCellularActivation(Error* error);
Darin Petkovc408e692011-08-17 13:47:15 -0700183
Paul Stewart1a212a62015-06-16 13:13:10 -0700184 virtual bool IsActive(Error* error);
Paul Stewart03dba0b2011-08-22 16:32:45 -0700185
Paul Stewart7fb09382012-07-18 17:32:27 -0700186 // Returns whether services of this type should be auto-connect by default.
187 virtual bool IsAutoConnectByDefault() const { return false; }
188
Paul Stewart03dba0b2011-08-22 16:32:45 -0700189 virtual ConnectState state() const { return state_; }
190 // Updates the state of the Service and alerts the manager. Also
191 // clears |failure_| if the new state isn't a failure.
192 virtual void SetState(ConnectState state);
Darin Petkov58f0b6d2012-06-12 12:52:30 +0200193 std::string GetStateString() const;
Paul Stewart03dba0b2011-08-22 16:32:45 -0700194
Peter Qiu9b83c892014-08-09 23:06:02 -0700195 // Set portal detection failure phase and status (reason). This function
196 // is called when portal detection failed for the Service.
Paul Stewart1a212a62015-06-16 13:13:10 -0700197 virtual void SetPortalDetectionFailure(const std::string& phase,
198 const std::string& status);
Peter Qiu9b83c892014-08-09 23:06:02 -0700199
Paul Stewart22aa71b2011-09-16 12:15:11 -0700200 // State utility functions
Darin Petkovc8d91e52013-01-21 11:43:47 +0100201 static bool IsConnectedState(ConnectState state);
202 static bool IsConnectingState(ConnectState state);
203
204 virtual bool IsConnected() const;
205 virtual bool IsConnecting() const;
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000206 virtual bool IsFailed() const {
mukesh agrawal568b5c62012-02-28 14:44:47 -0800207 // We sometimes lie about the failure state, to keep Chrome happy
208 // (see comment in WiFi::HandleDisconnect). Hence, we check both
209 // state and |failed_time_|.
210 return state() == kStateFailure || failed_time_ > 0;
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000211 }
Paul Stewartdf3c0a82012-11-09 15:54:33 -0800212
Peter Qiu49438222014-03-14 14:21:09 -0700213 virtual bool IsInFailState() const {
214 return state() == kStateFailure;
215 }
216
Peter Qiu700de642014-07-14 16:31:30 -0700217 virtual bool IsOnline() const {
218 return state() == kStateOnline;
219 }
220
Paul Stewartdf3c0a82012-11-09 15:54:33 -0800221 // Returns true if the connection for |this| depends on service |b|.
Paul Stewart1a212a62015-06-16 13:13:10 -0700222 virtual bool IsDependentOn(const ServiceRefPtr& b) const;
Paul Stewartdf3c0a82012-11-09 15:54:33 -0800223
Paul Stewarta121c442012-06-09 14:12:58 -0700224 virtual bool IsPortalled() const {
225 return state() == kStatePortal;
226 }
Paul Stewart22aa71b2011-09-16 12:15:11 -0700227
Peter Qiua89154b2014-05-23 15:45:42 -0700228 // Return true if service is allowed to automatically switch to fallback
229 // DNS server.
230 virtual bool is_dns_auto_fallback_allowed() const {
231 return is_dns_auto_fallback_allowed_;
232 }
233
Peter Qiud49760e2014-09-19 16:13:42 -0700234 virtual bool link_monitor_disabled() const { return link_monitor_disabled_; }
235
Paul Stewart03dba0b2011-08-22 16:32:45 -0700236 virtual ConnectFailure failure() const { return failure_; }
Paul Stewartd7c09a52014-02-19 12:50:29 -0800237 // Sets the |previous_error_| property based on the current |failure_|, and
238 // sets a serial number for this failure.
239 virtual void SaveFailure();
mukesh agrawal568b5c62012-02-28 14:44:47 -0800240 // Records the failure mode and time. Sets the Service state to "Failure".
Paul Stewart03dba0b2011-08-22 16:32:45 -0700241 virtual void SetFailure(ConnectFailure failure);
mukesh agrawal568b5c62012-02-28 14:44:47 -0800242 // Records the failure mode and time. Sets the Service state to "Idle".
243 // Avoids showing a failure mole in the UI.
244 virtual void SetFailureSilent(ConnectFailure failure);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700245
Darin Petkovba40dd32011-07-11 20:06:39 -0700246 // Returns a string that is guaranteed to uniquely identify this Service
247 // instance.
Paul Stewart1a212a62015-06-16 13:13:10 -0700248 const std::string& unique_name() const { return unique_name_; }
Darin Petkovafa6fc42011-06-21 16:21:08 -0700249
Chris Masone6791a432011-07-12 13:23:19 -0700250 virtual std::string GetRpcIdentifier() const;
Chris Masone3c3f6a12011-07-01 10:01:41 -0700251
Darin Petkovba40dd32011-07-11 20:06:39 -0700252 // Returns the unique persistent storage identifier for the service.
Chris Masone6515aab2011-10-12 16:19:09 -0700253 virtual std::string GetStorageIdentifier() const = 0;
Darin Petkovba40dd32011-07-11 20:06:39 -0700254
Paul Stewarte7de2942013-04-25 17:07:31 -0700255 // Returns the identifier within |storage| from which configuration for
256 // this service can be loaded. Returns an empty string if no entry in
257 // |storage| can be used.
258 virtual std::string GetLoadableStorageIdentifier(
Paul Stewart1a212a62015-06-16 13:13:10 -0700259 const StoreInterface& storage) const;
Paul Stewarte7de2942013-04-25 17:07:31 -0700260
Paul Stewartbba6a5b2011-11-02 18:45:59 -0700261 // Returns whether the service configuration can be loaded from |storage|.
Paul Stewart1a212a62015-06-16 13:13:10 -0700262 virtual bool IsLoadableFrom(const StoreInterface& storage) const;
Paul Stewartbba6a5b2011-11-02 18:45:59 -0700263
Paul Stewart81426132012-05-16 10:05:10 -0700264 // Returns true if the service uses 802.1x for key management.
Paul Stewartbe9abfd2013-04-22 12:18:48 -0700265 virtual bool Is8021x() const { return false; }
Paul Stewart81426132012-05-16 10:05:10 -0700266
Darin Petkovba40dd32011-07-11 20:06:39 -0700267 // Loads the service from persistent |storage|. Returns true on success.
Paul Stewart1a212a62015-06-16 13:13:10 -0700268 virtual bool Load(StoreInterface* storage);
Darin Petkovba40dd32011-07-11 20:06:39 -0700269
Paul Stewarta41e38d2011-11-11 07:47:29 -0800270 // Indicate to service that it is no longer persisted to storage. It
Paul Stewart65512e12012-03-26 18:01:08 -0700271 // should purge any stored profile state (e.g., credentials). Returns
272 // true to indicate that this service should also be unregistered from
273 // the manager, false otherwise.
274 virtual bool Unload();
Paul Stewarta41e38d2011-11-11 07:47:29 -0800275
Albert Chaulk0e1cdea2013-02-27 15:32:55 -0800276 // Attempt to remove the service. On failure, no changes in state will occur.
Paul Stewart1a212a62015-06-16 13:13:10 -0700277 virtual void Remove(Error* error);
Albert Chaulk0e1cdea2013-02-27 15:32:55 -0800278
Darin Petkovba40dd32011-07-11 20:06:39 -0700279 // Saves the service to persistent |storage|. Returns true on success.
Paul Stewart1a212a62015-06-16 13:13:10 -0700280 virtual bool Save(StoreInterface* storage);
Darin Petkovba40dd32011-07-11 20:06:39 -0700281
Thieu Led4e9e552012-02-16 16:26:07 -0800282 // Saves the service to the current profile.
Gary Moraind93615e2012-04-27 11:50:03 -0700283 virtual void SaveToCurrentProfile();
Thieu Led4e9e552012-02-16 16:26:07 -0800284
Paul Stewartcb59fed2012-03-21 21:14:46 -0700285 // Applies all the properties in |args| to this service object's mutable
286 // store, except for those in parameters_ignored_for_configure_.
287 // Returns an error in |error| if one or more parameter set attempts
288 // fails, but will only return the first error.
Paul Stewart1a212a62015-06-16 13:13:10 -0700289 virtual void Configure(const KeyValueStore& args, Error* error);
Paul Stewartcb59fed2012-03-21 21:14:46 -0700290
Paul Stewart7a20aa42013-01-17 12:21:41 -0800291 // Iterate over all the properties in |args| and test for an identical
292 // value in this service object's store. Returns false if one or more
293 // keys in |args| do not exist or have different values, true otherwise.
Paul Stewart1a212a62015-06-16 13:13:10 -0700294 virtual bool DoPropertiesMatch(const KeyValueStore& args) const;
Paul Stewart7a20aa42013-01-17 12:21:41 -0800295
Paul Stewartd215af62012-04-24 23:25:50 -0700296 // Returns whether portal detection is explicitly disabled on this service
297 // via a property set on it.
298 virtual bool IsPortalDetectionDisabled() const;
299
300 // Returns whether portal detection is set to follow the default setting
301 // of this service's technology via a property set on it.
302 virtual bool IsPortalDetectionAuto() const;
303
Paul Stewart10ccbb32012-04-26 15:59:30 -0700304 // Returns true if the service is persisted to a non-ephemeral profile.
305 virtual bool IsRemembered() const;
306
Paul Stewarta41e38d2011-11-11 07:47:29 -0800307 // Returns true if the service RPC identifier should be part of the
308 // manager's advertised services list, false otherwise.
309 virtual bool IsVisible() const { return true; }
310
Paul Stewart20088d82012-02-16 06:58:55 -0800311 // Returns true if there is a proxy configuration set on this service.
312 virtual bool HasProxyConfig() const { return !proxy_config_.empty(); }
313
Paul Stewarta47c3c62012-12-18 12:14:29 -0800314 // Returns whether this service has had recent connection issues.
315 virtual bool HasRecentConnectionIssues();
316
Paul Stewart2da34c02013-10-17 15:28:56 -0700317 // If the AutoConnect property has not already been marked as saved, set
318 // its value to true and mark it saved.
319 virtual void EnableAndRetainAutoConnect();
mukesh agrawal00917ce2011-11-22 23:56:55 +0000320
Darin Petkov5eb05422012-05-11 15:45:25 +0200321 // Set the connection for this service. If the connection is non-NULL, create
322 // an HTTP Proxy that will utilize this service's connection to serve
323 // requests.
Paul Stewart1a212a62015-06-16 13:13:10 -0700324 virtual void SetConnection(const ConnectionRefPtr& connection);
325 virtual const ConnectionRefPtr& connection() const { return connection_; }
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800326
Peter Qiua89154b2014-05-23 15:45:42 -0700327 // Emit service's IP config change event to chrome.
328 virtual void NotifyIPConfigChanges();
329
Peter Qiu1a72f542015-04-14 16:31:36 -0700330#if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X)
Gaurav Shah10109f22011-11-11 20:16:22 -0800331 // Examines the EAP credentials for the service and returns true if a
332 // connection attempt can be made.
Paul Stewart9413bcc2013-04-04 16:12:43 -0700333 virtual bool Is8021xConnectable() const;
Gaurav Shah10109f22011-11-11 20:16:22 -0800334
Paul Stewartbc6e7392012-05-24 07:07:48 -0700335 // Add an EAP certification id |name| at position |depth| in the stack.
336 // Returns true if entry was added, false otherwise.
Paul Stewart1a212a62015-06-16 13:13:10 -0700337 virtual bool AddEAPCertification(const std::string& name, size_t depth);
Paul Stewartbc6e7392012-05-24 07:07:48 -0700338 // Clear all EAP certification elements.
Paul Stewart9413bcc2013-04-04 16:12:43 -0700339 virtual void ClearEAPCertification();
Peter Qiu1a72f542015-04-14 16:31:36 -0700340#endif // DISABLE_WIFI || DISABLE_WIRED_8021X
Paul Stewartbc6e7392012-05-24 07:07:48 -0700341
Paul Stewart316acef2014-05-29 18:40:48 -0700342 // Returns true if this service contains a IP address in its static IP
343 // parameters, false otherwise.
344 virtual bool HasStaticIPAddress() const;
345
Garret Kellyd01b5cc2015-03-12 16:20:55 -0400346 // Returns true if this service contains nameservers in its static IP
347 // parameters, false otherwise.
348 virtual bool HasStaticNameServers() const;
349
Thieu Le48e6d6d2011-12-06 00:40:27 +0000350 // The inherited class that needs to send metrics after the service has
Thieu Leb84ba342012-03-02 15:15:19 -0800351 // transitioned to the ready state should override this method.
352 // |time_resume_to_ready_milliseconds| holds the elapsed time from when
353 // the system was resumed until when the service transitioned to the
354 // connected state. This value is non-zero for the first service transition
355 // to the connected state after a resume.
356 virtual void SendPostReadyStateMetrics(
Ben Chan7fab8972014-08-10 17:14:46 -0700357 int64_t /*time_resume_to_ready_milliseconds*/) const {}
Thieu Le48e6d6d2011-12-06 00:40:27 +0000358
Darin Petkovafa6fc42011-06-21 16:21:08 -0700359 bool auto_connect() const { return auto_connect_; }
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700360 void SetAutoConnect(bool connect);
Paul Stewart75897df2011-04-27 09:05:53 -0700361
Gaurav Shah435de2c2011-11-17 19:01:07 -0800362 bool connectable() const { return connectable_; }
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700363 // Sets the connectable property of the service, and broadcast the
364 // new value. Does not update the manager.
365 // TODO(petkov): Remove this method in favor of SetConnectableFull.
Darin Petkovb2ba39f2012-06-06 10:33:43 +0200366 void SetConnectable(bool connectable);
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700367 // Sets the connectable property of the service, broadcasts the new
368 // value, and alerts the manager if necessary.
369 void SetConnectableFull(bool connectable);
Gaurav Shah435de2c2011-11-17 19:01:07 -0800370
Thieu Le67370f62012-02-14 23:01:42 +0000371 virtual bool explicitly_disconnected() const {
372 return explicitly_disconnected_;
373 }
374
Paul Stewart2da34c02013-10-17 15:28:56 -0700375 bool retain_auto_connect() const { return retain_auto_connect_; }
376 // Setter is deliberately omitted; use EnableAndRetainAutoConnect.
Paul Stewart22aa71b2011-09-16 12:15:11 -0700377
Paul Stewart1a212a62015-06-16 13:13:10 -0700378 void set_friendly_name(const std::string& n) { friendly_name_ = n; }
379 const std::string& friendly_name() const { return friendly_name_; }
Ben Chan923a5022013-09-20 11:23:23 -0700380 // Sets the kNameProperty and broadcasts the change.
Paul Stewart1a212a62015-06-16 13:13:10 -0700381 void SetFriendlyName(const std::string& friendly_name);
mukesh agrawal15908392011-11-16 18:29:25 +0000382
Paul Stewart1a212a62015-06-16 13:13:10 -0700383 const std::string& guid() const { return guid_; }
384 bool SetGuid(const std::string& guid, Error* error);
Paul Stewart4c561612012-03-21 12:49:01 -0700385
mukesh agrawalcf24a242012-05-21 16:46:11 -0700386 bool has_ever_connected() const { return has_ever_connected_; }
Rebecca Silbersteine99f6642014-07-09 14:04:31 -0700387 // Sets the has_ever_connected_ property of the service
388 // and broadcasts the new value
389 void SetHasEverConnected(bool has_ever_connected);
mukesh agrawalcf24a242012-05-21 16:46:11 -0700390
Ben Chan7fab8972014-08-10 17:14:46 -0700391 int32_t priority() const { return priority_; }
Paul Stewart1a212a62015-06-16 13:13:10 -0700392 bool SetPriority(const int32_t& priority, Error* error);
Paul Stewartd9c7cfc2015-01-06 14:26:22 -0800393 int32_t priority_within_technology() const {
394 return priority_within_technology_;
395 }
Paul Stewart1a212a62015-06-16 13:13:10 -0700396 bool SetPriorityWithinTechnology(const int32_t& priority, Error* error);
Paul Stewart22aa71b2011-09-16 12:15:11 -0700397
mukesh agrawal43970a22013-02-15 16:00:07 -0800398 size_t crypto_algorithm() const { return crypto_algorithm_; }
399 bool key_rotation() const { return key_rotation_; }
400 bool endpoint_auth() const { return endpoint_auth_; }
Paul Stewart22aa71b2011-09-16 12:15:11 -0700401
Ben Chan7fab8972014-08-10 17:14:46 -0700402 void SetStrength(uint8_t strength);
mukesh agrawale1d90e92012-02-15 17:36:08 -0800403
Ben Chan7fab8972014-08-10 17:14:46 -0700404 // uint8_t streams out as a char. Coerce to a larger type, so that
mukesh agrawale1d90e92012-02-15 17:36:08 -0800405 // it prints as a number.
Ben Chan7fab8972014-08-10 17:14:46 -0700406 uint16_t strength() const { return strength_; }
Paul Stewart22aa71b2011-09-16 12:15:11 -0700407
Gaurav Shah435de2c2011-11-17 19:01:07 -0800408 virtual Technology::Identifier technology() const { return technology_; }
Darin Petkov58f0b6d2012-06-12 12:52:30 +0200409 std::string GetTechnologyString() const;
Gaurav Shah435de2c2011-11-17 19:01:07 -0800410
Peter Qiu1a72f542015-04-14 16:31:36 -0700411#if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X)
Paul Stewart1a212a62015-06-16 13:13:10 -0700412 virtual const EapCredentials* eap() const { return eap_.get(); }
413 void SetEapCredentials(EapCredentials* eap);
Peter Qiu1a72f542015-04-14 16:31:36 -0700414#endif // DISABLE_WIFI || DISABLE_WIRED_8021X
Gaurav Shah10109f22011-11-11 20:16:22 -0800415
Darin Petkovcb715292012-04-25 13:04:37 +0200416 bool save_credentials() const { return save_credentials_; }
417 void set_save_credentials(bool save) { save_credentials_ = save; }
418
Paul Stewart1a212a62015-06-16 13:13:10 -0700419 const std::string& error() const { return error_; }
420 void set_error(const std::string& error) { error_ = error; }
Darin Petkov51489002011-08-18 13:13:20 -0700421
Paul Stewart1a212a62015-06-16 13:13:10 -0700422 const std::string& error_details() const { return error_details_; }
423 void SetErrorDetails(const std::string& details);
Darin Petkovaba89322013-03-11 14:48:22 +0100424
Paul Stewart1a212a62015-06-16 13:13:10 -0700425 static const char* ConnectFailureToString(const ConnectFailure& state);
426 static const char* ConnectStateToString(const ConnectState& state);
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800427
Paul Stewart39db5ca2013-03-18 14:15:17 -0700428 // Compare two services. Returns true if Service |a| should be displayed
429 // above |b|. If |compare_connectivity_state| is true, the connectivity
430 // state of the service (service->state()) is used as the most significant
431 // criteria for comparsion, otherwise the service state is ignored. Use
432 // |tech_order| to rank services if more decisive criteria do not yield a
433 // difference. |reason| is populated with the exact criteria used for the
434 // ultimate comparison.
Paul Stewart1a212a62015-06-16 13:13:10 -0700435 static bool Compare(Manager* manager,
Rebecca Silberstein6d4836b2014-07-16 14:28:28 -0700436 ServiceRefPtr a,
Paul Stewart22aa71b2011-09-16 12:15:11 -0700437 ServiceRefPtr b,
Paul Stewart39db5ca2013-03-18 14:15:17 -0700438 bool compare_connectivity_state,
Paul Stewart1a212a62015-06-16 13:13:10 -0700439 const std::vector<Technology::Identifier>& tech_order,
440 const char** reason);
Paul Stewart22aa71b2011-09-16 12:15:11 -0700441
Chris Masone34af2182011-08-22 11:59:36 -0700442 // These are defined in service.cc so that we don't have to include profile.h
Chris Masone9d779932011-08-25 16:33:41 -0700443 // TODO(cmasone): right now, these are here only so that we can get the
444 // profile name as a property. Can we store just the name, and then handle
445 // setting the profile for this service via |manager_|?
Paul Stewart1a212a62015-06-16 13:13:10 -0700446 const ProfileRefPtr& profile() const;
Philipp Neubeck79173602012-11-13 21:10:09 +0100447
448 // Sets the profile property of this service. Broadcasts the new value if it's
Ben Chancc225ef2014-09-30 13:26:51 -0700449 // not nullptr. If the new value is nullptr, the service will either be set to
Philipp Neubeck79173602012-11-13 21:10:09 +0100450 // another profile afterwards or it will not be visible and not monitored
451 // anymore.
Paul Stewart1a212a62015-06-16 13:13:10 -0700452 void SetProfile(const ProfileRefPtr& p);
Philipp Neubeck79173602012-11-13 21:10:09 +0100453
454 // This is called from tests and shouldn't be called otherwise. Use SetProfile
455 // instead.
Paul Stewart1a212a62015-06-16 13:13:10 -0700456 void set_profile(const ProfileRefPtr& p);
Chris Masone6791a432011-07-12 13:23:19 -0700457
Paul Stewart4357f4e2012-04-26 17:39:26 -0700458 // Notification that occurs when a service now has profile data saved
459 // on its behalf. Some service types like WiFi can choose to register
460 // themselves at this point.
461 virtual void OnProfileConfigured() {}
462
Paul Stewartff14b022012-04-24 20:06:23 -0700463 // Notification that occurs when a single property has been changed via
464 // the RPC adaptor.
Paul Stewart1a212a62015-06-16 13:13:10 -0700465 virtual void OnPropertyChanged(const std::string& property);
Paul Stewartff14b022012-04-24 20:06:23 -0700466
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700467 // Notification that occurs when an EAP credential property has been
468 // changed. Some service subclasses can choose to respond to this
469 // event.
Rebecca Silberstein57776902014-09-15 21:43:02 -0700470 virtual void OnEapCredentialsChanged(UpdateCredentialsReason reason) {}
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700471
Christopher Wiley0801d192012-09-24 11:57:15 -0700472 // Called by the manager once after a resume.
473 virtual void OnAfterResume();
474
Prathmesh Prabhu64ad2382014-08-26 11:19:30 -0700475 // Called by the manager once when entering dark resume.
476 virtual void OnDarkResume();
477
Paul Stewart2eee6132014-05-09 13:33:26 -0700478 // Called by the manager to clear remembered state of being explicitly
479 // disconnected.
480 virtual void ClearExplicitlyDisconnected();
481
Peter Qiu1a72f542015-04-14 16:31:36 -0700482#if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X)
Paul Stewart1a212a62015-06-16 13:13:10 -0700483 EapCredentials* mutable_eap() { return eap_.get(); }
Peter Qiu1a72f542015-04-14 16:31:36 -0700484#endif // DISABLE_WIFI || DISABLE_WIRED_8021X
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700485
Paul Stewart1a212a62015-06-16 13:13:10 -0700486 PropertyStore* mutable_store() { return &store_; }
487 const PropertyStore& store() const { return store_; }
488 StaticIPParameters* mutable_static_ip_parameters() {
Paul Stewartdef189e2012-08-02 20:12:09 -0700489 return &static_ip_parameters_;
490 }
Paul Stewart1a212a62015-06-16 13:13:10 -0700491 const StaticIPParameters& static_ip_parameters() const {
Paul Stewart1062d9d2012-04-27 10:42:27 -0700492 return static_ip_parameters_;
493 }
Chris Masone27c4aa52011-07-02 13:10:14 -0700494
Paul Stewartc3dbff12013-07-17 10:32:48 -0700495 // Retrieves |key| from |id| in |storage| to |value|. If this key does
496 // not exist, assign |default_value| to |value|.
Paul Stewart1a212a62015-06-16 13:13:10 -0700497 static void LoadString(StoreInterface* storage,
498 const std::string& id,
499 const std::string& key,
500 const std::string& default_value,
501 std::string* value);
Paul Stewartc3dbff12013-07-17 10:32:48 -0700502
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700503 // Assigns |value| to |key| in |storage| if |value| is non-empty and |save| is
504 // true. Otherwise, removes |key| from |storage|. If |crypted| is true, the
505 // value is encrypted.
Paul Stewart1a212a62015-06-16 13:13:10 -0700506 static void SaveString(StoreInterface* storage,
507 const std::string& id,
508 const std::string& key,
509 const std::string& value,
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700510 bool crypted,
511 bool save);
512
Paul Stewart967eaeb2013-04-25 19:53:07 -0700513 // Called via RPC to get a dict containing profile-to-entry_name mappings
514 // of all the profile entires which contain configuration applicable to
515 // this service.
516 std::map<std::string, std::string> GetLoadableProfileEntries();
517
Peter Qiu9d581932014-04-14 16:37:37 -0700518 void set_connection_id(int connection_id) { connection_id_ = connection_id; }
519 int connection_id() const { return connection_id_; }
520
Peter Qiua388fdb2015-04-03 10:31:22 -0700521 void set_unreliable(bool unreliable) { unreliable_ = unreliable; }
522 bool unreliable() const { return unreliable_; }
523
mukesh agrawalb54601c2011-06-07 17:39:22 -0700524 protected:
Darin Petkov5eb05422012-05-11 15:45:25 +0200525 friend class base::RefCounted<Service>;
526
mukesh agrawal03c15ce2012-11-29 17:36:21 -0800527 static const char kAutoConnBusy[];
528
Darin Petkov5eb05422012-05-11 15:45:25 +0200529 virtual ~Service();
530
Chris Masone34af2182011-08-22 11:59:36 -0700531 // Returns true if a character is allowed to be in a service storage id.
532 static bool LegalChar(char a) { return isalnum(a) || a == '_'; }
533
Darin Petkov31332412012-01-28 01:50:02 +0100534 // Returns true if a character is disallowed to be in a service storage id.
535 static bool IllegalChar(char a) { return !LegalChar(a); }
536
Paul Stewart1a212a62015-06-16 13:13:10 -0700537 virtual std::string CalculateState(Error* error);
538 std::string CalculateTechnology(Error* error);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700539
Paul Stewart1a212a62015-06-16 13:13:10 -0700540 bool GetVisibleProperty(Error* error);
Paul Stewartcca85b12014-05-30 13:56:35 -0700541
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000542 // Returns whether this service is in a state conducive to auto-connect.
543 // This should include any tests used for computing connectable(),
544 // as well as other critera such as whether the device associated with
545 // this service is busy with another connection.
mukesh agrawalbf14e942012-03-02 14:36:34 -0800546 //
547 // If the service is not auto-connectable, |*reason| will be set to
548 // point to C-string explaining why the service is not auto-connectable.
Paul Stewart1a212a62015-06-16 13:13:10 -0700549 virtual bool IsAutoConnectable(const char** reason) const;
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000550
mukesh agrawal292dc0f2012-01-26 18:02:46 -0800551 // HelpRegisterDerived*: Expose a property over RPC, with the name |name|.
552 //
553 // Reads of the property will be handled by invoking |get|.
554 // Writes to the property will be handled by invoking |set|.
555 // Clearing the property will be handled by PropertyStore.
mukesh agrawalffa3d042011-10-06 15:26:10 -0700556 void HelpRegisterDerivedBool(
Paul Stewart1a212a62015-06-16 13:13:10 -0700557 const std::string& name,
558 bool(Service::*get)(Error* error),
559 bool(Service::*set)(const bool& value, Error* error),
560 void(Service::*clear)(Error* error));
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700561 void HelpRegisterDerivedInt32(
Paul Stewart1a212a62015-06-16 13:13:10 -0700562 const std::string& name,
563 int32_t(Service::*get)(Error* error),
564 bool(Service::*set)(const int32_t& value, Error* error));
mukesh agrawalffa3d042011-10-06 15:26:10 -0700565 void HelpRegisterDerivedString(
Paul Stewart1a212a62015-06-16 13:13:10 -0700566 const std::string& name,
567 std::string(Service::*get)(Error* error),
568 bool(Service::*set)(const std::string& value, Error* error));
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700569 void HelpRegisterConstDerivedUint16(
Paul Stewart1a212a62015-06-16 13:13:10 -0700570 const std::string& name,
571 uint16_t(Service::*get)(Error* error) const);
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700572 void HelpRegisterConstDerivedRpcIdentifier(
Paul Stewart1a212a62015-06-16 13:13:10 -0700573 const std::string& name,
574 std::string(Service::*get)(Error*) const);
Darin Petkov0c65bdd2012-12-05 13:42:41 +0100575 void HelpRegisterConstDerivedStrings(
Paul Stewart1a212a62015-06-16 13:13:10 -0700576 const std::string& name, Strings(Service::*get)(Error* error) const);
Paul Stewart1cf7eb82013-12-03 19:34:36 -0800577 void HelpRegisterConstDerivedString(
Paul Stewart1a212a62015-06-16 13:13:10 -0700578 const std::string& name, std::string(Service::*get)(Error* error) const);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700579
Paul Stewart45170bc2014-06-02 15:49:34 -0700580 // HelpRegisterObservedDerived*: Expose an property over RPC, with the
581 // name |name|, for which property changes are automatically generated.
582 //
583 void HelpRegisterObservedDerivedBool(
Paul Stewart1a212a62015-06-16 13:13:10 -0700584 const std::string& name,
585 bool(Service::*get)(Error* error),
586 bool(Service::*set)(const bool& value, Error* error),
587 void(Service::*clear)(Error* error));
588 ServiceAdaptorInterface* adaptor() const { return adaptor_.get(); }
Darin Petkovb72cf402011-11-22 14:51:39 +0100589
Peter Qiu1a72f542015-04-14 16:31:36 -0700590#if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X)
Paul Stewartd8ad3c42012-01-09 12:39:38 -0800591 void UnloadEapCredentials();
Peter Qiu1a72f542015-04-14 16:31:36 -0700592#endif // DISABLE_WIFI || DISABLE_WIRED_8021X
Darin Petkovba40dd32011-07-11 20:06:39 -0700593
Paul Stewartcb59fed2012-03-21 21:14:46 -0700594 // Ignore |parameter| when performing a Configure() operation.
Paul Stewart1a212a62015-06-16 13:13:10 -0700595 void IgnoreParameterForConfigure(const std::string& parameter);
Paul Stewartcb59fed2012-03-21 21:14:46 -0700596
Paul Stewartf2d60912012-07-15 08:37:30 -0700597 // Update the service's string-based "Error" RPC property based on the
598 // failure_ enum.
599 void UpdateErrorProperty();
600
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700601 // RPC setter for the the "AutoConnect" property. Updates the |manager_|.
602 // (cf. SetAutoConnect, which does not update the manager.)
Paul Stewart1a212a62015-06-16 13:13:10 -0700603 virtual bool SetAutoConnectFull(const bool& connect, Error* error);
Paul Stewartcf199de2012-08-16 07:50:41 -0700604
Paul Stewart43d8dc02013-10-17 10:32:53 -0700605 // RPC clear method for the "AutoConnect" property. Sets the AutoConnect
Paul Stewart2da34c02013-10-17 15:28:56 -0700606 // property back to its default value, and clears the retain_auto_connect_
607 // property to allow the AutoConnect property to be enabled automatically.
Paul Stewart1a212a62015-06-16 13:13:10 -0700608 void ClearAutoConnect(Error* error);
Paul Stewart43d8dc02013-10-17 10:32:53 -0700609
Paul Stewartac4ac002011-08-26 12:04:26 -0700610 // Property accessors reserved for subclasses
Paul Stewart1a212a62015-06-16 13:13:10 -0700611 EventDispatcher* dispatcher() const { return dispatcher_; }
Peter Qiu1a72f542015-04-14 16:31:36 -0700612#if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X)
Paul Stewart1a212a62015-06-16 13:13:10 -0700613 const std::string& GetEAPKeyManagement() const;
614 virtual void SetEAPKeyManagement(const std::string& key_management);
Peter Qiu1a72f542015-04-14 16:31:36 -0700615#endif // DISABLE_WIFI || DISABLE_WIRED_8021X
616
Paul Stewart1a212a62015-06-16 13:13:10 -0700617 Manager* manager() const { return manager_; }
618 Metrics* metrics() const { return metrics_; }
mukesh agrawalb54601c2011-06-07 17:39:22 -0700619
Paul Stewart2da34c02013-10-17 15:28:56 -0700620 // Save the serivce's auto_connect value, without affecting its auto_connect
621 // property itself. (cf. EnableAndRetainAutoConnect)
622 void RetainAutoConnect();
623
mukesh agrawal43970a22013-02-15 16:00:07 -0800624 // Inform base class of the security properties for the service.
625 //
626 // NB: When adding a call to this function from a subclass, please check
627 // that the semantics of SecurityLevel() are appropriate for the subclass.
628 void SetSecurity(CryptoAlgorithm crypt, bool rotation, bool endpoint_auth);
Darin Petkov1d0080a2012-04-30 17:10:36 +0200629
Paul Stewartfa11e282013-12-02 22:04:25 -0800630 // Return whether this service is suspected or confirmed to be
631 // provided by a mobile device, which is likely to be using a
632 // metered backhaul for internet connectivity.
Paul Stewart1a212a62015-06-16 13:13:10 -0700633 virtual std::string GetTethering(Error* error) const;
Paul Stewartfa11e282013-12-02 22:04:25 -0800634
Paul Stewart45170bc2014-06-02 15:49:34 -0700635 // Emit property change notifications for all observed properties.
636 void NotifyPropertyChanges();
Paul Stewart7cc90682014-05-30 17:01:56 -0700637
Paul Stewart75897df2011-04-27 09:05:53 -0700638 private:
Thieu Le43ce4d42013-10-04 16:08:55 -0700639 friend class ActivePassiveOutOfCreditsDetectorTest;
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700640 friend class EthernetEapServiceTest;
Paul Stewartcf199de2012-08-16 07:50:41 -0700641 friend class EthernetServiceTest;
Thieu Le48e6d6d2011-12-06 00:40:27 +0000642 friend class MetricsTest;
Paul Stewart9dd253e2013-04-22 08:32:59 -0700643 friend class ManagerTest;
Paul Stewart0756db92012-01-27 08:34:47 -0800644 friend class ServiceAdaptorInterface;
Darin Petkov385b9bc2012-12-03 15:25:05 +0100645 friend class ServiceTest;
Thieu Le43ce4d42013-10-04 16:08:55 -0700646 friend class SubscriptionStateOutOfCreditsDetectorTest;
Darin Petkov457728b2013-01-09 09:49:08 +0100647 friend class VPNProviderTest;
Darin Petkov5eb05422012-05-11 15:45:25 +0200648 friend class VPNServiceTest;
mukesh agrawale1d90e92012-02-15 17:36:08 -0800649 friend class WiFiServiceTest;
Darin Petkov457728b2013-01-09 09:49:08 +0100650 friend class WiMaxProviderTest;
Darin Petkov6b9b2e12012-07-10 15:51:42 +0200651 friend class WiMaxServiceTest;
Paul Stewart1a212a62015-06-16 13:13:10 -0700652 friend void TestCommonPropertyChanges(ServiceRefPtr, ServiceMockAdaptor*);
653 friend void TestCustomSetterNoopChange(ServiceRefPtr, MockManager*);
654 friend void TestNamePropertyChange(ServiceRefPtr, ServiceMockAdaptor*);
Christopher Wiley0801d192012-09-24 11:57:15 -0700655 FRIEND_TEST(AllMockServiceTest, AutoConnectWithFailures);
Darin Petkov457728b2013-01-09 09:49:08 +0100656 FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier);
Ben Chan19f83972012-10-03 23:25:56 -0700657 FRIEND_TEST(CellularServiceTest, IsAutoConnectable);
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700658 FRIEND_TEST(DeviceTest, IPConfigUpdatedFailureWithStatic);
Paul Stewart39db5ca2013-03-18 14:15:17 -0700659 FRIEND_TEST(ManagerTest, ConnectToBestServices);
mukesh agrawal03c15ce2012-11-29 17:36:21 -0800660 FRIEND_TEST(ServiceTest, AutoConnectLogging);
Darin Petkov58f0b6d2012-06-12 12:52:30 +0200661 FRIEND_TEST(ServiceTest, CalculateState);
662 FRIEND_TEST(ServiceTest, CalculateTechnology);
Paul Stewartbc6e7392012-05-24 07:07:48 -0700663 FRIEND_TEST(ServiceTest, Certification);
Paul Stewart22ce7652014-10-15 21:26:44 -0700664 FRIEND_TEST(ServiceTest, Compare);
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700665 FRIEND_TEST(ServiceTest, ConfigureEapStringProperty);
Paul Stewartcb59fed2012-03-21 21:14:46 -0700666 FRIEND_TEST(ServiceTest, ConfigureIgnoredProperty);
Darin Petkovba40dd32011-07-11 20:06:39 -0700667 FRIEND_TEST(ServiceTest, Constructor);
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700668 FRIEND_TEST(ServiceTest, CustomSetterNoopChange);
Paul Stewart10241e32012-04-23 18:15:06 -0700669 FRIEND_TEST(ServiceTest, GetIPConfigRpcIdentifier);
Thieu Le284fe792012-01-31 17:53:19 -0800670 FRIEND_TEST(ServiceTest, GetProperties);
Paul Stewartfa11e282013-12-02 22:04:25 -0800671 FRIEND_TEST(ServiceTest, GetTethering);
mukesh agrawal76d13882012-01-12 15:23:11 -0800672 FRIEND_TEST(ServiceTest, IsAutoConnectable);
Paul Stewartdf3c0a82012-11-09 15:54:33 -0800673 FRIEND_TEST(ServiceTest, IsDependentOn);
Paul Stewartc3dbff12013-07-17 10:32:48 -0700674 FRIEND_TEST(ServiceTest, Load);
Peter Qiu9b83c892014-08-09 23:06:02 -0700675 FRIEND_TEST(ServiceTest, PortalDetectionFailure);
Paul Stewartd215af62012-04-24 23:25:50 -0700676 FRIEND_TEST(ServiceTest, RecheckPortal);
Darin Petkovba40dd32011-07-11 20:06:39 -0700677 FRIEND_TEST(ServiceTest, Save);
678 FRIEND_TEST(ServiceTest, SaveString);
679 FRIEND_TEST(ServiceTest, SaveStringCrypted);
680 FRIEND_TEST(ServiceTest, SaveStringDontSave);
681 FRIEND_TEST(ServiceTest, SaveStringEmpty);
mukesh agrawal43970a22013-02-15 16:00:07 -0800682 FRIEND_TEST(ServiceTest, SecurityLevel);
Paul Stewartd215af62012-04-24 23:25:50 -0700683 FRIEND_TEST(ServiceTest, SetCheckPortal);
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700684 FRIEND_TEST(ServiceTest, SetConnectableFull);
Arman Uguray2717a102013-01-29 23:36:06 -0800685 FRIEND_TEST(ServiceTest, SetFriendlyName);
686 FRIEND_TEST(ServiceTest, SetProperty);
mukesh agrawal568b5c62012-02-28 14:44:47 -0800687 FRIEND_TEST(ServiceTest, State);
Thieu Leaf471412013-06-27 14:12:37 -0700688 FRIEND_TEST(ServiceTest, StateResetAfterFailure);
mukesh agrawale37ad322013-10-08 16:33:56 -0700689 FRIEND_TEST(ServiceTest, UniqueAttributes);
Paul Stewartd8ad3c42012-01-09 12:39:38 -0800690 FRIEND_TEST(ServiceTest, Unload);
Peter Qiudc4e0992014-05-01 10:02:52 -0700691 FRIEND_TEST(ServiceTest, UserInitiatedConnectionResult);
Rebecca Silbersteine99f6642014-07-09 14:04:31 -0700692 FRIEND_TEST(WiFiServiceTest, SetPassphraseResetHasEverConnected);
Paul Stewartbca08f82013-07-09 16:32:37 -0700693 FRIEND_TEST(WiFiServiceTest, SuspectedCredentialFailure);
Rebecca Silbersteinb6df8b12014-07-10 16:07:08 -0700694 FRIEND_TEST(WiFiServiceTest, SetPassphraseRemovesCachedCredentials);
Rebecca Silberstein57776902014-09-15 21:43:02 -0700695 FRIEND_TEST(WiFiServiceTest, LoadPassphraseClearCredentials);
Christopher Wiley0801d192012-09-24 11:57:15 -0700696 FRIEND_TEST(WiFiTimerTest, ReconnectTimer);
Paul Stewart11c224b2013-10-22 19:04:40 -0700697 FRIEND_TEST(WiFiMainTest, EAPEvent); // For eap_.
Rebecca Silbersteinb6df8b12014-07-10 16:07:08 -0700698 FRIEND_TEST(WiMaxServiceTest, ChangeCredResetHasEverConnected);
699 FRIEND_TEST(EthernetEapServiceTest, OnEapCredentialsChanged);
Darin Petkovba40dd32011-07-11 20:06:39 -0700700
mukesh agrawalbf14e942012-03-02 14:36:34 -0800701 static const char kAutoConnConnected[];
702 static const char kAutoConnConnecting[];
703 static const char kAutoConnExplicitDisconnect[];
704 static const char kAutoConnNotConnectable[];
Darin Petkov4cbff5b2013-01-29 16:29:05 +0100705 static const char kAutoConnOffline[];
Ben Chan8e6b8ef2014-07-14 21:50:18 -0700706 static const char kAutoConnTechnologyNotConnectable[];
Christopher Wiley0801d192012-09-24 11:57:15 -0700707 static const char kAutoConnThrottled[];
mukesh agrawalbf14e942012-03-02 14:36:34 -0800708
Peter Qiu1a72f542015-04-14 16:31:36 -0700709#if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X)
Paul Stewartbc6e7392012-05-24 07:07:48 -0700710 static const size_t kEAPMaxCertificationElements;
Peter Qiu1a72f542015-04-14 16:31:36 -0700711#endif // DISABLE_WIFI || DISABLE_WIRED_8021X
Paul Stewartbc6e7392012-05-24 07:07:48 -0700712
Darin Petkov2f903b32012-04-18 12:56:43 +0200713 static const char kServiceSortAutoConnect[];
714 static const char kServiceSortConnectable[];
Paul Stewart2da34c02013-10-17 15:28:56 -0700715 static const char kServiceSortHasEverConnected[];
mukesh agrawalddc378f2012-02-17 18:26:20 -0800716 static const char kServiceSortIsConnected[];
Paul Stewartdf3c0a82012-11-09 15:54:33 -0800717 static const char kServiceSortDependency[];
mukesh agrawalddc378f2012-02-17 18:26:20 -0800718 static const char kServiceSortIsConnecting[];
719 static const char kServiceSortIsFailed[];
Paul Stewarta121c442012-06-09 14:12:58 -0700720 static const char kServiceSortIsPortalled[];
Darin Petkov2f903b32012-04-18 12:56:43 +0200721 static const char kServiceSortPriority[];
Paul Stewartd9c7cfc2015-01-06 14:26:22 -0800722 static const char kServiceSortPriorityWithinTechnology[];
Rebecca Silberstein6d4836b2014-07-16 14:28:28 -0700723 static const char kServiceSortSecurity[];
724 static const char kServiceSortProfileOrder[];
725 static const char kServiceSortEtc[];
mukesh agrawale37ad322013-10-08 16:33:56 -0700726 static const char kServiceSortSerialNumber[];
Darin Petkov2f903b32012-04-18 12:56:43 +0200727 static const char kServiceSortTechnology[];
mukesh agrawalddc378f2012-02-17 18:26:20 -0800728
Ben Chan7fab8972014-08-10 17:14:46 -0700729 static const uint64_t kMaxAutoConnectCooldownTimeMilliseconds;
730 static const uint64_t kMinAutoConnectCooldownTimeMilliseconds;
731 static const uint64_t kAutoConnectCooldownBackoffFactor;
Christopher Wiley0801d192012-09-24 11:57:15 -0700732
Darin Petkov385b9bc2012-12-03 15:25:05 +0100733 static const int kDisconnectsMonitorSeconds;
734 static const int kMisconnectsMonitorSeconds;
735 static const int kReportDisconnectsThreshold;
736 static const int kReportMisconnectsThreshold;
737 static const int kMaxDisconnectEventHistory;
Samuel Tan07dfabc2015-01-20 15:10:39 -0800738 static const int kMaxMisconnectEventHistory;
Darin Petkov385b9bc2012-12-03 15:25:05 +0100739
Paul Stewart1a212a62015-06-16 13:13:10 -0700740 bool GetAutoConnect(Error* error);
Thieu Le284fe792012-01-31 17:53:19 -0800741
Paul Stewart1a212a62015-06-16 13:13:10 -0700742 std::string GetCheckPortal(Error* error);
743 bool SetCheckPortal(const std::string& check_portal, Error* error);
Paul Stewartd215af62012-04-24 23:25:50 -0700744
Paul Stewart1a212a62015-06-16 13:13:10 -0700745 std::string GetGuid(Error* error);
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700746
Paul Stewart1a212a62015-06-16 13:13:10 -0700747 virtual std::string GetDeviceRpcId(Error* error) const = 0;
Chris Masone95207da2011-06-29 16:50:49 -0700748
Paul Stewart1a212a62015-06-16 13:13:10 -0700749 std::string GetIPConfigRpcIdentifier(Error* error) const;
Paul Stewart10241e32012-04-23 18:15:06 -0700750
Paul Stewart1a212a62015-06-16 13:13:10 -0700751 std::string GetNameProperty(Error* error);
Darin Petkov9c6e9812013-03-26 13:49:07 +0100752 // The base implementation asserts that |name| matches the current Name
753 // property value.
Paul Stewart1a212a62015-06-16 13:13:10 -0700754 virtual bool SetNameProperty(const std::string& name, Error* error);
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700755
Paul Stewart1a212a62015-06-16 13:13:10 -0700756 int32_t GetPriority(Error* error);
757 int32_t GetPriorityWithinTechnology(Error* error);
Paul Stewart0c438332012-04-11 07:55:27 -0700758
Paul Stewart1a212a62015-06-16 13:13:10 -0700759 std::string GetProfileRpcId(Error* error);
760 bool SetProfileRpcId(const std::string& profile, Error* error);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700761
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800762 // Returns TCP port of service's HTTP proxy in host order.
Paul Stewart1a212a62015-06-16 13:13:10 -0700763 uint16_t GetHTTPProxyPort(Error* error) const;
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800764
Paul Stewart1a212a62015-06-16 13:13:10 -0700765 std::string GetProxyConfig(Error* error);
766 bool SetProxyConfig(const std::string& proxy_config, Error* error);
Philipp Neubeck79173602012-11-13 21:10:09 +0100767
Paul Stewart1a212a62015-06-16 13:13:10 -0700768 Strings GetDisconnectsProperty(Error* error) const;
769 Strings GetMisconnectsProperty(Error* error) const;
Darin Petkov0c65bdd2012-12-05 13:42:41 +0100770
Christopher Wiley0801d192012-09-24 11:57:15 -0700771 void ReEnableAutoConnectTask();
772 // Disables autoconnect and posts a task to re-enable it after a cooldown.
773 // Note that autoconnect could be disabled for other reasons as well.
774 void ThrottleFutureAutoConnects();
775
mukesh agrawalcf24a242012-05-21 16:46:11 -0700776 // Saves settings to profile, if we have one. Unlike
777 // SaveServiceToProfile, SaveToProfile never assigns this service
778 // into a profile.
779 void SaveToProfile();
780
Paul Stewart483e4722012-12-18 10:23:17 -0800781 // Qualify the conditions under which the most recent disconnect occurred.
782 // Make note ot the fact that there was a problem connecting / staying
783 // connected if the disconnection did not occur as a clear result of user
784 // action.
Darin Petkov385b9bc2012-12-03 15:25:05 +0100785 void NoteDisconnectEvent();
786
Paul Stewart22aa71b2011-09-16 12:15:11 -0700787 // Utility function that returns true if a is different from b. When they
788 // are, "decision" is populated with the boolean value of "a > b".
Paul Stewart1a212a62015-06-16 13:13:10 -0700789 static bool DecideBetween(int a, int b, bool* decision);
Paul Stewart22aa71b2011-09-16 12:15:11 -0700790
Peter Qiudc4e0992014-05-01 10:02:52 -0700791 // Report the result of user-initiated connection attempt to UMA stats.
792 // Currently only report stats for wifi service.
793 void ReportUserInitiatedConnectionResult(ConnectState state);
794
mukesh agrawal43970a22013-02-15 16:00:07 -0800795 // Linearize security parameters (crypto algorithm, key rotation, endpoint
796 // authentication) for comparison.
Ben Chan7fab8972014-08-10 17:14:46 -0700797 uint16_t SecurityLevel();
mukesh agrawal43970a22013-02-15 16:00:07 -0800798
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700799 // WeakPtrFactory comes first, so that other fields can use it.
800 base::WeakPtrFactory<Service> weak_ptr_factory_;
801
Paul Stewartac4ac002011-08-26 12:04:26 -0700802 ConnectState state_;
Darin Petkovc8d91e52013-01-21 11:43:47 +0100803 ConnectState previous_state_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700804 ConnectFailure failure_;
805 bool auto_connect_;
Paul Stewart2da34c02013-10-17 15:28:56 -0700806
807 // Denotes whether the value of auto_connect_ property value should be
808 // retained, i.e. only be allowed to change via explicit property changes
809 // from the UI.
810 bool retain_auto_connect_;
811
Paul Stewartac4ac002011-08-26 12:04:26 -0700812 std::string check_portal_;
813 bool connectable_;
814 std::string error_;
Darin Petkovaba89322013-03-11 14:48:22 +0100815 std::string error_details_;
Paul Stewartd7c09a52014-02-19 12:50:29 -0800816 std::string previous_error_;
Ben Chan7fab8972014-08-10 17:14:46 -0700817 int32_t previous_error_serial_number_;
mukesh agrawaladb68482012-01-17 16:31:51 -0800818 bool explicitly_disconnected_;
Peter Qiudc4e0992014-05-01 10:02:52 -0700819 bool is_in_user_connect_;
Ben Chan7fab8972014-08-10 17:14:46 -0700820 int32_t priority_;
Paul Stewartd9c7cfc2015-01-06 14:26:22 -0800821 int32_t priority_within_technology_;
Ben Chan7fab8972014-08-10 17:14:46 -0700822 uint8_t crypto_algorithm_;
mukesh agrawal43970a22013-02-15 16:00:07 -0800823 bool key_rotation_;
824 bool endpoint_auth_;
Peter Qiu9b83c892014-08-09 23:06:02 -0700825 std::string portal_detection_failure_phase_;
826 std::string portal_detection_failure_status_;
mukesh agrawal43970a22013-02-15 16:00:07 -0800827
Ben Chan7fab8972014-08-10 17:14:46 -0700828 uint8_t strength_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700829 std::string proxy_config_;
Paul Stewart987e71e2011-12-05 09:45:06 -0800830 std::string ui_data_;
Paul Stewart4c561612012-03-21 12:49:01 -0700831 std::string guid_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700832 bool save_credentials_;
Peter Qiu1a72f542015-04-14 16:31:36 -0700833#if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X)
Ben Chancd477322014-10-17 14:19:30 -0700834 std::unique_ptr<EapCredentials> eap_;
Peter Qiu1a72f542015-04-14 16:31:36 -0700835#endif // DISABLE_WIFI || DISABLE_WIRED_8021X
Gaurav Shah435de2c2011-11-17 19:01:07 -0800836 Technology::Identifier technology_;
mukesh agrawal568b5c62012-02-28 14:44:47 -0800837 // The time of the most recent failure. Value is 0 if the service is
838 // not currently failed.
839 time_t failed_time_;
mukesh agrawalcf24a242012-05-21 16:46:11 -0700840 // Whether or not this service has ever reached kStateConnected.
841 bool has_ever_connected_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700842
Samuel Tan07dfabc2015-01-20 15:10:39 -0800843 EventHistory disconnects_; // Connection drops.
844 EventHistory misconnects_; // Failures to connect.
Darin Petkov385b9bc2012-12-03 15:25:05 +0100845
Christopher Wiley0801d192012-09-24 11:57:15 -0700846 base::CancelableClosure reenable_auto_connect_task_;
Ben Chan7fab8972014-08-10 17:14:46 -0700847 uint64_t auto_connect_cooldown_milliseconds_;
Christopher Wiley0801d192012-09-24 11:57:15 -0700848
Paul Stewartac4ac002011-08-26 12:04:26 -0700849 ProfileRefPtr profile_;
850 PropertyStore store_;
Paul Stewartcb59fed2012-03-21 21:14:46 -0700851 std::set<std::string> parameters_ignored_for_configure_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700852
Paul Stewart1a212a62015-06-16 13:13:10 -0700853 EventDispatcher* dispatcher_;
mukesh agrawale37ad322013-10-08 16:33:56 -0700854 unsigned int serial_number_;
mukesh agrawald835b202011-10-07 15:26:47 -0700855 std::string unique_name_; // MUST be unique amongst service instances
Darin Petkov457728b2013-01-09 09:49:08 +0100856
857 // Service's friendly name is presented through the UI. By default it's the
858 // same as |unique_name_| but normally Service subclasses override
859 // it. WARNING: Don't log the friendly name at the default logging level due
860 // to PII concerns.
861 std::string friendly_name_;
862
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700863 // List of subject names reported by remote entity during TLS setup.
864 std::vector<std::string> remote_certification_;
865
Ben Chancd477322014-10-17 14:19:30 -0700866 std::unique_ptr<ServiceAdaptorInterface> adaptor_;
867 std::unique_ptr<ServicePropertyChangeNotifier> property_change_notifier_;
868 std::unique_ptr<HTTPProxy> http_proxy_;
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800869 ConnectionRefPtr connection_;
Paul Stewart1062d9d2012-04-27 10:42:27 -0700870 StaticIPParameters static_ip_parameters_;
Paul Stewart1a212a62015-06-16 13:13:10 -0700871 Metrics* metrics_;
872 Manager* manager_;
Ben Chancd477322014-10-17 14:19:30 -0700873 std::unique_ptr<Sockets> sockets_;
Paul Stewart1a212a62015-06-16 13:13:10 -0700874 Time* time_;
875 DiagnosticsReporter* diagnostics_reporter_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700876
mukesh agrawale37ad322013-10-08 16:33:56 -0700877 // The |serial_number_| for the next Service.
878 static unsigned int next_serial_number_;
879
Peter Qiu9d581932014-04-14 16:37:37 -0700880 // Network identifier indicating the network (gateway) the service is
881 // connected to.
882 int connection_id_;
Peter Qiua89154b2014-05-23 15:45:42 -0700883 // When set to true, this service will automatically fallback to Google's DNS
884 // servers if the portal detection failed due to DNS failure and Google's DNS
885 // servers are working.
886 bool is_dns_auto_fallback_allowed_;
Peter Qiud49760e2014-09-19 16:13:42 -0700887 // When set to true, will not start link monitor when the connection to this
888 // service is established.
889 bool link_monitor_disabled_;
Paul Stewart3fee7e32014-10-15 21:39:29 -0700890 // When set to true, the credentials for this service will be considered
891 // valid, and will not require an initial connection to rank it highly for
892 // auto-connect.
893 bool managed_credentials_;
Peter Qiua388fdb2015-04-03 10:31:22 -0700894 // Flag indicating if this service is unreliable (experiencing multiple
895 // link monitor failures in a short period of time).
896 bool unreliable_;
Peter Qiu9d581932014-04-14 16:37:37 -0700897
mukesh agrawalb54601c2011-06-07 17:39:22 -0700898 DISALLOW_COPY_AND_ASSIGN(Service);
Paul Stewart75897df2011-04-27 09:05:53 -0700899};
900
901} // namespace shill
902
Ben Chan19f83972012-10-03 23:25:56 -0700903#endif // SHILL_SERVICE_H_