blob: bc3ebdc8aa0cf18cc9eb14bf5ca28c683148b3c1 [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 Venture1470bec2019-03-06 07:33:12 -08006namespace ipmiblob
Patrick Venture123b5c02019-03-05 14:01:00 -08007{
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 */
Patrick Venture16a99a62019-05-03 17:21:30 -070066 StatResponse getStat(std::uint16_t session) override;
67
68 /**
69 * @throws BlobException.
70 */
Patrick Venture123b5c02019-03-05 14:01:00 -080071 std::uint16_t openBlob(const std::string& id,
72 std::uint16_t handlerFlags) override;
73
74 void closeBlob(std::uint16_t session) override;
75
76 /**
77 * @throws BlobException.
78 */
79 std::vector<std::uint8_t> readBytes(std::uint16_t session,
80 std::uint32_t offset,
81 std::uint32_t length) override;
82
83 private:
84 /**
85 * Send the contents of the payload to IPMI, this method handles wrapping
86 * with the OEN, subcommand and CRC.
87 *
88 * @param[in] command - the blob command.
89 * @param[in] payload - the payload bytes.
90 * @return the bytes returned from the ipmi interface.
91 * @throws BlobException.
92 */
93 std::vector<std::uint8_t>
94 sendIpmiPayload(BlobOEMCommands command,
95 const std::vector<std::uint8_t>& payload);
96
97 /**
98 * Generic blob byte writer.
99 *
100 * @param[in] command - the command associated with this write.
101 * @param[in] session - the session id.
102 * @param[in] offset - the offset for the metadata to write.
103 * @param[in] bytes - the bytes to send.
104 * @throws BlobException on failure.
105 */
106 void writeGeneric(BlobOEMCommands command, std::uint16_t session,
107 std::uint32_t offset,
108 const std::vector<std::uint8_t>& bytes);
109
Patrick Venture17186ae2019-05-06 10:30:55 -0700110 /**
111 * Generic stat reader.
112 *
113 * @param[in] command - the command associated with this write.
114 * @param[in] request - the bytes of the request
115 * @return the metadata StatResponse
116 * @throws BlobException on failure.
117 */
118 StatResponse statGeneric(BlobOEMCommands command,
119 const std::vector<std::uint8_t>& request);
120
Patrick Venture123b5c02019-03-05 14:01:00 -0800121 IpmiInterface* ipmi;
122};
123
Patrick Venture1470bec2019-03-06 07:33:12 -0800124} // namespace ipmiblob