Quoting Amira Solomovici <[EMAIL PROTECTED]>: > I am trying to write a usb device driver that is loaded as a module into the > kernel. The user mode application that communicates with the driver is > supposed to be running in the background all the time, and send/receive > commands whenever the device is connected. > > My question is how do I find out in the application whether the device is > connected or not?
Read the driver's /proc entry? Send an ioctl to the driver? Try to open a device? It's your driver, you can do whatever you want. The driver, once loaded, is in control of everything. probe() and disconnect() callbacks are mostly notifications that tell the driver about a new device or a device that is gone. But the driver itself is fully operational with or without device(s) plugged in. > I have created through mknod a link to the driver and use > the read/write/ioctl commands. However, if I disconnect the device while the > application is running, it crashes The application crashes? It should handle errors returned by the driver. > and sometimes the kernel gets stuck The driver should tolerate disappearing devices. The USB stack will complete pending URBs with an error code, and your driver should not try to talk to the device if it is no longer there (see disconnect). Synchronization of such events is a very important function of the driver. Normally, if the device is unplugged during read() the driver should return an appropriate error code. Then the application should close the file handle, and that will release all driver's resources associated with the device. You don't do it on disconnect() event because that would kill everything pending; you just mark the device as no longer present, and your driver should see this flag and fail requests to the device without sending anything to it; the driver should not use no longer valid USB structures after disconnect() notified it about unplugging. Dmitri -- "What's wrong with running away from reality if reality sucks?" -- Shinji Ikari, "Evangelion"
msg03553/pgp00000.pgp
Description: PGP signature