Ignore:
Timestamp:
2010-12-17T10:14:01Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6e5dc07
Parents:
9223dc5c (diff), 11658b64 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge with usb/development

File:
1 moved

Legend:

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

    r9223dc5c rf2962621  
    4040#include <usb/devreq.h>
    4141
     42/** Request type of a control transfer. */
     43typedef enum {
     44        /** Standard USB request. */
     45        USBVIRT_REQUEST_TYPE_STANDARD = 0,
     46        /** Standard class USB request. */
     47        USBVIRT_REQUEST_TYPE_CLASS = 1
     48} usbvirt_request_type_t;
     49
     50/** Recipient of control request. */
     51typedef enum {
     52        /** Device is the recipient of the control request. */
     53        USBVIRT_REQUEST_RECIPIENT_DEVICE = 0,
     54        /** Interface is the recipient of the control request. */
     55        USBVIRT_REQUEST_RECIPIENT_INTERFACE = 1,
     56        /** Endpoint is the recipient of the control request. */
     57        USBVIRT_REQUEST_RECIPIENT_ENDPOINT = 2,
     58        /** Other part of the device is the recipient of the control request. */
     59        USBVIRT_REQUEST_RECIPIENT_OTHER = 3
     60} usbvirt_request_recipient_t;
     61
     62/** Possible states of virtual USB device.
     63 * Notice that these are not 1:1 mappings to those in USB specification.
     64 */
     65typedef enum {
     66        /** Default state, device listens at default address. */
     67        USBVIRT_STATE_DEFAULT,
     68        /** Device has non-default address assigned. */
     69        USBVIRT_STATE_ADDRESS,
     70        /** Device is configured. */
     71        USBVIRT_STATE_CONFIGURED
     72} usbvirt_device_state_t;
     73
    4274typedef struct usbvirt_device usbvirt_device_t;
    4375struct usbvirt_control_transfer;
     
    4779        uint8_t *data);
    4880
    49 /** Callbacks for standard device requests.
    50  * When these functions are NULL or return EFORWARD, this
    51  * framework will try to satisfy the request by itself.
    52  */
    53 typedef struct {
    54         usbvirt_on_device_request_t on_get_status;
    55         usbvirt_on_device_request_t on_clear_feature;
    56         usbvirt_on_device_request_t on_set_feature;
    57         usbvirt_on_device_request_t on_set_address;
    58         usbvirt_on_device_request_t on_get_descriptor;
    59         usbvirt_on_device_request_t on_set_descriptor;
    60         usbvirt_on_device_request_t on_get_configuration;
    61         usbvirt_on_device_request_t on_set_configuration;
    62         usbvirt_on_device_request_t on_get_interface;
    63         usbvirt_on_device_request_t on_set_interface;
    64         usbvirt_on_device_request_t on_synch_frame;
    65 } usbvirt_standard_device_request_ops_t;
     81/** Callback for control request over pipe zero.
     82 *
     83 * @param dev Virtual device answering the call.
     84 * @param request Request setup packet.
     85 * @param data Data when DATA stage is present.
     86 * @return Error code.
     87 */
     88typedef int (*usbvirt_control_request_callback_t)(usbvirt_device_t *dev,
     89        usb_device_request_setup_packet_t *request,
     90        uint8_t *data);
     91
     92/** Handler for control transfer on endpoint zero. */
     93typedef struct {
     94        /** Request type bitmap.
     95         * Use USBVIRT_MAKE_CONTROL_REQUEST_TYPE for creating the bitmap.
     96         */
     97        uint8_t request_type;
     98        /** Request code. */
     99        uint8_t request;
     100        /** Request name for debugging. */
     101        const char *name;
     102        /** Callback for the request.
     103         * NULL value here announces end of a list.
     104         */
     105        usbvirt_control_request_callback_t callback;
     106} usbvirt_control_transfer_handler_t;
     107
     108/** Create control request type bitmap.
     109 *
     110 * @param direction Transfer direction (use usb_direction_t).
     111 * @param type Request type (use usbvirt_request_type_t).
     112 * @param recipient Recipient of the request (use usbvirt_request_recipient_t).
     113 * @return Request type bitmap.
     114 */
     115#define USBVIRT_MAKE_CONTROL_REQUEST_TYPE(direction, type, recipient) \
     116        ((((direction) == USB_DIRECTION_IN) ? 1 : 0) << 7) \
     117        | (((type) & 3) << 5) \
     118        | (((recipient) & 31))
     119
     120/** Create last item in an array of control request handlers. */
     121#define USBVIRT_CONTROL_TRANSFER_HANDLER_LAST { 0, 0, NULL, NULL }
    66122
    67123/** Device operations. */
    68124typedef struct {
    69         /** Callbacks for standard deivce requests. */
    70         usbvirt_standard_device_request_ops_t *standard_request_ops;
    71         /** Callback for class-specific USB request. */
    72         usbvirt_on_device_request_t on_class_device_request;
    73        
     125        /** Callbacks for transfers over control pipe zero. */
     126        usbvirt_control_transfer_handler_t *control_transfer_handlers;
     127
    74128        int (*on_control_transfer)(usbvirt_device_t *dev,
    75129            usb_endpoint_t endpoint, struct usbvirt_control_transfer *transfer);
     
    86140        usb_direction_t (*decide_control_transfer_direction)(
    87141            usb_endpoint_t endpoint, void *buffer, size_t size);
     142
     143        /** Callback when device changes its state.
     144         *
     145         * It is correct that this function is called when both states
     146         * are equal (e.g. this function is called during SET_CONFIGURATION
     147         * request done on already configured device).
     148         *
     149         * @warning The value of <code>dev->state</code> before calling
     150         * this function is not specified (i.e. can be @p old_state or
     151         * @p new_state).
     152         */
     153        void (*on_state_change)(usbvirt_device_t *dev,
     154            usbvirt_device_state_t old_state, usbvirt_device_state_t new_state);
    88155} usbvirt_device_ops_t;
    89156
     
    120187        uint8_t current_configuration;
    121188} usbvirt_descriptors_t;
    122 
    123 /** Possible states of virtual USB device.
    124  * Notice that these are not 1:1 mappings to those in USB specification.
    125  */
    126 typedef enum {
    127         USBVIRT_STATE_DEFAULT,
    128         USBVIRT_STATE_ADDRESS,
    129         USBVIRT_STATE_CONFIGURED
    130 } usbvirt_device_state_t;
    131189
    132190/** Information about on-going control transfer.
     
    157215        usbvirt_device_ops_t *ops;
    158216       
     217        /** Custom device data. */
     218        void *device_data;
     219
    159220        /** Reply onto control transfer.
    160221         */
Note: See TracChangeset for help on using the changeset viewer.