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> |
Patrick Venture | e08863e | 2018-11-15 14:39:44 -0800 | [diff] [blame^] | 27 | #include <host-ipmid/oemopenbmc.hpp> |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 28 | #include <host-ipmid/oemrouter.hpp> |
| 29 | #include <memory> |
Benjamin Fair | 1c4d3d3 | 2018-10-19 17:22:53 -0700 | [diff] [blame] | 30 | #include <phosphor-logging/log.hpp> |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 31 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 32 | namespace blobs |
| 33 | { |
| 34 | |
Benjamin Fair | 1c4d3d3 | 2018-10-19 17:22:53 -0700 | [diff] [blame] | 35 | using namespace phosphor::logging; |
| 36 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 37 | static ipmi_ret_t handleBlobCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf, |
| 38 | uint8_t* replyCmdBuf, size_t* dataLen) |
| 39 | { |
| 40 | /* It's holding at least a sub-command. The OEN is trimmed from the bytes |
| 41 | * before this is called. |
| 42 | */ |
| 43 | if ((*dataLen) < 1) |
| 44 | { |
Patrick Venture | 4125880 | 2018-11-12 10:46:30 -0800 | [diff] [blame] | 45 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Patrick Venture | 4125880 | 2018-11-12 10:46:30 -0800 | [diff] [blame] | 48 | /* on failure rc is set to the corresponding IPMI error. */ |
| 49 | ipmi_ret_t rc = IPMI_CC_OK; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 50 | Crc16 crc; |
| 51 | IpmiBlobHandler command = |
Patrick Venture | 4125880 | 2018-11-12 10:46:30 -0800 | [diff] [blame] | 52 | validateBlobCommand(&crc, reqBuf, replyCmdBuf, dataLen, &rc); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 53 | if (command == nullptr) |
| 54 | { |
Patrick Venture | 4125880 | 2018-11-12 10:46:30 -0800 | [diff] [blame] | 55 | return rc; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Patrick Venture | 73eb687 | 2018-10-01 18:37:34 -0700 | [diff] [blame] | 58 | return processBlobCommand(command, getBlobManager(), &crc, reqBuf, |
| 59 | replyCmdBuf, dataLen); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Patrick Venture | 5100a38 | 2018-09-27 10:40:50 -0700 | [diff] [blame] | 62 | /* TODO: this should come from the makefile or recipe... */ |
Patrick Venture | df53de1 | 2018-11-08 10:29:50 -0800 | [diff] [blame] | 63 | constexpr auto expectedHandlerPath = "/usr/lib/blob-ipmid"; |
Patrick Venture | 5100a38 | 2018-09-27 10:40:50 -0700 | [diff] [blame] | 64 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 65 | void setupBlobGlobalHandler() __attribute__((constructor)); |
| 66 | |
| 67 | void setupBlobGlobalHandler() |
| 68 | { |
| 69 | oem::Router* oemRouter = oem::mutableRouter(); |
| 70 | std::fprintf(stderr, |
| 71 | "Registering OEM:[%#08X], Cmd:[%#04X] for Blob Commands\n", |
Patrick Venture | e08863e | 2018-11-15 14:39:44 -0800 | [diff] [blame^] | 72 | oem::obmcOemNumber, oem::Cmd::blobTransferCmd); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 73 | |
Patrick Venture | e08863e | 2018-11-15 14:39:44 -0800 | [diff] [blame^] | 74 | oemRouter->registerHandler(oem::obmcOemNumber, oem::Cmd::blobTransferCmd, |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 75 | handleBlobCommand); |
| 76 | |
Patrick Venture | 5100a38 | 2018-09-27 10:40:50 -0700 | [diff] [blame] | 77 | /* Install handlers. */ |
Benjamin Fair | 1c4d3d3 | 2018-10-19 17:22:53 -0700 | [diff] [blame] | 78 | try |
| 79 | { |
| 80 | loadLibraries(expectedHandlerPath); |
| 81 | } |
| 82 | catch (const std::exception& e) |
| 83 | { |
| 84 | log<level::ERR>("ERROR loading blob handlers", |
| 85 | entry("ERROR=%s", e.what())); |
| 86 | } |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 87 | } |
| 88 | } // namespace blobs |