blob: 0e365336c20bfe81abff77aa28e0e4458ec9e7bc [file] [log] [blame]
Patrick Ventureef3aead2018-09-12 08:53:29 -07001/*
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 Venturecd8dab42019-01-15 19:57:38 -080020#include "manager.hpp"
Patrick Ventureef3aead2018-09-12 08:53:29 -070021#include "process.hpp"
Patrick Venture5100a382018-09-27 10:40:50 -070022#include "utils.hpp"
Patrick Ventureef3aead2018-09-12 08:53:29 -070023
William A. Kennington IIIacebece2019-02-07 15:15:44 -080024#include <ipmid/api.h>
Patrick Ventureef3aead2018-09-12 08:53:29 -070025
Willy Tu067ece12022-06-16 02:07:06 -070026#include <ipmid/api-types.hpp>
27#include <ipmid/handler.hpp>
William A. Kennington IIIacebece2019-02-07 15:15:44 -080028#include <ipmid/iana.hpp>
29#include <ipmid/oemopenbmc.hpp>
30#include <ipmid/oemrouter.hpp>
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070031#include <phosphor-logging/log.hpp>
Willy Tu83f99922022-06-22 14:59:07 -070032#include <user_channel/channel_layer.hpp>
Patrick Ventureef3aead2018-09-12 08:53:29 -070033
Patrick Williams52509572023-05-10 07:51:18 -050034#include <cstdio>
35#include <memory>
36#include <span>
37
Patrick Ventureef3aead2018-09-12 08:53:29 -070038namespace blobs
39{
40
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070041using namespace phosphor::logging;
42
Patrick Ventureef3aead2018-09-12 08:53:29 -070043void setupBlobGlobalHandler() __attribute__((constructor));
44
45void setupBlobGlobalHandler()
46{
Patrick Ventureef3aead2018-09-12 08:53:29 -070047 std::fprintf(stderr,
48 "Registering OEM:[%#08X], Cmd:[%#04X] for Blob Commands\n",
Patrick Venturee08863e2018-11-15 14:39:44 -080049 oem::obmcOemNumber, oem::Cmd::blobTransferCmd);
Patrick Ventureef3aead2018-09-12 08:53:29 -070050
Patrick Williams97e69ca2024-08-16 15:21:49 -040051 ipmi::registerOemHandler(
52 ipmi::prioOemBase, oem::obmcOemNumber, oem::Cmd::blobTransferCmd,
53 ::ipmi::Privilege::User,
54 [](ipmi::Context::ptr ctx, uint8_t cmd,
55 const std::vector<uint8_t>& data) {
56 // Get current IPMI channel and get the max transfer size
57 // (assuming that it does not change).
58 return handleBlobCommand(
59 cmd, data, ipmi::getChannelMaxTransferSize(ctx->channel));
60 });
Patrick Ventureef3aead2018-09-12 08:53:29 -070061
Patrick Venture5100a382018-09-27 10:40:50 -070062 /* Install handlers. */
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070063 try
64 {
Patrick Venture8aee0572018-11-28 14:59:23 -080065 loadLibraries(getBlobManager(), BLOB_LIB_PATH);
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070066 }
67 catch (const std::exception& e)
68 {
69 log<level::ERR>("ERROR loading blob handlers",
70 entry("ERROR=%s", e.what()));
71 }
Patrick Ventureef3aead2018-09-12 08:53:29 -070072}
73} // namespace blobs