blob: 836a840e59837f968dc7d6b6824bbd5bd6a8d2fe [file] [log] [blame]
Manojkiran Edad94bb832021-02-17 11:40:22 +05301#include "file_io_type_progress_src.hpp"
2
3#include "common/utils.hpp"
4
Manojkiran Edad94bb832021-02-17 11:40:22 +05305namespace pldm
6{
7
8namespace responder
9{
10
11int ProgressCodeHandler::setRawBootProperty(
12 const std::tuple<uint64_t, std::vector<uint8_t>>& progressCodeBuffer)
13{
14 static constexpr auto RawObjectPath =
15 "/xyz/openbmc_project/state/boot/raw0";
16 static constexpr auto RawInterface = "xyz.openbmc_project.State.Boot.Raw";
17 static constexpr auto FreedesktopInterface =
18 "org.freedesktop.DBus.Properties";
19 static constexpr auto RawProperty = "Value";
20 static constexpr auto SetMethod = "Set";
21
22 auto& bus = pldm::utils::DBusHandler::getBus();
23
24 try
25 {
26 auto service =
27 pldm::utils::DBusHandler().getService(RawObjectPath, RawInterface);
28 auto method = bus.new_method_call(service.c_str(), RawObjectPath,
29 FreedesktopInterface, SetMethod);
30 method.append(RawInterface, RawProperty,
31 std::variant<std::tuple<uint64_t, std::vector<uint8_t>>>(
32 progressCodeBuffer));
33
34 bus.call_noreply(method);
35 }
36 catch (const std::exception& e)
37 {
38 std::cerr << "failed to make a d-bus call to host-postd daemon, ERROR="
39 << e.what() << "\n";
40 return PLDM_ERROR;
41 }
42
43 return PLDM_SUCCESS;
44}
45
46int ProgressCodeHandler::write(const char* buffer, uint32_t /*offset*/,
47 uint32_t& length,
48 oem_platform::Handler* /*oemPlatformHandler*/)
49{
50 static constexpr auto StartOffset = 40;
51 static constexpr auto EndOffset = 48;
52 if (buffer != nullptr)
53 {
54 // read the data from the pointed location
55 std::vector<uint8_t> secondaryCode(buffer, buffer + length);
56
57 // Get the primary code from the offset 40 bytes in the received buffer
58
59 std::vector<uint8_t> primaryCodeArray(
60 secondaryCode.begin() + StartOffset,
61 secondaryCode.begin() + EndOffset);
62 uint64_t primaryCode = 0;
63
64 // form a uint64_t using uint8_t[8]
65 for (int i = 0; i < 8; i++)
66 primaryCode |= (uint64_t)primaryCodeArray[i] << 8 * i;
67
Manojkiran Edad94bb832021-02-17 11:40:22 +053068 return setRawBootProperty(std::make_tuple(primaryCode, secondaryCode));
69 }
70 return PLDM_ERROR;
71}
72
73} // namespace responder
74} // namespace pldm