blob: 085c2591fc0e3d600d812777869177c6372a19bf [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>
Patrick Venture4d49ae62018-09-17 11:35:32 -070023
24namespace google
25{
26namespace ipmi
27{
28
Patrick Venture45fad1b2019-03-18 16:52:14 -070029ipmi_ret_t psuHardReset(const uint8_t* reqBuf, uint8_t* replyBuf,
Patrick Ventureaa374122019-03-15 15:09:10 -070030 size_t* dataLen, const HandlerInterface* handler)
Patrick Venture4d49ae62018-09-17 11:35:32 -070031{
Patrick Ventureacd54232018-10-16 16:58:59 -070032 struct PsuResetRequest request;
33
34 if ((*dataLen) < sizeof(request))
Patrick Venture4d49ae62018-09-17 11:35:32 -070035 {
Patrick Venturece07ee02018-09-19 18:09:32 -070036 std::fprintf(stderr, "Invalid command length: %u\n",
37 static_cast<uint32_t>(*dataLen));
Patrick Venturefff98612018-11-12 09:05:54 -080038 return IPMI_CC_REQ_DATA_LEN_INVALID;
Patrick Venture4d49ae62018-09-17 11:35:32 -070039 }
40
Patrick Venturece07ee02018-09-19 18:09:32 -070041 std::memcpy(&request, &reqBuf[0], sizeof(struct PsuResetRequest));
Patrick Venture4d49ae62018-09-17 11:35:32 -070042 try
43 {
Patrick Ventureaa374122019-03-15 15:09:10 -070044 handler->psuResetDelay(request.delay);
Patrick Venture4d49ae62018-09-17 11:35:32 -070045 }
Patrick Ventureaa374122019-03-15 15:09:10 -070046 catch (const IpmiException& e)
Patrick Venture4d49ae62018-09-17 11:35:32 -070047 {
Patrick Ventureaa374122019-03-15 15:09:10 -070048 return e.getIpmiError();
Patrick Venture4d49ae62018-09-17 11:35:32 -070049 }
50
51 replyBuf[0] = SysPsuHardReset;
52 (*dataLen) = sizeof(uint8_t);
53
54 return IPMI_CC_OK;
55}
56
Shounak Mitraac4a16f2021-02-02 11:11:44 -080057ipmi_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 Venture4d49ae62018-09-17 11:35:32 -070086} // namespace ipmi
87} // namespace google