blob: fc66847223e9a5ff4a6355ca22ace3d0f58a0dcd [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/**
Patrick Venture2d3a2542018-11-08 09:23:24 -080016 * Representation of a session, includes how to read/write data.
17 */
18struct 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 Venturec7ca2912018-11-02 11:38:33 -070030 * Register only one firmware blob handler that will manage all sessions.
31 */
32class FirmwareBlobHandler : public GenericBlobInterface
33{
34 public:
Patrick Venturefc3857b2018-11-07 08:14:55 -080035 enum FirmwareUpdateFlags : std::uint16_t
36 {
Patrick Venture9158dcf2018-11-08 09:44:28 -080037 ipmi = (1 << 8), /* Expect to send contents over IPMI BlockTransfer. */
Patrick Venturefc3857b2018-11-07 08:14:55 -080038 p2a = (1 << 9), /* Expect to send contents over P2A bridge. */
39 lpc = (1 << 10), /* Expect to send contents over LPC bridge. */
40 };
41
Patrick Venture137ad2c2018-11-06 11:30:43 -080042 /**
43 * Create a FirmwareBlobHandler.
44 *
Patrick Venture4cceb8e2018-11-06 11:56:48 -080045 * @param[in] firmwares - list of firmware blob_ids to support.
Patrick Venture1cde5f92018-11-07 08:26:47 -080046 * @param[in] transports - list of transports to support.
Patrick Venture137ad2c2018-11-06 11:30:43 -080047 */
Patrick Venture1cde5f92018-11-07 08:26:47 -080048 static std::unique_ptr<GenericBlobInterface> CreateFirmwareBlobHandler(
49 const std::vector<HandlerPack>& firmwares,
50 const std::vector<DataHandlerPack>& transports);
Patrick Venture68cf64f2018-11-06 10:46:51 -080051
Patrick Venture137ad2c2018-11-06 11:30:43 -080052 /**
53 * Create a FirmwareBlobHandler.
54 *
Patrick Venture1cde5f92018-11-07 08:26:47 -080055 * @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 Venture137ad2c2018-11-06 11:30:43 -080059 */
Patrick Venturea78e39f2018-11-06 18:37:06 -080060 FirmwareBlobHandler(const std::vector<HandlerPack>& firmwares,
61 const std::vector<std::string>& blobs,
Patrick Venture1cde5f92018-11-07 08:26:47 -080062 const std::vector<DataHandlerPack>& transports,
63 std::uint16_t bitmask) :
Patrick Venturea78e39f2018-11-06 18:37:06 -080064 handlers(firmwares),
Patrick Venture1cde5f92018-11-07 08:26:47 -080065 blobIDs(blobs), transports(transports), bitmask(bitmask)
Patrick Venture148cd652018-11-06 10:59:47 -080066 {
67 }
Patrick Venturec7ca2912018-11-02 11:38:33 -070068 ~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 Venture148cd652018-11-06 10:59:47 -080090
Patrick Venture21be45a2018-11-06 12:08:52 -080091 static const std::string hashBlobID;
Patrick Venture7b9256f2018-11-06 15:06:04 -080092 static const std::string activeImageBlobID;
93 static const std::string activeHashBlobID;
Patrick Venture21be45a2018-11-06 12:08:52 -080094
Patrick Venture148cd652018-11-06 10:59:47 -080095 private:
Patrick Venturea78e39f2018-11-06 18:37:06 -080096 /** List of handlers by type. */
97 std::vector<HandlerPack> handlers;
98
Patrick Venturec02849b2018-11-06 17:31:15 -080099 /** Active list of blobIDs. */
Patrick Venture4cceb8e2018-11-06 11:56:48 -0800100 std::vector<std::string> blobIDs;
Patrick Venturec02849b2018-11-06 17:31:15 -0800101
Patrick Venture1cde5f92018-11-07 08:26:47 -0800102 /** List of handlers by transport type. */
103 std::vector<DataHandlerPack> transports;
104
Patrick Venturec02849b2018-11-06 17:31:15 -0800105 /** The bits set indicate what transport mechanisms are supported. */
Patrick Venture1cde5f92018-11-07 08:26:47 -0800106 std::uint16_t bitmask;
Patrick Venturec02849b2018-11-06 17:31:15 -0800107
108 /** Temporary variable to track whether a blob is open. */
109 bool fileOpen = false;
Patrick Venturec7ca2912018-11-02 11:38:33 -0700110};
111
112} // namespace blobs