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