blob: a9e6ef499e64bff8019b73b5e9ead92b8294f3c2 [file] [log] [blame]
Patrick Venture123b5c02019-03-05 14:01:00 -08001#pragma once
2
3#include "blob_interface.hpp"
4#include "ipmi_interface.hpp"
5
Patrick Venture786a5412019-05-13 07:40:22 -07006#include <memory>
7
Patrick Venture1470bec2019-03-06 07:33:12 -08008namespace ipmiblob
Patrick Venture123b5c02019-03-05 14:01:00 -08009{
10
11class BlobHandler : public BlobInterface
12{
13 public:
Patrick Venture22fcc842019-05-13 09:06:24 -070014 /**
15 * Create a BlobInterface pointer for use given an ipmi handler.
16 *
17 * @note This is a convenience method.
18 * @return a BlobHandler wrapped as a BlobInterface pointer.
19 */
20 static std::unique_ptr<BlobInterface>
21 CreateBlobHandler(std::unique_ptr<IpmiInterface> ipmi);
22
Patrick Venture786a5412019-05-13 07:40:22 -070023 explicit BlobHandler(std::unique_ptr<IpmiInterface> ipmi) :
24 ipmi(std::move(ipmi)){};
25
26 ~BlobHandler() = default;
27 BlobHandler(const BlobHandler&) = delete;
28 BlobHandler& operator=(const BlobHandler&) = delete;
29 BlobHandler(BlobHandler&&) = default;
30 BlobHandler& operator=(BlobHandler&&) = default;
Patrick Venture123b5c02019-03-05 14:01:00 -080031
32 /**
33 * Retrieve the blob count.
34 *
35 * @return the number of blob_ids found (0 on failure).
36 */
37 int getBlobCount();
38
39 /**
40 * Given an index into the list of blobs, return the name.
41 *
42 * @param[in] index - the index into the list of blob ids.
43 * @return the name as a string or empty on failure.
44 */
45 std::string enumerateBlob(std::uint32_t index);
46
47 /**
48 * @throws BlobException.
49 */
Patrick Venture8865e402019-05-14 13:29:10 -070050 void commit(std::uint16_t session,
Patrick Venture8752cdf2019-05-15 12:37:42 -070051 const std::vector<std::uint8_t>& bytes = {}) override;
Patrick Venture8865e402019-05-14 13:29:10 -070052
53 /**
54 * @throws BlobException.
55 */
Patrick Venture123b5c02019-03-05 14:01:00 -080056 void writeMeta(std::uint16_t session, std::uint32_t offset,
57 const std::vector<std::uint8_t>& bytes) override;
58
59 /**
60 * @throw BlobException.
61 */
62 void writeBytes(std::uint16_t session, std::uint32_t offset,
63 const std::vector<std::uint8_t>& bytes) override;
64
65 std::vector<std::string> getBlobList() override;
66
67 /**
68 * @throws BlobException.
69 */
70 StatResponse getStat(const std::string& id) override;
71
72 /**
73 * @throws BlobException.
74 */
Patrick Venture16a99a62019-05-03 17:21:30 -070075 StatResponse getStat(std::uint16_t session) override;
76
77 /**
78 * @throws BlobException.
79 */
Patrick Venture123b5c02019-03-05 14:01:00 -080080 std::uint16_t openBlob(const std::string& id,
81 std::uint16_t handlerFlags) override;
82
83 void closeBlob(std::uint16_t session) override;
84
William A. Kennington IIId46530f2021-11-06 17:12:07 -070085 bool deleteBlob(const std::string& id) override;
Brandon Kimcc4ef0c2019-10-18 10:08:37 -070086
Patrick Venture123b5c02019-03-05 14:01:00 -080087 /**
88 * @throws BlobException.
89 */
90 std::vector<std::uint8_t> readBytes(std::uint16_t session,
91 std::uint32_t offset,
92 std::uint32_t length) override;
93
94 private:
95 /**
96 * Send the contents of the payload to IPMI, this method handles wrapping
97 * with the OEN, subcommand and CRC.
98 *
99 * @param[in] command - the blob command.
100 * @param[in] payload - the payload bytes.
101 * @return the bytes returned from the ipmi interface.
102 * @throws BlobException.
103 */
104 std::vector<std::uint8_t>
105 sendIpmiPayload(BlobOEMCommands command,
106 const std::vector<std::uint8_t>& payload);
107
108 /**
109 * Generic blob byte writer.
110 *
111 * @param[in] command - the command associated with this write.
112 * @param[in] session - the session id.
113 * @param[in] offset - the offset for the metadata to write.
114 * @param[in] bytes - the bytes to send.
115 * @throws BlobException on failure.
116 */
117 void writeGeneric(BlobOEMCommands command, std::uint16_t session,
118 std::uint32_t offset,
119 const std::vector<std::uint8_t>& bytes);
120
Patrick Venture17186ae2019-05-06 10:30:55 -0700121 /**
122 * Generic stat reader.
123 *
124 * @param[in] command - the command associated with this write.
125 * @param[in] request - the bytes of the request
126 * @return the metadata StatResponse
127 * @throws BlobException on failure.
128 */
129 StatResponse statGeneric(BlobOEMCommands command,
130 const std::vector<std::uint8_t>& request);
131
Patrick Venture786a5412019-05-13 07:40:22 -0700132 std::unique_ptr<IpmiInterface> ipmi;
Patrick Venture123b5c02019-03-05 14:01:00 -0800133};
134
Patrick Venture958f1ce2019-05-31 17:07:25 -0700135constexpr int ipmiOEMNetFn = 46;
136constexpr int ipmiOEMBlobCmd = 128;
137
Patrick Venture1470bec2019-03-06 07:33:12 -0800138} // namespace ipmiblob