8 static char *edir[] = {"in", "out", "inout"};
9 static char *etype[] = {"ctl", "iso", "bulk", "intr"};
10 static char* cnames[] =
12 "none", "audio", "comms", "hid", "",
13 "", "", "printer", "storage", "hub", "data"
15 static char* devstates[] =
17 "detached", "attached", "enabled", "assigned", "configured"
25 if(c >= 0 && c < nelem(cnames))
28 seprint(buf, buf+30, "%d", c);
34 hexstr(void *a, int n)
41 dbuff = s = emallocz(1024, 0);
44 for(i = 0; i < n; i++)
45 s = seprint(s, e, " %.2ux", b[i]);
47 fprint(2, "%s: usb/lib: hexdump: bug: small buffer\n", argv0);
52 seprintiface(char *s, char *e, Iface *i)
59 s = seprint(s, e, "\t\tiface csp %s.%uld.%uld\n",
60 classname(Class(i->csp)), Subclass(i->csp), Proto(i->csp));
61 for(j = 0; j < Naltc; j++){
65 s = seprint(s, e, "\t\t alt %d attr %d ival %d",
66 j, a->attrib, a->interval);
68 s = seprint(s, e, " devspec %p\n", a->aux);
70 s = seprint(s, e, "\n");
72 for(j = 0; j < Nep; j++){
77 if(ep->dir <= nelem(edir))
79 if(ep->type <= nelem(etype))
80 ets = etype[ep->type];
81 s = seprint(s, e, "\t\t ep id %d addr %d dir %s type %s"
82 " itype %d maxpkt %d ntds %d\n",
83 ep->id, ep->addr, eds, ets, ep->isotype,
84 ep->maxpkt, ep->ntds);
90 seprintconf(char *s, char *e, Usbdev *d, int ci)
97 s = seprint(s, e, "\tconf: cval %d attrib %x %d mA\n",
98 c->cval, c->attrib, c->milliamps);
99 for(i = 0; i < Niface; i++)
100 if(c->iface[i] == nil)
103 s = seprintiface(s, e, c->iface[i]);
104 for(i = 0; i < Nddesc; i++)
105 if(d->ddesc[i] == nil)
107 else if(d->ddesc[i]->conf == c){
108 hd = hexstr((uchar*)&d->ddesc[i]->data,
109 d->ddesc[i]->data.bLength);
110 s = seprint(s, e, "\t\tdev desc %x[%d]: %s\n",
111 d->ddesc[i]->data.bDescriptorType,
112 d->ddesc[i]->data.bLength, hd);
129 d = va_arg(f->args, Dev*);
131 return fmtprint(f, "<nildev>\n");
132 s = seprint(s, e, "%s", d->dir);
135 return fmtprint(f, "%s %ld refs\n", buf, d->ref);
136 s = seprint(s, e, " csp %s.%uld.%uld",
137 classname(Class(ud->csp)), Subclass(ud->csp), Proto(ud->csp));
138 s = seprint(s, e, " vid %#ux did %#ux", ud->vid, ud->did);
139 s = seprint(s, e, " refs %ld\n", d->ref);
140 s = seprint(s, e, "\t%s %s %s\n", ud->vendor, ud->product, ud->serial);
141 for(i = 0; i < Nconf; i++){
142 if(ud->conf[i] == nil)
145 s = seprintconf(s, e, ud, i);
147 return fmtprint(f, "%s", buf);
157 sysfatal("strdup: %r");
158 setmalloctag(d, getcallerpc(&s));
163 emallocz(ulong size, int zero)
169 sysfatal("malloc: %r");
172 setmalloctag(x, getcallerpc(&size));