blob: 60ecebf06e2f90ef3423255b2bdf668e14378caf [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
George Liu92110f82025-07-02 15:07:35 +080022#include <ipmid/api-types.hpp>
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
George Liu92110f82025-07-02 15:07:35 +080029namespace pid_control::ipmi
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070030{
Patrick Venture391b8b02018-03-08 08:31:13 -080031
Patrick Venture391b8b02018-03-08 08:31:13 -080032static constexpr auto manualProperty = "Manual";
33static constexpr auto failsafeProperty = "FailSafe";
Patrick Venture391b8b02018-03-08 08:31:13 -080034
George Liu92110f82025-07-02 15:07:35 +080035::ipmi::Cc ZoneControlIpmiHandler::getFailsafeModeState(
Patrick Williamsbd63bca2024-08-16 15:21:10 -040036 const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -080037{
Patrick Venture391b8b02018-03-08 08:31:13 -080038 bool current;
39
40 if (*dataLen < sizeof(struct FanCtrlRequest))
41 {
George Liu92110f82025-07-02 15:07:35 +080042 return ::ipmi::ccInvalidCommand;
Patrick Venture391b8b02018-03-08 08:31:13 -080043 }
44
45 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070046 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -080047
George Liu92110f82025-07-02 15:07:35 +080048 ::ipmi::Cc rc =
Patrick Williamsbd63bca2024-08-16 15:21:10 -040049 _control->getFanCtrlProperty(request->zone, &current, failsafeProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -080050 if (rc)
51 {
52 return rc;
53 }
54
55 *replyBuf = (uint8_t)current;
56 *dataLen = sizeof(uint8_t);
George Liu92110f82025-07-02 15:07:35 +080057 return ::ipmi::ccSuccess;
Patrick Venture391b8b02018-03-08 08:31:13 -080058}
59
60/*
61 * <method name="GetAll">
62 * <arg name="interface" direction="in" type="s"/>
63 * <arg name="properties" direction="out" type="a{sv}"/>
64 * </method>
65 */
George Liu92110f82025-07-02 15:07:35 +080066::ipmi::Cc ZoneControlIpmiHandler::getManualModeState(
Patrick Williamsbd63bca2024-08-16 15:21:10 -040067 const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -080068{
Patrick Venture391b8b02018-03-08 08:31:13 -080069 bool current;
70
71 if (*dataLen < sizeof(struct FanCtrlRequest))
72 {
George Liu92110f82025-07-02 15:07:35 +080073 return ::ipmi::ccInvalidCommand;
Patrick Venture391b8b02018-03-08 08:31:13 -080074 }
75
76 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070077 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -080078
George Liu92110f82025-07-02 15:07:35 +080079 ::ipmi::Cc rc =
Patrick Williamsbd63bca2024-08-16 15:21:10 -040080 _control->getFanCtrlProperty(request->zone, &current, manualProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -080081 if (rc)
82 {
83 return rc;
84 }
85
86 *replyBuf = (uint8_t)current;
87 *dataLen = sizeof(uint8_t);
George Liu92110f82025-07-02 15:07:35 +080088 return ::ipmi::ccSuccess;
Patrick Venture391b8b02018-03-08 08:31:13 -080089}
90
91/*
92 * <method name="Set">
93 * <arg name="interface" direction="in" type="s"/>
94 * <arg name="property" direction="in" type="s"/>
95 * <arg name="value" direction="in" type="v"/>
96 * </method>
97 */
George Liu92110f82025-07-02 15:07:35 +080098::ipmi::Cc ZoneControlIpmiHandler::setManualModeState(
Harvey Wu22579ca2022-11-07 14:53:37 +080099 const uint8_t* reqBuf, [[maybe_unused]] uint8_t* replyBuf,
100 const size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -0800101{
Patrick Venture391b8b02018-03-08 08:31:13 -0800102 if (*dataLen < sizeof(struct FanCtrlRequestSet))
103 {
George Liu92110f82025-07-02 15:07:35 +0800104 return ::ipmi::ccInvalidCommand;
Patrick Venture391b8b02018-03-08 08:31:13 -0800105 }
106
Patrick Venture391b8b02018-03-08 08:31:13 -0800107 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700108 reinterpret_cast<const struct FanCtrlRequestSet*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -0800109
110 /* 0 is false, 1 is true */
George Liu92110f82025-07-02 15:07:35 +0800111 ::ipmi::Cc rc = _control->setFanCtrlProperty(
Patrick Venture09334bb2020-08-16 12:22:54 -0700112 request->zone, static_cast<bool>(request->value), manualProperty);
Patrick Venture391b8b02018-03-08 08:31:13 -0800113 return rc;
114}
115
116/* Three command packages: get, set true, set false */
George Liu92110f82025-07-02 15:07:35 +0800117::ipmi::Cc manualModeControl(
118 ZoneControlIpmiHandler* handler, [[maybe_unused]] uint8_t cmd,
Patrick Williamsbd63bca2024-08-16 15:21:10 -0400119 const uint8_t* reqBuf, uint8_t* replyCmdBuf, size_t* dataLen)
Patrick Venture391b8b02018-03-08 08:31:13 -0800120{
Patrick Venture391b8b02018-03-08 08:31:13 -0800121 // FanCtrlRequest is the smaller of the requests, so it's at a minimum.
122 if (*dataLen < sizeof(struct FanCtrlRequest))
123 {
George Liu92110f82025-07-02 15:07:35 +0800124 return ::ipmi::ccInvalidCommand;
Patrick Venture391b8b02018-03-08 08:31:13 -0800125 }
126
127 const auto request =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700128 reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]);
Patrick Venture391b8b02018-03-08 08:31:13 -0800129
George Liu92110f82025-07-02 15:07:35 +0800130 ::ipmi::Cc rc = ::ipmi::ccSuccess;
Patrick Venture37b247a2020-08-03 11:15:21 -0700131
Patrick Venture391b8b02018-03-08 08:31:13 -0800132 switch (request->command)
133 {
Patrick Venture12775432020-08-04 09:57:36 -0700134 case getControlState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700135 return handler->getManualModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture12775432020-08-04 09:57:36 -0700136 case setControlState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700137 return handler->setManualModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture12775432020-08-04 09:57:36 -0700138 case getFailsafeState:
Patrick Venture09334bb2020-08-16 12:22:54 -0700139 return handler->getFailsafeModeState(reqBuf, replyCmdBuf, dataLen);
Patrick Venture391b8b02018-03-08 08:31:13 -0800140 default:
George Liu92110f82025-07-02 15:07:35 +0800141 rc = ::ipmi::ccInvalidCommand;
Patrick Venture391b8b02018-03-08 08:31:13 -0800142 }
143
144 return rc;
145}
146
George Liu92110f82025-07-02 15:07:35 +0800147} // namespace pid_control::ipmi