mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -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 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 5 | #ifndef SHILL_WIFI_SERVICE_H_ |
| 6 | #define SHILL_WIFI_SERVICE_H_ |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 7 | |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 8 | #include <set> |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
Paul Stewart | 5baebb7 | 2013-03-14 11:43:29 -0700 | [diff] [blame] | 12 | #include <base/memory/scoped_ptr.h> |
| 13 | |
Paul Stewart | a283e4e | 2013-10-22 20:50:14 -0700 | [diff] [blame] | 14 | #include "shill/dbus_properties.h" |
Alex Vakulenko | a41ab51 | 2014-07-23 14:24:23 -0700 | [diff] [blame] | 15 | #include "shill/dbus_proxies/supplicant-interface.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 16 | #include "shill/event_dispatcher.h" |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 17 | #include "shill/key_value_store.h" |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 18 | #include "shill/refptr_types.h" |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 19 | #include "shill/service.h" |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 20 | |
| 21 | namespace shill { |
| 22 | |
Paul Stewart | 5baebb7 | 2013-03-14 11:43:29 -0700 | [diff] [blame] | 23 | class CertificateFile; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 24 | class ControlInterface; |
| 25 | class EventDispatcher; |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 26 | class Error; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 27 | class Manager; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 28 | class Metrics; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 29 | class WiFiProvider; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 30 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 31 | class WiFiService : public Service { |
| 32 | public: |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 33 | // TODO(pstew): Storage constants shouldn't need to be public |
Paul Stewart | ee6b3d7 | 2013-07-12 16:07:51 -0700 | [diff] [blame] | 34 | // crbug.com/208736 |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 35 | static const char kStorageHiddenSSID[]; |
| 36 | static const char kStorageMode[]; |
| 37 | static const char kStoragePassphrase[]; |
| 38 | static const char kStorageSecurity[]; |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 39 | static const char kStorageSecurityClass[]; |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 40 | static const char kStorageSSID[]; |
| 41 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 42 | WiFiService(ControlInterface *control_interface, |
| 43 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 44 | Metrics *metrics, |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 45 | Manager *manager, |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 46 | WiFiProvider *provider, |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 47 | const std::vector<uint8_t> &ssid, |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 48 | const std::string &mode, |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 49 | const std::string &security, |
| 50 | bool hidden_ssid); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 51 | ~WiFiService(); |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 52 | |
| 53 | // Inherited from Service. |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 54 | virtual void Connect(Error *error, const char *reason); |
Samuel Tan | 0d06119 | 2014-07-07 15:45:15 -0700 | [diff] [blame] | 55 | virtual void Disconnect(Error *error, const char *reason); |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 56 | virtual bool Is8021x() const; |
| 57 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 58 | virtual void AddEndpoint(const WiFiEndpointConstRefPtr &endpoint); |
| 59 | virtual void RemoveEndpoint(const WiFiEndpointConstRefPtr &endpoint); |
| 60 | virtual int GetEndpointCount() const { return endpoints_.size(); } |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 61 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 62 | // Called to update the identity of the currently connected endpoint. |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 63 | // To indicate that there is no currently connect endpoint, call with |
| 64 | // |endpoint| set to NULL. |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 65 | virtual void NotifyCurrentEndpoint(const WiFiEndpointConstRefPtr &endpoint); |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 66 | // Called to inform of changes in the properties of an endpoint. |
| 67 | // (Not necessarily the currently connected endpoint.) |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 68 | virtual void NotifyEndpointUpdated(const WiFiEndpointConstRefPtr &endpoint); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 69 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 70 | // wifi_<MAC>_<BSSID>_<mode_string>_<security_string> |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 71 | std::string GetStorageIdentifier() const; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 72 | static bool ParseStorageIdentifier(const std::string &storage_name, |
| 73 | std::string *address, |
| 74 | std::string *mode, |
| 75 | std::string *security); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 76 | |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 77 | // Iterate over |storage| looking for WiFi servces with "old-style" |
| 78 | // properties that don't include explicit type/mode/security, and add |
| 79 | // these properties. Returns true if any entries were fixed. |
| 80 | static bool FixupServiceEntries(StoreInterface *storage); |
| 81 | |
Paul Stewart | d2e1c36 | 2013-03-03 19:06:07 -0800 | [diff] [blame] | 82 | // Validate |mode| against all valid and supported service modes. |
| 83 | static bool IsValidMode(const std::string &mode); |
| 84 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 85 | // Validate |method| against all valid and supported security methods. |
| 86 | static bool IsValidSecurityMethod(const std::string &method); |
| 87 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 88 | const std::string &mode() const { return mode_; } |
| 89 | const std::string &key_management() const { return GetEAPKeyManagement(); } |
| 90 | const std::vector<uint8_t> &ssid() const { return ssid_; } |
Christopher Wiley | 1057cd7 | 2013-02-28 15:21:29 -0800 | [diff] [blame] | 91 | const std::string &bssid() const { return bssid_; } |
mukesh agrawal | e7c7e65 | 2013-06-18 17:19:39 -0700 | [diff] [blame] | 92 | const std::vector<uint16> &frequency_list() const { return frequency_list_; } |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 93 | uint16 physical_mode() const { return physical_mode_; } |
mukesh agrawal | a5dda0e | 2013-08-16 11:53:10 -0700 | [diff] [blame] | 94 | uint16 frequency() const { return frequency_; } |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 95 | |
Paul Stewart | e7de294 | 2013-04-25 17:07:31 -0700 | [diff] [blame] | 96 | // WiFi services can load from profile entries other than their current |
| 97 | // storage identifier. Override the methods from the parent Service |
| 98 | // class which pertain to whether this service may be loaded from |storage|. |
| 99 | virtual std::string GetLoadableStorageIdentifier( |
| 100 | const StoreInterface &storage) const; |
| 101 | virtual bool IsLoadableFrom(const StoreInterface &storage) const; |
| 102 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 103 | // Overrride Load and Save from parent Service class. We will call |
| 104 | // the parent method. |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 105 | virtual bool Load(StoreInterface *storage); |
| 106 | virtual bool Save(StoreInterface *storage); |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 107 | virtual bool Unload(); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 108 | |
Paul Stewart | 7cc9068 | 2014-05-30 17:01:56 -0700 | [diff] [blame] | 109 | // Override SetState from parent Service class. We will call the |
| 110 | // parent method. |
| 111 | virtual void SetState(ConnectState state) override; |
| 112 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 113 | virtual bool HasEndpoints() const { return !endpoints_.empty(); } |
Paul Stewart | cca85b1 | 2014-05-30 13:56:35 -0700 | [diff] [blame] | 114 | virtual bool IsVisible() const override; |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 115 | bool IsSecurityMatch(const std::string &security) const; |
Paul Stewart | bca08f8 | 2013-07-09 16:32:37 -0700 | [diff] [blame] | 116 | |
| 117 | // Used by WiFi objects to indicate that the credentials for this network |
| 118 | // have been called into question. This method returns true if given this |
| 119 | // suspicion, if it is probable that indeed these credentials are likely |
| 120 | // to be incorrect. Credentials that have never been used before are |
| 121 | // considered suspect by default, while those which have been used |
| 122 | // successfully in the past must have this method called a number of times |
| 123 | // since the last time ResetSuspectedCredentialsFailures() was called. |
| 124 | virtual bool AddSuspectedCredentialFailure(); |
| 125 | virtual void ResetSuspectedCredentialFailures(); |
| 126 | |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 127 | bool hidden_ssid() const { return hidden_ssid_; } |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 128 | bool ieee80211w_required() const { return ieee80211w_required_; } |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 129 | |
mukesh agrawal | 6cfe53f | 2013-08-13 13:39:01 -0700 | [diff] [blame] | 130 | void InitializeCustomMetrics() const; |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 131 | virtual void SendPostReadyStateMetrics( |
| 132 | int64 time_resume_to_ready_milliseconds) const; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 133 | |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 134 | // Clear any cached credentials stored in wpa_supplicant related to |this|. |
| 135 | // This will disconnect this service if it is currently connected. |
| 136 | void ClearCachedCredentials(); |
| 137 | |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 138 | // Override from parent Service class to correctly update connectability |
| 139 | // when the EAP credentials change for 802.1x networks. |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 140 | void OnEapCredentialsChanged(); |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 141 | |
Rebecca Silberstein | b6df8b1 | 2014-07-10 16:07:08 -0700 | [diff] [blame] | 142 | // Called by WiFiService to reset state associated with prior success |
| 143 | // of a connection with particular EAP credentials or a passphrase. |
| 144 | void OnCredentialChange(); |
| 145 | |
Paul Stewart | 4357f4e | 2012-04-26 17:39:26 -0700 | [diff] [blame] | 146 | // Override from parent Service class to register hidden services once they |
| 147 | // have been configured. |
| 148 | virtual void OnProfileConfigured(); |
| 149 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 150 | // Called by WiFiProvider to reset the WiFi device reference on shutdown. |
| 151 | virtual void ResetWiFi(); |
| 152 | |
Paul Stewart | a283e4e | 2013-10-22 20:50:14 -0700 | [diff] [blame] | 153 | // Called by WiFi to retrieve configuration parameters for wpa_supplicant. |
| 154 | virtual DBusPropertiesMap GetSupplicantConfigurationParameters() const; |
| 155 | |
Paul Stewart | 08a54eb | 2013-03-11 12:07:36 -0700 | [diff] [blame] | 156 | // "wpa", "rsn" and "psk" are equivalent from a configuration perspective. |
| 157 | // This function maps them all into "psk". |
| 158 | static std::string GetSecurityClass(const std::string &security); |
| 159 | |
Peter Qiu | 574996a | 2014-04-04 10:55:47 -0700 | [diff] [blame] | 160 | virtual bool IsAutoConnectable(const char **reason) const; |
| 161 | |
Wade Guthrie | 9ec0806 | 2013-09-25 15:22:24 -0700 | [diff] [blame] | 162 | // Signal level in dBm. If no current endpoint, returns |
| 163 | // std::numeric_limits<int>::min(). |
| 164 | int16 SignalLevel() const; |
| 165 | |
Peter Qiu | 4943822 | 2014-03-14 14:21:09 -0700 | [diff] [blame] | 166 | void set_expecting_disconnect(bool val) { expecting_disconnect_ = val; } |
| 167 | bool expecting_disconnect() const { return expecting_disconnect_; } |
| 168 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 169 | protected: |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 170 | virtual void SetEAPKeyManagement(const std::string &key_management); |
Paul Stewart | fa11e28 | 2013-12-02 22:04:25 -0800 | [diff] [blame] | 171 | virtual std::string GetTethering(Error *error) const override; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 172 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 173 | private: |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 174 | friend class WiFiServiceSecurityTest; |
Paul Stewart | 0b95044 | 2012-09-11 13:10:08 -0700 | [diff] [blame] | 175 | friend class WiFiServiceTest; // SetPassphrase |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 176 | friend class WiFiServiceUpdateFromEndpointsTest; // SignalToStrength |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 177 | FRIEND_TEST(MetricsTest, WiFiServicePostReady); |
Paul Stewart | e4cedde | 2013-07-17 08:56:44 -0700 | [diff] [blame] | 178 | FRIEND_TEST(MetricsTest, WiFiServicePostReadyAdHoc); |
Paul Stewart | 21f4096 | 2013-03-01 14:27:28 -0800 | [diff] [blame] | 179 | FRIEND_TEST(MetricsTest, WiFiServicePostReadyEAP); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 180 | FRIEND_TEST(WiFiMainTest, CurrentBSSChangedUpdateServiceEndpoint); |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 181 | FRIEND_TEST(WiFiProviderTest, OnEndpointAddedWithSecurity); // security_ |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 182 | FRIEND_TEST(WiFiServiceTest, AutoConnect); |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 183 | FRIEND_TEST(WiFiServiceTest, ClearWriteOnlyDerivedProperty); // passphrase_ |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 184 | FRIEND_TEST(WiFiServiceTest, ComputeCipher8021x); |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 185 | FRIEND_TEST(WiFiServiceTest, ConnectTask8021x); |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 186 | FRIEND_TEST(WiFiServiceTest, ConnectTaskDynamicWEP); |
Gaurav Shah | f8721ee | 2011-11-07 09:12:46 -0800 | [diff] [blame] | 187 | FRIEND_TEST(WiFiServiceTest, ConnectTaskPSK); |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 188 | FRIEND_TEST(WiFiServiceTest, ConnectTaskRSN); |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 189 | FRIEND_TEST(WiFiServiceTest, ConnectTaskWEP); |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 190 | FRIEND_TEST(WiFiServiceTest, ConnectTaskWPA); |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 191 | FRIEND_TEST(WiFiServiceTest, ConnectTaskWPA80211w); |
Paul Stewart | fa11e28 | 2013-12-02 22:04:25 -0800 | [diff] [blame] | 192 | FRIEND_TEST(WiFiServiceTest, GetTethering); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 193 | FRIEND_TEST(WiFiServiceTest, IsAutoConnectable); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 194 | FRIEND_TEST(WiFiServiceTest, LoadHidden); |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 195 | FRIEND_TEST(WiFiServiceTest, LoadAndUnloadPassphrase); |
Paul Stewart | 6df20bd | 2013-03-13 19:31:25 -0700 | [diff] [blame] | 196 | FRIEND_TEST(WiFiServiceTest, SecurityFromCurrentEndpoint); // GetSecurity |
Rebecca Silberstein | e99f664 | 2014-07-09 14:04:31 -0700 | [diff] [blame] | 197 | FRIEND_TEST(WiFiServiceTest, SetPassphraseResetHasEverConnected); |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 198 | FRIEND_TEST(WiFiServiceTest, SetPassphraseRemovesCachedCredentials); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 199 | FRIEND_TEST(WiFiServiceTest, SignalToStrength); // SignalToStrength |
Paul Stewart | bca08f8 | 2013-07-09 16:32:37 -0700 | [diff] [blame] | 200 | FRIEND_TEST(WiFiServiceTest, SuspectedCredentialFailure); |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 201 | FRIEND_TEST(WiFiServiceTest, UpdateSecurity); // SetEAPKeyManagement |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 202 | |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 203 | static const char kAutoConnNoEndpoint[]; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 204 | static const char kAnyDeviceAddress[]; |
Paul Stewart | bca08f8 | 2013-07-09 16:32:37 -0700 | [diff] [blame] | 205 | static const int kSuspectedCredentialFailureThreshold; |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 206 | |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 207 | // Override the base clase implementation, because we need to allow |
| 208 | // arguments that aren't base class methods. |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 209 | void HelpRegisterConstDerivedString( |
| 210 | const std::string &name, |
| 211 | std::string(WiFiService::*get)(Error *error)); |
Paul Stewart | 6df20bd | 2013-03-13 19:31:25 -0700 | [diff] [blame] | 212 | void HelpRegisterDerivedString( |
| 213 | const std::string &name, |
| 214 | std::string(WiFiService::*get)(Error *error), |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 215 | bool(WiFiService::*set)(const std::string &value, Error *error)); |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 216 | void HelpRegisterWriteOnlyDerivedString( |
Thieu Le | f770945 | 2011-11-15 01:13:19 +0000 | [diff] [blame] | 217 | const std::string &name, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 218 | bool(WiFiService::*set)(const std::string &value, Error *error), |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 219 | void(WiFiService::*clear)(Error *error), |
| 220 | const std::string *default_value); |
Thieu Le | f770945 | 2011-11-15 01:13:19 +0000 | [diff] [blame] | 221 | |
Paul Stewart | 1cf7eb8 | 2013-12-03 19:34:36 -0800 | [diff] [blame] | 222 | std::string GetDeviceRpcId(Error *error) const; |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 223 | |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 224 | void ClearPassphrase(Error *error); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 225 | void UpdateConnectable(); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 226 | void UpdateFromEndpoints(); |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 227 | void UpdateSecurity(); |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 228 | |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 229 | static CryptoAlgorithm ComputeCipher8021x( |
| 230 | const std::set<WiFiEndpointConstRefPtr> &endpoints); |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 231 | static void ValidateWEPPassphrase(const std::string &passphrase, |
| 232 | Error *error); |
| 233 | static void ValidateWPAPassphrase(const std::string &passphrase, |
| 234 | Error *error); |
| 235 | static void ParseWEPPassphrase(const std::string &passphrase, |
| 236 | int *key_index, |
| 237 | std::vector<uint8> *password_bytes, |
| 238 | Error *error); |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 239 | static bool CheckWEPIsHex(const std::string &passphrase, Error *error); |
| 240 | static bool CheckWEPKeyIndex(const std::string &passphrase, Error *error); |
| 241 | static bool CheckWEPPrefix(const std::string &passphrase, Error *error); |
| 242 | |
mukesh agrawal | 8f3f775 | 2012-02-17 19:42:09 -0800 | [diff] [blame] | 243 | // Maps a signal value, in dBm, to a "strength" value, from |
| 244 | // |Service::kStrengthMin| to |Service:kStrengthMax|. |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 245 | static uint8 SignalToStrength(int16 signal_dbm); |
| 246 | |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 247 | // Create a default group name for this WiFi service. |
| 248 | std::string GetDefaultStorageIdentifier() const; |
| 249 | |
Paul Stewart | 6df20bd | 2013-03-13 19:31:25 -0700 | [diff] [blame] | 250 | // Return the security of this service. If connected, the security |
| 251 | // reported from the currently connected endpoint is returned. Otherwise |
| 252 | // the configured security for the service is returned. |
| 253 | std::string GetSecurity(Error *error); |
| 254 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 255 | // Profile data for a WPA/RSN service can be stored under a number of |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 256 | // different security types. These functions create different storage |
| 257 | // property lists based on whether they are saved with their generic |
| 258 | // "psk" name or if they use the (legacy) specific "wpa" or "rsn" names. |
| 259 | KeyValueStore GetStorageProperties() const; |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 260 | |
Paul Stewart | 0b95044 | 2012-09-11 13:10:08 -0700 | [diff] [blame] | 261 | // Validate then apply a passphrase for this service. |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 262 | bool SetPassphrase(const std::string &passphrase, Error *error); |
Paul Stewart | 0b95044 | 2012-09-11 13:10:08 -0700 | [diff] [blame] | 263 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 264 | // Select a WiFi device (e.g, for connecting a hidden service with no |
| 265 | // endpoints). |
| 266 | WiFiRefPtr ChooseDevice(); |
| 267 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 268 | void SetWiFi(const WiFiRefPtr &new_wifi); |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 269 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 270 | // Properties |
| 271 | std::string passphrase_; |
| 272 | bool need_passphrase_; |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 273 | const std::string security_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 274 | // TODO(cmasone): see if the below can be pulled from the endpoint associated |
| 275 | // with this service instead. |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 276 | const std::string mode_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 277 | std::string auth_mode_; |
| 278 | bool hidden_ssid_; |
| 279 | uint16 frequency_; |
mukesh agrawal | e7c7e65 | 2013-06-18 17:19:39 -0700 | [diff] [blame] | 280 | std::vector<uint16> frequency_list_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 281 | uint16 physical_mode_; |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 282 | // The raw dBm signal strength from the associated endpoint. |
| 283 | int16 raw_signal_strength_; |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 284 | std::string hex_ssid_; |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 285 | std::string storage_identifier_; |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 286 | std::string bssid_; |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 287 | Stringmap vendor_information_; |
Paul Stewart | bdbd3c3 | 2013-04-17 09:47:21 -0700 | [diff] [blame] | 288 | // The country code reported by the current endpoint. |
| 289 | std::string country_code_; |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 290 | // If |security_| == kSecurity8021x, the crypto algorithm being used. |
| 291 | // (Otherwise, crypto algorithm is implied by |security_|.) |
| 292 | CryptoAlgorithm cipher_8021x_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 293 | |
Paul Stewart | bca08f8 | 2013-07-09 16:32:37 -0700 | [diff] [blame] | 294 | // Track the number of consecutive times our current credentials have |
| 295 | // been called into question. |
| 296 | int suspected_credential_failures_; |
| 297 | |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 298 | // Track whether or not we've warned about large signal values. |
| 299 | // Used to avoid spamming the log. |
| 300 | static bool logged_signal_warning; |
Paul Stewart | bca08f8 | 2013-07-09 16:32:37 -0700 | [diff] [blame] | 301 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 302 | WiFiRefPtr wifi_; |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 303 | std::set<WiFiEndpointConstRefPtr> endpoints_; |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 304 | WiFiEndpointConstRefPtr current_endpoint_; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 305 | const std::vector<uint8_t> ssid_; |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 306 | // Track whether IEEE 802.11w (Protected Management Frame) support is |
| 307 | // mandated by one or more endpoints we have seen that provide this service. |
| 308 | bool ieee80211w_required_; |
Peter Qiu | 4943822 | 2014-03-14 14:21:09 -0700 | [diff] [blame] | 309 | // Flag indicating if service disconnect is initiated by user for |
| 310 | // connecting to other service. |
| 311 | bool expecting_disconnect_; |
Paul Stewart | 5baebb7 | 2013-03-14 11:43:29 -0700 | [diff] [blame] | 312 | scoped_ptr<CertificateFile> certificate_file_; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 313 | // Bare pointer is safe because WiFi service instances are owned by |
| 314 | // the WiFiProvider and are guaranteed to be deallocated by the time |
| 315 | // the WiFiProvider is. |
| 316 | WiFiProvider *provider_; |
| 317 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 318 | DISALLOW_COPY_AND_ASSIGN(WiFiService); |
| 319 | }; |
| 320 | |
| 321 | } // namespace shill |
| 322 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 323 | #endif // SHILL_WIFI_SERVICE_H_ |