简体   繁体   中英

How to detect disconnection of usb0 device (USB gadget aka g_ether)?

Two Linux machines (embedded board and PC) are connected to each other via USB cable, and communication is established via USB gadget/Ethernet. Both sides have IP address, ping works, etc.

I need to find a way to detect USB cable disconnect on the board side, ideally with a single Bash command.

ifconfig usb0 still shows IP address and that device is "UP" and "RUNNING" even after unplugging the cable.

One way to do this is to check the file:

/sys/class/net/usb0/operstate

If the file content is "up" then the link exists. If the content is "down", then there is no link.

In my particular case it turned out to be HW+SW issue: driver (atmel_usba_udc) is using USB power (VBUS) to detect connection, since it's acting as a slave and power is provided by host. However in PCB power is provided unconditionally by the board itself for all USB ports at once.

Normally any standard method should work: ifconfig or sysfs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM