summaryrefslogtreecommitdiffstats
path: root/ipmi.hpp
blob: b79b1eed189ec0d30d0bf20ce1f0d60024ed7466 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#pragma once

#include "manager.hpp"

#include <ipmid/api.h>

#include <blobs-ipmid/blobs.hpp>
#include <string>

namespace blobs
{

/* Used by bmcBlobGetCount */
struct BmcBlobCountTx
{
    uint8_t cmd; /* bmcBlobGetCount */
} __attribute__((packed));

struct BmcBlobCountRx
{
    uint16_t crc;
    uint32_t blobCount;
} __attribute__((packed));

/* Used by bmcBlobEnumerate */
struct BmcBlobEnumerateTx
{
    uint8_t cmd; /* bmcBlobEnumerate */
    uint16_t crc;
    uint32_t blobIdx;
} __attribute__((packed));

struct BmcBlobEnumerateRx
{
    uint16_t crc;
    char blobId[];
} __attribute__((packed));

/* Used by bmcBlobOpen */
struct BmcBlobOpenTx
{
    uint8_t cmd; /* bmcBlobOpen */
    uint16_t crc;
    uint16_t flags;
    char blobId[]; /* Must correspond to a valid blob. */
} __attribute__((packed));

struct BmcBlobOpenRx
{
    uint16_t crc;
    uint16_t sessionId;
} __attribute__((packed));

/* Used by bmcBlobClose */
struct BmcBlobCloseTx
{
    uint8_t cmd; /* bmcBlobClose */
    uint16_t crc;
    uint16_t sessionId; /* Returned from BmcBlobOpen. */
} __attribute__((packed));

/* Used by bmcBlobDelete */
struct BmcBlobDeleteTx
{
    uint8_t cmd; /* bmcBlobDelete */
    uint16_t crc;
    char blobId[];
} __attribute__((packed));

/* Used by bmcBlobStat */
struct BmcBlobStatTx
{
    uint8_t cmd; /* bmcBlobStat */
    uint16_t crc;
    char blobId[];
} __attribute__((packed));

struct BmcBlobStatRx
{
    uint16_t crc;
    uint16_t blobState;
    uint32_t size; /* Size in bytes of the blob. */
    uint8_t metadataLen;
    uint8_t metadata[]; /* Optional blob-specific metadata. */
} __attribute__((packed));

/* Used by bmcBlobSessionStat */
struct BmcBlobSessionStatTx
{
    uint8_t cmd; /* bmcBlobSessionStat */
    uint16_t crc;
    uint16_t sessionId;
} __attribute__((packed));

/* Used by bmcBlobCommit */
struct BmcBlobCommitTx
{
    uint8_t cmd; /* bmcBlobCommit */
    uint16_t crc;
    uint16_t sessionId;
    uint8_t commitDataLen;
    uint8_t commitData[]; /* Optional blob-specific commit data. */
} __attribute__((packed));

/* Used by bmcBlobRead */
struct BmcBlobReadTx
{
    uint8_t cmd; /* bmcBlobRead */
    uint16_t crc;
    uint16_t sessionId;
    uint32_t offset;        /* The byte sequence start, 0-based. */
    uint32_t requestedSize; /* The number of bytes requested for reading. */
} __attribute__((packed));

struct BmcBlobReadRx
{
    uint16_t crc;
    uint8_t data[];
} __attribute__((packed));

/* Used by bmcBlobWrite */
struct BmcBlobWriteTx
{
    uint8_t cmd; /* bmcBlobWrite */
    uint16_t crc;
    uint16_t sessionId;
    uint32_t offset; /* The byte sequence start, 0-based. */
    uint8_t data[];
} __attribute__((packed));

/* Used by bmcBlobWriteMeta */
struct BmcBlobWriteMetaTx
{
    uint8_t cmd; /* bmcBlobWriteMeta */
    uint16_t crc;
    uint16_t sessionId; /* Returned from BmcBlobOpen. */
    uint32_t offset;    /* The byte sequence start, 0-based. */
    uint8_t data[];
} __attribute__((packed));

/**
 * Validate the minimum request length if there is one.
 *
 * @param[in] subcommand - the command
 * @param[in] requestLength - the length of the request
 * @return bool - true if valid.
 */
bool validateRequestLength(BlobOEMCommands command, size_t requestLen);

/**
 * Given a pointer into an IPMI request buffer and the length of the remaining
 * buffer, builds a string.  This does no string validation w.r.t content.
 *
 * @param[in] start - the start of the expected string.
 * @param[in] length - the number of bytes remaining in the buffer.
 * @return the string if valid otherwise an empty string.
 */
std::string stringFromBuffer(const char* start, size_t length);

/**
 * Writes out a BmcBlobCountRx structure and returns IPMI_OK.
 */
ipmi_ret_t getBlobCount(ManagerInterface* mgr, const uint8_t* reqBuf,
                        uint8_t* replyCmdBuf, size_t* dataLen);

/**
 * Writes out a BmcBlobEnumerateRx in response to a BmcBlobEnumerateTx
 * request.  If the index does not correspond to a blob, then this will
 * return failure.
 *
 * It will also return failure if the response buffer is of an invalid
 * length.
 */
ipmi_ret_t enumerateBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
                         uint8_t* replyCmdBuf, size_t* dataLen);

/**
 * Attempts to open the blobId specified and associate with a session id.
 */
ipmi_ret_t openBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
                    uint8_t* replyCmdBuf, size_t* dataLen);

/**
 * Attempts to close the session specified.
 */
ipmi_ret_t closeBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
                     uint8_t* replyCmdBuf, size_t* dataLen);

/**
 * Attempts to delete the blobId specified.
 */
ipmi_ret_t deleteBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
                      uint8_t* replyCmdBuf, size_t* dataLen);

/**
 * Attempts to retrieve the Stat for the blobId specified.
 */
ipmi_ret_t statBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
                    uint8_t* replyCmdBuf, size_t* dataLen);

/**
 * Attempts to retrieve the Stat for the session specified.
 */
ipmi_ret_t sessionStatBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
                           uint8_t* replyCmdBuf, size_t* dataLen);

/**
 * Attempts to commit the data in the blob.
 */
ipmi_ret_t commitBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
                      uint8_t* replyCmdBuf, size_t* dataLen);

/**
 * Attempt to read data from the blob.
 */
ipmi_ret_t readBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
                    uint8_t* replyCmdBuf, size_t* dataLen);

/**
 * Attempt to write data to the blob.
 */
ipmi_ret_t writeBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
                     uint8_t* replyCmdBuf, size_t* dataLen);

/**
 * Attempt to write metadata to the blob.
 */
ipmi_ret_t writeMeta(ManagerInterface* mgr, const uint8_t* reqBuf,
                     uint8_t* replyCmdBuf, size_t* dataLen);

} // namespace blobs
OpenPOWER on IntegriCloud