Systems: Restore old-style LocationIndicatorActive

The commit 2eaa927 [1] altered the D-Bus associations used for setting
and getting the LED state for the Systems resource. Machines which use
entity-manager do not have the new association yet.

This commit is adding back the use of the old D-Bus method under a
compile option. This will be enabled by default until October 15, 2025
and completely removed by June 2026.

[1] https://gerrit.openbmc.org/c/openbmc/bmcweb/+/82078

Tested:
 - Built with option enabled and confirmed logging showed old method
   being used.
 - Built with option disabled and confirmed logging showed new method
   being used.

Change-Id: I271fc464ef512b742a8c85419668aa09d38e525d
Signed-off-by: Janet Adkins <janeta@us.ibm.com>
diff --git a/config/meson.build b/config/meson.build
index eb29cf6..9668f5c 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -36,6 +36,7 @@
     'redfish-provisioning-feature',
     'redfish-updateservice-use-dbus',
     'redfish-use-3-digit-messageid',
+    'redfish-use-hardcoded-system-location-indicator',
     'rest',
     'session-auth',
     'static-hosting',
diff --git a/meson.options b/meson.options
index 6a28751..5ec28cd 100644
--- a/meson.options
+++ b/meson.options
@@ -311,6 +311,19 @@
                     option will be removed by March 2026.''',
 )
 
+# BMCWEB_REDFISH_USE_HARDCODED_SYSTEM_LOCATION_INDICATOR
+option(
+    'redfish-use-hardcoded-system-location-indicator',
+    type: 'feature',
+    value: 'enabled',
+    description: '''Enable/disable the use of hard-coded LED group
+                    enclosure_identify_blink and enclosure_identify for getting
+                    and setting the LocationIndicatorActive for the Systems
+                    response. The default condition will be enabled until
+                    October 15, 2025.  The code to enable this option will be
+                    removed by June 2026.''',
+)
+
 # BMCWEB_REDFISH_ALLOW_DEPRECATED_POWER_THERMAL
 option(
     'redfish-allow-deprecated-power-thermal',
diff --git a/redfish-core/lib/led.hpp b/redfish-core/lib/led.hpp
index 32e9725..b74dc4d 100644
--- a/redfish-core/lib/led.hpp
+++ b/redfish-core/lib/led.hpp
@@ -153,6 +153,96 @@
         });
 }
 
+/**
+ * @brief Retrieves identify system led group properties over dbus
+ *
+ * @param[in] asyncResp     Shared pointer for generating response message.
+ *
+ * @return None.
+ */
+inline void getSystemLocationIndicatorActive(
+    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
+{
+    BMCWEB_LOG_DEBUG("Get LocationIndicatorActive");
+    dbus::utility::getProperty<bool>(
+        "xyz.openbmc_project.LED.GroupManager",
+        "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
+        "xyz.openbmc_project.Led.Group", "Asserted",
+        [asyncResp](const boost::system::error_code& ec, const bool blinking) {
+            // Some systems may not have enclosure_identify_blink object so
+            // proceed to get enclosure_identify state.
+            if (ec == boost::system::errc::invalid_argument)
+            {
+                BMCWEB_LOG_DEBUG(
+                    "Get identity blinking LED failed, mismatch in property type");
+                messages::internalError(asyncResp->res);
+                return;
+            }
+
+            // Blinking ON, no need to check enclosure_identify assert.
+            if (!ec && blinking)
+            {
+                asyncResp->res.jsonValue["LocationIndicatorActive"] = true;
+                return;
+            }
+
+            dbus::utility::getProperty<bool>(
+                "xyz.openbmc_project.LED.GroupManager",
+                "/xyz/openbmc_project/led/groups/enclosure_identify",
+                "xyz.openbmc_project.Led.Group", "Asserted",
+                [asyncResp](const boost::system::error_code& ec2,
+                            const bool ledOn) {
+                    if (ec2 == boost::system::errc::invalid_argument)
+                    {
+                        BMCWEB_LOG_DEBUG(
+                            "Get enclosure identity led failed, mismatch in property type");
+                        messages::internalError(asyncResp->res);
+                        return;
+                    }
+
+                    if (ec2)
+                    {
+                        return;
+                    }
+
+                    asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
+                });
+        });
+}
+
+/**
+ * @brief Sets identify system led group properties
+ *
+ * @param[in] asyncResp     Shared pointer for generating response message.
+ * @param[in] ledState  LED state passed from request
+ *
+ * @return None.
+ */
+inline void setSystemLocationIndicatorActive(
+    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState)
+{
+    BMCWEB_LOG_DEBUG("Set LocationIndicatorActive");
+
+    sdbusplus::asio::setProperty(
+        *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
+        "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
+        "xyz.openbmc_project.Led.Group", "Asserted", ledState,
+        [asyncResp, ledState](const boost::system::error_code& ec) {
+            if (ec)
+            {
+                // Some systems may not have enclosure_identify_blink object so
+                // lets set enclosure_identify state also if
+                // enclosure_identify_blink failed
+                setDbusProperty(
+                    asyncResp, "LocationIndicatorActive",
+                    "xyz.openbmc_project.LED.GroupManager",
+                    sdbusplus::message::object_path(
+                        "/xyz/openbmc_project/led/groups/enclosure_identify"),
+                    "xyz.openbmc_project.Led.Group", "Asserted", ledState);
+            }
+        });
+}
+
 inline void handleLedGroupSubtree(
     const std::string& objPath, const boost::system::error_code& ec,
     const dbus::utility::MapperGetSubTreeResponse& subtree,
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 7057533..a336988 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -3132,15 +3132,22 @@
             nlohmann::json::array_t({"KVMIP"});
     }
 
-    systems_utils::getValidSystemsPath(
-        asyncResp, systemName,
-        [asyncResp,
-         systemName](const std::optional<std::string>& validSystemsPath) {
-            if (validSystemsPath)
-            {
-                getLocationIndicatorActive(asyncResp, *validSystemsPath);
-            }
-        });
+    if constexpr (BMCWEB_REDFISH_USE_HARDCODED_SYSTEM_LOCATION_INDICATOR)
+    {
+        getSystemLocationIndicatorActive(asyncResp);
+    }
+    else
+    {
+        systems_utils::getValidSystemsPath(
+            asyncResp, systemName,
+            [asyncResp,
+             systemName](const std::optional<std::string>& validSystemsPath) {
+                if (validSystemsPath)
+                {
+                    getLocationIndicatorActive(asyncResp, *validSystemsPath);
+                }
+            });
+    }
 
     if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_INDICATORLED)
     {
@@ -3313,20 +3320,28 @@
 
     if (patchParams.locationIndicatorActive)
     {
-        systems_utils::getValidSystemsPath(
-            asyncResp, systemName,
-            [asyncResp, systemName,
-             locationIndicatorActive{*patchParams.locationIndicatorActive}](
-                const std::optional<std::string>& validSystemsPath) {
-                if (!validSystemsPath)
-                {
-                    messages::resourceNotFound(asyncResp->res, "Systems",
-                                               systemName);
-                    return;
-                }
-                setLocationIndicatorActive(asyncResp, *validSystemsPath,
-                                           locationIndicatorActive);
-            });
+        if constexpr (BMCWEB_REDFISH_USE_HARDCODED_SYSTEM_LOCATION_INDICATOR)
+        {
+            setSystemLocationIndicatorActive(
+                asyncResp, *patchParams.locationIndicatorActive);
+        }
+        else
+        {
+            systems_utils::getValidSystemsPath(
+                asyncResp, systemName,
+                [asyncResp, systemName,
+                 locationIndicatorActive{*patchParams.locationIndicatorActive}](
+                    const std::optional<std::string>& validSystemsPath) {
+                    if (!validSystemsPath)
+                    {
+                        messages::resourceNotFound(asyncResp->res, "Systems",
+                                                   systemName);
+                        return;
+                    }
+                    setLocationIndicatorActive(asyncResp, *validSystemsPath,
+                                               locationIndicatorActive);
+                });
+        }
     }
 
     if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_INDICATORLED)