blob: e370f0c5b80ba2c52c14bf827b8271574cf98438 [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
Marri Devender Rao5e007a52018-01-08 06:18:36 -060030constexpr auto bmc_interface = "xyz.openbmc_project.Inventory.Item.Bmc";
31constexpr auto bmc_guid_interface = "xyz.openbmc_project.Common.UUID";
32constexpr auto bmc_guid_property = "UUID";
33constexpr auto bmc_guid_len = 16;
34
Chris Austen6caf28b2015-10-13 12:40:40 -050035void register_netfn_app_functions() __attribute__((constructor));
vishwabmcba0bd5f2015-09-30 16:50:23 +053036
Ratan Guptab8e99552017-07-27 07:07:48 +053037using namespace phosphor::logging;
38using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Ratan Gupta62736ec2017-09-02 12:02:47 +053039namespace fs = std::experimental::filesystem;
Ratan Guptab8e99552017-07-27 07:07:48 +053040
Nan Liee0cb902016-07-11 15:38:03 +080041// Offset in get device id command.
42typedef struct
43{
44 uint8_t id;
45 uint8_t revision;
46 uint8_t fw[2];
47 uint8_t ipmi_ver;
48 uint8_t addn_dev_support;
49 uint8_t manuf_id[3];
50 uint8_t prod_id[2];
51 uint8_t aux[4];
52}__attribute__((packed)) ipmi_device_id_t;
Chris Austen7303bdc2016-04-17 11:50:54 -050053
Adriana Kobylak3a552e12015-10-19 16:11:00 -050054ipmi_ret_t ipmi_app_set_acpi_power_state(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
55 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -050056 ipmi_data_len_t data_len, ipmi_context_t context)
57{
58 ipmi_ret_t rc = IPMI_CC_OK;
59 *data_len = 0;
60
61 printf("IPMI SET ACPI STATE Ignoring for now\n");
62 return rc;
63}
64
Chris Austen7303bdc2016-04-17 11:50:54 -050065typedef struct
66{
67 char major;
68 char minor;
Chris Austen176c9652016-04-30 16:32:17 -050069 uint16_t d[2];
Chris Austen7303bdc2016-04-17 11:50:54 -050070} rev_t;
71
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -060072/* Currently supports the vx.x-x-[-x] and v1.x.x-x-[-x] format. It will */
73/* return -1 if not in those formats, this routine knows how to parse */
Chris Austen7303bdc2016-04-17 11:50:54 -050074/* version = v0.6-19-gf363f61-dirty */
75/* ^ ^ ^^ ^ */
76/* | | |----------|-- additional details */
77/* | |---------------- Minor */
78/* |------------------ Major */
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -060079/* and version = v1.99.10-113-g65edf7d-r3-0-g9e4f715 */
80/* ^ ^ ^^ ^ */
81/* | | |--|---------- additional details */
82/* | |---------------- Minor */
83/* |------------------ Major */
Chris Austen7303bdc2016-04-17 11:50:54 -050084/* Additional details : If the option group exists it will force Auxiliary */
85/* Firmware Revision Information 4th byte to 1 indicating the build was */
86/* derived with additional edits */
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -060087int convert_version(const char * p, rev_t *rev)
Chris Austen7303bdc2016-04-17 11:50:54 -050088{
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -060089 std::string s(p);
90 std::string token;
Chris Austen176c9652016-04-30 16:32:17 -050091 uint16_t commits;
Chris Austen7303bdc2016-04-17 11:50:54 -050092
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -060093 auto location = s.find_first_of('v');
94 if (location != std::string::npos)
95 {
96 s = s.substr(location+1);
Chris Austen176c9652016-04-30 16:32:17 -050097 }
Chris Austen7303bdc2016-04-17 11:50:54 -050098
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -060099 if (!s.empty())
100 {
101 location = s.find_first_of(".");
102 if (location != std::string::npos)
103 {
Patrick Ventured2117022018-02-06 08:54:37 -0800104 rev->major = static_cast<char>(
105 std::stoi(s.substr(0, location), 0, 16));
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600106 token = s.substr(location+1);
107 }
Chris Austen176c9652016-04-30 16:32:17 -0500108
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600109 if (!token.empty())
110 {
111 location = token.find_first_of(".-");
112 if (location != std::string::npos)
113 {
Patrick Ventured2117022018-02-06 08:54:37 -0800114 rev->minor = static_cast<char>(
115 std::stoi(token.substr(0, location), 0, 16));
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600116 token = token.substr(location+1);
117 }
118 }
Chris Austen7303bdc2016-04-17 11:50:54 -0500119
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600120 // Capture the number of commits on top of the minor tag.
121 // I'm using BE format like the ipmi spec asked for
122 location = token.find_first_of(".-");
123 if (!token.empty())
124 {
125 commits = std::stoi(token.substr(0, location), 0, 16);
126 rev->d[0] = (commits>>8) | (commits<<8);
127
128 // commit number we skip
129 location = token.find_first_of(".-");
130 if (location != std::string::npos)
131 {
132 token = token.substr(location+1);
133 }
134 }
135 else {
136 rev->d[0] = 0;
137 }
138
139 if (location != std::string::npos)
140 {
141 token = token.substr(location+1);
142 }
143
144 // Any value of the optional parameter forces it to 1
145 location = token.find_first_of(".-");
146 if (location != std::string::npos)
147 {
148 token = token.substr(location+1);
149 }
150 commits = (!token.empty()) ? 1 : 0;
151
152 //We do this operation to get this displayed in least significant bytes
153 //of ipmitool device id command.
154 rev->d[1] = (commits>>8) | (commits<<8);
155 }
156
Chris Austen7303bdc2016-04-17 11:50:54 -0500157 return 0;
158}
159
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500160ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
161 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -0500162 ipmi_data_len_t data_len, ipmi_context_t context)
163{
164 ipmi_ret_t rc = IPMI_CC_OK;
Patrick Ventured2117022018-02-06 08:54:37 -0800165 const char *objname =
166 "/org/openbmc/inventory/system/chassis/motherboard/bmc";
167 const char *iface = "org.openbmc.InventoryItem";
Chris Austen7303bdc2016-04-17 11:50:54 -0500168 char *ver = NULL;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500169 char *busname = NULL;
Chris Austen7303bdc2016-04-17 11:50:54 -0500170 int r;
171 rev_t rev = {0};
David Cobbleya1adb072017-11-21 15:58:13 -0800172 static ipmi_device_id_t dev_id{};
173 static bool dev_id_initialized = false;
174 const char* filename = "/usr/share/ipmi-providers/dev_id.json";
Chris Austen6caf28b2015-10-13 12:40:40 -0500175
176 // Data length
Chris Austen7303bdc2016-04-17 11:50:54 -0500177 *data_len = sizeof(dev_id);
178
David Cobbleya1adb072017-11-21 15:58:13 -0800179 if (!dev_id_initialized)
180 {
181 // Firmware revision is already implemented,
182 // so get it from appropriate position.
183 r = mapper_get_service(bus, objname, &busname);
184 if (r < 0) {
185 fprintf(stderr, "Failed to get %s bus name: %s\n",
186 objname, strerror(-r));
187 goto finish;
188 }
189 r = sd_bus_get_property_string(bus,busname,objname,iface,"version",
190 NULL, &ver);
191 if ( r < 0 ) {
192 fprintf(stderr, "Failed to obtain version property: %s\n",
193 strerror(-r));
194 } else {
195 r = convert_version(ver, &rev);
196 if( r >= 0 ) {
197 // bit7 identifies if the device is available
198 // 0=normal operation
199 // 1=device firmware, SDR update,
200 // or self-initialization in progress.
201 // our SDR is normal working condition, so mask:
202 dev_id.fw[0] = 0x7F & rev.major;
Nan Liee0cb902016-07-11 15:38:03 +0800203
David Cobbleya1adb072017-11-21 15:58:13 -0800204 rev.minor = (rev.minor > 99 ? 99 : rev.minor);
205 dev_id.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16;
206 memcpy(&dev_id.aux, rev.d, 4);
207 }
208 }
Nan Liee0cb902016-07-11 15:38:03 +0800209
David Cobbleya1adb072017-11-21 15:58:13 -0800210 // IPMI Spec version 2.0
211 dev_id.ipmi_ver = 2;
Adriana Kobylak0e912642016-06-22 16:54:39 -0500212
David Cobbleya1adb072017-11-21 15:58:13 -0800213 std::ifstream dev_id_file(filename);
214 if (dev_id_file.is_open())
215 {
216 auto data = nlohmann::json::parse(dev_id_file, nullptr, false);
217 if (!data.is_discarded())
218 {
219 dev_id.id = data.value("id", 0);
220 dev_id.revision = data.value("revision", 0);
221 dev_id.addn_dev_support = data.value("addn_dev_support", 0);
222 dev_id.manuf_id[2] = data.value("manuf_id", 0) >> 16;
223 dev_id.manuf_id[1] = data.value("manuf_id", 0) >> 8;
224 dev_id.manuf_id[0] = data.value("manuf_id", 0);
225 dev_id.prod_id[1] = data.value("prod_id", 0) >> 8;
226 dev_id.prod_id[0] = data.value("prod_id", 0);
227 dev_id.aux[3] = data.value("aux", 0) >> 24;
228 dev_id.aux[2] = data.value("aux", 0) >> 16;
229 dev_id.aux[1] = data.value("aux", 0) >> 8;
230 dev_id.aux[0] = data.value("aux", 0);
231
232 //Don't read the file every time if successful
233 dev_id_initialized = true;
234 }
235 else
236 {
237 log<level::ERR>("Device ID JSON parser failure");
238 rc = IPMI_CC_UNSPECIFIED_ERROR;
239 }
240 }
241 else
242 {
243 log<level::ERR>("Device ID file not found");
244 rc = IPMI_CC_UNSPECIFIED_ERROR;
Chris Austen7303bdc2016-04-17 11:50:54 -0500245 }
246 }
Chris Austen6caf28b2015-10-13 12:40:40 -0500247
248 // Pack the actual response
Chris Austen7303bdc2016-04-17 11:50:54 -0500249 memcpy(response, &dev_id, *data_len);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500250finish:
251 free(busname);
Xo Wange5536382017-07-20 20:14:00 -0700252 free(ver);
Chris Austen6caf28b2015-10-13 12:40:40 -0500253 return rc;
254}
255
Nan Li41fa24a2016-11-10 20:12:37 +0800256ipmi_ret_t ipmi_app_get_self_test_results(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
257 ipmi_request_t request, ipmi_response_t response,
258 ipmi_data_len_t data_len, ipmi_context_t context)
259{
260 ipmi_ret_t rc = IPMI_CC_OK;
261
262 // Byte 2:
263 // 55h - No error.
Gunnar Mills8991dd62017-10-25 17:11:29 -0500264 // 56h - Self Test function not implemented in this controller.
Nan Li41fa24a2016-11-10 20:12:37 +0800265 // 57h - Corrupted or inaccesssible data or devices.
266 // 58h - Fatal hardware error.
267 // FFh - reserved.
268 // all other: Device-specific 'internal failure'.
269 // Byte 3:
270 // For byte 2 = 55h, 56h, FFh: 00h
271 // For byte 2 = 58h, all other: Device-specific
272 // For byte 2 = 57h: self-test error bitfield.
273 // Note: returning 57h does not imply that all test were run.
274 // [7] 1b = Cannot access SEL device.
275 // [6] 1b = Cannot access SDR Repository.
276 // [5] 1b = Cannot access BMC FRU device.
277 // [4] 1b = IPMB signal lines do not respond.
278 // [3] 1b = SDR Repository empty.
279 // [2] 1b = Internal Use Area of BMC FRU corrupted.
280 // [1] 1b = controller update 'boot block' firmware corrupted.
281 // [0] 1b = controller operational firmware corrupted.
282
283 char selftestresults[2] = {0};
284
285 *data_len = 2;
286
287 selftestresults[0] = 0x56;
288 selftestresults[1] = 0;
289
290 memcpy(response, selftestresults, *data_len);
291
292 return rc;
293}
294
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500295ipmi_ret_t ipmi_app_get_device_guid(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
296 ipmi_request_t request, ipmi_response_t response,
297 ipmi_data_len_t data_len, ipmi_context_t context)
298{
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500299 const char *objname = "/org/openbmc/control/chassis0";
Adriana Kobylak31bccae2015-11-05 13:31:06 -0600300 const char *iface = "org.freedesktop.DBus.Properties";
301 const char *chassis_iface = "org.openbmc.control.Chassis";
vishwa1eaea4f2016-02-26 11:57:40 -0600302 sd_bus_message *reply = NULL;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500303 sd_bus_error error = SD_BUS_ERROR_NULL;
304 int r = 0;
305 char *uuid = NULL;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500306 char *busname = NULL;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500307
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500308 // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
Patrick Ventured2117022018-02-06 08:54:37 -0800309 // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte
310 // order
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500311 // Ex: 0x2332fc2c40e66298e511f2782395a361
312
313 const int resp_size = 16; // Response is 16 hex bytes per IPMI Spec
314 uint8_t resp_uuid[resp_size]; // Array to hold the formatted response
Patrick Ventured2117022018-02-06 08:54:37 -0800315 // Point resp end of array to save in reverse order
316 int resp_loc = resp_size-1;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500317 int i = 0;
318 char *tokptr = NULL;
vishwa1eaea4f2016-02-26 11:57:40 -0600319 char *id_octet = NULL;
320
321 // Status code.
322 ipmi_ret_t rc = IPMI_CC_OK;
323 *data_len = 0;
324
325 printf("IPMI GET DEVICE GUID\n");
326
327 // Call Get properties method with the interface and property name
Sergey Solomineb9b8142016-08-23 09:07:28 -0500328 r = mapper_get_service(bus, objname, &busname);
329 if (r < 0) {
Brad Bishop819ddd42016-10-05 21:19:19 -0400330 fprintf(stderr, "Failed to get %s bus name: %s\n",
331 objname, strerror(-r));
Sergey Solomineb9b8142016-08-23 09:07:28 -0500332 goto finish;
333 }
vishwa1eaea4f2016-02-26 11:57:40 -0600334 r = sd_bus_call_method(bus,busname,objname,iface,
335 "Get",&error, &reply, "ss",
336 chassis_iface, "uuid");
337 if (r < 0)
338 {
339 fprintf(stderr, "Failed to call Get Method: %s\n", strerror(-r));
340 rc = IPMI_CC_UNSPECIFIED_ERROR;
341 goto finish;
342 }
343
344 r = sd_bus_message_read(reply, "v", "s", &uuid);
345 if (r < 0 || uuid == NULL)
346 {
347 fprintf(stderr, "Failed to get a response: %s", strerror(-r));
348 rc = IPMI_CC_RESPONSE_ERROR;
349 goto finish;
350 }
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500351
352 // Traverse the UUID
Patrick Ventured2117022018-02-06 08:54:37 -0800353 // Get the UUID octects separated by dash
354 id_octet = strtok_r(uuid, "-", &tokptr);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500355
356 if (id_octet == NULL)
vishwa1eaea4f2016-02-26 11:57:40 -0600357 {
358 // Error
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500359 fprintf(stderr, "Unexpected UUID format: %s", uuid);
vishwa1eaea4f2016-02-26 11:57:40 -0600360 rc = IPMI_CC_RESPONSE_ERROR;
361 goto finish;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500362 }
363
364 while (id_octet != NULL)
365 {
366 // Calculate the octet string size since it varies
367 // Divide it by 2 for the array size since 1 byte is built from 2 chars
368 int tmp_size = strlen(id_octet)/2;
369
370 for(i = 0; i < tmp_size; i++)
371 {
Patrick Ventured2117022018-02-06 08:54:37 -0800372 // Holder of the 2 chars that will become a byte
373 char tmp_array[3] = {0};
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500374 strncpy(tmp_array, id_octet, 2); // 2 chars at a time
375
376 int resp_byte = strtoul(tmp_array, NULL, 16); // Convert to hex byte
Patrick Ventured2117022018-02-06 08:54:37 -0800377 // Copy end to first
378 memcpy((void*)&resp_uuid[resp_loc], &resp_byte, 1);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500379 resp_loc--;
380 id_octet+=2; // Finished with the 2 chars, advance
381 }
382 id_octet=strtok_r(NULL, "-", &tokptr); // Get next octet
383 }
384
385 // Data length
386 *data_len = resp_size;
387
388 // Pack the actual response
389 memcpy(response, &resp_uuid, *data_len);
390
vishwa1eaea4f2016-02-26 11:57:40 -0600391finish:
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500392 sd_bus_error_free(&error);
vishwa1eaea4f2016-02-26 11:57:40 -0600393 reply = sd_bus_message_unref(reply);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500394 free(busname);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500395
396 return rc;
397}
Chris Austen6caf28b2015-10-13 12:40:40 -0500398
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500399ipmi_ret_t ipmi_app_get_bt_capabilities(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
400 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530401 ipmi_data_len_t data_len, ipmi_context_t context)
402{
403 printf("Handling Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd);
404
405 // Status code.
406 ipmi_ret_t rc = IPMI_CC_OK;
407
Adriana Kobylak88ad8152016-12-13 10:09:08 -0600408 // Per IPMI 2.0 spec, the input and output buffer size must be the max
409 // buffer size minus one byte to allocate space for the length byte.
410 uint8_t str[] = {0x01, MAX_IPMI_BUFFER-1, MAX_IPMI_BUFFER-1, 0x0A, 0x01};
vishwabmcba0bd5f2015-09-30 16:50:23 +0530411
412 // Data length
413 *data_len = sizeof(str);
414
415 // Pack the actual response
416 memcpy(response, &str, *data_len);
417
418 return rc;
419}
420
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500421ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
422 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530423 ipmi_data_len_t data_len, ipmi_context_t context)
424{
425 printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
426
427 // Status code.
Nan Li70aa8d92016-08-29 00:11:10 +0800428 ipmi_ret_t rc = IPMI_CC_INVALID;
vishwabmcba0bd5f2015-09-30 16:50:23 +0530429
430 *data_len = strlen("THIS IS WILDCARD");
431
432 // Now pack actual response
433 memcpy(response, "THIS IS WILDCARD", *data_len);
434
435 return rc;
436}
437
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600438ipmi_ret_t ipmi_app_get_sys_guid(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
439 ipmi_request_t request, ipmi_response_t response,
440 ipmi_data_len_t data_len, ipmi_context_t context)
441
442{
443 ipmi_ret_t rc = IPMI_CC_OK;
444 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
445
446 try
447 {
448 // Get the Inventory object implementing BMC interface
449 ipmi::DbusObjectInfo bmcObject =
450 ipmi::getDbusObject(bus, bmc_interface);
451
452 // Read UUID property value from bmcObject
453 // UUID is in RFC4122 format Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
454 auto variant = ipmi::getDbusProperty(
455 bus, bmcObject.second, bmcObject.first, bmc_guid_interface,
456 bmc_guid_property);
457 std::string guidProp = variant.get<std::string>();
458
459 // Erase "-" characters from the property value
460 guidProp.erase(std::remove(guidProp.begin(), guidProp.end(), '-'),
461 guidProp.end());
462
463 auto guidPropLen = guidProp.length();
464 // Validate UUID data
465 // Divide by 2 as 1 byte is built from 2 chars
466 if ( (guidPropLen <=0) || ((guidPropLen/2) != bmc_guid_len) )
467
468 {
469 log<level::ERR>("Invalid UUID property value",
470 entry("UUID_LENGTH=%d", guidPropLen));
471 return IPMI_CC_RESPONSE_ERROR;
472 }
473
474 // Convert data in RFC4122(MSB) format to LSB format
475 // Get 2 characters at a time as 1 byte is built from 2 chars and
476 // convert to hex byte
477 // TODO: Data printed for GUID command is not as per the
478 // GUID format defined in IPMI specification 2.0 section 20.8
479 // Ticket raised: https://sourceforge.net/p/ipmitool/bugs/501/
480 uint8_t respGuid[bmc_guid_len];
481 for (size_t i = 0, respLoc = (bmc_guid_len - 1);
482 i < guidPropLen && respLoc >= 0; i += 2, respLoc--)
483 {
484 auto value = static_cast<uint8_t>(
485 std::stoi(guidProp.substr(i, 2).c_str(), NULL, 16));
486 respGuid[respLoc] = value;
487 }
488
489 *data_len = bmc_guid_len;
490 memcpy(response, &respGuid, bmc_guid_len);
491 }
492 catch (const InternalFailure& e)
493 {
494 log<level::ERR>("Failed in reading BMC UUID property",
495 entry("INTERFACE=%s", bmc_interface),
496 entry("PROPERTY_INTERFACE=%s", bmc_guid_interface),
497 entry("PROPERTY=%s", bmc_guid_property));
498 return IPMI_CC_UNSPECIFIED_ERROR;
499 }
500 return rc;
501}
502
Chris Austen6caf28b2015-10-13 12:40:40 -0500503void register_netfn_app_functions()
vishwabmcba0bd5f2015-09-30 16:50:23 +0530504{
Tom05732372016-09-06 17:21:23 +0530505 // <Get BT Interface Capabilities>
Patrick Ventured2117022018-02-06 08:54:37 -0800506 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
507 NETFUN_APP,
508 IPMI_CMD_GET_CAP_BIT);
509 ipmi_register_callback(NETFUN_APP,
510 IPMI_CMD_GET_CAP_BIT,
511 NULL,
512 ipmi_app_get_bt_capabilities,
Tom05732372016-09-06 17:21:23 +0530513 PRIVILEGE_USER);
Chris Austen6caf28b2015-10-13 12:40:40 -0500514
Tom05732372016-09-06 17:21:23 +0530515 // <Wildcard Command>
Patrick Ventured2117022018-02-06 08:54:37 -0800516 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
517 NETFUN_APP,
518 IPMI_CMD_WILDCARD);
519 ipmi_register_callback(NETFUN_APP,
520 IPMI_CMD_WILDCARD,
521 NULL,
522 ipmi_app_wildcard_handler,
Tom05732372016-09-06 17:21:23 +0530523 PRIVILEGE_USER);
Chris Austen6caf28b2015-10-13 12:40:40 -0500524
Tom05732372016-09-06 17:21:23 +0530525 // <Reset Watchdog Timer>
Patrick Ventured2117022018-02-06 08:54:37 -0800526 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
527 NETFUN_APP,
528 IPMI_CMD_RESET_WD);
529 ipmi_register_callback(NETFUN_APP,
530 IPMI_CMD_RESET_WD,
531 NULL,
William A. Kennington III61d5f7b2018-02-09 15:23:53 -0800532 ipmi_app_watchdog_reset,
Tom05732372016-09-06 17:21:23 +0530533 PRIVILEGE_OPERATOR);
Chris Austen6caf28b2015-10-13 12:40:40 -0500534
Tom05732372016-09-06 17:21:23 +0530535 // <Set Watchdog Timer>
Patrick Ventured2117022018-02-06 08:54:37 -0800536 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
537 NETFUN_APP,
538 IPMI_CMD_SET_WD);
539 ipmi_register_callback(NETFUN_APP,
540 IPMI_CMD_SET_WD,
541 NULL,
William A. Kennington III61d5f7b2018-02-09 15:23:53 -0800542 ipmi_app_watchdog_set,
Tom05732372016-09-06 17:21:23 +0530543 PRIVILEGE_OPERATOR);
Chris Austen6caf28b2015-10-13 12:40:40 -0500544
William A. Kennington III73f44512018-02-09 15:28:46 -0800545 // <Get Watchdog Timer>
546 ipmi_register_callback(NETFUN_APP,
547 IPMI_CMD_GET_WD,
548 NULL,
549 ipmi_app_watchdog_get,
550 PRIVILEGE_OPERATOR);
551
Tom05732372016-09-06 17:21:23 +0530552 // <Get Device ID>
Patrick Ventured2117022018-02-06 08:54:37 -0800553 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
554 NETFUN_APP,
555 IPMI_CMD_GET_DEVICE_ID);
556 ipmi_register_callback(NETFUN_APP,
557 IPMI_CMD_GET_DEVICE_ID,
558 NULL,
559 ipmi_app_get_device_id,
Tom05732372016-09-06 17:21:23 +0530560 PRIVILEGE_USER);
Chris Austen6caf28b2015-10-13 12:40:40 -0500561
Tom05732372016-09-06 17:21:23 +0530562 // <Get Self Test Results>
Patrick Ventured2117022018-02-06 08:54:37 -0800563 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
564 NETFUN_APP,
565 IPMI_CMD_GET_SELF_TEST_RESULTS);
566 ipmi_register_callback(NETFUN_APP,
567 IPMI_CMD_GET_SELF_TEST_RESULTS,
568 NULL,
569 ipmi_app_get_self_test_results,
570 PRIVILEGE_USER);
Nan Li41fa24a2016-11-10 20:12:37 +0800571
Tom05732372016-09-06 17:21:23 +0530572 // <Get Device GUID>
Patrick Ventured2117022018-02-06 08:54:37 -0800573 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
574 NETFUN_APP,
575 IPMI_CMD_GET_DEVICE_GUID);
576 ipmi_register_callback(NETFUN_APP,
577 IPMI_CMD_GET_DEVICE_GUID,
578 NULL,
579 ipmi_app_get_device_guid,
Tom05732372016-09-06 17:21:23 +0530580 PRIVILEGE_USER);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500581
Tom05732372016-09-06 17:21:23 +0530582 // <Set ACPI Power State>
Patrick Ventured2117022018-02-06 08:54:37 -0800583 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
584 NETFUN_APP,
585 IPMI_CMD_SET_ACPI);
586 ipmi_register_callback(NETFUN_APP,
587 IPMI_CMD_SET_ACPI,
588 NULL,
589 ipmi_app_set_acpi_power_state,
Tom05732372016-09-06 17:21:23 +0530590 PRIVILEGE_ADMIN);
Chris Austen6caf28b2015-10-13 12:40:40 -0500591
Tom05732372016-09-06 17:21:23 +0530592 // <Set Channel Access>
Patrick Ventured2117022018-02-06 08:54:37 -0800593 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
594 NETFUN_APP,
595 IPMI_CMD_SET_CHAN_ACCESS);
596 ipmi_register_callback(NETFUN_APP,
597 IPMI_CMD_SET_CHAN_ACCESS,
598 NULL,
599 ipmi_set_channel_access,
600 PRIVILEGE_ADMIN);
Chris Austenc2cd29d2016-02-05 20:02:29 -0600601
Tom Joseph69fabfe2017-08-04 10:15:01 +0530602 // <Get Channel Access>
Patrick Ventured2117022018-02-06 08:54:37 -0800603 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
604 NETFUN_APP,
605 IPMI_CMD_GET_CHANNEL_ACCESS);
606 ipmi_register_callback(NETFUN_APP,
607 IPMI_CMD_GET_CHANNEL_ACCESS,
608 NULL,
609 ipmi_get_channel_access,
610 PRIVILEGE_USER);
Tom Joseph69fabfe2017-08-04 10:15:01 +0530611
Tom05732372016-09-06 17:21:23 +0530612 // <Get Channel Info Command>
Patrick Ventured2117022018-02-06 08:54:37 -0800613 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
614 NETFUN_APP,
615 IPMI_CMD_GET_CHAN_INFO);
616 ipmi_register_callback(NETFUN_APP,
617 IPMI_CMD_GET_CHAN_INFO,
618 NULL,
619 ipmi_app_channel_info,
Tom05732372016-09-06 17:21:23 +0530620 PRIVILEGE_USER);
Chris Austenc2cd29d2016-02-05 20:02:29 -0600621
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600622 // <Get System GUID Command>
Patrick Ventured2117022018-02-06 08:54:37 -0800623 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
624 NETFUN_APP,
625 IPMI_CMD_GET_SYS_GUID);
626 ipmi_register_callback(NETFUN_APP,
627 IPMI_CMD_GET_SYS_GUID,
628 NULL,
629 ipmi_app_get_sys_guid,
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600630 PRIVILEGE_USER);
vishwabmcba0bd5f2015-09-30 16:50:23 +0530631 return;
632}
633