blob: ed67d82db2e54ebfc335dad8985a578af3a9eae0 [file] [log] [blame]
William A. Kennington III03e6def2021-05-11 15:23:15 -07001#include "server.hpp"
2
William A. Kennington III03e6def2021-05-11 15:23:15 -07003#include <linux/ipmi_bmc.h>
4
5#include <sdbusplus/exception.hpp>
6#include <sdbusplus/server/interface.hpp>
7#include <sdbusplus/vtable.hpp>
8#include <stdplus/fd/ops.hpp>
Patrick Williamsc0c95be2024-08-19 16:02:44 -04009#include <stdplus/print.hpp>
William A. Kennington III03e6def2021-05-11 15:23:15 -070010
Patrick Williamse0602aa2023-07-17 11:20:00 -050011#include <cstdio>
William A. Kennington III03e6def2021-05-11 15:23:15 -070012#include <stdexcept>
13
14namespace kcsbridge
15{
16
Patrick Williams0efeb172022-07-22 19:26:56 -050017void setAttention(sdbusplus::message_t& m, stdplus::Fd& kcs)
William A. Kennington III03e6def2021-05-11 15:23:15 -070018{
19 stdplus::fd::ioctl(kcs, IPMI_BMC_IOCTL_SET_SMS_ATN, nullptr);
20 m.new_method_return().method_return();
21}
22
Patrick Williams0efeb172022-07-22 19:26:56 -050023void clearAttention(sdbusplus::message_t& m, stdplus::Fd& kcs)
William A. Kennington III03e6def2021-05-11 15:23:15 -070024{
25 stdplus::fd::ioctl(kcs, IPMI_BMC_IOCTL_CLEAR_SMS_ATN, nullptr);
26 m.new_method_return().method_return();
27}
28
Patrick Williams0efeb172022-07-22 19:26:56 -050029void forceAbort(sdbusplus::message_t& m, stdplus::Fd& kcs)
William A. Kennington III03e6def2021-05-11 15:23:15 -070030{
31 stdplus::fd::ioctl(kcs, IPMI_BMC_IOCTL_FORCE_ABORT, nullptr);
32 m.new_method_return().method_return();
33}
34
35template <auto func, typename Data>
36int methodRsp(sd_bus_message* mptr, void* dataptr, sd_bus_error* error) noexcept
37{
Patrick Williams0efeb172022-07-22 19:26:56 -050038 sdbusplus::message_t m(mptr);
William A. Kennington III03e6def2021-05-11 15:23:15 -070039 try
40 {
41 func(m, *reinterpret_cast<Data*>(dataptr));
42 }
43 catch (const std::exception& e)
44 {
Patrick Williamsc0c95be2024-08-19 16:02:44 -040045 stdplus::print(stderr, "Method response failed: {}\n", e.what());
William A. Kennington III03e6def2021-05-11 15:23:15 -070046 sd_bus_error_set(error,
47 "xyz.openbmc_project.Common.Error.InternalFailure",
48 "The operation failed internally.");
49 }
50 return 1;
51}
52
53template <typename Data>
54constexpr sdbusplus::vtable::vtable_t dbusMethods[] = {
55 sdbusplus::vtable::start(),
56 sdbusplus::vtable::method("setAttention", "", "",
57 methodRsp<setAttention, Data>),
58 sdbusplus::vtable::method("clearAttention", "", "",
59 methodRsp<clearAttention, Data>),
60 sdbusplus::vtable::method("forceAbort", "", "",
61 methodRsp<forceAbort, Data>),
62 sdbusplus::vtable::end(),
63};
64
Patrick Williams4bf990a2024-08-16 15:21:15 -040065sdbusplus::server::interface::interface createSMSHandler(
66 sdbusplus::bus_t& bus, const char* obj, stdplus::Fd& kcs)
William A. Kennington III03e6def2021-05-11 15:23:15 -070067{
68 return sdbusplus::server::interface::interface(
69 bus, obj, "xyz.openbmc_project.Ipmi.Channel.SMS",
70 dbusMethods<stdplus::Fd>, reinterpret_cast<stdplus::Fd*>(&kcs));
71}
72
73} // namespace kcsbridge