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