blob: 5804fd3685f8ac718483fc872fa759384af1c8e4 [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>
Patrick Venture28557a12018-09-28 08:56:05 -070027#include <cstdio>
Patrick Venture4d49ae62018-09-17 11:35:32 -070028#include <host-ipmid/iana.hpp>
29#include <host-ipmid/oemrouter.hpp>
Patrick Venture4d49ae62018-09-17 11:35:32 -070030
31namespace oem
32{
33namespace google
34{
35constexpr int sysCmd = 50;
36} // namespace google
37} // namespace oem
38
39namespace google
40{
41namespace ipmi
42{
43
44static ipmi_ret_t HandleSysCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf,
45 uint8_t* replyCmdBuf, size_t* dataLen)
46{
47 // Verify it's at least as long as it needs to be for a subcommand.
48 if ((*dataLen) < 1)
49 {
Patrick Venturece07ee02018-09-19 18:09:32 -070050 std::fprintf(stderr, "*dataLen too small: %u\n",
51 static_cast<uint32_t>(*dataLen));
Patrick Venture4d49ae62018-09-17 11:35:32 -070052 return IPMI_CC_INVALID;
53 }
54
55 switch (reqBuf[0])
56 {
57 case SysCableCheck:
58 return CableCheck(reqBuf, replyCmdBuf, dataLen);
59 case SysCpldVersion:
60 return CpldVersion(reqBuf, replyCmdBuf, dataLen);
61 case SysGetEthDevice:
62 return GetEthDevice(reqBuf, replyCmdBuf, dataLen);
63 case SysPsuHardReset:
64 return PsuHardReset(reqBuf, replyCmdBuf, dataLen);
65 default:
Patrick Venturece07ee02018-09-19 18:09:32 -070066 std::fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]);
Patrick Venture4d49ae62018-09-17 11:35:32 -070067 return IPMI_CC_INVALID;
68 }
69}
70
71void setupGlobalOemCableCheck() __attribute__((constructor));
72
73void setupGlobalOemCableCheck()
74{
75 oem::Router* oemRouter = oem::mutableRouter();
76
Patrick Venturece07ee02018-09-19 18:09:32 -070077 std::fprintf(stderr,
78 "Registering OEM:[%#08X], Cmd:[%#04X] for Sys Commands\n",
79 oem::googOemNumber, oem::google::sysCmd);
Patrick Venture4d49ae62018-09-17 11:35:32 -070080
81 oemRouter->registerHandler(oem::googOemNumber, oem::google::sysCmd,
82 HandleSysCommand);
83}
84
85} // namespace ipmi
86} // namespace google