Willy Tu | a2056e9 | 2021-10-10 13:36:16 -0700 | [diff] [blame] | 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. |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 14 | |
| 15 | #include "ipmi.hpp" |
| 16 | |
| 17 | #include "cable.hpp" |
Patrick Venture | 0e9aae5 | 2020-08-13 13:07:09 -0700 | [diff] [blame] | 18 | #include "commands.hpp" |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 19 | #include "cpld.hpp" |
| 20 | #include "entity_name.hpp" |
| 21 | #include "eth.hpp" |
Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 22 | #include "flash_size.hpp" |
Patrick Venture | 6d50744 | 2020-08-13 13:41:55 -0700 | [diff] [blame] | 23 | #include "handler.hpp" |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 24 | #include "host_power_off.hpp" |
William A. Kennington III | 29f35bc | 2020-11-03 23:30:31 -0800 | [diff] [blame] | 25 | #include "machine_name.hpp" |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 26 | #include "pcie_i2c.hpp" |
| 27 | #include "psu.hpp" |
| 28 | |
| 29 | #include <ipmid/api.h> |
| 30 | |
| 31 | #include <cstdint> |
| 32 | #include <cstdio> |
| 33 | |
| 34 | namespace google |
| 35 | { |
| 36 | namespace ipmi |
| 37 | { |
| 38 | |
William A. Kennington III | 5d78973 | 2021-06-24 03:39:31 -0700 | [diff] [blame] | 39 | ipmi_ret_t handleSysCommand(HandlerInterface* handler, ipmi_cmd_t, |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 40 | const uint8_t* reqBuf, uint8_t* replyCmdBuf, |
| 41 | size_t* dataLen) |
| 42 | { |
| 43 | // Verify it's at least as long as it needs to be for a subcommand. |
| 44 | if ((*dataLen) < 1) |
| 45 | { |
| 46 | std::fprintf(stderr, "*dataLen too small: %u\n", |
| 47 | static_cast<uint32_t>(*dataLen)); |
| 48 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 49 | } |
| 50 | |
| 51 | switch (reqBuf[0]) |
| 52 | { |
| 53 | case SysCableCheck: |
| 54 | return cableCheck(reqBuf, replyCmdBuf, dataLen, handler); |
| 55 | case SysCpldVersion: |
| 56 | return cpldVersion(reqBuf, replyCmdBuf, dataLen, handler); |
| 57 | case SysGetEthDevice: |
| 58 | return getEthDevice(reqBuf, replyCmdBuf, dataLen, handler); |
| 59 | case SysPsuHardReset: |
| 60 | return psuHardReset(reqBuf, replyCmdBuf, dataLen, handler); |
| 61 | case SysPcieSlotCount: |
| 62 | return pcieSlotCount(reqBuf, replyCmdBuf, dataLen, handler); |
| 63 | case SysPcieSlotI2cBusMapping: |
| 64 | return pcieSlotI2cBusMapping(reqBuf, replyCmdBuf, dataLen, handler); |
| 65 | case SysEntityName: |
| 66 | return getEntityName(reqBuf, replyCmdBuf, dataLen, handler); |
William A. Kennington III | 29f35bc | 2020-11-03 23:30:31 -0800 | [diff] [blame] | 67 | case SysMachineName: |
| 68 | return getMachineName(reqBuf, replyCmdBuf, dataLen, handler); |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 69 | case SysPsuHardResetOnShutdown: |
| 70 | return psuHardResetOnShutdown(reqBuf, replyCmdBuf, dataLen, |
| 71 | handler); |
Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 72 | case SysGetFlashSize: |
| 73 | return getFlashSize(reqBuf, replyCmdBuf, dataLen, handler); |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 74 | case SysHostPowerOff: |
| 75 | return hostPowerOff(reqBuf, replyCmdBuf, dataLen, handler); |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 76 | default: |
| 77 | std::fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]); |
| 78 | return IPMI_CC_INVALID; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | } // namespace ipmi |
| 83 | } // namespace google |