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