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 | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 5 | #include "shill/service.h" |
| 6 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 7 | #include <time.h> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 8 | #include <stdio.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 9 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 10 | #include <map> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 11 | #include <string> |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 12 | #include <vector> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 13 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 14 | #include <base/memory/scoped_ptr.h> |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 15 | #include <base/string_number_conversions.h> |
Paul Stewart | 2bf424f | 2012-04-11 18:59:39 -0700 | [diff] [blame] | 16 | #include <base/stringprintf.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 17 | #include <chromeos/dbus/service_constants.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 18 | |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 19 | #include "shill/connection.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 20 | #include "shill/control_interface.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 21 | #include "shill/error.h" |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 22 | #include "shill/http_proxy.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 23 | #include "shill/logging.h" |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 24 | #include "shill/manager.h" |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 25 | #include "shill/metrics.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 26 | #include "shill/profile.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 27 | #include "shill/property_accessor.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 28 | #include "shill/refptr_types.h" |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 29 | #include "shill/service_dbus_adaptor.h" |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 30 | #include "shill/sockets.h" |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 31 | #include "shill/store_interface.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 32 | |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 33 | using base::Bind; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 34 | using std::map; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 35 | using std::string; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 36 | using std::vector; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 37 | |
| 38 | namespace shill { |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 39 | |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 40 | const char Service::kAutoConnConnected[] = "connected"; |
| 41 | const char Service::kAutoConnConnecting[] = "connecting"; |
| 42 | const char Service::kAutoConnExplicitDisconnect[] = "explicitly disconnected"; |
| 43 | const char Service::kAutoConnNotConnectable[] = "not connectable"; |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 44 | const char Service::kAutoConnThrottled[] = "throttled"; |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 45 | |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 46 | const size_t Service::kEAPMaxCertificationElements = 10; |
| 47 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 48 | const char Service::kCheckPortalAuto[] = "auto"; |
| 49 | const char Service::kCheckPortalFalse[] = "false"; |
| 50 | const char Service::kCheckPortalTrue[] = "true"; |
| 51 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 52 | const int Service::kPriorityNone = 0; |
| 53 | |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 54 | const char Service::kServiceSortAutoConnect[] = "AutoConnect"; |
| 55 | const char Service::kServiceSortConnectable[] = "Connectable"; |
Paul Stewart | df3c0a8 | 2012-11-09 15:54:33 -0800 | [diff] [blame] | 56 | const char Service::kServiceSortDependency[] = "Dependency"; |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 57 | const char Service::kServiceSortFavorite[] = "Favorite"; |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 58 | const char Service::kServiceSortIsConnected[] = "IsConnected"; |
| 59 | const char Service::kServiceSortIsConnecting[] = "IsConnecting"; |
| 60 | const char Service::kServiceSortIsFailed[] = "IsFailed"; |
Paul Stewart | a121c44 | 2012-06-09 14:12:58 -0700 | [diff] [blame] | 61 | const char Service::kServiceSortIsPortalled[] = "IsPortal"; |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 62 | const char Service::kServiceSortPriority[] = "Priority"; |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 63 | const char Service::kServiceSortSecurityEtc[] = "SecurityEtc"; |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 64 | const char Service::kServiceSortTechnology[] = "Technology"; |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 65 | const char Service::kServiceSortUniqueName[] = "UniqueName"; |
| 66 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 67 | const char Service::kStorageAutoConnect[] = "AutoConnect"; |
| 68 | const char Service::kStorageCheckPortal[] = "CheckPortal"; |
| 69 | const char Service::kStorageEapAnonymousIdentity[] = "EAP.AnonymousIdentity"; |
| 70 | const char Service::kStorageEapCACert[] = "EAP.CACert"; |
| 71 | const char Service::kStorageEapCACertID[] = "EAP.CACertID"; |
Paul Stewart | ecf4cd1 | 2012-04-17 11:08:39 -0700 | [diff] [blame] | 72 | const char Service::kStorageEapCACertNSS[] = "EAP.CACertNSS"; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 73 | const char Service::kStorageEapCertID[] = "EAP.CertID"; |
| 74 | const char Service::kStorageEapClientCert[] = "EAP.ClientCert"; |
| 75 | const char Service::kStorageEapEap[] = "EAP.EAP"; |
| 76 | const char Service::kStorageEapIdentity[] = "EAP.Identity"; |
| 77 | const char Service::kStorageEapInnerEap[] = "EAP.InnerEAP"; |
| 78 | const char Service::kStorageEapKeyID[] = "EAP.KeyID"; |
| 79 | const char Service::kStorageEapKeyManagement[] = "EAP.KeyMgmt"; |
| 80 | const char Service::kStorageEapPIN[] = "EAP.PIN"; |
| 81 | const char Service::kStorageEapPassword[] = "EAP.Password"; |
| 82 | const char Service::kStorageEapPrivateKey[] = "EAP.PrivateKey"; |
| 83 | const char Service::kStorageEapPrivateKeyPassword[] = "EAP.PrivateKeyPassword"; |
| 84 | const char Service::kStorageEapUseSystemCAs[] = "EAP.UseSystemCAs"; |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 85 | const char Service::kStorageError[] = "Error"; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 86 | const char Service::kStorageFavorite[] = "Favorite"; |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 87 | const char Service::kStorageGUID[] = "GUID"; |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 88 | const char Service::kStorageHasEverConnected[] = "HasEverConnected"; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 89 | const char Service::kStorageName[] = "Name"; |
| 90 | const char Service::kStoragePriority[] = "Priority"; |
| 91 | const char Service::kStorageProxyConfig[] = "ProxyConfig"; |
| 92 | const char Service::kStorageSaveCredentials[] = "SaveCredentials"; |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 93 | const char Service::kStorageType[] = "Type"; |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 94 | const char Service::kStorageUIData[] = "UIData"; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 95 | |
mukesh agrawal | 8f3f775 | 2012-02-17 19:42:09 -0800 | [diff] [blame] | 96 | const uint8 Service::kStrengthMax = 100; |
| 97 | const uint8 Service::kStrengthMin = 0; |
| 98 | |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 99 | const uint64 Service::kMaxAutoConnectCooldownTimeMilliseconds = 30 * 60 * 1000; |
| 100 | const uint64 Service::kMinAutoConnectCooldownTimeMilliseconds = 1000; |
| 101 | const uint64 Service::kAutoConnectCooldownBackoffFactor = 2; |
| 102 | |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 103 | // static |
| 104 | unsigned int Service::serial_number_ = 0; |
| 105 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 106 | Service::Service(ControlInterface *control_interface, |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 107 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 108 | Metrics *metrics, |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 109 | Manager *manager, |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 110 | Technology::Identifier technology) |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 111 | : state_(kStateIdle), |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 112 | failure_(kFailureUnknown), |
| 113 | auto_connect_(false), |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 114 | check_portal_(kCheckPortalAuto), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 115 | connectable_(false), |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 116 | error_(ConnectFailureToString(failure_)), |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 117 | explicitly_disconnected_(false), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 118 | favorite_(false), |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 119 | priority_(kPriorityNone), |
Paul Stewart | 1ca3e85 | 2011-11-04 07:50:49 -0700 | [diff] [blame] | 120 | security_level_(0), |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 121 | strength_(0), |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 122 | save_credentials_(true), |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 123 | technology_(technology), |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 124 | failed_time_(0), |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 125 | has_ever_connected_(false), |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 126 | auto_connect_cooldown_milliseconds_(0), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 127 | dispatcher_(dispatcher), |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 128 | unique_name_(base::UintToString(serial_number_++)), |
| 129 | friendly_name_(unique_name_), |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 130 | adaptor_(control_interface->CreateServiceAdaptor(this)), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 131 | metrics_(metrics), |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 132 | manager_(manager), |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 133 | sockets_(new Sockets()), |
| 134 | weak_ptr_factory_(this) { |
Thieu Le | 284fe79 | 2012-01-31 17:53:19 -0800 | [diff] [blame] | 135 | HelpRegisterDerivedBool(flimflam::kAutoConnectProperty, |
| 136 | &Service::GetAutoConnect, |
| 137 | &Service::SetAutoConnect); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 138 | |
| 139 | // flimflam::kActivationStateProperty: Registered in CellularService |
| 140 | // flimflam::kCellularApnProperty: Registered in CellularService |
| 141 | // flimflam::kCellularLastGoodApnProperty: Registered in CellularService |
| 142 | // flimflam::kNetworkTechnologyProperty: Registered in CellularService |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 143 | // flimflam::kOperatorNameProperty: DEPRECATED |
| 144 | // flimflam::kOperatorCodeProperty: DEPRECATED |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 145 | // flimflam::kRoamingStateProperty: Registered in CellularService |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 146 | // flimflam::kServingOperatorProperty: Registered in CellularService |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 147 | // flimflam::kPaymentURLProperty: Registered in CellularService |
| 148 | |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 149 | HelpRegisterDerivedString(flimflam::kCheckPortalProperty, |
| 150 | &Service::GetCheckPortal, |
| 151 | &Service::SetCheckPortal); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 152 | store_.RegisterConstBool(flimflam::kConnectableProperty, &connectable_); |
Jason Glasgow | acdc11f | 2012-03-30 14:12:22 -0400 | [diff] [blame] | 153 | HelpRegisterDerivedRpcIdentifier(flimflam::kDeviceProperty, |
| 154 | &Service::GetDeviceRpcId, |
| 155 | NULL); |
Paul Stewart | 4c56161 | 2012-03-21 12:49:01 -0700 | [diff] [blame] | 156 | store_.RegisterString(flimflam::kGuidProperty, &guid_); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 157 | |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 158 | store_.RegisterString(flimflam::kEapIdentityProperty, &eap_.identity); |
| 159 | store_.RegisterString(flimflam::kEAPEAPProperty, &eap_.eap); |
| 160 | store_.RegisterString(flimflam::kEapPhase2AuthProperty, &eap_.inner_eap); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 161 | store_.RegisterString(flimflam::kEapAnonymousIdentityProperty, |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 162 | &eap_.anonymous_identity); |
| 163 | store_.RegisterString(flimflam::kEAPClientCertProperty, &eap_.client_cert); |
| 164 | store_.RegisterString(flimflam::kEAPCertIDProperty, &eap_.cert_id); |
| 165 | store_.RegisterString(flimflam::kEapPrivateKeyProperty, &eap_.private_key); |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 166 | HelpRegisterWriteOnlyDerivedString(flimflam::kEapPrivateKeyPasswordProperty, |
| 167 | &Service::SetEAPPrivateKeyPassword, |
| 168 | NULL, |
| 169 | &eap_.private_key_password); |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 170 | store_.RegisterString(flimflam::kEAPKeyIDProperty, &eap_.key_id); |
| 171 | store_.RegisterString(flimflam::kEapCaCertProperty, &eap_.ca_cert); |
| 172 | store_.RegisterString(flimflam::kEapCaCertIDProperty, &eap_.ca_cert_id); |
Paul Stewart | ecf4cd1 | 2012-04-17 11:08:39 -0700 | [diff] [blame] | 173 | store_.RegisterString(flimflam::kEapCaCertNssProperty, &eap_.ca_cert_nss); |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 174 | store_.RegisterString(flimflam::kEAPPINProperty, &eap_.pin); |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 175 | HelpRegisterWriteOnlyDerivedString(flimflam::kEapPasswordProperty, |
| 176 | &Service::SetEAPPassword, |
| 177 | NULL, |
| 178 | &eap_.password); |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 179 | store_.RegisterString(flimflam::kEapKeyMgmtProperty, &eap_.key_management); |
| 180 | store_.RegisterBool(flimflam::kEapUseSystemCAsProperty, &eap_.use_system_cas); |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 181 | store_.RegisterConstStrings(shill::kEapRemoteCertificationProperty, |
| 182 | &eap_.remote_certification); |
| 183 | store_.RegisterString(shill::kEapSubjectMatchProperty, |
| 184 | &eap_.subject_match); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 185 | |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 186 | // TODO(ers): in flimflam clearing Error has the side-effect of |
| 187 | // setting the service state to IDLE. Is this important? I could |
| 188 | // see an autotest depending on it. |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 189 | store_.RegisterConstString(flimflam::kErrorProperty, &error_); |
| 190 | store_.RegisterConstBool(flimflam::kFavoriteProperty, &favorite_); |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 191 | HelpRegisterDerivedUint16(shill::kHTTPProxyPortProperty, |
| 192 | &Service::GetHTTPProxyPort, |
| 193 | NULL); |
Paul Stewart | 10241e3 | 2012-04-23 18:15:06 -0700 | [diff] [blame] | 194 | HelpRegisterDerivedRpcIdentifier(shill::kIPConfigProperty, |
| 195 | &Service::GetIPConfigRpcIdentifier, |
| 196 | NULL); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 197 | HelpRegisterDerivedBool(flimflam::kIsActiveProperty, |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 198 | &Service::IsActive, |
| 199 | NULL); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 200 | // flimflam::kModeProperty: Registered in WiFiService |
Paul Stewart | 0c43833 | 2012-04-11 07:55:27 -0700 | [diff] [blame] | 201 | |
| 202 | // Although this is a read-only property, some callers want to blindly |
| 203 | // set this value to its current value. |
| 204 | HelpRegisterDerivedString(flimflam::kNameProperty, |
| 205 | &Service::GetNameProperty, |
| 206 | &Service::AssertTrivialSetNameProperty); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 207 | // flimflam::kPassphraseProperty: Registered in WiFiService |
| 208 | // flimflam::kPassphraseRequiredProperty: Registered in WiFiService |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 209 | store_.RegisterInt32(flimflam::kPriorityProperty, &priority_); |
| 210 | HelpRegisterDerivedString(flimflam::kProfileProperty, |
| 211 | &Service::GetProfileRpcId, |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 212 | &Service::SetProfileRpcId); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 213 | store_.RegisterString(flimflam::kProxyConfigProperty, &proxy_config_); |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 214 | store_.RegisterBool(flimflam::kSaveCredentialsProperty, &save_credentials_); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 215 | HelpRegisterDerivedString(flimflam::kTypeProperty, |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 216 | &Service::CalculateTechnology, |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 217 | NULL); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 218 | // flimflam::kSecurityProperty: Registered in WiFiService |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 219 | HelpRegisterDerivedString(flimflam::kStateProperty, |
| 220 | &Service::CalculateState, |
| 221 | NULL); |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 222 | store_.RegisterConstUint8(flimflam::kSignalStrengthProperty, &strength_); |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 223 | store_.RegisterString(flimflam::kUIDataProperty, &ui_data_); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 224 | // flimflam::kWifiAuthMode: Registered in WiFiService |
| 225 | // flimflam::kWifiHiddenSsid: Registered in WiFiService |
| 226 | // flimflam::kWifiFrequency: Registered in WiFiService |
| 227 | // flimflam::kWifiPhyMode: Registered in WiFiService |
| 228 | // flimflam::kWifiHexSsid: Registered in WiFiService |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 229 | |
| 230 | metrics_->RegisterService(this); |
| 231 | |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 232 | static_ip_parameters_.PlumbPropertyStore(&store_); |
| 233 | |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 234 | IgnoreParameterForConfigure(flimflam::kTypeProperty); |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 235 | IgnoreParameterForConfigure(flimflam::kProfileProperty); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 236 | |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 237 | SLOG(Service, 2) << "Service initialized."; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 240 | Service::~Service() { |
Darin Petkov | 9cd7ca1 | 2012-07-03 11:06:40 +0200 | [diff] [blame] | 241 | LOG(INFO) << "Service destroyed: " << friendly_name_; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 242 | metrics_->DeregisterService(this); |
| 243 | } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 244 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 245 | void Service::AutoConnect() { |
Darin Petkov | 3abc3be | 2012-06-27 10:48:23 +0200 | [diff] [blame] | 246 | const char *reason = NULL; |
| 247 | if (IsAutoConnectable(&reason)) { |
Darin Petkov | 9cd7ca1 | 2012-07-03 11:06:40 +0200 | [diff] [blame] | 248 | LOG(INFO) << "Auto-connecting to " << friendly_name_; |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 249 | ThrottleFutureAutoConnects(); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 250 | Error error; |
| 251 | Connect(&error); |
mukesh agrawal | 76d1388 | 2012-01-12 15:23:11 -0800 | [diff] [blame] | 252 | } else { |
Darin Petkov | 9cd7ca1 | 2012-07-03 11:06:40 +0200 | [diff] [blame] | 253 | LOG(INFO) << "Suppressed autoconnect to " << friendly_name_ << " " |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 254 | << "(" << reason << ")"; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 258 | void Service::Connect(Error */*error*/) { |
| 259 | explicitly_disconnected_ = false; |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 260 | // clear any failure state from a previous connect attempt |
| 261 | SetState(kStateIdle); |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | void Service::Disconnect(Error */*error*/) { |
Christopher Wiley | 3e7635e | 2012-08-15 09:46:17 -0700 | [diff] [blame] | 265 | MemoryLog::GetInstance()->FlushToDisk(); |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Christopher Wiley | abd3b50 | 2012-09-26 13:08:52 -0700 | [diff] [blame] | 268 | void Service::DisconnectWithFailure(ConnectFailure failure, Error *error) { |
| 269 | Disconnect(error); |
| 270 | SetFailure(failure); |
| 271 | } |
| 272 | |
| 273 | void Service::UserInitiatedDisconnect(Error *error) { |
| 274 | Disconnect(error); |
| 275 | explicitly_disconnected_ = true; |
| 276 | } |
| 277 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 278 | void Service::ActivateCellularModem(const string &/*carrier*/, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 279 | Error *error, |
| 280 | const ResultCallback &/*callback*/) { |
| 281 | Error::PopulateAndLog(error, Error::kNotSupported, |
| 282 | "Service doesn't support cellular modem activation."); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 285 | bool Service::IsActive(Error */*error*/) { |
Paul Stewart | bfb8255 | 2012-10-24 16:48:48 -0700 | [diff] [blame] | 286 | return state() != kStateUnknown && |
| 287 | state() != kStateIdle && |
| 288 | state() != kStateFailure; |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | void Service::SetState(ConnectState state) { |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 292 | LOG(INFO) << "In " << __func__ << "(): Service " << friendly_name_ |
| 293 | << " state " << ConnectStateToString(state_) << " -> " |
| 294 | << ConnectStateToString(state); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 295 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 296 | if (state == state_) { |
| 297 | return; |
| 298 | } |
| 299 | |
| 300 | state_ = state; |
| 301 | if (state != kStateFailure) { |
| 302 | failure_ = kFailureUnknown; |
| 303 | } |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 304 | if (state == kStateConnected) { |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 305 | failed_time_ = 0; |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 306 | has_ever_connected_ = true; |
| 307 | SaveToProfile(); |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 308 | // When we succeed in connecting, forget that connects failed in the past. |
| 309 | // Give services one chance at a fast autoconnect retry by resetting the |
| 310 | // cooldown to 0 to indicate that the last connect was successful. |
| 311 | auto_connect_cooldown_milliseconds_ = 0; |
| 312 | reenable_auto_connect_task_.Cancel(); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 313 | } |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 314 | UpdateErrorProperty(); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 315 | manager_->UpdateService(this); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 316 | metrics_->NotifyServiceStateChanged(this, state); |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 317 | adaptor_->EmitStringChanged(flimflam::kStateProperty, GetStateString()); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 320 | void Service::ReEnableAutoConnectTask() { |
| 321 | // Kill the thing blocking AutoConnect(). |
| 322 | reenable_auto_connect_task_.Cancel(); |
| 323 | // Post to the manager, giving it an opportunity to AutoConnect again. |
| 324 | manager_->UpdateService(this); |
| 325 | } |
| 326 | |
| 327 | void Service::ThrottleFutureAutoConnects() { |
| 328 | if (auto_connect_cooldown_milliseconds_ > 0) { |
| 329 | LOG(INFO) << "Throttling autoconnect to " << friendly_name_ << " for " |
| 330 | << auto_connect_cooldown_milliseconds_ << " milliseconds."; |
| 331 | reenable_auto_connect_task_.Reset(Bind(&Service::ReEnableAutoConnectTask, |
| 332 | weak_ptr_factory_.GetWeakPtr())); |
| 333 | dispatcher_->PostDelayedTask(reenable_auto_connect_task_.callback(), |
| 334 | auto_connect_cooldown_milliseconds_); |
| 335 | } |
| 336 | auto_connect_cooldown_milliseconds_ = |
| 337 | std::min(kMaxAutoConnectCooldownTimeMilliseconds, |
| 338 | std::max(kMinAutoConnectCooldownTimeMilliseconds, |
| 339 | auto_connect_cooldown_milliseconds_ * |
| 340 | kAutoConnectCooldownBackoffFactor)); |
| 341 | } |
| 342 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 343 | void Service::SetFailure(ConnectFailure failure) { |
| 344 | failure_ = failure; |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 345 | failed_time_ = time(NULL); |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 346 | UpdateErrorProperty(); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 347 | SetState(kStateFailure); |
| 348 | } |
| 349 | |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 350 | void Service::SetFailureSilent(ConnectFailure failure) { |
| 351 | // Note that order matters here, since SetState modifies |failure_| and |
| 352 | // |failed_time_|. |
| 353 | SetState(kStateIdle); |
| 354 | failure_ = failure; |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 355 | UpdateErrorProperty(); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 356 | failed_time_ = time(NULL); |
| 357 | } |
| 358 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 359 | string Service::GetRpcIdentifier() const { |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 360 | return adaptor_->GetRpcIdentifier(); |
| 361 | } |
| 362 | |
Paul Stewart | bba6a5b | 2011-11-02 18:45:59 -0700 | [diff] [blame] | 363 | bool Service::IsLoadableFrom(StoreInterface *storage) const { |
| 364 | return storage->ContainsGroup(GetStorageIdentifier()); |
| 365 | } |
| 366 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 367 | bool Service::Load(StoreInterface *storage) { |
| 368 | const string id = GetStorageIdentifier(); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 369 | if (!storage->ContainsGroup(id)) { |
| 370 | LOG(WARNING) << "Service is not available in the persistent store: " << id; |
| 371 | return false; |
| 372 | } |
| 373 | storage->GetBool(id, kStorageAutoConnect, &auto_connect_); |
| 374 | storage->GetString(id, kStorageCheckPortal, &check_portal_); |
| 375 | storage->GetBool(id, kStorageFavorite, &favorite_); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 376 | storage->GetString(id, kStorageGUID, &guid_); |
| 377 | storage->GetBool(id, kStorageHasEverConnected, &has_ever_connected_); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 378 | storage->GetInt(id, kStoragePriority, &priority_); |
| 379 | storage->GetString(id, kStorageProxyConfig, &proxy_config_); |
| 380 | storage->GetBool(id, kStorageSaveCredentials, &save_credentials_); |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 381 | storage->GetString(id, kStorageUIData, &ui_data_); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 382 | |
| 383 | LoadEapCredentials(storage, id); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 384 | static_ip_parameters_.Load(storage, id); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 385 | // TODO(petkov): Load these: |
| 386 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 387 | // "Failure" |
| 388 | // "Modified" |
| 389 | // "LastAttempt" |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 390 | |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 391 | explicitly_disconnected_ = false; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 392 | favorite_ = true; |
| 393 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 394 | return true; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 397 | bool Service::Unload() { |
Paul Stewart | 7fb0938 | 2012-07-18 17:32:27 -0700 | [diff] [blame] | 398 | auto_connect_ = IsAutoConnectByDefault(); |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 399 | check_portal_ = kCheckPortalAuto; |
Christopher Wiley | abd3b50 | 2012-09-26 13:08:52 -0700 | [diff] [blame] | 400 | explicitly_disconnected_ = false; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 401 | favorite_ = false; |
Paul Stewart | e7cce8f | 2012-09-11 10:56:38 -0700 | [diff] [blame] | 402 | guid_ = ""; |
Paul Stewart | 88769de | 2012-09-21 13:14:36 -0700 | [diff] [blame] | 403 | has_ever_connected_ = false; |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 404 | priority_ = kPriorityNone; |
| 405 | proxy_config_ = ""; |
| 406 | save_credentials_ = true; |
| 407 | ui_data_ = ""; |
| 408 | |
| 409 | UnloadEapCredentials(); |
Wade Guthrie | 9e0c250 | 2012-04-19 15:26:40 -0700 | [diff] [blame] | 410 | Error error; // Ignored. |
| 411 | Disconnect(&error); |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 412 | return false; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 413 | } |
| 414 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 415 | bool Service::Save(StoreInterface *storage) { |
| 416 | const string id = GetStorageIdentifier(); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 417 | |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 418 | storage->SetString(id, kStorageType, GetTechnologyString()); |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 419 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 420 | // TODO(petkov): We could choose to simplify the saving code by removing most |
| 421 | // conditionals thus saving even default values. |
Wade Guthrie | 4f28e8b | 2012-04-11 10:52:07 -0700 | [diff] [blame] | 422 | storage->SetBool(id, kStorageAutoConnect, auto_connect_); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 423 | if (check_portal_ == kCheckPortalAuto) { |
| 424 | storage->DeleteKey(id, kStorageCheckPortal); |
| 425 | } else { |
| 426 | storage->SetString(id, kStorageCheckPortal, check_portal_); |
| 427 | } |
| 428 | storage->SetBool(id, kStorageFavorite, favorite_); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 429 | SaveString(storage, id, kStorageGUID, guid_, false, true); |
| 430 | storage->SetBool(id, kStorageHasEverConnected, has_ever_connected_); |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 431 | storage->SetString(id, kStorageName, friendly_name_); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 432 | if (priority_ != kPriorityNone) { |
| 433 | storage->SetInt(id, kStoragePriority, priority_); |
| 434 | } else { |
| 435 | storage->DeleteKey(id, kStoragePriority); |
| 436 | } |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 437 | SaveString(storage, id, kStorageProxyConfig, proxy_config_, false, true); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 438 | if (save_credentials_) { |
| 439 | storage->DeleteKey(id, kStorageSaveCredentials); |
| 440 | } else { |
| 441 | storage->SetBool(id, kStorageSaveCredentials, false); |
| 442 | } |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 443 | SaveString(storage, id, kStorageUIData, ui_data_, false, true); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 444 | |
| 445 | SaveEapCredentials(storage, id); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 446 | static_ip_parameters_.Save(storage, id); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 447 | |
| 448 | // TODO(petkov): Save these: |
| 449 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 450 | // "Failure" |
| 451 | // "Modified" |
| 452 | // "LastAttempt" |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 453 | |
| 454 | return true; |
| 455 | } |
| 456 | |
Gary Morain | d93615e | 2012-04-27 11:50:03 -0700 | [diff] [blame] | 457 | void Service::SaveToCurrentProfile() { |
| 458 | // Some unittests do not specify a manager. |
| 459 | if (manager()) { |
| 460 | manager()->SaveServiceToProfile(this); |
| 461 | } |
Thieu Le | d4e9e55 | 2012-02-16 16:26:07 -0800 | [diff] [blame] | 462 | } |
| 463 | |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 464 | void Service::Configure(const KeyValueStore &args, Error *error) { |
| 465 | map<string, bool>::const_iterator bool_it; |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 466 | SLOG(Service, 5) << "Configuring bool properties:"; |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 467 | for (bool_it = args.bool_properties().begin(); |
| 468 | bool_it != args.bool_properties().end(); |
| 469 | ++bool_it) { |
| 470 | if (ContainsKey(parameters_ignored_for_configure_, bool_it->first)) { |
| 471 | continue; |
| 472 | } |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 473 | SLOG(Service, 5) << " " << bool_it->first; |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 474 | Error set_error; |
| 475 | store_.SetBoolProperty(bool_it->first, bool_it->second, &set_error); |
Christopher Wiley | 27b4723 | 2012-11-02 13:13:00 -0700 | [diff] [blame] | 476 | OnPropertyChanged(bool_it->first); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 477 | if (error->IsSuccess() && set_error.IsFailure()) { |
| 478 | error->CopyFrom(set_error); |
| 479 | } |
| 480 | } |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 481 | SLOG(Service, 5) << "Configuring string properties:"; |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 482 | map<string, string>::const_iterator string_it; |
| 483 | for (string_it = args.string_properties().begin(); |
| 484 | string_it != args.string_properties().end(); |
| 485 | ++string_it) { |
| 486 | if (ContainsKey(parameters_ignored_for_configure_, string_it->first)) { |
| 487 | continue; |
| 488 | } |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 489 | SLOG(Service, 5) << " " << string_it->first; |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 490 | Error set_error; |
| 491 | store_.SetStringProperty(string_it->first, string_it->second, &set_error); |
Christopher Wiley | 27b4723 | 2012-11-02 13:13:00 -0700 | [diff] [blame] | 492 | OnPropertyChanged(string_it->first); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 493 | if (error->IsSuccess() && set_error.IsFailure()) { |
| 494 | error->CopyFrom(set_error); |
| 495 | } |
| 496 | } |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 497 | SLOG(Service, 5) << "Configuring uint32 properties:"; |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 498 | map<string, uint32>::const_iterator int_it; |
| 499 | for (int_it = args.uint_properties().begin(); |
| 500 | int_it != args.uint_properties().end(); |
| 501 | ++int_it) { |
| 502 | if (ContainsKey(parameters_ignored_for_configure_, int_it->first)) { |
| 503 | continue; |
| 504 | } |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 505 | SLOG(Service, 5) << " " << int_it->first; |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 506 | Error set_error; |
| 507 | store_.SetUint32Property(int_it->first, int_it->second, &set_error); |
Christopher Wiley | 27b4723 | 2012-11-02 13:13:00 -0700 | [diff] [blame] | 508 | OnPropertyChanged(int_it->first); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 509 | if (error->IsSuccess() && set_error.IsFailure()) { |
| 510 | error->CopyFrom(set_error); |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 515 | bool Service::IsRemembered() const { |
| 516 | return profile_ && !manager_->IsServiceEphemeral(this); |
| 517 | } |
| 518 | |
Paul Stewart | df3c0a8 | 2012-11-09 15:54:33 -0800 | [diff] [blame] | 519 | bool Service::IsDependentOn(const ServiceRefPtr &b) const { |
| 520 | if (!connection_ || !b) { |
| 521 | return false; |
| 522 | } |
| 523 | return connection_->GetLowerConnection() == b->connection(); |
| 524 | } |
| 525 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 526 | void Service::MakeFavorite() { |
| 527 | if (favorite_) { |
| 528 | // We do not want to clobber the value of auto_connect_ (it may |
| 529 | // be user-set). So return early. |
| 530 | return; |
| 531 | } |
| 532 | |
| 533 | auto_connect_ = true; |
| 534 | favorite_ = true; |
| 535 | } |
| 536 | |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 537 | void Service::SetConnection(const ConnectionRefPtr &connection) { |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 538 | if (connection.get()) { |
Paul Stewart | 1e3bc496 | 2012-09-14 12:20:22 -0700 | [diff] [blame] | 539 | // TODO(pstew): Make this function testable by using a factory here. |
| 540 | // http://crosbug.com/34528 |
Paul Stewart | c8f4bef | 2011-12-13 09:45:51 -0800 | [diff] [blame] | 541 | http_proxy_.reset(new HTTPProxy(connection)); |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 542 | http_proxy_->Start(dispatcher_, sockets_.get()); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 543 | } else { |
| 544 | http_proxy_.reset(); |
Paul Stewart | def189e | 2012-08-02 20:12:09 -0700 | [diff] [blame] | 545 | static_ip_parameters_.ClearSavedParameters(); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 546 | } |
| 547 | connection_ = connection; |
Paul Stewart | 1e3bc496 | 2012-09-14 12:20:22 -0700 | [diff] [blame] | 548 | Error error; |
| 549 | string ipconfig = GetIPConfigRpcIdentifier(&error); |
| 550 | if (error.IsSuccess()) { |
| 551 | adaptor_->EmitRpcIdentifierChanged(shill::kIPConfigProperty, ipconfig); |
| 552 | } |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 553 | } |
| 554 | |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 555 | bool Service::Is8021xConnectable() const { |
| 556 | // We mirror all the flimflam checks (see service.c:is_connectable()). |
| 557 | |
| 558 | // Identity is required. |
| 559 | if (eap_.identity.empty()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 560 | SLOG(Service, 2) << "Not connectable: Identity is empty."; |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 561 | return false; |
| 562 | } |
| 563 | |
| 564 | if (!eap_.client_cert.empty() || !eap_.cert_id.empty()) { |
| 565 | // If a client certificate is being used, we must have a private key. |
| 566 | if (eap_.private_key.empty() && eap_.key_id.empty()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 567 | SLOG(Service, 2) |
| 568 | << "Not connectable. Client certificate but no private key."; |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 569 | return false; |
| 570 | } |
| 571 | } |
| 572 | if (!eap_.cert_id.empty() || !eap_.key_id.empty() || |
| 573 | !eap_.ca_cert_id.empty()) { |
| 574 | // If PKCS#11 data is needed, a PIN is required. |
| 575 | if (eap_.pin.empty()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 576 | SLOG(Service, 2) << "Not connectable. PKCS#11 data but no PIN."; |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 577 | return false; |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | // For EAP-TLS, a client certificate is required. |
| 582 | if (eap_.eap.empty() || eap_.eap == "TLS") { |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 583 | if ((!eap_.client_cert.empty() || !eap_.cert_id.empty()) && |
| 584 | (!eap_.private_key.empty() || !eap_.key_id.empty())) { |
| 585 | SLOG(Service, 2) << "Connectable. EAP-TLS with a client cert and key."; |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 586 | return true; |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | // For EAP types other than TLS (e.g. EAP-TTLS or EAP-PEAP, password is the |
| 591 | // minimum requirement), at least an identity + password is required. |
| 592 | if (eap_.eap.empty() || eap_.eap != "TLS") { |
| 593 | if (!eap_.password.empty()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 594 | SLOG(Service, 2) << "Connectable. !EAP-TLS and has a password."; |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 595 | return true; |
| 596 | } |
| 597 | } |
| 598 | |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 599 | SLOG(Service, 2) |
| 600 | << "Not connectable. No suitable EAP configuration was found."; |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 601 | return false; |
| 602 | } |
| 603 | |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 604 | bool Service::AddEAPCertification(const string &name, size_t depth) { |
| 605 | if (depth >= kEAPMaxCertificationElements) { |
| 606 | LOG(WARNING) << "Ignoring certification " << name |
| 607 | << " because depth " << depth |
| 608 | << " exceeds our maximum of " |
| 609 | << kEAPMaxCertificationElements; |
| 610 | return false; |
| 611 | } |
| 612 | |
| 613 | if (depth >= eap_.remote_certification.size()) { |
| 614 | eap_.remote_certification.resize(depth + 1); |
| 615 | } else if (name == eap_.remote_certification[depth]) { |
| 616 | return true; |
| 617 | } |
| 618 | |
| 619 | eap_.remote_certification[depth] = name; |
| 620 | LOG(INFO) << "Received certification for " |
| 621 | << name |
| 622 | << " at depth " |
| 623 | << depth; |
| 624 | return true; |
| 625 | } |
| 626 | |
| 627 | void Service::ClearEAPCertification() { |
| 628 | eap_.remote_certification.clear(); |
| 629 | } |
| 630 | |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 631 | void Service::set_eap(const EapCredentials &eap) { |
| 632 | eap_ = eap; |
| 633 | // Note: Connectability can only be updated by a subclass of Service |
| 634 | // with knowledge of whether the service actually uses 802.1x credentials. |
| 635 | } |
| 636 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 637 | // static |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 638 | const char *Service::ConnectFailureToString(const ConnectFailure &state) { |
| 639 | switch (state) { |
| 640 | case kFailureUnknown: |
| 641 | return "Unknown"; |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 642 | case kFailureAAA: |
| 643 | return flimflam::kErrorAaaFailed; |
| 644 | case kFailureActivation: |
| 645 | return flimflam::kErrorActivationFailed; |
| 646 | case kFailureBadPassphrase: |
| 647 | return flimflam::kErrorBadPassphrase; |
| 648 | case kFailureBadWEPKey: |
| 649 | return flimflam::kErrorBadWEPKey; |
| 650 | case kFailureConnect: |
| 651 | return flimflam::kErrorConnectFailed; |
| 652 | case kFailureDNSLookup: |
| 653 | return flimflam::kErrorDNSLookupFailed; |
| 654 | case kFailureDHCP: |
| 655 | return flimflam::kErrorDhcpFailed; |
| 656 | case kFailureHTTPGet: |
| 657 | return flimflam::kErrorHTTPGetFailed; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 658 | case kFailureNeedEVDO: |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 659 | return flimflam::kErrorNeedEvdo; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 660 | case kFailureNeedHomeNetwork: |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 661 | return flimflam::kErrorNeedHomeNetwork; |
| 662 | case kFailureOTASP: |
| 663 | return flimflam::kErrorOtaspFailed; |
| 664 | case kFailureOutOfRange: |
| 665 | return flimflam::kErrorOutOfRange; |
| 666 | case kFailurePinMissing: |
| 667 | return flimflam::kErrorPinMissing; |
| 668 | case kFailurePPPAuth: |
| 669 | return flimflam::kErrorPppAuthFailed; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 670 | case kFailureMax: |
| 671 | return "Max failure error code"; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 672 | } |
| 673 | return "Invalid"; |
| 674 | } |
| 675 | |
| 676 | // static |
| 677 | const char *Service::ConnectStateToString(const ConnectState &state) { |
| 678 | switch (state) { |
| 679 | case kStateUnknown: |
| 680 | return "Unknown"; |
| 681 | case kStateIdle: |
| 682 | return "Idle"; |
| 683 | case kStateAssociating: |
| 684 | return "Associating"; |
| 685 | case kStateConfiguring: |
| 686 | return "Configuring"; |
| 687 | case kStateConnected: |
| 688 | return "Connected"; |
| 689 | case kStateDisconnected: |
| 690 | return "Disconnected"; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 691 | case kStatePortal: |
| 692 | return "Portal"; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 693 | case kStateFailure: |
| 694 | return "Failure"; |
| 695 | case kStateOnline: |
| 696 | return "Online"; |
| 697 | } |
| 698 | return "Invalid"; |
| 699 | } |
| 700 | |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 701 | string Service::GetTechnologyString() const { |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 702 | return Technology::NameFromIdentifier(technology()); |
| 703 | } |
| 704 | |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 705 | string Service::CalculateTechnology(Error */*error*/) { |
| 706 | return GetTechnologyString(); |
| 707 | } |
| 708 | |
Jason Glasgow | b579005 | 2012-01-27 01:03:52 -0500 | [diff] [blame] | 709 | // static |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 710 | bool Service::DecideBetween(int a, int b, bool *decision) { |
| 711 | if (a == b) |
| 712 | return false; |
| 713 | *decision = (a > b); |
| 714 | return true; |
| 715 | } |
| 716 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 717 | // static |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 718 | bool Service::Compare(ServiceRefPtr a, |
| 719 | ServiceRefPtr b, |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 720 | const vector<Technology::Identifier> &tech_order, |
| 721 | const char **reason) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 722 | bool ret; |
| 723 | |
| 724 | if (a->state() != b->state()) { |
| 725 | if (DecideBetween(a->IsConnected(), b->IsConnected(), &ret)) { |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 726 | *reason = kServiceSortIsConnected; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 727 | return ret; |
| 728 | } |
| 729 | |
Paul Stewart | a121c44 | 2012-06-09 14:12:58 -0700 | [diff] [blame] | 730 | if (DecideBetween(!a->IsPortalled(), !b->IsPortalled(), &ret)) { |
| 731 | *reason = kServiceSortIsPortalled; |
| 732 | return ret; |
| 733 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 734 | |
| 735 | if (DecideBetween(a->IsConnecting(), b->IsConnecting(), &ret)) { |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 736 | *reason = kServiceSortIsConnecting; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 737 | return ret; |
| 738 | } |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 739 | |
| 740 | if (DecideBetween(!a->IsFailed(), !b->IsFailed(), &ret)) { |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 741 | *reason = kServiceSortIsFailed; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 742 | return ret; |
| 743 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 746 | if (DecideBetween(a->connectable(), b->connectable(), &ret)) { |
| 747 | *reason = kServiceSortConnectable; |
| 748 | return ret; |
| 749 | } |
| 750 | |
Paul Stewart | df3c0a8 | 2012-11-09 15:54:33 -0800 | [diff] [blame] | 751 | if (DecideBetween(a->IsDependentOn(b), b->IsDependentOn(a), &ret)) { |
| 752 | *reason = kServiceSortDependency; |
| 753 | return ret; |
| 754 | } |
| 755 | |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 756 | // Ignore the auto-connect property if both services are connected |
| 757 | // already. This allows connected non-autoconnectable VPN services to be |
| 758 | // sorted higher than other connected services based on technology order. |
| 759 | if (!a->IsConnected() && |
| 760 | DecideBetween(a->auto_connect(), b->auto_connect(), &ret)) { |
| 761 | *reason = kServiceSortAutoConnect; |
| 762 | return ret; |
| 763 | } |
| 764 | |
| 765 | if (DecideBetween(a->favorite(), b->favorite(), &ret)) { |
| 766 | *reason = kServiceSortFavorite; |
| 767 | return ret; |
| 768 | } |
| 769 | |
| 770 | if (DecideBetween(a->priority(), b->priority(), &ret)) { |
| 771 | *reason = kServiceSortPriority; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 772 | return ret; |
| 773 | } |
| 774 | |
| 775 | // TODO(pstew): Below this point we are making value judgements on |
| 776 | // services that are not related to anything intrinsic or |
| 777 | // user-specified. These heuristics should be richer (contain |
| 778 | // historical information, for example) and be subject to user |
| 779 | // customization. |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 780 | for (vector<Technology::Identifier>::const_iterator it = tech_order.begin(); |
| 781 | it != tech_order.end(); |
| 782 | ++it) { |
Joshua Kroll | 053fa82 | 2012-06-05 09:50:43 -0700 | [diff] [blame] | 783 | if (DecideBetween(a->technology() == *it, b->technology() == *it, &ret)) { |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 784 | *reason = kServiceSortTechnology; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 785 | return ret; |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 786 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 787 | } |
| 788 | |
Paul Stewart | 1ca3e85 | 2011-11-04 07:50:49 -0700 | [diff] [blame] | 789 | if (DecideBetween(a->security_level(), b->security_level(), &ret) || |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 790 | DecideBetween(a->strength(), b->strength(), &ret)) { |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 791 | *reason = kServiceSortSecurityEtc; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 792 | return ret; |
| 793 | } |
| 794 | |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 795 | *reason = kServiceSortUniqueName; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 796 | return a->UniqueName() < b->UniqueName(); |
| 797 | } |
| 798 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 799 | const ProfileRefPtr &Service::profile() const { return profile_; } |
| 800 | |
| 801 | void Service::set_profile(const ProfileRefPtr &p) { profile_ = p; } |
| 802 | |
Paul Stewart | ff14b02 | 2012-04-24 20:06:23 -0700 | [diff] [blame] | 803 | void Service::OnPropertyChanged(const string &property) { |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 804 | if (Is8021x() && |
| 805 | (property == flimflam::kEAPCertIDProperty || |
| 806 | property == flimflam::kEAPClientCertProperty || |
| 807 | property == flimflam::kEAPKeyIDProperty || |
| 808 | property == flimflam::kEAPPINProperty || |
| 809 | property == flimflam::kEapCaCertIDProperty || |
| 810 | property == flimflam::kEapIdentityProperty || |
Paul Stewart | adf79d8 | 2012-07-18 16:09:56 -0700 | [diff] [blame] | 811 | property == flimflam::kEapKeyMgmtProperty || |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 812 | property == flimflam::kEapPasswordProperty || |
| 813 | property == flimflam::kEapPrivateKeyProperty)) { |
| 814 | // This notifies subclassess that EAP parameters have been changed. |
| 815 | set_eap(eap_); |
| 816 | } |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 817 | SaveToProfile(); |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 818 | if ((property == flimflam::kCheckPortalProperty || |
| 819 | property == flimflam::kProxyConfigProperty) && |
| 820 | (state_ == kStateConnected || |
| 821 | state_ == kStatePortal || |
| 822 | state_ == kStateOnline)) { |
| 823 | manager_->RecheckPortalOnService(this); |
| 824 | } |
Paul Stewart | ff14b02 | 2012-04-24 20:06:23 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 827 | void Service::OnAfterResume() { |
| 828 | // Forget old autoconnect failures across suspend/resume. |
| 829 | auto_connect_cooldown_milliseconds_ = 0; |
| 830 | reenable_auto_connect_task_.Cancel(); |
Christopher Wiley | a4c61ae | 2012-10-01 11:04:30 -0700 | [diff] [blame] | 831 | // Forget if the user disconnected us, we might be able to connect now. |
| 832 | explicitly_disconnected_ = false; |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Paul Stewart | 10241e3 | 2012-04-23 18:15:06 -0700 | [diff] [blame] | 835 | string Service::GetIPConfigRpcIdentifier(Error *error) { |
| 836 | if (!connection_) { |
| 837 | error->Populate(Error::kNotFound); |
| 838 | return "/"; |
| 839 | } |
| 840 | |
| 841 | string id = connection_->ipconfig_rpc_identifier(); |
| 842 | |
| 843 | if (id.empty()) { |
| 844 | // Do not return an empty IPConfig. |
| 845 | error->Populate(Error::kNotFound); |
| 846 | return "/"; |
| 847 | } |
| 848 | |
| 849 | return id; |
| 850 | } |
| 851 | |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 852 | void Service::set_connectable(bool connectable) { |
| 853 | connectable_ = connectable; |
| 854 | adaptor_->EmitBoolChanged(flimflam::kConnectableProperty, connectable_); |
| 855 | } |
| 856 | |
Darin Petkov | b2ba39f | 2012-06-06 10:33:43 +0200 | [diff] [blame] | 857 | void Service::SetConnectable(bool connectable) { |
| 858 | if (connectable_ == connectable) { |
| 859 | return; |
| 860 | } |
| 861 | connectable_ = connectable; |
| 862 | adaptor_->EmitBoolChanged(flimflam::kConnectableProperty, connectable_); |
| 863 | if (manager_->HasService(this)) { |
| 864 | manager_->UpdateService(this); |
| 865 | } |
| 866 | } |
| 867 | |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 868 | string Service::GetStateString() const { |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 869 | switch (state_) { |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 870 | case kStateIdle: |
| 871 | return flimflam::kStateIdle; |
| 872 | case kStateAssociating: |
| 873 | return flimflam::kStateAssociation; |
| 874 | case kStateConfiguring: |
| 875 | return flimflam::kStateConfiguration; |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 876 | case kStateConnected: |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 877 | return flimflam::kStateReady; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 878 | case kStateDisconnected: |
| 879 | return flimflam::kStateDisconnect; |
| 880 | case kStateFailure: |
| 881 | return flimflam::kStateFailure; |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 882 | case kStatePortal: |
| 883 | return flimflam::kStatePortal; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 884 | case kStateOnline: |
| 885 | return flimflam::kStateOnline; |
| 886 | case kStateUnknown: |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 887 | default: |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 888 | return ""; |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 892 | string Service::CalculateState(Error */*error*/) { |
| 893 | return GetStateString(); |
| 894 | } |
| 895 | |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 896 | bool Service::IsAutoConnectable(const char **reason) const { |
| 897 | if (!connectable()) { |
| 898 | *reason = kAutoConnNotConnectable; |
| 899 | return false; |
| 900 | } |
| 901 | |
| 902 | if (IsConnected()) { |
| 903 | *reason = kAutoConnConnected; |
| 904 | return false; |
| 905 | } |
| 906 | |
| 907 | if (IsConnecting()) { |
| 908 | *reason = kAutoConnConnecting; |
| 909 | return false; |
| 910 | } |
| 911 | |
| 912 | if (explicitly_disconnected_) { |
| 913 | *reason = kAutoConnExplicitDisconnect; |
| 914 | return false; |
| 915 | } |
| 916 | |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 917 | if (!reenable_auto_connect_task_.IsCancelled()) { |
| 918 | *reason = kAutoConnThrottled; |
| 919 | return false; |
| 920 | } |
| 921 | |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 922 | return true; |
mukesh agrawal | 76d1388 | 2012-01-12 15:23:11 -0800 | [diff] [blame] | 923 | } |
| 924 | |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 925 | bool Service::IsPortalDetectionDisabled() const { |
| 926 | return check_portal_ == kCheckPortalFalse; |
| 927 | } |
| 928 | |
| 929 | bool Service::IsPortalDetectionAuto() const { |
| 930 | return check_portal_ == kCheckPortalAuto; |
| 931 | } |
| 932 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 933 | void Service::HelpRegisterDerivedBool( |
| 934 | const string &name, |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 935 | bool(Service::*get)(Error *), |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 936 | void(Service::*set)(const bool&, Error *)) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 937 | store_.RegisterDerivedBool( |
| 938 | name, |
| 939 | BoolAccessor(new CustomAccessor<Service, bool>(this, get, set))); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 940 | } |
| 941 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 942 | void Service::HelpRegisterDerivedString( |
| 943 | const string &name, |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 944 | string(Service::*get)(Error *), |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 945 | void(Service::*set)(const string&, Error *)) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 946 | store_.RegisterDerivedString( |
| 947 | name, |
| 948 | StringAccessor(new CustomAccessor<Service, string>(this, get, set))); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 949 | } |
| 950 | |
Jason Glasgow | acdc11f | 2012-03-30 14:12:22 -0400 | [diff] [blame] | 951 | void Service::HelpRegisterDerivedRpcIdentifier( |
| 952 | const string &name, |
| 953 | RpcIdentifier(Service::*get)(Error *), |
| 954 | void(Service::*set)(const RpcIdentifier&, Error *)) { |
| 955 | store_.RegisterDerivedRpcIdentifier( |
| 956 | name, |
| 957 | RpcIdentifierAccessor(new CustomAccessor<Service, RpcIdentifier>( |
| 958 | this, get, set))); |
| 959 | } |
| 960 | |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 961 | void Service::HelpRegisterDerivedUint16( |
| 962 | const string &name, |
| 963 | uint16(Service::*get)(Error *), |
| 964 | void(Service::*set)(const uint16&, Error *)) { |
| 965 | store_.RegisterDerivedUint16( |
| 966 | name, |
| 967 | Uint16Accessor(new CustomAccessor<Service, uint16>(this, get, set))); |
| 968 | } |
| 969 | |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 970 | void Service::HelpRegisterWriteOnlyDerivedString( |
| 971 | const string &name, |
| 972 | void(Service::*set)(const string &, Error *), |
| 973 | void(Service::*clear)(Error *), |
| 974 | const string *default_value) { |
| 975 | store_.RegisterDerivedString( |
| 976 | name, |
| 977 | StringAccessor( |
| 978 | new CustomWriteOnlyAccessor<Service, string>( |
| 979 | this, set, clear, default_value))); |
| 980 | } |
| 981 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 982 | void Service::SaveString(StoreInterface *storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 983 | const string &id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 984 | const string &key, |
| 985 | const string &value, |
| 986 | bool crypted, |
| 987 | bool save) { |
| 988 | if (value.empty() || !save) { |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 989 | storage->DeleteKey(id, key); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 990 | return; |
| 991 | } |
| 992 | if (crypted) { |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 993 | storage->SetCryptedString(id, key, value); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 994 | return; |
| 995 | } |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 996 | storage->SetString(id, key, value); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 997 | } |
| 998 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 999 | void Service::LoadEapCredentials(StoreInterface *storage, const string &id) { |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1000 | EapCredentials eap; |
| 1001 | storage->GetCryptedString(id, kStorageEapIdentity, &eap.identity); |
| 1002 | storage->GetString(id, kStorageEapEap, &eap.eap); |
| 1003 | storage->GetString(id, kStorageEapInnerEap, &eap.inner_eap); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1004 | storage->GetCryptedString(id, |
| 1005 | kStorageEapAnonymousIdentity, |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1006 | &eap.anonymous_identity); |
| 1007 | storage->GetString(id, kStorageEapClientCert, &eap.client_cert); |
| 1008 | storage->GetString(id, kStorageEapCertID, &eap.cert_id); |
| 1009 | storage->GetString(id, kStorageEapPrivateKey, &eap.private_key); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1010 | storage->GetCryptedString(id, |
| 1011 | kStorageEapPrivateKeyPassword, |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1012 | &eap.private_key_password); |
| 1013 | storage->GetString(id, kStorageEapKeyID, &eap.key_id); |
| 1014 | storage->GetString(id, kStorageEapCACert, &eap.ca_cert); |
| 1015 | storage->GetString(id, kStorageEapCACertID, &eap.ca_cert_id); |
Paul Stewart | ecf4cd1 | 2012-04-17 11:08:39 -0700 | [diff] [blame] | 1016 | storage->GetString(id, kStorageEapCACertNSS, &eap.ca_cert_nss); |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1017 | storage->GetBool(id, kStorageEapUseSystemCAs, &eap.use_system_cas); |
| 1018 | storage->GetString(id, kStorageEapPIN, &eap.pin); |
| 1019 | storage->GetCryptedString(id, kStorageEapPassword, &eap.password); |
| 1020 | storage->GetString(id, kStorageEapKeyManagement, &eap.key_management); |
| 1021 | set_eap(eap); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 1024 | void Service::SaveEapCredentials(StoreInterface *storage, const string &id) { |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1025 | bool save = save_credentials_; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 1026 | SaveString(storage, id, kStorageEapIdentity, eap_.identity, true, save); |
| 1027 | SaveString(storage, id, kStorageEapEap, eap_.eap, false, true); |
| 1028 | SaveString(storage, id, kStorageEapInnerEap, eap_.inner_eap, false, true); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1029 | SaveString(storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 1030 | id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1031 | kStorageEapAnonymousIdentity, |
| 1032 | eap_.anonymous_identity, |
| 1033 | true, |
| 1034 | save); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 1035 | SaveString(storage, id, kStorageEapClientCert, eap_.client_cert, false, save); |
| 1036 | SaveString(storage, id, kStorageEapCertID, eap_.cert_id, false, save); |
| 1037 | SaveString(storage, id, kStorageEapPrivateKey, eap_.private_key, false, save); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1038 | SaveString(storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 1039 | id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1040 | kStorageEapPrivateKeyPassword, |
| 1041 | eap_.private_key_password, |
| 1042 | true, |
| 1043 | save); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 1044 | SaveString(storage, id, kStorageEapKeyID, eap_.key_id, false, save); |
| 1045 | SaveString(storage, id, kStorageEapCACert, eap_.ca_cert, false, true); |
| 1046 | SaveString(storage, id, kStorageEapCACertID, eap_.ca_cert_id, false, true); |
Paul Stewart | ecf4cd1 | 2012-04-17 11:08:39 -0700 | [diff] [blame] | 1047 | SaveString(storage, id, kStorageEapCACertNSS, eap_.ca_cert_nss, false, true); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 1048 | storage->SetBool(id, kStorageEapUseSystemCAs, eap_.use_system_cas); |
| 1049 | SaveString(storage, id, kStorageEapPIN, eap_.pin, false, save); |
| 1050 | SaveString(storage, id, kStorageEapPassword, eap_.password, true, save); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1051 | SaveString(storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 1052 | id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1053 | kStorageEapKeyManagement, |
| 1054 | eap_.key_management, |
| 1055 | false, |
| 1056 | true); |
| 1057 | } |
| 1058 | |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 1059 | void Service::UnloadEapCredentials() { |
| 1060 | eap_.identity = ""; |
| 1061 | eap_.eap = ""; |
| 1062 | eap_.inner_eap = ""; |
| 1063 | eap_.anonymous_identity = ""; |
| 1064 | eap_.client_cert = ""; |
| 1065 | eap_.cert_id = ""; |
| 1066 | eap_.private_key = ""; |
| 1067 | eap_.private_key_password = ""; |
| 1068 | eap_.key_id = ""; |
| 1069 | eap_.ca_cert = ""; |
| 1070 | eap_.ca_cert_id = ""; |
Paul Stewart | 2055098 | 2012-04-16 12:16:11 -0700 | [diff] [blame] | 1071 | eap_.use_system_cas = true; |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 1072 | eap_.pin = ""; |
| 1073 | eap_.password = ""; |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 1074 | } |
| 1075 | |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1076 | void Service::IgnoreParameterForConfigure(const string ¶meter) { |
| 1077 | parameters_ignored_for_configure_.insert(parameter); |
| 1078 | } |
| 1079 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 1080 | const string &Service::GetEAPKeyManagement() const { |
| 1081 | return eap_.key_management; |
| 1082 | } |
| 1083 | |
| 1084 | void Service::SetEAPKeyManagement(const string &key_management) { |
| 1085 | eap_.key_management = key_management; |
| 1086 | } |
| 1087 | |
Thieu Le | 284fe79 | 2012-01-31 17:53:19 -0800 | [diff] [blame] | 1088 | bool Service::GetAutoConnect(Error */*error*/) { |
| 1089 | return auto_connect(); |
| 1090 | } |
| 1091 | |
| 1092 | void Service::SetAutoConnect(const bool &connect, Error *error) { |
Wade Guthrie | 4f28e8b | 2012-04-11 10:52:07 -0700 | [diff] [blame] | 1093 | set_auto_connect(connect); |
Thieu Le | 284fe79 | 2012-01-31 17:53:19 -0800 | [diff] [blame] | 1094 | } |
| 1095 | |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1096 | string Service::GetCheckPortal(Error *error) { |
| 1097 | return check_portal_; |
| 1098 | } |
| 1099 | |
| 1100 | void Service::SetCheckPortal(const string &check_portal, Error *error) { |
| 1101 | if (check_portal == check_portal_) { |
| 1102 | return; |
| 1103 | } |
| 1104 | if (check_portal != kCheckPortalFalse && |
| 1105 | check_portal != kCheckPortalTrue && |
| 1106 | check_portal != kCheckPortalAuto) { |
| 1107 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 1108 | base::StringPrintf( |
| 1109 | "Invalid Service CheckPortal property value: %s", |
| 1110 | check_portal.c_str())); |
| 1111 | return; |
| 1112 | } |
| 1113 | check_portal_ = check_portal; |
| 1114 | } |
| 1115 | |
Paul Stewart | 9f32d19 | 2012-01-30 20:37:50 -0800 | [diff] [blame] | 1116 | void Service::SetEAPPassword(const string &password, Error */*error*/) { |
| 1117 | eap_.password = password; |
| 1118 | } |
| 1119 | |
| 1120 | void Service::SetEAPPrivateKeyPassword(const string &password, |
| 1121 | Error */*error*/) { |
| 1122 | eap_.private_key_password = password; |
| 1123 | } |
| 1124 | |
Paul Stewart | 0c43833 | 2012-04-11 07:55:27 -0700 | [diff] [blame] | 1125 | string Service::GetNameProperty(Error *error) { |
| 1126 | return friendly_name_; |
| 1127 | } |
| 1128 | |
| 1129 | void Service::AssertTrivialSetNameProperty(const string &name, Error *error) { |
| 1130 | if (name != friendly_name_) { |
| 1131 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
Paul Stewart | 2bf424f | 2012-04-11 18:59:39 -0700 | [diff] [blame] | 1132 | base::StringPrintf( |
| 1133 | "Service Name property cannot be modified " |
| 1134 | "(%s to %s)", friendly_name_.c_str(), |
| 1135 | name.c_str())); |
Paul Stewart | 0c43833 | 2012-04-11 07:55:27 -0700 | [diff] [blame] | 1136 | } |
| 1137 | } |
| 1138 | |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 1139 | string Service::GetProfileRpcId(Error *error) { |
| 1140 | if (!profile_) { |
| 1141 | // This happens in some unit tests where profile_ is not set. |
| 1142 | error->Populate(Error::kNotFound); |
| 1143 | return ""; |
| 1144 | } |
| 1145 | return profile_->GetRpcIdentifier(); |
| 1146 | } |
| 1147 | |
| 1148 | void Service::SetProfileRpcId(const string &profile, Error *error) { |
| 1149 | manager_->SetProfileForService(this, profile, error); |
| 1150 | } |
| 1151 | |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 1152 | uint16 Service::GetHTTPProxyPort(Error */*error*/) { |
| 1153 | if (http_proxy_.get()) { |
| 1154 | return static_cast<uint16>(http_proxy_->proxy_port()); |
| 1155 | } |
| 1156 | return 0; |
| 1157 | } |
| 1158 | |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 1159 | void Service::SaveToProfile() { |
| 1160 | if (profile_.get() && profile_->GetConstStorage()) { |
| 1161 | profile_->UpdateService(this); |
| 1162 | } |
| 1163 | } |
| 1164 | |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 1165 | void Service::SetStrength(uint8 strength) { |
| 1166 | if (strength == strength_) { |
| 1167 | return; |
| 1168 | } |
| 1169 | strength_ = strength; |
| 1170 | adaptor_->EmitUint8Changed(flimflam::kSignalStrengthProperty, strength); |
| 1171 | } |
| 1172 | |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 1173 | void Service::UpdateErrorProperty() { |
| 1174 | const string error(ConnectFailureToString(failure_)); |
| 1175 | if (error == error_) { |
| 1176 | return; |
| 1177 | } |
| 1178 | error_ = error; |
| 1179 | adaptor_->EmitStringChanged(flimflam::kErrorProperty, error); |
| 1180 | } |
| 1181 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 1182 | } // namespace shill |