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 | |
| 18 | class Config |
| 19 | : public org::chromium::apmanager::ConfigAdaptor, |
| 20 | public org::chromium::apmanager::ConfigInterface { |
| 21 | public: |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame^] | 22 | explicit Config(const std::string& service_path); |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 23 | virtual ~Config(); |
| 24 | |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame^] | 25 | // Register Config DBus object. |
| 26 | void RegisterAsync( |
| 27 | chromeos::dbus_utils::ExportedObjectManager* object_manager, |
| 28 | chromeos::dbus_utils::AsyncEventSequencer* sequencer); |
| 29 | |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 30 | // Generate a config file string for a hostapd instance. Raise appropriate |
| 31 | // error when encounter invalid configuration. Return true if success, |
| 32 | // false otherwise. |
| 33 | virtual bool GenerateConfigFile(chromeos::ErrorPtr* error, |
| 34 | std::string* config_str); |
| 35 | |
| 36 | const std::string& control_interface() const { return control_interface_; } |
| 37 | void set_control_interface(const std::string& control_interface) { |
| 38 | control_interface_ = control_interface; |
| 39 | } |
| 40 | |
| 41 | const dbus::ObjectPath& dbus_path() const { return dbus_path_; } |
| 42 | |
| 43 | private: |
| 44 | // Keys used in hostapd config file. |
| 45 | static const char kHostapdConfigKeyBridgeInterface[]; |
| 46 | static const char kHostapdConfigKeyChannel[]; |
| 47 | static const char kHostapdConfigKeyControlInterface[]; |
| 48 | static const char kHostapdConfigKeyDriver[]; |
| 49 | static const char kHostapdConfigKeyFragmThreshold[]; |
| 50 | static const char kHostapdConfigKeyHwMode[]; |
| 51 | static const char kHostapdConfigKeyIeee80211ac[]; |
| 52 | static const char kHostapdConfigKeyIeee80211n[]; |
| 53 | static const char kHostapdConfigKeyIgnoreBroadcastSsid[]; |
| 54 | static const char kHostapdConfigKeyInterface[]; |
| 55 | static const char kHostapdConfigKeyRsnPairwise[]; |
| 56 | static const char kHostapdConfigKeyRtsThreshold[]; |
| 57 | static const char kHostapdConfigKeySsid[]; |
| 58 | static const char kHostapdConfigKeyWepDefaultKey[]; |
| 59 | static const char kHostapdConfigKeyWepKey0[]; |
| 60 | static const char kHostapdConfigKeyWpa[]; |
| 61 | static const char kHostapdConfigKeyWpaKeyMgmt[]; |
| 62 | static const char kHostapdConfigKeyWpaPassphrase[]; |
| 63 | |
| 64 | // Hardware mode value for hostapd config file. |
| 65 | static const char kHostapdHwMode80211a[]; |
| 66 | static const char kHostapdHwMode80211b[]; |
| 67 | static const char kHostapdHwMode80211g[]; |
| 68 | |
| 69 | // Default hostapd configuration values. User will not be able to configure |
| 70 | // these. |
| 71 | static const char kHostapdDefaultDriver[]; |
| 72 | static const char kHostapdDefaultRsnPairwise[]; |
| 73 | static const char kHostapdDefaultWpaKeyMgmt[]; |
| 74 | static const int kHostapdDefaultFragmThreshold; |
| 75 | static const int kHostapdDefaultRtsThreshold; |
| 76 | |
| 77 | // Default config property values. |
| 78 | static const uint16_t kPropertyDefaultChannel;; |
| 79 | static const bool kPropertyDefaultHiddenNetwork; |
| 80 | static const uint16_t kPropertyDefaultServerAddressIndex; |
| 81 | |
| 82 | // Append default hostapd configurations to the config file. |
| 83 | bool AppendHostapdDefaults(chromeos::ErrorPtr* error, |
| 84 | std::string* config_str); |
| 85 | |
| 86 | // Append hardware mode related configurations to the config file. |
| 87 | bool AppendHwMode(chromeos::ErrorPtr* error, std::string* config_str); |
| 88 | |
| 89 | // Determine/append interface configuration to the config file. |
| 90 | bool AppendInterface(chromeos::ErrorPtr* error, std::string* config_str); |
| 91 | |
| 92 | // Append security related configurations to the config file. |
| 93 | bool AppendSecurityMode(chromeos::ErrorPtr* error, std::string* config_str); |
| 94 | |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 95 | dbus::ObjectPath dbus_path_; |
| 96 | std::string control_interface_; |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame^] | 97 | std::unique_ptr<chromeos::dbus_utils::DBusObject> dbus_object_; |
Peter Qiu | f073173 | 2014-11-11 09:46:41 -0800 | [diff] [blame] | 98 | |
| 99 | DISALLOW_COPY_AND_ASSIGN(Config); |
| 100 | }; |
| 101 | |
| 102 | } // namespace apmanager |
| 103 | |
| 104 | #endif // APMANAGER_CONFIG_H_ |