Lines Matching refs:device

364 void usb_device_close(struct usb_device *device)  in usb_device_close()  argument
366 close(device->fd); in usb_device_close()
367 free(device); in usb_device_close()
372 struct usb_device *device = calloc(1, sizeof(struct usb_device)); in usb_device_new() local
379 length = read(fd, device->desc, sizeof(device->desc)); in usb_device_new()
384 strncpy(device->dev_name, dev_name, sizeof(device->dev_name) - 1); in usb_device_new()
385 device->fd = fd; in usb_device_new()
386 device->desc_length = length; in usb_device_new()
388 device->writeable = 1; in usb_device_new()
389 return device; in usb_device_new()
395 free(device); in usb_device_new()
399 static int usb_device_reopen_writeable(struct usb_device *device) in usb_device_reopen_writeable() argument
401 if (device->writeable) in usb_device_reopen_writeable()
404 int fd = open(device->dev_name, O_RDWR); in usb_device_reopen_writeable()
406 close(device->fd); in usb_device_reopen_writeable()
407 device->fd = fd; in usb_device_reopen_writeable()
408 device->writeable = 1; in usb_device_reopen_writeable()
415 int usb_device_get_fd(struct usb_device *device) in usb_device_get_fd() argument
417 if (!usb_device_reopen_writeable(device)) in usb_device_get_fd()
419 return device->fd; in usb_device_get_fd()
422 const char* usb_device_get_name(struct usb_device *device) in usb_device_get_name() argument
424 return device->dev_name; in usb_device_get_name()
427 int usb_device_get_unique_id(struct usb_device *device) in usb_device_get_unique_id() argument
430 sscanf(device->dev_name, USB_FS_ID_SCANNER, &bus, &dev); in usb_device_get_unique_id()
450 uint16_t usb_device_get_vendor_id(struct usb_device *device) in usb_device_get_vendor_id() argument
452 struct usb_device_descriptor* desc = (struct usb_device_descriptor*)device->desc; in usb_device_get_vendor_id()
456 uint16_t usb_device_get_product_id(struct usb_device *device) in usb_device_get_product_id() argument
458 struct usb_device_descriptor* desc = (struct usb_device_descriptor*)device->desc; in usb_device_get_product_id()
462 const struct usb_device_descriptor* usb_device_get_device_descriptor(struct usb_device* device) { in usb_device_get_device_descriptor() argument
463 return (struct usb_device_descriptor*)device->desc; in usb_device_get_device_descriptor()
466 size_t usb_device_get_descriptors_length(const struct usb_device* device) { in usb_device_get_descriptors_length() argument
467 return device->desc_length; in usb_device_get_descriptors_length()
470 const unsigned char* usb_device_get_raw_descriptors(const struct usb_device* device) { in usb_device_get_raw_descriptors() argument
471 return device->desc; in usb_device_get_raw_descriptors()
488 int usb_device_get_string_ucs2(struct usb_device* device, int id, int timeout, void** ucs2_out, in usb_device_get_string_ucs2() argument
501 result = usb_device_control_transfer(device, in usb_device_get_string_ucs2()
512 device, USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE, USB_REQ_GET_DESCRIPTOR, in usb_device_get_string_ucs2()
537 char* usb_device_get_string(struct usb_device* device, int id, int timeout) { in usb_device_get_string() argument
541 if (usb_device_get_string_ucs2(device, id, timeout, (void**)&ascii_string, &raw_string_len) < 0) in usb_device_get_string()
558 char* usb_device_get_manufacturer_name(struct usb_device *device, int timeout) in usb_device_get_manufacturer_name() argument
560 struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc; in usb_device_get_manufacturer_name()
561 return usb_device_get_string(device, desc->iManufacturer, timeout); in usb_device_get_manufacturer_name()
564 char* usb_device_get_product_name(struct usb_device *device, int timeout) in usb_device_get_product_name() argument
566 struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc; in usb_device_get_product_name()
567 return usb_device_get_string(device, desc->iProduct, timeout); in usb_device_get_product_name()
570 int usb_device_get_version(struct usb_device *device) in usb_device_get_version() argument
572 struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc; in usb_device_get_version()
576 char* usb_device_get_serial(struct usb_device *device, int timeout) in usb_device_get_serial() argument
578 struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc; in usb_device_get_serial()
579 return usb_device_get_string(device, desc->iSerialNumber, timeout); in usb_device_get_serial()
582 int usb_device_is_writeable(struct usb_device *device) in usb_device_is_writeable() argument
584 return device->writeable; in usb_device_is_writeable()
587 void usb_descriptor_iter_init(struct usb_device *device, struct usb_descriptor_iter *iter) in usb_descriptor_iter_init() argument
589 iter->config = device->desc; in usb_descriptor_iter_init()
590 iter->config_end = device->desc + device->desc_length; in usb_descriptor_iter_init()
591 iter->curr_desc = device->desc; in usb_descriptor_iter_init()
609 int usb_device_claim_interface(struct usb_device *device, unsigned int interface) in usb_device_claim_interface() argument
611 return ioctl(device->fd, USBDEVFS_CLAIMINTERFACE, &interface); in usb_device_claim_interface()
614 int usb_device_release_interface(struct usb_device *device, unsigned int interface) in usb_device_release_interface() argument
616 return ioctl(device->fd, USBDEVFS_RELEASEINTERFACE, &interface); in usb_device_release_interface()
619 int usb_device_connect_kernel_driver(struct usb_device *device, in usb_device_connect_kernel_driver() argument
627 return ioctl(device->fd, USBDEVFS_IOCTL, &ctl); in usb_device_connect_kernel_driver()
630 int usb_device_set_configuration(struct usb_device *device, int configuration) in usb_device_set_configuration() argument
632 return ioctl(device->fd, USBDEVFS_SETCONFIGURATION, &configuration); in usb_device_set_configuration()
635 int usb_device_set_interface(struct usb_device *device, unsigned int interface, in usb_device_set_interface() argument
642 return ioctl(device->fd, USBDEVFS_SETINTERFACE, &ctl); in usb_device_set_interface()
645 int usb_device_control_transfer(struct usb_device *device, in usb_device_control_transfer() argument
657 if (!usb_device_reopen_writeable(device)) in usb_device_control_transfer()
668 return ioctl(device->fd, USBDEVFS_CONTROL, &ctrl); in usb_device_control_transfer()
671 int usb_device_bulk_transfer(struct usb_device *device, in usb_device_bulk_transfer() argument
684 return ioctl(device->fd, USBDEVFS_BULK, &ctrl); in usb_device_bulk_transfer()
687 int usb_device_reset(struct usb_device *device) in usb_device_reset() argument
689 return ioctl(device->fd, USBDEVFS_RESET); in usb_device_reset()