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 | |
| 5 | #ifndef SHILL_WIFI_SERVICE_ |
| 6 | #define SHILL_WIFI_SERVICE_ |
| 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 | |
Darin Petkov | 4a09b6b | 2011-07-19 12:52:06 -0700 | [diff] [blame] | 12 | #include "shill/dbus_bindings/supplicant-interface.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 13 | #include "shill/event_dispatcher.h" |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 14 | #include "shill/refptr_types.h" |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 15 | #include "shill/service.h" |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 16 | |
| 17 | namespace shill { |
| 18 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 19 | class ControlInterface; |
| 20 | class EventDispatcher; |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 21 | class Error; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 22 | class Manager; |
| 23 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 24 | class WiFiService : public Service { |
| 25 | public: |
| 26 | WiFiService(ControlInterface *control_interface, |
| 27 | EventDispatcher *dispatcher, |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 28 | Manager *manager, |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 29 | const WiFiRefPtr &device, |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 30 | const std::vector<uint8_t> &ssid, |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 31 | const std::string &mode, |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 32 | const std::string &security, |
| 33 | bool hidden_ssid); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 34 | ~WiFiService(); |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 35 | |
| 36 | // Inherited from Service. |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 37 | virtual void AutoConnect(); |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 38 | virtual void Connect(Error *error); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 39 | virtual void Disconnect(Error *error); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 40 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 41 | virtual bool TechnologyIs(const Technology::Identifier type) const; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 42 | virtual bool IsConnecting() const; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 43 | |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 44 | virtual void AddEndpoint(WiFiEndpointConstRefPtr endpoint); |
| 45 | virtual void RemoveEndpoint(WiFiEndpointConstRefPtr endpoint); |
mukesh agrawal | 4eb4d78 | 2011-12-05 17:34:37 +0000 | [diff] [blame] | 46 | bool NumEndpoints() const { return endpoints_.size(); } |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 47 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 48 | // wifi_<MAC>_<BSSID>_<mode_string>_<security_string> |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 49 | std::string GetStorageIdentifier() const; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 50 | static bool ParseStorageIdentifier(const std::string &storage_name, |
| 51 | std::string *address, |
| 52 | std::string *mode, |
| 53 | std::string *security); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 54 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 55 | const std::string &mode() const { return mode_; } |
| 56 | const std::string &key_management() const { return GetEAPKeyManagement(); } |
| 57 | const std::vector<uint8_t> &ssid() const { return ssid_; } |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 58 | |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 59 | void SetPassphrase(const std::string &passphrase, Error *error); |
| 60 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 61 | // Overrride Load and Save from parent Service class. We will call |
| 62 | // the parent method. |
| 63 | virtual bool IsLoadableFrom(StoreInterface *storage) const; |
| 64 | virtual bool Load(StoreInterface *storage); |
| 65 | virtual bool Save(StoreInterface *storage); |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 66 | virtual void Unload(); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 67 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 68 | virtual bool HasEndpoints() const { return !endpoints_.empty(); } |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 69 | virtual bool IsVisible() const; |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 70 | bool IsSecurityMatch(const std::string &security) const; |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 71 | bool hidden_ssid() const { return hidden_ssid_; } |
| 72 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 73 | virtual void InitializeCustomMetrics() const; |
| 74 | virtual void SendPostReadyStateMetrics() const; |
| 75 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 76 | protected: |
| 77 | virtual bool IsAutoConnectable() const; |
| 78 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 79 | private: |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 80 | friend class WiFiServiceSecurityTest; |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 81 | FRIEND_TEST(MetricsTest, WiFiServicePostReady); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 82 | FRIEND_TEST(WiFiServiceTest, AutoConnect); |
mukesh agrawal | f2fd745 | 2011-10-03 16:38:47 -0700 | [diff] [blame] | 83 | FRIEND_TEST(WiFiServiceTest, ConnectTaskRSN); |
| 84 | FRIEND_TEST(WiFiServiceTest, ConnectTaskWPA); |
Gaurav Shah | f8721ee | 2011-11-07 09:12:46 -0800 | [diff] [blame] | 85 | FRIEND_TEST(WiFiServiceTest, ConnectTaskPSK); |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 86 | FRIEND_TEST(WiFiServiceTest, ConnectTaskWEP); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 87 | FRIEND_TEST(WiFiServiceTest, IsAutoConnectable); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 88 | FRIEND_TEST(WiFiServiceTest, LoadHidden); |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 89 | FRIEND_TEST(WiFiServiceTest, LoadAndUnloadPassphrase); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 90 | |
| 91 | static const char kStorageHiddenSSID[]; |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 92 | static const char kStorageMode[]; |
| 93 | static const char kStoragePassphrase[]; |
| 94 | static const char kStorageSecurity[]; |
| 95 | static const char kStorageSSID[]; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 96 | |
Thieu Le | f770945 | 2011-11-15 01:13:19 +0000 | [diff] [blame] | 97 | void HelpRegisterDerivedString( |
| 98 | PropertyStore *store, |
| 99 | const std::string &name, |
Hristo Stefanov | ed2c28c | 2011-11-29 15:37:30 -0800 | [diff] [blame] | 100 | std::string(WiFiService::*get)(Error *error), |
| 101 | void(WiFiService::*set)(const std::string &value, Error *error)); |
Thieu Le | f770945 | 2011-11-15 01:13:19 +0000 | [diff] [blame] | 102 | |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 103 | void ConnectTask(); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 104 | void DisconnectTask(); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 105 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 106 | std::string GetDeviceRpcId(Error *error); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 107 | void UpdateConnectable(); |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 108 | |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 109 | static void ValidateWEPPassphrase(const std::string &passphrase, |
| 110 | Error *error); |
| 111 | static void ValidateWPAPassphrase(const std::string &passphrase, |
| 112 | Error *error); |
| 113 | static void ParseWEPPassphrase(const std::string &passphrase, |
| 114 | int *key_index, |
| 115 | std::vector<uint8> *password_bytes, |
| 116 | Error *error); |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 117 | static bool CheckWEPIsHex(const std::string &passphrase, Error *error); |
| 118 | static bool CheckWEPKeyIndex(const std::string &passphrase, Error *error); |
| 119 | static bool CheckWEPPrefix(const std::string &passphrase, Error *error); |
| 120 | |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 121 | // replace non-ASCII characters with '?'. return true if one or more |
| 122 | // characters were changed |
| 123 | static bool SanitizeSSID(std::string *ssid); |
| 124 | |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 125 | // "wpa", "rsn" and "psk" are equivalent from a configuration perspective. |
| 126 | // This function maps them all into "psk". |
| 127 | static std::string GetSecurityClass(const std::string &security); |
| 128 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 129 | // Profile data for a WPA/RSN service can be stored under a number of |
| 130 | // different names. These functions create different storage identifiers |
| 131 | // based on whether they are referred to by their generic "psk" name or |
| 132 | // if they use the (legacy) specific "wpa" or "rsn" names. |
| 133 | std::string GetGenericStorageIdentifier() const; |
| 134 | std::string GetSpecificStorageIdentifier() const; |
| 135 | std::string GetStorageIdentifierForSecurity( |
| 136 | const std::string &security) const; |
| 137 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 138 | // Properties |
| 139 | std::string passphrase_; |
| 140 | bool need_passphrase_; |
| 141 | std::string security_; |
| 142 | uint8 strength_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 143 | // TODO(cmasone): see if the below can be pulled from the endpoint associated |
| 144 | // with this service instead. |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 145 | const std::string mode_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 146 | std::string auth_mode_; |
| 147 | bool hidden_ssid_; |
| 148 | uint16 frequency_; |
| 149 | uint16 physical_mode_; |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 150 | std::string hex_ssid_; |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 151 | std::string storage_identifier_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 152 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 153 | ScopedRunnableMethodFactory<WiFiService> task_factory_; |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 154 | WiFiRefPtr wifi_; |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 155 | std::set<WiFiEndpointConstRefPtr> endpoints_; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 156 | const std::vector<uint8_t> ssid_; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 157 | DISALLOW_COPY_AND_ASSIGN(WiFiService); |
| 158 | }; |
| 159 | |
| 160 | } // namespace shill |
| 161 | |
| 162 | #endif // SHILL_WIFI_SERVICE_ |