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" |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 6 | #include "nlohmann/json.hpp" |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 7 | #include "types.hpp" |
| 8 | #include "utils.hpp" |
| 9 | |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 10 | #include <fstream> |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 11 | #include <stdio.h> |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 12 | #include <stdint.h> |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 13 | #include <systemd/sd-bus.h> |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 14 | #include <mapper.h> |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 15 | #include <array> |
Tom Joseph | 69fabfe | 2017-08-04 10:15:01 +0530 | [diff] [blame] | 16 | #include <vector> |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 17 | #include <string> |
| 18 | #include <cstddef> |
Ratan Gupta | 62736ec | 2017-09-02 12:02:47 +0530 | [diff] [blame] | 19 | #include <experimental/filesystem> |
| 20 | |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 21 | #include <arpa/inet.h> |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 22 | #include "transporthandler.hpp" |
| 23 | |
| 24 | #include <phosphor-logging/log.hpp> |
| 25 | #include <phosphor-logging/elog-errors.hpp> |
| 26 | #include "xyz/openbmc_project/Common/error.hpp" |
| 27 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 28 | extern sd_bus *bus; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 29 | |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 30 | constexpr auto bmc_interface = "xyz.openbmc_project.Inventory.Item.Bmc"; |
| 31 | constexpr auto bmc_guid_interface = "xyz.openbmc_project.Common.UUID"; |
| 32 | constexpr auto bmc_guid_property = "UUID"; |
| 33 | constexpr auto bmc_guid_len = 16; |
| 34 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 35 | void register_netfn_app_functions() __attribute__((constructor)); |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 36 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 37 | using namespace phosphor::logging; |
| 38 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Ratan Gupta | 62736ec | 2017-09-02 12:02:47 +0530 | [diff] [blame] | 39 | namespace fs = std::experimental::filesystem; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 40 | |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 41 | // Offset in get device id command. |
| 42 | typedef struct |
| 43 | { |
| 44 | uint8_t id; |
| 45 | uint8_t revision; |
| 46 | uint8_t fw[2]; |
| 47 | uint8_t ipmi_ver; |
| 48 | uint8_t addn_dev_support; |
| 49 | uint8_t manuf_id[3]; |
| 50 | uint8_t prod_id[2]; |
| 51 | uint8_t aux[4]; |
| 52 | }__attribute__((packed)) ipmi_device_id_t; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 53 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 54 | ipmi_ret_t ipmi_app_set_acpi_power_state(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 55 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 56 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 57 | { |
| 58 | ipmi_ret_t rc = IPMI_CC_OK; |
| 59 | *data_len = 0; |
| 60 | |
| 61 | printf("IPMI SET ACPI STATE Ignoring for now\n"); |
| 62 | return rc; |
| 63 | } |
| 64 | |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 65 | typedef struct |
| 66 | { |
| 67 | char major; |
| 68 | char minor; |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 69 | uint16_t d[2]; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 70 | } rev_t; |
| 71 | |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 72 | /* Currently supports the vx.x-x-[-x] and v1.x.x-x-[-x] format. It will */ |
| 73 | /* 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] | 74 | /* version = v0.6-19-gf363f61-dirty */ |
| 75 | /* ^ ^ ^^ ^ */ |
| 76 | /* | | |----------|-- additional details */ |
| 77 | /* | |---------------- Minor */ |
| 78 | /* |------------------ Major */ |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 79 | /* and version = v1.99.10-113-g65edf7d-r3-0-g9e4f715 */ |
| 80 | /* ^ ^ ^^ ^ */ |
| 81 | /* | | |--|---------- additional details */ |
| 82 | /* | |---------------- Minor */ |
| 83 | /* |------------------ Major */ |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 84 | /* Additional details : If the option group exists it will force Auxiliary */ |
| 85 | /* Firmware Revision Information 4th byte to 1 indicating the build was */ |
| 86 | /* derived with additional edits */ |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 87 | int convert_version(const char * p, rev_t *rev) |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 88 | { |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 89 | std::string s(p); |
| 90 | std::string token; |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 91 | uint16_t commits; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 92 | |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 93 | auto location = s.find_first_of('v'); |
| 94 | if (location != std::string::npos) |
| 95 | { |
| 96 | s = s.substr(location+1); |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 97 | } |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 98 | |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 99 | if (!s.empty()) |
| 100 | { |
| 101 | location = s.find_first_of("."); |
| 102 | if (location != std::string::npos) |
| 103 | { |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 104 | rev->major = static_cast<char>( |
| 105 | std::stoi(s.substr(0, location), 0, 16)); |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 106 | token = s.substr(location+1); |
| 107 | } |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 108 | |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 109 | if (!token.empty()) |
| 110 | { |
| 111 | location = token.find_first_of(".-"); |
| 112 | if (location != std::string::npos) |
| 113 | { |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 114 | rev->minor = static_cast<char>( |
| 115 | std::stoi(token.substr(0, location), 0, 16)); |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 116 | token = token.substr(location+1); |
| 117 | } |
| 118 | } |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 119 | |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 120 | // Capture the number of commits on top of the minor tag. |
| 121 | // I'm using BE format like the ipmi spec asked for |
| 122 | location = token.find_first_of(".-"); |
| 123 | if (!token.empty()) |
| 124 | { |
| 125 | commits = std::stoi(token.substr(0, location), 0, 16); |
| 126 | rev->d[0] = (commits>>8) | (commits<<8); |
| 127 | |
| 128 | // commit number we skip |
| 129 | location = token.find_first_of(".-"); |
| 130 | if (location != std::string::npos) |
| 131 | { |
| 132 | token = token.substr(location+1); |
| 133 | } |
| 134 | } |
| 135 | else { |
| 136 | rev->d[0] = 0; |
| 137 | } |
| 138 | |
| 139 | if (location != std::string::npos) |
| 140 | { |
| 141 | token = token.substr(location+1); |
| 142 | } |
| 143 | |
| 144 | // Any value of the optional parameter forces it to 1 |
| 145 | location = token.find_first_of(".-"); |
| 146 | if (location != std::string::npos) |
| 147 | { |
| 148 | token = token.substr(location+1); |
| 149 | } |
| 150 | commits = (!token.empty()) ? 1 : 0; |
| 151 | |
| 152 | //We do this operation to get this displayed in least significant bytes |
| 153 | //of ipmitool device id command. |
| 154 | rev->d[1] = (commits>>8) | (commits<<8); |
| 155 | } |
| 156 | |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 157 | return 0; |
| 158 | } |
| 159 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 160 | ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 161 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 162 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 163 | { |
| 164 | ipmi_ret_t rc = IPMI_CC_OK; |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 165 | const char *objname = |
| 166 | "/org/openbmc/inventory/system/chassis/motherboard/bmc"; |
| 167 | const char *iface = "org.openbmc.InventoryItem"; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 168 | char *ver = NULL; |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 169 | char *busname = NULL; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 170 | int r; |
| 171 | rev_t rev = {0}; |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 172 | static ipmi_device_id_t dev_id{}; |
| 173 | static bool dev_id_initialized = false; |
| 174 | const char* filename = "/usr/share/ipmi-providers/dev_id.json"; |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 175 | |
| 176 | // Data length |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 177 | *data_len = sizeof(dev_id); |
| 178 | |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 179 | if (!dev_id_initialized) |
| 180 | { |
| 181 | // Firmware revision is already implemented, |
| 182 | // so get it from appropriate position. |
| 183 | r = mapper_get_service(bus, objname, &busname); |
| 184 | if (r < 0) { |
| 185 | fprintf(stderr, "Failed to get %s bus name: %s\n", |
| 186 | objname, strerror(-r)); |
| 187 | goto finish; |
| 188 | } |
| 189 | r = sd_bus_get_property_string(bus,busname,objname,iface,"version", |
| 190 | NULL, &ver); |
| 191 | if ( r < 0 ) { |
| 192 | fprintf(stderr, "Failed to obtain version property: %s\n", |
| 193 | strerror(-r)); |
| 194 | } else { |
| 195 | r = convert_version(ver, &rev); |
| 196 | if( r >= 0 ) { |
| 197 | // bit7 identifies if the device is available |
| 198 | // 0=normal operation |
| 199 | // 1=device firmware, SDR update, |
| 200 | // or self-initialization in progress. |
| 201 | // our SDR is normal working condition, so mask: |
| 202 | dev_id.fw[0] = 0x7F & rev.major; |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 203 | |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 204 | rev.minor = (rev.minor > 99 ? 99 : rev.minor); |
| 205 | dev_id.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16; |
| 206 | memcpy(&dev_id.aux, rev.d, 4); |
| 207 | } |
| 208 | } |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 209 | |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 210 | // IPMI Spec version 2.0 |
| 211 | dev_id.ipmi_ver = 2; |
Adriana Kobylak | 0e91264 | 2016-06-22 16:54:39 -0500 | [diff] [blame] | 212 | |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 213 | std::ifstream dev_id_file(filename); |
| 214 | if (dev_id_file.is_open()) |
| 215 | { |
| 216 | auto data = nlohmann::json::parse(dev_id_file, nullptr, false); |
| 217 | if (!data.is_discarded()) |
| 218 | { |
| 219 | dev_id.id = data.value("id", 0); |
| 220 | dev_id.revision = data.value("revision", 0); |
| 221 | dev_id.addn_dev_support = data.value("addn_dev_support", 0); |
| 222 | dev_id.manuf_id[2] = data.value("manuf_id", 0) >> 16; |
| 223 | dev_id.manuf_id[1] = data.value("manuf_id", 0) >> 8; |
| 224 | dev_id.manuf_id[0] = data.value("manuf_id", 0); |
| 225 | dev_id.prod_id[1] = data.value("prod_id", 0) >> 8; |
| 226 | dev_id.prod_id[0] = data.value("prod_id", 0); |
| 227 | dev_id.aux[3] = data.value("aux", 0) >> 24; |
| 228 | dev_id.aux[2] = data.value("aux", 0) >> 16; |
| 229 | dev_id.aux[1] = data.value("aux", 0) >> 8; |
| 230 | dev_id.aux[0] = data.value("aux", 0); |
| 231 | |
| 232 | //Don't read the file every time if successful |
| 233 | dev_id_initialized = true; |
| 234 | } |
| 235 | else |
| 236 | { |
| 237 | log<level::ERR>("Device ID JSON parser failure"); |
| 238 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 239 | } |
| 240 | } |
| 241 | else |
| 242 | { |
| 243 | log<level::ERR>("Device ID file not found"); |
| 244 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 245 | } |
| 246 | } |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 247 | |
| 248 | // Pack the actual response |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 249 | memcpy(response, &dev_id, *data_len); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 250 | finish: |
| 251 | free(busname); |
Xo Wang | e553638 | 2017-07-20 20:14:00 -0700 | [diff] [blame] | 252 | free(ver); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 253 | return rc; |
| 254 | } |
| 255 | |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 256 | ipmi_ret_t ipmi_app_get_self_test_results(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 257 | ipmi_request_t request, ipmi_response_t response, |
| 258 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 259 | { |
| 260 | ipmi_ret_t rc = IPMI_CC_OK; |
| 261 | |
| 262 | // Byte 2: |
| 263 | // 55h - No error. |
Gunnar Mills | 8991dd6 | 2017-10-25 17:11:29 -0500 | [diff] [blame] | 264 | // 56h - Self Test function not implemented in this controller. |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 265 | // 57h - Corrupted or inaccesssible data or devices. |
| 266 | // 58h - Fatal hardware error. |
| 267 | // FFh - reserved. |
| 268 | // all other: Device-specific 'internal failure'. |
| 269 | // Byte 3: |
| 270 | // For byte 2 = 55h, 56h, FFh: 00h |
| 271 | // For byte 2 = 58h, all other: Device-specific |
| 272 | // For byte 2 = 57h: self-test error bitfield. |
| 273 | // Note: returning 57h does not imply that all test were run. |
| 274 | // [7] 1b = Cannot access SEL device. |
| 275 | // [6] 1b = Cannot access SDR Repository. |
| 276 | // [5] 1b = Cannot access BMC FRU device. |
| 277 | // [4] 1b = IPMB signal lines do not respond. |
| 278 | // [3] 1b = SDR Repository empty. |
| 279 | // [2] 1b = Internal Use Area of BMC FRU corrupted. |
| 280 | // [1] 1b = controller update 'boot block' firmware corrupted. |
| 281 | // [0] 1b = controller operational firmware corrupted. |
| 282 | |
| 283 | char selftestresults[2] = {0}; |
| 284 | |
| 285 | *data_len = 2; |
| 286 | |
| 287 | selftestresults[0] = 0x56; |
| 288 | selftestresults[1] = 0; |
| 289 | |
| 290 | memcpy(response, selftestresults, *data_len); |
| 291 | |
| 292 | return rc; |
| 293 | } |
| 294 | |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 295 | ipmi_ret_t ipmi_app_get_device_guid(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 296 | ipmi_request_t request, ipmi_response_t response, |
| 297 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 298 | { |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 299 | const char *objname = "/org/openbmc/control/chassis0"; |
Adriana Kobylak | 31bccae | 2015-11-05 13:31:06 -0600 | [diff] [blame] | 300 | const char *iface = "org.freedesktop.DBus.Properties"; |
| 301 | const char *chassis_iface = "org.openbmc.control.Chassis"; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 302 | sd_bus_message *reply = NULL; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 303 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 304 | int r = 0; |
| 305 | char *uuid = NULL; |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 306 | char *busname = NULL; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 307 | |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 308 | // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223 |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 309 | // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte |
| 310 | // order |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 311 | // Ex: 0x2332fc2c40e66298e511f2782395a361 |
| 312 | |
| 313 | const int resp_size = 16; // Response is 16 hex bytes per IPMI Spec |
| 314 | uint8_t resp_uuid[resp_size]; // Array to hold the formatted response |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 315 | // Point resp end of array to save in reverse order |
| 316 | int resp_loc = resp_size-1; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 317 | int i = 0; |
| 318 | char *tokptr = NULL; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 319 | char *id_octet = NULL; |
| 320 | |
| 321 | // Status code. |
| 322 | ipmi_ret_t rc = IPMI_CC_OK; |
| 323 | *data_len = 0; |
| 324 | |
| 325 | printf("IPMI GET DEVICE GUID\n"); |
| 326 | |
| 327 | // Call Get properties method with the interface and property name |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 328 | r = mapper_get_service(bus, objname, &busname); |
| 329 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 330 | fprintf(stderr, "Failed to get %s bus name: %s\n", |
| 331 | objname, strerror(-r)); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 332 | goto finish; |
| 333 | } |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 334 | r = sd_bus_call_method(bus,busname,objname,iface, |
| 335 | "Get",&error, &reply, "ss", |
| 336 | chassis_iface, "uuid"); |
| 337 | if (r < 0) |
| 338 | { |
| 339 | fprintf(stderr, "Failed to call Get Method: %s\n", strerror(-r)); |
| 340 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 341 | goto finish; |
| 342 | } |
| 343 | |
| 344 | r = sd_bus_message_read(reply, "v", "s", &uuid); |
| 345 | if (r < 0 || uuid == NULL) |
| 346 | { |
| 347 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 348 | rc = IPMI_CC_RESPONSE_ERROR; |
| 349 | goto finish; |
| 350 | } |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 351 | |
| 352 | // Traverse the UUID |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 353 | // Get the UUID octects separated by dash |
| 354 | id_octet = strtok_r(uuid, "-", &tokptr); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 355 | |
| 356 | if (id_octet == NULL) |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 357 | { |
| 358 | // Error |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 359 | fprintf(stderr, "Unexpected UUID format: %s", uuid); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 360 | rc = IPMI_CC_RESPONSE_ERROR; |
| 361 | goto finish; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | while (id_octet != NULL) |
| 365 | { |
| 366 | // Calculate the octet string size since it varies |
| 367 | // Divide it by 2 for the array size since 1 byte is built from 2 chars |
| 368 | int tmp_size = strlen(id_octet)/2; |
| 369 | |
| 370 | for(i = 0; i < tmp_size; i++) |
| 371 | { |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 372 | // Holder of the 2 chars that will become a byte |
| 373 | char tmp_array[3] = {0}; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 374 | strncpy(tmp_array, id_octet, 2); // 2 chars at a time |
| 375 | |
| 376 | int resp_byte = strtoul(tmp_array, NULL, 16); // Convert to hex byte |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 377 | // Copy end to first |
| 378 | memcpy((void*)&resp_uuid[resp_loc], &resp_byte, 1); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 379 | resp_loc--; |
| 380 | id_octet+=2; // Finished with the 2 chars, advance |
| 381 | } |
| 382 | id_octet=strtok_r(NULL, "-", &tokptr); // Get next octet |
| 383 | } |
| 384 | |
| 385 | // Data length |
| 386 | *data_len = resp_size; |
| 387 | |
| 388 | // Pack the actual response |
| 389 | memcpy(response, &resp_uuid, *data_len); |
| 390 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 391 | finish: |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 392 | sd_bus_error_free(&error); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 393 | reply = sd_bus_message_unref(reply); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 394 | free(busname); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 395 | |
| 396 | return rc; |
| 397 | } |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 398 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 399 | ipmi_ret_t ipmi_app_get_bt_capabilities(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 400 | ipmi_request_t request, ipmi_response_t response, |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 401 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 402 | { |
| 403 | printf("Handling Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd); |
| 404 | |
| 405 | // Status code. |
| 406 | ipmi_ret_t rc = IPMI_CC_OK; |
| 407 | |
Adriana Kobylak | 88ad815 | 2016-12-13 10:09:08 -0600 | [diff] [blame] | 408 | // Per IPMI 2.0 spec, the input and output buffer size must be the max |
| 409 | // buffer size minus one byte to allocate space for the length byte. |
| 410 | 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] | 411 | |
| 412 | // Data length |
| 413 | *data_len = sizeof(str); |
| 414 | |
| 415 | // Pack the actual response |
| 416 | memcpy(response, &str, *data_len); |
| 417 | |
| 418 | return rc; |
| 419 | } |
| 420 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 421 | ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 422 | ipmi_request_t request, ipmi_response_t response, |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 423 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 424 | { |
| 425 | printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 426 | |
| 427 | // Status code. |
Nan Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 428 | ipmi_ret_t rc = IPMI_CC_INVALID; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 429 | |
| 430 | *data_len = strlen("THIS IS WILDCARD"); |
| 431 | |
| 432 | // Now pack actual response |
| 433 | memcpy(response, "THIS IS WILDCARD", *data_len); |
| 434 | |
| 435 | return rc; |
| 436 | } |
| 437 | |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 438 | ipmi_ret_t ipmi_app_get_sys_guid(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 439 | ipmi_request_t request, ipmi_response_t response, |
| 440 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 441 | |
| 442 | { |
| 443 | ipmi_ret_t rc = IPMI_CC_OK; |
| 444 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 445 | |
| 446 | try |
| 447 | { |
| 448 | // Get the Inventory object implementing BMC interface |
| 449 | ipmi::DbusObjectInfo bmcObject = |
| 450 | ipmi::getDbusObject(bus, bmc_interface); |
| 451 | |
| 452 | // Read UUID property value from bmcObject |
| 453 | // UUID is in RFC4122 format Ex: 61a39523-78f2-11e5-9862-e6402cfc3223 |
| 454 | auto variant = ipmi::getDbusProperty( |
| 455 | bus, bmcObject.second, bmcObject.first, bmc_guid_interface, |
| 456 | bmc_guid_property); |
| 457 | std::string guidProp = variant.get<std::string>(); |
| 458 | |
| 459 | // Erase "-" characters from the property value |
| 460 | guidProp.erase(std::remove(guidProp.begin(), guidProp.end(), '-'), |
| 461 | guidProp.end()); |
| 462 | |
| 463 | auto guidPropLen = guidProp.length(); |
| 464 | // Validate UUID data |
| 465 | // Divide by 2 as 1 byte is built from 2 chars |
| 466 | if ( (guidPropLen <=0) || ((guidPropLen/2) != bmc_guid_len) ) |
| 467 | |
| 468 | { |
| 469 | log<level::ERR>("Invalid UUID property value", |
| 470 | entry("UUID_LENGTH=%d", guidPropLen)); |
| 471 | return IPMI_CC_RESPONSE_ERROR; |
| 472 | } |
| 473 | |
| 474 | // Convert data in RFC4122(MSB) format to LSB format |
| 475 | // Get 2 characters at a time as 1 byte is built from 2 chars and |
| 476 | // convert to hex byte |
| 477 | // TODO: Data printed for GUID command is not as per the |
| 478 | // GUID format defined in IPMI specification 2.0 section 20.8 |
| 479 | // Ticket raised: https://sourceforge.net/p/ipmitool/bugs/501/ |
| 480 | uint8_t respGuid[bmc_guid_len]; |
| 481 | for (size_t i = 0, respLoc = (bmc_guid_len - 1); |
| 482 | i < guidPropLen && respLoc >= 0; i += 2, respLoc--) |
| 483 | { |
| 484 | auto value = static_cast<uint8_t>( |
| 485 | std::stoi(guidProp.substr(i, 2).c_str(), NULL, 16)); |
| 486 | respGuid[respLoc] = value; |
| 487 | } |
| 488 | |
| 489 | *data_len = bmc_guid_len; |
| 490 | memcpy(response, &respGuid, bmc_guid_len); |
| 491 | } |
| 492 | catch (const InternalFailure& e) |
| 493 | { |
| 494 | log<level::ERR>("Failed in reading BMC UUID property", |
| 495 | entry("INTERFACE=%s", bmc_interface), |
| 496 | entry("PROPERTY_INTERFACE=%s", bmc_guid_interface), |
| 497 | entry("PROPERTY=%s", bmc_guid_property)); |
| 498 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 499 | } |
| 500 | return rc; |
| 501 | } |
| 502 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 503 | void register_netfn_app_functions() |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 504 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 505 | // <Get BT Interface Capabilities> |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 506 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 507 | NETFUN_APP, |
| 508 | IPMI_CMD_GET_CAP_BIT); |
| 509 | ipmi_register_callback(NETFUN_APP, |
| 510 | IPMI_CMD_GET_CAP_BIT, |
| 511 | NULL, |
| 512 | ipmi_app_get_bt_capabilities, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 513 | PRIVILEGE_USER); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 514 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 515 | // <Wildcard Command> |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 516 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 517 | NETFUN_APP, |
| 518 | IPMI_CMD_WILDCARD); |
| 519 | ipmi_register_callback(NETFUN_APP, |
| 520 | IPMI_CMD_WILDCARD, |
| 521 | NULL, |
| 522 | ipmi_app_wildcard_handler, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 523 | PRIVILEGE_USER); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 524 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 525 | // <Reset Watchdog Timer> |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 526 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 527 | NETFUN_APP, |
| 528 | IPMI_CMD_RESET_WD); |
| 529 | ipmi_register_callback(NETFUN_APP, |
| 530 | IPMI_CMD_RESET_WD, |
| 531 | NULL, |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 532 | ipmi_app_watchdog_reset, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 533 | PRIVILEGE_OPERATOR); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 534 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 535 | // <Set Watchdog Timer> |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 536 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 537 | NETFUN_APP, |
| 538 | IPMI_CMD_SET_WD); |
| 539 | ipmi_register_callback(NETFUN_APP, |
| 540 | IPMI_CMD_SET_WD, |
| 541 | NULL, |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 542 | ipmi_app_watchdog_set, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 543 | PRIVILEGE_OPERATOR); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 544 | |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 545 | // <Get Watchdog Timer> |
| 546 | ipmi_register_callback(NETFUN_APP, |
| 547 | IPMI_CMD_GET_WD, |
| 548 | NULL, |
| 549 | ipmi_app_watchdog_get, |
| 550 | PRIVILEGE_OPERATOR); |
| 551 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 552 | // <Get Device ID> |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 553 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 554 | NETFUN_APP, |
| 555 | IPMI_CMD_GET_DEVICE_ID); |
| 556 | ipmi_register_callback(NETFUN_APP, |
| 557 | IPMI_CMD_GET_DEVICE_ID, |
| 558 | NULL, |
| 559 | ipmi_app_get_device_id, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 560 | PRIVILEGE_USER); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 561 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 562 | // <Get Self Test Results> |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 563 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 564 | NETFUN_APP, |
| 565 | IPMI_CMD_GET_SELF_TEST_RESULTS); |
| 566 | ipmi_register_callback(NETFUN_APP, |
| 567 | IPMI_CMD_GET_SELF_TEST_RESULTS, |
| 568 | NULL, |
| 569 | ipmi_app_get_self_test_results, |
| 570 | PRIVILEGE_USER); |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 571 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 572 | // <Get Device GUID> |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 573 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 574 | NETFUN_APP, |
| 575 | IPMI_CMD_GET_DEVICE_GUID); |
| 576 | ipmi_register_callback(NETFUN_APP, |
| 577 | IPMI_CMD_GET_DEVICE_GUID, |
| 578 | NULL, |
| 579 | ipmi_app_get_device_guid, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 580 | PRIVILEGE_USER); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 581 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 582 | // <Set ACPI Power State> |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 583 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 584 | NETFUN_APP, |
| 585 | IPMI_CMD_SET_ACPI); |
| 586 | ipmi_register_callback(NETFUN_APP, |
| 587 | IPMI_CMD_SET_ACPI, |
| 588 | NULL, |
| 589 | ipmi_app_set_acpi_power_state, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 590 | PRIVILEGE_ADMIN); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 591 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 592 | // <Set Channel Access> |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 593 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 594 | NETFUN_APP, |
| 595 | IPMI_CMD_SET_CHAN_ACCESS); |
| 596 | ipmi_register_callback(NETFUN_APP, |
| 597 | IPMI_CMD_SET_CHAN_ACCESS, |
| 598 | NULL, |
| 599 | ipmi_set_channel_access, |
| 600 | PRIVILEGE_ADMIN); |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 601 | |
Tom Joseph | 69fabfe | 2017-08-04 10:15:01 +0530 | [diff] [blame] | 602 | // <Get Channel Access> |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 603 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 604 | NETFUN_APP, |
| 605 | IPMI_CMD_GET_CHANNEL_ACCESS); |
| 606 | ipmi_register_callback(NETFUN_APP, |
| 607 | IPMI_CMD_GET_CHANNEL_ACCESS, |
| 608 | NULL, |
| 609 | ipmi_get_channel_access, |
| 610 | PRIVILEGE_USER); |
Tom Joseph | 69fabfe | 2017-08-04 10:15:01 +0530 | [diff] [blame] | 611 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 612 | // <Get Channel Info Command> |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 613 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 614 | NETFUN_APP, |
| 615 | IPMI_CMD_GET_CHAN_INFO); |
| 616 | ipmi_register_callback(NETFUN_APP, |
| 617 | IPMI_CMD_GET_CHAN_INFO, |
| 618 | NULL, |
| 619 | ipmi_app_channel_info, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 620 | PRIVILEGE_USER); |
Chris Austen | c2cd29d | 2016-02-05 20:02:29 -0600 | [diff] [blame] | 621 | |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 622 | // <Get System GUID Command> |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 623 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 624 | NETFUN_APP, |
| 625 | IPMI_CMD_GET_SYS_GUID); |
| 626 | ipmi_register_callback(NETFUN_APP, |
| 627 | IPMI_CMD_GET_SYS_GUID, |
| 628 | NULL, |
| 629 | ipmi_app_get_sys_guid, |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 630 | PRIVILEGE_USER); |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 631 | return; |
| 632 | } |
| 633 | |