summaryrefslogtreecommitdiffstats
path: root/src/ipmiblob/blob_interface.hpp
blob: fbd8c6a45ac0b1d4b21dfab754c52bca0ae46a4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#pragma once

#include <cstdint>
#include <string>
#include <vector>

namespace ipmiblob
{

enum class BlobOEMCommands : std::uint8_t
{
    bmcBlobGetCount = 0,
    bmcBlobEnumerate = 1,
    bmcBlobOpen = 2,
    bmcBlobRead = 3,
    bmcBlobWrite = 4,
    bmcBlobCommit = 5,
    bmcBlobClose = 6,
    bmcBlobDelete = 7,
    bmcBlobStat = 8,
    bmcBlobSessionStat = 9,
    bmcBlobWriteMeta = 10,
};

struct StatResponse
{
    std::uint16_t blob_state;
    std::uint32_t size;
    std::vector<std::uint8_t> metadata;

    bool operator==(const StatResponse& rhs) const
    {
        return (this->blob_state == rhs.blob_state && this->size == rhs.size &&
                this->metadata == rhs.metadata);
    }
};

class BlobInterface
{
  public:
    virtual ~BlobInterface() = default;

    /**
     * Call commit on a blob.  The behavior here is up to the blob itself.
     *
     * @param[in] session - the session id.
     * @param[in] bytes - the bytes to send.
     * @throws BlobException on failure.
     */
    virtual void commit(std::uint16_t session,
                        const std::vector<std::uint8_t>& bytes) = 0;

    /**
     * Write metadata to a blob.
     *
     * @param[in] session - the session id.
     * @param[in] offset - the offset for the metadata to write.
     * @param[in] bytes - the bytes to send.
     * @throws BlobException on failure.
     */
    virtual void writeMeta(std::uint16_t session, std::uint32_t offset,
                           const std::vector<std::uint8_t>& bytes) = 0;

    /**
     * Write bytes to a blob.
     *
     * @param[in] session - the session id.
     * @param[in] offset - the offset to which to write the bytes.
     * @param[in] bytes - the bytes to send.
     * @throws BlobException on failure.
     */
    virtual void writeBytes(std::uint16_t session, std::uint32_t offset,
                            const std::vector<std::uint8_t>& bytes) = 0;

    /**
     * Get a list of the blob_ids provided by the BMC.
     *
     * @return list of strings, each representing a blob_id returned.
     */
    virtual std::vector<std::string> getBlobList() = 0;

    /**
     * Get the stat() on the blob_id.
     *
     * @param[in] id - the blob_id.
     * @return metadata structure.
     */
    virtual StatResponse getStat(const std::string& id) = 0;

    /**
     * Get the stat() on the blob session.
     *
     * @param[in] session - the blob session
     * @return metadata structure
     */
    virtual StatResponse getStat(std::uint16_t session) = 0;

    /**
     * Attempt to open the file using the specific data interface flag.
     *
     * @param[in] blob - the blob_id to open.
     * @param[in] handlerFlags - the data interface flag, if relevant.
     * @return the session id on success.
     * @throws BlobException on failure.
     */
    virtual std::uint16_t openBlob(const std::string& id,
                                   std::uint16_t handlerFlags) = 0;

    /**
     * Attempt to close the open session.
     *
     * @param[in] session - the session to close.
     */
    virtual void closeBlob(std::uint16_t session) = 0;

    /**
     * Read bytes from a blob.
     *
     * @param[in] session - the session id.
     * @param[in] offset - the offset to which to write the bytes.
     * @param[in] length - the number of bytes to read.
     * @return the bytes read
     * @throws BlobException on failure.
     */
    virtual std::vector<std::uint8_t> readBytes(std::uint16_t session,
                                                std::uint32_t offset,
                                                std::uint32_t length) = 0;
};

} // namespace ipmiblob
OpenPOWER on IntegriCloud