Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2018 Intel Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | */ |
| 17 | #pragma once |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 18 | #include <ipmid/iana.hpp> |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 19 | |
| 20 | #include <cstdint> |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 21 | #include <optional> |
| 22 | #include <tuple> |
| 23 | |
| 24 | namespace ipmi |
| 25 | { |
| 26 | |
| 27 | using Iana = oem::Number; |
| 28 | |
| 29 | using Group = uint8_t; |
| 30 | constexpr Group groupPICMG = 0x00; |
| 31 | constexpr Group groupDMTG = 0x01; |
| 32 | constexpr Group groupSSI = 0x02; |
| 33 | constexpr Group groupVSO = 0x03; |
| 34 | constexpr Group groupDCMI = 0xDC; |
| 35 | |
| 36 | /* |
| 37 | * Set the priority as the lowest number that is necessary so |
| 38 | * it is possible that others can override it if desired. |
| 39 | * This may be linked to what level of integration the handler |
| 40 | * is being created at. |
| 41 | */ |
| 42 | constexpr int prioOpenBmcBase = 10; |
| 43 | constexpr int prioOemBase = 20; |
| 44 | constexpr int prioOdmBase = 30; |
| 45 | constexpr int prioCustomBase = 40; |
| 46 | constexpr int prioMax = 50; |
| 47 | |
| 48 | /* |
| 49 | * Channel IDs pulled from the IPMI 2.0 specification |
| 50 | */ |
| 51 | constexpr int channelPrimaryIpmb = 0x00; |
| 52 | // 0x01-0x0B Implementation specific |
| 53 | // Implementation specific channel numbers are specified |
| 54 | // by a configuration file external to ipmid |
| 55 | // 0x0C-0x0D reserved |
| 56 | constexpr int channelCurrentIface = 0x0E; // 'Present I/F' |
| 57 | constexpr int channelSystemIface = 0x0F; |
| 58 | |
| 59 | /* |
| 60 | * Specifies the minimum privilege level required to execute the command |
| 61 | * This means the command can be executed at a given privilege level or higher |
| 62 | * privilege level. Those commands which can be executed via system interface |
| 63 | * only should use SYSTEM_INTERFACE |
| 64 | */ |
| 65 | enum class Privilege : uint8_t |
| 66 | { |
| 67 | None = 0x00, |
| 68 | Callback, |
| 69 | User, |
| 70 | Operator, |
| 71 | Admin, |
| 72 | Oem, |
| 73 | }; |
| 74 | |
| 75 | // IPMI Net Function number as specified by IPMI V2.0 spec. |
| 76 | using NetFn = uint8_t; |
| 77 | |
| 78 | // IPMI Command for a Net Function number as specified by IPMI V2.0 spec. |
| 79 | using Cmd = uint8_t; |
| 80 | |
| 81 | // ipmi function return the status code |
| 82 | using Cc = uint8_t; |
| 83 | |
| 84 | // IPMI 2.0 and DCMI 1.5 standard commands, namespaced by NetFn |
| 85 | // OEM and non-standard commands should be defined where they are used |
| 86 | namespace app |
| 87 | { |
| 88 | // 0x00 reserved |
| 89 | constexpr Cmd cmdGetDeviceId = 0x01; |
| 90 | constexpr Cmd cmdColdReset = 0x02; |
| 91 | constexpr Cmd cmdWarmReset = 0x03; |
| 92 | constexpr Cmd cmdGetSelfTestResults = 0x04; |
| 93 | constexpr Cmd cmdManufacturingTestOn = 0x05; |
| 94 | constexpr Cmd cmdSetAcpiPowerState = 0x06; |
| 95 | constexpr Cmd cmdGetAcpiPowerState = 0x07; |
| 96 | constexpr Cmd cmdGetDeviceGuid = 0x08; |
| 97 | constexpr Cmd cmdGetNetFnSupport = 0x09; |
| 98 | constexpr Cmd cmdGetCmdSupport = 0x0A; |
| 99 | constexpr Cmd cmdGetCmdSubFnSupport = 0x0B; |
| 100 | constexpr Cmd cmdGetConfigurableCmds = 0x0C; |
| 101 | constexpr Cmd cmdGetConfigurableCmdSubFns = 0x0D; |
| 102 | // 0x0E-0x21 unassigned |
| 103 | constexpr Cmd cmdResetWatchdogTimer = 0x22; |
| 104 | // 0x23 unassigned |
| 105 | constexpr Cmd cmdSetWatchdogTimer = 0x24; |
| 106 | constexpr Cmd cmdGetWatchdogTimer = 0x25; |
| 107 | // 0x26-0x2D unassigned |
| 108 | constexpr Cmd cmdSetBmcGlobalEnables = 0x2E; |
| 109 | constexpr Cmd cmdGetBmcGlobalEnables = 0x2F; |
| 110 | constexpr Cmd cmdClearMessageFlags = 0x30; |
| 111 | constexpr Cmd cmdGetMessageFlags = 0x31; |
| 112 | constexpr Cmd cmdEnableMessageChannelRcv = 0x32; |
| 113 | constexpr Cmd cmdGetMessage = 0x33; |
| 114 | constexpr Cmd cmdSendMessage = 0x34; |
| 115 | constexpr Cmd cmdReadEventMessageBuffer = 0x35; |
| 116 | constexpr Cmd cmdGetBtIfaceCapabilities = 0x36; |
| 117 | constexpr Cmd cmdGetSystemGuid = 0x37; |
| 118 | constexpr Cmd cmdGetChannelAuthCapabilities = 0x38; |
| 119 | constexpr Cmd cmdGetSessionChallenge = 0x39; |
| 120 | constexpr Cmd cmdActivateSession = 0x3A; |
| 121 | constexpr Cmd cmdSetSessionPrivilegeLevel = 0x3B; |
| 122 | constexpr Cmd cmdCloseSession = 0x3C; |
| 123 | constexpr Cmd cmdGetSessionInfo = 0x3D; |
| 124 | // 0x3E unassigned |
| 125 | constexpr Cmd cmdGetAuthCode = 0x3F; |
| 126 | constexpr Cmd cmdSetChannelAccess = 0x40; |
| 127 | constexpr Cmd cmdGetChannelAccess = 0x41; |
| 128 | constexpr Cmd cmdGetChannelInfoCommand = 0x42; |
| 129 | constexpr Cmd cmdSetUserAccessCommand = 0x43; |
| 130 | constexpr Cmd cmdGetUserAccessCommand = 0x44; |
| 131 | constexpr Cmd cmdSetUserName = 0x45; |
| 132 | constexpr Cmd cmdGetUserNameCommand = 0x46; |
| 133 | constexpr Cmd cmdSetUserPasswordCommand = 0x47; |
| 134 | constexpr Cmd cmdActivatePayload = 0x48; |
| 135 | constexpr Cmd cmdDeactivatePayload = 0x49; |
| 136 | constexpr Cmd cmdGetPayloadActivationStatus = 0x4A; |
| 137 | constexpr Cmd cmdGetPayloadInstanceInfo = 0x4B; |
| 138 | constexpr Cmd cmdSetUserPayloadAccess = 0x4C; |
| 139 | constexpr Cmd cmdGetUserPayloadAccess = 0x4D; |
| 140 | constexpr Cmd cmdGetChannelPayloadSupport = 0x4E; |
| 141 | constexpr Cmd cmdGetChannelPayloadVersion = 0x4F; |
| 142 | constexpr Cmd cmdGetChannelOemPayloadInfo = 0x50; |
| 143 | // 0x51 unassigned |
| 144 | constexpr Cmd cmdMasterWriteRead = 0x52; |
| 145 | // 0x53 unassigned |
| 146 | constexpr Cmd cmdGetChannelCipherSuites = 0x54; |
| 147 | constexpr Cmd cmdSuspendResumePayloadEnc = 0x55; |
| 148 | constexpr Cmd cmdSetChannelSecurityKeys = 0x56; |
| 149 | constexpr Cmd cmdGetSystemIfCapabilities = 0x57; |
| 150 | constexpr Cmd cmdSetSystemInfoParameters = 0x58; |
| 151 | constexpr Cmd cmdGetSystemInfoParameters = 0x59; |
| 152 | // 0x5A-0x5F unassigned |
| 153 | constexpr Cmd cmdSetCommandEnables = 0x60; |
| 154 | constexpr Cmd cmdGetCommandEnables = 0x61; |
| 155 | constexpr Cmd cmdSetCommandSubFnEnables = 0x62; |
| 156 | constexpr Cmd cmdGetCommandSubFnEnables = 0x63; |
| 157 | constexpr Cmd cmdGetOemNetFnIanaSupport = 0x64; |
| 158 | // 0x65-0xff unassigned |
| 159 | } // namespace app |
| 160 | |
| 161 | namespace chassis |
| 162 | { |
| 163 | constexpr Cmd cmdGetChassisCapabilities = 0x00; |
| 164 | constexpr Cmd cmdGetChassisStatus = 0x01; |
| 165 | constexpr Cmd cmdChassisControl = 0x02; |
| 166 | constexpr Cmd cmdChassisReset = 0x03; |
| 167 | constexpr Cmd cmdChassisIdentify = 0x04; |
| 168 | constexpr Cmd cmdSetChassisCapabilities = 0x05; |
| 169 | constexpr Cmd cmdSetPowerRestorePolicy = 0x06; |
| 170 | constexpr Cmd cmdGetSystemRestartCause = 0x07; |
| 171 | constexpr Cmd cmdSetSystemBootOptions = 0x08; |
| 172 | constexpr Cmd cmdGetSystemBootOptions = 0x09; |
| 173 | constexpr Cmd cmdSetFrontPanelButtonEnables = 0x0A; |
| 174 | constexpr Cmd cmdSetPowerCycleInterval = 0x0B; |
| 175 | // 0x0C-0x0E unassigned |
| 176 | constexpr Cmd cmdGetPohCounter = 0x0F; |
| 177 | // 0x10-0xFF unassigned |
| 178 | } // namespace chassis |
| 179 | |
| 180 | namespace sensor_event |
| 181 | { |
| 182 | constexpr Cmd cmdSetEventReceiver = 0x00; |
| 183 | constexpr Cmd cmdGetEventReceiver = 0x01; |
| 184 | constexpr Cmd cmdPlatformEvent = 0x02; |
| 185 | // 0x03-0x0F unassigned |
| 186 | constexpr Cmd cmdGetPefCapabilities = 0x10; |
| 187 | constexpr Cmd cmdArmPefPostponeTimer = 0x11; |
| 188 | constexpr Cmd cmdSetPefConfigurationParams = 0x12; |
| 189 | constexpr Cmd cmdGetPefConfigurationParams = 0x13; |
| 190 | constexpr Cmd cmdSetLastProcessedEventId = 0x14; |
| 191 | constexpr Cmd cmdGetLastProcessedEventId = 0x15; |
| 192 | constexpr Cmd cmdAlertImmediate = 0x16; |
| 193 | constexpr Cmd cmdPetAcknowledge = 0x17; |
| 194 | constexpr Cmd cmdGetDeviceSdrInfo = 0x20; |
| 195 | constexpr Cmd cmdGetDeviceSdr = 0x21; |
| 196 | constexpr Cmd cmdReserveDeviceSdrRepository = 0x22; |
| 197 | constexpr Cmd cmdGetSensorReadingFactors = 0x23; |
| 198 | constexpr Cmd cmdSetSensorHysteresis = 0x24; |
| 199 | constexpr Cmd cmdGetSensorHysteresis = 0x25; |
| 200 | constexpr Cmd cmdSetSensorThreshold = 0x26; |
| 201 | constexpr Cmd cmdGetSensorThreshold = 0x27; |
| 202 | constexpr Cmd cmdSetSensorEventEnable = 0x28; |
| 203 | constexpr Cmd cmdGetSensorEventEnable = 0x29; |
| 204 | constexpr Cmd cmdRearmSensorEvents = 0x2A; |
| 205 | constexpr Cmd cmdGetSensorEventStatus = 0x2B; |
| 206 | constexpr Cmd cmdGetSensorReading = 0x2D; |
| 207 | constexpr Cmd cmdSetSensorType = 0x2E; |
| 208 | constexpr Cmd cmdGetSensorType = 0x2F; |
| 209 | constexpr Cmd cmdSetSensorReadingAndEvtSts = 0x30; |
| 210 | // 0x31-0xFF unassigned |
| 211 | } // namespace sensor_event |
| 212 | |
| 213 | namespace storage |
| 214 | { |
| 215 | // 0x00-0x0F unassigned |
| 216 | constexpr Cmd cmdGetFruInventoryAreaInfo = 0x10; |
| 217 | constexpr Cmd cmdReadFruData = 0x11; |
| 218 | constexpr Cmd cmdWriteFruData = 0x12; |
| 219 | // 0x13-0x1F unassigned |
| 220 | constexpr Cmd cmdGetSdrRepositoryInfo = 0x20; |
| 221 | constexpr Cmd cmdGetSdrRepositoryAllocInfo = 0x21; |
| 222 | constexpr Cmd cmdReserveSdrRepository = 0x22; |
| 223 | constexpr Cmd cmdGetSdr = 0x23; |
| 224 | constexpr Cmd cmdAddSdr = 0x24; |
| 225 | constexpr Cmd cmdPartialAddSdr = 0x25; |
| 226 | constexpr Cmd cmdDeleteSdr = 0x26; |
| 227 | constexpr Cmd cmdClearSdrRepository = 0x27; |
| 228 | constexpr Cmd cmdGetSdrRepositoryTime = 0x28; |
| 229 | constexpr Cmd cmdSetSdrRepositoryTime = 0x29; |
| 230 | constexpr Cmd cmdEnterSdrRepoUpdateMode = 0x2A; |
| 231 | constexpr Cmd cmdExitSdrReposUpdateMode = 0x2B; |
| 232 | constexpr Cmd cmdRunInitializationAgent = 0x2C; |
| 233 | // 0x2D-0x3F unassigned |
| 234 | constexpr Cmd cmdGetSelInfo = 0x40; |
| 235 | constexpr Cmd cmdGetSelAllocationInfo = 0x41; |
| 236 | constexpr Cmd cmdReserveSel = 0x42; |
| 237 | constexpr Cmd cmdGetSelEntry = 0x43; |
| 238 | constexpr Cmd cmdAddSelEntry = 0x44; |
| 239 | constexpr Cmd cmdPartialAddSelEntry = 0x45; |
| 240 | constexpr Cmd cmdDeleteSelEntry = 0x46; |
| 241 | constexpr Cmd cmdClearSel = 0x47; |
| 242 | constexpr Cmd cmdGetSelTime = 0x48; |
| 243 | constexpr Cmd cmdSetSelTime = 0x49; |
| 244 | constexpr Cmd cmdGetAuxiliaryLogStatus = 0x5A; |
| 245 | constexpr Cmd cmdSetAuxiliaryLogStatus = 0x5B; |
| 246 | constexpr Cmd cmdGetSelTimeUtcOffset = 0x5C; |
| 247 | constexpr Cmd cmdSetSelTimeUtcOffset = 0x5D; |
| 248 | // 0x5E-0xFF unassigned |
| 249 | } // namespace storage |
| 250 | |
| 251 | namespace transport |
| 252 | { |
| 253 | constexpr Cmd cmdSetLanConfigParameters = 0x01; |
| 254 | constexpr Cmd cmdGetLanConfigParameters = 0x02; |
| 255 | constexpr Cmd cmdSuspendBmcArps = 0x03; |
| 256 | constexpr Cmd cmdGetIpUdpRmcpStatistics = 0x04; |
| 257 | constexpr Cmd cmdSetSerialModemConfig = 0x10; |
| 258 | constexpr Cmd cmdGetSerialModemConfig = 0x11; |
| 259 | constexpr Cmd cmdSetSerialModemMux = 0x12; |
| 260 | constexpr Cmd cmdGetTapResponseCodes = 0x13; |
| 261 | constexpr Cmd cmdSetPppUdpProxyTransmitData = 0x14; |
| 262 | constexpr Cmd cmdGetPppUdpProxyTransmitData = 0x15; |
| 263 | constexpr Cmd cmdSendPppUdpProxyPacket = 0x16; |
| 264 | constexpr Cmd cmdGetPppUdpProxyReceiveData = 0x17; |
| 265 | constexpr Cmd cmdSerialModemConnActive = 0x18; |
| 266 | constexpr Cmd cmdCallback = 0x19; |
| 267 | constexpr Cmd cmdSetUserCallbackOptions = 0x1A; |
| 268 | constexpr Cmd cmdGetUserCallbackOptions = 0x1B; |
| 269 | constexpr Cmd cmdSetSerialRoutingMux = 0x1C; |
| 270 | constexpr Cmd cmdSolActivating = 0x20; |
| 271 | constexpr Cmd cmdSetSolConfigParameters = 0x21; |
| 272 | constexpr Cmd cmdGetSolConfigParameters = 0x22; |
| 273 | constexpr Cmd cmdForwardedCommand = 0x30; |
| 274 | constexpr Cmd cmdSetForwardedCommands = 0x31; |
| 275 | constexpr Cmd cmdGetForwardedCommands = 0x32; |
| 276 | constexpr Cmd cmdEnableForwardedCommands = 0x33; |
| 277 | } // namespace transport |
| 278 | |
| 279 | namespace bridge |
| 280 | { |
| 281 | constexpr Cmd cmdGetBridgeState = 0x00; |
| 282 | constexpr Cmd cmdSetBridgeState = 0x01; |
| 283 | constexpr Cmd cmdGetIcmbAddress = 0x02; |
| 284 | constexpr Cmd cmdSetIcmbAddress = 0x03; |
| 285 | constexpr Cmd cmdSetBridgeProxyAddress = 0x04; |
| 286 | constexpr Cmd cmdGetBridgeStatistics = 0x05; |
| 287 | constexpr Cmd cmdGetIcmbCapabilities = 0x06; |
| 288 | constexpr Cmd cmdClearBridgeStatistics = 0x08; |
| 289 | constexpr Cmd cmdGetBridgeProxyAddress = 0x09; |
| 290 | constexpr Cmd cmdGetIcmbConnectorInfo = 0x0A; |
| 291 | constexpr Cmd cmdGetIcmbConnectionId = 0x0B; |
| 292 | constexpr Cmd cmdSendIcmbConnectionId = 0x0C; |
| 293 | constexpr Cmd cmdPrepareForDiscovery = 0x10; |
| 294 | constexpr Cmd cmdGetAddresses = 0x11; |
| 295 | constexpr Cmd cmdSetDiscovered = 0x12; |
| 296 | constexpr Cmd cmdGetChassisDeviceId = 0x13; |
| 297 | constexpr Cmd cmdSetChassisDeviceId = 0x14; |
| 298 | constexpr Cmd cmdBridgeRequest = 0x20; |
| 299 | constexpr Cmd cmdBridgeMessage = 0x21; |
| 300 | // 0x22-0x2F unassigned |
| 301 | constexpr Cmd cmdGetEventCount = 0x30; |
| 302 | constexpr Cmd cmdSetEventDestination = 0x31; |
| 303 | constexpr Cmd cmdSetEventReceptionState = 0x32; |
| 304 | constexpr Cmd cmdSendIcmbEventMessage = 0x33; |
| 305 | constexpr Cmd cmdGetEventDestination = 0x34; |
| 306 | constexpr Cmd cmdGetEventReceptionState = 0x35; |
| 307 | // 0xC0-0xFE OEM Commands |
| 308 | constexpr Cmd cmdErrorReport = 0xFF; |
| 309 | } // namespace bridge |
| 310 | |
| 311 | namespace dcmi |
| 312 | { |
| 313 | constexpr Cmd cmdGetDcmiCapabilitiesInfo = 0x01; |
| 314 | constexpr Cmd cmdGetPowerReading = 0x02; |
| 315 | constexpr Cmd cmdGetPowerLimit = 0x03; |
| 316 | constexpr Cmd cmdSetPowerLimit = 0x04; |
| 317 | constexpr Cmd cmdActDeactivatePwrLimit = 0x05; |
| 318 | constexpr Cmd cmdGetAssetTag = 0x06; |
| 319 | constexpr Cmd cmdGetDcmiSensorInfo = 0x07; |
| 320 | constexpr Cmd cmdSetAssetTag = 0x08; |
| 321 | constexpr Cmd cmdGetMgmtCntlrIdString = 0x09; |
| 322 | constexpr Cmd cmdSetMgmtCntlrIdString = 0x0A; |
| 323 | constexpr Cmd cmdSetThermalLimit = 0x0B; |
| 324 | constexpr Cmd cmdGetThermalLimit = 0x0C; |
| 325 | constexpr Cmd cmdGetTemperatureReadings = 0x10; |
| 326 | constexpr Cmd cmdSetDcmiConfigParameters = 0x12; |
| 327 | constexpr Cmd cmdGetDcmiConfigParameters = 0x13; |
| 328 | } // namespace dcmi |
| 329 | |
| 330 | // These are the command network functions, the response |
| 331 | // network functions are the function + 1. So to determine |
| 332 | // the proper network function which issued the command |
| 333 | // associated with a response, subtract 1. |
| 334 | // Note: these will be left shifted when combined with the LUN |
| 335 | constexpr NetFn netFnChassis = 0x00; |
| 336 | constexpr NetFn netFnBridge = 0x02; |
| 337 | constexpr NetFn netFnSensor = 0x04; |
| 338 | constexpr NetFn netFnApp = 0x06; |
| 339 | constexpr NetFn netFnFirmware = 0x08; |
| 340 | constexpr NetFn netFnStorage = 0x0A; |
| 341 | constexpr NetFn netFnTransport = 0x0C; |
| 342 | // reserved 0Eh..28h |
| 343 | constexpr NetFn netFnGroup = 0x2C; |
| 344 | constexpr NetFn netFnOem = 0x2E; |
| 345 | constexpr NetFn netFnOemOne = 0x30; |
| 346 | constexpr NetFn netFnOemTwo = 0x32; |
| 347 | constexpr NetFn netFnOemThree = 0x34; |
| 348 | constexpr NetFn netFnOemFour = 0x36; |
| 349 | constexpr NetFn netFnOemFive = 0x38; |
| 350 | constexpr NetFn netFnOemSix = 0x3A; |
| 351 | constexpr NetFn netFnOemSeven = 0x3C; |
| 352 | constexpr NetFn netFnOemEight = 0x3E; |
| 353 | |
| 354 | // IPMI commands for net functions. Callbacks using this should be careful to |
| 355 | // parse arguments to the sub-functions and can take advantage of the built-in |
| 356 | // message handling mechanism to create custom routing |
| 357 | constexpr Cmd cmdWildcard = 0xFF; |
| 358 | |
| 359 | // IPMI standard completion codes specified by the IPMI V2.0 spec. |
| 360 | // |
| 361 | // This might have been an enum class, but that would make it hard for |
| 362 | // OEM- and command-specific completion codes to be added elsewhere. |
| 363 | // |
| 364 | // Custom completion codes can be defined in individual modules for |
| 365 | // command specific errors in the 0x80-0xBE range |
| 366 | // |
| 367 | // Alternately, OEM completion codes are in the 0x01-0x7E range |
| 368 | constexpr Cc ccSuccess = 0x00; |
| 369 | constexpr Cc ccBusy = 0xC0; |
| 370 | constexpr Cc ccInvalidCommand = 0xC1; |
| 371 | constexpr Cc ccInvalidCommandOnLun = 0xC2; |
Karol Niczyj | d18dfc4 | 2021-07-15 14:18:56 +0200 | [diff] [blame] | 372 | constexpr Cc ccTimeout = 0xC3; |
Sharad Yadav | a0de400 | 2021-01-05 17:38:30 +0530 | [diff] [blame] | 373 | constexpr Cc ccOutOfSpace = 0xC4; |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 374 | constexpr Cc ccInvalidReservationId = 0xC5; |
| 375 | constexpr Cc ccReqDataTruncated = 0xC6; |
| 376 | constexpr Cc ccReqDataLenInvalid = 0xC7; |
| 377 | constexpr Cc ccReqDataLenExceeded = 0xC8; |
| 378 | constexpr Cc ccParmOutOfRange = 0xC9; |
| 379 | constexpr Cc ccRetBytesUnavailable = 0xCA; |
| 380 | constexpr Cc ccSensorInvalid = 0xCB; |
| 381 | constexpr Cc ccInvalidFieldRequest = 0xCC; |
| 382 | constexpr Cc ccIllegalCommand = 0xCD; |
| 383 | constexpr Cc ccResponseError = 0xCE; |
| 384 | constexpr Cc ccDuplicateRequest = 0xCF; |
| 385 | constexpr Cc ccCmdFailSdrMode = 0xD0; |
| 386 | constexpr Cc ccCmdFailFwUpdMode = 0xD1; |
| 387 | constexpr Cc ccCmdFailInitAgent = 0xD2; |
| 388 | constexpr Cc ccDestinationUnavailable = 0xD3; |
| 389 | constexpr Cc ccInsufficientPrivilege = 0xD4; |
| 390 | constexpr Cc ccCommandNotAvailable = 0xD5; |
| 391 | constexpr Cc ccCommandDisabled = 0xD6; |
| 392 | constexpr Cc ccUnspecifiedError = 0xFF; |
| 393 | |
| 394 | /* ipmi often has two return types: |
| 395 | * 1. Failure: CC is non-zero; no trailing data |
| 396 | * 2. Success: CC is zero; trailing data (usually a fixed type) |
| 397 | * |
| 398 | * using ipmi::response(cc, ...), it will automatically always pack |
| 399 | * the correct type for the response without having to explicitly type out all |
| 400 | * the parameters that the function would return. |
| 401 | * |
| 402 | * To enable this feature, you just define the ipmi function as returning an |
| 403 | * ipmi::RspType which has the optional trailing data built in, with your types |
| 404 | * defined as parameters. |
| 405 | */ |
| 406 | |
| 407 | template <typename... RetTypes> |
| 408 | using RspType = std::tuple<ipmi::Cc, std::optional<std::tuple<RetTypes...>>>; |
| 409 | |
| 410 | /** |
| 411 | * @brief helper function to create an IPMI response tuple |
| 412 | * |
| 413 | * IPMI handlers all return a tuple with two parts: a completion code and an |
| 414 | * optional tuple containing the rest of the data to return. This helper |
| 415 | * function makes it easier by constructing that out of an arbitrary number of |
| 416 | * arguments. |
| 417 | * |
| 418 | * @param cc - the completion code for the response |
| 419 | * @param args... - the optional list of values to return |
| 420 | * |
| 421 | * @return a standard IPMI return type (as described above) |
| 422 | */ |
| 423 | template <typename... Args> |
| 424 | static inline auto response(ipmi::Cc cc, Args&&... args) |
| 425 | { |
| 426 | return std::make_tuple(cc, std::make_optional(std::make_tuple(args...))); |
| 427 | } |
| 428 | static inline auto response(ipmi::Cc cc) |
| 429 | { |
| 430 | return std::make_tuple(cc, std::nullopt); |
| 431 | } |
| 432 | |
| 433 | /** |
| 434 | * @brief helper function to create an IPMI success response tuple |
| 435 | * |
| 436 | * IPMI handlers all return a tuple with two parts: a completion code and an |
| 437 | * optional tuple containing the rest of the data to return. This helper |
| 438 | * function makes it easier by constructing that out of an arbitrary number of |
| 439 | * arguments. Because it is a success response, this automatically packs |
| 440 | * the completion code, without needing to explicitly pass it in. |
| 441 | * |
| 442 | * @param args... - the optional list of values to return |
| 443 | * |
| 444 | * @return a standard IPMI return type (as described above) |
| 445 | */ |
| 446 | template <typename... Args> |
| 447 | static inline auto responseSuccess(Args&&... args) |
| 448 | { |
Vernon Mauery | bea5392 | 2019-04-03 09:37:43 -0700 | [diff] [blame] | 449 | return response(ipmi::ccSuccess, args...); |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 450 | } |
| 451 | static inline auto responseSuccess() |
| 452 | { |
Vernon Mauery | bea5392 | 2019-04-03 09:37:43 -0700 | [diff] [blame] | 453 | return response(ipmi::ccSuccess); |
| 454 | } |
| 455 | |
| 456 | /* helper functions for the various standard error response types */ |
| 457 | static inline auto responseBusy() |
| 458 | { |
| 459 | return response(ccBusy); |
| 460 | } |
| 461 | static inline auto responseInvalidCommand() |
| 462 | { |
| 463 | return response(ccInvalidCommand); |
| 464 | } |
| 465 | static inline auto responseInvalidCommandOnLun() |
| 466 | { |
| 467 | return response(ccInvalidCommandOnLun); |
| 468 | } |
| 469 | static inline auto responseTimeout() |
| 470 | { |
| 471 | return response(ccTimeout); |
| 472 | } |
| 473 | static inline auto responseOutOfSpace() |
| 474 | { |
| 475 | return response(ccOutOfSpace); |
| 476 | } |
| 477 | static inline auto responseInvalidReservationId() |
| 478 | { |
| 479 | return response(ccInvalidReservationId); |
| 480 | } |
| 481 | static inline auto responseReqDataTruncated() |
| 482 | { |
| 483 | return response(ccReqDataTruncated); |
| 484 | } |
| 485 | static inline auto responseReqDataLenInvalid() |
| 486 | { |
| 487 | return response(ccReqDataLenInvalid); |
| 488 | } |
| 489 | static inline auto responseReqDataLenExceeded() |
| 490 | { |
| 491 | return response(ccReqDataLenExceeded); |
| 492 | } |
| 493 | static inline auto responseParmOutOfRange() |
| 494 | { |
| 495 | return response(ccParmOutOfRange); |
| 496 | } |
| 497 | static inline auto responseRetBytesUnavailable() |
| 498 | { |
| 499 | return response(ccRetBytesUnavailable); |
| 500 | } |
| 501 | static inline auto responseSensorInvalid() |
| 502 | { |
| 503 | return response(ccSensorInvalid); |
| 504 | } |
| 505 | static inline auto responseInvalidFieldRequest() |
| 506 | { |
| 507 | return response(ccInvalidFieldRequest); |
| 508 | } |
| 509 | static inline auto responseIllegalCommand() |
| 510 | { |
| 511 | return response(ccIllegalCommand); |
| 512 | } |
| 513 | static inline auto responseResponseError() |
| 514 | { |
| 515 | return response(ccResponseError); |
| 516 | } |
| 517 | static inline auto responseDuplicateRequest() |
| 518 | { |
| 519 | return response(ccDuplicateRequest); |
| 520 | } |
| 521 | static inline auto responseCmdFailSdrMode() |
| 522 | { |
| 523 | return response(ccCmdFailSdrMode); |
| 524 | } |
| 525 | static inline auto responseCmdFailFwUpdMode() |
| 526 | { |
| 527 | return response(ccCmdFailFwUpdMode); |
| 528 | } |
| 529 | static inline auto responseCmdFailInitAgent() |
| 530 | { |
| 531 | return response(ccCmdFailInitAgent); |
| 532 | } |
| 533 | static inline auto responseDestinationUnavailable() |
| 534 | { |
| 535 | return response(ccDestinationUnavailable); |
| 536 | } |
| 537 | static inline auto responseInsufficientPrivilege() |
| 538 | { |
| 539 | return response(ccInsufficientPrivilege); |
| 540 | } |
| 541 | static inline auto responseCommandNotAvailable() |
| 542 | { |
| 543 | return response(ccCommandNotAvailable); |
| 544 | } |
| 545 | static inline auto responseCommandDisabled() |
| 546 | { |
| 547 | return response(ccCommandDisabled); |
| 548 | } |
| 549 | static inline auto responseUnspecifiedError() |
| 550 | { |
| 551 | return response(ccUnspecifiedError); |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | } // namespace ipmi |