blob: 502dbae6a2bd07a37cb895d3a13ec4b62afa977e [file] [log] [blame]
Sampa Misra854e61f2019-08-22 04:36:47 -05001#pragma once
2
3#include "file_io.hpp"
4
5namespace pldm
6{
7
8namespace responder
9{
10
11namespace fs = std::filesystem;
12
13/**
14 * @class FileHandler
15 *
16 * Base class to handle read/write of all oem file types
17 */
18class 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 Misra69508502020-09-08 00:08:21 -050027 * @param[in] oemPlatformHandler - oem handler for PLDM platform related
28 * tasks
Sampa Misra854e61f2019-08-22 04:36:47 -050029 * @return PLDM status code
30 */
31 virtual int writeFromMemory(uint32_t offset, uint32_t length,
Sampa Misra69508502020-09-08 00:08:21 -050032 uint64_t address,
33 oem_platform::Handler* oemPlatformHandler) = 0;
Sampa Misra854e61f2019-08-22 04:36:47 -050034
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060035 /** @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 Kodihalli75e02f82019-11-20 02:51:05 -060039 * @param[in/out] length - length to be read mentioned by Host
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060040 * @param[in] address - DMA address
Sampa Misra69508502020-09-08 00:08:21 -050041 * @param[in] oemPlatformHandler - oem handler for PLDM platform related
42 * tasks
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060043 * @return PLDM status code
44 */
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060045 virtual int readIntoMemory(uint32_t offset, uint32_t& length,
Sampa Misra69508502020-09-08 00:08:21 -050046 uint64_t address,
47 oem_platform::Handler* oemPlatformHandler) = 0;
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060048
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060049 /** @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 Misra69508502020-09-08 00:08:21 -050053 * @param[in] oemPlatformHandler - oem handler for PLDM platform related
54 * tasks
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060055 * @return PLDM status code
56 */
Sampa Misra69508502020-09-08 00:08:21 -050057 virtual int read(uint32_t offset, uint32_t& length, Response& response,
58 oem_platform::Handler* oemPlatformHandler) = 0;
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060059
Sampa Misra18967162020-01-14 02:31:41 -060060 /** @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 Misra69508502020-09-08 00:08:21 -050064 * @param[in] oemPlatformHandler - oem handler for PLDM platform related
65 * tasks
Sampa Misra18967162020-01-14 02:31:41 -060066 * @return PLDM status code
67 */
Sampa Misra69508502020-09-08 00:08:21 -050068 virtual int write(const char* buffer, uint32_t offset, uint32_t& length,
69 oem_platform::Handler* oemPlatformHandler) = 0;
Sampa Misra18967162020-01-14 02:31:41 -060070
Deepak Kodihalli2da1bfe2019-12-14 08:28:09 -060071 virtual int fileAck(uint8_t fileStatus) = 0;
72
Sampa Misra18967162020-01-14 02:31:41 -060073 /** @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 Kodihalli75e02f82019-11-20 02:51:05 -060082 /** @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 Misra854e61f2019-08-22 04:36:47 -050092 /** @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 Kodihalli75e02f82019-11-20 02:51:05 -0600100 * @param[in/out] length - length to be read/write mentioned by Host
Sampa Misra854e61f2019-08-22 04:36:47 -0500101 * @param[in] address - DMA address
102 *
103 * @return PLDM status code
104 */
105 virtual int transferFileData(const fs::path& path, bool upstream,
Deepak Kodihalli75e02f82019-11-20 02:51:05 -0600106 uint32_t offset, uint32_t& length,
Sampa Misra854e61f2019-08-22 04:36:47 -0500107 uint64_t address);
108
Deepak Kodihalli15211b42019-12-14 02:24:49 -0600109 virtual int transferFileData(int fd, bool upstream, uint32_t offset,
110 uint32_t& length, uint64_t address);
111
Ravi Tejace1c96f2020-10-05 23:13:01 -0500112 virtual int transferFileDataToSocket(int fd, uint32_t& length,
113 uint64_t address);
114
Sampa Misra854e61f2019-08-22 04:36:47 -0500115 /** @brief Constructor to create a FileHandler object
116 */
117 FileHandler(uint32_t fileHandle) : fileHandle(fileHandle)
George Liu6492f522020-06-16 10:34:05 +0800118 {}
Sampa Misra854e61f2019-08-22 04:36:47 -0500119
120 /** FileHandler destructor
121 */
122 virtual ~FileHandler()
George Liu6492f522020-06-16 10:34:05 +0800123 {}
Sampa Misra854e61f2019-08-22 04:36:47 -0500124
125 protected:
126 uint32_t fileHandle; //!< file handle indicating name of file or invalid
127};
128
129/** @brief Method to create individual file handler objects based on file type
130 *
131 * @param[in] fileType - type of file
132 * @param[in] fileHandle - file handle
133 */
134
135std::unique_ptr<FileHandler> getHandlerByType(uint16_t fileType,
136 uint32_t fileHandle);
137
138} // namespace responder
139} // namespace pldm