示例#1
0
static
int garmin_usb_scan(libusb_unit_data *lud, int req_unit_number)
{
	int found_devices = 0;
	struct usb_bus *bus;

	for (bus = lud->busses; bus; bus = bus->next) {
		struct usb_device *dev;

		for (dev = bus->devices; dev; dev = dev->next) {
			/* 
			 * Exclude Mass Storage devices (CO, OR, Nuvi, etc.) 
			 * from this scan.
			 * At least on Mac, bDeviceClass isn't 
			 * USB_MASS_STORAGE as it should be (perhaps because
			 * the storage driver has already bound to it?) so
			 * we fondle only the proprietary class devices.
			 */
			if (dev->descriptor.idVendor == GARMIN_VID && 
			    dev->config &&
				dev->descriptor.bDeviceClass == USB_CLASS_VENDOR_SPEC ) {
				if (req_unit_number < 0) {
					garmin_usb_start(dev, lud);	
					/* 
					 * It's important to call _close
					 * here since the bulk/intr models
				  	 * may have a "dangling" packet that
					 * needs to be drained.
					 */ 		
					gusb_close(NULL);
				} else 
				if (req_unit_number == found_devices)
					garmin_usb_start(dev, lud);	
				found_devices++;
			}
		}
	}

	if (req_unit_number < 0) {
		gusb_list_units();
		exit (0);
	}

	if (0 == found_devices) {
		/* It's time for Plan B.  The user told us to use 
		 * Garmin Protocol in device "usb:" but it's possible
		 * that they're talking to one of the dozens of models
		 * that is wants to read and write GPX files on a 
		 * mounted drive.  Try that now.
		 */
		char **dlist = os_get_garmin_mountpoints();
		gdx = gdx_find_file(dlist);
		if (gdx) return 1;
		/* Plan C. */
		fatal("Found no Garmin USB devices.\n");
	} else { 
		return 1;
        }
}
示例#2
0
static
int garmin_usb_scan(libusb_unit_data *lud, int req_unit_number)
{
	int found_devices = 0;
	struct usb_bus *bus;

	for (bus = lud->busses; bus; bus = bus->next) {
		struct usb_device *dev;

		for (dev = bus->devices; dev; dev = dev->next) {
			/* Probably too promiscious of a match, but since
			 * Garmin doesn't document the _proper_ matching,
			 * we just take the easy way out for now.
			 * Unfortunatey, blowing on DeviceClass == Mass storage
			 * doesn't work on CO, at least.
			 */
			if (dev->descriptor.idVendor == GARMIN_VID && 
								dev->config) {
				switch (dev->descriptor.idProduct) {
					case 0x19:  // Nuvi;
					case 0x2244:  // Zumo;
					case 0x2295:  // CO;
						continue;
				}
				if (req_unit_number < 0) {
					garmin_usb_start(dev, lud);	
					/* 
					 * It's important to call _close
					 * here since the bulk/intr models
				  	 * may have a "dangling" packet that
					 * needs to be drained.
					 */ 		
					gusb_close(NULL);
				} else 
				if (req_unit_number == found_devices)
					garmin_usb_start(dev, lud);	
				found_devices++;
			}
		}
	}

	if (req_unit_number < 0) {
		gusb_list_units();
		exit (0);
	}

	if (0 == found_devices) {
		/* It's time for Plan B.  The user told us to use 
		 * Garmin Protocol in device "usb:" but it's possible
		 * that they're talking to one of the dozens of models
		 * that is wants to read and write GPX files on a 
		 * mounted drive.  Try that now.
		 */
		char **dlist = os_get_garmin_mountpoints();
		gdx = gdx_find_file(dlist);
		if (gdx) return 1;
		/* Plan C. */
		fatal("Found no Garmin USB devices.\n");
	} else { 
		return 1;
        }
}