blob: fd7b67d846ff34bfae2abc402ea3d5c7f0c65b0b [file] [log] [blame]
Brad Bishopb1e329a2017-08-02 01:23:12 -04001/**
2 * Copyright © 2017 IBM 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
Patrick Venture3d6d3182018-08-31 09:33:09 -070017#include "util.hpp"
18
Brad Bishopb1e329a2017-08-02 01:23:12 -040019#include <algorithm>
20#include <map>
21#include <string>
Brad Bishopb1e329a2017-08-02 01:23:12 -040022
23using namespace std::literals::string_literals;
24
Patrick Venture3d6d3182018-08-31 09:33:09 -070025template <typename T>
26struct BusMeetsMSL
Brad Bishopb1e329a2017-08-02 01:23:12 -040027{
28 std::string path;
29
Patrick Williamsc5fe26a2023-05-10 07:50:25 -050030 explicit BusMeetsMSL(const std::string& p) : path(p) {}
Brad Bishopb1e329a2017-08-02 01:23:12 -040031
32 auto operator()(const T& arg)
33 {
34 // Query each service hosting
35 // xyz.openbmc_project.Inventory.Decorator.MeetsMinimumShipLevel.
36
37 const auto& busName = arg.first;
38 return util::sdbusplus::getProperty<bool>(
Brad Bishopd1eac882018-03-29 10:34:05 -040039 busName, path,
40 "xyz.openbmc_project.Inventory."
41 "Decorator.MeetsMinimumShipLevel"s,
42 "MeetsMinimumShipLevel"s);
Brad Bishopb1e329a2017-08-02 01:23:12 -040043 }
44};
45
Patrick Venture3d6d3182018-08-31 09:33:09 -070046template <typename T>
47struct PathMeetsMSL
Brad Bishopb1e329a2017-08-02 01:23:12 -040048{
49 auto operator()(const T& arg)
50 {
51 // A given path in the mapper response is composed of
52 // a map of services/interfaces. Validate each service
53 // that hosts the MSL interface meets the MSL.
54
55 const auto& path = arg.first;
56 return std::all_of(
Brad Bishopd1eac882018-03-29 10:34:05 -040057 arg.second.begin(), arg.second.end(),
58 BusMeetsMSL<typename decltype(arg.second)::value_type>(path));
Brad Bishopb1e329a2017-08-02 01:23:12 -040059 }
60};
61
62int main(void)
63{
Brad Bishopd1eac882018-03-29 10:34:05 -040064 auto mslVerificationRequired = util::sdbusplus::getProperty<bool>(
65 "/xyz/openbmc_project/control/minimum_ship_level_required"s,
66 "xyz.openbmc_project.Control.MinimumShipLevel"s,
67 "MinimumShipLevelRequired"s);
Brad Bishopb1e329a2017-08-02 01:23:12 -040068
69 if (!mslVerificationRequired)
70 {
71 return 0;
72 }
73
74 // Obtain references to all objects hosting
75 // xyz.openbmc_project.Inventory.Decorator.MeetsMinimumShipLevel
76 // with a mapper subtree query. For each object, validate that
77 // the minimum ship level has been met.
78
79 using SubTreeType =
Brad Bishopd1eac882018-03-29 10:34:05 -040080 std::map<std::string, std::map<std::string, std::vector<std::string>>>;
Brad Bishopb1e329a2017-08-02 01:23:12 -040081
Brad Bishopd1eac882018-03-29 10:34:05 -040082 auto subtree = util::sdbusplus::callMethodAndRead<SubTreeType>(
83 "xyz.openbmc_project.ObjectMapper"s,
84 "/xyz/openbmc_project/object_mapper"s,
85 "xyz.openbmc_project.ObjectMapper"s, "GetSubTree"s, "/"s, 0,
86 std::vector<std::string>{"xyz.openbmc_project.Inventory"
87 ".Decorator.MeetsMinimumShipLevel"s});
Brad Bishopb1e329a2017-08-02 01:23:12 -040088
Brad Bishopd1eac882018-03-29 10:34:05 -040089 auto result = std::all_of(subtree.begin(), subtree.end(),
90 PathMeetsMSL<SubTreeType::value_type>());
Brad Bishopb1e329a2017-08-02 01:23:12 -040091
92 if (!result)
93 {
George Liu13e3df62022-06-22 15:03:06 +080094 lg2::info(
95 "The physical system configuration does not satisfy the minimum ship level.");
Brad Bishopb1e329a2017-08-02 01:23:12 -040096
97 return 1;
98 }
99
100 return 0;
101}