xref: /openbmc/google-ipmi-sys/ipmi.cpp (revision 5e70dc8c)
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 <cstdint>
35 #include <cstdio>
36 #include <ipmid/api-types.hpp>
37 #include <ipmid/message.hpp>
38 #include <optional>
39 #include <span>
40 
41 namespace google
42 {
43 namespace ipmi
44 {
45 
46 Resp handleSysCommand(HandlerInterface* handler, ::ipmi::Context::ptr,
47                       uint8_t cmd, std::span<const uint8_t> data)
48 {
49     switch (cmd)
50     {
51         case SysGetBmcMode:
52             return getBmcMode(data, handler);
53         case SysCableCheck:
54             return cableCheck(data, handler);
55         case SysCpldVersion:
56             return cpldVersion(data, handler);
57         case SysGetEthDevice:
58             return getEthDevice(data, handler);
59         case SysPsuHardReset:
60             return psuHardReset(data, handler);
61         case SysPcieSlotCount:
62             return pcieSlotCount(data, handler);
63         case SysPcieSlotI2cBusMapping:
64             return pcieSlotI2cBusMapping(data, handler);
65         case SysEntityName:
66             return getEntityName(data, handler);
67         case SysMachineName:
68             return getMachineName(data, handler);
69         case SysPsuHardResetOnShutdown:
70             return psuHardResetOnShutdown(data, handler);
71         case SysGetFlashSize:
72             return getFlashSize(data, handler);
73         case SysHostPowerOff:
74             return hostPowerOff(data, handler);
75         case SysAccelOobDeviceCount:
76             return accelOobDeviceCount(data, handler);
77         case SysAccelOobDeviceName:
78             return accelOobDeviceName(data, handler);
79         case SysAccelOobRead:
80             return accelOobRead(data, handler);
81         case SysAccelOobWrite:
82             return accelOobWrite(data, handler);
83         case SysPCIeSlotBifurcation:
84             return pcieBifurcation(data, handler);
85         default:
86             std::fprintf(stderr, "Invalid subcommand: 0x%x\n", cmd);
87             return ::ipmi::responseInvalidCommand();
88     }
89 }
90 
91 } // namespace ipmi
92 } // namespace google
93