blob: cfa0de9aebbfb831ce6fa3ef2d1622c0fd926f29 [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
26#include <cstdio>
Willy Tu067ece12022-06-16 02:07:06 -070027#include <ipmid/api-types.hpp>
28#include <ipmid/handler.hpp>
William A. Kennington IIIacebece2019-02-07 15:15:44 -080029#include <ipmid/iana.hpp>
30#include <ipmid/oemopenbmc.hpp>
31#include <ipmid/oemrouter.hpp>
Patrick Ventureef3aead2018-09-12 08:53:29 -070032#include <memory>
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070033#include <phosphor-logging/log.hpp>
Willy Tu067ece12022-06-16 02:07:06 -070034#include <span>
Willy Tu83f99922022-06-22 14:59:07 -070035#include <user_channel/channel_layer.hpp>
Patrick Ventureef3aead2018-09-12 08:53:29 -070036
Patrick Ventureef3aead2018-09-12 08:53:29 -070037namespace blobs
38{
39
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070040using namespace phosphor::logging;
41
Patrick Ventureef3aead2018-09-12 08:53:29 -070042void setupBlobGlobalHandler() __attribute__((constructor));
43
44void setupBlobGlobalHandler()
45{
Patrick Ventureef3aead2018-09-12 08:53:29 -070046 std::fprintf(stderr,
47 "Registering OEM:[%#08X], Cmd:[%#04X] for Blob Commands\n",
Patrick Venturee08863e2018-11-15 14:39:44 -080048 oem::obmcOemNumber, oem::Cmd::blobTransferCmd);
Patrick Ventureef3aead2018-09-12 08:53:29 -070049
Willy Tu067ece12022-06-16 02:07:06 -070050 ipmi::registerOemHandler(
51 ipmi::prioOemBase, oem::obmcOemNumber, oem::Cmd::blobTransferCmd,
52 ::ipmi::Privilege::User,
Willy Tu83f99922022-06-22 14:59:07 -070053 [](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(
58 cmd, data, ipmi::getChannelMaxTransferSize(ctx->channel));
Willy Tu067ece12022-06-16 02:07:06 -070059 });
Patrick Ventureef3aead2018-09-12 08:53:29 -070060
Patrick Venture5100a382018-09-27 10:40:50 -070061 /* Install handlers. */
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070062 try
63 {
Patrick Venture8aee0572018-11-28 14:59:23 -080064 loadLibraries(getBlobManager(), BLOB_LIB_PATH);
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070065 }
66 catch (const std::exception& e)
67 {
68 log<level::ERR>("ERROR loading blob handlers",
69 entry("ERROR=%s", e.what()));
70 }
Patrick Ventureef3aead2018-09-12 08:53:29 -070071}
72} // namespace blobs