apmanager: validate Config properties

Override the Validate functions in ConfigAdaptor for validating the property
values send by the remote application. Some properties doesn't require
any validation (such as HiddenNetwork). For these properties, the default
implementation in ConfigAdaptor will be used.

While there, add support for bridge mode operation and fix a bug when user
specified interface is invalid.

BUG=chromium:440874
TEST=USE="asan clang" FEATURES=test emerge-$BOARD apmanager
Manual Test:
Configure an AP service by setting properties in org.chromium.apmanager.Config
interface. Verify AP service is started with the right configuration.

Change-Id: I6dc5b688d9b4ba51c20485351b3cd8a78624bb1e
Reviewed-on: https://chromium-review.googlesource.com/234397
Trybot-Ready: Peter Qiu <zqiu@chromium.org>
Tested-by: Peter Qiu <zqiu@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Peter Qiu <zqiu@chromium.org>
diff --git a/config.h b/config.h
index 0038e83..7bc8f73 100644
--- a/config.h
+++ b/config.h
@@ -25,10 +25,19 @@
   Config(Manager* manager, const std::string& service_path);
   virtual ~Config();
 
-  // Implementation of ConfigInterface.
-  // Handles calls to org.chromium.apmanager.Config.SsidSet().
-  virtual bool SsidSet(chromeos::ErrorPtr* error,
-                       const std::string& ssid);
+  // Override ConfigAdaptor Validate functions.
+  bool ValidateSsid(chromeos::ErrorPtr* error,
+                    const std::string& value) override;
+  bool ValidateSecurityMode(chromeos::ErrorPtr* error,
+                            const std::string& value) override;
+  bool ValidatePassphrase(chromeos::ErrorPtr* error,
+                          const std::string& value) override;
+  bool ValidateHwMode(chromeos::ErrorPtr* error,
+                      const std::string& value) override;
+  bool ValidateOperationMode(chromeos::ErrorPtr* error,
+                             const std::string& value) override;
+  bool ValidateChannel(chromeos::ErrorPtr* error,
+                       const uint16_t& value) override;
 
   // Calculate the frequency based on the given |channel|. Return true and set
   // the output |frequency| if is valid channel, false otherwise.
@@ -107,6 +116,11 @@
   static const uint16_t kBand5GHzChannelHigh;
   static const uint16_t kBand5GHzBaseFrequency;
 
+  static const int kSsidMinLength;
+  static const int kSsidMaxLength;
+  static const int kPassphraseMinLength;
+  static const int kPassphraseMaxLength;
+
   // Append default hostapd configurations to the config file.
   bool AppendHostapdDefaults(chromeos::ErrorPtr* error,
                              std::string* config_str);