blob: 3eede31f0efa8db0de29608f09079daf317dcdd8 [file] [log] [blame]
Patrick Venturec7ca2912018-11-02 11:38:33 -07001#pragma once
2
3#include <blobs-ipmid/blobs.hpp>
Patrick Venture192d60f2018-11-06 11:11:59 -08004#include <cstdint>
Patrick Venture68cf64f2018-11-06 10:46:51 -08005#include <memory>
Patrick Venture148cd652018-11-06 10:59:47 -08006#include <string>
7#include <vector>
Patrick Venturec7ca2912018-11-02 11:38:33 -07008
9namespace blobs
10{
11
Patrick Venturedf3e6ae2018-11-02 17:37:18 -070012enum 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 Venturec7ca2912018-11-02 11:38:33 -070019/**
20 * Register only one firmware blob handler that will manage all sessions.
21 */
22class FirmwareBlobHandler : public GenericBlobInterface
23{
24 public:
Patrick Venture137ad2c2018-11-06 11:30:43 -080025 /**
26 * Create a FirmwareBlobHandler.
27 *
Patrick Venture4cceb8e2018-11-06 11:56:48 -080028 * @param[in] firmwares - list of firmware blob_ids to support.
Patrick Venture137ad2c2018-11-06 11:30:43 -080029 * @param[in] transports - bitmask of transports to support.
30 */
Patrick Venture148cd652018-11-06 10:59:47 -080031 static std::unique_ptr<GenericBlobInterface>
Patrick Venture192d60f2018-11-06 11:11:59 -080032 CreateFirmwareBlobHandler(const std::vector<std::string>& firmwares,
33 std::uint32_t transports);
Patrick Venture68cf64f2018-11-06 10:46:51 -080034
Patrick Venture137ad2c2018-11-06 11:30:43 -080035 /**
36 * Create a FirmwareBlobHandler.
37 *
Patrick Venture4cceb8e2018-11-06 11:56:48 -080038 * @param[in] blobs - list of blobs_ids to support.
Patrick Venture137ad2c2018-11-06 11:30:43 -080039 * @param[in] transports - bitmask of transports to support.
40 */
Patrick Venture4cceb8e2018-11-06 11:56:48 -080041 FirmwareBlobHandler(const std::vector<std::string>& blobs,
Patrick Venture192d60f2018-11-06 11:11:59 -080042 std::uint32_t transports) :
Patrick Venture4cceb8e2018-11-06 11:56:48 -080043 blobIDs(blobs),
Patrick Venture192d60f2018-11-06 11:11:59 -080044 transports(transports)
Patrick Venture148cd652018-11-06 10:59:47 -080045 {
46 }
Patrick Venturec7ca2912018-11-02 11:38:33 -070047 ~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 Venture148cd652018-11-06 10:59:47 -080069
70 private:
Patrick Venture4cceb8e2018-11-06 11:56:48 -080071 std::vector<std::string> blobIDs;
Patrick Venture192d60f2018-11-06 11:11:59 -080072 std::uint32_t transports;
Patrick Venturec7ca2912018-11-02 11:38:33 -070073};
74
75} // namespace blobs