Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "file_io.hpp" |
| 4 | |
| 5 | namespace pldm |
| 6 | { |
| 7 | |
| 8 | namespace responder |
| 9 | { |
| 10 | |
| 11 | namespace fs = std::filesystem; |
| 12 | |
| 13 | /** |
| 14 | * @class FileHandler |
| 15 | * |
| 16 | * Base class to handle read/write of all oem file types |
| 17 | */ |
| 18 | class FileHandler |
| 19 | { |
| 20 | public: |
| 21 | /** @brief Method to write an oem file type from host memory. Individual |
| 22 | * file types need to override this method to do the file specific |
| 23 | * processing |
| 24 | * @param[in] offset - offset to read/write |
| 25 | * @param[in] length - length to be read/write mentioned by Host |
| 26 | * @param[in] address - DMA address |
| 27 | * @return PLDM status code |
| 28 | */ |
| 29 | virtual int writeFromMemory(uint32_t offset, uint32_t length, |
| 30 | uint64_t address) = 0; |
| 31 | |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 32 | /** @brief Method to read an oem file type into host memory. Individual |
| 33 | * file types need to override this method to do the file specific |
| 34 | * processing |
| 35 | * @param[in] offset - offset to read |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 36 | * @param[in/out] length - length to be read mentioned by Host |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 37 | * @param[in] address - DMA address |
| 38 | * @return PLDM status code |
| 39 | */ |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 40 | virtual int readIntoMemory(uint32_t offset, uint32_t& length, |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 41 | uint64_t address) = 0; |
| 42 | |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 43 | /** @brief Method to read an oem file type's content into the PLDM response. |
| 44 | * @param[in] offset - offset to read |
| 45 | * @param[in/out] length - length to be read |
| 46 | * @param[in] response - PLDM response |
| 47 | * @return PLDM status code |
| 48 | */ |
| 49 | virtual int read(uint32_t offset, uint32_t& length, Response& response) = 0; |
| 50 | |
Deepak Kodihalli | 2da1bfe | 2019-12-14 08:28:09 -0600 | [diff] [blame] | 51 | virtual int fileAck(uint8_t fileStatus) = 0; |
| 52 | |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 53 | /** @brief Method to read an oem file type's content into the PLDM response. |
| 54 | * @param[in] filePath - file to read from |
| 55 | * @param[in] offset - offset to read |
| 56 | * @param[in/out] length - length to be read |
| 57 | * @param[in] response - PLDM response |
| 58 | * @return PLDM status code |
| 59 | */ |
| 60 | virtual int readFile(const std::string& filePath, uint32_t offset, |
| 61 | uint32_t& length, Response& response); |
| 62 | |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 63 | /** @brief Method to do the file content transfer ove DMA between host and |
| 64 | * bmc. This method is made virtual to be overridden in test case. And need |
| 65 | * not be defined in other child classes |
| 66 | * |
| 67 | * @param[in] path - file system path where read/write will be done |
| 68 | * @param[in] upstream - direction of DMA transfer. "false" means a |
| 69 | * transfer from host to BMC |
| 70 | * @param[in] offset - offset to read/write |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 71 | * @param[in/out] length - length to be read/write mentioned by Host |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 72 | * @param[in] address - DMA address |
| 73 | * |
| 74 | * @return PLDM status code |
| 75 | */ |
| 76 | virtual int transferFileData(const fs::path& path, bool upstream, |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 77 | uint32_t offset, uint32_t& length, |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 78 | uint64_t address); |
| 79 | |
Deepak Kodihalli | 15211b4 | 2019-12-14 02:24:49 -0600 | [diff] [blame] | 80 | virtual int transferFileData(int fd, bool upstream, uint32_t offset, |
| 81 | uint32_t& length, uint64_t address); |
| 82 | |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 83 | /** @brief Constructor to create a FileHandler object |
| 84 | */ |
| 85 | FileHandler(uint32_t fileHandle) : fileHandle(fileHandle) |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | /** FileHandler destructor |
| 90 | */ |
| 91 | virtual ~FileHandler() |
| 92 | { |
| 93 | } |
| 94 | |
| 95 | protected: |
| 96 | uint32_t fileHandle; //!< file handle indicating name of file or invalid |
| 97 | }; |
| 98 | |
| 99 | /** @brief Method to create individual file handler objects based on file type |
| 100 | * |
| 101 | * @param[in] fileType - type of file |
| 102 | * @param[in] fileHandle - file handle |
| 103 | */ |
| 104 | |
| 105 | std::unique_ptr<FileHandler> getHandlerByType(uint16_t fileType, |
| 106 | uint32_t fileHandle); |
| 107 | |
| 108 | } // namespace responder |
| 109 | } // namespace pldm |