blob: 30861580b06348bc018928829b8e49b00a9e70d2 [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";
Deepak Kodihalli09b017b2020-08-26 07:37:32 -050035 std::string patchDir =
36 permSide ? LID_ALTERNATE_PATCH_DIR : LID_RUNNING_PATCH_DIR;
37 auto patch = fs::path(patchDir) / lidName;
38 if (fs::is_regular_file(patch))
Adriana Kobylak6876f122019-12-12 09:49:56 -060039 {
40 lidPath = patch;
41 }
42 else
43 {
44 lidPath = std::move(dir) + '/' + lidName;
45 }
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060046 }
47
48 virtual int writeFromMemory(uint32_t /*offset*/, uint32_t /*length*/,
49 uint64_t /*address*/)
50 {
51 return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
52 }
53
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060054 virtual int readIntoMemory(uint32_t offset, uint32_t& length,
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060055 uint64_t address)
56 {
57 return transferFileData(lidPath, true, offset, length, address);
58 }
59
Sampa Misra18967162020-01-14 02:31:41 -060060 virtual int write(const char* /*buffer*/, uint32_t /*offset*/,
61 uint32_t& /*length*/)
62 {
63 return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
64 }
65
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060066 virtual int read(uint32_t offset, uint32_t& length, Response& response)
67 {
68 return readFile(lidPath, offset, length, response);
69 }
70
Deepak Kodihalli2da1bfe2019-12-14 08:28:09 -060071 virtual int fileAck(uint8_t /*fileStatus*/)
72 {
73 return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
74 }
75
Sampa Misra18967162020-01-14 02:31:41 -060076 virtual int newFileAvailable(uint64_t /*length*/)
77
78 {
79 return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
80 }
81
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060082 /** @brief LidHandler destructor
83 */
84 ~LidHandler()
George Liu6492f522020-06-16 10:34:05 +080085 {}
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060086
87 protected:
88 std::string lidPath;
89};
90
91} // namespace responder
92} // namespace pldm