blob: d297efc2c2ce42c933dfe453348b7a2a00c79557 [file] [log] [blame]
Patrick Ventureeff1f2e2020-08-05 08:27:36 -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 "ipmi.hpp"
18
19#include "cable.hpp"
Patrick Venture0e9aae52020-08-13 13:07:09 -070020#include "commands.hpp"
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070021#include "cpld.hpp"
22#include "entity_name.hpp"
23#include "eth.hpp"
Patrick Venture6d507442020-08-13 13:41:55 -070024#include "handler.hpp"
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070025#include "pcie_i2c.hpp"
26#include "psu.hpp"
27
28#include <ipmid/api.h>
29
30#include <cstdint>
31#include <cstdio>
32
33namespace google
34{
35namespace ipmi
36{
37
38ipmi_ret_t handleSysCommand(HandlerInterface* handler, ipmi_cmd_t cmd,
39 const uint8_t* reqBuf, uint8_t* replyCmdBuf,
40 size_t* dataLen)
41{
42 // Verify it's at least as long as it needs to be for a subcommand.
43 if ((*dataLen) < 1)
44 {
45 std::fprintf(stderr, "*dataLen too small: %u\n",
46 static_cast<uint32_t>(*dataLen));
47 return IPMI_CC_REQ_DATA_LEN_INVALID;
48 }
49
50 switch (reqBuf[0])
51 {
52 case SysCableCheck:
53 return cableCheck(reqBuf, replyCmdBuf, dataLen, handler);
54 case SysCpldVersion:
55 return cpldVersion(reqBuf, replyCmdBuf, dataLen, handler);
56 case SysGetEthDevice:
57 return getEthDevice(reqBuf, replyCmdBuf, dataLen, handler);
58 case SysPsuHardReset:
59 return psuHardReset(reqBuf, replyCmdBuf, dataLen, handler);
60 case SysPcieSlotCount:
61 return pcieSlotCount(reqBuf, replyCmdBuf, dataLen, handler);
62 case SysPcieSlotI2cBusMapping:
63 return pcieSlotI2cBusMapping(reqBuf, replyCmdBuf, dataLen, handler);
64 case SysEntityName:
65 return getEntityName(reqBuf, replyCmdBuf, dataLen, handler);
66 default:
67 std::fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]);
68 return IPMI_CC_INVALID;
69 }
70}
71
72} // namespace ipmi
73} // namespace google