blob: 00031b80e6a894f9949cd662a2d242424071415f [file] [log] [blame]
Patrick Venture00887592018-12-11 10:57:06 -08001#pragma once
2
Patrick Venture0533d0b2018-12-13 08:48:24 -08003#include "firmware_handler.hpp"
4
Patrick Venture7871b452018-12-13 08:53:14 -08005#include <cstdint>
Patrick Venture00887592018-12-11 10:57:06 -08006#include <string>
7#include <vector>
8
Patrick Venture9b534f02018-12-13 16:10:02 -08009namespace host_tool
10{
11
Patrick Venture0bf8bf02018-12-12 20:43:25 -080012struct StatResponse
13{
14 std::uint16_t blob_state;
15 std::uint32_t size;
16 std::vector<std::uint8_t> metadata;
17};
18
Patrick Venture00887592018-12-11 10:57:06 -080019class BlobInterface
20{
Patrick Venture00887592018-12-11 10:57:06 -080021 public:
22 virtual ~BlobInterface() = default;
23
24 /**
Patrick Venture0309f102019-01-15 13:41:05 -080025 * Write bytes to a blob.
26 *
27 * @param[in] session - the session id.
28 * @param[in] offset - the offset to which to write the bytes.
29 * @param[in] bytes - the bytes to send.
30 * @throws BlobException on failure.
31 */
32 virtual void writeBytes(std::uint16_t session, std::uint32_t offset,
33 const std::vector<std::uint8_t>& bytes) = 0;
34
35 /**
Patrick Venture00887592018-12-11 10:57:06 -080036 * Get a list of the blob_ids provided by the BMC.
37 *
38 * @return list of strings, each representing a blob_id returned.
39 */
40 virtual std::vector<std::string> getBlobList() = 0;
Patrick Venture0bf8bf02018-12-12 20:43:25 -080041
42 /**
43 * Get the stat() on the blob_id.
44 *
45 * @param[in] id - the blob_id.
46 * @return metadata structure.
47 */
48 virtual StatResponse getStat(const std::string& id) = 0;
Patrick Venture0533d0b2018-12-13 08:48:24 -080049
50 /**
51 * Attempt to open the file using the specific data interface flag.
52 *
53 * @param[in] blob - the blob_id to open.
54 * @param[in] handlerFlags - the data interface flag, if relevant.
55 * @return the session id on success.
56 * @throws BlobException on failure.
57 */
58 virtual std::uint16_t
59 openBlob(const std::string& id,
60 blobs::FirmwareBlobHandler::UpdateFlags handlerFlags) = 0;
Patrick Venture9a5ce562018-12-14 18:56:04 -080061
62 /**
63 * Attempt to close the open session.
64 *
65 * @param[in] session - the session to close.
66 */
67 virtual void closeBlob(std::uint16_t session) = 0;
Patrick Venture00887592018-12-11 10:57:06 -080068};
Patrick Venture9b534f02018-12-13 16:10:02 -080069
70} // namespace host_tool