blob: 2b713156636af8960af1666c56cbcb13c1babee3 [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"
Willy Tu3b1b4272021-03-02 17:58:10 -080024#include "flash_size.hpp"
Patrick Venture6d507442020-08-13 13:41:55 -070025#include "handler.hpp"
William A. Kennington III29f35bc2020-11-03 23:30:31 -080026#include "machine_name.hpp"
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070027#include "pcie_i2c.hpp"
28#include "psu.hpp"
29
30#include <ipmid/api.h>
31
32#include <cstdint>
33#include <cstdio>
34
35namespace google
36{
37namespace ipmi
38{
39
40ipmi_ret_t handleSysCommand(HandlerInterface* handler, ipmi_cmd_t cmd,
41 const uint8_t* reqBuf, uint8_t* replyCmdBuf,
42 size_t* dataLen)
43{
44 // Verify it's at least as long as it needs to be for a subcommand.
45 if ((*dataLen) < 1)
46 {
47 std::fprintf(stderr, "*dataLen too small: %u\n",
48 static_cast<uint32_t>(*dataLen));
49 return IPMI_CC_REQ_DATA_LEN_INVALID;
50 }
51
52 switch (reqBuf[0])
53 {
54 case SysCableCheck:
55 return cableCheck(reqBuf, replyCmdBuf, dataLen, handler);
56 case SysCpldVersion:
57 return cpldVersion(reqBuf, replyCmdBuf, dataLen, handler);
58 case SysGetEthDevice:
59 return getEthDevice(reqBuf, replyCmdBuf, dataLen, handler);
60 case SysPsuHardReset:
61 return psuHardReset(reqBuf, replyCmdBuf, dataLen, handler);
62 case SysPcieSlotCount:
63 return pcieSlotCount(reqBuf, replyCmdBuf, dataLen, handler);
64 case SysPcieSlotI2cBusMapping:
65 return pcieSlotI2cBusMapping(reqBuf, replyCmdBuf, dataLen, handler);
66 case SysEntityName:
67 return getEntityName(reqBuf, replyCmdBuf, dataLen, handler);
William A. Kennington III29f35bc2020-11-03 23:30:31 -080068 case SysMachineName:
69 return getMachineName(reqBuf, replyCmdBuf, dataLen, handler);
Shounak Mitraac4a16f2021-02-02 11:11:44 -080070 case SysPsuHardResetOnShutdown:
71 return psuHardResetOnShutdown(reqBuf, replyCmdBuf, dataLen,
72 handler);
Willy Tu3b1b4272021-03-02 17:58:10 -080073 case SysGetFlashSize:
74 return getFlashSize(reqBuf, replyCmdBuf, dataLen, handler);
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070075 default:
76 std::fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]);
77 return IPMI_CC_INVALID;
78 }
79}
80
81} // namespace ipmi
82} // namespace google