vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 1 | #include "apphandler.h" |
| 2 | #include "ipmid-api.h" |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 3 | #include "ipmid.H" |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 4 | #include <stdio.h> |
| 5 | #include <string.h> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 6 | #include <stdint.h> |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 7 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 8 | void register_netfn_app_functions() __attribute__((constructor)); |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 9 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 10 | |
| 11 | ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 12 | ipmi_request_t request, ipmi_response_t response, |
| 13 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 14 | { |
| 15 | ipmi_ret_t rc = IPMI_CC_OK; |
| 16 | *data_len = 0; |
| 17 | |
| 18 | printf("IPMI APP READ EVENT Ignoring for now\n"); |
| 19 | return rc; |
| 20 | |
| 21 | } |
| 22 | |
| 23 | |
| 24 | ipmi_ret_t ipmi_app_set_acpi_power_state(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 25 | ipmi_request_t request, ipmi_response_t response, |
| 26 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 27 | { |
| 28 | ipmi_ret_t rc = IPMI_CC_OK; |
| 29 | *data_len = 0; |
| 30 | |
| 31 | printf("IPMI SET ACPI STATE Ignoring for now\n"); |
| 32 | return rc; |
| 33 | } |
| 34 | |
| 35 | ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 36 | ipmi_request_t request, ipmi_response_t response, |
| 37 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 38 | { |
| 39 | ipmi_ret_t rc = IPMI_CC_OK; |
| 40 | |
| 41 | // TODO GET REAL VALUES HERE.... I made these ones up because |
| 42 | // we are in bringup mode. Version Major and Minor can be what we |
| 43 | // want like v1.03 but the IANA really should be something that |
| 44 | // we own. I would suggest getting the IANA from Hostboot as |
| 45 | // long as IBM owns it then no problem. If some other company |
| 46 | // gave us the IANA to use then use the one we have from the |
| 47 | // FSP ipmi code. |
| 48 | uint8_t str[] = {0x00, 0, 1, 1,2, 0xD, 0x41, 0xA7, 0x00, 0x43, 0x40}; |
| 49 | |
| 50 | // Data length |
| 51 | *data_len = sizeof(str); |
| 52 | |
| 53 | // Pack the actual response |
| 54 | memcpy(response, &str, *data_len); |
| 55 | return rc; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | ipmi_ret_t ipmi_app_get_bt_capabilities(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 60 | ipmi_request_t request, ipmi_response_t response, |
| 61 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 62 | { |
| 63 | printf("Handling Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd); |
| 64 | |
| 65 | // Status code. |
| 66 | ipmi_ret_t rc = IPMI_CC_OK; |
| 67 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 68 | uint8_t str[] = {0x01, MAX_IPMI_BUFFER, MAX_IPMI_BUFFER, 0x0A, 0x01}; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 69 | |
| 70 | // Data length |
| 71 | *data_len = sizeof(str); |
| 72 | |
| 73 | // Pack the actual response |
| 74 | memcpy(response, &str, *data_len); |
| 75 | |
| 76 | return rc; |
| 77 | } |
| 78 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 79 | |
| 80 | struct set_wd_data_t { |
| 81 | uint8_t t_use; |
| 82 | uint8_t t_action; |
| 83 | uint8_t preset; |
| 84 | uint8_t flags; |
| 85 | uint8_t ls; |
| 86 | uint8_t ms; |
| 87 | } __attribute__ ((packed)); |
| 88 | |
| 89 | |
| 90 | |
| 91 | ipmi_ret_t ipmi_app_set_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 92 | ipmi_request_t request, ipmi_response_t response, |
| 93 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 94 | { |
| 95 | |
| 96 | set_wd_data_t *reqptr = (set_wd_data_t*) request; |
| 97 | uint16_t timer = 0; |
| 98 | // Status code. |
| 99 | ipmi_ret_t rc = IPMI_CC_OK; |
| 100 | |
| 101 | *data_len = 0; |
| 102 | |
| 103 | timer = (((uint16_t)reqptr->ms) << 8) + reqptr->ls; |
| 104 | |
| 105 | printf("WATCHDOG SET Timer:[0x%X] 100ms intervals\n",timer); |
| 106 | |
| 107 | // TODO: Right here is where we would call some dbus method as a timer. |
| 108 | // If the timer expires it would iniate a reboot of the host. |
| 109 | |
| 110 | return rc; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | ipmi_ret_t ipmi_app_reset_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 115 | ipmi_request_t request, ipmi_response_t response, |
| 116 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 117 | { |
| 118 | // Status code. |
| 119 | ipmi_ret_t rc = IPMI_CC_OK; |
| 120 | *data_len = 0; |
| 121 | |
| 122 | printf("WATCHDOG RESET\n"); |
| 123 | // TODO Right here is where we would call some sdbus timer. |
| 124 | // If your are experiencing dejavu you are right. the |
| 125 | // set and the reset do similar things |
| 126 | return rc; |
| 127 | } |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 133 | ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 134 | ipmi_request_t request, ipmi_response_t response, |
| 135 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 136 | { |
| 137 | printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 138 | |
| 139 | // Status code. |
| 140 | ipmi_ret_t rc = IPMI_CC_OK; |
| 141 | |
| 142 | *data_len = strlen("THIS IS WILDCARD"); |
| 143 | |
| 144 | // Now pack actual response |
| 145 | memcpy(response, "THIS IS WILDCARD", *data_len); |
| 146 | |
| 147 | return rc; |
| 148 | } |
| 149 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 150 | void register_netfn_app_functions() |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 151 | { |
| 152 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CAP_BIT); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 153 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CAP_BIT, NULL, ipmi_app_get_bt_capabilities); |
| 154 | |
| 155 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_WILDCARD); |
| 156 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_WILDCARD, NULL, ipmi_app_wildcard_handler); |
| 157 | |
| 158 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_RESET_WD); |
| 159 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, ipmi_app_reset_watchdog); |
| 160 | |
| 161 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_WD); |
| 162 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, ipmi_app_set_watchdog); |
| 163 | |
| 164 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_ID); |
| 165 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_ID, NULL, ipmi_app_get_device_id); |
| 166 | |
| 167 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_ACPI); |
| 168 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, ipmi_app_set_acpi_power_state); |
| 169 | |
| 170 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_READ_EVENT); |
| 171 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, ipmi_app_read_event); |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 172 | return; |
| 173 | } |
| 174 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 175 | |