1 #include "file_io_type_progress_src.hpp"
2 
3 #include "common/utils.hpp"
4 
5 #include <phosphor-logging/lg2.hpp>
6 
7 PHOSPHOR_LOG2_USING;
8 
9 namespace pldm
10 {
11 
12 namespace responder
13 {
14 
setRawBootProperty(const std::tuple<uint64_t,std::vector<uint8_t>> & progressCodeBuffer)15 int 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 = pldm::utils::DBusHandler().getService(RawObjectPath,
31                                                              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, dbusTimeout);
39     }
40     catch (const std::exception& e)
41     {
42         error(
43             "Failed to make a d-bus call to host-postd daemon, error - {ERROR}",
44             "ERROR", e);
45         return PLDM_ERROR;
46     }
47 
48     return PLDM_SUCCESS;
49 }
50 
write(const char * buffer,uint32_t,uint32_t & length,oem_platform::Handler *)51 int 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 
73         return setRawBootProperty(std::make_tuple(primaryCode, secondaryCode));
74     }
75     return PLDM_ERROR;
76 }
77 
78 } // namespace responder
79 } // namespace pldm
80