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 "config.h" |
| 18 | |
| 19 | #include "ipmi.hpp" |
| 20 | #include "process.hpp" |
| 21 | |
| 22 | #include <host-ipmid/ipmid-api.h> |
| 23 | |
| 24 | #include <cstdio> |
| 25 | #include <host-ipmid/iana.hpp> |
| 26 | #include <host-ipmid/oemrouter.hpp> |
| 27 | #include <memory> |
| 28 | |
| 29 | /* TODO: Swap out once https://gerrit.openbmc-project.xyz/12743 is merged */ |
| 30 | namespace oem |
| 31 | { |
| 32 | constexpr auto blobTransferCmd = 128; |
| 33 | } // namespace oem |
| 34 | |
| 35 | namespace blobs |
| 36 | { |
| 37 | |
| 38 | static std::unique_ptr<BlobManager> manager; |
| 39 | |
| 40 | static ipmi_ret_t handleBlobCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf, |
| 41 | uint8_t* replyCmdBuf, size_t* dataLen) |
| 42 | { |
| 43 | /* It's holding at least a sub-command. The OEN is trimmed from the bytes |
| 44 | * before this is called. |
| 45 | */ |
| 46 | if ((*dataLen) < 1) |
| 47 | { |
| 48 | return IPMI_CC_INVALID; |
| 49 | } |
| 50 | |
| 51 | Crc16 crc; |
| 52 | IpmiBlobHandler command = |
| 53 | validateBlobCommand(&crc, reqBuf, replyCmdBuf, dataLen); |
| 54 | if (command == nullptr) |
| 55 | { |
| 56 | return IPMI_CC_INVALID; |
| 57 | } |
| 58 | |
| 59 | return processBlobCommand(command, manager.get(), &crc, reqBuf, replyCmdBuf, |
| 60 | dataLen); |
| 61 | } |
| 62 | |
| 63 | void setupBlobGlobalHandler() __attribute__((constructor)); |
| 64 | |
| 65 | void setupBlobGlobalHandler() |
| 66 | { |
| 67 | oem::Router* oemRouter = oem::mutableRouter(); |
| 68 | std::fprintf(stderr, |
| 69 | "Registering OEM:[%#08X], Cmd:[%#04X] for Blob Commands\n", |
| 70 | oem::obmcOemNumber, oem::blobTransferCmd); |
| 71 | |
| 72 | oemRouter->registerHandler(oem::obmcOemNumber, oem::blobTransferCmd, |
| 73 | handleBlobCommand); |
| 74 | |
| 75 | manager = std::make_unique<BlobManager>(); |
| 76 | } |
| 77 | } // namespace blobs |