blob: 93bc953f373da6ecab2e534489db800ee8afd3df [file] [log] [blame]
Patrick Ventureef3aead2018-09-12 08:53:29 -07001#pragma once
2
Patrick Venturecd8dab42019-01-15 19:57:38 -08003#include "manager.hpp"
4
Patrick Ventureef3aead2018-09-12 08:53:29 -07005#include <host-ipmid/ipmid-api.h>
6
Patrick Ventureef3aead2018-09-12 08:53:29 -07007#include <string>
8
9namespace blobs
10{
11
12enum BlobOEMCommands
13{
14 bmcBlobGetCount = 0,
15 bmcBlobEnumerate = 1,
16 bmcBlobOpen = 2,
17 bmcBlobRead = 3,
18 bmcBlobWrite = 4,
19 bmcBlobCommit = 5,
20 bmcBlobClose = 6,
21 bmcBlobDelete = 7,
22 bmcBlobStat = 8,
23 bmcBlobSessionStat = 9,
Patrick Venture5c4b17b2018-10-04 10:32:22 -070024 bmcBlobWriteMeta = 10,
Patrick Ventureef3aead2018-09-12 08:53:29 -070025};
26
27/* Used by bmcBlobGetCount */
28struct BmcBlobCountTx
29{
30 uint8_t cmd; /* bmcBlobGetCount */
31} __attribute__((packed));
32
33struct BmcBlobCountRx
34{
35 uint16_t crc;
36 uint32_t blobCount;
37} __attribute__((packed));
38
39/* Used by bmcBlobEnumerate */
40struct BmcBlobEnumerateTx
41{
42 uint8_t cmd; /* bmcBlobEnumerate */
43 uint16_t crc;
44 uint32_t blobIdx;
45} __attribute__((packed));
46
47struct BmcBlobEnumerateRx
48{
49 uint16_t crc;
50 char blobId[];
51} __attribute__((packed));
52
53/* Used by bmcBlobOpen */
54struct BmcBlobOpenTx
55{
56 uint8_t cmd; /* bmcBlobOpen */
57 uint16_t crc;
58 uint16_t flags;
59 char blobId[]; /* Must correspond to a valid blob. */
60} __attribute__((packed));
61
62struct BmcBlobOpenRx
63{
64 uint16_t crc;
65 uint16_t sessionId;
66} __attribute__((packed));
67
68/* Used by bmcBlobClose */
69struct BmcBlobCloseTx
70{
71 uint8_t cmd; /* bmcBlobClose */
72 uint16_t crc;
73 uint16_t sessionId; /* Returned from BmcBlobOpen. */
74} __attribute__((packed));
75
76/* Used by bmcBlobDelete */
77struct BmcBlobDeleteTx
78{
79 uint8_t cmd; /* bmcBlobDelete */
80 uint16_t crc;
81 char blobId[];
82} __attribute__((packed));
83
84/* Used by bmcBlobStat */
85struct BmcBlobStatTx
86{
87 uint8_t cmd; /* bmcBlobStat */
88 uint16_t crc;
89 char blobId[];
90} __attribute__((packed));
91
92struct BmcBlobStatRx
93{
94 uint16_t crc;
95 uint16_t blobState;
96 uint32_t size; /* Size in bytes of the blob. */
97 uint8_t metadataLen;
98 uint8_t metadata[]; /* Optional blob-specific metadata. */
99} __attribute__((packed));
100
101/* Used by bmcBlobSessionStat */
102struct BmcBlobSessionStatTx
103{
104 uint8_t cmd; /* bmcBlobSessionStat */
105 uint16_t crc;
106 uint16_t sessionId;
107} __attribute__((packed));
108
109/* Used by bmcBlobCommit */
110struct BmcBlobCommitTx
111{
112 uint8_t cmd; /* bmcBlobCommit */
113 uint16_t crc;
114 uint16_t sessionId;
115 uint8_t commitDataLen;
116 uint8_t commitData[]; /* Optional blob-specific commit data. */
117} __attribute__((packed));
118
119/* Used by bmcBlobRead */
120struct BmcBlobReadTx
121{
122 uint8_t cmd; /* bmcBlobRead */
123 uint16_t crc;
124 uint16_t sessionId;
125 uint32_t offset; /* The byte sequence start, 0-based. */
126 uint32_t requestedSize; /* The number of bytes requested for reading. */
127} __attribute__((packed));
128
129struct BmcBlobReadRx
130{
131 uint16_t crc;
132 uint8_t data[];
133} __attribute__((packed));
134
135/* Used by bmcBlobWrite */
136struct BmcBlobWriteTx
137{
138 uint8_t cmd; /* bmcBlobWrite */
139 uint16_t crc;
140 uint16_t sessionId;
141 uint32_t offset; /* The byte sequence start, 0-based. */
142 uint8_t data[];
143} __attribute__((packed));
144
Patrick Venture5c4b17b2018-10-04 10:32:22 -0700145/* Used by bmcBlobWriteMeta */
146struct BmcBlobWriteMetaTx
147{
148 uint8_t cmd; /* bmcBlobWriteMeta */
149 uint16_t crc;
150 uint16_t sessionId; /* Returned from BmcBlobOpen. */
151 uint32_t offset; /* The byte sequence start, 0-based. */
152 uint8_t data[];
153} __attribute__((packed));
154
Patrick Ventureef3aead2018-09-12 08:53:29 -0700155/**
156 * Validate the minimum request length if there is one.
157 *
158 * @param[in] subcommand - the command
159 * @param[in] requestLength - the length of the request
160 * @return bool - true if valid.
161 */
162bool validateRequestLength(BlobOEMCommands command, size_t requestLen);
163
164/**
165 * Given a pointer into an IPMI request buffer and the length of the remaining
166 * buffer, builds a string. This does no string validation w.r.t content.
167 *
168 * @param[in] start - the start of the expected string.
169 * @param[in] length - the number of bytes remaining in the buffer.
170 * @return the string if valid otherwise an empty string.
171 */
172std::string stringFromBuffer(const char* start, size_t length);
173
174/**
175 * Writes out a BmcBlobCountRx structure and returns IPMI_OK.
176 */
177ipmi_ret_t getBlobCount(ManagerInterface* mgr, const uint8_t* reqBuf,
178 uint8_t* replyCmdBuf, size_t* dataLen);
179
180/**
181 * Writes out a BmcBlobEnumerateRx in response to a BmcBlobEnumerateTx
182 * request. If the index does not correspond to a blob, then this will
183 * return failure.
184 *
185 * It will also return failure if the response buffer is of an invalid
186 * length.
187 */
188ipmi_ret_t enumerateBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
189 uint8_t* replyCmdBuf, size_t* dataLen);
190
191/**
192 * Attempts to open the blobId specified and associate with a session id.
193 */
194ipmi_ret_t openBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
195 uint8_t* replyCmdBuf, size_t* dataLen);
196
197/**
198 * Attempts to close the session specified.
199 */
200ipmi_ret_t closeBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
201 uint8_t* replyCmdBuf, size_t* dataLen);
202
203/**
204 * Attempts to delete the blobId specified.
205 */
206ipmi_ret_t deleteBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
207 uint8_t* replyCmdBuf, size_t* dataLen);
208
209/**
210 * Attempts to retrieve the Stat for the blobId specified.
211 */
212ipmi_ret_t statBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
213 uint8_t* replyCmdBuf, size_t* dataLen);
214
215/**
216 * Attempts to retrieve the Stat for the session specified.
217 */
218ipmi_ret_t sessionStatBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
219 uint8_t* replyCmdBuf, size_t* dataLen);
220
221/**
222 * Attempts to commit the data in the blob.
223 */
224ipmi_ret_t commitBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
225 uint8_t* replyCmdBuf, size_t* dataLen);
226
227/**
228 * Attempt to read data from the blob.
229 */
230ipmi_ret_t readBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
231 uint8_t* replyCmdBuf, size_t* dataLen);
232
233/**
234 * Attempt to write data to the blob.
235 */
236ipmi_ret_t writeBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
237 uint8_t* replyCmdBuf, size_t* dataLen);
Patrick Venture5c4b17b2018-10-04 10:32:22 -0700238
239/**
240 * Attempt to write metadata to the blob.
241 */
242ipmi_ret_t writeMeta(ManagerInterface* mgr, const uint8_t* reqBuf,
243 uint8_t* replyCmdBuf, size_t* dataLen);
244
Patrick Ventureef3aead2018-09-12 08:53:29 -0700245} // namespace blobs