Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 3 | #include "data_handler.hpp" |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 4 | #include "image_handler.hpp" |
| 5 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 6 | #include <blobs-ipmid/blobs.hpp> |
Patrick Venture | 192d60f | 2018-11-06 11:11:59 -0800 | [diff] [blame] | 7 | #include <cstdint> |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 8 | #include <memory> |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 11 | |
| 12 | namespace blobs |
| 13 | { |
| 14 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 15 | /** |
Patrick Venture | 2d3a254 | 2018-11-08 09:23:24 -0800 | [diff] [blame] | 16 | * Representation of a session, includes how to read/write data. |
| 17 | */ |
| 18 | struct Session |
| 19 | { |
| 20 | /** Pointer to the correct Data handler interface. (nullptr on BT (or KCS)) |
| 21 | */ |
| 22 | DataInterface* dataHandler; |
| 23 | |
| 24 | /** Pointer to the correct image handler interface. (nullptr on hash |
| 25 | * blob_id) */ |
| 26 | ImageHandlerInterface* imageHandler; |
| 27 | }; |
| 28 | |
| 29 | /** |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 30 | * Register only one firmware blob handler that will manage all sessions. |
| 31 | */ |
| 32 | class FirmwareBlobHandler : public GenericBlobInterface |
| 33 | { |
| 34 | public: |
Patrick Venture | fc3857b | 2018-11-07 08:14:55 -0800 | [diff] [blame] | 35 | enum FirmwareUpdateFlags : std::uint16_t |
| 36 | { |
Patrick Venture | 9158dcf | 2018-11-08 09:44:28 -0800 | [diff] [blame] | 37 | ipmi = (1 << 8), /* Expect to send contents over IPMI BlockTransfer. */ |
Patrick Venture | fc3857b | 2018-11-07 08:14:55 -0800 | [diff] [blame] | 38 | p2a = (1 << 9), /* Expect to send contents over P2A bridge. */ |
| 39 | lpc = (1 << 10), /* Expect to send contents over LPC bridge. */ |
| 40 | }; |
| 41 | |
Patrick Venture | 137ad2c | 2018-11-06 11:30:43 -0800 | [diff] [blame] | 42 | /** |
| 43 | * Create a FirmwareBlobHandler. |
| 44 | * |
Patrick Venture | 4cceb8e | 2018-11-06 11:56:48 -0800 | [diff] [blame] | 45 | * @param[in] firmwares - list of firmware blob_ids to support. |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 46 | * @param[in] transports - list of transports to support. |
Patrick Venture | 137ad2c | 2018-11-06 11:30:43 -0800 | [diff] [blame] | 47 | */ |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 48 | static std::unique_ptr<GenericBlobInterface> CreateFirmwareBlobHandler( |
| 49 | const std::vector<HandlerPack>& firmwares, |
| 50 | const std::vector<DataHandlerPack>& transports); |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 51 | |
Patrick Venture | 137ad2c | 2018-11-06 11:30:43 -0800 | [diff] [blame] | 52 | /** |
| 53 | * Create a FirmwareBlobHandler. |
| 54 | * |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 55 | * @param[in] firmwares - list of firmware types and their handlers |
| 56 | * @param[in] blobs - list of blobs_ids to support |
| 57 | * @param[in] transports - list of transport types and their handlers |
| 58 | * @param[in] bitmask - bitmask of transports to support |
Patrick Venture | 137ad2c | 2018-11-06 11:30:43 -0800 | [diff] [blame] | 59 | */ |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 60 | FirmwareBlobHandler(const std::vector<HandlerPack>& firmwares, |
| 61 | const std::vector<std::string>& blobs, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 62 | const std::vector<DataHandlerPack>& transports, |
| 63 | std::uint16_t bitmask) : |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 64 | handlers(firmwares), |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 65 | blobIDs(blobs), transports(transports), bitmask(bitmask) |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 66 | { |
| 67 | } |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 68 | ~FirmwareBlobHandler() = default; |
| 69 | FirmwareBlobHandler(const FirmwareBlobHandler&) = default; |
| 70 | FirmwareBlobHandler& operator=(const FirmwareBlobHandler&) = default; |
| 71 | FirmwareBlobHandler(FirmwareBlobHandler&&) = default; |
| 72 | FirmwareBlobHandler& operator=(FirmwareBlobHandler&&) = default; |
| 73 | |
| 74 | bool canHandleBlob(const std::string& path) override; |
| 75 | std::vector<std::string> getBlobIds() override; |
| 76 | bool deleteBlob(const std::string& path) override; |
| 77 | bool stat(const std::string& path, struct BlobMeta* meta) override; |
| 78 | bool open(uint16_t session, uint16_t flags, |
| 79 | const std::string& path) override; |
| 80 | std::vector<uint8_t> read(uint16_t session, uint32_t offset, |
| 81 | uint32_t requestedSize) override; |
| 82 | bool write(uint16_t session, uint32_t offset, |
| 83 | const std::vector<uint8_t>& data) override; |
| 84 | bool writeMeta(uint16_t session, uint32_t offset, |
| 85 | const std::vector<uint8_t>& data) override; |
| 86 | bool commit(uint16_t session, const std::vector<uint8_t>& data) override; |
| 87 | bool close(uint16_t session) override; |
| 88 | bool stat(uint16_t session, struct BlobMeta* meta) override; |
| 89 | bool expire(uint16_t session) override; |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 90 | |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 91 | static const std::string hashBlobID; |
Patrick Venture | 7b9256f | 2018-11-06 15:06:04 -0800 | [diff] [blame] | 92 | static const std::string activeImageBlobID; |
| 93 | static const std::string activeHashBlobID; |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 94 | |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 95 | private: |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 96 | /** List of handlers by type. */ |
| 97 | std::vector<HandlerPack> handlers; |
| 98 | |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 99 | /** Active list of blobIDs. */ |
Patrick Venture | 4cceb8e | 2018-11-06 11:56:48 -0800 | [diff] [blame] | 100 | std::vector<std::string> blobIDs; |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 101 | |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 102 | /** List of handlers by transport type. */ |
| 103 | std::vector<DataHandlerPack> transports; |
| 104 | |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 105 | /** The bits set indicate what transport mechanisms are supported. */ |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 106 | std::uint16_t bitmask; |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 107 | |
| 108 | /** Temporary variable to track whether a blob is open. */ |
| 109 | bool fileOpen = false; |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | } // namespace blobs |