blob: 73d716dec3a2cbf48073393e30e7b81b3296b6fd [file] [log] [blame]
Patrick Venture4d49ae62018-09-17 11:35:32 -07001/*
2 * Copyright 2018 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "psu.hpp"
18
Patrick Ventureaa374122019-03-15 15:09:10 -070019#include "errors.hpp"
20#include "handler.hpp"
Patrick Venture4d49ae62018-09-17 11:35:32 -070021#include "main.hpp"
22
23#include <cstdint>
Patrick Venturece07ee02018-09-19 18:09:32 -070024#include <cstring>
Patrick Venture4d49ae62018-09-17 11:35:32 -070025
26namespace google
27{
28namespace ipmi
29{
30
Patrick Venture4d49ae62018-09-17 11:35:32 -070031ipmi_ret_t PsuHardReset(const uint8_t* reqBuf, uint8_t* replyBuf,
Patrick Ventureaa374122019-03-15 15:09:10 -070032 size_t* dataLen, const HandlerInterface* handler)
Patrick Venture4d49ae62018-09-17 11:35:32 -070033{
Patrick Ventureacd54232018-10-16 16:58:59 -070034 struct PsuResetRequest request;
35
36 if ((*dataLen) < 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",
39 static_cast<uint32_t>(*dataLen));
Patrick Venturefff98612018-11-12 09:05:54 -080040 return IPMI_CC_REQ_DATA_LEN_INVALID;
Patrick Venture4d49ae62018-09-17 11:35:32 -070041 }
42
Patrick Venturece07ee02018-09-19 18:09:32 -070043 std::memcpy(&request, &reqBuf[0], 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 {
Patrick Ventureaa374122019-03-15 15:09:10 -070050 return e.getIpmiError();
Patrick Venture4d49ae62018-09-17 11:35:32 -070051 }
52
53 replyBuf[0] = SysPsuHardReset;
54 (*dataLen) = sizeof(uint8_t);
55
56 return IPMI_CC_OK;
57}
58
59} // namespace ipmi
60} // namespace google