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