blob: 6c4ba7a065a6dcc4464f981c037ed2aecfc7ba74 [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:
14 enum BlobOEMCommands
15 {
16 bmcBlobGetCount = 0,
17 bmcBlobEnumerate = 1,
18 bmcBlobOpen = 2,
19 bmcBlobRead = 3,
20 bmcBlobWrite = 4,
21 bmcBlobCommit = 5,
22 bmcBlobClose = 6,
23 bmcBlobDelete = 7,
24 bmcBlobStat = 8,
25 bmcBlobSessionStat = 9,
26 bmcBlobWriteMeta = 10,
27 };
28
Patrick Venture786a5412019-05-13 07:40:22 -070029 explicit BlobHandler(std::unique_ptr<IpmiInterface> ipmi) :
30 ipmi(std::move(ipmi)){};
31
32 ~BlobHandler() = default;
33 BlobHandler(const BlobHandler&) = delete;
34 BlobHandler& operator=(const BlobHandler&) = delete;
35 BlobHandler(BlobHandler&&) = default;
36 BlobHandler& operator=(BlobHandler&&) = default;
Patrick Venture123b5c02019-03-05 14:01:00 -080037
38 /**
39 * Retrieve the blob count.
40 *
41 * @return the number of blob_ids found (0 on failure).
42 */
43 int getBlobCount();
44
45 /**
46 * Given an index into the list of blobs, return the name.
47 *
48 * @param[in] index - the index into the list of blob ids.
49 * @return the name as a string or empty on failure.
50 */
51 std::string enumerateBlob(std::uint32_t index);
52
53 /**
54 * @throws BlobException.
55 */
56 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
85 /**
86 * @throws BlobException.
87 */
88 std::vector<std::uint8_t> readBytes(std::uint16_t session,
89 std::uint32_t offset,
90 std::uint32_t length) override;
91
92 private:
93 /**
94 * Send the contents of the payload to IPMI, this method handles wrapping
95 * with the OEN, subcommand and CRC.
96 *
97 * @param[in] command - the blob command.
98 * @param[in] payload - the payload bytes.
99 * @return the bytes returned from the ipmi interface.
100 * @throws BlobException.
101 */
102 std::vector<std::uint8_t>
103 sendIpmiPayload(BlobOEMCommands command,
104 const std::vector<std::uint8_t>& payload);
105
106 /**
107 * Generic blob byte writer.
108 *
109 * @param[in] command - the command associated with this write.
110 * @param[in] session - the session id.
111 * @param[in] offset - the offset for the metadata to write.
112 * @param[in] bytes - the bytes to send.
113 * @throws BlobException on failure.
114 */
115 void writeGeneric(BlobOEMCommands command, std::uint16_t session,
116 std::uint32_t offset,
117 const std::vector<std::uint8_t>& bytes);
118
Patrick Venture17186ae2019-05-06 10:30:55 -0700119 /**
120 * Generic stat reader.
121 *
122 * @param[in] command - the command associated with this write.
123 * @param[in] request - the bytes of the request
124 * @return the metadata StatResponse
125 * @throws BlobException on failure.
126 */
127 StatResponse statGeneric(BlobOEMCommands command,
128 const std::vector<std::uint8_t>& request);
129
Patrick Venture786a5412019-05-13 07:40:22 -0700130 std::unique_ptr<IpmiInterface> ipmi;
Patrick Venture123b5c02019-03-05 14:01:00 -0800131};
132
Patrick Venture1470bec2019-03-06 07:33:12 -0800133} // namespace ipmiblob