blob: eb6b48efd64db3a4cf9a3bdef99442a3262b97ad [file] [log] [blame]
Potin Laid96e2702024-05-23 23:21:46 +08001#include <commandutils.hpp>
2#include <groupextcommands.hpp>
3#include <ipmid/api-types.hpp>
4#include <ipmid/api.hpp>
5#include <phosphor-logging/lg2.hpp>
6
7namespace ipmi
8{
9
10PHOSPHOR_LOG2_USING;
11
12uint64_t bigEndianToHost(uint64_t bigEndianValue)
13{
14 if (std::endian::native == std::endian::little)
15 {
16 return std::byteswap(bigEndianValue);
17 }
18
19 return bigEndianValue;
20}
21
22void registerSBMRFunctions() __attribute__((constructor));
23
24ipmi::RspType<> ipmiSBMRSendBootProgress(ipmi::Context::ptr ctx,
25 std::vector<uint8_t> data)
26{
Cosmo Chou5e18a702024-10-06 09:27:15 +080027 using postcode_t = std::tuple<std::vector<uint8_t>, std::vector<uint8_t>>;
Potin Laid96e2702024-05-23 23:21:46 +080028
29 std::optional<size_t> hostId = findHost(ctx->hostIdx);
30
31 if (!hostId)
32 {
33 error("Invalid Host Id received");
34 return ipmi::responseInvalidCommand();
35 }
36
37 if (data.size() != 9)
38 {
39 error("Invalid request of boot progress length received: {LENGTH}",
40 "LENGTH", data.size());
41 return ipmi::responseReqDataLenInvalid();
42 }
43
44 try
45 {
Cosmo Chou5e18a702024-10-06 09:27:15 +080046 postcode_t postCode(std::move(data), {});
Potin Laid96e2702024-05-23 23:21:46 +080047 auto conn = getSdBus();
Patrick Williams33803b42024-08-27 08:03:35 -040048 auto hostbootRawObj =
49 std::string(bootRawObjPrefix) + std::to_string(*hostId);
Potin Laid96e2702024-05-23 23:21:46 +080050 auto method =
51 conn->new_method_call(bootRawBusName, hostbootRawObj.data(),
52 "org.freedesktop.DBus.Properties", "Set");
53
Cosmo Chou5e18a702024-10-06 09:27:15 +080054 method.append(bootRawIntf, "Value",
55 std::variant<postcode_t>(std::move(postCode)));
Potin Laid96e2702024-05-23 23:21:46 +080056
57 conn->call_noreply(method);
58 }
59 catch (std::exception& e)
60 {
61 error("postcode handler error: {ERROR}", "ERROR", e);
62 return ipmi::responseResponseError();
63 }
64
65 return ipmi::responseSuccess();
66}
67
68void registerSBMRFunctions()
69{
70 ipmi::registerGroupHandler(
71 ipmi::prioOemBase, ipmi::groupSBMR, ipmi::sbmr::cmdSendBootProgress,
72 ipmi::Privilege::Admin, ipmiSBMRSendBootProgress);
73 return;
74}
75
76} // end of namespace ipmi