blob: 1cbc9637c5ea29bf1305cf4747baac13625597fa [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 Venture957f0862019-02-01 14:40:06 -080072 /**
73 * @throws BlobException.
74 */
75 std::vector<std::uint8_t> readBytes(std::uint16_t session,
76 std::uint32_t offset,
77 std::uint32_t length) override;
78
Patrick Venturecf2d1b12018-12-11 18:22:36 -080079 private:
Patrick Venture596b6812019-01-31 13:23:09 -080080 /**
81 * Send the contents of the payload to IPMI, this method handles wrapping
82 * with the OEN, subcommand and CRC.
83 *
84 * @param[in] command - the blob command.
85 * @param[in] payload - the payload bytes.
86 * @return the bytes returned from the ipmi interface.
87 * @throws BlobException.
88 */
89 std::vector<std::uint8_t>
90 sendIpmiPayload(BlobOEMCommands command,
91 const std::vector<std::uint8_t>& payload);
92
93 /**
94 * Generic blob byte writer.
95 *
96 * @param[in] command - the command associated with this write.
97 * @param[in] session - the session id.
98 * @param[in] offset - the offset for the metadata to write.
99 * @param[in] bytes - the bytes to send.
100 * @throws BlobException on failure.
101 */
102 void writeGeneric(BlobOEMCommands command, std::uint16_t session,
103 std::uint32_t offset,
104 const std::vector<std::uint8_t>& bytes);
105
Patrick Venturecf2d1b12018-12-11 18:22:36 -0800106 IpmiInterface* ipmi;
Patrick Venture00887592018-12-11 10:57:06 -0800107};
Patrick Venture9b534f02018-12-13 16:10:02 -0800108
109} // namespace host_tool