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"; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 122 | sd_bus_message *reply = NULL, *m = NULL; |
| 123 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 124 | int r = 0; |
| 125 | char *uuid = NULL; |
| 126 | |
| 127 | // Status code. |
| 128 | ipmi_ret_t rc = IPMI_CC_OK; |
| 129 | *data_len = 0; |
| 130 | |
| 131 | printf("IPMI GET DEVICE GUID\n"); |
| 132 | |
Adriana Kobylak | 31bccae | 2015-11-05 13:31:06 -0600 | [diff] [blame] | 133 | // Call Get properties method with the interface and property name |
| 134 | r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"Get"); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 135 | if (r < 0) { |
Adriana Kobylak | 31bccae | 2015-11-05 13:31:06 -0600 | [diff] [blame] | 136 | fprintf(stderr, "Failed to add the Get method object: %s\n", strerror(-r)); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 137 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 138 | } |
Adriana Kobylak | 31bccae | 2015-11-05 13:31:06 -0600 | [diff] [blame] | 139 | r = sd_bus_message_append(m, "ss", chassis_iface, "uuid"); |
| 140 | if (r < 0) { |
| 141 | fprintf(stderr, "Failed to append arguments: %s\n", strerror(-r)); |
| 142 | return -1; |
| 143 | } |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 144 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 145 | if (r < 0) { |
Adriana Kobylak | 31bccae | 2015-11-05 13:31:06 -0600 | [diff] [blame] | 146 | fprintf(stderr, "Failed to call the Get method: %s\n", strerror(-r)); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 147 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 148 | } |
Adriana Kobylak | 31bccae | 2015-11-05 13:31:06 -0600 | [diff] [blame] | 149 | r = sd_bus_message_read(reply, "v", "s", &uuid); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 150 | if (r < 0) { |
| 151 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 152 | return IPMI_CC_RESPONSE_ERROR; |
| 153 | } |
| 154 | if (uuid == NULL) |
| 155 | { |
| 156 | fprintf(stderr, "Failed to get a valid response: %s", strerror(-r)); |
| 157 | return IPMI_CC_RESPONSE_ERROR; |
| 158 | } |
| 159 | |
| 160 | // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223 |
| 161 | // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte order |
| 162 | // Ex: 0x2332fc2c40e66298e511f2782395a361 |
| 163 | |
| 164 | const int resp_size = 16; // Response is 16 hex bytes per IPMI Spec |
| 165 | uint8_t resp_uuid[resp_size]; // Array to hold the formatted response |
| 166 | int resp_loc = resp_size-1; // Point resp end of array to save in reverse order |
| 167 | int i = 0; |
| 168 | char *tokptr = NULL; |
| 169 | |
| 170 | // Traverse the UUID |
| 171 | char* id_octet = strtok_r(uuid, "-", &tokptr); // Get the UUID octects separated by dash |
| 172 | |
| 173 | if (id_octet == NULL) |
| 174 | { // Error |
| 175 | fprintf(stderr, "Unexpected UUID format: %s", uuid); |
| 176 | return IPMI_CC_RESPONSE_ERROR; |
| 177 | } |
| 178 | |
| 179 | while (id_octet != NULL) |
| 180 | { |
| 181 | // Calculate the octet string size since it varies |
| 182 | // Divide it by 2 for the array size since 1 byte is built from 2 chars |
| 183 | int tmp_size = strlen(id_octet)/2; |
| 184 | |
| 185 | for(i = 0; i < tmp_size; i++) |
| 186 | { |
Joel Stanley | 38310cd | 2015-11-25 17:32:08 +1030 | [diff] [blame] | 187 | 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] | 188 | strncpy(tmp_array, id_octet, 2); // 2 chars at a time |
| 189 | |
| 190 | int resp_byte = strtoul(tmp_array, NULL, 16); // Convert to hex byte |
| 191 | memcpy((void*)&resp_uuid[resp_loc], &resp_byte, 1); // Copy end to first |
| 192 | resp_loc--; |
| 193 | id_octet+=2; // Finished with the 2 chars, advance |
| 194 | } |
| 195 | id_octet=strtok_r(NULL, "-", &tokptr); // Get next octet |
| 196 | } |
| 197 | |
| 198 | // Data length |
| 199 | *data_len = resp_size; |
| 200 | |
| 201 | // Pack the actual response |
| 202 | memcpy(response, &resp_uuid, *data_len); |
| 203 | |
| 204 | sd_bus_error_free(&error); |
| 205 | sd_bus_message_unref(m); |
| 206 | |
| 207 | return rc; |
| 208 | } |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 209 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 210 | ipmi_ret_t ipmi_app_get_bt_capabilities(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 Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd); |
| 215 | |
| 216 | // Status code. |
| 217 | ipmi_ret_t rc = IPMI_CC_OK; |
| 218 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 219 | uint8_t str[] = {0x01, MAX_IPMI_BUFFER, MAX_IPMI_BUFFER, 0x0A, 0x01}; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 220 | |
| 221 | // Data length |
| 222 | *data_len = sizeof(str); |
| 223 | |
| 224 | // Pack the actual response |
| 225 | memcpy(response, &str, *data_len); |
| 226 | |
| 227 | return rc; |
| 228 | } |
| 229 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 230 | |
| 231 | struct set_wd_data_t { |
| 232 | uint8_t t_use; |
| 233 | uint8_t t_action; |
| 234 | uint8_t preset; |
| 235 | uint8_t flags; |
| 236 | uint8_t ls; |
| 237 | uint8_t ms; |
| 238 | } __attribute__ ((packed)); |
| 239 | |
| 240 | |
| 241 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 242 | ipmi_ret_t ipmi_app_set_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 243 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 244 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 245 | { |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 246 | const char *busname = "org.openbmc.watchdog.Host"; |
Chris Austen | 454acfe | 2015-10-29 23:03:34 -0500 | [diff] [blame] | 247 | const char *objname = "/org/openbmc/watchdog/host0"; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 248 | const char *iface = "org.openbmc.Watchdog"; |
| 249 | sd_bus_message *reply = NULL, *m = NULL; |
| 250 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 251 | int r = 0; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 252 | |
| 253 | set_wd_data_t *reqptr = (set_wd_data_t*) request; |
| 254 | uint16_t timer = 0; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 255 | uint32_t timer_ms = 0; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 256 | // Status code. |
| 257 | ipmi_ret_t rc = IPMI_CC_OK; |
| 258 | |
| 259 | *data_len = 0; |
| 260 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 261 | // Get number of 100ms intervals |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 262 | timer = (((uint16_t)reqptr->ms) << 8) + reqptr->ls; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 263 | // Get timer value in ms |
| 264 | timer_ms = timer * 100; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 265 | |
| 266 | printf("WATCHDOG SET Timer:[0x%X] 100ms intervals\n",timer); |
| 267 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 268 | // Set watchdog timer |
| 269 | r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"set"); |
| 270 | if (r < 0) { |
| 271 | fprintf(stderr, "Failed to add the set method object: %s\n", strerror(-r)); |
| 272 | return -1; |
| 273 | } |
| 274 | r = sd_bus_message_append(m, "i", timer_ms); |
| 275 | if (r < 0) { |
| 276 | fprintf(stderr, "Failed to add timer value: %s\n", strerror(-r)); |
| 277 | return -1; |
| 278 | } |
| 279 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 280 | if (r < 0) { |
| 281 | fprintf(stderr, "Failed to call the set method: %s\n", strerror(-r)); |
| 282 | return -1; |
| 283 | } |
| 284 | |
Adriana Kobylak | 0896be3 | 2015-10-22 13:27:23 -0500 | [diff] [blame] | 285 | // Stop the current watchdog if any |
| 286 | 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] | 287 | if (r < 0) { |
| 288 | fprintf(stderr, "Failed to add the start method object: %s\n", strerror(-r)); |
| 289 | return -1; |
| 290 | } |
| 291 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 292 | if (r < 0) { |
| 293 | fprintf(stderr, "Failed to call the start method: %s\n", strerror(-r)); |
| 294 | return -1; |
| 295 | } |
| 296 | |
Adriana Kobylak | 0896be3 | 2015-10-22 13:27:23 -0500 | [diff] [blame] | 297 | // Start the watchdog if requested |
| 298 | if (reqptr->t_use & 0x40) |
| 299 | { |
| 300 | r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"start"); |
| 301 | if (r < 0) { |
| 302 | fprintf(stderr, "Failed to add the start method object: %s\n", strerror(-r)); |
| 303 | return -1; |
| 304 | } |
| 305 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 306 | if (r < 0) { |
| 307 | fprintf(stderr, "Failed to call the start method: %s\n", strerror(-r)); |
| 308 | return -1; |
| 309 | } |
| 310 | } |
| 311 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 312 | sd_bus_error_free(&error); |
| 313 | sd_bus_message_unref(m); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 314 | |
| 315 | return rc; |
| 316 | } |
| 317 | |
| 318 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 319 | ipmi_ret_t ipmi_app_reset_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 320 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 321 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 322 | { |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 323 | const char *busname = "org.openbmc.watchdog.Host"; |
Chris Austen | 454acfe | 2015-10-29 23:03:34 -0500 | [diff] [blame] | 324 | const char *objname = "/org/openbmc/watchdog/host0"; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 325 | const char *iface = "org.openbmc.Watchdog"; |
| 326 | sd_bus_message *reply = NULL, *m = NULL; |
| 327 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 328 | int r = 0; |
| 329 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 330 | // Status code. |
| 331 | ipmi_ret_t rc = IPMI_CC_OK; |
| 332 | *data_len = 0; |
| 333 | |
| 334 | printf("WATCHDOG RESET\n"); |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 335 | |
| 336 | // Refresh watchdog |
| 337 | r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"poke"); |
| 338 | if (r < 0) { |
| 339 | fprintf(stderr, "Failed to add the method object: %s\n", strerror(-r)); |
| 340 | return -1; |
| 341 | } |
| 342 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 343 | if (r < 0) { |
| 344 | fprintf(stderr, "Failed to call the method: %s\n", strerror(-r)); |
| 345 | return -1; |
| 346 | } |
| 347 | |
| 348 | sd_bus_error_free(&error); |
| 349 | sd_bus_message_unref(m); |
| 350 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 351 | return rc; |
| 352 | } |
| 353 | |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 354 | // ATTENTION: This ipmi function is very hardcoded on purpose |
| 355 | // OpenBMC does not fully support IPMI. This command is useful |
| 356 | // to have around because it enables testing of interfaces with |
| 357 | // the IPMI tool. |
| 358 | #define GET_CHANNEL_INFO_CHANNEL_OFFSET 0 |
| 359 | // IPMI Table 6-2 |
| 360 | #define IPMI_CHANNEL_TYPE_IPMB 1 |
| 361 | // IPMI Table 6-3 |
| 362 | #define IPMI_CHANNEL_MEDIUM_TYPE_OTHER 6 |
| 363 | |
| 364 | ipmi_ret_t ipmi_app_channel_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 365 | ipmi_request_t request, ipmi_response_t response, |
| 366 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 367 | { |
| 368 | ipmi_ret_t rc = IPMI_CC_OK; |
| 369 | uint8_t resp[] = { |
| 370 | 1, |
| 371 | IPMI_CHANNEL_MEDIUM_TYPE_OTHER, |
| 372 | IPMI_CHANNEL_TYPE_IPMB, |
| 373 | 1,0x41,0xA7,0x00,0,0}; |
| 374 | uint8_t *p = (uint8_t*) request; |
| 375 | |
| 376 | printf("IPMI APP GET CHANNEL INFO\n"); |
| 377 | |
| 378 | // I"m only supporting channel 1. 0xE is the 'default channel' |
| 379 | if (*p == 0xe || *p == 1) { |
| 380 | |
| 381 | *data_len = sizeof(resp); |
| 382 | memcpy(response, resp, *data_len); |
| 383 | |
| 384 | } else { |
| 385 | rc = IPMI_CC_PARM_OUT_OF_RANGE; |
| 386 | *data_len = 0; |
| 387 | } |
| 388 | |
| 389 | return rc; |
| 390 | } |
| 391 | |
Adriana Kobylak | dfc8d77 | 2015-10-20 09:34:48 -0500 | [diff] [blame] | 392 | ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 393 | ipmi_request_t request, ipmi_response_t response, |
| 394 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 395 | { |
| 396 | ipmi_ret_t rc = IPMI_CC_OK; |
| 397 | *data_len = 0; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 398 | |
Adriana Kobylak | dfc8d77 | 2015-10-20 09:34:48 -0500 | [diff] [blame] | 399 | // Event and message logging enabled by default so return for now |
| 400 | printf("IPMI APP SET BMC GLOBAL ENABLES Ignoring for now\n"); |
| 401 | |
| 402 | return rc; |
| 403 | } |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 404 | |
| 405 | |
| 406 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 407 | ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 408 | ipmi_request_t request, ipmi_response_t response, |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 409 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 410 | { |
| 411 | printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 412 | |
| 413 | // Status code. |
| 414 | ipmi_ret_t rc = IPMI_CC_OK; |
| 415 | |
| 416 | *data_len = strlen("THIS IS WILDCARD"); |
| 417 | |
| 418 | // Now pack actual response |
| 419 | memcpy(response, "THIS IS WILDCARD", *data_len); |
| 420 | |
| 421 | return rc; |
| 422 | } |
| 423 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 424 | void register_netfn_app_functions() |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 425 | { |
| 426 | 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] | 427 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CAP_BIT, NULL, ipmi_app_get_bt_capabilities); |
| 428 | |
| 429 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_WILDCARD); |
| 430 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_WILDCARD, NULL, ipmi_app_wildcard_handler); |
| 431 | |
| 432 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_RESET_WD); |
| 433 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, ipmi_app_reset_watchdog); |
| 434 | |
| 435 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_WD); |
| 436 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, ipmi_app_set_watchdog); |
| 437 | |
| 438 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_ID); |
| 439 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_ID, NULL, ipmi_app_get_device_id); |
| 440 | |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 441 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID); |
| 442 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID, NULL, ipmi_app_get_device_guid); |
| 443 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 444 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_ACPI); |
| 445 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, ipmi_app_set_acpi_power_state); |
| 446 | |
| 447 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_READ_EVENT); |
| 448 | 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] | 449 | |
| 450 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, |
| 451 | IPMI_CMD_SET_BMC_GLOBAL_ENABLES); |
| 452 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL, |
| 453 | ipmi_app_set_bmc_global_enables); |
| 454 | |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 455 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS); |
| 456 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS, NULL, ipmi_app_get_msg_flags); |
| 457 | |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 458 | |
| 459 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CHAN_INFO); |
| 460 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHAN_INFO, NULL, ipmi_app_channel_info); |
| 461 | |
| 462 | |
| 463 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 464 | return; |
| 465 | } |
| 466 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 467 | |