blob: 1f760f410291ffeb8af476ebd731fd836e5bb9ce [file] [log] [blame]
Willy Tua2056e92021-10-10 13:36:16 -07001// 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 Ventureeff1f2e2020-08-05 08:27:36 -070014
15#include "ipmi.hpp"
16
17#include "cable.hpp"
Patrick Venture0e9aae52020-08-13 13:07:09 -070018#include "commands.hpp"
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070019#include "cpld.hpp"
20#include "entity_name.hpp"
21#include "eth.hpp"
Willy Tu3b1b4272021-03-02 17:58:10 -080022#include "flash_size.hpp"
Patrick Venture6d507442020-08-13 13:41:55 -070023#include "handler.hpp"
linyuny8cfa4c42021-06-16 13:53:08 -070024#include "host_power_off.hpp"
William A. Kennington III29f35bc2020-11-03 23:30:31 -080025#include "machine_name.hpp"
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070026#include "pcie_i2c.hpp"
27#include "psu.hpp"
28
29#include <ipmid/api.h>
30
31#include <cstdint>
32#include <cstdio>
Willy Tuff3cd8e2021-09-14 22:49:55 -070033#include <ipmid/api-types.hpp>
34#include <ipmid/message.hpp>
35#include <optional>
Willy Tub4e37042021-10-12 17:12:30 -070036#include <span>
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070037
38namespace google
39{
40namespace ipmi
41{
42
Willy Tuff3cd8e2021-09-14 22:49:55 -070043Resp handleSysCommand(HandlerInterface* handler, ::ipmi::Context::ptr,
Willy Tub4e37042021-10-12 17:12:30 -070044 uint8_t cmd, std::span<const uint8_t> data)
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070045{
Willy Tuff3cd8e2021-09-14 22:49:55 -070046 switch (cmd)
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070047 {
48 case SysCableCheck:
Willy Tuff3cd8e2021-09-14 22:49:55 -070049 return cableCheck(data, handler);
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070050 case SysCpldVersion:
Willy Tuff3cd8e2021-09-14 22:49:55 -070051 return cpldVersion(data, handler);
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070052 case SysGetEthDevice:
Willy Tuff3cd8e2021-09-14 22:49:55 -070053 return getEthDevice(data, handler);
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070054 case SysPsuHardReset:
Willy Tuff3cd8e2021-09-14 22:49:55 -070055 return psuHardReset(data, handler);
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070056 case SysPcieSlotCount:
Willy Tuff3cd8e2021-09-14 22:49:55 -070057 return pcieSlotCount(data, handler);
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070058 case SysPcieSlotI2cBusMapping:
Willy Tuff3cd8e2021-09-14 22:49:55 -070059 return pcieSlotI2cBusMapping(data, handler);
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070060 case SysEntityName:
Willy Tuff3cd8e2021-09-14 22:49:55 -070061 return getEntityName(data, handler);
William A. Kennington III29f35bc2020-11-03 23:30:31 -080062 case SysMachineName:
Willy Tuff3cd8e2021-09-14 22:49:55 -070063 return getMachineName(data, handler);
Shounak Mitraac4a16f2021-02-02 11:11:44 -080064 case SysPsuHardResetOnShutdown:
Willy Tuff3cd8e2021-09-14 22:49:55 -070065 return psuHardResetOnShutdown(data, handler);
Willy Tu3b1b4272021-03-02 17:58:10 -080066 case SysGetFlashSize:
Willy Tuff3cd8e2021-09-14 22:49:55 -070067 return getFlashSize(data, handler);
linyuny8cfa4c42021-06-16 13:53:08 -070068 case SysHostPowerOff:
Willy Tuff3cd8e2021-09-14 22:49:55 -070069 return hostPowerOff(data, handler);
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070070 default:
Willy Tuff3cd8e2021-09-14 22:49:55 -070071 std::fprintf(stderr, "Invalid subcommand: 0x%x\n", cmd);
72 return ::ipmi::responseInvalidCommand();
Patrick Ventureeff1f2e2020-08-05 08:27:36 -070073 }
74}
75
76} // namespace ipmi
77} // namespace google