blob: 9e77688c0c76372d221b553c5842eb8f9f2cc20f [file] [log] [blame]
Patrick Ventureaf696252018-12-11 10:22:14 -08001#include "bt.hpp"
2
Patrick Venture907f3a72019-01-15 14:13:37 -08003#include <cstdint>
Patrick Venture664c5bc2019-03-07 08:09:45 -08004#include <ipmiblob/blob_errors.hpp>
Patrick Venture907f3a72019-01-15 14:13:37 -08005#include <vector>
6
Patrick Venture9b534f02018-12-13 16:10:02 -08007namespace host_tool
8{
9
Patrick Ventureaf696252018-12-11 10:22:14 -080010bool BtDataHandler::sendContents(const std::string& input,
11 std::uint16_t session)
12{
Patrick Venture907f3a72019-01-15 14:13:37 -080013 int inputFd = sys->open(input.c_str(), 0);
14 if (inputFd < 0)
15 {
16 return false;
17 }
18
Patrick Venture907f3a72019-01-15 14:13:37 -080019 try
20 {
Patrick Venture63528042019-05-20 18:10:02 -070021 static constexpr int btBufferLen = 50;
22 std::uint8_t readBuffer[btBufferLen];
23 int bytesRead;
24 std::uint32_t offset = 0;
25
Patrick Venture907f3a72019-01-15 14:13:37 -080026 do
27 {
28 bytesRead = sys->read(inputFd, readBuffer, sizeof(readBuffer));
29 if (bytesRead > 0)
30 {
31 /* minorly awkward repackaging. */
32 std::vector<std::uint8_t> buffer(&readBuffer[0],
33 &readBuffer[bytesRead]);
34 blob->writeBytes(session, offset, buffer);
35 offset += bytesRead;
36 }
37 } while (bytesRead > 0);
38 }
Patrick Venture664c5bc2019-03-07 08:09:45 -080039 catch (const ipmiblob::BlobException& b)
Patrick Venture907f3a72019-01-15 14:13:37 -080040 {
41 sys->close(inputFd);
42 return false;
43 }
44
45 sys->close(inputFd);
46 return true;
Patrick Ventureaf696252018-12-11 10:22:14 -080047}
Patrick Venture9b534f02018-12-13 16:10:02 -080048
49} // namespace host_tool