vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 1 | #ifndef __HOST_IPMID_IPMI_COMMON_H__ |
| 2 | #define __HOST_IPMID_IPMI_COMMON_H__ |
| 3 | #include <stdlib.h> |
Chris Austen | 30195fa | 2015-11-13 14:39:19 -0600 | [diff] [blame] | 4 | #include <systemd/sd-bus.h> |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 5 | |
Joel Stanley | c99350c | 2015-11-25 17:27:25 +1030 | [diff] [blame] | 6 | #ifdef __cplusplus |
| 7 | extern "C" { |
| 8 | #endif |
| 9 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 10 | /* |
| 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 | */ |
| 16 | enum CommandPrivilege { |
| 17 | PRIVILEGE_CALLBACK = 0x01, |
| 18 | PRIVILEGE_USER, |
| 19 | PRIVILEGE_OPERATOR, |
| 20 | PRIVILEGE_ADMIN, |
| 21 | PRIVILEGE_OEM, |
| 22 | SYSTEM_INTERFACE = 0xFF, |
| 23 | }; |
| 24 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 25 | // length of Completion Code and its ALWAYS _1_ |
| 26 | #define IPMI_CC_LEN 1 |
| 27 | |
| 28 | // IPMI Net Function number as specified by IPMI V2.0 spec. |
| 29 | // Example : |
| 30 | // NETFUN_APP = (0x06 << 2), |
| 31 | typedef unsigned char ipmi_netfn_t; |
| 32 | |
| 33 | // IPMI Command for a Net Function number as specified by IPMI V2.0 spec. |
| 34 | typedef unsigned char ipmi_cmd_t; |
| 35 | |
| 36 | // Buffer containing data from sender of netfn and command as part of request |
| 37 | typedef void* ipmi_request_t; |
| 38 | |
| 39 | // This is the response buffer that the provider of [netfn,cmd] will send back |
| 40 | // to the caller. Provider will allocate the memory inside the handler and then |
| 41 | // will do a memcpy to this response buffer and also will set the data size |
| 42 | // parameter to the size of the buffer. |
| 43 | // EXAMPLE : |
| 44 | // unsigned char str[] = {0x00, 0x01, 0xFE, 0xFF, 0x0A, 0x01}; |
| 45 | // *data_len = 6; |
| 46 | // memcpy(response, &str, *data_len); |
| 47 | typedef void* ipmi_response_t; |
| 48 | |
| 49 | // This buffer contains any *user specific* data that is of interest only to the |
| 50 | // plugin. For a ipmi function router, this data is opaque. At the time of |
| 51 | // registering the plugin handlers, plugin may optionally allocate a memory and |
| 52 | // fill in whatever needed that will be of help during the actual handling of |
| 53 | // command. IPMID will just pass the netfn, cmd and also this data to plugins |
| 54 | // during the command handler invocation. |
| 55 | typedef void* ipmi_context_t; |
| 56 | |
| 57 | // Length of request / response buffer depending on whether the data is a |
| 58 | // request or a response from a plugin handler. |
| 59 | typedef size_t* ipmi_data_len_t; |
| 60 | |
| 61 | // Plugin function return the status code |
| 62 | typedef unsigned char ipmi_ret_t; |
| 63 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 64 | typedef enum CommandPrivilege ipmi_cmd_privilege_t; |
| 65 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 66 | // This is the callback handler that the plugin registers with IPMID. IPMI |
| 67 | // function router will then make a call to this callback handler with the |
| 68 | // necessary arguments of netfn, cmd, request, response, size and context. |
| 69 | typedef ipmi_ret_t (*ipmid_callback_t)(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t, |
| 70 | ipmi_response_t, ipmi_data_len_t, ipmi_context_t); |
| 71 | |
| 72 | // This is the constructor function that is called into by each plugin handlers. |
| 73 | // When ipmi sets up the callback handlers, a call is made to this with |
| 74 | // information of netfn, cmd, callback handler pointer and context data. |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 75 | void ipmi_register_callback(ipmi_netfn_t, ipmi_cmd_t, ipmi_context_t, ipmid_callback_t, |
| 76 | ipmi_cmd_privilege_t); |
| 77 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 78 | |
Nan Li | 36c0cb6 | 2016-03-31 11:16:08 +0800 | [diff] [blame] | 79 | unsigned short get_sel_reserve_id(void); |
| 80 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 81 | // These are the command network functions, the response |
| 82 | // network functions are the function + 1. So to determine |
| 83 | // the proper network function which issued the command |
| 84 | // associated with a response, subtract 1. |
| 85 | // Note: these are also shifted left to make room for the LUN. |
| 86 | enum ipmi_net_fns |
| 87 | { |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 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_NONE = 0x30, |
Tom Joseph | 5914678 | 2017-10-24 20:27:51 +0530 | [diff] [blame] | 97 | NETFUN_OEM = 0x32, |
| 98 | NETFUN_IBM_OEM = 0x3A |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | // IPMI commands for net functions. Since this is to be used both by the ipmi |
| 102 | // function router and also the callback handler registration function, its put |
| 103 | // in this .H file. |
| 104 | enum ipmi_netfn_wild_card_cmd |
| 105 | { |
| 106 | IPMI_CMD_WILDCARD = 0xFF, |
| 107 | }; |
| 108 | |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 109 | // Return (completion) codes from a IPMI operation as needed by IPMI V2.0 spec. |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 110 | enum ipmi_return_codes |
| 111 | { |
| 112 | IPMI_CC_OK = 0x00, |
Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 113 | IPMI_DCMI_CC_NO_ACTIVE_POWER_LIMIT = 0x80, |
William A. Kennington III | 5325f2c | 2018-01-08 15:17:09 -0800 | [diff] [blame] | 114 | IPMI_WDOG_CC_NOT_INIT = 0x80, |
William A. Kennington III | 6ae3df3 | 2018-01-18 11:19:30 -0800 | [diff] [blame] | 115 | IPMI_CC_BUSY = 0xC0, |
Chris Austen | 8339f9d | 2015-10-21 20:07:31 -0500 | [diff] [blame] | 116 | IPMI_CC_INVALID = 0xC1, |
Nan Li | 36c0cb6 | 2016-03-31 11:16:08 +0800 | [diff] [blame] | 117 | IPMI_CC_INVALID_RESERVATION_ID = 0xC5, |
Tom | 63a3db7 | 2016-09-23 18:20:52 +0530 | [diff] [blame] | 118 | IPMI_CC_REQ_DATA_LEN_INVALID = 0xC7, |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 119 | IPMI_CC_PARM_OUT_OF_RANGE = 0xC9, |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 120 | IPMI_CC_SENSOR_INVALID = 0xCB, |
Tom Joseph | 50234ad | 2017-03-20 18:51:38 +0530 | [diff] [blame] | 121 | IPMI_CC_INVALID_FIELD_REQUEST = 0xCC, |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 122 | IPMI_CC_RESPONSE_ERROR = 0xCE, |
Tom Joseph | 9a61b4f | 2016-07-11 06:56:11 -0500 | [diff] [blame] | 123 | IPMI_CC_INSUFFICIENT_PRIVILEGE = 0xD4, |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 124 | IPMI_CC_UNSPECIFIED_ERROR = 0xFF, |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 125 | }; |
| 126 | |
Joel Stanley | c99350c | 2015-11-25 17:27:25 +1030 | [diff] [blame] | 127 | sd_bus *ipmid_get_sd_bus_connection(void); |
Andrew Geissler | 93c679b | 2017-04-02 10:06:43 -0500 | [diff] [blame] | 128 | sd_event *ipmid_get_sd_event_connection(void); |
vishwa | b9f559a | 2016-01-13 01:53:08 -0600 | [diff] [blame] | 129 | sd_bus_slot *ipmid_get_sd_bus_slot(void); |
Joel Stanley | c99350c | 2015-11-25 17:27:25 +1030 | [diff] [blame] | 130 | |
| 131 | #ifdef __cplusplus |
| 132 | } |
| 133 | #endif |
| 134 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 135 | #endif |