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