blob: d9c9c49de46ca77251640fcec02d504998a05792 [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 Ventured82d0b72020-08-16 09:17:37 -070020#include "dbus_mode.hpp"
Patrick Venture9bf5cef2020-08-16 08:59:54 -070021#include "manual_messages.hpp"
22
William A. Kennington III331143c2019-02-07 15:52:44 -080023#include <ipmid/api.h>
Patrick Venture391b8b02018-03-08 08:31:13 -080024
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070025#include <sdbusplus/bus.hpp>
26#include <sdbusplus/message.hpp>
Patrick Venturea83a3ec2020-08-04 09:52:05 -070027
28#include <map>
Patrick Venture09334bb2020-08-16 12:22:54 -070029#include <memory>
Patrick Venture391b8b02018-03-08 08:31:13 -080030#include <string>
31#include <tuple>
James Feist1f802f52019-02-08 13:51:43 -080032#include <variant>
Patrick Venture391b8b02018-03-08 08:31:13 -080033
Patrick Venture36ab6f62020-08-03 10:50:26 -070034namespace pid_control
Patrick Venture391b8b02018-03-08 08:31:13 -080035{
Patrick Venture36ab6f62020-08-03 10:50:26 -070036namespace ipmi
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070037{
Patrick Venture391b8b02018-03-08 08:31:13 -080038
Patrick Venture391b8b02018-03-08 08:31:13 -080039static constexpr auto manualProperty = "Manual";
40static constexpr auto failsafeProperty = "FailSafe";
Patrick Venture391b8b02018-03-08 08:31:13 -080041
Patrick Williamsbd63bca2024-08-16 15:21:10 -040042ipmi_ret_t ZoneControlIpmiHandler::getFailsafeModeState(
43 const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -080044{
Patrick Venture391b8b02018-03-08 08:31:13 -080045 bool current;
46
47 if (*dataLen < sizeof(struct FanCtrlRequest))
48 {
49 return IPMI_CC_INVALID;
50 }
51
52 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070053 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -080054
Patrick Williamsbd63bca2024-08-16 15:21:10 -040055 ipmi_ret_t rc =
56 _control->getFanCtrlProperty(request->zone, &current, failsafeProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -080057 if (rc)
58 {
59 return rc;
60 }
61
62 *replyBuf = (uint8_t)current;
63 *dataLen = sizeof(uint8_t);
Patrick Venture37b247a2020-08-03 11:15:21 -070064 return IPMI_CC_OK;
Patrick Venture391b8b02018-03-08 08:31:13 -080065}
66
67/*
68 * <method name="GetAll">
69 * <arg name="interface" direction="in" type="s"/>
70 * <arg name="properties" direction="out" type="a{sv}"/>
71 * </method>
72 */
Patrick Williamsbd63bca2024-08-16 15:21:10 -040073ipmi_ret_t ZoneControlIpmiHandler::getManualModeState(
74 const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -080075{
Patrick Venture391b8b02018-03-08 08:31:13 -080076 bool current;
77
78 if (*dataLen < sizeof(struct FanCtrlRequest))
79 {
80 return IPMI_CC_INVALID;
81 }
82
83 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070084 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -080085
Patrick Williamsbd63bca2024-08-16 15:21:10 -040086 ipmi_ret_t rc =
87 _control->getFanCtrlProperty(request->zone, &current, manualProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -080088 if (rc)
89 {
90 return rc;
91 }
92
93 *replyBuf = (uint8_t)current;
94 *dataLen = sizeof(uint8_t);
Patrick Venture37b247a2020-08-03 11:15:21 -070095 return IPMI_CC_OK;
Patrick Venture391b8b02018-03-08 08:31:13 -080096}
97
98/*
99 * <method name="Set">
100 * <arg name="interface" direction="in" type="s"/>
101 * <arg name="property" direction="in" type="s"/>
102 * <arg name="value" direction="in" type="v"/>
103 * </method>
104 */
Harvey.Wua1ae4fa2022-10-28 17:38:35 +0800105ipmi_ret_t ZoneControlIpmiHandler::setManualModeState(
Harvey Wu22579ca2022-11-07 14:53:37 +0800106 const uint8_t* reqBuf, [[maybe_unused]] uint8_t* replyBuf,
107 const size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -0800108{
Patrick Venture391b8b02018-03-08 08:31:13 -0800109 if (*dataLen < sizeof(struct FanCtrlRequestSet))
110 {
111 return IPMI_CC_INVALID;
112 }
113
Patrick Venture391b8b02018-03-08 08:31:13 -0800114 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700115 reinterpret_cast<const struct FanCtrlRequestSet*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -0800116
117 /* 0 is false, 1 is true */
Patrick Venture09334bb2020-08-16 12:22:54 -0700118 ipmi_ret_t rc = _control->setFanCtrlProperty(
119 request->zone, static_cast<bool>(request->value), manualProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -0800120 return rc;
121}
122
123/* Three command packages: get, set true, set false */
Patrick Williamsbd63bca2024-08-16 15:21:10 -0400124ipmi_ret_t manualModeControl(
125 ZoneControlIpmiHandler* handler, [[maybe_unused]] ipmi_cmd_t cmd,
126 const uint8_t* reqBuf, uint8_t* replyCmdBuf, size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -0800127{
Patrick Venture391b8b02018-03-08 08:31:13 -0800128 // FanCtrlRequest is the smaller of the requests, so it's at a minimum.
129 if (*dataLen < sizeof(struct FanCtrlRequest))
130 {
131 return IPMI_CC_INVALID;
132 }
133
134 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700135 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -0800136
Patrick Venture37b247a2020-08-03 11:15:21 -0700137 ipmi_ret_t rc = IPMI_CC_OK;
138
Patrick Venture391b8b02018-03-08 08:31:13 -0800139 switch (request->command)
140 {
Patrick Venture12775432020-08-04 09:57:36 -0700141 case getControlState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700142 return handler->getManualModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture12775432020-08-04 09:57:36 -0700143 case setControlState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700144 return handler->setManualModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture12775432020-08-04 09:57:36 -0700145 case getFailsafeState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700146 return handler->getFailsafeModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture391b8b02018-03-08 08:31:13 -0800147 default:
148 rc = IPMI_CC_INVALID;
149 }
150
151 return rc;
152}
153
Patrick Venture36ab6f62020-08-03 10:50:26 -0700154} // namespace ipmi
155} // namespace pid_control