blob: 653b4d05a322cc0249f524e115ed7400b264d410 [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[];
Peter Qiubfd410e2015-01-09 15:14:20 -080076 static const char kHostapdConfigKeyControlInterfaceGroup[];
Peter Qiuf0731732014-11-11 09:46:41 -080077 static const char kHostapdConfigKeyDriver[];
78 static const char kHostapdConfigKeyFragmThreshold[];
Peter Qiu8e785b92014-11-24 10:01:08 -080079 static const char kHostapdConfigKeyHTCapability[];
Peter Qiuf0731732014-11-11 09:46:41 -080080 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 Qiu8e785b92014-11-24 10:01:08 -0800112 // 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 Qiu68303292014-12-10 10:42:13 -0800120 static const int kSsidMinLength;
121 static const int kSsidMaxLength;
122 static const int kPassphraseMinLength;
123 static const int kPassphraseMaxLength;
124
Peter Qiuf0731732014-11-11 09:46:41 -0800125 // 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 Qiufb39ba42014-11-21 09:09:59 -0800138 Manager* manager_;
Peter Qiuf0731732014-11-11 09:46:41 -0800139 dbus::ObjectPath dbus_path_;
140 std::string control_interface_;
Peter Qiubf8e36c2014-12-03 22:59:45 -0800141 // Interface selected for hostapd.
142 std::string selected_interface_;
Peter Qiu376e4042014-11-13 09:40:28 -0800143 std::unique_ptr<chromeos::dbus_utils::DBusObject> dbus_object_;
Peter Qiufb39ba42014-11-21 09:09:59 -0800144 scoped_refptr<Device> device_;
Peter Qiuf0731732014-11-11 09:46:41 -0800145
146 DISALLOW_COPY_AND_ASSIGN(Config);
147};
148
149} // namespace apmanager
150
151#endif // APMANAGER_CONFIG_H_