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