Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "main.hpp" |
| 18 | |
| 19 | #include "cable.hpp" |
| 20 | #include "cpld.hpp" |
| 21 | #include "eth.hpp" |
| 22 | #include "psu.hpp" |
| 23 | |
| 24 | #include <host-ipmid/ipmid-api.h> |
| 25 | |
| 26 | #include <cstdint> |
Patrick Venture | 28557a1 | 2018-09-28 08:56:05 -0700 | [diff] [blame^] | 27 | #include <cstdio> |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 28 | #include <host-ipmid/iana.hpp> |
| 29 | #include <host-ipmid/oemrouter.hpp> |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 30 | |
| 31 | namespace oem |
| 32 | { |
| 33 | namespace google |
| 34 | { |
| 35 | constexpr int sysCmd = 50; |
| 36 | } // namespace google |
| 37 | } // namespace oem |
| 38 | |
| 39 | namespace google |
| 40 | { |
| 41 | namespace ipmi |
| 42 | { |
| 43 | |
| 44 | static ipmi_ret_t HandleSysCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf, |
| 45 | uint8_t* replyCmdBuf, size_t* dataLen) |
| 46 | { |
| 47 | // Verify it's at least as long as it needs to be for a subcommand. |
| 48 | if ((*dataLen) < 1) |
| 49 | { |
Patrick Venture | ce07ee0 | 2018-09-19 18:09:32 -0700 | [diff] [blame] | 50 | std::fprintf(stderr, "*dataLen too small: %u\n", |
| 51 | static_cast<uint32_t>(*dataLen)); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 52 | return IPMI_CC_INVALID; |
| 53 | } |
| 54 | |
| 55 | switch (reqBuf[0]) |
| 56 | { |
| 57 | case SysCableCheck: |
| 58 | return CableCheck(reqBuf, replyCmdBuf, dataLen); |
| 59 | case SysCpldVersion: |
| 60 | return CpldVersion(reqBuf, replyCmdBuf, dataLen); |
| 61 | case SysGetEthDevice: |
| 62 | return GetEthDevice(reqBuf, replyCmdBuf, dataLen); |
| 63 | case SysPsuHardReset: |
| 64 | return PsuHardReset(reqBuf, replyCmdBuf, dataLen); |
| 65 | default: |
Patrick Venture | ce07ee0 | 2018-09-19 18:09:32 -0700 | [diff] [blame] | 66 | std::fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 67 | return IPMI_CC_INVALID; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | void setupGlobalOemCableCheck() __attribute__((constructor)); |
| 72 | |
| 73 | void setupGlobalOemCableCheck() |
| 74 | { |
| 75 | oem::Router* oemRouter = oem::mutableRouter(); |
| 76 | |
Patrick Venture | ce07ee0 | 2018-09-19 18:09:32 -0700 | [diff] [blame] | 77 | std::fprintf(stderr, |
| 78 | "Registering OEM:[%#08X], Cmd:[%#04X] for Sys Commands\n", |
| 79 | oem::googOemNumber, oem::google::sysCmd); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 80 | |
| 81 | oemRouter->registerHandler(oem::googOemNumber, oem::google::sysCmd, |
| 82 | HandleSysCommand); |
| 83 | } |
| 84 | |
| 85 | } // namespace ipmi |
| 86 | } // namespace google |