Move simple firmware related queries into HardwareInterface.

This change moves the following functions from utils to
HardwareInterface:
    GetHardwareClass()
    GetFirmwareVersion()
    GetECVersion()

BUG=None
TEST=unit tests

Change-Id: I20047a3fac8cca3c36730fef305751e6da3c2bb5
Reviewed-on: https://chromium-review.googlesource.com/174930
Commit-Queue: Richard Barnette <jrbarnette@chromium.org>
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
diff --git a/hardware.cc b/hardware.cc
index 1c0b3a6..a44edcf 100644
--- a/hardware.cc
+++ b/hardware.cc
@@ -3,12 +3,16 @@
 // found in the LICENSE file.
 
 #include "update_engine/hardware.h"
-#include "update_engine/utils.h"
 
 #include <base/logging.h>
+#include <base/string_util.h>
 #include <rootdev/rootdev.h>
 
+#include "update_engine/subprocess.h"
+#include "update_engine/utils.h"
+
 using std::string;
+using std::vector;
 
 namespace chromeos_update_engine {
 
@@ -29,4 +33,45 @@
   return boot_path;
 }
 
+static string ReadValueFromCrosSystem(const string& key) {
+  int exit_code = 0;
+  vector<string> cmd(1, "/usr/bin/crossystem");
+  cmd.push_back(key);
+
+  string return_value;
+  bool success = Subprocess::SynchronousExec(cmd, &exit_code, &return_value);
+  if (success && !exit_code) {
+    TrimWhitespaceASCII(return_value, TRIM_ALL, &return_value);
+    return return_value;
+  }
+  LOG(ERROR) << "Unable to read " << key << " (" << exit_code << ") "
+             << return_value;
+  return "";
+}
+
+string Hardware::GetHardwareClass() {
+  return ReadValueFromCrosSystem("hwid");
+}
+
+string Hardware::GetFirmwareVersion() {
+  return ReadValueFromCrosSystem("fwid");
+}
+
+string Hardware::GetECVersion() {
+  string input_line;
+  int exit_code = 0;
+  vector<string> cmd(1, "/usr/sbin/mosys");
+  cmd.push_back("-k");
+  cmd.push_back("ec");
+  cmd.push_back("info");
+
+  bool success = Subprocess::SynchronousExec(cmd, &exit_code, &input_line);
+  if (!success || exit_code) {
+    LOG(ERROR) << "Unable to read ec info from mosys (" << exit_code << ")";
+    return "";
+  }
+
+  return utils::ParseECVersion(input_line);
+}
+
 }  // namespace chromeos_update_engine