Skip to content

Commit

Permalink
MdeModulePkg: UsbRndis: get rid of magic values
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Rebecca Cran <[email protected]>
Signed-off-by: Mike Maslenkin <[email protected]>
  • Loading branch information
ghbaccount authored and mergify[bot] committed Oct 16, 2023
1 parent e079482 commit 03d6569
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
42 changes: 21 additions & 21 deletions MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 03d6569

Please sign in to comment.