xref: /openbmc/phosphor-ipmi-blobs/main.cpp (revision 97e69ca106fc2415f89370eea36fb674435b5bdb)
1ef3aeadcSPatrick Venture /*
2ef3aeadcSPatrick Venture  * Copyright 2018 Google Inc.
3ef3aeadcSPatrick Venture  *
4ef3aeadcSPatrick Venture  * Licensed under the Apache License, Version 2.0 (the "License");
5ef3aeadcSPatrick Venture  * you may not use this file except in compliance with the License.
6ef3aeadcSPatrick Venture  * You may obtain a copy of the License at
7ef3aeadcSPatrick Venture  *
8ef3aeadcSPatrick Venture  *     http://www.apache.org/licenses/LICENSE-2.0
9ef3aeadcSPatrick Venture  *
10ef3aeadcSPatrick Venture  * Unless required by applicable law or agreed to in writing, software
11ef3aeadcSPatrick Venture  * distributed under the License is distributed on an "AS IS" BASIS,
12ef3aeadcSPatrick Venture  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13ef3aeadcSPatrick Venture  * See the License for the specific language governing permissions and
14ef3aeadcSPatrick Venture  * limitations under the License.
15ef3aeadcSPatrick Venture  */
16ef3aeadcSPatrick Venture 
17ef3aeadcSPatrick Venture #include "config.h"
18ef3aeadcSPatrick Venture 
19ef3aeadcSPatrick Venture #include "ipmi.hpp"
20cd8dab49SPatrick Venture #include "manager.hpp"
21ef3aeadcSPatrick Venture #include "process.hpp"
225100a386SPatrick Venture #include "utils.hpp"
23ef3aeadcSPatrick Venture 
24acebece3SWilliam A. Kennington III #include <ipmid/api.h>
25ef3aeadcSPatrick Venture 
26067ece15SWilly Tu #include <ipmid/api-types.hpp>
27067ece15SWilly Tu #include <ipmid/handler.hpp>
28acebece3SWilliam A. Kennington III #include <ipmid/iana.hpp>
29acebece3SWilliam A. Kennington III #include <ipmid/oemopenbmc.hpp>
30acebece3SWilliam A. Kennington III #include <ipmid/oemrouter.hpp>
311c4d3d34SBenjamin Fair #include <phosphor-logging/log.hpp>
3283f9992cSWilly Tu #include <user_channel/channel_layer.hpp>
33ef3aeadcSPatrick Venture 
3452509572SPatrick Williams #include <cstdio>
3552509572SPatrick Williams #include <memory>
3652509572SPatrick Williams #include <span>
3752509572SPatrick Williams 
38ef3aeadcSPatrick Venture namespace blobs
39ef3aeadcSPatrick Venture {
40ef3aeadcSPatrick Venture 
411c4d3d34SBenjamin Fair using namespace phosphor::logging;
421c4d3d34SBenjamin Fair 
43ef3aeadcSPatrick Venture void setupBlobGlobalHandler() __attribute__((constructor));
44ef3aeadcSPatrick Venture 
setupBlobGlobalHandler()45ef3aeadcSPatrick Venture void setupBlobGlobalHandler()
46ef3aeadcSPatrick Venture {
47ef3aeadcSPatrick Venture     std::fprintf(stderr,
48ef3aeadcSPatrick Venture                  "Registering OEM:[%#08X], Cmd:[%#04X] for Blob Commands\n",
49e08863e3SPatrick Venture                  oem::obmcOemNumber, oem::Cmd::blobTransferCmd);
50ef3aeadcSPatrick Venture 
51*97e69ca1SPatrick Williams     ipmi::registerOemHandler(
52*97e69ca1SPatrick Williams         ipmi::prioOemBase, oem::obmcOemNumber, oem::Cmd::blobTransferCmd,
53*97e69ca1SPatrick Williams         ::ipmi::Privilege::User,
5483f9992cSWilly Tu         [](ipmi::Context::ptr ctx, uint8_t cmd,
5583f9992cSWilly Tu            const std::vector<uint8_t>& data) {
5683f9992cSWilly Tu             // Get current IPMI channel and get the max transfer size
5783f9992cSWilly Tu             // (assuming that it does not change).
58*97e69ca1SPatrick Williams             return handleBlobCommand(
59*97e69ca1SPatrick Williams                 cmd, data, ipmi::getChannelMaxTransferSize(ctx->channel));
60067ece15SWilly Tu         });
61ef3aeadcSPatrick Venture 
625100a386SPatrick Venture     /* Install handlers. */
631c4d3d34SBenjamin Fair     try
641c4d3d34SBenjamin Fair     {
658aee057bSPatrick Venture         loadLibraries(getBlobManager(), BLOB_LIB_PATH);
66ef3aeadcSPatrick Venture     }
671c4d3d34SBenjamin Fair     catch (const std::exception& e)
681c4d3d34SBenjamin Fair     {
691c4d3d34SBenjamin Fair         log<level::ERR>("ERROR loading blob handlers",
701c4d3d34SBenjamin Fair                         entry("ERROR=%s", e.what()));
711c4d3d34SBenjamin Fair     }
721c4d3d34SBenjamin Fair }
73ef3aeadcSPatrick Venture } // namespace blobs
74