blob: 47a165bc28ef0828bb5fb02aebf93c36dd688e2b [file] [log] [blame]
vishwabmcba0bd5f2015-09-30 16:50:23 +05301#include "apphandler.h"
Patrick Venture5794fcf2017-10-26 11:11:14 -07002#include "app/channel.hpp"
Patrick Venture5e6ac712017-10-25 12:16:19 -07003#include "app/watchdog.hpp"
Patrick Williams37af7332016-09-02 21:21:42 -05004#include "host-ipmid/ipmid-api.h"
Patrick Williams53a360e2016-08-12 22:01:02 -05005#include "ipmid.hpp"
David Cobbleya1adb072017-11-21 15:58:13 -08006#include "nlohmann/json.hpp"
Ratan Guptab8e99552017-07-27 07:07:48 +05307#include "types.hpp"
8#include "utils.hpp"
9
David Cobbleya1adb072017-11-21 15:58:13 -080010#include <fstream>
vishwabmcba0bd5f2015-09-30 16:50:23 +053011#include <stdio.h>
Chris Austen6caf28b2015-10-13 12:40:40 -050012#include <stdint.h>
Adriana Kobylak3a552e12015-10-19 16:11:00 -050013#include <systemd/sd-bus.h>
Sergey Solomineb9b8142016-08-23 09:07:28 -050014#include <mapper.h>
Nan Liee0cb902016-07-11 15:38:03 +080015#include <array>
Tom Joseph69fabfe2017-08-04 10:15:01 +053016#include <vector>
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -060017#include <string>
18#include <cstddef>
Ratan Gupta62736ec2017-09-02 12:02:47 +053019#include <experimental/filesystem>
20
Nan Li3d0df912016-10-18 19:51:41 +080021#include <arpa/inet.h>
Ratan Guptab8e99552017-07-27 07:07:48 +053022#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 Kobylak3a552e12015-10-19 16:11:00 -050028extern sd_bus *bus;
vishwabmcba0bd5f2015-09-30 16:50:23 +053029
Nan Li3d0df912016-10-18 19:51:41 +080030constexpr auto app_obj = "/org/openbmc/NetworkManager/Interface";
31constexpr auto app_ifc = "org.openbmc.NetworkManager";
32constexpr auto app_nwinterface = "eth0";
33
Marri Devender Rao5e007a52018-01-08 06:18:36 -060034constexpr auto bmc_interface = "xyz.openbmc_project.Inventory.Item.Bmc";
35constexpr auto bmc_guid_interface = "xyz.openbmc_project.Common.UUID";
36constexpr auto bmc_guid_property = "UUID";
37constexpr auto bmc_guid_len = 16;
38
Chris Austen6caf28b2015-10-13 12:40:40 -050039void register_netfn_app_functions() __attribute__((constructor));
vishwabmcba0bd5f2015-09-30 16:50:23 +053040
Ratan Guptab8e99552017-07-27 07:07:48 +053041using namespace phosphor::logging;
42using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Ratan Gupta62736ec2017-09-02 12:02:47 +053043namespace fs = std::experimental::filesystem;
Ratan Guptab8e99552017-07-27 07:07:48 +053044
Nan Liee0cb902016-07-11 15:38:03 +080045// Offset in get device id command.
46typedef 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 Austen7303bdc2016-04-17 11:50:54 -050057
Adriana Kobylak3a552e12015-10-19 16:11:00 -050058ipmi_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 Austen6caf28b2015-10-13 12:40:40 -050060 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 Austen7303bdc2016-04-17 11:50:54 -050069typedef struct
70{
71 char major;
72 char minor;
Chris Austen176c9652016-04-30 16:32:17 -050073 uint16_t d[2];
Chris Austen7303bdc2016-04-17 11:50:54 -050074} rev_t;
75
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -060076/* 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 Austen7303bdc2016-04-17 11:50:54 -050078/* version = v0.6-19-gf363f61-dirty */
79/* ^ ^ ^^ ^ */
80/* | | |----------|-- additional details */
81/* | |---------------- Minor */
82/* |------------------ Major */
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -060083/* and version = v1.99.10-113-g65edf7d-r3-0-g9e4f715 */
84/* ^ ^ ^^ ^ */
85/* | | |--|---------- additional details */
86/* | |---------------- Minor */
87/* |------------------ Major */
Chris Austen7303bdc2016-04-17 11:50:54 -050088/* 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 Chinari2b7e07d2017-11-08 15:38:50 -060091int convert_version(const char * p, rev_t *rev)
Chris Austen7303bdc2016-04-17 11:50:54 -050092{
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -060093 std::string s(p);
94 std::string token;
Chris Austen176c9652016-04-30 16:32:17 -050095 uint16_t commits;
Chris Austen7303bdc2016-04-17 11:50:54 -050096
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -060097 auto location = s.find_first_of('v');
98 if (location != std::string::npos)
99 {
100 s = s.substr(location+1);
Chris Austen176c9652016-04-30 16:32:17 -0500101 }
Chris Austen7303bdc2016-04-17 11:50:54 -0500102
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600103 if (!s.empty())
104 {
105 location = s.find_first_of(".");
106 if (location != std::string::npos)
107 {
Patrick Ventured2117022018-02-06 08:54:37 -0800108 rev->major = static_cast<char>(
109 std::stoi(s.substr(0, location), 0, 16));
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600110 token = s.substr(location+1);
111 }
Chris Austen176c9652016-04-30 16:32:17 -0500112
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600113 if (!token.empty())
114 {
115 location = token.find_first_of(".-");
116 if (location != std::string::npos)
117 {
Patrick Ventured2117022018-02-06 08:54:37 -0800118 rev->minor = static_cast<char>(
119 std::stoi(token.substr(0, location), 0, 16));
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600120 token = token.substr(location+1);
121 }
122 }
Chris Austen7303bdc2016-04-17 11:50:54 -0500123
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600124 // 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 Austen7303bdc2016-04-17 11:50:54 -0500161 return 0;
162}
163
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500164ipmi_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 Austen6caf28b2015-10-13 12:40:40 -0500166 ipmi_data_len_t data_len, ipmi_context_t context)
167{
168 ipmi_ret_t rc = IPMI_CC_OK;
Patrick Ventured2117022018-02-06 08:54:37 -0800169 const char *objname =
170 "/org/openbmc/inventory/system/chassis/motherboard/bmc";
171 const char *iface = "org.openbmc.InventoryItem";
Chris Austen7303bdc2016-04-17 11:50:54 -0500172 char *ver = NULL;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500173 char *busname = NULL;
Chris Austen7303bdc2016-04-17 11:50:54 -0500174 int r;
175 rev_t rev = {0};
David Cobbleya1adb072017-11-21 15:58:13 -0800176 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 Austen6caf28b2015-10-13 12:40:40 -0500179
180 // Data length
Chris Austen7303bdc2016-04-17 11:50:54 -0500181 *data_len = sizeof(dev_id);
182
David Cobbleya1adb072017-11-21 15:58:13 -0800183 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 Liee0cb902016-07-11 15:38:03 +0800207
David Cobbleya1adb072017-11-21 15:58:13 -0800208 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 Liee0cb902016-07-11 15:38:03 +0800213
David Cobbleya1adb072017-11-21 15:58:13 -0800214 // IPMI Spec version 2.0
215 dev_id.ipmi_ver = 2;
Adriana Kobylak0e912642016-06-22 16:54:39 -0500216
David Cobbleya1adb072017-11-21 15:58:13 -0800217 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 Austen7303bdc2016-04-17 11:50:54 -0500249 }
250 }
Chris Austen6caf28b2015-10-13 12:40:40 -0500251
252 // Pack the actual response
Chris Austen7303bdc2016-04-17 11:50:54 -0500253 memcpy(response, &dev_id, *data_len);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500254finish:
255 free(busname);
Xo Wange5536382017-07-20 20:14:00 -0700256 free(ver);
Chris Austen6caf28b2015-10-13 12:40:40 -0500257 return rc;
258}
259
Nan Li41fa24a2016-11-10 20:12:37 +0800260ipmi_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 Mills8991dd62017-10-25 17:11:29 -0500268 // 56h - Self Test function not implemented in this controller.
Nan Li41fa24a2016-11-10 20:12:37 +0800269 // 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 Kobylakd100ee52015-10-20 17:02:37 -0500299ipmi_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 Kobylakd100ee52015-10-20 17:02:37 -0500303 const char *objname = "/org/openbmc/control/chassis0";
Adriana Kobylak31bccae2015-11-05 13:31:06 -0600304 const char *iface = "org.freedesktop.DBus.Properties";
305 const char *chassis_iface = "org.openbmc.control.Chassis";
vishwa1eaea4f2016-02-26 11:57:40 -0600306 sd_bus_message *reply = NULL;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500307 sd_bus_error error = SD_BUS_ERROR_NULL;
308 int r = 0;
309 char *uuid = NULL;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500310 char *busname = NULL;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500311
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500312 // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
Patrick Ventured2117022018-02-06 08:54:37 -0800313 // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte
314 // order
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500315 // 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 Ventured2117022018-02-06 08:54:37 -0800319 // Point resp end of array to save in reverse order
320 int resp_loc = resp_size-1;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500321 int i = 0;
322 char *tokptr = NULL;
vishwa1eaea4f2016-02-26 11:57:40 -0600323 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 Solomineb9b8142016-08-23 09:07:28 -0500332 r = mapper_get_service(bus, objname, &busname);
333 if (r < 0) {
Brad Bishop819ddd42016-10-05 21:19:19 -0400334 fprintf(stderr, "Failed to get %s bus name: %s\n",
335 objname, strerror(-r));
Sergey Solomineb9b8142016-08-23 09:07:28 -0500336 goto finish;
337 }
vishwa1eaea4f2016-02-26 11:57:40 -0600338 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 Kobylakd100ee52015-10-20 17:02:37 -0500355
356 // Traverse the UUID
Patrick Ventured2117022018-02-06 08:54:37 -0800357 // Get the UUID octects separated by dash
358 id_octet = strtok_r(uuid, "-", &tokptr);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500359
360 if (id_octet == NULL)
vishwa1eaea4f2016-02-26 11:57:40 -0600361 {
362 // Error
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500363 fprintf(stderr, "Unexpected UUID format: %s", uuid);
vishwa1eaea4f2016-02-26 11:57:40 -0600364 rc = IPMI_CC_RESPONSE_ERROR;
365 goto finish;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500366 }
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 Ventured2117022018-02-06 08:54:37 -0800376 // Holder of the 2 chars that will become a byte
377 char tmp_array[3] = {0};
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500378 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 Ventured2117022018-02-06 08:54:37 -0800381 // Copy end to first
382 memcpy((void*)&resp_uuid[resp_loc], &resp_byte, 1);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500383 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
vishwa1eaea4f2016-02-26 11:57:40 -0600395finish:
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500396 sd_bus_error_free(&error);
vishwa1eaea4f2016-02-26 11:57:40 -0600397 reply = sd_bus_message_unref(reply);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500398 free(busname);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500399
400 return rc;
401}
Chris Austen6caf28b2015-10-13 12:40:40 -0500402
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500403ipmi_ret_t ipmi_app_get_bt_capabilities(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
404 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530405 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 Kobylak88ad8152016-12-13 10:09:08 -0600412 // 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};
vishwabmcba0bd5f2015-09-30 16:50:23 +0530415
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 Kobylak3a552e12015-10-19 16:11:00 -0500425ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
426 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530427 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 Li70aa8d92016-08-29 00:11:10 +0800432 ipmi_ret_t rc = IPMI_CC_INVALID;
vishwabmcba0bd5f2015-09-30 16:50:23 +0530433
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 Rao5e007a52018-01-08 06:18:36 -0600442ipmi_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 Austen6caf28b2015-10-13 12:40:40 -0500507void register_netfn_app_functions()
vishwabmcba0bd5f2015-09-30 16:50:23 +0530508{
Tom05732372016-09-06 17:21:23 +0530509 // <Get BT Interface Capabilities>
Patrick Ventured2117022018-02-06 08:54:37 -0800510 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,
Tom05732372016-09-06 17:21:23 +0530517 PRIVILEGE_USER);
Chris Austen6caf28b2015-10-13 12:40:40 -0500518
Tom05732372016-09-06 17:21:23 +0530519 // <Wildcard Command>
Patrick Ventured2117022018-02-06 08:54:37 -0800520 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,
Tom05732372016-09-06 17:21:23 +0530527 PRIVILEGE_USER);
Chris Austen6caf28b2015-10-13 12:40:40 -0500528
Tom05732372016-09-06 17:21:23 +0530529 // <Reset Watchdog Timer>
Patrick Ventured2117022018-02-06 08:54:37 -0800530 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,
William A. Kennington III61d5f7b2018-02-09 15:23:53 -0800536 ipmi_app_watchdog_reset,
Tom05732372016-09-06 17:21:23 +0530537 PRIVILEGE_OPERATOR);
Chris Austen6caf28b2015-10-13 12:40:40 -0500538
Tom05732372016-09-06 17:21:23 +0530539 // <Set Watchdog Timer>
Patrick Ventured2117022018-02-06 08:54:37 -0800540 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,
William A. Kennington III61d5f7b2018-02-09 15:23:53 -0800546 ipmi_app_watchdog_set,
Tom05732372016-09-06 17:21:23 +0530547 PRIVILEGE_OPERATOR);
Chris Austen6caf28b2015-10-13 12:40:40 -0500548
Tom05732372016-09-06 17:21:23 +0530549 // <Get Device ID>
Patrick Ventured2117022018-02-06 08:54:37 -0800550 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,
Tom05732372016-09-06 17:21:23 +0530557 PRIVILEGE_USER);
Chris Austen6caf28b2015-10-13 12:40:40 -0500558
Tom05732372016-09-06 17:21:23 +0530559 // <Get Self Test Results>
Patrick Ventured2117022018-02-06 08:54:37 -0800560 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 Li41fa24a2016-11-10 20:12:37 +0800568
Tom05732372016-09-06 17:21:23 +0530569 // <Get Device GUID>
Patrick Ventured2117022018-02-06 08:54:37 -0800570 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,
Tom05732372016-09-06 17:21:23 +0530577 PRIVILEGE_USER);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500578
Tom05732372016-09-06 17:21:23 +0530579 // <Set ACPI Power State>
Patrick Ventured2117022018-02-06 08:54:37 -0800580 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,
Tom05732372016-09-06 17:21:23 +0530587 PRIVILEGE_ADMIN);
Chris Austen6caf28b2015-10-13 12:40:40 -0500588
Tom05732372016-09-06 17:21:23 +0530589 // <Set Channel Access>
Patrick Ventured2117022018-02-06 08:54:37 -0800590 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 Austenc2cd29d2016-02-05 20:02:29 -0600598
Tom Joseph69fabfe2017-08-04 10:15:01 +0530599 // <Get Channel Access>
Patrick Ventured2117022018-02-06 08:54:37 -0800600 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 Joseph69fabfe2017-08-04 10:15:01 +0530608
Tom05732372016-09-06 17:21:23 +0530609 // <Get Channel Info Command>
Patrick Ventured2117022018-02-06 08:54:37 -0800610 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,
Tom05732372016-09-06 17:21:23 +0530617 PRIVILEGE_USER);
Chris Austenc2cd29d2016-02-05 20:02:29 -0600618
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600619 // <Get System GUID Command>
Patrick Ventured2117022018-02-06 08:54:37 -0800620 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 Rao5e007a52018-01-08 06:18:36 -0600627 PRIVILEGE_USER);
vishwabmcba0bd5f2015-09-30 16:50:23 +0530628 return;
629}
630