1 #include "utils/dbus_utils.hpp" 2 3 #include "async_resp.hpp" 4 5 #include <boost/system/error_code.hpp> 6 #include <nlohmann/json.hpp> 7 #include <sdbusplus/message.hpp> 8 9 #include <memory> 10 #include <string> 11 #include <string_view> 12 13 namespace redfish 14 { 15 namespace details 16 { 17 18 void afterSetProperty(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 19 const std::string& redfishPropertyName, 20 const nlohmann::json& propertyValue, 21 const boost::system::error_code& ec, 22 const sdbusplus::message_t& msg) 23 { 24 if (ec) 25 { 26 if (ec.value() == boost::system::errc::permission_denied) 27 { 28 messages::insufficientPrivilege(asyncResp->res); 29 } 30 if (ec.value() == boost::asio::error::host_unreachable) 31 { 32 messages::resourceNotFound(asyncResp->res, "Set", 33 redfishPropertyName); 34 return; 35 } 36 const sd_bus_error* dbusError = msg.get_error(); 37 if (dbusError != nullptr) 38 { 39 std::string_view errorName(dbusError->name); 40 41 if (errorName == "xyz.openbmc_project.Common.Error.InvalidArgument") 42 { 43 BMCWEB_LOG_WARNING("DBUS response error: {}", ec); 44 messages::propertyValueIncorrect( 45 asyncResp->res, redfishPropertyName, propertyValue); 46 return; 47 } 48 if (errorName == 49 "xyz.openbmc_project.State.Chassis.Error.BMCNotReady") 50 { 51 BMCWEB_LOG_WARNING( 52 "BMC not ready, operation not allowed right now"); 53 messages::serviceTemporarilyUnavailable(asyncResp->res, "10"); 54 return; 55 } 56 if (errorName == "xyz.openbmc_project.State.Host.Error.BMCNotReady") 57 { 58 BMCWEB_LOG_WARNING( 59 "BMC not ready, operation not allowed right now"); 60 messages::serviceTemporarilyUnavailable(asyncResp->res, "10"); 61 return; 62 } 63 if (errorName == "xyz.openbmc_project.Common.Error.NotAllowed") 64 { 65 messages::propertyNotWritable(asyncResp->res, 66 redfishPropertyName); 67 return; 68 } 69 if (errorName == "xyz.openbmc_project.Common.Error.Unavailable") 70 { 71 messages::resourceInStandby(asyncResp->res); 72 return; 73 } 74 } 75 BMCWEB_LOG_ERROR("D-Bus error setting Redfish Property {} ec={}", 76 redfishPropertyName, ec); 77 messages::internalError(asyncResp->res); 78 return; 79 } 80 // Only set 204 if another error hasn't already happened. 81 if (asyncResp->res.result() == boost::beast::http::status::ok) 82 { 83 asyncResp->res.result(boost::beast::http::status::no_content); 84 } 85 }; 86 87 void afterSetPropertyAction(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 88 const std::string& redfishActionName, 89 const std::string& redfishActionParameterName, 90 const boost::system::error_code& ec, 91 const sdbusplus::message_t& /*msg*/) 92 { 93 if (ec) 94 { 95 if (ec.value() == boost::asio::error::invalid_argument) 96 { 97 BMCWEB_LOG_WARNING( 98 "Resource {} is patched with invalid argument during action {}", 99 redfishActionParameterName, redfishActionName); 100 if (redfishActionParameterName.empty()) 101 { 102 messages::operationFailed(asyncResp->res); 103 } 104 else 105 { 106 messages::actionParameterValueError(asyncResp->res, 107 redfishActionParameterName, 108 redfishActionName); 109 } 110 return; 111 } 112 if (ec.value() == boost::asio::error::host_unreachable) 113 { 114 BMCWEB_LOG_WARNING( 115 "Resource {} is not found while performing action {}", 116 redfishActionParameterName, redfishActionName); 117 messages::resourceNotFound(asyncResp->res, "Actions", 118 redfishActionName); 119 return; 120 } 121 122 BMCWEB_LOG_ERROR("D-Bus error setting Redfish Property {} ec={}", 123 redfishActionParameterName, ec); 124 messages::internalError(asyncResp->res); 125 return; 126 } 127 // Only set 204 if another error hasn't already happened. 128 if (asyncResp->res.result() == boost::beast::http::status::ok) 129 { 130 asyncResp->res.result(boost::beast::http::status::no_content); 131 } 132 }; 133 } // namespace details 134 } // namespace redfish 135