blob: 51a9d7936eeda1a7d7c2c777a49eacf30d23809d [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>
9#include <span>
Patrick Ventureef3aead2018-09-12 08:53:29 -070010#include <string>
Willy Tu067ece12022-06-16 02:07:06 -070011#include <vector>
Patrick Ventureef3aead2018-09-12 08:53:29 -070012
13namespace blobs
14{
15
Willy Tu067ece12022-06-16 02:07:06 -070016using Resp = ipmi::RspType<std::vector<uint8_t>>;
17
Patrick Ventureef3aead2018-09-12 08:53:29 -070018/* Used by bmcBlobGetCount */
19struct BmcBlobCountTx
20{
Patrick Ventureef3aead2018-09-12 08:53:29 -070021} __attribute__((packed));
22
23struct BmcBlobCountRx
24{
25 uint16_t crc;
26 uint32_t blobCount;
27} __attribute__((packed));
28
29/* Used by bmcBlobEnumerate */
30struct BmcBlobEnumerateTx
31{
Patrick Ventureef3aead2018-09-12 08:53:29 -070032 uint16_t crc;
33 uint32_t blobIdx;
34} __attribute__((packed));
35
36struct BmcBlobEnumerateRx
37{
38 uint16_t crc;
Patrick Ventureef3aead2018-09-12 08:53:29 -070039} __attribute__((packed));
40
41/* Used by bmcBlobOpen */
42struct BmcBlobOpenTx
43{
Patrick Ventureef3aead2018-09-12 08:53:29 -070044 uint16_t crc;
45 uint16_t flags;
Patrick Ventureef3aead2018-09-12 08:53:29 -070046} __attribute__((packed));
47
48struct BmcBlobOpenRx
49{
50 uint16_t crc;
51 uint16_t sessionId;
52} __attribute__((packed));
53
54/* Used by bmcBlobClose */
55struct BmcBlobCloseTx
56{
Patrick Ventureef3aead2018-09-12 08:53:29 -070057 uint16_t crc;
58 uint16_t sessionId; /* Returned from BmcBlobOpen. */
59} __attribute__((packed));
60
61/* Used by bmcBlobDelete */
62struct BmcBlobDeleteTx
63{
Patrick Ventureef3aead2018-09-12 08:53:29 -070064 uint16_t crc;
Patrick Ventureef3aead2018-09-12 08:53:29 -070065} __attribute__((packed));
66
67/* Used by bmcBlobStat */
68struct BmcBlobStatTx
69{
Patrick Ventureef3aead2018-09-12 08:53:29 -070070 uint16_t crc;
Patrick Ventureef3aead2018-09-12 08:53:29 -070071} __attribute__((packed));
72
73struct BmcBlobStatRx
74{
75 uint16_t crc;
76 uint16_t blobState;
77 uint32_t size; /* Size in bytes of the blob. */
78 uint8_t metadataLen;
Patrick Ventureef3aead2018-09-12 08:53:29 -070079} __attribute__((packed));
80
81/* Used by bmcBlobSessionStat */
82struct BmcBlobSessionStatTx
83{
Patrick Ventureef3aead2018-09-12 08:53:29 -070084 uint16_t crc;
85 uint16_t sessionId;
86} __attribute__((packed));
87
88/* Used by bmcBlobCommit */
89struct BmcBlobCommitTx
90{
Patrick Ventureef3aead2018-09-12 08:53:29 -070091 uint16_t crc;
92 uint16_t sessionId;
93 uint8_t commitDataLen;
Patrick Ventureef3aead2018-09-12 08:53:29 -070094} __attribute__((packed));
95
96/* Used by bmcBlobRead */
97struct BmcBlobReadTx
98{
Patrick Ventureef3aead2018-09-12 08:53:29 -070099 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
105struct BmcBlobReadRx
106{
107 uint16_t crc;
Patrick Ventureef3aead2018-09-12 08:53:29 -0700108} __attribute__((packed));
109
110/* Used by bmcBlobWrite */
111struct BmcBlobWriteTx
112{
Patrick Ventureef3aead2018-09-12 08:53:29 -0700113 uint16_t crc;
114 uint16_t sessionId;
115 uint32_t offset; /* The byte sequence start, 0-based. */
Patrick Ventureef3aead2018-09-12 08:53:29 -0700116} __attribute__((packed));
117
Patrick Venture5c4b17b2018-10-04 10:32:22 -0700118/* Used by bmcBlobWriteMeta */
119struct BmcBlobWriteMetaTx
120{
Patrick Venture5c4b17b2018-10-04 10:32:22 -0700121 uint16_t crc;
122 uint16_t sessionId; /* Returned from BmcBlobOpen. */
123 uint32_t offset; /* The byte sequence start, 0-based. */
Patrick Venture5c4b17b2018-10-04 10:32:22 -0700124} __attribute__((packed));
125
Patrick Ventureef3aead2018-09-12 08:53:29 -0700126/**
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 */
133bool 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 *
Willy Tu067ece12022-06-16 02:07:06 -0700139 * @param[in] data - Buffer containing the string.
Patrick Ventureef3aead2018-09-12 08:53:29 -0700140 * @return the string if valid otherwise an empty string.
141 */
Willy Tu067ece12022-06-16 02:07:06 -0700142std::string stringFromBuffer(std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700143
144/**
145 * Writes out a BmcBlobCountRx structure and returns IPMI_OK.
146 */
Willy Tu067ece12022-06-16 02:07:06 -0700147Resp getBlobCount(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700148
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 */
Willy Tu067ece12022-06-16 02:07:06 -0700157Resp enumerateBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700158
159/**
160 * Attempts to open the blobId specified and associate with a session id.
161 */
Willy Tu067ece12022-06-16 02:07:06 -0700162Resp openBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700163
164/**
165 * Attempts to close the session specified.
166 */
Willy Tu067ece12022-06-16 02:07:06 -0700167Resp closeBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700168
169/**
170 * Attempts to delete the blobId specified.
171 */
Willy Tu067ece12022-06-16 02:07:06 -0700172Resp deleteBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700173
174/**
175 * Attempts to retrieve the Stat for the blobId specified.
176 */
Willy Tu067ece12022-06-16 02:07:06 -0700177Resp statBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700178
179/**
180 * Attempts to retrieve the Stat for the session specified.
181 */
Willy Tu067ece12022-06-16 02:07:06 -0700182Resp sessionStatBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700183
184/**
185 * Attempts to commit the data in the blob.
186 */
Willy Tu067ece12022-06-16 02:07:06 -0700187Resp commitBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700188
189/**
190 * Attempt to read data from the blob.
191 */
Willy Tu067ece12022-06-16 02:07:06 -0700192Resp readBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Ventureef3aead2018-09-12 08:53:29 -0700193
194/**
195 * Attempt to write data to the blob.
196 */
Willy Tu067ece12022-06-16 02:07:06 -0700197Resp writeBlob(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Venture5c4b17b2018-10-04 10:32:22 -0700198
199/**
200 * Attempt to write metadata to the blob.
201 */
Willy Tu067ece12022-06-16 02:07:06 -0700202Resp writeMeta(ManagerInterface* mgr, std::span<const uint8_t> data);
Patrick Venture5c4b17b2018-10-04 10:32:22 -0700203
Patrick Ventureef3aead2018-09-12 08:53:29 -0700204} // namespace blobs