mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 5 | #ifndef SHILL_SERVICE_ |
| 6 | #define SHILL_SERVICE_ |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 7 | |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 8 | #include <time.h> |
| 9 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 10 | #include <string> |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 11 | #include <map> |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 12 | #include <set> |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 13 | #include <vector> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 14 | |
| 15 | #include <base/memory/ref_counted.h> |
Paul Stewart | ba41b99 | 2011-05-26 07:02:46 -0700 | [diff] [blame] | 16 | #include <base/memory/scoped_ptr.h> |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 17 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 18 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 19 | #include "shill/adaptor_interfaces.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 20 | #include "shill/accessor_interface.h" |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 21 | #include "shill/callbacks.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 22 | #include "shill/property_store.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 23 | #include "shill/refptr_types.h" |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 24 | #include "shill/sockets.h" |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 25 | #include "shill/technology.h" |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 26 | |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 27 | namespace chromeos_metrics { |
| 28 | class Timer; |
| 29 | } |
| 30 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 31 | namespace shill { |
| 32 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 33 | class Configuration; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 34 | class ControlInterface; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 35 | class Endpoint; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 36 | class Error; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 37 | class EventDispatcher; |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 38 | class HTTPProxy; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 39 | class KeyValueStore; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 40 | class Manager; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 41 | class Metrics; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 42 | class ServiceAdaptorInterface; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 43 | class StoreInterface; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 44 | |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 45 | // A Service is a uniquely named entity, which the system can |
| 46 | // connect in order to begin sending and receiving network traffic. |
| 47 | // All Services are bound to an Entry, which represents the persistable |
| 48 | // state of the Service. If the Entry is populated at the time of Service |
| 49 | // creation, that information is used to prime the Service. If not, the Entry |
| 50 | // becomes populated over time. |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 51 | class Service : public base::RefCounted<Service> { |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 52 | public: |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 53 | static const char kCheckPortalAuto[]; |
| 54 | static const char kCheckPortalFalse[]; |
| 55 | static const char kCheckPortalTrue[]; |
| 56 | |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 57 | // TODO(pstew): Storage constants shouldn't need to be public |
| 58 | // crosbug.com/25813 |
| 59 | static const char kStorageAutoConnect[]; |
| 60 | static const char kStorageCheckPortal[]; |
| 61 | static const char kStorageEapAnonymousIdentity[]; |
| 62 | static const char kStorageEapCACert[]; |
| 63 | static const char kStorageEapCACertID[]; |
| 64 | static const char kStorageEapCertID[]; |
| 65 | static const char kStorageEapClientCert[]; |
| 66 | static const char kStorageEapEap[]; |
| 67 | static const char kStorageEapIdentity[]; |
| 68 | static const char kStorageEapInnerEap[]; |
| 69 | static const char kStorageEapKeyID[]; |
| 70 | static const char kStorageEapKeyManagement[]; |
| 71 | static const char kStorageEapPIN[]; |
| 72 | static const char kStorageEapPassword[]; |
| 73 | static const char kStorageEapPrivateKey[]; |
| 74 | static const char kStorageEapPrivateKeyPassword[]; |
| 75 | static const char kStorageEapUseSystemCAs[]; |
| 76 | static const char kStorageError[]; |
| 77 | static const char kStorageFavorite[]; |
| 78 | static const char kStorageGUID[]; |
| 79 | static const char kStorageName[]; |
| 80 | static const char kStoragePriority[]; |
| 81 | static const char kStorageProxyConfig[]; |
| 82 | static const char kStorageSaveCredentials[]; |
| 83 | static const char kStorageType[]; |
| 84 | static const char kStorageUIData[]; |
| 85 | |
mukesh agrawal | 8f3f775 | 2012-02-17 19:42:09 -0800 | [diff] [blame] | 86 | static const uint8 kStrengthMax; |
| 87 | static const uint8 kStrengthMin; |
| 88 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 89 | enum ConnectFailure { |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 90 | kFailureUnknown, |
| 91 | kFailureActivationFailure, |
| 92 | kFailureOutOfRange, |
| 93 | kFailurePinMissing, |
| 94 | kFailureConfigurationFailed, |
| 95 | kFailureBadCredentials, |
| 96 | kFailureNeedEVDO, |
| 97 | kFailureNeedHomeNetwork, |
| 98 | kFailureOTASPFailure, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 99 | kFailureAAAFailure, |
| 100 | kFailureMax |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 101 | }; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 102 | enum ConnectState { |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 103 | kStateUnknown, |
| 104 | kStateIdle, |
| 105 | kStateAssociating, |
| 106 | kStateConfiguring, |
| 107 | kStateConnected, |
| 108 | kStateDisconnected, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 109 | kStatePortal, |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 110 | kStateFailure, |
| 111 | kStateOnline |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 112 | }; |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 113 | struct EapCredentials { |
| 114 | EapCredentials() : use_system_cas(false) {} |
| 115 | std::string identity; |
| 116 | std::string eap; |
| 117 | std::string inner_eap; |
| 118 | std::string anonymous_identity; |
| 119 | std::string client_cert; |
| 120 | std::string cert_id; |
| 121 | std::string private_key; |
| 122 | std::string private_key_password; |
| 123 | std::string key_id; |
| 124 | std::string ca_cert; |
| 125 | std::string ca_cert_id; |
| 126 | bool use_system_cas; |
| 127 | std::string pin; |
| 128 | std::string password; |
| 129 | std::string key_management; |
| 130 | }; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 131 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 132 | static const int kPriorityNone; |
| 133 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 134 | // A constructor for the Service object |
| 135 | Service(ControlInterface *control_interface, |
| 136 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 137 | Metrics *metrics, |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 138 | Manager *manager, |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 139 | Technology::Identifier technology); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 140 | virtual ~Service(); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 141 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 142 | // AutoConnect MAY choose to ignore the connection request in some |
| 143 | // cases. For example, if the corresponding Device only supports one |
| 144 | // concurrent connection, and another Service is already connected |
| 145 | // or connecting. |
| 146 | // |
| 147 | // AutoConnect MAY issue RPCs immediately. So AutoConnect MUST NOT |
| 148 | // be called from a D-Bus signal handler context. |
| 149 | virtual void AutoConnect(); |
| 150 | // Queue up a connection attempt. |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 151 | virtual void Connect(Error *error); |
| 152 | // Disconnect this service. The service will not be eligible for |
| 153 | // auto-connect until a subsequent call to Connect, or Load. |
| 154 | virtual void Disconnect(Error *error); |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 155 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 156 | // The default implementation returns the error kInvalidArguments. |
| 157 | virtual void ActivateCellularModem(const std::string &carrier, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 158 | Error *error, |
| 159 | const ResultCallback &callback); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 160 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 161 | // Base method always returns false. |
| 162 | virtual bool TechnologyIs(const Technology::Identifier type) const; |
| 163 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 164 | virtual bool IsActive(Error *error); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 165 | |
| 166 | virtual ConnectState state() const { return state_; } |
| 167 | // Updates the state of the Service and alerts the manager. Also |
| 168 | // clears |failure_| if the new state isn't a failure. |
| 169 | virtual void SetState(ConnectState state); |
| 170 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 171 | // State utility functions |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 172 | virtual bool IsConnected() const { |
| 173 | return state() == kStateConnected || state() == kStatePortal || |
| 174 | state() == kStateOnline; |
| 175 | } |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 176 | virtual bool IsConnecting() const { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 177 | return state() == kStateAssociating || state() == kStateConfiguring; |
| 178 | } |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 179 | virtual bool IsFailed() const { |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 180 | // We sometimes lie about the failure state, to keep Chrome happy |
| 181 | // (see comment in WiFi::HandleDisconnect). Hence, we check both |
| 182 | // state and |failed_time_|. |
| 183 | return state() == kStateFailure || failed_time_ > 0; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 184 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 185 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 186 | virtual ConnectFailure failure() const { return failure_; } |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 187 | // Records the failure mode and time. Sets the Service state to "Failure". |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 188 | virtual void SetFailure(ConnectFailure failure); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 189 | // Records the failure mode and time. Sets the Service state to "Idle". |
| 190 | // Avoids showing a failure mole in the UI. |
| 191 | virtual void SetFailureSilent(ConnectFailure failure); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 192 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 193 | // Returns a string that is guaranteed to uniquely identify this Service |
| 194 | // instance. |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 195 | const std::string &UniqueName() const { return unique_name_; } |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 196 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 197 | virtual std::string GetRpcIdentifier() const; |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 198 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 199 | // Returns the unique persistent storage identifier for the service. |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 200 | virtual std::string GetStorageIdentifier() const = 0; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 201 | |
Paul Stewart | bba6a5b | 2011-11-02 18:45:59 -0700 | [diff] [blame] | 202 | // Returns whether the service configuration can be loaded from |storage|. |
| 203 | virtual bool IsLoadableFrom(StoreInterface *storage) const; |
| 204 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 205 | // Loads the service from persistent |storage|. Returns true on success. |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 206 | virtual bool Load(StoreInterface *storage); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 207 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 208 | // Indicate to service that it is no longer persisted to storage. It |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 209 | // should purge any stored profile state (e.g., credentials). Returns |
| 210 | // true to indicate that this service should also be unregistered from |
| 211 | // the manager, false otherwise. |
| 212 | virtual bool Unload(); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 213 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 214 | // Saves the service to persistent |storage|. Returns true on success. |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 215 | virtual bool Save(StoreInterface *storage); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 216 | |
Thieu Le | d4e9e55 | 2012-02-16 16:26:07 -0800 | [diff] [blame] | 217 | // Saves the service to the current profile. |
| 218 | virtual bool SaveToCurrentProfile(); |
| 219 | |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 220 | // Applies all the properties in |args| to this service object's mutable |
| 221 | // store, except for those in parameters_ignored_for_configure_. |
| 222 | // Returns an error in |error| if one or more parameter set attempts |
| 223 | // fails, but will only return the first error. |
| 224 | virtual void Configure(const KeyValueStore &args, Error *error); |
| 225 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 226 | // Returns true if the service RPC identifier should be part of the |
| 227 | // manager's advertised services list, false otherwise. |
| 228 | virtual bool IsVisible() const { return true; } |
| 229 | |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 230 | // Returns true if there is a proxy configuration set on this service. |
| 231 | virtual bool HasProxyConfig() const { return !proxy_config_.empty(); } |
| 232 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 233 | virtual void MakeFavorite(); |
| 234 | |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 235 | // Set the connection for this service. If the connection is |
| 236 | // non-NULL, create an HTTP Proxy that will utilize this service's |
| 237 | // connection to serve requests. |
| 238 | virtual void SetConnection(ConnectionRefPtr connection); |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 239 | |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 240 | // Examines the EAP credentials for the service and returns true if a |
| 241 | // connection attempt can be made. |
| 242 | bool Is8021xConnectable() const; |
| 243 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 244 | // The inherited class should register any custom metrics in this method. |
| 245 | virtual void InitializeCustomMetrics() const {} |
| 246 | |
| 247 | // The inherited class that needs to send metrics after the service has |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 248 | // transitioned to the ready state should override this method. |
| 249 | // |time_resume_to_ready_milliseconds| holds the elapsed time from when |
| 250 | // the system was resumed until when the service transitioned to the |
| 251 | // connected state. This value is non-zero for the first service transition |
| 252 | // to the connected state after a resume. |
| 253 | virtual void SendPostReadyStateMetrics( |
| 254 | int64 /*time_resume_to_ready_milliseconds*/) const {} |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 255 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 256 | bool auto_connect() const { return auto_connect_; } |
| 257 | void set_auto_connect(bool connect) { auto_connect_ = connect; } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 258 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 259 | bool connectable() const { return connectable_; } |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 260 | void set_connectable(bool connectable); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 261 | |
Thieu Le | 67370f6 | 2012-02-14 23:01:42 +0000 | [diff] [blame] | 262 | virtual bool explicitly_disconnected() const { |
| 263 | return explicitly_disconnected_; |
| 264 | } |
| 265 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 266 | bool favorite() const { return favorite_; } |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 267 | // Setter is deliberately omitted; use MakeFavorite. |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 268 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 269 | const std::string &friendly_name() const { return friendly_name_; } |
Darin Petkov | 7f06033 | 2012-03-14 11:46:47 +0100 | [diff] [blame] | 270 | void set_friendly_name(const std::string &n) { friendly_name_ = n; } |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 271 | |
Paul Stewart | 4c56161 | 2012-03-21 12:49:01 -0700 | [diff] [blame] | 272 | const std::string &guid() const { return guid_; } |
| 273 | void set_guid(const std::string &guid) { guid_ = guid; } |
| 274 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 275 | int32 priority() const { return priority_; } |
| 276 | void set_priority(int32 priority) { priority_ = priority; } |
| 277 | |
Paul Stewart | 1ca3e85 | 2011-11-04 07:50:49 -0700 | [diff] [blame] | 278 | int32 security_level() const { return security_level_; } |
| 279 | void set_security_level(int32 security) { security_level_ = security; } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 280 | |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 281 | void SetStrength(uint8 strength); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 282 | |
| 283 | // uint8 streams out as a char. Coerce to a larger type, so that |
| 284 | // it prints as a number. |
| 285 | uint16 strength() const { return strength_; } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 286 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 287 | virtual Technology::Identifier technology() const { return technology_; } |
| 288 | std::string GetTechnologyString(Error *error); |
| 289 | |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 290 | const EapCredentials &eap() const { return eap_; } |
| 291 | virtual void set_eap(const EapCredentials &eap); |
| 292 | |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 293 | const std::string &error() const { return error_; } |
| 294 | void set_error(const std::string &error) { error_ = error; } |
| 295 | |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 296 | static const char *ConnectFailureToString(const ConnectFailure &state); |
| 297 | static const char *ConnectStateToString(const ConnectState &state); |
| 298 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 299 | // Compare two services. Returns true if Service a should be displayed |
| 300 | // above Service b |
| 301 | static bool Compare(ServiceRefPtr a, |
| 302 | ServiceRefPtr b, |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 303 | const std::vector<Technology::Identifier> &tech_order, |
| 304 | const char **reason); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 305 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 306 | // These are defined in service.cc so that we don't have to include profile.h |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 307 | // TODO(cmasone): right now, these are here only so that we can get the |
| 308 | // profile name as a property. Can we store just the name, and then handle |
| 309 | // setting the profile for this service via |manager_|? |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 310 | const ProfileRefPtr &profile() const; |
| 311 | void set_profile(const ProfileRefPtr &p); |
| 312 | |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 313 | PropertyStore *mutable_store() { return &store_; } |
| 314 | const PropertyStore &store() const { return store_; } |
Paul Stewart | ce4ec19 | 2012-03-14 12:53:46 -0700 | [diff] [blame] | 315 | virtual const ConnectionRefPtr &connection() const { return connection_; } |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 316 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 317 | protected: |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 318 | // Returns true if a character is allowed to be in a service storage id. |
| 319 | static bool LegalChar(char a) { return isalnum(a) || a == '_'; } |
| 320 | |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 321 | // Returns true if a character is disallowed to be in a service storage id. |
| 322 | static bool IllegalChar(char a) { return !LegalChar(a); } |
| 323 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 324 | virtual std::string CalculateState(Error *error); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 325 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 326 | // Returns whether this service is in a state conducive to auto-connect. |
| 327 | // This should include any tests used for computing connectable(), |
| 328 | // as well as other critera such as whether the device associated with |
| 329 | // this service is busy with another connection. |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 330 | // |
| 331 | // If the service is not auto-connectable, |*reason| will be set to |
| 332 | // point to C-string explaining why the service is not auto-connectable. |
| 333 | virtual bool IsAutoConnectable(const char **reason) const; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 334 | |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 335 | // HelpRegisterDerived*: Expose a property over RPC, with the name |name|. |
| 336 | // |
| 337 | // Reads of the property will be handled by invoking |get|. |
| 338 | // Writes to the property will be handled by invoking |set|. |
| 339 | // Clearing the property will be handled by PropertyStore. |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 340 | void HelpRegisterDerivedBool( |
| 341 | const std::string &name, |
Hristo Stefanov | ed2c28c | 2011-11-29 15:37:30 -0800 | [diff] [blame] | 342 | bool(Service::*get)(Error *error), |
| 343 | void(Service::*set)(const bool &value, Error *error)); |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 344 | void HelpRegisterDerivedString( |
| 345 | const std::string &name, |
Hristo Stefanov | ed2c28c | 2011-11-29 15:37:30 -0800 | [diff] [blame] | 346 | std::string(Service::*get)(Error *error), |
| 347 | void(Service::*set)(const std::string &value, Error *error)); |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 348 | void HelpRegisterDerivedUint16( |
| 349 | const std::string &name, |
| 350 | uint16(Service::*get)(Error *error), |
| 351 | void(Service::*set)(const uint16 &value, Error *error)); |
Jason Glasgow | acdc11f | 2012-03-30 14:12:22 -0400 | [diff] [blame] | 352 | void HelpRegisterDerivedRpcIdentifier( |
| 353 | const std::string &name, |
| 354 | std::string(Service::*get)(Error *), |
| 355 | void(Service::*set)(const RpcIdentifier&, Error *)); |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 356 | // Expose a property over RPC, with the name |name|. |
| 357 | // |
| 358 | // Reads of the property will be handled by invoking |get|. |
| 359 | // Writes to the property will be handled by invoking |set|. |
| 360 | // |
| 361 | // Clearing the property will be handled by invoking |clear|, or |
| 362 | // calling |set| with |default_value| (whichever is non-NULL). It |
| 363 | // is an error to call this method with both |clear| and |
| 364 | // |default_value| non-NULL. |
| 365 | void HelpRegisterWriteOnlyDerivedString( |
| 366 | const std::string &name, |
| 367 | void(Service::*set)(const std::string &value, Error *error), |
| 368 | void(Service::*clear)(Error *error), |
| 369 | const std::string *default_value); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 370 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 371 | ServiceAdaptorInterface *adaptor() const { return adaptor_.get(); } |
| 372 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 373 | // Assigns |value| to |key| in |storage| if |value| is non-empty and |save| is |
| 374 | // true. Otherwise, removes |key| from |storage|. If |crypted| is true, the |
| 375 | // value is encrypted. |
| 376 | void SaveString(StoreInterface *storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 377 | const std::string &id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 378 | const std::string &key, |
| 379 | const std::string &value, |
| 380 | bool crypted, |
| 381 | bool save); |
| 382 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 383 | void LoadEapCredentials(StoreInterface *storage, const std::string &id); |
| 384 | void SaveEapCredentials(StoreInterface *storage, const std::string &id); |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 385 | void UnloadEapCredentials(); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 386 | |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 387 | // Ignore |parameter| when performing a Configure() operation. |
| 388 | void IgnoreParameterForConfigure(const std::string ¶meter); |
| 389 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 390 | // Property accessors reserved for subclasses |
| 391 | EventDispatcher *dispatcher() const { return dispatcher_; } |
| 392 | const std::string &GetEAPKeyManagement() const; |
| 393 | void SetEAPKeyManagement(const std::string &key_management); |
Paul Stewart | 9f32d19 | 2012-01-30 20:37:50 -0800 | [diff] [blame] | 394 | void SetEAPPassword(const std::string &password, Error *error); |
| 395 | void SetEAPPrivateKeyPassword(const std::string &password, Error *error); |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 396 | Manager *manager() const { return manager_; } |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 397 | Metrics *metrics() const { return metrics_; } |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 398 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 399 | private: |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 400 | friend class MetricsTest; |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 401 | friend class ServiceAdaptorInterface; |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 402 | friend class WiFiServiceTest; |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 403 | FRIEND_TEST(ServiceTest, ConfigureIgnoredProperty); |
| 404 | FRIEND_TEST(ServiceTest, ConfigureStringProperty); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 405 | FRIEND_TEST(ServiceTest, Constructor); |
Thieu Le | 284fe79 | 2012-01-31 17:53:19 -0800 | [diff] [blame] | 406 | FRIEND_TEST(ServiceTest, GetProperties); |
mukesh agrawal | 76d1388 | 2012-01-12 15:23:11 -0800 | [diff] [blame] | 407 | FRIEND_TEST(ServiceTest, IsAutoConnectable); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 408 | FRIEND_TEST(ServiceTest, Save); |
| 409 | FRIEND_TEST(ServiceTest, SaveString); |
| 410 | FRIEND_TEST(ServiceTest, SaveStringCrypted); |
| 411 | FRIEND_TEST(ServiceTest, SaveStringDontSave); |
| 412 | FRIEND_TEST(ServiceTest, SaveStringEmpty); |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 413 | FRIEND_TEST(ServiceTest, SetProperty); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 414 | FRIEND_TEST(ServiceTest, State); |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 415 | FRIEND_TEST(ServiceTest, Unload); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 416 | |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 417 | static const char kAutoConnConnected[]; |
| 418 | static const char kAutoConnConnecting[]; |
| 419 | static const char kAutoConnExplicitDisconnect[]; |
| 420 | static const char kAutoConnNotConnectable[]; |
| 421 | |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 422 | static const char kServiceSortConnectEtc[]; |
| 423 | static const char kServiceSortIsConnected[]; |
| 424 | static const char kServiceSortIsConnecting[]; |
| 425 | static const char kServiceSortIsFailed[]; |
| 426 | static const char kServiceSortTechnology[]; |
| 427 | static const char kServiceSortSecurityEtc[]; |
| 428 | static const char kServiceSortUniqueName[]; |
| 429 | |
Thieu Le | 284fe79 | 2012-01-31 17:53:19 -0800 | [diff] [blame] | 430 | bool GetAutoConnect(Error *error); |
| 431 | void SetAutoConnect(const bool &connect, Error *error); |
| 432 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 433 | virtual std::string GetDeviceRpcId(Error *error) = 0; |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 434 | |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 435 | std::string GetProfileRpcId(Error *error); |
| 436 | void SetProfileRpcId(const std::string &profile, Error *error); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 437 | |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 438 | // Returns TCP port of service's HTTP proxy in host order. |
| 439 | uint16 GetHTTPProxyPort(Error *error); |
| 440 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 441 | // Utility function that returns true if a is different from b. When they |
| 442 | // are, "decision" is populated with the boolean value of "a > b". |
| 443 | static bool DecideBetween(int a, int b, bool *decision); |
| 444 | |
Thieu Le | 284fe79 | 2012-01-31 17:53:19 -0800 | [diff] [blame] | 445 | // For unit testing. |
| 446 | void set_favorite(bool favorite) { favorite_ = favorite; } |
| 447 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 448 | ConnectState state_; |
| 449 | ConnectFailure failure_; |
| 450 | bool auto_connect_; |
| 451 | std::string check_portal_; |
| 452 | bool connectable_; |
| 453 | std::string error_; |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 454 | bool explicitly_disconnected_; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 455 | bool favorite_; |
| 456 | int32 priority_; |
Paul Stewart | 1ca3e85 | 2011-11-04 07:50:49 -0700 | [diff] [blame] | 457 | int32 security_level_; |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 458 | uint8 strength_; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 459 | std::string proxy_config_; |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 460 | std::string ui_data_; |
Paul Stewart | 4c56161 | 2012-03-21 12:49:01 -0700 | [diff] [blame] | 461 | std::string guid_; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 462 | bool save_credentials_; |
| 463 | EapCredentials eap_; // Only saved if |save_credentials_| is true. |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 464 | Technology::Identifier technology_; |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 465 | // The time of the most recent failure. Value is 0 if the service is |
| 466 | // not currently failed. |
| 467 | time_t failed_time_; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 468 | |
| 469 | ProfileRefPtr profile_; |
| 470 | PropertyStore store_; |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 471 | std::set<std::string> parameters_ignored_for_configure_; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 472 | |
| 473 | EventDispatcher *dispatcher_; |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 474 | static unsigned int serial_number_; |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 475 | std::string unique_name_; // MUST be unique amongst service instances |
| 476 | std::string friendly_name_; // MAY be same as |unique_name_| |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 477 | bool available_; |
| 478 | bool configured_; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 479 | Configuration *configuration_; |
Paul Stewart | ba41b99 | 2011-05-26 07:02:46 -0700 | [diff] [blame] | 480 | scoped_ptr<ServiceAdaptorInterface> adaptor_; |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 481 | scoped_ptr<HTTPProxy> http_proxy_; |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 482 | ConnectionRefPtr connection_; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 483 | Metrics *metrics_; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 484 | Manager *manager_; |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 485 | Sockets sockets_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 486 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 487 | DISALLOW_COPY_AND_ASSIGN(Service); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 488 | }; |
| 489 | |
| 490 | } // namespace shill |
| 491 | |
| 492 | #endif // SHILL_SERVICE_ |