Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 3 | #include <host-ipmid/ipmid-api.h> |
| 4 | |
Patrick Venture | aceb4ba | 2018-09-27 14:50:37 -0700 | [diff] [blame] | 5 | #include <blobs-ipmid/manager.hpp> |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 6 | #include <string> |
| 7 | |
| 8 | namespace blobs |
| 9 | { |
| 10 | |
| 11 | enum BlobOEMCommands |
| 12 | { |
| 13 | bmcBlobGetCount = 0, |
| 14 | bmcBlobEnumerate = 1, |
| 15 | bmcBlobOpen = 2, |
| 16 | bmcBlobRead = 3, |
| 17 | bmcBlobWrite = 4, |
| 18 | bmcBlobCommit = 5, |
| 19 | bmcBlobClose = 6, |
| 20 | bmcBlobDelete = 7, |
| 21 | bmcBlobStat = 8, |
| 22 | bmcBlobSessionStat = 9, |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 23 | bmcBlobWriteMeta = 10, |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | /* Used by bmcBlobGetCount */ |
| 27 | struct BmcBlobCountTx |
| 28 | { |
| 29 | uint8_t cmd; /* bmcBlobGetCount */ |
| 30 | } __attribute__((packed)); |
| 31 | |
| 32 | struct BmcBlobCountRx |
| 33 | { |
| 34 | uint16_t crc; |
| 35 | uint32_t blobCount; |
| 36 | } __attribute__((packed)); |
| 37 | |
| 38 | /* Used by bmcBlobEnumerate */ |
| 39 | struct BmcBlobEnumerateTx |
| 40 | { |
| 41 | uint8_t cmd; /* bmcBlobEnumerate */ |
| 42 | uint16_t crc; |
| 43 | uint32_t blobIdx; |
| 44 | } __attribute__((packed)); |
| 45 | |
| 46 | struct BmcBlobEnumerateRx |
| 47 | { |
| 48 | uint16_t crc; |
| 49 | char blobId[]; |
| 50 | } __attribute__((packed)); |
| 51 | |
| 52 | /* Used by bmcBlobOpen */ |
| 53 | struct BmcBlobOpenTx |
| 54 | { |
| 55 | uint8_t cmd; /* bmcBlobOpen */ |
| 56 | uint16_t crc; |
| 57 | uint16_t flags; |
| 58 | char blobId[]; /* Must correspond to a valid blob. */ |
| 59 | } __attribute__((packed)); |
| 60 | |
| 61 | struct BmcBlobOpenRx |
| 62 | { |
| 63 | uint16_t crc; |
| 64 | uint16_t sessionId; |
| 65 | } __attribute__((packed)); |
| 66 | |
| 67 | /* Used by bmcBlobClose */ |
| 68 | struct BmcBlobCloseTx |
| 69 | { |
| 70 | uint8_t cmd; /* bmcBlobClose */ |
| 71 | uint16_t crc; |
| 72 | uint16_t sessionId; /* Returned from BmcBlobOpen. */ |
| 73 | } __attribute__((packed)); |
| 74 | |
| 75 | /* Used by bmcBlobDelete */ |
| 76 | struct BmcBlobDeleteTx |
| 77 | { |
| 78 | uint8_t cmd; /* bmcBlobDelete */ |
| 79 | uint16_t crc; |
| 80 | char blobId[]; |
| 81 | } __attribute__((packed)); |
| 82 | |
| 83 | /* Used by bmcBlobStat */ |
| 84 | struct BmcBlobStatTx |
| 85 | { |
| 86 | uint8_t cmd; /* bmcBlobStat */ |
| 87 | uint16_t crc; |
| 88 | char blobId[]; |
| 89 | } __attribute__((packed)); |
| 90 | |
| 91 | struct BmcBlobStatRx |
| 92 | { |
| 93 | uint16_t crc; |
| 94 | uint16_t blobState; |
| 95 | uint32_t size; /* Size in bytes of the blob. */ |
| 96 | uint8_t metadataLen; |
| 97 | uint8_t metadata[]; /* Optional blob-specific metadata. */ |
| 98 | } __attribute__((packed)); |
| 99 | |
| 100 | /* Used by bmcBlobSessionStat */ |
| 101 | struct BmcBlobSessionStatTx |
| 102 | { |
| 103 | uint8_t cmd; /* bmcBlobSessionStat */ |
| 104 | uint16_t crc; |
| 105 | uint16_t sessionId; |
| 106 | } __attribute__((packed)); |
| 107 | |
| 108 | /* Used by bmcBlobCommit */ |
| 109 | struct BmcBlobCommitTx |
| 110 | { |
| 111 | uint8_t cmd; /* bmcBlobCommit */ |
| 112 | uint16_t crc; |
| 113 | uint16_t sessionId; |
| 114 | uint8_t commitDataLen; |
| 115 | uint8_t commitData[]; /* Optional blob-specific commit data. */ |
| 116 | } __attribute__((packed)); |
| 117 | |
| 118 | /* Used by bmcBlobRead */ |
| 119 | struct BmcBlobReadTx |
| 120 | { |
| 121 | uint8_t cmd; /* bmcBlobRead */ |
| 122 | uint16_t crc; |
| 123 | uint16_t sessionId; |
| 124 | uint32_t offset; /* The byte sequence start, 0-based. */ |
| 125 | uint32_t requestedSize; /* The number of bytes requested for reading. */ |
| 126 | } __attribute__((packed)); |
| 127 | |
| 128 | struct BmcBlobReadRx |
| 129 | { |
| 130 | uint16_t crc; |
| 131 | uint8_t data[]; |
| 132 | } __attribute__((packed)); |
| 133 | |
| 134 | /* Used by bmcBlobWrite */ |
| 135 | struct BmcBlobWriteTx |
| 136 | { |
| 137 | uint8_t cmd; /* bmcBlobWrite */ |
| 138 | uint16_t crc; |
| 139 | uint16_t sessionId; |
| 140 | uint32_t offset; /* The byte sequence start, 0-based. */ |
| 141 | uint8_t data[]; |
| 142 | } __attribute__((packed)); |
| 143 | |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 144 | /* Used by bmcBlobWriteMeta */ |
| 145 | struct BmcBlobWriteMetaTx |
| 146 | { |
| 147 | uint8_t cmd; /* bmcBlobWriteMeta */ |
| 148 | uint16_t crc; |
| 149 | uint16_t sessionId; /* Returned from BmcBlobOpen. */ |
| 150 | uint32_t offset; /* The byte sequence start, 0-based. */ |
| 151 | uint8_t data[]; |
| 152 | } __attribute__((packed)); |
| 153 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 154 | /** |
| 155 | * Validate the minimum request length if there is one. |
| 156 | * |
| 157 | * @param[in] subcommand - the command |
| 158 | * @param[in] requestLength - the length of the request |
| 159 | * @return bool - true if valid. |
| 160 | */ |
| 161 | bool validateRequestLength(BlobOEMCommands command, size_t requestLen); |
| 162 | |
| 163 | /** |
| 164 | * Given a pointer into an IPMI request buffer and the length of the remaining |
| 165 | * buffer, builds a string. This does no string validation w.r.t content. |
| 166 | * |
| 167 | * @param[in] start - the start of the expected string. |
| 168 | * @param[in] length - the number of bytes remaining in the buffer. |
| 169 | * @return the string if valid otherwise an empty string. |
| 170 | */ |
| 171 | std::string stringFromBuffer(const char* start, size_t length); |
| 172 | |
| 173 | /** |
| 174 | * Writes out a BmcBlobCountRx structure and returns IPMI_OK. |
| 175 | */ |
| 176 | ipmi_ret_t getBlobCount(ManagerInterface* mgr, const uint8_t* reqBuf, |
| 177 | uint8_t* replyCmdBuf, size_t* dataLen); |
| 178 | |
| 179 | /** |
| 180 | * Writes out a BmcBlobEnumerateRx in response to a BmcBlobEnumerateTx |
| 181 | * request. If the index does not correspond to a blob, then this will |
| 182 | * return failure. |
| 183 | * |
| 184 | * It will also return failure if the response buffer is of an invalid |
| 185 | * length. |
| 186 | */ |
| 187 | ipmi_ret_t enumerateBlob(ManagerInterface* mgr, const uint8_t* reqBuf, |
| 188 | uint8_t* replyCmdBuf, size_t* dataLen); |
| 189 | |
| 190 | /** |
| 191 | * Attempts to open the blobId specified and associate with a session id. |
| 192 | */ |
| 193 | ipmi_ret_t openBlob(ManagerInterface* mgr, const uint8_t* reqBuf, |
| 194 | uint8_t* replyCmdBuf, size_t* dataLen); |
| 195 | |
| 196 | /** |
| 197 | * Attempts to close the session specified. |
| 198 | */ |
| 199 | ipmi_ret_t closeBlob(ManagerInterface* mgr, const uint8_t* reqBuf, |
| 200 | uint8_t* replyCmdBuf, size_t* dataLen); |
| 201 | |
| 202 | /** |
| 203 | * Attempts to delete the blobId specified. |
| 204 | */ |
| 205 | ipmi_ret_t deleteBlob(ManagerInterface* mgr, const uint8_t* reqBuf, |
| 206 | uint8_t* replyCmdBuf, size_t* dataLen); |
| 207 | |
| 208 | /** |
| 209 | * Attempts to retrieve the Stat for the blobId specified. |
| 210 | */ |
| 211 | ipmi_ret_t statBlob(ManagerInterface* mgr, const uint8_t* reqBuf, |
| 212 | uint8_t* replyCmdBuf, size_t* dataLen); |
| 213 | |
| 214 | /** |
| 215 | * Attempts to retrieve the Stat for the session specified. |
| 216 | */ |
| 217 | ipmi_ret_t sessionStatBlob(ManagerInterface* mgr, const uint8_t* reqBuf, |
| 218 | uint8_t* replyCmdBuf, size_t* dataLen); |
| 219 | |
| 220 | /** |
| 221 | * Attempts to commit the data in the blob. |
| 222 | */ |
| 223 | ipmi_ret_t commitBlob(ManagerInterface* mgr, const uint8_t* reqBuf, |
| 224 | uint8_t* replyCmdBuf, size_t* dataLen); |
| 225 | |
| 226 | /** |
| 227 | * Attempt to read data from the blob. |
| 228 | */ |
| 229 | ipmi_ret_t readBlob(ManagerInterface* mgr, const uint8_t* reqBuf, |
| 230 | uint8_t* replyCmdBuf, size_t* dataLen); |
| 231 | |
| 232 | /** |
| 233 | * Attempt to write data to the blob. |
| 234 | */ |
| 235 | ipmi_ret_t writeBlob(ManagerInterface* mgr, const uint8_t* reqBuf, |
| 236 | uint8_t* replyCmdBuf, size_t* dataLen); |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 237 | |
| 238 | /** |
| 239 | * Attempt to write metadata to the blob. |
| 240 | */ |
| 241 | ipmi_ret_t writeMeta(ManagerInterface* mgr, const uint8_t* reqBuf, |
| 242 | uint8_t* replyCmdBuf, size_t* dataLen); |
| 243 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 244 | } // namespace blobs |