Lines Matching full:device
148 D("Created device discovery thread\n");
193 D("new device %s\n", path);
196 D("gone device %s\n", path);
237 void usb_device_close(struct usb_device *device)
239 close(device->fd);
240 free(device);
245 struct usb_device *device = calloc(1, sizeof(struct usb_device));
252 length = read(fd, device->desc, sizeof(device->desc));
257 strncpy(device->dev_name, dev_name, sizeof(device->dev_name) - 1);
258 device->fd = fd;
259 device->desc_length = length;
261 device->writeable = 1;
262 return device;
266 free(device);
270 static int usb_device_reopen_writeable(struct usb_device *device)
272 if (device->writeable)
275 int fd = open(device->dev_name, O_RDWR);
277 close(device->fd);
278 device->fd = fd;
279 device->writeable = 1;
286 int usb_device_get_fd(struct usb_device *device)
288 if (!usb_device_reopen_writeable(device))
290 return device->fd;
293 const char* usb_device_get_name(struct usb_device *device)
295 return device->dev_name;
298 int usb_device_get_unique_id(struct usb_device *device)
301 sscanf(device->dev_name, USB_FS_ID_SCANNER, &bus, &dev);
321 uint16_t usb_device_get_vendor_id(struct usb_device *device)
323 struct usb_device_descriptor* desc = (struct usb_device_descriptor*)device->desc;
327 uint16_t usb_device_get_product_id(struct usb_device *device)
329 struct usb_device_descriptor* desc = (struct usb_device_descriptor*)device->desc;
333 const struct usb_device_descriptor* usb_device_get_device_descriptor(struct usb_device *device)
335 return (struct usb_device_descriptor*)device->desc;
338 char* usb_device_get_string(struct usb_device *device, int id)
350 result = usb_device_control_transfer(device,
359 result = usb_device_control_transfer(device,
376 char* usb_device_get_manufacturer_name(struct usb_device *device)
378 struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc;
381 return usb_device_get_string(device, desc->iManufacturer);
386 char* usb_device_get_product_name(struct usb_device *device)
388 struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc;
391 return usb_device_get_string(device, desc->iProduct);
396 char* usb_device_get_serial(struct usb_device *device)
398 struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc;
401 return usb_device_get_string(device, desc->iSerialNumber);
406 int usb_device_is_writeable(struct usb_device *device)
408 return device->writeable;
411 void usb_descriptor_iter_init(struct usb_device *device, struct usb_descriptor_iter *iter)
413 iter->config = device->desc;
414 iter->config_end = device->desc + device->desc_length;
415 iter->curr_desc = device->desc;
428 int usb_device_claim_interface(struct usb_device *device, unsigned int interface)
430 return ioctl(device->fd, USBDEVFS_CLAIMINTERFACE, &interface);
433 int usb_device_release_interface(struct usb_device *device, unsigned int interface)
435 return ioctl(device->fd, USBDEVFS_RELEASEINTERFACE, &interface);
438 int usb_device_connect_kernel_driver(struct usb_device *device,
446 return ioctl(device->fd, USBDEVFS_IOCTL, &ctl);
449 int usb_device_control_transfer(struct usb_device *device,
461 if (!usb_device_reopen_writeable(device))
472 return ioctl(device->fd, USBDEVFS_CONTROL, &ctrl);
475 int usb_device_bulk_transfer(struct usb_device *device,
492 return ioctl(device->fd, USBDEVFS_BULK, &ctrl);