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 "manager.hpp" 21 #include "process.hpp" 22 #include "utils.hpp" 23 24 #include <ipmid/api.h> 25 26 #include <ipmid/api-types.hpp> 27 #include <ipmid/handler.hpp> 28 #include <ipmid/iana.hpp> 29 #include <ipmid/oemopenbmc.hpp> 30 #include <ipmid/oemrouter.hpp> 31 #include <phosphor-logging/log.hpp> 32 #include <user_channel/channel_layer.hpp> 33 34 #include <cstdio> 35 #include <memory> 36 #include <span> 37 38 namespace blobs 39 { 40 41 using namespace phosphor::logging; 42 43 void setupBlobGlobalHandler() __attribute__((constructor)); 44 45 void setupBlobGlobalHandler() 46 { 47 std::fprintf(stderr, 48 "Registering OEM:[%#08X], Cmd:[%#04X] for Blob Commands\n", 49 oem::obmcOemNumber, oem::Cmd::blobTransferCmd); 50 51 ipmi::registerOemHandler(ipmi::prioOemBase, oem::obmcOemNumber, 52 oem::Cmd::blobTransferCmd, ::ipmi::Privilege::User, 53 [](ipmi::Context::ptr ctx, uint8_t cmd, 54 const std::vector<uint8_t>& data) { 55 // Get current IPMI channel and get the max transfer size 56 // (assuming that it does not change). 57 return handleBlobCommand(cmd, data, 58 ipmi::getChannelMaxTransferSize(ctx->channel)); 59 }); 60 61 /* Install handlers. */ 62 try 63 { 64 loadLibraries(getBlobManager(), BLOB_LIB_PATH); 65 } 66 catch (const std::exception& e) 67 { 68 log<level::ERR>("ERROR loading blob handlers", 69 entry("ERROR=%s", e.what())); 70 } 71 } 72 } // namespace blobs 73