Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "chassishandler.hpp" |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 4 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 5 | #include <arpa/inet.h> |
| 6 | #include <endian.h> |
| 7 | #include <limits.h> |
| 8 | #include <mapper.h> |
| 9 | #include <netinet/in.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 10 | |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 11 | #include <array> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 12 | #include <chrono> |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 13 | #include <cstring> |
Vernon Mauery | bdda800 | 2019-02-26 10:18:51 -0800 | [diff] [blame] | 14 | #include <filesystem> |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 15 | #include <fstream> |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 16 | #include <future> |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 17 | #include <ipmid/api.hpp> |
Vernon Mauery | 3325024 | 2019-03-12 16:49:26 -0700 | [diff] [blame] | 18 | #include <ipmid/types.hpp> |
Vernon Mauery | 6a98fe7 | 2019-03-11 15:57:48 -0700 | [diff] [blame] | 19 | #include <ipmid/utils.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 20 | #include <map> |
| 21 | #include <phosphor-logging/elog-errors.hpp> |
| 22 | #include <phosphor-logging/log.hpp> |
| 23 | #include <sdbusplus/bus.hpp> |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 24 | #include <sdbusplus/message/types.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 25 | #include <sdbusplus/server/object.hpp> |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 26 | #include <sdbusplus/timer.hpp> |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame^] | 27 | #include <settings.hpp> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 28 | #include <sstream> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 29 | #include <string> |
| 30 | #include <xyz/openbmc_project/Common/error.hpp> |
| 31 | #include <xyz/openbmc_project/Control/Boot/Mode/server.hpp> |
| 32 | #include <xyz/openbmc_project/Control/Boot/Source/server.hpp> |
| 33 | #include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp> |
| 34 | #include <xyz/openbmc_project/State/Host/server.hpp> |
| 35 | #include <xyz/openbmc_project/State/PowerOnHours/server.hpp> |
| 36 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 37 | // Defines |
| 38 | #define SET_PARM_VERSION 0x01 |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 39 | #define SET_PARM_BOOT_FLAGS_PERMANENT 0x40 |
| 40 | #define SET_PARM_BOOT_FLAGS_VALID_ONE_TIME 0x80 |
| 41 | #define SET_PARM_BOOT_FLAGS_VALID_PERMANENT 0xC0 |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 42 | |
Lei YU | 4b0ddb6 | 2019-01-25 16:43:50 +0800 | [diff] [blame] | 43 | std::unique_ptr<phosphor::Timer> identifyTimer |
| 44 | __attribute__((init_priority(101))); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 45 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 46 | constexpr size_t SIZE_MAC = 18; |
| 47 | constexpr size_t SIZE_BOOT_OPTION = (uint8_t) |
| 48 | BootOptionResponseSize::OPAL_NETWORK_SETTINGS; // Maximum size of the boot |
| 49 | // option parametrs |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 50 | constexpr size_t SIZE_PREFIX = 7; |
| 51 | constexpr size_t MAX_PREFIX_VALUE = 32; |
| 52 | constexpr size_t SIZE_COOKIE = 4; |
| 53 | constexpr size_t SIZE_VERSION = 2; |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 54 | constexpr size_t DEFAULT_IDENTIFY_TIME_OUT = 15; |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 55 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 56 | // PetiBoot-Specific |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 57 | static constexpr uint8_t net_conf_initial_bytes[] = {0x80, 0x21, 0x70, 0x62, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 58 | 0x21, 0x00, 0x01, 0x06}; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 59 | |
| 60 | static constexpr size_t COOKIE_OFFSET = 1; |
| 61 | static constexpr size_t VERSION_OFFSET = 5; |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 62 | static constexpr size_t ADDR_SIZE_OFFSET = 8; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 63 | static constexpr size_t MAC_OFFSET = 9; |
| 64 | static constexpr size_t ADDRTYPE_OFFSET = 16; |
| 65 | static constexpr size_t IPADDR_OFFSET = 17; |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 66 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 67 | static constexpr size_t encIdentifyObjectsSize = 1; |
| 68 | static constexpr size_t chassisIdentifyReqLength = 2; |
| 69 | static constexpr size_t identifyIntervalPos = 0; |
| 70 | static constexpr size_t forceIdentifyPos = 1; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 71 | |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 72 | void register_netfn_chassis_functions() __attribute__((constructor)); |
| 73 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 74 | // Host settings in dbus |
| 75 | // Service name should be referenced by connection name got via object mapper |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 76 | const char* settings_object_name = "/org/openbmc/settings/host0"; |
| 77 | const char* settings_intf_name = "org.freedesktop.DBus.Properties"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 78 | const char* identify_led_object_name = |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 79 | "/xyz/openbmc_project/led/groups/enclosure_identify"; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 80 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 81 | constexpr auto SETTINGS_ROOT = "/"; |
| 82 | constexpr auto SETTINGS_MATCH = "host0"; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 83 | |
| 84 | constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP"; |
| 85 | constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress"; |
| 86 | |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 87 | static constexpr auto chassisStateRoot = "/xyz/openbmc_project/state"; |
| 88 | static constexpr auto chassisPOHStateIntf = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 89 | "xyz.openbmc_project.State.PowerOnHours"; |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 90 | static constexpr auto pOHCounterProperty = "POHCounter"; |
| 91 | static constexpr auto match = "chassis0"; |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 92 | const static constexpr char chassisCapIntf[] = |
| 93 | "xyz.openbmc_project.Control.ChassisCapabilities"; |
| 94 | const static constexpr char chassisCapFlagsProp[] = "CapabilitiesFlags"; |
| 95 | const static constexpr char chassisFRUDevAddrProp[] = "FRUDeviceAddress"; |
| 96 | const static constexpr char chassisSDRDevAddrProp[] = "SDRDeviceAddress"; |
| 97 | const static constexpr char chassisSELDevAddrProp[] = "SELDeviceAddress"; |
| 98 | const static constexpr char chassisSMDevAddrProp[] = "SMDeviceAddress"; |
| 99 | const static constexpr char chassisBridgeDevAddrProp[] = "BridgeDeviceAddress"; |
| 100 | static constexpr uint8_t chassisCapFlagMask = 0x0f; |
| 101 | static constexpr uint8_t chassisCapAddrMask = 0xfe; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 102 | |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 103 | typedef struct |
| 104 | { |
| 105 | uint8_t cap_flags; |
| 106 | uint8_t fru_info_dev_addr; |
| 107 | uint8_t sdr_dev_addr; |
| 108 | uint8_t sel_dev_addr; |
| 109 | uint8_t system_management_dev_addr; |
| 110 | uint8_t bridge_dev_addr; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 111 | } __attribute__((packed)) ipmi_chassis_cap_t; |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 112 | |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 113 | typedef struct |
| 114 | { |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 115 | uint8_t cur_power_state; |
| 116 | uint8_t last_power_event; |
| 117 | uint8_t misc_power_state; |
| 118 | uint8_t front_panel_button_cap_status; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 119 | } __attribute__((packed)) ipmi_get_chassis_status_t; |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 120 | |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 121 | // Phosphor Host State manager |
| 122 | namespace State = sdbusplus::xyz::openbmc_project::State::server; |
| 123 | |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 124 | namespace fs = std::filesystem; |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 125 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 126 | using namespace phosphor::logging; |
| 127 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 128 | using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server; |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 129 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 130 | namespace chassis |
| 131 | { |
| 132 | namespace internal |
| 133 | { |
| 134 | |
| 135 | constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode"; |
| 136 | constexpr auto bootSourceIntf = "xyz.openbmc_project.Control.Boot.Source"; |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 137 | constexpr auto powerRestoreIntf = |
| 138 | "xyz.openbmc_project.Control.Power.RestorePolicy"; |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 139 | sdbusplus::bus::bus dbus(ipmid_get_sd_bus_connection()); |
| 140 | |
| 141 | namespace cache |
| 142 | { |
| 143 | |
| 144 | settings::Objects objects(dbus, |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 145 | {bootModeIntf, bootSourceIntf, powerRestoreIntf}); |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 146 | |
| 147 | } // namespace cache |
| 148 | } // namespace internal |
| 149 | } // namespace chassis |
| 150 | |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 151 | namespace poh |
| 152 | { |
| 153 | |
| 154 | constexpr auto minutesPerCount = 60; |
| 155 | |
| 156 | } // namespace poh |
| 157 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 158 | struct get_sys_boot_options_t |
| 159 | { |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 160 | uint8_t parameter; |
| 161 | uint8_t set; |
| 162 | uint8_t block; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 163 | } __attribute__((packed)); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 164 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 165 | struct get_sys_boot_options_response_t |
| 166 | { |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 167 | uint8_t version; |
| 168 | uint8_t parm; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 169 | uint8_t data[SIZE_BOOT_OPTION]; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 170 | } __attribute__((packed)); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 171 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 172 | struct set_sys_boot_options_t |
| 173 | { |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 174 | uint8_t parameter; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 175 | uint8_t data[SIZE_BOOT_OPTION]; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 176 | } __attribute__((packed)); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 177 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 178 | int getHostNetworkData(get_sys_boot_options_response_t* respptr) |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 179 | { |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 180 | ipmi::PropertyMap properties; |
| 181 | int rc = 0; |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 182 | uint8_t addrSize = ipmi::network::IPV4_ADDRESS_SIZE_BYTE; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 183 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 184 | try |
| 185 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 186 | // TODO There may be cases where an interface is implemented by multiple |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 187 | // objects,to handle such cases we are interested on that object |
| 188 | // which are on interested busname. |
| 189 | // Currenlty mapper doesn't give the readable busname(gives busid) |
| 190 | // so we can't match with bus name so giving some object specific info |
| 191 | // as SETTINGS_MATCH. |
| 192 | // Later SETTINGS_MATCH will be replaced with busname. |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 193 | |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 194 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 195 | |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 196 | auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE, |
| 197 | SETTINGS_ROOT, SETTINGS_MATCH); |
| 198 | |
| 199 | auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE, |
| 200 | SETTINGS_ROOT, SETTINGS_MATCH); |
| 201 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 202 | properties = ipmi::getAllDbusProperties( |
| 203 | bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE); |
| 204 | auto variant = ipmi::getDbusProperty(bus, macObjectInfo.second, |
| 205 | macObjectInfo.first, MAC_INTERFACE, |
| 206 | "MACAddress"); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 207 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 208 | auto ipAddress = std::get<std::string>(properties["Address"]); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 209 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 210 | auto gateway = std::get<std::string>(properties["Gateway"]); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 211 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 212 | auto prefix = std::get<uint8_t>(properties["PrefixLength"]); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 213 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 214 | uint8_t isStatic = |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 215 | (std::get<std::string>(properties["Origin"]) == |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 216 | "xyz.openbmc_project.Network.IP.AddressOrigin.Static") |
| 217 | ? 1 |
| 218 | : 0; |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 219 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 220 | auto MACAddress = std::get<std::string>(variant); |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 221 | |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 222 | // it is expected here that we should get the valid data |
| 223 | // but we may also get the default values. |
| 224 | // Validation of the data is done by settings. |
| 225 | // |
| 226 | // if mac address is default mac address then |
| 227 | // don't send blank override. |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 228 | if ((MACAddress == ipmi::network::DEFAULT_MAC_ADDRESS)) |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 229 | { |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 230 | std::memset(respptr->data, 0, SIZE_BOOT_OPTION); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 231 | rc = -1; |
| 232 | return rc; |
| 233 | } |
| 234 | // if addr is static then ipaddress,gateway,prefix |
| 235 | // should not be default one,don't send blank override. |
| 236 | if (isStatic) |
| 237 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 238 | if ((ipAddress == ipmi::network::DEFAULT_ADDRESS) || |
| 239 | (gateway == ipmi::network::DEFAULT_ADDRESS) || (!prefix)) |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 240 | { |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 241 | std::memset(respptr->data, 0, SIZE_BOOT_OPTION); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 242 | rc = -1; |
| 243 | return rc; |
| 244 | } |
| 245 | } |
| 246 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 247 | sscanf( |
| 248 | MACAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT, |
| 249 | (respptr->data + MAC_OFFSET), (respptr->data + MAC_OFFSET + 1), |
| 250 | (respptr->data + MAC_OFFSET + 2), (respptr->data + MAC_OFFSET + 3), |
| 251 | (respptr->data + MAC_OFFSET + 4), (respptr->data + MAC_OFFSET + 5)); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 252 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 253 | respptr->data[MAC_OFFSET + 6] = 0x00; |
| 254 | |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 255 | std::memcpy(respptr->data + ADDRTYPE_OFFSET, &isStatic, |
| 256 | sizeof(isStatic)); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 257 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 258 | uint8_t addressFamily = (std::get<std::string>(properties["Type"]) == |
| 259 | "xyz.openbmc_project.Network.IP.Protocol.IPv4") |
| 260 | ? AF_INET |
| 261 | : AF_INET6; |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 262 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 263 | addrSize = (addressFamily == AF_INET) |
| 264 | ? ipmi::network::IPV4_ADDRESS_SIZE_BYTE |
| 265 | : ipmi::network::IPV6_ADDRESS_SIZE_BYTE; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 266 | |
| 267 | // ipaddress and gateway would be in IPv4 format |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 268 | inet_pton(addressFamily, ipAddress.c_str(), |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 269 | (respptr->data + IPADDR_OFFSET)); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 270 | |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 271 | uint8_t prefixOffset = IPADDR_OFFSET + addrSize; |
| 272 | |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 273 | std::memcpy(respptr->data + prefixOffset, &prefix, sizeof(prefix)); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 274 | |
| 275 | uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix)); |
| 276 | |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 277 | inet_pton(addressFamily, gateway.c_str(), |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 278 | (respptr->data + gatewayOffset)); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 279 | } |
| 280 | catch (InternalFailure& e) |
| 281 | { |
| 282 | commit<InternalFailure>(); |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 283 | std::memset(respptr->data, 0, SIZE_BOOT_OPTION); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 284 | rc = -1; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 285 | return rc; |
| 286 | } |
| 287 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 288 | // PetiBoot-Specific |
| 289 | // If success then copy the first 9 bytes to the data |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 290 | std::memcpy(respptr->data, net_conf_initial_bytes, |
| 291 | sizeof(net_conf_initial_bytes)); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 292 | |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 293 | std::memcpy(respptr->data + ADDR_SIZE_OFFSET, &addrSize, sizeof(addrSize)); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 294 | |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 295 | #ifdef _IPMI_DEBUG_ |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 296 | std::printf("\n===Printing the IPMI Formatted Data========\n"); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 297 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 298 | for (uint8_t pos = 0; pos < index; pos++) |
| 299 | { |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 300 | std::printf("%02x ", respptr->data[pos]); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 301 | } |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 302 | #endif |
| 303 | |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 304 | return rc; |
| 305 | } |
| 306 | |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 307 | /** @brief convert IPv4 and IPv6 addresses from binary to text form. |
| 308 | * @param[in] family - IPv4/Ipv6 |
| 309 | * @param[in] data - req data pointer. |
| 310 | * @param[in] offset - offset in the data. |
| 311 | * @param[in] addrSize - size of the data which needs to be read from offset. |
| 312 | * @returns address in text form. |
| 313 | */ |
| 314 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 315 | std::string getAddrStr(uint8_t family, uint8_t* data, uint8_t offset, |
| 316 | uint8_t addrSize) |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 317 | { |
| 318 | char ipAddr[INET6_ADDRSTRLEN] = {}; |
| 319 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 320 | switch (family) |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 321 | { |
| 322 | case AF_INET: |
| 323 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 324 | struct sockaddr_in addr4 |
| 325 | { |
| 326 | }; |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 327 | std::memcpy(&addr4.sin_addr.s_addr, &data[offset], addrSize); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 328 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 329 | inet_ntop(AF_INET, &addr4.sin_addr, ipAddr, INET_ADDRSTRLEN); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 330 | |
| 331 | break; |
| 332 | } |
| 333 | case AF_INET6: |
| 334 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 335 | struct sockaddr_in6 addr6 |
| 336 | { |
| 337 | }; |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 338 | std::memcpy(&addr6.sin6_addr.s6_addr, &data[offset], addrSize); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 339 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 340 | inet_ntop(AF_INET6, &addr6.sin6_addr, ipAddr, INET6_ADDRSTRLEN); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 341 | |
| 342 | break; |
| 343 | } |
| 344 | default: |
| 345 | { |
| 346 | return {}; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | return ipAddr; |
| 351 | } |
| 352 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 353 | int setHostNetworkData(set_sys_boot_options_t* reqptr) |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 354 | { |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 355 | using namespace std::string_literals; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 356 | std::string host_network_config; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 357 | char mac[]{"00:00:00:00:00:00"}; |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 358 | std::string ipAddress, gateway; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 359 | char addrOrigin{0}; |
| 360 | uint8_t addrSize{0}; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 361 | std::string addressOrigin = |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 362 | "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 363 | std::string addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv4"; |
| 364 | uint8_t prefix{0}; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 365 | uint32_t zeroCookie = 0; |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 366 | uint8_t family = AF_INET; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 367 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 368 | // cookie starts from second byte |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 369 | // version starts from sixth byte |
| 370 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 371 | try |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 372 | { |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 373 | do |
| 374 | { |
| 375 | // cookie == 0x21 0x70 0x62 0x21 |
| 376 | if (memcmp(&(reqptr->data[COOKIE_OFFSET]), |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 377 | (net_conf_initial_bytes + COOKIE_OFFSET), |
| 378 | SIZE_COOKIE) != 0) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 379 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 380 | // cookie == 0 |
| 381 | if (memcmp(&(reqptr->data[COOKIE_OFFSET]), &zeroCookie, |
| 382 | SIZE_COOKIE) == 0) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 383 | { |
| 384 | // need to zero out the network settings. |
| 385 | break; |
| 386 | } |
| 387 | |
| 388 | log<level::ERR>("Invalid Cookie"); |
| 389 | elog<InternalFailure>(); |
| 390 | } |
| 391 | |
| 392 | // vesion == 0x00 0x01 |
| 393 | if (memcmp(&(reqptr->data[VERSION_OFFSET]), |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 394 | (net_conf_initial_bytes + VERSION_OFFSET), |
| 395 | SIZE_VERSION) != 0) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 396 | { |
| 397 | |
| 398 | log<level::ERR>("Invalid Version"); |
| 399 | elog<InternalFailure>(); |
| 400 | } |
| 401 | |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 402 | std::snprintf( |
| 403 | mac, SIZE_MAC, ipmi::network::MAC_ADDRESS_FORMAT, |
| 404 | reqptr->data[MAC_OFFSET], reqptr->data[MAC_OFFSET + 1], |
| 405 | reqptr->data[MAC_OFFSET + 2], reqptr->data[MAC_OFFSET + 3], |
| 406 | reqptr->data[MAC_OFFSET + 4], reqptr->data[MAC_OFFSET + 5]); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 407 | |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 408 | std::memcpy(&addrOrigin, &(reqptr->data[ADDRTYPE_OFFSET]), |
| 409 | sizeof(decltype(addrOrigin))); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 410 | |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 411 | if (addrOrigin) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 412 | { |
| 413 | addressOrigin = |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 414 | "xyz.openbmc_project.Network.IP.AddressOrigin.Static"; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 415 | } |
| 416 | |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 417 | // Get the address size |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 418 | std::memcpy(&addrSize, &reqptr->data[ADDR_SIZE_OFFSET], |
| 419 | sizeof(addrSize)); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 420 | |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 421 | uint8_t prefixOffset = IPADDR_OFFSET + addrSize; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 422 | |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 423 | std::memcpy(&prefix, &(reqptr->data[prefixOffset]), |
| 424 | sizeof(decltype(prefix))); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 425 | |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 426 | uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix)); |
| 427 | |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 428 | if (addrSize != ipmi::network::IPV4_ADDRESS_SIZE_BYTE) |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 429 | { |
| 430 | addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv6"; |
| 431 | family = AF_INET6; |
| 432 | } |
| 433 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 434 | ipAddress = |
| 435 | getAddrStr(family, reqptr->data, IPADDR_OFFSET, addrSize); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 436 | |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 437 | gateway = getAddrStr(family, reqptr->data, gatewayOffset, addrSize); |
| 438 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 439 | } while (0); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 440 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 441 | // Cookie == 0 or it is a valid cookie |
| 442 | host_network_config += "ipaddress="s + ipAddress + ",prefix="s + |
| 443 | std::to_string(prefix) + ",gateway="s + gateway + |
| 444 | ",mac="s + mac + ",addressOrigin="s + |
| 445 | addressOrigin; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 446 | |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 447 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
| 448 | |
| 449 | auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE, |
| 450 | SETTINGS_ROOT, SETTINGS_MATCH); |
| 451 | auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE, |
| 452 | SETTINGS_ROOT, SETTINGS_MATCH); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 453 | // set the dbus property |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 454 | ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 455 | IP_INTERFACE, "Address", std::string(ipAddress)); |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 456 | ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 457 | IP_INTERFACE, "PrefixLength", prefix); |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 458 | ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 459 | IP_INTERFACE, "Origin", addressOrigin); |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 460 | ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 461 | IP_INTERFACE, "Gateway", std::string(gateway)); |
| 462 | ipmi::setDbusProperty( |
| 463 | bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE, "Type", |
| 464 | std::string("xyz.openbmc_project.Network.IP.Protocol.IPv4")); |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 465 | ipmi::setDbusProperty(bus, macObjectInfo.second, macObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 466 | MAC_INTERFACE, "MACAddress", std::string(mac)); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 467 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 468 | log<level::DEBUG>( |
| 469 | "Network configuration changed", |
| 470 | entry("NETWORKCONFIG=%s", host_network_config.c_str())); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 471 | } |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 472 | catch (InternalFailure& e) |
| 473 | { |
| 474 | commit<InternalFailure>(); |
| 475 | return -1; |
| 476 | } |
| 477 | |
| 478 | return 0; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 479 | } |
| 480 | |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 481 | uint32_t getPOHCounter() |
| 482 | { |
| 483 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 484 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 485 | auto chassisStateObj = |
| 486 | ipmi::getDbusObject(bus, chassisPOHStateIntf, chassisStateRoot, match); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 487 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 488 | auto service = |
| 489 | ipmi::getService(bus, chassisPOHStateIntf, chassisStateObj.first); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 490 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 491 | auto propValue = |
| 492 | ipmi::getDbusProperty(bus, service, chassisStateObj.first, |
| 493 | chassisPOHStateIntf, pOHCounterProperty); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 494 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 495 | return std::get<uint32_t>(propValue); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 496 | } |
| 497 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 498 | ipmi_ret_t ipmi_chassis_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 499 | ipmi_request_t request, |
| 500 | ipmi_response_t response, |
| 501 | ipmi_data_len_t data_len, |
| 502 | ipmi_context_t context) |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 503 | { |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 504 | // Status code. |
Nan Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 505 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 506 | *data_len = 0; |
| 507 | return rc; |
| 508 | } |
| 509 | |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 510 | ipmi_ret_t ipmi_get_chassis_cap(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 511 | ipmi_request_t request, |
| 512 | ipmi_response_t response, |
| 513 | ipmi_data_len_t data_len, |
| 514 | ipmi_context_t context) |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 515 | { |
| 516 | // sd_bus error |
| 517 | ipmi_ret_t rc = IPMI_CC_OK; |
| 518 | |
| 519 | ipmi_chassis_cap_t chassis_cap{}; |
| 520 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 521 | if (*data_len != 0) |
| 522 | { |
| 523 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 524 | } |
| 525 | |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 526 | *data_len = sizeof(ipmi_chassis_cap_t); |
| 527 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 528 | try |
| 529 | { |
| 530 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 531 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 532 | ipmi::DbusObjectInfo chassisCapObject = |
| 533 | ipmi::getDbusObject(bus, chassisCapIntf); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 534 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 535 | // capabilities flags |
| 536 | // [7..4] - reserved |
| 537 | // [3] – 1b = provides power interlock (IPM 1.5) |
| 538 | // [2] – 1b = provides Diagnostic Interrupt (FP NMI) |
| 539 | // [1] – 1b = provides “Front Panel Lockout” (indicates that the chassis |
| 540 | // has capabilities |
| 541 | // to lock out external power control and reset button or |
| 542 | // front panel interfaces and/or detect tampering with those |
| 543 | // interfaces). |
| 544 | // [0] -1b = Chassis provides intrusion (physical security) sensor. |
| 545 | // set to default value 0x0. |
| 546 | ipmi::Value variant = ipmi::getDbusProperty( |
| 547 | bus, chassisCapObject.second, chassisCapObject.first, |
| 548 | chassisCapIntf, chassisCapFlagsProp); |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 549 | chassis_cap.cap_flags = std::get<uint8_t>(variant); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 550 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 551 | variant = ipmi::getDbusProperty(bus, chassisCapObject.second, |
| 552 | chassisCapObject.first, chassisCapIntf, |
| 553 | chassisFRUDevAddrProp); |
| 554 | // Chassis FRU info Device Address. |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 555 | chassis_cap.fru_info_dev_addr = std::get<uint8_t>(variant); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 556 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 557 | variant = ipmi::getDbusProperty(bus, chassisCapObject.second, |
| 558 | chassisCapObject.first, chassisCapIntf, |
| 559 | chassisSDRDevAddrProp); |
| 560 | // Chassis SDR Device Address. |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 561 | chassis_cap.sdr_dev_addr = std::get<uint8_t>(variant); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 562 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 563 | variant = ipmi::getDbusProperty(bus, chassisCapObject.second, |
| 564 | chassisCapObject.first, chassisCapIntf, |
| 565 | chassisSELDevAddrProp); |
| 566 | // Chassis SEL Device Address. |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 567 | chassis_cap.sel_dev_addr = std::get<uint8_t>(variant); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 568 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 569 | variant = ipmi::getDbusProperty(bus, chassisCapObject.second, |
| 570 | chassisCapObject.first, chassisCapIntf, |
| 571 | chassisSMDevAddrProp); |
| 572 | // Chassis System Management Device Address. |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 573 | chassis_cap.system_management_dev_addr = std::get<uint8_t>(variant); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 574 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 575 | variant = ipmi::getDbusProperty(bus, chassisCapObject.second, |
| 576 | chassisCapObject.first, chassisCapIntf, |
| 577 | chassisBridgeDevAddrProp); |
| 578 | // Chassis Bridge Device Address. |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 579 | chassis_cap.bridge_dev_addr = std::get<uint8_t>(variant); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 580 | uint8_t* respP = reinterpret_cast<uint8_t*>(response); |
| 581 | uint8_t* chassisP = reinterpret_cast<uint8_t*>(&chassis_cap); |
| 582 | std::copy(chassisP, chassisP + *data_len, respP); |
| 583 | } |
| 584 | catch (std::exception& e) |
| 585 | { |
| 586 | log<level::ERR>(e.what()); |
| 587 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 588 | *data_len = 0; |
| 589 | return rc; |
| 590 | } |
| 591 | |
| 592 | return rc; |
| 593 | } |
| 594 | |
| 595 | ipmi_ret_t ipmi_set_chassis_cap(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 596 | ipmi_request_t request, |
| 597 | ipmi_response_t response, |
| 598 | ipmi_data_len_t data_len, |
| 599 | ipmi_context_t context) |
| 600 | { |
| 601 | ipmi_ret_t rc = IPMI_CC_OK; |
| 602 | |
| 603 | if (*data_len != sizeof(ipmi_chassis_cap_t)) |
| 604 | { |
| 605 | log<level::ERR>("Unsupported request length", |
| 606 | entry("LEN=0x%x", *data_len)); |
| 607 | *data_len = 0; |
| 608 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 609 | } |
| 610 | |
| 611 | ipmi_chassis_cap_t* chassisCap = static_cast<ipmi_chassis_cap_t*>(request); |
| 612 | |
| 613 | *data_len = 0; |
| 614 | |
| 615 | // check input data |
| 616 | if (0 != (chassisCap->cap_flags & ~chassisCapFlagMask)) |
| 617 | { |
| 618 | log<level::ERR>("Unsupported request parameter(CAP Flags)", |
| 619 | entry("REQ=0x%x", chassisCap->cap_flags)); |
| 620 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 621 | } |
| 622 | |
| 623 | if (0 != (chassisCap->fru_info_dev_addr & ~chassisCapAddrMask)) |
| 624 | { |
| 625 | log<level::ERR>("Unsupported request parameter(FRU Addr)", |
| 626 | entry("REQ=0x%x", chassisCap->fru_info_dev_addr)); |
| 627 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 628 | } |
| 629 | |
| 630 | if (0 != (chassisCap->sdr_dev_addr & ~chassisCapAddrMask)) |
| 631 | { |
| 632 | log<level::ERR>("Unsupported request parameter(SDR Addr)", |
| 633 | entry("REQ=0x%x", chassisCap->sdr_dev_addr)); |
| 634 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 635 | } |
| 636 | |
| 637 | if (0 != (chassisCap->sel_dev_addr & ~chassisCapAddrMask)) |
| 638 | { |
| 639 | log<level::ERR>("Unsupported request parameter(SEL Addr)", |
| 640 | entry("REQ=0x%x", chassisCap->sel_dev_addr)); |
| 641 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 642 | } |
| 643 | |
| 644 | if (0 != (chassisCap->system_management_dev_addr & ~chassisCapAddrMask)) |
| 645 | { |
| 646 | log<level::ERR>( |
| 647 | "Unsupported request parameter(SM Addr)", |
| 648 | entry("REQ=0x%x", chassisCap->system_management_dev_addr)); |
| 649 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 650 | } |
| 651 | |
| 652 | if (0 != (chassisCap->bridge_dev_addr & ~chassisCapAddrMask)) |
| 653 | { |
| 654 | log<level::ERR>("Unsupported request parameter(Bridge Addr)", |
| 655 | entry("REQ=0x%x", chassisCap->bridge_dev_addr)); |
| 656 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 657 | } |
| 658 | |
| 659 | try |
| 660 | { |
| 661 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
| 662 | ipmi::DbusObjectInfo chassisCapObject = |
| 663 | ipmi::getDbusObject(bus, chassisCapIntf); |
| 664 | |
| 665 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 666 | chassisCapObject.first, chassisCapIntf, |
| 667 | chassisCapFlagsProp, chassisCap->cap_flags); |
| 668 | |
| 669 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 670 | chassisCapObject.first, chassisCapIntf, |
| 671 | chassisFRUDevAddrProp, |
| 672 | chassisCap->fru_info_dev_addr); |
| 673 | |
| 674 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 675 | chassisCapObject.first, chassisCapIntf, |
| 676 | chassisSDRDevAddrProp, chassisCap->sdr_dev_addr); |
| 677 | |
| 678 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 679 | chassisCapObject.first, chassisCapIntf, |
| 680 | chassisSELDevAddrProp, chassisCap->sel_dev_addr); |
| 681 | |
| 682 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 683 | chassisCapObject.first, chassisCapIntf, |
| 684 | chassisSMDevAddrProp, |
| 685 | chassisCap->system_management_dev_addr); |
| 686 | |
| 687 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 688 | chassisCapObject.first, chassisCapIntf, |
| 689 | chassisBridgeDevAddrProp, |
| 690 | chassisCap->bridge_dev_addr); |
| 691 | } |
| 692 | catch (std::exception& e) |
| 693 | { |
| 694 | log<level::ERR>(e.what()); |
| 695 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 696 | return rc; |
| 697 | } |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 698 | |
| 699 | return rc; |
| 700 | } |
| 701 | |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 702 | //------------------------------------------ |
| 703 | // Calls into Host State Manager Dbus object |
| 704 | //------------------------------------------ |
| 705 | int initiate_state_transition(State::Host::Transition transition) |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 706 | { |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 707 | // OpenBMC Host State Manager dbus framework |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 708 | constexpr auto HOST_STATE_MANAGER_ROOT = "/xyz/openbmc_project/state/host0"; |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 709 | constexpr auto HOST_STATE_MANAGER_IFACE = "xyz.openbmc_project.State.Host"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 710 | constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties"; |
| 711 | constexpr auto PROPERTY = "RequestedHostTransition"; |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 712 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 713 | // sd_bus error |
| 714 | int rc = 0; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 715 | char* busname = NULL; |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 716 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 717 | // SD Bus error report mechanism. |
| 718 | sd_bus_error bus_error = SD_BUS_ERROR_NULL; |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 719 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 720 | // Gets a hook onto either a SYSTEM or SESSION bus |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 721 | sd_bus* bus_type = ipmid_get_sd_bus_connection(); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 722 | rc = mapper_get_service(bus_type, HOST_STATE_MANAGER_ROOT, &busname); |
| 723 | if (rc < 0) |
| 724 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 725 | log<level::ERR>( |
| 726 | "Failed to get bus name", |
| 727 | entry("ERRNO=0x%X, OBJPATH=%s", -rc, HOST_STATE_MANAGER_ROOT)); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 728 | return rc; |
| 729 | } |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 730 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 731 | // Convert to string equivalent of the passed in transition enum. |
| 732 | auto request = State::convertForMessage(transition); |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 733 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 734 | rc = sd_bus_call_method(bus_type, // On the system bus |
| 735 | busname, // Service to contact |
| 736 | HOST_STATE_MANAGER_ROOT, // Object path |
| 737 | DBUS_PROPERTY_IFACE, // Interface name |
| 738 | "Set", // Method to be called |
| 739 | &bus_error, // object to return error |
| 740 | nullptr, // Response buffer if any |
| 741 | "ssv", // Takes 3 arguments |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 742 | HOST_STATE_MANAGER_IFACE, PROPERTY, "s", |
| 743 | request.c_str()); |
| 744 | if (rc < 0) |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 745 | { |
| 746 | log<level::ERR>("Failed to initiate transition", |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 747 | entry("ERRNO=0x%X, REQUEST=%s", -rc, request.c_str())); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 748 | } |
| 749 | else |
| 750 | { |
| 751 | log<level::INFO>("Transition request initiated successfully"); |
| 752 | } |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 753 | |
| 754 | sd_bus_error_free(&bus_error); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 755 | free(busname); |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 756 | |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 757 | return rc; |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 758 | } |
| 759 | |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 760 | namespace power_policy |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 761 | { |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 762 | |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 763 | using namespace sdbusplus::xyz::openbmc_project::Control::Power::server; |
| 764 | using IpmiValue = uint8_t; |
| 765 | using DbusValue = RestorePolicy::Policy; |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 766 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 767 | std::map<DbusValue, IpmiValue> dbusToIpmi = { |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 768 | {RestorePolicy::Policy::AlwaysOff, 0x00}, |
| 769 | {RestorePolicy::Policy::Restore, 0x01}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 770 | {RestorePolicy::Policy::AlwaysOn, 0x02}}; |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 771 | |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 772 | static constexpr uint8_t noChange = 0x03; |
| 773 | static constexpr uint8_t allSupport = 0x01 | 0x02 | 0x04; |
| 774 | static constexpr uint8_t policyBitMask = 0x07; |
| 775 | static constexpr uint8_t setPolicyReqLen = 1; |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 776 | } // namespace power_policy |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 777 | |
| 778 | //---------------------------------------------------------------------- |
| 779 | // Get Chassis Status commands |
| 780 | //---------------------------------------------------------------------- |
| 781 | ipmi_ret_t ipmi_get_chassis_status(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 782 | ipmi_request_t request, |
| 783 | ipmi_response_t response, |
| 784 | ipmi_data_len_t data_len, |
| 785 | ipmi_context_t context) |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 786 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 787 | const char* objname = "/org/openbmc/control/power0"; |
| 788 | const char* intf = "org.openbmc.control.Power"; |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 789 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 790 | sd_bus* bus = NULL; |
| 791 | sd_bus_message* reply = NULL; |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 792 | int r = 0; |
| 793 | int pgood = 0; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 794 | char* busname = NULL; |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 795 | ipmi_ret_t rc = IPMI_CC_OK; |
| 796 | ipmi_get_chassis_status_t chassis_status{}; |
| 797 | |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 798 | uint8_t s = 0; |
| 799 | |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 800 | using namespace chassis::internal; |
| 801 | using namespace chassis::internal::cache; |
| 802 | using namespace power_policy; |
| 803 | |
Deepak Kodihalli | e602709 | 2017-08-27 08:13:37 -0500 | [diff] [blame] | 804 | const auto& powerRestoreSetting = objects.map.at(powerRestoreIntf).front(); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 805 | auto method = dbus.new_method_call( |
| 806 | objects.service(powerRestoreSetting, powerRestoreIntf).c_str(), |
| 807 | powerRestoreSetting.c_str(), ipmi::PROP_INTF, "Get"); |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 808 | method.append(powerRestoreIntf, "PowerRestorePolicy"); |
| 809 | auto resp = dbus.call(method); |
| 810 | if (resp.is_method_error()) |
| 811 | { |
| 812 | log<level::ERR>("Error in PowerRestorePolicy Get"); |
| 813 | report<InternalFailure>(); |
| 814 | *data_len = 0; |
| 815 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 816 | } |
| 817 | sdbusplus::message::variant<std::string> result; |
| 818 | resp.read(result); |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 819 | auto powerRestore = |
| 820 | RestorePolicy::convertPolicyFromString(std::get<std::string>(result)); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 821 | |
| 822 | *data_len = 4; |
| 823 | |
Tom Joseph | 63a0051 | 2017-08-09 23:39:59 +0530 | [diff] [blame] | 824 | bus = ipmid_get_sd_bus_connection(); |
| 825 | |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 826 | r = mapper_get_service(bus, objname, &busname); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 827 | if (r < 0) |
| 828 | { |
| 829 | log<level::ERR>("Failed to get bus name", entry("ERRNO=0x%X", -r)); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 830 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 831 | goto finish; |
| 832 | } |
| 833 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 834 | r = sd_bus_get_property(bus, busname, objname, intf, "pgood", NULL, &reply, |
| 835 | "i"); |
| 836 | if (r < 0) |
| 837 | { |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 838 | log<level::ERR>("Failed to call sd_bus_get_property", |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 839 | entry("PROPERTY=%s", "pgood"), entry("ERRNO=0x%X", -r), |
| 840 | entry("BUS=%s", busname), entry("PATH=%s", objname), |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 841 | entry("INTERFACE=%s", intf)); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 842 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 843 | goto finish; |
| 844 | } |
| 845 | |
| 846 | r = sd_bus_message_read(reply, "i", &pgood); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 847 | if (r < 0) |
| 848 | { |
| 849 | log<level::ERR>("Failed to read sensor:", entry("ERRNO=0x%X", -r)); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 850 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 851 | goto finish; |
| 852 | } |
| 853 | |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 854 | s = dbusToIpmi.at(powerRestore); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 855 | |
| 856 | // Current Power State |
| 857 | // [7] reserved |
| 858 | // [6..5] power restore policy |
| 859 | // 00b = chassis stays powered off after AC/mains returns |
| 860 | // 01b = after AC returns, power is restored to the state that was |
| 861 | // in effect when AC/mains was lost. |
| 862 | // 10b = chassis always powers up after AC/mains returns |
| 863 | // 11b = unknow |
| 864 | // Set to 00b, by observing the hardware behavior. |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 865 | // Do we need to define a dbus property to identify the restore |
| 866 | // policy? |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 867 | |
| 868 | // [4] power control fault |
| 869 | // 1b = controller attempted to turn system power on or off, but |
| 870 | // system did not enter desired state. |
| 871 | // Set to 0b, since We don't support it.. |
| 872 | |
| 873 | // [3] power fault |
| 874 | // 1b = fault detected in main power subsystem. |
| 875 | // set to 0b. for we don't support it. |
| 876 | |
| 877 | // [2] 1b = interlock (chassis is presently shut down because a chassis |
| 878 | // panel interlock switch is active). (IPMI 1.5) |
| 879 | // set to 0b, for we don't support it. |
| 880 | |
| 881 | // [1] power overload |
| 882 | // 1b = system shutdown because of power overload condition. |
| 883 | // set to 0b, for we don't support it. |
| 884 | |
| 885 | // [0] power is on |
| 886 | // 1b = system power is on |
| 887 | // 0b = system power is off(soft-off S4/S5, or mechanical off) |
| 888 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 889 | chassis_status.cur_power_state = ((s & 0x3) << 5) | (pgood & 0x1); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 890 | |
| 891 | // Last Power Event |
| 892 | // [7..5] – reserved |
| 893 | // [4] – 1b = last ‘Power is on’ state was entered via IPMI command |
| 894 | // [3] – 1b = last power down caused by power fault |
| 895 | // [2] – 1b = last power down caused by a power interlock being activated |
| 896 | // [1] – 1b = last power down caused by a Power overload |
| 897 | // [0] – 1b = AC failed |
| 898 | // set to 0x0, for we don't support these fields. |
| 899 | |
| 900 | chassis_status.last_power_event = 0; |
| 901 | |
| 902 | // Misc. Chassis State |
| 903 | // [7] – reserved |
| 904 | // [6] – 1b = Chassis Identify command and state info supported (Optional) |
| 905 | // 0b = Chassis Identify command support unspecified via this command. |
| 906 | // (The Get Command Support command , if implemented, would still |
| 907 | // indicate support for the Chassis Identify command) |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 908 | // [5..4] – Chassis Identify State. Mandatory when bit[6] =1b, reserved |
| 909 | // (return |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 910 | // as 00b) otherwise. Returns the present chassis identify state. |
| 911 | // Refer to the Chassis Identify command for more info. |
| 912 | // 00b = chassis identify state = Off |
| 913 | // 01b = chassis identify state = Temporary(timed) On |
| 914 | // 10b = chassis identify state = Indefinite On |
| 915 | // 11b = reserved |
| 916 | // [3] – 1b = Cooling/fan fault detected |
| 917 | // [2] – 1b = Drive Fault |
| 918 | // [1] – 1b = Front Panel Lockout active (power off and reset via chassis |
| 919 | // push-buttons disabled.) |
| 920 | // [0] – 1b = Chassis Intrusion active |
| 921 | // set to 0, for we don't support them. |
| 922 | chassis_status.misc_power_state = 0; |
| 923 | |
| 924 | // Front Panel Button Capabilities and disable/enable status(Optional) |
| 925 | // set to 0, for we don't support them. |
| 926 | chassis_status.front_panel_button_cap_status = 0; |
| 927 | |
| 928 | // Pack the actual response |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 929 | std::memcpy(response, &chassis_status, *data_len); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 930 | |
| 931 | finish: |
| 932 | free(busname); |
| 933 | reply = sd_bus_message_unref(reply); |
| 934 | |
| 935 | return rc; |
| 936 | } |
Chris Austen | 7888c4d | 2015-12-03 15:26:20 -0600 | [diff] [blame] | 937 | |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 938 | //------------------------------------------------------------- |
| 939 | // Send a command to SoftPowerOff application to stop any timer |
| 940 | //------------------------------------------------------------- |
| 941 | int stop_soft_off_timer() |
| 942 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 943 | constexpr auto iface = "org.freedesktop.DBus.Properties"; |
| 944 | constexpr auto soft_off_iface = "xyz.openbmc_project.Ipmi.Internal." |
| 945 | "SoftPowerOff"; |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 946 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 947 | constexpr auto property = "ResponseReceived"; |
| 948 | constexpr auto value = "xyz.openbmc_project.Ipmi.Internal." |
| 949 | "SoftPowerOff.HostResponse.HostShutdown"; |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 950 | |
| 951 | // Get the system bus where most system services are provided. |
| 952 | auto bus = ipmid_get_sd_bus_connection(); |
| 953 | |
| 954 | // Get the service name |
Andrew Geissler | 2b4e459 | 2017-06-08 11:18:35 -0500 | [diff] [blame] | 955 | // TODO openbmc/openbmc#1661 - Mapper refactor |
| 956 | // |
| 957 | // See openbmc/openbmc#1743 for some details but high level summary is that |
| 958 | // for now the code will directly call the soft off interface due to a |
| 959 | // race condition with mapper usage |
| 960 | // |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 961 | // char *busname = nullptr; |
| 962 | // auto r = mapper_get_service(bus, SOFTOFF_OBJPATH, &busname); |
| 963 | // if (r < 0) |
Andrew Geissler | 2b4e459 | 2017-06-08 11:18:35 -0500 | [diff] [blame] | 964 | //{ |
| 965 | // fprintf(stderr, "Failed to get %s bus name: %s\n", |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 966 | // SOFTOFF_OBJPATH, -r); |
Andrew Geissler | 2b4e459 | 2017-06-08 11:18:35 -0500 | [diff] [blame] | 967 | // return r; |
| 968 | //} |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 969 | |
| 970 | // No error object or reply expected. |
Andrew Geissler | 2b4e459 | 2017-06-08 11:18:35 -0500 | [diff] [blame] | 971 | int rc = sd_bus_call_method(bus, SOFTOFF_BUSNAME, SOFTOFF_OBJPATH, iface, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 972 | "Set", nullptr, nullptr, "ssv", soft_off_iface, |
| 973 | property, "s", value); |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 974 | if (rc < 0) |
| 975 | { |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 976 | log<level::ERR>("Failed to set property in SoftPowerOff object", |
| 977 | entry("ERRNO=0x%X", -rc)); |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 978 | } |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 979 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 980 | // TODO openbmc/openbmc#1661 - Mapper refactor |
| 981 | // free(busname); |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 982 | return rc; |
| 983 | } |
| 984 | |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 985 | //---------------------------------------------------------------------- |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 986 | // Create file to indicate there is no need for softoff notification to host |
| 987 | //---------------------------------------------------------------------- |
| 988 | void indicate_no_softoff_needed() |
| 989 | { |
| 990 | fs::path path{HOST_INBAND_REQUEST_DIR}; |
| 991 | if (!fs::is_directory(path)) |
| 992 | { |
| 993 | fs::create_directory(path); |
| 994 | } |
| 995 | |
| 996 | // Add the host instance (default 0 for now) to the file name |
| 997 | std::string file{HOST_INBAND_REQUEST_FILE}; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 998 | auto size = std::snprintf(nullptr, 0, file.c_str(), 0); |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 999 | size++; // null |
| 1000 | std::unique_ptr<char[]> buf(new char[size]); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1001 | std::snprintf(buf.get(), size, file.c_str(), 0); |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1002 | |
| 1003 | // Append file name to directory and create it |
| 1004 | path /= buf.get(); |
| 1005 | std::ofstream(path.c_str()); |
| 1006 | } |
| 1007 | |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1008 | /** @brief Implementation of chassis control command |
| 1009 | * |
| 1010 | * @param - chassisControl command byte |
| 1011 | * |
| 1012 | * @return Success or InvalidFieldRequest. |
| 1013 | */ |
| 1014 | ipmi::RspType<> ipmiChassisControl(uint8_t chassisControl) |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1015 | { |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1016 | int rc = 0; |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1017 | switch (chassisControl) |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1018 | { |
| 1019 | case CMD_POWER_ON: |
| 1020 | rc = initiate_state_transition(State::Host::Transition::On); |
| 1021 | break; |
| 1022 | case CMD_POWER_OFF: |
Vishwanatha Subbanna | 8b26d35 | 2017-08-04 18:35:18 +0530 | [diff] [blame] | 1023 | // This path would be hit in 2 conditions. |
| 1024 | // 1: When user asks for power off using ipmi chassis command 0x04 |
| 1025 | // 2: Host asking for power off post shutting down. |
| 1026 | |
| 1027 | // If it's a host requested power off, then need to nudge Softoff |
| 1028 | // application that it needs to stop the watchdog timer if running. |
| 1029 | // If it is a user requested power off, then this is not really |
| 1030 | // needed. But then we need to differentiate between user and host |
| 1031 | // calling this same command |
| 1032 | |
| 1033 | // For now, we are going ahead with trying to nudge the soft off and |
| 1034 | // interpret the failure to do so as a non softoff case |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1035 | rc = stop_soft_off_timer(); |
Vishwanatha Subbanna | 8b26d35 | 2017-08-04 18:35:18 +0530 | [diff] [blame] | 1036 | |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1037 | // Only request the Off transition if the soft power off |
| 1038 | // application is not running |
| 1039 | if (rc < 0) |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1040 | { |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1041 | // First create a file to indicate to the soft off application |
Vishwanatha Subbanna | 8b26d35 | 2017-08-04 18:35:18 +0530 | [diff] [blame] | 1042 | // that it should not run. Not doing this will result in State |
| 1043 | // manager doing a default soft power off when asked for power |
| 1044 | // off. |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1045 | indicate_no_softoff_needed(); |
| 1046 | |
| 1047 | // Now request the shutdown |
| 1048 | rc = initiate_state_transition(State::Host::Transition::Off); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1049 | } |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1050 | else |
| 1051 | { |
Vishwanatha Subbanna | 8b26d35 | 2017-08-04 18:35:18 +0530 | [diff] [blame] | 1052 | log<level::INFO>("Soft off is running, so let shutdown target " |
| 1053 | "stop the host"); |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1054 | } |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1055 | break; |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 1056 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1057 | case CMD_HARD_RESET: |
| 1058 | case CMD_POWER_CYCLE: |
| 1059 | // SPEC has a section that says certain implementations can trigger |
| 1060 | // PowerOn if power is Off when a command to power cycle is |
| 1061 | // requested |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1062 | |
| 1063 | // First create a file to indicate to the soft off application |
| 1064 | // that it should not run since this is a direct user initiated |
| 1065 | // power reboot request (i.e. a reboot request that is not |
| 1066 | // originating via a soft power off SMS request) |
| 1067 | indicate_no_softoff_needed(); |
| 1068 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1069 | rc = initiate_state_transition(State::Host::Transition::Reboot); |
| 1070 | break; |
Vishwanatha Subbanna | 8b26d35 | 2017-08-04 18:35:18 +0530 | [diff] [blame] | 1071 | |
| 1072 | case CMD_SOFT_OFF_VIA_OVER_TEMP: |
| 1073 | // Request Host State Manager to do a soft power off |
| 1074 | rc = initiate_state_transition(State::Host::Transition::Off); |
| 1075 | break; |
| 1076 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1077 | default: |
| 1078 | { |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 1079 | log<level::ERR>("Invalid Chassis Control command", |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1080 | entry("CMD=0x%X", chassisControl)); |
| 1081 | return ipmi::responseInvalidFieldRequest(); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1082 | } |
| 1083 | } |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1084 | |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1085 | return ((rc < 0) ? ipmi::responseUnspecifiedError() |
| 1086 | : ipmi::responseSuccess()); |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1087 | } |
| 1088 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1089 | /** @brief Return D-Bus connection string to enclosure identify LED object |
| 1090 | * |
| 1091 | * @param[in, out] connection - connection to D-Bus object |
| 1092 | * @return a IPMI return code |
| 1093 | */ |
| 1094 | std::string getEnclosureIdentifyConnection() |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1095 | { |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1096 | // lookup enclosure_identify group owner(s) in mapper |
| 1097 | auto mapperCall = chassis::internal::dbus.new_method_call( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1098 | ipmi::MAPPER_BUS_NAME, ipmi::MAPPER_OBJ, ipmi::MAPPER_INTF, |
| 1099 | "GetObject"); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1100 | |
| 1101 | mapperCall.append(identify_led_object_name); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1102 | static const std::vector<std::string> interfaces = { |
| 1103 | "xyz.openbmc_project.Led.Group"}; |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1104 | mapperCall.append(interfaces); |
| 1105 | auto mapperReply = chassis::internal::dbus.call(mapperCall); |
| 1106 | if (mapperReply.is_method_error()) |
| 1107 | { |
| 1108 | log<level::ERR>("Chassis Identify: Error communicating to mapper."); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1109 | elog<InternalFailure>(); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1110 | } |
| 1111 | std::vector<std::pair<std::string, std::vector<std::string>>> mapperResp; |
| 1112 | mapperReply.read(mapperResp); |
| 1113 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1114 | if (mapperResp.size() != encIdentifyObjectsSize) |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1115 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1116 | log<level::ERR>( |
| 1117 | "Invalid number of enclosure identify objects.", |
| 1118 | entry("ENC_IDENTITY_OBJECTS_SIZE=%d", mapperResp.size())); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1119 | elog<InternalFailure>(); |
| 1120 | } |
| 1121 | auto pair = mapperResp[encIdentifyObjectsSize - 1]; |
| 1122 | return pair.first; |
| 1123 | } |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1124 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1125 | /** @brief Turn On/Off enclosure identify LED |
| 1126 | * |
| 1127 | * @param[in] flag - true to turn on LED, false to turn off |
| 1128 | * @return a IPMI return code |
| 1129 | */ |
| 1130 | void enclosureIdentifyLed(bool flag) |
| 1131 | { |
| 1132 | using namespace chassis::internal; |
| 1133 | std::string connection = std::move(getEnclosureIdentifyConnection()); |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1134 | auto msg = std::string("enclosureIdentifyLed(") + |
| 1135 | boost::lexical_cast<std::string>(flag) + ")"; |
| 1136 | log<level::DEBUG>(msg.c_str()); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1137 | auto led = |
| 1138 | dbus.new_method_call(connection.c_str(), identify_led_object_name, |
| 1139 | "org.freedesktop.DBus.Properties", "Set"); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1140 | led.append("xyz.openbmc_project.Led.Group", "Asserted", |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 1141 | std::variant<bool>(flag)); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1142 | auto ledReply = dbus.call(led); |
| 1143 | if (ledReply.is_method_error()) |
| 1144 | { |
| 1145 | log<level::ERR>("Chassis Identify: Error Setting State On/Off\n", |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1146 | entry("LED_STATE=%d", flag)); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1147 | elog<InternalFailure>(); |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | /** @brief Callback method to turn off LED |
| 1152 | */ |
| 1153 | void enclosureIdentifyLedOff() |
| 1154 | { |
| 1155 | try |
| 1156 | { |
| 1157 | enclosureIdentifyLed(false); |
| 1158 | } |
| 1159 | catch (const InternalFailure& e) |
| 1160 | { |
| 1161 | report<InternalFailure>(); |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | /** @brief Create timer to turn on and off the enclosure LED |
| 1166 | */ |
| 1167 | void createIdentifyTimer() |
| 1168 | { |
| 1169 | if (!identifyTimer) |
| 1170 | { |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1171 | identifyTimer = |
| 1172 | std::make_unique<phosphor::Timer>(enclosureIdentifyLedOff); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1173 | } |
| 1174 | } |
| 1175 | |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1176 | ipmi::RspType<> ipmiChassisIdentify(std::optional<uint8_t> interval, |
| 1177 | std::optional<uint8_t> force) |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1178 | { |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1179 | uint8_t identifyInterval = interval.value_or(DEFAULT_IDENTIFY_TIME_OUT); |
| 1180 | bool forceIdentify = force.value_or(0) & 0x01; |
Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1181 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1182 | if (identifyInterval || forceIdentify) |
| 1183 | { |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1184 | // stop the timer if already started; |
| 1185 | // for force identify we should not turn off LED |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1186 | identifyTimer->stop(); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1187 | try |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1188 | { |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1189 | enclosureIdentifyLed(true); |
| 1190 | } |
| 1191 | catch (const InternalFailure& e) |
| 1192 | { |
| 1193 | report<InternalFailure>(); |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1194 | return ipmi::responseResponseError(); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1195 | } |
| 1196 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1197 | if (forceIdentify) |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1198 | { |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1199 | return ipmi::responseSuccess(); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1200 | } |
| 1201 | // start the timer |
| 1202 | auto time = std::chrono::duration_cast<std::chrono::microseconds>( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1203 | std::chrono::seconds(identifyInterval)); |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1204 | identifyTimer->start(time); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1205 | } |
Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1206 | else if (!identifyInterval) |
| 1207 | { |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1208 | identifyTimer->stop(); |
Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1209 | enclosureIdentifyLedOff(); |
| 1210 | } |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1211 | return ipmi::responseSuccess(); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1212 | } |
| 1213 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1214 | namespace boot_options |
| 1215 | { |
| 1216 | |
| 1217 | using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server; |
| 1218 | using IpmiValue = uint8_t; |
| 1219 | constexpr auto ipmiDefault = 0; |
| 1220 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1221 | std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1222 | {0x01, Source::Sources::Network}, |
| 1223 | {0x02, Source::Sources::Disk}, |
| 1224 | {0x05, Source::Sources::ExternalMedia}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1225 | {ipmiDefault, Source::Sources::Default}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1226 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1227 | std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1228 | {0x03, Mode::Modes::Safe}, |
| 1229 | {0x06, Mode::Modes::Setup}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1230 | {ipmiDefault, Mode::Modes::Regular}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1231 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1232 | std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1233 | {Source::Sources::Network, 0x01}, |
| 1234 | {Source::Sources::Disk, 0x02}, |
| 1235 | {Source::Sources::ExternalMedia, 0x05}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1236 | {Source::Sources::Default, ipmiDefault}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1237 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1238 | std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1239 | {Mode::Modes::Safe, 0x03}, |
| 1240 | {Mode::Modes::Setup, 0x06}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1241 | {Mode::Modes::Regular, ipmiDefault}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1242 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1243 | } // namespace boot_options |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1244 | |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1245 | /** @brief Set the property value for boot source |
| 1246 | * @param[in] source - boot source value |
| 1247 | * @return On failure return IPMI error. |
| 1248 | */ |
| 1249 | static ipmi_ret_t setBootSource(const Source::Sources& source) |
| 1250 | { |
| 1251 | using namespace chassis::internal; |
| 1252 | using namespace chassis::internal::cache; |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 1253 | std::variant<std::string> property = convertForMessage(source); |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1254 | auto bootSetting = settings::boot::setting(objects, bootSourceIntf); |
| 1255 | const auto& bootSourceSetting = std::get<settings::Path>(bootSetting); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1256 | auto method = dbus.new_method_call( |
| 1257 | objects.service(bootSourceSetting, bootSourceIntf).c_str(), |
| 1258 | bootSourceSetting.c_str(), ipmi::PROP_INTF, "Set"); |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1259 | method.append(bootSourceIntf, "BootSource", property); |
| 1260 | auto reply = dbus.call(method); |
| 1261 | if (reply.is_method_error()) |
| 1262 | { |
| 1263 | log<level::ERR>("Error in BootSource Set"); |
| 1264 | report<InternalFailure>(); |
| 1265 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1266 | } |
| 1267 | return IPMI_CC_OK; |
| 1268 | } |
| 1269 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1270 | /** @brief Set the property value for boot mode |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1271 | * @param[in] mode - boot mode value |
| 1272 | * @return On failure return IPMI error. |
| 1273 | */ |
| 1274 | static ipmi_ret_t setBootMode(const Mode::Modes& mode) |
| 1275 | { |
| 1276 | using namespace chassis::internal; |
| 1277 | using namespace chassis::internal::cache; |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 1278 | std::variant<std::string> property = convertForMessage(mode); |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1279 | auto bootSetting = settings::boot::setting(objects, bootModeIntf); |
| 1280 | const auto& bootModeSetting = std::get<settings::Path>(bootSetting); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1281 | auto method = dbus.new_method_call( |
| 1282 | objects.service(bootModeSetting, bootModeIntf).c_str(), |
| 1283 | bootModeSetting.c_str(), ipmi::PROP_INTF, "Set"); |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1284 | method.append(bootModeIntf, "BootMode", property); |
| 1285 | auto reply = dbus.call(method); |
| 1286 | if (reply.is_method_error()) |
| 1287 | { |
| 1288 | log<level::ERR>("Error in BootMode Set"); |
| 1289 | report<InternalFailure>(); |
| 1290 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1291 | } |
| 1292 | return IPMI_CC_OK; |
| 1293 | } |
| 1294 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1295 | ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 1296 | ipmi_request_t request, |
| 1297 | ipmi_response_t response, |
| 1298 | ipmi_data_len_t data_len, |
| 1299 | ipmi_context_t context) |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1300 | { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1301 | using namespace boot_options; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1302 | ipmi_ret_t rc = IPMI_CC_PARM_NOT_SUPPORTED; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1303 | char* p = NULL; |
| 1304 | get_sys_boot_options_response_t* resp = |
| 1305 | (get_sys_boot_options_response_t*)response; |
| 1306 | get_sys_boot_options_t* reqptr = (get_sys_boot_options_t*)request; |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1307 | IpmiValue bootOption = ipmiDefault; |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1308 | |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 1309 | std::memset(resp, 0, sizeof(*resp)); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1310 | resp->version = SET_PARM_VERSION; |
| 1311 | resp->parm = 5; |
| 1312 | resp->data[0] = SET_PARM_BOOT_FLAGS_VALID_ONE_TIME; |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1313 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1314 | /* |
| 1315 | * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc. |
| 1316 | * This is the only parameter used by petitboot. |
| 1317 | */ |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1318 | if (reqptr->parameter == |
| 1319 | static_cast<uint8_t>(BootOptionParameter::BOOT_FLAGS)) |
| 1320 | { |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1321 | |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 1322 | *data_len = static_cast<uint8_t>(BootOptionResponseSize::BOOT_FLAGS); |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1323 | using namespace chassis::internal; |
| 1324 | using namespace chassis::internal::cache; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1325 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1326 | try |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1327 | { |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1328 | auto bootSetting = settings::boot::setting(objects, bootSourceIntf); |
| 1329 | const auto& bootSourceSetting = |
| 1330 | std::get<settings::Path>(bootSetting); |
| 1331 | auto oneTimeEnabled = |
| 1332 | std::get<settings::boot::OneTimeEnabled>(bootSetting); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1333 | auto method = dbus.new_method_call( |
| 1334 | objects.service(bootSourceSetting, bootSourceIntf).c_str(), |
| 1335 | bootSourceSetting.c_str(), ipmi::PROP_INTF, "Get"); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1336 | method.append(bootSourceIntf, "BootSource"); |
| 1337 | auto reply = dbus.call(method); |
| 1338 | if (reply.is_method_error()) |
| 1339 | { |
| 1340 | log<level::ERR>("Error in BootSource Get"); |
| 1341 | report<InternalFailure>(); |
| 1342 | *data_len = 0; |
| 1343 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1344 | } |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 1345 | std::variant<std::string> result; |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1346 | reply.read(result); |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 1347 | auto bootSource = |
| 1348 | Source::convertSourcesFromString(std::get<std::string>(result)); |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1349 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1350 | bootSetting = settings::boot::setting(objects, bootModeIntf); |
| 1351 | const auto& bootModeSetting = std::get<settings::Path>(bootSetting); |
| 1352 | method = dbus.new_method_call( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1353 | objects.service(bootModeSetting, bootModeIntf).c_str(), |
| 1354 | bootModeSetting.c_str(), ipmi::PROP_INTF, "Get"); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1355 | method.append(bootModeIntf, "BootMode"); |
| 1356 | reply = dbus.call(method); |
| 1357 | if (reply.is_method_error()) |
| 1358 | { |
| 1359 | log<level::ERR>("Error in BootMode Get"); |
| 1360 | report<InternalFailure>(); |
| 1361 | *data_len = 0; |
| 1362 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1363 | } |
| 1364 | reply.read(result); |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 1365 | auto bootMode = |
| 1366 | Mode::convertModesFromString(std::get<std::string>(result)); |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1367 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1368 | bootOption = sourceDbusToIpmi.at(bootSource); |
| 1369 | if ((Mode::Modes::Regular == bootMode) && |
| 1370 | (Source::Sources::Default == bootSource)) |
| 1371 | { |
| 1372 | bootOption = ipmiDefault; |
| 1373 | } |
| 1374 | else if (Source::Sources::Default == bootSource) |
| 1375 | { |
| 1376 | bootOption = modeDbusToIpmi.at(bootMode); |
| 1377 | } |
| 1378 | resp->data[1] = (bootOption << 2); |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1379 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1380 | resp->data[0] = oneTimeEnabled |
| 1381 | ? SET_PARM_BOOT_FLAGS_VALID_ONE_TIME |
| 1382 | : SET_PARM_BOOT_FLAGS_VALID_PERMANENT; |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1383 | |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1384 | rc = IPMI_CC_OK; |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1385 | } |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1386 | catch (InternalFailure& e) |
| 1387 | { |
| 1388 | report<InternalFailure>(); |
| 1389 | *data_len = 0; |
| 1390 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1391 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1392 | } |
| 1393 | else if (reqptr->parameter == |
| 1394 | static_cast<uint8_t>(BootOptionParameter::OPAL_NETWORK_SETTINGS)) |
| 1395 | { |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 1396 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1397 | *data_len = |
| 1398 | static_cast<uint8_t>(BootOptionResponseSize::OPAL_NETWORK_SETTINGS); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 1399 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1400 | resp->parm = |
| 1401 | static_cast<uint8_t>(BootOptionParameter::OPAL_NETWORK_SETTINGS); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 1402 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1403 | int ret = getHostNetworkData(resp); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 1404 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1405 | if (ret < 0) |
| 1406 | { |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 1407 | |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 1408 | log<level::ERR>( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1409 | "getHostNetworkData failed for get_sys_boot_options."); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1410 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1411 | } |
| 1412 | else |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1413 | rc = IPMI_CC_OK; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 1414 | } |
| 1415 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1416 | else |
| 1417 | { |
| 1418 | log<level::ERR>("Unsupported parameter", |
| 1419 | entry("PARAM=0x%x", reqptr->parameter)); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | if (p) |
| 1423 | free(p); |
| 1424 | |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 1425 | if (rc == IPMI_CC_OK) |
| 1426 | { |
| 1427 | *data_len += 2; |
| 1428 | } |
| 1429 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1430 | return rc; |
| 1431 | } |
| 1432 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1433 | ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1434 | ipmi_request_t request, |
| 1435 | ipmi_response_t response, |
| 1436 | ipmi_data_len_t data_len, |
| 1437 | ipmi_context_t context) |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1438 | { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1439 | using namespace boot_options; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1440 | ipmi_ret_t rc = IPMI_CC_OK; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1441 | set_sys_boot_options_t* reqptr = (set_sys_boot_options_t*)request; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1442 | |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 1443 | std::printf("IPMI SET_SYS_BOOT_OPTIONS reqptr->parameter =[%d]\n", |
| 1444 | reqptr->parameter); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 1445 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1446 | // This IPMI command does not have any resposne data |
| 1447 | *data_len = 0; |
| 1448 | |
| 1449 | /* 000101 |
| 1450 | * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc. |
| 1451 | * This is the only parameter used by petitboot. |
| 1452 | */ |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 1453 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1454 | if (reqptr->parameter == (uint8_t)BootOptionParameter::BOOT_FLAGS) |
| 1455 | { |
| 1456 | IpmiValue bootOption = ((reqptr->data[1] & 0x3C) >> 2); |
| 1457 | using namespace chassis::internal; |
| 1458 | using namespace chassis::internal::cache; |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1459 | auto oneTimeEnabled = false; |
| 1460 | constexpr auto enabledIntf = "xyz.openbmc_project.Object.Enable"; |
Tom Joseph | 57e8eb7 | 2017-09-25 18:05:02 +0530 | [diff] [blame] | 1461 | constexpr auto oneTimePath = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1462 | "/xyz/openbmc_project/control/host0/boot/one_time"; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1463 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1464 | try |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1465 | { |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1466 | bool permanent = |
| 1467 | (reqptr->data[0] & SET_PARM_BOOT_FLAGS_PERMANENT) == |
| 1468 | SET_PARM_BOOT_FLAGS_PERMANENT; |
| 1469 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1470 | auto bootSetting = settings::boot::setting(objects, bootSourceIntf); |
Tom Joseph | 57e8eb7 | 2017-09-25 18:05:02 +0530 | [diff] [blame] | 1471 | |
| 1472 | oneTimeEnabled = |
| 1473 | std::get<settings::boot::OneTimeEnabled>(bootSetting); |
| 1474 | |
| 1475 | /* |
| 1476 | * Check if the current boot setting is onetime or permanent, if the |
| 1477 | * request in the command is otherwise, then set the "Enabled" |
| 1478 | * property in one_time object path to 'True' to indicate onetime |
| 1479 | * and 'False' to indicate permanent. |
| 1480 | * |
| 1481 | * Once the onetime/permanent setting is applied, then the bootMode |
| 1482 | * and bootSource is updated for the corresponding object. |
| 1483 | */ |
| 1484 | if ((permanent && oneTimeEnabled) || |
| 1485 | (!permanent && !oneTimeEnabled)) |
| 1486 | { |
| 1487 | auto service = ipmi::getService(dbus, enabledIntf, oneTimePath); |
| 1488 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1489 | ipmi::setDbusProperty(dbus, service, oneTimePath, enabledIntf, |
| 1490 | "Enabled", !permanent); |
Tom Joseph | 57e8eb7 | 2017-09-25 18:05:02 +0530 | [diff] [blame] | 1491 | } |
| 1492 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1493 | auto modeItr = modeIpmiToDbus.find(bootOption); |
| 1494 | auto sourceItr = sourceIpmiToDbus.find(bootOption); |
| 1495 | if (sourceIpmiToDbus.end() != sourceItr) |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1496 | { |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1497 | rc = setBootSource(sourceItr->second); |
| 1498 | if (rc != IPMI_CC_OK) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1499 | { |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1500 | *data_len = 0; |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1501 | return rc; |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1502 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 1503 | // If a set boot device is mapping to a boot source, then reset |
| 1504 | // the boot mode D-Bus property to default. |
| 1505 | // This way the ipmid code can determine which property is not |
| 1506 | // at the default value |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1507 | if (sourceItr->second != Source::Sources::Default) |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 1508 | { |
| 1509 | setBootMode(Mode::Modes::Regular); |
| 1510 | } |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1511 | } |
| 1512 | if (modeIpmiToDbus.end() != modeItr) |
| 1513 | { |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1514 | rc = setBootMode(modeItr->second); |
| 1515 | if (rc != IPMI_CC_OK) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1516 | { |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1517 | *data_len = 0; |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1518 | return rc; |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1519 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 1520 | // If a set boot device is mapping to a boot mode, then reset |
| 1521 | // the boot source D-Bus property to default. |
| 1522 | // This way the ipmid code can determine which property is not |
| 1523 | // at the default value |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1524 | if (modeItr->second != Mode::Modes::Regular) |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 1525 | { |
| 1526 | setBootSource(Source::Sources::Default); |
| 1527 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1528 | } |
| 1529 | } |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1530 | catch (InternalFailure& e) |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1531 | { |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1532 | report<InternalFailure>(); |
| 1533 | *data_len = 0; |
| 1534 | return IPMI_CC_UNSPECIFIED_ERROR; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1535 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1536 | } |
| 1537 | else if (reqptr->parameter == |
| 1538 | (uint8_t)BootOptionParameter::OPAL_NETWORK_SETTINGS) |
| 1539 | { |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 1540 | |
| 1541 | int ret = setHostNetworkData(reqptr); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1542 | if (ret < 0) |
| 1543 | { |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 1544 | log<level::ERR>( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1545 | "setHostNetworkData failed for set_sys_boot_options"); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 1546 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 1547 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1548 | } |
| 1549 | else if (reqptr->parameter == |
| 1550 | static_cast<uint8_t>(BootOptionParameter::BOOT_INFO)) |
| 1551 | { |
Tom Joseph | f536c90 | 2017-09-25 18:08:15 +0530 | [diff] [blame] | 1552 | // Handle parameter #4 and return command completed normally |
| 1553 | // (IPMI_CC_OK). There is no implementation in OpenBMC for this |
| 1554 | // parameter. This is added to support the ipmitool command `chassis |
| 1555 | // bootdev` which sends set on parameter #4, before setting the boot |
| 1556 | // flags. |
| 1557 | rc = IPMI_CC_OK; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1558 | } |
| 1559 | else |
| 1560 | { |
| 1561 | log<level::ERR>("Unsupported parameter", |
| 1562 | entry("PARAM=0x%x", reqptr->parameter)); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1563 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | return rc; |
| 1567 | } |
| 1568 | |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 1569 | /** @brief implements Get POH counter command |
| 1570 | * @parameter |
| 1571 | * - none |
| 1572 | * @returns IPMI completion code plus response data |
| 1573 | * - minPerCount - Minutes per count |
| 1574 | * - counterReading - counter reading |
| 1575 | */ |
| 1576 | ipmi::RspType<uint8_t, // Minutes per count |
| 1577 | uint32_t // Counter reading |
| 1578 | > |
| 1579 | ipmiGetPOHCounter() |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 1580 | { |
| 1581 | // sd_bus error |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 1582 | try |
| 1583 | { |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 1584 | return ipmi::responseSuccess(static_cast<uint8_t>(poh::minutesPerCount), |
| 1585 | getPOHCounter()); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 1586 | } |
| 1587 | catch (std::exception& e) |
| 1588 | { |
| 1589 | log<level::ERR>(e.what()); |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 1590 | return ipmi::responseUnspecifiedError(); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 1591 | } |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 1592 | } |
| 1593 | |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame^] | 1594 | ipmi::RspType<uint8_t> |
| 1595 | ipmiChassisSetPowerRestorePolicy(boost::asio::yield_context yield, |
| 1596 | uint8_t policy) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 1597 | { |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame^] | 1598 | constexpr uint8_t ccParamNotSupported = 0x80; |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 1599 | power_policy::DbusValue value = |
| 1600 | power_policy::RestorePolicy::Policy::AlwaysOff; |
| 1601 | |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame^] | 1602 | if (policy & ~power_policy::policyBitMask) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 1603 | { |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame^] | 1604 | phosphor::logging::log<level::ERR>( |
| 1605 | "Reserved request parameter", |
| 1606 | entry("REQ=0x%x", static_cast<int>(policy))); |
| 1607 | return ipmi::response(ccParamNotSupported); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 1608 | } |
| 1609 | |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame^] | 1610 | if (policy == power_policy::noChange) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 1611 | { |
| 1612 | // just return the supported policy |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame^] | 1613 | return ipmi::responseSuccess(power_policy::allSupport); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | for (auto const& it : power_policy::dbusToIpmi) |
| 1617 | { |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame^] | 1618 | if (it.second == policy) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 1619 | { |
| 1620 | value = it.first; |
| 1621 | break; |
| 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | try |
| 1626 | { |
| 1627 | const settings::Path& powerRestoreSetting = |
| 1628 | chassis::internal::cache::objects.map |
| 1629 | .at(chassis::internal::powerRestoreIntf) |
| 1630 | .front(); |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 1631 | std::variant<std::string> property = convertForMessage(value); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 1632 | |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame^] | 1633 | auto sdbusp = getSdBus(); |
| 1634 | boost::system::error_code ec; |
| 1635 | sdbusp->yield_method_call<void>( |
| 1636 | yield, ec, |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 1637 | chassis::internal::cache::objects |
| 1638 | .service(powerRestoreSetting, |
| 1639 | chassis::internal::powerRestoreIntf) |
| 1640 | .c_str(), |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame^] | 1641 | powerRestoreSetting, ipmi::PROP_INTF, "Set", |
| 1642 | chassis::internal::powerRestoreIntf, "PowerRestorePolicy", |
| 1643 | property); |
| 1644 | if (ec) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 1645 | { |
| 1646 | phosphor::logging::log<level::ERR>("Unspecified Error"); |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame^] | 1647 | return ipmi::responseUnspecifiedError(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 1648 | } |
| 1649 | } |
| 1650 | catch (InternalFailure& e) |
| 1651 | { |
| 1652 | report<InternalFailure>(); |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame^] | 1653 | return ipmi::responseUnspecifiedError(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 1654 | } |
| 1655 | |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame^] | 1656 | return ipmi::responseSuccess(power_policy::allSupport); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 1657 | } |
| 1658 | |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1659 | void register_netfn_chassis_functions() |
| 1660 | { |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1661 | createIdentifyTimer(); |
| 1662 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1663 | // <Wildcard Command> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1664 | ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_WILDCARD, NULL, |
| 1665 | ipmi_chassis_wildcard, PRIVILEGE_USER); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1666 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1667 | // Get Chassis Capabilities |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1668 | ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_CHASSIS_CAP, NULL, |
| 1669 | ipmi_get_chassis_cap, PRIVILEGE_USER); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 1670 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 1671 | // Set Chassis Capabilities |
| 1672 | ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_SET_CHASSIS_CAP, NULL, |
| 1673 | ipmi_set_chassis_cap, PRIVILEGE_USER); |
| 1674 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1675 | // <Get System Boot Options> |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1676 | ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_SYS_BOOT_OPTIONS, NULL, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1677 | ipmi_chassis_get_sys_boot_options, |
| 1678 | PRIVILEGE_OPERATOR); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1679 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1680 | // <Get Chassis Status> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1681 | ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_CHASSIS_STATUS, NULL, |
| 1682 | ipmi_get_chassis_status, PRIVILEGE_USER); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1683 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1684 | // <Chassis Control> |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1685 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 1686 | ipmi::chassis::cmdChassisControl, |
| 1687 | ipmi::Privilege::Operator, ipmiChassisControl); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1688 | |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1689 | // <Chassis Identify> |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1690 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 1691 | ipmi::chassis::cmdChassisIdentify, |
| 1692 | ipmi::Privilege::Operator, ipmiChassisIdentify); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1693 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1694 | // <Set System Boot Options> |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1695 | ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_SET_SYS_BOOT_OPTIONS, NULL, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1696 | ipmi_chassis_set_sys_boot_options, |
| 1697 | PRIVILEGE_OPERATOR); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 1698 | // <Get POH Counter> |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 1699 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 1700 | ipmi::chassis::cmdGetPohCounter, |
| 1701 | ipmi::Privilege::User, ipmiGetPOHCounter); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 1702 | |
| 1703 | // <Set Power Restore Policy> |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame^] | 1704 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 1705 | ipmi::chassis::cmdSetPowerRestorePolicy, |
| 1706 | ipmi::Privilege::Operator, |
| 1707 | ipmiChassisSetPowerRestorePolicy); |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1708 | } |