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 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 8 | #include <string> |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 9 | #include <map> |
| 10 | #include <vector> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 11 | |
| 12 | #include <base/memory/ref_counted.h> |
Paul Stewart | ba41b99 | 2011-05-26 07:02:46 -0700 | [diff] [blame] | 13 | #include <base/memory/scoped_ptr.h> |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 14 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 15 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 16 | #include "shill/accessor_interface.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 17 | #include "shill/property_store.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 18 | #include "shill/refptr_types.h" |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 19 | #include "shill/sockets.h" |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 20 | #include "shill/technology.h" |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 21 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 22 | namespace shill { |
| 23 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 24 | class Configuration; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 25 | class ControlInterface; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 26 | class Endpoint; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 27 | class Error; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 28 | class EventDispatcher; |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 29 | class HTTPProxy; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 30 | class KeyValueStore; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 31 | class Manager; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 32 | class Metrics; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 33 | class ServiceAdaptorInterface; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 34 | class StoreInterface; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 35 | |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 36 | // A Service is a uniquely named entity, which the system can |
| 37 | // connect in order to begin sending and receiving network traffic. |
| 38 | // All Services are bound to an Entry, which represents the persistable |
| 39 | // state of the Service. If the Entry is populated at the time of Service |
| 40 | // creation, that information is used to prime the Service. If not, the Entry |
| 41 | // becomes populated over time. |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 42 | class Service : public base::RefCounted<Service> { |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 43 | public: |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 44 | static const char kCheckPortalAuto[]; |
| 45 | static const char kCheckPortalFalse[]; |
| 46 | static const char kCheckPortalTrue[]; |
| 47 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 48 | enum ConnectFailure { |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 49 | kFailureUnknown, |
| 50 | kFailureActivationFailure, |
| 51 | kFailureOutOfRange, |
| 52 | kFailurePinMissing, |
| 53 | kFailureConfigurationFailed, |
| 54 | kFailureBadCredentials, |
| 55 | kFailureNeedEVDO, |
| 56 | kFailureNeedHomeNetwork, |
| 57 | kFailureOTASPFailure, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 58 | kFailureAAAFailure, |
| 59 | kFailureMax |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 60 | }; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 61 | enum ConnectState { |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 62 | kStateUnknown, |
| 63 | kStateIdle, |
| 64 | kStateAssociating, |
| 65 | kStateConfiguring, |
| 66 | kStateConnected, |
| 67 | kStateDisconnected, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 68 | kStateReady, |
| 69 | kStatePortal, |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 70 | kStateFailure, |
| 71 | kStateOnline |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 72 | }; |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 73 | struct EapCredentials { |
| 74 | EapCredentials() : use_system_cas(false) {} |
| 75 | std::string identity; |
| 76 | std::string eap; |
| 77 | std::string inner_eap; |
| 78 | std::string anonymous_identity; |
| 79 | std::string client_cert; |
| 80 | std::string cert_id; |
| 81 | std::string private_key; |
| 82 | std::string private_key_password; |
| 83 | std::string key_id; |
| 84 | std::string ca_cert; |
| 85 | std::string ca_cert_id; |
| 86 | bool use_system_cas; |
| 87 | std::string pin; |
| 88 | std::string password; |
| 89 | std::string key_management; |
| 90 | }; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 91 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 92 | static const int kPriorityNone; |
| 93 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 94 | // A constructor for the Service object |
| 95 | Service(ControlInterface *control_interface, |
| 96 | EventDispatcher *dispatcher, |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 97 | Manager *manager, |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 98 | Technology::Identifier technology); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 99 | virtual ~Service(); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 100 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 101 | // AutoConnect MAY choose to ignore the connection request in some |
| 102 | // cases. For example, if the corresponding Device only supports one |
| 103 | // concurrent connection, and another Service is already connected |
| 104 | // or connecting. |
| 105 | // |
| 106 | // AutoConnect MAY issue RPCs immediately. So AutoConnect MUST NOT |
| 107 | // be called from a D-Bus signal handler context. |
| 108 | virtual void AutoConnect(); |
| 109 | // Queue up a connection attempt. |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 110 | virtual void Connect(Error *error) = 0; |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 111 | virtual void Disconnect(Error *error) = 0; |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 112 | |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 113 | // The default implementation sets |error| to kInvalidArguments. |
| 114 | virtual void ActivateCellularModem(const std::string &carrier, Error *error); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 115 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 116 | // Base method always returns false. |
| 117 | virtual bool TechnologyIs(const Technology::Identifier type) const; |
| 118 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 119 | virtual bool IsActive(Error *error); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 120 | |
| 121 | virtual ConnectState state() const { return state_; } |
| 122 | // Updates the state of the Service and alerts the manager. Also |
| 123 | // clears |failure_| if the new state isn't a failure. |
| 124 | virtual void SetState(ConnectState state); |
| 125 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 126 | // State utility functions |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 127 | virtual bool IsConnected() const { return state() == kStateConnected; } |
| 128 | virtual bool IsConnecting() const { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 129 | return state() == kStateAssociating || state() == kStateConfiguring; |
| 130 | } |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 131 | virtual bool IsFailed() const { |
| 132 | return state() == kStateFailure; |
| 133 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 134 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 135 | virtual ConnectFailure failure() const { return failure_; } |
| 136 | // Records the failure mode, and sets the Service state to "Failure". |
| 137 | virtual void SetFailure(ConnectFailure failure); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 138 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 139 | // Returns a string that is guaranteed to uniquely identify this Service |
| 140 | // instance. |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 141 | const std::string &UniqueName() const { return unique_name_; } |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 142 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 143 | virtual std::string GetRpcIdentifier() const; |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 144 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 145 | // Returns the unique persistent storage identifier for the service. |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 146 | virtual std::string GetStorageIdentifier() const = 0; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 147 | |
Paul Stewart | bba6a5b | 2011-11-02 18:45:59 -0700 | [diff] [blame] | 148 | // Returns whether the service configuration can be loaded from |storage|. |
| 149 | virtual bool IsLoadableFrom(StoreInterface *storage) const; |
| 150 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 151 | // Loads the service from persistent |storage|. Returns true on success. |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 152 | virtual bool Load(StoreInterface *storage); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 153 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 154 | // Indicate to service that it is no longer persisted to storage. It |
| 155 | // should purge any stored profile state (e.g., credentials). |
| 156 | virtual void Unload(); |
| 157 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 158 | // Saves the service to persistent |storage|. Returns true on success. |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 159 | virtual bool Save(StoreInterface *storage); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 160 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 161 | // Returns true if the service RPC identifier should be part of the |
| 162 | // manager's advertised services list, false otherwise. |
| 163 | virtual bool IsVisible() const { return true; } |
| 164 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 165 | virtual void MakeFavorite(); |
| 166 | |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 167 | // Set the connection for this service. If the connection is |
| 168 | // non-NULL, create an HTTP Proxy that will utilize this service's |
| 169 | // connection to serve requests. |
| 170 | virtual void SetConnection(ConnectionRefPtr connection); |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 171 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 172 | // The inherited class should register any custom metrics in this method. |
| 173 | virtual void InitializeCustomMetrics() const {} |
| 174 | |
| 175 | // The inherited class that needs to send metrics after the service has |
| 176 | // transitioned to the ready state. |
| 177 | virtual void SendPostReadyStateMetrics() const {} |
| 178 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 179 | bool auto_connect() const { return auto_connect_; } |
| 180 | void set_auto_connect(bool connect) { auto_connect_ = connect; } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 181 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 182 | bool connectable() const { return connectable_; } |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 183 | void set_connectable(bool connectable); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 184 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 185 | bool favorite() const { return favorite_; } |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 186 | // Setter is deliberately omitted; use MakeFavorite. |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 187 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 188 | const std::string &friendly_name() const { return friendly_name_; } |
| 189 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 190 | int32 priority() const { return priority_; } |
| 191 | void set_priority(int32 priority) { priority_ = priority; } |
| 192 | |
Paul Stewart | 1ca3e85 | 2011-11-04 07:50:49 -0700 | [diff] [blame] | 193 | int32 security_level() const { return security_level_; } |
| 194 | void set_security_level(int32 security) { security_level_ = security; } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 195 | |
| 196 | int32 strength() const { return strength_; } |
| 197 | void set_strength(int32 strength) { strength_ = strength; } |
| 198 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 199 | virtual Technology::Identifier technology() const { return technology_; } |
| 200 | std::string GetTechnologyString(Error *error); |
| 201 | |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 202 | const std::string &error() const { return error_; } |
| 203 | void set_error(const std::string &error) { error_ = error; } |
| 204 | |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 205 | static const char *ConnectFailureToString(const ConnectFailure &state); |
| 206 | static const char *ConnectStateToString(const ConnectState &state); |
| 207 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 208 | // Compare two services. Returns true if Service a should be displayed |
| 209 | // above Service b |
| 210 | static bool Compare(ServiceRefPtr a, |
| 211 | ServiceRefPtr b, |
| 212 | const std::vector<Technology::Identifier> &tech_order); |
| 213 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 214 | // 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] | 215 | // TODO(cmasone): right now, these are here only so that we can get the |
| 216 | // profile name as a property. Can we store just the name, and then handle |
| 217 | // setting the profile for this service via |manager_|? |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 218 | const ProfileRefPtr &profile() const; |
| 219 | void set_profile(const ProfileRefPtr &p); |
| 220 | |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 221 | PropertyStore *mutable_store() { return &store_; } |
| 222 | const PropertyStore &store() const { return store_; } |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 223 | const ConnectionRefPtr &connection() const { return connection_; } |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 224 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 225 | protected: |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 226 | // Returns true if a character is allowed to be in a service storage id. |
| 227 | static bool LegalChar(char a) { return isalnum(a) || a == '_'; } |
| 228 | |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 229 | void set_friendly_name(const std::string &n) { friendly_name_ = n; } |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 230 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 231 | virtual std::string CalculateState(Error *error); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 232 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 233 | // Returns whether this service is in a state conducive to auto-connect. |
| 234 | // This should include any tests used for computing connectable(), |
| 235 | // as well as other critera such as whether the device associated with |
| 236 | // this service is busy with another connection. |
| 237 | virtual bool IsAutoConnectable() const { return connectable(); } |
| 238 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 239 | void HelpRegisterDerivedBool( |
| 240 | const std::string &name, |
Hristo Stefanov | ed2c28c | 2011-11-29 15:37:30 -0800 | [diff] [blame] | 241 | bool(Service::*get)(Error *error), |
| 242 | void(Service::*set)(const bool &value, Error *error)); |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 243 | void HelpRegisterDerivedString( |
| 244 | const std::string &name, |
Hristo Stefanov | ed2c28c | 2011-11-29 15:37:30 -0800 | [diff] [blame] | 245 | std::string(Service::*get)(Error *error), |
| 246 | void(Service::*set)(const std::string &value, Error *error)); |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 247 | void HelpRegisterDerivedUint16( |
| 248 | const std::string &name, |
| 249 | uint16(Service::*get)(Error *error), |
| 250 | void(Service::*set)(const uint16 &value, Error *error)); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 251 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 252 | ServiceAdaptorInterface *adaptor() const { return adaptor_.get(); } |
| 253 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 254 | // Assigns |value| to |key| in |storage| if |value| is non-empty and |save| is |
| 255 | // true. Otherwise, removes |key| from |storage|. If |crypted| is true, the |
| 256 | // value is encrypted. |
| 257 | void SaveString(StoreInterface *storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 258 | const std::string &id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 259 | const std::string &key, |
| 260 | const std::string &value, |
| 261 | bool crypted, |
| 262 | bool save); |
| 263 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 264 | void LoadEapCredentials(StoreInterface *storage, const std::string &id); |
| 265 | void SaveEapCredentials(StoreInterface *storage, const std::string &id); |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 266 | void UnloadEapCredentials(); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 267 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 268 | // Property accessors reserved for subclasses |
| 269 | EventDispatcher *dispatcher() const { return dispatcher_; } |
| 270 | const std::string &GetEAPKeyManagement() const; |
| 271 | void SetEAPKeyManagement(const std::string &key_management); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 272 | Metrics *metrics() const { return metrics_; } |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 273 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 274 | private: |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 275 | friend class ServiceAdaptorInterface; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 276 | friend class MetricsTest; |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 277 | FRIEND_TEST(DeviceTest, SelectedService); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 278 | FRIEND_TEST(ManagerTest, SortServicesWithConnection); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 279 | FRIEND_TEST(ServiceTest, Constructor); |
| 280 | FRIEND_TEST(ServiceTest, Save); |
| 281 | FRIEND_TEST(ServiceTest, SaveString); |
| 282 | FRIEND_TEST(ServiceTest, SaveStringCrypted); |
| 283 | FRIEND_TEST(ServiceTest, SaveStringDontSave); |
| 284 | FRIEND_TEST(ServiceTest, SaveStringEmpty); |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 285 | FRIEND_TEST(ServiceTest, Unload); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 286 | |
| 287 | static const char kStorageAutoConnect[]; |
| 288 | static const char kStorageCheckPortal[]; |
| 289 | static const char kStorageEapAnonymousIdentity[]; |
| 290 | static const char kStorageEapCACert[]; |
| 291 | static const char kStorageEapCACertID[]; |
| 292 | static const char kStorageEapCertID[]; |
| 293 | static const char kStorageEapClientCert[]; |
| 294 | static const char kStorageEapEap[]; |
| 295 | static const char kStorageEapIdentity[]; |
| 296 | static const char kStorageEapInnerEap[]; |
| 297 | static const char kStorageEapKeyID[]; |
| 298 | static const char kStorageEapKeyManagement[]; |
| 299 | static const char kStorageEapPIN[]; |
| 300 | static const char kStorageEapPassword[]; |
| 301 | static const char kStorageEapPrivateKey[]; |
| 302 | static const char kStorageEapPrivateKeyPassword[]; |
| 303 | static const char kStorageEapUseSystemCAs[]; |
| 304 | static const char kStorageFavorite[]; |
| 305 | static const char kStorageName[]; |
| 306 | static const char kStoragePriority[]; |
| 307 | static const char kStorageProxyConfig[]; |
| 308 | static const char kStorageSaveCredentials[]; |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 309 | static const char kStorageType[]; |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 310 | static const char kStorageUIData[]; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 311 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 312 | virtual std::string GetDeviceRpcId(Error *error) = 0; |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 313 | |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 314 | std::string GetProfileRpcId(Error *error); |
| 315 | void SetProfileRpcId(const std::string &profile, Error *error); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 316 | |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 317 | // Returns TCP port of service's HTTP proxy in host order. |
| 318 | uint16 GetHTTPProxyPort(Error *error); |
| 319 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 320 | // Utility function that returns true if a is different from b. When they |
| 321 | // are, "decision" is populated with the boolean value of "a > b". |
| 322 | static bool DecideBetween(int a, int b, bool *decision); |
| 323 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 324 | // For unit testing. |
| 325 | void set_metrics(Metrics *metrics) { metrics_ = metrics; } |
| 326 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 327 | ConnectState state_; |
| 328 | ConnectFailure failure_; |
| 329 | bool auto_connect_; |
| 330 | std::string check_portal_; |
| 331 | bool connectable_; |
| 332 | std::string error_; |
| 333 | bool favorite_; |
| 334 | int32 priority_; |
Paul Stewart | 1ca3e85 | 2011-11-04 07:50:49 -0700 | [diff] [blame] | 335 | int32 security_level_; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 336 | int32 strength_; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 337 | std::string proxy_config_; |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 338 | std::string ui_data_; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 339 | bool save_credentials_; |
| 340 | EapCredentials eap_; // Only saved if |save_credentials_| is true. |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 341 | Technology::Identifier technology_; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 342 | |
| 343 | ProfileRefPtr profile_; |
| 344 | PropertyStore store_; |
| 345 | |
| 346 | EventDispatcher *dispatcher_; |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 347 | static unsigned int serial_number_; |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 348 | std::string unique_name_; // MUST be unique amongst service instances |
| 349 | std::string friendly_name_; // MAY be same as |unique_name_| |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 350 | bool available_; |
| 351 | bool configured_; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 352 | Configuration *configuration_; |
Paul Stewart | ba41b99 | 2011-05-26 07:02:46 -0700 | [diff] [blame] | 353 | scoped_ptr<ServiceAdaptorInterface> adaptor_; |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 354 | scoped_ptr<HTTPProxy> http_proxy_; |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 355 | ConnectionRefPtr connection_; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 356 | Manager *manager_; |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 357 | Sockets sockets_; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 358 | Metrics *metrics_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 359 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 360 | DISALLOW_COPY_AND_ASSIGN(Service); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 361 | }; |
| 362 | |
| 363 | } // namespace shill |
| 364 | |
| 365 | #endif // SHILL_SERVICE_ |