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 #include "utils.hpp" 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 #include <phosphor-logging/log.hpp> 30 31 /* TODO: Swap out once https://gerrit.openbmc-project.xyz/12743 is merged */ 32 namespace oem 33 { 34 constexpr auto blobTransferCmd = 128; 35 } // namespace oem 36 37 namespace blobs 38 { 39 40 using namespace phosphor::logging; 41 42 static ipmi_ret_t handleBlobCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf, 43 uint8_t* replyCmdBuf, size_t* dataLen) 44 { 45 /* It's holding at least a sub-command. The OEN is trimmed from the bytes 46 * before this is called. 47 */ 48 if ((*dataLen) < 1) 49 { 50 return IPMI_CC_REQ_DATA_LEN_INVALID; 51 } 52 53 /* on failure rc is set to the corresponding IPMI error. */ 54 ipmi_ret_t rc = IPMI_CC_OK; 55 Crc16 crc; 56 IpmiBlobHandler command = 57 validateBlobCommand(&crc, reqBuf, replyCmdBuf, dataLen, &rc); 58 if (command == nullptr) 59 { 60 return rc; 61 } 62 63 return processBlobCommand(command, getBlobManager(), &crc, reqBuf, 64 replyCmdBuf, dataLen); 65 } 66 67 /* TODO: this should come from the makefile or recipe... */ 68 constexpr auto expectedHandlerPath = "/usr/lib/blob-ipmid"; 69 70 void setupBlobGlobalHandler() __attribute__((constructor)); 71 72 void setupBlobGlobalHandler() 73 { 74 oem::Router* oemRouter = oem::mutableRouter(); 75 std::fprintf(stderr, 76 "Registering OEM:[%#08X], Cmd:[%#04X] for Blob Commands\n", 77 oem::obmcOemNumber, oem::blobTransferCmd); 78 79 oemRouter->registerHandler(oem::obmcOemNumber, oem::blobTransferCmd, 80 handleBlobCommand); 81 82 /* Install handlers. */ 83 try 84 { 85 loadLibraries(expectedHandlerPath); 86 } 87 catch (const std::exception& e) 88 { 89 log<level::ERR>("ERROR loading blob handlers", 90 entry("ERROR=%s", e.what())); 91 } 92 } 93 } // namespace blobs 94