blob: ee236d9b68e19849ebbf08b6f5710d96449e378a [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"
20#include "process.hpp"
Patrick Venture5100a382018-09-27 10:40:50 -070021#include "utils.hpp"
Patrick Ventureef3aead2018-09-12 08:53:29 -070022
23#include <host-ipmid/ipmid-api.h>
24
Patrick Venture25368632018-11-21 14:52:12 -080025#include <blobs-ipmid/manager.hpp>
Patrick Ventureef3aead2018-09-12 08:53:29 -070026#include <cstdio>
27#include <host-ipmid/iana.hpp>
Patrick Venturee08863e2018-11-15 14:39:44 -080028#include <host-ipmid/oemopenbmc.hpp>
Patrick Ventureef3aead2018-09-12 08:53:29 -070029#include <host-ipmid/oemrouter.hpp>
30#include <memory>
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070031#include <phosphor-logging/log.hpp>
Patrick Ventureef3aead2018-09-12 08:53:29 -070032
Patrick Ventureef3aead2018-09-12 08:53:29 -070033namespace blobs
34{
35
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070036using namespace phosphor::logging;
37
Patrick Ventureef3aead2018-09-12 08:53:29 -070038static ipmi_ret_t handleBlobCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf,
39 uint8_t* replyCmdBuf, size_t* dataLen)
40{
41 /* It's holding at least a sub-command. The OEN is trimmed from the bytes
42 * before this is called.
43 */
44 if ((*dataLen) < 1)
45 {
Patrick Venture41258802018-11-12 10:46:30 -080046 return IPMI_CC_REQ_DATA_LEN_INVALID;
Patrick Ventureef3aead2018-09-12 08:53:29 -070047 }
48
Patrick Venture41258802018-11-12 10:46:30 -080049 /* on failure rc is set to the corresponding IPMI error. */
50 ipmi_ret_t rc = IPMI_CC_OK;
Patrick Ventureef3aead2018-09-12 08:53:29 -070051 Crc16 crc;
52 IpmiBlobHandler command =
Patrick Venture41258802018-11-12 10:46:30 -080053 validateBlobCommand(&crc, reqBuf, replyCmdBuf, dataLen, &rc);
Patrick Ventureef3aead2018-09-12 08:53:29 -070054 if (command == nullptr)
55 {
Patrick Venture41258802018-11-12 10:46:30 -080056 return rc;
Patrick Ventureef3aead2018-09-12 08:53:29 -070057 }
58
Patrick Venture73eb6872018-10-01 18:37:34 -070059 return processBlobCommand(command, getBlobManager(), &crc, reqBuf,
60 replyCmdBuf, dataLen);
Patrick Ventureef3aead2018-09-12 08:53:29 -070061}
62
Patrick Venture5100a382018-09-27 10:40:50 -070063/* TODO: this should come from the makefile or recipe... */
Patrick Venturedf53de12018-11-08 10:29:50 -080064constexpr auto expectedHandlerPath = "/usr/lib/blob-ipmid";
Patrick Venture5100a382018-09-27 10:40:50 -070065
Patrick Ventureef3aead2018-09-12 08:53:29 -070066void setupBlobGlobalHandler() __attribute__((constructor));
67
68void setupBlobGlobalHandler()
69{
70 oem::Router* oemRouter = oem::mutableRouter();
71 std::fprintf(stderr,
72 "Registering OEM:[%#08X], Cmd:[%#04X] for Blob Commands\n",
Patrick Venturee08863e2018-11-15 14:39:44 -080073 oem::obmcOemNumber, oem::Cmd::blobTransferCmd);
Patrick Ventureef3aead2018-09-12 08:53:29 -070074
Patrick Venturee08863e2018-11-15 14:39:44 -080075 oemRouter->registerHandler(oem::obmcOemNumber, oem::Cmd::blobTransferCmd,
Patrick Ventureef3aead2018-09-12 08:53:29 -070076 handleBlobCommand);
77
Patrick Venture5100a382018-09-27 10:40:50 -070078 /* Install handlers. */
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070079 try
80 {
Patrick Venturec18e2b62018-11-21 14:19:28 -080081 loadLibraries(getBlobManager(), expectedHandlerPath);
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070082 }
83 catch (const std::exception& e)
84 {
85 log<level::ERR>("ERROR loading blob handlers",
86 entry("ERROR=%s", e.what()));
87 }
Patrick Ventureef3aead2018-09-12 08:53:29 -070088}
89} // namespace blobs