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 | |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 22 | #include <ipmid/api-types.hpp> |
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 | |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 29 | namespace pid_control::ipmi |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 30 | { |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 31 | |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 32 | static constexpr auto manualProperty = "Manual"; |
| 33 | static constexpr auto failsafeProperty = "FailSafe"; |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 34 | |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 35 | ::ipmi::Cc ZoneControlIpmiHandler::getFailsafeModeState( |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 36 | const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 37 | { |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 38 | bool current; |
| 39 | |
| 40 | if (*dataLen < sizeof(struct FanCtrlRequest)) |
| 41 | { |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 42 | return ::ipmi::ccInvalidCommand; |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | const auto request = |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 46 | reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 47 | |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 48 | ::ipmi::Cc rc = |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 49 | _control->getFanCtrlProperty(request->zone, ¤t, failsafeProperty); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 50 | if (rc) |
| 51 | { |
| 52 | return rc; |
| 53 | } |
| 54 | |
| 55 | *replyBuf = (uint8_t)current; |
| 56 | *dataLen = sizeof(uint8_t); |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 57 | return ::ipmi::ccSuccess; |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 58 | } |
| 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 Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 66 | ::ipmi::Cc ZoneControlIpmiHandler::getManualModeState( |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 67 | const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 68 | { |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 69 | bool current; |
| 70 | |
| 71 | if (*dataLen < sizeof(struct FanCtrlRequest)) |
| 72 | { |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 73 | return ::ipmi::ccInvalidCommand; |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | const auto request = |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 77 | reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 78 | |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 79 | ::ipmi::Cc rc = |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 80 | _control->getFanCtrlProperty(request->zone, ¤t, manualProperty); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 81 | if (rc) |
| 82 | { |
| 83 | return rc; |
| 84 | } |
| 85 | |
| 86 | *replyBuf = (uint8_t)current; |
| 87 | *dataLen = sizeof(uint8_t); |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 88 | return ::ipmi::ccSuccess; |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 89 | } |
| 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 Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 98 | ::ipmi::Cc ZoneControlIpmiHandler::setManualModeState( |
Harvey Wu | 22579ca | 2022-11-07 14:53:37 +0800 | [diff] [blame] | 99 | const uint8_t* reqBuf, [[maybe_unused]] uint8_t* replyBuf, |
| 100 | const size_t* dataLen) |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 101 | { |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 102 | if (*dataLen < sizeof(struct FanCtrlRequestSet)) |
| 103 | { |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 104 | return ::ipmi::ccInvalidCommand; |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 107 | const auto request = |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 108 | reinterpret_cast<const struct FanCtrlRequestSet*>(&reqBuf[0]); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 109 | |
| 110 | /* 0 is false, 1 is true */ |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 111 | ::ipmi::Cc rc = _control->setFanCtrlProperty( |
Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 112 | request->zone, static_cast<bool>(request->value), manualProperty); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 113 | return rc; |
| 114 | } |
| 115 | |
| 116 | /* Three command packages: get, set true, set false */ |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 117 | ::ipmi::Cc manualModeControl( |
| 118 | ZoneControlIpmiHandler* handler, [[maybe_unused]] uint8_t cmd, |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 119 | const uint8_t* reqBuf, uint8_t* replyCmdBuf, size_t* dataLen) |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 120 | { |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 121 | // FanCtrlRequest is the smaller of the requests, so it's at a minimum. |
| 122 | if (*dataLen < sizeof(struct FanCtrlRequest)) |
| 123 | { |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 124 | return ::ipmi::ccInvalidCommand; |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | const auto request = |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 128 | reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 129 | |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 130 | ::ipmi::Cc rc = ::ipmi::ccSuccess; |
Patrick Venture | 37b247a | 2020-08-03 11:15:21 -0700 | [diff] [blame] | 131 | |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 132 | switch (request->command) |
| 133 | { |
Patrick Venture | 1277543 | 2020-08-04 09:57:36 -0700 | [diff] [blame] | 134 | case getControlState: |
Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 135 | return handler->getManualModeState(reqBuf, replyCmdBuf, dataLen); |
Patrick Venture | 1277543 | 2020-08-04 09:57:36 -0700 | [diff] [blame] | 136 | case setControlState: |
Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 137 | return handler->setManualModeState(reqBuf, replyCmdBuf, dataLen); |
Patrick Venture | 1277543 | 2020-08-04 09:57:36 -0700 | [diff] [blame] | 138 | case getFailsafeState: |
Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 139 | return handler->getFailsafeModeState(reqBuf, replyCmdBuf, dataLen); |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 140 | default: |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 141 | rc = ::ipmi::ccInvalidCommand; |
Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | return rc; |
| 145 | } |
| 146 | |
George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame^] | 147 | } // namespace pid_control::ipmi |