blob: 69817b2151d109b74eabab6ea56e24192f8b84f2 [file] [log] [blame]
Patrick Venture391b8b02018-03-08 08:31:13 -08001/**
2 * Copyright 2017 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Patrick Venture36ab6f62020-08-03 10:50:26 -070017#include "manualcmds.hpp"
18
Patrick Venture09334bb2020-08-16 12:22:54 -070019#include "control.hpp"
Patrick Venture9bf5cef2020-08-16 08:59:54 -070020#include "manual_messages.hpp"
21
William A. Kennington III331143c2019-02-07 15:52:44 -080022#include <ipmid/api.h>
Patrick Venture391b8b02018-03-08 08:31:13 -080023
Ed Tanousf8b6e552025-06-27 13:27:50 -070024#include <cstddef>
25#include <cstdint>
Patrick Venture09334bb2020-08-16 12:22:54 -070026#include <memory>
Patrick Venture391b8b02018-03-08 08:31:13 -080027#include <string>
Patrick Venture391b8b02018-03-08 08:31:13 -080028
Patrick Venture36ab6f62020-08-03 10:50:26 -070029namespace pid_control
Patrick Venture391b8b02018-03-08 08:31:13 -080030{
Patrick Venture36ab6f62020-08-03 10:50:26 -070031namespace ipmi
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070032{
Patrick Venture391b8b02018-03-08 08:31:13 -080033
Patrick Venture391b8b02018-03-08 08:31:13 -080034static constexpr auto manualProperty = "Manual";
35static constexpr auto failsafeProperty = "FailSafe";
Patrick Venture391b8b02018-03-08 08:31:13 -080036
Patrick Williamsbd63bca2024-08-16 15:21:10 -040037ipmi_ret_t ZoneControlIpmiHandler::getFailsafeModeState(
38 const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -080039{
Patrick Venture391b8b02018-03-08 08:31:13 -080040 bool current;
41
42 if (*dataLen < sizeof(struct FanCtrlRequest))
43 {
44 return IPMI_CC_INVALID;
45 }
46
47 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070048 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -080049
Patrick Williamsbd63bca2024-08-16 15:21:10 -040050 ipmi_ret_t rc =
51 _control->getFanCtrlProperty(request->zone, &current, failsafeProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -080052 if (rc)
53 {
54 return rc;
55 }
56
57 *replyBuf = (uint8_t)current;
58 *dataLen = sizeof(uint8_t);
Patrick Venture37b247a2020-08-03 11:15:21 -070059 return IPMI_CC_OK;
Patrick Venture391b8b02018-03-08 08:31:13 -080060}
61
62/*
63 * <method name="GetAll">
64 * <arg name="interface" direction="in" type="s"/>
65 * <arg name="properties" direction="out" type="a{sv}"/>
66 * </method>
67 */
Patrick Williamsbd63bca2024-08-16 15:21:10 -040068ipmi_ret_t ZoneControlIpmiHandler::getManualModeState(
69 const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -080070{
Patrick Venture391b8b02018-03-08 08:31:13 -080071 bool current;
72
73 if (*dataLen < sizeof(struct FanCtrlRequest))
74 {
75 return IPMI_CC_INVALID;
76 }
77
78 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070079 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -080080
Patrick Williamsbd63bca2024-08-16 15:21:10 -040081 ipmi_ret_t rc =
82 _control->getFanCtrlProperty(request->zone, &current, manualProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -080083 if (rc)
84 {
85 return rc;
86 }
87
88 *replyBuf = (uint8_t)current;
89 *dataLen = sizeof(uint8_t);
Patrick Venture37b247a2020-08-03 11:15:21 -070090 return IPMI_CC_OK;
Patrick Venture391b8b02018-03-08 08:31:13 -080091}
92
93/*
94 * <method name="Set">
95 * <arg name="interface" direction="in" type="s"/>
96 * <arg name="property" direction="in" type="s"/>
97 * <arg name="value" direction="in" type="v"/>
98 * </method>
99 */
Harvey.Wua1ae4fa2022-10-28 17:38:35 +0800100ipmi_ret_t ZoneControlIpmiHandler::setManualModeState(
Harvey Wu22579ca2022-11-07 14:53:37 +0800101 const uint8_t* reqBuf, [[maybe_unused]] uint8_t* replyBuf,
102 const size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -0800103{
Patrick Venture391b8b02018-03-08 08:31:13 -0800104 if (*dataLen < sizeof(struct FanCtrlRequestSet))
105 {
106 return IPMI_CC_INVALID;
107 }
108
Patrick Venture391b8b02018-03-08 08:31:13 -0800109 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700110 reinterpret_cast<const struct FanCtrlRequestSet*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -0800111
112 /* 0 is false, 1 is true */
Patrick Venture09334bb2020-08-16 12:22:54 -0700113 ipmi_ret_t rc = _control->setFanCtrlProperty(
114 request->zone, static_cast<bool>(request->value), manualProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -0800115 return rc;
116}
117
118/* Three command packages: get, set true, set false */
Patrick Williamsbd63bca2024-08-16 15:21:10 -0400119ipmi_ret_t manualModeControl(
120 ZoneControlIpmiHandler* handler, [[maybe_unused]] ipmi_cmd_t cmd,
121 const uint8_t* reqBuf, uint8_t* replyCmdBuf, size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -0800122{
Patrick Venture391b8b02018-03-08 08:31:13 -0800123 // FanCtrlRequest is the smaller of the requests, so it's at a minimum.
124 if (*dataLen < sizeof(struct FanCtrlRequest))
125 {
126 return IPMI_CC_INVALID;
127 }
128
129 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700130 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -0800131
Patrick Venture37b247a2020-08-03 11:15:21 -0700132 ipmi_ret_t rc = IPMI_CC_OK;
133
Patrick Venture391b8b02018-03-08 08:31:13 -0800134 switch (request->command)
135 {
Patrick Venture12775432020-08-04 09:57:36 -0700136 case getControlState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700137 return handler->getManualModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture12775432020-08-04 09:57:36 -0700138 case setControlState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700139 return handler->setManualModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture12775432020-08-04 09:57:36 -0700140 case getFailsafeState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700141 return handler->getFailsafeModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture391b8b02018-03-08 08:31:13 -0800142 default:
143 rc = IPMI_CC_INVALID;
144 }
145
146 return rc;
147}
148
Patrick Venture36ab6f62020-08-03 10:50:26 -0700149} // namespace ipmi
150} // namespace pid_control