ugen - USB generic device support
device ugen
Alternatively, to load the driver as a module at boot time, place the following line in loader.conf5:
ugen_load="YES"
There can be up to 127 USB devices connected to a USB bus. Each USB device can have up to 16 endpoints. Each of these endpoints will communicate in one of four different modes: control, isochronous, bulk, or interrupt. Each of the endpoints will have a different device node. The four least significant bits in the minor device number determines which endpoint the device accesses and the rest of the bits determines which USB device.
If an endpoint address is used both for input and output the device can be opened for both read or write.
To find out what endpoints that exist there are a series of ioctl(2) operation on the control endpoint that returns the USB descriptors of the device, configurations, interfaces, and endpoints.
The control transfer mode can only happen on the control endpoint which is always endpoint 0. The control endpoint accepts request and may respond with an answer to such request. Control request are issued by ioctl(2) calls.
The bulk transfer mode can be in or out depending on the endpoint. To perform I/O on a bulk endpoint read(2) and write(2) should be used. All I/O operations on a bulk endpoint are unbuffered.
The interrupt transfer mode can be in or out depending on the endpoint. To perform I/O on an interrupt endpoint read(2) and write(2) should be used. A moderate amount of buffering is done by the driver.
All endpoints handle the following ioctl(2) calls:
The control endpoint (endpoint 0) handles the following ioctl(2) calls:
This operation can only be performed when the control endpoint is the sole open endpoint.
struct usb_alt_interface { int uai_config_index; int uai_interface_index; int uai_alt_no; };
This operation can only be performed when no endpoints for the interface are open.
struct usb_config_desc { int ucd_config_index; usb_config_descriptor_t ucd_desc; };
struct usb_interface_desc { int uid_config_index; int uid_interface_index; int uid_alt_index; usb_interface_descriptor_t uid_desc; };
struct usb_endpoint_desc { int ued_config_index; int ued_interface_index; int ued_alt_index; int ued_endpoint_index; usb_endpoint_descriptor_t ued_desc; };
struct usb_full_desc { int ufd_config_index; u_int ufd_size; u_char *ufd_data; };The ufd_data field should point to a memory area of the size given in the ufd_size field. The proper size can be determined by first issuing a USB_GET_CONFIG_DESC and inspecting the wTotalLength field.
struct usb_string_desc { int usd_string_index; int usd_language_id; usb_string_descriptor_t usd_desc; };
struct usb_ctl_request { int ucr_addr; usb_device_request_t ucr_request; void *ucr_data; int ucr_flags; #define USBD_SHORT_XFER_OK 0x04 /* allow short reads */ int ucr_actlen; /* actual length transferred */ };This is a dangerous operation in that it can perform arbitrary operations on the device. Some of the most dangerous (e.g., changing the device address) are not allowed.
Note that there are two different ways of addressing configurations, interfaces, alternatives, and endpoints: by index or by number. The index is the ordinal number (starting from 0) of the descriptor as presented by the device. The number is the respective number of the entity as found in its descriptor. Enumeration of descriptors use the index, getting and setting typically uses numbers.
Example: all endpoints (except the control endpoint) for the current configuration can be found by iterating the interface_index from 0 to config_desc->bNumInterface -1 and for each of these iterating the endpoint_index from 0 to interface_desc->bNumEndpoints The config_index should set to USB_CURRENT_CONFIG_INDEX and alt_index should be set to USB_CURRENT_ALT_INDEX
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |