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