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