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