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