Ejemplo n.º 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;
        }
}
Ejemplo n.º 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;
        }
}
Ejemplo n.º 3
0
/*
 * Main entry point from the upper layer.   Walk the device tree, find our
 * device, and light it up.
 */
int
gusb_init(const char *pname, gpsdevh **dh)
{
	int req_unit_number = 0;
	int un = 0;
	int match;

	HDEVINFO hdevinfo;
	SP_DEVICE_INTERFACE_DATA devinterface;

	winusb_unit_data *wud = xcalloc(sizeof (winusb_unit_data), 1);
	*dh = (gpsdevh*) wud;

	gusb_register_ll(&win_llops);

	if (strlen(pname) > 4) {
		if (0 == strcmp(pname+4, "list")) {
			req_unit_number = -1;
		} else {
			req_unit_number = atoi(pname+4);
		}
	}

	hdevinfo = SetupDiGetClassDevs( (GUID *) &GARMIN_GUID, NULL, NULL, 
			DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);

	if (hdevinfo == INVALID_HANDLE_VALUE) {
		GPS_Serial_Error("SetupDiGetClassDevs failed");
		warning("Is the Garmin USB driver installed?");
		return 0;
	}

	devinterface.cbSize = sizeof(devinterface);
	
	if (req_unit_number >= 0) {
		if (!SetupDiEnumDeviceInterfaces(hdevinfo, NULL, 
				(GUID *) &GARMIN_GUID, 
				req_unit_number, &devinterface)) {
        // If there were zero matches, we may be trying to talk to a "GPX Mode" device.
      
   
          char **dlist = get_garmin_mountpoints();
          gdx = gdx_find_file(dlist);
          if (gdx) return 1;
       

         // Plan C.
			GPS_Serial_Error("SetupDiEnumDeviceInterfaces");
			warning("Is the Garmin USB unit number %d powered up and connected?\nIs it really a USB unit?  If it's serial, don't choose USB, choose serial.\nAre the Garmin USB drivers installed and functioning with other programs?\nIs it a storage based device like Nuvi, CO, or OR?\n  If so, send GPX files to it, don't use this module.\n", un);
			return 0;
		}
		/* We've matched.  Now start the specific unit. */
		garmin_usb_start(hdevinfo, &devinterface);
		return 1;
	}

	/* 
	 * Out unit nunber  is less than zero, so loop over all units
	 * and display them.
	 */
	for(match = 0;;match++) {
		if (!SetupDiEnumDeviceInterfaces(hdevinfo, NULL, 
			(GUID *) &GARMIN_GUID, match, &devinterface)) {
			if (GetLastError() == ERROR_NO_MORE_ITEMS) {
 
				break;
			} else {

				GPS_Serial_Error("SetupDiEnumDeviceInterfaces");
				warning("Is the Garmin USB unit number %d powered up and connected?", un);
				return 0;
			}	
		}
		/* We've matched.  Now start the specific unit. */
		garmin_usb_start(hdevinfo, &devinterface);
		gusb_close(NULL);
	}
	gusb_list_units();
	exit (0);
}