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