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