Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbvirt/include/usbvirt/device.h

    rbeee81a r6cb58e6  
    3131 */
    3232/** @file
    33  * Virtual USB device.
     33 * @brief Virtual USB device.
    3434 */
    3535#ifndef LIBUSBVIRT_DEVICE_H_
     
    3939#include <usb/request.h>
    4040
    41 /** Maximum number of endpoints supported by virtual USB. */
    4241#define USBVIRT_ENDPOINT_MAX 16
    4342
    4443typedef struct usbvirt_device usbvirt_device_t;
    4544
    46 /** Callback for data to device (OUT transaction).
    47  *
    48  * @param dev Virtual device to which the transaction belongs.
    49  * @param endpoint Target endpoint number.
    50  * @param transfer_type Transfer type.
    51  * @param buffer Data buffer.
    52  * @param buffer_size Size of the buffer in bytes.
    53  * @return Error code.
    54  */
    55 typedef int (*usbvirt_on_data_to_device_t)(usbvirt_device_t *dev,
    56     usb_endpoint_t endpoint, usb_transfer_type_t transfer_type,
    57     void *buffer, size_t buffer_size);
     45typedef int (*usbvirt_on_data_to_device_t)(usbvirt_device_t *, usb_endpoint_t,
     46    usb_transfer_type_t, void *, size_t);
     47typedef int (*usbvirt_on_data_from_device_t)(usbvirt_device_t *, usb_endpoint_t,
     48    usb_transfer_type_t, void *, size_t, size_t *);
     49typedef int (*usbvirt_on_control_t)(usbvirt_device_t *,
     50    const usb_device_request_setup_packet_t *, uint8_t *, size_t *);
    5851
    59 /** Callback for data from device (IN transaction).
    60  *
    61  * @param dev Virtual device to which the transaction belongs.
    62  * @param endpoint Target endpoint number.
    63  * @param transfer_type Transfer type.
    64  * @param buffer Data buffer to write answer to.
    65  * @param buffer_size Size of the buffer in bytes.
    66  * @param act_buffer_size Write here how many bytes were actually written.
    67  * @return Error code.
    68  */
    69 typedef int (*usbvirt_on_data_from_device_t)(usbvirt_device_t *dev,
    70     usb_endpoint_t endpoint, usb_transfer_type_t transfer_type,
    71     void *buffer, size_t buffer_size, size_t *act_buffer_size);
    72 
    73 /** Callback for control transfer on endpoint zero.
    74  *
    75  * Notice that size of the data buffer is expected to be read from the
    76  * setup packet.
    77  *
    78  * @param dev Virtual device to which the transaction belongs.
    79  * @param setup_packet Standard setup packet.
    80  * @param data Data (might be NULL).
    81  * @param act_data_size Size of returned data in bytes.
    82  * @return Error code.
    83  */
    84 typedef int (*usbvirt_on_control_t)(usbvirt_device_t *dev,
    85     const usb_device_request_setup_packet_t *setup_packet,
    86     uint8_t *data, size_t *act_data_size);
    87 
    88 /** Callback for control request on a virtual USB device.
    89  *
    90  * See usbvirt_control_reply_helper() for simple way of answering
    91  * control read requests.
    92  */
    9352typedef struct {
    94         /** Request direction (in or out). */
    9553        usb_direction_t req_direction;
    96         /** Request recipient (device, interface or endpoint). */
    9754        usb_request_recipient_t req_recipient;
    98         /** Request type (standard, class or vendor). */
    9955        usb_request_type_t req_type;
    100         /** Actual request code. */
    10156        uint8_t request;
    102         /** Request handler name for debugging purposes. */
    10357        const char *name;
    104         /** Callback to be executed on matching request. */
    10558        usbvirt_on_control_t callback;
    10659} usbvirt_control_request_handler_t;
     
    12477} usbvirt_device_configuration_t;
    12578
    126 /** Standard USB descriptors for virtual device. */
     79/** Standard USB descriptors. */
    12780typedef struct {
    12881        /** Standard device descriptor.
     
    149102} usbvirt_device_state_t;
    150103
    151 /** Ops structure for virtual USB device. */
    152104typedef struct {
    153         /** Callbacks for data to device.
    154          * Index zero is ignored.
    155          */
    156105        usbvirt_on_data_to_device_t data_out[USBVIRT_ENDPOINT_MAX];
    157         /** Callbacks for data from device.
    158          * Index zero is ignored.
    159          */
    160106        usbvirt_on_data_from_device_t data_in[USBVIRT_ENDPOINT_MAX];
    161         /** Array of control handlers.
    162          * Last handler is expected to have the @c callback field set to NULL
    163          */
    164107        usbvirt_control_request_handler_t *control;
    165         /** Callback when device changes state.
    166          *
    167          * The value of @c state attribute of @p dev device is not
    168          * defined during call of this function.
    169          *
    170          * @param dev The virtual USB device.
    171          * @param old_state Old device state.
    172          * @param new_state New device state.
    173          */
    174108        void (*state_changed)(usbvirt_device_t *dev,
    175109            usbvirt_device_state_t old_state, usbvirt_device_state_t new_state);
    176110} usbvirt_device_ops_t;
    177111
    178 /** Virtual USB device. */
    179112struct usbvirt_device {
    180         /** Name for debugging purposes. */
    181113        const char *name;
    182         /** Custom device data. */
    183114        void *device_data;
    184         /** Device ops. */
    185115        usbvirt_device_ops_t *ops;
    186         /** Device descriptors. */
    187116        usbvirt_descriptors_t *descriptors;
    188         /** Current device address.
    189          * You shall treat this field as read only in your code.
    190          */
    191117        usb_address_t address;
    192         /** Current device state.
    193          * You shall treat this field as read only in your code.
    194          */
    195118        usbvirt_device_state_t state;
    196         /** Phone to the host controller.
    197          * You shall treat this field as read only in your code.
    198          */
    199         int vhc_phone;
    200119};
    201120
    202121int usbvirt_device_plug(usbvirt_device_t *, const char *);
    203 void usbvirt_device_unplug(usbvirt_device_t *);
    204122
    205123void usbvirt_control_reply_helper(const usb_device_request_setup_packet_t *,
Note: See TracChangeset for help on using the changeset viewer.