blob: 0025d5969a7967bab6d5979208c81f9dbd3de6f5 [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 Venture09334bb2020-08-16 12:22:54 -070042ipmi_ret_t ZoneControlIpmiHandler::getFailsafeModeState(const uint8_t* reqBuf,
43 uint8_t* replyBuf,
44 size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -080045{
Patrick Venture391b8b02018-03-08 08:31:13 -080046 bool current;
47
48 if (*dataLen < sizeof(struct FanCtrlRequest))
49 {
50 return IPMI_CC_INVALID;
51 }
52
53 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070054 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -080055
Patrick Williams8c051122023-05-10 07:50:59 -050056 ipmi_ret_t rc = _control->getFanCtrlProperty(request->zone, &current,
57 failsafeProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -080058 if (rc)
59 {
60 return rc;
61 }
62
63 *replyBuf = (uint8_t)current;
64 *dataLen = sizeof(uint8_t);
Patrick Venture37b247a2020-08-03 11:15:21 -070065 return IPMI_CC_OK;
Patrick Venture391b8b02018-03-08 08:31:13 -080066}
67
68/*
69 * <method name="GetAll">
70 * <arg name="interface" direction="in" type="s"/>
71 * <arg name="properties" direction="out" type="a{sv}"/>
72 * </method>
73 */
Patrick Venture09334bb2020-08-16 12:22:54 -070074ipmi_ret_t ZoneControlIpmiHandler::getManualModeState(const uint8_t* reqBuf,
75 uint8_t* replyBuf,
76 size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -080077{
Patrick Venture391b8b02018-03-08 08:31:13 -080078 bool current;
79
80 if (*dataLen < sizeof(struct FanCtrlRequest))
81 {
82 return IPMI_CC_INVALID;
83 }
84
85 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070086 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -080087
Patrick Williams8c051122023-05-10 07:50:59 -050088 ipmi_ret_t rc = _control->getFanCtrlProperty(request->zone, &current,
89 manualProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -080090 if (rc)
91 {
92 return rc;
93 }
94
95 *replyBuf = (uint8_t)current;
96 *dataLen = sizeof(uint8_t);
Patrick Venture37b247a2020-08-03 11:15:21 -070097 return IPMI_CC_OK;
Patrick Venture391b8b02018-03-08 08:31:13 -080098}
99
100/*
101 * <method name="Set">
102 * <arg name="interface" direction="in" type="s"/>
103 * <arg name="property" direction="in" type="s"/>
104 * <arg name="value" direction="in" type="v"/>
105 * </method>
106 */
Harvey.Wua1ae4fa2022-10-28 17:38:35 +0800107ipmi_ret_t ZoneControlIpmiHandler::setManualModeState(
Harvey Wu22579ca2022-11-07 14:53:37 +0800108 const uint8_t* reqBuf, [[maybe_unused]] uint8_t* replyBuf,
109 const size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -0800110{
Patrick Venture391b8b02018-03-08 08:31:13 -0800111 if (*dataLen < sizeof(struct FanCtrlRequestSet))
112 {
113 return IPMI_CC_INVALID;
114 }
115
Patrick Venture391b8b02018-03-08 08:31:13 -0800116 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700117 reinterpret_cast<const struct FanCtrlRequestSet*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -0800118
119 /* 0 is false, 1 is true */
Patrick Venture09334bb2020-08-16 12:22:54 -0700120 ipmi_ret_t rc = _control->setFanCtrlProperty(
121 request->zone, static_cast<bool>(request->value), manualProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -0800122 return rc;
123}
124
125/* Three command packages: get, set true, set false */
Harvey.Wua1ae4fa2022-10-28 17:38:35 +0800126ipmi_ret_t manualModeControl(ZoneControlIpmiHandler* handler,
127 [[maybe_unused]] ipmi_cmd_t cmd,
Patrick Venture09334bb2020-08-16 12:22:54 -0700128 const uint8_t* reqBuf, uint8_t* replyCmdBuf,
129 size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -0800130{
Patrick Venture391b8b02018-03-08 08:31:13 -0800131 // FanCtrlRequest is the smaller of the requests, so it's at a minimum.
132 if (*dataLen < sizeof(struct FanCtrlRequest))
133 {
134 return IPMI_CC_INVALID;
135 }
136
137 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700138 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -0800139
Patrick Venture37b247a2020-08-03 11:15:21 -0700140 ipmi_ret_t rc = IPMI_CC_OK;
141
Patrick Venture391b8b02018-03-08 08:31:13 -0800142 switch (request->command)
143 {
Patrick Venture12775432020-08-04 09:57:36 -0700144 case getControlState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700145 return handler->getManualModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture12775432020-08-04 09:57:36 -0700146 case setControlState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700147 return handler->setManualModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture12775432020-08-04 09:57:36 -0700148 case getFailsafeState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700149 return handler->getFailsafeModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture391b8b02018-03-08 08:31:13 -0800150 default:
151 rc = IPMI_CC_INVALID;
152 }
153
154 return rc;
155}
156
Patrick Venture36ab6f62020-08-03 10:50:26 -0700157} // namespace ipmi
158} // namespace pid_control