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