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