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