blob: 9575a1a2710da90092f60fb1a8f1571402414608 [file] [log] [blame]
Patrick Venture4d49ae62018-09-17 11:35:32 -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 "main.hpp"
18
19#include "cable.hpp"
20#include "cpld.hpp"
21#include "eth.hpp"
22#include "psu.hpp"
23
24#include <host-ipmid/ipmid-api.h>
25
26#include <cstdint>
27#include <experimental/filesystem>
28#include <fstream>
29#include <host-ipmid/iana.hpp>
30#include <host-ipmid/oemrouter.hpp>
31#include <sstream>
32#include <string>
33#include <system_error>
34
35namespace oem
36{
37namespace google
38{
39constexpr int sysCmd = 50;
40} // namespace google
41} // namespace oem
42
43namespace google
44{
45namespace ipmi
46{
47
48static ipmi_ret_t HandleSysCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf,
49 uint8_t* replyCmdBuf, size_t* dataLen)
50{
51 // Verify it's at least as long as it needs to be for a subcommand.
52 if ((*dataLen) < 1)
53 {
Patrick Venturece07ee02018-09-19 18:09:32 -070054 std::fprintf(stderr, "*dataLen too small: %u\n",
55 static_cast<uint32_t>(*dataLen));
Patrick Venture4d49ae62018-09-17 11:35:32 -070056 return IPMI_CC_INVALID;
57 }
58
59 switch (reqBuf[0])
60 {
61 case SysCableCheck:
62 return CableCheck(reqBuf, replyCmdBuf, dataLen);
63 case SysCpldVersion:
64 return CpldVersion(reqBuf, replyCmdBuf, dataLen);
65 case SysGetEthDevice:
66 return GetEthDevice(reqBuf, replyCmdBuf, dataLen);
67 case SysPsuHardReset:
68 return PsuHardReset(reqBuf, replyCmdBuf, dataLen);
69 default:
Patrick Venturece07ee02018-09-19 18:09:32 -070070 std::fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]);
Patrick Venture4d49ae62018-09-17 11:35:32 -070071 return IPMI_CC_INVALID;
72 }
73}
74
75void setupGlobalOemCableCheck() __attribute__((constructor));
76
77void setupGlobalOemCableCheck()
78{
79 oem::Router* oemRouter = oem::mutableRouter();
80
Patrick Venturece07ee02018-09-19 18:09:32 -070081 std::fprintf(stderr,
82 "Registering OEM:[%#08X], Cmd:[%#04X] for Sys Commands\n",
83 oem::googOemNumber, oem::google::sysCmd);
Patrick Venture4d49ae62018-09-17 11:35:32 -070084
85 oemRouter->registerHandler(oem::googOemNumber, oem::google::sysCmd,
86 HandleSysCommand);
87}
88
89} // namespace ipmi
90} // namespace google