Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <blobs-ipmid/blobs.hpp> |
Patrick Venture | 192d60f | 2018-11-06 11:11:59 -0800 | [diff] [blame] | 4 | #include <cstdint> |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 5 | #include <memory> |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 6 | #include <string> |
| 7 | #include <vector> |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 8 | |
| 9 | namespace blobs |
| 10 | { |
| 11 | |
Patrick Venture | df3e6ae | 2018-11-02 17:37:18 -0700 | [diff] [blame] | 12 | enum class FirmwareUpdateFlags |
| 13 | { |
| 14 | bt = (1 << 8), /* Expect to send contents over IPMI BlockTransfer. */ |
| 15 | p2a = (1 << 9), /* Expect to send contents over P2A bridge. */ |
| 16 | lpc = (1 << 10), /* Expect to send contents over LPC bridge. */ |
| 17 | }; |
| 18 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 19 | /** |
| 20 | * Register only one firmware blob handler that will manage all sessions. |
| 21 | */ |
| 22 | class FirmwareBlobHandler : public GenericBlobInterface |
| 23 | { |
| 24 | public: |
Patrick Venture | 137ad2c | 2018-11-06 11:30:43 -0800 | [diff] [blame] | 25 | /** |
| 26 | * Create a FirmwareBlobHandler. |
| 27 | * |
Patrick Venture | 4cceb8e | 2018-11-06 11:56:48 -0800 | [diff] [blame^] | 28 | * @param[in] firmwares - list of firmware blob_ids to support. |
Patrick Venture | 137ad2c | 2018-11-06 11:30:43 -0800 | [diff] [blame] | 29 | * @param[in] transports - bitmask of transports to support. |
| 30 | */ |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 31 | static std::unique_ptr<GenericBlobInterface> |
Patrick Venture | 192d60f | 2018-11-06 11:11:59 -0800 | [diff] [blame] | 32 | CreateFirmwareBlobHandler(const std::vector<std::string>& firmwares, |
| 33 | std::uint32_t transports); |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 34 | |
Patrick Venture | 137ad2c | 2018-11-06 11:30:43 -0800 | [diff] [blame] | 35 | /** |
| 36 | * Create a FirmwareBlobHandler. |
| 37 | * |
Patrick Venture | 4cceb8e | 2018-11-06 11:56:48 -0800 | [diff] [blame^] | 38 | * @param[in] blobs - list of blobs_ids to support. |
Patrick Venture | 137ad2c | 2018-11-06 11:30:43 -0800 | [diff] [blame] | 39 | * @param[in] transports - bitmask of transports to support. |
| 40 | */ |
Patrick Venture | 4cceb8e | 2018-11-06 11:56:48 -0800 | [diff] [blame^] | 41 | FirmwareBlobHandler(const std::vector<std::string>& blobs, |
Patrick Venture | 192d60f | 2018-11-06 11:11:59 -0800 | [diff] [blame] | 42 | std::uint32_t transports) : |
Patrick Venture | 4cceb8e | 2018-11-06 11:56:48 -0800 | [diff] [blame^] | 43 | blobIDs(blobs), |
Patrick Venture | 192d60f | 2018-11-06 11:11:59 -0800 | [diff] [blame] | 44 | transports(transports) |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 45 | { |
| 46 | } |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 47 | ~FirmwareBlobHandler() = default; |
| 48 | FirmwareBlobHandler(const FirmwareBlobHandler&) = default; |
| 49 | FirmwareBlobHandler& operator=(const FirmwareBlobHandler&) = default; |
| 50 | FirmwareBlobHandler(FirmwareBlobHandler&&) = default; |
| 51 | FirmwareBlobHandler& operator=(FirmwareBlobHandler&&) = default; |
| 52 | |
| 53 | bool canHandleBlob(const std::string& path) override; |
| 54 | std::vector<std::string> getBlobIds() override; |
| 55 | bool deleteBlob(const std::string& path) override; |
| 56 | bool stat(const std::string& path, struct BlobMeta* meta) override; |
| 57 | bool open(uint16_t session, uint16_t flags, |
| 58 | const std::string& path) override; |
| 59 | std::vector<uint8_t> read(uint16_t session, uint32_t offset, |
| 60 | uint32_t requestedSize) override; |
| 61 | bool write(uint16_t session, uint32_t offset, |
| 62 | const std::vector<uint8_t>& data) override; |
| 63 | bool writeMeta(uint16_t session, uint32_t offset, |
| 64 | const std::vector<uint8_t>& data) override; |
| 65 | bool commit(uint16_t session, const std::vector<uint8_t>& data) override; |
| 66 | bool close(uint16_t session) override; |
| 67 | bool stat(uint16_t session, struct BlobMeta* meta) override; |
| 68 | bool expire(uint16_t session) override; |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 69 | |
| 70 | private: |
Patrick Venture | 4cceb8e | 2018-11-06 11:56:48 -0800 | [diff] [blame^] | 71 | std::vector<std::string> blobIDs; |
Patrick Venture | 192d60f | 2018-11-06 11:11:59 -0800 | [diff] [blame] | 72 | std::uint32_t transports; |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | } // namespace blobs |