Patrick Venture | af69625 | 2018-12-11 10:22:14 -0800 | [diff] [blame] | 1 | #include "bt.hpp" |
| 2 | |
Patrick Venture | 907f3a7 | 2019-01-15 14:13:37 -0800 | [diff] [blame] | 3 | #include <cstdint> |
Patrick Venture | 664c5bc | 2019-03-07 08:09:45 -0800 | [diff] [blame] | 4 | #include <ipmiblob/blob_errors.hpp> |
Patrick Venture | 907f3a7 | 2019-01-15 14:13:37 -0800 | [diff] [blame] | 5 | #include <vector> |
| 6 | |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 7 | namespace host_tool |
| 8 | { |
| 9 | |
Patrick Venture | af69625 | 2018-12-11 10:22:14 -0800 | [diff] [blame] | 10 | bool BtDataHandler::sendContents(const std::string& input, |
| 11 | std::uint16_t session) |
| 12 | { |
Patrick Venture | 907f3a7 | 2019-01-15 14:13:37 -0800 | [diff] [blame] | 13 | int inputFd = sys->open(input.c_str(), 0); |
| 14 | if (inputFd < 0) |
| 15 | { |
| 16 | return false; |
| 17 | } |
| 18 | |
Patrick Venture | 907f3a7 | 2019-01-15 14:13:37 -0800 | [diff] [blame] | 19 | try |
| 20 | { |
Patrick Venture | 6352804 | 2019-05-20 18:10:02 -0700 | [diff] [blame] | 21 | static constexpr int btBufferLen = 50; |
| 22 | std::uint8_t readBuffer[btBufferLen]; |
| 23 | int bytesRead; |
| 24 | std::uint32_t offset = 0; |
| 25 | |
Patrick Venture | 907f3a7 | 2019-01-15 14:13:37 -0800 | [diff] [blame] | 26 | 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 Venture | 664c5bc | 2019-03-07 08:09:45 -0800 | [diff] [blame] | 39 | catch (const ipmiblob::BlobException& b) |
Patrick Venture | 907f3a7 | 2019-01-15 14:13:37 -0800 | [diff] [blame] | 40 | { |
| 41 | sys->close(inputFd); |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | sys->close(inputFd); |
| 46 | return true; |
Patrick Venture | af69625 | 2018-12-11 10:22:14 -0800 | [diff] [blame] | 47 | } |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 48 | |
| 49 | } // namespace host_tool |