Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "ipmi.hpp" |
| 18 | |
| 19 | #include <cstring> |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 20 | #include <span> |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 21 | #include <string> |
| 22 | #include <unordered_map> |
| 23 | |
| 24 | namespace blobs |
| 25 | { |
| 26 | |
| 27 | bool validateRequestLength(BlobOEMCommands command, size_t requestLen) |
| 28 | { |
| 29 | /* The smallest string is one letter and the nul-terminator. */ |
| 30 | static const int kMinStrLen = 2; |
| 31 | |
| 32 | static const std::unordered_map<BlobOEMCommands, size_t> minimumLengths = { |
| 33 | {BlobOEMCommands::bmcBlobEnumerate, sizeof(struct BmcBlobEnumerateTx)}, |
| 34 | {BlobOEMCommands::bmcBlobOpen, |
| 35 | sizeof(struct BmcBlobOpenTx) + kMinStrLen}, |
| 36 | {BlobOEMCommands::bmcBlobClose, sizeof(struct BmcBlobCloseTx)}, |
| 37 | {BlobOEMCommands::bmcBlobDelete, |
| 38 | sizeof(struct BmcBlobDeleteTx) + kMinStrLen}, |
| 39 | {BlobOEMCommands::bmcBlobStat, |
| 40 | sizeof(struct BmcBlobStatTx) + kMinStrLen}, |
| 41 | {BlobOEMCommands::bmcBlobSessionStat, |
| 42 | sizeof(struct BmcBlobSessionStatTx)}, |
| 43 | {BlobOEMCommands::bmcBlobCommit, sizeof(struct BmcBlobCommitTx)}, |
| 44 | {BlobOEMCommands::bmcBlobRead, sizeof(struct BmcBlobReadTx)}, |
| 45 | {BlobOEMCommands::bmcBlobWrite, |
| 46 | sizeof(struct BmcBlobWriteTx) + sizeof(uint8_t)}, |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 47 | {BlobOEMCommands::bmcBlobWriteMeta, |
| 48 | sizeof(struct BmcBlobWriteMetaTx) + sizeof(uint8_t)}, |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | auto results = minimumLengths.find(command); |
| 52 | if (results == minimumLengths.end()) |
| 53 | { |
| 54 | /* Valid length by default if we don't care. */ |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | /* If the request is shorter than the minimum, it's invalid. */ |
| 59 | if (requestLen < results->second) |
| 60 | { |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | return true; |
| 65 | } |
| 66 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 67 | std::string stringFromBuffer(std::span<const uint8_t> data) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 68 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 69 | if (data.empty() || data.back() != '\0') |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 70 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 71 | return std::string(); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 74 | // Last index is nul-terminator. |
| 75 | return std::string(data.begin(), data.end() - 1); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 78 | Resp getBlobCount(ManagerInterface* mgr, std::span<const uint8_t>) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 79 | { |
| 80 | struct BmcBlobCountRx resp; |
| 81 | resp.crc = 0; |
| 82 | resp.blobCount = mgr->buildBlobList(); |
| 83 | |
| 84 | /* Copy the response into the reply buffer */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 85 | std::vector<uint8_t> output(sizeof(BmcBlobCountRx), 0); |
| 86 | std::memcpy(output.data(), &resp, sizeof(resp)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 87 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 88 | return ipmi::responseSuccess(output); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 91 | Resp enumerateBlob(ManagerInterface* mgr, std::span<const uint8_t> data) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 92 | { |
| 93 | /* Verify datalen is >= sizeof(request) */ |
| 94 | struct BmcBlobEnumerateTx request; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 95 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 96 | std::memcpy(&request, data.data(), sizeof(request)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 97 | |
| 98 | std::string blobId = mgr->getBlobId(request.blobIdx); |
Willy Tu | 3d1fdfa | 2022-02-08 16:05:15 -0800 | [diff] [blame] | 99 | if (blobId.empty()) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 100 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 101 | return ipmi::responseInvalidFieldRequest(); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 104 | std::vector<uint8_t> output(sizeof(BmcBlobEnumerateRx), 0); |
| 105 | output.insert(output.end(), blobId.c_str(), |
| 106 | blobId.c_str() + blobId.length() + 1); |
| 107 | return ipmi::responseSuccess(output); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 110 | Resp openBlob(ManagerInterface* mgr, std::span<const uint8_t> data) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 111 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 112 | auto request = reinterpret_cast<const struct BmcBlobOpenTx*>(data.data()); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 113 | uint16_t session; |
| 114 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 115 | std::string path = stringFromBuffer(data.subspan(sizeof(BmcBlobOpenTx))); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 116 | if (path.empty()) |
| 117 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 118 | return ipmi::responseReqDataLenInvalid(); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /* Attempt to open. */ |
| 122 | if (!mgr->open(request->flags, path, &session)) |
| 123 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 124 | return ipmi::responseUnspecifiedError(); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | struct BmcBlobOpenRx reply; |
| 128 | reply.crc = 0; |
| 129 | reply.sessionId = session; |
| 130 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 131 | std::vector<uint8_t> output(sizeof(BmcBlobOpenRx), 0); |
| 132 | std::memcpy(output.data(), &reply, sizeof(reply)); |
| 133 | return ipmi::responseSuccess(output); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 136 | Resp closeBlob(ManagerInterface* mgr, std::span<const uint8_t> data) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 137 | { |
| 138 | struct BmcBlobCloseTx request; |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 139 | if (data.size() < sizeof(request)) |
| 140 | { |
| 141 | return ipmi::responseReqDataLenInvalid(); |
| 142 | } |
| 143 | std::memcpy(&request, data.data(), sizeof(request)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 144 | |
| 145 | /* Attempt to close. */ |
| 146 | if (!mgr->close(request.sessionId)) |
| 147 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 148 | return ipmi::responseUnspecifiedError(); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 151 | return ipmi::responseSuccess(std::vector<uint8_t>{}); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 154 | Resp deleteBlob(ManagerInterface* mgr, std::span<const uint8_t> data) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 155 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 156 | std::string path = stringFromBuffer(data.subspan(sizeof(BmcBlobDeleteTx))); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 157 | if (path.empty()) |
| 158 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 159 | return ipmi::responseReqDataLenInvalid(); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /* Attempt to delete. */ |
| 163 | if (!mgr->deleteBlob(path)) |
| 164 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 165 | return ipmi::responseUnspecifiedError(); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 168 | return ipmi::responseSuccess(std::vector<uint8_t>{}); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 171 | static Resp returnStatBlob(BlobMeta* meta) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 172 | { |
| 173 | struct BmcBlobStatRx reply; |
| 174 | reply.crc = 0; |
| 175 | reply.blobState = meta->blobState; |
| 176 | reply.size = meta->size; |
| 177 | reply.metadataLen = meta->metadata.size(); |
| 178 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 179 | std::vector<uint8_t> output(sizeof(BmcBlobStatRx), 0); |
| 180 | std::memcpy(output.data(), &reply, sizeof(reply)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 181 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 182 | /* If there is metadata, insert it to output. */ |
Willy Tu | 3d1fdfa | 2022-02-08 16:05:15 -0800 | [diff] [blame] | 183 | if (!meta->metadata.empty()) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 184 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 185 | output.insert(output.end(), meta->metadata.begin(), |
| 186 | meta->metadata.end()); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 187 | } |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 188 | return ipmi::responseSuccess(output); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 191 | Resp statBlob(ManagerInterface* mgr, std::span<const uint8_t> data) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 192 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 193 | std::string path = stringFromBuffer(data.subspan(sizeof(BmcBlobStatTx))); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 194 | if (path.empty()) |
| 195 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 196 | return ipmi::responseReqDataLenInvalid(); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /* Attempt to stat. */ |
Patrick Venture | 8bc1177 | 2019-06-04 07:20:24 -0700 | [diff] [blame] | 200 | BlobMeta meta; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 201 | if (!mgr->stat(path, &meta)) |
| 202 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 203 | return ipmi::responseUnspecifiedError(); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 206 | return returnStatBlob(&meta); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 209 | Resp sessionStatBlob(ManagerInterface* mgr, std::span<const uint8_t> data) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 210 | { |
| 211 | struct BmcBlobSessionStatTx request; |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 212 | if (data.size() < sizeof(request)) |
| 213 | { |
| 214 | return ipmi::responseReqDataLenInvalid(); |
| 215 | } |
| 216 | std::memcpy(&request, data.data(), sizeof(request)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 217 | |
| 218 | /* Attempt to stat. */ |
Patrick Venture | 8bc1177 | 2019-06-04 07:20:24 -0700 | [diff] [blame] | 219 | BlobMeta meta; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 220 | |
| 221 | if (!mgr->stat(request.sessionId, &meta)) |
| 222 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 223 | return ipmi::responseUnspecifiedError(); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 226 | return returnStatBlob(&meta); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 229 | Resp commitBlob(ManagerInterface* mgr, std::span<const uint8_t> data) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 230 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 231 | auto request = reinterpret_cast<const struct BmcBlobCommitTx*>(data.data()); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 232 | |
| 233 | /* Sanity check the commitDataLen */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 234 | if (request->commitDataLen > (data.size() - sizeof(struct BmcBlobCommitTx))) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 235 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 236 | return ipmi::responseReqDataLenInvalid(); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 239 | data = data.subspan(sizeof(struct BmcBlobCommitTx), request->commitDataLen); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 240 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 241 | if (!mgr->commit(request->sessionId, |
| 242 | std::vector<uint8_t>(data.begin(), data.end()))) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 243 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 244 | return ipmi::responseUnspecifiedError(); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 247 | return ipmi::responseSuccess(std::vector<uint8_t>{}); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 250 | Resp readBlob(ManagerInterface* mgr, std::span<const uint8_t> data) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 251 | { |
| 252 | struct BmcBlobReadTx request; |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 253 | if (data.size() < sizeof(request)) |
| 254 | { |
| 255 | return ipmi::responseReqDataLenInvalid(); |
| 256 | } |
| 257 | std::memcpy(&request, data.data(), sizeof(request)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 258 | |
Patrick Williams | 97e69ca | 2024-08-16 15:21:49 -0400 | [diff] [blame^] | 259 | std::vector<uint8_t> result = |
| 260 | mgr->read(request.sessionId, request.offset, request.requestedSize); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 261 | |
| 262 | /* If the Read fails, it returns success but with only the crc and 0 bytes |
| 263 | * of data. |
| 264 | * If there was data returned, copy into the reply buffer. |
| 265 | */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 266 | std::vector<uint8_t> output(sizeof(BmcBlobReadRx), 0); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 267 | |
Willy Tu | 3d1fdfa | 2022-02-08 16:05:15 -0800 | [diff] [blame] | 268 | if (!result.empty()) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 269 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 270 | output.insert(output.end(), result.begin(), result.end()); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 273 | return ipmi::responseSuccess(output); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 276 | Resp writeBlob(ManagerInterface* mgr, std::span<const uint8_t> data) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 277 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 278 | auto request = reinterpret_cast<const struct BmcBlobWriteTx*>(data.data()); |
| 279 | data = data.subspan(sizeof(struct BmcBlobWriteTx)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 280 | |
| 281 | /* Attempt to write the bytes. */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 282 | if (!mgr->write(request->sessionId, request->offset, |
| 283 | std::vector<uint8_t>(data.begin(), data.end()))) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 284 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 285 | return ipmi::responseUnspecifiedError(); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 288 | return ipmi::responseSuccess(std::vector<uint8_t>{}); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 291 | Resp writeMeta(ManagerInterface* mgr, std::span<const uint8_t> data) |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 292 | { |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 293 | struct BmcBlobWriteMetaTx request; |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 294 | if (data.size() < sizeof(request)) |
| 295 | { |
| 296 | return ipmi::responseReqDataLenInvalid(); |
| 297 | } |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 298 | |
| 299 | /* Copy over the request. */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 300 | std::memcpy(&request, data.data(), sizeof(request)); |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 301 | |
| 302 | /* Nothing really else to validate, we just copy those bytes. */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 303 | data = data.subspan(sizeof(struct BmcBlobWriteMetaTx)); |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 304 | |
| 305 | /* Attempt to write the bytes. */ |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 306 | if (!mgr->writeMeta(request.sessionId, request.offset, |
| 307 | std::vector<uint8_t>(data.begin(), data.end()))) |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 308 | { |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 309 | return ipmi::responseUnspecifiedError(); |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 312 | return ipmi::responseSuccess(std::vector<uint8_t>{}); |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 315 | } // namespace blobs |