1 // 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. 14 15 #include "psu.hpp" 16 17 #include "commands.hpp" 18 #include "errors.hpp" 19 #include "handler.hpp" 20 21 #include <cstdint> 22 #include <cstring> 23 #include <ipmid/api-types.hpp> 24 #include <span> 25 #include <vector> 26 27 namespace google 28 { 29 namespace ipmi 30 { 31 32 Resp psuHardReset(std::span<const uint8_t> data, 33 const HandlerInterface* handler) 34 { 35 struct PsuResetRequest request; 36 37 if (data.size() < sizeof(request)) 38 { 39 std::fprintf(stderr, "Invalid command length: %u\n", 40 static_cast<uint32_t>(data.size())); 41 return ::ipmi::responseReqDataLenInvalid(); 42 } 43 44 std::memcpy(&request, data.data(), sizeof(struct PsuResetRequest)); 45 try 46 { 47 handler->psuResetDelay(request.delay); 48 } 49 catch (const IpmiException& e) 50 { 51 return ::ipmi::response(e.getIpmiError()); 52 } 53 54 return ::ipmi::responseSuccess(SysOEMCommands::SysPsuHardReset, 55 std::vector<uint8_t>{}); 56 } 57 58 Resp psuHardResetOnShutdown(std::span<const uint8_t>, 59 const HandlerInterface* handler) 60 { 61 try 62 { 63 handler->psuResetOnShutdown(); 64 } 65 catch (const IpmiException& e) 66 { 67 return ::ipmi::response(e.getIpmiError()); 68 } 69 70 return ::ipmi::responseSuccess(SysOEMCommands::SysPsuHardResetOnShutdown, 71 std::vector<uint8_t>{}); 72 } 73 74 } // namespace ipmi 75 } // namespace google 76