blob: a3a1b471db348d81fd538830fb0bead3e567b583 [file] [log] [blame]
William A. Kennington III03e6def2021-05-11 15:23:15 -07001#include "server.hpp"
2
Patrick Williamse0602aa2023-07-17 11:20:00 -05003#include "print.hpp"
4
William A. Kennington III03e6def2021-05-11 15:23:15 -07005#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 Williamse0602aa2023-07-17 11:20:00 -050012#include <cstdio>
William A. Kennington III03e6def2021-05-11 15:23:15 -070013#include <stdexcept>
14
15namespace kcsbridge
16{
17
Patrick Williams0efeb172022-07-22 19:26:56 -050018void setAttention(sdbusplus::message_t& m, stdplus::Fd& kcs)
William A. Kennington III03e6def2021-05-11 15:23:15 -070019{
20 stdplus::fd::ioctl(kcs, IPMI_BMC_IOCTL_SET_SMS_ATN, nullptr);
21 m.new_method_return().method_return();
22}
23
Patrick Williams0efeb172022-07-22 19:26:56 -050024void clearAttention(sdbusplus::message_t& m, stdplus::Fd& kcs)
William A. Kennington III03e6def2021-05-11 15:23:15 -070025{
26 stdplus::fd::ioctl(kcs, IPMI_BMC_IOCTL_CLEAR_SMS_ATN, nullptr);
27 m.new_method_return().method_return();
28}
29
Patrick Williams0efeb172022-07-22 19:26:56 -050030void forceAbort(sdbusplus::message_t& m, stdplus::Fd& kcs)
William A. Kennington III03e6def2021-05-11 15:23:15 -070031{
32 stdplus::fd::ioctl(kcs, IPMI_BMC_IOCTL_FORCE_ABORT, nullptr);
33 m.new_method_return().method_return();
34}
35
36template <auto func, typename Data>
37int methodRsp(sd_bus_message* mptr, void* dataptr, sd_bus_error* error) noexcept
38{
Patrick Williams0efeb172022-07-22 19:26:56 -050039 sdbusplus::message_t m(mptr);
William A. Kennington III03e6def2021-05-11 15:23:15 -070040 try
41 {
42 func(m, *reinterpret_cast<Data*>(dataptr));
43 }
44 catch (const std::exception& e)
45 {
Patrick Williamse0602aa2023-07-17 11:20:00 -050046 std::print(stderr, "Method response failed: {}\n", e.what());
William A. Kennington III03e6def2021-05-11 15:23:15 -070047 sd_bus_error_set(error,
48 "xyz.openbmc_project.Common.Error.InternalFailure",
49 "The operation failed internally.");
50 }
51 return 1;
52}
53
54template <typename Data>
55constexpr 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 Williams4bf990a2024-08-16 15:21:15 -040066sdbusplus::server::interface::interface createSMSHandler(
67 sdbusplus::bus_t& bus, const char* obj, stdplus::Fd& kcs)
William A. Kennington III03e6def2021-05-11 15:23:15 -070068{
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