Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "blob_interface.hpp" |
Patrick Venture | cf2d1b1 | 2018-12-11 18:22:36 -0800 | [diff] [blame] | 4 | #include "ipmi_interface.hpp" |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame] | 5 | |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 6 | namespace host_tool |
| 7 | { |
| 8 | |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame] | 9 | class BlobHandler : public BlobInterface |
| 10 | { |
| 11 | public: |
Patrick Venture | c79faa1 | 2018-12-12 13:12:21 -0800 | [diff] [blame] | 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 | |
Patrick Venture | cf2d1b1 | 2018-12-11 18:22:36 -0800 | [diff] [blame] | 27 | explicit BlobHandler(IpmiInterface* ipmi) : ipmi(ipmi){}; |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame] | 28 | |
Patrick Venture | c79faa1 | 2018-12-12 13:12:21 -0800 | [diff] [blame] | 29 | /** |
| 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 Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 36 | * @throws BlobException. |
Patrick Venture | c79faa1 | 2018-12-12 13:12:21 -0800 | [diff] [blame] | 37 | */ |
| 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 Venture | 0309f10 | 2019-01-15 13:41:05 -0800 | [diff] [blame] | 57 | /** |
Patrick Venture | 77c5918 | 2019-01-17 14:53:31 -0800 | [diff] [blame^] | 58 | * 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 Venture | 0309f10 | 2019-01-15 13:41:05 -0800 | [diff] [blame] | 77 | * @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 Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame] | 82 | std::vector<std::string> getBlobList() override; |
Patrick Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * @throws BlobException. |
| 86 | */ |
Patrick Venture | 0bf8bf0 | 2018-12-12 20:43:25 -0800 | [diff] [blame] | 87 | StatResponse getStat(const std::string& id) override; |
Patrick Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * @throws BlobException. |
| 91 | */ |
Patrick Venture | 0533d0b | 2018-12-13 08:48:24 -0800 | [diff] [blame] | 92 | std::uint16_t |
| 93 | openBlob(const std::string& id, |
| 94 | blobs::FirmwareBlobHandler::UpdateFlags handlerFlags) override; |
Patrick Venture | cf2d1b1 | 2018-12-11 18:22:36 -0800 | [diff] [blame] | 95 | |
Patrick Venture | 9a5ce56 | 2018-12-14 18:56:04 -0800 | [diff] [blame] | 96 | void closeBlob(std::uint16_t session) override; |
| 97 | |
Patrick Venture | cf2d1b1 | 2018-12-11 18:22:36 -0800 | [diff] [blame] | 98 | private: |
| 99 | IpmiInterface* ipmi; |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame] | 100 | }; |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 101 | |
| 102 | } // namespace host_tool |