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