Home:ALL Converter>how to detect the USB gadget(device side) status on linux?

how to detect the USB gadget(device side) status on linux?

Ask Time:2015-10-20T14:00:57         Author:Galavant

Json Formatter

So i have this small linux-based device that collects some data and implements usb gadget to emulate a flash drive, so that people can have access to the data.

I was able to capture the eject event by detecting the power loss on the vbus pin, as mentioned in this article, which works very well. Using Linux USB gadget - Need to capture eject event

But I can't figure out a way to detect the plug-in event. I need this information so that the device can stop collecting data and avoid crashing the file system. Detecting the power on status on USB pin is not a option since the usb port is also used as a charging interface.

But the kernel is aware of this event since it prints "g_multi gadget: high-speed config #1: Multifunction with CDC ECM" in the console.

My question is how can I extract the plug-in event from kernel in C?

Thanks in advanced.

Author:Galavant,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/33229108/how-to-detect-the-usb-gadgetdevice-side-status-on-linux
yy