vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 1 | #include "apphandler.h" |
Patrick Venture | 5794fcf | 2017-10-26 11:11:14 -0700 | [diff] [blame] | 2 | #include "app/channel.hpp" |
Patrick Venture | 5e6ac71 | 2017-10-25 12:16:19 -0700 | [diff] [blame] | 3 | #include "app/watchdog.hpp" |
Patrick Williams | 37af733 | 2016-09-02 21:21:42 -0500 | [diff] [blame] | 4 | #include "host-ipmid/ipmid-api.h" |
Patrick Williams | 53a360e | 2016-08-12 22:01:02 -0500 | [diff] [blame] | 5 | #include "ipmid.hpp" |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 6 | #include "types.hpp" |
| 7 | #include "utils.hpp" |
| 8 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 9 | #include <stdio.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> |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <cstddef> |
Ratan Gupta | 62736ec | 2017-09-02 12:02:47 +0530 | [diff] [blame] | 17 | #include <experimental/filesystem> |
| 18 | |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 19 | #include <arpa/inet.h> |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 20 | #include "transporthandler.hpp" |
| 21 | |
| 22 | #include <phosphor-logging/log.hpp> |
| 23 | #include <phosphor-logging/elog-errors.hpp> |
| 24 | #include "xyz/openbmc_project/Common/error.hpp" |
| 25 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 26 | extern sd_bus *bus; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 27 | |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 28 | constexpr auto app_obj = "/org/openbmc/NetworkManager/Interface"; |
| 29 | constexpr auto app_ifc = "org.openbmc.NetworkManager"; |
| 30 | constexpr auto app_nwinterface = "eth0"; |
| 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 | |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 70 | /* Currently supports the vx.x-x-[-x] and v1.x.x-x-[-x] format. It will */ |
| 71 | /* return -1 if not in those formats, this routine knows how to parse */ |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 72 | /* version = v0.6-19-gf363f61-dirty */ |
| 73 | /* ^ ^ ^^ ^ */ |
| 74 | /* | | |----------|-- additional details */ |
| 75 | /* | |---------------- Minor */ |
| 76 | /* |------------------ Major */ |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 77 | /* and version = v1.99.10-113-g65edf7d-r3-0-g9e4f715 */ |
| 78 | /* ^ ^ ^^ ^ */ |
| 79 | /* | | |--|---------- additional details */ |
| 80 | /* | |---------------- Minor */ |
| 81 | /* |------------------ Major */ |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 82 | /* Additional details : If the option group exists it will force Auxiliary */ |
| 83 | /* Firmware Revision Information 4th byte to 1 indicating the build was */ |
| 84 | /* derived with additional edits */ |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 85 | int convert_version(const char * p, rev_t *rev) |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 86 | { |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 87 | std::string s(p); |
| 88 | std::string token; |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 89 | uint16_t commits; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 90 | |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 91 | auto location = s.find_first_of('v'); |
| 92 | if (location != std::string::npos) |
| 93 | { |
| 94 | s = s.substr(location+1); |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 95 | } |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 96 | |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 97 | if (!s.empty()) |
| 98 | { |
| 99 | location = s.find_first_of("."); |
| 100 | if (location != std::string::npos) |
| 101 | { |
| 102 | rev->major = static_cast<char>(std::stoi(s.substr(0, location), 0, 16)); |
| 103 | token = s.substr(location+1); |
| 104 | } |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 105 | |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 106 | if (!token.empty()) |
| 107 | { |
| 108 | location = token.find_first_of(".-"); |
| 109 | if (location != std::string::npos) |
| 110 | { |
| 111 | rev->minor = static_cast<char>(std::stoi(token.substr(0, location), 0, 16)); |
| 112 | token = token.substr(location+1); |
| 113 | } |
| 114 | } |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 115 | |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 116 | // Capture the number of commits on top of the minor tag. |
| 117 | // I'm using BE format like the ipmi spec asked for |
| 118 | location = token.find_first_of(".-"); |
| 119 | if (!token.empty()) |
| 120 | { |
| 121 | commits = std::stoi(token.substr(0, location), 0, 16); |
| 122 | rev->d[0] = (commits>>8) | (commits<<8); |
| 123 | |
| 124 | // commit number we skip |
| 125 | location = token.find_first_of(".-"); |
| 126 | if (location != std::string::npos) |
| 127 | { |
| 128 | token = token.substr(location+1); |
| 129 | } |
| 130 | } |
| 131 | else { |
| 132 | rev->d[0] = 0; |
| 133 | } |
| 134 | |
| 135 | if (location != std::string::npos) |
| 136 | { |
| 137 | token = token.substr(location+1); |
| 138 | } |
| 139 | |
| 140 | // Any value of the optional parameter forces it to 1 |
| 141 | location = token.find_first_of(".-"); |
| 142 | if (location != std::string::npos) |
| 143 | { |
| 144 | token = token.substr(location+1); |
| 145 | } |
| 146 | commits = (!token.empty()) ? 1 : 0; |
| 147 | |
| 148 | //We do this operation to get this displayed in least significant bytes |
| 149 | //of ipmitool device id command. |
| 150 | rev->d[1] = (commits>>8) | (commits<<8); |
| 151 | } |
| 152 | |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 153 | return 0; |
| 154 | } |
| 155 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 156 | ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 157 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 158 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 159 | { |
| 160 | ipmi_ret_t rc = IPMI_CC_OK; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 161 | const char *objname = "/org/openbmc/inventory/system/chassis/motherboard/bmc"; |
| 162 | const char *iface = "org.openbmc.InventoryItem"; |
| 163 | char *ver = NULL; |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 164 | char *busname = NULL; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 165 | int r; |
| 166 | rev_t rev = {0}; |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 167 | ipmi_device_id_t dev_id{}; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 168 | |
| 169 | // Data length |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 170 | *data_len = sizeof(dev_id); |
| 171 | |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 172 | // From IPMI spec, controller that have different application commands, or different |
| 173 | // definitions of OEM fields, are expected to have different Device ID values. |
| 174 | // Set to 0 now. |
| 175 | |
| 176 | // Device Revision is set to 0 now. |
| 177 | // Bit7 identifies if device provide Device SDRs, obmc don't have SDR,we use ipmi to |
| 178 | // simulate SDR, hence the value: |
| 179 | dev_id.revision = 0x80; |
| 180 | |
| 181 | // Firmware revision is already implemented, so get it from appropriate position. |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 182 | r = mapper_get_service(bus, objname, &busname); |
| 183 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 184 | fprintf(stderr, "Failed to get %s bus name: %s\n", |
| 185 | objname, strerror(-r)); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 186 | goto finish; |
| 187 | } |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 188 | r = sd_bus_get_property_string(bus,busname,objname,iface,"version", NULL, &ver); |
| 189 | if ( r < 0 ) { |
| 190 | fprintf(stderr, "Failed to obtain version property: %s\n", strerror(-r)); |
| 191 | } else { |
| 192 | r = convert_version(ver, &rev); |
| 193 | if( r >= 0 ) { |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 194 | // bit7 identifies if the device is available, 0=normal operation, |
| 195 | // 1=device firmware, SDR update or self-initialization in progress. |
| 196 | // our SDR is normal working condition, so mask: |
| 197 | dev_id.fw[0] = 0x7F & rev.major; |
Adriana Kobylak | 0e91264 | 2016-06-22 16:54:39 -0500 | [diff] [blame] | 198 | |
| 199 | rev.minor = (rev.minor > 99 ? 99 : rev.minor); |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 200 | dev_id.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16; |
| 201 | memcpy(&dev_id.aux, rev.d, 4); |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 202 | } |
| 203 | } |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 204 | |
Gunnar Mills | 8991dd6 | 2017-10-25 17:11:29 -0500 | [diff] [blame] | 205 | // IPMI Spec version 2.0 |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 206 | dev_id.ipmi_ver = 2; |
| 207 | |
| 208 | // Additional device Support. |
| 209 | // List the 'logical device' commands and functions that the controller supports |
| 210 | // that are in addition to the mandatory IPM and Application commands. |
| 211 | // [7] Chassis Device (device functions as chassis device per ICMB spec.) |
| 212 | // [6] Bridge (device responds to Bridge NetFn commands) |
| 213 | // [5] IPMB Event Generator |
| 214 | // [4] IPMB Event Receiver |
| 215 | // [3] FRU Inventory Device |
| 216 | // [2] SEL Device |
| 217 | // [1] SDR Repository Device |
| 218 | // [0] Sensor Device |
| 219 | // We support FRU/SEL/Sensor now: |
| 220 | dev_id.addn_dev_support = 0x8D; |
| 221 | |
| 222 | // This value is the IANA number assigned to "IBM Platform Firmware |
| 223 | // Division", which is also used by our service processor. We may want |
| 224 | // a different number or at least a different version? |
| 225 | dev_id.manuf_id[0] = 0x41; |
| 226 | dev_id.manuf_id[1] = 0xA7; |
| 227 | dev_id.manuf_id[2] = 0x00; |
| 228 | |
| 229 | // Witherspoon's product ID is hardcoded to 4F42(ASCII 'OB'). |
| 230 | // TODO: openbmc/openbmc#495 |
| 231 | dev_id.prod_id[0] = 0x4F; |
| 232 | dev_id.prod_id[1] = 0x42; |
| 233 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 234 | // Pack the actual response |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 235 | memcpy(response, &dev_id, *data_len); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 236 | finish: |
| 237 | free(busname); |
Xo Wang | e553638 | 2017-07-20 20:14:00 -0700 | [diff] [blame] | 238 | free(ver); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 239 | return rc; |
| 240 | } |
| 241 | |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 242 | ipmi_ret_t ipmi_app_get_self_test_results(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 243 | ipmi_request_t request, ipmi_response_t response, |
| 244 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 245 | { |
| 246 | ipmi_ret_t rc = IPMI_CC_OK; |
| 247 | |
| 248 | // Byte 2: |
| 249 | // 55h - No error. |
Gunnar Mills | 8991dd6 | 2017-10-25 17:11:29 -0500 | [diff] [blame] | 250 | // 56h - Self Test function not implemented in this controller. |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 251 | // 57h - Corrupted or inaccesssible data or devices. |
| 252 | // 58h - Fatal hardware error. |
| 253 | // FFh - reserved. |
| 254 | // all other: Device-specific 'internal failure'. |
| 255 | // Byte 3: |
| 256 | // For byte 2 = 55h, 56h, FFh: 00h |
| 257 | // For byte 2 = 58h, all other: Device-specific |
| 258 | // For byte 2 = 57h: self-test error bitfield. |
| 259 | // Note: returning 57h does not imply that all test were run. |
| 260 | // [7] 1b = Cannot access SEL device. |
| 261 | // [6] 1b = Cannot access SDR Repository. |
| 262 | // [5] 1b = Cannot access BMC FRU device. |
| 263 | // [4] 1b = IPMB signal lines do not respond. |
| 264 | // [3] 1b = SDR Repository empty. |
| 265 | // [2] 1b = Internal Use Area of BMC FRU corrupted. |
| 266 | // [1] 1b = controller update 'boot block' firmware corrupted. |
| 267 | // [0] 1b = controller operational firmware corrupted. |
| 268 | |
| 269 | char selftestresults[2] = {0}; |
| 270 | |
| 271 | *data_len = 2; |
| 272 | |
| 273 | selftestresults[0] = 0x56; |
| 274 | selftestresults[1] = 0; |
| 275 | |
| 276 | memcpy(response, selftestresults, *data_len); |
| 277 | |
| 278 | return rc; |
| 279 | } |
| 280 | |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 281 | ipmi_ret_t ipmi_app_get_device_guid(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 282 | ipmi_request_t request, ipmi_response_t response, |
| 283 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 284 | { |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 285 | const char *objname = "/org/openbmc/control/chassis0"; |
Adriana Kobylak | 31bccae | 2015-11-05 13:31:06 -0600 | [diff] [blame] | 286 | const char *iface = "org.freedesktop.DBus.Properties"; |
| 287 | const char *chassis_iface = "org.openbmc.control.Chassis"; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 288 | sd_bus_message *reply = NULL; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 289 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 290 | int r = 0; |
| 291 | char *uuid = NULL; |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 292 | char *busname = NULL; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 293 | |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 294 | // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223 |
| 295 | // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte order |
| 296 | // Ex: 0x2332fc2c40e66298e511f2782395a361 |
| 297 | |
| 298 | const int resp_size = 16; // Response is 16 hex bytes per IPMI Spec |
| 299 | uint8_t resp_uuid[resp_size]; // Array to hold the formatted response |
| 300 | int resp_loc = resp_size-1; // Point resp end of array to save in reverse order |
| 301 | int i = 0; |
| 302 | char *tokptr = NULL; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 303 | char *id_octet = NULL; |
| 304 | |
| 305 | // Status code. |
| 306 | ipmi_ret_t rc = IPMI_CC_OK; |
| 307 | *data_len = 0; |
| 308 | |
| 309 | printf("IPMI GET DEVICE GUID\n"); |
| 310 | |
| 311 | // Call Get properties method with the interface and property name |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 312 | r = mapper_get_service(bus, objname, &busname); |
| 313 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 314 | fprintf(stderr, "Failed to get %s bus name: %s\n", |
| 315 | objname, strerror(-r)); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 316 | goto finish; |
| 317 | } |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 318 | r = sd_bus_call_method(bus,busname,objname,iface, |
| 319 | "Get",&error, &reply, "ss", |
| 320 | chassis_iface, "uuid"); |
| 321 | if (r < 0) |
| 322 | { |
| 323 | fprintf(stderr, "Failed to call Get Method: %s\n", strerror(-r)); |
| 324 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 325 | goto finish; |
| 326 | } |
| 327 | |
| 328 | r = sd_bus_message_read(reply, "v", "s", &uuid); |
| 329 | if (r < 0 || uuid == NULL) |
| 330 | { |
| 331 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 332 | rc = IPMI_CC_RESPONSE_ERROR; |
| 333 | goto finish; |
| 334 | } |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 335 | |
| 336 | // Traverse the UUID |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 337 | 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] | 338 | |
| 339 | if (id_octet == NULL) |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 340 | { |
| 341 | // Error |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 342 | fprintf(stderr, "Unexpected UUID format: %s", uuid); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 343 | rc = IPMI_CC_RESPONSE_ERROR; |
| 344 | goto finish; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | while (id_octet != NULL) |
| 348 | { |
| 349 | // Calculate the octet string size since it varies |
| 350 | // Divide it by 2 for the array size since 1 byte is built from 2 chars |
| 351 | int tmp_size = strlen(id_octet)/2; |
| 352 | |
| 353 | for(i = 0; i < tmp_size; i++) |
| 354 | { |
Joel Stanley | 38310cd | 2015-11-25 17:32:08 +1030 | [diff] [blame] | 355 | 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] | 356 | strncpy(tmp_array, id_octet, 2); // 2 chars at a time |
| 357 | |
| 358 | int resp_byte = strtoul(tmp_array, NULL, 16); // Convert to hex byte |
| 359 | memcpy((void*)&resp_uuid[resp_loc], &resp_byte, 1); // Copy end to first |
| 360 | resp_loc--; |
| 361 | id_octet+=2; // Finished with the 2 chars, advance |
| 362 | } |
| 363 | id_octet=strtok_r(NULL, "-", &tokptr); // Get next octet |
| 364 | } |
| 365 | |
| 366 | // Data length |
| 367 | *data_len = resp_size; |
| 368 | |
| 369 | // Pack the actual response |
| 370 | memcpy(response, &resp_uuid, *data_len); |
| 371 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 372 | finish: |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 373 | sd_bus_error_free(&error); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 374 | reply = sd_bus_message_unref(reply); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 375 | free(busname); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 376 | |
| 377 | return rc; |
| 378 | } |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 379 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 380 | ipmi_ret_t ipmi_app_get_bt_capabilities(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 381 | ipmi_request_t request, ipmi_response_t response, |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 382 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 383 | { |
| 384 | printf("Handling Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd); |
| 385 | |
| 386 | // Status code. |
| 387 | ipmi_ret_t rc = IPMI_CC_OK; |
| 388 | |
Adriana Kobylak | 88ad815 | 2016-12-13 10:09:08 -0600 | [diff] [blame] | 389 | // Per IPMI 2.0 spec, the input and output buffer size must be the max |
| 390 | // buffer size minus one byte to allocate space for the length byte. |
| 391 | 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] | 392 | |
| 393 | // Data length |
| 394 | *data_len = sizeof(str); |
| 395 | |
| 396 | // Pack the actual response |
| 397 | memcpy(response, &str, *data_len); |
| 398 | |
| 399 | return rc; |
| 400 | } |
| 401 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 402 | ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 403 | ipmi_request_t request, ipmi_response_t response, |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 404 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 405 | { |
| 406 | printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 407 | |
| 408 | // Status code. |
Nan Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 409 | ipmi_ret_t rc = IPMI_CC_INVALID; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 410 | |
| 411 | *data_len = strlen("THIS IS WILDCARD"); |
| 412 | |
| 413 | // Now pack actual response |
| 414 | memcpy(response, "THIS IS WILDCARD", *data_len); |
| 415 | |
| 416 | return rc; |
| 417 | } |
| 418 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 419 | void register_netfn_app_functions() |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 420 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 421 | // <Get BT Interface Capabilities> |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 422 | 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] | 423 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CAP_BIT, NULL, ipmi_app_get_bt_capabilities, |
| 424 | PRIVILEGE_USER); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 425 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 426 | // <Wildcard Command> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 427 | 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] | 428 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_WILDCARD, NULL, ipmi_app_wildcard_handler, |
| 429 | PRIVILEGE_USER); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 430 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 431 | // <Reset Watchdog Timer> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 432 | 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] | 433 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, ipmi_app_reset_watchdog, |
| 434 | PRIVILEGE_OPERATOR); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 435 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 436 | // <Set Watchdog Timer> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 437 | 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] | 438 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, ipmi_app_set_watchdog, |
| 439 | PRIVILEGE_OPERATOR); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 440 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 441 | // <Get Device ID> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 442 | 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] | 443 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_ID, NULL, ipmi_app_get_device_id, |
| 444 | PRIVILEGE_USER); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 445 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 446 | // <Get Self Test Results> |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 447 | 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] | 448 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_SELF_TEST_RESULTS, NULL, |
| 449 | ipmi_app_get_self_test_results, PRIVILEGE_USER); |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 450 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 451 | // <Get Device GUID> |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 452 | 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] | 453 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID, NULL, ipmi_app_get_device_guid, |
| 454 | PRIVILEGE_USER); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 455 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 456 | // <Set ACPI Power State> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 457 | 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] | 458 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, ipmi_app_set_acpi_power_state, |
| 459 | PRIVILEGE_ADMIN); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 460 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 461 | // <Set Channel Access> |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 462 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, |
| 463 | IPMI_CMD_SET_CHAN_ACCESS); |
| 464 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_CHAN_ACCESS, NULL, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 465 | ipmi_set_channel_access, PRIVILEGE_ADMIN); |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 466 | |
Tom Joseph | 69fabfe | 2017-08-04 10:15:01 +0530 | [diff] [blame] | 467 | // <Get Channel Access> |
| 468 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CHANNEL_ACCESS); |
| 469 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHANNEL_ACCESS, NULL, |
Patrick Venture | 5794fcf | 2017-10-26 11:11:14 -0700 | [diff] [blame] | 470 | ipmi_get_channel_access, PRIVILEGE_USER); |
Tom Joseph | 69fabfe | 2017-08-04 10:15:01 +0530 | [diff] [blame] | 471 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 472 | // <Get Channel Info Command> |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 473 | 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] | 474 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHAN_INFO, NULL, ipmi_app_channel_info, |
| 475 | PRIVILEGE_USER); |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 476 | |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 477 | return; |
| 478 | } |
| 479 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 480 | |