| /* |
| * Copyright 2018 Google Inc. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #include "main.hpp" |
| |
| #include "cable.hpp" |
| #include "cpld.hpp" |
| #include "entity_name.hpp" |
| #include "eth.hpp" |
| #include "handler_impl.hpp" |
| #include "pcie_i2c.hpp" |
| #include "psu.hpp" |
| |
| #include <ipmid/api.h> |
| |
| #include <cstdint> |
| #include <cstdio> |
| #include <ipmid/iana.hpp> |
| #include <ipmid/oemrouter.hpp> |
| |
| namespace oem |
| { |
| namespace google |
| { |
| constexpr int sysCmd = 50; |
| } // namespace google |
| } // namespace oem |
| |
| namespace google |
| { |
| namespace ipmi |
| { |
| |
| Handler handlerImpl; |
| |
| static ipmi_ret_t handleSysCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf, |
| uint8_t* replyCmdBuf, size_t* dataLen) |
| { |
| // Verify it's at least as long as it needs to be for a subcommand. |
| if ((*dataLen) < 1) |
| { |
| std::fprintf(stderr, "*dataLen too small: %u\n", |
| static_cast<uint32_t>(*dataLen)); |
| return IPMI_CC_REQ_DATA_LEN_INVALID; |
| } |
| |
| switch (reqBuf[0]) |
| { |
| case SysCableCheck: |
| return cableCheck(reqBuf, replyCmdBuf, dataLen, &handlerImpl); |
| case SysCpldVersion: |
| return cpldVersion(reqBuf, replyCmdBuf, dataLen, &handlerImpl); |
| case SysGetEthDevice: |
| return getEthDevice(reqBuf, replyCmdBuf, dataLen, &handlerImpl); |
| case SysPsuHardReset: |
| return psuHardReset(reqBuf, replyCmdBuf, dataLen, &handlerImpl); |
| case SysPcieSlotCount: |
| return pcieSlotCount(reqBuf, replyCmdBuf, dataLen, &handlerImpl); |
| case SysPcieSlotI2cBusMapping: |
| return pcieSlotI2cBusMapping(reqBuf, replyCmdBuf, dataLen, |
| &handlerImpl); |
| case SysEntityName: |
| return getEntityName(reqBuf, replyCmdBuf, dataLen, &handlerImpl); |
| default: |
| std::fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]); |
| return IPMI_CC_INVALID; |
| } |
| } |
| |
| void setupGoogleOemSysCommands() __attribute__((constructor)); |
| |
| void setupGoogleOemSysCommands() |
| { |
| oem::Router* oemRouter = oem::mutableRouter(); |
| |
| std::fprintf(stderr, |
| "Registering OEM:[%#08X], Cmd:[%#04X] for Sys Commands\n", |
| oem::googOemNumber, oem::google::sysCmd); |
| |
| oemRouter->registerHandler(oem::googOemNumber, oem::google::sysCmd, |
| handleSysCommand); |
| } |
| |
| } // namespace ipmi |
| } // namespace google |