blob: f73065cd5747e114e0d0afb2634deff737e68606 [file] [log] [blame]
Patrick Ventureef3aead2018-09-12 08:53:29 -07001#pragma once
2
Patrick Venturecd8dab42019-01-15 19:57:38 -08003#include "manager.hpp"
4
William A. Kennington IIIacebece2019-02-07 15:15:44 -08005#include <ipmid/api.h>
Patrick Ventureef3aead2018-09-12 08:53:29 -07006
Patrick Venture4beac9a2019-02-11 08:21:10 -08007#include <blobs-ipmid/blobs.hpp>
Willy Tu067ece12022-06-16 02:07:06 -07008#include <ipmid/api-types.hpp>
Patrick Williams52509572023-05-10 07:51:18 -05009
Willy Tu067ece12022-06-16 02:07:06 -070010#include <span>
Patrick Ventureef3aead2018-09-12 08:53:29 -070011#include <string>
Willy Tu067ece12022-06-16 02:07:06 -070012#include <vector>
Patrick Ventureef3aead2018-09-12 08:53:29 -070013
14namespace blobs
15{
16
Willy Tu067ece12022-06-16 02:07:06 -070017using Resp = ipmi::RspType<std::vector<uint8_t>>;
18
Patrick Ventureef3aead2018-09-12 08:53:29 -070019/* Used by bmcBlobGetCount */
20struct BmcBlobCountTx
21{
Patrick Ventureef3aead2018-09-12 08:53:29 -070022} __attribute__((packed));
23
24struct BmcBlobCountRx
25{
26 uint16_t crc;
27 uint32_t blobCount;
28} __attribute__((packed));
29
30/* Used by bmcBlobEnumerate */
31struct BmcBlobEnumerateTx
32{
Patrick Ventureef3aead2018-09-12 08:53:29 -070033 uint16_t crc;
34 uint32_t blobIdx;
35} __attribute__((packed));
36
37struct BmcBlobEnumerateRx
38{
39 uint16_t crc;
Patrick Ventureef3aead2018-09-12 08:53:29 -070040} __attribute__((packed));
41
42/* Used by bmcBlobOpen */
43struct BmcBlobOpenTx
44{
Patrick Ventureef3aead2018-09-12 08:53:29 -070045 uint16_t crc;
46 uint16_t flags;
Patrick Ventureef3aead2018-09-12 08:53:29 -070047} __attribute__((packed));
48
49struct BmcBlobOpenRx
50{
51 uint16_t crc;
52 uint16_t sessionId;
53} __attribute__((packed));
54
55/* Used by bmcBlobClose */
56struct BmcBlobCloseTx
57{
Patrick Ventureef3aead2018-09-12 08:53:29 -070058 uint16_t crc;
59 uint16_t sessionId; /* Returned from BmcBlobOpen. */
60} __attribute__((packed));
61
62/* Used by bmcBlobDelete */
63struct BmcBlobDeleteTx
64{
Patrick Ventureef3aead2018-09-12 08:53:29 -070065 uint16_t crc;
Patrick Ventureef3aead2018-09-12 08:53:29 -070066} __attribute__((packed));
67
68/* Used by bmcBlobStat */
69struct BmcBlobStatTx
70{
Patrick Ventureef3aead2018-09-12 08:53:29 -070071 uint16_t crc;
Patrick Ventureef3aead2018-09-12 08:53:29 -070072} __attribute__((packed));
73
74struct BmcBlobStatRx
75{
76 uint16_t crc;
77 uint16_t blobState;
78 uint32_t size; /* Size in bytes of the blob. */
79 uint8_t metadataLen;
Patrick Ventureef3aead2018-09-12 08:53:29 -070080} __attribute__((packed));
81
82/* Used by bmcBlobSessionStat */
83struct BmcBlobSessionStatTx
84{
Patrick Ventureef3aead2018-09-12 08:53:29 -070085 uint16_t crc;
86 uint16_t sessionId;
87} __attribute__((packed));
88
89/* Used by bmcBlobCommit */
90struct BmcBlobCommitTx
91{
Patrick Ventureef3aead2018-09-12 08:53:29 -070092 uint16_t crc;
93 uint16_t sessionId;
94 uint8_t commitDataLen;
Patrick Ventureef3aead2018-09-12 08:53:29 -070095} __attribute__((packed));
96
97/* Used by bmcBlobRead */
98struct BmcBlobReadTx
99{
Patrick Ventureef3aead2018-09-12 08:53:29 -0700100 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
106struct BmcBlobReadRx
107{
108 uint16_t crc;
Patrick Ventureef3aead2018-09-12 08:53:29 -0700109} __attribute__((packed));
110
111/* Used by bmcBlobWrite */
112struct BmcBlobWriteTx
113{
Patrick Ventureef3aead2018-09-12 08:53:29 -0700114 uint16_t crc;
115 uint16_t sessionId;
116 uint32_t offset; /* The byte sequence start, 0-based. */
Patrick Ventureef3aead2018-09-12 08:53:29 -0700117} __attribute__((packed));
118
Patrick Venture5c4b17b2018-10-04 10:32:22 -0700119/* Used by bmcBlobWriteMeta */
120struct BmcBlobWriteMetaTx
121{
Patrick Venture5c4b17b2018-10-04 10:32:22 -0700122 uint16_t crc;
123 uint16_t sessionId; /* Returned from BmcBlobOpen. */
124 uint32_t offset; /* The byte sequence start, 0-based. */
Patrick Venture5c4b17b2018-10-04 10:32:22 -0700125} __attribute__((packed));
126
Patrick Ventureef3aead2018-09-12 08:53:29 -0700127/**
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 */
134bool 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 *
Willy Tu067ece12022-06-16 02:07:06 -0700140 * @param[in] data - Buffer containing the string.
Patrick Ventureef3aead2018-09-12 08:53:29 -0700141 * @return the string if valid otherwise an empty string.
142 */
Willy Tu067ece12022-06-16 02:07:06 -0700143std::string stringFromBuffer(std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700144
145/**
146 * Writes out a BmcBlobCountRx structure and returns IPMI_OK.
147 */
Willy Tu067ece12022-06-16 02:07:06 -0700148Resp getBlobCount(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700149
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 */
Willy Tu067ece12022-06-16 02:07:06 -0700158Resp enumerateBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700159
160/**
161 * Attempts to open the blobId specified and associate with a session id.
162 */
Willy Tu067ece12022-06-16 02:07:06 -0700163Resp openBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700164
165/**
166 * Attempts to close the session specified.
167 */
Willy Tu067ece12022-06-16 02:07:06 -0700168Resp closeBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700169
170/**
171 * Attempts to delete the blobId specified.
172 */
Willy Tu067ece12022-06-16 02:07:06 -0700173Resp deleteBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700174
175/**
176 * Attempts to retrieve the Stat for the blobId specified.
177 */
Willy Tu067ece12022-06-16 02:07:06 -0700178Resp statBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700179
180/**
181 * Attempts to retrieve the Stat for the session specified.
182 */
Willy Tu067ece12022-06-16 02:07:06 -0700183Resp sessionStatBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700184
185/**
186 * Attempts to commit the data in the blob.
187 */
Willy Tu067ece12022-06-16 02:07:06 -0700188Resp commitBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700189
190/**
191 * Attempt to read data from the blob.
192 */
Willy Tu067ece12022-06-16 02:07:06 -0700193Resp readBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700194
195/**
196 * Attempt to write data to the blob.
197 */
Willy Tu067ece12022-06-16 02:07:06 -0700198Resp writeBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Venture5c4b17b2018-10-04 10:32:22 -0700199
200/**
201 * Attempt to write metadata to the blob.
202 */
Willy Tu067ece12022-06-16 02:07:06 -0700203Resp writeMeta(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Venture5c4b17b2018-10-04 10:32:22 -0700204
Patrick Ventureef3aead2018-09-12 08:53:29 -0700205} // namespace blobs