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 | |
Patrick Williams | 444b5ea | 2023-05-19 13:56:42 -0500 | [diff] [blame] | 21 | #include <ipmid/api-types.hpp> |
Michael Shen | 8d61853 | 2023-10-25 09:14:07 +0000 | [diff] [blame] | 22 | #include <stdplus/print.hpp> |
Patrick Williams | 444b5ea | 2023-05-19 13:56:42 -0500 | [diff] [blame] | 23 | |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 24 | #include <cstdint> |
Patrick Venture | ce07ee0 | 2018-09-19 18:09:32 -0700 | [diff] [blame] | 25 | #include <cstring> |
Willy Tu | b4e3704 | 2021-10-12 17:12:30 -0700 | [diff] [blame] | 26 | #include <span> |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 27 | #include <vector> |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 28 | |
| 29 | namespace google |
| 30 | { |
| 31 | namespace ipmi |
| 32 | { |
| 33 | |
Willy Tu | b4e3704 | 2021-10-12 17:12:30 -0700 | [diff] [blame] | 34 | Resp psuHardReset(std::span<const uint8_t> data, |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 35 | const HandlerInterface* handler) |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 36 | { |
Patrick Venture | acd5423 | 2018-10-16 16:58:59 -0700 | [diff] [blame] | 37 | struct PsuResetRequest request; |
| 38 | |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 39 | if (data.size() < sizeof(request)) |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 40 | { |
Michael Shen | 8d61853 | 2023-10-25 09:14:07 +0000 | [diff] [blame] | 41 | stdplus::print(stderr, "Invalid command length: {}\n", data.size()); |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 42 | return ::ipmi::responseReqDataLenInvalid(); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 45 | std::memcpy(&request, data.data(), sizeof(struct PsuResetRequest)); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 46 | try |
| 47 | { |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 48 | handler->psuResetDelay(request.delay); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 49 | } |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 50 | catch (const IpmiException& e) |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 51 | { |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 52 | return ::ipmi::response(e.getIpmiError()); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 55 | return ::ipmi::responseSuccess(SysOEMCommands::SysPsuHardReset, |
| 56 | std::vector<uint8_t>{}); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Willy Tu | b4e3704 | 2021-10-12 17:12:30 -0700 | [diff] [blame] | 59 | Resp psuHardResetOnShutdown(std::span<const uint8_t>, |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 60 | const HandlerInterface* handler) |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 61 | { |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 62 | try |
| 63 | { |
| 64 | handler->psuResetOnShutdown(); |
| 65 | } |
| 66 | catch (const IpmiException& e) |
| 67 | { |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 68 | return ::ipmi::response(e.getIpmiError()); |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 69 | } |
| 70 | |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 71 | return ::ipmi::responseSuccess(SysOEMCommands::SysPsuHardResetOnShutdown, |
| 72 | std::vector<uint8_t>{}); |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 75 | } // namespace ipmi |
| 76 | } // namespace google |