public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Mike Maslenkin" <mike.maslenkin@gmail.com>
To: devel@edk2.groups.io
Cc: richardho@ami.com, rebecca@bsdio.com,
	Mike Maslenkin <mike.maslenkin@gmail.com>
Subject: [edk2-devel] [PATCH 2/2] MdeModulePkg: UsbRndis: get rid of magic values
Date: Sat, 26 Aug 2023 04:58:00 +0300	[thread overview]
Message-ID: <20230826015800.74524-3-mike.maslenkin@gmail.com> (raw)
In-Reply-To: <20230826015800.74524-1-mike.maslenkin@gmail.com>

Replace magic values used for checking Base Class, SubClass and Protocol
fields of USB Interface Descriptor.
Add definitions for Base Class EFh (Miscellaneous) and RNDIS subclass.
These definitions were taken from https://www.usb.org/defined-class-codes

Cc: Richard Ho <richardho@ami.com>
Cc: Rebecca Cran <rebecca@bsdio.com>
Signed-off-by: Mike Maslenkin <mike.maslenkin@gmail.com>
---
 .../Bus/Usb/UsbNetwork/UsbRndis/UsbRndis.c    | 42 +++++++++----------
 .../Include/Protocol/UsbEthernetProtocol.h    |  4 ++
 2 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndis.c b/MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndis.c
index 056b0ff0fd8e..cc8e076c0a12 100644
--- a/MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndis.c
+++ b/MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndis.c
@@ -40,15 +40,15 @@ IsSupportedDevice (
   }
 
   // Check specific device/RNDIS and CDC-DATA
-  if (((InterfaceDescriptor.InterfaceClass == 0x2) &&
-       (InterfaceDescriptor.InterfaceSubClass == 0x2) &&
-       (InterfaceDescriptor.InterfaceProtocol == 0xFF)) || \
-      ((InterfaceDescriptor.InterfaceClass == 0xEF) &&
-       (InterfaceDescriptor.InterfaceSubClass == 0x4) &&
-       (InterfaceDescriptor.InterfaceProtocol == 0x1)) || \
-      ((InterfaceDescriptor.InterfaceClass == 0xA) &&
-       (InterfaceDescriptor.InterfaceSubClass == 0x0) &&
-       (InterfaceDescriptor.InterfaceProtocol == 0x00))
+  if (((InterfaceDescriptor.InterfaceClass == USB_CDC_CLASS) &&
+       (InterfaceDescriptor.InterfaceSubClass == USB_CDC_ACM_SUBCLASS) &&
+       (InterfaceDescriptor.InterfaceProtocol == USB_VENDOR_PROTOCOL)) || \
+      ((InterfaceDescriptor.InterfaceClass == USB_MISC_CLASS) &&
+       (InterfaceDescriptor.InterfaceSubClass == USB_RNDIS_SUBCLASS) &&
+       (InterfaceDescriptor.InterfaceProtocol == USB_RNDIS_ETHERNET_PROTOCOL)) || \
+      ((InterfaceDescriptor.InterfaceClass == USB_CDC_DATA_CLASS) &&
+       (InterfaceDescriptor.InterfaceSubClass == USB_CDC_DATA_SUBCLASS) &&
+       (InterfaceDescriptor.InterfaceProtocol == USB_NO_CLASS_PROTOCOL))
       )
   {
     return TRUE;
@@ -79,12 +79,12 @@ IsRndisInterface (
   }
 
   // Check for specific device/RNDIS and CDC-DATA
-  if (((InterfaceDescriptor.InterfaceClass == 0x2) &&
-       (InterfaceDescriptor.InterfaceSubClass == 0x2) &&
-       (InterfaceDescriptor.InterfaceProtocol == 0xFF)) || \
-      ((InterfaceDescriptor.InterfaceClass == 0xEF) &&
-       (InterfaceDescriptor.InterfaceSubClass == 0x4) &&
-       (InterfaceDescriptor.InterfaceProtocol == 0x1))
+  if (((InterfaceDescriptor.InterfaceClass == USB_CDC_CLASS) &&
+       (InterfaceDescriptor.InterfaceSubClass == USB_CDC_ACM_SUBCLASS) &&
+       (InterfaceDescriptor.InterfaceProtocol == USB_VENDOR_PROTOCOL)) || \
+      ((InterfaceDescriptor.InterfaceClass == USB_MISC_CLASS) &&
+       (InterfaceDescriptor.InterfaceSubClass == USB_RNDIS_SUBCLASS) &&
+       (InterfaceDescriptor.InterfaceProtocol == USB_RNDIS_ETHERNET_PROTOCOL))
       )
   {
     return TRUE;
@@ -155,9 +155,9 @@ IsUsbCdcData (
   }
 
   // Check for CDC-DATA
-  if ((InterfaceDescriptor.InterfaceClass == 0xA) &&
-      (InterfaceDescriptor.InterfaceSubClass == 0x0) &&
-      (InterfaceDescriptor.InterfaceProtocol == 0x0))
+  if ((InterfaceDescriptor.InterfaceClass == USB_CDC_DATA_CLASS) &&
+      (InterfaceDescriptor.InterfaceSubClass == USB_CDC_DATA_SUBCLASS) &&
+      (InterfaceDescriptor.InterfaceProtocol == USB_NO_CLASS_PROTOCOL))
   {
     return TRUE;
   }
@@ -188,9 +188,9 @@ IsUsbRndis (
   }
 
   // Check for Rndis
-  if ((InterfaceDescriptor.InterfaceClass == 0x2) &&
-      (InterfaceDescriptor.InterfaceSubClass == 0x2) &&
-      (InterfaceDescriptor.InterfaceProtocol == 0xFF))
+  if ((InterfaceDescriptor.InterfaceClass == USB_CDC_CLASS) &&
+      (InterfaceDescriptor.InterfaceSubClass == USB_CDC_ACM_SUBCLASS) &&
+      (InterfaceDescriptor.InterfaceProtocol == USB_VENDOR_PROTOCOL))
   {
     return TRUE;
   }
diff --git a/MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h b/MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h
index 4cc2cee1167d..f65674c91ba9 100644
--- a/MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h
+++ b/MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h
@@ -24,6 +24,10 @@ typedef struct _EDKII_USB_ETHERNET_PROTOCOL EDKII_USB_ETHERNET_PROTOCOL;
 #define USB_NCM_NTB_PROTOCOL   0x01
 #define USB_VENDOR_PROTOCOL    0xFF
 
+#define USB_MISC_CLASS               0xEF
+#define USB_RNDIS_SUBCLASS           0x04
+#define USB_RNDIS_ETHERNET_PROTOCOL  0x01
+
 // Type Values for the DescriptorType Field
 #define CS_INTERFACE  0x24
 #define CS_ENDPOINT   0x25
-- 
2.32.0 (Apple Git-132)



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108041): https://edk2.groups.io/g/devel/message/108041
Mute This Topic: https://groups.io/mt/100968488/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2023-08-26  1:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-26  1:57 [edk2-devel] [PATCH 0/2] MdeModulePkg: small improvements to UsbNetwork Mike Maslenkin
2023-08-26  1:57 ` [edk2-devel] [PATCH 1/2] MdeModulePkg: UsbNetwork: fix Ethernet functional descriptor processing Mike Maslenkin
2023-08-26  1:58 ` Mike Maslenkin [this message]
2023-08-30  2:05 ` [edk2-devel] [PATCH 0/2] MdeModulePkg: small improvements to UsbNetwork RichardHo [何明忠] via groups.io
2023-08-31 12:32   ` Rebecca Cran
2023-10-08 10:20     ` Mike Maslenkin
2023-10-16 21:34       ` Rebecca Cran
2023-10-16 22:52 ` Rebecca Cran

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230826015800.74524-3-mike.maslenkin@gmail.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox