xref: /openbmc/google-ipmi-sys/ipmi.cpp (revision 444b5ea4)
1 // Copyright 2022 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "ipmi.hpp"
16 
17 #include "bmc_mode.hpp"
18 #include "cable.hpp"
19 #include "commands.hpp"
20 #include "cpld.hpp"
21 #include "entity_name.hpp"
22 #include "eth.hpp"
23 #include "flash_size.hpp"
24 #include "google_accel_oob.hpp"
25 #include "handler.hpp"
26 #include "host_power_off.hpp"
27 #include "machine_name.hpp"
28 #include "pcie_bifurcation.hpp"
29 #include "pcie_i2c.hpp"
30 #include "psu.hpp"
31 
32 #include <ipmid/api.h>
33 
34 #include <ipmid/api-types.hpp>
35 #include <ipmid/message.hpp>
36 
37 #include <cstdint>
38 #include <cstdio>
39 #include <optional>
40 #include <span>
41 
42 namespace google
43 {
44 namespace ipmi
45 {
46 
47 Resp handleSysCommand(HandlerInterface* handler, ::ipmi::Context::ptr,
48                       uint8_t cmd, std::span<const uint8_t> data)
49 {
50     switch (cmd)
51     {
52         case SysGetBmcMode:
53             return getBmcMode(data, handler);
54         case SysCableCheck:
55             return cableCheck(data, handler);
56         case SysCpldVersion:
57             return cpldVersion(data, handler);
58         case SysGetEthDevice:
59             return getEthDevice(data, handler);
60         case SysPsuHardReset:
61             return psuHardReset(data, handler);
62         case SysPcieSlotCount:
63             return pcieSlotCount(data, handler);
64         case SysPcieSlotI2cBusMapping:
65             return pcieSlotI2cBusMapping(data, handler);
66         case SysEntityName:
67             return getEntityName(data, handler);
68         case SysMachineName:
69             return getMachineName(data, handler);
70         case SysPsuHardResetOnShutdown:
71             return psuHardResetOnShutdown(data, handler);
72         case SysGetFlashSize:
73             return getFlashSize(data, handler);
74         case SysHostPowerOff:
75             return hostPowerOff(data, handler);
76         case SysAccelOobDeviceCount:
77             return accelOobDeviceCount(data, handler);
78         case SysAccelOobDeviceName:
79             return accelOobDeviceName(data, handler);
80         case SysAccelOobRead:
81             return accelOobRead(data, handler);
82         case SysAccelOobWrite:
83             return accelOobWrite(data, handler);
84         case SysPCIeSlotBifurcation:
85             return pcieBifurcation(data, handler);
86         default:
87             std::fprintf(stderr, "Invalid subcommand: 0x%x\n", cmd);
88             return ::ipmi::responseInvalidCommand();
89     }
90 }
91 
92 } // namespace ipmi
93 } // namespace google
94