Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 1 | /** |
| 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 Venture | 36ab6f6 | 2020-08-03 10:50:26 -0700 | [diff] [blame] | 17 | #include "manualcmds.hpp" |
| 18 | |
Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 19 | #include "control.hpp" |
Patrick Venture | 9bf5cef | 2020-08-16 08:59:54 -0700 | [diff] [blame] | 20 | #include "manual_messages.hpp" |
| 21 | |
William A. Kennington III | 331143c | 2019-02-07 15:52:44 -0800 | [diff] [blame] | 22 | #include <ipmid/api.h> |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 23 | |
Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame^] | 24 | #include <cstddef> |
| 25 | #include <cstdint> |
Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 26 | #include <memory> |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 27 | #include <string> |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 28 | |
Patrick Venture | 36ab6f6 | 2020-08-03 10:50:26 -0700 | [diff] [blame] | 29 | namespace pid_control |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 30 | { |
Patrick Venture | 36ab6f6 | 2020-08-03 10:50:26 -0700 | [diff] [blame] | 31 | namespace ipmi |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 32 | { |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 33 | |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 34 | static constexpr auto manualProperty = "Manual"; |
| 35 | static constexpr auto failsafeProperty = "FailSafe"; |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 36 | |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 37 | ipmi_ret_t ZoneControlIpmiHandler::getFailsafeModeState( |
| 38 | const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 39 | { |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 40 | bool current; |
| 41 | |
| 42 | if (*dataLen < sizeof(struct FanCtrlRequest)) |
| 43 | { |
| 44 | return IPMI_CC_INVALID; |
| 45 | } |
| 46 | |
| 47 | const auto request = |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 48 | reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 49 | |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 50 | ipmi_ret_t rc = |
| 51 | _control->getFanCtrlProperty(request->zone, ¤t, failsafeProperty); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 52 | if (rc) |
| 53 | { |
| 54 | return rc; |
| 55 | } |
| 56 | |
| 57 | *replyBuf = (uint8_t)current; |
| 58 | *dataLen = sizeof(uint8_t); |
Patrick Venture | 37b247a | 2020-08-03 11:15:21 -0700 | [diff] [blame] | 59 | return IPMI_CC_OK; |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 60 | } |
| 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 Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 68 | ipmi_ret_t ZoneControlIpmiHandler::getManualModeState( |
| 69 | const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 70 | { |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 71 | bool current; |
| 72 | |
| 73 | if (*dataLen < sizeof(struct FanCtrlRequest)) |
| 74 | { |
| 75 | return IPMI_CC_INVALID; |
| 76 | } |
| 77 | |
| 78 | const auto request = |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 79 | reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 80 | |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 81 | ipmi_ret_t rc = |
| 82 | _control->getFanCtrlProperty(request->zone, ¤t, manualProperty); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 83 | if (rc) |
| 84 | { |
| 85 | return rc; |
| 86 | } |
| 87 | |
| 88 | *replyBuf = (uint8_t)current; |
| 89 | *dataLen = sizeof(uint8_t); |
Patrick Venture | 37b247a | 2020-08-03 11:15:21 -0700 | [diff] [blame] | 90 | return IPMI_CC_OK; |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 91 | } |
| 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.Wu | a1ae4fa | 2022-10-28 17:38:35 +0800 | [diff] [blame] | 100 | ipmi_ret_t ZoneControlIpmiHandler::setManualModeState( |
Harvey Wu | 22579ca | 2022-11-07 14:53:37 +0800 | [diff] [blame] | 101 | const uint8_t* reqBuf, [[maybe_unused]] uint8_t* replyBuf, |
| 102 | const size_t* dataLen) |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 103 | { |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 104 | if (*dataLen < sizeof(struct FanCtrlRequestSet)) |
| 105 | { |
| 106 | return IPMI_CC_INVALID; |
| 107 | } |
| 108 | |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 109 | const auto request = |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 110 | reinterpret_cast<const struct FanCtrlRequestSet*>(&reqBuf[0]); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 111 | |
| 112 | /* 0 is false, 1 is true */ |
Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 113 | ipmi_ret_t rc = _control->setFanCtrlProperty( |
| 114 | request->zone, static_cast<bool>(request->value), manualProperty); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 115 | return rc; |
| 116 | } |
| 117 | |
| 118 | /* Three command packages: get, set true, set false */ |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 119 | ipmi_ret_t manualModeControl( |
| 120 | ZoneControlIpmiHandler* handler, [[maybe_unused]] ipmi_cmd_t cmd, |
| 121 | const uint8_t* reqBuf, uint8_t* replyCmdBuf, size_t* dataLen) |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 122 | { |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 123 | // 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 Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 130 | reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 131 | |
Patrick Venture | 37b247a | 2020-08-03 11:15:21 -0700 | [diff] [blame] | 132 | ipmi_ret_t rc = IPMI_CC_OK; |
| 133 | |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 134 | switch (request->command) |
| 135 | { |
Patrick Venture | 1277543 | 2020-08-04 09:57:36 -0700 | [diff] [blame] | 136 | case getControlState: |
Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 137 | return handler->getManualModeState(reqBuf, replyCmdBuf, dataLen); |
Patrick Venture | 1277543 | 2020-08-04 09:57:36 -0700 | [diff] [blame] | 138 | case setControlState: |
Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 139 | return handler->setManualModeState(reqBuf, replyCmdBuf, dataLen); |
Patrick Venture | 1277543 | 2020-08-04 09:57:36 -0700 | [diff] [blame] | 140 | case getFailsafeState: |
Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 141 | return handler->getFailsafeModeState(reqBuf, replyCmdBuf, dataLen); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 142 | default: |
| 143 | rc = IPMI_CC_INVALID; |
| 144 | } |
| 145 | |
| 146 | return rc; |
| 147 | } |
| 148 | |
Patrick Venture | 36ab6f6 | 2020-08-03 10:50:26 -0700 | [diff] [blame] | 149 | } // namespace ipmi |
| 150 | } // namespace pid_control |