blob: aa9a213c738b2e9b740a4a7701e520dd7bdbf336 [file] [log] [blame]
Alexander Hansen46a755f2025-10-27 16:31:08 +01001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright 2017 Google Inc
Patrick Venture391b8b02018-03-08 08:31:13 -08003
Patrick Venture36ab6f62020-08-03 10:50:26 -07004#include "manualcmds.hpp"
5
Patrick Venture09334bb2020-08-16 12:22:54 -07006#include "control.hpp"
Patrick Venture9bf5cef2020-08-16 08:59:54 -07007#include "manual_messages.hpp"
8
George Liu92110f82025-07-02 15:07:35 +08009#include <ipmid/api-types.hpp>
Patrick Venture391b8b02018-03-08 08:31:13 -080010
Ed Tanousf8b6e552025-06-27 13:27:50 -070011#include <cstddef>
12#include <cstdint>
Patrick Venture09334bb2020-08-16 12:22:54 -070013#include <memory>
Patrick Venture391b8b02018-03-08 08:31:13 -080014#include <string>
Patrick Venture391b8b02018-03-08 08:31:13 -080015
George Liu92110f82025-07-02 15:07:35 +080016namespace pid_control::ipmi
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070017{
Patrick Venture391b8b02018-03-08 08:31:13 -080018
Patrick Venture391b8b02018-03-08 08:31:13 -080019static constexpr auto manualProperty = "Manual";
20static constexpr auto failsafeProperty = "FailSafe";
Patrick Venture391b8b02018-03-08 08:31:13 -080021
George Liu92110f82025-07-02 15:07:35 +080022::ipmi::Cc ZoneControlIpmiHandler::getFailsafeModeState(
Patrick Williamsbd63bca2024-08-16 15:21:10 -040023 const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -080024{
Patrick Venture391b8b02018-03-08 08:31:13 -080025 bool current;
26
27 if (*dataLen < sizeof(struct FanCtrlRequest))
28 {
George Liu92110f82025-07-02 15:07:35 +080029 return ::ipmi::ccInvalidCommand;
Patrick Venture391b8b02018-03-08 08:31:13 -080030 }
31
32 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070033 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -080034
George Liu92110f82025-07-02 15:07:35 +080035 ::ipmi::Cc rc =
Patrick Williamsbd63bca2024-08-16 15:21:10 -040036 _control->getFanCtrlProperty(request->zone, &current, failsafeProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -080037 if (rc)
38 {
39 return rc;
40 }
41
42 *replyBuf = (uint8_t)current;
43 *dataLen = sizeof(uint8_t);
George Liu92110f82025-07-02 15:07:35 +080044 return ::ipmi::ccSuccess;
Patrick Venture391b8b02018-03-08 08:31:13 -080045}
46
47/*
48 * <method name="GetAll">
49 * <arg name="interface" direction="in" type="s"/>
50 * <arg name="properties" direction="out" type="a{sv}"/>
51 * </method>
52 */
George Liu92110f82025-07-02 15:07:35 +080053::ipmi::Cc ZoneControlIpmiHandler::getManualModeState(
Patrick Williamsbd63bca2024-08-16 15:21:10 -040054 const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -080055{
Patrick Venture391b8b02018-03-08 08:31:13 -080056 bool current;
57
58 if (*dataLen < sizeof(struct FanCtrlRequest))
59 {
George Liu92110f82025-07-02 15:07:35 +080060 return ::ipmi::ccInvalidCommand;
Patrick Venture391b8b02018-03-08 08:31:13 -080061 }
62
63 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070064 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -080065
George Liu92110f82025-07-02 15:07:35 +080066 ::ipmi::Cc rc =
Patrick Williamsbd63bca2024-08-16 15:21:10 -040067 _control->getFanCtrlProperty(request->zone, &current, manualProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -080068 if (rc)
69 {
70 return rc;
71 }
72
73 *replyBuf = (uint8_t)current;
74 *dataLen = sizeof(uint8_t);
George Liu92110f82025-07-02 15:07:35 +080075 return ::ipmi::ccSuccess;
Patrick Venture391b8b02018-03-08 08:31:13 -080076}
77
78/*
79 * <method name="Set">
80 * <arg name="interface" direction="in" type="s"/>
81 * <arg name="property" direction="in" type="s"/>
82 * <arg name="value" direction="in" type="v"/>
83 * </method>
84 */
George Liu92110f82025-07-02 15:07:35 +080085::ipmi::Cc ZoneControlIpmiHandler::setManualModeState(
Harvey Wu22579ca2022-11-07 14:53:37 +080086 const uint8_t* reqBuf, [[maybe_unused]] uint8_t* replyBuf,
87 const size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -080088{
Patrick Venture391b8b02018-03-08 08:31:13 -080089 if (*dataLen < sizeof(struct FanCtrlRequestSet))
90 {
George Liu92110f82025-07-02 15:07:35 +080091 return ::ipmi::ccInvalidCommand;
Patrick Venture391b8b02018-03-08 08:31:13 -080092 }
93
Patrick Venture391b8b02018-03-08 08:31:13 -080094 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070095 reinterpret_cast<const struct FanCtrlRequestSet*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -080096
97 /* 0 is false, 1 is true */
George Liu92110f82025-07-02 15:07:35 +080098 ::ipmi::Cc rc = _control->setFanCtrlProperty(
Patrick Venture09334bb2020-08-16 12:22:54 -070099 request->zone, static_cast<bool>(request->value), manualProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -0800100 return rc;
101}
102
103/* Three command packages: get, set true, set false */
George Liu92110f82025-07-02 15:07:35 +0800104::ipmi::Cc manualModeControl(
105 ZoneControlIpmiHandler* handler, [[maybe_unused]] uint8_t cmd,
Patrick Williamsbd63bca2024-08-16 15:21:10 -0400106 const uint8_t* reqBuf, uint8_t* replyCmdBuf, size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -0800107{
Patrick Venture391b8b02018-03-08 08:31:13 -0800108 // FanCtrlRequest is the smaller of the requests, so it's at a minimum.
109 if (*dataLen < sizeof(struct FanCtrlRequest))
110 {
George Liu92110f82025-07-02 15:07:35 +0800111 return ::ipmi::ccInvalidCommand;
Patrick Venture391b8b02018-03-08 08:31:13 -0800112 }
113
114 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700115 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -0800116
George Liu92110f82025-07-02 15:07:35 +0800117 ::ipmi::Cc rc = ::ipmi::ccSuccess;
Patrick Venture37b247a2020-08-03 11:15:21 -0700118
Patrick Venture391b8b02018-03-08 08:31:13 -0800119 switch (request->command)
120 {
Patrick Venture12775432020-08-04 09:57:36 -0700121 case getControlState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700122 return handler->getManualModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture12775432020-08-04 09:57:36 -0700123 case setControlState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700124 return handler->setManualModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture12775432020-08-04 09:57:36 -0700125 case getFailsafeState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700126 return handler->getFailsafeModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture391b8b02018-03-08 08:31:13 -0800127 default:
George Liu92110f82025-07-02 15:07:35 +0800128 rc = ::ipmi::ccInvalidCommand;
Patrick Venture391b8b02018-03-08 08:31:13 -0800129 }
130
131 return rc;
132}
133
George Liu92110f82025-07-02 15:07:35 +0800134} // namespace pid_control::ipmi