diff --git a/gc/ogc/usb.h b/gc/ogc/usb.h index 264dff45e..022dfe0b6 100644 --- a/gc/ogc/usb.h +++ b/gc/ogc/usb.h @@ -12,7 +12,9 @@ #define USB_FAILED 1 #define USB_CLASS_HID 0x03 +#define USB_SUBCLASS_NONE 0x00 #define USB_SUBCLASS_BOOT 0x01 +#define USB_PROTOCOL_NONE 0x00 #define USB_PROTOCOL_KEYBOARD 0x01 #define USB_PROTOCOL_MOUSE 0x02 @@ -66,6 +68,7 @@ #define USB_DT_ENDPOINT_SIZE 7 #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ #define USB_DT_HID_SIZE 9 +#define USB_DT_MINREPORT_SIZE 8 #define USB_DT_HUB_NONVAR_SIZE 7 /* control message request type bitmask */ @@ -190,6 +193,8 @@ void USB_FreeDescriptors(usb_devdesc *udd); s32 USB_GetGenericDescriptor(s32 fd,u8 type,u8 index,u8 interface,void *data,u32 size); s32 USB_GetHIDDescriptor(s32 fd,u8 interface,usb_hiddesc *uhd,u32 size); +s32 USB_GetReportDescriptorSize(s32 fd, u8 interface); +s32 USB_GetReportDescriptor(s32 fd, u8 interface, void* data, u16 size); s32 USB_GetDeviceDescription(s32 fd,usb_devdesc *devdesc); s32 USB_DeviceRemovalNotifyAsync(s32 fd,usbcallback cb,void *userdata); diff --git a/libogc/usb.c b/libogc/usb.c index f8d5eb03f..c3df42f9e 100644 --- a/libogc/usb.c +++ b/libogc/usb.c @@ -1085,6 +1085,41 @@ s32 USB_GetHIDDescriptor(s32 fd,u8 interface,usb_hiddesc *uhd,u32 size) return retval; } +s32 USB_GetReportDescriptorSize(s32 fd, u8 interface) +{ + //Retrieve complete HID descriptor + //in testing it was always 9 bytes, but in the HID specifications it says it can be more (if the device has more than 1 descriptor). + //currently we only support 1 thou + usb_hiddesc hiddesc; + s32 retval = USB_GetHIDDescriptor(fd, interface, &hiddesc, USB_DT_HID_SIZE); + + if(retval < 0) + return retval; + + if(hiddesc.bLength > USB_DT_HID_SIZE) + return -1; + + retval = -2; + for(int i = 0; i < hiddesc.bNumDescriptors; i++) + { + if(hiddesc.descr[i].bDescriptorType == USB_DT_REPORT) + { + retval = hiddesc.descr[i].wDescriptorLength; + break; + } + } + + return retval; +} + +s32 USB_GetReportDescriptor(s32 fd, u8 interface, void* data, u16 size) +{ + if (data == NULL || size < USB_DT_MINREPORT_SIZE) + return IPC_EINVAL; + + return USB_GetGenericDescriptor(fd, USB_DT_REPORT, 0, interface, data, size); +} + void USB_FreeDescriptors(usb_devdesc *udd) { int iConf, iInterface;