Add Lan channel check for Set/Get Lan Commands

The `ipmitool lan6 print <invalid_lan_channel> command has a lot of
error messages, we should check thar the channel we are using is a
vaild lan channel. if not, return `invalid filed`.

BTW, the `ipmitool lan print <invalid_lan_channel>` without the error,
because the `lan print` using the `getChannelInfo` command first,
and checked it in the `ipmitool`, `lan6 print` doesn't.

Anyway, we should check it in BMC side.

Change-Id: I229f8b607a4f9a8038dc4892ae982d29a6bedb19
Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com>
diff --git a/transporthandler.cpp b/transporthandler.cpp
index da4231a..dd2ac14 100644
--- a/transporthandler.cpp
+++ b/transporthandler.cpp
@@ -843,6 +843,28 @@
     return true;
 }
 
+/**
+ * @brief is a valid LAN channel.
+ *
+ * This function checks whether the input channel is a valid LAN channel or not.
+ *
+ * @param[in] channel: the channel number.
+ * @return nullopt if the channel is invalid, false if the channel is not a LAN
+ * channel, true if the channel is a LAN channel.
+ **/
+std::optional<bool> isLanChannel(uint8_t channel)
+{
+    ChannelInfo chInfo;
+    auto cc = getChannelInfo(channel, chInfo);
+    if (cc != ccSuccess)
+    {
+        return std::nullopt;
+    }
+
+    return chInfo.mediumType ==
+           static_cast<uint8_t>(EChannelMediumType::lan8032);
+}
+
 RspType<> setLan(Context::ptr ctx, uint4_t channelBits, uint4_t reserved1,
                  uint8_t parameter, message::Payload& req)
 {
@@ -855,6 +877,12 @@
         return responseInvalidFieldRequest();
     }
 
+    if (!isLanChannel(channel).value_or(false))
+    {
+        log<level::ERR>("Set Lan - Not a LAN channel");
+        return responseInvalidFieldRequest();
+    }
+
     switch (static_cast<LanParam>(parameter))
     {
         case LanParam::SetStatus:
@@ -1278,6 +1306,12 @@
         return responseInvalidFieldRequest();
     }
 
+    if (!isLanChannel(channel).value_or(false))
+    {
+        log<level::ERR>("Set Lan - Not a LAN channel");
+        return responseInvalidFieldRequest();
+    }
+
     static std::vector<uint8_t> cipherList;
     static bool listInit = false;
     if (!listInit)