blob: a08527019764cb8d23bfc0dc895c7da78eb95996 [file] [log] [blame]
vishwabmcba0bd5f2015-09-30 16:50:23 +05301#ifndef __HOST_IPMID_IPMI_COMMON_H__
2#define __HOST_IPMID_IPMI_COMMON_H__
3#include <stdlib.h>
Chris Austen30195fa2015-11-13 14:39:19 -06004#include <systemd/sd-bus.h>
vishwabmcba0bd5f2015-09-30 16:50:23 +05305
Joel Stanleyc99350c2015-11-25 17:27:25 +10306#ifdef __cplusplus
7extern "C" {
8#endif
9
Tom05732372016-09-06 17:21:23 +053010/*
11 * Specifies the minimum privilege level required to execute the command
12 * This means the command can be executed at a given privilege level or higher
13 * privilege level. Those commands which can be executed via system interface
14 * only should use SYSTEM_INTERFACE
15 */
Patrick Venture0b02be92018-08-31 11:55:55 -070016enum CommandPrivilege
17{
18 PRIVILEGE_CALLBACK = 0x01,
19 PRIVILEGE_USER,
20 PRIVILEGE_OPERATOR,
21 PRIVILEGE_ADMIN,
22 PRIVILEGE_OEM,
23 SYSTEM_INTERFACE = 0xFF,
Tom05732372016-09-06 17:21:23 +053024};
25
vishwabmcba0bd5f2015-09-30 16:50:23 +053026// length of Completion Code and its ALWAYS _1_
27#define IPMI_CC_LEN 1
28
29// IPMI Net Function number as specified by IPMI V2.0 spec.
Gunnar Millsd8249ee2018-04-12 16:33:53 -050030// Example :
vishwabmcba0bd5f2015-09-30 16:50:23 +053031// NETFUN_APP = (0x06 << 2),
Patrick Venture0b02be92018-08-31 11:55:55 -070032typedef unsigned char ipmi_netfn_t;
vishwabmcba0bd5f2015-09-30 16:50:23 +053033
34// IPMI Command for a Net Function number as specified by IPMI V2.0 spec.
Patrick Venture0b02be92018-08-31 11:55:55 -070035typedef unsigned char ipmi_cmd_t;
vishwabmcba0bd5f2015-09-30 16:50:23 +053036
37// Buffer containing data from sender of netfn and command as part of request
Patrick Venture0b02be92018-08-31 11:55:55 -070038typedef void* ipmi_request_t;
vishwabmcba0bd5f2015-09-30 16:50:23 +053039
40// This is the response buffer that the provider of [netfn,cmd] will send back
41// to the caller. Provider will allocate the memory inside the handler and then
42// will do a memcpy to this response buffer and also will set the data size
43// parameter to the size of the buffer.
44// EXAMPLE :
45// unsigned char str[] = {0x00, 0x01, 0xFE, 0xFF, 0x0A, 0x01};
46// *data_len = 6;
47// memcpy(response, &str, *data_len);
Patrick Venture0b02be92018-08-31 11:55:55 -070048typedef void* ipmi_response_t;
vishwabmcba0bd5f2015-09-30 16:50:23 +053049
50// This buffer contains any *user specific* data that is of interest only to the
51// plugin. For a ipmi function router, this data is opaque. At the time of
52// registering the plugin handlers, plugin may optionally allocate a memory and
53// fill in whatever needed that will be of help during the actual handling of
54// command. IPMID will just pass the netfn, cmd and also this data to plugins
55// during the command handler invocation.
Patrick Venture0b02be92018-08-31 11:55:55 -070056typedef void* ipmi_context_t;
vishwabmcba0bd5f2015-09-30 16:50:23 +053057
58// Length of request / response buffer depending on whether the data is a
59// request or a response from a plugin handler.
Patrick Venture0b02be92018-08-31 11:55:55 -070060typedef size_t* ipmi_data_len_t;
vishwabmcba0bd5f2015-09-30 16:50:23 +053061
62// Plugin function return the status code
63typedef unsigned char ipmi_ret_t;
64
Tom05732372016-09-06 17:21:23 +053065typedef enum CommandPrivilege ipmi_cmd_privilege_t;
66
vishwabmcba0bd5f2015-09-30 16:50:23 +053067// This is the callback handler that the plugin registers with IPMID. IPMI
68// function router will then make a call to this callback handler with the
69// necessary arguments of netfn, cmd, request, response, size and context.
70typedef ipmi_ret_t (*ipmid_callback_t)(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
Patrick Venture0b02be92018-08-31 11:55:55 -070071 ipmi_response_t, ipmi_data_len_t,
72 ipmi_context_t);
vishwabmcba0bd5f2015-09-30 16:50:23 +053073
74// This is the constructor function that is called into by each plugin handlers.
75// When ipmi sets up the callback handlers, a call is made to this with
76// information of netfn, cmd, callback handler pointer and context data.
Patrick Venture0b02be92018-08-31 11:55:55 -070077void ipmi_register_callback(ipmi_netfn_t, ipmi_cmd_t, ipmi_context_t,
78 ipmid_callback_t, ipmi_cmd_privilege_t);
vishwabmcba0bd5f2015-09-30 16:50:23 +053079
Nan Li36c0cb62016-03-31 11:16:08 +080080unsigned short get_sel_reserve_id(void);
81
vishwabmcba0bd5f2015-09-30 16:50:23 +053082// These are the command network functions, the response
83// network functions are the function + 1. So to determine
84// the proper network function which issued the command
85// associated with a response, subtract 1.
86// Note: these are also shifted left to make room for the LUN.
87enum ipmi_net_fns
88{
Patrick Venture0b02be92018-08-31 11:55:55 -070089 NETFUN_CHASSIS = 0x00,
90 NETFUN_BRIDGE = 0x02,
91 NETFUN_SENSOR = 0x04,
92 NETFUN_APP = 0x06,
93 NETFUN_FIRMWARE = 0x08,
94 NETFUN_STORAGE = 0x0a,
95 NETFUN_TRANSPORT = 0x0c,
96 NETFUN_GRPEXT = 0x2c,
97 NETFUN_OEM_GROUP = 0x2e,
98 NETFUN_NONE = 0x30,
99 NETFUN_OEM = 0x32,
100 NETFUN_IBM_OEM = 0x3A
vishwabmcba0bd5f2015-09-30 16:50:23 +0530101};
102
103// IPMI commands for net functions. Since this is to be used both by the ipmi
104// function router and also the callback handler registration function, its put
105// in this .H file.
106enum ipmi_netfn_wild_card_cmd
107{
Patrick Venture0b02be92018-08-31 11:55:55 -0700108 IPMI_CMD_WILDCARD = 0xFF,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530109};
110
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500111// Return (completion) codes from a IPMI operation as needed by IPMI V2.0 spec.
vishwabmcba0bd5f2015-09-30 16:50:23 +0530112enum ipmi_return_codes
113{
114 IPMI_CC_OK = 0x00,
Chris Austen1810bec2015-10-13 12:12:39 -0500115 IPMI_DCMI_CC_NO_ACTIVE_POWER_LIMIT = 0x80,
William A. Kennington III5325f2c2018-01-08 15:17:09 -0800116 IPMI_WDOG_CC_NOT_INIT = 0x80,
William A. Kennington III6ae3df32018-01-18 11:19:30 -0800117 IPMI_CC_BUSY = 0xC0,
Chris Austen8339f9d2015-10-21 20:07:31 -0500118 IPMI_CC_INVALID = 0xC1,
Nan Li36c0cb62016-03-31 11:16:08 +0800119 IPMI_CC_INVALID_RESERVATION_ID = 0xC5,
Tom63a3db72016-09-23 18:20:52 +0530120 IPMI_CC_REQ_DATA_LEN_INVALID = 0xC7,
Chris Austenc2cd29d2016-02-05 20:02:29 -0600121 IPMI_CC_PARM_OUT_OF_RANGE = 0xC9,
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500122 IPMI_CC_SENSOR_INVALID = 0xCB,
Tom Joseph50234ad2017-03-20 18:51:38 +0530123 IPMI_CC_INVALID_FIELD_REQUEST = 0xCC,
Jayanth Othayoth0922bde2018-04-02 07:59:34 -0500124 IPMI_CC_ILLEGAL_COMMAND = 0xCD,
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500125 IPMI_CC_RESPONSE_ERROR = 0xCE,
Tom Joseph9a61b4f2016-07-11 06:56:11 -0500126 IPMI_CC_INSUFFICIENT_PRIVILEGE = 0xD4,
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500127 IPMI_CC_UNSPECIFIED_ERROR = 0xFF,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530128};
129
Patrick Venture0b02be92018-08-31 11:55:55 -0700130sd_bus* ipmid_get_sd_bus_connection(void);
131sd_event* ipmid_get_sd_event_connection(void);
132sd_bus_slot* ipmid_get_sd_bus_slot(void);
Joel Stanleyc99350c2015-11-25 17:27:25 +1030133
134#ifdef __cplusplus
135}
136#endif
137
vishwabmcba0bd5f2015-09-30 16:50:23 +0530138#endif