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