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> |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 7 | #include <systemd/sd-bus.h> |
| 8 | |
| 9 | extern sd_bus *bus; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 10 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 11 | void register_netfn_app_functions() __attribute__((constructor)); |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 12 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 13 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 14 | ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 15 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 16 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 17 | { |
| 18 | ipmi_ret_t rc = IPMI_CC_OK; |
| 19 | *data_len = 0; |
| 20 | |
| 21 | printf("IPMI APP READ EVENT Ignoring for now\n"); |
| 22 | return rc; |
| 23 | |
| 24 | } |
| 25 | |
| 26 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 27 | ipmi_ret_t ipmi_app_set_acpi_power_state(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 28 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 29 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 30 | { |
| 31 | ipmi_ret_t rc = IPMI_CC_OK; |
| 32 | *data_len = 0; |
| 33 | |
| 34 | printf("IPMI SET ACPI STATE Ignoring for now\n"); |
| 35 | return rc; |
| 36 | } |
| 37 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 38 | ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 39 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 40 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 41 | { |
| 42 | ipmi_ret_t rc = IPMI_CC_OK; |
| 43 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 44 | // TODO GET REAL VALUES HERE.... I made these ones up because |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 45 | // we are in bringup mode. Version Major and Minor can be what we |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 46 | // want like v1.03 but the IANA really should be something that |
| 47 | // we own. I would suggest getting the IANA from Hostboot as |
| 48 | // long as IBM owns it then no problem. If some other company |
| 49 | // gave us the IANA to use then use the one we have from the |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 50 | // FSP ipmi code. |
| 51 | uint8_t str[] = {0x00, 0, 1, 1,2, 0xD, 0x41, 0xA7, 0x00, 0x43, 0x40}; |
| 52 | |
| 53 | // Data length |
| 54 | *data_len = sizeof(str); |
| 55 | |
| 56 | // Pack the actual response |
| 57 | memcpy(response, &str, *data_len); |
| 58 | return rc; |
| 59 | } |
| 60 | |
| 61 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 62 | ipmi_ret_t ipmi_app_get_bt_capabilities(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 63 | ipmi_request_t request, ipmi_response_t response, |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 64 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 65 | { |
| 66 | printf("Handling Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd); |
| 67 | |
| 68 | // Status code. |
| 69 | ipmi_ret_t rc = IPMI_CC_OK; |
| 70 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 71 | uint8_t str[] = {0x01, MAX_IPMI_BUFFER, MAX_IPMI_BUFFER, 0x0A, 0x01}; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 72 | |
| 73 | // Data length |
| 74 | *data_len = sizeof(str); |
| 75 | |
| 76 | // Pack the actual response |
| 77 | memcpy(response, &str, *data_len); |
| 78 | |
| 79 | return rc; |
| 80 | } |
| 81 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 82 | |
| 83 | struct set_wd_data_t { |
| 84 | uint8_t t_use; |
| 85 | uint8_t t_action; |
| 86 | uint8_t preset; |
| 87 | uint8_t flags; |
| 88 | uint8_t ls; |
| 89 | uint8_t ms; |
| 90 | } __attribute__ ((packed)); |
| 91 | |
| 92 | |
| 93 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 94 | ipmi_ret_t ipmi_app_set_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 95 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 96 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 97 | { |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 98 | const char *busname = "org.openbmc.watchdog.Host"; |
| 99 | const char *objname = "/org/openbmc/watchdog/HostWatchdog_0"; |
| 100 | const char *iface = "org.openbmc.Watchdog"; |
| 101 | sd_bus_message *reply = NULL, *m = NULL; |
| 102 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 103 | int r = 0; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 104 | |
| 105 | set_wd_data_t *reqptr = (set_wd_data_t*) request; |
| 106 | uint16_t timer = 0; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 107 | uint32_t timer_ms = 0; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 108 | // Status code. |
| 109 | ipmi_ret_t rc = IPMI_CC_OK; |
| 110 | |
| 111 | *data_len = 0; |
| 112 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 113 | // Get number of 100ms intervals |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 114 | timer = (((uint16_t)reqptr->ms) << 8) + reqptr->ls; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 115 | // Get timer value in ms |
| 116 | timer_ms = timer * 100; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 117 | |
| 118 | printf("WATCHDOG SET Timer:[0x%X] 100ms intervals\n",timer); |
| 119 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 120 | // Set watchdog timer |
| 121 | r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"set"); |
| 122 | if (r < 0) { |
| 123 | fprintf(stderr, "Failed to add the set method object: %s\n", strerror(-r)); |
| 124 | return -1; |
| 125 | } |
| 126 | r = sd_bus_message_append(m, "i", timer_ms); |
| 127 | if (r < 0) { |
| 128 | fprintf(stderr, "Failed to add timer value: %s\n", strerror(-r)); |
| 129 | return -1; |
| 130 | } |
| 131 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 132 | if (r < 0) { |
| 133 | fprintf(stderr, "Failed to call the set method: %s\n", strerror(-r)); |
| 134 | return -1; |
| 135 | } |
| 136 | |
| 137 | // Start watchdog |
| 138 | r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"start"); |
| 139 | if (r < 0) { |
| 140 | fprintf(stderr, "Failed to add the start method object: %s\n", strerror(-r)); |
| 141 | return -1; |
| 142 | } |
| 143 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 144 | if (r < 0) { |
| 145 | fprintf(stderr, "Failed to call the start method: %s\n", strerror(-r)); |
| 146 | return -1; |
| 147 | } |
| 148 | |
| 149 | sd_bus_error_free(&error); |
| 150 | sd_bus_message_unref(m); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 151 | |
| 152 | return rc; |
| 153 | } |
| 154 | |
| 155 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 156 | ipmi_ret_t ipmi_app_reset_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 157 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 158 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 159 | { |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 160 | const char *busname = "org.openbmc.watchdog.Host"; |
| 161 | const char *objname = "/org/openbmc/watchdog/HostWatchdog_0"; |
| 162 | const char *iface = "org.openbmc.Watchdog"; |
| 163 | sd_bus_message *reply = NULL, *m = NULL; |
| 164 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 165 | int r = 0; |
| 166 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 167 | // Status code. |
| 168 | ipmi_ret_t rc = IPMI_CC_OK; |
| 169 | *data_len = 0; |
| 170 | |
| 171 | printf("WATCHDOG RESET\n"); |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 172 | |
| 173 | // Refresh watchdog |
| 174 | r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"poke"); |
| 175 | if (r < 0) { |
| 176 | fprintf(stderr, "Failed to add the method object: %s\n", strerror(-r)); |
| 177 | return -1; |
| 178 | } |
| 179 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 180 | if (r < 0) { |
| 181 | fprintf(stderr, "Failed to call the method: %s\n", strerror(-r)); |
| 182 | return -1; |
| 183 | } |
| 184 | |
| 185 | sd_bus_error_free(&error); |
| 186 | sd_bus_message_unref(m); |
| 187 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 188 | return rc; |
| 189 | } |
| 190 | |
Adriana Kobylak | dfc8d77 | 2015-10-20 09:34:48 -0500 | [diff] [blame^] | 191 | ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 192 | ipmi_request_t request, ipmi_response_t response, |
| 193 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 194 | { |
| 195 | ipmi_ret_t rc = IPMI_CC_OK; |
| 196 | *data_len = 0; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 197 | |
Adriana Kobylak | dfc8d77 | 2015-10-20 09:34:48 -0500 | [diff] [blame^] | 198 | // Event and message logging enabled by default so return for now |
| 199 | printf("IPMI APP SET BMC GLOBAL ENABLES Ignoring for now\n"); |
| 200 | |
| 201 | return rc; |
| 202 | } |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 203 | |
| 204 | |
| 205 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 206 | ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 207 | ipmi_request_t request, ipmi_response_t response, |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 208 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 209 | { |
| 210 | printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 211 | |
| 212 | // Status code. |
| 213 | ipmi_ret_t rc = IPMI_CC_OK; |
| 214 | |
| 215 | *data_len = strlen("THIS IS WILDCARD"); |
| 216 | |
| 217 | // Now pack actual response |
| 218 | memcpy(response, "THIS IS WILDCARD", *data_len); |
| 219 | |
| 220 | return rc; |
| 221 | } |
| 222 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 223 | void register_netfn_app_functions() |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 224 | { |
| 225 | 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] | 226 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CAP_BIT, NULL, ipmi_app_get_bt_capabilities); |
| 227 | |
| 228 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_WILDCARD); |
| 229 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_WILDCARD, NULL, ipmi_app_wildcard_handler); |
| 230 | |
| 231 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_RESET_WD); |
| 232 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, ipmi_app_reset_watchdog); |
| 233 | |
| 234 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_WD); |
| 235 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, ipmi_app_set_watchdog); |
| 236 | |
| 237 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_ID); |
| 238 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_ID, NULL, ipmi_app_get_device_id); |
| 239 | |
| 240 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_ACPI); |
| 241 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, ipmi_app_set_acpi_power_state); |
| 242 | |
| 243 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_READ_EVENT); |
| 244 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, ipmi_app_read_event); |
Adriana Kobylak | dfc8d77 | 2015-10-20 09:34:48 -0500 | [diff] [blame^] | 245 | |
| 246 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, |
| 247 | IPMI_CMD_SET_BMC_GLOBAL_ENABLES); |
| 248 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL, |
| 249 | ipmi_app_set_bmc_global_enables); |
| 250 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 251 | return; |
| 252 | } |
| 253 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 254 | |