blob: 786b2d196e83ddbb378608acd869e331b866fe8c [file] [log] [blame]
Patrick Venturec7ca2912018-11-02 11:38:33 -07001#pragma once
2
Patrick Venture1cde5f92018-11-07 08:26:47 -08003#include "data_handler.hpp"
Patrick Venturea78e39f2018-11-06 18:37:06 -08004#include "image_handler.hpp"
5
Patrick Venturec7ca2912018-11-02 11:38:33 -07006#include <blobs-ipmid/blobs.hpp>
Patrick Venture192d60f2018-11-06 11:11:59 -08007#include <cstdint>
Patrick Venture68cf64f2018-11-06 10:46:51 -08008#include <memory>
Patrick Venture148cd652018-11-06 10:59:47 -08009#include <string>
10#include <vector>
Patrick Venturec7ca2912018-11-02 11:38:33 -070011
12namespace blobs
13{
14
Patrick Venturec7ca2912018-11-02 11:38:33 -070015/**
16 * Register only one firmware blob handler that will manage all sessions.
17 */
18class FirmwareBlobHandler : public GenericBlobInterface
19{
20 public:
Patrick Venturefc3857b2018-11-07 08:14:55 -080021 enum FirmwareUpdateFlags : std::uint16_t
22 {
23 bt = (1 << 8), /* Expect to send contents over IPMI BlockTransfer. */
24 p2a = (1 << 9), /* Expect to send contents over P2A bridge. */
25 lpc = (1 << 10), /* Expect to send contents over LPC bridge. */
26 };
27
Patrick Venture137ad2c2018-11-06 11:30:43 -080028 /**
29 * Create a FirmwareBlobHandler.
30 *
Patrick Venture4cceb8e2018-11-06 11:56:48 -080031 * @param[in] firmwares - list of firmware blob_ids to support.
Patrick Venture1cde5f92018-11-07 08:26:47 -080032 * @param[in] transports - list of transports to support.
Patrick Venture137ad2c2018-11-06 11:30:43 -080033 */
Patrick Venture1cde5f92018-11-07 08:26:47 -080034 static std::unique_ptr<GenericBlobInterface> CreateFirmwareBlobHandler(
35 const std::vector<HandlerPack>& firmwares,
36 const std::vector<DataHandlerPack>& transports);
Patrick Venture68cf64f2018-11-06 10:46:51 -080037
Patrick Venture137ad2c2018-11-06 11:30:43 -080038 /**
39 * Create a FirmwareBlobHandler.
40 *
Patrick Venture1cde5f92018-11-07 08:26:47 -080041 * @param[in] firmwares - list of firmware types and their handlers
42 * @param[in] blobs - list of blobs_ids to support
43 * @param[in] transports - list of transport types and their handlers
44 * @param[in] bitmask - bitmask of transports to support
Patrick Venture137ad2c2018-11-06 11:30:43 -080045 */
Patrick Venturea78e39f2018-11-06 18:37:06 -080046 FirmwareBlobHandler(const std::vector<HandlerPack>& firmwares,
47 const std::vector<std::string>& blobs,
Patrick Venture1cde5f92018-11-07 08:26:47 -080048 const std::vector<DataHandlerPack>& transports,
49 std::uint16_t bitmask) :
Patrick Venturea78e39f2018-11-06 18:37:06 -080050 handlers(firmwares),
Patrick Venture1cde5f92018-11-07 08:26:47 -080051 blobIDs(blobs), transports(transports), bitmask(bitmask)
Patrick Venture148cd652018-11-06 10:59:47 -080052 {
53 }
Patrick Venturec7ca2912018-11-02 11:38:33 -070054 ~FirmwareBlobHandler() = default;
55 FirmwareBlobHandler(const FirmwareBlobHandler&) = default;
56 FirmwareBlobHandler& operator=(const FirmwareBlobHandler&) = default;
57 FirmwareBlobHandler(FirmwareBlobHandler&&) = default;
58 FirmwareBlobHandler& operator=(FirmwareBlobHandler&&) = default;
59
60 bool canHandleBlob(const std::string& path) override;
61 std::vector<std::string> getBlobIds() override;
62 bool deleteBlob(const std::string& path) override;
63 bool stat(const std::string& path, struct BlobMeta* meta) override;
64 bool open(uint16_t session, uint16_t flags,
65 const std::string& path) override;
66 std::vector<uint8_t> read(uint16_t session, uint32_t offset,
67 uint32_t requestedSize) override;
68 bool write(uint16_t session, uint32_t offset,
69 const std::vector<uint8_t>& data) override;
70 bool writeMeta(uint16_t session, uint32_t offset,
71 const std::vector<uint8_t>& data) override;
72 bool commit(uint16_t session, const std::vector<uint8_t>& data) override;
73 bool close(uint16_t session) override;
74 bool stat(uint16_t session, struct BlobMeta* meta) override;
75 bool expire(uint16_t session) override;
Patrick Venture148cd652018-11-06 10:59:47 -080076
Patrick Venture21be45a2018-11-06 12:08:52 -080077 static const std::string hashBlobID;
Patrick Venture7b9256f2018-11-06 15:06:04 -080078 static const std::string activeImageBlobID;
79 static const std::string activeHashBlobID;
Patrick Venture21be45a2018-11-06 12:08:52 -080080
Patrick Venture148cd652018-11-06 10:59:47 -080081 private:
Patrick Venturea78e39f2018-11-06 18:37:06 -080082 /** List of handlers by type. */
83 std::vector<HandlerPack> handlers;
84
Patrick Venturec02849b2018-11-06 17:31:15 -080085 /** Active list of blobIDs. */
Patrick Venture4cceb8e2018-11-06 11:56:48 -080086 std::vector<std::string> blobIDs;
Patrick Venturec02849b2018-11-06 17:31:15 -080087
Patrick Venture1cde5f92018-11-07 08:26:47 -080088 /** List of handlers by transport type. */
89 std::vector<DataHandlerPack> transports;
90
Patrick Venturec02849b2018-11-06 17:31:15 -080091 /** The bits set indicate what transport mechanisms are supported. */
Patrick Venture1cde5f92018-11-07 08:26:47 -080092 std::uint16_t bitmask;
Patrick Venturec02849b2018-11-06 17:31:15 -080093
94 /** Temporary variable to track whether a blob is open. */
95 bool fileOpen = false;
Patrick Venturec7ca2912018-11-02 11:38:33 -070096};
97
98} // namespace blobs