xref: /openbmc/phosphor-host-ipmid/include/ipmid/api.h (revision e58eb308e561bcc0ddb6ad9cf479e35b214ab46d)
1 #ifndef __HOST_IPMID_IPMI_COMMON_H__
2 #define __HOST_IPMID_IPMI_COMMON_H__
3 
4 #include <systemd/sd-bus.h>
5 
6 #include <cstddef>
7 
8 /*
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  */
14 enum CommandPrivilege
15 {
16     PRIVILEGE_CALLBACK = 0x01,
17     PRIVILEGE_USER,
18     PRIVILEGE_OPERATOR,
19     PRIVILEGE_ADMIN,
20     PRIVILEGE_OEM,
21     SYSTEM_INTERFACE = 0xFF,
22 };
23 
24 // IPMI Net Function number as specified by IPMI V2.0 spec.
25 // Example :
26 // NETFUN_APP      =   (0x06 << 2),
27 typedef unsigned char ipmi_netfn_t;
28 
29 // IPMI Command for a Net Function number as specified by IPMI V2.0 spec.
30 typedef unsigned char ipmi_cmd_t;
31 
32 // Buffer containing data from sender of netfn and command as part of request
33 typedef void* ipmi_request_t;
34 
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);
43 typedef void* ipmi_response_t;
44 
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.
51 typedef void* ipmi_context_t;
52 
53 // Length of request / response buffer depending on whether the data is a
54 // request or a response from a plugin handler.
55 typedef std::size_t* ipmi_data_len_t;
56 
57 // Plugin function return the status code
58 typedef unsigned char ipmi_ret_t;
59 
60 typedef enum CommandPrivilege ipmi_cmd_privilege_t;
61 
62 // 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.
65 typedef ipmi_ret_t (*ipmid_callback_t)(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
66                                        ipmi_response_t, ipmi_data_len_t,
67                                        ipmi_context_t);
68 
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.
72 void ipmi_register_callback(ipmi_netfn_t, ipmi_cmd_t, ipmi_context_t,
73                             ipmid_callback_t, ipmi_cmd_privilege_t);
74 
75 unsigned short reserveSel(void);
76 bool checkSELReservation(unsigned short id);
77 void cancelSELReservation(void);
78 
79 // 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.
84 enum __attribute__((deprecated(
85     "Deprecated enum: use netfn values from ipmi-api.hpp; this enum will be removed after 31-Dec-2025")))
86 ipmi_net_fns
87 {
88     NETFUN_CHASSIS = 0x00,
89     NETFUN_BRIDGE = 0x02,
90     NETFUN_SENSOR = 0x04,
91     NETFUN_APP = 0x06,
92     NETFUN_FIRMWARE = 0x08,
93     NETFUN_STORAGE = 0x0a,
94     NETFUN_TRANSPORT = 0x0c,
95     NETFUN_GRPEXT = 0x2c,
96     NETFUN_OEM_GROUP = 0x2e,
97     NETFUN_NONE = 0x30,
98     NETFUN_OEM = 0x32,
99     NETFUN_IBM_OEM = 0x3A
100 };
101 
102 // Return (completion) codes from a IPMI operation as needed by IPMI V2.0 spec.
103 enum ipmi_return_codes
104 {
105     IPMI_CC_OK = 0x00,
106     IPMI_DCMI_CC_NO_ACTIVE_POWER_LIMIT = 0x80,
107     IPMI_WDOG_CC_NOT_INIT = 0x80,
108     IPMI_CC_SYSTEM_INFO_PARAMETER_NOT_SUPPORTED = 0x80,
109     IPMI_CC_SYSTEM_INFO_PARAMETER_SET_READ_ONLY = 0x82,
110     IPMI_CC_BUSY = 0xC0,
111     IPMI_CC_INVALID = 0xC1,
112     IPMI_CC_TIMEOUT = 0xC3,
113     IPMI_CC_OUT_OF_SPACE = 0xC4,
114     IPMI_CC_INVALID_RESERVATION_ID = 0xC5,
115     IPMI_CC_REQ_DATA_TRUNCATED = 0xC6,
116     IPMI_CC_REQ_DATA_LEN_INVALID = 0xC7,
117     IPMI_CC_PARM_OUT_OF_RANGE = 0xC9,
118     IPMI_CC_REQUESTED_TOO_MANY_BYTES = 0xCA,
119     IPMI_CC_SENSOR_INVALID = 0xCB,
120     IPMI_CC_INVALID_FIELD_REQUEST = 0xCC,
121     IPMI_CC_ILLEGAL_COMMAND = 0xCD,
122     IPMI_CC_RESPONSE_ERROR = 0xCE,
123     IPMI_CC_INSUFFICIENT_PRIVILEGE = 0xD4,
124     IPMI_CC_UNSPECIFIED_ERROR = 0xFF,
125 };
126 
127 // Temp solution: To detect the request source channel.
128 // There is no stright forward way to get the exact
129 // channel so we are hardcoding it to KCS in case host-ipmid
130 // and LAN1 for netipmid.
131 // we can't differentiate between LAN1 & LAN2 for netipmid in this logic.
132 // As our current design will not be able to support the same. This is done
133 // so that in all the places where ever we need to use the self channel can be
134 // be implemented properly and based on new architecture.this can be updated.
135 typedef enum
136 {
137     interfaceKCS = 0,
138     interfaceLAN1 = 1,
139     interfaceUnknown = 0xFF
140 } EInterfaceIndex;
141 
142 EInterfaceIndex getInterfaceIndex(void);
143 
144 sd_bus* ipmid_get_sd_bus_connection(void);
145 sd_event* ipmid_get_sd_event_connection(void);
146 
147 // move this from ipmid.hpp, which is now gone
148 // this should not be used. Use the channel API to get the channel size
149 #define MAX_IPMI_BUFFER 64
150 
151 #endif
152