blob: e680d7ca411e9adbbfb80f3413e977200097b460 [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
25#include <cstdio>
26#include <host-ipmid/iana.hpp>
27#include <host-ipmid/oemrouter.hpp>
28#include <memory>
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070029#include <phosphor-logging/log.hpp>
Patrick Ventureef3aead2018-09-12 08:53:29 -070030
31/* TODO: Swap out once https://gerrit.openbmc-project.xyz/12743 is merged */
32namespace oem
33{
34constexpr auto blobTransferCmd = 128;
35} // namespace oem
36
37namespace blobs
38{
39
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070040using namespace phosphor::logging;
41
Patrick Ventureef3aead2018-09-12 08:53:29 -070042static ipmi_ret_t handleBlobCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf,
43 uint8_t* replyCmdBuf, size_t* dataLen)
44{
45 /* It's holding at least a sub-command. The OEN is trimmed from the bytes
46 * before this is called.
47 */
48 if ((*dataLen) < 1)
49 {
50 return IPMI_CC_INVALID;
51 }
52
53 Crc16 crc;
54 IpmiBlobHandler command =
55 validateBlobCommand(&crc, reqBuf, replyCmdBuf, dataLen);
56 if (command == nullptr)
57 {
58 return IPMI_CC_INVALID;
59 }
60
Patrick Venture73eb6872018-10-01 18:37:34 -070061 return processBlobCommand(command, getBlobManager(), &crc, reqBuf,
62 replyCmdBuf, dataLen);
Patrick Ventureef3aead2018-09-12 08:53:29 -070063}
64
Patrick Venture5100a382018-09-27 10:40:50 -070065/* TODO: this should come from the makefile or recipe... */
66constexpr auto expectedHandlerPath = "/usr/lib/blobs-ipmid";
67
Patrick Ventureef3aead2018-09-12 08:53:29 -070068void setupBlobGlobalHandler() __attribute__((constructor));
69
70void setupBlobGlobalHandler()
71{
72 oem::Router* oemRouter = oem::mutableRouter();
73 std::fprintf(stderr,
74 "Registering OEM:[%#08X], Cmd:[%#04X] for Blob Commands\n",
75 oem::obmcOemNumber, oem::blobTransferCmd);
76
77 oemRouter->registerHandler(oem::obmcOemNumber, oem::blobTransferCmd,
78 handleBlobCommand);
79
Patrick Venture5100a382018-09-27 10:40:50 -070080 /* Install handlers. */
Benjamin Fair1c4d3d32018-10-19 17:22:53 -070081 try
82 {
83 loadLibraries(expectedHandlerPath);
84 }
85 catch (const std::exception& e)
86 {
87 log<level::ERR>("ERROR loading blob handlers",
88 entry("ERROR=%s", e.what()));
89 }
Patrick Ventureef3aead2018-09-12 08:53:29 -070090}
91} // namespace blobs