1 // Copyright 2021 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 "handler.hpp" 24 #include "host_power_off.hpp" 25 #include "machine_name.hpp" 26 #include "pcie_i2c.hpp" 27 #include "psu.hpp" 28 29 #include <ipmid/api.h> 30 31 #include <cstdint> 32 #include <cstdio> 33 #include <ipmid/api-types.hpp> 34 #include <ipmid/message.hpp> 35 #include <optional> 36 #include <span> 37 38 namespace google 39 { 40 namespace ipmi 41 { 42 43 Resp handleSysCommand(HandlerInterface* handler, ::ipmi::Context::ptr, 44 uint8_t cmd, std::span<const uint8_t> data) 45 { 46 switch (cmd) 47 { 48 case SysCableCheck: 49 return cableCheck(data, handler); 50 case SysCpldVersion: 51 return cpldVersion(data, handler); 52 case SysGetEthDevice: 53 return getEthDevice(data, handler); 54 case SysPsuHardReset: 55 return psuHardReset(data, handler); 56 case SysPcieSlotCount: 57 return pcieSlotCount(data, handler); 58 case SysPcieSlotI2cBusMapping: 59 return pcieSlotI2cBusMapping(data, handler); 60 case SysEntityName: 61 return getEntityName(data, handler); 62 case SysMachineName: 63 return getMachineName(data, handler); 64 case SysPsuHardResetOnShutdown: 65 return psuHardResetOnShutdown(data, handler); 66 case SysGetFlashSize: 67 return getFlashSize(data, handler); 68 case SysHostPowerOff: 69 return hostPowerOff(data, handler); 70 default: 71 std::fprintf(stderr, "Invalid subcommand: 0x%x\n", cmd); 72 return ::ipmi::responseInvalidCommand(); 73 } 74 } 75 76 } // namespace ipmi 77 } // namespace google 78