mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-06 03:12:15 +02:00
usb: fixup comments, allow custom bInterfaceClass etc in usbComms
This commit is contained in:
parent
d6e270854d
commit
6fb6bdb6de
@ -8,10 +8,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../../types.h"
|
#include "../../types.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
u8 bInterfaceClass;
|
||||||
|
u8 bInterfaceSubClass;
|
||||||
|
u8 bInterfaceProtocol;
|
||||||
|
} UsbCommsInterfaceInfo;
|
||||||
|
|
||||||
/// Initializes usbComms with the default number of interfaces (1)
|
/// Initializes usbComms with the default number of interfaces (1)
|
||||||
Result usbCommsInitialize(void);
|
Result usbCommsInitialize(const UsbCommsInterfaceInfo *info);
|
||||||
|
|
||||||
/// Initializes usbComms with a specific number of interfaces.
|
/// Initializes usbComms with a specific number of interfaces.
|
||||||
Result usbCommsInitializeEx(u32 num_interfaces);
|
Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *infos);
|
||||||
|
|
||||||
/// Exits usbComms.
|
/// Exits usbComms.
|
||||||
void usbCommsExit(void);
|
void usbCommsExit(void);
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
/// Imported from libusb, with some adjustments.
|
/// Imported from libusb, with some adjustments.
|
||||||
struct usb_endpoint_descriptor {
|
struct usb_endpoint_descriptor {
|
||||||
uint8_t bLength;
|
uint8_t bLength;
|
||||||
uint8_t bDescriptorType; /// Must match USB_DT_ENDPOINT.
|
uint8_t bDescriptorType; ///< Must match USB_DT_ENDPOINT.
|
||||||
uint8_t bEndpointAddress; /// Should be one of the usb_endpoint_direction values, the endpoint-number is automatically allocated.
|
uint8_t bEndpointAddress; ///< Should be one of the usb_endpoint_direction values, the endpoint-number is automatically allocated.
|
||||||
uint8_t bmAttributes;
|
uint8_t bmAttributes;
|
||||||
uint16_t wMaxPacketSize;
|
uint16_t wMaxPacketSize;
|
||||||
uint8_t bInterval;
|
uint8_t bInterval;
|
||||||
@ -35,20 +35,20 @@ struct usb_endpoint_descriptor {
|
|||||||
/// Imported from libusb, with some adjustments.
|
/// Imported from libusb, with some adjustments.
|
||||||
struct usb_interface_descriptor {
|
struct usb_interface_descriptor {
|
||||||
uint8_t bLength;
|
uint8_t bLength;
|
||||||
uint8_t bDescriptorType; /// Must match USB_DT_INTERFACE.
|
uint8_t bDescriptorType; ///< Must match USB_DT_INTERFACE.
|
||||||
uint8_t bInterfaceNumber; /// See also USBDS_DEFAULT_InterfaceNumber.
|
uint8_t bInterfaceNumber; ///< See also USBDS_DEFAULT_InterfaceNumber.
|
||||||
uint8_t bAlternateSetting; /// Must match 0.
|
uint8_t bAlternateSetting; ///< Must match 0.
|
||||||
uint8_t bNumEndpoints;
|
uint8_t bNumEndpoints;
|
||||||
uint8_t bInterfaceClass;
|
uint8_t bInterfaceClass;
|
||||||
uint8_t bInterfaceSubClass;
|
uint8_t bInterfaceSubClass;
|
||||||
uint8_t bInterfaceProtocol;
|
uint8_t bInterfaceProtocol;
|
||||||
uint8_t iInterface; /// Ignored.
|
uint8_t iInterface; ///< Ignored.
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Imported from libusb, with some adjustments.
|
/// Imported from libusb, with some adjustments.
|
||||||
struct usb_device_descriptor {
|
struct usb_device_descriptor {
|
||||||
uint8_t bLength;
|
uint8_t bLength;
|
||||||
uint8_t bDescriptorType; /// Must match USB_DT_Device.
|
uint8_t bDescriptorType; ///< Must match USB_DT_Device.
|
||||||
uint16_t bcdUSB;
|
uint16_t bcdUSB;
|
||||||
uint8_t bDeviceClass;
|
uint8_t bDeviceClass;
|
||||||
uint8_t bDeviceSubClass;
|
uint8_t bDeviceSubClass;
|
||||||
@ -66,7 +66,7 @@ struct usb_device_descriptor {
|
|||||||
/// Imported from libusb, with some adjustments.
|
/// Imported from libusb, with some adjustments.
|
||||||
struct usb_ss_endpoint_companion_descriptor {
|
struct usb_ss_endpoint_companion_descriptor {
|
||||||
uint8_t bLength;
|
uint8_t bLength;
|
||||||
uint8_t bDescriptorType; /// Must match USB_DT_SS_ENDPOINT_COMPANION.
|
uint8_t bDescriptorType; ///< Must match USB_DT_SS_ENDPOINT_COMPANION.
|
||||||
uint8_t bMaxBurst;
|
uint8_t bMaxBurst;
|
||||||
uint8_t bmAttributes;
|
uint8_t bmAttributes;
|
||||||
uint16_t wBytesPerInterval;
|
uint16_t wBytesPerInterval;
|
||||||
@ -75,13 +75,13 @@ struct usb_ss_endpoint_companion_descriptor {
|
|||||||
/// Imported from libusb, with some adjustments.
|
/// Imported from libusb, with some adjustments.
|
||||||
struct usb_string_descriptor {
|
struct usb_string_descriptor {
|
||||||
uint8_t bLength;
|
uint8_t bLength;
|
||||||
uint8_t bDescriptorType; /// Must match USB_DT_STRING.
|
uint8_t bDescriptorType; ///< Must match USB_DT_STRING.
|
||||||
uint16_t wData[0x40];
|
uint16_t wData[0x40];
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u16 idVendor; /// VID
|
u16 idVendor; ///< VID
|
||||||
u16 idProduct; /// PID
|
u16 idProduct; ///< PID
|
||||||
u16 bcdDevice;
|
u16 bcdDevice;
|
||||||
char Manufacturer[0x20];
|
char Manufacturer[0x20];
|
||||||
char Product[0x20];
|
char Product[0x20];
|
||||||
@ -89,7 +89,7 @@ typedef struct {
|
|||||||
} UsbDsDeviceInfo;
|
} UsbDsDeviceInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u32 id; /// urbId from post-buffer cmds
|
u32 id; ///< urbId from post-buffer cmds
|
||||||
u32 requestedSize;
|
u32 requestedSize;
|
||||||
u32 transferredSize;
|
u32 transferredSize;
|
||||||
u32 urb_status;
|
u32 urb_status;
|
||||||
|
@ -26,13 +26,21 @@ static usbCommsInterface g_usbCommsInterfaces[TOTAL_INTERFACES];
|
|||||||
|
|
||||||
static RwLock g_usbCommsLock;
|
static RwLock g_usbCommsLock;
|
||||||
|
|
||||||
static Result _usbCommsInterfaceInit1x(u32 intf_ind);
|
static Result _usbCommsInterfaceInit1x(u32 intf_ind, const UsbCommsInterfaceInfo *info);
|
||||||
static Result _usbCommsInterfaceInit5x(u32 intf_ind);
|
static Result _usbCommsInterfaceInit5x(u32 intf_ind, const UsbCommsInterfaceInfo *info);
|
||||||
static Result _usbCommsInterfaceInit(u32 intf_ind);
|
static Result _usbCommsInterfaceInit(u32 intf_ind, const UsbCommsInterfaceInfo *info);
|
||||||
|
|
||||||
static Result _usbCommsWrite(usbCommsInterface *interface, const void* buffer, size_t size, size_t *transferredSize);
|
static Result _usbCommsWrite(usbCommsInterface *interface, const void* buffer, size_t size, size_t *transferredSize);
|
||||||
|
|
||||||
Result usbCommsInitializeEx(u32 num_interfaces)
|
static void _usbCommsUpdateInterfaceDescriptor(struct usb_interface_descriptor *desc, const UsbCommsInterfaceInfo *info) {
|
||||||
|
if (info != NULL) {
|
||||||
|
desc->bInterfaceClass = info->bInterfaceClass;
|
||||||
|
desc->bInterfaceSubClass = info->bInterfaceSubClass;
|
||||||
|
desc->bInterfaceProtocol = info->bInterfaceProtocol;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *infos)
|
||||||
{
|
{
|
||||||
Result rc = 0;
|
Result rc = 0;
|
||||||
rwlockWriteLock(&g_usbCommsLock);
|
rwlockWriteLock(&g_usbCommsLock);
|
||||||
@ -115,7 +123,7 @@ Result usbCommsInitializeEx(u32 num_interfaces)
|
|||||||
rwlockWriteLock(&intf->lock);
|
rwlockWriteLock(&intf->lock);
|
||||||
rwlockWriteLock(&intf->lock_in);
|
rwlockWriteLock(&intf->lock_in);
|
||||||
rwlockWriteLock(&intf->lock_out);
|
rwlockWriteLock(&intf->lock_out);
|
||||||
rc = _usbCommsInterfaceInit(i);
|
rc = _usbCommsInterfaceInit(i, infos + i);
|
||||||
rwlockWriteUnlock(&intf->lock_out);
|
rwlockWriteUnlock(&intf->lock_out);
|
||||||
rwlockWriteUnlock(&intf->lock_in);
|
rwlockWriteUnlock(&intf->lock_in);
|
||||||
rwlockWriteUnlock(&intf->lock);
|
rwlockWriteUnlock(&intf->lock);
|
||||||
@ -141,9 +149,9 @@ Result usbCommsInitializeEx(u32 num_interfaces)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result usbCommsInitialize(void)
|
Result usbCommsInitialize(const UsbCommsInterfaceInfo *info)
|
||||||
{
|
{
|
||||||
return usbCommsInitializeEx(1);
|
return usbCommsInitializeEx(1, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _usbCommsInterfaceFree(usbCommsInterface *interface)
|
static void _usbCommsInterfaceFree(usbCommsInterface *interface)
|
||||||
@ -192,16 +200,16 @@ void usbCommsExit(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result _usbCommsInterfaceInit(u32 intf_ind)
|
static Result _usbCommsInterfaceInit(u32 intf_ind, const UsbCommsInterfaceInfo *info)
|
||||||
{
|
{
|
||||||
if (kernelAbove500()) {
|
if (kernelAbove500()) {
|
||||||
return _usbCommsInterfaceInit5x(intf_ind);
|
return _usbCommsInterfaceInit5x(intf_ind, info);
|
||||||
} else {
|
} else {
|
||||||
return _usbCommsInterfaceInit1x(intf_ind);
|
return _usbCommsInterfaceInit1x(intf_ind, info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result _usbCommsInterfaceInit5x(u32 intf_ind)
|
static Result _usbCommsInterfaceInit5x(u32 intf_ind, const UsbCommsInterfaceInfo *info)
|
||||||
{
|
{
|
||||||
Result rc = 0;
|
Result rc = 0;
|
||||||
u32 ep_num = intf_ind + 1;
|
u32 ep_num = intf_ind + 1;
|
||||||
@ -212,10 +220,11 @@ static Result _usbCommsInterfaceInit5x(u32 intf_ind)
|
|||||||
.bDescriptorType = USB_DT_INTERFACE,
|
.bDescriptorType = USB_DT_INTERFACE,
|
||||||
.bInterfaceNumber = intf_ind,
|
.bInterfaceNumber = intf_ind,
|
||||||
.bNumEndpoints = 2,
|
.bNumEndpoints = 2,
|
||||||
.bInterfaceClass = 0xFF,
|
.bInterfaceClass = USB_CLASS_VENDOR_SPEC,
|
||||||
.bInterfaceSubClass = 0xFF,
|
.bInterfaceSubClass = USB_CLASS_VENDOR_SPEC,
|
||||||
.bInterfaceProtocol = 0xFF,
|
.bInterfaceProtocol = USB_CLASS_VENDOR_SPEC,
|
||||||
};
|
};
|
||||||
|
_usbCommsUpdateInterfaceDescriptor(&interface_descriptor, info);
|
||||||
|
|
||||||
struct usb_endpoint_descriptor endpoint_descriptor_in = {
|
struct usb_endpoint_descriptor endpoint_descriptor_in = {
|
||||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||||
@ -308,7 +317,7 @@ static Result _usbCommsInterfaceInit5x(u32 intf_ind)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Result _usbCommsInterfaceInit1x(u32 intf_ind)
|
static Result _usbCommsInterfaceInit1x(u32 intf_ind, const UsbCommsInterfaceInfo *info)
|
||||||
{
|
{
|
||||||
Result rc = 0;
|
Result rc = 0;
|
||||||
u32 ep_num = intf_ind + 1;
|
u32 ep_num = intf_ind + 1;
|
||||||
@ -318,10 +327,11 @@ static Result _usbCommsInterfaceInit1x(u32 intf_ind)
|
|||||||
.bLength = USB_DT_INTERFACE_SIZE,
|
.bLength = USB_DT_INTERFACE_SIZE,
|
||||||
.bDescriptorType = USB_DT_INTERFACE,
|
.bDescriptorType = USB_DT_INTERFACE,
|
||||||
.bInterfaceNumber = intf_ind,
|
.bInterfaceNumber = intf_ind,
|
||||||
.bInterfaceClass = 0xFF,
|
.bInterfaceClass = USB_CLASS_VENDOR_SPEC,
|
||||||
.bInterfaceSubClass = 0xFF,
|
.bInterfaceSubClass = USB_CLASS_VENDOR_SPEC,
|
||||||
.bInterfaceProtocol = 0xFF,
|
.bInterfaceProtocol = USB_CLASS_VENDOR_SPEC,
|
||||||
};
|
};
|
||||||
|
_usbCommsUpdateInterfaceDescriptor(&interface_descriptor, info);
|
||||||
|
|
||||||
struct usb_endpoint_descriptor endpoint_descriptor_in = {
|
struct usb_endpoint_descriptor endpoint_descriptor_in = {
|
||||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||||
|
Loading…
Reference in New Issue
Block a user