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