예제 #1
0
void
dump_device_info(struct libusb20_device *pdev, uint8_t show_ifdrv)
{
	char buf[128];
	uint8_t n;
	unsigned int usage;

	usage = libusb20_dev_get_power_usage(pdev);

	printf("%s, cfg=%u md=%s spd=%s pwr=%s (%umA)\n",
	    libusb20_dev_get_desc(pdev),
	    libusb20_dev_get_config_index(pdev),
	    dump_mode(libusb20_dev_get_mode(pdev)),
	    dump_speed(libusb20_dev_get_speed(pdev)),
	    dump_power_mode(libusb20_dev_get_power_mode(pdev)),
	    usage);

	if (!show_ifdrv)
		return;

	for (n = 0; n != 255; n++) {
		if (libusb20_dev_get_iface_desc(pdev, n, buf, sizeof(buf)))
			break;
		if (buf[0] == 0)
			continue;
		printf("ugen%u.%u.%u: %s\n",
		    libusb20_dev_get_bus_number(pdev),
		    libusb20_dev_get_address(pdev), n, buf);
	}
}
예제 #2
0
파일: libusb01.c 프로젝트: coyizumi/cs111
static struct libusb20_transfer *
usb_get_transfer_by_ep_no(usb_dev_handle * dev, uint8_t ep_no)
{
	struct libusb20_device *pdev = (void *)dev;
	struct libusb20_transfer *xfer;
	int err;
	uint32_t bufsize;
	uint8_t x;
	uint8_t speed;

	x = (ep_no & LIBUSB20_ENDPOINT_ADDRESS_MASK) * 2;

	if (ep_no & LIBUSB20_ENDPOINT_DIR_MASK) {
		/* this is an IN endpoint */
		x |= 1;
	}
	speed = libusb20_dev_get_speed(pdev);

	/* select a sensible buffer size */
	if (speed == LIBUSB20_SPEED_LOW) {
		bufsize = 256;
	} else if (speed == LIBUSB20_SPEED_FULL) {
		bufsize = 4096;
	} else if (speed == LIBUSB20_SPEED_SUPER) {
		bufsize = 65536;
	} else {
		bufsize = 16384;
	}

	xfer = libusb20_tr_get_pointer(pdev, x);

	if (xfer == NULL)
		return (xfer);

	err = libusb20_tr_open(xfer, bufsize, 1, ep_no);
	if (err == LIBUSB20_ERROR_BUSY) {
		/* already opened */
		return (xfer);
	} else if (err) {
		return (NULL);
	}
	/* success */
	return (xfer);
}
예제 #3
0
enum libusb_speed
libusb_get_device_speed(libusb_device *dev)
{
	if (dev == NULL)
		return (LIBUSB_SPEED_UNKNOWN);	/* should not happen */

	switch (libusb20_dev_get_speed(dev->os_priv)) {
	case LIBUSB20_SPEED_LOW:
		return (LIBUSB_SPEED_LOW);
	case LIBUSB20_SPEED_FULL:
		return (LIBUSB_SPEED_FULL);
	case LIBUSB20_SPEED_HIGH:
		return (LIBUSB_SPEED_HIGH);
	case LIBUSB20_SPEED_SUPER:
		return (LIBUSB_SPEED_SUPER);
	default:
		break;
	}
	return (LIBUSB_SPEED_UNKNOWN);
}
예제 #4
0
int
libusb_get_max_iso_packet_size(libusb_device *dev, uint8_t endpoint)
{
	int multiplier;
	int ret;

	ret = libusb_get_max_packet_size(dev, endpoint);

	switch (libusb20_dev_get_speed(dev->os_priv)) {
	case LIBUSB20_SPEED_LOW:
	case LIBUSB20_SPEED_FULL:
		break;
	default:
		if (ret > -1) {
			multiplier = (1 + ((ret >> 11) & 3));
			if (multiplier > 3)
				multiplier = 3;
			ret = (ret & 0x7FF) * multiplier;
		}
		break;
	}