Nikhil Namjoshi | 4aa9317 | 2022-09-22 18:51:37 +0000 | [diff] [blame^] | 1 | // Copyright 2022 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. |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 14 | |
| 15 | #include "host_power_off.hpp" |
| 16 | |
| 17 | #include "commands.hpp" |
| 18 | #include "errors.hpp" |
| 19 | #include "handler.hpp" |
| 20 | |
| 21 | #include <cstdint> |
| 22 | #include <cstring> |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 23 | #include <ipmid/api-types.hpp> |
Willy Tu | b4e3704 | 2021-10-12 17:12:30 -0700 | [diff] [blame] | 24 | #include <span> |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 25 | #include <vector> |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 26 | |
| 27 | namespace google |
| 28 | { |
| 29 | namespace ipmi |
| 30 | { |
| 31 | |
Willy Tu | b4e3704 | 2021-10-12 17:12:30 -0700 | [diff] [blame] | 32 | Resp hostPowerOff(std::span<const uint8_t> data, |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 33 | const HandlerInterface* handler) |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 34 | { |
| 35 | struct HostPowerOffRequest request; |
| 36 | |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 37 | if (data.size() < sizeof(request)) |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 38 | { |
| 39 | std::fprintf(stderr, "Invalid command length: %u\n", |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 40 | static_cast<uint32_t>(data.size())); |
| 41 | return ::ipmi::responseReqDataLenInvalid(); |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 44 | std::memcpy(&request, data.data(), sizeof(struct HostPowerOffRequest)); |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 45 | try |
| 46 | { |
| 47 | handler->hostPowerOffDelay(request.delay); |
| 48 | } |
| 49 | catch (const IpmiException& e) |
| 50 | { |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 51 | return ::ipmi::response(e.getIpmiError()); |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 54 | return ::ipmi::responseSuccess(SysOEMCommands::SysHostPowerOff, |
| 55 | std::vector<uint8_t>{}); |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 56 | } |
| 57 | } // namespace ipmi |
| 58 | } // namespace google |