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