blob: e09798837744d9b68678f98a36badaaf41679fa8 [file] [log] [blame]
Chicago Duan184f6022020-04-17 11:30:49 +08001#include "softoff.hpp"
2
Dung Cao3d03f3f2023-09-07 06:51:33 +00003#include "common/instance_id.hpp"
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +10004#include "common/transport.hpp"
Chicago Duan184f6022020-04-17 11:30:49 +08005#include "common/utils.hpp"
6
George Liuc453e162022-12-21 17:16:23 +08007#include <libpldm/entity.h>
8#include <libpldm/platform.h>
George Liuc453e162022-12-21 17:16:23 +08009#include <libpldm/state_set.h>
10
Riya Dixit49cfb132023-03-02 04:26:53 -060011#include <phosphor-logging/lg2.hpp>
Chicago Duan184f6022020-04-17 11:30:49 +080012#include <sdbusplus/bus.hpp>
13#include <sdeventplus/clock.hpp>
George Liua2767e62021-02-24 18:53:34 +080014#include <sdeventplus/exception.hpp>
Chicago Duan184f6022020-04-17 11:30:49 +080015#include <sdeventplus/source/io.hpp>
16#include <sdeventplus/source/time.hpp>
Archana Kakani50554252025-03-17 01:37:29 -050017#include <xyz/openbmc_project/State/Host/common.hpp>
Chicago Duan184f6022020-04-17 11:30:49 +080018
19#include <array>
Sagar Srinivas4d99c312024-03-28 06:50:13 -050020#include <filesystem>
21#include <fstream>
Chicago Duan184f6022020-04-17 11:30:49 +080022
Riya Dixit49cfb132023-03-02 04:26:53 -060023PHOSPHOR_LOG2_USING;
24
Alexander Hansen24c04d52025-11-11 14:46:21 +010025using HostState = sdbusplus::common::xyz::openbmc_project::state::Host;
26
Chicago Duan184f6022020-04-17 11:30:49 +080027namespace pldm
28{
Chicago Duan184f6022020-04-17 11:30:49 +080029using namespace sdeventplus;
30using namespace sdeventplus::source;
Sagar Srinivas4d99c312024-03-28 06:50:13 -050031namespace fs = std::filesystem;
Chicago Duan184f6022020-04-17 11:30:49 +080032constexpr auto clockId = sdeventplus::ClockId::RealTime;
33using Clock = Clock<clockId>;
34using Timer = Time<clockId>;
35
Zach Clarke98c51b2021-06-08 11:29:06 -050036using sdbusplus::exception::SdBusError;
37
38// Shutdown effecter terminus ID, set when we look up the effecter
39pldm::pdr::TerminusID TID = 0;
40
Chicago Duan184f6022020-04-17 11:30:49 +080041namespace sdbusRule = sdbusplus::bus::match::rules;
42
Manojkiran Eda3fcfaa12024-02-26 15:17:58 +053043SoftPowerOff::SoftPowerOff(sdbusplus::bus_t& bus, sd_event* event,
44 pldm::InstanceIdDb& instanceIdDb) :
Eric Yang70eca962025-05-11 01:48:15 +080045 timer(event), instanceIdDb(instanceIdDb)
Chicago Duan184f6022020-04-17 11:30:49 +080046{
Sagar Srinivas4d99c312024-03-28 06:50:13 -050047 auto jsonData = parseConfig();
48
49 if (jsonData.is_discarded())
50 {
Riya Dixit087a7512024-04-06 14:28:08 -050051 error("Failed to parse softoff config JSON file");
Sagar Srinivas4d99c312024-03-28 06:50:13 -050052 return;
53 }
54
Manojkiran Eda31a78442021-09-12 15:18:25 +053055 getHostState();
Chicago Duan184f6022020-04-17 11:30:49 +080056 if (hasError || completed)
57 {
58 return;
59 }
Sagar Srinivas4d99c312024-03-28 06:50:13 -050060 const std::vector<Json> emptyJsonList{};
61 auto entries = jsonData.value("entries", emptyJsonList);
62 for (const auto& entry : entries)
63 {
64 TID = entry.value("tid", 0);
65 pldm::pdr::EntityType entityType = entry.value("entityType", 0);
66 pldm::pdr::StateSetId stateSetId = entry.value("stateSetId", 0);
Chicago Duan184f6022020-04-17 11:30:49 +080067
Sagar Srinivas4d99c312024-03-28 06:50:13 -050068 bool effecterFound = getEffecterID(entityType, stateSetId);
69 if (effecterFound)
70 {
71 auto rc = getSensorInfo(entityType, stateSetId);
72 if (rc != PLDM_SUCCESS)
73 {
Riya Dixit087a7512024-04-06 14:28:08 -050074 error("Failed to get Sensor PDRs, response code '{RC}'", "RC",
Riya Dixit1e5c81e2024-05-03 07:54:00 -050075 lg2::hex, rc);
Sagar Srinivas4d99c312024-03-28 06:50:13 -050076 hasError = true;
77 return;
78 }
79 break;
80 }
81 else
82 {
83 continue;
84 }
Chicago Duan184f6022020-04-17 11:30:49 +080085 }
86
87 // Matches on the pldm StateSensorEvent signal
88 pldmEventSignal = std::make_unique<sdbusplus::bus::match_t>(
89 bus,
90 sdbusRule::type::signal() + sdbusRule::member("StateSensorEvent") +
91 sdbusRule::path("/xyz/openbmc_project/pldm") +
92 sdbusRule::interface("xyz.openbmc_project.PLDM.Event"),
93 std::bind(std::mem_fn(&SoftPowerOff::hostSoftOffComplete), this,
94 std::placeholders::_1));
95}
96
97int SoftPowerOff::getHostState()
98{
99 try
100 {
101 pldm::utils::PropertyValue propertyValue =
102 pldm::utils::DBusHandler().getDbusPropertyVariant(
Alexander Hansen24c04d52025-11-11 14:46:21 +0100103 "/xyz/openbmc_project/state/host0",
104 HostState::property_names::current_host_state,
105 HostState::interface);
Chicago Duan184f6022020-04-17 11:30:49 +0800106
Andrew Geissler5b5fa432021-01-22 16:27:24 -0600107 if ((std::get<std::string>(propertyValue) !=
108 "xyz.openbmc_project.State.Host.HostState.Running") &&
109 (std::get<std::string>(propertyValue) !=
110 "xyz.openbmc_project.State.Host.HostState.TransitioningToOff"))
Chicago Duan184f6022020-04-17 11:30:49 +0800111 {
112 // Host state is not "Running", this app should return success
113 completed = true;
114 return PLDM_SUCCESS;
115 }
116 }
117 catch (const std::exception& e)
118 {
Riya Dixit087a7512024-04-06 14:28:08 -0500119 error(
120 "PLDM remote terminus soft off. Can't get current remote terminus state, error - {ERROR}",
121 "ERROR", e);
Chicago Duan184f6022020-04-17 11:30:49 +0800122 hasError = true;
123 return PLDM_ERROR;
124 }
125
126 return PLDM_SUCCESS;
127}
128
Patrick Williams84b790c2022-07-22 19:26:56 -0500129void SoftPowerOff::hostSoftOffComplete(sdbusplus::message_t& msg)
Chicago Duan184f6022020-04-17 11:30:49 +0800130{
131 pldm::pdr::TerminusID msgTID;
132 pldm::pdr::SensorID msgSensorID;
133 pldm::pdr::SensorOffset msgSensorOffset;
134 pldm::pdr::EventState msgEventState;
135 pldm::pdr::EventState msgPreviousEventState;
136
137 // Read the msg and populate each variable
138 msg.read(msgTID, msgSensorID, msgSensorOffset, msgEventState,
139 msgPreviousEventState);
140
141 if (msgSensorID == sensorID && msgSensorOffset == sensorOffset &&
Zach Clarke98c51b2021-06-08 11:29:06 -0500142 msgEventState == PLDM_SW_TERM_GRACEFUL_SHUTDOWN && msgTID == TID)
Chicago Duan184f6022020-04-17 11:30:49 +0800143 {
144 // Receive Graceful shutdown completion event message. Disable the timer
145 auto rc = timer.stop();
146 if (rc < 0)
147 {
Riya Dixit087a7512024-04-06 14:28:08 -0500148 error(
149 "Failure to STOP the timer of PLDM soft off, response code '{RC}'",
150 "RC", rc);
Chicago Duan184f6022020-04-17 11:30:49 +0800151 }
152
153 // This marks the completion of pldm soft power off.
154 completed = true;
155 }
156}
157
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500158Json SoftPowerOff::parseConfig()
159{
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400160 fs::path softoffConfigJson(
161 fs::path(SOFTOFF_CONFIG_JSON) / "softoff_config.json");
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500162
163 if (!fs::exists(softoffConfigJson) || fs::is_empty(softoffConfigJson))
164 {
Riya Dixit087a7512024-04-06 14:28:08 -0500165 error(
166 "Failed to parse softoff config JSON file '{PATH}', file does not exist",
167 "PATH", softoffConfigJson);
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500168 return PLDM_ERROR;
169 }
170
171 std::ifstream jsonFile(softoffConfigJson);
172 return Json::parse(jsonFile);
173}
174
175bool SoftPowerOff::getEffecterID(pldm::pdr::EntityType& entityType,
176 pldm::pdr::StateSetId& stateSetId)
Chicago Duan184f6022020-04-17 11:30:49 +0800177{
178 auto& bus = pldm::utils::DBusHandler::getBus();
Chicago Duan184f6022020-04-17 11:30:49 +0800179 try
180 {
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500181 std::vector<std::vector<uint8_t>> response{};
182 auto method = bus.new_method_call(
Chicago Duan184f6022020-04-17 11:30:49 +0800183 "xyz.openbmc_project.PLDM", "/xyz/openbmc_project/pldm",
184 "xyz.openbmc_project.PLDM.PDR", "FindStateEffecterPDR");
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500185 method.append(TID, entityType, stateSetId);
186 auto responseMsg = bus.call(method, dbusTimeout);
Chicago Duan184f6022020-04-17 11:30:49 +0800187
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500188 responseMsg.read(response);
189 if (response.size())
Chicago Duan184f6022020-04-17 11:30:49 +0800190 {
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500191 for (auto& rep : response)
Chicago Duan184f6022020-04-17 11:30:49 +0800192 {
Pavithra Barithaya3c8b3e32025-01-30 10:45:51 +0530193 auto softoffPdr = new (rep.data()) pldm_state_effecter_pdr;
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500194 effecterID = softoffPdr->effecter_id;
Chicago Duan184f6022020-04-17 11:30:49 +0800195 }
196 }
197 else
198 {
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500199 return false;
Chicago Duan184f6022020-04-17 11:30:49 +0800200 }
201 }
Patrick Williams84b790c2022-07-22 19:26:56 -0500202 catch (const sdbusplus::exception_t& e)
Chicago Duan184f6022020-04-17 11:30:49 +0800203 {
Riya Dixit087a7512024-04-06 14:28:08 -0500204 error("Failed to get softPowerOff PDR, error - {ERROR}", "ERROR", e);
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500205 return false;
Chicago Duan184f6022020-04-17 11:30:49 +0800206 }
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500207 return true;
Chicago Duan184f6022020-04-17 11:30:49 +0800208}
209
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500210int SoftPowerOff::getSensorInfo(pldm::pdr::EntityType& entityType,
211 pldm::pdr::StateSetId& stateSetId)
Chicago Duan184f6022020-04-17 11:30:49 +0800212{
Chicago Duan184f6022020-04-17 11:30:49 +0800213 try
214 {
215 auto& bus = pldm::utils::DBusHandler::getBus();
216 std::vector<std::vector<uint8_t>> Response{};
217 auto method = bus.new_method_call(
218 "xyz.openbmc_project.PLDM", "/xyz/openbmc_project/pldm",
219 "xyz.openbmc_project.PLDM.PDR", "FindStateSensorPDR");
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500220 method.append(TID, entityType, stateSetId);
Chicago Duan184f6022020-04-17 11:30:49 +0800221
vkaverap@in.ibm.com91a092f2023-09-18 23:39:44 -0500222 auto ResponseMsg = bus.call(method, dbusTimeout);
Chicago Duan184f6022020-04-17 11:30:49 +0800223
224 ResponseMsg.read(Response);
225
226 if (Response.size() == 0)
227 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600228 error("No sensor PDR has been found that matches the criteria");
Chicago Duan184f6022020-04-17 11:30:49 +0800229 return PLDM_ERROR;
230 }
231
ThuBaNguyen499a29d2023-05-30 06:32:06 +0700232 pldm_state_sensor_pdr* pdr = nullptr;
Chicago Duan184f6022020-04-17 11:30:49 +0800233 for (auto& rep : Response)
234 {
Pavithra Barithaya3c8b3e32025-01-30 10:45:51 +0530235 pdr = new (rep.data()) pldm_state_sensor_pdr;
Manojkiran Eda31a78442021-09-12 15:18:25 +0530236 if (!pdr)
237 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600238 error("Failed to get state sensor PDR.");
Manojkiran Eda31a78442021-09-12 15:18:25 +0530239 return PLDM_ERROR;
240 }
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530241 }
242
Chicago Duan184f6022020-04-17 11:30:49 +0800243 sensorID = pdr->sensor_id;
244
245 auto compositeSensorCount = pdr->composite_sensor_count;
246 auto possibleStatesStart = pdr->possible_states;
247
248 for (auto offset = 0; offset < compositeSensorCount; offset++)
249 {
Pavithra Barithaya3c8b3e32025-01-30 10:45:51 +0530250 auto possibleStates = new (possibleStatesStart)
251 state_sensor_possible_states;
Chicago Duan184f6022020-04-17 11:30:49 +0800252 auto setId = possibleStates->state_set_id;
253 auto possibleStateSize = possibleStates->possible_states_size;
254
255 if (setId == PLDM_STATE_SET_SW_TERMINATION_STATUS)
256 {
257 sensorOffset = offset;
258 break;
259 }
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400260 possibleStatesStart +=
261 possibleStateSize + sizeof(setId) + sizeof(possibleStateSize);
Chicago Duan184f6022020-04-17 11:30:49 +0800262 }
263 }
Patrick Williams84b790c2022-07-22 19:26:56 -0500264 catch (const sdbusplus::exception_t& e)
Chicago Duan184f6022020-04-17 11:30:49 +0800265 {
Riya Dixit087a7512024-04-06 14:28:08 -0500266 error("Failed to get state sensor PDR during soft-off, error - {ERROR}",
267 "ERROR", e);
Chicago Duan184f6022020-04-17 11:30:49 +0800268 return PLDM_ERROR;
269 }
270
271 return PLDM_SUCCESS;
272}
273
274int SoftPowerOff::hostSoftOff(sdeventplus::Event& event)
275{
276 constexpr uint8_t effecterCount = 1;
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000277 PldmTransport pldmTransport{};
ManojKiran Eda22bcb072025-07-11 23:49:43 +0000278 uint8_t instanceID;
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000279 uint8_t mctpEID;
Chicago Duan184f6022020-04-17 11:30:49 +0800280
281 mctpEID = pldm::utils::readHostEID();
Dung Cao3d03f3f2023-09-07 06:51:33 +0000282 // TODO: fix mapping to work around OpenBMC ecosystem deficiencies
283 pldm_tid_t pldmTID = static_cast<pldm_tid_t>(mctpEID);
Chicago Duan184f6022020-04-17 11:30:49 +0800284
Archana Kakani50554252025-03-17 01:37:29 -0500285 uint8_t effecterState;
286 auto requestHostTransition =
287 pldm::utils::DBusHandler().getDbusProperty<std::string>(
Alexander Hansen24c04d52025-11-11 14:46:21 +0100288 "/xyz/openbmc_project/state/host0",
289 HostState::property_names::requested_host_transition,
Archana Kakani50554252025-03-17 01:37:29 -0500290 sdbusplus::common::xyz::openbmc_project::state::Host::interface);
291 if (requestHostTransition !=
292 "xyz.openbmc_project.State.Host.Transition.Off")
293 {
294 effecterState = PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED;
295 }
296 else
297 {
298 effecterState = PLDM_SW_TERM_GRACEFUL_SHUTDOWN_REQUESTED;
299 }
300
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400301 std::array<uint8_t,
302 sizeof(pldm_msg_hdr) + sizeof(effecterID) +
303 sizeof(effecterCount) + sizeof(set_effecter_state_field)>
Chicago Duan184f6022020-04-17 11:30:49 +0800304 requestMsg{};
Pavithra Barithaya3c8b3e32025-01-30 10:45:51 +0530305 auto request = new (requestMsg.data()) pldm_msg;
Archana Kakani50554252025-03-17 01:37:29 -0500306 set_effecter_state_field stateField{PLDM_REQUEST_SET, effecterState};
ManojKiran Eda22bcb072025-07-11 23:49:43 +0000307 instanceID = instanceIdDb.next(pldmTID);
Chicago Duan184f6022020-04-17 11:30:49 +0800308 auto rc = encode_set_state_effecter_states_req(
309 instanceID, effecterID, effecterCount, &stateField, request);
310 if (rc != PLDM_SUCCESS)
311 {
Dung Cao3d03f3f2023-09-07 06:51:33 +0000312 instanceIdDb.free(pldmTID, instanceID);
Riya Dixit087a7512024-04-06 14:28:08 -0500313 error(
314 "Failed to encode set state effecter states request message, response code '{RC}'",
Riya Dixit1e5c81e2024-05-03 07:54:00 -0500315 "RC", lg2::hex, rc);
Chicago Duan184f6022020-04-17 11:30:49 +0800316 return PLDM_ERROR;
317 }
318
Chicago Duan184f6022020-04-17 11:30:49 +0800319 // Add a timer to the event loop, default 30s.
Patrick Williamsa6756622023-10-20 11:19:15 -0500320 auto timerCallback = [=, this](Timer& /*source*/,
321 Timer::TimePoint /*time*/) mutable {
Chicago Duan184f6022020-04-17 11:30:49 +0800322 if (!responseReceived)
323 {
Dung Cao3d03f3f2023-09-07 06:51:33 +0000324 instanceIdDb.free(pldmTID, instanceID);
Riya Dixit49cfb132023-03-02 04:26:53 -0600325 error(
Riya Dixit087a7512024-04-06 14:28:08 -0500326 "PLDM soft off failed, can't get the response for the PLDM request msg. Time out! Exit the pldm-softpoweroff");
Chicago Duan184f6022020-04-17 11:30:49 +0800327 exit(-1);
328 }
329 return;
330 };
331 Timer time(event, (Clock(event).now() + std::chrono::seconds{30}),
332 std::chrono::seconds{1}, std::move(timerCallback));
333
334 // Add a callback to handle EPOLLIN on fd
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400335 auto callback = [=, &pldmTransport,
336 this](IO& io, int fd, uint32_t revents) mutable {
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000337 if (fd != pldmTransport.getEventSource())
338 {
339 return;
340 }
341
Chicago Duan184f6022020-04-17 11:30:49 +0800342 if (!(revents & EPOLLIN))
343 {
344 return;
345 }
346
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000347 void* responseMsg = nullptr;
Chicago Duan184f6022020-04-17 11:30:49 +0800348 size_t responseMsgSize{};
Dung Cao3d03f3f2023-09-07 06:51:33 +0000349 pldm_tid_t srcTID = pldmTID;
Chicago Duan184f6022020-04-17 11:30:49 +0800350
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000351 auto rc = pldmTransport.recvMsg(pldmTID, responseMsg, responseMsgSize);
Chicago Duan184f6022020-04-17 11:30:49 +0800352 if (rc)
353 {
Riya Dixit087a7512024-04-06 14:28:08 -0500354 error(
355 "Failed to receive pldm data during soft-off, response code '{RC}'",
Riya Dixit1e5c81e2024-05-03 07:54:00 -0500356 "RC", rc);
Chicago Duan184f6022020-04-17 11:30:49 +0800357 return;
358 }
359
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400360 std::unique_ptr<void, decltype(std::free)*> responseMsgPtr{
361 responseMsg, std::free};
Chicago Duan184f6022020-04-17 11:30:49 +0800362
363 // We've got the response meant for the PLDM request msg that was
364 // sent out
365 io.set_enabled(Enabled::Off);
Pavithra Barithaya3c8b3e32025-01-30 10:45:51 +0530366 auto response = new (responseMsgPtr.get()) pldm_msg;
Dung Cao3d03f3f2023-09-07 06:51:33 +0000367
368 if (srcTID != pldmTID ||
369 !pldm_msg_hdr_correlate_response(&request->hdr, &response->hdr))
370 {
371 /* This isn't the response we were looking for */
372 return;
373 }
374
375 /* We have the right response, release the instance ID and process */
376 io.set_enabled(Enabled::Off);
377 instanceIdDb.free(pldmTID, instanceID);
378
George Liu9915d022021-12-21 14:04:31 +0800379 if (response->payload[0] != PLDM_SUCCESS)
380 {
Riya Dixit087a7512024-04-06 14:28:08 -0500381 error("Getting the wrong response, response code '{RC}'", "RC",
Riya Dixit1e5c81e2024-05-03 07:54:00 -0500382 response->payload[0]);
George Liu9915d022021-12-21 14:04:31 +0800383 exit(-1);
384 }
Chicago Duan184f6022020-04-17 11:30:49 +0800385
386 responseReceived = true;
387
388 // Start Timer
389 using namespace std::chrono;
390 auto timeMicroseconds =
391 duration_cast<microseconds>(seconds(SOFTOFF_TIMEOUT_SECONDS));
392
393 auto ret = startTimer(timeMicroseconds);
394 if (ret < 0)
395 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600396 error(
Riya Dixit087a7512024-04-06 14:28:08 -0500397 "Failure to start remote terminus soft off wait timer, Exit the pldm-softpoweroff with response code:{NUM}",
398 "NUM", ret);
Chicago Duan184f6022020-04-17 11:30:49 +0800399 exit(-1);
400 }
401 else
402 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600403 error(
Riya Dixit087a7512024-04-06 14:28:08 -0500404 "Timer started waiting for remote terminus soft off, timeout in sec '{TIMEOUT_SEC}'",
Riya Dixit49cfb132023-03-02 04:26:53 -0600405 "TIMEOUT_SEC", SOFTOFF_TIMEOUT_SECONDS);
Chicago Duan184f6022020-04-17 11:30:49 +0800406 }
407 return;
408 };
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000409 IO io(event, pldmTransport.getEventSource(), EPOLLIN, std::move(callback));
Chicago Duan184f6022020-04-17 11:30:49 +0800410
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000411 // Asynchronously send the PLDM request
412 rc = pldmTransport.sendMsg(pldmTID, requestMsg.data(), requestMsg.size());
Sampa Misra9f8d2b02021-03-24 08:33:14 +0000413 if (0 > rc)
Chicago Duan184f6022020-04-17 11:30:49 +0800414 {
Dung Cao3d03f3f2023-09-07 06:51:33 +0000415 instanceIdDb.free(pldmTID, instanceID);
Riya Dixit49cfb132023-03-02 04:26:53 -0600416 error(
Riya Dixit087a7512024-04-06 14:28:08 -0500417 "Failed to send message/receive response, response code '{RC}' and error - {ERROR}",
Riya Dixit1e5c81e2024-05-03 07:54:00 -0500418 "RC", rc, "ERROR", errno);
Chicago Duan184f6022020-04-17 11:30:49 +0800419 return PLDM_ERROR;
420 }
421
422 // Time out or soft off complete
423 while (!isCompleted() && !isTimerExpired())
424 {
425 try
426 {
427 event.run(std::nullopt);
428 }
429 catch (const sdeventplus::SdEventError& e)
430 {
Dung Cao3d03f3f2023-09-07 06:51:33 +0000431 instanceIdDb.free(pldmTID, instanceID);
Riya Dixit49cfb132023-03-02 04:26:53 -0600432 error(
Riya Dixit087a7512024-04-06 14:28:08 -0500433 "Failed to process request while remote terminus soft off, error - {ERROR}",
434 "ERROR", e);
Chicago Duan184f6022020-04-17 11:30:49 +0800435 return PLDM_ERROR;
436 }
437 }
438
439 return PLDM_SUCCESS;
440}
441
442int SoftPowerOff::startTimer(const std::chrono::microseconds& usec)
443{
444 return timer.start(usec);
445}
446} // namespace pldm