blob: 69ea4e46d38a1c5409dbb719f6158572f9ad4612 [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 {
108 rev->major = static_cast<char>(std::stoi(s.substr(0, location), 0, 16));
109 token = s.substr(location+1);
110 }
Chris Austen176c9652016-04-30 16:32:17 -0500111
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600112 if (!token.empty())
113 {
114 location = token.find_first_of(".-");
115 if (location != std::string::npos)
116 {
117 rev->minor = static_cast<char>(std::stoi(token.substr(0, location), 0, 16));
118 token = token.substr(location+1);
119 }
120 }
Chris Austen7303bdc2016-04-17 11:50:54 -0500121
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600122 // Capture the number of commits on top of the minor tag.
123 // I'm using BE format like the ipmi spec asked for
124 location = token.find_first_of(".-");
125 if (!token.empty())
126 {
127 commits = std::stoi(token.substr(0, location), 0, 16);
128 rev->d[0] = (commits>>8) | (commits<<8);
129
130 // commit number we skip
131 location = token.find_first_of(".-");
132 if (location != std::string::npos)
133 {
134 token = token.substr(location+1);
135 }
136 }
137 else {
138 rev->d[0] = 0;
139 }
140
141 if (location != std::string::npos)
142 {
143 token = token.substr(location+1);
144 }
145
146 // Any value of the optional parameter forces it to 1
147 location = token.find_first_of(".-");
148 if (location != std::string::npos)
149 {
150 token = token.substr(location+1);
151 }
152 commits = (!token.empty()) ? 1 : 0;
153
154 //We do this operation to get this displayed in least significant bytes
155 //of ipmitool device id command.
156 rev->d[1] = (commits>>8) | (commits<<8);
157 }
158
Chris Austen7303bdc2016-04-17 11:50:54 -0500159 return 0;
160}
161
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500162ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
163 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -0500164 ipmi_data_len_t data_len, ipmi_context_t context)
165{
166 ipmi_ret_t rc = IPMI_CC_OK;
Chris Austen7303bdc2016-04-17 11:50:54 -0500167 const char *objname = "/org/openbmc/inventory/system/chassis/motherboard/bmc";
168 const char *iface = "org.openbmc.InventoryItem";
169 char *ver = NULL;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500170 char *busname = NULL;
Chris Austen7303bdc2016-04-17 11:50:54 -0500171 int r;
172 rev_t rev = {0};
David Cobbleya1adb072017-11-21 15:58:13 -0800173 static ipmi_device_id_t dev_id{};
174 static bool dev_id_initialized = false;
175 const char* filename = "/usr/share/ipmi-providers/dev_id.json";
Chris Austen6caf28b2015-10-13 12:40:40 -0500176
177 // Data length
Chris Austen7303bdc2016-04-17 11:50:54 -0500178 *data_len = sizeof(dev_id);
179
David Cobbleya1adb072017-11-21 15:58:13 -0800180 if (!dev_id_initialized)
181 {
182 // Firmware revision is already implemented,
183 // so get it from appropriate position.
184 r = mapper_get_service(bus, objname, &busname);
185 if (r < 0) {
186 fprintf(stderr, "Failed to get %s bus name: %s\n",
187 objname, strerror(-r));
188 goto finish;
189 }
190 r = sd_bus_get_property_string(bus,busname,objname,iface,"version",
191 NULL, &ver);
192 if ( r < 0 ) {
193 fprintf(stderr, "Failed to obtain version property: %s\n",
194 strerror(-r));
195 } else {
196 r = convert_version(ver, &rev);
197 if( r >= 0 ) {
198 // bit7 identifies if the device is available
199 // 0=normal operation
200 // 1=device firmware, SDR update,
201 // or self-initialization in progress.
202 // our SDR is normal working condition, so mask:
203 dev_id.fw[0] = 0x7F & rev.major;
Nan Liee0cb902016-07-11 15:38:03 +0800204
David Cobbleya1adb072017-11-21 15:58:13 -0800205 rev.minor = (rev.minor > 99 ? 99 : rev.minor);
206 dev_id.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16;
207 memcpy(&dev_id.aux, rev.d, 4);
208 }
209 }
Nan Liee0cb902016-07-11 15:38:03 +0800210
David Cobbleya1adb072017-11-21 15:58:13 -0800211 // IPMI Spec version 2.0
212 dev_id.ipmi_ver = 2;
Adriana Kobylak0e912642016-06-22 16:54:39 -0500213
David Cobbleya1adb072017-11-21 15:58:13 -0800214 std::ifstream dev_id_file(filename);
215 if (dev_id_file.is_open())
216 {
217 auto data = nlohmann::json::parse(dev_id_file, nullptr, false);
218 if (!data.is_discarded())
219 {
220 dev_id.id = data.value("id", 0);
221 dev_id.revision = data.value("revision", 0);
222 dev_id.addn_dev_support = data.value("addn_dev_support", 0);
223 dev_id.manuf_id[2] = data.value("manuf_id", 0) >> 16;
224 dev_id.manuf_id[1] = data.value("manuf_id", 0) >> 8;
225 dev_id.manuf_id[0] = data.value("manuf_id", 0);
226 dev_id.prod_id[1] = data.value("prod_id", 0) >> 8;
227 dev_id.prod_id[0] = data.value("prod_id", 0);
228 dev_id.aux[3] = data.value("aux", 0) >> 24;
229 dev_id.aux[2] = data.value("aux", 0) >> 16;
230 dev_id.aux[1] = data.value("aux", 0) >> 8;
231 dev_id.aux[0] = data.value("aux", 0);
232
233 //Don't read the file every time if successful
234 dev_id_initialized = true;
235 }
236 else
237 {
238 log<level::ERR>("Device ID JSON parser failure");
239 rc = IPMI_CC_UNSPECIFIED_ERROR;
240 }
241 }
242 else
243 {
244 log<level::ERR>("Device ID file not found");
245 rc = IPMI_CC_UNSPECIFIED_ERROR;
Chris Austen7303bdc2016-04-17 11:50:54 -0500246 }
247 }
Chris Austen6caf28b2015-10-13 12:40:40 -0500248
249 // Pack the actual response
Chris Austen7303bdc2016-04-17 11:50:54 -0500250 memcpy(response, &dev_id, *data_len);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500251finish:
252 free(busname);
Xo Wange5536382017-07-20 20:14:00 -0700253 free(ver);
Chris Austen6caf28b2015-10-13 12:40:40 -0500254 return rc;
255}
256
Nan Li41fa24a2016-11-10 20:12:37 +0800257ipmi_ret_t ipmi_app_get_self_test_results(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
258 ipmi_request_t request, ipmi_response_t response,
259 ipmi_data_len_t data_len, ipmi_context_t context)
260{
261 ipmi_ret_t rc = IPMI_CC_OK;
262
263 // Byte 2:
264 // 55h - No error.
Gunnar Mills8991dd62017-10-25 17:11:29 -0500265 // 56h - Self Test function not implemented in this controller.
Nan Li41fa24a2016-11-10 20:12:37 +0800266 // 57h - Corrupted or inaccesssible data or devices.
267 // 58h - Fatal hardware error.
268 // FFh - reserved.
269 // all other: Device-specific 'internal failure'.
270 // Byte 3:
271 // For byte 2 = 55h, 56h, FFh: 00h
272 // For byte 2 = 58h, all other: Device-specific
273 // For byte 2 = 57h: self-test error bitfield.
274 // Note: returning 57h does not imply that all test were run.
275 // [7] 1b = Cannot access SEL device.
276 // [6] 1b = Cannot access SDR Repository.
277 // [5] 1b = Cannot access BMC FRU device.
278 // [4] 1b = IPMB signal lines do not respond.
279 // [3] 1b = SDR Repository empty.
280 // [2] 1b = Internal Use Area of BMC FRU corrupted.
281 // [1] 1b = controller update 'boot block' firmware corrupted.
282 // [0] 1b = controller operational firmware corrupted.
283
284 char selftestresults[2] = {0};
285
286 *data_len = 2;
287
288 selftestresults[0] = 0x56;
289 selftestresults[1] = 0;
290
291 memcpy(response, selftestresults, *data_len);
292
293 return rc;
294}
295
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500296ipmi_ret_t ipmi_app_get_device_guid(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
297 ipmi_request_t request, ipmi_response_t response,
298 ipmi_data_len_t data_len, ipmi_context_t context)
299{
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500300 const char *objname = "/org/openbmc/control/chassis0";
Adriana Kobylak31bccae2015-11-05 13:31:06 -0600301 const char *iface = "org.freedesktop.DBus.Properties";
302 const char *chassis_iface = "org.openbmc.control.Chassis";
vishwa1eaea4f2016-02-26 11:57:40 -0600303 sd_bus_message *reply = NULL;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500304 sd_bus_error error = SD_BUS_ERROR_NULL;
305 int r = 0;
306 char *uuid = NULL;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500307 char *busname = NULL;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500308
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500309 // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
310 // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte order
311 // Ex: 0x2332fc2c40e66298e511f2782395a361
312
313 const int resp_size = 16; // Response is 16 hex bytes per IPMI Spec
314 uint8_t resp_uuid[resp_size]; // Array to hold the formatted response
315 int resp_loc = resp_size-1; // Point resp end of array to save in reverse order
316 int i = 0;
317 char *tokptr = NULL;
vishwa1eaea4f2016-02-26 11:57:40 -0600318 char *id_octet = NULL;
319
320 // Status code.
321 ipmi_ret_t rc = IPMI_CC_OK;
322 *data_len = 0;
323
324 printf("IPMI GET DEVICE GUID\n");
325
326 // Call Get properties method with the interface and property name
Sergey Solomineb9b8142016-08-23 09:07:28 -0500327 r = mapper_get_service(bus, objname, &busname);
328 if (r < 0) {
Brad Bishop819ddd42016-10-05 21:19:19 -0400329 fprintf(stderr, "Failed to get %s bus name: %s\n",
330 objname, strerror(-r));
Sergey Solomineb9b8142016-08-23 09:07:28 -0500331 goto finish;
332 }
vishwa1eaea4f2016-02-26 11:57:40 -0600333 r = sd_bus_call_method(bus,busname,objname,iface,
334 "Get",&error, &reply, "ss",
335 chassis_iface, "uuid");
336 if (r < 0)
337 {
338 fprintf(stderr, "Failed to call Get Method: %s\n", strerror(-r));
339 rc = IPMI_CC_UNSPECIFIED_ERROR;
340 goto finish;
341 }
342
343 r = sd_bus_message_read(reply, "v", "s", &uuid);
344 if (r < 0 || uuid == NULL)
345 {
346 fprintf(stderr, "Failed to get a response: %s", strerror(-r));
347 rc = IPMI_CC_RESPONSE_ERROR;
348 goto finish;
349 }
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500350
351 // Traverse the UUID
vishwa1eaea4f2016-02-26 11:57:40 -0600352 id_octet = strtok_r(uuid, "-", &tokptr); // Get the UUID octects separated by dash
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500353
354 if (id_octet == NULL)
vishwa1eaea4f2016-02-26 11:57:40 -0600355 {
356 // Error
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500357 fprintf(stderr, "Unexpected UUID format: %s", uuid);
vishwa1eaea4f2016-02-26 11:57:40 -0600358 rc = IPMI_CC_RESPONSE_ERROR;
359 goto finish;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500360 }
361
362 while (id_octet != NULL)
363 {
364 // Calculate the octet string size since it varies
365 // Divide it by 2 for the array size since 1 byte is built from 2 chars
366 int tmp_size = strlen(id_octet)/2;
367
368 for(i = 0; i < tmp_size; i++)
369 {
Joel Stanley38310cd2015-11-25 17:32:08 +1030370 char tmp_array[3] = {0}; // Holder of the 2 chars that will become a byte
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500371 strncpy(tmp_array, id_octet, 2); // 2 chars at a time
372
373 int resp_byte = strtoul(tmp_array, NULL, 16); // Convert to hex byte
374 memcpy((void*)&resp_uuid[resp_loc], &resp_byte, 1); // Copy end to first
375 resp_loc--;
376 id_octet+=2; // Finished with the 2 chars, advance
377 }
378 id_octet=strtok_r(NULL, "-", &tokptr); // Get next octet
379 }
380
381 // Data length
382 *data_len = resp_size;
383
384 // Pack the actual response
385 memcpy(response, &resp_uuid, *data_len);
386
vishwa1eaea4f2016-02-26 11:57:40 -0600387finish:
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500388 sd_bus_error_free(&error);
vishwa1eaea4f2016-02-26 11:57:40 -0600389 reply = sd_bus_message_unref(reply);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500390 free(busname);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500391
392 return rc;
393}
Chris Austen6caf28b2015-10-13 12:40:40 -0500394
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500395ipmi_ret_t ipmi_app_get_bt_capabilities(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
396 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530397 ipmi_data_len_t data_len, ipmi_context_t context)
398{
399 printf("Handling Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd);
400
401 // Status code.
402 ipmi_ret_t rc = IPMI_CC_OK;
403
Adriana Kobylak88ad8152016-12-13 10:09:08 -0600404 // Per IPMI 2.0 spec, the input and output buffer size must be the max
405 // buffer size minus one byte to allocate space for the length byte.
406 uint8_t str[] = {0x01, MAX_IPMI_BUFFER-1, MAX_IPMI_BUFFER-1, 0x0A, 0x01};
vishwabmcba0bd5f2015-09-30 16:50:23 +0530407
408 // Data length
409 *data_len = sizeof(str);
410
411 // Pack the actual response
412 memcpy(response, &str, *data_len);
413
414 return rc;
415}
416
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500417ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
418 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530419 ipmi_data_len_t data_len, ipmi_context_t context)
420{
421 printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
422
423 // Status code.
Nan Li70aa8d92016-08-29 00:11:10 +0800424 ipmi_ret_t rc = IPMI_CC_INVALID;
vishwabmcba0bd5f2015-09-30 16:50:23 +0530425
426 *data_len = strlen("THIS IS WILDCARD");
427
428 // Now pack actual response
429 memcpy(response, "THIS IS WILDCARD", *data_len);
430
431 return rc;
432}
433
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600434ipmi_ret_t ipmi_app_get_sys_guid(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
435 ipmi_request_t request, ipmi_response_t response,
436 ipmi_data_len_t data_len, ipmi_context_t context)
437
438{
439 ipmi_ret_t rc = IPMI_CC_OK;
440 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
441
442 try
443 {
444 // Get the Inventory object implementing BMC interface
445 ipmi::DbusObjectInfo bmcObject =
446 ipmi::getDbusObject(bus, bmc_interface);
447
448 // Read UUID property value from bmcObject
449 // UUID is in RFC4122 format Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
450 auto variant = ipmi::getDbusProperty(
451 bus, bmcObject.second, bmcObject.first, bmc_guid_interface,
452 bmc_guid_property);
453 std::string guidProp = variant.get<std::string>();
454
455 // Erase "-" characters from the property value
456 guidProp.erase(std::remove(guidProp.begin(), guidProp.end(), '-'),
457 guidProp.end());
458
459 auto guidPropLen = guidProp.length();
460 // Validate UUID data
461 // Divide by 2 as 1 byte is built from 2 chars
462 if ( (guidPropLen <=0) || ((guidPropLen/2) != bmc_guid_len) )
463
464 {
465 log<level::ERR>("Invalid UUID property value",
466 entry("UUID_LENGTH=%d", guidPropLen));
467 return IPMI_CC_RESPONSE_ERROR;
468 }
469
470 // Convert data in RFC4122(MSB) format to LSB format
471 // Get 2 characters at a time as 1 byte is built from 2 chars and
472 // convert to hex byte
473 // TODO: Data printed for GUID command is not as per the
474 // GUID format defined in IPMI specification 2.0 section 20.8
475 // Ticket raised: https://sourceforge.net/p/ipmitool/bugs/501/
476 uint8_t respGuid[bmc_guid_len];
477 for (size_t i = 0, respLoc = (bmc_guid_len - 1);
478 i < guidPropLen && respLoc >= 0; i += 2, respLoc--)
479 {
480 auto value = static_cast<uint8_t>(
481 std::stoi(guidProp.substr(i, 2).c_str(), NULL, 16));
482 respGuid[respLoc] = value;
483 }
484
485 *data_len = bmc_guid_len;
486 memcpy(response, &respGuid, bmc_guid_len);
487 }
488 catch (const InternalFailure& e)
489 {
490 log<level::ERR>("Failed in reading BMC UUID property",
491 entry("INTERFACE=%s", bmc_interface),
492 entry("PROPERTY_INTERFACE=%s", bmc_guid_interface),
493 entry("PROPERTY=%s", bmc_guid_property));
494 return IPMI_CC_UNSPECIFIED_ERROR;
495 }
496 return rc;
497}
498
Chris Austen6caf28b2015-10-13 12:40:40 -0500499void register_netfn_app_functions()
vishwabmcba0bd5f2015-09-30 16:50:23 +0530500{
Tom05732372016-09-06 17:21:23 +0530501 // <Get BT Interface Capabilities>
vishwabmcba0bd5f2015-09-30 16:50:23 +0530502 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CAP_BIT);
Tom05732372016-09-06 17:21:23 +0530503 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CAP_BIT, NULL, ipmi_app_get_bt_capabilities,
504 PRIVILEGE_USER);
Chris Austen6caf28b2015-10-13 12:40:40 -0500505
Tom05732372016-09-06 17:21:23 +0530506 // <Wildcard Command>
Chris Austen6caf28b2015-10-13 12:40:40 -0500507 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_WILDCARD);
Tom05732372016-09-06 17:21:23 +0530508 ipmi_register_callback(NETFUN_APP, IPMI_CMD_WILDCARD, NULL, ipmi_app_wildcard_handler,
509 PRIVILEGE_USER);
Chris Austen6caf28b2015-10-13 12:40:40 -0500510
Tom05732372016-09-06 17:21:23 +0530511 // <Reset Watchdog Timer>
Chris Austen6caf28b2015-10-13 12:40:40 -0500512 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_RESET_WD);
Tom05732372016-09-06 17:21:23 +0530513 ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, ipmi_app_reset_watchdog,
514 PRIVILEGE_OPERATOR);
Chris Austen6caf28b2015-10-13 12:40:40 -0500515
Tom05732372016-09-06 17:21:23 +0530516 // <Set Watchdog Timer>
Chris Austen6caf28b2015-10-13 12:40:40 -0500517 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_WD);
Tom05732372016-09-06 17:21:23 +0530518 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, ipmi_app_set_watchdog,
519 PRIVILEGE_OPERATOR);
Chris Austen6caf28b2015-10-13 12:40:40 -0500520
Tom05732372016-09-06 17:21:23 +0530521 // <Get Device ID>
Chris Austen6caf28b2015-10-13 12:40:40 -0500522 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_ID);
Tom05732372016-09-06 17:21:23 +0530523 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_ID, NULL, ipmi_app_get_device_id,
524 PRIVILEGE_USER);
Chris Austen6caf28b2015-10-13 12:40:40 -0500525
Tom05732372016-09-06 17:21:23 +0530526 // <Get Self Test Results>
Nan Li41fa24a2016-11-10 20:12:37 +0800527 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_SELF_TEST_RESULTS);
Tom05732372016-09-06 17:21:23 +0530528 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_SELF_TEST_RESULTS, NULL,
529 ipmi_app_get_self_test_results, PRIVILEGE_USER);
Nan Li41fa24a2016-11-10 20:12:37 +0800530
Tom05732372016-09-06 17:21:23 +0530531 // <Get Device GUID>
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500532 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID);
Tom05732372016-09-06 17:21:23 +0530533 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID, NULL, ipmi_app_get_device_guid,
534 PRIVILEGE_USER);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500535
Tom05732372016-09-06 17:21:23 +0530536 // <Set ACPI Power State>
Chris Austen6caf28b2015-10-13 12:40:40 -0500537 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_ACPI);
Tom05732372016-09-06 17:21:23 +0530538 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, ipmi_app_set_acpi_power_state,
539 PRIVILEGE_ADMIN);
Chris Austen6caf28b2015-10-13 12:40:40 -0500540
Tom05732372016-09-06 17:21:23 +0530541 // <Set Channel Access>
Nan Li3d0df912016-10-18 19:51:41 +0800542 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP,
543 IPMI_CMD_SET_CHAN_ACCESS);
544 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_CHAN_ACCESS, NULL,
Tom05732372016-09-06 17:21:23 +0530545 ipmi_set_channel_access, PRIVILEGE_ADMIN);
Chris Austenc2cd29d2016-02-05 20:02:29 -0600546
Tom Joseph69fabfe2017-08-04 10:15:01 +0530547 // <Get Channel Access>
548 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CHANNEL_ACCESS);
549 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHANNEL_ACCESS, NULL,
Patrick Venture5794fcf2017-10-26 11:11:14 -0700550 ipmi_get_channel_access, PRIVILEGE_USER);
Tom Joseph69fabfe2017-08-04 10:15:01 +0530551
Tom05732372016-09-06 17:21:23 +0530552 // <Get Channel Info Command>
Chris Austenc2cd29d2016-02-05 20:02:29 -0600553 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CHAN_INFO);
Tom05732372016-09-06 17:21:23 +0530554 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHAN_INFO, NULL, ipmi_app_channel_info,
555 PRIVILEGE_USER);
Chris Austenc2cd29d2016-02-05 20:02:29 -0600556
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600557 // <Get System GUID Command>
558 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_SYS_GUID);
559 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_SYS_GUID, NULL, ipmi_app_get_sys_guid,
560 PRIVILEGE_USER);
vishwabmcba0bd5f2015-09-30 16:50:23 +0530561 return;
562}
563
Chris Austen6caf28b2015-10-13 12:40:40 -0500564