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 |
Sampa Misra | 6950850 | 2020-09-08 00:08:21 -0500 | [diff] [blame] | 27 | * @param[in] oemPlatformHandler - oem handler for PLDM platform related |
| 28 | * tasks |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 29 | * @return PLDM status code |
| 30 | */ |
| 31 | virtual int writeFromMemory(uint32_t offset, uint32_t length, |
Sampa Misra | 6950850 | 2020-09-08 00:08:21 -0500 | [diff] [blame] | 32 | uint64_t address, |
| 33 | oem_platform::Handler* oemPlatformHandler) = 0; |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 34 | |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 35 | /** @brief Method to read an oem file type into host memory. Individual |
| 36 | * file types need to override this method to do the file specific |
| 37 | * processing |
| 38 | * @param[in] offset - offset to read |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 39 | * @param[in/out] length - length to be read mentioned by Host |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 40 | * @param[in] address - DMA address |
Sampa Misra | 6950850 | 2020-09-08 00:08:21 -0500 | [diff] [blame] | 41 | * @param[in] oemPlatformHandler - oem handler for PLDM platform related |
| 42 | * tasks |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 43 | * @return PLDM status code |
| 44 | */ |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 45 | virtual int readIntoMemory(uint32_t offset, uint32_t& length, |
Sampa Misra | 6950850 | 2020-09-08 00:08:21 -0500 | [diff] [blame] | 46 | uint64_t address, |
| 47 | oem_platform::Handler* oemPlatformHandler) = 0; |
Deepak Kodihalli | f6d3a83 | 2019-11-19 07:00:29 -0600 | [diff] [blame] | 48 | |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 49 | /** @brief Method to read an oem file type's content into the PLDM response. |
| 50 | * @param[in] offset - offset to read |
| 51 | * @param[in/out] length - length to be read |
| 52 | * @param[in] response - PLDM response |
Sampa Misra | 6950850 | 2020-09-08 00:08:21 -0500 | [diff] [blame] | 53 | * @param[in] oemPlatformHandler - oem handler for PLDM platform related |
| 54 | * tasks |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 55 | * @return PLDM status code |
| 56 | */ |
Sampa Misra | 6950850 | 2020-09-08 00:08:21 -0500 | [diff] [blame] | 57 | virtual int read(uint32_t offset, uint32_t& length, Response& response, |
| 58 | oem_platform::Handler* oemPlatformHandler) = 0; |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 59 | |
Sampa Misra | 1896716 | 2020-01-14 02:31:41 -0600 | [diff] [blame] | 60 | /** @brief Method to write an oem file by type |
| 61 | * @param[in] buffer - buffer to be written to file |
| 62 | * @param[in] offset - offset to write to |
| 63 | * @param[in/out] length - length to be written |
Sampa Misra | 6950850 | 2020-09-08 00:08:21 -0500 | [diff] [blame] | 64 | * @param[in] oemPlatformHandler - oem handler for PLDM platform related |
| 65 | * tasks |
Sampa Misra | 1896716 | 2020-01-14 02:31:41 -0600 | [diff] [blame] | 66 | * @return PLDM status code |
| 67 | */ |
Sampa Misra | 6950850 | 2020-09-08 00:08:21 -0500 | [diff] [blame] | 68 | virtual int write(const char* buffer, uint32_t offset, uint32_t& length, |
| 69 | oem_platform::Handler* oemPlatformHandler) = 0; |
Sampa Misra | 1896716 | 2020-01-14 02:31:41 -0600 | [diff] [blame] | 70 | |
Deepak Kodihalli | 2da1bfe | 2019-12-14 08:28:09 -0600 | [diff] [blame] | 71 | virtual int fileAck(uint8_t fileStatus) = 0; |
| 72 | |
Sampa Misra | 1896716 | 2020-01-14 02:31:41 -0600 | [diff] [blame] | 73 | /** @brief Method to process a new file available notification from the |
| 74 | * host. The bmc can chose to do different actions based on the file type. |
| 75 | * |
| 76 | * @param[in] length - size of the file content to be transferred |
| 77 | * |
| 78 | * @return PLDM status code |
| 79 | */ |
| 80 | virtual int newFileAvailable(uint64_t length) = 0; |
| 81 | |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 82 | /** @brief Method to read an oem file type's content into the PLDM response. |
| 83 | * @param[in] filePath - file to read from |
| 84 | * @param[in] offset - offset to read |
| 85 | * @param[in/out] length - length to be read |
| 86 | * @param[in] response - PLDM response |
| 87 | * @return PLDM status code |
| 88 | */ |
| 89 | virtual int readFile(const std::string& filePath, uint32_t offset, |
| 90 | uint32_t& length, Response& response); |
| 91 | |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 92 | /** @brief Method to do the file content transfer ove DMA between host and |
| 93 | * bmc. This method is made virtual to be overridden in test case. And need |
| 94 | * not be defined in other child classes |
| 95 | * |
| 96 | * @param[in] path - file system path where read/write will be done |
| 97 | * @param[in] upstream - direction of DMA transfer. "false" means a |
| 98 | * transfer from host to BMC |
| 99 | * @param[in] offset - offset to read/write |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 100 | * @param[in/out] length - length to be read/write mentioned by Host |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 101 | * @param[in] address - DMA address |
| 102 | * |
| 103 | * @return PLDM status code |
| 104 | */ |
| 105 | virtual int transferFileData(const fs::path& path, bool upstream, |
Deepak Kodihalli | 75e02f8 | 2019-11-20 02:51:05 -0600 | [diff] [blame] | 106 | uint32_t offset, uint32_t& length, |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 107 | uint64_t address); |
| 108 | |
Deepak Kodihalli | 15211b4 | 2019-12-14 02:24:49 -0600 | [diff] [blame] | 109 | virtual int transferFileData(int fd, bool upstream, uint32_t offset, |
| 110 | uint32_t& length, uint64_t address); |
| 111 | |
Ravi Teja | ce1c96f | 2020-10-05 23:13:01 -0500 | [diff] [blame] | 112 | virtual int transferFileDataToSocket(int fd, uint32_t& length, |
| 113 | uint64_t address); |
| 114 | |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 115 | /** @brief Constructor to create a FileHandler object |
| 116 | */ |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 117 | FileHandler(uint32_t fileHandle) : fileHandle(fileHandle) {} |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 118 | |
| 119 | /** FileHandler destructor |
| 120 | */ |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 121 | virtual ~FileHandler() {} |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 122 | |
| 123 | protected: |
| 124 | uint32_t fileHandle; //!< file handle indicating name of file or invalid |
| 125 | }; |
| 126 | |
| 127 | /** @brief Method to create individual file handler objects based on file type |
| 128 | * |
| 129 | * @param[in] fileType - type of file |
| 130 | * @param[in] fileHandle - file handle |
| 131 | */ |
| 132 | |
| 133 | std::unique_ptr<FileHandler> getHandlerByType(uint16_t fileType, |
| 134 | uint32_t fileHandle); |
Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 135 | } // namespace responder |
| 136 | } // namespace pldm |