Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "config.h" |
| 4 | |
| 5 | #include "file_io_by_type.hpp" |
| 6 | |
Adriana Kobylak | 6876f12 | 2019-12-12 09:49:56 -0600 | [diff] [blame] | 7 | #include <filesystem> |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 8 | #include <sstream> |
| 9 | #include <string> |
| 10 | |
| 11 | namespace pldm |
| 12 | { |
| 13 | namespace responder |
| 14 | { |
| 15 | |
| 16 | using namespace pldm::responder::dma; |
Adriana Kobylak | 6876f12 | 2019-12-12 09:49:56 -0600 | [diff] [blame] | 17 | namespace fs = std::filesystem; |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 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 | { |
Adriana Kobylak | 76f820c | 2020-07-16 11:02:03 -0500 | [diff] [blame] | 31 | std::string dir = permSide ? LID_ALTERNATE_DIR : LID_RUNNING_DIR; |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 32 | std::stringstream stream; |
| 33 | stream << std::hex << fileHandle; |
Adriana Kobylak | 6876f12 | 2019-12-12 09:49:56 -0600 | [diff] [blame] | 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 | } |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 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 | |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 52 | virtual int readIntoMemory(uint32_t offset, uint32_t& length, |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 53 | uint64_t address) |
| 54 | { |
| 55 | return transferFileData(lidPath, true, offset, length, address); |
| 56 | } |
| 57 | |
Sampa Misra | 1896716 | 2020-01-14 02:31:41 -0600 | [diff] [blame] | 58 | virtual int write(const char* /*buffer*/, uint32_t /*offset*/, |
| 59 | uint32_t& /*length*/) |
| 60 | { |
| 61 | return PLDM_ERROR_UNSUPPORTED_PLDM_CMD; |
| 62 | } |
| 63 | |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 64 | virtual int read(uint32_t offset, uint32_t& length, Response& response) |
| 65 | { |
| 66 | return readFile(lidPath, offset, length, response); |
| 67 | } |
| 68 | |
Deepak Kodihalli | 2da1bfe | 2019-12-14 08:28:09 -0600 | [diff] [blame] | 69 | virtual int fileAck(uint8_t /*fileStatus*/) |
| 70 | { |
| 71 | return PLDM_ERROR_UNSUPPORTED_PLDM_CMD; |
| 72 | } |
| 73 | |
Sampa Misra | 1896716 | 2020-01-14 02:31:41 -0600 | [diff] [blame] | 74 | virtual int newFileAvailable(uint64_t /*length*/) |
| 75 | |
| 76 | { |
| 77 | return PLDM_ERROR_UNSUPPORTED_PLDM_CMD; |
| 78 | } |
| 79 | |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 80 | /** @brief LidHandler destructor |
| 81 | */ |
| 82 | ~LidHandler() |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 83 | {} |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 84 | |
| 85 | protected: |
| 86 | std::string lidPath; |
| 87 | }; |
| 88 | |
| 89 | } // namespace responder |
| 90 | } // namespace pldm |