blob: 0114b897de6562e91a13f15bb2604387ba758d7d [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 /**
58 * @throw BlobException.
59 */
60 void writeBytes(std::uint16_t session, std::uint32_t offset,
61 const std::vector<std::uint8_t>& bytes) override;
62
Patrick Venture00887592018-12-11 10:57:06 -080063 std::vector<std::string> getBlobList() override;
Patrick Venture339dece2018-12-14 18:32:04 -080064
65 /**
66 * @throws BlobException.
67 */
Patrick Venture0bf8bf02018-12-12 20:43:25 -080068 StatResponse getStat(const std::string& id) override;
Patrick Venture339dece2018-12-14 18:32:04 -080069
70 /**
71 * @throws BlobException.
72 */
Patrick Venture0533d0b2018-12-13 08:48:24 -080073 std::uint16_t
74 openBlob(const std::string& id,
75 blobs::FirmwareBlobHandler::UpdateFlags handlerFlags) override;
Patrick Venturecf2d1b12018-12-11 18:22:36 -080076
Patrick Venture9a5ce562018-12-14 18:56:04 -080077 void closeBlob(std::uint16_t session) override;
78
Patrick Venturecf2d1b12018-12-11 18:22:36 -080079 private:
80 IpmiInterface* ipmi;
Patrick Venture00887592018-12-11 10:57:06 -080081};
Patrick Venture9b534f02018-12-13 16:10:02 -080082
83} // namespace host_tool