Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 0533d0b | 2018-12-13 08:48:24 -0800 | [diff] [blame] | 3 | #include "firmware_handler.hpp" |
| 4 | |
Patrick Venture | 7871b45 | 2018-12-13 08:53:14 -0800 | [diff] [blame] | 5 | #include <cstdint> |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame] | 6 | #include <string> |
| 7 | #include <vector> |
| 8 | |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 9 | namespace host_tool |
| 10 | { |
| 11 | |
Patrick Venture | 0bf8bf0 | 2018-12-12 20:43:25 -0800 | [diff] [blame] | 12 | struct StatResponse |
| 13 | { |
| 14 | std::uint16_t blob_state; |
| 15 | std::uint32_t size; |
| 16 | std::vector<std::uint8_t> metadata; |
| 17 | }; |
| 18 | |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame] | 19 | class BlobInterface |
| 20 | { |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame] | 21 | public: |
| 22 | virtual ~BlobInterface() = default; |
| 23 | |
| 24 | /** |
Patrick Venture | 77c5918 | 2019-01-17 14:53:31 -0800 | [diff] [blame] | 25 | * Write metadata to a blob. |
| 26 | * |
| 27 | * @param[in] session - the session id. |
| 28 | * @param[in] offset - the offset for the metadata to write. |
| 29 | * @param[in] bytes - the bytes to send. |
| 30 | * @throws BlobException on failure. |
| 31 | */ |
| 32 | virtual void writeMeta(std::uint16_t session, std::uint32_t offset, |
| 33 | const std::vector<std::uint8_t>& bytes) = 0; |
| 34 | |
| 35 | /** |
Patrick Venture | 0309f10 | 2019-01-15 13:41:05 -0800 | [diff] [blame] | 36 | * Write bytes to a blob. |
| 37 | * |
| 38 | * @param[in] session - the session id. |
| 39 | * @param[in] offset - the offset to which to write the bytes. |
| 40 | * @param[in] bytes - the bytes to send. |
| 41 | * @throws BlobException on failure. |
| 42 | */ |
| 43 | virtual void writeBytes(std::uint16_t session, std::uint32_t offset, |
| 44 | const std::vector<std::uint8_t>& bytes) = 0; |
| 45 | |
| 46 | /** |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame] | 47 | * Get a list of the blob_ids provided by the BMC. |
| 48 | * |
| 49 | * @return list of strings, each representing a blob_id returned. |
| 50 | */ |
| 51 | virtual std::vector<std::string> getBlobList() = 0; |
Patrick Venture | 0bf8bf0 | 2018-12-12 20:43:25 -0800 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * Get the stat() on the blob_id. |
| 55 | * |
| 56 | * @param[in] id - the blob_id. |
| 57 | * @return metadata structure. |
| 58 | */ |
| 59 | virtual StatResponse getStat(const std::string& id) = 0; |
Patrick Venture | 0533d0b | 2018-12-13 08:48:24 -0800 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Attempt to open the file using the specific data interface flag. |
| 63 | * |
| 64 | * @param[in] blob - the blob_id to open. |
| 65 | * @param[in] handlerFlags - the data interface flag, if relevant. |
| 66 | * @return the session id on success. |
| 67 | * @throws BlobException on failure. |
| 68 | */ |
| 69 | virtual std::uint16_t |
| 70 | openBlob(const std::string& id, |
| 71 | blobs::FirmwareBlobHandler::UpdateFlags handlerFlags) = 0; |
Patrick Venture | 9a5ce56 | 2018-12-14 18:56:04 -0800 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Attempt to close the open session. |
| 75 | * |
| 76 | * @param[in] session - the session to close. |
| 77 | */ |
| 78 | virtual void closeBlob(std::uint16_t session) = 0; |
Patrick Venture | 957f086 | 2019-02-01 14:40:06 -0800 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * Read bytes from a blob. |
| 82 | * |
| 83 | * @param[in] session - the session id. |
| 84 | * @param[in] offset - the offset to which to write the bytes. |
| 85 | * @param[in] length - the number of bytes to read. |
| 86 | * @return the bytes read |
| 87 | * @throws BlobException on failure. |
| 88 | */ |
| 89 | virtual std::vector<std::uint8_t> readBytes(std::uint16_t session, |
| 90 | std::uint32_t offset, |
| 91 | std::uint32_t length) = 0; |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame] | 92 | }; |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 93 | |
| 94 | } // namespace host_tool |