usbstorage: error handling and better return codes
[svpe-wii.git] / usbstorage.h
blob94f74d0a1074f44979a4fa605a34ccc1a23c97ac
1 #ifndef __USBSTORAGE_H
2 #define __USBSTORAGE_H 1
4 #ifdef __cplusplus
5 extern "C" {
6 #endif /* __cplusplus */
8 #include <gctypes.h>
10 #define USBSTORAGE_OK 0
11 #define USBSTORAGE_ENOINTERFACE -10000
12 #define USBSTORAGE_ESENSE -10001
13 #define USBSTORAGE_ECAPACITY -10002
14 #define USBSTORAGE_ESHORTWRITE -10003
15 #define USBSTORAGE_ESHORTREAD -10004
16 #define USBSTORAGE_ESIGNATURE -10005
17 #define USBSTORAGE_ETAG -10006
18 #define USBSTORAGE_ESTATUS -10007
19 #define USBSTORAGE_EDATARESIDUE -10008
21 #pragma pack(1)
22 typedef struct _usbendpointdesc
24 u8 bLength;
25 u8 bDescriptorType;
26 u8 bEndpointAddress;
27 u8 bmAttributes;
28 u16 wMaxPacketSize;
29 u8 bInterval;
30 } usb_endpointdesc;
32 typedef struct _usbinterfacedesc
34 u8 bLength;
35 u8 bDescriptorType;
36 u8 bInterfaceNumber;
37 u8 bAlternateSetting;
38 u8 bNumEndpoints;
39 u8 bInterfaceClass;
40 u8 bInterfaceSubClass;
41 u8 bInterfaceProtocol;
42 u8 iInterface;
43 struct _usbendpointdesc *endpoints;
44 } usb_interfacedesc;
46 typedef struct _usbconfdesc
48 u8 bLength;
49 u8 bDescriptorType;
50 u16 wTotalLength;
51 u8 bNumInterfaces;
52 u8 bConfigurationValue;
53 u8 iConfiguration;
54 u8 bmAttributes;
55 u8 bMaxPower;
56 struct _usbinterfacedesc *interfaces;
57 } usb_configurationdesc;
59 typedef struct _usbdevdesc
61 u8 bLength;
62 u8 bDescriptorType;
63 u16 bcdUSB;
64 u8 bDeviceClass;
65 u8 bDeviceSubClass;
66 u8 bDeviceProtocol;
67 u8 bMaxPacketSize0;
68 u16 idVendor;
69 u16 idProduct;
70 u16 bcdDevice;
71 u8 iManufactor;
72 u8 iProduct;
73 u8 iSerialNumber;
74 u8 bNumConfigurations;
75 struct _usbconfdesc *configurations;
76 } _usb_devdesc;
77 #pragma pack()
79 typedef struct
81 u8 configuration;
82 u32 interface;
83 u32 altInterface;
85 u8 ep_in;
86 u8 ep_out;
88 u32 ep_in_size;
89 u32 ep_out_size;
91 u32 sector_size;
92 u32 n_sectors;
94 s32 usb_fd;
96 mutex_t lock;
98 u32 tag;
99 } usbstorage_handle;
101 s32 USB_GetDescriptors(s32 fd, _usb_devdesc *udd);
102 void USB_FreeDescriptors(_usb_devdesc *udd);
104 s32 USBStorage_Initialize();
105 s32 USBStorage_Deinitialize();
107 s32 USBStorage_Open(usbstorage_handle *dev, const char *bus, u16 vid, u16 pid);
108 s32 USBStorage_Close(usbstorage_handle *dev);
109 s32 USBStorage_Reset(usbstorage_handle *dev);
111 s32 USBStorage_ReadCapacity(usbstorage_handle *dev, u32 *sector_size, u32 *n_sectors);
113 s32 USBStorage_Read(usbstorage_handle *dev, u32 sector, u8 *buffer, u16 n_sectors);
114 s32 USBStorage_Write(usbstorage_handle *dev, u32 sector, const u8 *buffer, u16 n_sectors);
116 #ifdef __cplusplus
118 #endif /* __cplusplus */
120 #endif