blob: 7bc8f73114747db90ed8d17ce92b10dc99077088 [file] [log] [blame]
Peter Qiuf0731732014-11-11 09:46:41 -08001// 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
16namespace apmanager {
17
Peter Qiufb39ba42014-11-21 09:09:59 -080018class Device;
19class Manager;
20
Peter Qiuf0731732014-11-11 09:46:41 -080021class Config
22 : public org::chromium::apmanager::ConfigAdaptor,
23 public org::chromium::apmanager::ConfigInterface {
24 public:
Peter Qiufb39ba42014-11-21 09:09:59 -080025 Config(Manager* manager, const std::string& service_path);
Peter Qiuf0731732014-11-11 09:46:41 -080026 virtual ~Config();
27
Peter Qiu68303292014-12-10 10:42:13 -080028 // 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 Qiubf8e36c2014-12-03 22:59:45 -080041
Peter Qiu8e785b92014-11-24 10:01:08 -080042 // 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 Qiu376e4042014-11-13 09:40:28 -080046 // Register Config DBus object.
47 void RegisterAsync(
48 chromeos::dbus_utils::ExportedObjectManager* object_manager,
Peter Qiuc9ce1f12014-12-05 11:14:29 -080049 const scoped_refptr<dbus::Bus>& bus,
Peter Qiu376e4042014-11-13 09:40:28 -080050 chromeos::dbus_utils::AsyncEventSequencer* sequencer);
51
Peter Qiuf0731732014-11-11 09:46:41 -080052 // 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 Qiufb39ba42014-11-21 09:09:59 -080058 // Claim and release the device needed for this configuration.
59 virtual bool ClaimDevice();
60 virtual bool ReleaseDevice();
61
Peter Qiuf0731732014-11-11 09:46:41 -080062 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 Qiubf8e36c2014-12-03 22:59:45 -080067 const std::string& selected_interface() const { return selected_interface_; }
68
Peter Qiuf0731732014-11-11 09:46:41 -080069 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[];
76 static const char kHostapdConfigKeyDriver[];
77 static const char kHostapdConfigKeyFragmThreshold[];
Peter Qiu8e785b92014-11-24 10:01:08 -080078 static const char kHostapdConfigKeyHTCapability[];
Peter Qiuf0731732014-11-11 09:46:41 -080079 static const char kHostapdConfigKeyHwMode[];
80 static const char kHostapdConfigKeyIeee80211ac[];
81 static const char kHostapdConfigKeyIeee80211n[];
82 static const char kHostapdConfigKeyIgnoreBroadcastSsid[];
83 static const char kHostapdConfigKeyInterface[];
84 static const char kHostapdConfigKeyRsnPairwise[];
85 static const char kHostapdConfigKeyRtsThreshold[];
86 static const char kHostapdConfigKeySsid[];
87 static const char kHostapdConfigKeyWepDefaultKey[];
88 static const char kHostapdConfigKeyWepKey0[];
89 static const char kHostapdConfigKeyWpa[];
90 static const char kHostapdConfigKeyWpaKeyMgmt[];
91 static const char kHostapdConfigKeyWpaPassphrase[];
92
93 // Hardware mode value for hostapd config file.
94 static const char kHostapdHwMode80211a[];
95 static const char kHostapdHwMode80211b[];
96 static const char kHostapdHwMode80211g[];
97
98 // Default hostapd configuration values. User will not be able to configure
99 // these.
100 static const char kHostapdDefaultDriver[];
101 static const char kHostapdDefaultRsnPairwise[];
102 static const char kHostapdDefaultWpaKeyMgmt[];
103 static const int kHostapdDefaultFragmThreshold;
104 static const int kHostapdDefaultRtsThreshold;
105
106 // Default config property values.
107 static const uint16_t kPropertyDefaultChannel;;
108 static const bool kPropertyDefaultHiddenNetwork;
109 static const uint16_t kPropertyDefaultServerAddressIndex;
110
Peter Qiu8e785b92014-11-24 10:01:08 -0800111 // Constants use for converting channel to frequency.
112 static const uint16_t kBand24GHzChannelLow;
113 static const uint16_t kBand24GHzChannelHigh;
114 static const uint32_t kBand24GHzBaseFrequency;
115 static const uint16_t kBand5GHzChannelLow;
116 static const uint16_t kBand5GHzChannelHigh;
117 static const uint16_t kBand5GHzBaseFrequency;
118
Peter Qiu68303292014-12-10 10:42:13 -0800119 static const int kSsidMinLength;
120 static const int kSsidMaxLength;
121 static const int kPassphraseMinLength;
122 static const int kPassphraseMaxLength;
123
Peter Qiuf0731732014-11-11 09:46:41 -0800124 // Append default hostapd configurations to the config file.
125 bool AppendHostapdDefaults(chromeos::ErrorPtr* error,
126 std::string* config_str);
127
128 // Append hardware mode related configurations to the config file.
129 bool AppendHwMode(chromeos::ErrorPtr* error, std::string* config_str);
130
131 // Determine/append interface configuration to the config file.
132 bool AppendInterface(chromeos::ErrorPtr* error, std::string* config_str);
133
134 // Append security related configurations to the config file.
135 bool AppendSecurityMode(chromeos::ErrorPtr* error, std::string* config_str);
136
Peter Qiufb39ba42014-11-21 09:09:59 -0800137 Manager* manager_;
Peter Qiuf0731732014-11-11 09:46:41 -0800138 dbus::ObjectPath dbus_path_;
139 std::string control_interface_;
Peter Qiubf8e36c2014-12-03 22:59:45 -0800140 // Interface selected for hostapd.
141 std::string selected_interface_;
Peter Qiu376e4042014-11-13 09:40:28 -0800142 std::unique_ptr<chromeos::dbus_utils::DBusObject> dbus_object_;
Peter Qiufb39ba42014-11-21 09:09:59 -0800143 scoped_refptr<Device> device_;
Peter Qiuf0731732014-11-11 09:46:41 -0800144
145 DISALLOW_COPY_AND_ASSIGN(Config);
146};
147
148} // namespace apmanager
149
150#endif // APMANAGER_CONFIG_H_