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 | |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 13 | //--------------------------------------------------------------------- |
| 14 | // Called by Host on seeing a SMS_ATN bit set. Return a hardcoded |
| 15 | // value of 0x2 indicating we need Host read some data. |
| 16 | //------------------------------------------------------------------- |
| 17 | ipmi_ret_t ipmi_app_get_msg_flags(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 18 | ipmi_request_t request, ipmi_response_t response, |
| 19 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 20 | { |
| 21 | // Generic return from IPMI commands. |
| 22 | ipmi_ret_t rc = IPMI_CC_OK; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 23 | |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 24 | printf("IPMI APP GET MSG FLAGS returning with [bit:2] set\n"); |
| 25 | |
| 26 | // From IPMI spec V2.0 for Get Message Flags Command : |
| 27 | // bit:[1] from LSB : 1b = Event Message Buffer Full. |
| 28 | // Return as 0 if Event Message Buffer is not supported, |
| 29 | // or when the Event Message buffer is disabled. |
| 30 | // TODO. For now. assume its not disabled and send "0x2" anyway: |
| 31 | |
| 32 | uint8_t set_event_msg_buffer_full = 0x2; |
| 33 | *data_len = sizeof(set_event_msg_buffer_full); |
| 34 | |
| 35 | // Pack the actual response |
| 36 | memcpy(response, &set_event_msg_buffer_full, *data_len); |
| 37 | |
| 38 | return rc; |
| 39 | } |
| 40 | |
| 41 | //------------------------------------------------------------------- |
| 42 | // Called by Host post response from Get_Message_Flags |
| 43 | //------------------------------------------------------------------- |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 44 | ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 45 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 46 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 47 | { |
| 48 | ipmi_ret_t rc = IPMI_CC_OK; |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 49 | printf("IPMI APP READ EVENT command received\n"); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 50 | |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 51 | // TODO : For now, this is catering only to the Soft Power Off via OEM SEL |
| 52 | // mechanism. If we need to make this generically used for some |
| 53 | // other conditions, then we can take advantage of context pointer. |
| 54 | |
| 55 | struct oem_sel_timestamped soft_off = {0}; |
| 56 | *data_len = sizeof(struct oem_sel_timestamped); |
| 57 | |
| 58 | // either id[0] -or- id[1] can be filled in. We will use id[0] |
| 59 | soft_off.id[0] = SEL_OEM_ID_0; |
| 60 | soft_off.id[1] = SEL_OEM_ID_0; |
| 61 | soft_off.type = SEL_RECORD_TYPE_OEM; |
| 62 | |
| 63 | // Following 3 bytes are from IANA Manufactre_Id field. See below |
| 64 | soft_off.manuf_id[0]= 0x41; |
| 65 | soft_off.manuf_id[1]= 0xA7; |
| 66 | soft_off.manuf_id[2]= 0x00; |
| 67 | |
| 68 | // per IPMI spec NetFuntion for OEM |
| 69 | soft_off.netfun = 0x3A; |
| 70 | |
| 71 | // Mechanism to kick start soft shutdown. |
| 72 | soft_off.cmd = CMD_POWER; |
| 73 | soft_off.data[0] = SOFT_OFF; |
| 74 | |
| 75 | // All '0xFF' since unused. |
| 76 | memset(&soft_off.data[1], 0xFF, 3); |
| 77 | |
| 78 | // Pack the actual response |
| 79 | memcpy(response, &soft_off, *data_len); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 80 | return rc; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 81 | } |
| 82 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 83 | ipmi_ret_t ipmi_app_set_acpi_power_state(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 84 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 85 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 86 | { |
| 87 | ipmi_ret_t rc = IPMI_CC_OK; |
| 88 | *data_len = 0; |
| 89 | |
| 90 | printf("IPMI SET ACPI STATE Ignoring for now\n"); |
| 91 | return rc; |
| 92 | } |
| 93 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 94 | ipmi_ret_t ipmi_app_get_device_id(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 | { |
| 98 | ipmi_ret_t rc = IPMI_CC_OK; |
| 99 | |
Patrick Williams | 76b51f6 | 2015-10-28 12:14:56 -0500 | [diff] [blame] | 100 | // TODO: |
| 101 | // This value is the IANA number assigned to "IBM Platform Firmware |
| 102 | // Division", which is also used by our service processor. We may want |
| 103 | // a different number or at least a different version? |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 104 | uint8_t str[] = {0x00, 0, 1, 1,2, 0xD, 0x41, 0xA7, 0x00, 0x43, 0x40}; |
| 105 | |
| 106 | // Data length |
| 107 | *data_len = sizeof(str); |
| 108 | |
| 109 | // Pack the actual response |
| 110 | memcpy(response, &str, *data_len); |
| 111 | return rc; |
| 112 | } |
| 113 | |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 114 | ipmi_ret_t ipmi_app_get_device_guid(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 | const char *busname = "org.openbmc.control.Chassis"; |
| 119 | const char *objname = "/org/openbmc/control/chassis0"; |
Adriana Kobylak | 31bccae | 2015-11-05 13:31:06 -0600 | [diff] [blame] | 120 | const char *iface = "org.freedesktop.DBus.Properties"; |
| 121 | const char *chassis_iface = "org.openbmc.control.Chassis"; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 122 | sd_bus_message *reply = NULL; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 123 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 124 | int r = 0; |
| 125 | char *uuid = NULL; |
| 126 | |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 127 | // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223 |
| 128 | // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte order |
| 129 | // Ex: 0x2332fc2c40e66298e511f2782395a361 |
| 130 | |
| 131 | const int resp_size = 16; // Response is 16 hex bytes per IPMI Spec |
| 132 | uint8_t resp_uuid[resp_size]; // Array to hold the formatted response |
| 133 | int resp_loc = resp_size-1; // Point resp end of array to save in reverse order |
| 134 | int i = 0; |
| 135 | char *tokptr = NULL; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 136 | char *id_octet = NULL; |
| 137 | |
| 138 | // Status code. |
| 139 | ipmi_ret_t rc = IPMI_CC_OK; |
| 140 | *data_len = 0; |
| 141 | |
| 142 | printf("IPMI GET DEVICE GUID\n"); |
| 143 | |
| 144 | // Call Get properties method with the interface and property name |
| 145 | r = sd_bus_call_method(bus,busname,objname,iface, |
| 146 | "Get",&error, &reply, "ss", |
| 147 | chassis_iface, "uuid"); |
| 148 | if (r < 0) |
| 149 | { |
| 150 | fprintf(stderr, "Failed to call Get Method: %s\n", strerror(-r)); |
| 151 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 152 | goto finish; |
| 153 | } |
| 154 | |
| 155 | r = sd_bus_message_read(reply, "v", "s", &uuid); |
| 156 | if (r < 0 || uuid == NULL) |
| 157 | { |
| 158 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 159 | rc = IPMI_CC_RESPONSE_ERROR; |
| 160 | goto finish; |
| 161 | } |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 162 | |
| 163 | // Traverse the UUID |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 164 | id_octet = strtok_r(uuid, "-", &tokptr); // Get the UUID octects separated by dash |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 165 | |
| 166 | if (id_octet == NULL) |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 167 | { |
| 168 | // Error |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 169 | fprintf(stderr, "Unexpected UUID format: %s", uuid); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 170 | rc = IPMI_CC_RESPONSE_ERROR; |
| 171 | goto finish; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | while (id_octet != NULL) |
| 175 | { |
| 176 | // Calculate the octet string size since it varies |
| 177 | // Divide it by 2 for the array size since 1 byte is built from 2 chars |
| 178 | int tmp_size = strlen(id_octet)/2; |
| 179 | |
| 180 | for(i = 0; i < tmp_size; i++) |
| 181 | { |
Joel Stanley | 38310cd | 2015-11-25 17:32:08 +1030 | [diff] [blame] | 182 | char tmp_array[3] = {0}; // Holder of the 2 chars that will become a byte |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 183 | strncpy(tmp_array, id_octet, 2); // 2 chars at a time |
| 184 | |
| 185 | int resp_byte = strtoul(tmp_array, NULL, 16); // Convert to hex byte |
| 186 | memcpy((void*)&resp_uuid[resp_loc], &resp_byte, 1); // Copy end to first |
| 187 | resp_loc--; |
| 188 | id_octet+=2; // Finished with the 2 chars, advance |
| 189 | } |
| 190 | id_octet=strtok_r(NULL, "-", &tokptr); // Get next octet |
| 191 | } |
| 192 | |
| 193 | // Data length |
| 194 | *data_len = resp_size; |
| 195 | |
| 196 | // Pack the actual response |
| 197 | memcpy(response, &resp_uuid, *data_len); |
| 198 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 199 | finish: |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 200 | sd_bus_error_free(&error); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 201 | reply = sd_bus_message_unref(reply); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 202 | |
| 203 | return rc; |
| 204 | } |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 205 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 206 | ipmi_ret_t ipmi_app_get_bt_capabilities(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 Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd); |
| 211 | |
| 212 | // Status code. |
| 213 | ipmi_ret_t rc = IPMI_CC_OK; |
| 214 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 215 | uint8_t str[] = {0x01, MAX_IPMI_BUFFER, MAX_IPMI_BUFFER, 0x0A, 0x01}; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 216 | |
| 217 | // Data length |
| 218 | *data_len = sizeof(str); |
| 219 | |
| 220 | // Pack the actual response |
| 221 | memcpy(response, &str, *data_len); |
| 222 | |
| 223 | return rc; |
| 224 | } |
| 225 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 226 | |
| 227 | struct set_wd_data_t { |
| 228 | uint8_t t_use; |
| 229 | uint8_t t_action; |
| 230 | uint8_t preset; |
| 231 | uint8_t flags; |
| 232 | uint8_t ls; |
| 233 | uint8_t ms; |
| 234 | } __attribute__ ((packed)); |
| 235 | |
| 236 | |
| 237 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 238 | ipmi_ret_t ipmi_app_set_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 239 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 240 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 241 | { |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 242 | const char *busname = "org.openbmc.watchdog.Host"; |
Chris Austen | 454acfe | 2015-10-29 23:03:34 -0500 | [diff] [blame] | 243 | const char *objname = "/org/openbmc/watchdog/host0"; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 244 | const char *iface = "org.openbmc.Watchdog"; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 245 | sd_bus_message *reply = NULL; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 246 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 247 | int r = 0; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 248 | |
| 249 | set_wd_data_t *reqptr = (set_wd_data_t*) request; |
| 250 | uint16_t timer = 0; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 251 | uint32_t timer_ms = 0; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 252 | |
| 253 | *data_len = 0; |
| 254 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 255 | // Get number of 100ms intervals |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 256 | timer = (((uint16_t)reqptr->ms) << 8) + reqptr->ls; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 257 | // Get timer value in ms |
| 258 | timer_ms = timer * 100; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 259 | |
| 260 | printf("WATCHDOG SET Timer:[0x%X] 100ms intervals\n",timer); |
| 261 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 262 | // Set watchdog timer |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 263 | r = sd_bus_call_method(bus, busname, objname, iface, |
| 264 | "set", &error, &reply, "i", timer_ms); |
| 265 | if(r < 0) |
Adriana Kobylak | 0896be3 | 2015-10-22 13:27:23 -0500 | [diff] [blame] | 266 | { |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 267 | fprintf(stderr, "Failed to call the SET method: %s\n", strerror(-r)); |
| 268 | goto finish; |
Adriana Kobylak | 0896be3 | 2015-10-22 13:27:23 -0500 | [diff] [blame] | 269 | } |
| 270 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 271 | sd_bus_error_free(&error); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 272 | reply = sd_bus_message_unref(reply); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 273 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 274 | // Stop the current watchdog if any |
| 275 | r = sd_bus_call_method(bus, busname, objname, iface, |
| 276 | "stop", &error, &reply, NULL); |
| 277 | if(r < 0) |
| 278 | { |
| 279 | fprintf(stderr, "Failed to call the STOP method: %s\n", strerror(-r)); |
| 280 | goto finish; |
| 281 | } |
| 282 | |
| 283 | if (reqptr->t_use & 0x40) |
| 284 | { |
| 285 | sd_bus_error_free(&error); |
| 286 | reply = sd_bus_message_unref(reply); |
| 287 | |
| 288 | // Start the watchdog if requested |
| 289 | r = sd_bus_call_method(bus, busname, objname, iface, |
| 290 | "start", &error, &reply, NULL); |
| 291 | if(r < 0) |
| 292 | { |
| 293 | fprintf(stderr, "Failed to call the START method: %s\n", strerror(-r)); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | finish: |
| 298 | sd_bus_error_free(&error); |
| 299 | reply = sd_bus_message_unref(reply); |
| 300 | |
| 301 | return (r < 0) ? -1 : IPMI_CC_OK; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 305 | ipmi_ret_t ipmi_app_reset_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 306 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 307 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 308 | { |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 309 | const char *busname = "org.openbmc.watchdog.Host"; |
Chris Austen | 454acfe | 2015-10-29 23:03:34 -0500 | [diff] [blame] | 310 | const char *objname = "/org/openbmc/watchdog/host0"; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 311 | const char *iface = "org.openbmc.Watchdog"; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 312 | sd_bus_message *reply = NULL; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 313 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 314 | int r = 0; |
| 315 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 316 | // Status code. |
| 317 | ipmi_ret_t rc = IPMI_CC_OK; |
| 318 | *data_len = 0; |
| 319 | |
| 320 | printf("WATCHDOG RESET\n"); |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 321 | |
| 322 | // Refresh watchdog |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 323 | r = sd_bus_call_method(bus, busname, objname, iface, |
| 324 | "poke", &error, &reply, NULL); |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 325 | if (r < 0) { |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 326 | fprintf(stderr, "Failed to add reset watchdog: %s\n", strerror(-r)); |
| 327 | rc = -1; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | sd_bus_error_free(&error); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 331 | reply = sd_bus_message_unref(reply); |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 332 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 333 | return rc; |
| 334 | } |
| 335 | |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 336 | // ATTENTION: This ipmi function is very hardcoded on purpose |
| 337 | // OpenBMC does not fully support IPMI. This command is useful |
| 338 | // to have around because it enables testing of interfaces with |
| 339 | // the IPMI tool. |
| 340 | #define GET_CHANNEL_INFO_CHANNEL_OFFSET 0 |
| 341 | // IPMI Table 6-2 |
| 342 | #define IPMI_CHANNEL_TYPE_IPMB 1 |
| 343 | // IPMI Table 6-3 |
| 344 | #define IPMI_CHANNEL_MEDIUM_TYPE_OTHER 6 |
| 345 | |
| 346 | ipmi_ret_t ipmi_app_channel_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 347 | ipmi_request_t request, ipmi_response_t response, |
| 348 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 349 | { |
| 350 | ipmi_ret_t rc = IPMI_CC_OK; |
| 351 | uint8_t resp[] = { |
| 352 | 1, |
| 353 | IPMI_CHANNEL_MEDIUM_TYPE_OTHER, |
| 354 | IPMI_CHANNEL_TYPE_IPMB, |
| 355 | 1,0x41,0xA7,0x00,0,0}; |
| 356 | uint8_t *p = (uint8_t*) request; |
| 357 | |
| 358 | printf("IPMI APP GET CHANNEL INFO\n"); |
| 359 | |
| 360 | // I"m only supporting channel 1. 0xE is the 'default channel' |
tomjose | 13fb441 | 2016-03-08 14:02:34 -0600 | [diff] [blame] | 361 | if (*p == 0xe || *p == 1 || *p == 8) { |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 362 | |
| 363 | *data_len = sizeof(resp); |
| 364 | memcpy(response, resp, *data_len); |
| 365 | |
| 366 | } else { |
| 367 | rc = IPMI_CC_PARM_OUT_OF_RANGE; |
| 368 | *data_len = 0; |
| 369 | } |
| 370 | |
| 371 | return rc; |
| 372 | } |
| 373 | |
Adriana Kobylak | dfc8d77 | 2015-10-20 09:34:48 -0500 | [diff] [blame] | 374 | ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 375 | ipmi_request_t request, ipmi_response_t response, |
| 376 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 377 | { |
| 378 | ipmi_ret_t rc = IPMI_CC_OK; |
| 379 | *data_len = 0; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 380 | |
Adriana Kobylak | dfc8d77 | 2015-10-20 09:34:48 -0500 | [diff] [blame] | 381 | // Event and message logging enabled by default so return for now |
| 382 | printf("IPMI APP SET BMC GLOBAL ENABLES Ignoring for now\n"); |
| 383 | |
| 384 | return rc; |
| 385 | } |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 386 | |
| 387 | |
| 388 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 389 | ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 390 | ipmi_request_t request, ipmi_response_t response, |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 391 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 392 | { |
| 393 | printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 394 | |
| 395 | // Status code. |
| 396 | ipmi_ret_t rc = IPMI_CC_OK; |
| 397 | |
| 398 | *data_len = strlen("THIS IS WILDCARD"); |
| 399 | |
| 400 | // Now pack actual response |
| 401 | memcpy(response, "THIS IS WILDCARD", *data_len); |
| 402 | |
| 403 | return rc; |
| 404 | } |
| 405 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 406 | void register_netfn_app_functions() |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 407 | { |
| 408 | 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] | 409 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CAP_BIT, NULL, ipmi_app_get_bt_capabilities); |
| 410 | |
| 411 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_WILDCARD); |
| 412 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_WILDCARD, NULL, ipmi_app_wildcard_handler); |
| 413 | |
| 414 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_RESET_WD); |
| 415 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, ipmi_app_reset_watchdog); |
| 416 | |
| 417 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_WD); |
| 418 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, ipmi_app_set_watchdog); |
| 419 | |
| 420 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_ID); |
| 421 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_ID, NULL, ipmi_app_get_device_id); |
| 422 | |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 423 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID); |
| 424 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID, NULL, ipmi_app_get_device_guid); |
| 425 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 426 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_ACPI); |
| 427 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, ipmi_app_set_acpi_power_state); |
| 428 | |
| 429 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_READ_EVENT); |
| 430 | 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] | 431 | |
| 432 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, |
| 433 | IPMI_CMD_SET_BMC_GLOBAL_ENABLES); |
| 434 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL, |
| 435 | ipmi_app_set_bmc_global_enables); |
| 436 | |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 437 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS); |
| 438 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS, NULL, ipmi_app_get_msg_flags); |
| 439 | |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 440 | |
| 441 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CHAN_INFO); |
| 442 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHAN_INFO, NULL, ipmi_app_channel_info); |
| 443 | |
| 444 | |
| 445 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 446 | return; |
| 447 | } |
| 448 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 449 | |