blob: 1e2ed92ee1327dee47c4ec61d43f76a79e827de8 [file] [log] [blame]
Willy Tua2056e92021-10-10 13:36:16 -07001// 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 Venture4d49ae62018-09-17 11:35:32 -070014
15#include "psu.hpp"
16
Patrick Venture0e9aae52020-08-13 13:07:09 -070017#include "commands.hpp"
Patrick Ventureaa374122019-03-15 15:09:10 -070018#include "errors.hpp"
19#include "handler.hpp"
Patrick Venture4d49ae62018-09-17 11:35:32 -070020
21#include <cstdint>
Patrick Venturece07ee02018-09-19 18:09:32 -070022#include <cstring>
Willy Tuff3cd8e2021-09-14 22:49:55 -070023#include <ipmid/api-types.hpp>
24#include <vector>
Patrick Venture4d49ae62018-09-17 11:35:32 -070025
26namespace google
27{
28namespace ipmi
29{
30
Willy Tuff3cd8e2021-09-14 22:49:55 -070031Resp psuHardReset(const std::vector<std::uint8_t>& data,
32 const HandlerInterface* handler)
Patrick Venture4d49ae62018-09-17 11:35:32 -070033{
Patrick Ventureacd54232018-10-16 16:58:59 -070034 struct PsuResetRequest request;
35
Willy Tuff3cd8e2021-09-14 22:49:55 -070036 if (data.size() < sizeof(request))
Patrick Venture4d49ae62018-09-17 11:35:32 -070037 {
Patrick Venturece07ee02018-09-19 18:09:32 -070038 std::fprintf(stderr, "Invalid command length: %u\n",
Willy Tuff3cd8e2021-09-14 22:49:55 -070039 static_cast<uint32_t>(data.size()));
40 return ::ipmi::responseReqDataLenInvalid();
Patrick Venture4d49ae62018-09-17 11:35:32 -070041 }
42
Willy Tuff3cd8e2021-09-14 22:49:55 -070043 std::memcpy(&request, data.data(), sizeof(struct PsuResetRequest));
Patrick Venture4d49ae62018-09-17 11:35:32 -070044 try
45 {
Patrick Ventureaa374122019-03-15 15:09:10 -070046 handler->psuResetDelay(request.delay);
Patrick Venture4d49ae62018-09-17 11:35:32 -070047 }
Patrick Ventureaa374122019-03-15 15:09:10 -070048 catch (const IpmiException& e)
Patrick Venture4d49ae62018-09-17 11:35:32 -070049 {
Willy Tuff3cd8e2021-09-14 22:49:55 -070050 return ::ipmi::response(e.getIpmiError());
Patrick Venture4d49ae62018-09-17 11:35:32 -070051 }
52
Willy Tuff3cd8e2021-09-14 22:49:55 -070053 return ::ipmi::responseSuccess(SysOEMCommands::SysPsuHardReset,
54 std::vector<uint8_t>{});
Patrick Venture4d49ae62018-09-17 11:35:32 -070055}
56
Willy Tuff3cd8e2021-09-14 22:49:55 -070057Resp psuHardResetOnShutdown(const std::vector<std::uint8_t>&,
58 const HandlerInterface* handler)
Shounak Mitraac4a16f2021-02-02 11:11:44 -080059{
Shounak Mitraac4a16f2021-02-02 11:11:44 -080060 try
61 {
62 handler->psuResetOnShutdown();
63 }
64 catch (const IpmiException& e)
65 {
Willy Tuff3cd8e2021-09-14 22:49:55 -070066 return ::ipmi::response(e.getIpmiError());
Shounak Mitraac4a16f2021-02-02 11:11:44 -080067 }
68
Willy Tuff3cd8e2021-09-14 22:49:55 -070069 return ::ipmi::responseSuccess(SysOEMCommands::SysPsuHardResetOnShutdown,
70 std::vector<uint8_t>{});
Shounak Mitraac4a16f2021-02-02 11:11:44 -080071}
72
Patrick Venture4d49ae62018-09-17 11:35:32 -070073} // namespace ipmi
74} // namespace google