blob: 3acf883a1aa11c3f3c1fd33ee298ac90d6e40b47 [file] [log] [blame]
Deepak Kodihallif6d3a832019-11-19 07:00:29 -06001#pragma once
2
3#include "config.h"
4
5#include "file_io_by_type.hpp"
6
Adriana Kobylak6876f122019-12-12 09:49:56 -06007#include <filesystem>
Deepak Kodihallif6d3a832019-11-19 07:00:29 -06008#include <sstream>
9#include <string>
10
11namespace pldm
12{
13namespace responder
14{
15
16using namespace pldm::responder::dma;
Adriana Kobylak6876f122019-12-12 09:49:56 -060017namespace fs = std::filesystem;
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060018
19/** @class LidHandler
20 *
21 * @brief Inherits and implements FileHandler. This class is used
22 * to read/write LIDs.
23 */
24class LidHandler : public FileHandler
25{
26 public:
27 /** @brief LidHandler constructor
28 */
29 LidHandler(uint32_t fileHandle, bool permSide) : FileHandler(fileHandle)
30 {
Adriana Kobylak76f820c2020-07-16 11:02:03 -050031 std::string dir = permSide ? LID_ALTERNATE_DIR : LID_RUNNING_DIR;
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060032 std::stringstream stream;
33 stream << std::hex << fileHandle;
Adriana Kobylak6876f122019-12-12 09:49:56 -060034 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 }
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060044 }
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
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060052 virtual int readIntoMemory(uint32_t offset, uint32_t& length,
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060053 uint64_t address)
54 {
55 return transferFileData(lidPath, true, offset, length, address);
56 }
57
Sampa Misra18967162020-01-14 02:31:41 -060058 virtual int write(const char* /*buffer*/, uint32_t /*offset*/,
59 uint32_t& /*length*/)
60 {
61 return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
62 }
63
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060064 virtual int read(uint32_t offset, uint32_t& length, Response& response)
65 {
66 return readFile(lidPath, offset, length, response);
67 }
68
Deepak Kodihalli2da1bfe2019-12-14 08:28:09 -060069 virtual int fileAck(uint8_t /*fileStatus*/)
70 {
71 return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
72 }
73
Sampa Misra18967162020-01-14 02:31:41 -060074 virtual int newFileAvailable(uint64_t /*length*/)
75
76 {
77 return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
78 }
79
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060080 /** @brief LidHandler destructor
81 */
82 ~LidHandler()
George Liu6492f522020-06-16 10:34:05 +080083 {}
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060084
85 protected:
86 std::string lidPath;
87};
88
89} // namespace responder
90} // namespace pldm