Robert Murrell
|
Re: USB drive detection on startup
|
Robert Murrell
05/17/2013 9:22 AM
post101520
|
Re: USB drive detection on startup
Thanks. I didn't know this interface existed. This might be just what I'm looking for.
|
|
|
Robert Murrell
|
Re: USB drive detection on startup
|
Robert Murrell
05/17/2013 11:32 AM
post101526
|
Re: USB drive detection on startup
Base on your suggestion and the example code in the docs, I wrote this test program:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/usbdi.h>
int main(int argc, char *argv[]) {
int rc;
usbd_connect_parm_t parms;
struct usbd_connection *connection;
usbd_device_ident_t ident;
usbd_funcs_t funcs;
usbd_device_instance_t instance;
struct usbd_device *device;
usbd_device_descriptor_t *descriptor;
struct usbd_desc_node *node;
memset(&parms, 0, sizeof(parms));
memset(&funcs, 0, sizeof(funcs));
funcs.nentries = _USBDI_NFUNCS;
ident.vendor = USBD_CONNECT_WILDCARD;
ident.device = USBD_CONNECT_WILDCARD;
ident.dclass = USBD_CONNECT_WILDCARD;
ident.subclass = USBD_CONNECT_WILDCARD;
ident.protocol = USBD_CONNECT_WILDCARD;
parms.vusb = USB_VERSION;
parms.vusbd = USBD_VERSION;
parms.ident = &ident;
parms.funcs = &funcs;
parms.connect_wait = 2;
if ((rc = usbd_connect(&parms, &connection)) == EOK) {
//attach to USB0
int busno;
int devno;
for (busno = 0; busno < 10; ++busno) {
for (devno = 0; devno < 64; ++devno) {
memset(&instance, USBD_CONNECT_WILDCARD, sizeof(instance));
instance.path = busno;
instance.devno = devno;
if ((rc = usbd_attach(connection, &instance, 0, &device)) == EOK) {
if ((descriptor = usbd_device_descriptor(device, &node)) != NULL) {
printf("Found device\n");
}
} else {
printf("Bus %d device %d: %s\n", busno, devno, strerror(rc));
}
}
}
rc = usbd_disconnect(connection);
}
return EXIT_SUCCESS;
}
All calls to usbd_attach return ENODEV, except the call for busno = 0 and devno = 1. That call returns EBUSY. I have a
USB drive plugged in and the values corresponds to the report given by "usb". What am I doing wrong?
> You could do a shared access scan for the device by connecting
> (usbd_connect())to the USB server but not providing any callbacks and
> setting the device ident to use wildcards. You then use usbd_attach() to
> loop through all the devices (see usbd_attach() docs for notes on
> "Looping") and check the instance of the attached device for a dclass of
> 0x06, a subclass of 0x08 and maybe even a protocol of 0x50 (that's what
> usb -vv showed for my umass device, your mileage will vary though). You
> could then increment a counter to track how many umass devices are
> plugged in at the time or just bail out at that point and return status
> to your script etc.
>
|
|
|