Programmation système |
Classe | Description | Exemple |
00h | Inconnu | Spécifique |
01h | Audio | Carte son |
02h | Communications | Carte réseau |
03h | Human interface device (HID) | Clavier |
05h | Physical Interface Device (PID) | Equipement à retour de force |
06h | Image | Webcam |
07h | Printer | Imprimante |
08h | Mass storage | Clef USB |
09h | USB hub | Répéteur USB |
0Bh | Smart Card | Lecteur de carte |
0Dh | Content security | Lecteur d’empreinte digitale |
0Eh | Video | Webcam |
0Fh | Personal Healthcare | Tensiomètre |
E0h | Wireless Controller | Adaptateur Bluetooth |
# lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub Bus 001 Device 003: ID 13d3:5130 IMC Networks Bus 001 Device 004: ID 058f:6366 Alcor Micro Corp. Multi Flash Reader Bus 002 Device 003: ID 05fe:1958 Chic Technology Corp. Bus 002 Device 004: ID 13fe:1e00 Kingston Technology Company Inc.
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver ... ehci_hcd 0000:00:1a.0: new USB bus registered, assigned bus number 1 ... usb usb1: New USB device found, idVendor=1d6b, idProduct=0002 ... hub 1-0:1.0: USB hub found hub 1-0:1.0: 2 ports detected ... ehci_hcd 0000:00:1d.0: new USB bus registered, assigned bus number 2 ... hub 2-0:1.0: USB hub found hub 2-0:1.0: 2 ports detected ... hub 1-1:1.0: USB hub found hub 1-1:1.0: 6 ports detected ... hub 2-1:1.0: USB hub found hub 2-1:1.0: 8 ports detected
usb 1-1.2: new high speed USB device number 3 using ehci_hcd usb 1-1.2: New USB device found, idVendor=13d3, idProduct=5130 usb 1-1.2: New USB device strings: Mfr=2, Product=1, SerialNumber=0 usb 1-1.2: Product: USB 2.0 Camera
# lsusb -v -s 1:3 Bus 001 Device 003: ID 13d3:5130 IMC Networks Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 239 Miscellaneous Device bDeviceSubClass 2 ? bDeviceProtocol 1 Interface Association bMaxPacketSize0 64 idVendor 0x13d3 IMC Networks idProduct 0x5130 bcdDevice 12.11 iManufacturer 2 Sonix Technology Co., Ltd. iProduct 1 USB 2.0 Camera iSerial 0 bNumConfigurations 1 ... # ls -d /sys/bus/usb/devices/1-1.2* /sys/bus/usb/devices/1-1.2 /sys/bus/usb/devices/1-1.2:1.1 /sys/bus/usb/devices/1-1.2:1.0
Type (8 bits) IN|OUT | Adresse (7 bits) | Point d’accès (4 bits) | Somme de contrôle (5 bits) |
Type (8 bits) DATAx | Données (8 à 1024 octets) | Somme de contrôle (16 bits) |
Type (8 bits) ACK|NAK|STALL |
libusb_context *context; int status=libusb_init(&context); if(status!=0) {perror("libusb_init"); exit(-1);} /* ... some code ... */ libusb_exit(context);
libusb_device **list; ssize_t count=libusb_get_device_list(context,&list); if(count<0) {perror("libusb_get_device_list"); exit(-1);} ssize_t i=0; for(i=0;i<count;i++){ libusb_device *device=list[i]; struct libusb_device_descriptor desc; int status=libusb_get_device_descriptor(device,&desc); if(status!=0) continue; uint8_t bus=libusb_get_bus_number(device); uint8_t address=libusb_get_device_address(device); printf("Device Found @ (Bus:Address) %d:%d\n",bus,address); printf("Vendor ID 0x0%x\n",desc.idVendor); printf("Product ID 0x0%x\n",desc.idProduct); } libusb_free_device_list(list,1);
libusb_device_handle *handle; int status=libusb_open(device,&handle); if(status!=0){ perror("libusb_open"); exit(-1); } /* ... some ... code */ libusb_close(handle);
if(libusb_kernel_driver_active(handle,interface)){ int status=libusb_detach_kernel_driver(handle,interface); if(status!=0){ perror("libusb_detach_kernel_driver"); exit(-1); } }
int configuration=valueof("bConfigurationValue"); int status=libusb_set_configuration(handle,configuration); if(status!=0){ perror("libusb_set_configuration"); exit(-1); }
int interface=valueof("bInterfaceNumber"); int status=libusb_claim_interface(handle,interface); if(status!=0){ perror("libusb_claim_interface"); exit(-1); } /* ... some code ... */ status=libusb_release_interface(handle,interface); if(status!=0){ perror("libusb_release_interface"); exit(-1); }
int typ=LIBUSB_REQUEST_TYPE_xxx; /* see libusb.h */ int req=LIBUSB_REQUEST_yyy ; /* see libusb.h */ int val=...; /* parameter for req */ int ind=...; /* parameter for req */ char data[MAX_DATA]; /* data to send or to receive */ int size=...; /* size to send or maximum size to receive */ int timeout=...; /* timeout in ms */ int nb_bytes=libusb_control_transfer(handle,typ,req,val,ind,data,size,timeout);
int endpoint_out=...; /* ID of endpoint (bit 8 is 0) */ int endpoint_in=...; /* ID of endpoint (bit 8 is 1) */ char data[MAX_DATA]; /* data to send or to receive */ int size=...; /* size to send or maximum size to receive */ int timeout=...; /* timeout in ms */ /* OUT interrupt, from host to device */ int bytes_out; int status=libusb_interrupt_transfer(handle,endpoint_out,data,size,&bytes_out,timeout); if(status!=0){ perror("libusb_interrupt_transfer"); exit(-1); } /* IN interrupt, host polling device */ int bytes_in; int status=libusb_interrupt_transfer(handle,endpoint_in,data,size,&bytes_in,timeout); if(status!=0){ perror("libusb_interrupt_transfer"); exit(-1); }
int endpoint_out=...; /* ID of endpoint (bit 8 is 0) */ int endpoint_in=...; /* ID of endpoint (bit 8 is 1) */ char data[MAX_DATA]; /* data to send or to receive */ int size=...; /* size to send or maximum size to receive */ int timeout=...; /* timeout in ms */ /* OUT bulk transfer */ int bytes_out; int status=libusb_bulk_transfer(handle,endpoint_out,data,size,&bytes_out,timeout); if(status!=0){ perror("libusb_bulk_transfer"); exit(-1); } /* IN bulk transfer */ int bytes_in; int status=libusb_bulk_transfer(handle,endpoint_in,data,size,&bytes_in,timeout); if(status!=0){ perror("libusb_bulk_transfer"); exit(-1); }
Ce document a été traduit de LATEX par HEVEA