blob: ef6508b2f4e67c403209a196e184968b52a43415 [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 {
54 fprintf(stderr, "*dataLen too small: %lu\n", (*dataLen));
55 return IPMI_CC_INVALID;
56 }
57
58 switch (reqBuf[0])
59 {
60 case SysCableCheck:
61 return CableCheck(reqBuf, replyCmdBuf, dataLen);
62 case SysCpldVersion:
63 return CpldVersion(reqBuf, replyCmdBuf, dataLen);
64 case SysGetEthDevice:
65 return GetEthDevice(reqBuf, replyCmdBuf, dataLen);
66 case SysPsuHardReset:
67 return PsuHardReset(reqBuf, replyCmdBuf, dataLen);
68 default:
69 fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]);
70 return IPMI_CC_INVALID;
71 }
72}
73
74void setupGlobalOemCableCheck() __attribute__((constructor));
75
76void setupGlobalOemCableCheck()
77{
78 oem::Router* oemRouter = oem::mutableRouter();
79
80 fprintf(stderr, "Registering OEM:[%#08X], Cmd:[%#04X] for Sys Commands\n",
81 oem::googOemNumber, oem::google::sysCmd);
82
83 oemRouter->registerHandler(oem::googOemNumber, oem::google::sysCmd,
84 HandleSysCommand);
85}
86
87} // namespace ipmi
88} // namespace google