blob: 05da67e673d3da636924d159ec64bf41382bb1a1 [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
Vernon Mauery185b9f82018-07-20 10:52:36 -070010#if __has_include(<filesystem>)
11#include <filesystem>
12#elif __has_include(<experimental/filesystem>)
13#include <experimental/filesystem>
14namespace std {
15 // splice experimental::filesystem into std
16 namespace filesystem = std::experimental::filesystem;
17}
18#else
19# error filesystem not available
20#endif
David Cobbleya1adb072017-11-21 15:58:13 -080021#include <fstream>
vishwabmcba0bd5f2015-09-30 16:50:23 +053022#include <stdio.h>
Chris Austen6caf28b2015-10-13 12:40:40 -050023#include <stdint.h>
Adriana Kobylak3a552e12015-10-19 16:11:00 -050024#include <systemd/sd-bus.h>
Sergey Solomineb9b8142016-08-23 09:07:28 -050025#include <mapper.h>
Nan Liee0cb902016-07-11 15:38:03 +080026#include <array>
Tom Joseph69fabfe2017-08-04 10:15:01 +053027#include <vector>
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -060028#include <string>
29#include <cstddef>
Ratan Gupta62736ec2017-09-02 12:02:47 +053030
Nan Li3d0df912016-10-18 19:51:41 +080031#include <arpa/inet.h>
Ratan Guptab8e99552017-07-27 07:07:48 +053032#include "transporthandler.hpp"
33
34#include <phosphor-logging/log.hpp>
35#include <phosphor-logging/elog-errors.hpp>
36#include "xyz/openbmc_project/Common/error.hpp"
Nagaraju Goruganti744398d2018-02-20 09:52:00 -060037#include "xyz/openbmc_project/Software/Version/server.hpp"
38#include "xyz/openbmc_project/Software/Activation/server.hpp"
Ratan Guptab8e99552017-07-27 07:07:48 +053039
Adriana Kobylak3a552e12015-10-19 16:11:00 -050040extern sd_bus *bus;
vishwabmcba0bd5f2015-09-30 16:50:23 +053041
Marri Devender Rao5e007a52018-01-08 06:18:36 -060042constexpr auto bmc_interface = "xyz.openbmc_project.Inventory.Item.Bmc";
43constexpr auto bmc_guid_interface = "xyz.openbmc_project.Common.UUID";
44constexpr auto bmc_guid_property = "UUID";
45constexpr auto bmc_guid_len = 16;
46
Nagaraju Goruganti744398d2018-02-20 09:52:00 -060047static constexpr auto redundancyIntf =
48 "xyz.openbmc_project.Software.RedundancyPriority";
49static constexpr auto versionIntf =
50 "xyz.openbmc_project.Software.Version";
51static constexpr auto activationIntf =
52 "xyz.openbmc_project.Software.Activation";
53static constexpr auto softwareRoot = "/xyz/openbmc_project/software";
54
Chris Austen6caf28b2015-10-13 12:40:40 -050055void register_netfn_app_functions() __attribute__((constructor));
vishwabmcba0bd5f2015-09-30 16:50:23 +053056
Ratan Guptab8e99552017-07-27 07:07:48 +053057using namespace phosphor::logging;
58using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Nagaraju Goruganti744398d2018-02-20 09:52:00 -060059using Version = sdbusplus::xyz::openbmc_project::Software::server::Version;
60using Activation =
61 sdbusplus::xyz::openbmc_project::Software::server::Activation;
Vernon Mauery185b9f82018-07-20 10:52:36 -070062namespace fs = std::filesystem;
Ratan Guptab8e99552017-07-27 07:07:48 +053063
Nan Liee0cb902016-07-11 15:38:03 +080064// Offset in get device id command.
65typedef struct
66{
67 uint8_t id;
68 uint8_t revision;
69 uint8_t fw[2];
70 uint8_t ipmi_ver;
71 uint8_t addn_dev_support;
72 uint8_t manuf_id[3];
73 uint8_t prod_id[2];
74 uint8_t aux[4];
75}__attribute__((packed)) ipmi_device_id_t;
Chris Austen7303bdc2016-04-17 11:50:54 -050076
Nagaraju Goruganti744398d2018-02-20 09:52:00 -060077/**
78 * @brief Returns the Version info from primary s/w object
79 *
80 * Get the Version info from the active s/w object which is having high
81 * "Priority" value(a smaller number is a higher priority) and "Purpose"
82 * is "BMC" from the list of all s/w objects those are implementing
83 * RedundancyPriority interface from the given softwareRoot path.
84 *
85 * @return On success returns the Version info from primary s/w object.
86 *
87 */
88std::string getActiveSoftwareVersionInfo()
89{
90 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
91
92 std::string revision{};
93 auto objectTree = ipmi::getAllDbusObjects(bus, softwareRoot, redundancyIntf,
94 "");
95 if (objectTree.empty())
96 {
97 log<level::ERR>("No Obj has implemented the s/w redundancy interface",
98 entry("INTERFACE=%s", redundancyIntf));
99 elog<InternalFailure>();
100 }
101
102 auto objectFound = false;
103 for (auto& softObject : objectTree)
104 {
105 auto service = ipmi::getService(bus, redundancyIntf, softObject.first);
106 auto objValueTree = ipmi::getManagedObjects(bus, service, softwareRoot);
107
108 auto minPriority = 0xFF;
109 for (const auto& objIter : objValueTree)
110 {
111 try
112 {
113 auto& intfMap = objIter.second;
114 auto& redundancyPriorityProps = intfMap.at(redundancyIntf);
115 auto& versionProps = intfMap.at(versionIntf);
116 auto& activationProps = intfMap.at(activationIntf);
117 auto priority =
118 redundancyPriorityProps.at("Priority").get<uint8_t>();
119 auto purpose = versionProps.at("Purpose").get<std::string>();
120 auto activation =
121 activationProps.at("Activation").get<std::string>();
122 auto version = versionProps.at("Version").get<std::string>();
123 if ((Version::convertVersionPurposeFromString(purpose) ==
124 Version::VersionPurpose::BMC) &&
125 (Activation::convertActivationsFromString(activation) ==
126 Activation::Activations::Active))
127 {
128 if (priority < minPriority)
129 {
130 minPriority = priority;
131 objectFound = true;
132 revision = std::move(version);
133 }
134 }
135 }
136 catch (const std::exception& e)
137 {
138 log<level::ERR>(e.what());
139 }
140 }
141 }
142
143 if (!objectFound)
144 {
145 log<level::ERR>("Could not found an BMC software Object");
146 elog<InternalFailure>();
147 }
148
149 return revision;
150}
151
152
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500153ipmi_ret_t ipmi_app_set_acpi_power_state(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
154 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -0500155 ipmi_data_len_t data_len, ipmi_context_t context)
156{
157 ipmi_ret_t rc = IPMI_CC_OK;
158 *data_len = 0;
159
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530160 log<level::DEBUG>("IPMI SET ACPI STATE Ignoring for now\n");
Chris Austen6caf28b2015-10-13 12:40:40 -0500161 return rc;
162}
163
Chris Austen7303bdc2016-04-17 11:50:54 -0500164typedef struct
165{
166 char major;
167 char minor;
Chris Austen176c9652016-04-30 16:32:17 -0500168 uint16_t d[2];
Chris Austen7303bdc2016-04-17 11:50:54 -0500169} rev_t;
170
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600171/* Currently supports the vx.x-x-[-x] and v1.x.x-x-[-x] format. It will */
172/* return -1 if not in those formats, this routine knows how to parse */
Chris Austen7303bdc2016-04-17 11:50:54 -0500173/* version = v0.6-19-gf363f61-dirty */
174/* ^ ^ ^^ ^ */
175/* | | |----------|-- additional details */
176/* | |---------------- Minor */
177/* |------------------ Major */
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600178/* and version = v1.99.10-113-g65edf7d-r3-0-g9e4f715 */
179/* ^ ^ ^^ ^ */
180/* | | |--|---------- additional details */
181/* | |---------------- Minor */
182/* |------------------ Major */
Chris Austen7303bdc2016-04-17 11:50:54 -0500183/* Additional details : If the option group exists it will force Auxiliary */
184/* Firmware Revision Information 4th byte to 1 indicating the build was */
185/* derived with additional edits */
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600186int convert_version(const char * p, rev_t *rev)
Chris Austen7303bdc2016-04-17 11:50:54 -0500187{
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600188 std::string s(p);
189 std::string token;
Chris Austen176c9652016-04-30 16:32:17 -0500190 uint16_t commits;
Chris Austen7303bdc2016-04-17 11:50:54 -0500191
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600192 auto location = s.find_first_of('v');
193 if (location != std::string::npos)
194 {
195 s = s.substr(location+1);
Chris Austen176c9652016-04-30 16:32:17 -0500196 }
Chris Austen7303bdc2016-04-17 11:50:54 -0500197
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600198 if (!s.empty())
199 {
200 location = s.find_first_of(".");
201 if (location != std::string::npos)
202 {
Patrick Ventured2117022018-02-06 08:54:37 -0800203 rev->major = static_cast<char>(
204 std::stoi(s.substr(0, location), 0, 16));
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600205 token = s.substr(location+1);
206 }
Chris Austen176c9652016-04-30 16:32:17 -0500207
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600208 if (!token.empty())
209 {
210 location = token.find_first_of(".-");
211 if (location != std::string::npos)
212 {
Patrick Ventured2117022018-02-06 08:54:37 -0800213 rev->minor = static_cast<char>(
214 std::stoi(token.substr(0, location), 0, 16));
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600215 token = token.substr(location+1);
216 }
217 }
Chris Austen7303bdc2016-04-17 11:50:54 -0500218
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600219 // Capture the number of commits on top of the minor tag.
220 // I'm using BE format like the ipmi spec asked for
221 location = token.find_first_of(".-");
222 if (!token.empty())
223 {
224 commits = std::stoi(token.substr(0, location), 0, 16);
225 rev->d[0] = (commits>>8) | (commits<<8);
226
227 // commit number we skip
228 location = token.find_first_of(".-");
229 if (location != std::string::npos)
230 {
231 token = token.substr(location+1);
232 }
233 }
234 else {
235 rev->d[0] = 0;
236 }
237
238 if (location != std::string::npos)
239 {
240 token = token.substr(location+1);
241 }
242
243 // Any value of the optional parameter forces it to 1
244 location = token.find_first_of(".-");
245 if (location != std::string::npos)
246 {
247 token = token.substr(location+1);
248 }
249 commits = (!token.empty()) ? 1 : 0;
250
251 //We do this operation to get this displayed in least significant bytes
252 //of ipmitool device id command.
253 rev->d[1] = (commits>>8) | (commits<<8);
254 }
255
Chris Austen7303bdc2016-04-17 11:50:54 -0500256 return 0;
257}
258
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500259ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
260 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -0500261 ipmi_data_len_t data_len, ipmi_context_t context)
262{
263 ipmi_ret_t rc = IPMI_CC_OK;
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600264 int r = -1;
Chris Austen7303bdc2016-04-17 11:50:54 -0500265 rev_t rev = {0};
David Cobbleya1adb072017-11-21 15:58:13 -0800266 static ipmi_device_id_t dev_id{};
267 static bool dev_id_initialized = false;
268 const char* filename = "/usr/share/ipmi-providers/dev_id.json";
Chris Austen6caf28b2015-10-13 12:40:40 -0500269
270 // Data length
Chris Austen7303bdc2016-04-17 11:50:54 -0500271 *data_len = sizeof(dev_id);
272
David Cobbleya1adb072017-11-21 15:58:13 -0800273 if (!dev_id_initialized)
274 {
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600275 try
276 {
277 auto version = getActiveSoftwareVersionInfo();
278 r = convert_version(version.c_str(), &rev);
David Cobbleya1adb072017-11-21 15:58:13 -0800279 }
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600280 catch (const std::exception& e)
281 {
282 log<level::ERR>(e.what());
283 }
Nan Liee0cb902016-07-11 15:38:03 +0800284
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600285 if( r >= 0 ) {
286 // bit7 identifies if the device is available
287 // 0=normal operation
288 // 1=device firmware, SDR update,
289 // or self-initialization in progress.
290 // our SDR is normal working condition, so mask:
291 dev_id.fw[0] = 0x7F & rev.major;
292
293 rev.minor = (rev.minor > 99 ? 99 : rev.minor);
294 dev_id.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16;
295 memcpy(&dev_id.aux, rev.d, 4);
David Cobbleya1adb072017-11-21 15:58:13 -0800296 }
Nan Liee0cb902016-07-11 15:38:03 +0800297
David Cobbleya1adb072017-11-21 15:58:13 -0800298 // IPMI Spec version 2.0
299 dev_id.ipmi_ver = 2;
Adriana Kobylak0e912642016-06-22 16:54:39 -0500300
David Cobbleya1adb072017-11-21 15:58:13 -0800301 std::ifstream dev_id_file(filename);
302 if (dev_id_file.is_open())
303 {
304 auto data = nlohmann::json::parse(dev_id_file, nullptr, false);
305 if (!data.is_discarded())
306 {
307 dev_id.id = data.value("id", 0);
308 dev_id.revision = data.value("revision", 0);
309 dev_id.addn_dev_support = data.value("addn_dev_support", 0);
310 dev_id.manuf_id[2] = data.value("manuf_id", 0) >> 16;
311 dev_id.manuf_id[1] = data.value("manuf_id", 0) >> 8;
312 dev_id.manuf_id[0] = data.value("manuf_id", 0);
313 dev_id.prod_id[1] = data.value("prod_id", 0) >> 8;
314 dev_id.prod_id[0] = data.value("prod_id", 0);
Tom Josephaf8a0982018-03-09 07:54:02 -0600315 dev_id.aux[3] = data.value("aux", 0);
316 dev_id.aux[2] = data.value("aux", 0) >> 8;
317 dev_id.aux[1] = data.value("aux", 0) >> 16;
318 dev_id.aux[0] = data.value("aux", 0) >> 24;
David Cobbleya1adb072017-11-21 15:58:13 -0800319
320 //Don't read the file every time if successful
321 dev_id_initialized = true;
322 }
323 else
324 {
325 log<level::ERR>("Device ID JSON parser failure");
326 rc = IPMI_CC_UNSPECIFIED_ERROR;
327 }
328 }
329 else
330 {
331 log<level::ERR>("Device ID file not found");
332 rc = IPMI_CC_UNSPECIFIED_ERROR;
Chris Austen7303bdc2016-04-17 11:50:54 -0500333 }
334 }
Chris Austen6caf28b2015-10-13 12:40:40 -0500335
336 // Pack the actual response
Chris Austen7303bdc2016-04-17 11:50:54 -0500337 memcpy(response, &dev_id, *data_len);
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600338
Chris Austen6caf28b2015-10-13 12:40:40 -0500339 return rc;
340}
341
Nan Li41fa24a2016-11-10 20:12:37 +0800342ipmi_ret_t ipmi_app_get_self_test_results(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
343 ipmi_request_t request, ipmi_response_t response,
344 ipmi_data_len_t data_len, ipmi_context_t context)
345{
346 ipmi_ret_t rc = IPMI_CC_OK;
347
348 // Byte 2:
349 // 55h - No error.
Gunnar Mills8991dd62017-10-25 17:11:29 -0500350 // 56h - Self Test function not implemented in this controller.
Nan Li41fa24a2016-11-10 20:12:37 +0800351 // 57h - Corrupted or inaccesssible data or devices.
352 // 58h - Fatal hardware error.
353 // FFh - reserved.
354 // all other: Device-specific 'internal failure'.
355 // Byte 3:
356 // For byte 2 = 55h, 56h, FFh: 00h
357 // For byte 2 = 58h, all other: Device-specific
358 // For byte 2 = 57h: self-test error bitfield.
359 // Note: returning 57h does not imply that all test were run.
360 // [7] 1b = Cannot access SEL device.
361 // [6] 1b = Cannot access SDR Repository.
362 // [5] 1b = Cannot access BMC FRU device.
363 // [4] 1b = IPMB signal lines do not respond.
364 // [3] 1b = SDR Repository empty.
365 // [2] 1b = Internal Use Area of BMC FRU corrupted.
366 // [1] 1b = controller update 'boot block' firmware corrupted.
367 // [0] 1b = controller operational firmware corrupted.
368
369 char selftestresults[2] = {0};
370
371 *data_len = 2;
372
373 selftestresults[0] = 0x56;
374 selftestresults[1] = 0;
375
376 memcpy(response, selftestresults, *data_len);
377
378 return rc;
379}
380
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500381ipmi_ret_t ipmi_app_get_device_guid(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
382 ipmi_request_t request, ipmi_response_t response,
383 ipmi_data_len_t data_len, ipmi_context_t context)
384{
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500385 const char *objname = "/org/openbmc/control/chassis0";
Adriana Kobylak31bccae2015-11-05 13:31:06 -0600386 const char *iface = "org.freedesktop.DBus.Properties";
387 const char *chassis_iface = "org.openbmc.control.Chassis";
vishwa1eaea4f2016-02-26 11:57:40 -0600388 sd_bus_message *reply = NULL;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500389 sd_bus_error error = SD_BUS_ERROR_NULL;
390 int r = 0;
391 char *uuid = NULL;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500392 char *busname = NULL;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500393
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500394 // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
Patrick Ventured2117022018-02-06 08:54:37 -0800395 // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte
396 // order
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500397 // Ex: 0x2332fc2c40e66298e511f2782395a361
398
399 const int resp_size = 16; // Response is 16 hex bytes per IPMI Spec
400 uint8_t resp_uuid[resp_size]; // Array to hold the formatted response
Patrick Ventured2117022018-02-06 08:54:37 -0800401 // Point resp end of array to save in reverse order
402 int resp_loc = resp_size-1;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500403 int i = 0;
404 char *tokptr = NULL;
vishwa1eaea4f2016-02-26 11:57:40 -0600405 char *id_octet = NULL;
406
407 // Status code.
408 ipmi_ret_t rc = IPMI_CC_OK;
409 *data_len = 0;
410
vishwa1eaea4f2016-02-26 11:57:40 -0600411 // Call Get properties method with the interface and property name
Sergey Solomineb9b8142016-08-23 09:07:28 -0500412 r = mapper_get_service(bus, objname, &busname);
413 if (r < 0) {
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530414 log<level::ERR>("Failed to get bus name",
415 entry("BUS=%s", objname),
416 entry("ERRNO=0x%X", -r));
Sergey Solomineb9b8142016-08-23 09:07:28 -0500417 goto finish;
418 }
vishwa1eaea4f2016-02-26 11:57:40 -0600419 r = sd_bus_call_method(bus,busname,objname,iface,
420 "Get",&error, &reply, "ss",
421 chassis_iface, "uuid");
422 if (r < 0)
423 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530424 log<level::ERR>("Failed to call Get Method",
425 entry("ERRNO=0x%X", -r));
vishwa1eaea4f2016-02-26 11:57:40 -0600426 rc = IPMI_CC_UNSPECIFIED_ERROR;
427 goto finish;
428 }
429
430 r = sd_bus_message_read(reply, "v", "s", &uuid);
431 if (r < 0 || uuid == NULL)
432 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530433 log<level::ERR>("Failed to get a response",
434 entry("ERRNO=0x%X", -r));
vishwa1eaea4f2016-02-26 11:57:40 -0600435 rc = IPMI_CC_RESPONSE_ERROR;
436 goto finish;
437 }
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500438
439 // Traverse the UUID
Patrick Ventured2117022018-02-06 08:54:37 -0800440 // Get the UUID octects separated by dash
441 id_octet = strtok_r(uuid, "-", &tokptr);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500442
443 if (id_octet == NULL)
vishwa1eaea4f2016-02-26 11:57:40 -0600444 {
445 // Error
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530446 log<level::ERR>("Unexpected UUID format",
447 entry("UUID=%s", uuid));
vishwa1eaea4f2016-02-26 11:57:40 -0600448 rc = IPMI_CC_RESPONSE_ERROR;
449 goto finish;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500450 }
451
452 while (id_octet != NULL)
453 {
454 // Calculate the octet string size since it varies
455 // Divide it by 2 for the array size since 1 byte is built from 2 chars
456 int tmp_size = strlen(id_octet)/2;
457
458 for(i = 0; i < tmp_size; i++)
459 {
Patrick Ventured2117022018-02-06 08:54:37 -0800460 // Holder of the 2 chars that will become a byte
461 char tmp_array[3] = {0};
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500462 strncpy(tmp_array, id_octet, 2); // 2 chars at a time
463
464 int resp_byte = strtoul(tmp_array, NULL, 16); // Convert to hex byte
Patrick Ventured2117022018-02-06 08:54:37 -0800465 // Copy end to first
466 memcpy((void*)&resp_uuid[resp_loc], &resp_byte, 1);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500467 resp_loc--;
468 id_octet+=2; // Finished with the 2 chars, advance
469 }
470 id_octet=strtok_r(NULL, "-", &tokptr); // Get next octet
471 }
472
473 // Data length
474 *data_len = resp_size;
475
476 // Pack the actual response
477 memcpy(response, &resp_uuid, *data_len);
478
vishwa1eaea4f2016-02-26 11:57:40 -0600479finish:
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500480 sd_bus_error_free(&error);
vishwa1eaea4f2016-02-26 11:57:40 -0600481 reply = sd_bus_message_unref(reply);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500482 free(busname);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500483
484 return rc;
485}
Chris Austen6caf28b2015-10-13 12:40:40 -0500486
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500487ipmi_ret_t ipmi_app_get_bt_capabilities(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
488 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530489 ipmi_data_len_t data_len, ipmi_context_t context)
490{
vishwabmcba0bd5f2015-09-30 16:50:23 +0530491
492 // Status code.
493 ipmi_ret_t rc = IPMI_CC_OK;
494
Adriana Kobylak88ad8152016-12-13 10:09:08 -0600495 // Per IPMI 2.0 spec, the input and output buffer size must be the max
496 // buffer size minus one byte to allocate space for the length byte.
497 uint8_t str[] = {0x01, MAX_IPMI_BUFFER-1, MAX_IPMI_BUFFER-1, 0x0A, 0x01};
vishwabmcba0bd5f2015-09-30 16:50:23 +0530498
499 // Data length
500 *data_len = sizeof(str);
501
502 // Pack the actual response
503 memcpy(response, &str, *data_len);
504
505 return rc;
506}
507
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500508ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
509 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530510 ipmi_data_len_t data_len, ipmi_context_t context)
511{
vishwabmcba0bd5f2015-09-30 16:50:23 +0530512 // Status code.
Nan Li70aa8d92016-08-29 00:11:10 +0800513 ipmi_ret_t rc = IPMI_CC_INVALID;
vishwabmcba0bd5f2015-09-30 16:50:23 +0530514
515 *data_len = strlen("THIS IS WILDCARD");
516
517 // Now pack actual response
518 memcpy(response, "THIS IS WILDCARD", *data_len);
519
520 return rc;
521}
522
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600523ipmi_ret_t ipmi_app_get_sys_guid(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
524 ipmi_request_t request, ipmi_response_t response,
525 ipmi_data_len_t data_len, ipmi_context_t context)
526
527{
528 ipmi_ret_t rc = IPMI_CC_OK;
529 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
530
531 try
532 {
533 // Get the Inventory object implementing BMC interface
534 ipmi::DbusObjectInfo bmcObject =
535 ipmi::getDbusObject(bus, bmc_interface);
536
537 // Read UUID property value from bmcObject
538 // UUID is in RFC4122 format Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
539 auto variant = ipmi::getDbusProperty(
540 bus, bmcObject.second, bmcObject.first, bmc_guid_interface,
541 bmc_guid_property);
542 std::string guidProp = variant.get<std::string>();
543
544 // Erase "-" characters from the property value
545 guidProp.erase(std::remove(guidProp.begin(), guidProp.end(), '-'),
546 guidProp.end());
547
548 auto guidPropLen = guidProp.length();
549 // Validate UUID data
550 // Divide by 2 as 1 byte is built from 2 chars
551 if ( (guidPropLen <=0) || ((guidPropLen/2) != bmc_guid_len) )
552
553 {
554 log<level::ERR>("Invalid UUID property value",
555 entry("UUID_LENGTH=%d", guidPropLen));
556 return IPMI_CC_RESPONSE_ERROR;
557 }
558
559 // Convert data in RFC4122(MSB) format to LSB format
560 // Get 2 characters at a time as 1 byte is built from 2 chars and
561 // convert to hex byte
562 // TODO: Data printed for GUID command is not as per the
563 // GUID format defined in IPMI specification 2.0 section 20.8
564 // Ticket raised: https://sourceforge.net/p/ipmitool/bugs/501/
565 uint8_t respGuid[bmc_guid_len];
566 for (size_t i = 0, respLoc = (bmc_guid_len - 1);
567 i < guidPropLen && respLoc >= 0; i += 2, respLoc--)
568 {
569 auto value = static_cast<uint8_t>(
570 std::stoi(guidProp.substr(i, 2).c_str(), NULL, 16));
571 respGuid[respLoc] = value;
572 }
573
574 *data_len = bmc_guid_len;
575 memcpy(response, &respGuid, bmc_guid_len);
576 }
577 catch (const InternalFailure& e)
578 {
579 log<level::ERR>("Failed in reading BMC UUID property",
580 entry("INTERFACE=%s", bmc_interface),
581 entry("PROPERTY_INTERFACE=%s", bmc_guid_interface),
582 entry("PROPERTY=%s", bmc_guid_property));
583 return IPMI_CC_UNSPECIFIED_ERROR;
584 }
585 return rc;
586}
587
Chris Austen6caf28b2015-10-13 12:40:40 -0500588void register_netfn_app_functions()
vishwabmcba0bd5f2015-09-30 16:50:23 +0530589{
Tom05732372016-09-06 17:21:23 +0530590 // <Get BT Interface Capabilities>
Patrick Ventured2117022018-02-06 08:54:37 -0800591 ipmi_register_callback(NETFUN_APP,
592 IPMI_CMD_GET_CAP_BIT,
593 NULL,
594 ipmi_app_get_bt_capabilities,
Tom05732372016-09-06 17:21:23 +0530595 PRIVILEGE_USER);
Chris Austen6caf28b2015-10-13 12:40:40 -0500596
Tom05732372016-09-06 17:21:23 +0530597 // <Wildcard Command>
Patrick Ventured2117022018-02-06 08:54:37 -0800598 ipmi_register_callback(NETFUN_APP,
599 IPMI_CMD_WILDCARD,
600 NULL,
601 ipmi_app_wildcard_handler,
Tom05732372016-09-06 17:21:23 +0530602 PRIVILEGE_USER);
Chris Austen6caf28b2015-10-13 12:40:40 -0500603
Tom05732372016-09-06 17:21:23 +0530604 // <Reset Watchdog Timer>
Patrick Ventured2117022018-02-06 08:54:37 -0800605 ipmi_register_callback(NETFUN_APP,
606 IPMI_CMD_RESET_WD,
607 NULL,
William A. Kennington III61d5f7b2018-02-09 15:23:53 -0800608 ipmi_app_watchdog_reset,
Tom05732372016-09-06 17:21:23 +0530609 PRIVILEGE_OPERATOR);
Chris Austen6caf28b2015-10-13 12:40:40 -0500610
Tom05732372016-09-06 17:21:23 +0530611 // <Set Watchdog Timer>
Patrick Ventured2117022018-02-06 08:54:37 -0800612 ipmi_register_callback(NETFUN_APP,
613 IPMI_CMD_SET_WD,
614 NULL,
William A. Kennington III61d5f7b2018-02-09 15:23:53 -0800615 ipmi_app_watchdog_set,
Tom05732372016-09-06 17:21:23 +0530616 PRIVILEGE_OPERATOR);
Chris Austen6caf28b2015-10-13 12:40:40 -0500617
William A. Kennington III73f44512018-02-09 15:28:46 -0800618 // <Get Watchdog Timer>
619 ipmi_register_callback(NETFUN_APP,
620 IPMI_CMD_GET_WD,
621 NULL,
622 ipmi_app_watchdog_get,
623 PRIVILEGE_OPERATOR);
624
Tom05732372016-09-06 17:21:23 +0530625 // <Get Device ID>
Patrick Ventured2117022018-02-06 08:54:37 -0800626 ipmi_register_callback(NETFUN_APP,
627 IPMI_CMD_GET_DEVICE_ID,
628 NULL,
629 ipmi_app_get_device_id,
Tom05732372016-09-06 17:21:23 +0530630 PRIVILEGE_USER);
Chris Austen6caf28b2015-10-13 12:40:40 -0500631
Tom05732372016-09-06 17:21:23 +0530632 // <Get Self Test Results>
Patrick Ventured2117022018-02-06 08:54:37 -0800633 ipmi_register_callback(NETFUN_APP,
634 IPMI_CMD_GET_SELF_TEST_RESULTS,
635 NULL,
636 ipmi_app_get_self_test_results,
637 PRIVILEGE_USER);
Nan Li41fa24a2016-11-10 20:12:37 +0800638
Tom05732372016-09-06 17:21:23 +0530639 // <Get Device GUID>
Patrick Ventured2117022018-02-06 08:54:37 -0800640 ipmi_register_callback(NETFUN_APP,
641 IPMI_CMD_GET_DEVICE_GUID,
642 NULL,
643 ipmi_app_get_device_guid,
Tom05732372016-09-06 17:21:23 +0530644 PRIVILEGE_USER);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500645
Tom05732372016-09-06 17:21:23 +0530646 // <Set ACPI Power State>
Patrick Ventured2117022018-02-06 08:54:37 -0800647 ipmi_register_callback(NETFUN_APP,
648 IPMI_CMD_SET_ACPI,
649 NULL,
650 ipmi_app_set_acpi_power_state,
Tom05732372016-09-06 17:21:23 +0530651 PRIVILEGE_ADMIN);
Chris Austen6caf28b2015-10-13 12:40:40 -0500652
Tom Joseph69fabfe2017-08-04 10:15:01 +0530653 // <Get Channel Access>
Patrick Ventured2117022018-02-06 08:54:37 -0800654 ipmi_register_callback(NETFUN_APP,
655 IPMI_CMD_GET_CHANNEL_ACCESS,
656 NULL,
657 ipmi_get_channel_access,
658 PRIVILEGE_USER);
Tom Joseph69fabfe2017-08-04 10:15:01 +0530659
Tom05732372016-09-06 17:21:23 +0530660 // <Get Channel Info Command>
Patrick Ventured2117022018-02-06 08:54:37 -0800661 ipmi_register_callback(NETFUN_APP,
662 IPMI_CMD_GET_CHAN_INFO,
663 NULL,
664 ipmi_app_channel_info,
Tom05732372016-09-06 17:21:23 +0530665 PRIVILEGE_USER);
Chris Austenc2cd29d2016-02-05 20:02:29 -0600666
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600667 // <Get System GUID Command>
Patrick Ventured2117022018-02-06 08:54:37 -0800668 ipmi_register_callback(NETFUN_APP,
669 IPMI_CMD_GET_SYS_GUID,
670 NULL,
671 ipmi_app_get_sys_guid,
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600672 PRIVILEGE_USER);
Tom Joseph7cbe2282018-03-21 21:17:33 +0530673
674 // <Get Channel Cipher Suites Command>
675 ipmi_register_callback(NETFUN_APP,
676 IPMI_CMD_GET_CHAN_CIPHER_SUITES,
677 NULL,
678 getChannelCipherSuites,
679 PRIVILEGE_CALLBACK);
vishwabmcba0bd5f2015-09-30 16:50:23 +0530680 return;
681}
682