Lines Matching refs:device
200 D("Created device discovery thread\n");
287 D("new device %s\n", path);
290 D("gone device %s\n", path);
351 void usb_device_close(struct usb_device *device)
353 close(device->fd);
354 free(device);
359 struct usb_device *device = calloc(1, sizeof(struct usb_device));
366 length = read(fd, device->desc, sizeof(device->desc));
371 strncpy(device->dev_name, dev_name, sizeof(device->dev_name) - 1);
372 device->fd = fd;
373 device->desc_length = length;
375 device->writeable = 1;
376 return device;
380 free(device);
384 static int usb_device_reopen_writeable(struct usb_device *device)
386 if (device->writeable)
389 int fd = open(device->dev_name, O_RDWR);
391 close(device->fd);
392 device->fd = fd;
393 device->writeable = 1;
400 int usb_device_get_fd(struct usb_device *device)
402 if (!usb_device_reopen_writeable(device))
404 return device->fd;
407 const char* usb_device_get_name(struct usb_device *device)
409 return device->dev_name;
412 int usb_device_get_unique_id(struct usb_device *device)
415 sscanf(device->dev_name, USB_FS_ID_SCANNER, &bus, &dev);
435 uint16_t usb_device_get_vendor_id(struct usb_device *device)
437 struct usb_device_descriptor* desc = (struct usb_device_descriptor*)device->desc;
441 uint16_t usb_device_get_product_id(struct usb_device *device)
443 struct usb_device_descriptor* desc = (struct usb_device_descriptor*)device->desc;
447 const struct usb_device_descriptor* usb_device_get_device_descriptor(struct usb_device *device)
449 return (struct usb_device_descriptor*)device->desc;
452 char* usb_device_get_string(struct usb_device *device, int id)
466 result = usb_device_control_transfer(device,
475 result = usb_device_control_transfer(device,
492 char* usb_device_get_manufacturer_name(struct usb_device *device)
494 struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc;
495 return usb_device_get_string(device, desc->iManufacturer);
498 char* usb_device_get_product_name(struct usb_device *device)
500 struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc;
501 return usb_device_get_string(device, desc->iProduct);
504 int usb_device_get_version(struct usb_device *device)
506 struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc;
510 char* usb_device_get_serial(struct usb_device *device)
512 struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc;
513 return usb_device_get_string(device, desc->iSerialNumber);
516 int usb_device_is_writeable(struct usb_device *device)
518 return device->writeable;
521 void usb_descriptor_iter_init(struct usb_device *device, struct usb_descriptor_iter *iter)
523 iter->config = device->desc;
524 iter->config_end = device->desc + device->desc_length;
525 iter->curr_desc = device->desc;
538 int usb_device_claim_interface(struct usb_device *device, unsigned int interface)
540 return ioctl(device
543 int usb_device_release_interface(struct usb_device *device, unsigned int interface)
545 return ioctl(device->fd, USBDEVFS_RELEASEINTERFACE, &interface);
548 int usb_device_connect_kernel_driver(struct usb_device *device,
556 return ioctl(device->fd, USBDEVFS_IOCTL, &ctl);
559 int usb_device_set_configuration(struct usb_device *device, int configuration)
561 return ioctl(device->fd, USBDEVFS_SETCONFIGURATION, &configuration);
564 int usb_device_set_interface(struct usb_device *device, unsigned int interface,
571 return ioctl(device->fd, USBDEVFS_SETINTERFACE, &ctl);
574 int usb_device_control_transfer(struct usb_device *device,
586 if (!usb_device_reopen_writeable(device))
597 return ioctl(device->fd, USBDEVFS_CONTROL, &ctrl);
600 int usb_device_bulk_transfer(struct usb_device *device,
617 return ioctl(device->fd, USBDEVFS_BULK, &ctrl);
620 int usb_device_reset(struct usb_device *device)
622 return ioctl(device->fd, USBDEVFS_RESET);