xref: /openbmc/bmcweb/redfish-core/include/utils/systemd_utils.hpp (revision 40e9b92ec19acffb46f83a6e55b18974da5d708e)
1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3 // SPDX-FileCopyrightText: Copyright 2019 Intel Corporation
4 #pragma once
5 
6 #include <systemd/sd-id128.h>
7 
8 #include <array>
9 #include <string>
10 
11 namespace redfish
12 {
13 
14 namespace systemd_utils
15 {
16 
17 /**
18  * @brief Retrieve service root UUID
19  *
20  * @return Service root UUID
21  */
22 
getUuid()23 inline std::string getUuid()
24 {
25     std::string ret;
26     // This ID needs to match the one in ipmid
27     sd_id128_t appId{{0Xe0, 0Xe1, 0X73, 0X76, 0X64, 0X61, 0X47, 0Xda, 0Xa5,
28                       0X0c, 0Xd0, 0Xcc, 0X64, 0X12, 0X45, 0X78}};
29     sd_id128_t machineId{};
30 
31     if (sd_id128_get_machine_app_specific(appId, &machineId) == 0)
32     {
33         std::array<char, SD_ID128_STRING_MAX> str{};
34         ret = sd_id128_to_string(machineId, str.data());
35         ret.insert(8, 1, '-');
36         ret.insert(13, 1, '-');
37         ret.insert(18, 1, '-');
38         ret.insert(23, 1, '-');
39     }
40 
41     return ret;
42 }
43 
44 } // namespace systemd_utils
45 } // namespace redfish
46