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 | |
Sampa Misra | 1896716 | 2020-01-14 02:31:41 -0600 | [diff] [blame] | 51 | /** @brief Method to write an oem file by type |
| 52 | * @param[in] buffer - buffer to be written to file |
| 53 | * @param[in] offset - offset to write to |
| 54 | * @param[in/out] length - length to be written |
| 55 | * @return PLDM status code |
| 56 | */ |
| 57 | virtual int write(const char* buffer, uint32_t offset, |
| 58 | uint32_t& length) = 0; |
| 59 | |
Deepak Kodihalli | 2da1bfe | 2019-12-14 08:28:09 -0600 | [diff] [blame] | 60 | virtual int fileAck(uint8_t fileStatus) = 0; |
| 61 | |
Sampa Misra | 1896716 | 2020-01-14 02:31:41 -0600 | [diff] [blame] | 62 | /** @brief Method to process a new file available notification from the |
| 63 | * host. The bmc can chose to do different actions based on the file type. |
| 64 | * |
| 65 | * @param[in] length - size of the file content to be transferred |
| 66 | * |
| 67 | * @return PLDM status code |
| 68 | */ |
| 69 | virtual int newFileAvailable(uint64_t length) = 0; |
| 70 | |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 71 | /** @brief Method to read an oem file type's content into the PLDM response. |
| 72 | * @param[in] filePath - file to read from |
| 73 | * @param[in] offset - offset to read |
| 74 | * @param[in/out] length - length to be read |
| 75 | * @param[in] response - PLDM response |
| 76 | * @return PLDM status code |
| 77 | */ |
| 78 | virtual int readFile(const std::string& filePath, uint32_t offset, |
| 79 | uint32_t& length, Response& response); |
| 80 | |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 81 | /** @brief Method to do the file content transfer ove DMA between host and |
| 82 | * bmc. This method is made virtual to be overridden in test case. And need |
| 83 | * not be defined in other child classes |
| 84 | * |
| 85 | * @param[in] path - file system path where read/write will be done |
| 86 | * @param[in] upstream - direction of DMA transfer. "false" means a |
| 87 | * transfer from host to BMC |
| 88 | * @param[in] offset - offset to read/write |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 89 | * @param[in/out] length - length to be read/write mentioned by Host |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 90 | * @param[in] address - DMA address |
| 91 | * |
| 92 | * @return PLDM status code |
| 93 | */ |
| 94 | virtual int transferFileData(const fs::path& path, bool upstream, |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 95 | uint32_t offset, uint32_t& length, |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 96 | uint64_t address); |
| 97 | |
Deepak Kodihalli | 15211b4 | 2019-12-14 02:24:49 -0600 | [diff] [blame] | 98 | virtual int transferFileData(int fd, bool upstream, uint32_t offset, |
| 99 | uint32_t& length, uint64_t address); |
| 100 | |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 101 | /** @brief Constructor to create a FileHandler object |
| 102 | */ |
| 103 | FileHandler(uint32_t fileHandle) : fileHandle(fileHandle) |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 104 | {} |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 105 | |
| 106 | /** FileHandler destructor |
| 107 | */ |
| 108 | virtual ~FileHandler() |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 109 | {} |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 110 | |
| 111 | protected: |
| 112 | uint32_t fileHandle; //!< file handle indicating name of file or invalid |
| 113 | }; |
| 114 | |
| 115 | /** @brief Method to create individual file handler objects based on file type |
| 116 | * |
| 117 | * @param[in] fileType - type of file |
| 118 | * @param[in] fileHandle - file handle |
| 119 | */ |
| 120 | |
| 121 | std::unique_ptr<FileHandler> getHandlerByType(uint16_t fileType, |
| 122 | uint32_t fileHandle); |
| 123 | |
| 124 | } // namespace responder |
| 125 | } // namespace pldm |