From e473399654b26eba755a11abb3f949debe62557a Mon Sep 17 00:00:00 2001
From: roly <Rolyli.Li@luxshare-ict.com>
Date: Wed, 20 Nov 2024 15:23:06 +0800
Subject: [PATCH] Support ipmi cmd set sol bitrate

---
 transporthandler.cpp | 118 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 116 insertions(+), 2 deletions(-)

diff --git a/transporthandler.cpp b/transporthandler.cpp
index dd2ac14..38faccc 100644
--- a/transporthandler.cpp
+++ b/transporthandler.cpp
@@ -1741,7 +1741,88 @@ RspType<> setSolConfParams(Context::ptr ctx, uint4_t channelBits,
             return response(ipmiCCWriteReadParameter);
         }
         case SolConfParam::NonVbitrate:
+        {
+            uint4_t encodedBitRate;
+            uint4_t reserved2;
+            uint64_t baudRate;
+
+            if (req.unpack(encodedBitRate, reserved2) != 0 ||
+                !req.fullyUnpacked())
+            {
+                return responseReqDataLenInvalid();
+            }
+
+            switch (static_cast<uint8_t>(encodedBitRate))
+            {
+                case 0x06:
+                    baudRate = 9600;
+                    break;
+                case 0x07:
+                    baudRate = 19200;
+                    break;
+                case 0x08:
+                    baudRate = 38400;
+                    break;
+                case 0x09:
+                    baudRate = 57600;
+                    break;
+                case 0x0a:
+                    baudRate = 115200;
+                    break;
+                default:
+                    return responseParmOutOfRange();
+            }
+
+            if (ipmi::setDbusProperty(
+                    ctx, "xyz.openbmc_project.Console.default",
+                    "/xyz/openbmc_project/console/default",
+                    "xyz.openbmc_project.Console.UART", "NonVbitrate", baudRate))
+            {
+                return responseUnspecifiedError();
+            }
+            break;
+        }
         case SolConfParam::Vbitrate:
+        {
+            uint4_t encodedBitRate;
+            uint4_t reserved2;
+            uint64_t baudRate;
+
+            if (req.unpack(encodedBitRate, reserved2) != 0 ||
+                !req.fullyUnpacked())
+            {
+                return responseReqDataLenInvalid();
+            }
+
+            switch (static_cast<uint8_t>(encodedBitRate))
+            {
+                case 0x06:
+                    baudRate = 9600;
+                    break;
+                case 0x07:
+                    baudRate = 19200;
+                    break;
+                case 0x08:
+                    baudRate = 38400;
+                    break;
+                case 0x09:
+                    baudRate = 57600;
+                    break;
+                case 0x0a:
+                    baudRate = 115200;
+                    break;
+                default:
+                    return responseParmOutOfRange();
+            }
+            if (ipmi::setDbusProperty(
+                    ctx, "xyz.openbmc_project.Console.default",
+                    "/xyz/openbmc_project/console/default",
+                    "xyz.openbmc_project.Console.UART", "Vbitrate", baudRate))
+            {
+                return responseUnspecifiedError();
+            }            
+            break;
+        }
         case SolConfParam::Channel:
         default:
             return response(ipmiCCParamNotSupported);
@@ -1895,10 +1976,10 @@ RspType<message::Payload> getSolConfParams(Context::ptr ctx,
             if (ipmi::getDbusProperty(
                     ctx, "xyz.openbmc_project.Console.default",
                     "/xyz/openbmc_project/console/default",
-                    "xyz.openbmc_project.Console.UART", "Baud", baudRate))
+                    "xyz.openbmc_project.Console.UART", "NonVbitrate", baudRate))
             {
                 return ipmi::responseUnspecifiedError();
-            }
+            }  
             switch (baudRate)
             {
                 case 9600:
@@ -1923,6 +2004,39 @@ RspType<message::Payload> getSolConfParams(Context::ptr ctx,
             return responseSuccess(std::move(ret));
         }
         case SolConfParam::Vbitrate:
+        {
+            uint64_t baudRate;
+            uint8_t encodedBitRate = 0;
+            if (ipmi::getDbusProperty(
+                    ctx, "xyz.openbmc_project.Console.default",
+                    "/xyz/openbmc_project/console/default",
+                    "xyz.openbmc_project.Console.UART", "Vbitrate", baudRate))
+            {
+                return ipmi::responseUnspecifiedError();
+            } 
+            switch (baudRate)
+            {
+                case 9600:
+                    encodedBitRate = 0x06;
+                    break;
+                case 19200:
+                    encodedBitRate = 0x07;
+                    break;
+                case 38400:
+                    encodedBitRate = 0x08;
+                    break;
+                case 57600:
+                    encodedBitRate = 0x09;
+                    break;
+                case 115200:
+                    encodedBitRate = 0x0a;
+                    break;
+                default:
+                    break;
+            }
+            ret.pack(encodedBitRate);
+            return responseSuccess(std::move(ret));
+        }
         default:
             return response(ipmiCCParamNotSupported);
     }
-- 
2.25.1

