William A. Kennington III | 03e6def | 2021-05-11 15:23:15 -0700 | [diff] [blame] | 1 | #include "server.hpp" |
| 2 | |
Patrick Williams | e0602aa | 2023-07-17 11:20:00 -0500 | [diff] [blame] | 3 | #include "print.hpp" |
| 4 | |
William A. Kennington III | 03e6def | 2021-05-11 15:23:15 -0700 | [diff] [blame] | 5 | #include <linux/ipmi_bmc.h> |
| 6 | |
| 7 | #include <sdbusplus/exception.hpp> |
| 8 | #include <sdbusplus/server/interface.hpp> |
| 9 | #include <sdbusplus/vtable.hpp> |
| 10 | #include <stdplus/fd/ops.hpp> |
| 11 | |
Patrick Williams | e0602aa | 2023-07-17 11:20:00 -0500 | [diff] [blame] | 12 | #include <cstdio> |
William A. Kennington III | 03e6def | 2021-05-11 15:23:15 -0700 | [diff] [blame] | 13 | #include <stdexcept> |
| 14 | |
| 15 | namespace kcsbridge |
| 16 | { |
| 17 | |
Patrick Williams | 0efeb17 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 18 | void setAttention(sdbusplus::message_t& m, stdplus::Fd& kcs) |
William A. Kennington III | 03e6def | 2021-05-11 15:23:15 -0700 | [diff] [blame] | 19 | { |
| 20 | stdplus::fd::ioctl(kcs, IPMI_BMC_IOCTL_SET_SMS_ATN, nullptr); |
| 21 | m.new_method_return().method_return(); |
| 22 | } |
| 23 | |
Patrick Williams | 0efeb17 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 24 | void clearAttention(sdbusplus::message_t& m, stdplus::Fd& kcs) |
William A. Kennington III | 03e6def | 2021-05-11 15:23:15 -0700 | [diff] [blame] | 25 | { |
| 26 | stdplus::fd::ioctl(kcs, IPMI_BMC_IOCTL_CLEAR_SMS_ATN, nullptr); |
| 27 | m.new_method_return().method_return(); |
| 28 | } |
| 29 | |
Patrick Williams | 0efeb17 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 30 | void forceAbort(sdbusplus::message_t& m, stdplus::Fd& kcs) |
William A. Kennington III | 03e6def | 2021-05-11 15:23:15 -0700 | [diff] [blame] | 31 | { |
| 32 | stdplus::fd::ioctl(kcs, IPMI_BMC_IOCTL_FORCE_ABORT, nullptr); |
| 33 | m.new_method_return().method_return(); |
| 34 | } |
| 35 | |
| 36 | template <auto func, typename Data> |
| 37 | int methodRsp(sd_bus_message* mptr, void* dataptr, sd_bus_error* error) noexcept |
| 38 | { |
Patrick Williams | 0efeb17 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 39 | sdbusplus::message_t m(mptr); |
William A. Kennington III | 03e6def | 2021-05-11 15:23:15 -0700 | [diff] [blame] | 40 | try |
| 41 | { |
| 42 | func(m, *reinterpret_cast<Data*>(dataptr)); |
| 43 | } |
| 44 | catch (const std::exception& e) |
| 45 | { |
Patrick Williams | e0602aa | 2023-07-17 11:20:00 -0500 | [diff] [blame] | 46 | std::print(stderr, "Method response failed: {}\n", e.what()); |
William A. Kennington III | 03e6def | 2021-05-11 15:23:15 -0700 | [diff] [blame] | 47 | sd_bus_error_set(error, |
| 48 | "xyz.openbmc_project.Common.Error.InternalFailure", |
| 49 | "The operation failed internally."); |
| 50 | } |
| 51 | return 1; |
| 52 | } |
| 53 | |
| 54 | template <typename Data> |
| 55 | constexpr sdbusplus::vtable::vtable_t dbusMethods[] = { |
| 56 | sdbusplus::vtable::start(), |
| 57 | sdbusplus::vtable::method("setAttention", "", "", |
| 58 | methodRsp<setAttention, Data>), |
| 59 | sdbusplus::vtable::method("clearAttention", "", "", |
| 60 | methodRsp<clearAttention, Data>), |
| 61 | sdbusplus::vtable::method("forceAbort", "", "", |
| 62 | methodRsp<forceAbort, Data>), |
| 63 | sdbusplus::vtable::end(), |
| 64 | }; |
| 65 | |
Patrick Williams | 4bf990a | 2024-08-16 15:21:15 -0400 | [diff] [blame^] | 66 | sdbusplus::server::interface::interface createSMSHandler( |
| 67 | sdbusplus::bus_t& bus, const char* obj, stdplus::Fd& kcs) |
William A. Kennington III | 03e6def | 2021-05-11 15:23:15 -0700 | [diff] [blame] | 68 | { |
| 69 | return sdbusplus::server::interface::interface( |
| 70 | bus, obj, "xyz.openbmc_project.Ipmi.Channel.SMS", |
| 71 | dbusMethods<stdplus::Fd>, reinterpret_cast<stdplus::Fd*>(&kcs)); |
| 72 | } |
| 73 | |
| 74 | } // namespace kcsbridge |