1a2056e9cSWilly Tu // Copyright 2021 Google LLC
2a2056e9cSWilly Tu //
3a2056e9cSWilly Tu // Licensed under the Apache License, Version 2.0 (the "License");
4a2056e9cSWilly Tu // you may not use this file except in compliance with the License.
5a2056e9cSWilly Tu // You may obtain a copy of the License at
6a2056e9cSWilly Tu //
7a2056e9cSWilly Tu // http://www.apache.org/licenses/LICENSE-2.0
8a2056e9cSWilly Tu //
9a2056e9cSWilly Tu // Unless required by applicable law or agreed to in writing, software
10a2056e9cSWilly Tu // distributed under the License is distributed on an "AS IS" BASIS,
11a2056e9cSWilly Tu // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a2056e9cSWilly Tu // See the License for the specific language governing permissions and
13a2056e9cSWilly Tu // limitations under the License.
144d49ae65SPatrick Venture
154d49ae65SPatrick Venture #include "psu.hpp"
164d49ae65SPatrick Venture
170e9aae5dSPatrick Venture #include "commands.hpp"
18aa374120SPatrick Venture #include "errors.hpp"
19aa374120SPatrick Venture #include "handler.hpp"
204d49ae65SPatrick Venture
21444b5ea4SPatrick Williams #include <ipmid/api-types.hpp>
22*8d618532SMichael Shen #include <stdplus/print.hpp>
23444b5ea4SPatrick Williams
244d49ae65SPatrick Venture #include <cstdint>
25ce07ee0aSPatrick Venture #include <cstring>
26b4e3704cSWilly Tu #include <span>
27ff3cd8e9SWilly Tu #include <vector>
284d49ae65SPatrick Venture
294d49ae65SPatrick Venture namespace google
304d49ae65SPatrick Venture {
314d49ae65SPatrick Venture namespace ipmi
324d49ae65SPatrick Venture {
334d49ae65SPatrick Venture
psuHardReset(std::span<const uint8_t> data,const HandlerInterface * handler)34b4e3704cSWilly Tu Resp psuHardReset(std::span<const uint8_t> data,
35ff3cd8e9SWilly Tu const HandlerInterface* handler)
364d49ae65SPatrick Venture {
37acd5423aSPatrick Venture struct PsuResetRequest request;
38acd5423aSPatrick Venture
39ff3cd8e9SWilly Tu if (data.size() < sizeof(request))
404d49ae65SPatrick Venture {
41*8d618532SMichael Shen stdplus::print(stderr, "Invalid command length: {}\n", data.size());
42ff3cd8e9SWilly Tu return ::ipmi::responseReqDataLenInvalid();
434d49ae65SPatrick Venture }
444d49ae65SPatrick Venture
45ff3cd8e9SWilly Tu std::memcpy(&request, data.data(), sizeof(struct PsuResetRequest));
464d49ae65SPatrick Venture try
474d49ae65SPatrick Venture {
48aa374120SPatrick Venture handler->psuResetDelay(request.delay);
494d49ae65SPatrick Venture }
50aa374120SPatrick Venture catch (const IpmiException& e)
514d49ae65SPatrick Venture {
52ff3cd8e9SWilly Tu return ::ipmi::response(e.getIpmiError());
534d49ae65SPatrick Venture }
544d49ae65SPatrick Venture
55ff3cd8e9SWilly Tu return ::ipmi::responseSuccess(SysOEMCommands::SysPsuHardReset,
56ff3cd8e9SWilly Tu std::vector<uint8_t>{});
574d49ae65SPatrick Venture }
584d49ae65SPatrick Venture
psuHardResetOnShutdown(std::span<const uint8_t>,const HandlerInterface * handler)59b4e3704cSWilly Tu Resp psuHardResetOnShutdown(std::span<const uint8_t>,
60ac4a16f7SShounak Mitra const HandlerInterface* handler)
61ac4a16f7SShounak Mitra {
62ac4a16f7SShounak Mitra try
63ac4a16f7SShounak Mitra {
64ac4a16f7SShounak Mitra handler->psuResetOnShutdown();
65ac4a16f7SShounak Mitra }
66ac4a16f7SShounak Mitra catch (const IpmiException& e)
67ac4a16f7SShounak Mitra {
68ff3cd8e9SWilly Tu return ::ipmi::response(e.getIpmiError());
69ac4a16f7SShounak Mitra }
70ac4a16f7SShounak Mitra
71ff3cd8e9SWilly Tu return ::ipmi::responseSuccess(SysOEMCommands::SysPsuHardResetOnShutdown,
72ff3cd8e9SWilly Tu std::vector<uint8_t>{});
73ac4a16f7SShounak Mitra }
74ac4a16f7SShounak Mitra
754d49ae65SPatrick Venture } // namespace ipmi
764d49ae65SPatrick Venture } // namespace google
77