blob: 3c904043777c9854249f7fbf8170392852945bd0 [file] [log] [blame]
Patrick Venture00887592018-12-11 10:57:06 -08001#pragma once
2
3#include "blob_interface.hpp"
Patrick Venturecf2d1b12018-12-11 18:22:36 -08004#include "ipmi_interface.hpp"
Patrick Venture00887592018-12-11 10:57:06 -08005
Patrick Venture9b534f02018-12-13 16:10:02 -08006namespace host_tool
7{
8
Patrick Venture00887592018-12-11 10:57:06 -08009class BlobHandler : public BlobInterface
10{
11 public:
Patrick Venturec79faa12018-12-12 13:12:21 -080012 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
Patrick Venturecf2d1b12018-12-11 18:22:36 -080027 explicit BlobHandler(IpmiInterface* ipmi) : ipmi(ipmi){};
Patrick Venture00887592018-12-11 10:57:06 -080028
Patrick Venturec79faa12018-12-12 13:12:21 -080029 /**
30 * Send the contents of the payload to IPMI, this method handles wrapping
31 * with the OEN, subcommand and CRC.
32 *
33 * @param[in] command - the blob command.
34 * @param[in] payload - the payload bytes.
35 * @return the bytes returned from the ipmi interface.
Patrick Venture339dece2018-12-14 18:32:04 -080036 * @throws BlobException.
Patrick Venturec79faa12018-12-12 13:12:21 -080037 */
38 std::vector<std::uint8_t>
39 sendIpmiPayload(BlobOEMCommands command,
40 const std::vector<std::uint8_t>& payload);
41
42 /**
43 * Retrieve the blob count.
44 *
45 * @return the number of blob_ids found (0 on failure).
46 */
47 int getBlobCount();
48
49 /**
50 * Given an index into the list of blobs, return the name.
51 *
52 * @param[in] index - the index into the list of blob ids.
53 * @return the name as a string or empty on failure.
54 */
55 std::string enumerateBlob(std::uint32_t index);
56
Patrick Venture0309f102019-01-15 13:41:05 -080057 /**
Patrick Venture77c59182019-01-17 14:53:31 -080058 * Generic blob byte writer.
59 *
60 * @param[in] command - the command associated with this write.
61 * @param[in] session - the session id.
62 * @param[in] offset - the offset for the metadata to write.
63 * @param[in] bytes - the bytes to send.
64 * @throws BlobException on failure.
65 */
66 void writeGeneric(BlobOEMCommands command, std::uint16_t session,
67 std::uint32_t offset,
68 const std::vector<std::uint8_t>& bytes);
69
70 /**
71 * @throws BlobException.
72 */
73 void writeMeta(std::uint16_t session, std::uint32_t offset,
74 const std::vector<std::uint8_t>& bytes) override;
75
76 /**
Patrick Venture0309f102019-01-15 13:41:05 -080077 * @throw BlobException.
78 */
79 void writeBytes(std::uint16_t session, std::uint32_t offset,
80 const std::vector<std::uint8_t>& bytes) override;
81
Patrick Venture00887592018-12-11 10:57:06 -080082 std::vector<std::string> getBlobList() override;
Patrick Venture339dece2018-12-14 18:32:04 -080083
84 /**
85 * @throws BlobException.
86 */
Patrick Venture0bf8bf02018-12-12 20:43:25 -080087 StatResponse getStat(const std::string& id) override;
Patrick Venture339dece2018-12-14 18:32:04 -080088
89 /**
90 * @throws BlobException.
91 */
Patrick Venture0533d0b2018-12-13 08:48:24 -080092 std::uint16_t
93 openBlob(const std::string& id,
94 blobs::FirmwareBlobHandler::UpdateFlags handlerFlags) override;
Patrick Venturecf2d1b12018-12-11 18:22:36 -080095
Patrick Venture9a5ce562018-12-14 18:56:04 -080096 void closeBlob(std::uint16_t session) override;
97
Patrick Venturecf2d1b12018-12-11 18:22:36 -080098 private:
99 IpmiInterface* ipmi;
Patrick Venture00887592018-12-11 10:57:06 -0800100};
Patrick Venture9b534f02018-12-13 16:10:02 -0800101
102} // namespace host_tool