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