Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 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 | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 19 | #include "shill/control_interface.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 20 | #include "shill/error.h" |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 21 | #include "shill/manager.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 22 | #include "shill/profile.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 23 | #include "shill/property_accessor.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 24 | #include "shill/refptr_types.h" |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 25 | #include "shill/service_dbus_adaptor.h" |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 26 | #include "shill/store_interface.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 27 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 28 | using std::map; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 29 | using std::string; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 30 | using std::vector; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 31 | |
| 32 | namespace shill { |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 33 | |
| 34 | const char Service::kCheckPortalAuto[] = "auto"; |
| 35 | const char Service::kCheckPortalFalse[] = "false"; |
| 36 | const char Service::kCheckPortalTrue[] = "true"; |
| 37 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 38 | const int Service::kPriorityNone = 0; |
| 39 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 40 | const char Service::kStorageAutoConnect[] = "AutoConnect"; |
| 41 | const char Service::kStorageCheckPortal[] = "CheckPortal"; |
| 42 | const char Service::kStorageEapAnonymousIdentity[] = "EAP.AnonymousIdentity"; |
| 43 | const char Service::kStorageEapCACert[] = "EAP.CACert"; |
| 44 | const char Service::kStorageEapCACertID[] = "EAP.CACertID"; |
| 45 | const char Service::kStorageEapCertID[] = "EAP.CertID"; |
| 46 | const char Service::kStorageEapClientCert[] = "EAP.ClientCert"; |
| 47 | const char Service::kStorageEapEap[] = "EAP.EAP"; |
| 48 | const char Service::kStorageEapIdentity[] = "EAP.Identity"; |
| 49 | const char Service::kStorageEapInnerEap[] = "EAP.InnerEAP"; |
| 50 | const char Service::kStorageEapKeyID[] = "EAP.KeyID"; |
| 51 | const char Service::kStorageEapKeyManagement[] = "EAP.KeyMgmt"; |
| 52 | const char Service::kStorageEapPIN[] = "EAP.PIN"; |
| 53 | const char Service::kStorageEapPassword[] = "EAP.Password"; |
| 54 | const char Service::kStorageEapPrivateKey[] = "EAP.PrivateKey"; |
| 55 | const char Service::kStorageEapPrivateKeyPassword[] = "EAP.PrivateKeyPassword"; |
| 56 | const char Service::kStorageEapUseSystemCAs[] = "EAP.UseSystemCAs"; |
| 57 | const char Service::kStorageFavorite[] = "Favorite"; |
| 58 | const char Service::kStorageName[] = "Name"; |
| 59 | const char Service::kStoragePriority[] = "Priority"; |
| 60 | const char Service::kStorageProxyConfig[] = "ProxyConfig"; |
| 61 | const char Service::kStorageSaveCredentials[] = "SaveCredentials"; |
| 62 | |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 63 | // static |
| 64 | unsigned int Service::serial_number_ = 0; |
| 65 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 66 | Service::Service(ControlInterface *control_interface, |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 67 | EventDispatcher *dispatcher, |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 68 | Manager *manager, |
| 69 | const string &type) |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 70 | : state_(kStateUnknown), |
| 71 | failure_(kFailureUnknown), |
| 72 | auto_connect_(false), |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 73 | check_portal_(kCheckPortalAuto), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 74 | connectable_(false), |
| 75 | favorite_(false), |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 76 | priority_(kPriorityNone), |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 77 | security_(0), |
| 78 | strength_(0), |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 79 | save_credentials_(true), |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 80 | type_(type), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 81 | dispatcher_(dispatcher), |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 82 | name_(base::UintToString(serial_number_++)), |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 83 | available_(false), |
| 84 | configured_(false), |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 85 | configuration_(NULL), |
| 86 | connection_(NULL), |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 87 | adaptor_(control_interface->CreateServiceAdaptor(this)), |
| 88 | manager_(manager) { |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 89 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 90 | store_.RegisterBool(flimflam::kAutoConnectProperty, &auto_connect_); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 91 | |
| 92 | // flimflam::kActivationStateProperty: Registered in CellularService |
| 93 | // flimflam::kCellularApnProperty: Registered in CellularService |
| 94 | // flimflam::kCellularLastGoodApnProperty: Registered in CellularService |
| 95 | // flimflam::kNetworkTechnologyProperty: Registered in CellularService |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 96 | // flimflam::kOperatorNameProperty: DEPRECATED |
| 97 | // flimflam::kOperatorCodeProperty: DEPRECATED |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 98 | // flimflam::kRoamingStateProperty: Registered in CellularService |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 99 | // flimflam::kServingOperatorProperty: Registered in CellularService |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 100 | // flimflam::kPaymentURLProperty: Registered in CellularService |
| 101 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 102 | store_.RegisterString(flimflam::kCheckPortalProperty, &check_portal_); |
| 103 | store_.RegisterConstBool(flimflam::kConnectableProperty, &connectable_); |
| 104 | HelpRegisterDerivedString(flimflam::kDeviceProperty, |
| 105 | &Service::GetDeviceRpcId, |
| 106 | NULL); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 107 | |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 108 | store_.RegisterString(flimflam::kEapIdentityProperty, &eap_.identity); |
| 109 | store_.RegisterString(flimflam::kEAPEAPProperty, &eap_.eap); |
| 110 | store_.RegisterString(flimflam::kEapPhase2AuthProperty, &eap_.inner_eap); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 111 | store_.RegisterString(flimflam::kEapAnonymousIdentityProperty, |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 112 | &eap_.anonymous_identity); |
| 113 | store_.RegisterString(flimflam::kEAPClientCertProperty, &eap_.client_cert); |
| 114 | store_.RegisterString(flimflam::kEAPCertIDProperty, &eap_.cert_id); |
| 115 | store_.RegisterString(flimflam::kEapPrivateKeyProperty, &eap_.private_key); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 116 | store_.RegisterString(flimflam::kEapPrivateKeyPasswordProperty, |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 117 | &eap_.private_key_password); |
| 118 | store_.RegisterString(flimflam::kEAPKeyIDProperty, &eap_.key_id); |
| 119 | store_.RegisterString(flimflam::kEapCaCertProperty, &eap_.ca_cert); |
| 120 | store_.RegisterString(flimflam::kEapCaCertIDProperty, &eap_.ca_cert_id); |
| 121 | store_.RegisterString(flimflam::kEAPPINProperty, &eap_.pin); |
| 122 | store_.RegisterString(flimflam::kEapPasswordProperty, &eap_.password); |
| 123 | store_.RegisterString(flimflam::kEapKeyMgmtProperty, &eap_.key_management); |
| 124 | store_.RegisterBool(flimflam::kEapUseSystemCAsProperty, &eap_.use_system_cas); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 125 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 126 | store_.RegisterConstString(flimflam::kErrorProperty, &error_); |
| 127 | store_.RegisterConstBool(flimflam::kFavoriteProperty, &favorite_); |
| 128 | HelpRegisterDerivedBool(flimflam::kIsActiveProperty, |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 129 | &Service::IsActive, |
| 130 | NULL); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 131 | // flimflam::kModeProperty: Registered in WiFiService |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 132 | store_.RegisterConstString(flimflam::kNameProperty, &name_); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 133 | // flimflam::kPassphraseProperty: Registered in WiFiService |
| 134 | // flimflam::kPassphraseRequiredProperty: Registered in WiFiService |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 135 | store_.RegisterInt32(flimflam::kPriorityProperty, &priority_); |
| 136 | HelpRegisterDerivedString(flimflam::kProfileProperty, |
| 137 | &Service::GetProfileRpcId, |
| 138 | NULL); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 139 | store_.RegisterString(flimflam::kProxyConfigProperty, &proxy_config_); |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 140 | // TODO(cmasone): Create VPN Service with this property |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 141 | // store_.RegisterConstStringmap(flimflam::kProviderProperty, &provider_); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 142 | |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 143 | store_.RegisterBool(flimflam::kSaveCredentialsProperty, &save_credentials_); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 144 | store_.RegisterConstString(flimflam::kTypeProperty, &type_); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 145 | // flimflam::kSecurityProperty: Registered in WiFiService |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 146 | HelpRegisterDerivedString(flimflam::kStateProperty, |
| 147 | &Service::CalculateState, |
| 148 | NULL); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 149 | // flimflam::kSignalStrengthProperty: Registered in WiFi/CellularService |
| 150 | // flimflam::kTypeProperty: Registered in all derived classes. |
| 151 | // flimflam::kWifiAuthMode: Registered in WiFiService |
| 152 | // flimflam::kWifiHiddenSsid: Registered in WiFiService |
| 153 | // flimflam::kWifiFrequency: Registered in WiFiService |
| 154 | // flimflam::kWifiPhyMode: Registered in WiFiService |
| 155 | // flimflam::kWifiHexSsid: Registered in WiFiService |
Chris Masone | b07006b | 2011-05-14 16:10:04 -0700 | [diff] [blame] | 156 | VLOG(2) << "Service initialized."; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Paul Stewart | ba41b99 | 2011-05-26 07:02:46 -0700 | [diff] [blame] | 159 | Service::~Service() {} |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 160 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 161 | void Service::ActivateCellularModem(const std::string &/*carrier*/, |
| 162 | Error *error) { |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 163 | const string kMessage = "Service doesn't support cellular modem activation."; |
| 164 | LOG(ERROR) << kMessage; |
| 165 | CHECK(error); |
| 166 | error->Populate(Error::kInvalidArguments, kMessage); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 167 | } |
| 168 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 169 | bool Service::TechnologyIs(const Technology::Identifier /*type*/) const { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 170 | return false; |
| 171 | } |
| 172 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 173 | bool Service::IsActive() { |
| 174 | return state_ != kStateUnknown && |
| 175 | state_ != kStateIdle && |
| 176 | state_ != kStateFailure; |
| 177 | } |
| 178 | |
| 179 | void Service::SetState(ConnectState state) { |
| 180 | if (state == state_) { |
| 181 | return; |
| 182 | } |
| 183 | |
| 184 | state_ = state; |
| 185 | if (state != kStateFailure) { |
| 186 | failure_ = kFailureUnknown; |
| 187 | } |
| 188 | manager_->UpdateService(this); |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 189 | adaptor_->EmitStringChanged(flimflam::kStateProperty, CalculateState()); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | void Service::SetFailure(ConnectFailure failure) { |
| 193 | failure_ = failure; |
| 194 | SetState(kStateFailure); |
| 195 | } |
| 196 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 197 | string Service::GetRpcIdentifier() const { |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 198 | return adaptor_->GetRpcIdentifier(); |
| 199 | } |
| 200 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 201 | bool Service::Load(StoreInterface *storage) { |
| 202 | const string id = GetStorageIdentifier(); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 203 | if (!storage->ContainsGroup(id)) { |
| 204 | LOG(WARNING) << "Service is not available in the persistent store: " << id; |
| 205 | return false; |
| 206 | } |
| 207 | storage->GetBool(id, kStorageAutoConnect, &auto_connect_); |
| 208 | storage->GetString(id, kStorageCheckPortal, &check_portal_); |
| 209 | storage->GetBool(id, kStorageFavorite, &favorite_); |
| 210 | storage->GetInt(id, kStoragePriority, &priority_); |
| 211 | storage->GetString(id, kStorageProxyConfig, &proxy_config_); |
| 212 | storage->GetBool(id, kStorageSaveCredentials, &save_credentials_); |
| 213 | |
| 214 | LoadEapCredentials(storage, id); |
| 215 | |
| 216 | // TODO(petkov): Load these: |
| 217 | |
| 218 | // "Name" |
| 219 | // "WiFi.HiddenSSID" |
| 220 | // "SSID" |
| 221 | // "Failure" |
| 222 | // "Modified" |
| 223 | // "LastAttempt" |
| 224 | // WiFiService: "Passphrase" |
| 225 | // "APN" |
| 226 | // "LastGoodAPN" |
| 227 | |
| 228 | return true; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 231 | bool Service::Save(StoreInterface *storage) { |
| 232 | const string id = GetStorageIdentifier(); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 233 | |
| 234 | // TODO(petkov): We could choose to simplify the saving code by removing most |
| 235 | // conditionals thus saving even default values. |
| 236 | if (favorite_) { |
| 237 | storage->SetBool(id, kStorageAutoConnect, auto_connect_); |
| 238 | } |
| 239 | if (check_portal_ == kCheckPortalAuto) { |
| 240 | storage->DeleteKey(id, kStorageCheckPortal); |
| 241 | } else { |
| 242 | storage->SetString(id, kStorageCheckPortal, check_portal_); |
| 243 | } |
| 244 | storage->SetBool(id, kStorageFavorite, favorite_); |
| 245 | storage->SetString(id, kStorageName, name_); |
| 246 | SaveString(storage, id, kStorageProxyConfig, proxy_config_, false, true); |
| 247 | if (priority_ != kPriorityNone) { |
| 248 | storage->SetInt(id, kStoragePriority, priority_); |
| 249 | } else { |
| 250 | storage->DeleteKey(id, kStoragePriority); |
| 251 | } |
| 252 | if (save_credentials_) { |
| 253 | storage->DeleteKey(id, kStorageSaveCredentials); |
| 254 | } else { |
| 255 | storage->SetBool(id, kStorageSaveCredentials, false); |
| 256 | } |
| 257 | |
| 258 | SaveEapCredentials(storage, id); |
| 259 | |
| 260 | // TODO(petkov): Save these: |
| 261 | |
| 262 | // "WiFi.HiddenSSID" |
| 263 | // "SSID" |
| 264 | // "Failure" |
| 265 | // "Modified" |
| 266 | // "LastAttempt" |
| 267 | // WiFiService: "Passphrase" |
| 268 | // "APN" |
| 269 | // "LastGoodAPN" |
| 270 | |
| 271 | return true; |
| 272 | } |
| 273 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 274 | bool Service::DecideBetween(int a, int b, bool *decision) { |
| 275 | if (a == b) |
| 276 | return false; |
| 277 | *decision = (a > b); |
| 278 | return true; |
| 279 | } |
| 280 | |
| 281 | bool Service::Compare(ServiceRefPtr a, |
| 282 | ServiceRefPtr b, |
| 283 | const vector<Technology::Identifier> &tech_order) { |
| 284 | bool ret; |
| 285 | |
| 286 | if (a->state() != b->state()) { |
| 287 | if (DecideBetween(a->IsConnected(), b->IsConnected(), &ret)) { |
| 288 | return ret; |
| 289 | } |
| 290 | |
| 291 | // TODO(pstew): Services don't know about portal state yet |
| 292 | |
| 293 | if (DecideBetween(a->IsConnecting(), b->IsConnecting(), &ret)) { |
| 294 | return ret; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | if (DecideBetween(a->favorite(), b->favorite(), &ret) || |
| 299 | DecideBetween(a->priority(), b->priority(), &ret)) { |
| 300 | return ret; |
| 301 | } |
| 302 | |
| 303 | // TODO(pstew): Below this point we are making value judgements on |
| 304 | // services that are not related to anything intrinsic or |
| 305 | // user-specified. These heuristics should be richer (contain |
| 306 | // historical information, for example) and be subject to user |
| 307 | // customization. |
| 308 | |
| 309 | for (vector<Technology::Identifier>::const_iterator it = tech_order.begin(); |
| 310 | it != tech_order.end(); |
| 311 | ++it) { |
| 312 | if (DecideBetween(a->TechnologyIs(*it), b->TechnologyIs(*it), &ret)) |
| 313 | return ret; |
| 314 | } |
| 315 | |
| 316 | if (DecideBetween(a->security(), b->security(), &ret) || |
| 317 | DecideBetween(a->strength(), b->strength(), &ret)) { |
| 318 | return ret; |
| 319 | } |
| 320 | |
| 321 | return a->UniqueName() < b->UniqueName(); |
| 322 | } |
| 323 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 324 | const ProfileRefPtr &Service::profile() const { return profile_; } |
| 325 | |
| 326 | void Service::set_profile(const ProfileRefPtr &p) { profile_ = p; } |
| 327 | |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 328 | string Service::CalculateState() { |
| 329 | switch (state_) { |
| 330 | case kStateConnected: |
| 331 | return flimflam::kStateReady; |
| 332 | default: |
| 333 | // TODO(quiche): provide strings for other states |
| 334 | return flimflam::kStateIdle; |
| 335 | } |
| 336 | } |
| 337 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 338 | void Service::HelpRegisterDerivedBool(const string &name, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 339 | bool(Service::*get)(void), |
| 340 | bool(Service::*set)(const bool&)) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 341 | store_.RegisterDerivedBool( |
| 342 | name, |
| 343 | BoolAccessor(new CustomAccessor<Service, bool>(this, get, set))); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 346 | void Service::HelpRegisterDerivedString(const string &name, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 347 | string(Service::*get)(void), |
| 348 | bool(Service::*set)(const string&)) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 349 | store_.RegisterDerivedString( |
| 350 | name, |
| 351 | StringAccessor(new CustomAccessor<Service, string>(this, get, set))); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 354 | void Service::SaveString(StoreInterface *storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 355 | const string &id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 356 | const string &key, |
| 357 | const string &value, |
| 358 | bool crypted, |
| 359 | bool save) { |
| 360 | if (value.empty() || !save) { |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 361 | storage->DeleteKey(id, key); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 362 | return; |
| 363 | } |
| 364 | if (crypted) { |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 365 | storage->SetCryptedString(id, key, value); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 366 | return; |
| 367 | } |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 368 | storage->SetString(id, key, value); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 371 | void Service::LoadEapCredentials(StoreInterface *storage, const string &id) { |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 372 | storage->GetCryptedString(id, kStorageEapIdentity, &eap_.identity); |
| 373 | storage->GetString(id, kStorageEapEap, &eap_.eap); |
| 374 | storage->GetString(id, kStorageEapInnerEap, &eap_.inner_eap); |
| 375 | storage->GetCryptedString(id, |
| 376 | kStorageEapAnonymousIdentity, |
| 377 | &eap_.anonymous_identity); |
| 378 | storage->GetString(id, kStorageEapClientCert, &eap_.client_cert); |
| 379 | storage->GetString(id, kStorageEapCertID, &eap_.cert_id); |
| 380 | storage->GetString(id, kStorageEapPrivateKey, &eap_.private_key); |
| 381 | storage->GetCryptedString(id, |
| 382 | kStorageEapPrivateKeyPassword, |
| 383 | &eap_.private_key_password); |
| 384 | storage->GetString(id, kStorageEapKeyID, &eap_.key_id); |
| 385 | storage->GetString(id, kStorageEapCACert, &eap_.ca_cert); |
| 386 | storage->GetString(id, kStorageEapCACertID, &eap_.ca_cert_id); |
| 387 | storage->GetBool(id, kStorageEapUseSystemCAs, &eap_.use_system_cas); |
| 388 | storage->GetString(id, kStorageEapPIN, &eap_.pin); |
| 389 | storage->GetCryptedString(id, kStorageEapPassword, &eap_.password); |
| 390 | storage->GetString(id, kStorageEapKeyManagement, &eap_.key_management); |
| 391 | } |
| 392 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 393 | void Service::SaveEapCredentials(StoreInterface *storage, const string &id) { |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 394 | bool save = save_credentials_; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 395 | SaveString(storage, id, kStorageEapIdentity, eap_.identity, true, save); |
| 396 | SaveString(storage, id, kStorageEapEap, eap_.eap, false, true); |
| 397 | SaveString(storage, id, kStorageEapInnerEap, eap_.inner_eap, false, true); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 398 | SaveString(storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 399 | id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 400 | kStorageEapAnonymousIdentity, |
| 401 | eap_.anonymous_identity, |
| 402 | true, |
| 403 | save); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 404 | SaveString(storage, id, kStorageEapClientCert, eap_.client_cert, false, save); |
| 405 | SaveString(storage, id, kStorageEapCertID, eap_.cert_id, false, save); |
| 406 | SaveString(storage, id, kStorageEapPrivateKey, eap_.private_key, false, save); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 407 | SaveString(storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 408 | id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 409 | kStorageEapPrivateKeyPassword, |
| 410 | eap_.private_key_password, |
| 411 | true, |
| 412 | save); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 413 | SaveString(storage, id, kStorageEapKeyID, eap_.key_id, false, save); |
| 414 | SaveString(storage, id, kStorageEapCACert, eap_.ca_cert, false, true); |
| 415 | SaveString(storage, id, kStorageEapCACertID, eap_.ca_cert_id, false, true); |
| 416 | storage->SetBool(id, kStorageEapUseSystemCAs, eap_.use_system_cas); |
| 417 | SaveString(storage, id, kStorageEapPIN, eap_.pin, false, save); |
| 418 | SaveString(storage, id, kStorageEapPassword, eap_.password, true, save); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 419 | SaveString(storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 420 | id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 421 | kStorageEapKeyManagement, |
| 422 | eap_.key_management, |
| 423 | false, |
| 424 | true); |
| 425 | } |
| 426 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 427 | const string &Service::GetEAPKeyManagement() const { |
| 428 | return eap_.key_management; |
| 429 | } |
| 430 | |
| 431 | void Service::SetEAPKeyManagement(const string &key_management) { |
| 432 | eap_.key_management = key_management; |
| 433 | } |
| 434 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 435 | } // namespace shill |