blob: f5641ddcafbc0ae80d53be3043a4a7648e34661a [file] [log] [blame]
vishwabmcba0bd5f2015-09-30 16:50:23 +05301#ifndef __HOST_IPMID_IPMI_COMMON_H__
2#define __HOST_IPMID_IPMI_COMMON_H__
vishwabmcba0bd5f2015-09-30 16:50:23 +05303
Patrick Venture2edd0e62018-10-25 16:10:10 -07004#include <systemd/sd-bus.h>
Joel Stanleyc99350c2015-11-25 17:27:25 +10305
Patrick Venturee86e7852020-05-07 17:41:23 -07006#include <cstddef>
7
Tom05732372016-09-06 17:21:23 +05308/*
9 * Specifies the minimum privilege level required to execute the command
10 * This means the command can be executed at a given privilege level or higher
11 * privilege level. Those commands which can be executed via system interface
12 * only should use SYSTEM_INTERFACE
13 */
Patrick Venture0b02be92018-08-31 11:55:55 -070014enum CommandPrivilege
15{
16 PRIVILEGE_CALLBACK = 0x01,
17 PRIVILEGE_USER,
18 PRIVILEGE_OPERATOR,
19 PRIVILEGE_ADMIN,
20 PRIVILEGE_OEM,
21 SYSTEM_INTERFACE = 0xFF,
Tom05732372016-09-06 17:21:23 +053022};
23
vishwabmcba0bd5f2015-09-30 16:50:23 +053024// IPMI Net Function number as specified by IPMI V2.0 spec.
Gunnar Millsd8249ee2018-04-12 16:33:53 -050025// Example :
vishwabmcba0bd5f2015-09-30 16:50:23 +053026// NETFUN_APP = (0x06 << 2),
Patrick Venture0b02be92018-08-31 11:55:55 -070027typedef unsigned char ipmi_netfn_t;
vishwabmcba0bd5f2015-09-30 16:50:23 +053028
29// IPMI Command for a Net Function number as specified by IPMI V2.0 spec.
Patrick Venture0b02be92018-08-31 11:55:55 -070030typedef unsigned char ipmi_cmd_t;
vishwabmcba0bd5f2015-09-30 16:50:23 +053031
32// Buffer containing data from sender of netfn and command as part of request
Patrick Venture0b02be92018-08-31 11:55:55 -070033typedef void* ipmi_request_t;
vishwabmcba0bd5f2015-09-30 16:50:23 +053034
35// This is the response buffer that the provider of [netfn,cmd] will send back
36// to the caller. Provider will allocate the memory inside the handler and then
37// will do a memcpy to this response buffer and also will set the data size
38// parameter to the size of the buffer.
39// EXAMPLE :
40// unsigned char str[] = {0x00, 0x01, 0xFE, 0xFF, 0x0A, 0x01};
41// *data_len = 6;
42// memcpy(response, &str, *data_len);
Patrick Venture0b02be92018-08-31 11:55:55 -070043typedef void* ipmi_response_t;
vishwabmcba0bd5f2015-09-30 16:50:23 +053044
45// This buffer contains any *user specific* data that is of interest only to the
46// plugin. For a ipmi function router, this data is opaque. At the time of
47// registering the plugin handlers, plugin may optionally allocate a memory and
48// fill in whatever needed that will be of help during the actual handling of
49// command. IPMID will just pass the netfn, cmd and also this data to plugins
50// during the command handler invocation.
Patrick Venture0b02be92018-08-31 11:55:55 -070051typedef void* ipmi_context_t;
vishwabmcba0bd5f2015-09-30 16:50:23 +053052
53// Length of request / response buffer depending on whether the data is a
54// request or a response from a plugin handler.
Patrick Venturee86e7852020-05-07 17:41:23 -070055typedef std::size_t* ipmi_data_len_t;
vishwabmcba0bd5f2015-09-30 16:50:23 +053056
57// Plugin function return the status code
58typedef unsigned char ipmi_ret_t;
59
Tom05732372016-09-06 17:21:23 +053060typedef enum CommandPrivilege ipmi_cmd_privilege_t;
61
vishwabmcba0bd5f2015-09-30 16:50:23 +053062// This is the callback handler that the plugin registers with IPMID. IPMI
63// function router will then make a call to this callback handler with the
64// necessary arguments of netfn, cmd, request, response, size and context.
65typedef ipmi_ret_t (*ipmid_callback_t)(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
Patrick Venture0b02be92018-08-31 11:55:55 -070066 ipmi_response_t, ipmi_data_len_t,
67 ipmi_context_t);
vishwabmcba0bd5f2015-09-30 16:50:23 +053068
69// This is the constructor function that is called into by each plugin handlers.
70// When ipmi sets up the callback handlers, a call is made to this with
71// information of netfn, cmd, callback handler pointer and context data.
Patrick Venture0b02be92018-08-31 11:55:55 -070072void ipmi_register_callback(ipmi_netfn_t, ipmi_cmd_t, ipmi_context_t,
73 ipmid_callback_t, ipmi_cmd_privilege_t);
vishwabmcba0bd5f2015-09-30 16:50:23 +053074
Jason M. Bills13e67c82018-09-10 14:12:16 -070075unsigned short reserveSel(void);
76bool checkSELReservation(unsigned short id);
77void cancelSELReservation(void);
Nan Li36c0cb62016-03-31 11:16:08 +080078
vishwabmcba0bd5f2015-09-30 16:50:23 +053079// These are the command network functions, the response
80// network functions are the function + 1. So to determine
81// the proper network function which issued the command
82// associated with a response, subtract 1.
83// Note: these are also shifted left to make room for the LUN.
84enum ipmi_net_fns
85{
Patrick Venture0b02be92018-08-31 11:55:55 -070086 NETFUN_CHASSIS = 0x00,
87 NETFUN_BRIDGE = 0x02,
88 NETFUN_SENSOR = 0x04,
89 NETFUN_APP = 0x06,
90 NETFUN_FIRMWARE = 0x08,
91 NETFUN_STORAGE = 0x0a,
92 NETFUN_TRANSPORT = 0x0c,
93 NETFUN_GRPEXT = 0x2c,
94 NETFUN_OEM_GROUP = 0x2e,
95 NETFUN_NONE = 0x30,
96 NETFUN_OEM = 0x32,
97 NETFUN_IBM_OEM = 0x3A
vishwabmcba0bd5f2015-09-30 16:50:23 +053098};
99
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500100// Return (completion) codes from a IPMI operation as needed by IPMI V2.0 spec.
vishwabmcba0bd5f2015-09-30 16:50:23 +0530101enum ipmi_return_codes
102{
103 IPMI_CC_OK = 0x00,
Chris Austen1810bec2015-10-13 12:12:39 -0500104 IPMI_DCMI_CC_NO_ACTIVE_POWER_LIMIT = 0x80,
William A. Kennington III5325f2c2018-01-08 15:17:09 -0800105 IPMI_WDOG_CC_NOT_INIT = 0x80,
Xo Wangf542e8b2017-08-09 15:34:16 -0700106 IPMI_CC_SYSTEM_INFO_PARAMETER_NOT_SUPPORTED = 0x80,
107 IPMI_CC_SYSTEM_INFO_PARAMETER_SET_READ_ONLY = 0x82,
William A. Kennington III6ae3df32018-01-18 11:19:30 -0800108 IPMI_CC_BUSY = 0xC0,
Chris Austen8339f9d2015-10-21 20:07:31 -0500109 IPMI_CC_INVALID = 0xC1,
Patrick Venturead359eb2018-11-12 15:03:54 -0800110 IPMI_CC_TIMEOUT = 0xC3,
111 IPMI_CC_OUT_OF_SPACE = 0xC4,
Nan Li36c0cb62016-03-31 11:16:08 +0800112 IPMI_CC_INVALID_RESERVATION_ID = 0xC5,
Patrick Venturead359eb2018-11-12 15:03:54 -0800113 IPMI_CC_REQ_DATA_TRUNCATED = 0xC6,
Tom63a3db72016-09-23 18:20:52 +0530114 IPMI_CC_REQ_DATA_LEN_INVALID = 0xC7,
Chris Austenc2cd29d2016-02-05 20:02:29 -0600115 IPMI_CC_PARM_OUT_OF_RANGE = 0xC9,
Patrick Venturead359eb2018-11-12 15:03:54 -0800116 IPMI_CC_REQUESTED_TOO_MANY_BYTES = 0xCA,
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500117 IPMI_CC_SENSOR_INVALID = 0xCB,
Tom Joseph50234ad2017-03-20 18:51:38 +0530118 IPMI_CC_INVALID_FIELD_REQUEST = 0xCC,
Jayanth Othayoth0922bde2018-04-02 07:59:34 -0500119 IPMI_CC_ILLEGAL_COMMAND = 0xCD,
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500120 IPMI_CC_RESPONSE_ERROR = 0xCE,
Tom Joseph9a61b4f2016-07-11 06:56:11 -0500121 IPMI_CC_INSUFFICIENT_PRIVILEGE = 0xD4,
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500122 IPMI_CC_UNSPECIFIED_ERROR = 0xFF,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530123};
124
ssekarb8491102018-08-16 17:31:43 +0530125// Temp solution: To detect the request source channel.
126// There is no stright forward way to get the exact
127// channel so we are hardcoding it to KCS in case host-ipmid
128// and LAN1 for netipmid.
129// we can't differentiate between LAN1 & LAN2 for netipmid in this logic.
130// As our current design will not be able to support the same. This is done
131// so that in all the places where ever we need to use the self channel can be
132// be implemented properly and based on new architecture.this can be updated.
133typedef enum
134{
135 interfaceKCS = 0,
136 interfaceLAN1 = 1,
137 interfaceUnknown = 0xFF
138} EInterfaceIndex;
139
140EInterfaceIndex getInterfaceIndex(void);
141
Patrick Venture0b02be92018-08-31 11:55:55 -0700142sd_bus* ipmid_get_sd_bus_connection(void);
Patrick Williams3b301a32025-02-03 13:05:36 -0500143sd_event* ipmid_get_sd_event_connection(void);
Joel Stanleyc99350c2015-11-25 17:27:25 +1030144
Vernon Mauery392050f2019-04-01 14:53:19 -0700145// move this from ipmid.hpp, which is now gone
146// this should not be used. Use the channel API to get the channel size
147#define MAX_IPMI_BUFFER 64
148
vishwabmcba0bd5f2015-09-30 16:50:23 +0530149#endif