blob: 280dbe0f07ff0192b069abcf30ae64eab9aa43c7 [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
Patrick Williams444b5ea2023-05-19 13:56:42 -050021#include <ipmid/api-types.hpp>
Michael Shen8d618532023-10-25 09:14:07 +000022#include <stdplus/print.hpp>
Patrick Williams444b5ea2023-05-19 13:56:42 -050023
Patrick Venture4d49ae62018-09-17 11:35:32 -070024#include <cstdint>
Patrick Venturece07ee02018-09-19 18:09:32 -070025#include <cstring>
Willy Tub4e37042021-10-12 17:12:30 -070026#include <span>
Willy Tuff3cd8e2021-09-14 22:49:55 -070027#include <vector>
Patrick Venture4d49ae62018-09-17 11:35:32 -070028
29namespace google
30{
31namespace ipmi
32{
33
Willy Tub4e37042021-10-12 17:12:30 -070034Resp psuHardReset(std::span<const uint8_t> data,
Willy Tuff3cd8e2021-09-14 22:49:55 -070035 const HandlerInterface* handler)
Patrick Venture4d49ae62018-09-17 11:35:32 -070036{
Patrick Ventureacd54232018-10-16 16:58:59 -070037 struct PsuResetRequest request;
38
Willy Tuff3cd8e2021-09-14 22:49:55 -070039 if (data.size() < sizeof(request))
Patrick Venture4d49ae62018-09-17 11:35:32 -070040 {
Michael Shen8d618532023-10-25 09:14:07 +000041 stdplus::print(stderr, "Invalid command length: {}\n", data.size());
Willy Tuff3cd8e2021-09-14 22:49:55 -070042 return ::ipmi::responseReqDataLenInvalid();
Patrick Venture4d49ae62018-09-17 11:35:32 -070043 }
44
Willy Tuff3cd8e2021-09-14 22:49:55 -070045 std::memcpy(&request, data.data(), sizeof(struct PsuResetRequest));
Patrick Venture4d49ae62018-09-17 11:35:32 -070046 try
47 {
Patrick Ventureaa374122019-03-15 15:09:10 -070048 handler->psuResetDelay(request.delay);
Patrick Venture4d49ae62018-09-17 11:35:32 -070049 }
Patrick Ventureaa374122019-03-15 15:09:10 -070050 catch (const IpmiException& e)
Patrick Venture4d49ae62018-09-17 11:35:32 -070051 {
Willy Tuff3cd8e2021-09-14 22:49:55 -070052 return ::ipmi::response(e.getIpmiError());
Patrick Venture4d49ae62018-09-17 11:35:32 -070053 }
54
Willy Tuff3cd8e2021-09-14 22:49:55 -070055 return ::ipmi::responseSuccess(SysOEMCommands::SysPsuHardReset,
56 std::vector<uint8_t>{});
Patrick Venture4d49ae62018-09-17 11:35:32 -070057}
58
Willy Tub4e37042021-10-12 17:12:30 -070059Resp psuHardResetOnShutdown(std::span<const uint8_t>,
Willy Tuff3cd8e2021-09-14 22:49:55 -070060 const HandlerInterface* handler)
Shounak Mitraac4a16f2021-02-02 11:11:44 -080061{
Shounak Mitraac4a16f2021-02-02 11:11:44 -080062 try
63 {
64 handler->psuResetOnShutdown();
65 }
66 catch (const IpmiException& e)
67 {
Willy Tuff3cd8e2021-09-14 22:49:55 -070068 return ::ipmi::response(e.getIpmiError());
Shounak Mitraac4a16f2021-02-02 11:11:44 -080069 }
70
Willy Tuff3cd8e2021-09-14 22:49:55 -070071 return ::ipmi::responseSuccess(SysOEMCommands::SysPsuHardResetOnShutdown,
72 std::vector<uint8_t>{});
Shounak Mitraac4a16f2021-02-02 11:11:44 -080073}
74
Patrick Venture4d49ae62018-09-17 11:35:32 -070075} // namespace ipmi
76} // namespace google