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 | |
Adriana Kobylak | 0896be3 | 2015-10-22 13:27:23 -0500 | [diff] [blame] | 137 | // Stop the current watchdog if any |
| 138 | r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"stop"); |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 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 | |
Adriana Kobylak | 0896be3 | 2015-10-22 13:27:23 -0500 | [diff] [blame] | 149 | // Start the watchdog if requested |
| 150 | if (reqptr->t_use & 0x40) |
| 151 | { |
| 152 | r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"start"); |
| 153 | if (r < 0) { |
| 154 | fprintf(stderr, "Failed to add the start method object: %s\n", strerror(-r)); |
| 155 | return -1; |
| 156 | } |
| 157 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 158 | if (r < 0) { |
| 159 | fprintf(stderr, "Failed to call the start method: %s\n", strerror(-r)); |
| 160 | return -1; |
| 161 | } |
| 162 | } |
| 163 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 164 | sd_bus_error_free(&error); |
| 165 | sd_bus_message_unref(m); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 166 | |
| 167 | return rc; |
| 168 | } |
| 169 | |
| 170 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 171 | ipmi_ret_t ipmi_app_reset_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 172 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 173 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 174 | { |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 175 | const char *busname = "org.openbmc.watchdog.Host"; |
| 176 | const char *objname = "/org/openbmc/watchdog/HostWatchdog_0"; |
| 177 | const char *iface = "org.openbmc.Watchdog"; |
| 178 | sd_bus_message *reply = NULL, *m = NULL; |
| 179 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 180 | int r = 0; |
| 181 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 182 | // Status code. |
| 183 | ipmi_ret_t rc = IPMI_CC_OK; |
| 184 | *data_len = 0; |
| 185 | |
| 186 | printf("WATCHDOG RESET\n"); |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 187 | |
| 188 | // Refresh watchdog |
| 189 | r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"poke"); |
| 190 | if (r < 0) { |
| 191 | fprintf(stderr, "Failed to add the method object: %s\n", strerror(-r)); |
| 192 | return -1; |
| 193 | } |
| 194 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 195 | if (r < 0) { |
| 196 | fprintf(stderr, "Failed to call the method: %s\n", strerror(-r)); |
| 197 | return -1; |
| 198 | } |
| 199 | |
| 200 | sd_bus_error_free(&error); |
| 201 | sd_bus_message_unref(m); |
| 202 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 203 | return rc; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 210 | ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 211 | ipmi_request_t request, ipmi_response_t response, |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 212 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 213 | { |
| 214 | printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 215 | |
| 216 | // Status code. |
| 217 | ipmi_ret_t rc = IPMI_CC_OK; |
| 218 | |
| 219 | *data_len = strlen("THIS IS WILDCARD"); |
| 220 | |
| 221 | // Now pack actual response |
| 222 | memcpy(response, "THIS IS WILDCARD", *data_len); |
| 223 | |
| 224 | return rc; |
| 225 | } |
| 226 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 227 | void register_netfn_app_functions() |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 228 | { |
| 229 | 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] | 230 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CAP_BIT, NULL, ipmi_app_get_bt_capabilities); |
| 231 | |
| 232 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_WILDCARD); |
| 233 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_WILDCARD, NULL, ipmi_app_wildcard_handler); |
| 234 | |
| 235 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_RESET_WD); |
| 236 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, ipmi_app_reset_watchdog); |
| 237 | |
| 238 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_WD); |
| 239 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, ipmi_app_set_watchdog); |
| 240 | |
| 241 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_ID); |
| 242 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_ID, NULL, ipmi_app_get_device_id); |
| 243 | |
| 244 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_ACPI); |
| 245 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, ipmi_app_set_acpi_power_state); |
| 246 | |
| 247 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_READ_EVENT); |
| 248 | 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] | 249 | return; |
| 250 | } |
| 251 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 252 | |