summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/0007-BIOS-config-Add-support-for-PATCH-operation.patch
blob: 6f3794478091ddd9fa3abda8aa4de81b75da8e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
From ad2b1c83bd9cb1bb6eb86bebd1867b0172e5a7a8 Mon Sep 17 00:00:00 2001
From: Kuiying Wang <kuiying.wang@intel.com>
Date: Wed, 23 Dec 2020 16:50:45 +0800
Subject: [PATCH] BaseBiosTable: Add support for PATCH operation

This commit brings in support for PATCH operation of the
bios variables that updates the BaseBiosTable.

Tested-By:
* Passed Redfish validator

* Single Attribute:
PATCH https://${bmc}/redfish/v1/Systems/system/Bios/Settings -d
'{"data":[{"AttributeName": <attribute name>, "AttributeType":
<attribute type>, "AttributeValue": <attribute value>}]}'

* Multiple Attributes:
PATCH https://${bmc}/redfish/v1/Systems/system/Bios/Settings -d
'{"data":[{"AttributeName": <attribute name>, "AttributeType":
<attribute type>, "AttributeValue": <attribute value>},
{"AttributeName": <attribute name>, "AttributeType":
<attribute type>, "AttributeValue": <attribute value>}]}'

This makes use of the "Set" of "PendingAttributes" in the
backend and that updates the BaseBiosTable.

Signed-off-by: Kuiying Wang <kuiying.wang@intel.com>
---
 redfish-core/lib/bios.hpp | 94 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 93 insertions(+), 1 deletion(-)

diff --git a/redfish-core/lib/bios.hpp b/redfish-core/lib/bios.hpp
index 5f8c91b..cf76fe0 100644
--- a/redfish-core/lib/bios.hpp
+++ b/redfish-core/lib/bios.hpp
@@ -96,6 +96,29 @@ static std::string mapAttrTypeToRedfish(const std::string_view typeDbus)
 
     return ret;
 }
+static std::string mapRedfishToAttrType(const std::string_view type)
+{
+    std::string ret;
+    if (type == "string")
+    {
+        ret = "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.String";
+    }
+    else if (type == "int")
+    {
+        ret = "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.Integer";
+    }
+    else if (type == "enum")
+    {
+        ret = "xyz.openbmc_project.BIOSConfig.Manager.AttributeType."
+              "Enumeration";
+    }
+    else
+    {
+        ret = "UNKNOWN";
+    }
+
+    return ret;
+}
 static std::string mapBoundTypeToRedfish(const std::string_view typeDbus)
 {
     std::string ret;
@@ -262,7 +285,9 @@ class BiosSettings : public Node
     BiosSettings(App& app) :
         Node(app, "/redfish/v1/Systems/system/Bios/Settings")
     {
-        entityPrivileges = {{boost::beast::http::verb::get, {{"Login"}}}};
+        entityPrivileges = {
+            {boost::beast::http::verb::get, {{"Login"}}},
+            {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}};
     }
 
   private:
@@ -359,6 +384,73 @@ class BiosSettings : public Node
             "/xyz/openbmc_project/bios_config/manager",
             std::array<const char*, 0>());
     }
+
+    void doPatch(crow::Response& res, const crow::Request& req,
+                 const std::vector<std::string>&) override
+    {
+        auto asyncResp = std::make_shared<AsyncResp>(res);
+
+        nlohmann::json inpJson;
+
+        if (!redfish::json_util::readJson(req, asyncResp->res, "data", inpJson))
+        {
+            return;
+        }
+
+        for (auto& attrInfo : inpJson)
+        {
+            std::optional<std::string> attrName;
+            std::optional<std::string> attrType;
+            std::optional<std::string> attrValue;
+            if (!json_util::getValueFromJsonObject(attrInfo, "AttributeName",
+                                                   attrName))
+            {
+                messages::propertyMissing(asyncResp->res, "AttributeName");
+                return;
+            }
+            if (!json_util::getValueFromJsonObject(attrInfo, "AttributeType",
+                                                   attrType))
+            {
+                messages::propertyMissing(asyncResp->res, "AttributeType");
+                return;
+            }
+            if (!json_util::getValueFromJsonObject(attrInfo, "AttributeValue",
+                                                   attrValue))
+            {
+                messages::propertyMissing(asyncResp->res, "AttributeValue");
+                return;
+            }
+            std::string biosAttrType = mapRedfishToAttrType(*attrType);
+
+            if (biosAttrType == "UNKNOWN")
+            {
+                BMCWEB_LOG_ERROR << "Invalid attribute type";
+                messages::propertyValueNotInList(asyncResp->res,
+                                                 "AttributeType", *attrType);
+                return;
+            }
+
+            PendingAttributesType pendingAttributes;
+            pendingAttributes.emplace_back(std::make_pair(
+                *attrName, std::make_tuple(biosAttrType, *attrValue)));
+
+            crow::connections::systemBus->async_method_call(
+                [asyncResp](const boost::system::error_code ec) {
+                    if (ec)
+                    {
+                        BMCWEB_LOG_ERROR << "doPatch resp_handler got error "
+                                         << ec;
+                        messages::internalError(asyncResp->res);
+                        return;
+                    }
+                },
+                "xyz.openbmc_project.BIOSConfigManager",
+                "/xyz/openbmc_project/bios_config/manager",
+                "org.freedesktop.DBus.Properties", "Set",
+                "xyz.openbmc_project.BIOSConfig.Manager", "PendingAttributes",
+                std::variant<PendingAttributesType>(pendingAttributes));
+        }
+    }
 };
 /**
  * BiosAttributeRegistry class supports handle get method for BIOS attribute
-- 
2.17.1