1d02aad39SEd Tanous #include "utils/dbus_utils.hpp" 2d02aad39SEd Tanous 3d02aad39SEd Tanous #include "async_resp.hpp" 4d02aad39SEd Tanous 5d02aad39SEd Tanous #include <boost/system/error_code.hpp> 6d02aad39SEd Tanous #include <nlohmann/json.hpp> 7d02aad39SEd Tanous #include <sdbusplus/message.hpp> 8d02aad39SEd Tanous 9d02aad39SEd Tanous #include <memory> 10d02aad39SEd Tanous #include <string> 11d02aad39SEd Tanous #include <string_view> 12d02aad39SEd Tanous 13d02aad39SEd Tanous namespace redfish 14d02aad39SEd Tanous { 15d02aad39SEd Tanous namespace details 16d02aad39SEd Tanous { 17d02aad39SEd Tanous 18d02aad39SEd Tanous void afterSetProperty(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 19d02aad39SEd Tanous const std::string& redfishPropertyName, 20d02aad39SEd Tanous const nlohmann::json& propertyValue, 21d02aad39SEd Tanous const boost::system::error_code& ec, 22d02aad39SEd Tanous const sdbusplus::message_t& msg) 23d02aad39SEd Tanous { 24d02aad39SEd Tanous if (ec) 25d02aad39SEd Tanous { 26d02aad39SEd Tanous if (ec.value() == boost::system::errc::permission_denied) 27d02aad39SEd Tanous { 28d02aad39SEd Tanous messages::insufficientPrivilege(asyncResp->res); 29d02aad39SEd Tanous } 30*87c44966SAsmitha Karunanithi if (ec.value() == boost::asio::error::host_unreachable) 31*87c44966SAsmitha Karunanithi { 32*87c44966SAsmitha Karunanithi messages::resourceNotFound(asyncResp->res, "Set", 33*87c44966SAsmitha Karunanithi redfishPropertyName); 34*87c44966SAsmitha Karunanithi return; 35*87c44966SAsmitha Karunanithi } 36d02aad39SEd Tanous const sd_bus_error* dbusError = msg.get_error(); 37d02aad39SEd Tanous if (dbusError != nullptr) 38d02aad39SEd Tanous { 39d02aad39SEd Tanous std::string_view errorName(dbusError->name); 40d02aad39SEd Tanous 41d02aad39SEd Tanous if (errorName == "xyz.openbmc_project.Common.Error.InvalidArgument") 42d02aad39SEd Tanous { 43d02aad39SEd Tanous BMCWEB_LOG_WARNING("DBUS response error: {}", ec); 44d02aad39SEd Tanous messages::propertyValueIncorrect( 45d02aad39SEd Tanous asyncResp->res, redfishPropertyName, propertyValue); 46d02aad39SEd Tanous return; 47d02aad39SEd Tanous } 48d02aad39SEd Tanous if (errorName == 49d02aad39SEd Tanous "xyz.openbmc_project.State.Chassis.Error.BMCNotReady") 50d02aad39SEd Tanous { 51d02aad39SEd Tanous BMCWEB_LOG_WARNING( 52d02aad39SEd Tanous "BMC not ready, operation not allowed right now"); 53d02aad39SEd Tanous messages::serviceTemporarilyUnavailable(asyncResp->res, "10"); 54d02aad39SEd Tanous return; 55d02aad39SEd Tanous } 56d02aad39SEd Tanous if (errorName == "xyz.openbmc_project.State.Host.Error.BMCNotReady") 57d02aad39SEd Tanous { 58d02aad39SEd Tanous BMCWEB_LOG_WARNING( 59d02aad39SEd Tanous "BMC not ready, operation not allowed right now"); 60d02aad39SEd Tanous messages::serviceTemporarilyUnavailable(asyncResp->res, "10"); 61d02aad39SEd Tanous return; 62d02aad39SEd Tanous } 63d02aad39SEd Tanous if (errorName == "xyz.openbmc_project.Common.Error.NotAllowed") 64d02aad39SEd Tanous { 65d02aad39SEd Tanous messages::propertyNotWritable(asyncResp->res, 66d02aad39SEd Tanous redfishPropertyName); 67d02aad39SEd Tanous return; 68d02aad39SEd Tanous } 69*87c44966SAsmitha Karunanithi if (errorName == "xyz.openbmc_project.Common.Error.Unavailable") 70*87c44966SAsmitha Karunanithi { 71*87c44966SAsmitha Karunanithi messages::resourceInStandby(asyncResp->res); 72*87c44966SAsmitha Karunanithi return; 73*87c44966SAsmitha Karunanithi } 74d02aad39SEd Tanous } 75d02aad39SEd Tanous BMCWEB_LOG_ERROR("D-Bus error setting Redfish Property {} ec={}", 76d02aad39SEd Tanous redfishPropertyName, ec); 77d02aad39SEd Tanous messages::internalError(asyncResp->res); 78d02aad39SEd Tanous return; 79d02aad39SEd Tanous } 801827b4f1SAsmitha Karunanithi // Only set 204 if another error hasn't already happened. 811827b4f1SAsmitha Karunanithi if (asyncResp->res.result() == boost::beast::http::status::ok) 821827b4f1SAsmitha Karunanithi { 831827b4f1SAsmitha Karunanithi asyncResp->res.result(boost::beast::http::status::no_content); 841827b4f1SAsmitha Karunanithi } 851827b4f1SAsmitha Karunanithi }; 861827b4f1SAsmitha Karunanithi 871827b4f1SAsmitha Karunanithi void afterSetPropertyAction(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 881827b4f1SAsmitha Karunanithi const std::string& redfishActionName, 891827b4f1SAsmitha Karunanithi const std::string& redfishActionParameterName, 901827b4f1SAsmitha Karunanithi const boost::system::error_code& ec, 911827b4f1SAsmitha Karunanithi const sdbusplus::message_t& /*msg*/) 921827b4f1SAsmitha Karunanithi { 931827b4f1SAsmitha Karunanithi if (ec) 941827b4f1SAsmitha Karunanithi { 951827b4f1SAsmitha Karunanithi if (ec.value() == boost::asio::error::invalid_argument) 961827b4f1SAsmitha Karunanithi { 971827b4f1SAsmitha Karunanithi BMCWEB_LOG_WARNING( 981827b4f1SAsmitha Karunanithi "Resource {} is patched with invalid argument during action {}", 991827b4f1SAsmitha Karunanithi redfishActionParameterName, redfishActionName); 1001827b4f1SAsmitha Karunanithi if (redfishActionParameterName.empty()) 1011827b4f1SAsmitha Karunanithi { 1021827b4f1SAsmitha Karunanithi messages::operationFailed(asyncResp->res); 1031827b4f1SAsmitha Karunanithi } 1041827b4f1SAsmitha Karunanithi else 1051827b4f1SAsmitha Karunanithi { 1061827b4f1SAsmitha Karunanithi messages::actionParameterValueError(asyncResp->res, 1071827b4f1SAsmitha Karunanithi redfishActionParameterName, 1081827b4f1SAsmitha Karunanithi redfishActionName); 1091827b4f1SAsmitha Karunanithi } 1101827b4f1SAsmitha Karunanithi return; 1111827b4f1SAsmitha Karunanithi } 1121827b4f1SAsmitha Karunanithi if (ec.value() == boost::asio::error::host_unreachable) 1131827b4f1SAsmitha Karunanithi { 1141827b4f1SAsmitha Karunanithi BMCWEB_LOG_WARNING( 1151827b4f1SAsmitha Karunanithi "Resource {} is not found while performing action {}", 1161827b4f1SAsmitha Karunanithi redfishActionParameterName, redfishActionName); 1171827b4f1SAsmitha Karunanithi messages::resourceNotFound(asyncResp->res, "Actions", 1181827b4f1SAsmitha Karunanithi redfishActionName); 1191827b4f1SAsmitha Karunanithi return; 1201827b4f1SAsmitha Karunanithi } 1211827b4f1SAsmitha Karunanithi 1221827b4f1SAsmitha Karunanithi BMCWEB_LOG_ERROR("D-Bus error setting Redfish Property {} ec={}", 1231827b4f1SAsmitha Karunanithi redfishActionParameterName, ec); 1241827b4f1SAsmitha Karunanithi messages::internalError(asyncResp->res); 1251827b4f1SAsmitha Karunanithi return; 1261827b4f1SAsmitha Karunanithi } 1271827b4f1SAsmitha Karunanithi // Only set 204 if another error hasn't already happened. 128d02aad39SEd Tanous if (asyncResp->res.result() == boost::beast::http::status::ok) 129d02aad39SEd Tanous { 130d02aad39SEd Tanous asyncResp->res.result(boost::beast::http::status::no_content); 131d02aad39SEd Tanous } 132d02aad39SEd Tanous }; 133d02aad39SEd Tanous } // namespace details 134d02aad39SEd Tanous } // namespace redfish 135