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