blob: 5b41c05c9a69adf77f93bc34c517f93bcf1585cf [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
Patrick Williams0efeb172022-07-22 19:26:56 -050016void setAttention(sdbusplus::message_t& m, stdplus::Fd& kcs)
William A. Kennington III03e6def2021-05-11 15:23:15 -070017{
18 stdplus::fd::ioctl(kcs, IPMI_BMC_IOCTL_SET_SMS_ATN, nullptr);
19 m.new_method_return().method_return();
20}
21
Patrick Williams0efeb172022-07-22 19:26:56 -050022void clearAttention(sdbusplus::message_t& m, stdplus::Fd& kcs)
William A. Kennington III03e6def2021-05-11 15:23:15 -070023{
24 stdplus::fd::ioctl(kcs, IPMI_BMC_IOCTL_CLEAR_SMS_ATN, nullptr);
25 m.new_method_return().method_return();
26}
27
Patrick Williams0efeb172022-07-22 19:26:56 -050028void forceAbort(sdbusplus::message_t& m, stdplus::Fd& kcs)
William A. Kennington III03e6def2021-05-11 15:23:15 -070029{
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{
Patrick Williams0efeb172022-07-22 19:26:56 -050037 sdbusplus::message_t m(mptr);
William A. Kennington III03e6def2021-05-11 15:23:15 -070038 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
Patrick Williams0efeb172022-07-22 19:26:56 -050064sdbusplus::server::interface::interface createSMSHandler(sdbusplus::bus_t& bus,
65 const char* obj,
66 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