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 | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 14 | #include <base/logging.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 15 | #include <base/memory/scoped_ptr.h> |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 16 | #include <base/string_number_conversions.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" |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 23 | #include "shill/manager.h" |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 24 | #include "shill/metrics.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 25 | #include "shill/profile.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 26 | #include "shill/property_accessor.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 27 | #include "shill/refptr_types.h" |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 28 | #include "shill/service_dbus_adaptor.h" |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 29 | #include "shill/store_interface.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 30 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 31 | using std::map; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 32 | using std::string; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 33 | using std::vector; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 34 | |
| 35 | namespace shill { |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 36 | |
| 37 | const char Service::kCheckPortalAuto[] = "auto"; |
| 38 | const char Service::kCheckPortalFalse[] = "false"; |
| 39 | const char Service::kCheckPortalTrue[] = "true"; |
| 40 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 41 | const int Service::kPriorityNone = 0; |
| 42 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 43 | const char Service::kStorageAutoConnect[] = "AutoConnect"; |
| 44 | const char Service::kStorageCheckPortal[] = "CheckPortal"; |
| 45 | const char Service::kStorageEapAnonymousIdentity[] = "EAP.AnonymousIdentity"; |
| 46 | const char Service::kStorageEapCACert[] = "EAP.CACert"; |
| 47 | const char Service::kStorageEapCACertID[] = "EAP.CACertID"; |
| 48 | const char Service::kStorageEapCertID[] = "EAP.CertID"; |
| 49 | const char Service::kStorageEapClientCert[] = "EAP.ClientCert"; |
| 50 | const char Service::kStorageEapEap[] = "EAP.EAP"; |
| 51 | const char Service::kStorageEapIdentity[] = "EAP.Identity"; |
| 52 | const char Service::kStorageEapInnerEap[] = "EAP.InnerEAP"; |
| 53 | const char Service::kStorageEapKeyID[] = "EAP.KeyID"; |
| 54 | const char Service::kStorageEapKeyManagement[] = "EAP.KeyMgmt"; |
| 55 | const char Service::kStorageEapPIN[] = "EAP.PIN"; |
| 56 | const char Service::kStorageEapPassword[] = "EAP.Password"; |
| 57 | const char Service::kStorageEapPrivateKey[] = "EAP.PrivateKey"; |
| 58 | const char Service::kStorageEapPrivateKeyPassword[] = "EAP.PrivateKeyPassword"; |
| 59 | const char Service::kStorageEapUseSystemCAs[] = "EAP.UseSystemCAs"; |
| 60 | const char Service::kStorageFavorite[] = "Favorite"; |
| 61 | const char Service::kStorageName[] = "Name"; |
| 62 | const char Service::kStoragePriority[] = "Priority"; |
| 63 | const char Service::kStorageProxyConfig[] = "ProxyConfig"; |
| 64 | const char Service::kStorageSaveCredentials[] = "SaveCredentials"; |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 65 | const char Service::kStorageType[] = "Type"; |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 66 | const char Service::kStorageUIData[] = "UIData"; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 67 | |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 68 | // static |
| 69 | unsigned int Service::serial_number_ = 0; |
| 70 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 71 | Service::Service(ControlInterface *control_interface, |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 72 | EventDispatcher *dispatcher, |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 73 | Manager *manager, |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 74 | Technology::Identifier technology) |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 75 | : state_(kStateUnknown), |
| 76 | failure_(kFailureUnknown), |
| 77 | auto_connect_(false), |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 78 | check_portal_(kCheckPortalAuto), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 79 | connectable_(false), |
| 80 | favorite_(false), |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 81 | priority_(kPriorityNone), |
Paul Stewart | 1ca3e85 | 2011-11-04 07:50:49 -0700 | [diff] [blame] | 82 | security_level_(0), |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 83 | strength_(0), |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 84 | save_credentials_(true), |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 85 | technology_(technology), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 86 | dispatcher_(dispatcher), |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 87 | unique_name_(base::UintToString(serial_number_++)), |
| 88 | friendly_name_(unique_name_), |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 89 | available_(false), |
| 90 | configured_(false), |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 91 | configuration_(NULL), |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 92 | adaptor_(control_interface->CreateServiceAdaptor(this)), |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 93 | manager_(manager), |
| 94 | metrics_(Metrics::GetInstance()) { |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 95 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 96 | store_.RegisterBool(flimflam::kAutoConnectProperty, &auto_connect_); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 97 | |
| 98 | // flimflam::kActivationStateProperty: Registered in CellularService |
| 99 | // flimflam::kCellularApnProperty: Registered in CellularService |
| 100 | // flimflam::kCellularLastGoodApnProperty: Registered in CellularService |
| 101 | // flimflam::kNetworkTechnologyProperty: Registered in CellularService |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 102 | // flimflam::kOperatorNameProperty: DEPRECATED |
| 103 | // flimflam::kOperatorCodeProperty: DEPRECATED |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 104 | // flimflam::kRoamingStateProperty: Registered in CellularService |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 105 | // flimflam::kServingOperatorProperty: Registered in CellularService |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 106 | // flimflam::kPaymentURLProperty: Registered in CellularService |
| 107 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 108 | store_.RegisterString(flimflam::kCheckPortalProperty, &check_portal_); |
| 109 | store_.RegisterConstBool(flimflam::kConnectableProperty, &connectable_); |
| 110 | HelpRegisterDerivedString(flimflam::kDeviceProperty, |
| 111 | &Service::GetDeviceRpcId, |
| 112 | NULL); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 113 | |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 114 | store_.RegisterString(flimflam::kEapIdentityProperty, &eap_.identity); |
| 115 | store_.RegisterString(flimflam::kEAPEAPProperty, &eap_.eap); |
| 116 | store_.RegisterString(flimflam::kEapPhase2AuthProperty, &eap_.inner_eap); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 117 | store_.RegisterString(flimflam::kEapAnonymousIdentityProperty, |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 118 | &eap_.anonymous_identity); |
| 119 | store_.RegisterString(flimflam::kEAPClientCertProperty, &eap_.client_cert); |
| 120 | store_.RegisterString(flimflam::kEAPCertIDProperty, &eap_.cert_id); |
| 121 | store_.RegisterString(flimflam::kEapPrivateKeyProperty, &eap_.private_key); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 122 | store_.RegisterString(flimflam::kEapPrivateKeyPasswordProperty, |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 123 | &eap_.private_key_password); |
| 124 | store_.RegisterString(flimflam::kEAPKeyIDProperty, &eap_.key_id); |
| 125 | store_.RegisterString(flimflam::kEapCaCertProperty, &eap_.ca_cert); |
| 126 | store_.RegisterString(flimflam::kEapCaCertIDProperty, &eap_.ca_cert_id); |
| 127 | store_.RegisterString(flimflam::kEAPPINProperty, &eap_.pin); |
| 128 | store_.RegisterString(flimflam::kEapPasswordProperty, &eap_.password); |
| 129 | store_.RegisterString(flimflam::kEapKeyMgmtProperty, &eap_.key_management); |
| 130 | store_.RegisterBool(flimflam::kEapUseSystemCAsProperty, &eap_.use_system_cas); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 131 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 132 | store_.RegisterConstString(flimflam::kErrorProperty, &error_); |
| 133 | store_.RegisterConstBool(flimflam::kFavoriteProperty, &favorite_); |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 134 | HelpRegisterDerivedUint16(shill::kHTTPProxyPortProperty, |
| 135 | &Service::GetHTTPProxyPort, |
| 136 | NULL); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 137 | HelpRegisterDerivedBool(flimflam::kIsActiveProperty, |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 138 | &Service::IsActive, |
| 139 | NULL); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 140 | // flimflam::kModeProperty: Registered in WiFiService |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 141 | store_.RegisterConstString(flimflam::kNameProperty, &friendly_name_); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 142 | // flimflam::kPassphraseProperty: Registered in WiFiService |
| 143 | // flimflam::kPassphraseRequiredProperty: Registered in WiFiService |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 144 | store_.RegisterInt32(flimflam::kPriorityProperty, &priority_); |
| 145 | HelpRegisterDerivedString(flimflam::kProfileProperty, |
| 146 | &Service::GetProfileRpcId, |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 147 | &Service::SetProfileRpcId); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 148 | store_.RegisterString(flimflam::kProxyConfigProperty, &proxy_config_); |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 149 | // TODO(cmasone): Create VPN Service with this property |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 150 | // store_.RegisterConstStringmap(flimflam::kProviderProperty, &provider_); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 151 | |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 152 | store_.RegisterBool(flimflam::kSaveCredentialsProperty, &save_credentials_); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 153 | HelpRegisterDerivedString(flimflam::kTypeProperty, |
| 154 | &Service::GetTechnologyString, |
| 155 | NULL); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 156 | // flimflam::kSecurityProperty: Registered in WiFiService |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 157 | HelpRegisterDerivedString(flimflam::kStateProperty, |
| 158 | &Service::CalculateState, |
| 159 | NULL); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 160 | // flimflam::kSignalStrengthProperty: Registered in WiFi/CellularService |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 161 | store_.RegisterString(flimflam::kUIDataProperty, &ui_data_); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 162 | // flimflam::kWifiAuthMode: Registered in WiFiService |
| 163 | // flimflam::kWifiHiddenSsid: Registered in WiFiService |
| 164 | // flimflam::kWifiFrequency: Registered in WiFiService |
| 165 | // flimflam::kWifiPhyMode: Registered in WiFiService |
| 166 | // flimflam::kWifiHexSsid: Registered in WiFiService |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 167 | |
| 168 | metrics_->RegisterService(this); |
| 169 | |
Chris Masone | b07006b | 2011-05-14 16:10:04 -0700 | [diff] [blame] | 170 | VLOG(2) << "Service initialized."; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 173 | Service::~Service() { |
| 174 | metrics_->DeregisterService(this); |
| 175 | } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 176 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 177 | void Service::AutoConnect() { |
| 178 | if (this->IsAutoConnectable()) { |
| 179 | Error error; |
| 180 | Connect(&error); |
| 181 | } |
| 182 | } |
| 183 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 184 | void Service::ActivateCellularModem(const string &/*carrier*/, Error *error) { |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 185 | const string kMessage = "Service doesn't support cellular modem activation."; |
| 186 | LOG(ERROR) << kMessage; |
| 187 | CHECK(error); |
| 188 | error->Populate(Error::kInvalidArguments, kMessage); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 189 | } |
| 190 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 191 | bool Service::TechnologyIs(const Technology::Identifier /*type*/) const { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 192 | return false; |
| 193 | } |
| 194 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 195 | bool Service::IsActive(Error */*error*/) { |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 196 | return state_ != kStateUnknown && |
| 197 | state_ != kStateIdle && |
| 198 | state_ != kStateFailure; |
| 199 | } |
| 200 | |
| 201 | void Service::SetState(ConnectState state) { |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 202 | LOG(INFO) << "In " << __func__ << "(): Service " << friendly_name_ |
| 203 | << " state " << ConnectStateToString(state_) << " -> " |
| 204 | << ConnectStateToString(state); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 205 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 206 | if (state == state_) { |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | state_ = state; |
| 211 | if (state != kStateFailure) { |
| 212 | failure_ = kFailureUnknown; |
| 213 | } |
| 214 | manager_->UpdateService(this); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 215 | metrics_->NotifyServiceStateChanged(this, state); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 216 | Error error; |
mukesh agrawal | fa602f2 | 2011-11-29 02:00:46 +0000 | [diff] [blame] | 217 | if (state == kStateConnected) { |
| 218 | // TODO(quiche): After we have portal detection in place, CalculateState |
| 219 | // should map kStateConnected to kStateReady. At that point, we should |
| 220 | // remove this. crosbug.com/23318. |
| 221 | adaptor_->EmitStringChanged( |
| 222 | flimflam::kStateProperty, flimflam::kStateReady); |
| 223 | } |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 224 | adaptor_->EmitStringChanged(flimflam::kStateProperty, CalculateState(&error)); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | void Service::SetFailure(ConnectFailure failure) { |
| 228 | failure_ = failure; |
| 229 | SetState(kStateFailure); |
| 230 | } |
| 231 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 232 | string Service::GetRpcIdentifier() const { |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 233 | return adaptor_->GetRpcIdentifier(); |
| 234 | } |
| 235 | |
Paul Stewart | bba6a5b | 2011-11-02 18:45:59 -0700 | [diff] [blame] | 236 | bool Service::IsLoadableFrom(StoreInterface *storage) const { |
| 237 | return storage->ContainsGroup(GetStorageIdentifier()); |
| 238 | } |
| 239 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 240 | bool Service::Load(StoreInterface *storage) { |
| 241 | const string id = GetStorageIdentifier(); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 242 | if (!storage->ContainsGroup(id)) { |
| 243 | LOG(WARNING) << "Service is not available in the persistent store: " << id; |
| 244 | return false; |
| 245 | } |
| 246 | storage->GetBool(id, kStorageAutoConnect, &auto_connect_); |
| 247 | storage->GetString(id, kStorageCheckPortal, &check_portal_); |
| 248 | storage->GetBool(id, kStorageFavorite, &favorite_); |
| 249 | storage->GetInt(id, kStoragePriority, &priority_); |
| 250 | storage->GetString(id, kStorageProxyConfig, &proxy_config_); |
| 251 | storage->GetBool(id, kStorageSaveCredentials, &save_credentials_); |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 252 | storage->GetString(id, kStorageUIData, &ui_data_); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 253 | |
| 254 | LoadEapCredentials(storage, id); |
| 255 | |
| 256 | // TODO(petkov): Load these: |
| 257 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 258 | // "Failure" |
| 259 | // "Modified" |
| 260 | // "LastAttempt" |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 261 | // "APN" |
| 262 | // "LastGoodAPN" |
| 263 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 264 | favorite_ = true; |
| 265 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 266 | return true; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 269 | void Service::Unload() { |
| 270 | auto_connect_ = false; |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 271 | check_portal_ = kCheckPortalAuto; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 272 | favorite_ = false; |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 273 | priority_ = kPriorityNone; |
| 274 | proxy_config_ = ""; |
| 275 | save_credentials_ = true; |
| 276 | ui_data_ = ""; |
| 277 | |
| 278 | UnloadEapCredentials(); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 279 | } |
| 280 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 281 | bool Service::Save(StoreInterface *storage) { |
| 282 | const string id = GetStorageIdentifier(); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 283 | |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 284 | storage->SetString(id, kStorageType, GetTechnologyString(NULL)); |
| 285 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 286 | // TODO(petkov): We could choose to simplify the saving code by removing most |
| 287 | // conditionals thus saving even default values. |
| 288 | if (favorite_) { |
| 289 | storage->SetBool(id, kStorageAutoConnect, auto_connect_); |
| 290 | } |
| 291 | if (check_portal_ == kCheckPortalAuto) { |
| 292 | storage->DeleteKey(id, kStorageCheckPortal); |
| 293 | } else { |
| 294 | storage->SetString(id, kStorageCheckPortal, check_portal_); |
| 295 | } |
| 296 | storage->SetBool(id, kStorageFavorite, favorite_); |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 297 | storage->SetString(id, kStorageName, friendly_name_); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 298 | if (priority_ != kPriorityNone) { |
| 299 | storage->SetInt(id, kStoragePriority, priority_); |
| 300 | } else { |
| 301 | storage->DeleteKey(id, kStoragePriority); |
| 302 | } |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 303 | SaveString(storage, id, kStorageProxyConfig, proxy_config_, false, true); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 304 | if (save_credentials_) { |
| 305 | storage->DeleteKey(id, kStorageSaveCredentials); |
| 306 | } else { |
| 307 | storage->SetBool(id, kStorageSaveCredentials, false); |
| 308 | } |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 309 | SaveString(storage, id, kStorageUIData, ui_data_, false, true); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 310 | |
| 311 | SaveEapCredentials(storage, id); |
| 312 | |
| 313 | // TODO(petkov): Save these: |
| 314 | |
| 315 | // "WiFi.HiddenSSID" |
| 316 | // "SSID" |
| 317 | // "Failure" |
| 318 | // "Modified" |
| 319 | // "LastAttempt" |
| 320 | // WiFiService: "Passphrase" |
| 321 | // "APN" |
| 322 | // "LastGoodAPN" |
| 323 | |
| 324 | return true; |
| 325 | } |
| 326 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 327 | void Service::MakeFavorite() { |
| 328 | if (favorite_) { |
| 329 | // We do not want to clobber the value of auto_connect_ (it may |
| 330 | // be user-set). So return early. |
| 331 | return; |
| 332 | } |
| 333 | |
| 334 | auto_connect_ = true; |
| 335 | favorite_ = true; |
| 336 | } |
| 337 | |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 338 | void Service::SetConnection(ConnectionRefPtr connection) { |
| 339 | if (connection.get()) { |
Paul Stewart | c8f4bef | 2011-12-13 09:45:51 -0800 | [diff] [blame] | 340 | http_proxy_.reset(new HTTPProxy(connection)); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 341 | http_proxy_->Start(dispatcher_, &sockets_); |
| 342 | } else { |
| 343 | http_proxy_.reset(); |
| 344 | } |
| 345 | connection_ = connection; |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 346 | } |
| 347 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 348 | // static |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 349 | const char *Service::ConnectFailureToString(const ConnectFailure &state) { |
| 350 | switch (state) { |
| 351 | case kFailureUnknown: |
| 352 | return "Unknown"; |
| 353 | case kFailureActivationFailure: |
| 354 | return "Activation Failure"; |
| 355 | case kFailureOutOfRange: |
| 356 | return "Out of range"; |
| 357 | case kFailurePinMissing: |
| 358 | return "PIN missing"; |
| 359 | case kFailureConfigurationFailed: |
| 360 | return "Configuration Failed"; |
| 361 | case kFailureBadCredentials: |
| 362 | return "Bad Credentials"; |
| 363 | case kFailureNeedEVDO: |
| 364 | return "Need EVDO"; |
| 365 | case kFailureNeedHomeNetwork: |
| 366 | return "Need Home Network"; |
| 367 | case kFailureOTASPFailure: |
| 368 | return "OTASP Failure"; |
| 369 | case kFailureAAAFailure: |
| 370 | return "AAA Failure"; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 371 | case kFailureMax: |
| 372 | return "Max failure error code"; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 373 | } |
| 374 | return "Invalid"; |
| 375 | } |
| 376 | |
| 377 | // static |
| 378 | const char *Service::ConnectStateToString(const ConnectState &state) { |
| 379 | switch (state) { |
| 380 | case kStateUnknown: |
| 381 | return "Unknown"; |
| 382 | case kStateIdle: |
| 383 | return "Idle"; |
| 384 | case kStateAssociating: |
| 385 | return "Associating"; |
| 386 | case kStateConfiguring: |
| 387 | return "Configuring"; |
| 388 | case kStateConnected: |
| 389 | return "Connected"; |
| 390 | case kStateDisconnected: |
| 391 | return "Disconnected"; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 392 | case kStateReady: |
| 393 | return "Ready"; |
| 394 | case kStatePortal: |
| 395 | return "Portal"; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 396 | case kStateFailure: |
| 397 | return "Failure"; |
| 398 | case kStateOnline: |
| 399 | return "Online"; |
| 400 | } |
| 401 | return "Invalid"; |
| 402 | } |
| 403 | |
| 404 | |
| 405 | // static |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 406 | string Service::GetTechnologyString(Error */*error*/) { |
| 407 | return Technology::NameFromIdentifier(technology()); |
| 408 | } |
| 409 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 410 | bool Service::DecideBetween(int a, int b, bool *decision) { |
| 411 | if (a == b) |
| 412 | return false; |
| 413 | *decision = (a > b); |
| 414 | return true; |
| 415 | } |
| 416 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 417 | // static |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 418 | bool Service::Compare(ServiceRefPtr a, |
| 419 | ServiceRefPtr b, |
| 420 | const vector<Technology::Identifier> &tech_order) { |
| 421 | bool ret; |
| 422 | |
| 423 | if (a->state() != b->state()) { |
| 424 | if (DecideBetween(a->IsConnected(), b->IsConnected(), &ret)) { |
| 425 | return ret; |
| 426 | } |
| 427 | |
| 428 | // TODO(pstew): Services don't know about portal state yet |
| 429 | |
| 430 | if (DecideBetween(a->IsConnecting(), b->IsConnecting(), &ret)) { |
| 431 | return ret; |
| 432 | } |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 433 | |
| 434 | if (DecideBetween(!a->IsFailed(), !b->IsFailed(), &ret)) { |
| 435 | return ret; |
| 436 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 437 | } |
| 438 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 439 | if (DecideBetween(a->connectable(), b->connectable(), &ret) || |
| 440 | DecideBetween(a->auto_connect(), b->auto_connect(), &ret) || |
| 441 | DecideBetween(a->favorite(), b->favorite(), &ret) || |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 442 | DecideBetween(a->priority(), b->priority(), &ret)) { |
| 443 | return ret; |
| 444 | } |
| 445 | |
| 446 | // TODO(pstew): Below this point we are making value judgements on |
| 447 | // services that are not related to anything intrinsic or |
| 448 | // user-specified. These heuristics should be richer (contain |
| 449 | // historical information, for example) and be subject to user |
| 450 | // customization. |
| 451 | |
| 452 | for (vector<Technology::Identifier>::const_iterator it = tech_order.begin(); |
| 453 | it != tech_order.end(); |
| 454 | ++it) { |
| 455 | if (DecideBetween(a->TechnologyIs(*it), b->TechnologyIs(*it), &ret)) |
| 456 | return ret; |
| 457 | } |
| 458 | |
Paul Stewart | 1ca3e85 | 2011-11-04 07:50:49 -0700 | [diff] [blame] | 459 | if (DecideBetween(a->security_level(), b->security_level(), &ret) || |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 460 | DecideBetween(a->strength(), b->strength(), &ret)) { |
| 461 | return ret; |
| 462 | } |
| 463 | |
| 464 | return a->UniqueName() < b->UniqueName(); |
| 465 | } |
| 466 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 467 | const ProfileRefPtr &Service::profile() const { return profile_; } |
| 468 | |
| 469 | void Service::set_profile(const ProfileRefPtr &p) { profile_ = p; } |
| 470 | |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 471 | void Service::set_connectable(bool connectable) { |
| 472 | connectable_ = connectable; |
| 473 | adaptor_->EmitBoolChanged(flimflam::kConnectableProperty, connectable_); |
| 474 | } |
| 475 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 476 | string Service::CalculateState(Error */*error*/) { |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 477 | switch (state_) { |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 478 | case kStateIdle: |
| 479 | return flimflam::kStateIdle; |
| 480 | case kStateAssociating: |
| 481 | return flimflam::kStateAssociation; |
| 482 | case kStateConfiguring: |
| 483 | return flimflam::kStateConfiguration; |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 484 | case kStateConnected: |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 485 | // TODO(gauravsh): Until portal handling is implemented, go to "online" |
| 486 | // instead of "ready" state. crosbug.com/23318 |
| 487 | return flimflam::kStateOnline; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 488 | case kStateDisconnected: |
| 489 | return flimflam::kStateDisconnect; |
| 490 | case kStateFailure: |
| 491 | return flimflam::kStateFailure; |
| 492 | case kStateOnline: |
| 493 | return flimflam::kStateOnline; |
| 494 | case kStateUnknown: |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 495 | default: |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 496 | return ""; |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 500 | void Service::HelpRegisterDerivedBool( |
| 501 | const string &name, |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 502 | bool(Service::*get)(Error *), |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 503 | void(Service::*set)(const bool&, Error *)) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 504 | store_.RegisterDerivedBool( |
| 505 | name, |
| 506 | BoolAccessor(new CustomAccessor<Service, bool>(this, get, set))); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 507 | } |
| 508 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 509 | void Service::HelpRegisterDerivedString( |
| 510 | const string &name, |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 511 | string(Service::*get)(Error *), |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 512 | void(Service::*set)(const string&, Error *)) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 513 | store_.RegisterDerivedString( |
| 514 | name, |
| 515 | StringAccessor(new CustomAccessor<Service, string>(this, get, set))); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 518 | void Service::HelpRegisterDerivedUint16( |
| 519 | const string &name, |
| 520 | uint16(Service::*get)(Error *), |
| 521 | void(Service::*set)(const uint16&, Error *)) { |
| 522 | store_.RegisterDerivedUint16( |
| 523 | name, |
| 524 | Uint16Accessor(new CustomAccessor<Service, uint16>(this, get, set))); |
| 525 | } |
| 526 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 527 | void Service::SaveString(StoreInterface *storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 528 | const string &id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 529 | const string &key, |
| 530 | const string &value, |
| 531 | bool crypted, |
| 532 | bool save) { |
| 533 | if (value.empty() || !save) { |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 534 | storage->DeleteKey(id, key); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 535 | return; |
| 536 | } |
| 537 | if (crypted) { |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 538 | storage->SetCryptedString(id, key, value); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 539 | return; |
| 540 | } |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 541 | storage->SetString(id, key, value); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 544 | void Service::LoadEapCredentials(StoreInterface *storage, const string &id) { |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 545 | storage->GetCryptedString(id, kStorageEapIdentity, &eap_.identity); |
| 546 | storage->GetString(id, kStorageEapEap, &eap_.eap); |
| 547 | storage->GetString(id, kStorageEapInnerEap, &eap_.inner_eap); |
| 548 | storage->GetCryptedString(id, |
| 549 | kStorageEapAnonymousIdentity, |
| 550 | &eap_.anonymous_identity); |
| 551 | storage->GetString(id, kStorageEapClientCert, &eap_.client_cert); |
| 552 | storage->GetString(id, kStorageEapCertID, &eap_.cert_id); |
| 553 | storage->GetString(id, kStorageEapPrivateKey, &eap_.private_key); |
| 554 | storage->GetCryptedString(id, |
| 555 | kStorageEapPrivateKeyPassword, |
| 556 | &eap_.private_key_password); |
| 557 | storage->GetString(id, kStorageEapKeyID, &eap_.key_id); |
| 558 | storage->GetString(id, kStorageEapCACert, &eap_.ca_cert); |
| 559 | storage->GetString(id, kStorageEapCACertID, &eap_.ca_cert_id); |
| 560 | storage->GetBool(id, kStorageEapUseSystemCAs, &eap_.use_system_cas); |
| 561 | storage->GetString(id, kStorageEapPIN, &eap_.pin); |
| 562 | storage->GetCryptedString(id, kStorageEapPassword, &eap_.password); |
| 563 | storage->GetString(id, kStorageEapKeyManagement, &eap_.key_management); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 564 | // TODO(quiche): Update Connectable property. (crosbug.com/23466) |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 567 | void Service::SaveEapCredentials(StoreInterface *storage, const string &id) { |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 568 | bool save = save_credentials_; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 569 | SaveString(storage, id, kStorageEapIdentity, eap_.identity, true, save); |
| 570 | SaveString(storage, id, kStorageEapEap, eap_.eap, false, true); |
| 571 | SaveString(storage, id, kStorageEapInnerEap, eap_.inner_eap, false, true); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 572 | SaveString(storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 573 | id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 574 | kStorageEapAnonymousIdentity, |
| 575 | eap_.anonymous_identity, |
| 576 | true, |
| 577 | save); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 578 | SaveString(storage, id, kStorageEapClientCert, eap_.client_cert, false, save); |
| 579 | SaveString(storage, id, kStorageEapCertID, eap_.cert_id, false, save); |
| 580 | SaveString(storage, id, kStorageEapPrivateKey, eap_.private_key, false, save); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 581 | SaveString(storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 582 | id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 583 | kStorageEapPrivateKeyPassword, |
| 584 | eap_.private_key_password, |
| 585 | true, |
| 586 | save); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 587 | SaveString(storage, id, kStorageEapKeyID, eap_.key_id, false, save); |
| 588 | SaveString(storage, id, kStorageEapCACert, eap_.ca_cert, false, true); |
| 589 | SaveString(storage, id, kStorageEapCACertID, eap_.ca_cert_id, false, true); |
| 590 | storage->SetBool(id, kStorageEapUseSystemCAs, eap_.use_system_cas); |
| 591 | SaveString(storage, id, kStorageEapPIN, eap_.pin, false, save); |
| 592 | SaveString(storage, id, kStorageEapPassword, eap_.password, true, save); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 593 | SaveString(storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 594 | id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 595 | kStorageEapKeyManagement, |
| 596 | eap_.key_management, |
| 597 | false, |
| 598 | true); |
| 599 | } |
| 600 | |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 601 | void Service::UnloadEapCredentials() { |
| 602 | eap_.identity = ""; |
| 603 | eap_.eap = ""; |
| 604 | eap_.inner_eap = ""; |
| 605 | eap_.anonymous_identity = ""; |
| 606 | eap_.client_cert = ""; |
| 607 | eap_.cert_id = ""; |
| 608 | eap_.private_key = ""; |
| 609 | eap_.private_key_password = ""; |
| 610 | eap_.key_id = ""; |
| 611 | eap_.ca_cert = ""; |
| 612 | eap_.ca_cert_id = ""; |
| 613 | eap_.use_system_cas = false; |
| 614 | eap_.pin = ""; |
| 615 | eap_.password = ""; |
| 616 | eap_.key_management = ""; |
| 617 | } |
| 618 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 619 | const string &Service::GetEAPKeyManagement() const { |
| 620 | return eap_.key_management; |
| 621 | } |
| 622 | |
| 623 | void Service::SetEAPKeyManagement(const string &key_management) { |
| 624 | eap_.key_management = key_management; |
| 625 | } |
| 626 | |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 627 | string Service::GetProfileRpcId(Error *error) { |
| 628 | if (!profile_) { |
| 629 | // This happens in some unit tests where profile_ is not set. |
| 630 | error->Populate(Error::kNotFound); |
| 631 | return ""; |
| 632 | } |
| 633 | return profile_->GetRpcIdentifier(); |
| 634 | } |
| 635 | |
| 636 | void Service::SetProfileRpcId(const string &profile, Error *error) { |
| 637 | manager_->SetProfileForService(this, profile, error); |
| 638 | } |
| 639 | |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 640 | uint16 Service::GetHTTPProxyPort(Error */*error*/) { |
| 641 | if (http_proxy_.get()) { |
| 642 | return static_cast<uint16>(http_proxy_->proxy_port()); |
| 643 | } |
| 644 | return 0; |
| 645 | } |
| 646 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 647 | } // namespace shill |