xref: /openbmc/phosphor-ipmi-blobs/ipmi.hpp (revision 5250957212ebf851d49df046acd6416a0d17c749)
1ef3aeadcSPatrick Venture #pragma once
2ef3aeadcSPatrick Venture 
3cd8dab49SPatrick Venture #include "manager.hpp"
4cd8dab49SPatrick Venture 
5acebece3SWilliam A. Kennington III #include <ipmid/api.h>
6ef3aeadcSPatrick Venture 
74beac9a0SPatrick Venture #include <blobs-ipmid/blobs.hpp>
8067ece15SWilly Tu #include <ipmid/api-types.hpp>
9*52509572SPatrick Williams 
10067ece15SWilly Tu #include <span>
11ef3aeadcSPatrick Venture #include <string>
12067ece15SWilly Tu #include <vector>
13ef3aeadcSPatrick Venture 
14ef3aeadcSPatrick Venture namespace blobs
15ef3aeadcSPatrick Venture {
16ef3aeadcSPatrick Venture 
17067ece15SWilly Tu using Resp = ipmi::RspType<std::vector<uint8_t>>;
18067ece15SWilly Tu 
19ef3aeadcSPatrick Venture /* Used by bmcBlobGetCount */
20ef3aeadcSPatrick Venture struct BmcBlobCountTx
21ef3aeadcSPatrick Venture {
22ef3aeadcSPatrick Venture } __attribute__((packed));
23ef3aeadcSPatrick Venture 
24ef3aeadcSPatrick Venture struct BmcBlobCountRx
25ef3aeadcSPatrick Venture {
26ef3aeadcSPatrick Venture     uint16_t crc;
27ef3aeadcSPatrick Venture     uint32_t blobCount;
28ef3aeadcSPatrick Venture } __attribute__((packed));
29ef3aeadcSPatrick Venture 
30ef3aeadcSPatrick Venture /* Used by bmcBlobEnumerate */
31ef3aeadcSPatrick Venture struct BmcBlobEnumerateTx
32ef3aeadcSPatrick Venture {
33ef3aeadcSPatrick Venture     uint16_t crc;
34ef3aeadcSPatrick Venture     uint32_t blobIdx;
35ef3aeadcSPatrick Venture } __attribute__((packed));
36ef3aeadcSPatrick Venture 
37ef3aeadcSPatrick Venture struct BmcBlobEnumerateRx
38ef3aeadcSPatrick Venture {
39ef3aeadcSPatrick Venture     uint16_t crc;
40ef3aeadcSPatrick Venture } __attribute__((packed));
41ef3aeadcSPatrick Venture 
42ef3aeadcSPatrick Venture /* Used by bmcBlobOpen */
43ef3aeadcSPatrick Venture struct BmcBlobOpenTx
44ef3aeadcSPatrick Venture {
45ef3aeadcSPatrick Venture     uint16_t crc;
46ef3aeadcSPatrick Venture     uint16_t flags;
47ef3aeadcSPatrick Venture } __attribute__((packed));
48ef3aeadcSPatrick Venture 
49ef3aeadcSPatrick Venture struct BmcBlobOpenRx
50ef3aeadcSPatrick Venture {
51ef3aeadcSPatrick Venture     uint16_t crc;
52ef3aeadcSPatrick Venture     uint16_t sessionId;
53ef3aeadcSPatrick Venture } __attribute__((packed));
54ef3aeadcSPatrick Venture 
55ef3aeadcSPatrick Venture /* Used by bmcBlobClose */
56ef3aeadcSPatrick Venture struct BmcBlobCloseTx
57ef3aeadcSPatrick Venture {
58ef3aeadcSPatrick Venture     uint16_t crc;
59ef3aeadcSPatrick Venture     uint16_t sessionId; /* Returned from BmcBlobOpen. */
60ef3aeadcSPatrick Venture } __attribute__((packed));
61ef3aeadcSPatrick Venture 
62ef3aeadcSPatrick Venture /* Used by bmcBlobDelete */
63ef3aeadcSPatrick Venture struct BmcBlobDeleteTx
64ef3aeadcSPatrick Venture {
65ef3aeadcSPatrick Venture     uint16_t crc;
66ef3aeadcSPatrick Venture } __attribute__((packed));
67ef3aeadcSPatrick Venture 
68ef3aeadcSPatrick Venture /* Used by bmcBlobStat */
69ef3aeadcSPatrick Venture struct BmcBlobStatTx
70ef3aeadcSPatrick Venture {
71ef3aeadcSPatrick Venture     uint16_t crc;
72ef3aeadcSPatrick Venture } __attribute__((packed));
73ef3aeadcSPatrick Venture 
74ef3aeadcSPatrick Venture struct BmcBlobStatRx
75ef3aeadcSPatrick Venture {
76ef3aeadcSPatrick Venture     uint16_t crc;
77ef3aeadcSPatrick Venture     uint16_t blobState;
78ef3aeadcSPatrick Venture     uint32_t size; /* Size in bytes of the blob. */
79ef3aeadcSPatrick Venture     uint8_t metadataLen;
80ef3aeadcSPatrick Venture } __attribute__((packed));
81ef3aeadcSPatrick Venture 
82ef3aeadcSPatrick Venture /* Used by bmcBlobSessionStat */
83ef3aeadcSPatrick Venture struct BmcBlobSessionStatTx
84ef3aeadcSPatrick Venture {
85ef3aeadcSPatrick Venture     uint16_t crc;
86ef3aeadcSPatrick Venture     uint16_t sessionId;
87ef3aeadcSPatrick Venture } __attribute__((packed));
88ef3aeadcSPatrick Venture 
89ef3aeadcSPatrick Venture /* Used by bmcBlobCommit */
90ef3aeadcSPatrick Venture struct BmcBlobCommitTx
91ef3aeadcSPatrick Venture {
92ef3aeadcSPatrick Venture     uint16_t crc;
93ef3aeadcSPatrick Venture     uint16_t sessionId;
94ef3aeadcSPatrick Venture     uint8_t commitDataLen;
95ef3aeadcSPatrick Venture } __attribute__((packed));
96ef3aeadcSPatrick Venture 
97ef3aeadcSPatrick Venture /* Used by bmcBlobRead */
98ef3aeadcSPatrick Venture struct BmcBlobReadTx
99ef3aeadcSPatrick Venture {
100ef3aeadcSPatrick Venture     uint16_t crc;
101ef3aeadcSPatrick Venture     uint16_t sessionId;
102ef3aeadcSPatrick Venture     uint32_t offset;        /* The byte sequence start, 0-based. */
103ef3aeadcSPatrick Venture     uint32_t requestedSize; /* The number of bytes requested for reading. */
104ef3aeadcSPatrick Venture } __attribute__((packed));
105ef3aeadcSPatrick Venture 
106ef3aeadcSPatrick Venture struct BmcBlobReadRx
107ef3aeadcSPatrick Venture {
108ef3aeadcSPatrick Venture     uint16_t crc;
109ef3aeadcSPatrick Venture } __attribute__((packed));
110ef3aeadcSPatrick Venture 
111ef3aeadcSPatrick Venture /* Used by bmcBlobWrite */
112ef3aeadcSPatrick Venture struct BmcBlobWriteTx
113ef3aeadcSPatrick Venture {
114ef3aeadcSPatrick Venture     uint16_t crc;
115ef3aeadcSPatrick Venture     uint16_t sessionId;
116ef3aeadcSPatrick Venture     uint32_t offset; /* The byte sequence start, 0-based. */
117ef3aeadcSPatrick Venture } __attribute__((packed));
118ef3aeadcSPatrick Venture 
1195c4b17b2SPatrick Venture /* Used by bmcBlobWriteMeta */
1205c4b17b2SPatrick Venture struct BmcBlobWriteMetaTx
1215c4b17b2SPatrick Venture {
1225c4b17b2SPatrick Venture     uint16_t crc;
1235c4b17b2SPatrick Venture     uint16_t sessionId; /* Returned from BmcBlobOpen. */
1245c4b17b2SPatrick Venture     uint32_t offset;    /* The byte sequence start, 0-based. */
1255c4b17b2SPatrick Venture } __attribute__((packed));
1265c4b17b2SPatrick Venture 
127ef3aeadcSPatrick Venture /**
128ef3aeadcSPatrick Venture  * Validate the minimum request length if there is one.
129ef3aeadcSPatrick Venture  *
130ef3aeadcSPatrick Venture  * @param[in] subcommand - the command
131ef3aeadcSPatrick Venture  * @param[in] requestLength - the length of the request
132ef3aeadcSPatrick Venture  * @return bool - true if valid.
133ef3aeadcSPatrick Venture  */
134ef3aeadcSPatrick Venture bool validateRequestLength(BlobOEMCommands command, size_t requestLen);
135ef3aeadcSPatrick Venture 
136ef3aeadcSPatrick Venture /**
137ef3aeadcSPatrick Venture  * Given a pointer into an IPMI request buffer and the length of the remaining
138ef3aeadcSPatrick Venture  * buffer, builds a string.  This does no string validation w.r.t content.
139ef3aeadcSPatrick Venture  *
140067ece15SWilly Tu  * @param[in] data - Buffer containing the string.
141ef3aeadcSPatrick Venture  * @return the string if valid otherwise an empty string.
142ef3aeadcSPatrick Venture  */
143067ece15SWilly Tu std::string stringFromBuffer(std::span<const uint8_t> data);
144ef3aeadcSPatrick Venture 
145ef3aeadcSPatrick Venture /**
146ef3aeadcSPatrick Venture  * Writes out a BmcBlobCountRx structure and returns IPMI_OK.
147ef3aeadcSPatrick Venture  */
148067ece15SWilly Tu Resp getBlobCount(ManagerInterface* mgr, std::span<const uint8_t> data);
149ef3aeadcSPatrick Venture 
150ef3aeadcSPatrick Venture /**
151ef3aeadcSPatrick Venture  * Writes out a BmcBlobEnumerateRx in response to a BmcBlobEnumerateTx
152ef3aeadcSPatrick Venture  * request.  If the index does not correspond to a blob, then this will
153ef3aeadcSPatrick Venture  * return failure.
154ef3aeadcSPatrick Venture  *
155ef3aeadcSPatrick Venture  * It will also return failure if the response buffer is of an invalid
156ef3aeadcSPatrick Venture  * length.
157ef3aeadcSPatrick Venture  */
158067ece15SWilly Tu Resp enumerateBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
159ef3aeadcSPatrick Venture 
160ef3aeadcSPatrick Venture /**
161ef3aeadcSPatrick Venture  * Attempts to open the blobId specified and associate with a session id.
162ef3aeadcSPatrick Venture  */
163067ece15SWilly Tu Resp openBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
164ef3aeadcSPatrick Venture 
165ef3aeadcSPatrick Venture /**
166ef3aeadcSPatrick Venture  * Attempts to close the session specified.
167ef3aeadcSPatrick Venture  */
168067ece15SWilly Tu Resp closeBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
169ef3aeadcSPatrick Venture 
170ef3aeadcSPatrick Venture /**
171ef3aeadcSPatrick Venture  * Attempts to delete the blobId specified.
172ef3aeadcSPatrick Venture  */
173067ece15SWilly Tu Resp deleteBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
174ef3aeadcSPatrick Venture 
175ef3aeadcSPatrick Venture /**
176ef3aeadcSPatrick Venture  * Attempts to retrieve the Stat for the blobId specified.
177ef3aeadcSPatrick Venture  */
178067ece15SWilly Tu Resp statBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
179ef3aeadcSPatrick Venture 
180ef3aeadcSPatrick Venture /**
181ef3aeadcSPatrick Venture  * Attempts to retrieve the Stat for the session specified.
182ef3aeadcSPatrick Venture  */
183067ece15SWilly Tu Resp sessionStatBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
184ef3aeadcSPatrick Venture 
185ef3aeadcSPatrick Venture /**
186ef3aeadcSPatrick Venture  * Attempts to commit the data in the blob.
187ef3aeadcSPatrick Venture  */
188067ece15SWilly Tu Resp commitBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
189ef3aeadcSPatrick Venture 
190ef3aeadcSPatrick Venture /**
191ef3aeadcSPatrick Venture  * Attempt to read data from the blob.
192ef3aeadcSPatrick Venture  */
193067ece15SWilly Tu Resp readBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
194ef3aeadcSPatrick Venture 
195ef3aeadcSPatrick Venture /**
196ef3aeadcSPatrick Venture  * Attempt to write data to the blob.
197ef3aeadcSPatrick Venture  */
198067ece15SWilly Tu Resp writeBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
1995c4b17b2SPatrick Venture 
2005c4b17b2SPatrick Venture /**
2015c4b17b2SPatrick Venture  * Attempt to write metadata to the blob.
2025c4b17b2SPatrick Venture  */
203067ece15SWilly Tu Resp writeMeta(ManagerInterface* mgr, std::span<const uint8_t> data);
2045c4b17b2SPatrick Venture 
205ef3aeadcSPatrick Venture } // namespace blobs
206