blob: 45391ecac9353431ce754a0ccc551eca28da8f38 [file] [log] [blame]
Vernon Mauerye7329c72018-10-08 12:05:16 -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#pragma once
17
18#include <ipmid/api.hpp>
Vernon Mauery08a70aa2018-11-07 09:36:22 -080019#include <ipmid/filter.hpp>
Vernon Mauerye7329c72018-10-08 12:05:16 -070020#include <ipmid/handler.hpp>
21
22namespace ipmi
23{
24
25namespace impl
26{
27
28// IPMI command handler registration implementation
29bool registerHandler(int prio, NetFn netFn, Cmd cmd, Privilege priv,
30 ::ipmi::HandlerBase::ptr handler);
Vernon Maueryf984a012018-10-08 12:05:18 -070031bool registerGroupHandler(int prio, Group group, Cmd cmd, Privilege priv,
32 ::ipmi::HandlerBase::ptr handler);
33bool registerOemHandler(int prio, Iana iana, Cmd cmd, Privilege priv,
34 ::ipmi::HandlerBase::ptr handler);
35
Vernon Mauery08a70aa2018-11-07 09:36:22 -080036// IPMI command filter registration implementation
37void registerFilter(int prio, ::ipmi::FilterBase::ptr filter);
38
Vernon Mauerye7329c72018-10-08 12:05:16 -070039} // namespace impl
40
41/**
42 * @brief main IPMI handler registration function
43 *
44 * This function should be used to register all new-style IPMI handler
45 * functions. This function just passes the callback to makeHandler, which
46 * creates a new wrapper object that will automatically extract the appropriate
47 * parameters for the callback function as well as pack up the response.
48 *
49 * @param prio - priority at which to register; see api.hpp
50 * @param netFn - the IPMI net function number to register
51 * @param cmd - the IPMI command number to register
52 * @param priv - the IPMI user privilige required for this command
53 * @param handler - the callback function that will handle this request
54 *
55 * @return bool - success of registering the handler
56 */
57template <typename Handler>
58bool registerHandler(int prio, NetFn netFn, Cmd cmd, Privilege priv,
59 Handler&& handler)
60{
61 auto h = ipmi::makeHandler(std::forward<Handler>(handler));
62 return impl::registerHandler(prio, netFn, cmd, priv, h);
63}
64
Vernon Maueryf984a012018-10-08 12:05:18 -070065/**
66 * @brief register a IPMI OEM group handler
67 *
68 * From IPMI 2.0 spec Network Function Codes Table (Row 2Ch):
69 * The first data byte position in requests and responses under this network
70 * function identifies the defining body that specifies command functionality.
71 * Software assumes that the command and completion code field positions will
72 * hold command and completion code values.
73 *
74 * The following values are used to identify the defining body:
75 * 00h PICMG - PCI Industrial Computer Manufacturer’s Group. (www.picmg.com)
76 * 01h DMTF Pre-OS Working Group ASF Specification (www.dmtf.org)
77 * 02h Server System Infrastructure (SSI) Forum (www.ssiforum.org)
78 * 03h VITA Standards Organization (VSO) (www.vita.com)
79 * DCh DCMI Specifications (www.intel.com/go/dcmi)
80 * all other Reserved
81 *
82 * When this network function is used, the ID for the defining body occupies
83 * the first data byte in a request, and the second data byte (following the
84 * completion code) in a response.
85 *
86 * @tparam Handler - implicitly specified callback function type
87 * @param prio - priority at which to register; see api.hpp
88 * @param netFn - the IPMI net function number to register
89 * @param cmd - the IPMI command number to register
90 * @param priv - the IPMI user privilige required for this command
91 * @param handler - the callback function that will handle this request
92 *
93 * @return bool - success of registering the handler
94 *
95 */
96template <typename Handler>
97void registerGroupHandler(int prio, Group group, Cmd cmd, Privilege priv,
98 Handler&& handler)
99{
100 auto h = ipmi::makeHandler(handler);
101 impl::registerGroupHandler(prio, group, cmd, priv, h);
102}
103
104/**
105 * @brief register a IPMI OEM IANA handler
106 *
107 * From IPMI spec Network Function Codes Table (Row 2Eh):
108 * The first three data bytes of requests and responses under this network
109 * function explicitly identify the OEM or non-IPMI group that specifies the
110 * command functionality. While the OEM or non-IPMI group defines the
111 * functional semantics for the cmd and remaining data fields, the cmd field
112 * is required to hold the same value in requests and responses for a given
113 * operation in order to be supported under the IPMI message handling and
114 * transport mechanisms.
115 *
116 * When this network function is used, the IANA Enterprise Number for the
117 * defining body occupies the first three data bytes in a request, and the
118 * first three data bytes following the completion code position in a
119 * response.
120 *
121 * @tparam Handler - implicitly specified callback function type
122 * @param prio - priority at which to register; see api.hpp
123 * @param netFn - the IPMI net function number to register
124 * @param cmd - the IPMI command number to register
125 * @param priv - the IPMI user privilige required for this command
126 * @param handler - the callback function that will handle this request
127 *
128 * @return bool - success of registering the handler
129 *
130 */
131template <typename Handler>
132void registerOemHandler(int prio, Iana iana, Cmd cmd, Privilege priv,
133 Handler&& handler)
134{
135 auto h = ipmi::makeHandler(handler);
136 impl::registerOemHandler(prio, iana, cmd, priv, h);
137}
138
Vernon Mauery08a70aa2018-11-07 09:36:22 -0800139/**
140 * @brief IPMI command filter registration function
141 *
142 * This function should be used to register IPMI command filter functions.
143 * This function just passes the callback to makeFilter, which creates a
144 * wrapper functor object that ultimately calls the callback.
145 *
146 * Filters are called with a ipmi::message::Request shared_ptr on all IPMI
147 * commands in priority order and each filter has the opportunity to reject the
148 * command (by returning an IPMI error competion code.) If all the filters
149 * return success, the actual IPMI command will be executed. Filters can reject
150 * the command for any reason, based on system state, the context, the command
151 * payload, etc.
152 *
153 * @param prio - priority at which to register; see api.hpp
154 * @param filter - the callback function that will handle this request
155 *
156 * @return bool - success of registering the handler
157 */
158template <typename Filter>
159void registerFilter(int prio, Filter&& filter)
160{
161 auto f = ipmi::makeFilter(std::forward<Filter>(filter));
162 impl::registerFilter(prio, f);
163}
164
165template <typename Filter>
166void registerFilter(int prio, const Filter& filter)
167{
168 auto f = ipmi::makeFilter(filter);
169 impl::registerFilter(prio, f);
170}
Vernon Mauerye7329c72018-10-08 12:05:16 -0700171} // namespace ipmi
172
173#ifdef ALLOW_DEPRECATED_API
174/**
175 * @brief legacy IPMI handler registration function
176 *
177 * This function should be used to register all legacy IPMI handler
178 * functions. This function just behaves just as the legacy registration
179 * mechanism did, silently replacing any existing handler with a new one.
180 *
181 * @param netFn - the IPMI net function number to register
182 * @param cmd - the IPMI command number to register
183 * @param context - ignored
184 * @param handler - the callback function that will handle this request
185 * @param priv - the IPMI user privilige required for this command
186 */
187// [[deprecated("Use ipmi::registerHandler() instead")]]
188void ipmi_register_callback(ipmi_netfn_t netFn, ipmi_cmd_t cmd,
189 ipmi_context_t context, ipmid_callback_t handler,
190 ipmi_cmd_privilege_t priv);
191
192#endif /* ALLOW_DEPRECATED_API */
193
194// IPMI 2.0 and DCMI 1.5 standard commands, namespaced by NetFn
195// OEM and non-standard commands should be defined where they are used
196namespace ipmi
197{
198namespace app
199{
200// 0x00 reserved
201constexpr Cmd cmdGetDeviceId = 0x01;
202constexpr Cmd cmdColdReset = 0x02;
203constexpr Cmd cmdWarmReset = 0x03;
204constexpr Cmd cmdGetSelfTestResults = 0x04;
205constexpr Cmd cmdManufacturingTestOn = 0x05;
206constexpr Cmd cmdSetAcpiPowerState = 0x06;
207constexpr Cmd cmdGetAcpiPowerState = 0x07;
208constexpr Cmd cmdGetDeviceGuid = 0x08;
209constexpr Cmd cmdGetNetFnSupport = 0x09;
210constexpr Cmd cmdGetCmdSupport = 0x0A;
211constexpr Cmd cmdGetCmdSubFnSupport = 0x0B;
212constexpr Cmd cmdGetConfigurableCmds = 0x0C;
213constexpr Cmd cmdGetConfigurableCmdSubFns = 0x0D;
214// 0x0E-0x21 unassigned
215constexpr Cmd cmdResetWatchdogTimer = 0x22;
216// 0x23 unassigned
217constexpr Cmd cmdSetWatchdogTimer = 0x24;
218constexpr Cmd cmdGetWatchdogTimer = 0x25;
219// 0x26-0x2D unassigned
220constexpr Cmd cmdSetBmcGlobalEnables = 0x2E;
221constexpr Cmd cmdGetBmcGlobalEnables = 0x2F;
222constexpr Cmd cmdClearMessageFlags = 0x30;
223constexpr Cmd cmdGetMessageFlags = 0x31;
224constexpr Cmd cmdEnableMessageChannelRcv = 0x32;
225constexpr Cmd cmdGetMessage = 0x33;
226constexpr Cmd cmdSendMessage = 0x34;
227constexpr Cmd cmdReadEventMessageBuffer = 0x35;
228constexpr Cmd cmdGetBtIfaceCapabilities = 0x36;
229constexpr Cmd cmdGetSystemGuid = 0x37;
230constexpr Cmd cmdGetChannelAuthCapabilities = 0x38;
231constexpr Cmd cmdGetSessionChallenge = 0x39;
232constexpr Cmd cmdActivateSession = 0x3A;
233constexpr Cmd cmdSetSessionPrivilegeLevel = 0x3B;
234constexpr Cmd cmdCloseSession = 0x3C;
235constexpr Cmd cmdGetSessionInfo = 0x3D;
236// 0x3E unassigned
237constexpr Cmd cmdGetAuthCode = 0x3F;
238constexpr Cmd cmdSetChannelAccess = 0x40;
239constexpr Cmd cmdGetChannelAccess = 0x41;
240constexpr Cmd cmdGetChannelInfoCommand = 0x42;
241constexpr Cmd cmdSetUserAccessCommand = 0x43;
242constexpr Cmd cmdGetUserAccessCommand = 0x44;
243constexpr Cmd cmdSetUserName = 0x45;
244constexpr Cmd cmdGetUserNameCommand = 0x46;
245constexpr Cmd cmdSetUserPasswordCommand = 0x47;
246constexpr Cmd cmdActivatePayload = 0x48;
247constexpr Cmd cmdDeactivatePayload = 0x49;
248constexpr Cmd cmdGetPayloadActivationStatus = 0x4A;
249constexpr Cmd cmdGetPayloadInstanceInfo = 0x4B;
250constexpr Cmd cmdSetUserPayloadAccess = 0x4C;
251constexpr Cmd cmdGetUserPayloadAccess = 0x4D;
252constexpr Cmd cmdGetChannelPayloadSupport = 0x4E;
253constexpr Cmd cmdGetChannelPayloadVersion = 0x4F;
254constexpr Cmd cmdGetChannelOemPayloadInfo = 0x50;
255// 0x51 unassigned
256constexpr Cmd cmdMasterWriteRead = 0x52;
257// 0x53 unassigned
258constexpr Cmd cmdGetChannelCipherSuites = 0x54;
259constexpr Cmd cmdSuspendResumePayloadEnc = 0x55;
260constexpr Cmd cmdSetChannelSecurityKeys = 0x56;
261constexpr Cmd cmdGetSystemIfCapabilities = 0x57;
262constexpr Cmd cmdSetSystemInfoParameters = 0x58;
263constexpr Cmd cmdGetSystemInfoParameters = 0x59;
264// 0x5A-0x5F unassigned
265constexpr Cmd cmdSetCommandEnables = 0x60;
266constexpr Cmd cmdGetCommandEnables = 0x61;
267constexpr Cmd cmdSetCommandSubFnEnables = 0x62;
268constexpr Cmd cmdGetCommandSubFnEnables = 0x63;
269constexpr Cmd cmdGetOemNetFnIanaSupport = 0x64;
270// 0x65-0xff unassigned
271} // namespace app
272
273namespace chassis
274{
275constexpr Cmd cmdGetChassisCapabilities = 0x00;
276constexpr Cmd cmdGetChassisStatus = 0x01;
277constexpr Cmd cmdChassisControl = 0x02;
278constexpr Cmd cmdChassisReset = 0x03;
279constexpr Cmd cmdChassisIdentify = 0x04;
280constexpr Cmd cmdSetChassisCapabilities = 0x05;
281constexpr Cmd cmdSetPowerRestorePolicy = 0x06;
282constexpr Cmd cmdGetSystemRestartCause = 0x07;
283constexpr Cmd cmdSetSystemBootOptions = 0x08;
284constexpr Cmd cmdGetSystemBootOptions = 0x09;
285constexpr Cmd cmdSetFrontPanelButtonEnables = 0x0A;
286constexpr Cmd cmdSetPowerCycleInterval = 0x0B;
287// 0x0C-0x0E unassigned
288constexpr Cmd cmdGetPohCounter = 0x0F;
289// 0x10-0xFF unassigned
290} // namespace chassis
291
292namespace sensor_event
293{
294constexpr Cmd cmdSetEventReceiver = 0x00;
295constexpr Cmd cmdGetEventReceiver = 0x01;
296constexpr Cmd cmdPlatformEvent = 0x02;
297// 0x03-0x0F unassigned
298constexpr Cmd cmdGetPefCapabilities = 0x10;
299constexpr Cmd cmdArmPefPostponeTimer = 0x11;
300constexpr Cmd cmdSetPefConfigurationParams = 0x12;
301constexpr Cmd cmdGetPefConfigurationParams = 0x13;
302constexpr Cmd cmdSetLastProcessedEventId = 0x14;
303constexpr Cmd cmdGetLastProcessedEventId = 0x15;
304constexpr Cmd cmdAlertImmediate = 0x16;
305constexpr Cmd cmdPetAcknowledge = 0x17;
306constexpr Cmd cmdGetDeviceSdrInfo = 0x20;
307constexpr Cmd cmdGetDeviceSdr = 0x21;
308constexpr Cmd cmdReserveDeviceSdrRepository = 0x22;
309constexpr Cmd cmdGetSensorReadingFactors = 0x23;
310constexpr Cmd cmdSetSensorHysteresis = 0x24;
311constexpr Cmd cmdGetSensorHysteresis = 0x25;
312constexpr Cmd cmdSetSensorThreshold = 0x26;
313constexpr Cmd cmdGetSensorThreshold = 0x27;
314constexpr Cmd cmdSetSensorEventEnable = 0x28;
315constexpr Cmd cmdGetSensorEventEnable = 0x29;
316constexpr Cmd cmdRearmSensorEvents = 0x2A;
317constexpr Cmd cmdGetSensorEventStatus = 0x2B;
318constexpr Cmd cmdGetSensorReading = 0x2D;
319constexpr Cmd cmdSetSensorType = 0x2E;
320constexpr Cmd cmdGetSensorType = 0x2F;
321constexpr Cmd cmdSetSensorReadingAndEvtSts = 0x30;
322// 0x31-0xFF unassigned
323} // namespace sensor_event
324
325namespace storage
326{
327// 0x00-0x0F unassigned
328constexpr Cmd cmdGetFruInventoryAreaInfo = 0x10;
329constexpr Cmd cmdReadFruData = 0x11;
330constexpr Cmd cmdWriteFruData = 0x12;
331// 0x13-0x1F unassigned
332constexpr Cmd cmdGetSdrRepositoryInfo = 0x20;
333constexpr Cmd cmdGetSdrRepositoryAllocInfo = 0x21;
334constexpr Cmd cmdReserveSdrRepository = 0x22;
335constexpr Cmd cmdGetSdr = 0x23;
336constexpr Cmd cmdAddSdr = 0x24;
337constexpr Cmd cmdPartialAddSdr = 0x25;
338constexpr Cmd cmdDeleteSdr = 0x26;
339constexpr Cmd cmdClearSdrRepository = 0x27;
340constexpr Cmd cmdGetSdrRepositoryTime = 0x28;
341constexpr Cmd cmdSetSdrRepositoryTime = 0x29;
342constexpr Cmd cmdEnterSdrRepoUpdateMode = 0x2A;
343constexpr Cmd cmdExitSdrReposUpdateMode = 0x2B;
344constexpr Cmd cmdRunInitializationAgent = 0x2C;
345// 0x2D-0x3F unassigned
346constexpr Cmd cmdGetSelInfo = 0x40;
347constexpr Cmd cmdGetSelAllocationInfo = 0x41;
348constexpr Cmd cmdReserveSel = 0x42;
349constexpr Cmd cmdGetSelEntry = 0x43;
350constexpr Cmd cmdAddSelEntry = 0x44;
351constexpr Cmd cmdPartialAddSelEntry = 0x45;
352constexpr Cmd cmdDeleteSelEntry = 0x46;
353constexpr Cmd cmdClearSel = 0x47;
354constexpr Cmd cmdGetSelTime = 0x48;
355constexpr Cmd cmdSetSelTime = 0x49;
356constexpr Cmd cmdGetAuxiliaryLogStatus = 0x5A;
357constexpr Cmd cmdSetAuxiliaryLogStatus = 0x5B;
358constexpr Cmd cmdGetSelTimeUtcOffset = 0x5C;
359constexpr Cmd cmdSetSelTimeUtcOffset = 0x5D;
360// 0x5E-0xFF unassigned
361} // namespace storage
362
363namespace transport
364{
365constexpr Cmd cmdSetLanConfigParameters = 0x01;
366constexpr Cmd cmdGetLanConfigParameters = 0x02;
367constexpr Cmd cmdSuspendBmcArps = 0x03;
368constexpr Cmd cmdGetIpUdpRmcpStatistics = 0x04;
369constexpr Cmd cmdSetSerialModemConfig = 0x10;
370constexpr Cmd cmdGetSerialModemConfig = 0x11;
371constexpr Cmd cmdSetSerialModemMux = 0x12;
372constexpr Cmd cmdGetTapResponseCodes = 0x13;
373constexpr Cmd cmdSetPppUdpProxyTransmitData = 0x14;
374constexpr Cmd cmdGetPppUdpProxyTransmitData = 0x15;
375constexpr Cmd cmdSendPppUdpProxyPacket = 0x16;
376constexpr Cmd cmdGetPppUdpProxyReceiveData = 0x17;
377constexpr Cmd cmdSerialModemConnActive = 0x18;
378constexpr Cmd cmdCallback = 0x19;
379constexpr Cmd cmdSetUserCallbackOptions = 0x1A;
380constexpr Cmd cmdGetUserCallbackOptions = 0x1B;
381constexpr Cmd cmdSetSerialRoutingMux = 0x1C;
382constexpr Cmd cmdSolActivating = 0x20;
383constexpr Cmd cmdSetSolConfigParameters = 0x21;
384constexpr Cmd cmdGetSolConfigParameters = 0x22;
385constexpr Cmd cmdForwardedCommand = 0x30;
386constexpr Cmd cmdSetForwardedCommands = 0x31;
387constexpr Cmd cmdGetForwardedCommands = 0x32;
388constexpr Cmd cmdEnableForwardedCommands = 0x33;
389} // namespace transport
390
391namespace bridge
392{
393constexpr Cmd cmdGetBridgeState = 0x00;
394constexpr Cmd cmdSetBridgeState = 0x01;
395constexpr Cmd cmdGetIcmbAddress = 0x02;
396constexpr Cmd cmdSetIcmbAddress = 0x03;
397constexpr Cmd cmdSetBridgeProxyAddress = 0x04;
398constexpr Cmd cmdGetBridgeStatistics = 0x05;
399constexpr Cmd cmdGetIcmbCapabilities = 0x06;
400constexpr Cmd cmdClearBridgeStatistics = 0x08;
401constexpr Cmd cmdGetBridgeProxyAddress = 0x09;
402constexpr Cmd cmdGetIcmbConnectorInfo = 0x0A;
403constexpr Cmd cmdGetIcmbConnectionId = 0x0B;
404constexpr Cmd cmdSendIcmbConnectionId = 0x0C;
405constexpr Cmd cmdPrepareForDiscovery = 0x10;
406constexpr Cmd cmdGetAddresses = 0x11;
407constexpr Cmd cmdSetDiscovered = 0x12;
408constexpr Cmd cmdGetChassisDeviceId = 0x13;
409constexpr Cmd cmdSetChassisDeviceId = 0x14;
410constexpr Cmd cmdBridgeRequest = 0x20;
411constexpr Cmd cmdBridgeMessage = 0x21;
412// 0x22-0x2F unassigned
413constexpr Cmd cmdGetEventCount = 0x30;
414constexpr Cmd cmdSetEventDestination = 0x31;
415constexpr Cmd cmdSetEventReceptionState = 0x32;
416constexpr Cmd cmdSendIcmbEventMessage = 0x33;
417constexpr Cmd cmdGetEventDestination = 0x34;
418constexpr Cmd cmdGetEventReceptionState = 0x35;
419// 0xC0-0xFE OEM Commands
420constexpr Cmd cmdErrorReport = 0xFF;
421} // namespace bridge
422
423namespace dcmi
424{
425constexpr Cmd cmdGetDcmiCapabilitiesInfo = 0x01;
426constexpr Cmd cmdGetPowerReading = 0x02;
427constexpr Cmd cmdGetPowerLimit = 0x03;
428constexpr Cmd cmdSetPowerLimit = 0x04;
429constexpr Cmd cmdActDeactivatePwrLimit = 0x05;
430constexpr Cmd cmdGetAssetTag = 0x06;
431constexpr Cmd cmdGetDcmiSensorInfo = 0x07;
432constexpr Cmd cmdSetAssetTag = 0x08;
433constexpr Cmd cmdGetMgmtCntlrIdString = 0x09;
434constexpr Cmd cmdSetMgmtCntlrIdString = 0x0A;
435constexpr Cmd cmdSetThermalLimit = 0x0B;
436constexpr Cmd cmdGetThermalLimit = 0x0C;
437constexpr Cmd cmdGetTemperatureReadings = 0x10;
438constexpr Cmd cmdSetDcmiConfigParameters = 0x12;
439constexpr Cmd cmdGetDcmiConfigParameters = 0x13;
440} // namespace dcmi
441
442} // namespace ipmi