Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | cd8dab4 | 2019-01-15 19:57:38 -0800 | [diff] [blame] | 3 | #include "manager.hpp" |
| 4 | |
William A. Kennington III | acebece | 2019-02-07 15:15:44 -0800 | [diff] [blame] | 5 | #include <ipmid/api.h> |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 6 | |
Patrick Venture | 4beac9a | 2019-02-11 08:21:10 -0800 | [diff] [blame] | 7 | #include <blobs-ipmid/blobs.hpp> |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 8 | #include <ipmid/api-types.hpp> |
| 9 | #include <span> |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 10 | #include <string> |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 11 | #include <vector> |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 12 | |
| 13 | namespace blobs |
| 14 | { |
| 15 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 16 | using Resp = ipmi::RspType<std::vector<uint8_t>>; |
| 17 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 18 | /* Used by bmcBlobGetCount */ |
| 19 | struct BmcBlobCountTx |
| 20 | { |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 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 | { |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 32 | uint16_t crc; |
| 33 | uint32_t blobIdx; |
| 34 | } __attribute__((packed)); |
| 35 | |
| 36 | struct BmcBlobEnumerateRx |
| 37 | { |
| 38 | uint16_t crc; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 39 | } __attribute__((packed)); |
| 40 | |
| 41 | /* Used by bmcBlobOpen */ |
| 42 | struct BmcBlobOpenTx |
| 43 | { |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 44 | uint16_t crc; |
| 45 | uint16_t flags; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 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 | { |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 57 | uint16_t crc; |
| 58 | uint16_t sessionId; /* Returned from BmcBlobOpen. */ |
| 59 | } __attribute__((packed)); |
| 60 | |
| 61 | /* Used by bmcBlobDelete */ |
| 62 | struct BmcBlobDeleteTx |
| 63 | { |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 64 | uint16_t crc; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 65 | } __attribute__((packed)); |
| 66 | |
| 67 | /* Used by bmcBlobStat */ |
| 68 | struct BmcBlobStatTx |
| 69 | { |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 70 | uint16_t crc; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 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; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 79 | } __attribute__((packed)); |
| 80 | |
| 81 | /* Used by bmcBlobSessionStat */ |
| 82 | struct BmcBlobSessionStatTx |
| 83 | { |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 84 | uint16_t crc; |
| 85 | uint16_t sessionId; |
| 86 | } __attribute__((packed)); |
| 87 | |
| 88 | /* Used by bmcBlobCommit */ |
| 89 | struct BmcBlobCommitTx |
| 90 | { |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 91 | uint16_t crc; |
| 92 | uint16_t sessionId; |
| 93 | uint8_t commitDataLen; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 94 | } __attribute__((packed)); |
| 95 | |
| 96 | /* Used by bmcBlobRead */ |
| 97 | struct BmcBlobReadTx |
| 98 | { |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 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; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 108 | } __attribute__((packed)); |
| 109 | |
| 110 | /* Used by bmcBlobWrite */ |
| 111 | struct BmcBlobWriteTx |
| 112 | { |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 113 | uint16_t crc; |
| 114 | uint16_t sessionId; |
| 115 | uint32_t offset; /* The byte sequence start, 0-based. */ |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 116 | } __attribute__((packed)); |
| 117 | |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 118 | /* Used by bmcBlobWriteMeta */ |
| 119 | struct BmcBlobWriteMetaTx |
| 120 | { |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 121 | uint16_t crc; |
| 122 | uint16_t sessionId; /* Returned from BmcBlobOpen. */ |
| 123 | uint32_t offset; /* The byte sequence start, 0-based. */ |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 124 | } __attribute__((packed)); |
| 125 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 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 | * |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 139 | * @param[in] data - Buffer containing the string. |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 140 | * @return the string if valid otherwise an empty string. |
| 141 | */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 142 | std::string stringFromBuffer(std::span<const uint8_t> data); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 143 | |
| 144 | /** |
| 145 | * Writes out a BmcBlobCountRx structure and returns IPMI_OK. |
| 146 | */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 147 | Resp getBlobCount(ManagerInterface* mgr, std::span<const uint8_t> data); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 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 | */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 157 | Resp enumerateBlob(ManagerInterface* mgr, std::span<const uint8_t> data); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 158 | |
| 159 | /** |
| 160 | * Attempts to open the blobId specified and associate with a session id. |
| 161 | */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 162 | Resp openBlob(ManagerInterface* mgr, std::span<const uint8_t> data); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 163 | |
| 164 | /** |
| 165 | * Attempts to close the session specified. |
| 166 | */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 167 | Resp closeBlob(ManagerInterface* mgr, std::span<const uint8_t> data); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 168 | |
| 169 | /** |
| 170 | * Attempts to delete the blobId specified. |
| 171 | */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 172 | Resp deleteBlob(ManagerInterface* mgr, std::span<const uint8_t> data); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * Attempts to retrieve the Stat for the blobId specified. |
| 176 | */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 177 | Resp statBlob(ManagerInterface* mgr, std::span<const uint8_t> data); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 178 | |
| 179 | /** |
| 180 | * Attempts to retrieve the Stat for the session specified. |
| 181 | */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 182 | Resp sessionStatBlob(ManagerInterface* mgr, std::span<const uint8_t> data); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 183 | |
| 184 | /** |
| 185 | * Attempts to commit the data in the blob. |
| 186 | */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 187 | Resp commitBlob(ManagerInterface* mgr, std::span<const uint8_t> data); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * Attempt to read data from the blob. |
| 191 | */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 192 | Resp readBlob(ManagerInterface* mgr, std::span<const uint8_t> data); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 193 | |
| 194 | /** |
| 195 | * Attempt to write data to the blob. |
| 196 | */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 197 | Resp writeBlob(ManagerInterface* mgr, std::span<const uint8_t> data); |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 198 | |
| 199 | /** |
| 200 | * Attempt to write metadata to the blob. |
| 201 | */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 202 | Resp writeMeta(ManagerInterface* mgr, std::span<const uint8_t> data); |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 203 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 204 | } // namespace blobs |