xref: /openbmc/bmcweb/features/redfish/include/utils/systemd_utils.hpp (revision 7bffdb7e9da69ae5416cda8df826372c33716beb)
1 /*
2 // Copyright (c) 2019 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 #pragma once
17 
18 #include <systemd/sd-id128.h>
19 
20 namespace redfish
21 {
22 
23 namespace systemd_utils
24 {
25 
26 /**
27  * @brief Retrieve service root UUID
28  *
29  * @return Service root UUID
30  */
31 
32 const std::string getUuid()
33 {
34     std::string ret;
35     // This ID needs to match the one in ipmid
36     sd_id128_t appId = SD_ID128_MAKE(e0, e1, 73, 76, 64, 61, 47, da, a5, 0c, d0,
37                                      cc, 64, 12, 45, 78);
38     sd_id128_t machineId = SD_ID128_NULL;
39 
40     if (sd_id128_get_machine_app_specific(appId, &machineId) == 0)
41     {
42         std::array<char, SD_ID128_STRING_MAX> str;
43         ret = sd_id128_to_string(machineId, str.data());
44         ret.insert(8, 1, '-');
45         ret.insert(13, 1, '-');
46         ret.insert(18, 1, '-');
47         ret.insert(23, 1, '-');
48     }
49 
50     return ret;
51 }
52 
53 } // namespace systemd_utils
54 } // namespace redfish
55