xref: /openbmc/phosphor-pid-control/ipmi/manualcmds.cpp (revision bd63bcaca2ac9edf1778136cf240e3bbe8b31566)
1391b8b0fSPatrick Venture /**
2391b8b0fSPatrick Venture  * Copyright 2017 Google Inc.
3391b8b0fSPatrick Venture  *
4391b8b0fSPatrick Venture  * Licensed under the Apache License, Version 2.0 (the "License");
5391b8b0fSPatrick Venture  * you may not use this file except in compliance with the License.
6391b8b0fSPatrick Venture  * You may obtain a copy of the License at
7391b8b0fSPatrick Venture  *
8391b8b0fSPatrick Venture  *     http://www.apache.org/licenses/LICENSE-2.0
9391b8b0fSPatrick Venture  *
10391b8b0fSPatrick Venture  * Unless required by applicable law or agreed to in writing, software
11391b8b0fSPatrick Venture  * distributed under the License is distributed on an "AS IS" BASIS,
12391b8b0fSPatrick Venture  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13391b8b0fSPatrick Venture  * See the License for the specific language governing permissions and
14391b8b0fSPatrick Venture  * limitations under the License.
15391b8b0fSPatrick Venture  */
16391b8b0fSPatrick Venture 
1736ab6f6eSPatrick Venture #include "manualcmds.hpp"
1836ab6f6eSPatrick Venture 
1909334bbeSPatrick Venture #include "control.hpp"
20d82d0b7dSPatrick Venture #include "dbus_mode.hpp"
219bf5cef4SPatrick Venture #include "manual_messages.hpp"
229bf5cef4SPatrick Venture 
23331143ceSWilliam A. Kennington III #include <ipmid/api.h>
24391b8b0fSPatrick Venture 
25da4a5dd1SPatrick Venture #include <sdbusplus/bus.hpp>
26da4a5dd1SPatrick Venture #include <sdbusplus/message.hpp>
27a83a3eccSPatrick Venture 
28a83a3eccSPatrick Venture #include <map>
2909334bbeSPatrick Venture #include <memory>
30391b8b0fSPatrick Venture #include <string>
31391b8b0fSPatrick Venture #include <tuple>
321f802f5eSJames Feist #include <variant>
33391b8b0fSPatrick Venture 
3436ab6f6eSPatrick Venture namespace pid_control
35391b8b0fSPatrick Venture {
3636ab6f6eSPatrick Venture namespace ipmi
37da4a5dd1SPatrick Venture {
38391b8b0fSPatrick Venture 
39391b8b0fSPatrick Venture static constexpr auto manualProperty = "Manual";
40391b8b0fSPatrick Venture static constexpr auto failsafeProperty = "FailSafe";
41391b8b0fSPatrick Venture 
getFailsafeModeState(const uint8_t * reqBuf,uint8_t * replyBuf,size_t * dataLen)42*bd63bcacSPatrick Williams ipmi_ret_t ZoneControlIpmiHandler::getFailsafeModeState(
43*bd63bcacSPatrick Williams     const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen)
44391b8b0fSPatrick Venture {
45391b8b0fSPatrick Venture     bool current;
46391b8b0fSPatrick Venture 
47391b8b0fSPatrick Venture     if (*dataLen < sizeof(struct FanCtrlRequest))
48391b8b0fSPatrick Venture     {
49391b8b0fSPatrick Venture         return IPMI_CC_INVALID;
50391b8b0fSPatrick Venture     }
51391b8b0fSPatrick Venture 
52391b8b0fSPatrick Venture     const auto request =
53391b8b0fSPatrick Venture         reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
54391b8b0fSPatrick Venture 
55*bd63bcacSPatrick Williams     ipmi_ret_t rc =
56*bd63bcacSPatrick Williams         _control->getFanCtrlProperty(request->zone, &current, failsafeProperty);
57391b8b0fSPatrick Venture     if (rc)
58391b8b0fSPatrick Venture     {
59391b8b0fSPatrick Venture         return rc;
60391b8b0fSPatrick Venture     }
61391b8b0fSPatrick Venture 
62391b8b0fSPatrick Venture     *replyBuf = (uint8_t)current;
63391b8b0fSPatrick Venture     *dataLen = sizeof(uint8_t);
6437b247abSPatrick Venture     return IPMI_CC_OK;
65391b8b0fSPatrick Venture }
66391b8b0fSPatrick Venture 
67391b8b0fSPatrick Venture /*
68391b8b0fSPatrick Venture  * <method name="GetAll">
69391b8b0fSPatrick Venture  *   <arg name="interface" direction="in" type="s"/>
70391b8b0fSPatrick Venture  *   <arg name="properties" direction="out" type="a{sv}"/>
71391b8b0fSPatrick Venture  * </method>
72391b8b0fSPatrick Venture  */
getManualModeState(const uint8_t * reqBuf,uint8_t * replyBuf,size_t * dataLen)73*bd63bcacSPatrick Williams ipmi_ret_t ZoneControlIpmiHandler::getManualModeState(
74*bd63bcacSPatrick Williams     const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen)
75391b8b0fSPatrick Venture {
76391b8b0fSPatrick Venture     bool current;
77391b8b0fSPatrick Venture 
78391b8b0fSPatrick Venture     if (*dataLen < sizeof(struct FanCtrlRequest))
79391b8b0fSPatrick Venture     {
80391b8b0fSPatrick Venture         return IPMI_CC_INVALID;
81391b8b0fSPatrick Venture     }
82391b8b0fSPatrick Venture 
83391b8b0fSPatrick Venture     const auto request =
84391b8b0fSPatrick Venture         reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
85391b8b0fSPatrick Venture 
86*bd63bcacSPatrick Williams     ipmi_ret_t rc =
87*bd63bcacSPatrick Williams         _control->getFanCtrlProperty(request->zone, &current, manualProperty);
88391b8b0fSPatrick Venture     if (rc)
89391b8b0fSPatrick Venture     {
90391b8b0fSPatrick Venture         return rc;
91391b8b0fSPatrick Venture     }
92391b8b0fSPatrick Venture 
93391b8b0fSPatrick Venture     *replyBuf = (uint8_t)current;
94391b8b0fSPatrick Venture     *dataLen = sizeof(uint8_t);
9537b247abSPatrick Venture     return IPMI_CC_OK;
96391b8b0fSPatrick Venture }
97391b8b0fSPatrick Venture 
98391b8b0fSPatrick Venture /*
99391b8b0fSPatrick Venture  * <method name="Set">
100391b8b0fSPatrick Venture  *   <arg name="interface" direction="in" type="s"/>
101391b8b0fSPatrick Venture  *   <arg name="property" direction="in" type="s"/>
102391b8b0fSPatrick Venture  *   <arg name="value" direction="in" type="v"/>
103391b8b0fSPatrick Venture  * </method>
104391b8b0fSPatrick Venture  */
setManualModeState(const uint8_t * reqBuf,uint8_t * replyBuf,const size_t * dataLen)105a1ae4fa1SHarvey.Wu ipmi_ret_t ZoneControlIpmiHandler::setManualModeState(
10622579ca4SHarvey Wu     const uint8_t* reqBuf, [[maybe_unused]] uint8_t* replyBuf,
10722579ca4SHarvey Wu     const size_t* dataLen)
108391b8b0fSPatrick Venture {
109391b8b0fSPatrick Venture     if (*dataLen < sizeof(struct FanCtrlRequestSet))
110391b8b0fSPatrick Venture     {
111391b8b0fSPatrick Venture         return IPMI_CC_INVALID;
112391b8b0fSPatrick Venture     }
113391b8b0fSPatrick Venture 
114391b8b0fSPatrick Venture     const auto request =
115391b8b0fSPatrick Venture         reinterpret_cast<const struct FanCtrlRequestSet*>(&reqBuf[0]);
116391b8b0fSPatrick Venture 
117391b8b0fSPatrick Venture     /* 0 is false, 1 is true */
11809334bbeSPatrick Venture     ipmi_ret_t rc = _control->setFanCtrlProperty(
11909334bbeSPatrick Venture         request->zone, static_cast<bool>(request->value), manualProperty);
120391b8b0fSPatrick Venture     return rc;
121391b8b0fSPatrick Venture }
122391b8b0fSPatrick Venture 
123391b8b0fSPatrick Venture /* Three command packages: get, set true, set false */
manualModeControl(ZoneControlIpmiHandler * handler,ipmi_cmd_t cmd,const uint8_t * reqBuf,uint8_t * replyCmdBuf,size_t * dataLen)124*bd63bcacSPatrick Williams ipmi_ret_t manualModeControl(
125*bd63bcacSPatrick Williams     ZoneControlIpmiHandler* handler, [[maybe_unused]] ipmi_cmd_t cmd,
126*bd63bcacSPatrick Williams     const uint8_t* reqBuf, uint8_t* replyCmdBuf, size_t* dataLen)
127391b8b0fSPatrick Venture {
128391b8b0fSPatrick Venture     // FanCtrlRequest is the smaller of the requests, so it's at a minimum.
129391b8b0fSPatrick Venture     if (*dataLen < sizeof(struct FanCtrlRequest))
130391b8b0fSPatrick Venture     {
131391b8b0fSPatrick Venture         return IPMI_CC_INVALID;
132391b8b0fSPatrick Venture     }
133391b8b0fSPatrick Venture 
134391b8b0fSPatrick Venture     const auto request =
135391b8b0fSPatrick Venture         reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
136391b8b0fSPatrick Venture 
13737b247abSPatrick Venture     ipmi_ret_t rc = IPMI_CC_OK;
13837b247abSPatrick Venture 
139391b8b0fSPatrick Venture     switch (request->command)
140391b8b0fSPatrick Venture     {
1411277543aSPatrick Venture         case getControlState:
14209334bbeSPatrick Venture             return handler->getManualModeState(reqBuf, replyCmdBuf, dataLen);
1431277543aSPatrick Venture         case setControlState:
14409334bbeSPatrick Venture             return handler->setManualModeState(reqBuf, replyCmdBuf, dataLen);
1451277543aSPatrick Venture         case getFailsafeState:
14609334bbeSPatrick Venture             return handler->getFailsafeModeState(reqBuf, replyCmdBuf, dataLen);
147391b8b0fSPatrick Venture         default:
148391b8b0fSPatrick Venture             rc = IPMI_CC_INVALID;
149391b8b0fSPatrick Venture     }
150391b8b0fSPatrick Venture 
151391b8b0fSPatrick Venture     return rc;
152391b8b0fSPatrick Venture }
153391b8b0fSPatrick Venture 
15436ab6f6eSPatrick Venture } // namespace ipmi
15536ab6f6eSPatrick Venture } // namespace pid_control
156