xref: /openbmc/google-ipmi-sys/ipmi.cpp (revision 6c71b0f9)
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 "cable.hpp"
18 #include "commands.hpp"
19 #include "cpld.hpp"
20 #include "entity_name.hpp"
21 #include "eth.hpp"
22 #include "flash_size.hpp"
23 #include "google_accel_oob.hpp"
24 #include "handler.hpp"
25 #include "host_power_off.hpp"
26 #include "machine_name.hpp"
27 #include "pcie_bifurcation.hpp"
28 #include "pcie_i2c.hpp"
29 #include "psu.hpp"
30 
31 #include <ipmid/api.h>
32 
33 #include <cstdint>
34 #include <cstdio>
35 #include <ipmid/api-types.hpp>
36 #include <ipmid/message.hpp>
37 #include <optional>
38 #include <span>
39 
40 namespace google
41 {
42 namespace ipmi
43 {
44 
45 Resp handleSysCommand(HandlerInterface* handler, ::ipmi::Context::ptr,
46                       uint8_t cmd, std::span<const uint8_t> data)
47 {
48     switch (cmd)
49     {
50         case SysCableCheck:
51             return cableCheck(data, handler);
52         case SysCpldVersion:
53             return cpldVersion(data, handler);
54         case SysGetEthDevice:
55             return getEthDevice(data, handler);
56         case SysPsuHardReset:
57             return psuHardReset(data, handler);
58         case SysPcieSlotCount:
59             return pcieSlotCount(data, handler);
60         case SysPcieSlotI2cBusMapping:
61             return pcieSlotI2cBusMapping(data, handler);
62         case SysEntityName:
63             return getEntityName(data, handler);
64         case SysMachineName:
65             return getMachineName(data, handler);
66         case SysPsuHardResetOnShutdown:
67             return psuHardResetOnShutdown(data, handler);
68         case SysGetFlashSize:
69             return getFlashSize(data, handler);
70         case SysHostPowerOff:
71             return hostPowerOff(data, handler);
72         case SysAccelOobDeviceCount:
73             return accelOobDeviceCount(data, handler);
74         case SysAccelOobDeviceName:
75             return accelOobDeviceName(data, handler);
76         case SysAccelOobRead:
77             return accelOobRead(data, handler);
78         case SysAccelOobWrite:
79             return accelOobWrite(data, handler);
80         case SysPCIeSlotBifurcation:
81             return pcieBifurcation(data, handler);
82         default:
83             std::fprintf(stderr, "Invalid subcommand: 0x%x\n", cmd);
84             return ::ipmi::responseInvalidCommand();
85     }
86 }
87 
88 } // namespace ipmi
89 } // namespace google
90