1 typedef struct Altc Altc;
2 typedef struct Conf Conf;
3 typedef struct DConf DConf;
4 typedef struct DDesc DDesc;
5 typedef struct DDev DDev;
6 typedef struct DEp DEp;
7 typedef struct DIface DIface;
8 typedef struct Desc Desc;
9 typedef struct Dev Dev;
11 typedef struct Iface Iface;
12 typedef struct Usbdev Usbdev;
15 /* fundamental constants */
16 Nep = 256, /* max. endpoints per usb device & per interface */
18 /* tunable parameters */
19 Nconf = 16, /* max. configurations per usb device */
20 Nddesc = 8*Nep, /* max. device-specific descriptors per usb device */
21 Niface = 16, /* max. interfaces per configuration */
22 Naltc = 256, /* max. alt configurations per interface */
23 Uctries = 4, /* no. of tries for usbcmd */
24 Ucdelay = 50, /* delay before retrying */
27 Rh2d = 0<<7, /* host to device */
28 Rd2h = 1<<7, /* device to host */
30 Rstd = 0<<5, /* types */
34 Rdev = 0, /* recipients */
36 Rep = 2, /* endpoint */
39 /* standard requests (USB2.0) */
52 /* standard requests (USB3.0) */
66 Clnone = 0, /* not in usb */
75 /* standard descriptor sizes */
81 /* descriptor types */
91 /* feature selectors */
102 /* endpoint direction */
113 /* endpoint isotype */
122 Cremotewakeup = 1<<5,
163 * Usb device (when used for ep0s) or endpoint.
164 * RC: One ref because of existing, another one per ogoing I/O.
165 * per-driver resources (including FS if any) are released by aux
166 * once the last ref is gone. This may include other Devs using
167 * to access endpoints for actual I/O.
172 char* dir; /* path for the endpoint dir */
173 int id; /* usb id for device or ep. number */
174 int dfd; /* descriptor for the data file */
175 int cfd; /* descriptor for the control file */
176 int isusb3; /* this is a usb3 device */
177 int depth; /* hub depth for usb3 hubs */
178 int maxpkt; /* cached from usb description */
179 Usbdev* usb; /* USB description */
180 void* aux; /* for the device driver */
181 char* hname; /* hash name, unique for device */
185 * device description as reported by USB (unpacked).
189 int ver; /* usb version */
190 ulong csp; /* USB class/subclass/proto */
191 int vid; /* vendor id */
192 int did; /* product (device) id */
193 int dno; /* device release number */
200 int class; /* from descriptor */
201 int nconf; /* from descriptor */
202 Conf* conf[Nconf]; /* configurations */
203 Ep* ep[Nep]; /* all endpoints in device */
204 Desc* ddesc[Nddesc]; /* (raw) device specific descriptors */
209 uchar addr; /* endpt address, 0-15 (|0x80 if Ein) */
210 uchar dir; /* direction, Ein/Eout */
211 uchar type; /* Econtrol, Eiso, Ebulk, Eintr */
212 uchar isotype; /* Eunknown, Easync, Eadapt, Esync */
214 int maxpkt; /* max. packet size */
215 int ntds; /* nb. of Tds per µframe */
216 Conf* conf; /* the endpoint belongs to */
217 Iface* iface; /* the endpoint belongs to */
226 void* aux; /* for the driver program */
231 int id; /* interface number */
232 ulong csp; /* USB class/subclass/proto */
235 void* aux; /* for the driver program */
240 int cval; /* value for set configuration */
242 int milliamps; /* maximum power in this config. */
243 Iface* iface[Niface];
247 * Device-specific descriptors.
248 * They show up mixed with other descriptors
249 * within a configuration.
250 * These are unknown to the library but handed to the driver.
255 uchar bDescriptorType;
257 /* extra bytes allocated here to keep the rest of it */
262 Conf* conf; /* where this descriptor was read */
263 Iface* iface; /* last iface before desc in conf. */
264 Ep* ep; /* last endpt before desc in conf. */
265 Altc* altc; /* last alt.c. before desc in conf. */
266 DDesc data; /* unparsed standard USB descriptor */
270 * layout of standard descriptor types
275 uchar bDescriptorType;
280 uchar bMaxPacketSize0;
287 uchar bNumConfigurations;
293 uchar bDescriptorType;
294 uchar wTotalLength[2];
295 uchar bNumInterfaces;
296 uchar bConfigurationValue;
297 uchar iConfiguration;
305 uchar bDescriptorType;
306 uchar bInterfaceNumber;
307 uchar bAlternateSetting;
309 uchar bInterfaceClass;
310 uchar bInterfaceSubClass;
311 uchar bInterfaceProtocol;
318 uchar bDescriptorType;
319 uchar bEndpointAddress;
321 uchar wMaxPacketSize[2];
325 #define Class(csp) ((csp) & 0xff)
326 #define Subclass(csp) (((csp)>>8) & 0xff)
327 #define Proto(csp) (((csp)>>16) & 0xff)
328 #define CSP(c, s, p) ((c) | (s)<<8 | (p)<<16)
330 #define GET2(p) (((p)[1] & 0xFF)<<8 | ((p)[0] & 0xFF))
331 #define PUT2(p,v) {(p)[0] = (v); (p)[1] = (v)>>8;}
332 #define GET4(p) (((p)[3]&0xFF)<<24 | ((p)[2]&0xFF)<<16 | \
333 ((p)[1]&0xFF)<<8 | ((p)[0]&0xFF))
334 #define PUT4(p,v) {(p)[0] = (v); (p)[1] = (v)>>8; \
335 (p)[2] = (v)>>16; (p)[3] = (v)>>24;}
337 #define dprint if(usbdebug)fprint
338 #define ddprint if(usbdebug > 1)fprint
340 #pragma varargck type "U" Dev*
341 #pragma varargck argpos devctl 2
344 char* classname(int c);
345 void closedev(Dev *d);
346 int configdev(Dev *d);
347 int devctl(Dev *dev, char *fmt, ...);
348 void* emallocz(ulong size, int zero);
349 char* estrdup(char *s);
350 char* hexstr(void *a, int n);
351 int loaddevconf(Dev *d, int n);
352 int loaddevdesc(Dev *d);
353 char* loaddevstr(Dev *d, int sid);
354 Dev* opendev(char *fn);
355 int opendevdata(Dev *d, int mode);
356 Dev* openep(Dev *d, int id);
357 int parseconf(Usbdev *d, Conf *c, uchar *b, int n);
358 int parsedesc(Usbdev *d, Conf *c, uchar *b, int n);
359 int parsedev(Dev *xd, uchar *b, int n);
360 int unstall(Dev *dev, Dev *ep, int dir);
361 int usbcmd(Dev *d, int type, int req, int value, int index, uchar *data, int count);
362 Dev* getdev(char *devid);
364 extern int usbdebug; /* more messages for bigger values */