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