1 #pragma once
2 
3 #include "config.h"
4 
5 #include "file_io_by_type.hpp"
6 
7 #include <filesystem>
8 #include <sstream>
9 #include <string>
10 
11 namespace pldm
12 {
13 namespace responder
14 {
15 
16 using namespace pldm::responder::dma;
17 namespace fs = std::filesystem;
18 
19 /** @class LidHandler
20  *
21  *  @brief Inherits and implements FileHandler. This class is used
22  *  to read/write LIDs.
23  */
24 class LidHandler : public FileHandler
25 {
26   public:
27     /** @brief LidHandler constructor
28      */
29     LidHandler(uint32_t fileHandle, bool permSide) : FileHandler(fileHandle)
30     {
31         std::string dir = permSide ? LID_ALTERNATE_DIR : LID_RUNNING_DIR;
32         std::stringstream stream;
33         stream << std::hex << fileHandle;
34         auto lidName = stream.str() + ".lid";
35         auto patch = fs::path(LID_PATCH_DIR) / lidName;
36         if (fs::is_regular_file(patch))
37         {
38             lidPath = patch;
39         }
40         else
41         {
42             lidPath = std::move(dir) + '/' + lidName;
43         }
44     }
45 
46     virtual int writeFromMemory(uint32_t /*offset*/, uint32_t /*length*/,
47                                 uint64_t /*address*/)
48     {
49         return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
50     }
51 
52     virtual int readIntoMemory(uint32_t offset, uint32_t& length,
53                                uint64_t address)
54     {
55         return transferFileData(lidPath, true, offset, length, address);
56     }
57 
58     virtual int write(const char* /*buffer*/, uint32_t /*offset*/,
59                       uint32_t& /*length*/)
60     {
61         return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
62     }
63 
64     virtual int read(uint32_t offset, uint32_t& length, Response& response)
65     {
66         return readFile(lidPath, offset, length, response);
67     }
68 
69     virtual int fileAck(uint8_t /*fileStatus*/)
70     {
71         return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
72     }
73 
74     virtual int newFileAvailable(uint64_t /*length*/)
75 
76     {
77         return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
78     }
79 
80     /** @brief LidHandler destructor
81      */
82     ~LidHandler()
83     {}
84 
85   protected:
86     std::string lidPath;
87 };
88 
89 } // namespace responder
90 } // namespace pldm
91