1 typedef struct Device Device; 2 typedef struct Dconf Dconf; 3 typedef struct Ddesc Ddesc; 4 typedef struct Dinf Dinf; 5 typedef struct Dalt Dalt; 6 typedef struct Endpt Endpt; 7 8 struct Device 9 { 10 Ref; 11 int ctlrno; 12 int id; 13 int state; 14 int ctl; 15 int setup; 16 int status; 17 int ls; /* low speed */ 18 19 int vers; /* USB version supported, in BCD */ 20 ulong csp; /* USB class/subclass/proto */ 21 int max0; /* max packet size for endpoint 0 */ 22 int vid; /* vendor id */ 23 int did; /* product (device) id */ 24 int release; /* device release number, in BCD */ 25 int manufacturer; /* string index */ 26 int product; /* string index */ 27 int serial; /* string index */ 28 int nconf; 29 Dconf* config; 30 char *strings[256]; 31 }; 32 33 struct Ddesc 34 { 35 int ndesc; /* number of descriptors */ 36 int bytes; /* total size of descriptors */ 37 uchar *data; /* descriptor data */ 38 }; 39 40 struct Dconf 41 { 42 Device *d; /* owning device */ 43 int x; /* index into Device.config array */ 44 int nif; /* number of interfaces */ 45 int cval; /* value for set configuration request */ 46 int config; /* string index */ 47 int attrib; 48 int milliamps; /* maximum power in this configuration */ 49 Ddesc desc; /* additional descriptors for this configuration */ 50 Dinf* iface; 51 }; 52 53 struct Dinf 54 { 55 Device *d; /* owning device */ 56 Dconf *conf; /* owning configuration */ 57 int x; /* index into Dconf.iface array */ 58 ulong csp; /* USB class/subclass/proto */ 59 int interface; /* string index */ 60 Dalt *alt; /* linked list of alternatives */ 61 Dinf *next; /* caller-maintained list of interfaces */ 62 }; 63 64 struct Dalt 65 { 66 Dinf *intf; /* owning interface */ 67 int alt; /* alternate number, used to select this alternate */ 68 int npt; /* number of endpoints */ 69 Endpt* ep; /* endpoints for this interface alternate */ 70 Ddesc desc; /* additional descriptors for this alternate */ 71 Dalt* next; /* next in linked list of alternatives */ 72 }; 73 74 struct Endpt 75 { 76 uchar addr; /* endpoint address, 0-15 */ 77 uchar dir; /* direction, Ein/Eout */ 78 uchar type; /* Econtrol, Eiso, Ebulk, Eintr */ 79 uchar isotype; /* Eunknown, Easync, Eadapt, Esync */ 80 int maxpkt; /* maximum packet size for endpoint */ 81 int pollms; /* polling interval for interrupts */ 82 Ddesc desc; /* additional descriptors for this endpoint */ 83 }; 84 85 enum 86 { 87 /* Device.state */ 88 Detached = 0, 89 Attached, 90 Enabled, 91 Assigned, 92 Configured, 93 94 /* Dconf.attrib */ 95 Cbuspowered = 1<<7, 96 Cselfpowered = 1<<6, 97 Cremotewakeup = 1<<5, 98 99 /* Endpt.dir */ 100 Ein = 0, 101 Eout, 102 103 /* Endpt.type */ 104 Econtrol = 0, 105 Eiso, 106 Ebulk, 107 Eintr, 108 109 /* Endpt.isotype */ 110 Eunknown = 0, 111 Easync, 112 Eadapt, 113 Esync, 114 }; 115 116 #define Class(csp) ((csp)&0xff) 117 #define Subclass(csp) (((csp)>>8)&0xff) 118 #define Proto(csp) (((csp)>>16)&0xff) 119 #define CSP(c, s, p) ((c) | ((s)<<8) | ((p)<<16)) 120 121 enum 122 { 123 /* known classes */ 124 CL_AUDIO = 1, 125 CL_COMMS = 2, 126 CL_HID = 3, 127 CL_PHYSICAL = 5, 128 CL_IMAGE = 6, 129 CL_PRINTER = 7, 130 CL_STORAGE = 8, 131 CL_HUB = 9, 132 CL_DATA = 10, 133 CL_CHIP = 11, 134 CL_SECURITY = 13, 135 }; 136 137 /* 138 * interface 139 */ 140 void usbfmtinit(void); 141 Device* opendev(int, int); 142 void closedev(Device*); 143 int describedevice(Device*); 144 void dumpdevice(int, Device*); 145 void loadstr(Device*, int, int); 146 void loadstrings(Device*, int); 147 148 int setupreq(Device*, int, int, int, int, uchar*, int); 149 150 void * emalloc(ulong); 151 void * emallocz(ulong, int); 152 153 #pragma varargck type "D" Device* 154