Files | |
file | ctrltransfer.c |
Control transfer handling. | |
file | device.c |
Virtual USB device main routines. | |
file | device.h |
Virtual USB device. | |
file | ipc.h |
IPC wrappers for virtual USB. | |
file | ipc_dev.c |
IPC wrappers, device side. | |
file | ipc_hc.c |
IPC wrappers, host controller side. | |
file | private.h |
Private definitions. | |
file | stdreq.c |
Standard control request handlers. | |
file | transfer.c |
Transfer handling. | |
Data Structures | |
struct | usbvirt_control_request_handler_t |
Callback for control request on a virtual USB device. More... | |
struct | usbvirt_descriptors_t |
Standard USB descriptors for virtual device. More... | |
struct | usbvirt_device |
Virtual USB device. More... | |
struct | usbvirt_device_configuration_extras_t |
Extra configuration data for GET_CONFIGURATION request. More... | |
struct | usbvirt_device_configuration_t |
Single device configuration. More... | |
struct | usbvirt_device_ops_t |
Ops structure for virtual USB device. More... | |
Defines | |
#define | USBVIRT_ENDPOINT_MAX 16 |
Maximum number of endpoints supported by virtual USB. | |
Typedefs | |
typedef usbvirt_device | usbvirt_device_t |
typedef int(*) | usbvirt_on_control_t (usbvirt_device_t *dev, const usb_device_request_setup_packet_t *setup_packet, uint8_t *data, size_t *act_data_size) |
Callback for control transfer on endpoint zero. | |
typedef int(*) | usbvirt_on_data_from_device_t (usbvirt_device_t *dev, usb_endpoint_t endpoint, usb_transfer_type_t transfer_type, void *buffer, size_t buffer_size, size_t *act_buffer_size) |
Callback for data from device (IN transaction). | |
typedef int(*) | usbvirt_on_data_to_device_t (usbvirt_device_t *dev, usb_endpoint_t endpoint, usb_transfer_type_t transfer_type, void *buffer, size_t buffer_size) |
Callback for data to device (OUT transaction). | |
Enumerations | |
enum | usbvirt_device_state_t { USBVIRT_STATE_DEFAULT, USBVIRT_STATE_ADDRESS, USBVIRT_STATE_CONFIGURED } |
Possible states of virtual USB device. More... | |
enum | usbvirt_hc_to_device_method_t |
IPC methods communication between host controller and virtual device. | |
Functions | |
static void | callback_connection (ipc_callid_t iid, ipc_call_t *icall) |
Main IPC call handling from virtual host controller. | |
static void | ipc_control_read (usbvirt_device_t *dev, ipc_callid_t iid, ipc_call_t *icall) |
Handle VHC request for control read from the device. | |
static void | ipc_control_write (usbvirt_device_t *dev, ipc_callid_t iid, ipc_call_t *icall) |
Handle VHC request for control write to the device. | |
static void | ipc_data_in (usbvirt_device_t *dev, usb_transfer_type_t transfer_type, ipc_callid_t iid, ipc_call_t *icall) |
Handle VHC request for data read from the device (in transfer). | |
static void | ipc_data_out (usbvirt_device_t *dev, usb_transfer_type_t transfer_type, ipc_callid_t iid, ipc_call_t *icall) |
Handle VHC request for data write to the device (out transfer). | |
static void | ipc_get_name (usbvirt_device_t *dev, ipc_callid_t iid, ipc_call_t *icall) |
Handle VHC request for device name. | |
int | process_control_transfer (usbvirt_device_t *dev, usbvirt_control_request_handler_t *control_handlers, usb_device_request_setup_packet_t *setup, uint8_t *data, size_t *data_sent_size) |
Find and execute control transfer handler for virtual USB device. | |
static int | req_get_descriptor (usbvirt_device_t *device, const usb_device_request_setup_packet_t *setup_packet, uint8_t *data, size_t *act_size) |
GET_DESCRIPTOR handler. | |
static int | req_set_address (usbvirt_device_t *device, const usb_device_request_setup_packet_t *setup_packet, uint8_t *data, size_t *act_size) |
static int | req_set_configuration (usbvirt_device_t *device, const usb_device_request_setup_packet_t *setup_packet, uint8_t *data, size_t *act_size) |
int | usbvirt_control_read (usbvirt_device_t *dev, void *setup, size_t setup_size, void *data, size_t data_size, size_t *data_size_sent) |
Issue a control read transfer to virtual USB device. | |
void | usbvirt_control_reply_helper (const usb_device_request_setup_packet_t *setup_packet, uint8_t *data, size_t *act_size, void *actual_data, size_t actual_data_size) |
Helper for replying to control read transfer from virtual USB device. | |
static int | usbvirt_control_transfer (usbvirt_device_t *dev, void *setup, size_t setup_size, void *data, size_t data_size, size_t *data_size_sent) |
Process a control transfer to the virtual USB device. | |
int | usbvirt_control_write (usbvirt_device_t *dev, void *setup, size_t setup_size, void *data, size_t data_size) |
Issue a control write transfer to virtual USB device. | |
int | usbvirt_data_in (usbvirt_device_t *dev, usb_transfer_type_t transf_type, usb_endpoint_t endpoint, void *data, size_t data_size, size_t *data_size_sent) |
Request data from virtual USB device. | |
int | usbvirt_data_out (usbvirt_device_t *dev, usb_transfer_type_t transf_type, usb_endpoint_t endpoint, void *data, size_t data_size) |
Send data to virtual USB device. | |
int | usbvirt_device_plug (usbvirt_device_t *dev, const char *vhc_path) |
Connect the device to the virtual host controller. | |
void | usbvirt_device_unplug (usbvirt_device_t *dev) |
Disconnect the device from virtual host controller. | |
bool | usbvirt_ipc_handle_call (usbvirt_device_t *dev, ipc_callid_t callid, ipc_call_t *call) |
Handle incoming IPC call for virtual USB device. | |
int | usbvirt_ipc_send_control_read (int phone, void *setup_buffer, size_t setup_buffer_size, void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size) |
Send control read transfer to virtual USB device. | |
int | usbvirt_ipc_send_control_write (int phone, void *setup_buffer, size_t setup_buffer_size, void *data_buffer, size_t data_buffer_size) |
Send control write transfer to virtual USB device. | |
int | usbvirt_ipc_send_data_in (int phone, usb_endpoint_t ep, usb_transfer_type_t tr_type, void *data, size_t data_size, size_t *act_size) |
Request data transfer from virtual USB device. | |
int | usbvirt_ipc_send_data_out (int phone, usb_endpoint_t ep, usb_transfer_type_t tr_type, void *data, size_t data_size) |
Send data to virtual USB device. | |
Variables | |
static usbvirt_device_t * | DEV = NULL |
Current device. | |
usbvirt_control_request_handler_t | library_handlers [] |
Standard request handlers. | |
usbvirt_control_request_handler_t | library_handlers [] |
Standard request handlers. |
typedef int(*) usbvirt_on_control_t(usbvirt_device_t *dev, const usb_device_request_setup_packet_t *setup_packet, uint8_t *data, size_t *act_data_size) |
Callback for control transfer on endpoint zero.
Notice that size of the data buffer is expected to be read from the setup packet.
dev | Virtual device to which the transaction belongs. | |
setup_packet | Standard setup packet. | |
data | Data (might be NULL). | |
act_data_size | Size of returned data in bytes. |
typedef int(*) usbvirt_on_data_from_device_t(usbvirt_device_t *dev, usb_endpoint_t endpoint, usb_transfer_type_t transfer_type, void *buffer, size_t buffer_size, size_t *act_buffer_size) |
Callback for data from device (IN transaction).
dev | Virtual device to which the transaction belongs. | |
endpoint | Target endpoint number. | |
transfer_type | Transfer type. | |
buffer | Data buffer to write answer to. | |
buffer_size | Size of the buffer in bytes. | |
act_buffer_size | Write here how many bytes were actually written. |
typedef int(*) usbvirt_on_data_to_device_t(usbvirt_device_t *dev, usb_endpoint_t endpoint, usb_transfer_type_t transfer_type, void *buffer, size_t buffer_size) |
Possible states of virtual USB device.
Notice that these are not 1:1 mappings to those in USB specification.
static void callback_connection | ( | ipc_callid_t | iid, | |
ipc_call_t * | icall | |||
) | [static] |
static void ipc_control_read | ( | usbvirt_device_t * | dev, | |
ipc_callid_t | iid, | |||
ipc_call_t * | icall | |||
) | [static] |
static void ipc_control_write | ( | usbvirt_device_t * | dev, | |
ipc_callid_t | iid, | |||
ipc_call_t * | icall | |||
) | [static] |
static void ipc_data_in | ( | usbvirt_device_t * | dev, | |
usb_transfer_type_t | transfer_type, | |||
ipc_callid_t | iid, | |||
ipc_call_t * | icall | |||
) | [static] |
static void ipc_data_out | ( | usbvirt_device_t * | dev, | |
usb_transfer_type_t | transfer_type, | |||
ipc_callid_t | iid, | |||
ipc_call_t * | icall | |||
) | [static] |
static void ipc_get_name | ( | usbvirt_device_t * | dev, | |
ipc_callid_t | iid, | |||
ipc_call_t * | icall | |||
) | [static] |
int process_control_transfer | ( | usbvirt_device_t * | dev, | |
usbvirt_control_request_handler_t * | control_handlers, | |||
usb_device_request_setup_packet_t * | setup, | |||
uint8_t * | data, | |||
size_t * | data_sent_size | |||
) |
Find and execute control transfer handler for virtual USB device.
dev | Target virtual device. | |
control_handlers | Array of control request handlers. | |
setup | Setup packet. | |
data | Extra data. | |
data_sent_size | Size of extra data in bytes. |
EFORWARD | No suitable handler found. |
Definition at line 51 of file ctrltransfer.c.
int usbvirt_control_read | ( | usbvirt_device_t * | dev, | |
void * | setup, | |||
size_t | setup_size, | |||
void * | data, | |||
size_t | data_size, | |||
size_t * | data_size_sent | |||
) |
Issue a control read transfer to virtual USB device.
dev | Target virtual device. | |
setup | Setup data. | |
setup_size | Size of setup packet. | |
data | Extra data (DATA stage). | |
data_size | Size of extra data buffer in bytes. | |
data_size_sent | Number of actually send bytes during the transfer. |
Definition at line 121 of file transfer.c.
void usbvirt_control_reply_helper | ( | const usb_device_request_setup_packet_t * | setup_packet, | |
uint8_t * | data, | |||
size_t * | act_size, | |||
void * | actual_data, | |||
size_t | actual_data_size | |||
) |
Helper for replying to control read transfer from virtual USB device.
This function takes care of copying data to answer buffer taking care of buffer sizes properly.
setup_packet | The setup packet. | |
data | Data buffer to write to. | |
act_size | Where to write actual size of returned data. | |
actual_data | Data to be returned. | |
actual_data_size | Size of answer data (actual_data ) in bytes. |
static int usbvirt_control_transfer | ( | usbvirt_device_t * | dev, | |
void * | setup, | |||
size_t | setup_size, | |||
void * | data, | |||
size_t | data_size, | |||
size_t * | data_size_sent | |||
) | [static] |
Process a control transfer to the virtual USB device.
dev | Target device. | |
setup | Setup packet data. | |
setup_size | Size of setup packet. | |
data | Extra data (DATA stage). | |
data_size | Size of extra data in bytes. | |
data_size_sent | Number of actually send bytes during the transfer (only used for READ transfers). |
Definition at line 52 of file transfer.c.
int usbvirt_control_write | ( | usbvirt_device_t * | dev, | |
void * | setup, | |||
size_t | setup_size, | |||
void * | data, | |||
size_t | data_size | |||
) |
Issue a control write transfer to virtual USB device.
dev | Target virtual device. | |
setup | Setup data. | |
setup_size | Size of setup packet. | |
data | Extra data (DATA stage). | |
data_size | Size of extra data buffer in bytes. |
Definition at line 102 of file transfer.c.
int usbvirt_data_in | ( | usbvirt_device_t * | dev, | |
usb_transfer_type_t | transf_type, | |||
usb_endpoint_t | endpoint, | |||
void * | data, | |||
size_t | data_size, | |||
size_t * | data_size_sent | |||
) |
Request data from virtual USB device.
dev | Target virtual device. | |
transf_type | Transfer type (interrupt, bulk). | |
endpoint | Endpoint number. | |
data | Where to stored data the device returns to the driver. | |
data_size | Size of the data buffer in bytes. | |
data_size_sent | Number of actually written bytes. |
Definition at line 163 of file transfer.c.
int usbvirt_data_out | ( | usbvirt_device_t * | dev, | |
usb_transfer_type_t | transf_type, | |||
usb_endpoint_t | endpoint, | |||
void * | data, | |||
size_t | data_size | |||
) |
Send data to virtual USB device.
dev | Target virtual device. | |
transf_type | Transfer type (interrupt, bulk). | |
endpoint | Endpoint number. | |
data | Data sent from the driver to the device. | |
data_size | Size of the data buffer in bytes. |
Definition at line 137 of file transfer.c.
int usbvirt_device_plug | ( | usbvirt_device_t * | dev, | |
const char * | vhc_path | |||
) |
void usbvirt_device_unplug | ( | usbvirt_device_t * | dev | ) |
bool usbvirt_ipc_handle_call | ( | usbvirt_device_t * | dev, | |
ipc_callid_t | callid, | |||
ipc_call_t * | call | |||
) |
int usbvirt_ipc_send_control_read | ( | int | phone, | |
void * | setup_buffer, | |||
size_t | setup_buffer_size, | |||
void * | data_buffer, | |||
size_t | data_buffer_size, | |||
size_t * | data_transfered_size | |||
) |
Send control read transfer to virtual USB device.
phone | IPC phone to the virtual device. | |
ep | Target endpoint number. | |
setup_buffer | Setup buffer. | |
setup_buffer_size | Setup buffer size in bytes. | |
data_buffer | Data buffer (DATA stage of control transfer). | |
data_buffer_size | Size of data buffer in bytes. | |
data_transfered_size | Number of actually transferred bytes. |
int usbvirt_ipc_send_control_write | ( | int | phone, | |
void * | setup_buffer, | |||
size_t | setup_buffer_size, | |||
void * | data_buffer, | |||
size_t | data_buffer_size | |||
) |
Send control write transfer to virtual USB device.
phone | IPC phone to the virtual device. | |
ep | Target endpoint number. | |
setup_buffer | Setup buffer. | |
setup_buffer_size | Setup buffer size in bytes. | |
data_buffer | Data buffer (DATA stage of control transfer). | |
data_buffer_size | Size of data buffer in bytes. |
int usbvirt_ipc_send_data_in | ( | int | phone, | |
usb_endpoint_t | ep, | |||
usb_transfer_type_t | tr_type, | |||
void * | data, | |||
size_t | data_size, | |||
size_t * | act_size | |||
) |
Request data transfer from virtual USB device.
phone | IPC phone to the virtual device. | |
ep | Target endpoint number. | |
tr_type | Transfer type (interrupt or bulk). | |
data | Data buffer. | |
data_size | Size of the data buffer in bytes. | |
act_size | Number of actually returned bytes. |
int usbvirt_ipc_send_data_out | ( | int | phone, | |
usb_endpoint_t | ep, | |||
usb_transfer_type_t | tr_type, | |||
void * | data, | |||
size_t | data_size | |||
) |