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