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 #include <array>
21 #include <string>
22 
23 namespace redfish
24 {
25 
26 namespace systemd_utils
27 {
28 
29 /**
30  * @brief Retrieve service root UUID
31  *
32  * @return Service root UUID
33  */
34 
getUuid()35 inline std::string getUuid()
36 {
37     std::string ret;
38     // This ID needs to match the one in ipmid
39     sd_id128_t appId{{0Xe0, 0Xe1, 0X73, 0X76, 0X64, 0X61, 0X47, 0Xda, 0Xa5,
40                       0X0c, 0Xd0, 0Xcc, 0X64, 0X12, 0X45, 0X78}};
41     sd_id128_t machineId{};
42 
43     if (sd_id128_get_machine_app_specific(appId, &machineId) == 0)
44     {
45         std::array<char, SD_ID128_STRING_MAX> str{};
46         ret = sd_id128_to_string(machineId, str.data());
47         ret.insert(8, 1, '-');
48         ret.insert(13, 1, '-');
49         ret.insert(18, 1, '-');
50         ret.insert(23, 1, '-');
51     }
52 
53     return ret;
54 }
55 
56 } // namespace systemd_utils
57 } // namespace redfish
58