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