blob: fbd8c6a45ac0b1d4b21dfab754c52bca0ae46a4b [file] [log] [blame]
Patrick Venture123b5c02019-03-05 14:01:00 -08001#pragma once
2
3#include <cstdint>
4#include <string>
5#include <vector>
6
Patrick Venture1470bec2019-03-06 07:33:12 -08007namespace ipmiblob
Patrick Venture123b5c02019-03-05 14:01:00 -08008{
9
Patrick Venture44474642019-05-20 19:11:04 -070010enum class BlobOEMCommands : std::uint8_t
11{
12 bmcBlobGetCount = 0,
13 bmcBlobEnumerate = 1,
14 bmcBlobOpen = 2,
15 bmcBlobRead = 3,
16 bmcBlobWrite = 4,
17 bmcBlobCommit = 5,
18 bmcBlobClose = 6,
19 bmcBlobDelete = 7,
20 bmcBlobStat = 8,
21 bmcBlobSessionStat = 9,
22 bmcBlobWriteMeta = 10,
23};
24
Patrick Venture123b5c02019-03-05 14:01:00 -080025struct StatResponse
26{
27 std::uint16_t blob_state;
28 std::uint32_t size;
29 std::vector<std::uint8_t> metadata;
Patrick Venture99400c82019-05-15 15:26:48 -070030
31 bool operator==(const StatResponse& rhs) const
32 {
33 return (this->blob_state == rhs.blob_state && this->size == rhs.size &&
34 this->metadata == rhs.metadata);
35 }
Patrick Venture123b5c02019-03-05 14:01:00 -080036};
37
38class BlobInterface
39{
40 public:
41 virtual ~BlobInterface() = default;
42
43 /**
Patrick Venture8865e402019-05-14 13:29:10 -070044 * Call commit on a blob. The behavior here is up to the blob itself.
45 *
46 * @param[in] session - the session id.
47 * @param[in] bytes - the bytes to send.
48 * @throws BlobException on failure.
49 */
50 virtual void commit(std::uint16_t session,
51 const std::vector<std::uint8_t>& bytes) = 0;
52
53 /**
Patrick Venture123b5c02019-03-05 14:01:00 -080054 * Write metadata to a blob.
55 *
56 * @param[in] session - the session id.
57 * @param[in] offset - the offset for the metadata to write.
58 * @param[in] bytes - the bytes to send.
59 * @throws BlobException on failure.
60 */
61 virtual void writeMeta(std::uint16_t session, std::uint32_t offset,
62 const std::vector<std::uint8_t>& bytes) = 0;
63
64 /**
65 * Write bytes to a blob.
66 *
67 * @param[in] session - the session id.
68 * @param[in] offset - the offset to which to write the bytes.
69 * @param[in] bytes - the bytes to send.
70 * @throws BlobException on failure.
71 */
72 virtual void writeBytes(std::uint16_t session, std::uint32_t offset,
73 const std::vector<std::uint8_t>& bytes) = 0;
74
75 /**
76 * Get a list of the blob_ids provided by the BMC.
77 *
78 * @return list of strings, each representing a blob_id returned.
79 */
80 virtual std::vector<std::string> getBlobList() = 0;
81
82 /**
83 * Get the stat() on the blob_id.
84 *
85 * @param[in] id - the blob_id.
86 * @return metadata structure.
87 */
88 virtual StatResponse getStat(const std::string& id) = 0;
89
90 /**
Patrick Venture16a99a62019-05-03 17:21:30 -070091 * Get the stat() on the blob session.
92 *
93 * @param[in] session - the blob session
94 * @return metadata structure
95 */
96 virtual StatResponse getStat(std::uint16_t session) = 0;
97
98 /**
Patrick Venture123b5c02019-03-05 14:01:00 -080099 * Attempt to open the file using the specific data interface flag.
100 *
101 * @param[in] blob - the blob_id to open.
102 * @param[in] handlerFlags - the data interface flag, if relevant.
103 * @return the session id on success.
104 * @throws BlobException on failure.
105 */
106 virtual std::uint16_t openBlob(const std::string& id,
107 std::uint16_t handlerFlags) = 0;
108
109 /**
110 * Attempt to close the open session.
111 *
112 * @param[in] session - the session to close.
113 */
114 virtual void closeBlob(std::uint16_t session) = 0;
115
116 /**
117 * Read bytes from a blob.
118 *
119 * @param[in] session - the session id.
120 * @param[in] offset - the offset to which to write the bytes.
121 * @param[in] length - the number of bytes to read.
122 * @return the bytes read
123 * @throws BlobException on failure.
124 */
125 virtual std::vector<std::uint8_t> readBytes(std::uint16_t session,
126 std::uint32_t offset,
127 std::uint32_t length) = 0;
128};
129
Patrick Venture1470bec2019-03-06 07:33:12 -0800130} // namespace ipmiblob