xref: /openbmc/phosphor-ipmi-blobs/ipmi.hpp (revision acebece3)
1 #pragma once
2 
3 #include "manager.hpp"
4 
5 #include <ipmid/api.h>
6 
7 #include <blobs-ipmid/blobs.hpp>
8 #include <string>
9 
10 namespace blobs
11 {
12 
13 /* Used by bmcBlobGetCount */
14 struct BmcBlobCountTx
15 {
16     uint8_t cmd; /* bmcBlobGetCount */
17 } __attribute__((packed));
18 
19 struct BmcBlobCountRx
20 {
21     uint16_t crc;
22     uint32_t blobCount;
23 } __attribute__((packed));
24 
25 /* Used by bmcBlobEnumerate */
26 struct BmcBlobEnumerateTx
27 {
28     uint8_t cmd; /* bmcBlobEnumerate */
29     uint16_t crc;
30     uint32_t blobIdx;
31 } __attribute__((packed));
32 
33 struct BmcBlobEnumerateRx
34 {
35     uint16_t crc;
36     char blobId[];
37 } __attribute__((packed));
38 
39 /* Used by bmcBlobOpen */
40 struct 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 
48 struct BmcBlobOpenRx
49 {
50     uint16_t crc;
51     uint16_t sessionId;
52 } __attribute__((packed));
53 
54 /* Used by bmcBlobClose */
55 struct 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 */
63 struct BmcBlobDeleteTx
64 {
65     uint8_t cmd; /* bmcBlobDelete */
66     uint16_t crc;
67     char blobId[];
68 } __attribute__((packed));
69 
70 /* Used by bmcBlobStat */
71 struct BmcBlobStatTx
72 {
73     uint8_t cmd; /* bmcBlobStat */
74     uint16_t crc;
75     char blobId[];
76 } __attribute__((packed));
77 
78 struct 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 */
88 struct BmcBlobSessionStatTx
89 {
90     uint8_t cmd; /* bmcBlobSessionStat */
91     uint16_t crc;
92     uint16_t sessionId;
93 } __attribute__((packed));
94 
95 /* Used by bmcBlobCommit */
96 struct 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 */
106 struct 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 
115 struct BmcBlobReadRx
116 {
117     uint16_t crc;
118     uint8_t data[];
119 } __attribute__((packed));
120 
121 /* Used by bmcBlobWrite */
122 struct 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 
131 /* Used by bmcBlobWriteMeta */
132 struct 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 
141 /**
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  */
148 bool 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  */
158 std::string stringFromBuffer(const char* start, size_t length);
159 
160 /**
161  * Writes out a BmcBlobCountRx structure and returns IPMI_OK.
162  */
163 ipmi_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  */
174 ipmi_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  */
180 ipmi_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  */
186 ipmi_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  */
192 ipmi_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  */
198 ipmi_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  */
204 ipmi_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  */
210 ipmi_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  */
216 ipmi_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  */
222 ipmi_ret_t writeBlob(ManagerInterface* mgr, const uint8_t* reqBuf,
223                      uint8_t* replyCmdBuf, size_t* dataLen);
224 
225 /**
226  * Attempt to write metadata to the blob.
227  */
228 ipmi_ret_t writeMeta(ManagerInterface* mgr, const uint8_t* reqBuf,
229                      uint8_t* replyCmdBuf, size_t* dataLen);
230 
231 } // namespace blobs
232