blob: 228f12df21ca71440c11a218e0cfb3fa0b533a92 [file] [log] [blame]
Peter Qiu326b6cf2015-09-02 11:11:42 -07001//
2// Copyright (C) 2014 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
Peter Qiuf0731732014-11-11 09:46:41 -080016
17#ifndef APMANAGER_CONFIG_H_
18#define APMANAGER_CONFIG_H_
19
20#include <memory>
21#include <string>
22
23#include <base/macros.h>
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070024#include <brillo/errors/error.h>
Peter Qiuf0731732014-11-11 09:46:41 -080025
Peter Qiu1ec4e7e2015-09-17 21:49:00 -070026#include "dbus_bindings/org.chromium.apmanager.Config.h"
Peter Qiuf0731732014-11-11 09:46:41 -080027
28namespace apmanager {
29
Peter Qiufb39ba42014-11-21 09:09:59 -080030class Device;
31class Manager;
32
Peter Qiuf0731732014-11-11 09:46:41 -080033class Config
34 : public org::chromium::apmanager::ConfigAdaptor,
35 public org::chromium::apmanager::ConfigInterface {
36 public:
Peter Qiufb39ba42014-11-21 09:09:59 -080037 Config(Manager* manager, const std::string& service_path);
Peter Qiuf0731732014-11-11 09:46:41 -080038 virtual ~Config();
39
Peter Qiu68303292014-12-10 10:42:13 -080040 // Override ConfigAdaptor Validate functions.
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070041 bool ValidateSsid(brillo::ErrorPtr* error,
Peter Qiu68303292014-12-10 10:42:13 -080042 const std::string& value) override;
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070043 bool ValidateSecurityMode(brillo::ErrorPtr* error,
Peter Qiu68303292014-12-10 10:42:13 -080044 const std::string& value) override;
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070045 bool ValidatePassphrase(brillo::ErrorPtr* error,
Peter Qiu68303292014-12-10 10:42:13 -080046 const std::string& value) override;
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070047 bool ValidateHwMode(brillo::ErrorPtr* error,
Peter Qiu68303292014-12-10 10:42:13 -080048 const std::string& value) override;
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070049 bool ValidateOperationMode(brillo::ErrorPtr* error,
Peter Qiu68303292014-12-10 10:42:13 -080050 const std::string& value) override;
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070051 bool ValidateChannel(brillo::ErrorPtr* error,
Peter Qiu68303292014-12-10 10:42:13 -080052 const uint16_t& value) override;
Peter Qiubf8e36c2014-12-03 22:59:45 -080053
Peter Qiu8e785b92014-11-24 10:01:08 -080054 // Calculate the frequency based on the given |channel|. Return true and set
55 // the output |frequency| if is valid channel, false otherwise.
56 static bool GetFrequencyFromChannel(uint16_t channel, uint32_t* freq);
57
Peter Qiu376e4042014-11-13 09:40:28 -080058 // Register Config DBus object.
59 void RegisterAsync(
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070060 brillo::dbus_utils::ExportedObjectManager* object_manager,
Peter Qiuc9ce1f12014-12-05 11:14:29 -080061 const scoped_refptr<dbus::Bus>& bus,
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070062 brillo::dbus_utils::AsyncEventSequencer* sequencer);
Peter Qiu376e4042014-11-13 09:40:28 -080063
Peter Qiuf0731732014-11-11 09:46:41 -080064 // Generate a config file string for a hostapd instance. Raise appropriate
65 // error when encounter invalid configuration. Return true if success,
66 // false otherwise.
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070067 virtual bool GenerateConfigFile(brillo::ErrorPtr* error,
Peter Qiuf0731732014-11-11 09:46:41 -080068 std::string* config_str);
69
Peter Qiufb39ba42014-11-21 09:09:59 -080070 // Claim and release the device needed for this configuration.
71 virtual bool ClaimDevice();
72 virtual bool ReleaseDevice();
73
Peter Qiuf0731732014-11-11 09:46:41 -080074 const std::string& control_interface() const { return control_interface_; }
75 void set_control_interface(const std::string& control_interface) {
76 control_interface_ = control_interface;
77 }
78
Peter Qiubf8e36c2014-12-03 22:59:45 -080079 const std::string& selected_interface() const { return selected_interface_; }
80
Peter Qiuf0731732014-11-11 09:46:41 -080081 const dbus::ObjectPath& dbus_path() const { return dbus_path_; }
82
83 private:
84 // Keys used in hostapd config file.
85 static const char kHostapdConfigKeyBridgeInterface[];
86 static const char kHostapdConfigKeyChannel[];
87 static const char kHostapdConfigKeyControlInterface[];
Peter Qiubfd410e2015-01-09 15:14:20 -080088 static const char kHostapdConfigKeyControlInterfaceGroup[];
Peter Qiuf0731732014-11-11 09:46:41 -080089 static const char kHostapdConfigKeyDriver[];
90 static const char kHostapdConfigKeyFragmThreshold[];
Peter Qiu8e785b92014-11-24 10:01:08 -080091 static const char kHostapdConfigKeyHTCapability[];
Peter Qiuf0731732014-11-11 09:46:41 -080092 static const char kHostapdConfigKeyHwMode[];
93 static const char kHostapdConfigKeyIeee80211ac[];
94 static const char kHostapdConfigKeyIeee80211n[];
95 static const char kHostapdConfigKeyIgnoreBroadcastSsid[];
96 static const char kHostapdConfigKeyInterface[];
97 static const char kHostapdConfigKeyRsnPairwise[];
98 static const char kHostapdConfigKeyRtsThreshold[];
99 static const char kHostapdConfigKeySsid[];
100 static const char kHostapdConfigKeyWepDefaultKey[];
101 static const char kHostapdConfigKeyWepKey0[];
102 static const char kHostapdConfigKeyWpa[];
103 static const char kHostapdConfigKeyWpaKeyMgmt[];
104 static const char kHostapdConfigKeyWpaPassphrase[];
105
106 // Hardware mode value for hostapd config file.
107 static const char kHostapdHwMode80211a[];
108 static const char kHostapdHwMode80211b[];
109 static const char kHostapdHwMode80211g[];
110
111 // Default hostapd configuration values. User will not be able to configure
112 // these.
113 static const char kHostapdDefaultDriver[];
114 static const char kHostapdDefaultRsnPairwise[];
115 static const char kHostapdDefaultWpaKeyMgmt[];
116 static const int kHostapdDefaultFragmThreshold;
117 static const int kHostapdDefaultRtsThreshold;
118
119 // Default config property values.
120 static const uint16_t kPropertyDefaultChannel;;
121 static const bool kPropertyDefaultHiddenNetwork;
122 static const uint16_t kPropertyDefaultServerAddressIndex;
123
Peter Qiu8e785b92014-11-24 10:01:08 -0800124 // Constants use for converting channel to frequency.
125 static const uint16_t kBand24GHzChannelLow;
126 static const uint16_t kBand24GHzChannelHigh;
127 static const uint32_t kBand24GHzBaseFrequency;
128 static const uint16_t kBand5GHzChannelLow;
129 static const uint16_t kBand5GHzChannelHigh;
130 static const uint16_t kBand5GHzBaseFrequency;
131
Peter Qiu68303292014-12-10 10:42:13 -0800132 static const int kSsidMinLength;
133 static const int kSsidMaxLength;
134 static const int kPassphraseMinLength;
135 static const int kPassphraseMaxLength;
136
Peter Qiuf0731732014-11-11 09:46:41 -0800137 // Append default hostapd configurations to the config file.
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700138 bool AppendHostapdDefaults(brillo::ErrorPtr* error,
Peter Qiuf0731732014-11-11 09:46:41 -0800139 std::string* config_str);
140
141 // Append hardware mode related configurations to the config file.
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700142 bool AppendHwMode(brillo::ErrorPtr* error, std::string* config_str);
Peter Qiuf0731732014-11-11 09:46:41 -0800143
144 // Determine/append interface configuration to the config file.
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700145 bool AppendInterface(brillo::ErrorPtr* error, std::string* config_str);
Peter Qiuf0731732014-11-11 09:46:41 -0800146
147 // Append security related configurations to the config file.
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700148 bool AppendSecurityMode(brillo::ErrorPtr* error, std::string* config_str);
Peter Qiuf0731732014-11-11 09:46:41 -0800149
Peter Qiufb39ba42014-11-21 09:09:59 -0800150 Manager* manager_;
Peter Qiuf0731732014-11-11 09:46:41 -0800151 dbus::ObjectPath dbus_path_;
152 std::string control_interface_;
Peter Qiubf8e36c2014-12-03 22:59:45 -0800153 // Interface selected for hostapd.
154 std::string selected_interface_;
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -0700155 std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object_;
Peter Qiufb39ba42014-11-21 09:09:59 -0800156 scoped_refptr<Device> device_;
Peter Qiuf0731732014-11-11 09:46:41 -0800157
158 DISALLOW_COPY_AND_ASSIGN(Config);
159};
160
161} // namespace apmanager
162
163#endif // APMANAGER_CONFIG_H_