blob: 71fa9dc084bd914d06c0ad23c83d483df338956a [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
Chicago Duan184f6022020-04-17 11:30:49 +080025namespace pldm
26{
Chicago Duan184f6022020-04-17 11:30:49 +080027using namespace sdeventplus;
28using namespace sdeventplus::source;
Sagar Srinivas4d99c312024-03-28 06:50:13 -050029namespace fs = std::filesystem;
Chicago Duan184f6022020-04-17 11:30:49 +080030constexpr auto clockId = sdeventplus::ClockId::RealTime;
31using Clock = Clock<clockId>;
32using Timer = Time<clockId>;
33
Zach Clarke98c51b2021-06-08 11:29:06 -050034using sdbusplus::exception::SdBusError;
35
36// Shutdown effecter terminus ID, set when we look up the effecter
37pldm::pdr::TerminusID TID = 0;
38
Chicago Duan184f6022020-04-17 11:30:49 +080039namespace sdbusRule = sdbusplus::bus::match::rules;
40
Manojkiran Eda3fcfaa12024-02-26 15:17:58 +053041SoftPowerOff::SoftPowerOff(sdbusplus::bus_t& bus, sd_event* event,
42 pldm::InstanceIdDb& instanceIdDb) :
Eric Yang70eca962025-05-11 01:48:15 +080043 timer(event), instanceIdDb(instanceIdDb)
Chicago Duan184f6022020-04-17 11:30:49 +080044{
Sagar Srinivas4d99c312024-03-28 06:50:13 -050045 auto jsonData = parseConfig();
46
47 if (jsonData.is_discarded())
48 {
Riya Dixit087a7512024-04-06 14:28:08 -050049 error("Failed to parse softoff config JSON file");
Sagar Srinivas4d99c312024-03-28 06:50:13 -050050 return;
51 }
52
Manojkiran Eda31a78442021-09-12 15:18:25 +053053 getHostState();
Chicago Duan184f6022020-04-17 11:30:49 +080054 if (hasError || completed)
55 {
56 return;
57 }
Sagar Srinivas4d99c312024-03-28 06:50:13 -050058 const std::vector<Json> emptyJsonList{};
59 auto entries = jsonData.value("entries", emptyJsonList);
60 for (const auto& entry : entries)
61 {
62 TID = entry.value("tid", 0);
63 pldm::pdr::EntityType entityType = entry.value("entityType", 0);
64 pldm::pdr::StateSetId stateSetId = entry.value("stateSetId", 0);
Chicago Duan184f6022020-04-17 11:30:49 +080065
Sagar Srinivas4d99c312024-03-28 06:50:13 -050066 bool effecterFound = getEffecterID(entityType, stateSetId);
67 if (effecterFound)
68 {
69 auto rc = getSensorInfo(entityType, stateSetId);
70 if (rc != PLDM_SUCCESS)
71 {
Riya Dixit087a7512024-04-06 14:28:08 -050072 error("Failed to get Sensor PDRs, response code '{RC}'", "RC",
Riya Dixit1e5c81e2024-05-03 07:54:00 -050073 lg2::hex, rc);
Sagar Srinivas4d99c312024-03-28 06:50:13 -050074 hasError = true;
75 return;
76 }
77 break;
78 }
79 else
80 {
81 continue;
82 }
Chicago Duan184f6022020-04-17 11:30:49 +080083 }
84
85 // Matches on the pldm StateSensorEvent signal
86 pldmEventSignal = std::make_unique<sdbusplus::bus::match_t>(
87 bus,
88 sdbusRule::type::signal() + sdbusRule::member("StateSensorEvent") +
89 sdbusRule::path("/xyz/openbmc_project/pldm") +
90 sdbusRule::interface("xyz.openbmc_project.PLDM.Event"),
91 std::bind(std::mem_fn(&SoftPowerOff::hostSoftOffComplete), this,
92 std::placeholders::_1));
93}
94
95int SoftPowerOff::getHostState()
96{
97 try
98 {
99 pldm::utils::PropertyValue propertyValue =
100 pldm::utils::DBusHandler().getDbusPropertyVariant(
101 "/xyz/openbmc_project/state/host0", "CurrentHostState",
102 "xyz.openbmc_project.State.Host");
103
Andrew Geissler5b5fa432021-01-22 16:27:24 -0600104 if ((std::get<std::string>(propertyValue) !=
105 "xyz.openbmc_project.State.Host.HostState.Running") &&
106 (std::get<std::string>(propertyValue) !=
107 "xyz.openbmc_project.State.Host.HostState.TransitioningToOff"))
Chicago Duan184f6022020-04-17 11:30:49 +0800108 {
109 // Host state is not "Running", this app should return success
110 completed = true;
111 return PLDM_SUCCESS;
112 }
113 }
114 catch (const std::exception& e)
115 {
Riya Dixit087a7512024-04-06 14:28:08 -0500116 error(
117 "PLDM remote terminus soft off. Can't get current remote terminus state, error - {ERROR}",
118 "ERROR", e);
Chicago Duan184f6022020-04-17 11:30:49 +0800119 hasError = true;
120 return PLDM_ERROR;
121 }
122
123 return PLDM_SUCCESS;
124}
125
Patrick Williams84b790c2022-07-22 19:26:56 -0500126void SoftPowerOff::hostSoftOffComplete(sdbusplus::message_t& msg)
Chicago Duan184f6022020-04-17 11:30:49 +0800127{
128 pldm::pdr::TerminusID msgTID;
129 pldm::pdr::SensorID msgSensorID;
130 pldm::pdr::SensorOffset msgSensorOffset;
131 pldm::pdr::EventState msgEventState;
132 pldm::pdr::EventState msgPreviousEventState;
133
134 // Read the msg and populate each variable
135 msg.read(msgTID, msgSensorID, msgSensorOffset, msgEventState,
136 msgPreviousEventState);
137
138 if (msgSensorID == sensorID && msgSensorOffset == sensorOffset &&
Zach Clarke98c51b2021-06-08 11:29:06 -0500139 msgEventState == PLDM_SW_TERM_GRACEFUL_SHUTDOWN && msgTID == TID)
Chicago Duan184f6022020-04-17 11:30:49 +0800140 {
141 // Receive Graceful shutdown completion event message. Disable the timer
142 auto rc = timer.stop();
143 if (rc < 0)
144 {
Riya Dixit087a7512024-04-06 14:28:08 -0500145 error(
146 "Failure to STOP the timer of PLDM soft off, response code '{RC}'",
147 "RC", rc);
Chicago Duan184f6022020-04-17 11:30:49 +0800148 }
149
150 // This marks the completion of pldm soft power off.
151 completed = true;
152 }
153}
154
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500155Json SoftPowerOff::parseConfig()
156{
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400157 fs::path softoffConfigJson(
158 fs::path(SOFTOFF_CONFIG_JSON) / "softoff_config.json");
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500159
160 if (!fs::exists(softoffConfigJson) || fs::is_empty(softoffConfigJson))
161 {
Riya Dixit087a7512024-04-06 14:28:08 -0500162 error(
163 "Failed to parse softoff config JSON file '{PATH}', file does not exist",
164 "PATH", softoffConfigJson);
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500165 return PLDM_ERROR;
166 }
167
168 std::ifstream jsonFile(softoffConfigJson);
169 return Json::parse(jsonFile);
170}
171
172bool SoftPowerOff::getEffecterID(pldm::pdr::EntityType& entityType,
173 pldm::pdr::StateSetId& stateSetId)
Chicago Duan184f6022020-04-17 11:30:49 +0800174{
175 auto& bus = pldm::utils::DBusHandler::getBus();
Chicago Duan184f6022020-04-17 11:30:49 +0800176 try
177 {
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500178 std::vector<std::vector<uint8_t>> response{};
179 auto method = bus.new_method_call(
Chicago Duan184f6022020-04-17 11:30:49 +0800180 "xyz.openbmc_project.PLDM", "/xyz/openbmc_project/pldm",
181 "xyz.openbmc_project.PLDM.PDR", "FindStateEffecterPDR");
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500182 method.append(TID, entityType, stateSetId);
183 auto responseMsg = bus.call(method, dbusTimeout);
Chicago Duan184f6022020-04-17 11:30:49 +0800184
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500185 responseMsg.read(response);
186 if (response.size())
Chicago Duan184f6022020-04-17 11:30:49 +0800187 {
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500188 for (auto& rep : response)
Chicago Duan184f6022020-04-17 11:30:49 +0800189 {
Pavithra Barithaya3c8b3e32025-01-30 10:45:51 +0530190 auto softoffPdr = new (rep.data()) pldm_state_effecter_pdr;
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500191 effecterID = softoffPdr->effecter_id;
Chicago Duan184f6022020-04-17 11:30:49 +0800192 }
193 }
194 else
195 {
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500196 return false;
Chicago Duan184f6022020-04-17 11:30:49 +0800197 }
198 }
Patrick Williams84b790c2022-07-22 19:26:56 -0500199 catch (const sdbusplus::exception_t& e)
Chicago Duan184f6022020-04-17 11:30:49 +0800200 {
Riya Dixit087a7512024-04-06 14:28:08 -0500201 error("Failed to get softPowerOff PDR, error - {ERROR}", "ERROR", e);
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500202 return false;
Chicago Duan184f6022020-04-17 11:30:49 +0800203 }
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500204 return true;
Chicago Duan184f6022020-04-17 11:30:49 +0800205}
206
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500207int SoftPowerOff::getSensorInfo(pldm::pdr::EntityType& entityType,
208 pldm::pdr::StateSetId& stateSetId)
Chicago Duan184f6022020-04-17 11:30:49 +0800209{
Chicago Duan184f6022020-04-17 11:30:49 +0800210 try
211 {
212 auto& bus = pldm::utils::DBusHandler::getBus();
213 std::vector<std::vector<uint8_t>> Response{};
214 auto method = bus.new_method_call(
215 "xyz.openbmc_project.PLDM", "/xyz/openbmc_project/pldm",
216 "xyz.openbmc_project.PLDM.PDR", "FindStateSensorPDR");
Sagar Srinivas4d99c312024-03-28 06:50:13 -0500217 method.append(TID, entityType, stateSetId);
Chicago Duan184f6022020-04-17 11:30:49 +0800218
vkaverap@in.ibm.com91a092f2023-09-18 23:39:44 -0500219 auto ResponseMsg = bus.call(method, dbusTimeout);
Chicago Duan184f6022020-04-17 11:30:49 +0800220
221 ResponseMsg.read(Response);
222
223 if (Response.size() == 0)
224 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600225 error("No sensor PDR has been found that matches the criteria");
Chicago Duan184f6022020-04-17 11:30:49 +0800226 return PLDM_ERROR;
227 }
228
ThuBaNguyen499a29d2023-05-30 06:32:06 +0700229 pldm_state_sensor_pdr* pdr = nullptr;
Chicago Duan184f6022020-04-17 11:30:49 +0800230 for (auto& rep : Response)
231 {
Pavithra Barithaya3c8b3e32025-01-30 10:45:51 +0530232 pdr = new (rep.data()) pldm_state_sensor_pdr;
Manojkiran Eda31a78442021-09-12 15:18:25 +0530233 if (!pdr)
234 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600235 error("Failed to get state sensor PDR.");
Manojkiran Eda31a78442021-09-12 15:18:25 +0530236 return PLDM_ERROR;
237 }
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530238 }
239
Chicago Duan184f6022020-04-17 11:30:49 +0800240 sensorID = pdr->sensor_id;
241
242 auto compositeSensorCount = pdr->composite_sensor_count;
243 auto possibleStatesStart = pdr->possible_states;
244
245 for (auto offset = 0; offset < compositeSensorCount; offset++)
246 {
Pavithra Barithaya3c8b3e32025-01-30 10:45:51 +0530247 auto possibleStates = new (possibleStatesStart)
248 state_sensor_possible_states;
Chicago Duan184f6022020-04-17 11:30:49 +0800249 auto setId = possibleStates->state_set_id;
250 auto possibleStateSize = possibleStates->possible_states_size;
251
252 if (setId == PLDM_STATE_SET_SW_TERMINATION_STATUS)
253 {
254 sensorOffset = offset;
255 break;
256 }
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400257 possibleStatesStart +=
258 possibleStateSize + sizeof(setId) + sizeof(possibleStateSize);
Chicago Duan184f6022020-04-17 11:30:49 +0800259 }
260 }
Patrick Williams84b790c2022-07-22 19:26:56 -0500261 catch (const sdbusplus::exception_t& e)
Chicago Duan184f6022020-04-17 11:30:49 +0800262 {
Riya Dixit087a7512024-04-06 14:28:08 -0500263 error("Failed to get state sensor PDR during soft-off, error - {ERROR}",
264 "ERROR", e);
Chicago Duan184f6022020-04-17 11:30:49 +0800265 return PLDM_ERROR;
266 }
267
268 return PLDM_SUCCESS;
269}
270
271int SoftPowerOff::hostSoftOff(sdeventplus::Event& event)
272{
273 constexpr uint8_t effecterCount = 1;
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000274 PldmTransport pldmTransport{};
ManojKiran Eda22bcb072025-07-11 23:49:43 +0000275 uint8_t instanceID;
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000276 uint8_t mctpEID;
Chicago Duan184f6022020-04-17 11:30:49 +0800277
278 mctpEID = pldm::utils::readHostEID();
Dung Cao3d03f3f2023-09-07 06:51:33 +0000279 // TODO: fix mapping to work around OpenBMC ecosystem deficiencies
280 pldm_tid_t pldmTID = static_cast<pldm_tid_t>(mctpEID);
Chicago Duan184f6022020-04-17 11:30:49 +0800281
Archana Kakani50554252025-03-17 01:37:29 -0500282 uint8_t effecterState;
283 auto requestHostTransition =
284 pldm::utils::DBusHandler().getDbusProperty<std::string>(
285 "/xyz/openbmc_project/state/host0", "RequestedHostTransition",
286 sdbusplus::common::xyz::openbmc_project::state::Host::interface);
287 if (requestHostTransition !=
288 "xyz.openbmc_project.State.Host.Transition.Off")
289 {
290 effecterState = PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED;
291 }
292 else
293 {
294 effecterState = PLDM_SW_TERM_GRACEFUL_SHUTDOWN_REQUESTED;
295 }
296
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400297 std::array<uint8_t,
298 sizeof(pldm_msg_hdr) + sizeof(effecterID) +
299 sizeof(effecterCount) + sizeof(set_effecter_state_field)>
Chicago Duan184f6022020-04-17 11:30:49 +0800300 requestMsg{};
Pavithra Barithaya3c8b3e32025-01-30 10:45:51 +0530301 auto request = new (requestMsg.data()) pldm_msg;
Archana Kakani50554252025-03-17 01:37:29 -0500302 set_effecter_state_field stateField{PLDM_REQUEST_SET, effecterState};
ManojKiran Eda22bcb072025-07-11 23:49:43 +0000303 instanceID = instanceIdDb.next(pldmTID);
Chicago Duan184f6022020-04-17 11:30:49 +0800304 auto rc = encode_set_state_effecter_states_req(
305 instanceID, effecterID, effecterCount, &stateField, request);
306 if (rc != PLDM_SUCCESS)
307 {
Dung Cao3d03f3f2023-09-07 06:51:33 +0000308 instanceIdDb.free(pldmTID, instanceID);
Riya Dixit087a7512024-04-06 14:28:08 -0500309 error(
310 "Failed to encode set state effecter states request message, response code '{RC}'",
Riya Dixit1e5c81e2024-05-03 07:54:00 -0500311 "RC", lg2::hex, rc);
Chicago Duan184f6022020-04-17 11:30:49 +0800312 return PLDM_ERROR;
313 }
314
Chicago Duan184f6022020-04-17 11:30:49 +0800315 // Add a timer to the event loop, default 30s.
Patrick Williamsa6756622023-10-20 11:19:15 -0500316 auto timerCallback = [=, this](Timer& /*source*/,
317 Timer::TimePoint /*time*/) mutable {
Chicago Duan184f6022020-04-17 11:30:49 +0800318 if (!responseReceived)
319 {
Dung Cao3d03f3f2023-09-07 06:51:33 +0000320 instanceIdDb.free(pldmTID, instanceID);
Riya Dixit49cfb132023-03-02 04:26:53 -0600321 error(
Riya Dixit087a7512024-04-06 14:28:08 -0500322 "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 +0800323 exit(-1);
324 }
325 return;
326 };
327 Timer time(event, (Clock(event).now() + std::chrono::seconds{30}),
328 std::chrono::seconds{1}, std::move(timerCallback));
329
330 // Add a callback to handle EPOLLIN on fd
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400331 auto callback = [=, &pldmTransport,
332 this](IO& io, int fd, uint32_t revents) mutable {
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000333 if (fd != pldmTransport.getEventSource())
334 {
335 return;
336 }
337
Chicago Duan184f6022020-04-17 11:30:49 +0800338 if (!(revents & EPOLLIN))
339 {
340 return;
341 }
342
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000343 void* responseMsg = nullptr;
Chicago Duan184f6022020-04-17 11:30:49 +0800344 size_t responseMsgSize{};
Dung Cao3d03f3f2023-09-07 06:51:33 +0000345 pldm_tid_t srcTID = pldmTID;
Chicago Duan184f6022020-04-17 11:30:49 +0800346
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000347 auto rc = pldmTransport.recvMsg(pldmTID, responseMsg, responseMsgSize);
Chicago Duan184f6022020-04-17 11:30:49 +0800348 if (rc)
349 {
Riya Dixit087a7512024-04-06 14:28:08 -0500350 error(
351 "Failed to receive pldm data during soft-off, response code '{RC}'",
Riya Dixit1e5c81e2024-05-03 07:54:00 -0500352 "RC", rc);
Chicago Duan184f6022020-04-17 11:30:49 +0800353 return;
354 }
355
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400356 std::unique_ptr<void, decltype(std::free)*> responseMsgPtr{
357 responseMsg, std::free};
Chicago Duan184f6022020-04-17 11:30:49 +0800358
359 // We've got the response meant for the PLDM request msg that was
360 // sent out
361 io.set_enabled(Enabled::Off);
Pavithra Barithaya3c8b3e32025-01-30 10:45:51 +0530362 auto response = new (responseMsgPtr.get()) pldm_msg;
Dung Cao3d03f3f2023-09-07 06:51:33 +0000363
364 if (srcTID != pldmTID ||
365 !pldm_msg_hdr_correlate_response(&request->hdr, &response->hdr))
366 {
367 /* This isn't the response we were looking for */
368 return;
369 }
370
371 /* We have the right response, release the instance ID and process */
372 io.set_enabled(Enabled::Off);
373 instanceIdDb.free(pldmTID, instanceID);
374
George Liu9915d022021-12-21 14:04:31 +0800375 if (response->payload[0] != PLDM_SUCCESS)
376 {
Riya Dixit087a7512024-04-06 14:28:08 -0500377 error("Getting the wrong response, response code '{RC}'", "RC",
Riya Dixit1e5c81e2024-05-03 07:54:00 -0500378 response->payload[0]);
George Liu9915d022021-12-21 14:04:31 +0800379 exit(-1);
380 }
Chicago Duan184f6022020-04-17 11:30:49 +0800381
382 responseReceived = true;
383
384 // Start Timer
385 using namespace std::chrono;
386 auto timeMicroseconds =
387 duration_cast<microseconds>(seconds(SOFTOFF_TIMEOUT_SECONDS));
388
389 auto ret = startTimer(timeMicroseconds);
390 if (ret < 0)
391 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600392 error(
Riya Dixit087a7512024-04-06 14:28:08 -0500393 "Failure to start remote terminus soft off wait timer, Exit the pldm-softpoweroff with response code:{NUM}",
394 "NUM", ret);
Chicago Duan184f6022020-04-17 11:30:49 +0800395 exit(-1);
396 }
397 else
398 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600399 error(
Riya Dixit087a7512024-04-06 14:28:08 -0500400 "Timer started waiting for remote terminus soft off, timeout in sec '{TIMEOUT_SEC}'",
Riya Dixit49cfb132023-03-02 04:26:53 -0600401 "TIMEOUT_SEC", SOFTOFF_TIMEOUT_SECONDS);
Chicago Duan184f6022020-04-17 11:30:49 +0800402 }
403 return;
404 };
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000405 IO io(event, pldmTransport.getEventSource(), EPOLLIN, std::move(callback));
Chicago Duan184f6022020-04-17 11:30:49 +0800406
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000407 // Asynchronously send the PLDM request
408 rc = pldmTransport.sendMsg(pldmTID, requestMsg.data(), requestMsg.size());
Sampa Misra9f8d2b02021-03-24 08:33:14 +0000409 if (0 > rc)
Chicago Duan184f6022020-04-17 11:30:49 +0800410 {
Dung Cao3d03f3f2023-09-07 06:51:33 +0000411 instanceIdDb.free(pldmTID, instanceID);
Riya Dixit49cfb132023-03-02 04:26:53 -0600412 error(
Riya Dixit087a7512024-04-06 14:28:08 -0500413 "Failed to send message/receive response, response code '{RC}' and error - {ERROR}",
Riya Dixit1e5c81e2024-05-03 07:54:00 -0500414 "RC", rc, "ERROR", errno);
Chicago Duan184f6022020-04-17 11:30:49 +0800415 return PLDM_ERROR;
416 }
417
418 // Time out or soft off complete
419 while (!isCompleted() && !isTimerExpired())
420 {
421 try
422 {
423 event.run(std::nullopt);
424 }
425 catch (const sdeventplus::SdEventError& e)
426 {
Dung Cao3d03f3f2023-09-07 06:51:33 +0000427 instanceIdDb.free(pldmTID, instanceID);
Riya Dixit49cfb132023-03-02 04:26:53 -0600428 error(
Riya Dixit087a7512024-04-06 14:28:08 -0500429 "Failed to process request while remote terminus soft off, error - {ERROR}",
430 "ERROR", e);
Chicago Duan184f6022020-04-17 11:30:49 +0800431 return PLDM_ERROR;
432 }
433 }
434
435 return PLDM_SUCCESS;
436}
437
438int SoftPowerOff::startTimer(const std::chrono::microseconds& usec)
439{
440 return timer.start(usec);
441}
442} // namespace pldm