summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/ipmi/phosphor-ipmi-net/0009-Add-dbus-interface-for-sol-commands.patch
blob: dc7f7357c246ffc75ead20a40ff2f10bce4f5013 (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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
From 97c21a556702a0d65096b30c07ef23f15cb6a7d9 Mon Sep 17 00:00:00 2001
From: Cheng C Yang <cheng.c.yang@intel.com>
Date: Wed, 3 Jul 2019 07:39:47 +0800
Subject: [PATCH] Add dbus interface for sol commands

Add dbus interface for sol config parameters so that after move set/get
sol config parameter command from net-ipmid to host-ipmid, the command
can send config parameters to net-ipmid sol service through the dbus
interface.

Tested by:
busctl introspect xyz.openbmc_project.Settings /xyz/openbmc_project
/network/host0/sol can show correct dbus properties of sol parameters.
ipmitool -I lanplus -H x -U x -P x raw 0x0c 0x21 0x0e 0x00 0x01
ipmitool -I lanplus -H x -U x -P x raw 0x0c 0x21 0x0e 0x01 0x00
ipmitool -I lanplus -H x -U x -P x raw 0x0c 0x21 0x0e 0x02 0x83
ipmitool -I lanplus -H x -U x -P x raw 0x0c 0x21 0x0e 0x03 0x5 0x03
ipmitool -I lanplus -H x -U x -P x raw 0x0c 0x21 0x0e 0x04 0x5 0x03
all these commands can change the dbus properties as the value in
above commands.
Before and after run these commands, ipmitool -I lanplus -H x -U x
-P x sol activate can start sol session correctly.
After reboot BMC, "Progress" property in dbus interface change back
to 0 and other properties will not reset to default value.

Signed-off-by: Cheng C Yang <cheng.c.yang@intel.com>
---
 command/payload_cmds.cpp |   3 ++
 command/sol_cmds.cpp     |  84 -------------------------------
 sol/sol_manager.cpp      | 125 +++++++++++++++++++++++++++++++++++++++++++++++
 sol/sol_manager.hpp      |   1 +
 sol_module.cpp           |   6 ---
 5 files changed, 129 insertions(+), 90 deletions(-)

diff --git a/command/payload_cmds.cpp b/command/payload_cmds.cpp
index c32a510..17167a7 100644
--- a/command/payload_cmds.cpp
+++ b/command/payload_cmds.cpp
@@ -34,6 +34,9 @@ std::vector<uint8_t> activatePayload(const std::vector<uint8_t>& inPayload,
         return outPayload;
     }
 
+    std::get<sol::Manager&>(singletonPool)
+        .updateSOLParameter(ipmi::convertCurrentChannelNum(
+            ipmi::currentChNum, getInterfaceIndex()));
     if (!std::get<sol::Manager&>(singletonPool).enable)
     {
         response->completionCode = IPMI_CC_PAYLOAD_TYPE_DISABLED;
diff --git a/command/sol_cmds.cpp b/command/sol_cmds.cpp
index a8fa410..804b5ea 100644
--- a/command/sol_cmds.cpp
+++ b/command/sol_cmds.cpp
@@ -65,90 +65,6 @@ void activating(uint8_t payloadInstance, uint32_t sessionID)
                                           outPayload);
 }
 
-std::vector<uint8_t> setConfParams(const std::vector<uint8_t>& inPayload,
-                                   const message::Handler& handler)
-{
-    std::vector<uint8_t> outPayload(sizeof(SetConfParamsResponse));
-    auto request =
-        reinterpret_cast<const SetConfParamsRequest*>(inPayload.data());
-    auto response = reinterpret_cast<SetConfParamsResponse*>(outPayload.data());
-    response->completionCode = IPMI_CC_OK;
-
-    switch (static_cast<Parameter>(request->paramSelector))
-    {
-        case Parameter::PROGRESS:
-        {
-            uint8_t progress = request->value & progressMask;
-            std::get<sol::Manager&>(singletonPool).progress = progress;
-            break;
-        }
-        case Parameter::ENABLE:
-        {
-            bool enable = request->value & enableMask;
-            std::get<sol::Manager&>(singletonPool).enable = enable;
-            break;
-        }
-        case Parameter::AUTHENTICATION:
-        {
-            if (!request->auth.auth || !request->auth.encrypt)
-            {
-                response->completionCode = ipmiCCWriteReadParameter;
-            }
-            else if (request->auth.privilege <
-                         static_cast<uint8_t>(session::Privilege::USER) ||
-                     request->auth.privilege >
-                         static_cast<uint8_t>(session::Privilege::OEM))
-            {
-                response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST;
-            }
-            else
-            {
-                std::get<sol::Manager&>(singletonPool).solMinPrivilege =
-                    static_cast<session::Privilege>(request->auth.privilege);
-            }
-            break;
-        }
-        case Parameter::ACCUMULATE:
-        {
-            using namespace std::chrono_literals;
-
-            if (request->acc.threshold == 0)
-            {
-                response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST;
-                break;
-            }
-
-            std::get<sol::Manager&>(singletonPool).accumulateInterval =
-                request->acc.interval * sol::accIntervalFactor * 1ms;
-            std::get<sol::Manager&>(singletonPool).sendThreshold =
-                request->acc.threshold;
-            break;
-        }
-        case Parameter::RETRY:
-        {
-            using namespace std::chrono_literals;
-
-            std::get<sol::Manager&>(singletonPool).retryCount =
-                request->retry.count;
-            std::get<sol::Manager&>(singletonPool).retryInterval =
-                request->retry.interval * sol::retryIntervalFactor * 1ms;
-            break;
-        }
-        case Parameter::PORT:
-        {
-            response->completionCode = ipmiCCWriteReadParameter;
-            break;
-        }
-        case Parameter::NVBITRATE:
-        case Parameter::VBITRATE:
-        case Parameter::CHANNEL:
-        default:
-            response->completionCode = ipmiCCParamNotSupported;
-    }
-
-    return outPayload;
-}
-
 std::vector<uint8_t> getConfParams(const std::vector<uint8_t>& inPayload,
                                    const message::Handler& handler)
 {
diff --git a/sol/sol_manager.cpp b/sol/sol_manager.cpp
index 2046fe4..eedd28a 100644
--- a/sol/sol_manager.cpp
+++ b/sol/sol_manager.cpp
@@ -12,7 +12,13 @@
 #include <boost/asio/write.hpp>
 #include <chrono>
 #include <cmath>
+#include <ipmid/utils.hpp>
 #include <phosphor-logging/log.hpp>
+#include <sdbusplus/message/types.hpp>
+
+constexpr const char* solInterface = "xyz.openbmc_project.Ipmi.SOL";
+constexpr const char* solPath = "/xyz/openbmc_project/ipmi/sol/";
+constexpr const char* PROP_INTF = "org.freedesktop.DBus.Properties";
 
 namespace sol
 {
@@ -93,6 +99,125 @@ void Manager::stopHostConsole()
     }
 }
 
+std::string getService(sdbusplus::bus::bus& bus, const std::string& intf,
+                       const std::string& path)
+{
+    auto mapperCall =
+        bus.new_method_call("xyz.openbmc_project.ObjectMapper",
+                            "/xyz/openbmc_project/object_mapper",
+                            "xyz.openbmc_project.ObjectMapper", "GetObject");
+
+    mapperCall.append(path);
+    mapperCall.append(std::vector<std::string>({intf}));
+
+    std::map<std::string, std::vector<std::string>> mapperResponse;
+
+    try
+    {
+        auto mapperResponseMsg = bus.call(mapperCall);
+        mapperResponseMsg.read(mapperResponse);
+    }
+    catch (sdbusplus::exception_t&)
+    {
+        throw std::runtime_error("ERROR in mapper call");
+    }
+
+    if (mapperResponse.begin() == mapperResponse.end())
+    {
+        throw std::runtime_error("ERROR in reading the mapper response");
+    }
+
+    return mapperResponse.begin()->first;
+}
+
+ipmi::PropertyMap getAllDbusProperties(sdbusplus::bus::bus& bus,
+                                       const std::string& service,
+                                       const std::string& objPath,
+                                       const std::string& interface)
+{
+    ipmi::PropertyMap properties;
+
+    sdbusplus::message::message method = bus.new_method_call(
+        service.c_str(), objPath.c_str(), PROP_INTF, "GetAll");
+
+    method.append(interface);
+
+    try
+    {
+        sdbusplus::message::message reply = bus.call(method);
+        reply.read(properties);
+    }
+    catch (sdbusplus::exception_t&)
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "Failed to get all properties",
+            phosphor::logging::entry("PATH=%s", objPath.c_str()),
+            phosphor::logging::entry("INTERFACE=%s", interface.c_str()));
+        throw std::runtime_error("ERROR in reading proerties");
+    }
+
+    return properties;
+}
+
+void Manager::updateSOLParameter(uint8_t channelNum)
+{
+    std::variant<uint8_t, bool> value;
+    sdbusplus::bus::bus dbus(ipmid_get_sd_bus_connection());
+    static std::string solService{};
+    ipmi::PropertyMap properties;
+    std::string ethdevice = ipmi::getChannelName(channelNum);
+    std::string solPathWitheEthName = solPath + ethdevice;
+    if (solService.empty())
+    {
+        try
+        {
+            solService = getService(dbus, solInterface, solPathWitheEthName);
+        }
+        catch (const std::runtime_error& e)
+        {
+            solService.clear();
+            phosphor::logging::log<phosphor::logging::level::ERR>(
+                "Error: get SOL service failed");
+            return;
+        }
+    }
+    try
+    {
+        properties = getAllDbusProperties(dbus, solService, solPathWitheEthName,
+                                          solInterface);
+    }
+    catch (const std::runtime_error&)
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "Error setting sol parameter");
+        return;
+    }
+
+    progress = std::get<uint8_t>(properties["Progress"]);
+
+    enable = std::get<bool>(properties["Enable"]);
+
+    forceEncrypt = std::get<bool>(properties["ForceEncryption"]);
+
+    forceAuth = std::get<bool>(properties["ForceAuthentication"]);
+
+    solMinPrivilege = static_cast<session::Privilege>(
+        std::get<uint8_t>(properties["Privilege"]));
+
+    accumulateInterval =
+        std::get<uint8_t>((properties["AccumulateIntervalMS"])) *
+        sol::accIntervalFactor * 1ms;
+
+    sendThreshold = std::get<uint8_t>(properties["Threshold"]);
+
+    retryCount = std::get<uint8_t>(properties["RetryCount"]);
+
+    retryInterval = std::get<uint8_t>(properties["RetryIntervalMS"]) *
+                    sol::retryIntervalFactor * 1ms;
+
+    return;
+}
+
 void Manager::startPayloadInstance(uint8_t payloadInstance,
                                    session::SessionID sessionID)
 {
diff --git a/sol/sol_manager.hpp b/sol/sol_manager.hpp
index 5d96890..00da9fb 100644
--- a/sol/sol_manager.hpp
+++ b/sol/sol_manager.hpp
@@ -248,6 +248,7 @@ class Manager
      *  @return 0 on success and errno on failure.
      */
     int writeConsoleSocket(const std::vector<uint8_t>& input) const;
+    void updateSOLParameter(uint8_t channelNum);
 
   private:
     SOLPayloadMap payloadMap;
diff --git a/sol_module.cpp b/sol_module.cpp
index 8200e74..2b1fb46 100644
--- a/sol_module.cpp
+++ b/sol_module.cpp
@@ -42,12 +42,6 @@ void registerCommands()
          &getPayloadInfo,
          session::Privilege::USER,
          false},
-        // Set SOL Configuration Parameters
-        {{(static_cast<uint32_t>(message::PayloadType::IPMI) << 16) |
-          static_cast<uint16_t>(::command::NetFns::TRANSPORT) | 0x21},
-         &setConfParams,
-         session::Privilege::ADMIN,
-         false},
         // Get SOL Configuration Parameters
         {{(static_cast<uint32_t>(message::PayloadType::IPMI) << 16) |
           static_cast<uint16_t>(::command::NetFns::TRANSPORT) | 0x22},
-- 
2.7.4