Changeset 2c381250 in mainline


Ignore:
Timestamp:
2010-10-13T06:49:48Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7da3219
Parents:
fd17ab5
Message:

virtusb: add get_descriptor(config) handling

The virtusb framework is now able to handle the standard request for
obtaining configuration descriptor. This includes sending extra data
such as interface or endpoint descriptor.

Using this approach, the virtual keyboard sends also its HID descriptor.

Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/virtusbkbd/kbdconfig.c

    rfd17ab5 r2c381250  
    3535 */
    3636#include "kbdconfig.h"
     37#include <usb/hcd.h>
     38#include <usb/hid.h>
    3739#include <usb/hidut.h>
    3840#include <usb/classes.h>
    3941
    4042/** Standard device descriptor. */
    41 usb_standard_device_descriptor_t std_descriptor = {
     43usb_standard_device_descriptor_t std_device_descriptor = {
    4244        .length = sizeof(usb_standard_device_descriptor_t),
    43         .descriptor_type = 1,
     45        .descriptor_type = USB_DESCTYPE_DEVICE,
    4446        .usb_spec_version = 0x110,
    45         .device_class = USB_CLASS_HID,
     47        .device_class = USB_CLASS_USE_INTERFACE,
    4648        .device_subclass = 0,
    4749        .device_protocol = 0,
     
    4951        .configuration_count = 1
    5052};
    51 size_t std_descriptor_size = sizeof(std_descriptor);
     53
     54/** Standard interface descriptor. */
     55usb_standard_interface_descriptor_t std_interface_descriptor = {
     56        .length = sizeof(usb_standard_interface_descriptor_t),
     57        .descriptor_type = USB_DESCTYPE_INTERFACE,
     58        .interface_number = 0,
     59        .alternate_setting = 0,
     60        .endpoint_count = 1,
     61        .interface_class = USB_CLASS_HID,
     62        .interface_subclass = 0,
     63        .interface_protocol = USB_HID_PROTOCOL_KEYBOARD,
     64        .str_interface = 0
     65};
    5266
    5367/** USB keyboard report descriptor.
     
    105119        .descriptor1_length = sizeof(report_descriptor)
    106120};
    107 size_t hid_descriptor_size = sizeof(hid_descriptor);
     121
     122/** Endpoint descriptor. */
     123usb_standard_endpoint_descriptor_t endpoint_descriptor = {
     124        .length = sizeof(usb_standard_endpoint_descriptor_t),
     125        .descriptor_type = USB_DESCTYPE_ENDPOINT,
     126        .endpoint_address = 1 | 128,
     127        .attributes = USB_TRANSFER_INTERRUPT,
     128        .max_packet_size = 8,
     129        .poll_interval = 10
     130};
     131
     132/** Standard configuration descriptor. */
     133usb_standard_configuration_descriptor_t std_configuration_descriptor = {
     134        .length = sizeof(usb_standard_configuration_descriptor_t),
     135        .descriptor_type = USB_DESCTYPE_CONFIGURATION,
     136        .total_length =
     137                sizeof(usb_standard_configuration_descriptor_t)
     138                + sizeof(std_interface_descriptor)
     139                + sizeof(hid_descriptor)
     140                + sizeof(endpoint_descriptor)
     141                ,
     142        .interface_count = 1,
     143        .configuration_number = 1,
     144        .str_configuration = 0,
     145        .attributes = 128, /* denotes bus-powered device */
     146        .max_power = 50
     147};
     148
     149
    108150
    109151
  • uspace/app/virtusbkbd/kbdconfig.h

    rfd17ab5 r2c381250  
    4040#include "descriptor.h"
    4141
    42 extern usb_standard_device_descriptor_t std_descriptor;
    43 extern size_t std_descriptor_size;
     42extern usb_standard_device_descriptor_t std_device_descriptor;
     43
     44extern usb_standard_configuration_descriptor_t std_configuration_descriptor;
     45
     46extern usb_standard_interface_descriptor_t std_interface_descriptor;
     47
     48extern usb_standard_endpoint_descriptor_t endpoint_descriptor;
     49
     50
    4451extern hid_descriptor_t hid_descriptor;
    45 extern size_t hid_descriptor_size;
     52
    4653extern report_descriptor_data_t report_descriptor;
    4754extern size_t report_descriptor_size;
  • uspace/app/virtusbkbd/virtusbkbd.c

    rfd17ab5 r2c381250  
    8989};
    9090
     91usbvirt_device_configuration_extras_t extra_descriptors[] = {
     92        {
     93                .data = (uint8_t *) &std_interface_descriptor,
     94                .length = sizeof(std_interface_descriptor)
     95        },
     96        {
     97                .data = (uint8_t *) &hid_descriptor,
     98                .length = sizeof(hid_descriptor)
     99        },
     100        {
     101                .data = (uint8_t *) &endpoint_descriptor,
     102                .length = sizeof(endpoint_descriptor)
     103        }
     104};
     105
     106/** Keyboard configuration. */
     107usbvirt_device_configuration_t configuration = {
     108        .descriptor = &std_configuration_descriptor,
     109        .extra = extra_descriptors,
     110        .extra_count = sizeof(extra_descriptors)/sizeof(extra_descriptors[0])
     111};
     112
     113/** Keyboard standard descriptors. */
     114usbvirt_descriptors_t descriptors = {
     115        .device = &std_device_descriptor,
     116        .configuration = &configuration,
     117        .configuration_count = 1,
     118};
     119
    91120/** Keyboard device.
    92121 * Rest of the items will be initialized later.
     
    94123static usbvirt_device_t keyboard_dev = {
    95124        .ops = &keyboard_ops,
    96         .standard_descriptor = &std_descriptor,
     125        .descriptors = &descriptors,
    97126        .device_id_ = USBVIRT_DEV_KEYBOARD_ID
    98127};
  • uspace/lib/usbvirt/device.h

    rfd17ab5 r2c381250  
    4646        uint8_t *data);
    4747
     48/** Device operations. */
    4849typedef struct {
     50        /** Callback for standard USB request.
     51         * Called only when the request could not be handled by this
     52         * framework.
     53         */
    4954        usbvirt_on_device_request_t on_devreq_std;
     55        /** Callback for class-specific USB request. */
    5056        usbvirt_on_device_request_t on_devreq_class;
     57        /** Callback for all other incoming data. */
    5158        int (*on_data)(struct usbvirt_device *dev,
    5259            usb_endpoint_t endpoint, void *buffer, size_t size);
    5360} usbvirt_device_ops_t;
     61
     62/** Extra configuration data for GET_CONFIGURATION request. */
     63typedef struct {
     64        /** Actual data. */
     65        uint8_t *data;
     66        /** Data length. */
     67        size_t length;
     68} usbvirt_device_configuration_extras_t;
     69
     70/** Single device configuration. */
     71typedef struct {
     72        /** Standard configuration descriptor. */
     73        usb_standard_configuration_descriptor_t *descriptor;
     74        /** Array of extra data. */
     75        usbvirt_device_configuration_extras_t *extra;
     76        /** Length of @c extra array. */
     77        size_t extra_count;
     78} usbvirt_device_configuration_t;
     79
     80/** Standard USB descriptors. */
     81typedef struct {
     82        /** Standard device descriptor.
     83         * There is always only one such descriptor for the device.
     84         */
     85        usb_standard_device_descriptor_t *device;
     86       
     87        /** Configurations. */
     88        usbvirt_device_configuration_t *configuration;
     89        /** Number of configurations. */
     90        size_t configuration_count;
     91} usbvirt_descriptors_t;
     92
    5493
    5594typedef struct usbvirt_device {
     
    69108        /* Device attributes. */
    70109       
    71         /** Standard device descriptor.
    72          * If this descriptor is set (i.e. not NULL), the framework
    73          * automatically handles call for its retrieval.
    74          */
    75         usb_standard_device_descriptor_t *standard_descriptor;
     110        /** Standard descriptors. */
     111        usbvirt_descriptors_t *descriptors;
    76112       
    77113       
  • uspace/lib/usbvirt/stdreq.c

    rfd17ab5 r2c381250  
    3434 */
    3535#include <errno.h>
     36#include <stdlib.h>
     37#include <mem.h>
    3638#include <usb/devreq.h>
    3739
    3840#include "private.h"
     41
     42
    3943
    4044/*
     
    5256         */
    5357        if ((type == USB_DESCTYPE_DEVICE) && (index == 0)) {
    54                 if (device->standard_descriptor) {
     58                if (device->descriptors && device->descriptors->device) {
    5559                        return device->send_data(device, 0,
    56                             device->standard_descriptor,
    57                             device->standard_descriptor->length);
     60                            device->descriptors->device,
     61                            device->descriptors->device->length);
    5862                } else {
    5963                        return EFORWARD;
    6064                }
     65        }
     66       
     67        /*
     68         * Configuration descriptor together with interface, endpoint and
     69         * class-specific descriptors.
     70         */
     71        if (type == USB_DESCTYPE_CONFIGURATION) {
     72                if (!device->descriptors) {
     73                        return EFORWARD;
     74                }
     75                if (index >= device->descriptors->configuration_count) {
     76                        return EFORWARD;
     77                }
     78                /* Copy the data. */
     79                usbvirt_device_configuration_t *config = &device->descriptors
     80                    ->configuration[index];
     81                uint8_t *all_data = malloc(config->descriptor->total_length);
     82                if (all_data == NULL) {
     83                        return ENOMEM;
     84                }
     85               
     86                uint8_t *ptr = all_data;
     87                memcpy(ptr, config->descriptor, config->descriptor->length);
     88                ptr += config->descriptor->length;
     89                size_t i;
     90                for (i = 0; i < config->extra_count; i++) {
     91                        usbvirt_device_configuration_extras_t *extra
     92                            = &config->extra[i];
     93                        memcpy(ptr, extra->data, extra->length);
     94                        ptr += extra->length;
     95                }
     96               
     97                int rc = device->send_data(device, 0, all_data,
     98                    config->descriptor->total_length);
     99               
     100                free(all_data);
     101               
     102                return rc;
    61103        }
    62104       
Note: See TracChangeset for help on using the changeset viewer.