blob: a28a232e786a34a8df60986b86546e9fe7d996ce [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"
21
22#include <host-ipmid/ipmid-api.h>
23
24#include <cstdio>
25#include <host-ipmid/iana.hpp>
26#include <host-ipmid/oemrouter.hpp>
27#include <memory>
28
Patrick Venturec0f499b2018-09-14 17:57:42 -070029#if ENABLE_EXAMPLE
30#include "example/example.hpp"
31#endif
32
Patrick Ventureef3aead2018-09-12 08:53:29 -070033/* TODO: Swap out once https://gerrit.openbmc-project.xyz/12743 is merged */
34namespace oem
35{
36constexpr auto blobTransferCmd = 128;
37} // namespace oem
38
39namespace blobs
40{
41
42static std::unique_ptr<BlobManager> manager;
43
44static ipmi_ret_t handleBlobCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf,
45 uint8_t* replyCmdBuf, size_t* dataLen)
46{
47 /* It's holding at least a sub-command. The OEN is trimmed from the bytes
48 * before this is called.
49 */
50 if ((*dataLen) < 1)
51 {
52 return IPMI_CC_INVALID;
53 }
54
55 Crc16 crc;
56 IpmiBlobHandler command =
57 validateBlobCommand(&crc, reqBuf, replyCmdBuf, dataLen);
58 if (command == nullptr)
59 {
60 return IPMI_CC_INVALID;
61 }
62
63 return processBlobCommand(command, manager.get(), &crc, reqBuf, replyCmdBuf,
64 dataLen);
65}
66
67void setupBlobGlobalHandler() __attribute__((constructor));
68
69void setupBlobGlobalHandler()
70{
71 oem::Router* oemRouter = oem::mutableRouter();
72 std::fprintf(stderr,
73 "Registering OEM:[%#08X], Cmd:[%#04X] for Blob Commands\n",
74 oem::obmcOemNumber, oem::blobTransferCmd);
75
76 oemRouter->registerHandler(oem::obmcOemNumber, oem::blobTransferCmd,
77 handleBlobCommand);
78
79 manager = std::make_unique<BlobManager>();
Patrick Venturec0f499b2018-09-14 17:57:42 -070080
81#if ENABLE_EXAMPLE
82 manager->registerHandler(std::move(std::make_unique<ExampleBlobHandler>()));
83#endif
Patrick Ventureef3aead2018-09-12 08:53:29 -070084}
85} // namespace blobs