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 | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 28 | // Calculate the frequency based on the given |channel|. Return true and set |
| 29 | // the output |frequency| if is valid channel, false otherwise. |
| 30 | static bool GetFrequencyFromChannel(uint16_t channel, uint32_t* freq); |
| 31 | |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 32 | // Register Config DBus object. |
| 33 | void RegisterAsync( |
| 34 | chromeos::dbus_utils::ExportedObjectManager* object_manager, |
| 35 | chromeos::dbus_utils::AsyncEventSequencer* sequencer); |
| 36 | |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 37 | // Generate a config file string for a hostapd instance. Raise appropriate |
| 38 | // error when encounter invalid configuration. Return true if success, |
| 39 | // false otherwise. |
| 40 | virtual bool GenerateConfigFile(chromeos::ErrorPtr* error, |
| 41 | std::string* config_str); |
| 42 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 43 | // Claim and release the device needed for this configuration. |
| 44 | virtual bool ClaimDevice(); |
| 45 | virtual bool ReleaseDevice(); |
| 46 | |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 47 | const std::string& control_interface() const { return control_interface_; } |
| 48 | void set_control_interface(const std::string& control_interface) { |
| 49 | control_interface_ = control_interface; |
| 50 | } |
| 51 | |
| 52 | const dbus::ObjectPath& dbus_path() const { return dbus_path_; } |
| 53 | |
| 54 | private: |
| 55 | // Keys used in hostapd config file. |
| 56 | static const char kHostapdConfigKeyBridgeInterface[]; |
| 57 | static const char kHostapdConfigKeyChannel[]; |
| 58 | static const char kHostapdConfigKeyControlInterface[]; |
| 59 | static const char kHostapdConfigKeyDriver[]; |
| 60 | static const char kHostapdConfigKeyFragmThreshold[]; |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 61 | static const char kHostapdConfigKeyHTCapability[]; |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 62 | static const char kHostapdConfigKeyHwMode[]; |
| 63 | static const char kHostapdConfigKeyIeee80211ac[]; |
| 64 | static const char kHostapdConfigKeyIeee80211n[]; |
| 65 | static const char kHostapdConfigKeyIgnoreBroadcastSsid[]; |
| 66 | static const char kHostapdConfigKeyInterface[]; |
| 67 | static const char kHostapdConfigKeyRsnPairwise[]; |
| 68 | static const char kHostapdConfigKeyRtsThreshold[]; |
| 69 | static const char kHostapdConfigKeySsid[]; |
| 70 | static const char kHostapdConfigKeyWepDefaultKey[]; |
| 71 | static const char kHostapdConfigKeyWepKey0[]; |
| 72 | static const char kHostapdConfigKeyWpa[]; |
| 73 | static const char kHostapdConfigKeyWpaKeyMgmt[]; |
| 74 | static const char kHostapdConfigKeyWpaPassphrase[]; |
| 75 | |
| 76 | // Hardware mode value for hostapd config file. |
| 77 | static const char kHostapdHwMode80211a[]; |
| 78 | static const char kHostapdHwMode80211b[]; |
| 79 | static const char kHostapdHwMode80211g[]; |
| 80 | |
| 81 | // Default hostapd configuration values. User will not be able to configure |
| 82 | // these. |
| 83 | static const char kHostapdDefaultDriver[]; |
| 84 | static const char kHostapdDefaultRsnPairwise[]; |
| 85 | static const char kHostapdDefaultWpaKeyMgmt[]; |
| 86 | static const int kHostapdDefaultFragmThreshold; |
| 87 | static const int kHostapdDefaultRtsThreshold; |
| 88 | |
| 89 | // Default config property values. |
| 90 | static const uint16_t kPropertyDefaultChannel;; |
| 91 | static const bool kPropertyDefaultHiddenNetwork; |
| 92 | static const uint16_t kPropertyDefaultServerAddressIndex; |
| 93 | |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 94 | // Constants use for converting channel to frequency. |
| 95 | static const uint16_t kBand24GHzChannelLow; |
| 96 | static const uint16_t kBand24GHzChannelHigh; |
| 97 | static const uint32_t kBand24GHzBaseFrequency; |
| 98 | static const uint16_t kBand5GHzChannelLow; |
| 99 | static const uint16_t kBand5GHzChannelHigh; |
| 100 | static const uint16_t kBand5GHzBaseFrequency; |
| 101 | |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 102 | // Append default hostapd configurations to the config file. |
| 103 | bool AppendHostapdDefaults(chromeos::ErrorPtr* error, |
| 104 | std::string* config_str); |
| 105 | |
| 106 | // Append hardware mode related configurations to the config file. |
| 107 | bool AppendHwMode(chromeos::ErrorPtr* error, std::string* config_str); |
| 108 | |
| 109 | // Determine/append interface configuration to the config file. |
| 110 | bool AppendInterface(chromeos::ErrorPtr* error, std::string* config_str); |
| 111 | |
| 112 | // Append security related configurations to the config file. |
| 113 | bool AppendSecurityMode(chromeos::ErrorPtr* error, std::string* config_str); |
| 114 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 115 | Manager* manager_; |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 116 | dbus::ObjectPath dbus_path_; |
| 117 | std::string control_interface_; |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 118 | std::unique_ptr<chromeos::dbus_utils::DBusObject> dbus_object_; |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 119 | scoped_refptr<Device> device_; |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 120 | |
| 121 | DISALLOW_COPY_AND_ASSIGN(Config); |
| 122 | }; |
| 123 | |
| 124 | } // namespace apmanager |
| 125 | |
| 126 | #endif // APMANAGER_CONFIG_H_ |