Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "blob_interface.hpp" |
| 4 | #include "ipmi_interface.hpp" |
| 5 | |
Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 6 | namespace ipmiblob |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 7 | { |
| 8 | |
| 9 | class BlobHandler : public BlobInterface |
| 10 | { |
| 11 | public: |
| 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 | |
| 27 | explicit BlobHandler(IpmiInterface* ipmi) : ipmi(ipmi){}; |
| 28 | |
| 29 | /** |
| 30 | * 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 | |
| 44 | /** |
| 45 | * @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 | /** |
| 51 | * @throw BlobException. |
| 52 | */ |
| 53 | void writeBytes(std::uint16_t session, std::uint32_t offset, |
| 54 | const std::vector<std::uint8_t>& bytes) override; |
| 55 | |
| 56 | std::vector<std::string> getBlobList() override; |
| 57 | |
| 58 | /** |
| 59 | * @throws BlobException. |
| 60 | */ |
| 61 | StatResponse getStat(const std::string& id) override; |
| 62 | |
| 63 | /** |
| 64 | * @throws BlobException. |
| 65 | */ |
Patrick Venture | 16a99a6 | 2019-05-03 17:21:30 -0700 | [diff] [blame^] | 66 | StatResponse getStat(std::uint16_t session) override; |
| 67 | |
| 68 | /** |
| 69 | * @throws BlobException. |
| 70 | */ |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 71 | std::uint16_t openBlob(const std::string& id, |
| 72 | std::uint16_t handlerFlags) override; |
| 73 | |
| 74 | void closeBlob(std::uint16_t session) override; |
| 75 | |
| 76 | /** |
| 77 | * @throws BlobException. |
| 78 | */ |
| 79 | std::vector<std::uint8_t> readBytes(std::uint16_t session, |
| 80 | std::uint32_t offset, |
| 81 | std::uint32_t length) override; |
| 82 | |
| 83 | private: |
| 84 | /** |
| 85 | * Send the contents of the payload to IPMI, this method handles wrapping |
| 86 | * with the OEN, subcommand and CRC. |
| 87 | * |
| 88 | * @param[in] command - the blob command. |
| 89 | * @param[in] payload - the payload bytes. |
| 90 | * @return the bytes returned from the ipmi interface. |
| 91 | * @throws BlobException. |
| 92 | */ |
| 93 | std::vector<std::uint8_t> |
| 94 | sendIpmiPayload(BlobOEMCommands command, |
| 95 | const std::vector<std::uint8_t>& payload); |
| 96 | |
| 97 | /** |
| 98 | * Generic blob byte writer. |
| 99 | * |
| 100 | * @param[in] command - the command associated with this write. |
| 101 | * @param[in] session - the session id. |
| 102 | * @param[in] offset - the offset for the metadata to write. |
| 103 | * @param[in] bytes - the bytes to send. |
| 104 | * @throws BlobException on failure. |
| 105 | */ |
| 106 | void writeGeneric(BlobOEMCommands command, std::uint16_t session, |
| 107 | std::uint32_t offset, |
| 108 | const std::vector<std::uint8_t>& bytes); |
| 109 | |
| 110 | IpmiInterface* ipmi; |
| 111 | }; |
| 112 | |
Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 113 | } // namespace ipmiblob |