summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Maslenkin <mike.maslenkin@gmail.com>2023-08-26 04:58:00 +0300
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-10-16 22:49:33 +0000
commit03d6569f70939d2a1653265367121212459a6b89 (patch)
tree0682dbca0eee4d2b7c5f515a3d6e62c5fc5f7f4b
parente07948255cfafb75fa9cbe4555bfe3421488dd9a (diff)
downloadedk2-03d6569f70939d2a1653265367121212459a6b89.tar.gz
edk2-03d6569f70939d2a1653265367121212459a6b89.tar.bz2
edk2-03d6569f70939d2a1653265367121212459a6b89.zip
MdeModulePkg: UsbRndis: get rid of magic values
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>
-rw-r--r--MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndis.c42
-rw-r--r--MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h4
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 056b0ff0fd..cc8e076c0a 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 7b9896ab3c..250de0b591 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