| Alexander Hansen | 46a755f | 2025-10-27 16:31:08 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2017 Google Inc |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 3 | |
| Patrick Venture | 36ab6f6 | 2020-08-03 10:50:26 -0700 | [diff] [blame] | 4 | #include "manualcmds.hpp" |
| 5 | |
| Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 6 | #include "control.hpp" |
| Patrick Venture | 9bf5cef | 2020-08-16 08:59:54 -0700 | [diff] [blame] | 7 | #include "manual_messages.hpp" |
| 8 | |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 9 | #include <ipmid/api-types.hpp> |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 10 | |
| Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame] | 11 | #include <cstddef> |
| 12 | #include <cstdint> |
| Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 13 | #include <memory> |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 14 | #include <string> |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 15 | |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 16 | namespace pid_control::ipmi |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 17 | { |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 18 | |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 19 | static constexpr auto manualProperty = "Manual"; |
| 20 | static constexpr auto failsafeProperty = "FailSafe"; |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 21 | |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 22 | ::ipmi::Cc ZoneControlIpmiHandler::getFailsafeModeState( |
| Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 23 | const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 24 | { |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 25 | bool current; |
| 26 | |
| 27 | if (*dataLen < sizeof(struct FanCtrlRequest)) |
| 28 | { |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 29 | return ::ipmi::ccInvalidCommand; |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | const auto request = |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 33 | reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); |
| 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 rc = |
| Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 36 | _control->getFanCtrlProperty(request->zone, ¤t, failsafeProperty); |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 37 | if (rc) |
| 38 | { |
| 39 | return rc; |
| 40 | } |
| 41 | |
| 42 | *replyBuf = (uint8_t)current; |
| 43 | *dataLen = sizeof(uint8_t); |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 44 | return ::ipmi::ccSuccess; |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /* |
| 48 | * <method name="GetAll"> |
| 49 | * <arg name="interface" direction="in" type="s"/> |
| 50 | * <arg name="properties" direction="out" type="a{sv}"/> |
| 51 | * </method> |
| 52 | */ |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 53 | ::ipmi::Cc ZoneControlIpmiHandler::getManualModeState( |
| Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 54 | const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 55 | { |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 56 | bool current; |
| 57 | |
| 58 | if (*dataLen < sizeof(struct FanCtrlRequest)) |
| 59 | { |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 60 | return ::ipmi::ccInvalidCommand; |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | const auto request = |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 64 | reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 65 | |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 66 | ::ipmi::Cc rc = |
| Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 67 | _control->getFanCtrlProperty(request->zone, ¤t, manualProperty); |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 68 | if (rc) |
| 69 | { |
| 70 | return rc; |
| 71 | } |
| 72 | |
| 73 | *replyBuf = (uint8_t)current; |
| 74 | *dataLen = sizeof(uint8_t); |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 75 | return ::ipmi::ccSuccess; |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /* |
| 79 | * <method name="Set"> |
| 80 | * <arg name="interface" direction="in" type="s"/> |
| 81 | * <arg name="property" direction="in" type="s"/> |
| 82 | * <arg name="value" direction="in" type="v"/> |
| 83 | * </method> |
| 84 | */ |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 85 | ::ipmi::Cc ZoneControlIpmiHandler::setManualModeState( |
| Harvey Wu | 22579ca | 2022-11-07 14:53:37 +0800 | [diff] [blame] | 86 | const uint8_t* reqBuf, [[maybe_unused]] uint8_t* replyBuf, |
| 87 | const size_t* dataLen) |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 88 | { |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 89 | if (*dataLen < sizeof(struct FanCtrlRequestSet)) |
| 90 | { |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 91 | return ::ipmi::ccInvalidCommand; |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 94 | const auto request = |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 95 | reinterpret_cast<const struct FanCtrlRequestSet*>(&reqBuf[0]); |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 96 | |
| 97 | /* 0 is false, 1 is true */ |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 98 | ::ipmi::Cc rc = _control->setFanCtrlProperty( |
| Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 99 | request->zone, static_cast<bool>(request->value), manualProperty); |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 100 | return rc; |
| 101 | } |
| 102 | |
| 103 | /* Three command packages: get, set true, set false */ |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 104 | ::ipmi::Cc manualModeControl( |
| 105 | ZoneControlIpmiHandler* handler, [[maybe_unused]] uint8_t cmd, |
| Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 106 | const uint8_t* reqBuf, uint8_t* replyCmdBuf, size_t* dataLen) |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 107 | { |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 108 | // FanCtrlRequest is the smaller of the requests, so it's at a minimum. |
| 109 | if (*dataLen < sizeof(struct FanCtrlRequest)) |
| 110 | { |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 111 | return ::ipmi::ccInvalidCommand; |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | const auto request = |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 115 | reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 116 | |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 117 | ::ipmi::Cc rc = ::ipmi::ccSuccess; |
| Patrick Venture | 37b247a | 2020-08-03 11:15:21 -0700 | [diff] [blame] | 118 | |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 119 | switch (request->command) |
| 120 | { |
| Patrick Venture | 1277543 | 2020-08-04 09:57:36 -0700 | [diff] [blame] | 121 | case getControlState: |
| Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 122 | return handler->getManualModeState(reqBuf, replyCmdBuf, dataLen); |
| Patrick Venture | 1277543 | 2020-08-04 09:57:36 -0700 | [diff] [blame] | 123 | case setControlState: |
| Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 124 | return handler->setManualModeState(reqBuf, replyCmdBuf, dataLen); |
| Patrick Venture | 1277543 | 2020-08-04 09:57:36 -0700 | [diff] [blame] | 125 | case getFailsafeState: |
| Patrick Venture | 09334bb | 2020-08-16 12:22:54 -0700 | [diff] [blame] | 126 | return handler->getFailsafeModeState(reqBuf, replyCmdBuf, dataLen); |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 127 | default: |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 128 | rc = ::ipmi::ccInvalidCommand; |
| Patrick Venture | 391b8b0 | 2018-03-08 08:31:13 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | return rc; |
| 132 | } |
| 133 | |
| George Liu | 92110f8 | 2025-07-02 15:07:35 +0800 | [diff] [blame] | 134 | } // namespace pid_control::ipmi |