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