Changeset ca07cd3 in mainline for uspace/lib/usbvirt/transaction.c


Ignore:
Timestamp:
2010-10-25T13:23:33Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
23cb44b
Parents:
355f7c2
Message:

Code cleanup, various bugfixes

The internal functions of virtual device framework always get
device structure as parameter, thus possible enabling more devices
within single task (that is not possible because currently there
is no way to pass extra argument into callback_connection()).

Also, added some missing comments and completely removed the device
id nonsense (devices can send their descriptors and the hub is able
to enable/disable its ports).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbvirt/transaction.c

    r355f7c2 rca07cd3  
    3838#include <mem.h>
    3939
    40 #include "ids.h"
     40#include "hub.h"
    4141#include "private.h"
    4242
    43 static usb_direction_t setup_transaction_direction(usb_endpoint_t, void *, size_t);
    44 static void process_control_transfer(usb_endpoint_t, usbvirt_control_transfer_t *);
     43static usb_direction_t setup_transaction_direction(usbvirt_device_t *,
     44    usb_endpoint_t, void *, size_t);
     45static void process_control_transfer(usbvirt_device_t *,
     46    usb_endpoint_t, usbvirt_control_transfer_t *);
    4547
    4648/** Convert virtual USB transaction type to string.
     
    6062}
    6163
     64/** SETUP transaction handling.
     65 * The setup transaction only prepares control transfer on given endpoint.
     66 */
    6267int transaction_setup(usbvirt_device_t *device, usb_endpoint_t endpoint,
    6368    void *buffer, size_t size)
     
    7277        }
    7378       
    74         transfer->direction = setup_transaction_direction(endpoint,
     79        transfer->direction = setup_transaction_direction(device, endpoint,
    7580            buffer, size);
    7681        transfer->request = buffer;
     
    7984        transfer->data_size = 0;
    8085       
     86        if (transfer->direction == USB_DIRECTION_IN) {
     87                process_control_transfer(device, endpoint, transfer);
     88        }
     89       
    8190        return EOK;
    8291}
    8392
     93/** OUT transaction handling.
     94 * The OUT transaction can trigger processing of a control transfer.
     95 */
    8496int transaction_out(usbvirt_device_t *device, usb_endpoint_t endpoint,
    8597    void *buffer, size_t size)
     
    133145}
    134146
     147/** IN transaction handling.
     148 * The IN transaction can trigger processing of a control transfer.
     149 */
    135150int transaction_in(usbvirt_device_t *device, usb_endpoint_t endpoint,
    136151    void *buffer, size_t size, size_t *data_size)
     
    145160                         * This means end of input data.
    146161                         */
    147                         process_control_transfer(endpoint, transfer);
     162                        process_control_transfer(device, endpoint, transfer);
    148163                } else {
    149164                        /*
     
    151166                         * of the buffer.
    152167                         */
    153                         // TODO: implement
     168                        // FIXME: handle when the HC wants the data back
     169                        // in more chunks
     170                        size_t actual_size = 0;
     171                        if (transfer->data) {
     172                                actual_size = transfer->data_size;
     173                        }
     174                        if (actual_size > size) {
     175                                actual_size = size;
     176                        }
     177                        if (actual_size > 0) {
     178                                memcpy(buffer, transfer->data, actual_size);
     179                                if (data_size) {
     180                                        *data_size = actual_size;
     181                                }
     182                        }
    154183                }
    155184               
     
    170199}
    171200
    172 
    173 static usb_direction_t setup_transaction_direction(usb_endpoint_t endpoint,
     201/** Determine direction of control transfer.
     202 * First, try the user provided callback, otherwise guess, believing that
     203 * it uses the same format as control pipe 0.
     204 */
     205static usb_direction_t setup_transaction_direction(usbvirt_device_t *device,
     206    usb_endpoint_t endpoint,
    174207    void *data, size_t size)
    175208{
     
    202235}
    203236
    204 static void process_control_transfer(usb_endpoint_t endpoint,
     237/** Process control transfer.
     238 */
     239static void process_control_transfer(usbvirt_device_t *device,
     240    usb_endpoint_t endpoint,
    205241    usbvirt_control_transfer_t *transfer)
    206242{
     
    213249        if (rc == EFORWARD) {
    214250                if (endpoint == 0) {
    215                         rc = control_pipe(transfer);
     251                        rc = control_pipe(device, transfer);
    216252                }
    217253        }
Note: See TracChangeset for help on using the changeset viewer.