9 static char *edir[] = {"in", "out", "inout"};
10 static char *etype[] = {"ctl", "iso", "bulk", "intr"};
11 static char* cnames[] =
13 "none", "audio", "comms", "hid", "",
14 "", "", "printer", "storage", "hub", "data"
16 static char* devstates[] =
18 "detached", "attached", "enabled", "assigned", "configured"
26 if(c >= 0 && c < nelem(cnames))
29 seprint(buf, buf+30, "%d", c);
35 hexstr(void *a, int n)
42 dbuff = s = emallocz(1024, 0);
45 for(i = 0; i < n; i++)
46 s = seprint(s, e, " %.2ux", b[i]);
48 fprint(2, "%s: usb/lib: hexdump: bug: small buffer\n", argv0);
53 seprintiface(char *s, char *e, Iface *i)
60 s = seprint(s, e, "\t\tiface csp %s.%uld.%uld\n",
61 classname(Class(i->csp)), Subclass(i->csp), Proto(i->csp));
62 for(j = 0; j < Naltc; j++){
66 s = seprint(s, e, "\t\t alt %d attr %d ival %d",
67 j, a->attrib, a->interval);
69 s = seprint(s, e, " devspec %p\n", a->aux);
71 s = seprint(s, e, "\n");
73 for(j = 0; j < Nep; j++){
78 if(ep->dir <= nelem(edir))
80 if(ep->type <= nelem(etype))
81 ets = etype[ep->type];
82 s = seprint(s, e, "\t\t ep id %d addr %d dir %s type %s"
83 " itype %d maxpkt %d ntds %d\n",
84 ep->id, ep->addr, eds, ets, ep->isotype,
85 ep->maxpkt, ep->ntds);
91 seprintconf(char *s, char *e, Usbdev *d, int ci)
98 s = seprint(s, e, "\tconf: cval %d attrib %x %d mA\n",
99 c->cval, c->attrib, c->milliamps);
100 for(i = 0; i < Niface; i++)
101 if(c->iface[i] == nil)
104 s = seprintiface(s, e, c->iface[i]);
105 for(i = 0; i < Nddesc; i++)
106 if(d->ddesc[i] == nil)
108 else if(d->ddesc[i]->conf == c){
109 hd = hexstr((uchar*)&d->ddesc[i]->data,
110 d->ddesc[i]->data.bLength);
111 s = seprint(s, e, "\t\tdev desc %x[%d]: %s\n",
112 d->ddesc[i]->data.bDescriptorType,
113 d->ddesc[i]->data.bLength, hd);
130 d = va_arg(f->args, Dev*);
132 return fmtprint(f, "<nildev>\n");
133 s = seprint(s, e, "%s", d->dir);
136 return fmtprint(f, "%s %ld refs\n", buf, d->ref);
137 s = seprint(s, e, " csp %s.%uld.%uld",
138 classname(Class(ud->csp)), Subclass(ud->csp), Proto(ud->csp));
139 s = seprint(s, e, " vid %#ux did %#ux", ud->vid, ud->did);
140 s = seprint(s, e, " refs %ld\n", d->ref);
141 s = seprint(s, e, "\t%s %s %s\n", ud->vendor, ud->product, ud->serial);
142 for(i = 0; i < Nconf; i++){
143 if(ud->conf[i] == nil)
146 s = seprintconf(s, e, ud, i);
148 return fmtprint(f, "%s", buf);
158 sysfatal("strdup: %r");
159 setmalloctag(d, getcallerpc(&s));
164 emallocz(ulong size, int zero)
170 sysfatal("malloc: %r");
173 setmalloctag(x, getcallerpc(&size));