Willy Tu | a2056e9 | 2021-10-10 13:36:16 -0700 | [diff] [blame^] | 1 | // Copyright 2021 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 14 | |
| 15 | #include "psu.hpp" |
| 16 | |
Patrick Venture | 0e9aae5 | 2020-08-13 13:07:09 -0700 | [diff] [blame] | 17 | #include "commands.hpp" |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 18 | #include "errors.hpp" |
| 19 | #include "handler.hpp" |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 20 | |
| 21 | #include <cstdint> |
Patrick Venture | ce07ee0 | 2018-09-19 18:09:32 -0700 | [diff] [blame] | 22 | #include <cstring> |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 23 | |
| 24 | namespace google |
| 25 | { |
| 26 | namespace ipmi |
| 27 | { |
| 28 | |
Patrick Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 29 | ipmi_ret_t psuHardReset(const uint8_t* reqBuf, uint8_t* replyBuf, |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 30 | size_t* dataLen, const HandlerInterface* handler) |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 31 | { |
Patrick Venture | acd5423 | 2018-10-16 16:58:59 -0700 | [diff] [blame] | 32 | struct PsuResetRequest request; |
| 33 | |
| 34 | if ((*dataLen) < sizeof(request)) |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 35 | { |
Patrick Venture | ce07ee0 | 2018-09-19 18:09:32 -0700 | [diff] [blame] | 36 | std::fprintf(stderr, "Invalid command length: %u\n", |
| 37 | static_cast<uint32_t>(*dataLen)); |
Patrick Venture | fff9861 | 2018-11-12 09:05:54 -0800 | [diff] [blame] | 38 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Patrick Venture | ce07ee0 | 2018-09-19 18:09:32 -0700 | [diff] [blame] | 41 | std::memcpy(&request, &reqBuf[0], sizeof(struct PsuResetRequest)); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 42 | try |
| 43 | { |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 44 | handler->psuResetDelay(request.delay); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 45 | } |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 46 | catch (const IpmiException& e) |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 47 | { |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 48 | return e.getIpmiError(); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | replyBuf[0] = SysPsuHardReset; |
| 52 | (*dataLen) = sizeof(uint8_t); |
| 53 | |
| 54 | return IPMI_CC_OK; |
| 55 | } |
| 56 | |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 57 | ipmi_ret_t psuHardResetOnShutdown(const uint8_t* reqBuf, uint8_t* replyBuf, |
| 58 | size_t* dataLen, |
| 59 | const HandlerInterface* handler) |
| 60 | { |
| 61 | struct PsuResetOnShutdownRequest request; |
| 62 | |
| 63 | if ((*dataLen) < sizeof(request)) |
| 64 | { |
| 65 | std::fprintf(stderr, "Invalid command length: %u\n", |
| 66 | static_cast<uint32_t>(*dataLen)); |
| 67 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 68 | } |
| 69 | |
| 70 | std::memcpy(&request, &reqBuf[0], sizeof(request)); |
| 71 | try |
| 72 | { |
| 73 | handler->psuResetOnShutdown(); |
| 74 | } |
| 75 | catch (const IpmiException& e) |
| 76 | { |
| 77 | return e.getIpmiError(); |
| 78 | } |
| 79 | |
| 80 | replyBuf[0] = SysPsuHardResetOnShutdown; |
| 81 | (*dataLen) = sizeof(uint8_t); |
| 82 | |
| 83 | return IPMI_CC_OK; |
| 84 | } |
| 85 | |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 86 | } // namespace ipmi |
| 87 | } // namespace google |