summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/ipmi/phosphor-ipmi-host/0060-Move-Get-SOL-config-parameter-to-host-ipmid.patch
blob: d6ba705626873c6115562832f7d9852207ade8f5 (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
From ff1d4198e8ad8f824f34fb9d261ea0e25179f070 Mon Sep 17 00:00:00 2001
From: Cheng C Yang <cheng.c.yang@intel.com>
Date: Thu, 11 Jul 2019 00:32:58 +0800
Subject: [PATCH] Move Get SOL config parameter to host-ipmid

Move Get SOL config parameter command from net-ipmid to host-ipmid.

Tested:
Run command ipmitool sol info 1
Set in progress                 : set-complete
Enabled                         : true
Force Encryption                : false
Force Authentication            : false
Privilege Level                 : ADMINISTRATOR
Character Accumulate Level (ms) : 60
Character Send Threshold        : 96
Retry Count                     : 6
Retry Interval (ms)             : 200
Volatile Bit Rate (kbps)        : IPMI-Over-Serial-Setting
Non-Volatile Bit Rate (kbps)    : 115.2
Payload Channel                 : 1 (0x01)
Payload Port                    : 623

Signed-off-by: Cheng C Yang <cheng.c.yang@intel.com>
Signed-off-by: James Feist <james.feist@linux.intel.com>
---
 host-ipmid-whitelist.conf |   1 +
 transporthandler.cpp      | 191 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 192 insertions(+)

diff --git a/host-ipmid-whitelist.conf b/host-ipmid-whitelist.conf
index c93f3b1..730437d 100644
--- a/host-ipmid-whitelist.conf
+++ b/host-ipmid-whitelist.conf
@@ -42,6 +42,7 @@
 0x0A:0x49    //<Storage>:<Set SEL Time>
 0x0C:0x02    //<Transport>:<Get LAN Configuration Parameters>
 0x0C:0x21    //<Transport>:<Set SOL Configuration Parameters>
+0x0C:0x22    //<Transport>:<Get SOL Configuration Parameters>
 0x2C:0x00    //<Group Extension>:<Group Extension Command>
 0x2C:0x01    //<Group Extension>:<Get DCMI Capabilities>
 0x2C:0x02    //<Group Extension>:<Get Power Reading>
diff --git a/transporthandler.cpp b/transporthandler.cpp
index 0de76c4..b81e0d5 100644
--- a/transporthandler.cpp
+++ b/transporthandler.cpp
@@ -2120,6 +2120,28 @@ static int getSOLParameter(const std::string& property, ipmi::Value& value,
     return 0;
 }
 
+constexpr const char* consoleInterface = "xyz.openbmc_project.console";
+constexpr const char* consolePath = "/xyz/openbmc_project/console";
+static int getSOLBaudRate(ipmi::Value& value)
+{
+    auto dbus = getSdBus();
+
+    try
+    {
+        value =
+            ipmi::getDbusProperty(*dbus, "xyz.openbmc_project.console",
+                                  consolePath, consoleInterface, "baudrate");
+    }
+    catch (sdbusplus::exception_t&)
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "Error getting sol baud rate");
+        return -1;
+    }
+
+    return 0;
+}
+
 static const constexpr uint8_t encryptMask = 0x80;
 static const constexpr uint8_t encryptShift = 7;
 static const constexpr uint8_t authMask = 0x40;
@@ -2322,6 +2344,171 @@ ipmi::RspType<> setSOLConfParams(ipmi::Context::ptr ctx, uint4_t chNum,
     return ipmi::responseSuccess();
 }
 
+static const constexpr uint8_t retryCountMask = 0x07;
+static constexpr uint16_t ipmiStdPort = 623;
+static constexpr uint8_t solParameterRevision = 0x11;
+ipmi::RspType<uint8_t, std::optional<uint8_t>, std::optional<uint8_t>>
+    getSOLConfParams(ipmi::Context::ptr ctx, uint4_t chNum, uint3_t reserved,
+                     bool getParamRev, uint8_t paramSelector,
+                     uint8_t setSelector, uint8_t blockSelector)
+{
+    ipmi::ChannelInfo chInfo;
+    uint8_t channelNum = ipmi::convertCurrentChannelNum(
+        static_cast<uint8_t>(chNum), ctx->channel);
+    if (reserved != 0 ||
+        (!ipmi::isValidChannel(static_cast<uint8_t>(channelNum))) ||
+        (ipmi::EChannelSessSupported::none ==
+         ipmi::getChannelSessionSupport(static_cast<uint8_t>(channelNum))))
+    {
+        return ipmi::responseInvalidFieldRequest();
+    }
+    ipmi_ret_t compCode =
+        ipmi::getChannelInfo(static_cast<uint8_t>(channelNum), chInfo);
+    if (compCode != IPMI_CC_OK ||
+        chInfo.mediumType !=
+            static_cast<uint8_t>(ipmi::EChannelMediumType::lan8032))
+    {
+        return ipmi::responseInvalidFieldRequest();
+    }
+
+    if (getParamRev)
+    {
+        return ipmi::responseSuccess(solParameterRevision, std::nullopt,
+                                     std::nullopt);
+    }
+
+    ipmi::Value value;
+    switch (static_cast<sol::Parameter>(paramSelector))
+    {
+        case sol::Parameter::progress:
+        {
+            if (getSOLParameter("Progress", value, channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+            return ipmi::responseSuccess(
+                solParameterRevision, std::get<uint8_t>(value), std::nullopt);
+        }
+        case sol::Parameter::enable:
+        {
+            if (getSOLParameter("Enable", value, channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+            return ipmi::responseSuccess(
+                solParameterRevision,
+                static_cast<uint8_t>(std::get<bool>(value)), std::nullopt);
+        }
+        case sol::Parameter::authentication:
+        {
+            uint8_t authentication = 0;
+            if (getSOLParameter("Privilege", value, channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+            authentication = (std::get<uint8_t>(value) & 0x0f);
+
+            if (getSOLParameter("ForceAuthentication", value, channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+            authentication |=
+                (static_cast<uint8_t>(std::get<bool>(value)) << 6);
+
+            if (getSOLParameter("ForceEncryption", value, channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+            authentication |=
+                (static_cast<uint8_t>(std::get<bool>(value)) << 7);
+            return ipmi::responseSuccess(solParameterRevision, authentication,
+                                         std::nullopt);
+        }
+        case sol::Parameter::accumulate:
+        {
+            if (getSOLParameter("AccumulateIntervalMS", value, channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+
+            ipmi::Value value1;
+            if (getSOLParameter("Threshold", value1, channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+            return ipmi::responseSuccess(solParameterRevision,
+                                         std::get<uint8_t>(value),
+                                         std::get<uint8_t>(value1));
+        }
+        case sol::Parameter::retry:
+        {
+            if (getSOLParameter("RetryCount", value, channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+
+            ipmi::Value value1;
+            if (getSOLParameter("RetryIntervalMS", value1, channelNum) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+            return ipmi::responseSuccess(
+                solParameterRevision, std::get<uint8_t>(value) & retryCountMask,
+                std::get<uint8_t>(value1));
+        }
+        case sol::Parameter::channel:
+        {
+            return ipmi::responseSuccess(solParameterRevision, channelNum,
+                                         std::nullopt);
+        }
+        case sol::Parameter::port:
+        {
+            uint16_t port = htole16(ipmiStdPort);
+            auto buffer = reinterpret_cast<const uint8_t*>(&port);
+            return ipmi::responseSuccess(solParameterRevision, buffer[0],
+                                         buffer[1]);
+        }
+        case sol::Parameter::nvbitrate:
+        {
+            if (getSOLBaudRate(value) < 0)
+            {
+                return ipmi::responseUnspecifiedError();
+            }
+            uint8_t bitRate = 0;
+            uint32_t* pBaudRate = std::get_if<uint32_t>(&value);
+            if (!pBaudRate)
+            {
+                phosphor::logging::log<phosphor::logging::level::ERR>(
+                    "Failed to get valid baud rate from D-Bus interface");
+            }
+            switch (*pBaudRate)
+            {
+                case 9600:
+                    bitRate = 0x06;
+                    break;
+                case 19200:
+                    bitRate = 0x07;
+                    break;
+                case 38400:
+                    bitRate = 0x08;
+                    break;
+                case 57600:
+                    bitRate = 0x09;
+                    break;
+                case 115200:
+                    bitRate = 0x0a;
+                    break;
+                default:
+                    break;
+            }
+            return ipmi::responseSuccess(solParameterRevision, bitRate,
+                                         std::nullopt);
+        }
+        default:
+            return ipmi::responseParmNotSupported();
+    }
+}
+
 void register_netfn_transport_functions()
 {
     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnTransport,
@@ -2334,4 +2521,8 @@ void register_netfn_transport_functions()
     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnTransport,
                           ipmi::transport::cmdSetSolConfigParameters,
                           ipmi::Privilege::Admin, setSOLConfParams);
+
+    ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnTransport,
+                          ipmi::transport::cmdGetSolConfigParameters,
+                          ipmi::Privilege::User, getSOLConfParams);
 }
-- 
2.17.1