From b53c6c8844ec79f98bd293b8edd57e01f1017d88 Mon Sep 17 00:00:00 2001 From: Sven Peter Date: Fri, 2 May 2008 14:25:57 +0200 Subject: [PATCH] basic error handling added --- usbstorage.c | 51 +++++++++++++++++++++++++++++++++++++++++++++------ usbstorage.h | 1 + 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/usbstorage.c b/usbstorage.c index ae70f81..f24430c 100644 --- a/usbstorage.c +++ b/usbstorage.c @@ -40,21 +40,21 @@ distribution. #define CBW_OUT 0 #define CSW_SIZE 13 -#define CSW_SIGNATURE 0x53425355 +#define CSW_SIGNATURE 0x53425355 #define SCSI_TEST_UNIT_READY 0x00 #define SCSI_REQUEST_SENSE 0x03 #define SCSI_READ_CAPACITY 0x25 #define SCSI_READ_10 0x28 -#define SCSI_WRITE_10 0x2A +#define SCSI_WRITE_10 0x2A #define SCSI_SENSE_REPLY_SIZE 18 #define USB_CLASS_MASS_STORAGE 0x08 -#define MASS_STORAGE_SCSI_COMMANDS 0x06 -#define MASS_STORAGE_BULK_ONLY 0x50 +#define MASS_STORAGE_SCSI_COMMANDS 0x06 +#define MASS_STORAGE_BULK_ONLY 0x50 -#define USB_ENDPOINT_BULK 0x02 +#define USB_ENDPOINT_BULK 0x02 #ifdef DEBUG #include @@ -264,6 +264,11 @@ static s32 __send_cbw(usbstorage_handle *dev, u32 len, u8 flags, const u8 *cb, u free_and_return: if(cbw != NULL) iosFree(hId, cbw); + if(retval < 0) + { + USBStorage_Reset(dev); + LWP_MutexUnlock(dev->lock); + } return retval; } @@ -318,11 +323,13 @@ static s32 __read_csw(usbstorage_handle *dev, u8 *status, u32 *dataResidue) dev->tag++; - LWP_MutexUnlock(dev->lock); free_and_return: if(csw != NULL) iosFree(hId, csw); + if(retval < 0) + USBStorage_Reset(dev); + LWP_MutexUnlock(dev->lock); return retval; } @@ -538,6 +545,8 @@ usbstorage_handle *USBStorage_Open(const char *bus, u16 vid, u16 pid) found: USB_FreeDescriptors(&udd); + // TODO support for non-default configurations + /* some devices needs this (TEST_UNIT_READY -> REQUEST_SENSE * to be working... */ memset(cmd, 0, sizeof(cmd)); @@ -628,6 +637,36 @@ s32 USBStorage_Close(usbstorage_handle *dev) return 0; } +// FIXME: remove the (void *)32 stuff when libogc gets updated +s32 USBStorage_Reset(usbstorage_handle *dev) +{ + s32 retval; + LWP_MutexLock(dev->lock); +#if 0 + retval = USB_WriteCtrlMsg(dev->usb_fd, 33, 0xFF, dev->interface, 0, 0, NULL); +#else + retval = USB_WriteCtrlMsg(dev->usb_fd, 33, 0xFF, dev->interface, 0, 0, (void *)32); +#endif + if(retval < 0) + goto end; +#if 0 + retval = USB_WriteCtrlMsg(dev->usb_fd, 2, 0x1, 0, dev->ep_in, 0, NULL); +#else + retval = USB_WriteCtrlMsg(dev->usb_fd, 2, 0x1, 0, dev->ep_in, 0, (void *)32); +#endif + if(retval < 0) + goto end; +#if 0 + retval = USB_WriteCtrlMsg(dev->usb_fd, 2, 0x1, 0, dev->ep_out, 0, NULL); +#else + retval = USB_WriteCtrlMsg(dev->usb_fd, 2, 0x1, 0, dev->ep_out, 0, (void *)32); +#endif + + end: + LWP_MutexUnlock(dev->lock); + return retval; +} + s32 USBStorage_Read(usbstorage_handle *dev, u32 sector, u8 *buffer, u16 n_sectors) { u8 cmd[] = { diff --git a/usbstorage.h b/usbstorage.h index 27d3f6d..a598157 100644 --- a/usbstorage.h +++ b/usbstorage.h @@ -91,6 +91,7 @@ s32 USBStorage_Deinitialize(); usbstorage_handle *USBStorage_Open(const char *bus, u16 vid, u16 pid); s32 USBStorage_Close(usbstorage_handle *dev); +s32 USBStorage_Reset(usbstorage_handle *dev); s32 USBStorage_ReadCapacity(usbstorage_handle *dev, u32 *sector_size, u32 *n_sectors); -- 2.11.4.GIT