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 fmtprintiface(Fmt *f, Iface *i)
59 fmtprint(f, "\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 fmtprint(f, "\t\t alt %d attr %d ival %d",
66 j, a->attrib, a->interval);
68 fmtprint(f, " devspec %p\n", a->aux);
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 fmtprint(f, "\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);
89 fmtprintconf(Fmt *f, Usbdev *d, int ci)
96 fmtprint(f, "\tconf: cval %d attrib %x %d mA\n",
97 c->cval, c->attrib, c->milliamps);
98 for(i = 0; i < Niface; i++)
99 if(c->iface[i] == nil)
102 fmtprintiface(f, c->iface[i]);
103 for(i = 0; i < Nddesc; i++)
104 if(d->ddesc[i] == nil)
106 else if(d->ddesc[i]->conf == c){
107 hd = hexstr((uchar*)&d->ddesc[i]->data,
108 d->ddesc[i]->data.bLength);
109 fmtprint(f, "\t\tdev desc %x[%d]: %s\n",
110 d->ddesc[i]->data.bDescriptorType,
111 d->ddesc[i]->data.bLength, hd);
123 d = va_arg(f->args, Dev*);
125 return fmtprint(f, "<nildev>\n");
126 fmtprint(f, "%s", d->dir);
129 return fmtprint(f, " %ld refs\n", d->ref);
130 fmtprint(f, " csp %s.%uld.%uld",
131 classname(Class(ud->csp)), Subclass(ud->csp), Proto(ud->csp));
132 fmtprint(f, " vid %#ux did %#ux", ud->vid, ud->did);
133 fmtprint(f, " refs %ld\n", d->ref);
134 fmtprint(f, "\t%s %s %s\n", ud->vendor, ud->product, ud->serial);
135 for(i = 0; i < Nconf; i++){
136 if(ud->conf[i] == nil)
139 fmtprintconf(f, ud, i);
151 sysfatal("strdup: %r");
152 setmalloctag(d, getcallerpc(&s));
157 emallocz(ulong size, int zero)
163 sysfatal("malloc: %r");
166 setmalloctag(x, getcallerpc(&size));