# Controlling USB ports



## balanga (Feb 15, 2018)

Is it possible to programatically control USB ports by enabling and disabling them?


----------



## tobik@ (Feb 15, 2018)

Yeah, with usbconfig(8) (see the EXAMPLES section).


----------



## balanga (Feb 15, 2018)

Thanks, but it wasn't quite what I was looking for... I'd like to be able to control devices such as lights which only use USB ports for drawing power.  usbconfig(8)  showed no indication that I had a lamp connected to a port.

I have no idea if this is even possible.


----------



## drhowarddrfine (Feb 15, 2018)

Of course. People do it all the time.


----------



## ralphbsz (Feb 15, 2018)

If you have a purely passive lamp, which has no electronics that's connected to the two USB data pins, and only uses the two USB power pins to get 5V using at most the minimum unmanaged power (which I think is 100 or 150mA, the details are lost in my brain), then there is nothing you can control.  I think such devices do exist; whether they are USB standard conforming would be a question for a USB expert.

If you have USB-conforming devices, they use the data pins to speak some USB protocol which controls power delivery.  This is the point where the USB controller (host) can perform power management, and this is the point where programs like `usbcontrol` can interact with the USB controller.


----------



## balanga (Feb 15, 2018)

ralphbsz said:


> If you have a purely passive lamp, which has no electronics that's connected to the two USB data pins, and only uses the two USB power pins to get 5V using at most the minimum unmanaged power (which I think is 100 or 150mA, the details are lost in my brain), then there is nothing you can control.  I think such devices do exist; whether they are USB standard conforming would be a question for a USB expert.



That's basically what my question was about, ie whether you could control the port itself, not device attatched to the port. I was think of something equivalent to enabling/disabling LAN ports...


----------



## ralphbsz (Feb 15, 2018)

Actually, on further thinking: I think the USB controller chips may be capable of turning the +5V power completely off.  But power management of USB is complicated, and involves the OS, the motherboard's ACPI implementation (for power during sleep and such things), and the controller hardware.  You'll either have to rely on trial and error (start with "usbconfig power_off"), or read the whole specification and the interface documents (which sounds like a lot of work).


----------



## balanga (Feb 15, 2018)

I'll rely on trial and error  although it would be nice to know what unit and addr referred to, or even how many there were of each...


----------

