Add system status LED support

When there is any CPU IERR or SSB thermal error,
the system amber LED will be solid on.

Tested:
Heat the PCH to trigger the SSB thermal error, or trigger the IERR by ITP,
check the status LED state.

Change-Id: I019e87a7e4f763eb6cc0297197faae264388c90b
Signed-off-by: Yong Li <yong.b.li@linux.intel.com>
diff --git a/src/host_error_monitor.cpp b/src/host_error_monitor.cpp
index 88ed84a..9047677 100644
--- a/src/host_error_monitor.cpp
+++ b/src/host_error_monitor.cpp
@@ -30,6 +30,12 @@
 static std::shared_ptr<sdbusplus::asio::connection> conn;
 static std::shared_ptr<sdbusplus::asio::dbus_interface> hostErrorTimeoutIface;
 
+using Association = std::tuple<std::string, std::string, std::string>;
+static std::shared_ptr<sdbusplus::asio::dbus_interface> associationSSBThermTrip;
+static std::shared_ptr<sdbusplus::asio::dbus_interface> associationCATAssert;
+
+static const constexpr char* rootPath = "/xyz/openbmc_project/CallbackManager";
+
 static bool hostOff = true;
 
 static size_t caterrTimeoutMs = 2000;
@@ -737,14 +743,24 @@
 
         bool caterr =
             gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
+
+        std::vector<Association> associations;
         if (caterr)
         {
             caterrAssertHandler();
+            associations.emplace_back(
+                "", "critical",
+                "/xyz/openbmc_project/host_error_monitor/cat_error");
+            associations.emplace_back("", "critical",
+                                      host_error_monitor::rootPath);
         }
         else
         {
             caterrAssertTimer.cancel();
+            associations.emplace_back("", "", "");
         }
+        host_error_monitor::associationCATAssert->set_property("Associations",
+                                                               associations);
     }
     caterrEvent.async_wait(boost::asio::posix::stream_descriptor::wait_read,
                            [](const boost::system::error_code ec) {
@@ -1056,6 +1072,8 @@
 
 static void pchThermtripHandler()
 {
+    std::vector<Association> associations;
+
     gpiod::line_event gpioLineEvent = pchThermtripLine.event_read();
 
     bool pchThermtrip =
@@ -1063,7 +1081,17 @@
     if (pchThermtrip)
     {
         ssbThermTripLog();
+        associations.emplace_back(
+            "", "critical",
+            "/xyz/openbmc_project/host_error_monitor/ssb_thermal_trip");
+        associations.emplace_back("", "critical", host_error_monitor::rootPath);
     }
+    else
+    {
+        associations.emplace_back("", "", "");
+    }
+    host_error_monitor::associationSSBThermTrip->set_property("Associations",
+                                                              associations);
 
     pchThermtripEvent.async_wait(
         boost::asio::posix::stream_descriptor::wait_read,
@@ -1408,6 +1436,12 @@
     if (caterrLine.get_value() == 0)
     {
         caterrAssertHandler();
+        std::vector<Association> associations;
+        associations.emplace_back(
+            "", "critical", "/xyz/openbmc_project/host_error_monitor/cat_err");
+        associations.emplace_back("", "critical", host_error_monitor::rootPath);
+        host_error_monitor::associationCATAssert->set_property("Associations",
+                                                               associations);
     }
 
     // Handle CPU_ERR0 if it's asserted now
@@ -1498,6 +1532,13 @@
     if (pchThermtripLine.get_value() == 0)
     {
         ssbThermTripLog();
+        std::vector<Association> associations;
+        associations.emplace_back(
+            "", "critical",
+            "/xyz/openbmc_project/host_error_monitor/ssb_thermal_trip");
+        associations.emplace_back("", "critical", host_error_monitor::rootPath);
+        host_error_monitor::associationSSBThermTrip->set_property(
+            "Associations", associations);
     }
 }
 } // namespace host_error_monitor
@@ -1514,6 +1555,23 @@
     sdbusplus::asio::object_server server =
         sdbusplus::asio::object_server(host_error_monitor::conn);
 
+    // Associations interface for led status
+    std::vector<host_error_monitor::Association> associations;
+    associations.emplace_back("", "", "");
+    host_error_monitor::associationSSBThermTrip = server.add_interface(
+        "/xyz/openbmc_project/host_error_monitor/ssb_thermal_trip",
+        "xyz.openbmc_project.Association.Definitions");
+    host_error_monitor::associationSSBThermTrip->register_property(
+        "Associations", associations);
+    host_error_monitor::associationSSBThermTrip->initialize();
+
+    host_error_monitor::associationCATAssert = server.add_interface(
+        "/xyz/openbmc_project/host_error_monitor/cat_assert",
+        "xyz.openbmc_project.Association.Definitions");
+    host_error_monitor::associationCATAssert->register_property("Associations",
+                                                                associations);
+    host_error_monitor::associationCATAssert->initialize();
+
     // Restart Cause Interface
     host_error_monitor::hostErrorTimeoutIface =
         server.add_interface("/xyz/openbmc_project/host_error_monitor",