Changeset 47e3a8e in mainline for uspace/lib/usbvirt


Ignore:
Timestamp:
2010-10-15T16:32:57Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
186d630
Parents:
73301a0
Message:

Virtual USB device tracks its address

Now, each virtual device tracks its address and its state.

The virtual HC dispatches all transactions to all devices, thus
more precisely simulating situation on USB. The usbvirt framework
then decides whether it can accept the data or not, based on
their destination address.

Location:
uspace/lib/usbvirt
Files:
3 edited

Legend:

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

    r73301a0 r47e3a8e  
    106106} usbvirt_descriptors_t;
    107107
     108/** Possible states of virtual USB device.
     109 * Notice that these are not 1:1 mappings to those in USB specification.
     110 */
     111typedef enum {
     112        USBVIRT_STATE_DEFAULT,
     113        USBVIRT_STATE_ADDRESS,
     114        USBVIRT_STATE_CONFIGURED
     115} usbvirt_device_state_t;
    108116
     117/** Virtual USB device. */
    109118typedef struct usbvirt_device {
    110119        /** Callback device operations. */
     
    126135        usbvirt_descriptors_t *descriptors;
    127136       
     137        /** Current device state. */
     138        usbvirt_device_state_t state;
     139        /** Device address. */
     140        usb_address_t address;
    128141       
    129142        /* Private attributes. */
  • uspace/lib/usbvirt/main.c

    r73301a0 r47e3a8e  
    5050static void handle_data_to_device(ipc_callid_t iid, ipc_call_t icall)
    5151{
    52         usb_endpoint_t endpoint = IPC_GET_ARG1(icall);
     52        usb_address_t address = IPC_GET_ARG1(icall);
     53        usb_endpoint_t endpoint = IPC_GET_ARG2(icall);
     54       
     55        if (address != device->address) {
     56                ipc_answer_0(iid, EADDRNOTAVAIL);
     57                return;
     58        }
    5359       
    5460        size_t len;
     
    95101}
    96102
     103static void device_init(usbvirt_device_t *dev)
     104{
     105        dev->send_data = usbvirt_data_to_host;
     106        dev->state = USBVIRT_STATE_DEFAULT;
     107        dev->address = 0;
     108}
     109
    97110int usbvirt_data_to_host(struct usbvirt_device *dev,
    98111    usb_endpoint_t endpoint, void *buffer, size_t size)
     
    112125        int rc;
    113126       
    114         req = async_send_1(phone,
     127        req = async_send_2(phone,
    115128            IPC_M_USBVIRT_DATA_FROM_DEVICE,
     129            dev->address,
    116130            endpoint,
    117131            &answer_data);
     
    174188       
    175189        dev->vhcd_phone_ = hcd_phone;
    176         dev->send_data = usbvirt_data_to_host;
     190        device_init(dev);
    177191       
    178192        device = dev;
  • uspace/lib/usbvirt/stdreq.c

    r73301a0 r47e3a8e  
    118118       
    119119        /*
    120          * TODO: inform the HC that device has new address assigned.
     120         * TODO: handle when this request is invalid (e.g.
     121         * setting address when in configured state).
    121122         */
     123        if (new_address == 0) {
     124                device->state = USBVIRT_STATE_DEFAULT;
     125        } else {
     126                device->state = USBVIRT_STATE_ADDRESS;
     127        }
     128       
     129        device->address = new_address;
     130       
    122131        return EOK;
    123132}
Note: See TracChangeset for help on using the changeset viewer.