/* * Copyright (c) 2007, Benedikt Sauter * All rights reserved. * * Short descripton of file: * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the FH Augsburg nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __STORAGE_H #define __STORAGE_H void usb_storage_probe(); void usb_storage_check(); /* CSW Status Definitions */ #define CSW_CMD_PASSED 0x00 #define CSW_CMD_FAILED 0x01 #define CSW_PHASE_ERROR 0x02 /* SCSI Commands */ #define SCSI_TEST_UNIT_READY 0x00 #define SCSI_REQUEST_SENSE 0x03 #define SCSI_FORMAT_UNIT 0x04 #define SCSI_INQUIRY 0x12 #define SCSI_MODE_SELECT6 0x15 #define SCSI_MODE_SENSE6 0x1A #define SCSI_START_STOP_UNIT 0x1B #define SCSI_MEDIA_REMOVAL 0x1E #define SCSI_READ_FORMAT_CAPACITIES 0x23 #define SCSI_READ_CAPACITY 0x25 #define SCSI_READ10 0x28 #define SCSI_WRITE10 0x2A #define SCSI_VERIFY10 0x2F #define SCSI_MODE_SELECT10 0x55 #define SCSI_MODE_SENSE10 0x5A typedef struct usb_storage_cbw_t usb_storage_cbw; struct usb_storage_cbw_t { u32 dCBWSignature; u32 dCBWTag; u32 dCBWDataTransferLength; u8 bCWDFlags; u8 bCBWLun; u8 bCBWCBLength; u8 CBWCB[16]; }; typedef struct usb_storage_csw_t usb_storage_csw; struct usb_storage_csw_t { u32 dCSWSignature; u32 dCSWTag; u32 dCSWDataResidue; u8 bCSWStatus; }; void usb_storage_init(); u8 usb_storage_open(u8 device); u8 usb_storage_read_capacity(u8 device); u8 usb_storage_inquiry(u8 device); u8 usb_storage_read_sector(u8 device, u32 sector, char * buf); u8 usb_storage_write_sector(u8 device, u32 sector, char * buf); #define USBSTORAGE_OK 0 #define USBSTORAGE_ENOINTERFACE -10000 #define USBSTORAGE_ESENSE -10001 #define USBSTORAGE_ESHORTWRITE -10002 #define USBSTORAGE_ESHORTREAD -10003 #define USBSTORAGE_ESIGNATURE -10004 #define USBSTORAGE_ETAG -10005 #define USBSTORAGE_ESTATUS -10006 #define USBSTORAGE_EDATARESIDUE -10007 #define USBSTORAGE_ETIMEDOUT -10008 #define USBSTORAGE_EINIT -10009 #define USBSTORAGE_PROCESSING -10010 typedef struct { u8 configuration; u32 interface; u32 altInterface; u8 ep_in; u8 ep_out; u8 max_lun; u32 *sector_size; s32 usb_fd; s32 retval; u32 tag; u8 suspended; u8 *buffer; } usbstorage_handle; s32 USBStorage_Initialize(); s32 USBStorage_Open(usbstorage_handle *dev, const char *bus, u16 vid, u16 pid); s32 USBStorage_Close(usbstorage_handle *dev); s32 USBStorage_Reset(usbstorage_handle *dev); s32 USBStorage_GetMaxLUN(usbstorage_handle *dev); s32 USBStorage_MountLUN(usbstorage_handle *dev, u8 lun); s32 USBStorage_Suspend(usbstorage_handle *dev); s32 USBStorage_ReadCapacity(usbstorage_handle *dev, u8 lun, u32 *sector_size, u32 *n_sectors); s32 USBStorage_Read(usbstorage_handle *dev, u8 lun, u32 sector, u16 n_sectors, u8 *buffer); s32 USBStorage_Write(usbstorage_handle *dev, u8 lun, u32 sector, u16 n_sectors, const u8 *buffer); #if 0 #define DEVICE_TYPE_WII_USB (('W'<<24)|('U'<<16)|('S'<<8)|'B') extern const DISC_INTERFACE __io_usbstorage; #endif #define __stwbrx(base,index,value) \ __asm__ volatile ("stwbrx %0,%1,%2" : : "r"(value), "b%"(index), "r"(base) : "memory") #define __lwbrx(base,index) \ ({ register u32 res; \ __asm__ volatile ("lwbrx %0,%1,%2" : "=r"(res) : "b%"(index), "r"(base) : "memory"); \ res; }) #endif /* __STORAGE_H */