ref: 457ba087b13a881b013940f6e54c09566ec10ed1
parent: 556eea1f5a6cd0f1eeb74156ff3899803d107822
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Jan 5 12:15:24 EST 2023
nusb/usbd: assign hname to hubs For the port control, it can be usefull to refer to a hub by its stable hash name.
--- a/sys/src/cmd/nusb/usbd/fns.h
+++ b/sys/src/cmd/nusb/usbd/fns.h
@@ -3,5 +3,6 @@
void work(void);
Hub* newhub(char *, Dev*);
int hname(char *);
+void assignhname(Dev *dev);
void checkidle(void);
int portfeature(Hub*, int, int, int);
--- a/sys/src/cmd/nusb/usbd/hub.c
+++ b/sys/src/cmd/nusb/usbd/hub.c
@@ -199,8 +199,10 @@
devctl(h->dev, "info roothub csp %#08ux ports %d",
0x000009, h->nport);
else{
- devctl(h->dev, "info hub csp %#08ulx ports %d vid %#.4ux did %#.4ux %q %q",
- ud->csp, h->nport, ud->vid, ud->did, ud->vendor, ud->product);
+ assignhname(h->dev);
+
+ devctl(h->dev, "info hub csp %#08ulx ports %d vid %#.4ux did %#.4ux %q %q %s",
+ ud->csp, h->nport, ud->vid, ud->did, ud->vendor, ud->product, h->dev->hname);
for(i = 1; i <= h->nport; i++)
if(portfeature(h, i, Fportpower, 1) < 0)
fprint(2, "%s: %s: power: %r\n", argv0, fn);
--- a/sys/src/cmd/nusb/usbd/usbd.c
+++ b/sys/src/cmd/nusb/usbd/usbd.c
@@ -227,7 +227,8 @@
extern Hub *hubs;
Hub *hub;
Cmdbuf *cb;
- int hubid, port, feature, on;
+ char hubid[16];
+ int port, feature, on;
if((long)req->fid->qid.path != Qusbhubctl){
respond(req, Enonexist);
@@ -246,7 +247,6 @@
respond(req, "unnown feature");
goto out;
}
- hubid = atoi(cb->f[1]);
port = atoi(cb->f[2]);
if(strcmp(cb->f[3], "on") == 0)
on = 1;
@@ -256,9 +256,13 @@
on = atoi(cb->f[3]) != 0;
qlock(&hublock);
- for(hub = hubs; hub != nil; hub = hub->next)
- if(hub->dev->id == hubid)
+ for(hub = hubs; hub != nil; hub = hub->next){
+ if(hub->dev->hname != nil && strcmp(hub->dev->hname, cb->f[1]) == 0)
break;
+ snprint(hubid, sizeof(hubid), "%d", hub->dev->id);
+ if(strcmp(hubid, cb->f[1]) == 0)
+ break;
+ }
if(hub == nil){
qunlock(&hublock);
respond(req, "unknown hub");
@@ -441,7 +445,7 @@
.destroyfid = usbddestroyfid,
};
-static void
+void
assignhname(Dev *dev)
{
extern Hub *hubs;
@@ -462,6 +466,13 @@
/* check for collisions */
col = 0;
for(h = hubs; h != nil; h = h->next){
+ if(ud->class == Clhub){
+ if(h->dev->hname == nil)
+ continue;
+ if(strncmp(h->dev->hname, buf, n) == 0)
+ col++;
+ continue;
+ }
for(i = 1; i <= h->nport; i++){
if(h->port[i].dev == nil)
continue;