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> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 8 | #include <netinet/in.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 9 | |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 10 | #include <ipmid/api.hpp> |
Vernon Mauery | 3325024 | 2019-03-12 16:49:26 -0700 | [diff] [blame] | 11 | #include <ipmid/types.hpp> |
Vernon Mauery | 6a98fe7 | 2019-03-11 15:57:48 -0700 | [diff] [blame] | 12 | #include <ipmid/utils.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 13 | #include <phosphor-logging/elog-errors.hpp> |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 14 | #include <phosphor-logging/lg2.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 15 | #include <sdbusplus/bus.hpp> |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 16 | #include <sdbusplus/message/types.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 17 | #include <sdbusplus/server/object.hpp> |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 18 | #include <sdbusplus/timer.hpp> |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 19 | #include <settings.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 20 | #include <xyz/openbmc_project/Common/error.hpp> |
| 21 | #include <xyz/openbmc_project/Control/Boot/Mode/server.hpp> |
| 22 | #include <xyz/openbmc_project/Control/Boot/Source/server.hpp> |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 23 | #include <xyz/openbmc_project/Control/Boot/Type/server.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 24 | #include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp> |
Jason M. Bills | ad588bf | 2020-01-30 16:18:33 -0800 | [diff] [blame] | 25 | #include <xyz/openbmc_project/State/Chassis/server.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 26 | #include <xyz/openbmc_project/State/Host/server.hpp> |
| 27 | #include <xyz/openbmc_project/State/PowerOnHours/server.hpp> |
| 28 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 29 | #include <array> |
| 30 | #include <chrono> |
| 31 | #include <cstring> |
| 32 | #include <filesystem> |
| 33 | #include <fstream> |
| 34 | #include <future> |
| 35 | #include <map> |
| 36 | #include <sstream> |
| 37 | #include <string> |
| 38 | |
Patrick Williams | 9565522 | 2023-12-05 12:45:02 -0600 | [diff] [blame] | 39 | std::unique_ptr<sdbusplus::Timer> identifyTimer |
Lei YU | 4b0ddb6 | 2019-01-25 16:43:50 +0800 | [diff] [blame] | 40 | __attribute__((init_priority(101))); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 41 | |
Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 42 | static ChassisIDState chassisIDState = ChassisIDState::reserved; |
| 43 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 44 | constexpr size_t sizeVersion = 2; |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 45 | constexpr size_t DEFAULT_IDENTIFY_TIME_OUT = 15; |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 46 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 47 | // PetiBoot-Specific |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 48 | static constexpr uint8_t netConfInitialBytes[] = {0x80, 0x21, 0x70, 0x62, |
| 49 | 0x21, 0x00, 0x01, 0x06}; |
| 50 | static constexpr uint8_t oemParmStart = 96; |
| 51 | static constexpr uint8_t oemParmEnd = 127; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 52 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 53 | static constexpr size_t cookieOffset = 1; |
| 54 | static constexpr size_t versionOffset = 5; |
| 55 | static constexpr size_t addrSizeOffset = 8; |
| 56 | static constexpr size_t macOffset = 9; |
| 57 | static constexpr size_t addrTypeOffset = 16; |
| 58 | static constexpr size_t ipAddrOffset = 17; |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 59 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 60 | namespace ipmi |
| 61 | { |
| 62 | constexpr Cc ccParmNotSupported = 0x80; |
| 63 | |
| 64 | static inline auto responseParmNotSupported() |
| 65 | { |
| 66 | return response(ccParmNotSupported); |
| 67 | } |
| 68 | } // namespace ipmi |
| 69 | |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 70 | void register_netfn_chassis_functions() __attribute__((constructor)); |
| 71 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 72 | // Host settings in dbus |
| 73 | // Service name should be referenced by connection name got via object mapper |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 74 | const char* settings_object_name = "/org/openbmc/settings/host0"; |
| 75 | const char* settings_intf_name = "org.freedesktop.DBus.Properties"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 76 | const char* identify_led_object_name = |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 77 | "/xyz/openbmc_project/led/groups/enclosure_identify"; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 78 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 79 | constexpr auto SETTINGS_ROOT = "/"; |
| 80 | constexpr auto SETTINGS_MATCH = "host0"; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 81 | |
| 82 | constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP"; |
| 83 | constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress"; |
| 84 | |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 85 | static constexpr auto chassisStateRoot = "/xyz/openbmc_project/state"; |
| 86 | static constexpr auto chassisPOHStateIntf = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 87 | "xyz.openbmc_project.State.PowerOnHours"; |
Patrick Williams | 7345ac4 | 2021-04-30 20:57:39 -0500 | [diff] [blame] | 88 | static constexpr auto pohCounterProperty = "POHCounter"; |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 89 | static constexpr auto match = "chassis0"; |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 90 | const static constexpr char chassisCapIntf[] = |
| 91 | "xyz.openbmc_project.Control.ChassisCapabilities"; |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 92 | const static constexpr char chassisIntrusionProp[] = "ChassisIntrusionEnabled"; |
| 93 | const static constexpr char chassisFrontPanelLockoutProp[] = |
| 94 | "ChassisFrontPanelLockoutEnabled"; |
| 95 | const static constexpr char chassisNMIProp[] = "ChassisNMIEnabled"; |
| 96 | const static constexpr char chassisPowerInterlockProp[] = |
| 97 | "ChassisPowerInterlockEnabled"; |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 98 | const static constexpr char chassisFRUDevAddrProp[] = "FRUDeviceAddress"; |
| 99 | const static constexpr char chassisSDRDevAddrProp[] = "SDRDeviceAddress"; |
| 100 | const static constexpr char chassisSELDevAddrProp[] = "SELDeviceAddress"; |
| 101 | const static constexpr char chassisSMDevAddrProp[] = "SMDeviceAddress"; |
| 102 | const static constexpr char chassisBridgeDevAddrProp[] = "BridgeDeviceAddress"; |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 103 | static constexpr uint8_t chassisCapAddrMask = 0xfe; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 104 | static constexpr const char* powerButtonIntf = |
| 105 | "xyz.openbmc_project.Chassis.Buttons.Power"; |
| 106 | static constexpr const char* powerButtonPath = |
| 107 | "/xyz/openbmc_project/Chassis/Buttons/Power0"; |
| 108 | static constexpr const char* resetButtonIntf = |
| 109 | "xyz.openbmc_project.Chassis.Buttons.Reset"; |
| 110 | static constexpr const char* resetButtonPath = |
| 111 | "/xyz/openbmc_project/Chassis/Buttons/Reset0"; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 112 | |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 113 | // Phosphor Host State manager |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 114 | namespace State = sdbusplus::server::xyz::openbmc_project::state; |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 115 | namespace fs = std::filesystem; |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 116 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 117 | using namespace phosphor::logging; |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 118 | using namespace sdbusplus::error::xyz::openbmc_project::common; |
| 119 | using namespace sdbusplus::server::xyz::openbmc_project::control::boot; |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 120 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 121 | namespace chassis |
| 122 | { |
| 123 | namespace internal |
| 124 | { |
| 125 | |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 126 | constexpr auto bootSettingsPath = "/xyz/openbmc_project/control/host0/boot"; |
| 127 | constexpr auto bootEnableIntf = "xyz.openbmc_project.Object.Enable"; |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 128 | constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode"; |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 129 | constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type"; |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 130 | constexpr auto bootSourceIntf = "xyz.openbmc_project.Control.Boot.Source"; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 131 | constexpr auto bootSettingsOneTimePath = |
| 132 | "/xyz/openbmc_project/control/host0/boot/one_time"; |
| 133 | constexpr auto bootOneTimeIntf = "xyz.openbmc_project.Object.Enable"; |
| 134 | |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 135 | constexpr auto powerRestoreIntf = |
| 136 | "xyz.openbmc_project.Control.Power.RestorePolicy"; |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 137 | sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection()); |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 138 | |
| 139 | namespace cache |
| 140 | { |
| 141 | |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 142 | std::unique_ptr<settings::Objects> objectsPtr = nullptr; |
| 143 | |
| 144 | settings::Objects& getObjects() |
| 145 | { |
| 146 | if (objectsPtr == nullptr) |
| 147 | { |
| 148 | objectsPtr = std::make_unique<settings::Objects>( |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 149 | dbus, std::vector<std::string>{bootModeIntf, bootTypeIntf, |
| 150 | bootSourceIntf, powerRestoreIntf}); |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 151 | } |
| 152 | return *objectsPtr; |
| 153 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 154 | |
| 155 | } // namespace cache |
| 156 | } // namespace internal |
| 157 | } // namespace chassis |
| 158 | |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 159 | namespace poh |
| 160 | { |
| 161 | |
| 162 | constexpr auto minutesPerCount = 60; |
| 163 | |
| 164 | } // namespace poh |
| 165 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 166 | int getHostNetworkData(ipmi::message::Payload& payload) |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 167 | { |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 168 | ipmi::PropertyMap properties; |
| 169 | int rc = 0; |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 170 | uint8_t addrSize = ipmi::network::IPV4_ADDRESS_SIZE_BYTE; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 171 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 172 | try |
| 173 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 174 | // TODO There may be cases where an interface is implemented by multiple |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 175 | // objects,to handle such cases we are interested on that object |
| 176 | // which are on interested busname. |
| 177 | // Currenlty mapper doesn't give the readable busname(gives busid) |
| 178 | // so we can't match with bus name so giving some object specific info |
| 179 | // as SETTINGS_MATCH. |
| 180 | // Later SETTINGS_MATCH will be replaced with busname. |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 181 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 182 | sdbusplus::bus_t bus(ipmid_get_sd_bus_connection()); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 183 | |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 184 | auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE, |
| 185 | SETTINGS_ROOT, SETTINGS_MATCH); |
| 186 | |
| 187 | auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE, |
| 188 | SETTINGS_ROOT, SETTINGS_MATCH); |
| 189 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 190 | properties = ipmi::getAllDbusProperties( |
| 191 | bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE); |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 192 | auto variant = ipmi::getDbusProperty( |
| 193 | bus, macObjectInfo.second, macObjectInfo.first, MAC_INTERFACE, |
| 194 | "MACAddress"); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 195 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 196 | auto ipAddress = std::get<std::string>(properties["Address"]); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 197 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 198 | auto gateway = std::get<std::string>(properties["Gateway"]); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 199 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 200 | auto prefix = std::get<uint8_t>(properties["PrefixLength"]); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 201 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 202 | uint8_t isStatic = |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 203 | (std::get<std::string>(properties["Origin"]) == |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 204 | "xyz.openbmc_project.Network.IP.AddressOrigin.Static") |
| 205 | ? 1 |
| 206 | : 0; |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 207 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 208 | auto MACAddress = std::get<std::string>(variant); |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 209 | |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 210 | // it is expected here that we should get the valid data |
| 211 | // but we may also get the default values. |
| 212 | // Validation of the data is done by settings. |
| 213 | // |
| 214 | // if mac address is default mac address then |
| 215 | // don't send blank override. |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 216 | if ((MACAddress == ipmi::network::DEFAULT_MAC_ADDRESS)) |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 217 | { |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 218 | rc = -1; |
| 219 | return rc; |
| 220 | } |
| 221 | // if addr is static then ipaddress,gateway,prefix |
| 222 | // should not be default one,don't send blank override. |
| 223 | if (isStatic) |
| 224 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 225 | if ((ipAddress == ipmi::network::DEFAULT_ADDRESS) || |
| 226 | (gateway == ipmi::network::DEFAULT_ADDRESS) || (!prefix)) |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 227 | { |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 228 | rc = -1; |
| 229 | return rc; |
| 230 | } |
| 231 | } |
| 232 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 233 | std::string token; |
| 234 | std::stringstream ss(MACAddress); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 235 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 236 | // First pack macOffset no of bytes in payload. |
| 237 | // Latter this PetiBoot-Specific data will be populated. |
| 238 | std::vector<uint8_t> payloadInitialBytes(macOffset); |
| 239 | payload.pack(payloadInitialBytes); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 240 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 241 | while (std::getline(ss, token, ':')) |
| 242 | { |
| 243 | payload.pack(stoi(token, nullptr, 16)); |
| 244 | } |
| 245 | |
| 246 | payload.pack(0x00); |
| 247 | |
| 248 | payload.pack(isStatic); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 249 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 250 | uint8_t addressFamily = (std::get<std::string>(properties["Type"]) == |
| 251 | "xyz.openbmc_project.Network.IP.Protocol.IPv4") |
| 252 | ? AF_INET |
| 253 | : AF_INET6; |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 254 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 255 | addrSize = (addressFamily == AF_INET) |
| 256 | ? ipmi::network::IPV4_ADDRESS_SIZE_BYTE |
| 257 | : ipmi::network::IPV6_ADDRESS_SIZE_BYTE; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 258 | |
| 259 | // ipaddress and gateway would be in IPv4 format |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 260 | std::vector<uint8_t> addrInBinary(addrSize); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 261 | inet_pton(addressFamily, ipAddress.c_str(), |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 262 | reinterpret_cast<void*>(addrInBinary.data())); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 263 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 264 | payload.pack(addrInBinary); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 265 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 266 | payload.pack(prefix); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 267 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 268 | std::vector<uint8_t> gatewayDetails(addrSize); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 269 | inet_pton(addressFamily, gateway.c_str(), |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 270 | reinterpret_cast<void*>(gatewayDetails.data())); |
| 271 | payload.pack(gatewayDetails); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 272 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 273 | catch (const InternalFailure& e) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 274 | { |
| 275 | commit<InternalFailure>(); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 276 | rc = -1; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 277 | return rc; |
| 278 | } |
| 279 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 280 | // PetiBoot-Specific |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 281 | // If success then copy the first 9 bytes to the payload message |
| 282 | // payload first 2 bytes contain the parameter values. Skip that 2 bytes. |
| 283 | uint8_t skipFirstTwoBytes = 2; |
| 284 | size_t payloadSize = payload.size(); |
| 285 | uint8_t* configDataStartingAddress = payload.data() + skipFirstTwoBytes; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 286 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 287 | if (payloadSize < skipFirstTwoBytes + sizeof(netConfInitialBytes)) |
| 288 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 289 | lg2::error("Invalid net config"); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 290 | rc = -1; |
| 291 | return rc; |
| 292 | } |
| 293 | std::copy(netConfInitialBytes, |
| 294 | netConfInitialBytes + sizeof(netConfInitialBytes), |
| 295 | configDataStartingAddress); |
| 296 | |
| 297 | if (payloadSize < skipFirstTwoBytes + addrSizeOffset + sizeof(addrSize)) |
| 298 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 299 | lg2::error("Invalid length of address size"); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 300 | rc = -1; |
| 301 | return rc; |
| 302 | } |
| 303 | std::copy(&addrSize, &(addrSize) + sizeof(addrSize), |
| 304 | configDataStartingAddress + addrSizeOffset); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 305 | |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 306 | #ifdef _IPMI_DEBUG_ |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 307 | std::printf("\n===Printing the IPMI Formatted Data========\n"); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 308 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 309 | for (uint8_t pos = 0; pos < index; pos++) |
| 310 | { |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 311 | std::printf("%02x ", payloadStartingAddress[pos]); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 312 | } |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 313 | #endif |
| 314 | |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 315 | return rc; |
| 316 | } |
| 317 | |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 318 | /** @brief convert IPv4 and IPv6 addresses from binary to text form. |
| 319 | * @param[in] family - IPv4/Ipv6 |
| 320 | * @param[in] data - req data pointer. |
| 321 | * @param[in] offset - offset in the data. |
| 322 | * @param[in] addrSize - size of the data which needs to be read from offset. |
| 323 | * @returns address in text form. |
| 324 | */ |
| 325 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 326 | std::string getAddrStr(uint8_t family, uint8_t* data, uint8_t offset, |
| 327 | uint8_t addrSize) |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 328 | { |
| 329 | char ipAddr[INET6_ADDRSTRLEN] = {}; |
| 330 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 331 | switch (family) |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 332 | { |
| 333 | case AF_INET: |
| 334 | { |
Patrick Williams | 99db688 | 2024-12-18 11:20:17 -0500 | [diff] [blame] | 335 | struct sockaddr_in addr4{}; |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 336 | std::memcpy(&addr4.sin_addr.s_addr, &data[offset], addrSize); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 337 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 338 | inet_ntop(AF_INET, &addr4.sin_addr, ipAddr, INET_ADDRSTRLEN); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 339 | |
| 340 | break; |
| 341 | } |
| 342 | case AF_INET6: |
| 343 | { |
Patrick Williams | 99db688 | 2024-12-18 11:20:17 -0500 | [diff] [blame] | 344 | struct sockaddr_in6 addr6{}; |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 345 | std::memcpy(&addr6.sin6_addr.s6_addr, &data[offset], addrSize); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 346 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 347 | inet_ntop(AF_INET6, &addr6.sin6_addr, ipAddr, INET6_ADDRSTRLEN); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 348 | |
| 349 | break; |
| 350 | } |
| 351 | default: |
| 352 | { |
| 353 | return {}; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | return ipAddr; |
| 358 | } |
| 359 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 360 | ipmi::Cc setHostNetworkData(ipmi::message::Payload& data) |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 361 | { |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 362 | using namespace std::string_literals; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 363 | std::string hostNetworkConfig; |
| 364 | std::string mac("00:00:00:00:00:00"); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 365 | std::string ipAddress, gateway; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 366 | std::string addrOrigin{0}; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 367 | uint8_t addrSize{0}; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 368 | std::string addressOrigin = |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 369 | "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 370 | std::string addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv4"; |
| 371 | uint8_t prefix{0}; |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 372 | uint8_t family = AF_INET; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 373 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 374 | // cookie starts from second byte |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 375 | // version starts from sixth byte |
| 376 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 377 | try |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 378 | { |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 379 | do |
| 380 | { |
| 381 | // cookie == 0x21 0x70 0x62 0x21 |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 382 | data.trailingOk = true; |
| 383 | auto msgLen = data.size(); |
| 384 | std::vector<uint8_t> msgPayloadBytes(msgLen); |
| 385 | if (data.unpack(msgPayloadBytes) != 0 || !data.fullyUnpacked()) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 386 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 387 | lg2::error("Error in unpacking message of setHostNetworkData"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 388 | return ipmi::ccReqDataLenInvalid; |
| 389 | } |
| 390 | |
| 391 | uint8_t* msgPayloadStartingPos = msgPayloadBytes.data(); |
| 392 | constexpr size_t cookieSize = 4; |
| 393 | if (msgLen < cookieOffset + cookieSize) |
| 394 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 395 | lg2::error("Error in cookie getting of setHostNetworkData"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 396 | return ipmi::ccReqDataLenInvalid; |
| 397 | } |
| 398 | if (std::equal(msgPayloadStartingPos + cookieOffset, |
| 399 | msgPayloadStartingPos + cookieOffset + cookieSize, |
| 400 | (netConfInitialBytes + cookieOffset)) != 0) |
| 401 | { |
| 402 | // all cookie == 0 |
| 403 | if (std::all_of(msgPayloadStartingPos + cookieOffset, |
| 404 | msgPayloadStartingPos + cookieOffset + |
| 405 | cookieSize, |
| 406 | [](int i) { return i == 0; }) == true) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 407 | { |
| 408 | // need to zero out the network settings. |
| 409 | break; |
| 410 | } |
| 411 | |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 412 | lg2::error("Invalid Cookie"); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 413 | elog<InternalFailure>(); |
| 414 | } |
| 415 | |
| 416 | // vesion == 0x00 0x01 |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 417 | if (msgLen < versionOffset + sizeVersion) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 418 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 419 | lg2::error("Error in version getting of setHostNetworkData"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 420 | return ipmi::ccReqDataLenInvalid; |
| 421 | } |
| 422 | if (std::equal(msgPayloadStartingPos + versionOffset, |
| 423 | msgPayloadStartingPos + versionOffset + sizeVersion, |
| 424 | (netConfInitialBytes + versionOffset)) != 0) |
| 425 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 426 | lg2::error("Invalid Version"); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 427 | elog<InternalFailure>(); |
| 428 | } |
| 429 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 430 | if (msgLen < macOffset + 6) |
| 431 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 432 | lg2::error( |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 433 | "Error in mac address getting of setHostNetworkData"); |
| 434 | return ipmi::ccReqDataLenInvalid; |
| 435 | } |
| 436 | std::stringstream result; |
| 437 | std::copy((msgPayloadStartingPos + macOffset), |
| 438 | (msgPayloadStartingPos + macOffset + 5), |
| 439 | std::ostream_iterator<int>(result, ":")); |
| 440 | mac = result.str(); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 441 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 442 | if (msgLen < addrTypeOffset + sizeof(decltype(addrOrigin))) |
| 443 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 444 | lg2::error( |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 445 | "Error in original address getting of setHostNetworkData"); |
| 446 | return ipmi::ccReqDataLenInvalid; |
| 447 | } |
| 448 | std::copy(msgPayloadStartingPos + addrTypeOffset, |
| 449 | msgPayloadStartingPos + addrTypeOffset + |
| 450 | sizeof(decltype(addrOrigin)), |
| 451 | std::ostream_iterator<int>(result, "")); |
| 452 | addrOrigin = result.str(); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 453 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 454 | if (!addrOrigin.empty()) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 455 | { |
| 456 | addressOrigin = |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 457 | "xyz.openbmc_project.Network.IP.AddressOrigin.Static"; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 458 | } |
| 459 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 460 | if (msgLen < addrSizeOffset + sizeof(decltype(addrSize))) |
| 461 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 462 | lg2::error( |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 463 | "Error in address size getting of setHostNetworkData"); |
| 464 | return ipmi::ccReqDataLenInvalid; |
| 465 | } |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 466 | // Get the address size |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 467 | std::copy(msgPayloadStartingPos + addrSizeOffset, |
| 468 | (msgPayloadStartingPos + addrSizeOffset + |
| 469 | sizeof(decltype(addrSize))), |
| 470 | &addrSize); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 471 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 472 | uint8_t prefixOffset = ipAddrOffset + addrSize; |
| 473 | if (msgLen < prefixOffset + sizeof(decltype(prefix))) |
| 474 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 475 | lg2::error("Error in prefix getting of setHostNetworkData"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 476 | return ipmi::ccReqDataLenInvalid; |
| 477 | } |
William A. Kennington III | 4c52102 | 2023-07-28 13:07:30 -0700 | [diff] [blame] | 478 | // std::copy(msgPayloadStartingPos + prefixOffset, |
| 479 | // msgPayloadStartingPos + prefixOffset + |
| 480 | // sizeof(decltype(prefix)), |
| 481 | // &prefix); |
| 482 | // Workaround compiler misdetecting out of bounds memcpy |
| 483 | prefix = msgPayloadStartingPos[prefixOffset]; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 484 | |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 485 | uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix)); |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 486 | if (addrSize != ipmi::network::IPV4_ADDRESS_SIZE_BYTE) |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 487 | { |
| 488 | addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv6"; |
| 489 | family = AF_INET6; |
| 490 | } |
| 491 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 492 | if (msgLen < ipAddrOffset + addrSize) |
| 493 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 494 | lg2::error("Error in IP address getting of setHostNetworkData"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 495 | return ipmi::ccReqDataLenInvalid; |
| 496 | } |
| 497 | ipAddress = getAddrStr(family, msgPayloadStartingPos, ipAddrOffset, |
| 498 | addrSize); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 499 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 500 | if (msgLen < gatewayOffset + addrSize) |
| 501 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 502 | lg2::error( |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 503 | "Error in gateway address getting of setHostNetworkData"); |
| 504 | return ipmi::ccReqDataLenInvalid; |
| 505 | } |
| 506 | gateway = getAddrStr(family, msgPayloadStartingPos, gatewayOffset, |
| 507 | addrSize); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 508 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 509 | } while (0); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 510 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 511 | // Cookie == 0 or it is a valid cookie |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 512 | hostNetworkConfig += |
| 513 | "ipaddress="s + ipAddress + ",prefix="s + std::to_string(prefix) + |
| 514 | ",gateway="s + gateway + ",mac="s + mac + ",addressOrigin="s + |
| 515 | addressOrigin; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 516 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 517 | sdbusplus::bus_t bus(ipmid_get_sd_bus_connection()); |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 518 | |
| 519 | auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE, |
| 520 | SETTINGS_ROOT, SETTINGS_MATCH); |
| 521 | auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE, |
| 522 | SETTINGS_ROOT, SETTINGS_MATCH); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 523 | // set the dbus property |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 524 | ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 525 | IP_INTERFACE, "Address", std::string(ipAddress)); |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 526 | ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 527 | IP_INTERFACE, "PrefixLength", prefix); |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 528 | ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 529 | IP_INTERFACE, "Origin", addressOrigin); |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 530 | ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 531 | IP_INTERFACE, "Gateway", std::string(gateway)); |
| 532 | ipmi::setDbusProperty( |
| 533 | bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE, "Type", |
| 534 | std::string("xyz.openbmc_project.Network.IP.Protocol.IPv4")); |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 535 | ipmi::setDbusProperty(bus, macObjectInfo.second, macObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 536 | MAC_INTERFACE, "MACAddress", std::string(mac)); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 537 | |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 538 | lg2::debug("Network configuration changed: {NETWORKCONFIG}", |
| 539 | "NETWORKCONFIG", hostNetworkConfig); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 540 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 541 | catch (const sdbusplus::exception_t& e) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 542 | { |
| 543 | commit<InternalFailure>(); |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 544 | lg2::error("Error in ipmiChassisSetSysBootOptions call"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 545 | return ipmi::ccUnspecifiedError; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 546 | } |
| 547 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 548 | return ipmi::ccSuccess; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 549 | } |
| 550 | |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 551 | uint32_t getPOHCounter() |
| 552 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 553 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 554 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 555 | auto chassisStateObj = |
| 556 | ipmi::getDbusObject(bus, chassisPOHStateIntf, chassisStateRoot, match); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 557 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 558 | auto service = |
| 559 | ipmi::getService(bus, chassisPOHStateIntf, chassisStateObj.first); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 560 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 561 | auto propValue = |
| 562 | ipmi::getDbusProperty(bus, service, chassisStateObj.first, |
| 563 | chassisPOHStateIntf, pohCounterProperty); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 564 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 565 | return std::get<uint32_t>(propValue); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 566 | } |
| 567 | |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 568 | /** @brief Implements the get chassis capabilities command |
| 569 | * |
| 570 | * @returns IPMI completion code plus response data |
| 571 | * chassisCapFlags - chassis capability flag |
| 572 | * chassisFRUInfoDevAddr - chassis FRU info Device Address |
| 573 | * chassisSDRDevAddr - chassis SDR device address |
| 574 | * chassisSELDevAddr - chassis SEL device address |
| 575 | * chassisSMDevAddr - chassis system management device address |
| 576 | * chassisBridgeDevAddr - chassis bridge device address |
| 577 | */ |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 578 | ipmi::RspType<bool, // chassis intrusion sensor |
| 579 | bool, // chassis Front panel lockout |
| 580 | bool, // chassis NMI |
| 581 | bool, // chassis power interlock |
| 582 | uint4_t, // reserved |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 583 | uint8_t, // chassis FRU info Device Address |
| 584 | uint8_t, // chassis SDR device address |
| 585 | uint8_t, // chassis SEL device address |
| 586 | uint8_t, // chassis system management device address |
| 587 | uint8_t // chassis bridge device address |
| 588 | > |
| 589 | ipmiGetChassisCap() |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 590 | { |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 591 | ipmi::PropertyMap properties; |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 592 | try |
| 593 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 594 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 595 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 596 | ipmi::DbusObjectInfo chassisCapObject = |
| 597 | ipmi::getDbusObject(bus, chassisCapIntf); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 598 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 599 | // capabilities flags |
| 600 | // [7..4] - reserved |
| 601 | // [3] – 1b = provides power interlock (IPM 1.5) |
| 602 | // [2] – 1b = provides Diagnostic Interrupt (FP NMI) |
| 603 | // [1] – 1b = provides “Front Panel Lockout” (indicates that the chassis |
| 604 | // has capabilities |
| 605 | // to lock out external power control and reset button or |
| 606 | // front panel interfaces and/or detect tampering with those |
| 607 | // interfaces). |
| 608 | // [0] -1b = Chassis provides intrusion (physical security) sensor. |
| 609 | // set to default value 0x0. |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 610 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 611 | properties = |
| 612 | ipmi::getAllDbusProperties(bus, chassisCapObject.second, |
| 613 | chassisCapObject.first, chassisCapIntf); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 614 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 615 | catch (const std::exception& e) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 616 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 617 | lg2::error("Failed to fetch Chassis Capability properties: {ERROR}", |
| 618 | "ERROR", e); |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 619 | return ipmi::responseUnspecifiedError(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 620 | } |
| 621 | |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 622 | bool* chassisIntrusionFlag = |
| 623 | std::get_if<bool>(&properties[chassisIntrusionProp]); |
| 624 | if (chassisIntrusionFlag == nullptr) |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 625 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 626 | lg2::error("Error to get chassis Intrusion flags"); |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 627 | return ipmi::responseUnspecifiedError(); |
| 628 | } |
| 629 | bool* chassisFrontPanelFlag = |
| 630 | std::get_if<bool>(&properties[chassisFrontPanelLockoutProp]); |
| 631 | if (chassisFrontPanelFlag == nullptr) |
| 632 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 633 | lg2::error("Error to get chassis intrusion flags"); |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 634 | return ipmi::responseUnspecifiedError(); |
| 635 | } |
| 636 | bool* chassisNMIFlag = std::get_if<bool>(&properties[chassisNMIProp]); |
| 637 | if (chassisNMIFlag == nullptr) |
| 638 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 639 | lg2::error("Error to get chassis NMI flags"); |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 640 | return ipmi::responseUnspecifiedError(); |
| 641 | } |
| 642 | bool* chassisPowerInterlockFlag = |
| 643 | std::get_if<bool>(&properties[chassisPowerInterlockProp]); |
| 644 | if (chassisPowerInterlockFlag == nullptr) |
| 645 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 646 | lg2::error("Error to get chassis power interlock flags"); |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 647 | return ipmi::responseUnspecifiedError(); |
| 648 | } |
| 649 | uint8_t* chassisFRUInfoDevAddr = |
| 650 | std::get_if<uint8_t>(&properties[chassisFRUDevAddrProp]); |
| 651 | if (chassisFRUInfoDevAddr == nullptr) |
| 652 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 653 | lg2::error("Error to get chassis FRU info device address"); |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 654 | return ipmi::responseUnspecifiedError(); |
| 655 | } |
| 656 | uint8_t* chassisSDRDevAddr = |
| 657 | std::get_if<uint8_t>(&properties[chassisSDRDevAddrProp]); |
| 658 | if (chassisSDRDevAddr == nullptr) |
| 659 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 660 | lg2::error("Error to get chassis SDR device address"); |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 661 | return ipmi::responseUnspecifiedError(); |
| 662 | } |
| 663 | uint8_t* chassisSELDevAddr = |
| 664 | std::get_if<uint8_t>(&properties[chassisSELDevAddrProp]); |
| 665 | if (chassisSELDevAddr == nullptr) |
| 666 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 667 | lg2::error("Error to get chassis SEL device address"); |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 668 | return ipmi::responseUnspecifiedError(); |
| 669 | } |
| 670 | uint8_t* chassisSMDevAddr = |
| 671 | std::get_if<uint8_t>(&properties[chassisSMDevAddrProp]); |
| 672 | if (chassisSMDevAddr == nullptr) |
| 673 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 674 | lg2::error("Error to get chassis SM device address"); |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 675 | return ipmi::responseUnspecifiedError(); |
| 676 | } |
| 677 | uint8_t* chassisBridgeDevAddr = |
| 678 | std::get_if<uint8_t>(&properties[chassisBridgeDevAddrProp]); |
| 679 | if (chassisBridgeDevAddr == nullptr) |
| 680 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 681 | lg2::error("Error to get chassis bridge device address"); |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 682 | return ipmi::responseUnspecifiedError(); |
| 683 | } |
| 684 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 685 | return ipmi::responseSuccess( |
| 686 | *chassisIntrusionFlag, *chassisFrontPanelFlag, *chassisNMIFlag, |
| 687 | *chassisPowerInterlockFlag, 0, *chassisFRUInfoDevAddr, |
| 688 | *chassisSDRDevAddr, *chassisSELDevAddr, *chassisSMDevAddr, |
| 689 | *chassisBridgeDevAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 690 | } |
| 691 | |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 692 | /** @brief implements set chassis capalibities command |
| 693 | * @param intrusion - chassis intrusion |
| 694 | * @param fpLockout - frontpannel lockout |
| 695 | * @param reserved1 - skip one bit |
| 696 | * @param fruDeviceAddr - chassis FRU info Device Address |
| 697 | * @param sdrDeviceAddr - chassis SDR device address |
| 698 | * @param selDeviceAddr - chassis SEL device address |
| 699 | * @param smDeviceAddr - chassis system management device address |
| 700 | * @param bridgeDeviceAddr - chassis bridge device address |
| 701 | * |
| 702 | * @returns IPMI completion code |
| 703 | */ |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 704 | ipmi::RspType<> ipmiSetChassisCap( |
| 705 | bool intrusion, bool fpLockout, uint6_t reserved1, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 706 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 707 | uint8_t fruDeviceAddr, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 708 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 709 | uint8_t sdrDeviceAddr, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 710 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 711 | uint8_t selDeviceAddr, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 712 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 713 | uint8_t smDeviceAddr, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 714 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 715 | uint8_t bridgeDeviceAddr) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 716 | { |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 717 | // check input data |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 718 | if (reserved1 != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 719 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 720 | lg2::error("Unsupported request parameter"); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 721 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 722 | } |
| 723 | |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 724 | if ((fruDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 725 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 726 | lg2::error("Unsupported request parameter(FRU Addr) for REQ={REQ}", |
| 727 | "REQ", lg2::hex, fruDeviceAddr); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 728 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 729 | } |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 730 | if ((sdrDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 731 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 732 | lg2::error("Unsupported request parameter(SDR Addr) for REQ={REQ}", |
| 733 | "REQ", lg2::hex, sdrDeviceAddr); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 734 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 735 | } |
| 736 | |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 737 | if ((selDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 738 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 739 | lg2::error("Unsupported request parameter(SEL Addr) for REQ={REQ}", |
| 740 | "REQ", lg2::hex, selDeviceAddr); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 741 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 742 | } |
| 743 | |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 744 | if ((smDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 745 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 746 | lg2::error("Unsupported request parameter(SM Addr) for REQ={REQ}", |
| 747 | "REQ", lg2::hex, smDeviceAddr); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 748 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 749 | } |
| 750 | |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 751 | if ((bridgeDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 752 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 753 | lg2::error("Unsupported request parameter(Bridge Addr) for REQ={REQ}", |
| 754 | "REQ", lg2::hex, bridgeDeviceAddr); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 755 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | try |
| 759 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 760 | sdbusplus::bus_t bus(ipmid_get_sd_bus_connection()); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 761 | ipmi::DbusObjectInfo chassisCapObject = |
| 762 | ipmi::getDbusObject(bus, chassisCapIntf); |
| 763 | |
| 764 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 765 | chassisCapObject.first, chassisCapIntf, |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 766 | chassisIntrusionProp, intrusion); |
| 767 | |
| 768 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 769 | chassisCapObject.first, chassisCapIntf, |
| 770 | chassisFrontPanelLockoutProp, fpLockout); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 771 | |
| 772 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 773 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 774 | chassisFRUDevAddrProp, fruDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 775 | |
| 776 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 777 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 778 | chassisSDRDevAddrProp, sdrDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 779 | |
| 780 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 781 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 782 | chassisSELDevAddrProp, selDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 783 | |
| 784 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 785 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 786 | chassisSMDevAddrProp, smDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 787 | |
| 788 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 789 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 790 | chassisBridgeDevAddrProp, bridgeDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 791 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 792 | catch (const std::exception& e) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 793 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 794 | lg2::error("Failed to set chassis capability properties: {ERR}", "ERR", |
| 795 | e); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 796 | return ipmi::responseUnspecifiedError(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 797 | } |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 798 | return ipmi::responseSuccess(); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 799 | } |
| 800 | |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 801 | //------------------------------------------ |
| 802 | // Calls into Host State Manager Dbus object |
| 803 | //------------------------------------------ |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 804 | int initiateHostStateTransition(ipmi::Context::ptr& ctx, |
| 805 | State::Host::Transition transition) |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 806 | { |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 807 | // OpenBMC Host State Manager dbus framework |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 808 | constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0"; |
| 809 | constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host"; |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 810 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 811 | // Convert to string equivalent of the passed in transition enum. |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 812 | auto request = |
| 813 | sdbusplus::common::xyz::openbmc_project::state::convertForMessage( |
| 814 | transition); |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 815 | |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 816 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 817 | boost::system::error_code ec = |
| 818 | ipmi::getService(ctx, hostStateIntf, hostStatePath, service); |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 819 | |
| 820 | if (!ec) |
| 821 | { |
| 822 | ec = ipmi::setDbusProperty(ctx, service, hostStatePath, hostStateIntf, |
| 823 | "RequestedHostTransition", request); |
| 824 | } |
| 825 | if (ec) |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 826 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 827 | lg2::error( |
| 828 | "Failed to initiate transition for request {REQUEST}: {EXCEPTION}", |
| 829 | "REQUEST", request, "EXCEPTION", ec.message()); |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 830 | return -1; |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 831 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 832 | lg2::info( |
| 833 | "Transition request {REQUEST} initiated successfully by user {USERID}", |
| 834 | "REQUEST", request, "USERID", ctx->userId); |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 835 | return 0; |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 836 | } |
| 837 | |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 838 | //------------------------------------------ |
Jason M. Bills | ad588bf | 2020-01-30 16:18:33 -0800 | [diff] [blame] | 839 | // Calls into Chassis State Manager Dbus object |
| 840 | //------------------------------------------ |
| 841 | int initiateChassisStateTransition(ipmi::Context::ptr& ctx, |
| 842 | State::Chassis::Transition transition) |
| 843 | { |
| 844 | // OpenBMC Chassis State Manager dbus framework |
| 845 | constexpr auto chassisStatePath = "/xyz/openbmc_project/state/chassis0"; |
| 846 | constexpr auto chassisStateIntf = "xyz.openbmc_project.State.Chassis"; |
| 847 | |
| 848 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 849 | boost::system::error_code ec = |
| 850 | ipmi::getService(ctx, chassisStateIntf, chassisStatePath, service); |
Jason M. Bills | ad588bf | 2020-01-30 16:18:33 -0800 | [diff] [blame] | 851 | |
| 852 | // Convert to string equivalent of the passed in transition enum. |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 853 | auto request = |
| 854 | sdbusplus::common::xyz::openbmc_project::state::convertForMessage( |
| 855 | transition); |
Jason M. Bills | ad588bf | 2020-01-30 16:18:33 -0800 | [diff] [blame] | 856 | |
| 857 | if (!ec) |
| 858 | { |
| 859 | ec = ipmi::setDbusProperty(ctx, service, chassisStatePath, |
| 860 | chassisStateIntf, "RequestedPowerTransition", |
| 861 | request); |
| 862 | } |
| 863 | if (ec) |
| 864 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 865 | lg2::error("Failed to initiate transition {REQUEST}: {EXCEPTION}", |
| 866 | "REQUEST", request, "EXCEPTION", ec.message()); |
| 867 | |
Jason M. Bills | ad588bf | 2020-01-30 16:18:33 -0800 | [diff] [blame] | 868 | return -1; |
| 869 | } |
| 870 | |
| 871 | return 0; |
| 872 | } |
| 873 | |
| 874 | //------------------------------------------ |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 875 | // Trigger an NMI on the host via dbus |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 876 | //------------------------------------------ |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 877 | static int doNmi(ipmi::Context::ptr& ctx) |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 878 | { |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 879 | constexpr const char* nmiIntfName = "xyz.openbmc_project.Control.Host.NMI"; |
| 880 | ipmi::DbusObjectInfo nmiObj{}; |
| 881 | boost::system::error_code ec; |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 882 | |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 883 | ec = ipmi::getDbusObject(ctx, nmiIntfName, nmiObj); |
Vernon Mauery | 9bb4a38 | 2021-11-05 12:46:19 -0700 | [diff] [blame] | 884 | if (ec) |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 885 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 886 | lg2::error("Failed to find NMI service: {ERROR}", "ERROR", |
| 887 | ec.message()); |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 888 | return -1; |
| 889 | } |
| 890 | |
| 891 | ctx->bus->yield_method_call<void>(ctx->yield, ec, nmiObj.second, |
| 892 | nmiObj.first, nmiIntfName, "NMI"); |
| 893 | if (ec) |
| 894 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 895 | lg2::error("NMI call failed: {ERROR}", "ERROR", ec.message()); |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 896 | elog<InternalFailure>(); |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 897 | return -1; |
| 898 | } |
| 899 | |
| 900 | return 0; |
| 901 | } |
| 902 | |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 903 | namespace power_policy |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 904 | { |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 905 | |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 906 | using namespace sdbusplus::server::xyz::openbmc_project::control::power; |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 907 | using IpmiValue = uint8_t; |
| 908 | using DbusValue = RestorePolicy::Policy; |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 909 | |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 910 | const std::map<DbusValue, IpmiValue> dbusToIpmi = { |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 911 | {RestorePolicy::Policy::AlwaysOff, 0x00}, |
| 912 | {RestorePolicy::Policy::Restore, 0x01}, |
George Liu | e561d3e | 2024-02-04 15:19:30 +0800 | [diff] [blame] | 913 | {RestorePolicy::Policy::AlwaysOn, 0x02}, |
| 914 | {RestorePolicy::Policy::None, 0x03}}; |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 915 | |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 916 | static constexpr uint8_t noChange = 0x03; |
| 917 | static constexpr uint8_t allSupport = 0x01 | 0x02 | 0x04; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 918 | |
| 919 | /* helper function for Get Chassis Status Command |
| 920 | */ |
| 921 | std::optional<uint2_t> getPowerRestorePolicy() |
| 922 | { |
| 923 | uint2_t restorePolicy = 0; |
| 924 | using namespace chassis::internal; |
| 925 | |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 926 | settings::Objects& objects = cache::getObjects(); |
| 927 | |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 928 | try |
| 929 | { |
| 930 | const auto& powerRestoreSetting = |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 931 | objects.map.at(powerRestoreIntf).front(); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 932 | ipmi::Value result = ipmi::getDbusProperty( |
| 933 | *getSdBus(), |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 934 | objects.service(powerRestoreSetting, powerRestoreIntf).c_str(), |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 935 | powerRestoreSetting.c_str(), powerRestoreIntf, |
| 936 | "PowerRestorePolicy"); |
| 937 | auto powerRestore = RestorePolicy::convertPolicyFromString( |
| 938 | std::get<std::string>(result)); |
| 939 | restorePolicy = dbusToIpmi.at(powerRestore); |
| 940 | } |
| 941 | catch (const std::exception& e) |
| 942 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 943 | lg2::error( |
| 944 | "Failed to fetch pgood property ({PATH}/{INTERFACE}): {ERROR}", |
| 945 | "PATH", objects.map.at(powerRestoreIntf).front(), "INTERFACE", |
| 946 | powerRestoreIntf, "ERROR", e); |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 947 | cache::objectsPtr.reset(); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 948 | return std::nullopt; |
| 949 | } |
| 950 | return std::make_optional(restorePolicy); |
| 951 | } |
| 952 | |
| 953 | /* |
| 954 | * getPowerStatus |
| 955 | * helper function for Get Chassis Status Command |
| 956 | * return - optional value for pgood (no value on error) |
| 957 | */ |
| 958 | std::optional<bool> getPowerStatus() |
| 959 | { |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 960 | bool powerGood = false; |
| 961 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 962 | try |
| 963 | { |
Jason M. Bills | 3de424c | 2019-05-21 09:57:16 -0700 | [diff] [blame] | 964 | constexpr const char* chassisStatePath = |
| 965 | "/xyz/openbmc_project/state/chassis0"; |
| 966 | constexpr const char* chassisStateIntf = |
| 967 | "xyz.openbmc_project.State.Chassis"; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 968 | auto service = |
| 969 | ipmi::getService(*busp, chassisStateIntf, chassisStatePath); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 970 | |
Jason M. Bills | 3de424c | 2019-05-21 09:57:16 -0700 | [diff] [blame] | 971 | ipmi::Value powerState = |
| 972 | ipmi::getDbusProperty(*busp, service, chassisStatePath, |
| 973 | chassisStateIntf, "CurrentPowerState"); |
Chau Ly | ee3983b | 2024-01-05 07:33:45 +0000 | [diff] [blame] | 974 | std::string powerStateStr = std::get<std::string>(powerState); |
| 975 | if (powerStateStr.ends_with(".On") || |
| 976 | powerStateStr.ends_with(".TransitioningToOff")) |
| 977 | { |
| 978 | powerGood = true; |
| 979 | } |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 980 | } |
| 981 | catch (const std::exception& e) |
| 982 | { |
| 983 | try |
| 984 | { |
| 985 | // FIXME: some legacy modules use the older path; try that next |
| 986 | constexpr const char* legacyPwrCtrlObj = |
| 987 | "/org/openbmc/control/power0"; |
| 988 | constexpr const char* legacyPwrCtrlIntf = |
| 989 | "org.openbmc.control.Power"; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 990 | auto service = |
| 991 | ipmi::getService(*busp, legacyPwrCtrlIntf, legacyPwrCtrlObj); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 992 | |
| 993 | ipmi::Value variant = ipmi::getDbusProperty( |
| 994 | *busp, service, legacyPwrCtrlObj, legacyPwrCtrlIntf, "pgood"); |
| 995 | powerGood = static_cast<bool>(std::get<int>(variant)); |
| 996 | } |
| 997 | catch (const std::exception& e) |
| 998 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 999 | lg2::error("Failed to fetch pgood property: {ERROR}", "ERROR", e); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1000 | return std::nullopt; |
| 1001 | } |
| 1002 | } |
| 1003 | return std::make_optional(powerGood); |
| 1004 | } |
| 1005 | |
Yong Li | 70ce735 | 2019-05-16 21:15:27 +0800 | [diff] [blame] | 1006 | /* |
| 1007 | * getACFailStatus |
| 1008 | * helper function for Get Chassis Status Command |
| 1009 | * return - bool value for ACFail (false on error) |
| 1010 | */ |
| 1011 | bool getACFailStatus() |
| 1012 | { |
| 1013 | constexpr const char* powerControlObj = |
| 1014 | "/xyz/openbmc_project/Chassis/Control/Power0"; |
| 1015 | constexpr const char* powerControlIntf = |
| 1016 | "xyz.openbmc_project.Chassis.Control.Power"; |
| 1017 | bool acFail = false; |
| 1018 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 1019 | try |
| 1020 | { |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1021 | auto service = |
| 1022 | ipmi::getService(*bus, powerControlIntf, powerControlObj); |
Yong Li | 70ce735 | 2019-05-16 21:15:27 +0800 | [diff] [blame] | 1023 | |
| 1024 | ipmi::Value variant = ipmi::getDbusProperty( |
| 1025 | *bus, service, powerControlObj, powerControlIntf, "PFail"); |
| 1026 | acFail = std::get<bool>(variant); |
| 1027 | } |
| 1028 | catch (const std::exception& e) |
| 1029 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1030 | lg2::error( |
Konstantin Aladyshev | 37de2e1 | 2025-01-29 11:49:26 +0300 | [diff] [blame] | 1031 | "Failed to fetch PFail property ({PATH}/{INTERFACE}): {ERROR}", |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1032 | "PATH", powerControlObj, "INTERFACE", powerControlIntf, "ERROR", e); |
Yong Li | 70ce735 | 2019-05-16 21:15:27 +0800 | [diff] [blame] | 1033 | } |
| 1034 | return acFail; |
| 1035 | } |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1036 | } // namespace power_policy |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1037 | |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1038 | static std::optional<bool> getButtonEnabled(const std::string& buttonPath, |
| 1039 | const std::string& buttonIntf) |
| 1040 | { |
| 1041 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 1042 | bool buttonDisabled = false; |
| 1043 | try |
| 1044 | { |
| 1045 | auto service = ipmi::getService(*busp, buttonIntf, buttonPath); |
| 1046 | ipmi::Value enabled = ipmi::getDbusProperty(*busp, service, buttonPath, |
| 1047 | buttonIntf, "Enabled"); |
| 1048 | buttonDisabled = !std::get<bool>(enabled); |
| 1049 | } |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 1050 | catch (const sdbusplus::exception_t& e) |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1051 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1052 | lg2::error("Fail to get button Enabled property ({PATH}): {ERROR}", |
| 1053 | "PATH", buttonPath, "ERROR", e); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1054 | return std::nullopt; |
| 1055 | } |
| 1056 | return std::make_optional(buttonDisabled); |
| 1057 | } |
| 1058 | |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 1059 | static bool setButtonEnabled(ipmi::Context::ptr& ctx, |
| 1060 | const std::string& buttonPath, |
| 1061 | const std::string& buttonIntf, bool enable) |
| 1062 | { |
| 1063 | std::string service; |
| 1064 | boost::system::error_code ec; |
| 1065 | ec = ipmi::getService(ctx, buttonIntf, buttonPath, service); |
| 1066 | if (!ec) |
| 1067 | { |
| 1068 | ec = ipmi::setDbusProperty(ctx, service, buttonPath, buttonIntf, |
| 1069 | "Enabled", enable); |
| 1070 | } |
| 1071 | if (ec) |
| 1072 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1073 | lg2::error( |
| 1074 | "Fail to set button Enabled property ({SERVICE}:{PATH}): {ERROR}", |
| 1075 | "SERVICE", service, "PATH", buttonPath, "ERROR", ec.message()); |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 1076 | return false; |
| 1077 | } |
| 1078 | return true; |
| 1079 | } |
| 1080 | |
Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1081 | static std::optional<bool> getChassisIntrusionStatus(ipmi::Context::ptr& ctx) |
| 1082 | { |
| 1083 | constexpr const char* chassisIntrusionPath = |
| 1084 | "/xyz/openbmc_project/Chassis/Intrusion"; |
| 1085 | constexpr const char* chassisIntrusionInf = |
| 1086 | "xyz.openbmc_project.Chassis.Intrusion"; |
| 1087 | |
| 1088 | std::string service; |
| 1089 | boost::system::error_code ec = ipmi::getService( |
| 1090 | ctx, chassisIntrusionInf, chassisIntrusionPath, service); |
| 1091 | if (!ec) |
| 1092 | { |
| 1093 | std::string chassisIntrusionStr; |
| 1094 | ec = ipmi::getDbusProperty<std::string>( |
| 1095 | ctx, service, chassisIntrusionPath, chassisIntrusionInf, "Status", |
| 1096 | chassisIntrusionStr); |
| 1097 | if (!ec) |
| 1098 | { |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1099 | bool ret = |
| 1100 | (chassisIntrusionStr == "HardwareIntrusion") ? true : false; |
Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1101 | return std::make_optional(ret); |
| 1102 | } |
| 1103 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1104 | lg2::error("Fail to get Chassis Intrusion Status property " |
| 1105 | "({PATH}/{INTERFACE}): {ERROR}", |
| 1106 | "PATH", chassisIntrusionPath, "INTERFACE", chassisIntrusionInf, |
| 1107 | "ERROR", ec.message()); |
Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1108 | return std::nullopt; |
| 1109 | } |
| 1110 | |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1111 | //---------------------------------------------------------------------- |
| 1112 | // Get Chassis Status commands |
| 1113 | //---------------------------------------------------------------------- |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1114 | ipmi::RspType<bool, // Power is on |
| 1115 | bool, // Power overload |
| 1116 | bool, // Interlock |
| 1117 | bool, // power fault |
| 1118 | bool, // power control fault |
| 1119 | uint2_t, // power restore policy |
| 1120 | bool, // reserved |
| 1121 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1122 | bool, // AC failed |
| 1123 | bool, // last power down caused by a Power overload |
| 1124 | bool, // last power down caused by a power interlock |
| 1125 | bool, // last power down caused by power fault |
Patrick Williams | 99db688 | 2024-12-18 11:20:17 -0500 | [diff] [blame] | 1126 | bool, // last ‘Power is on’ state was entered via IPMI command |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1127 | uint3_t, // reserved |
| 1128 | |
| 1129 | bool, // Chassis intrusion active |
| 1130 | bool, // Front Panel Lockout active |
| 1131 | bool, // Drive Fault |
| 1132 | bool, // Cooling/fan fault detected |
| 1133 | uint2_t, // Chassis Identify State |
| 1134 | bool, // Chassis Identify command and state info supported |
| 1135 | bool, // reserved |
| 1136 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1137 | bool, // Power off button disabled |
| 1138 | bool, // Reset button disabled |
| 1139 | bool, // Diagnostic Interrupt button disabled |
| 1140 | bool, // Standby (sleep) button disabled |
| 1141 | bool, // Power off button disable allowed |
| 1142 | bool, // Reset button disable allowed |
| 1143 | bool, // Diagnostic Interrupt button disable allowed |
| 1144 | bool // Standby (sleep) button disable allowed |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1145 | > |
Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1146 | ipmiGetChassisStatus(ipmi::Context::ptr& ctx) |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1147 | { |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1148 | using namespace chassis::internal; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1149 | std::optional<uint2_t> restorePolicy = |
| 1150 | power_policy::getPowerRestorePolicy(); |
| 1151 | std::optional<bool> powerGood = power_policy::getPowerStatus(); |
| 1152 | if (!restorePolicy || !powerGood) |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1153 | { |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1154 | return ipmi::responseUnspecifiedError(); |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1155 | } |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1156 | |
| 1157 | // Front Panel Button Capabilities and disable/enable status(Optional) |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1158 | std::optional<bool> powerButtonReading = |
| 1159 | getButtonEnabled(powerButtonPath, powerButtonIntf); |
Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1160 | // allow disable if the interface is present |
| 1161 | bool powerButtonDisableAllow = static_cast<bool>(powerButtonReading); |
| 1162 | // default return the button is enabled (not disabled) |
| 1163 | bool powerButtonDisabled = false; |
| 1164 | if (powerButtonDisableAllow) |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1165 | { |
Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1166 | // return the real value of the button status, if present |
| 1167 | powerButtonDisabled = *powerButtonReading; |
| 1168 | } |
| 1169 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1170 | std::optional<bool> resetButtonReading = |
| 1171 | getButtonEnabled(resetButtonPath, resetButtonIntf); |
Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1172 | // allow disable if the interface is present |
| 1173 | bool resetButtonDisableAllow = static_cast<bool>(resetButtonReading); |
| 1174 | // default return the button is enabled (not disabled) |
| 1175 | bool resetButtonDisabled = false; |
| 1176 | if (resetButtonDisableAllow) |
| 1177 | { |
| 1178 | // return the real value of the button status, if present |
| 1179 | resetButtonDisabled = *resetButtonReading; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1180 | } |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1181 | |
Yong Li | 70ce735 | 2019-05-16 21:15:27 +0800 | [diff] [blame] | 1182 | bool powerDownAcFailed = power_policy::getACFailStatus(); |
| 1183 | |
Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1184 | bool chassisIntrusionActive = false; |
| 1185 | std::optional<bool> chassisIntrusionStatus = getChassisIntrusionStatus(ctx); |
| 1186 | if (chassisIntrusionStatus) |
| 1187 | { |
| 1188 | chassisIntrusionActive = chassisIntrusionStatus.value(); |
| 1189 | } |
| 1190 | |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1191 | // This response has a lot of hard-coded, unsupported fields |
| 1192 | // They are set to false or 0 |
| 1193 | constexpr bool powerOverload = false; |
| 1194 | constexpr bool chassisInterlock = false; |
| 1195 | constexpr bool powerFault = false; |
| 1196 | constexpr bool powerControlFault = false; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1197 | constexpr bool powerDownOverload = false; |
| 1198 | constexpr bool powerDownInterlock = false; |
| 1199 | constexpr bool powerDownPowerFault = false; |
| 1200 | constexpr bool powerStatusIPMI = false; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1201 | constexpr bool frontPanelLockoutActive = false; |
| 1202 | constexpr bool driveFault = false; |
| 1203 | constexpr bool coolingFanFault = false; |
| 1204 | // chassisIdentifySupport set because this command is implemented |
| 1205 | constexpr bool chassisIdentifySupport = true; |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1206 | uint2_t chassisIdentifyState = types::enum_cast<uint2_t>(chassisIDState); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1207 | constexpr bool diagButtonDisabled = false; |
| 1208 | constexpr bool sleepButtonDisabled = false; |
| 1209 | constexpr bool diagButtonDisableAllow = false; |
| 1210 | constexpr bool sleepButtonDisableAllow = false; |
| 1211 | |
| 1212 | return ipmi::responseSuccess( |
| 1213 | *powerGood, powerOverload, chassisInterlock, powerFault, |
| 1214 | powerControlFault, *restorePolicy, |
| 1215 | false, // reserved |
| 1216 | |
| 1217 | powerDownAcFailed, powerDownOverload, powerDownInterlock, |
| 1218 | powerDownPowerFault, powerStatusIPMI, |
| 1219 | uint3_t(0), // reserved |
| 1220 | |
| 1221 | chassisIntrusionActive, frontPanelLockoutActive, driveFault, |
| 1222 | coolingFanFault, chassisIdentifyState, chassisIdentifySupport, |
| 1223 | false, // reserved |
| 1224 | |
Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1225 | powerButtonDisabled, resetButtonDisabled, diagButtonDisabled, |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1226 | sleepButtonDisabled, powerButtonDisableAllow, resetButtonDisableAllow, |
| 1227 | diagButtonDisableAllow, sleepButtonDisableAllow); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1228 | } |
Chris Austen | 7888c4d | 2015-12-03 15:26:20 -0600 | [diff] [blame] | 1229 | |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1230 | enum class IpmiRestartCause |
| 1231 | { |
| 1232 | Unknown = 0x0, |
| 1233 | RemoteCommand = 0x1, |
| 1234 | ResetButton = 0x2, |
| 1235 | PowerButton = 0x3, |
| 1236 | WatchdogTimer = 0x4, |
| 1237 | PowerPolicyAlwaysOn = 0x6, |
| 1238 | PowerPolicyPreviousState = 0x7, |
| 1239 | SoftReset = 0xa, |
| 1240 | }; |
| 1241 | |
Patrick Williams | 56c04e2 | 2025-03-03 11:19:13 -0500 | [diff] [blame^] | 1242 | static IpmiRestartCause restartCauseToIpmiRestartCause( |
| 1243 | State::Host::RestartCause cause) |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1244 | { |
| 1245 | switch (cause) |
| 1246 | { |
| 1247 | case State::Host::RestartCause::Unknown: |
| 1248 | { |
| 1249 | return IpmiRestartCause::Unknown; |
| 1250 | } |
| 1251 | case State::Host::RestartCause::RemoteCommand: |
| 1252 | { |
| 1253 | return IpmiRestartCause::RemoteCommand; |
| 1254 | } |
| 1255 | case State::Host::RestartCause::ResetButton: |
| 1256 | { |
| 1257 | return IpmiRestartCause::ResetButton; |
| 1258 | } |
| 1259 | case State::Host::RestartCause::PowerButton: |
| 1260 | { |
| 1261 | return IpmiRestartCause::PowerButton; |
| 1262 | } |
| 1263 | case State::Host::RestartCause::WatchdogTimer: |
| 1264 | { |
| 1265 | return IpmiRestartCause::WatchdogTimer; |
| 1266 | } |
| 1267 | case State::Host::RestartCause::PowerPolicyAlwaysOn: |
| 1268 | { |
| 1269 | return IpmiRestartCause::PowerPolicyAlwaysOn; |
| 1270 | } |
| 1271 | case State::Host::RestartCause::PowerPolicyPreviousState: |
| 1272 | { |
| 1273 | return IpmiRestartCause::PowerPolicyPreviousState; |
| 1274 | } |
| 1275 | case State::Host::RestartCause::SoftReset: |
| 1276 | { |
| 1277 | return IpmiRestartCause::SoftReset; |
| 1278 | } |
| 1279 | default: |
| 1280 | { |
| 1281 | return IpmiRestartCause::Unknown; |
| 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | /* |
| 1287 | * getRestartCause |
| 1288 | * helper function for Get Host restart cause Command |
| 1289 | * return - optional value for RestartCause (no value on error) |
| 1290 | */ |
| 1291 | static std::optional<uint4_t> getRestartCause(ipmi::Context::ptr ctx) |
| 1292 | { |
okashany | ced0ddf | 2023-05-18 18:35:09 +0000 | [diff] [blame] | 1293 | constexpr const char* restartCausePath = "/xyz/openbmc_project/state/host0"; |
| 1294 | constexpr const char* restartCauseIntf = "xyz.openbmc_project.State.Host"; |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1295 | |
| 1296 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1297 | boost::system::error_code ec = |
| 1298 | ipmi::getService(ctx, restartCauseIntf, restartCausePath, service); |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1299 | if (!ec) |
| 1300 | { |
| 1301 | std::string restartCauseStr; |
| 1302 | ec = ipmi::getDbusProperty<std::string>( |
| 1303 | ctx, service, restartCausePath, restartCauseIntf, "RestartCause", |
| 1304 | restartCauseStr); |
| 1305 | if (!ec) |
| 1306 | { |
| 1307 | auto cause = |
| 1308 | State::Host::convertRestartCauseFromString(restartCauseStr); |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1309 | return types::enum_cast<uint4_t>( |
| 1310 | restartCauseToIpmiRestartCause(cause)); |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1311 | } |
| 1312 | } |
| 1313 | |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1314 | lg2::error( |
| 1315 | "Failed to fetch RestartCause property ({PATH}/{INTERFACE}): {ERROR}", |
| 1316 | "ERROR", ec.message(), "PATH", restartCausePath, "INTERFACE", |
| 1317 | restartCauseIntf); |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1318 | return std::nullopt; |
| 1319 | } |
| 1320 | |
| 1321 | ipmi::RspType<uint4_t, // Restart Cause |
| 1322 | uint4_t, // reserved |
| 1323 | uint8_t // channel number (not supported) |
| 1324 | > |
| 1325 | ipmiGetSystemRestartCause(ipmi::Context::ptr ctx) |
| 1326 | { |
| 1327 | std::optional<uint4_t> cause = getRestartCause(ctx); |
| 1328 | if (!cause) |
| 1329 | { |
| 1330 | return ipmi::responseUnspecifiedError(); |
| 1331 | } |
| 1332 | |
Vernon Mauery | 916d423 | 2021-03-29 13:42:16 -0700 | [diff] [blame] | 1333 | constexpr uint4_t reserved = 0; |
| 1334 | auto channel = static_cast<uint8_t>(ctx->channel); |
| 1335 | return ipmi::responseSuccess(cause.value(), reserved, channel); |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1336 | } |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1337 | /** @brief Implementation of chassis control command |
| 1338 | * |
| 1339 | * @param - chassisControl command byte |
| 1340 | * |
| 1341 | * @return Success or InvalidFieldRequest. |
| 1342 | */ |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1343 | ipmi::RspType<> ipmiChassisControl(ipmi::Context::ptr& ctx, |
| 1344 | uint8_t chassisControl) |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1345 | { |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1346 | int rc = 0; |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1347 | switch (chassisControl) |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1348 | { |
| 1349 | case CMD_POWER_ON: |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1350 | rc = initiateHostStateTransition(ctx, State::Host::Transition::On); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1351 | break; |
| 1352 | case CMD_POWER_OFF: |
Jason M. Bills | c2c3a40 | 2020-01-30 16:22:24 -0800 | [diff] [blame] | 1353 | rc = initiateChassisStateTransition( |
| 1354 | ctx, State::Chassis::Transition::Off); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1355 | break; |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1356 | case CMD_HARD_RESET: |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1357 | rc = initiateHostStateTransition( |
| 1358 | ctx, State::Host::Transition::ForceWarmReboot); |
Chanh Nguyen | d0a7fcd | 2021-07-16 22:59:28 +0700 | [diff] [blame] | 1359 | break; |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1360 | case CMD_POWER_CYCLE: |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1361 | rc = initiateHostStateTransition(ctx, |
| 1362 | State::Host::Transition::Reboot); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1363 | break; |
Vishwanatha Subbanna | 8b26d35 | 2017-08-04 18:35:18 +0530 | [diff] [blame] | 1364 | case CMD_SOFT_OFF_VIA_OVER_TEMP: |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1365 | rc = initiateHostStateTransition(ctx, State::Host::Transition::Off); |
Vishwanatha Subbanna | 8b26d35 | 2017-08-04 18:35:18 +0530 | [diff] [blame] | 1366 | break; |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 1367 | case CMD_PULSE_DIAGNOSTIC_INTR: |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 1368 | rc = doNmi(ctx); |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 1369 | break; |
| 1370 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1371 | default: |
| 1372 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1373 | lg2::error("Invalid Chassis Control command: {CMD}", "CMD", |
| 1374 | lg2::hex, chassisControl); |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1375 | return ipmi::responseInvalidFieldRequest(); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1376 | } |
| 1377 | } |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1378 | |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1379 | return ((rc < 0) ? ipmi::responseUnspecifiedError() |
| 1380 | : ipmi::responseSuccess()); |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1381 | } |
| 1382 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1383 | /** @brief Return D-Bus connection string to enclosure identify LED object |
| 1384 | * |
| 1385 | * @param[in, out] connection - connection to D-Bus object |
| 1386 | * @return a IPMI return code |
| 1387 | */ |
| 1388 | std::string getEnclosureIdentifyConnection() |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1389 | { |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1390 | // lookup enclosure_identify group owner(s) in mapper |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 1391 | try |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1392 | { |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 1393 | return ipmi::getService(*getSdBus(), "xyz.openbmc_project.Led.Group", |
| 1394 | identify_led_object_name); |
| 1395 | } |
| 1396 | catch (const std::exception& e) |
| 1397 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1398 | lg2::error("Chassis Identify: Error communicating to mapper: {ERROR}", |
| 1399 | "ERROR", e); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1400 | elog<InternalFailure>(); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1401 | } |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1402 | } |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1403 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1404 | /** @brief Turn On/Off enclosure identify LED |
| 1405 | * |
| 1406 | * @param[in] flag - true to turn on LED, false to turn off |
| 1407 | * @return a IPMI return code |
| 1408 | */ |
| 1409 | void enclosureIdentifyLed(bool flag) |
| 1410 | { |
| 1411 | using namespace chassis::internal; |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 1412 | try |
| 1413 | { |
| 1414 | std::string connection = getEnclosureIdentifyConnection(); |
| 1415 | |
| 1416 | auto msg = std::string("enclosureIdentifyLed(") + |
| 1417 | boost::lexical_cast<std::string>(flag) + ")"; |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1418 | lg2::debug(msg.c_str()); |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 1419 | |
| 1420 | ipmi::setDbusProperty(*getSdBus(), connection, identify_led_object_name, |
| 1421 | "xyz.openbmc_project.Led.Group", "Asserted", |
| 1422 | flag); |
| 1423 | } |
| 1424 | catch (const std::exception& e) |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1425 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1426 | lg2::error("Chassis Identify: Error Setting State {LED_STATE}: {ERROR}", |
| 1427 | "LED_STATE", flag, "ERROR", e); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1428 | elog<InternalFailure>(); |
| 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | /** @brief Callback method to turn off LED |
| 1433 | */ |
| 1434 | void enclosureIdentifyLedOff() |
| 1435 | { |
| 1436 | try |
| 1437 | { |
Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 1438 | chassisIDState = ChassisIDState::off; |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1439 | enclosureIdentifyLed(false); |
| 1440 | } |
| 1441 | catch (const InternalFailure& e) |
| 1442 | { |
| 1443 | report<InternalFailure>(); |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | /** @brief Create timer to turn on and off the enclosure LED |
| 1448 | */ |
| 1449 | void createIdentifyTimer() |
| 1450 | { |
| 1451 | if (!identifyTimer) |
| 1452 | { |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1453 | identifyTimer = |
Patrick Williams | 9565522 | 2023-12-05 12:45:02 -0600 | [diff] [blame] | 1454 | std::make_unique<sdbusplus::Timer>(enclosureIdentifyLedOff); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1455 | } |
| 1456 | } |
| 1457 | |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1458 | ipmi::RspType<> ipmiChassisIdentify(std::optional<uint8_t> interval, |
| 1459 | std::optional<uint8_t> force) |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1460 | { |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1461 | uint8_t identifyInterval = interval.value_or(DEFAULT_IDENTIFY_TIME_OUT); |
| 1462 | bool forceIdentify = force.value_or(0) & 0x01; |
Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1463 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1464 | if (identifyInterval || forceIdentify) |
| 1465 | { |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1466 | // stop the timer if already started; |
| 1467 | // for force identify we should not turn off LED |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1468 | identifyTimer->stop(); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1469 | try |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1470 | { |
Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 1471 | chassisIDState = ChassisIDState::temporaryOn; |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1472 | enclosureIdentifyLed(true); |
| 1473 | } |
| 1474 | catch (const InternalFailure& e) |
| 1475 | { |
| 1476 | report<InternalFailure>(); |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1477 | return ipmi::responseResponseError(); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1478 | } |
| 1479 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1480 | if (forceIdentify) |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1481 | { |
Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 1482 | chassisIDState = ChassisIDState::indefiniteOn; |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1483 | return ipmi::responseSuccess(); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1484 | } |
| 1485 | // start the timer |
| 1486 | auto time = std::chrono::duration_cast<std::chrono::microseconds>( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1487 | std::chrono::seconds(identifyInterval)); |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1488 | identifyTimer->start(time); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1489 | } |
Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1490 | else if (!identifyInterval) |
| 1491 | { |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1492 | identifyTimer->stop(); |
Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1493 | enclosureIdentifyLedOff(); |
| 1494 | } |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1495 | return ipmi::responseSuccess(); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1496 | } |
| 1497 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1498 | namespace boot_options |
| 1499 | { |
| 1500 | |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 1501 | using namespace sdbusplus::server::xyz::openbmc_project::control::boot; |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1502 | using IpmiValue = uint8_t; |
| 1503 | constexpr auto ipmiDefault = 0; |
| 1504 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1505 | std::map<IpmiValue, Type::Types> typeIpmiToDbus = {{0x00, Type::Types::Legacy}, |
| 1506 | {0x01, Type::Types::EFI}}; |
| 1507 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1508 | std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1509 | {0x01, Source::Sources::Network}, |
| 1510 | {0x02, Source::Sources::Disk}, |
| 1511 | {0x05, Source::Sources::ExternalMedia}, |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 1512 | {0x0f, Source::Sources::RemovableMedia}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1513 | {ipmiDefault, Source::Sources::Default}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1514 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1515 | std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = { |
Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1516 | #ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1517 | {0x03, Mode::Modes::Safe}, |
Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1518 | #endif // ENABLE_BOOT_SAFE_MODE_SUPPORT |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1519 | {0x06, Mode::Modes::Setup}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1520 | {ipmiDefault, Mode::Modes::Regular}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1521 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1522 | std::map<Type::Types, IpmiValue> typeDbusToIpmi = {{Type::Types::Legacy, 0x00}, |
| 1523 | {Type::Types::EFI, 0x01}}; |
| 1524 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1525 | std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1526 | {Source::Sources::Network, 0x01}, |
| 1527 | {Source::Sources::Disk, 0x02}, |
| 1528 | {Source::Sources::ExternalMedia, 0x05}, |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 1529 | {Source::Sources::RemovableMedia, 0x0f}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1530 | {Source::Sources::Default, ipmiDefault}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1531 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1532 | std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = { |
Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1533 | #ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1534 | {Mode::Modes::Safe, 0x03}, |
Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1535 | #endif // ENABLE_BOOT_SAFE_MODE_SUPPORT |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1536 | {Mode::Modes::Setup, 0x06}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1537 | {Mode::Modes::Regular, ipmiDefault}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1538 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1539 | } // namespace boot_options |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1540 | |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1541 | /** @brief Get the property value for boot source |
| 1542 | * @param[in] ctx - context pointer |
| 1543 | * @param[out] source - boot source value |
| 1544 | * @return On failure return IPMI error. |
| 1545 | */ |
| 1546 | static ipmi::Cc getBootSource(ipmi::Context::ptr& ctx, Source::Sources& source) |
| 1547 | { |
| 1548 | using namespace chassis::internal; |
| 1549 | std::string result; |
| 1550 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1551 | boost::system::error_code ec = |
| 1552 | getService(ctx, bootSourceIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1553 | if (!ec) |
| 1554 | { |
| 1555 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, |
| 1556 | bootSourceIntf, "BootSource", result); |
| 1557 | if (!ec) |
| 1558 | { |
| 1559 | source = Source::convertSourcesFromString(result); |
| 1560 | return ipmi::ccSuccess; |
| 1561 | } |
| 1562 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1563 | lg2::error("Error in BootSource Get: {ERROR}", "ERROR", ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1564 | return ipmi::ccUnspecifiedError; |
| 1565 | } |
| 1566 | |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1567 | /** @brief Set the property value for boot source |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1568 | * @param[in] ctx - context pointer |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1569 | * @param[in] source - boot source value |
| 1570 | * @return On failure return IPMI error. |
| 1571 | */ |
Jayaprakash Mutyala | 6088e9f | 2021-07-14 07:40:29 +0000 | [diff] [blame] | 1572 | static ipmi::Cc setBootSource(ipmi::Context::ptr& ctx, |
| 1573 | const Source::Sources& source) |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1574 | { |
| 1575 | using namespace chassis::internal; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1576 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1577 | boost::system::error_code ec = |
| 1578 | getService(ctx, bootSourceIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1579 | if (!ec) |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1580 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1581 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, |
| 1582 | bootSourceIntf, "BootSource", |
| 1583 | convertForMessage(source)); |
| 1584 | if (!ec) |
| 1585 | { |
| 1586 | return ipmi::ccSuccess; |
| 1587 | } |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1588 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1589 | lg2::error("Error in BootSource Set: {ERROR}", "ERROR", ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1590 | return ipmi::ccUnspecifiedError; |
| 1591 | } |
| 1592 | |
| 1593 | /** @brief Get the property value for boot mode |
| 1594 | * @param[in] ctx - context pointer |
| 1595 | * @param[out] mode - boot mode value |
| 1596 | * @return On failure return IPMI error. |
| 1597 | */ |
| 1598 | static ipmi::Cc getBootMode(ipmi::Context::ptr& ctx, Mode::Modes& mode) |
| 1599 | { |
| 1600 | using namespace chassis::internal; |
| 1601 | std::string result; |
| 1602 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1603 | boost::system::error_code ec = |
| 1604 | getService(ctx, bootModeIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1605 | if (!ec) |
| 1606 | { |
| 1607 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootModeIntf, |
| 1608 | "BootMode", result); |
| 1609 | if (!ec) |
| 1610 | { |
| 1611 | mode = Mode::convertModesFromString(result); |
| 1612 | return ipmi::ccSuccess; |
| 1613 | } |
| 1614 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1615 | lg2::error("Error in BootMode Get: {ERROR}", "ERROR", ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1616 | return ipmi::ccUnspecifiedError; |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1617 | } |
| 1618 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1619 | /** @brief Set the property value for boot mode |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1620 | * @param[in] ctx - context pointer |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1621 | * @param[in] mode - boot mode value |
| 1622 | * @return On failure return IPMI error. |
| 1623 | */ |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1624 | static ipmi::Cc setBootMode(ipmi::Context::ptr& ctx, const Mode::Modes& mode) |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1625 | { |
| 1626 | using namespace chassis::internal; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1627 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1628 | boost::system::error_code ec = |
| 1629 | getService(ctx, bootModeIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1630 | if (!ec) |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1631 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1632 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootModeIntf, |
| 1633 | "BootMode", convertForMessage(mode)); |
| 1634 | if (!ec) |
| 1635 | { |
| 1636 | return ipmi::ccSuccess; |
| 1637 | } |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1638 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1639 | lg2::error("Error in BootMode Set: {ERROR}", "ERROR", ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1640 | return ipmi::ccUnspecifiedError; |
| 1641 | } |
| 1642 | |
| 1643 | /** @brief Get the property value for boot type |
| 1644 | * @param[in] ctx - context pointer |
| 1645 | * @param[out] type - boot type value |
| 1646 | * @return On failure return IPMI error. |
| 1647 | */ |
| 1648 | static ipmi::Cc getBootType(ipmi::Context::ptr& ctx, Type::Types& type) |
| 1649 | { |
| 1650 | using namespace chassis::internal; |
| 1651 | std::string result; |
| 1652 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1653 | boost::system::error_code ec = |
| 1654 | getService(ctx, bootTypeIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1655 | |
| 1656 | // Don't throw error if BootType interface is not present. |
| 1657 | // This interface is not relevant for some Host architectures |
| 1658 | // (for example POWER). In this case we don't won't IPMI to |
| 1659 | // return an error, but simply return bootType as EFI. |
| 1660 | type = Type::Types::EFI; |
| 1661 | if (!ec) |
| 1662 | { |
| 1663 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf, |
| 1664 | "BootType", result); |
| 1665 | if (ec) |
| 1666 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1667 | lg2::error("Error in BootType Get: {ERROR}", "ERROR", ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1668 | return ipmi::ccUnspecifiedError; |
| 1669 | } |
| 1670 | type = Type::convertTypesFromString(result); |
| 1671 | } |
| 1672 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1673 | return ipmi::ccSuccess; |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1674 | } |
| 1675 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1676 | /** @brief Set the property value for boot type |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1677 | * @param[in] ctx - context pointer |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1678 | * @param[in] type - boot type value |
| 1679 | * @return On failure return IPMI error. |
| 1680 | */ |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1681 | static ipmi::Cc setBootType(ipmi::Context::ptr& ctx, const Type::Types& type) |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1682 | { |
| 1683 | using namespace chassis::internal; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1684 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1685 | boost::system::error_code ec = |
| 1686 | getService(ctx, bootTypeIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1687 | if (!ec) |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1688 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1689 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf, |
| 1690 | "BootType", convertForMessage(type)); |
| 1691 | if (ec) |
| 1692 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1693 | lg2::error("Error in BootType Set: {ERROR}", "ERROR", ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1694 | return ipmi::ccUnspecifiedError; |
| 1695 | } |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1696 | } |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1697 | // Don't throw error if BootType interface is not present. |
| 1698 | // This interface is not relevant for some Host architectures |
| 1699 | // (for example POWER). In this case we don't won't IPMI to |
| 1700 | // return an error, but want to just skip this function. |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1701 | return ipmi::ccSuccess; |
| 1702 | } |
| 1703 | |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1704 | /** @brief Get the property value for boot override enable |
| 1705 | * @param[in] ctx - context pointer |
| 1706 | * @param[out] enable - boot override enable |
| 1707 | * @return On failure return IPMI error. |
| 1708 | */ |
| 1709 | static ipmi::Cc getBootEnable(ipmi::Context::ptr& ctx, bool& enable) |
| 1710 | { |
| 1711 | using namespace chassis::internal; |
| 1712 | std::string result; |
| 1713 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1714 | boost::system::error_code ec = |
| 1715 | getService(ctx, bootEnableIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1716 | if (!ec) |
| 1717 | { |
| 1718 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, |
| 1719 | bootEnableIntf, "Enabled", enable); |
| 1720 | if (!ec) |
| 1721 | { |
| 1722 | return ipmi::ccSuccess; |
| 1723 | } |
| 1724 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1725 | lg2::error("Error in Boot Override Enable Get: {ERROR}", "ERROR", |
| 1726 | ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1727 | return ipmi::ccUnspecifiedError; |
| 1728 | } |
| 1729 | |
| 1730 | /** @brief Set the property value for boot override enable |
| 1731 | * @param[in] ctx - context pointer |
| 1732 | * @param[in] enable - boot override enable |
| 1733 | * @return On failure return IPMI error. |
| 1734 | */ |
| 1735 | static ipmi::Cc setBootEnable(ipmi::Context::ptr& ctx, const bool& enable) |
| 1736 | { |
| 1737 | using namespace chassis::internal; |
| 1738 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1739 | boost::system::error_code ec = |
| 1740 | getService(ctx, bootEnableIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1741 | if (!ec) |
| 1742 | { |
| 1743 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, |
| 1744 | bootEnableIntf, "Enabled", enable); |
| 1745 | if (!ec) |
| 1746 | { |
| 1747 | return ipmi::ccSuccess; |
| 1748 | } |
| 1749 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1750 | lg2::error("Error in Boot Source Override Enable Set: {ERROR}", "ERROR", |
| 1751 | ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1752 | return ipmi::ccUnspecifiedError; |
| 1753 | } |
| 1754 | |
| 1755 | /** @brief Get the property value for boot override one-time |
| 1756 | * @param[in] ctx - context pointer |
| 1757 | * @param[out] onetime - boot override one-time |
| 1758 | * @return On failure return IPMI error. |
| 1759 | */ |
| 1760 | static ipmi::Cc getBootOneTime(ipmi::Context::ptr& ctx, bool& onetime) |
| 1761 | { |
| 1762 | using namespace chassis::internal; |
| 1763 | std::string result; |
| 1764 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1765 | boost::system::error_code ec = |
| 1766 | getService(ctx, bootOneTimeIntf, bootSettingsOneTimePath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1767 | if (!ec) |
| 1768 | { |
| 1769 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsOneTimePath, |
| 1770 | bootOneTimeIntf, "Enabled", onetime); |
| 1771 | if (!ec) |
| 1772 | { |
| 1773 | return ipmi::ccSuccess; |
| 1774 | } |
| 1775 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1776 | lg2::error("Error in Boot Override OneTime Get: {ERROR}", "ERROR", |
| 1777 | ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1778 | return ipmi::ccUnspecifiedError; |
| 1779 | } |
| 1780 | |
| 1781 | /** @brief Set the property value for boot override one-time |
| 1782 | * @param[in] ctx - context pointer |
| 1783 | * @param[in] onetime - boot override one-time |
| 1784 | * @return On failure return IPMI error. |
| 1785 | */ |
| 1786 | static ipmi::Cc setBootOneTime(ipmi::Context::ptr& ctx, const bool& onetime) |
| 1787 | { |
| 1788 | using namespace chassis::internal; |
| 1789 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1790 | boost::system::error_code ec = |
| 1791 | getService(ctx, bootOneTimeIntf, bootSettingsOneTimePath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1792 | if (!ec) |
| 1793 | { |
| 1794 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsOneTimePath, |
| 1795 | bootOneTimeIntf, "Enabled", onetime); |
| 1796 | if (!ec) |
| 1797 | { |
| 1798 | return ipmi::ccSuccess; |
| 1799 | } |
| 1800 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1801 | lg2::error("Error in Boot Source Override OneTime Set: {ERROR}", "ERROR", |
| 1802 | ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1803 | return ipmi::ccUnspecifiedError; |
| 1804 | } |
| 1805 | |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1806 | static constexpr uint8_t setComplete = 0x0; |
| 1807 | static constexpr uint8_t setInProgress = 0x1; |
| 1808 | static uint8_t transferStatus = setComplete; |
Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 1809 | static uint8_t bootFlagValidBitClr = 0; |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 1810 | static uint5_t bootInitiatorAckData = 0x0; |
Hieu Huynh | 1982a3f | 2021-09-21 03:06:45 +0000 | [diff] [blame] | 1811 | static bool cmosClear = false; |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1812 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1813 | /** @brief implements the Get Chassis system boot option |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1814 | * @param ctx - context pointer |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1815 | * @param bootOptionParameter - boot option parameter selector |
| 1816 | * @param reserved1 - reserved bit |
| 1817 | * @param setSelector - selects a particular block or set of parameters |
| 1818 | * under the given parameter selector |
| 1819 | * write as 00h if parameter doesn't use a setSelector |
| 1820 | * @param blockSelector- selects a particular block within a set of |
| 1821 | * parameters write as 00h if parameter doesn't use a |
| 1822 | * blockSelector |
| 1823 | * |
| 1824 | * @return IPMI completion code plus response data |
| 1825 | * @return Payload contains below parameters: |
| 1826 | * version - parameter version |
| 1827 | * bootOptionParameter - boot option parameter selector |
Patrick Venture | 8b1c303 | 2020-09-15 09:43:03 -0700 | [diff] [blame] | 1828 | * parmIndicator - parameter valid/invalid indicator |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1829 | * data - configuration parameter data |
| 1830 | */ |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1831 | ipmi::RspType<ipmi::message::Payload> ipmiChassisGetSysBootOptions( |
| 1832 | ipmi::Context::ptr ctx, uint7_t bootOptionParameter, bool reserved1, |
| 1833 | [[maybe_unused]] uint8_t setSelector, |
| 1834 | [[maybe_unused]] uint8_t blockSelector) |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1835 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1836 | ipmi::Cc rc; |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1837 | if (reserved1) |
| 1838 | { |
| 1839 | return ipmi::responseInvalidFieldRequest(); |
| 1840 | } |
| 1841 | |
| 1842 | constexpr uint4_t version = 0x01; |
| 1843 | ipmi::message::Payload response; |
| 1844 | response.pack(version, uint4_t{}); |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1845 | using namespace boot_options; |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1846 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1847 | IpmiValue bootOption = ipmiDefault; |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1848 | |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1849 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1850 | BootOptionParameter::setInProgress) |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1851 | { |
| 1852 | response.pack(bootOptionParameter, reserved1, transferStatus); |
| 1853 | return ipmi::responseSuccess(std::move(response)); |
| 1854 | } |
| 1855 | |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1856 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1857 | BootOptionParameter::bootInfo) |
John Wang | 0213f90 | 2020-12-28 14:49:57 +0800 | [diff] [blame] | 1858 | { |
| 1859 | constexpr uint8_t writeMask = 0; |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 1860 | response.pack(bootOptionParameter, reserved1, writeMask, |
| 1861 | bootInitiatorAckData); |
John Wang | 0213f90 | 2020-12-28 14:49:57 +0800 | [diff] [blame] | 1862 | return ipmi::responseSuccess(std::move(response)); |
| 1863 | } |
| 1864 | |
Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 1865 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1866 | BootOptionParameter::bootFlagValidClr) |
| 1867 | { |
| 1868 | response.pack(bootOptionParameter, reserved1, |
| 1869 | uint5_t{bootFlagValidBitClr}, uint3_t{}); |
| 1870 | return ipmi::responseSuccess(std::move(response)); |
| 1871 | } |
| 1872 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1873 | /* |
| 1874 | * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc. |
| 1875 | * This is the only parameter used by petitboot. |
| 1876 | */ |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1877 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1878 | BootOptionParameter::bootFlags) |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1879 | { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1880 | using namespace chassis::internal; |
| 1881 | using namespace chassis::internal::cache; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1882 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1883 | try |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1884 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1885 | Source::Sources bootSource; |
| 1886 | rc = getBootSource(ctx, bootSource); |
| 1887 | if (rc != ipmi::ccSuccess) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1888 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1889 | return ipmi::response(rc); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1890 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1891 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1892 | Type::Types bootType; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1893 | rc = getBootType(ctx, bootType); |
| 1894 | if (rc != ipmi::ccSuccess) |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1895 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1896 | return ipmi::response(rc); |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1897 | } |
| 1898 | |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1899 | Mode::Modes bootMode; |
| 1900 | rc = getBootMode(ctx, bootMode); |
| 1901 | if (rc != ipmi::ccSuccess) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1902 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1903 | return ipmi::response(rc); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1904 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1905 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1906 | bootOption = sourceDbusToIpmi.at(bootSource); |
| 1907 | if ((Mode::Modes::Regular == bootMode) && |
| 1908 | (Source::Sources::Default == bootSource)) |
| 1909 | { |
| 1910 | bootOption = ipmiDefault; |
| 1911 | } |
| 1912 | else if (Source::Sources::Default == bootSource) |
| 1913 | { |
| 1914 | bootOption = modeDbusToIpmi.at(bootMode); |
| 1915 | } |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1916 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1917 | IpmiValue biosBootType = typeDbusToIpmi.at(bootType); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1918 | |
| 1919 | bool oneTimeEnabled; |
| 1920 | rc = getBootOneTime(ctx, oneTimeEnabled); |
| 1921 | if (rc != ipmi::ccSuccess) |
| 1922 | { |
| 1923 | return ipmi::response(rc); |
| 1924 | } |
| 1925 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1926 | uint1_t permanent = oneTimeEnabled ? 0 : 1; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1927 | |
| 1928 | bool valid; |
| 1929 | rc = getBootEnable(ctx, valid); |
| 1930 | if (rc != ipmi::ccSuccess) |
| 1931 | { |
| 1932 | return ipmi::response(rc); |
| 1933 | } |
| 1934 | |
| 1935 | uint1_t validFlag = valid ? 1 : 0; |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1936 | |
| 1937 | response.pack(bootOptionParameter, reserved1, uint5_t{}, |
| 1938 | uint1_t{biosBootType}, uint1_t{permanent}, |
| 1939 | uint1_t{validFlag}, uint2_t{}, uint4_t{bootOption}, |
Hieu Huynh | 1982a3f | 2021-09-21 03:06:45 +0000 | [diff] [blame] | 1940 | uint1_t{}, cmosClear, uint8_t{}, uint8_t{}, |
| 1941 | uint8_t{}); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1942 | return ipmi::responseSuccess(std::move(response)); |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1943 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 1944 | catch (const InternalFailure& e) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1945 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 1946 | cache::objectsPtr.reset(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1947 | report<InternalFailure>(); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1948 | return ipmi::responseUnspecifiedError(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1949 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1950 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1951 | else |
| 1952 | { |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1953 | if ((bootOptionParameter >= oemParmStart) && |
| 1954 | (bootOptionParameter <= oemParmEnd)) |
| 1955 | { |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1956 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1957 | BootOptionParameter::opalNetworkSettings) |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1958 | { |
| 1959 | response.pack(bootOptionParameter, reserved1); |
| 1960 | int ret = getHostNetworkData(response); |
| 1961 | if (ret < 0) |
| 1962 | { |
| 1963 | response.trailingOk = true; |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1964 | lg2::error( |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1965 | "getHostNetworkData failed for GetSysBootOptions."); |
| 1966 | return ipmi::responseUnspecifiedError(); |
| 1967 | } |
| 1968 | else |
| 1969 | { |
| 1970 | return ipmi::responseSuccess(std::move(response)); |
| 1971 | } |
| 1972 | } |
Jayaprakash Mutyala | 43a8810 | 2021-08-04 16:41:58 +0000 | [diff] [blame] | 1973 | else |
| 1974 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1975 | lg2::error( |
| 1976 | "ipmiChassisGetSysBootOptions: Unsupported parameter {PARAM}", |
| 1977 | "PARAM", lg2::hex, |
| 1978 | static_cast<uint8_t>(bootOptionParameter)); |
Jayaprakash Mutyala | 43a8810 | 2021-08-04 16:41:58 +0000 | [diff] [blame] | 1979 | return ipmi::responseParmNotSupported(); |
| 1980 | } |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1981 | } |
| 1982 | else |
| 1983 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1984 | lg2::error( |
| 1985 | "ipmiChassisGetSysBootOptions: Unsupported parameter {PARAM}", |
| 1986 | "PARAM", lg2::hex, static_cast<uint8_t>(bootOptionParameter)); |
Jayaprakash Mutyala | 6088e9f | 2021-07-14 07:40:29 +0000 | [diff] [blame] | 1987 | return ipmi::responseParmNotSupported(); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1988 | } |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1989 | } |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1990 | return ipmi::responseUnspecifiedError(); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1991 | } |
| 1992 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1993 | ipmi::RspType<> ipmiChassisSetSysBootOptions(ipmi::Context::ptr ctx, |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 1994 | uint7_t parameterSelector, bool, |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1995 | ipmi::message::Payload& data) |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1996 | { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1997 | using namespace boot_options; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1998 | ipmi::Cc rc; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1999 | |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2000 | if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2001 | BootOptionParameter::setInProgress) |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 2002 | { |
| 2003 | uint2_t setInProgressFlag; |
| 2004 | uint6_t rsvd; |
| 2005 | if (data.unpack(setInProgressFlag, rsvd) != 0 || !data.fullyUnpacked()) |
| 2006 | { |
| 2007 | return ipmi::responseReqDataLenInvalid(); |
| 2008 | } |
| 2009 | if (rsvd) |
| 2010 | { |
| 2011 | return ipmi::responseInvalidFieldRequest(); |
| 2012 | } |
| 2013 | if ((transferStatus == setInProgress) && |
| 2014 | (static_cast<uint8_t>(setInProgressFlag) != setComplete)) |
| 2015 | { |
| 2016 | return ipmi::response(IPMI_CC_FAIL_SET_IN_PROGRESS); |
| 2017 | } |
| 2018 | transferStatus = static_cast<uint8_t>(setInProgressFlag); |
| 2019 | return ipmi::responseSuccess(); |
| 2020 | } |
| 2021 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2022 | /* 000101 |
| 2023 | * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc. |
| 2024 | * This is the only parameter used by petitboot. |
| 2025 | */ |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 2026 | |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2027 | if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2028 | BootOptionParameter::bootFlags) |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2029 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2030 | uint5_t rsvd; |
| 2031 | bool validFlag; |
| 2032 | bool permanent; |
| 2033 | bool biosBootType; |
| 2034 | bool lockOutResetButton; |
| 2035 | bool screenBlank; |
| 2036 | uint4_t bootDeviceSelector; |
| 2037 | bool lockKeyboard; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2038 | uint8_t data3; |
| 2039 | uint4_t biosInfo; |
| 2040 | uint4_t rsvd1; |
| 2041 | uint5_t deviceInstance; |
| 2042 | uint3_t rsvd2; |
| 2043 | |
| 2044 | if (data.unpack(rsvd, biosBootType, permanent, validFlag, |
| 2045 | lockOutResetButton, screenBlank, bootDeviceSelector, |
| 2046 | lockKeyboard, cmosClear, data3, biosInfo, rsvd1, |
| 2047 | deviceInstance, rsvd2) != 0 || |
| 2048 | !data.fullyUnpacked()) |
| 2049 | { |
| 2050 | return ipmi::responseReqDataLenInvalid(); |
| 2051 | } |
| 2052 | if (rsvd || rsvd1 || rsvd2) |
| 2053 | { |
| 2054 | return ipmi::responseInvalidFieldRequest(); |
| 2055 | } |
| 2056 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2057 | using namespace chassis::internal; |
| 2058 | using namespace chassis::internal::cache; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2059 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2060 | try |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2061 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2062 | rc = setBootOneTime(ctx, !permanent); |
| 2063 | if (rc != ipmi::ccSuccess) |
Konstantin Aladyshev | 69e8e84 | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2064 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2065 | return ipmi::response(rc); |
| 2066 | } |
Vernon Mauery | afd45db | 2021-07-29 16:27:25 +0000 | [diff] [blame] | 2067 | |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2068 | rc = setBootEnable(ctx, validFlag); |
| 2069 | if (rc != ipmi::ccSuccess) |
| 2070 | { |
| 2071 | return ipmi::response(rc); |
Tom Joseph | 57e8eb7 | 2017-09-25 18:05:02 +0530 | [diff] [blame] | 2072 | } |
| 2073 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2074 | auto modeItr = |
| 2075 | modeIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector)); |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2076 | auto typeItr = |
| 2077 | typeIpmiToDbus.find(static_cast<uint8_t>(biosBootType)); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2078 | auto sourceItr = |
| 2079 | sourceIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector)); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2080 | if (sourceIpmiToDbus.end() != sourceItr) |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2081 | { |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 2082 | rc = setBootSource(ctx, sourceItr->second); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2083 | if (rc != ipmi::ccSuccess) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2084 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2085 | return ipmi::response(rc); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2086 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2087 | // If a set boot device is mapping to a boot source, then reset |
| 2088 | // the boot mode D-Bus property to default. |
| 2089 | // This way the ipmid code can determine which property is not |
| 2090 | // at the default value |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2091 | if (sourceItr->second != Source::Sources::Default) |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2092 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2093 | rc = setBootMode(ctx, Mode::Modes::Regular); |
| 2094 | if (rc != ipmi::ccSuccess) |
| 2095 | { |
| 2096 | return ipmi::response(rc); |
| 2097 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2098 | } |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2099 | } |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2100 | |
| 2101 | if (typeIpmiToDbus.end() != typeItr) |
| 2102 | { |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 2103 | rc = setBootType(ctx, typeItr->second); |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2104 | if (rc != ipmi::ccSuccess) |
| 2105 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2106 | return ipmi::response(rc); |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2107 | } |
| 2108 | } |
| 2109 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2110 | if (modeIpmiToDbus.end() != modeItr) |
| 2111 | { |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 2112 | rc = setBootMode(ctx, modeItr->second); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2113 | if (rc != ipmi::ccSuccess) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2114 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2115 | return ipmi::response(rc); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2116 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2117 | // If a set boot device is mapping to a boot mode, then reset |
| 2118 | // the boot source D-Bus property to default. |
| 2119 | // This way the ipmid code can determine which property is not |
| 2120 | // at the default value |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2121 | if (modeItr->second != Mode::Modes::Regular) |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2122 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2123 | rc = setBootSource(ctx, Source::Sources::Default); |
| 2124 | if (rc != ipmi::ccSuccess) |
| 2125 | { |
| 2126 | return ipmi::response(rc); |
| 2127 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2128 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2129 | } |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 2130 | if ((modeIpmiToDbus.end() == modeItr) && |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2131 | (typeIpmiToDbus.end() == typeItr) && |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 2132 | (sourceIpmiToDbus.end() == sourceItr)) |
| 2133 | { |
| 2134 | // return error if boot option is not supported |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2135 | lg2::error( |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2136 | "ipmiChassisSetSysBootOptions: Boot option not supported"); |
| 2137 | return ipmi::responseInvalidFieldRequest(); |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 2138 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2139 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 2140 | catch (const sdbusplus::exception_t& e) |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2141 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2142 | objectsPtr.reset(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2143 | report<InternalFailure>(); |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2144 | lg2::error("ipmiChassisSetSysBootOptions: Error in setting Boot " |
| 2145 | "flag parameters"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2146 | return ipmi::responseUnspecifiedError(); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 2147 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2148 | } |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2149 | else if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2150 | BootOptionParameter::bootInfo) |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2151 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2152 | uint8_t writeMak; |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 2153 | uint5_t bootInfoAck; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2154 | uint3_t rsvd; |
| 2155 | |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 2156 | if (data.unpack(writeMak, bootInfoAck, rsvd) != 0 || |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2157 | !data.fullyUnpacked()) |
| 2158 | { |
| 2159 | return ipmi::responseReqDataLenInvalid(); |
| 2160 | } |
| 2161 | if (rsvd) |
| 2162 | { |
| 2163 | return ipmi::responseInvalidFieldRequest(); |
| 2164 | } |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 2165 | bootInitiatorAckData &= ~writeMak; |
| 2166 | bootInitiatorAckData |= (writeMak & bootInfoAck); |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2167 | lg2::info("ipmiChassisSetSysBootOptions: bootInfo parameter set " |
| 2168 | "successfully"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2169 | data.trailingOk = true; |
| 2170 | return ipmi::responseSuccess(); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2171 | } |
Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 2172 | else if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2173 | BootOptionParameter::bootFlagValidClr) |
| 2174 | { |
| 2175 | uint5_t bootFlagValidClr; |
| 2176 | uint3_t rsvd; |
| 2177 | |
| 2178 | if (data.unpack(bootFlagValidClr, rsvd) != 0 || !data.fullyUnpacked()) |
| 2179 | { |
| 2180 | return ipmi::responseReqDataLenInvalid(); |
| 2181 | } |
| 2182 | if (rsvd) |
| 2183 | { |
| 2184 | return ipmi::responseInvalidFieldRequest(); |
| 2185 | } |
| 2186 | // store boot flag valid bits clear value |
| 2187 | bootFlagValidBitClr = static_cast<uint8_t>(bootFlagValidClr); |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2188 | lg2::info( |
Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 2189 | "ipmiChassisSetSysBootOptions: bootFlagValidBits parameter set " |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2190 | "successfully to {VALUE}", |
| 2191 | "VALUE", lg2::hex, bootFlagValidBitClr); |
Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 2192 | return ipmi::responseSuccess(); |
| 2193 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2194 | else |
| 2195 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2196 | if ((parameterSelector >= static_cast<uint7_t>(oemParmStart)) && |
| 2197 | (parameterSelector <= static_cast<uint7_t>(oemParmEnd))) |
| 2198 | { |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2199 | if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2200 | BootOptionParameter::opalNetworkSettings) |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2201 | { |
| 2202 | ipmi::Cc ret = setHostNetworkData(data); |
| 2203 | if (ret != ipmi::ccSuccess) |
| 2204 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2205 | lg2::error("ipmiChassisSetSysBootOptions: Error in " |
| 2206 | "setHostNetworkData"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2207 | data.trailingOk = true; |
| 2208 | return ipmi::response(ret); |
| 2209 | } |
| 2210 | data.trailingOk = true; |
| 2211 | return ipmi::responseSuccess(); |
| 2212 | } |
| 2213 | else |
| 2214 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2215 | lg2::error( |
| 2216 | "ipmiChassisSetSysBootOptions: Unsupported param: {PARAM}", |
| 2217 | "PARAM", lg2::hex, static_cast<uint8_t>(parameterSelector)); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2218 | data.trailingOk = true; |
| 2219 | return ipmi::responseParmNotSupported(); |
| 2220 | } |
| 2221 | } |
| 2222 | data.trailingOk = true; |
| 2223 | return ipmi::responseParmNotSupported(); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2224 | } |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2225 | return ipmi::responseSuccess(); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2226 | } |
| 2227 | |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2228 | /** @brief implements Get POH counter command |
| 2229 | * @parameter |
| 2230 | * - none |
| 2231 | * @returns IPMI completion code plus response data |
| 2232 | * - minPerCount - Minutes per count |
| 2233 | * - counterReading - counter reading |
| 2234 | */ |
| 2235 | ipmi::RspType<uint8_t, // Minutes per count |
| 2236 | uint32_t // Counter reading |
| 2237 | > |
| 2238 | ipmiGetPOHCounter() |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2239 | { |
| 2240 | // sd_bus error |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2241 | try |
| 2242 | { |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2243 | return ipmi::responseSuccess(static_cast<uint8_t>(poh::minutesPerCount), |
| 2244 | getPOHCounter()); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2245 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 2246 | catch (const std::exception& e) |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2247 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2248 | lg2::error("getPOHCounter error: {ERROR}", "ERROR", e); |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2249 | return ipmi::responseUnspecifiedError(); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2250 | } |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2251 | } |
| 2252 | |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2253 | ipmi::RspType<uint3_t, // policy support |
| 2254 | uint5_t // reserved |
| 2255 | > |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2256 | ipmiChassisSetPowerRestorePolicy(boost::asio::yield_context yield, |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2257 | uint3_t policy, uint5_t reserved) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2258 | { |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2259 | power_policy::DbusValue value = |
| 2260 | power_policy::RestorePolicy::Policy::AlwaysOff; |
| 2261 | |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2262 | if (reserved || (policy > power_policy::noChange)) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2263 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2264 | lg2::error("Reserved request parameter: {REQ}", "REQ", lg2::hex, |
| 2265 | static_cast<int>(policy)); |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2266 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2267 | } |
| 2268 | |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2269 | if (policy == power_policy::noChange) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2270 | { |
| 2271 | // just return the supported policy |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2272 | return ipmi::responseSuccess(power_policy::allSupport, reserved); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2273 | } |
| 2274 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 2275 | for (const auto& it : power_policy::dbusToIpmi) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2276 | { |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2277 | if (it.second == policy) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2278 | { |
| 2279 | value = it.first; |
| 2280 | break; |
| 2281 | } |
| 2282 | } |
| 2283 | |
| 2284 | try |
| 2285 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2286 | settings::Objects& objects = chassis::internal::cache::getObjects(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2287 | const settings::Path& powerRestoreSetting = |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2288 | objects.map.at(chassis::internal::powerRestoreIntf).front(); |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 2289 | std::variant<std::string> property = convertForMessage(value); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2290 | |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2291 | auto sdbusp = getSdBus(); |
| 2292 | boost::system::error_code ec; |
| 2293 | sdbusp->yield_method_call<void>( |
| 2294 | yield, ec, |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2295 | objects |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2296 | .service(powerRestoreSetting, |
| 2297 | chassis::internal::powerRestoreIntf) |
| 2298 | .c_str(), |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2299 | powerRestoreSetting, ipmi::PROP_INTF, "Set", |
| 2300 | chassis::internal::powerRestoreIntf, "PowerRestorePolicy", |
| 2301 | property); |
| 2302 | if (ec) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2303 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2304 | lg2::error("Unspecified Error"); |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2305 | return ipmi::responseUnspecifiedError(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2306 | } |
| 2307 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 2308 | catch (const InternalFailure& e) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2309 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2310 | chassis::internal::cache::objectsPtr.reset(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2311 | report<InternalFailure>(); |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2312 | return ipmi::responseUnspecifiedError(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2313 | } |
| 2314 | |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2315 | return ipmi::responseSuccess(power_policy::allSupport, reserved); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2316 | } |
| 2317 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 2318 | ipmi::RspType<> ipmiSetFrontPanelButtonEnables( |
| 2319 | ipmi::Context::ptr ctx, bool disablePowerButton, bool disableResetButton, |
| 2320 | bool, bool, uint4_t) |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 2321 | { |
| 2322 | using namespace chassis::internal; |
| 2323 | |
| 2324 | // set power button Enabled property |
| 2325 | bool success = setButtonEnabled(ctx, powerButtonPath, powerButtonIntf, |
| 2326 | !disablePowerButton); |
| 2327 | |
| 2328 | // set reset button Enabled property |
| 2329 | success &= setButtonEnabled(ctx, resetButtonPath, resetButtonIntf, |
| 2330 | !disableResetButton); |
| 2331 | |
| 2332 | if (!success) |
| 2333 | { |
| 2334 | // not all buttons were successfully set |
| 2335 | return ipmi::responseUnspecifiedError(); |
| 2336 | } |
| 2337 | return ipmi::responseSuccess(); |
| 2338 | } |
| 2339 | |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2340 | void register_netfn_chassis_functions() |
| 2341 | { |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 2342 | createIdentifyTimer(); |
| 2343 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2344 | // Get Chassis Capabilities |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 2345 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2346 | ipmi::chassis::cmdGetChassisCapabilities, |
| 2347 | ipmi::Privilege::User, ipmiGetChassisCap); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 2348 | |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 2349 | // Set Front Panel Button Enables |
| 2350 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2351 | ipmi::chassis::cmdSetFrontPanelButtonEnables, |
| 2352 | ipmi::Privilege::Admin, |
| 2353 | ipmiSetFrontPanelButtonEnables); |
| 2354 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 2355 | // Set Chassis Capabilities |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 2356 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2357 | ipmi::chassis::cmdSetChassisCapabilities, |
| 2358 | ipmi::Privilege::User, ipmiSetChassisCap); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 2359 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2360 | // <Get System Boot Options> |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2361 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2362 | ipmi::chassis::cmdGetSystemBootOptions, |
| 2363 | ipmi::Privilege::Operator, |
| 2364 | ipmiChassisGetSysBootOptions); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2365 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2366 | // <Get Chassis Status> |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 2367 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2368 | ipmi::chassis::cmdGetChassisStatus, |
| 2369 | ipmi::Privilege::User, ipmiGetChassisStatus); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 2370 | |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 2371 | // <Chassis Get System Restart Cause> |
| 2372 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2373 | ipmi::chassis::cmdGetSystemRestartCause, |
| 2374 | ipmi::Privilege::User, ipmiGetSystemRestartCause); |
| 2375 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2376 | // <Chassis Control> |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 2377 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2378 | ipmi::chassis::cmdChassisControl, |
| 2379 | ipmi::Privilege::Operator, ipmiChassisControl); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2380 | |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 2381 | // <Chassis Identify> |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 2382 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2383 | ipmi::chassis::cmdChassisIdentify, |
| 2384 | ipmi::Privilege::Operator, ipmiChassisIdentify); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 2385 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2386 | // <Set System Boot Options> |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2387 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2388 | ipmi::chassis::cmdSetSystemBootOptions, |
| 2389 | ipmi::Privilege::Operator, |
| 2390 | ipmiChassisSetSysBootOptions); |
| 2391 | |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2392 | // <Get POH Counter> |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2393 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2394 | ipmi::chassis::cmdGetPohCounter, |
| 2395 | ipmi::Privilege::User, ipmiGetPOHCounter); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2396 | |
| 2397 | // <Set Power Restore Policy> |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2398 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2399 | ipmi::chassis::cmdSetPowerRestorePolicy, |
| 2400 | ipmi::Privilege::Operator, |
| 2401 | ipmiChassisSetPowerRestorePolicy); |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 2402 | } |