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