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 | |
Patrick Venture | 6c50ad9 | 2017-07-29 22:38:28 -0700 | [diff] [blame] | 420 | /* |
| 421 | * If the action is 0, it means, do nothing. Multiple actions on timer |
| 422 | * expiration aren't supported by phosphor-watchdog yet, so when the |
| 423 | * action set is "none", we should just leave the timer disabled. |
| 424 | */ |
| 425 | if (0 == reqptr->t_action) |
| 426 | { |
| 427 | goto finish; |
| 428 | } |
| 429 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 430 | if (reqptr->t_use & 0x40) |
| 431 | { |
| 432 | sd_bus_error_free(&error); |
| 433 | reply = sd_bus_message_unref(reply); |
| 434 | |
Vishwanatha Subbanna | 8fc0988 | 2017-06-12 19:57:37 +0530 | [diff] [blame] | 435 | // Now Enable Watchdog |
| 436 | r = sd_bus_call_method(bus, busname, objname, property_iface, |
| 437 | "Set", &error, &reply, "ssv", |
| 438 | iface, "Enabled", "b", true); |
| 439 | if(r < 0) { |
| 440 | fprintf(stderr, "Failed to Enable Watchdog: %s\n", |
| 441 | strerror(-r)); |
| 442 | goto finish; |
| 443 | } |
| 444 | |
| 445 | // Set watchdog timer |
| 446 | r = sd_bus_call_method(bus, busname, objname, property_iface, |
| 447 | "Set", &error, &reply, "ssv", |
| 448 | iface, "TimeRemaining", "t", timer_ms); |
| 449 | if(r < 0) { |
| 450 | fprintf(stderr, "Failed to set new expiration time: %s\n", |
| 451 | strerror(-r)); |
| 452 | goto finish; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
| 456 | finish: |
| 457 | sd_bus_error_free(&error); |
| 458 | reply = sd_bus_message_unref(reply); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 459 | free(busname); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 460 | |
| 461 | return (r < 0) ? -1 : IPMI_CC_OK; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 465 | ipmi_ret_t ipmi_app_reset_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 466 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 467 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 468 | { |
Vishwanatha Subbanna | 8fc0988 | 2017-06-12 19:57:37 +0530 | [diff] [blame] | 469 | const char *objname = "/xyz/openbmc_project/watchdog/host0"; |
| 470 | const char *iface = "xyz.openbmc_project.State.Watchdog"; |
| 471 | const char *property_iface = "org.freedesktop.DBus.Properties"; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 472 | sd_bus_message *reply = NULL; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 473 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 474 | int r = 0; |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 475 | char *busname = NULL; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 476 | |
Vishwanatha Subbanna | 8fc0988 | 2017-06-12 19:57:37 +0530 | [diff] [blame] | 477 | // Current time interval that is set in watchdog. |
| 478 | uint64_t interval = 0; |
| 479 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 480 | // Status code. |
| 481 | ipmi_ret_t rc = IPMI_CC_OK; |
| 482 | *data_len = 0; |
| 483 | |
| 484 | printf("WATCHDOG RESET\n"); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 485 | // Get bus name |
| 486 | r = mapper_get_service(bus, objname, &busname); |
| 487 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 488 | fprintf(stderr, "Failed to get %s bus name: %s\n", |
| 489 | objname, strerror(-r)); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 490 | goto finish; |
| 491 | } |
Vishwanatha Subbanna | 8fc0988 | 2017-06-12 19:57:37 +0530 | [diff] [blame] | 492 | |
| 493 | // Get the current interval and set it back. |
| 494 | r = sd_bus_call_method(bus, busname, objname, property_iface, |
| 495 | "Get", &error, &reply, "ss", |
| 496 | iface, "Interval"); |
| 497 | |
| 498 | if(r < 0) { |
| 499 | fprintf(stderr, "Failed to get current Interval msg: %s\n", |
| 500 | strerror(-r)); |
| 501 | goto finish; |
| 502 | } |
| 503 | |
| 504 | // Now extract the value |
| 505 | r = sd_bus_message_read(reply, "v", "t", &interval); |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 506 | if (r < 0) { |
Vishwanatha Subbanna | 8fc0988 | 2017-06-12 19:57:37 +0530 | [diff] [blame] | 507 | fprintf(stderr, "Failed to read current interval: %s\n", |
| 508 | strerror(-r)); |
| 509 | goto finish; |
| 510 | } |
| 511 | |
| 512 | sd_bus_error_free(&error); |
| 513 | reply = sd_bus_message_unref(reply); |
| 514 | |
| 515 | // Set watchdog timer |
| 516 | r = sd_bus_call_method(bus, busname, objname, property_iface, |
| 517 | "Set", &error, &reply, "ssv", |
| 518 | iface, "TimeRemaining", "t", interval); |
| 519 | if(r < 0) { |
| 520 | fprintf(stderr, "Failed to refresh the timer: %s\n", |
| 521 | strerror(-r)); |
| 522 | goto finish; |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 523 | } |
| 524 | |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 525 | finish: |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 526 | sd_bus_error_free(&error); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 527 | reply = sd_bus_message_unref(reply); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 528 | free(busname); |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 529 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 530 | return rc; |
| 531 | } |
| 532 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 533 | extern struct ChannelConfig_t channelConfig; |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 534 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 535 | ipmi_ret_t ipmi_set_channel_access(ipmi_netfn_t netfn, |
| 536 | ipmi_cmd_t cmd, |
| 537 | ipmi_request_t request, |
| 538 | ipmi_response_t response, |
| 539 | ipmi_data_len_t data_len, |
| 540 | ipmi_context_t context) |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 541 | { |
| 542 | ipmi_ret_t rc = IPMI_CC_OK; |
| 543 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 544 | std::string ipaddress; |
| 545 | std::string gateway; |
| 546 | uint8_t prefix {}; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 547 | uint32_t vlanID {}; |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 548 | |
| 549 | // Todo: parse the request data if needed. |
| 550 | |
| 551 | // Using Set Channel cmd to apply changes of Set Lan Cmd. |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 552 | try |
| 553 | { |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 554 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 555 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
| 556 | |
| 557 | log<level::INFO>("Network data from Cache", |
| 558 | entry("PREFIX=%s", channelConfig.netmask.c_str()), |
| 559 | entry("ADDRESS=%s", channelConfig.ipaddr.c_str()), |
| 560 | entry("GATEWAY=%s", channelConfig.gateway.c_str())); |
| 561 | |
| 562 | auto systemObject = ipmi::getDbusObject(bus, |
| 563 | ipmi::network::SYSTEMCONFIG_INTERFACE, |
| 564 | ipmi::network::ROOT); |
| 565 | |
| 566 | // TODO Currently IPMI supports single interface,need to handle |
| 567 | // Multiple interface through |
| 568 | // https://github.com/openbmc/openbmc/issues/2138 |
| 569 | |
| 570 | auto networkInterfaceObject = ipmi::getDbusObject( |
| 571 | bus, |
| 572 | ipmi::network::ETHERNET_INTERFACE, |
| 573 | ipmi::network::ROOT, |
| 574 | ipmi::network::INTERFACE); |
| 575 | |
| 576 | |
| 577 | |
| 578 | // check wthether user has given all the data |
| 579 | if (!channelConfig.ipaddr.empty() && |
| 580 | !channelConfig.netmask.empty() && |
| 581 | !channelConfig.gateway.empty()) |
| 582 | { |
| 583 | //convert mask into prefix |
| 584 | ipaddress = channelConfig.ipaddr; |
| 585 | prefix = ipmi::network::toPrefix(AF_INET, channelConfig.netmask); |
| 586 | gateway = channelConfig.gateway; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 587 | |
| 588 | if (channelConfig.vlanID != ipmi::network::VLAN_ID_MASK) |
| 589 | { |
| 590 | //get the first twelve bits which is vlan id |
| 591 | //not interested in rest of the bits. |
| 592 | vlanID = channelConfig.vlanID & ipmi::network::VLAN_ID_MASK; |
| 593 | channelConfig.vlanID = le32toh(channelConfig.vlanID); |
| 594 | } |
| 595 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 596 | } |
| 597 | else |
| 598 | { |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 599 | // We have partial filled cache so get the remaning |
| 600 | // info from the system. |
| 601 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 602 | // gets the network data from the system as user has |
| 603 | // not given all the data then use the data fetched from the |
| 604 | // system but it is implementation dependent,IPMI spec doesn't |
| 605 | // force it. |
| 606 | |
| 607 | // if system is not having any ip object don't throw error, |
| 608 | try |
| 609 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 610 | auto ipObjectInfo = ipmi::getDbusObject(bus, |
| 611 | ipmi::network::IP_INTERFACE, |
| 612 | ipmi::network::ROOT, |
| 613 | ipmi::network::IP_TYPE); |
| 614 | |
| 615 | auto properties = ipmi::getAllDbusProperties(bus, |
| 616 | ipObjectInfo.second, |
| 617 | ipObjectInfo.first, |
| 618 | ipmi::network::IP_INTERFACE); |
| 619 | |
| 620 | ipaddress = channelConfig.ipaddr.empty() ? |
| 621 | std::move(properties["Address"].get<std::string>()) : |
| 622 | channelConfig.ipaddr; |
| 623 | |
| 624 | prefix = channelConfig.netmask.empty() ? |
| 625 | properties["PrefixLength"].get<uint8_t>() : |
| 626 | ipmi::network::toPrefix(AF_INET, |
| 627 | channelConfig.netmask); |
| 628 | |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 629 | if (channelConfig.vlanID != ipmi::network::VLAN_ID_MASK) |
| 630 | { |
| 631 | //get the first twelve bits which is vlan id |
| 632 | //not interested in rest of the bits. |
| 633 | vlanID = channelConfig.vlanID & ipmi::network::VLAN_ID_MASK; |
| 634 | channelConfig.vlanID = le32toh(channelConfig.vlanID); |
| 635 | } |
| 636 | else |
| 637 | { |
| 638 | vlanID = ipmi::network::getVLAN(ipObjectInfo.first); |
| 639 | } |
| 640 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 641 | } |
| 642 | catch (InternalFailure& e) |
| 643 | { |
| 644 | log<level::INFO>("Failed to get IP object which matches", |
| 645 | entry("INTERFACE=%s", ipmi::network::IP_INTERFACE), |
| 646 | entry("MATCH=%s", ipmi::network::IP_TYPE)); |
| 647 | } |
| 648 | |
| 649 | auto systemProperties = ipmi::getAllDbusProperties( |
| 650 | bus, |
| 651 | systemObject.second, |
| 652 | systemObject.first, |
| 653 | ipmi::network::SYSTEMCONFIG_INTERFACE); |
| 654 | |
| 655 | gateway = channelConfig.gateway.empty() ? |
| 656 | std::move(systemProperties["DefaultGateway"].get<std::string>()) : |
| 657 | channelConfig.gateway; |
| 658 | |
| 659 | } |
| 660 | |
| 661 | // Currently network manager doesn't support purging of all the |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 662 | // ip addresses and the vlan interfaces from the parent interface, |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 663 | // TODO once the support is there, will make the change here. |
| 664 | // https://github.com/openbmc/openbmc/issues/2141. |
| 665 | |
| 666 | // TODO Currently IPMI supports single interface,need to handle |
| 667 | // Multiple interface through |
| 668 | // https://github.com/openbmc/openbmc/issues/2138 |
| 669 | |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 670 | //delete all the vlan interfaces |
| 671 | //delete all the ipv4 addresses |
| 672 | ipmi::deleteAllDbusObjects(bus, ipmi::network::ROOT, |
| 673 | ipmi::network::VLAN_INTERFACE); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 674 | ipmi::deleteAllDbusObjects(bus, ipmi::network::ROOT, |
| 675 | ipmi::network::IP_INTERFACE, |
| 676 | ipmi::network::IP_TYPE); |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 677 | if (vlanID) |
| 678 | { |
| 679 | ipmi::network::createVLAN(bus, ipmi::network::SERVICE, |
| 680 | ipmi::network::ROOT, |
| 681 | ipmi::network::INTERFACE, vlanID); |
| 682 | |
| 683 | networkInterfaceObject = ipmi::getDbusObject( |
| 684 | bus, |
| 685 | ipmi::network::VLAN_INTERFACE, |
| 686 | ipmi::network::ROOT); |
| 687 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 688 | |
| 689 | ipmi::network::createIP(bus, networkInterfaceObject.second, |
| 690 | networkInterfaceObject.first, |
| 691 | ipv4Protocol, ipaddress, prefix); |
| 692 | |
| 693 | ipmi::setDbusProperty(bus, systemObject.second, systemObject.first, |
| 694 | ipmi::network::SYSTEMCONFIG_INTERFACE, |
| 695 | "DefaultGateway", gateway); |
| 696 | |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 697 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 698 | catch (InternalFailure& e) |
| 699 | { |
| 700 | log<level::ERR>("Failed to set network data", |
| 701 | entry("PREFIX=%d", prefix), |
| 702 | entry("ADDRESS=%s", ipaddress), |
| 703 | entry("GATEWAY=%s", gateway)); |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 704 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 705 | commit<InternalFailure>(); |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 706 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 707 | } |
| 708 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 709 | channelConfig.clear(); |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 710 | return rc; |
| 711 | } |
| 712 | |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 713 | |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 714 | // ATTENTION: This ipmi function is very hardcoded on purpose |
| 715 | // OpenBMC does not fully support IPMI. This command is useful |
| 716 | // to have around because it enables testing of interfaces with |
| 717 | // the IPMI tool. |
| 718 | #define GET_CHANNEL_INFO_CHANNEL_OFFSET 0 |
| 719 | // IPMI Table 6-2 |
| 720 | #define IPMI_CHANNEL_TYPE_IPMB 1 |
| 721 | // IPMI Table 6-3 |
| 722 | #define IPMI_CHANNEL_MEDIUM_TYPE_OTHER 6 |
| 723 | |
| 724 | ipmi_ret_t ipmi_app_channel_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 725 | ipmi_request_t request, ipmi_response_t response, |
| 726 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 727 | { |
| 728 | ipmi_ret_t rc = IPMI_CC_OK; |
| 729 | uint8_t resp[] = { |
| 730 | 1, |
| 731 | IPMI_CHANNEL_MEDIUM_TYPE_OTHER, |
| 732 | IPMI_CHANNEL_TYPE_IPMB, |
| 733 | 1,0x41,0xA7,0x00,0,0}; |
| 734 | uint8_t *p = (uint8_t*) request; |
| 735 | |
| 736 | printf("IPMI APP GET CHANNEL INFO\n"); |
| 737 | |
tomjose | 7ec0add | 2016-06-27 07:59:28 -0500 | [diff] [blame] | 738 | // The supported channels numbers are 1 and 8. |
| 739 | // Channel Number E is used as way to identify the current channel |
| 740 | // that the command is being is received from. |
tomjose | 13fb441 | 2016-03-08 14:02:34 -0600 | [diff] [blame] | 741 | if (*p == 0xe || *p == 1 || *p == 8) { |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 742 | |
| 743 | *data_len = sizeof(resp); |
| 744 | memcpy(response, resp, *data_len); |
| 745 | |
| 746 | } else { |
| 747 | rc = IPMI_CC_PARM_OUT_OF_RANGE; |
| 748 | *data_len = 0; |
| 749 | } |
| 750 | |
| 751 | return rc; |
| 752 | } |
| 753 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 754 | ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 755 | ipmi_request_t request, ipmi_response_t response, |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 756 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 757 | { |
| 758 | printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 759 | |
| 760 | // Status code. |
Nan Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 761 | ipmi_ret_t rc = IPMI_CC_INVALID; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 762 | |
| 763 | *data_len = strlen("THIS IS WILDCARD"); |
| 764 | |
| 765 | // Now pack actual response |
| 766 | memcpy(response, "THIS IS WILDCARD", *data_len); |
| 767 | |
| 768 | return rc; |
| 769 | } |
| 770 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 771 | void register_netfn_app_functions() |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 772 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 773 | // <Get BT Interface Capabilities> |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 774 | 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] | 775 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CAP_BIT, NULL, ipmi_app_get_bt_capabilities, |
| 776 | PRIVILEGE_USER); |
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 | // <Wildcard Command> |
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_WILDCARD); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 780 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_WILDCARD, NULL, ipmi_app_wildcard_handler, |
| 781 | PRIVILEGE_USER); |
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 | // <Reset Watchdog Timer> |
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_RESET_WD); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 785 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, ipmi_app_reset_watchdog, |
| 786 | PRIVILEGE_OPERATOR); |
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 | // <Set Watchdog Timer> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 789 | 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] | 790 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, ipmi_app_set_watchdog, |
| 791 | PRIVILEGE_OPERATOR); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 792 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 793 | // <Get Device ID> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 794 | 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] | 795 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_ID, NULL, ipmi_app_get_device_id, |
| 796 | PRIVILEGE_USER); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 797 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 798 | // <Get Self Test Results> |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 799 | 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] | 800 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_SELF_TEST_RESULTS, NULL, |
| 801 | ipmi_app_get_self_test_results, PRIVILEGE_USER); |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 802 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 803 | // <Get Device GUID> |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 804 | 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] | 805 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID, NULL, ipmi_app_get_device_guid, |
| 806 | PRIVILEGE_USER); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 807 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 808 | // <Set ACPI Power State> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 809 | 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] | 810 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, ipmi_app_set_acpi_power_state, |
| 811 | PRIVILEGE_ADMIN); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 812 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 813 | // <Set Channel Access> |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 814 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, |
| 815 | IPMI_CMD_SET_CHAN_ACCESS); |
| 816 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_CHAN_ACCESS, NULL, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 817 | ipmi_set_channel_access, PRIVILEGE_ADMIN); |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 818 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 819 | // <Get Channel Info Command> |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 820 | 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] | 821 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHAN_INFO, NULL, ipmi_app_channel_info, |
| 822 | PRIVILEGE_USER); |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 823 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 824 | return; |
| 825 | } |
| 826 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 827 | |