usb: common: debug: Check non-standard control requests
Previously usb_decode_ctrl() only decodes standard control requests, but it was used for non-standard requests also. If it's non-standard or unknown standard bRequest, print the Setup data values. Fixes: af32423a2d86 ("usb: dwc3: trace: decode ctrl request") Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com> Link: https://lore.kernel.org/r/8d6a30f2f2f953eff833a5bc5aac640a4cc2fc9f.1658971571.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
808e8bff6f
commit
b6155eaf6b
@ -208,30 +208,28 @@ static void usb_decode_set_isoch_delay(__u8 wValue, char *str, size_t size)
|
|||||||
snprintf(str, size, "Set Isochronous Delay(Delay = %d ns)", wValue);
|
snprintf(str, size, "Set Isochronous Delay(Delay = %d ns)", wValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static void usb_decode_ctrl_generic(char *str, size_t size, __u8 bRequestType,
|
||||||
* usb_decode_ctrl - Returns human readable representation of control request.
|
__u8 bRequest, __u16 wValue, __u16 wIndex,
|
||||||
* @str: buffer to return a human-readable representation of control request.
|
__u16 wLength)
|
||||||
* This buffer should have about 200 bytes.
|
{
|
||||||
* @size: size of str buffer.
|
u8 recip = bRequestType & USB_RECIP_MASK;
|
||||||
* @bRequestType: matches the USB bmRequestType field
|
u8 type = bRequestType & USB_TYPE_MASK;
|
||||||
* @bRequest: matches the USB bRequest field
|
|
||||||
* @wValue: matches the USB wValue field (CPU byte order)
|
snprintf(str, size,
|
||||||
* @wIndex: matches the USB wIndex field (CPU byte order)
|
"Type=%s Recipient=%s Dir=%s bRequest=%u wValue=%u wIndex=%u wLength=%u",
|
||||||
* @wLength: matches the USB wLength field (CPU byte order)
|
(type == USB_TYPE_STANDARD) ? "Standard" :
|
||||||
*
|
(type == USB_TYPE_VENDOR) ? "Vendor" :
|
||||||
* Function returns decoded, formatted and human-readable description of
|
(type == USB_TYPE_CLASS) ? "Class" : "Unknown",
|
||||||
* control request packet.
|
(recip == USB_RECIP_DEVICE) ? "Device" :
|
||||||
*
|
(recip == USB_RECIP_INTERFACE) ? "Interface" :
|
||||||
* The usage scenario for this is for tracepoints, so function as a return
|
(recip == USB_RECIP_ENDPOINT) ? "Endpoint" : "Unknown",
|
||||||
* use the same value as in parameters. This approach allows to use this
|
(bRequestType & USB_DIR_IN) ? "IN" : "OUT",
|
||||||
* function in TP_printk
|
bRequest, wValue, wIndex, wLength);
|
||||||
*
|
}
|
||||||
* Important: wValue, wIndex, wLength parameters before invoking this function
|
|
||||||
* should be processed by le16_to_cpu macro.
|
static void usb_decode_ctrl_standard(char *str, size_t size, __u8 bRequestType,
|
||||||
*/
|
__u8 bRequest, __u16 wValue, __u16 wIndex,
|
||||||
const char *usb_decode_ctrl(char *str, size_t size, __u8 bRequestType,
|
__u16 wLength)
|
||||||
__u8 bRequest, __u16 wValue, __u16 wIndex,
|
|
||||||
__u16 wLength)
|
|
||||||
{
|
{
|
||||||
switch (bRequest) {
|
switch (bRequest) {
|
||||||
case USB_REQ_GET_STATUS:
|
case USB_REQ_GET_STATUS:
|
||||||
@ -272,14 +270,48 @@ const char *usb_decode_ctrl(char *str, size_t size, __u8 bRequestType,
|
|||||||
usb_decode_set_isoch_delay(wValue, str, size);
|
usb_decode_set_isoch_delay(wValue, str, size);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
snprintf(str, size, "%02x %02x %02x %02x %02x %02x %02x %02x",
|
usb_decode_ctrl_generic(str, size, bRequestType, bRequest,
|
||||||
bRequestType, bRequest,
|
wValue, wIndex, wLength);
|
||||||
(u8)(cpu_to_le16(wValue) & 0xff),
|
break;
|
||||||
(u8)(cpu_to_le16(wValue) >> 8),
|
}
|
||||||
(u8)(cpu_to_le16(wIndex) & 0xff),
|
}
|
||||||
(u8)(cpu_to_le16(wIndex) >> 8),
|
|
||||||
(u8)(cpu_to_le16(wLength) & 0xff),
|
/**
|
||||||
(u8)(cpu_to_le16(wLength) >> 8));
|
* usb_decode_ctrl - Returns human readable representation of control request.
|
||||||
|
* @str: buffer to return a human-readable representation of control request.
|
||||||
|
* This buffer should have about 200 bytes.
|
||||||
|
* @size: size of str buffer.
|
||||||
|
* @bRequestType: matches the USB bmRequestType field
|
||||||
|
* @bRequest: matches the USB bRequest field
|
||||||
|
* @wValue: matches the USB wValue field (CPU byte order)
|
||||||
|
* @wIndex: matches the USB wIndex field (CPU byte order)
|
||||||
|
* @wLength: matches the USB wLength field (CPU byte order)
|
||||||
|
*
|
||||||
|
* Function returns decoded, formatted and human-readable description of
|
||||||
|
* control request packet.
|
||||||
|
*
|
||||||
|
* The usage scenario for this is for tracepoints, so function as a return
|
||||||
|
* use the same value as in parameters. This approach allows to use this
|
||||||
|
* function in TP_printk
|
||||||
|
*
|
||||||
|
* Important: wValue, wIndex, wLength parameters before invoking this function
|
||||||
|
* should be processed by le16_to_cpu macro.
|
||||||
|
*/
|
||||||
|
const char *usb_decode_ctrl(char *str, size_t size, __u8 bRequestType,
|
||||||
|
__u8 bRequest, __u16 wValue, __u16 wIndex,
|
||||||
|
__u16 wLength)
|
||||||
|
{
|
||||||
|
switch (bRequestType & USB_TYPE_MASK) {
|
||||||
|
case USB_TYPE_STANDARD:
|
||||||
|
usb_decode_ctrl_standard(str, size, bRequestType, bRequest,
|
||||||
|
wValue, wIndex, wLength);
|
||||||
|
break;
|
||||||
|
case USB_TYPE_VENDOR:
|
||||||
|
case USB_TYPE_CLASS:
|
||||||
|
default:
|
||||||
|
usb_decode_ctrl_generic(str, size, bRequestType, bRequest,
|
||||||
|
wValue, wIndex, wLength);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user