vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 1 | #include "apphandler.h" |
Patrick Williams | 37af733 | 2016-09-02 21:21:42 -0500 | [diff] [blame] | 2 | #include "host-ipmid/ipmid-api.h" |
Patrick Williams | 53a360e | 2016-08-12 22:01:02 -0500 | [diff] [blame] | 3 | #include "ipmid.hpp" |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 4 | #include "types.hpp" |
| 5 | #include "utils.hpp" |
| 6 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 7 | #include <stdio.h> |
| 8 | #include <string.h> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 9 | #include <stdint.h> |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 10 | #include <systemd/sd-bus.h> |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 11 | #include <mapper.h> |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 12 | #include <array> |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 13 | #include <arpa/inet.h> |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 14 | #include "transporthandler.hpp" |
| 15 | |
| 16 | #include <phosphor-logging/log.hpp> |
| 17 | #include <phosphor-logging/elog-errors.hpp> |
| 18 | #include "xyz/openbmc_project/Common/error.hpp" |
| 19 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 20 | extern sd_bus *bus; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 21 | |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 22 | constexpr auto app_obj = "/org/openbmc/NetworkManager/Interface"; |
| 23 | constexpr auto app_ifc = "org.openbmc.NetworkManager"; |
| 24 | constexpr auto app_nwinterface = "eth0"; |
| 25 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 26 | constexpr auto ipv4Protocol = "xyz.openbmc_project.Network.IP.Protocol.IPv4"; |
| 27 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 28 | void register_netfn_app_functions() __attribute__((constructor)); |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 29 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 30 | using namespace phosphor::logging; |
| 31 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
| 32 | |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 33 | // Offset in get device id command. |
| 34 | typedef struct |
| 35 | { |
| 36 | uint8_t id; |
| 37 | uint8_t revision; |
| 38 | uint8_t fw[2]; |
| 39 | uint8_t ipmi_ver; |
| 40 | uint8_t addn_dev_support; |
| 41 | uint8_t manuf_id[3]; |
| 42 | uint8_t prod_id[2]; |
| 43 | uint8_t aux[4]; |
| 44 | }__attribute__((packed)) ipmi_device_id_t; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 45 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 46 | ipmi_ret_t ipmi_app_set_acpi_power_state(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 47 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 48 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 49 | { |
| 50 | ipmi_ret_t rc = IPMI_CC_OK; |
| 51 | *data_len = 0; |
| 52 | |
| 53 | printf("IPMI SET ACPI STATE Ignoring for now\n"); |
| 54 | return rc; |
| 55 | } |
| 56 | |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 57 | |
| 58 | typedef struct |
| 59 | { |
| 60 | char major; |
| 61 | char minor; |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 62 | uint16_t d[2]; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 63 | } rev_t; |
| 64 | |
| 65 | |
| 66 | /* Currently only supports the vx.x-x-[-x] format Will return -1 if not in */ |
| 67 | /* the format this routine knows how to parse */ |
| 68 | /* version = v0.6-19-gf363f61-dirty */ |
| 69 | /* ^ ^ ^^ ^ */ |
| 70 | /* | | |----------|-- additional details */ |
| 71 | /* | |---------------- Minor */ |
| 72 | /* |------------------ Major */ |
| 73 | /* Additional details : If the option group exists it will force Auxiliary */ |
| 74 | /* Firmware Revision Information 4th byte to 1 indicating the build was */ |
| 75 | /* derived with additional edits */ |
| 76 | int convert_version(const char *p, rev_t *rev) |
| 77 | { |
| 78 | char *s, *token; |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 79 | uint16_t commits; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 80 | |
| 81 | if (*p != 'v') |
| 82 | return -1; |
| 83 | p++; |
| 84 | |
| 85 | s = strdup(p); |
| 86 | token = strtok(s,".-"); |
| 87 | |
| 88 | rev->major = (int8_t) atoi(token); |
| 89 | |
| 90 | token = strtok(NULL, ".-"); |
| 91 | rev->minor = (int8_t) atoi(token); |
| 92 | |
| 93 | // Capture the number of commits on top of the minor tag. |
| 94 | // I'm using BE format like the ipmi spec asked for |
| 95 | token = strtok(NULL,".-"); |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 96 | |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 97 | if (token) { |
| 98 | commits = (int16_t) atoi(token); |
| 99 | rev->d[0] = (commits>>8) | (commits<<8); |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 100 | |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 101 | // commit number we skip |
| 102 | token = strtok(NULL,".-"); |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 103 | |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 104 | } else { |
| 105 | rev->d[0] = 0; |
| 106 | } |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 107 | |
| 108 | // Any value of the optional parameter forces it to 1 |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 109 | if (token) |
| 110 | token = strtok(NULL,".-"); |
| 111 | |
| 112 | rev->d[1] = (token != NULL) ? 1 : 0; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 113 | |
| 114 | free(s); |
| 115 | return 0; |
| 116 | } |
| 117 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 118 | ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 119 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 120 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 121 | { |
| 122 | ipmi_ret_t rc = IPMI_CC_OK; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 123 | const char *objname = "/org/openbmc/inventory/system/chassis/motherboard/bmc"; |
| 124 | const char *iface = "org.openbmc.InventoryItem"; |
| 125 | char *ver = NULL; |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 126 | char *busname = NULL; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 127 | int r; |
| 128 | rev_t rev = {0}; |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 129 | ipmi_device_id_t dev_id{}; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 130 | |
| 131 | // Data length |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 132 | *data_len = sizeof(dev_id); |
| 133 | |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 134 | // From IPMI spec, controller that have different application commands, or different |
| 135 | // definitions of OEM fields, are expected to have different Device ID values. |
| 136 | // Set to 0 now. |
| 137 | |
| 138 | // Device Revision is set to 0 now. |
| 139 | // Bit7 identifies if device provide Device SDRs, obmc don't have SDR,we use ipmi to |
| 140 | // simulate SDR, hence the value: |
| 141 | dev_id.revision = 0x80; |
| 142 | |
| 143 | // Firmware revision is already implemented, so get it from appropriate position. |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 144 | r = mapper_get_service(bus, objname, &busname); |
| 145 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 146 | fprintf(stderr, "Failed to get %s bus name: %s\n", |
| 147 | objname, strerror(-r)); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 148 | goto finish; |
| 149 | } |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 150 | r = sd_bus_get_property_string(bus,busname,objname,iface,"version", NULL, &ver); |
| 151 | if ( r < 0 ) { |
| 152 | fprintf(stderr, "Failed to obtain version property: %s\n", strerror(-r)); |
| 153 | } else { |
| 154 | r = convert_version(ver, &rev); |
| 155 | if( r >= 0 ) { |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 156 | // bit7 identifies if the device is available, 0=normal operation, |
| 157 | // 1=device firmware, SDR update or self-initialization in progress. |
| 158 | // our SDR is normal working condition, so mask: |
| 159 | dev_id.fw[0] = 0x7F & rev.major; |
Adriana Kobylak | 0e91264 | 2016-06-22 16:54:39 -0500 | [diff] [blame] | 160 | |
| 161 | rev.minor = (rev.minor > 99 ? 99 : rev.minor); |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 162 | dev_id.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16; |
| 163 | memcpy(&dev_id.aux, rev.d, 4); |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 164 | } |
| 165 | } |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 166 | |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 167 | // IPMI Spec verison 2.0 |
| 168 | dev_id.ipmi_ver = 2; |
| 169 | |
| 170 | // Additional device Support. |
| 171 | // List the 'logical device' commands and functions that the controller supports |
| 172 | // that are in addition to the mandatory IPM and Application commands. |
| 173 | // [7] Chassis Device (device functions as chassis device per ICMB spec.) |
| 174 | // [6] Bridge (device responds to Bridge NetFn commands) |
| 175 | // [5] IPMB Event Generator |
| 176 | // [4] IPMB Event Receiver |
| 177 | // [3] FRU Inventory Device |
| 178 | // [2] SEL Device |
| 179 | // [1] SDR Repository Device |
| 180 | // [0] Sensor Device |
| 181 | // We support FRU/SEL/Sensor now: |
| 182 | dev_id.addn_dev_support = 0x8D; |
| 183 | |
| 184 | // This value is the IANA number assigned to "IBM Platform Firmware |
| 185 | // Division", which is also used by our service processor. We may want |
| 186 | // a different number or at least a different version? |
| 187 | dev_id.manuf_id[0] = 0x41; |
| 188 | dev_id.manuf_id[1] = 0xA7; |
| 189 | dev_id.manuf_id[2] = 0x00; |
| 190 | |
| 191 | // Witherspoon's product ID is hardcoded to 4F42(ASCII 'OB'). |
| 192 | // TODO: openbmc/openbmc#495 |
| 193 | dev_id.prod_id[0] = 0x4F; |
| 194 | dev_id.prod_id[1] = 0x42; |
| 195 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 196 | // Pack the actual response |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 197 | memcpy(response, &dev_id, *data_len); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 198 | finish: |
| 199 | free(busname); |
Xo Wang | e553638 | 2017-07-20 20:14:00 -0700 | [diff] [blame] | 200 | free(ver); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 201 | return rc; |
| 202 | } |
| 203 | |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 204 | ipmi_ret_t ipmi_app_get_self_test_results(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 205 | ipmi_request_t request, ipmi_response_t response, |
| 206 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 207 | { |
| 208 | ipmi_ret_t rc = IPMI_CC_OK; |
| 209 | |
| 210 | // Byte 2: |
| 211 | // 55h - No error. |
| 212 | // 56h - Self Test funciton not implemented in this controller. |
| 213 | // 57h - Corrupted or inaccesssible data or devices. |
| 214 | // 58h - Fatal hardware error. |
| 215 | // FFh - reserved. |
| 216 | // all other: Device-specific 'internal failure'. |
| 217 | // Byte 3: |
| 218 | // For byte 2 = 55h, 56h, FFh: 00h |
| 219 | // For byte 2 = 58h, all other: Device-specific |
| 220 | // For byte 2 = 57h: self-test error bitfield. |
| 221 | // Note: returning 57h does not imply that all test were run. |
| 222 | // [7] 1b = Cannot access SEL device. |
| 223 | // [6] 1b = Cannot access SDR Repository. |
| 224 | // [5] 1b = Cannot access BMC FRU device. |
| 225 | // [4] 1b = IPMB signal lines do not respond. |
| 226 | // [3] 1b = SDR Repository empty. |
| 227 | // [2] 1b = Internal Use Area of BMC FRU corrupted. |
| 228 | // [1] 1b = controller update 'boot block' firmware corrupted. |
| 229 | // [0] 1b = controller operational firmware corrupted. |
| 230 | |
| 231 | char selftestresults[2] = {0}; |
| 232 | |
| 233 | *data_len = 2; |
| 234 | |
| 235 | selftestresults[0] = 0x56; |
| 236 | selftestresults[1] = 0; |
| 237 | |
| 238 | memcpy(response, selftestresults, *data_len); |
| 239 | |
| 240 | return rc; |
| 241 | } |
| 242 | |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 243 | ipmi_ret_t ipmi_app_get_device_guid(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 244 | ipmi_request_t request, ipmi_response_t response, |
| 245 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 246 | { |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 247 | const char *objname = "/org/openbmc/control/chassis0"; |
Adriana Kobylak | 31bccae | 2015-11-05 13:31:06 -0600 | [diff] [blame] | 248 | const char *iface = "org.freedesktop.DBus.Properties"; |
| 249 | const char *chassis_iface = "org.openbmc.control.Chassis"; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 250 | sd_bus_message *reply = NULL; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 251 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 252 | int r = 0; |
| 253 | char *uuid = NULL; |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 254 | char *busname = NULL; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 255 | |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 256 | // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223 |
| 257 | // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte order |
| 258 | // Ex: 0x2332fc2c40e66298e511f2782395a361 |
| 259 | |
| 260 | const int resp_size = 16; // Response is 16 hex bytes per IPMI Spec |
| 261 | uint8_t resp_uuid[resp_size]; // Array to hold the formatted response |
| 262 | int resp_loc = resp_size-1; // Point resp end of array to save in reverse order |
| 263 | int i = 0; |
| 264 | char *tokptr = NULL; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 265 | char *id_octet = NULL; |
| 266 | |
| 267 | // Status code. |
| 268 | ipmi_ret_t rc = IPMI_CC_OK; |
| 269 | *data_len = 0; |
| 270 | |
| 271 | printf("IPMI GET DEVICE GUID\n"); |
| 272 | |
| 273 | // Call Get properties method with the interface and property name |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 274 | r = mapper_get_service(bus, objname, &busname); |
| 275 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 276 | fprintf(stderr, "Failed to get %s bus name: %s\n", |
| 277 | objname, strerror(-r)); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 278 | goto finish; |
| 279 | } |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 280 | r = sd_bus_call_method(bus,busname,objname,iface, |
| 281 | "Get",&error, &reply, "ss", |
| 282 | chassis_iface, "uuid"); |
| 283 | if (r < 0) |
| 284 | { |
| 285 | fprintf(stderr, "Failed to call Get Method: %s\n", strerror(-r)); |
| 286 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 287 | goto finish; |
| 288 | } |
| 289 | |
| 290 | r = sd_bus_message_read(reply, "v", "s", &uuid); |
| 291 | if (r < 0 || uuid == NULL) |
| 292 | { |
| 293 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 294 | rc = IPMI_CC_RESPONSE_ERROR; |
| 295 | goto finish; |
| 296 | } |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 297 | |
| 298 | // Traverse the UUID |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 299 | 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] | 300 | |
| 301 | if (id_octet == NULL) |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 302 | { |
| 303 | // Error |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 304 | fprintf(stderr, "Unexpected UUID format: %s", uuid); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 305 | rc = IPMI_CC_RESPONSE_ERROR; |
| 306 | goto finish; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | while (id_octet != NULL) |
| 310 | { |
| 311 | // Calculate the octet string size since it varies |
| 312 | // Divide it by 2 for the array size since 1 byte is built from 2 chars |
| 313 | int tmp_size = strlen(id_octet)/2; |
| 314 | |
| 315 | for(i = 0; i < tmp_size; i++) |
| 316 | { |
Joel Stanley | 38310cd | 2015-11-25 17:32:08 +1030 | [diff] [blame] | 317 | 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] | 318 | strncpy(tmp_array, id_octet, 2); // 2 chars at a time |
| 319 | |
| 320 | int resp_byte = strtoul(tmp_array, NULL, 16); // Convert to hex byte |
| 321 | memcpy((void*)&resp_uuid[resp_loc], &resp_byte, 1); // Copy end to first |
| 322 | resp_loc--; |
| 323 | id_octet+=2; // Finished with the 2 chars, advance |
| 324 | } |
| 325 | id_octet=strtok_r(NULL, "-", &tokptr); // Get next octet |
| 326 | } |
| 327 | |
| 328 | // Data length |
| 329 | *data_len = resp_size; |
| 330 | |
| 331 | // Pack the actual response |
| 332 | memcpy(response, &resp_uuid, *data_len); |
| 333 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 334 | finish: |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 335 | sd_bus_error_free(&error); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 336 | reply = sd_bus_message_unref(reply); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 337 | free(busname); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 338 | |
| 339 | return rc; |
| 340 | } |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 341 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 342 | ipmi_ret_t ipmi_app_get_bt_capabilities(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 343 | ipmi_request_t request, ipmi_response_t response, |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 344 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 345 | { |
| 346 | printf("Handling Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd); |
| 347 | |
| 348 | // Status code. |
| 349 | ipmi_ret_t rc = IPMI_CC_OK; |
| 350 | |
Adriana Kobylak | 88ad815 | 2016-12-13 10:09:08 -0600 | [diff] [blame] | 351 | // Per IPMI 2.0 spec, the input and output buffer size must be the max |
| 352 | // buffer size minus one byte to allocate space for the length byte. |
| 353 | uint8_t str[] = {0x01, MAX_IPMI_BUFFER-1, MAX_IPMI_BUFFER-1, 0x0A, 0x01}; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 354 | |
| 355 | // Data length |
| 356 | *data_len = sizeof(str); |
| 357 | |
| 358 | // Pack the actual response |
| 359 | memcpy(response, &str, *data_len); |
| 360 | |
| 361 | return rc; |
| 362 | } |
| 363 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 364 | |
| 365 | struct set_wd_data_t { |
| 366 | uint8_t t_use; |
| 367 | uint8_t t_action; |
| 368 | uint8_t preset; |
| 369 | uint8_t flags; |
| 370 | uint8_t ls; |
| 371 | uint8_t ms; |
| 372 | } __attribute__ ((packed)); |
| 373 | |
| 374 | |
| 375 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 376 | ipmi_ret_t ipmi_app_set_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 377 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 378 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 379 | { |
Vishwanatha Subbanna | 8fc0988 | 2017-06-12 19:57:37 +0530 | [diff] [blame] | 380 | const char *objname = "/xyz/openbmc_project/watchdog/host0"; |
| 381 | const char *iface = "xyz.openbmc_project.State.Watchdog"; |
| 382 | const char *property_iface = "org.freedesktop.DBus.Properties"; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 383 | sd_bus_message *reply = NULL; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 384 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 385 | int r = 0; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 386 | |
| 387 | set_wd_data_t *reqptr = (set_wd_data_t*) request; |
| 388 | uint16_t timer = 0; |
Vishwanatha Subbanna | 8fc0988 | 2017-06-12 19:57:37 +0530 | [diff] [blame] | 389 | |
| 390 | // Making this uint64_t to match with provider |
| 391 | uint64_t timer_ms = 0; |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 392 | char *busname = NULL; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 393 | *data_len = 0; |
| 394 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 395 | // Get number of 100ms intervals |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 396 | timer = (((uint16_t)reqptr->ms) << 8) + reqptr->ls; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 397 | // Get timer value in ms |
| 398 | timer_ms = timer * 100; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 399 | |
| 400 | printf("WATCHDOG SET Timer:[0x%X] 100ms intervals\n",timer); |
| 401 | |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 402 | // Get bus name |
| 403 | r = mapper_get_service(bus, objname, &busname); |
| 404 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 405 | fprintf(stderr, "Failed to get %s bus name: %s\n", |
| 406 | objname, strerror(-r)); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 407 | goto finish; |
| 408 | } |
Adriana Kobylak | 0896be3 | 2015-10-22 13:27:23 -0500 | [diff] [blame] | 409 | |
Vishwanatha Subbanna | 8fc0988 | 2017-06-12 19:57:37 +0530 | [diff] [blame] | 410 | // Disable watchdog if running |
| 411 | r = sd_bus_call_method(bus, busname, objname, property_iface, |
| 412 | "Set", &error, &reply, "ssv", |
| 413 | iface, "Enabled", "b", false); |
| 414 | if(r < 0) { |
| 415 | fprintf(stderr, "Failed to disable Watchdog: %s\n", |
| 416 | strerror(-r)); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 417 | goto finish; |
| 418 | } |
| 419 | |
| 420 | if (reqptr->t_use & 0x40) |
| 421 | { |
| 422 | sd_bus_error_free(&error); |
| 423 | reply = sd_bus_message_unref(reply); |
| 424 | |
Vishwanatha Subbanna | 8fc0988 | 2017-06-12 19:57:37 +0530 | [diff] [blame] | 425 | // Now Enable Watchdog |
| 426 | r = sd_bus_call_method(bus, busname, objname, property_iface, |
| 427 | "Set", &error, &reply, "ssv", |
| 428 | iface, "Enabled", "b", true); |
| 429 | if(r < 0) { |
| 430 | fprintf(stderr, "Failed to Enable Watchdog: %s\n", |
| 431 | strerror(-r)); |
| 432 | goto finish; |
| 433 | } |
| 434 | |
| 435 | // Set watchdog timer |
| 436 | r = sd_bus_call_method(bus, busname, objname, property_iface, |
| 437 | "Set", &error, &reply, "ssv", |
| 438 | iface, "TimeRemaining", "t", timer_ms); |
| 439 | if(r < 0) { |
| 440 | fprintf(stderr, "Failed to set new expiration time: %s\n", |
| 441 | strerror(-r)); |
| 442 | goto finish; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
| 446 | finish: |
| 447 | sd_bus_error_free(&error); |
| 448 | reply = sd_bus_message_unref(reply); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 449 | free(busname); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 450 | |
| 451 | return (r < 0) ? -1 : IPMI_CC_OK; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 455 | ipmi_ret_t ipmi_app_reset_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 456 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 457 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 458 | { |
Vishwanatha Subbanna | 8fc0988 | 2017-06-12 19:57:37 +0530 | [diff] [blame] | 459 | const char *objname = "/xyz/openbmc_project/watchdog/host0"; |
| 460 | const char *iface = "xyz.openbmc_project.State.Watchdog"; |
| 461 | const char *property_iface = "org.freedesktop.DBus.Properties"; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 462 | sd_bus_message *reply = NULL; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 463 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 464 | int r = 0; |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 465 | char *busname = NULL; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 466 | |
Vishwanatha Subbanna | 8fc0988 | 2017-06-12 19:57:37 +0530 | [diff] [blame] | 467 | // Current time interval that is set in watchdog. |
| 468 | uint64_t interval = 0; |
| 469 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 470 | // Status code. |
| 471 | ipmi_ret_t rc = IPMI_CC_OK; |
| 472 | *data_len = 0; |
| 473 | |
| 474 | printf("WATCHDOG RESET\n"); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 475 | // Get bus name |
| 476 | r = mapper_get_service(bus, objname, &busname); |
| 477 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 478 | fprintf(stderr, "Failed to get %s bus name: %s\n", |
| 479 | objname, strerror(-r)); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 480 | goto finish; |
| 481 | } |
Vishwanatha Subbanna | 8fc0988 | 2017-06-12 19:57:37 +0530 | [diff] [blame] | 482 | |
| 483 | // Get the current interval and set it back. |
| 484 | r = sd_bus_call_method(bus, busname, objname, property_iface, |
| 485 | "Get", &error, &reply, "ss", |
| 486 | iface, "Interval"); |
| 487 | |
| 488 | if(r < 0) { |
| 489 | fprintf(stderr, "Failed to get current Interval msg: %s\n", |
| 490 | strerror(-r)); |
| 491 | goto finish; |
| 492 | } |
| 493 | |
| 494 | // Now extract the value |
| 495 | r = sd_bus_message_read(reply, "v", "t", &interval); |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 496 | if (r < 0) { |
Vishwanatha Subbanna | 8fc0988 | 2017-06-12 19:57:37 +0530 | [diff] [blame] | 497 | fprintf(stderr, "Failed to read current interval: %s\n", |
| 498 | strerror(-r)); |
| 499 | goto finish; |
| 500 | } |
| 501 | |
| 502 | sd_bus_error_free(&error); |
| 503 | reply = sd_bus_message_unref(reply); |
| 504 | |
| 505 | // Set watchdog timer |
| 506 | r = sd_bus_call_method(bus, busname, objname, property_iface, |
| 507 | "Set", &error, &reply, "ssv", |
| 508 | iface, "TimeRemaining", "t", interval); |
| 509 | if(r < 0) { |
| 510 | fprintf(stderr, "Failed to refresh the timer: %s\n", |
| 511 | strerror(-r)); |
| 512 | goto finish; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 513 | } |
| 514 | |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 515 | finish: |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 516 | sd_bus_error_free(&error); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 517 | reply = sd_bus_message_unref(reply); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 518 | free(busname); |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 519 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 520 | return rc; |
| 521 | } |
| 522 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 523 | extern struct ChannelConfig_t channelConfig; |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 524 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 525 | ipmi_ret_t ipmi_set_channel_access(ipmi_netfn_t netfn, |
| 526 | ipmi_cmd_t cmd, |
| 527 | ipmi_request_t request, |
| 528 | ipmi_response_t response, |
| 529 | ipmi_data_len_t data_len, |
| 530 | ipmi_context_t context) |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 531 | { |
| 532 | ipmi_ret_t rc = IPMI_CC_OK; |
| 533 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 534 | std::string ipaddress; |
| 535 | std::string gateway; |
| 536 | uint8_t prefix {}; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 537 | uint32_t vlanID {}; |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 538 | |
| 539 | // Todo: parse the request data if needed. |
| 540 | |
| 541 | // Using Set Channel cmd to apply changes of Set Lan Cmd. |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 542 | try |
| 543 | { |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 544 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 545 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
| 546 | |
| 547 | log<level::INFO>("Network data from Cache", |
| 548 | entry("PREFIX=%s", channelConfig.netmask.c_str()), |
| 549 | entry("ADDRESS=%s", channelConfig.ipaddr.c_str()), |
| 550 | entry("GATEWAY=%s", channelConfig.gateway.c_str())); |
| 551 | |
| 552 | auto systemObject = ipmi::getDbusObject(bus, |
| 553 | ipmi::network::SYSTEMCONFIG_INTERFACE, |
| 554 | ipmi::network::ROOT); |
| 555 | |
| 556 | // TODO Currently IPMI supports single interface,need to handle |
| 557 | // Multiple interface through |
| 558 | // https://github.com/openbmc/openbmc/issues/2138 |
| 559 | |
| 560 | auto networkInterfaceObject = ipmi::getDbusObject( |
| 561 | bus, |
| 562 | ipmi::network::ETHERNET_INTERFACE, |
| 563 | ipmi::network::ROOT, |
| 564 | ipmi::network::INTERFACE); |
| 565 | |
| 566 | |
| 567 | |
| 568 | // check wthether user has given all the data |
| 569 | if (!channelConfig.ipaddr.empty() && |
| 570 | !channelConfig.netmask.empty() && |
| 571 | !channelConfig.gateway.empty()) |
| 572 | { |
| 573 | //convert mask into prefix |
| 574 | ipaddress = channelConfig.ipaddr; |
| 575 | prefix = ipmi::network::toPrefix(AF_INET, channelConfig.netmask); |
| 576 | gateway = channelConfig.gateway; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 577 | |
| 578 | if (channelConfig.vlanID != ipmi::network::VLAN_ID_MASK) |
| 579 | { |
| 580 | //get the first twelve bits which is vlan id |
| 581 | //not interested in rest of the bits. |
| 582 | vlanID = channelConfig.vlanID & ipmi::network::VLAN_ID_MASK; |
| 583 | channelConfig.vlanID = le32toh(channelConfig.vlanID); |
| 584 | } |
| 585 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 586 | } |
| 587 | else |
| 588 | { |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 589 | // We have partial filled cache so get the remaning |
| 590 | // info from the system. |
| 591 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 592 | // gets the network data from the system as user has |
| 593 | // not given all the data then use the data fetched from the |
| 594 | // system but it is implementation dependent,IPMI spec doesn't |
| 595 | // force it. |
| 596 | |
| 597 | // if system is not having any ip object don't throw error, |
| 598 | try |
| 599 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 600 | auto ipObjectInfo = ipmi::getDbusObject(bus, |
| 601 | ipmi::network::IP_INTERFACE, |
| 602 | ipmi::network::ROOT, |
| 603 | ipmi::network::IP_TYPE); |
| 604 | |
| 605 | auto properties = ipmi::getAllDbusProperties(bus, |
| 606 | ipObjectInfo.second, |
| 607 | ipObjectInfo.first, |
| 608 | ipmi::network::IP_INTERFACE); |
| 609 | |
| 610 | ipaddress = channelConfig.ipaddr.empty() ? |
| 611 | std::move(properties["Address"].get<std::string>()) : |
| 612 | channelConfig.ipaddr; |
| 613 | |
| 614 | prefix = channelConfig.netmask.empty() ? |
| 615 | properties["PrefixLength"].get<uint8_t>() : |
| 616 | ipmi::network::toPrefix(AF_INET, |
| 617 | channelConfig.netmask); |
| 618 | |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 619 | if (channelConfig.vlanID != ipmi::network::VLAN_ID_MASK) |
| 620 | { |
| 621 | //get the first twelve bits which is vlan id |
| 622 | //not interested in rest of the bits. |
| 623 | vlanID = channelConfig.vlanID & ipmi::network::VLAN_ID_MASK; |
| 624 | channelConfig.vlanID = le32toh(channelConfig.vlanID); |
| 625 | } |
| 626 | else |
| 627 | { |
| 628 | vlanID = ipmi::network::getVLAN(ipObjectInfo.first); |
| 629 | } |
| 630 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 631 | } |
| 632 | catch (InternalFailure& e) |
| 633 | { |
| 634 | log<level::INFO>("Failed to get IP object which matches", |
| 635 | entry("INTERFACE=%s", ipmi::network::IP_INTERFACE), |
| 636 | entry("MATCH=%s", ipmi::network::IP_TYPE)); |
| 637 | } |
| 638 | |
| 639 | auto systemProperties = ipmi::getAllDbusProperties( |
| 640 | bus, |
| 641 | systemObject.second, |
| 642 | systemObject.first, |
| 643 | ipmi::network::SYSTEMCONFIG_INTERFACE); |
| 644 | |
| 645 | gateway = channelConfig.gateway.empty() ? |
| 646 | std::move(systemProperties["DefaultGateway"].get<std::string>()) : |
| 647 | channelConfig.gateway; |
| 648 | |
| 649 | } |
| 650 | |
| 651 | // Currently network manager doesn't support purging of all the |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 652 | // ip addresses and the vlan interfaces from the parent interface, |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 653 | // TODO once the support is there, will make the change here. |
| 654 | // https://github.com/openbmc/openbmc/issues/2141. |
| 655 | |
| 656 | // TODO Currently IPMI supports single interface,need to handle |
| 657 | // Multiple interface through |
| 658 | // https://github.com/openbmc/openbmc/issues/2138 |
| 659 | |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 660 | //delete all the vlan interfaces |
| 661 | //delete all the ipv4 addresses |
| 662 | ipmi::deleteAllDbusObjects(bus, ipmi::network::ROOT, |
| 663 | ipmi::network::VLAN_INTERFACE); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 664 | ipmi::deleteAllDbusObjects(bus, ipmi::network::ROOT, |
| 665 | ipmi::network::IP_INTERFACE, |
| 666 | ipmi::network::IP_TYPE); |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 667 | if (vlanID) |
| 668 | { |
| 669 | ipmi::network::createVLAN(bus, ipmi::network::SERVICE, |
| 670 | ipmi::network::ROOT, |
| 671 | ipmi::network::INTERFACE, vlanID); |
| 672 | |
| 673 | networkInterfaceObject = ipmi::getDbusObject( |
| 674 | bus, |
| 675 | ipmi::network::VLAN_INTERFACE, |
| 676 | ipmi::network::ROOT); |
| 677 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 678 | |
| 679 | ipmi::network::createIP(bus, networkInterfaceObject.second, |
| 680 | networkInterfaceObject.first, |
| 681 | ipv4Protocol, ipaddress, prefix); |
| 682 | |
| 683 | ipmi::setDbusProperty(bus, systemObject.second, systemObject.first, |
| 684 | ipmi::network::SYSTEMCONFIG_INTERFACE, |
| 685 | "DefaultGateway", gateway); |
| 686 | |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 687 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 688 | catch (InternalFailure& e) |
| 689 | { |
| 690 | log<level::ERR>("Failed to set network data", |
| 691 | entry("PREFIX=%d", prefix), |
| 692 | entry("ADDRESS=%s", ipaddress), |
| 693 | entry("GATEWAY=%s", gateway)); |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 694 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 695 | commit<InternalFailure>(); |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 696 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 697 | } |
| 698 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 699 | channelConfig.clear(); |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 700 | return rc; |
| 701 | } |
| 702 | |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 703 | |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 704 | // ATTENTION: This ipmi function is very hardcoded on purpose |
| 705 | // OpenBMC does not fully support IPMI. This command is useful |
| 706 | // to have around because it enables testing of interfaces with |
| 707 | // the IPMI tool. |
| 708 | #define GET_CHANNEL_INFO_CHANNEL_OFFSET 0 |
| 709 | // IPMI Table 6-2 |
| 710 | #define IPMI_CHANNEL_TYPE_IPMB 1 |
| 711 | // IPMI Table 6-3 |
| 712 | #define IPMI_CHANNEL_MEDIUM_TYPE_OTHER 6 |
| 713 | |
| 714 | ipmi_ret_t ipmi_app_channel_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 715 | ipmi_request_t request, ipmi_response_t response, |
| 716 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 717 | { |
| 718 | ipmi_ret_t rc = IPMI_CC_OK; |
| 719 | uint8_t resp[] = { |
| 720 | 1, |
| 721 | IPMI_CHANNEL_MEDIUM_TYPE_OTHER, |
| 722 | IPMI_CHANNEL_TYPE_IPMB, |
| 723 | 1,0x41,0xA7,0x00,0,0}; |
| 724 | uint8_t *p = (uint8_t*) request; |
| 725 | |
| 726 | printf("IPMI APP GET CHANNEL INFO\n"); |
| 727 | |
tomjose | 7ec0add | 2016-06-27 07:59:28 -0500 | [diff] [blame] | 728 | // The supported channels numbers are 1 and 8. |
| 729 | // Channel Number E is used as way to identify the current channel |
| 730 | // that the command is being is received from. |
tomjose | 13fb441 | 2016-03-08 14:02:34 -0600 | [diff] [blame] | 731 | if (*p == 0xe || *p == 1 || *p == 8) { |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 732 | |
| 733 | *data_len = sizeof(resp); |
| 734 | memcpy(response, resp, *data_len); |
| 735 | |
| 736 | } else { |
| 737 | rc = IPMI_CC_PARM_OUT_OF_RANGE; |
| 738 | *data_len = 0; |
| 739 | } |
| 740 | |
| 741 | return rc; |
| 742 | } |
| 743 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 744 | ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 745 | ipmi_request_t request, ipmi_response_t response, |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 746 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 747 | { |
| 748 | printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 749 | |
| 750 | // Status code. |
Nan Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 751 | ipmi_ret_t rc = IPMI_CC_INVALID; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 752 | |
| 753 | *data_len = strlen("THIS IS WILDCARD"); |
| 754 | |
| 755 | // Now pack actual response |
| 756 | memcpy(response, "THIS IS WILDCARD", *data_len); |
| 757 | |
| 758 | return rc; |
| 759 | } |
| 760 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 761 | void register_netfn_app_functions() |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 762 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 763 | // <Get BT Interface Capabilities> |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 764 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CAP_BIT); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 765 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CAP_BIT, NULL, ipmi_app_get_bt_capabilities, |
| 766 | PRIVILEGE_USER); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 767 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 768 | // <Wildcard Command> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 769 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_WILDCARD); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 770 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_WILDCARD, NULL, ipmi_app_wildcard_handler, |
| 771 | PRIVILEGE_USER); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 772 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 773 | // <Reset Watchdog Timer> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 774 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_RESET_WD); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 775 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, ipmi_app_reset_watchdog, |
| 776 | PRIVILEGE_OPERATOR); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 777 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 778 | // <Set Watchdog Timer> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 779 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_WD); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 780 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, ipmi_app_set_watchdog, |
| 781 | PRIVILEGE_OPERATOR); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 782 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 783 | // <Get Device ID> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 784 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_ID); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 785 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_ID, NULL, ipmi_app_get_device_id, |
| 786 | PRIVILEGE_USER); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 787 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 788 | // <Get Self Test Results> |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 789 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_SELF_TEST_RESULTS); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 790 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_SELF_TEST_RESULTS, NULL, |
| 791 | ipmi_app_get_self_test_results, PRIVILEGE_USER); |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 792 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 793 | // <Get Device GUID> |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 794 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 795 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID, NULL, ipmi_app_get_device_guid, |
| 796 | PRIVILEGE_USER); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 797 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 798 | // <Set ACPI Power State> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 799 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_ACPI); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 800 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, ipmi_app_set_acpi_power_state, |
| 801 | PRIVILEGE_ADMIN); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 802 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 803 | // <Set Channel Access> |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 804 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, |
| 805 | IPMI_CMD_SET_CHAN_ACCESS); |
| 806 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_CHAN_ACCESS, NULL, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 807 | ipmi_set_channel_access, PRIVILEGE_ADMIN); |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 808 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 809 | // <Get Channel Info Command> |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 810 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CHAN_INFO); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 811 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHAN_INFO, NULL, ipmi_app_channel_info, |
| 812 | PRIVILEGE_USER); |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 813 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 814 | return; |
| 815 | } |
| 816 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 817 | |