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