diff options
author | Patrick Venture <venture@google.com> | 2019-05-14 13:29:10 -0700 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2019-05-14 13:42:05 -0700 |
commit | 8865e40b6e54384fc3c9911d15d6261b414a3d91 (patch) | |
tree | b82fb451998bcf64f547431088494414e3bd58cd /src | |
parent | 22fcc84469975fe5ca3597f78fe8103e8a8bbc52 (diff) | |
download | ipmi-blob-tool-8865e40b6e54384fc3c9911d15d6261b414a3d91.tar.gz ipmi-blob-tool-8865e40b6e54384fc3c9911d15d6261b414a3d91.zip |
blob: implement commit command
Implement the commit command for the blob handler.
Change-Id: Ia3be86083991cbdf7fe85c15986f4e1cb60971f5
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/ipmiblob/blob_handler.cpp | 24 | ||||
-rw-r--r-- | src/ipmiblob/blob_handler.hpp | 6 | ||||
-rw-r--r-- | src/ipmiblob/blob_interface.hpp | 10 | ||||
-rw-r--r-- | src/ipmiblob/test/blob_interface_mock.hpp | 1 |
4 files changed, 41 insertions, 0 deletions
diff --git a/src/ipmiblob/blob_handler.cpp b/src/ipmiblob/blob_handler.cpp index 77fcb6c..e5b78e1 100644 --- a/src/ipmiblob/blob_handler.cpp +++ b/src/ipmiblob/blob_handler.cpp @@ -162,6 +162,30 @@ std::string BlobHandler::enumerateBlob(std::uint32_t index) } } +void BlobHandler::commit(std::uint16_t session, + const std::vector<std::uint8_t>& bytes) +{ + std::vector<std::uint8_t> request; + auto addrSession = reinterpret_cast<const std::uint8_t*>(&session); + std::copy(addrSession, addrSession + sizeof(session), + std::back_inserter(request)); + + /* You have one byte to describe the length. */ + if (bytes.size() > std::numeric_limits<std::uint8_t>::max()) + { + throw BlobException("Commit data length greater than 8-bit limit\n"); + } + + std::uint8_t length = static_cast<std::uint8_t>(bytes.size()); + auto addrLength = reinterpret_cast<const std::uint8_t*>(&length); + std::copy(addrLength, addrLength + sizeof(length), + std::back_inserter(request)); + + std::copy(bytes.begin(), bytes.end(), std::back_inserter(request)); + + sendIpmiPayload(BlobOEMCommands::bmcBlobCommit, request); +} + void BlobHandler::writeGeneric(BlobOEMCommands command, std::uint16_t session, std::uint32_t offset, const std::vector<std::uint8_t>& bytes) diff --git a/src/ipmiblob/blob_handler.hpp b/src/ipmiblob/blob_handler.hpp index 0b6db17..200dfd5 100644 --- a/src/ipmiblob/blob_handler.hpp +++ b/src/ipmiblob/blob_handler.hpp @@ -62,6 +62,12 @@ class BlobHandler : public BlobInterface /** * @throws BlobException. */ + void commit(std::uint16_t session, + const std::vector<std::uint8_t>& bytes) override; + + /** + * @throws BlobException. + */ void writeMeta(std::uint16_t session, std::uint32_t offset, const std::vector<std::uint8_t>& bytes) override; diff --git a/src/ipmiblob/blob_interface.hpp b/src/ipmiblob/blob_interface.hpp index ece5c34..989d461 100644 --- a/src/ipmiblob/blob_interface.hpp +++ b/src/ipmiblob/blob_interface.hpp @@ -20,6 +20,16 @@ class BlobInterface virtual ~BlobInterface() = default; /** + * Call commit on a blob. The behavior here is up to the blob itself. + * + * @param[in] session - the session id. + * @param[in] bytes - the bytes to send. + * @throws BlobException on failure. + */ + virtual void commit(std::uint16_t session, + const std::vector<std::uint8_t>& bytes) = 0; + + /** * Write metadata to a blob. * * @param[in] session - the session id. diff --git a/src/ipmiblob/test/blob_interface_mock.hpp b/src/ipmiblob/test/blob_interface_mock.hpp index 0faa6fe..7fb94c5 100644 --- a/src/ipmiblob/test/blob_interface_mock.hpp +++ b/src/ipmiblob/test/blob_interface_mock.hpp @@ -9,6 +9,7 @@ class BlobInterfaceMock : public BlobInterface { public: virtual ~BlobInterfaceMock() = default; + MOCK_METHOD2(commit, void(std::uint16_t, const std::vector<std::uint8_t>&)); MOCK_METHOD3(writeMeta, void(std::uint16_t, std::uint32_t, const std::vector<std::uint8_t>&)); MOCK_METHOD3(writeBytes, void(std::uint16_t, std::uint32_t, |