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