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