blob: e7da30ff22d018110a967308e636cc9e7e3dd4df [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 /**
Patrick Venturec79faa12018-12-12 13:12:21 -080030 * 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
Patrick Venture0309f102019-01-15 13:41:05 -080044 /**
Patrick Venture77c59182019-01-17 14:53:31 -080045 * @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 /**
Patrick Venture0309f102019-01-15 13:41:05 -080051 * @throw BlobException.
52 */
53 void writeBytes(std::uint16_t session, std::uint32_t offset,
54 const std::vector<std::uint8_t>& bytes) override;
55
Patrick Venture00887592018-12-11 10:57:06 -080056 std::vector<std::string> getBlobList() override;
Patrick Venture339dece2018-12-14 18:32:04 -080057
58 /**
59 * @throws BlobException.
60 */
Patrick Venture0bf8bf02018-12-12 20:43:25 -080061 StatResponse getStat(const std::string& id) override;
Patrick Venture339dece2018-12-14 18:32:04 -080062
63 /**
64 * @throws BlobException.
65 */
Patrick Venture0533d0b2018-12-13 08:48:24 -080066 std::uint16_t
67 openBlob(const std::string& id,
68 blobs::FirmwareBlobHandler::UpdateFlags handlerFlags) override;
Patrick Venturecf2d1b12018-12-11 18:22:36 -080069
Patrick Venture9a5ce562018-12-14 18:56:04 -080070 void closeBlob(std::uint16_t session) override;
71
Patrick Venturecf2d1b12018-12-11 18:22:36 -080072 private:
Patrick Venture596b6812019-01-31 13:23:09 -080073 /**
74 * Send the contents of the payload to IPMI, this method handles wrapping
75 * with the OEN, subcommand and CRC.
76 *
77 * @param[in] command - the blob command.
78 * @param[in] payload - the payload bytes.
79 * @return the bytes returned from the ipmi interface.
80 * @throws BlobException.
81 */
82 std::vector<std::uint8_t>
83 sendIpmiPayload(BlobOEMCommands command,
84 const std::vector<std::uint8_t>& payload);
85
86 /**
87 * Generic blob byte writer.
88 *
89 * @param[in] command - the command associated with this write.
90 * @param[in] session - the session id.
91 * @param[in] offset - the offset for the metadata to write.
92 * @param[in] bytes - the bytes to send.
93 * @throws BlobException on failure.
94 */
95 void writeGeneric(BlobOEMCommands command, std::uint16_t session,
96 std::uint32_t offset,
97 const std::vector<std::uint8_t>& bytes);
98
Patrick Venturecf2d1b12018-12-11 18:22:36 -080099 IpmiInterface* ipmi;
Patrick Venture00887592018-12-11 10:57:06 -0800100};
Patrick Venture9b534f02018-12-13 16:10:02 -0800101
102} // namespace host_tool