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