blob: cbac9d41dec303ecc12c9531b30556a1c7493b5e [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
6namespace host_tool
7{
8
9class BlobHandler : public BlobInterface
10{
11 public:
12 enum BlobOEMCommands
13 {
14 bmcBlobGetCount = 0,
15 bmcBlobEnumerate = 1,
16 bmcBlobOpen = 2,
17 bmcBlobRead = 3,
18 bmcBlobWrite = 4,
19 bmcBlobCommit = 5,
20 bmcBlobClose = 6,
21 bmcBlobDelete = 7,
22 bmcBlobStat = 8,
23 bmcBlobSessionStat = 9,
24 bmcBlobWriteMeta = 10,
25 };
26
27 explicit BlobHandler(IpmiInterface* ipmi) : ipmi(ipmi){};
28
29 /**
30 * Retrieve the blob count.
31 *
32 * @return the number of blob_ids found (0 on failure).
33 */
34 int getBlobCount();
35
36 /**
37 * Given an index into the list of blobs, return the name.
38 *
39 * @param[in] index - the index into the list of blob ids.
40 * @return the name as a string or empty on failure.
41 */
42 std::string enumerateBlob(std::uint32_t index);
43
44 /**
45 * @throws BlobException.
46 */
47 void writeMeta(std::uint16_t session, std::uint32_t offset,
48 const std::vector<std::uint8_t>& bytes) override;
49
50 /**
51 * @throw BlobException.
52 */
53 void writeBytes(std::uint16_t session, std::uint32_t offset,
54 const std::vector<std::uint8_t>& bytes) override;
55
56 std::vector<std::string> getBlobList() override;
57
58 /**
59 * @throws BlobException.
60 */
61 StatResponse getStat(const std::string& id) override;
62
63 /**
64 * @throws BlobException.
65 */
66 std::uint16_t openBlob(const std::string& id,
67 std::uint16_t handlerFlags) override;
68
69 void closeBlob(std::uint16_t session) override;
70
71 /**
72 * @throws BlobException.
73 */
74 std::vector<std::uint8_t> readBytes(std::uint16_t session,
75 std::uint32_t offset,
76 std::uint32_t length) override;
77
78 private:
79 /**
80 * Send the contents of the payload to IPMI, this method handles wrapping
81 * with the OEN, subcommand and CRC.
82 *
83 * @param[in] command - the blob command.
84 * @param[in] payload - the payload bytes.
85 * @return the bytes returned from the ipmi interface.
86 * @throws BlobException.
87 */
88 std::vector<std::uint8_t>
89 sendIpmiPayload(BlobOEMCommands command,
90 const std::vector<std::uint8_t>& payload);
91
92 /**
93 * Generic blob byte writer.
94 *
95 * @param[in] command - the command associated with this write.
96 * @param[in] session - the session id.
97 * @param[in] offset - the offset for the metadata to write.
98 * @param[in] bytes - the bytes to send.
99 * @throws BlobException on failure.
100 */
101 void writeGeneric(BlobOEMCommands command, std::uint16_t session,
102 std::uint32_t offset,
103 const std::vector<std::uint8_t>& bytes);
104
105 IpmiInterface* ipmi;
106};
107
108} // namespace host_tool