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