Peter Qiu | 326b6cf | 2015-09-02 11:11:42 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2014 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 16 | |
| 17 | #ifndef APMANAGER_CONFIG_H_ |
| 18 | #define APMANAGER_CONFIG_H_ |
| 19 | |
| 20 | #include <memory> |
| 21 | #include <string> |
| 22 | |
| 23 | #include <base/macros.h> |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 24 | #include <brillo/errors/error.h> |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 25 | |
Peter Qiu | 1ec4e7e | 2015-09-17 21:49:00 -0700 | [diff] [blame] | 26 | #include "dbus_bindings/org.chromium.apmanager.Config.h" |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 27 | |
| 28 | namespace apmanager { |
| 29 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 30 | class Device; |
| 31 | class Manager; |
| 32 | |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 33 | class Config |
| 34 | : public org::chromium::apmanager::ConfigAdaptor, |
| 35 | public org::chromium::apmanager::ConfigInterface { |
| 36 | public: |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 37 | Config(Manager* manager, const std::string& service_path); |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 38 | virtual ~Config(); |
| 39 | |
Peter Qiu | 6830329 | 2014-12-10 10:42:13 -0800 | [diff] [blame] | 40 | // Override ConfigAdaptor Validate functions. |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 41 | bool ValidateSsid(brillo::ErrorPtr* error, |
Peter Qiu | 6830329 | 2014-12-10 10:42:13 -0800 | [diff] [blame] | 42 | const std::string& value) override; |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 43 | bool ValidateSecurityMode(brillo::ErrorPtr* error, |
Peter Qiu | 6830329 | 2014-12-10 10:42:13 -0800 | [diff] [blame] | 44 | const std::string& value) override; |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 45 | bool ValidatePassphrase(brillo::ErrorPtr* error, |
Peter Qiu | 6830329 | 2014-12-10 10:42:13 -0800 | [diff] [blame] | 46 | const std::string& value) override; |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 47 | bool ValidateHwMode(brillo::ErrorPtr* error, |
Peter Qiu | 6830329 | 2014-12-10 10:42:13 -0800 | [diff] [blame] | 48 | const std::string& value) override; |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 49 | bool ValidateOperationMode(brillo::ErrorPtr* error, |
Peter Qiu | 6830329 | 2014-12-10 10:42:13 -0800 | [diff] [blame] | 50 | const std::string& value) override; |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 51 | bool ValidateChannel(brillo::ErrorPtr* error, |
Peter Qiu | 6830329 | 2014-12-10 10:42:13 -0800 | [diff] [blame] | 52 | const uint16_t& value) override; |
Peter Qiu | bf8e36c | 2014-12-03 22:59:45 -0800 | [diff] [blame] | 53 | |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 54 | // Calculate the frequency based on the given |channel|. Return true and set |
| 55 | // the output |frequency| if is valid channel, false otherwise. |
| 56 | static bool GetFrequencyFromChannel(uint16_t channel, uint32_t* freq); |
| 57 | |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 58 | // Register Config DBus object. |
| 59 | void RegisterAsync( |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 60 | brillo::dbus_utils::ExportedObjectManager* object_manager, |
Peter Qiu | c9ce1f1 | 2014-12-05 11:14:29 -0800 | [diff] [blame] | 61 | const scoped_refptr<dbus::Bus>& bus, |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 62 | brillo::dbus_utils::AsyncEventSequencer* sequencer); |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 63 | |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 64 | // Generate a config file string for a hostapd instance. Raise appropriate |
| 65 | // error when encounter invalid configuration. Return true if success, |
| 66 | // false otherwise. |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 67 | virtual bool GenerateConfigFile(brillo::ErrorPtr* error, |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 68 | std::string* config_str); |
| 69 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 70 | // Claim and release the device needed for this configuration. |
| 71 | virtual bool ClaimDevice(); |
| 72 | virtual bool ReleaseDevice(); |
| 73 | |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 74 | const std::string& control_interface() const { return control_interface_; } |
| 75 | void set_control_interface(const std::string& control_interface) { |
| 76 | control_interface_ = control_interface; |
| 77 | } |
| 78 | |
Peter Qiu | bf8e36c | 2014-12-03 22:59:45 -0800 | [diff] [blame] | 79 | const std::string& selected_interface() const { return selected_interface_; } |
| 80 | |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 81 | const dbus::ObjectPath& dbus_path() const { return dbus_path_; } |
| 82 | |
| 83 | private: |
| 84 | // Keys used in hostapd config file. |
| 85 | static const char kHostapdConfigKeyBridgeInterface[]; |
| 86 | static const char kHostapdConfigKeyChannel[]; |
| 87 | static const char kHostapdConfigKeyControlInterface[]; |
Peter Qiu | bfd410e | 2015-01-09 15:14:20 -0800 | [diff] [blame] | 88 | static const char kHostapdConfigKeyControlInterfaceGroup[]; |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 89 | static const char kHostapdConfigKeyDriver[]; |
| 90 | static const char kHostapdConfigKeyFragmThreshold[]; |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 91 | static const char kHostapdConfigKeyHTCapability[]; |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 92 | static const char kHostapdConfigKeyHwMode[]; |
| 93 | static const char kHostapdConfigKeyIeee80211ac[]; |
| 94 | static const char kHostapdConfigKeyIeee80211n[]; |
| 95 | static const char kHostapdConfigKeyIgnoreBroadcastSsid[]; |
| 96 | static const char kHostapdConfigKeyInterface[]; |
| 97 | static const char kHostapdConfigKeyRsnPairwise[]; |
| 98 | static const char kHostapdConfigKeyRtsThreshold[]; |
| 99 | static const char kHostapdConfigKeySsid[]; |
| 100 | static const char kHostapdConfigKeyWepDefaultKey[]; |
| 101 | static const char kHostapdConfigKeyWepKey0[]; |
| 102 | static const char kHostapdConfigKeyWpa[]; |
| 103 | static const char kHostapdConfigKeyWpaKeyMgmt[]; |
| 104 | static const char kHostapdConfigKeyWpaPassphrase[]; |
| 105 | |
| 106 | // Hardware mode value for hostapd config file. |
| 107 | static const char kHostapdHwMode80211a[]; |
| 108 | static const char kHostapdHwMode80211b[]; |
| 109 | static const char kHostapdHwMode80211g[]; |
| 110 | |
| 111 | // Default hostapd configuration values. User will not be able to configure |
| 112 | // these. |
| 113 | static const char kHostapdDefaultDriver[]; |
| 114 | static const char kHostapdDefaultRsnPairwise[]; |
| 115 | static const char kHostapdDefaultWpaKeyMgmt[]; |
| 116 | static const int kHostapdDefaultFragmThreshold; |
| 117 | static const int kHostapdDefaultRtsThreshold; |
| 118 | |
| 119 | // Default config property values. |
| 120 | static const uint16_t kPropertyDefaultChannel;; |
| 121 | static const bool kPropertyDefaultHiddenNetwork; |
| 122 | static const uint16_t kPropertyDefaultServerAddressIndex; |
| 123 | |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 124 | // Constants use for converting channel to frequency. |
| 125 | static const uint16_t kBand24GHzChannelLow; |
| 126 | static const uint16_t kBand24GHzChannelHigh; |
| 127 | static const uint32_t kBand24GHzBaseFrequency; |
| 128 | static const uint16_t kBand5GHzChannelLow; |
| 129 | static const uint16_t kBand5GHzChannelHigh; |
| 130 | static const uint16_t kBand5GHzBaseFrequency; |
| 131 | |
Peter Qiu | 6830329 | 2014-12-10 10:42:13 -0800 | [diff] [blame] | 132 | static const int kSsidMinLength; |
| 133 | static const int kSsidMaxLength; |
| 134 | static const int kPassphraseMinLength; |
| 135 | static const int kPassphraseMaxLength; |
| 136 | |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 137 | // Append default hostapd configurations to the config file. |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 138 | bool AppendHostapdDefaults(brillo::ErrorPtr* error, |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 139 | std::string* config_str); |
| 140 | |
| 141 | // Append hardware mode related configurations to the config file. |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 142 | bool AppendHwMode(brillo::ErrorPtr* error, std::string* config_str); |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 143 | |
| 144 | // Determine/append interface configuration to the config file. |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 145 | bool AppendInterface(brillo::ErrorPtr* error, std::string* config_str); |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 146 | |
| 147 | // Append security related configurations to the config file. |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 148 | bool AppendSecurityMode(brillo::ErrorPtr* error, std::string* config_str); |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 149 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 150 | Manager* manager_; |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 151 | dbus::ObjectPath dbus_path_; |
| 152 | std::string control_interface_; |
Peter Qiu | bf8e36c | 2014-12-03 22:59:45 -0800 | [diff] [blame] | 153 | // Interface selected for hostapd. |
| 154 | std::string selected_interface_; |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame^] | 155 | std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object_; |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 156 | scoped_refptr<Device> device_; |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 157 | |
| 158 | DISALLOW_COPY_AND_ASSIGN(Config); |
| 159 | }; |
| 160 | |
| 161 | } // namespace apmanager |
| 162 | |
| 163 | #endif // APMANAGER_CONFIG_H_ |